<?php

//變量名,變量值,工具條模式,編輯器目錄,高度,寬度,全頁
function ECMS_ShowEditorVar($varname,$varvalue,$toolbar='full',$basepath='',$height='300',$width='100%',$fullpage=0){
	global $eshoweditorhtml;
	$toolbar=strtolower($toolbar);
	if($varvalue)
	{
		$varvalue=ehtmlspecialchars($varvalue);
	}
	if(empty($basepath))
	{
		$basepath='ecmseditor/infoeditor/';
	}
	if(empty($height))
	{
		$height='300';
	}
	if(empty($width))
	{
		$width='100%';
	}
	$editorvars='';
	if($fullpage==1)
	{
		$editorvars.="fullPage:true, ";
	}
	if($toolbar=='basic')
	{
		$editorvars.="toolbar:'basic', ";
	}
	if($eshoweditorhtml)
	{
		$editorvars.="startupMode:'source', ";
	}
	$editorvars.="width:'".$width."', height:'".$height."'";

	$echoeditor="<textarea cols='90' rows='10' id='".$varname."' name='".$varname."'>".$varvalue."</textarea>
<script type='text/javascript'>CKEDITOR.replace('".$varname."',
{
     ".$editorvars."
});</script>";

	return $echoeditor;
}

//返回加載JS文件
function ECMS_ShowEditorJS($basepath=''){
	if(empty($basepath))
	{
		$basepath='ecmseditor/infoeditor/';
	}
	$addcs=ECMS_ReturnEditorCx();

	$loadjs='<input type=hidden id=doecmseditor_eaddcs value="'.$addcs.'"> <script type="text/javascript" src="'.$basepath.'ckeditor.js?&empirecms=1"></script>';

	return $loadjs;
}

//附加參數
function ECMS_ReturnEditorCx(){
	global $classid,$filepass,$id,$r,$enews,$ecms_hashur;
	if($enews=='AddClass'||$enews=='EditClass')
	{
		$modtype=1;
	}
	elseif($enews=='AddZt'||$enews=='EditZt')
	{
		$modtype=2;
	}
	else
	{
		$modtype=0;
	}
	$classid=(int)$classid;
	$filepass=(int)$filepass;
	$id=(int)$id;
	$modtype=(int)$modtype;
	$str="&classid=$classid&filepass=$filepass&infoid=$id&modtype=$modtype&sinfo=1".$ecms_hashur['ehref'];
	return $str;
}

//上傳提示
function ECMS_PTEditorShowError($type,$error,$showstr,$add,$ecms=0){
?>
<script type='text/javascript'>
<?php
if($error)
{
	echo'alert("'.$error.'");';
}
if($showstr&&$showstr!='####')
{
	echo"window.parent.EcmsEditorReturnDoAction".$type."('".addslashes($showstr)."');";
}
?>
</script>
<?php
}

//返回type
function ECMS_EditorReturnType($page){
	if(empty($page))
	{
		$page=$_POST['doecmspage']?$_POST['doecmspage']:$_GET['doecmspage'];
	}
	if($page=='TranFile')
	{
		$r['ftype']=0;
		$r['jsfun']='EHEcmsEditorDoTranFile';
	}
	elseif($page=='TranFlash')
	{
		$r['ftype']=2;
		$r['jsfun']='EHEcmsEditorDoTranFlash';
	}
	elseif($page=='TranMedia')
	{
		$r['ftype']=3;
		$r['jsfun']='EHEcmsEditorDoTranMedia';
	}
	elseif($page=='TranMore')
	{
		$r['ftype']='TM';
		$r['jsfun']='EHEcmsEditorDoTranMore';
	}
	elseif($page=='TranImg2')
	{
		$r['ftype']=1;
		$r['jsfun']='EHEcmsEditorDoTranImgTwo';
	}
	else	//TranImg
	{
		$r['ftype']=1;
		$r['jsfun']='EHEcmsEditorDoTranImg';
	}
	return $r;
}

//選擇提示
function ECMS_EditorChFileFun($page){
	$r=ECMS_EditorReturnType($page);
	return $r['jsfun'];
}

?>