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

	if(!empty($_GET['cid']))
	{
		$sql="update  ".$TableBbs_content." set click_count=click_count+1 where id=".$cid;
		$query=$db->query($sql);
	}

	if($status=="add")
	{
		$answername="Guest";
		if(isLogin()) $answername=$_SESSION['SessionUser']['username'];
		$publictime=date('Y-n-j H:i:s');
		$sql="insert into  ".$TableBbs_answer."(cid,bcategoryid,categoryid,username,content,publictime)values(".$cid.",".$bcatid.",".$scatid.",'".$answername."','".$content."','".$publictime."')";
		
		$query=$db->query($sql);
		
		$sql="update  ".$TableBbs_content." set reply_count=reply_count+1 where id=".$cid;
		$query=$db->query($sql);
		//
		$sql="update ".$TableUser." set article_count=article_count+1 where username='".$_SESSION['SessionUser']['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="<?=$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>

<style type="text/css">
<!--
.STYLE1 {color: #FFFFFF}
-->
</style>
</head>
<script language="javascript">
	function Check()
	{
		var form=document.getElementById("form1");
		/*if(form.content.value=="")
		{
			alert("Please enter your  content!");
			form.content.focus();
			return;
		}*/
		 form.status.value="add";
		 form.submit();
  	}
</script>
<body>

<form name="form1" id="form1" method="post" >
  <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>
<?

		if(!empty($cid))
		{
			$sql="select * from ".$TableBbs_content." where id=".$cid ;
			$row_title=$db->getRow($sql);
		}		


?>
        	<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"?>
	  → <?=$row_title['title']?></font></td>
                </tr>
              </table></td>
      	  </tr>
<?
		/*******************edit by huxinbo*********************/

?>
        	<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">
					 <?
					 if(isLogin())
					{
					 ?>
                      <td width="85" height="26" class="link3"><img src="<?=$BBSFolder?>/images/clustindex.gif" width="14" height="11"> <a href="<?=$BBSFolder?>/forumadd.php?bcatid=<?=$bcatid?>&scatid=<?=$scatid?>">添加主题</a></td>
                      <td width="10">&nbsp;</td>
                      <td width="85" class="link3"><img src="<?=$BBSFolder?>/images/dbcindex.gif" width="16" height="13" class="link3"><a href="#an"> 回复</a></td>
                      <?
					  }
					  ?>
					  <td>&nbsp;</td>
                    </tr>
                  </table></td>
                  <td>&nbsp;</td>
                </tr>
              </table></td>
      	  </tr>
        	<tr>
        	  <td align="center">		
			  <?
			if(empty($page))
			{$page=1;}
			else
			{
				 if($page<1){ $page=1;}
			}
			if(empty($page_start))
			{$page_start=1;}
			else
			{
				 if($page_start<1){ $page_start=1;}
			}
			$pagenum=30;
			$bpage=10;//大翻页数
			
             $b=false;
             $filter="";
             
             $fvalue=$cid;
             if(!empty($fvalue))
             {
                 if($b)
                     $filter.=" and";
                 $filter.=" a.cid = ".$fvalue."  ";
                 $b=true;
             }
			 
            
			$sql="select a.*,b.id as bid,b.photo,b.embed_photo,b.upload_type,b.regtime,b.UserGrade,b.article_count from  ".$TableBbs_answer." as a left join ".$TableUser." as b ";
			$sql1="select count(*) as num from   ".$TableBbs_answer." as a left join ".$TableUser." as b ";
			if($b)
			{
				$sql.=" on a.username=b.username  where ".$filter."   limit ".(($page-1)*$pagenum).",$pagenum";
				$sql1.=" on a.username=b.username  where ".$filter."   ";
			}
			else
			{
				$sql.="  on a.username=b.username         limit ".(($page-1)*$pagenum).",$pagenum";
				$sql1.="  on a.username=b.username     ";
			}
			
			$query=$db->query($sql);
			$query1=$db->query($sql1);
			$rows=$db->fetch_row($query1);
			$page_num=ceil($rows[num]/$pagenum);
			$totalpage=ceil($rows[num]/($pagenum*$bpage));
			$page_end=$page*$bpage;
			if((int)$page_end>=(int)$rows[num])  
				$page_end=$page_num;
			  ?>	  
			  <table width="100%" style="font-size:12px;" border="0" cellspacing="0" cellpadding="0">
                <tr align="center" class="bar" style="font-size:12px; font-weight:bold;color:#FFF2B1; ">
                  <td height="28" colspan="2"><table width="100%" border="0" cellspacing="0" cellpadding="0">
                    <tr>
                      <td>&nbsp;</td>
                      <td align="right" class="link3" style="padding-left:10px;">&nbsp;</td>
                    </tr>
                  </table></td>
                </tr>
				<?
				$sql="select a.*,b.id as bid,b.photo,b.embed_photo,b.upload_type,b.regtime,b.UserGrade,b.article_count ,c.name as role_name from  ".$TableBbs_content." as a , ".$TableUser." as b, ".$TableRole." as c where a.username=b.username and b.UserGrade=c.id and a.id=".$cid; //主题
				$row=$db->getRow($sql);
				?>
				<tr>
                  <td width="195" height="275" align="center" valign="top" class="lefttd" ><table width="80%"  border="0" cellpadding="0" cellspacing="0" class="font1">
                    <tr>
                      <td height="40">用户：                        <?=$row[username]?></td>
                    </tr>
                    <?
					$user_pic=$SETUPFOLDER."/upload/manager_users/default.jpg";
					if((int)$row['upload_type']==1)
						$user_pic=$SETUPFOLDER."/upload/manager_users/".$row['photo']; 
					if((int)$row['upload_type']==2)
						$user_pic=$row['embed_photo']; 
					?>
                    <tr>
                      <td height="20"><img  src="<?=$user_pic?>"  width="<?=$config_row['user_thumbnail_width']?>" height="<?=$config_row['user_thumbnail_height']?>"    border="0" ></td>
                    </tr>
                    <tr>
                      <td height="20"> 发帖数： <?=$row[article_count]?></td>
                    </tr>
                    <tr>
                      <td height="20">注册日期： <?=$row[regtime]?></td>
                    </tr>
                  </table></td>
                  <td align="center" valign="top" class="righttd"><table width="94%"  border="0" cellspacing="0" cellpadding="0">
                    <tr>
                      <td height="40" class="line"><table width="100%"  border="0" cellpadding="0" cellspacing="0" class="font1">
                        <tr>
                          <td><span class="link3" style="padding-left:10px;">
                            <?
					 if(isLogin()&&$_SESSION['SessionUser']['username']==$row[username])
					{
					 ?>
                            <img src="<?=$BBSFolder?>/images/dbcindex.gif" width="16" height="13" class="link3"><a href='<?=$BBSFolder?>/forumedit.php?bcatid=<?=$bcatid?>&scatid=<?=$scatid?>&cid=<?=$cid?>'> 修改</a>
                            <?
					 }
					 ?>
                          </span></td>
                          <td width="30" align="right"><img src="<?=$BBSFolder?>/images/bokefav.gif" width="28" height="18"></td>
                          <td width="60" align="center">主题</td>
                        </tr>
                      </table></td>
                    </tr>
                    <tr>
                      <td class="font1" style="padding-top:10px; padding-left:5px; ">
					  <font style="font-weight:bold; "><?=$row[title]?></font><br>
					  <?
					  if(!empty($row[pic])) echo "附件:<a target='_blank' href='../upload/bbs/".$row[id].$row[pic]."'>".$row[id].$row[pic]."</a><br>";
					  ?>
					  <?=$row[content]?></td>
                    </tr>
                  </table></td>
                </tr>
				<?
				$k=1;//楼数
				while($object=$db->fetch_object($query))
				{

					$user_pic=$SETUPFOLDER."/upload/manager_users/default.jpg";
					if((int)$row['upload_type']==1)
						$user_pic=$SETUPFOLDER."/upload/manager_users/".$object->photo; 
					if((int)$row['upload_type']==2)
						$user_pic=$object->embed_photo; 
				
				?>
                <tr>
                  <td width="195" height="275" align="center" valign="top" class="lefttd" ><table width="80%"  border="0" cellpadding="0" cellspacing="0" class="font1">
                    <tr>
                      <td height="40">用户：<?=$object->username?></td>
                    </tr>
                    <tr>
                      <td height="20"><img  src="<?=$user_pic?>"  width="<?=$config_row['user_thumbnail_width']?>" height="<?=$config_row['user_thumbnail_height']?>"    border="0" ></td>
                    </tr>
                    <tr>
                      <td height="20"> 发帖数： <?=$object->article_count?></td>
                    </tr>
                    <tr>
                      <td height="20"> 注册日期： <?=$object->regtime?></td>
                    </tr>
                  </table></td>
                  <td align="center" valign="top" class="righttd"><table width="94%"  border="0" cellspacing="0" cellpadding="0">
                    <tr>
                      <td height="40" class="line"><table width="100%"  border="0" cellpadding="0" cellspacing="0" class="font1">
                        <tr>
                          <td><span class="link3" style="padding-left:10px;">
                            <?
					 if(isLogin()&&$_SESSION['SessionUser']['username']==$row[username])
					{
					 ?>
                            <img src="<?=$BBSFolder?>/images/dbcindex.gif" width="16" height="13" class="link3"><a href='<?=$BBSFolder?>/answeredit.php?bcatid=<?=$bcatid?>&scatid=<?=$scatid?>&cid=<?=$cid?>&aid=<?=$object->id?>'> 修改</a>
                            <?
					 }
					 ?>
                          </span></td>
                          <td width="30" align="right"><img src="<?=$BBSFolder?>/images/bokefav.gif" width="28" height="18"></td>
                          <td width="60" align="center"><?=$k*$page_start?></td>
                        </tr>
                      </table></td>
                    </tr>
                    <tr>
                      <td class="font1"  style="padding-top:10px; padding-left:5px; "><?=$object->content?></td>
                    </tr>
                  </table></td>
                </tr>
				<?
				$k++;
				}
				?>
              </table></td>
      	  </tr>
        	<tr> 
       		  <td height="50" align="right" ><table width="400"  class="tabb1" border="0" cellspacing="0" cellpadding="0">
                <tr>
                  <td height="30" align="center"><table width="99%" style="font-size:12px; "  border="0" cellspacing="1" cellpadding="0">
                    <tr>
                      <td width="60" height="24" align="center" class="tabb2"><?=$rows[num]?></td>
                      <td width="60" align="center" class="tabb2"><?=$pagenum?></td>
                      <td width="80" align="center" class="tabb2"><?=$page_start."/".$page_num?>页</td>
					  <?
					  if($page>1)
					  {
					  ?>
                      <td width="20" align="center" bgcolor="#F7F7F7"><a href="javascript:first()"><img src="<?=$BBSFolder?>/images/First.gif" width="9" height="8" border="0"></a></td>
					 
                      <td width="20" align="center" bgcolor="#F7F7F7"><a href="javascript:pre()"><img src="<?=$BBSFolder?>/images/Previous.gif" width="8" height="8" border="0"></a></td>
					   <?
					  }
					  ?>
                      <?
					  for($i=(($page-1)*$bpage)+1;$i<=$page_end;$i++)
					  {
					  	if((int)$page_start==$i)
					  		echo "<td align=\"center\" bgcolor=\"#F7F7F7\" class='link2' style=\"padding-left:4px; padding-right:4px; \"><a href='javascript:currentpage(".$i.")'><b>".$i."</b></a></td>";
						else
							echo "<td align=\"center\" bgcolor=\"#F7F7F7\" class='link2'  style=\"padding-left:4px; padding-right:4px; \"><a href='javascript:currentpage(".$i.")'>".$i."</a></td>";
					  }
					  ?>
					  <?
					  if($page<$totalpage)
					  {
					  ?>
                      <td width="20" align="center" bgcolor="#F7F7F7"><a href="javascript:next()"><img src="<?=$BBSFolder?>/images/Next.gif" width="8" height="8" border="0"></a></td>
                      <td width="20" align="center" bgcolor="#F7F7F7"><a href="javascript:last()"><img src="<?=$BBSFolder?>/images/Last.gif" width="9" height="8" border="0"></a></td>
					  <?
					  }
					  ?>
                      <td width="20" align="center"><input name="position" type="text" id="position" size="3" value="<?=$page_start?>"></td>
                      <td width="10" align="center"><input type="button" name="Button" value="GO" onClick="goposition()"></td>
                    </tr>
                  </table></td>
                </tr>
              </table>
			  </td>
          </tr>
		  <?
		 if(isLogin())
		 {
		 ?>
            <tr>
              <td id="an" align="center"><table width="100%" style="font-size:12px;" border="0" cellspacing="0" cellpadding="0">
				<tr align="center" class="bar" style="font-size:12px; font-weight:bold;color:#FFF2B1; ">
                  <td height="28" >&nbsp;</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 align="center" valign="top" class="righttd">
				
				
					<textarea name="content" cols="70" rows="10" id="content"></textarea>
					
				
				  </td>
                </tr>
				<tr>
                  <td align="center" valign="top" class="righttd"><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();?>
