<?php
class netsEditor extends netsConfig {
	public $sName='';
	public $sModel='Base';//0.Normal,1.Base
	public $sValue='';
	public $sBasePath='../../../';
	public $sSheme='default';
	
	public $sysSPLIT1=',';
	public $sVersion='Nets UserEditor 0.01';
	public $sConfigPath='Config/netsEditorConfig.xml';
	public $sXmlElement=array();
	public $sConfig=array();
	
	public function netsEditor(){}
	public function readFile($pFilePath){
		$tmpSTR='';
		//
		if(is_file($pFilePath)){
			$tmpfileHandle=fopen($pFilePath, 'r');
			$tmpSTR=fread($tmpfileHandle, filesize ($pFilePath));
			fclose($tmpfileHandle);
		}else {}
		return $tmpSTR;
	}
	public function getFileExname($pFileName){
		$pFileName=str_replace('\\','/',$pFileName);
		$tmpAR0=explode('/',$pFileName);
		$tmpAR0=explode('.',$tmpAR0[count($tmpAR0)-1]);
		$tmpSTR=$tmpAR0[count($tmpAR0)-1];
		if(count($tmpAR0)<2){
			$tmpSTR='.';
		}
		return $tmpSTR;
	}
	public function Create($pColumn){
		//-- ------ #Read config ------ --
		$tmpSTR=$this->sBasePath.'Component/Nets/netsEditor/'.$this->sConfigPath;
		$this->sXmlElement=new SimpleXMLElement($this->readFile($tmpSTR));
		foreach($this->sXmlElement->Parameters as $Row0){
			if($this->sModel==$Row0['name']){
				$this->sConfig=$Row0['name'];
			}
		}
		if(count($this->sConfig)==0){
			$this->sConfig=$this->sXmlElement->Parameters[0];
		}
		//-- ------ #Check ------ --
		if($this->sValue==''){
			$this->sValue='&nbsp;';
		}
?>
<link href="<?php echo($this->sBasePath); ?>Component/Nets/netsEditor/Ssheet/<?php echo($this->sSheme); ?>.css" rel="stylesheet" />
<script src="<?php echo($this->sBasePath); ?>Component/Nets/netsEditor/Jscript/<?php echo($this->sSheme); ?>.js" type="text/javascript"></script>
<div id="<?php echo($this->sName); ?>_Box" class="netsEdit_Box">
<!-- ------ #<?php echo($this->sName); ?> Button ------ -->
<div class="netsEdit_Button">
<!-- #<?php echo($this->sName); ?> Font -->
<ul class="netsEdit_Button_0">
<?php
$Coun0=0;
foreach($this->sConfig->Cells as $Cells){
	//-- ------ #Control ------ --
	if($Cells->Type=='button'){
		//-- #Button --
		$tmpSTR=$Cells->Operation;
		$tmpSTR=str_replace('{Nets.Name}',$this->sName,$tmpSTR);
?>
<li id="<?php echo($this->sName); ?>_Button_<?php echo($Coun0); ?>" class="netsEdit_Button_1" onclick="<?php echo($tmpSTR); ?>" onmouseover="this.className='netsEdit_Button_2';this.childNodes[0].src='<?php echo($this->sBasePath); ?>Component/Nets/netsEditor/Img/<?php echo($Cells->ImgHead); ?>b.jpg';" onmouseout="this.className='netsEdit_Button_1';this.childNodes[0].src='<?php echo($this->sBasePath); ?>Component/Nets/netsEditor/Img/<?php echo($Cells->ImgHead); ?>a.jpg';"><img src="<?php echo($this->sBasePath); ?>Component/Nets/netsEditor/Img/<?php echo($Cells->ImgHead); ?>a.jpg" /></li>
<?php
	}else if($Cells->Type=='line'){
		//-- #line --
?><li class="netsEdit_Button_100">&nbsp;</li>
<?php
	}else if($Cells->Type=='dropdownImg'){
		//-- #Dropdown img --
		$tmpAR1=explode($this->sysSPLIT5,$Cells->Options);
		$tmpAR0=array();
		foreach ($tmpAR1 as $Cell0){
			$tmpAR0[]=explode($this->sysSPLIT1,$Cell0);
		}
?>
<li id="<?php echo($this->sName); ?>_Button_<?php echo($Coun0); ?>" class="netsEdit_Button_1" onmouseover="this.className='netsEdit_Button_3';this.childNodes[0].src='<?php echo($this->sBasePath); ?>Component/Nets/netsEditor/Img/<?php echo($Cells->ImgHead); ?>c.jpg';document.getElementById('<?php echo($this->sName); ?>_Box_<?php echo($Coun0); ?>').className='netsEdit_Button_3_A';" onmouseout="this.className='netsEdit_Button_1';this.childNodes[0].src='<?php echo($this->sBasePath); ?>Component/Nets/netsEditor/Img/<?php echo($Cells->ImgHead); ?>a.jpg';document.getElementById('<?php echo($this->sName); ?>_Box_<?php echo($Coun0); ?>').className='DHidden';"><img src="<?php echo($this->sBasePath); ?>Component/Nets/netsEditor/Img/<?php echo($Cells->ImgHead); ?>a.jpg" />
<div id="<?php echo($this->sName); ?>_Box_<?php echo($Coun0); ?>" class="DHidden">
<!-- #TAB -->
<ul class="netsEdit_Button_3_DE">
<?php $Coun1=0; foreach ($tmpAR0 as $Cell0){
	$tmpStyle='netsEdit_Button_3_E';
	if($Coun1==0){ $tmpStyle='netsEdit_Button_3_D'; } ?>
<li id="<?php echo($this->sName); ?>_Button_<?php echo($Coun0); ?>_ImgTab_<?php echo($Coun1); ?>" class="<?php echo ($tmpStyle); ?>" onmouseover="tmpEditor_<?php echo($this->sName); ?>.tabIMG(<?php echo($Coun0); ?>,<?php echo ($Coun1); ?>);"><?php echo ($Cell0[0]); ?></li>
<?php $Coun1++; } ?>
<li class="DClear"></li></ul>
<!-- #IMG -->
<?php $Coun1=0; foreach ($tmpAR0 as $Cell0){
	$tmpStyle=$this->sysHidden;
	if($Coun1==0){ $tmpStyle='netsEdit_Button_3_F'; } ?>
<table id="<?php echo($this->sName); ?>_Button_<?php echo($Coun0); ?>_ImgBox_<?php echo($Coun1); ?>" class="<?php echo ($tmpStyle); ?>" cellpadding="2" cellspacing="0"><tr>
<?php
		$tmpPATH=$this->sBasePath.'Component/Nets/netsEditor/'.$Cell0[1];
		$tmpDIR=dir($tmpPATH);
		$Coun2=0;
		while(($Cell1 = $tmpDIR->read())!==false){
			$tmpImg=$tmpPATH.$Cell1;
			$tmpSTR=$Cells->Operation;
			$tmpSTR=str_replace('{Nets.Name}',$this->sName,$tmpSTR);
			$tmpSTR=str_replace('{Nets.Img}',$tmpImg,$tmpSTR);
			$tmpExtendName=$this->getFileExname($Cell1);
			if($tmpExtendName=='gif' || $tmpExtendName=='jpg' || $tmpExtendName=='png'){ 
?><td class="netsEdit_Button_3_B" onclick="<?php echo($tmpSTR); ?>"><img src="<?php echo($tmpImg); ?>" /></td>
<?php
				$Coun2++;
			}
			if (($Coun2)%12==0){
				?></tr><tr><?php
			}
		}
		$tmpDIR->close();
?>
</tr></table>
<?php $Coun1++; } ?>
</div></li>
<?php } $Coun0++; } ?>
<li class="DClear"></li></ul></div>
<!-- ------ #<?php echo($this->sName); ?> Content ------ -->
<div class="netsEdit_Content"><iframe id="<?php echo($this->sName); ?>_Content" class="netsEdit_Frame"
	onclick="<?php echo($pColumn['Parameter_JS_Onclick']); ?>"
	onfocus="tmpEditor_<?php echo($this->sName); ?>.ResetContent();<?php echo($pColumn['Parameter_JS_Onfocus']); ?>"
	onblur="tmpEditor_<?php echo($this->sName); ?>.ResetContent();<?php echo($pColumn['Parameter_JS_Onblur']); ?>"
	onchange="<?php echo($pColumn['Parameter_JS_Onchange']); ?>"
	onmouseover="<?php echo($pColumn['Parameter_JS_Onmouseover']); ?>"
	onmouseout="<?php echo($pColumn['Parameter_JS_Onmouseout']); ?>"
	frameborder="0"></iframe></div>
<textarea id="<?php echo($this->sName); ?>" name="<?php echo($this->sName); ?>" class="DHidden"><?php echo ($this->sValue); ?></textarea>
</div>
<!-- ------ #<?php echo($this->sName); ?> Version ------ -->
<div id="<?php echo($this->sName); ?>_Version" class="netsEdit_Version"><?php echo($this->sVersion); ?></div>
<!-- ------ #<?php echo($this->sName); ?> SCRIPT ------ -->
<script type="text/javascript">
var tmpEditor_<?php echo($this->sName); ?>=new netsEditor();
tmpEditor_<?php echo($this->sName); ?>.sName="<?php echo($this->sName); ?>";
tmpEditor_<?php echo($this->sName); ?>.sEditor=<?php echo($this->sName); ?>_Content;
tmpEditor_<?php echo($this->sName); ?>.Initial();

</script>
<?php
	}
}
?>