<? require "header.php"?>
<? require "include/authorizeuser.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(".$bcatid.",".$scatid.",'$title','$content','$pic','".$_SESSION['SessionUser']['username']."','$publictime',0,0,0,'".$_SESSION['SessionUser']['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."upload/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(".$bcatid.",".$scatid.",'$title','$content','".$_SESSION['SessionUser']['username']."','$publictime',0,0,0,'".$_SESSION['SessionUser']['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 (".$bcatid.",".$scatid.")";
		$query=$db->query($sql);
		//
		$sql="update ".$TableUser." set article_count=article_count+1 where username='".$_SESSION['SessionUser']['username']."' ";
		$query=$db->query($sql);
		$message=1;
	}
?>
<html>
<head>
<title><?=$bbs_config_row['bbs_name']?></title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link href="<?=$T_BBS_Style_CSS?>" rel="stylesheet" type="text/css">
<script type="text/javascript" src="<?=$BBSFolder?>/js/check.js"></script>
<script type="text/javascript" src="<?=$BBSFolder?>/admin/fckeditor/fckeditor.js"></script>
</head>
<script language="javascript">
	function Check()
	{
		var form=document.getElementById("form1");
		if(form.title.value=="")
		{
			alert("请输入主题标题!");
			form.title.focus();
			return;
		}
		 form.status.value="add";
		 form.submit();
  	}
</script>
<body>

<form name="form1" id="form1"  method="post"  enctype="multipart/form-data">
  <table border="0" cellpadding="0"  cellspacing="0" class="firsttable">
    <tr>
      <td align="center" valign="top">
	  	<table  cellpadding="0" cellspacing="0"  class="centertable">
      		<tr> 
            	<td align="center"><? include "top.php"?> 
            	</td>
       		</tr>
        	<tr>
        	  <td align="center">&nbsp;</td>
      	  </tr>
        	<tr>
        	  <td align="center"><table width="100%"  border="0" cellpadding="0" cellspacing="0" class="bg2">
                <tr>
                  <td height="26" style="padding-left:10px; ">
                  <font class="font1">
                  <? include "navegator.php"?>
      → 添加主题</font></td>
                </tr>
              </table></td>
      	  </tr>
        	<tr>
        	  <td align="center"><table width="100%"  border="0" cellspacing="0" cellpadding="0">
                <tr>
                  <td height="40"><table width="100%"  border="0" cellspacing="0" cellpadding="0">
                    <tr align="center">
                      <td width="85" height="26" class="link3"><img src="<?=$BBSFolder?>/images/clustindex.gif" width="14" height="11"> <a href="<?=$BBSFolder?>/forum.php?bcatid=<?=$bcatid?>&scatid=<?=$scatid?>">返回主题</a></td>
                      <td width="10">&nbsp;</td>
                      <td width="85" class="link3">&nbsp;</td>
                      <td>&nbsp;</td>
                    </tr>
                  </table></td>
                  <td>&nbsp;</td>
                </tr>
              </table></td>
      	  </tr>
            <tr>
              <td id="an" align="center"><table width="100%" border="0" cellpadding="0" cellspacing="0" class="bg1" style="font-size:12px;">
                <tr align="center" class="bar" style="font-size:12px; font-weight:bold;color:#FFF2B1; ">
                  <td height="28" colspan="2" >&nbsp;</td>
                </tr>
              
                <tr>
                  <td height="30" colspan="2" align="center" class="lefttd">
                  <font class="message"><?
						if($message=="1")
						{
							echo "Add Successfully";
						}
				   ?>
                  </font>
                  </td>
                </tr>
                <tr>
					<td width="100" height="30" align="center" class="lefttd">主题标题</td>
                    <td class="righttd" style="padding-left:10px; ">  <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" size="60" ></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>
					<td width="100" align="center" class="lefttd" >内容</td>
					<td class="righttd" style="padding-left:10px; padding-right:10px; " >
					<textarea name="content" cols="70" rows="10" id="content"></textarea>					</td>
				</tr>
			
				<tr>
					<td width="100" height="30" align="center" class="lefttd">上传</td>
                  <td class="righttd" style="padding-left:10px; "><input name="file" type="file" size="50"></td>
                </tr>
				<tr>
                  <td align="center" valign="top" class="righttd" colspan="2"><input name="Button" type="button" class="font1" onClick="Check()" value="提交">                  </td>
                </tr>
               
              </table></td>
            </tr>
          <tr>
               <td align="center">&nbsp;</td>
          </tr>
		   <tr>
               <td align="center"><span class="link2">
                 <? include "bottom.php"?>
               </span></td>
          </tr>
        </table>
	  </td>
    </tr>
</table>
	<input type="hidden" name="status" value="">
  <input type="hidden" name="page" value=<?=$page?>>
  <input type="hidden" name="totalpage" value=<?=$totalpage?>>
  <input type="hidden" name="page_start" value=<?=$page_start?>>
   <input type="hidden" name="id" value="">
   <input type="hidden" name="ids" value="">
</form>
</body>
</html>
<script language="JavaScript" type="text/JavaScript">
  function currentpage(id)
  {
       var form=document.getElementById("form1");
       form.page_start.value=id;
       form.submit();
  }
  function first()
  {
       var form=document.getElementById("form1");
       if(eval(form.page.value)==1)
	   	return;
       form.page.value=1;
       form.submit();
  }

  function next()
  {
      var form=document.getElementById("form1");
      if(eval(form.page.value)>=eval(form.totalpage.value))
	  return;
      form.page.value=eval(form.page.value)+1;
      form.submit();
  }

  function last()
  {
       var form=document.getElementById("form1");
       if(eval(form.page.value)==eval(form.totalpage.value))
	   	  return;
       form.page.value=eval(form.totalpage.value);
       form.submit();
  }

  function pre()
  {
       var form=document.getElementById("form1");
       if(form.page.value<=1)
		return;
       form.page.value=eval(form.page.value)-1;
       form.submit();
  }

  function  goposition()
  {
       var form=document.getElementById("form1");
       form.page_start.value=form.position.value;
       form.submit();
  }
</script>
<? $db->close_db();?>
