<? require "../../admin_header.php"?>
<?
/**
 * @version		1.0
 * @package		HonoWeb->HonoBBS
 * @copyright	Copyright (C) HonoWeb. All rights reserved.
 * @Website		www.honoweb.com.
 */
 ?>
<?

	if($status=="edit")
	{
			$PublishTime=date('Y-n-j H:i:s');
			$pic=substr($file_name,strrpos($file_name,'.'),strlen($file_name)-strrpos($file_name,'.'));
	   	 	
			if(!empty($file_name))
	    	{
				$sql="update ".$TableBbs_content." set bcategoryid=$bcategoryid,categoryid=$categoryid,title='$title',content='$content',pic='$pic',update_time='$publictime',update_username='".$_SESSION['SessionAdminUser']['username']."',content_type=".$content_type." where id=$id";
	   	    	$query=$db->query($sql);
				if($query)
				{
					$FileName=$UploadPath."bbs/".$id.$pic;
					$file = $_FILES['file']['tmp_name'];
			   		if(copy($file,$FileName))
			  	 	{
				  		unlink($file);
			   		}
				}
			}
			else
			{
				$sql="update ".$TableBbs_content." set bcategoryid=$bcategoryid,categoryid=$categoryid,title='$title',content='$content',update_time='$publictime',update_username='".$_SESSION['SessionAdminUser']['username']."',content_type=".$content_type." where id=$id";
	   	    	$query=$db->query($sql);
			}
			header("location: bbs_content.php");
		        return;
	}
	$sql="select * from ".$TableBbs_content." where id=$id";
	$query=$db->query($sql);
	$row=$db->fetch_row($query);
?>
<html>
<head>
<title><?=$bbs_config_row['bbs_name']?></title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link href="../../css/css.css" rel="stylesheet" type="text/css">
<script type="text/javascript" src="../fckeditor/fckeditor.js"></script>
<script language="javascript" src="../../js/check.js"></script>
</head>
<script language="javascript">

	function back()
	{
		location="bbs_content.php";
	}

	function Check()
   {
		var form=form1;
		if(form.bcategoryid.value=="")
		{
			alert("请选择 论坛一级分类!");
			form.bcategoryid.focus();
			return;
		}
		if(form.categoryid.value=="")
		{
			alert("请选择 论坛板块分类!");
			form.categoryid.focus();
			return;
		}
		if(form.title.value=="")
		{
			alert("请输入标题!");
			form.title.focus();
			return;
		}

		
		 form.status.value="edit";
		 form.submit();
  	}
</script>
<body>

