<?php
$add=$_POST;
//$add[id]=2;
//$add[isadd]=0;
$movietype=$add[movietype];
$isadd=$add[isadd];
$islist=$add[islist];
$id=$add[id];

if($isadd!=1){
require("connect.php");
require("db_sql.php");
$empire=new mysqlquery;
$link=db_connect();

$r1=array();
$r2=array();
$query="select id,stb from {$dbtbpre}ecms_movie where id='$id' limit 1 ";
$r1=$empire->fetch1($query);
$stb=$r1[stb];
$query="select ".$movietype." from {$dbtbpre}ecms_movie_data_".$stb." where id='$id' limit 1 ";
$r2=$empire->fetch1($query);
$data=$r2[$movietype];

if($islist!=1){  //如果是文本
$html='<textarea name="'.$movietype.'text" style="height:250px;width:100%" id="'.$movietype.'textstr">'.str_replace("%%%","\r\n",htmlspecialchars(stripSlashes($data))).'</textarea>';

}
else{              //如果是列表

	$onlinemoviepath="";
	if($data)
	{
		$j=0;
		$od_record=explode("%%%",$data);
		for($i=0;$i<count($od_record);$i++)
		{
			$j=$i+1;
			$od_field=explode("$$$",$od_record[$i]);
			$onlinemoviepath.="	
		<tr>
			<td width='10%'><span align=center>".$j."</span></td>
			<td width='20%'><span align=left><input name=".$movietype."name[] type=text value='".$od_field[0]."' size=17></span></td>
			<td width='50%'><input name=".$movietype."url[] type=text value='".$od_field[1]."' size=80 id=".$movietype."url".$j."></td>
			<td width='20%'>
                    <span align=center> 
<input type=hidden name=".$movietype."pathid[] value=".$j."><input type=checkbox name=".$movietype."delpathid[] value=".$j.">删
                    </span>
			</td></tr>";
		}
		$oeditnum=$j;
		$onlinemoviepath="<table width='100%' border=0 cellspacing=1 cellpadding=3>".$onlinemoviepath."</table>";
		$html=$onlinemoviepath;
	}
	else{
	$oeditnum=3;
	$newhtml='';
	for($openi=1;$openi<=$oeditnum;$openi++){
	$newhtml.="	       <tr> 
                  <td width='10%'> <span align=center>".$openi."</span></td>
                  <td width='20%'> <span align=left> 
                      <input name=".$movietype."name[] type=text value='第".$openi."集' size=17>
                    </span></td>
                  <td width='50%'> 
		  <input name=".$movietype."url[] type=text id='".$movietype."url".$openi."' size=80 >
                  </td>
                  <td width='20%'><span align=center> 
<input type=hidden name=".$movietype."pathid[] value=".$j."><input type=checkbox name=".$movietype."delpathid[] value=".$j.">删
                    </span></td>
                </tr>";

	
	}
	$onlinemoviepath="<table width='100%' border=0 cellspacing=1 cellpadding=3>".$newhtml."</table>";
	$html=$onlinemoviepath;	
	}
     
}


echo $html;


echo '<hr>';
echo $isadd;
echo $movietype;
echo $islist;

db_close();
$empire=NULL;
}
?>