<?php 
if(!defined('IN_GATEWEI')) {
	exit('access denied');
}
require_once GATEWEI_ROOT.'./engine/attachment.func.php';
require_once GATEWEI_ROOT.'./engine/post.func.php';
$pagerecords=50;
$curpage=isset($page)?$page:1;
$startrecord=($curpage-1)*$pagerecords;
$totalrecord = $db->result($db->query("select count(*) from g_threads where top = 0"),0);
$q = $db->query("select * from g_threads where top =0 order by ord desc limit $startrecord , $pagerecords");
$qurl="siteadmin.php?iframe=threadmanagement";
$topq = $db->query("select * from g_threads where top =1 order by ord desc limit 0 , 5");
$ctopq = $db->query("select count(*) from g_threads where top =1");

	if($ipost=='query'){
		if($action=='cid'){
			$textarray=explode(',',$qtxt);
			if($textarray[0]==0 && $textarray[1]==0){
				gadminmessage("请选择论坛分类");
			}
			$totalrecord = $db->result($db->query("select count(*) from g_threads where forid = $textarray[1]"),0);
			$q = $db->query("select * from g_threads where forid = $textarray[1] order by ord desc limit $startrecord , $pagerecords");
			$qurl="siteadmin.php?iframe=threadmanagement&ipost=query&action=cid&qtxt=".$qtxt;
		}elseif($action=="threadtitle"){
			if(empty($qtxt)){
				gadminmessage("查询关键字不能为空");
			}
			$totalrecord = $db->result($db->query("select count(*) from g_threads where title like '%$qtxt%'"),0);
		    $q = $db->query("select * from g_threads where title like '%$qtxt%' order by ord desc limit $startrecord , $pagerecords");
			$qurl="siteadmin.php?iframe=threadmanagement&ipost=query&action=title&qtxt=".$qtxt;
		}elseif($action=="useraccount"){
			if(empty($qtxt)){
				gadminmessage("查询关键字不能为空");
			}
			$totalrecord = $db->result($db->query("select count(*) from g_threads where useraccount = ('$qtxt')"),0);
		    $q = $db->query("select * from g_threads where useraccount = ('$qtxt') order by ord desc limit $startrecord , $pagerecords");
			$qurl="siteadmin.php?iframe=threadmanagement&ipost=query&action=userid&qtxt=".$qtxt;
		}elseif($action=="timeslice"){
			$date=explode(';',$qtxt);
			list($sy,$sm,$sd)=explode(',',$date[0]);
			list($ey,$em,$ed)=explode(',',$date[1]);
			$stime=mktime(0,0,0,$sm,$sd,$sy);
			$etime=mktime(23,59,59,$em,$ed,$ey);
			$totalrecord = $db->result($db->query("select count(*) from g_threads where subtime > $stime and subtime < $etime"),0);
		    $q = $db->query("select * from g_threads where subtime > $stime and subtime < $etime order by ord desc limit $startrecord , $pagerecords");
			$qurl="siteadmin.php?iframe=threadmanagement&ipost=query&action=timeslice&qtxt=".$qtxt;
		}
	}

	$multipage=multi($totalrecord, $pagerecords, $curpage, $qurl);


if($ipost=='setthread'){
	if(!$pervalue{17}){
		showmsg("该用户组无此权限");
	}
	if($action=='unsettop'){
		forumsetting($action,$top_thread_check);
	}elseif($action=='delete'){
		$thread_check = isset($thread_check)?$thread_check:array();
		$top_thread_check = isset($top_thread_check)?$top_thread_check:array();
		$merge_check=array_merge($thread_check,$top_thread_check);
		forumsetting($action,$merge_check);
	}else{
		forumsetting($action,$thread_check);
	}
}

?>
<script language=javascript src="./engine/js/calendar.js"></script>
<table>
<caption>论坛信息管理</caption>

	<form id="threadquery" method="post">
		<input type="hidden" id="qtxt" name="qtxt">
	</form>

<tr>
      <td width="20%"><span>主题标题关键字</span></td>
      <td width="80%"><input type="text" id="threadtitle" name="threadtitle" class="formtext">  <input type="button" value="查询" onclick="tquery('threadtitle')"></td>   </tr>
<tr>
      <td width="20%"><span>发帖人</span></td>
      <td width="80%"><input type="text" id="useraccount" name="useraccount" class="formtext">  <input type="button" value="查询" onclick="tquery('useraccount')"></td>
</tr>

 <tr>
    <td><span>所属分类</span></td>
    <td >
	  <select id="cid" name="cid" class="formselect">
		<option value="0,0" selected >主题根分类</option >
