<? require "../../admin_header.php"?>
<?
/**
 * @version		1.0
 * @package		HonoWeb->HonoBBS
 * @copyright	Copyright (C) HonoWeb. All rights reserved.
 * @Website		www.honoweb.com.
 */
 ?>
<?
    //添加
	if($status=="add")
	{
		$publictime=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="insert into ".$TableBbs_content."(bcategoryid,categoryid,title,content,pic,username,publictime,click_count,reply_count,vote_count,update_username,update_time,content_type)values($bcategoryid,$categoryid,'$title','$content','$pic','".$_SESSION['SessionAdminUser']['username']."','$publictime',0,0,0,'".$_SESSION['SessionAdminUser']['username']."','$publictime',$content_type)";
			$query=$db->query($sql);
			if($query)
			{
				$sql="select max(id) as id from ".$TableBbs_content;
				$row=$db->getRow($sql);
				$FileName=$UploadPath."bbs/".$row[id].$pic;
				$file = $_FILES['file']['tmp_name'];
			   if(copy($file,$FileName))
			   {
				  unlink($file);
			   }
			}
		}
		else
		{
			$sql="insert into ".$TableBbs_content."(bcategoryid,categoryid,title,content,username,publictime,click_count,reply_count,vote_count,update_username,update_time,content_type)values($bcategoryid,$categoryid,'$title','$content','".$_SESSION['SessionAdminUser']['username']."','$publictime',0,0,0,'".$_SESSION['SessionAdminUser']['username']."','$publictime',$content_type)";
			$query=$db->query($sql);
			
		}
		//
		$sql="select max(id) as id from ".$TableBbs_content;
		$row=$db->getRow($sql);
		$sql="update ".$TableBbs_category." set topic_id=".$row['id']." where id in(".$categoryid.",".$bcategoryid.")";
		$query=$db->query($sql);
		//
		$sql="update ".$TableUser." set article_count=article_count+1 where username='".$_SESSION['SessionAdminUser']['username']."' ";
		$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 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="add";
		 form.message.value=1;
		 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 align="center"  class='tr2' >
               					 <td colspan="2">
                  					<font  class="message">
                                                               <?
                                                                    if($message=="1")
                                                                    {
                                                                        echo "添加成功!";
                                                                    }
                                                               ?>
                                   </font>
       				          </td>
              				</tr>
              				<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($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=".$bcategoryid;
								$result2 = $db->getAll($sql);
								for($i=0; $i<count($result2); $i++)
								{
									if($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)$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" ></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"></textarea>
									</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" 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="message" value=0>
</form>
</body>
</html>

<script language="javascript">
function select_kind(obj)
{ //把产品的类别列出
	var f2Array = new Array();
	<?
		$sql = "select * from ".$TableBbs_category." where pid <> 0";
		$result2 = $db->getAll($sql);
		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();?>