<? require "../../admin_header.php"?>
<?
/**
 * @version		1.0
 * @package		HonoWeb->HonoBBS
 * @copyright	Copyright (C) HonoWeb. All rights reserved.
 * @Website		www.honoweb.com.
 */
 ?>
<?
	//修改
	if($status=="edit")
	{
	  if(empty($pid))
	  {
	   	$sql="update ".$TableBbs_category." set is_show=".$is_show.",name='$name',description='$description' , sortid=".$sortid." where id=$id";
	   	$query=$db->query($sql);
		header("location: bbs_category.php");
		return;
	  }
	  else
	  {	
	  	$file_name = $_FILES["file"]['name'];
	  	$pic=substr($file_name,strrpos($file_name,'.'),strlen($file_name)-strrpos($file_name,'.'));
		if(!empty($file_name))
	    {
			$sql="update ".$TableBbs_category." set  is_show=".$is_show.",name='$name',pid=$pid,description='$description',picture='$pic', sortid=".$sortid."  where id=$id";
			$query=$db->query($sql);
			if($query)
			{
				$FileName=$UploadPath."upload/bbs/category/".$id.$pic;
				$file = $_FILES['file']['tmp_name'];
			   	if(copy($file,$FileName))
			  	 {
				  	unlink($file);
			   	}
			}
		}
		else
		{
			$sql="update ".$TableBbs_category." set is_show=".$is_show.", name='$name',pid=$pid,description='$description', sortid=".$sortid."  where id=$id";
			$query=$db->query($sql);
		}
		header("location: bbs_category.php");
		return;
	  }
	}
	$sql="select * from ".$TableBbs_category." 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 language="javascript" src="../../js/check.js"></script>
</head>
<script language="javascript">

	function back()
	{
		location="bbs_category.php";
	}
	function Check()
    {
		var form=form1;
		if(form.name.value=="")
		{
			alert("请选择 论坛分类名称!");
			form.name.focus();
			return;
		}
		if(!isIntegerPlus(form.sortid.value))
		{
			alert("排序号必须为整数!");
			form.sortid.focus();
			return;
		}
		 form.status.value="edit";
		 form.submit();    
  }
</script>
<body>
<form action=""  method="post"  name="form1" enctype="multipart/form-data">
  <table class="firsttable">
      <tr>
    	<td align="center" valign="top">
        	    <table class="centertable">
          	<tr>
            		<td></td>
          	</tr>
          	<tr>
            		<td align="center" class="addborder">
					  <table  class="addTable" border='0'  cellpadding='0'  cellspacing='1'>
					  <?
						  if($row[pid]!="0"){
				      ?>
                        <tr  class='tr2' >
                          <td >论坛分类:</td>
                          <td >
						  
                            <select name="pid" id="pid">
                              <? 
	                         			$sql3="select * from ".$TableBbs_category." where pid=0";
										$query3=$db->query($sql3);
							 			while($object3=$db->fetch_object($query3))
							 	  		{
										  if($row[pid]==$object3->id)
										  {
                          					echo "<option value='$object3->id' selected>";
                          					echo $object3->name;
                         				    echo "</option>";
										  }
										  else
										  {
										  	echo "<option value='$object3->id' >";
                          					echo $object3->name;
                         				    echo "</option>";
										  }
                         			 	}
									?>
                            </select>
                          </td>
                        </tr>
						<?
						}
						?>
                        <tr  class='tr2' >
                          <td >论坛分类名称</td>
                          <td ><input name="name" type="text" id="name"  value="<?=$row[name]?>"></td>
                        </tr>
						<tr  class='tr2'>
									<td width="156" > 排序号:</td>
								    <td width="632" ><input name="sortid" type="text" id="sortid"  value="<?=$row[sortid]?>" ></td>
								</tr>
                        <tr class='tr2'  >
                          <td >描述:</td>
                          <td ><textarea name="description" cols="70" rows="8" id="description"><?=$row[description]?>
                          </textarea></td>
                        </tr>
                        <tr  class='tr2'  >
									<td >显示:</td>
									<td >									
									<?
										for($i=1;$i<=count($T_Is_YesNO);$i++)
										{
											if((int)$row['is_show']==$i)
												echo "<input name='is_show' type='radio' checked  value=".$i.">".$T_Is_YesNO[$i];
											else
												echo "<input name='is_show' type='radio'   value=".$i.">".$T_Is_YesNO[$i];
										}
									?>									<span class="star">*</span></td>
					  </tr>
						<tr class='tr2'  >
                				<td >图标:</td>
                				<td ><img width="80" height="50"  src="../../upload/bbs/category/<? $pic="default.gif";
												if(!empty($row[picture]))
													$pic=$row[id].$row[picture]; echo $pic;?>" border="0" ><br><input name="file" type="file" size="50"></td>
              				</tr>
                        <tr  class='tr2' >
                          <td colspan="2" align="center">
                            <input type="button" class="button" name="Button" value="提交" onClick="Check()">
&nbsp;

      <input type="button" name="Submit2" value="返回" class="button" 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>
<? $db->close_db();?>

