<? require "../../admin_header.php"?>
<?
/**
 * @version		1.0
 * @package		HonoWeb->HonoBBS
 * @copyright	Copyright (C) HonoWeb. All rights reserved.
 * @Website		www.honoweb.com.
 */
 ?>
<?
    //Add
	if($status=="add")
	{
	 	$sql="insert into ".$TableBbs_category."(name,pid,description,sortid,is_show)values('$name',0,'$description',".$sortid.",".$is_show.")";
		$query=$db->query($sql);
	}
	if($status=="addSub")
	{
		$file_name = $_FILES["file"]['name'];
		$pic=substr($file_name,strrpos($file_name,'.'),strlen($file_name)-strrpos($file_name,'.'));
	   	if(!empty($file_name))
	    {
			$sql="insert into ".$TableBbs_category."(name,pid,description,picture,sortid,is_show)values('$name',$pid,'$description','$pic',".$sortid.",".$is_show.")";
			$query=$db->query($sql);
			if($query)
			{
				$sql="select max(id) as id from ".$TableBbs_category;
				$row=$db->getRow($sql);
				$FileName=$UploadPath."upload/bbs/category/".$row[id].$pic;
				$file = $_FILES['file']['tmp_name'];
			   if(copy($file,$FileName))
			   {
				  unlink($file);
			   }
			}
		}
		else
		{
			$sql="insert into ".$TableBbs_category."(name,pid,description,sortid,is_show)values('$name',$pid,'$description',".$sortid.",".$is_show.")";
			$query=$db->query($sql);
		}
	}
?>
<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="add";
		 form.message.value=1;
		 form.submit();    
  	}
	
	function addSub()
    {
		var form=form1;
		if(form.pid.value=="")
		{
			alert("请选择 论坛分类!");
			form.pid.focus();
			return;
		}
		if(form.name.value=="")
		{
			alert("请输入 论坛分类名称!");
			form.name.focus();
			return;
		}
		if(!isIntegerPlus(form.sortid.value))
		{
			alert("排序号必须为整数!");
			form.sortid.focus();
			return;
		}
		 form.status.value="addSub";
		 form.message.value=1;
		 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'>
                        <tr align="center"  class='tr2' >
                          <td colspan="2"> <font  class="message">
                            <? if($message==1){echo "Add Successfully";}?>
                          </font> </td>
                        </tr>
                        <tr  class='tr2' >
                          <td >论坛分类:</td>
                          <td >
                            <select name="pid" id="pid">
							<option value=""></option>
                              <? 
	                         			$sql3="select * from ".$TableBbs_category." where pid=0";
										$query3=$db->query($sql3);
							 			while($object3=$db->fetch_object($query3))
							 	  		{
										  if($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" ></td>
                        </tr>
						<tr  class='tr2'>
									<td width="156" > 排序号:</td>
								    <td width="632" ><input name="sortid" type="text" id="sortid" value="1" ></td>
								</tr>
                       <tr  class='tr2' >
                          <td >描述:</td>
                          <td ><textarea name="description" cols="70" rows="8" id="description"></textarea></td>
                        </tr>
                        <tr  class='tr2'  >
									<td >显示:</td>
									<td >									
									<?
										for($i=1;$i<=count($T_Is_YesNO);$i++)
										{
											if((int)$is_show==$i||(empty($is_show)&&$i==1))
												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 ><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="Button" value="添加下级" class="button"  onClick="addSub()">
&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="message" value=0>
</form>
</body>
</html>
<? $db->close_db();?>