<form action=""  method="post"  enctype="multipart/form-data" name="form1">
  <table class="firsttable">
      <tr>
    	<td align="center" valign="top">
        	    <table class="centertable">
          	<tr>
            		<td></td>
          	</tr>
          	<tr>
            		<td align="center" class="addborder">
					<table width="700"  class="addTable" border='0'  cellpadding='0'  cellspacing='1'>
              				<tr  class='tr2' >
                				<td >论坛一级分类:</td>
                				<td ><select name="bcategoryid" id="bcategoryid" onChange="select_kind(this)">
                                  <option value=""></option>
                                  <?
									$sql = "select * from ".$TableBbs_category." where pid = 0";
									$result = $db->getAll($sql);
									for($i=0;$i<count($result);$i++) 
									{
										if($row[bcategoryid] == $result[$i][id])
										{
											echo "<option value='".$result[$i][id]."' selected>".$result[$i][name]."</option>";
										}
										else
										{
											echo "<option value='".$result[$i][id]."' >".$result[$i][name]."</option>";
										}
									}
								?>
                                </select></td>
              				</tr>
              				<tr  class='tr2' >
                				<td >论坛板块分类:</td>
                				<td >
								  <select name="categoryid" id="categoryid">
                                    <? 
							   $sql = "select * from ".$TableBbs_category." where pid=".$row[bcategoryid];
								$result2 = $db->getAll($sql);
								for($i=0; $i<count($result2); $i++)
								{
									if($row[categoryid]==$result2[$i][id])
									{
										echo "<option selected value='".$result2[$i][id]."'>".$result2[$i][name]."</option>";
									}
									else
									{
										echo "<option  value='".$result2[$i][id]."'>".$result2[$i][name]."</option>";
									}
									
								}
							    ?>
                                  </select>
                              </td>
              				</tr>
              				<tr  class='tr2' >
                				<td >标题:</td>
                				<td ><select name="content_type" id="content_type">
                                  <?
									for($i=1;$i<=count($T_Content_type);$i++)
									{
										 if((int)$row['content_type']==$i)
											echo "<option value=".$i." selected>".$T_Content_type[$i]."</option>";
										else
											echo "<option value=".$i.">".$T_Content_type[$i]."</option>";
									}
								?>
                                </select>
                				<input name="title" type="text" id="title"  value="<?=$row[title]?>" ></td>
              				</tr>
              			<script language="javascript">
									window.onload = function()
									{
								    	var sBasePath  = "<?=$T_Fk_sBasePath?>";
								   		var oFCKeditor = new FCKeditor( 'content' );
								    	oFCKeditor.BasePath	= sBasePath;
										oFCKeditor.Config['AutoDetectLanguage'] = false;
										oFCKeditor.Config['DefaultLanguage']    = '<?=$T_FkDefaultLanguage?>';
										oFCKeditor.Config['LinkBrowserURL']     = oFCKeditor.BasePath + 'editor/filemanager/browser/default/browser.html?Connector=connectors/php/connector.php&Type=File';
										oFCKeditor.Config['ImageBrowserURL']    = oFCKeditor.BasePath + 'editor/filemanager/browser/default/browser.html?Connector=connectors/php/connector.php&Type=Image';
										oFCKeditor.Config['FlashBrowserURL']    = oFCKeditor.BasePath + 'editor/filemanager/browser/default/browser.html?Connector=connectors/php/connector.php&Type=Flash';
										oFCKeditor.Config['LinkUploadURL']      = oFCKeditor.BasePath + 'editor/filemanager/upload/php/upload.php?Type=File';
										oFCKeditor.Config['ImageUploadURL']     = oFCKeditor.BasePath + 'editor/filemanager/upload/php/upload.php?Type=Image';
										oFCKeditor.Config['FlashUploadURL']     = oFCKeditor.BasePath + 'editor/filemanager/upload/php/upload.php?Type=Flash';
										oFCKeditor.Height='<?=$config_row['editor_height']?>';
										oFCKeditor.Width='<?=$config_row['editor_width']?>';
										oFCKeditor.ReplaceTextarea();
									}
								</script>
								<tr  class='tr2' >
									<td >内容:</td>
									<td >
									<textarea name="content" cols="70" rows="10" id="content"><?=$row['content']?></textarea>
									</td>
								</tr>
								
              				<tr  class='tr2' >
                				<td >上传:</td>
                				<td ><img width="100" height="80"  src="../../upload/guide/<?=$row[id].$row[pic]?>?>" border="0" ><br><input name="file" type="file" size="50"></td>
              				</tr>
              				<tr  class='tr2' >
                				        <td colspan="2" align="center">
							     <input type="button" name="Button" class="button" value="提交" onClick="Check()">
							    &nbsp;&nbsp;&nbsp;&nbsp;
      						    <input type="button" name="Submit2" class="button" value="返回" onClick="back()">
						        </td>
              				</tr>
           			  </table>
				  </td>
          		</tr>
          		<tr>
            		  <td></td>
          		</tr>
       	           </table>
    	   </td>
     </tr>
</table>
<input type="hidden" name="status" value=0>
<input type="hidden" name="id" value=<?=$id?>>
</form>
</body>
</html>
<script language="javascript">
function select_kind(obj)
{ //把产品的类别列出
	var f2Array = new Array();
	<?

		for($i=0; $i<count($result); $i++)
		{
			echo "f2Array[".$result[$i][id]."] = new Array();"."\n";
			$j = 0;
			for($k=0; $k<count($result2); $k++)
			{
				if($result2[$k][Pid] == $result[$i][id])
				{
					echo "f2Array[".$result[$i][id]."][".$j."] = new Option();"."\n";
					echo "f2Array[".$result[$i][id]."][".$j."].value = ".$result2[$k][id].";\n";
					echo "f2Array[".$result[$i][id]."][".$j."].text = '".$result2[$k][name]."';\n";
					$j++;
				}
				
			}
		}
	?>
	var form = form1;
	var i = eval(obj.value);
	form.categoryid.length = 0;
	for(var j=0; j<f2Array[i].length; j++)
	{
		form.categoryid.options[form.categoryid.length] = f2Array[i][j];
	}
}
</script>
<? $db->close_db();?>