<?php echo $echoselectform;?>
      </select>
	    <input type="button" value="查询" onclick="tquery('cid')">
	</td>
  </tr>
      <tr>
    <td><span>主题发布时间段</span></td>
    <td >
	<div id="calendar_start" class="calendar"></div>
	<div class="calendarspace">至</div>
	<div id="calendar_end" class="calendar"></div>
	<div class="calendarquery"><input type="button" value="查询" onclick="tquery('timeslice')"></div>
	</td>
  </tr>
    	   <tr>
          <td colspan="5">
	         <div id="hr_u"> </div>
	         <div id="hr_d"> </div>
	      </td>
   </tr>
</table>


<table>
<form id="form_threadlist" method="post">
<?php if($db->result($ctopq,0)){?>
 <tr>
    <th colspan="3">置顶主题<img src="images/siteadmin/g_admin_top.gif"></th>
  </tr>
<tr>
<tr>
     <td width="5%" ><input type="checkbox" name="top_thread_check_all" id="top_thread_check_all" onclick="checkall_onclick('top_thread')"></td>
	    <td width="75%" >主题标题</td>
		<td width="15%" >发布时间</td>
  </tr>
  <?php
   $i=0;
	while($threads=$db->fetch_array($topq)){	?>
    <tr>
    <td ><input type="checkbox" id="top_thread_check_<?php echo $i?>" name="top_thread_check[]" value="<?php echo $threads['aid']?>"></td>
	<td ><?php echo $forumcategory[$threads['forid']]['forumtitle']?> | <a href="viewthread.php?tid=<?php echo $threads['tid']?>" target="_Blank"><?php echo $threads['title']?></a></td>
	<td ><?php echo gmdate('Y-n-j H:i',$threads['subtime']+3600*8) ?></td>
  </tr>
  <?php	
		$i++;
	  } ?>
<?php }?>
 <tr >
    <th colspan="3">主题列表(本次查询到 <font color="red"><?php echo $totalrecord?></font> 条记录)</th>
  </tr>
<tr>
     <td width="5%" ><input type="checkbox" name="thread_check_all" id="thread_check_all" onclick="checkall_onclick('thread')"></td>
	    <td width="75%" >主题标题</td>
		<td width="15%" >发布时间</td>
  </tr>
  <?php
   $i=0;
	while($thread=$db->fetch_array($q)){?>
    <tr>
    <td >
		<input type="checkbox" id="thread_check_<?php echo $i?>" name="thread_check[]" value="<?php echo $thread['tid']?>">
	</td>
<td ><?php echo $forumcategory[$thread['forid']]['forumtitle']?> | 
<a href="viewthread.php?tid=<?php echo $thread['tid']?>" target="_Blank">
				<?php echo height_light($thread['title'],$thread['hlight'],$forumcategory[$thread['forid']]['hlightway'])?></a>
</td>
	<td ><?php echo gmdate('Y-n-j H:i',$thread['subtime']+3600*8) ?></td>

  </tr>
  <?php	
		$i++;
	  } ?>

 <tr >
    <td colspan="4"> 
	<?php	
				if($multipage){
				echo '<div class="pages_btns font_14">'.$multipage.'</div>';
				}
			?></td>
  </tr>	  

   <tr>
          <td colspan="5">&nbsp;
	         <div id="hr_u"> </div>
	         <div id="hr_d"> </div>
 <div id="moveform" style="display:none;">
			<select id="move_select_cid" name="move_select_cid">
				<option value="0,0" selected >论坛根分类</option >
                   <?php echo $echoselectform?>
            </select>
	        <button onclick="asetting('siteadmin.php?iframe=threadmanagement&','move',0,0)"> 开始转移 </button> 
	</div>


	      </td>
   </tr>
   </form>
      <tr>
        <td colspan="5"> 
		<div id="toolbox">
	<button onclick="tsetting('siteadmin.php?iframe=threadmanagement&','settop',0,0)">主题置顶</button>
   <button onclick="tsetting('siteadmin.php?iframe=threadmanagement&','unsettop',0,0)"> 取消置顶</button>
	<button onclick="tsetting('siteadmin.php?iframe=threadmanagement&','priority',0,0)"> 主题优先</button>
	<button onclick="tsetting('siteadmin.php?iframe=threadmanagement&','unpriority',0,0)"> 取消优先</button>
	<button onclick="tsetting('siteadmin.php?iframe=threadmanagement&','sethlight',0,0)"> 高亮显示</button>
	<button onclick="tsetting('siteadmin.php?iframe=threadmanagement&','unsethlight',0,0)"> 取消高亮</button>
	<button onclick="tsetting('siteadmin.php?iframe=threadmanagement&','delete',0,0)"> 删除主题</button> 
	<button onclick='showmoveform()'> 转移论坛</button> 
	</div>
	      </td>
   </tr>
  
</table>

<script language="javascript">

	loadcalendar("_start");
	loadcalendar("_end");

</script>
