<? require "../../admin_header.php"?>
<?
/**
 * @version		1.0
 * @package		HonoWeb->HonoBBS
 * @copyright	Copyright (C) HonoWeb. All rights reserved.
 * @Website		www.honoweb.com.
 */
 ?>
<?
	//delete
	if($status=="remove")
	{
		//check sub category
		$sql="select count(*) as num from ".$TableBbs_category."  where pid=".$id;
	    $row=$db->getRow($sql);
		$b=false;
		if(!empty($row[num]))
		{
			echo "<meta http-equiv='Content-Type' content='text/html; charset=utf-8'>";
			echo "<script language='javascript'>alert('存在下级论坛分类名称,请先删除论坛分类名称');</script>";
			$b=true;
		}
		//check articles
		if(!$b){
			$sql="select count(*) as num from ".$TableBbs_content."  where categoryid=".$id;
	    	$row=$db->getRow($sql);
			if(!empty($row[num]))
			{
				echo "<meta http-equiv='Content-Type' content='text/html; charset=utf-8'>";
				echo "<script language='javascript'>alert('存在主题文章,请先删除主题文章');</script>";
				$b=true;
			}
		}
		if(!$b){
	    	$sql="delete from ".$TableBbs_category."  where id=".$id;
	    	$query=$db->query($sql);
		}
	}
	//删除全部选择的
	/*if($status=="removeSelect")
	{
	  $checkednums=array();
	  $checkednums=explode('.',$ids);
	  $filter="";
	  for($i=0;$i<count($checkednums)-2;$i++)
	  {
	     	$filter=$filter.$checkednums[$i].",";
	  }
	  $filter=$filter.$checkednums[count($checkednums)-2].")";
	  $sql="delete from ".$TableBbs_category."  where id in (".$filter." or pid in(".$filter;
	  $query=$db->query($sql);
	}*/
	
	//修改排序号
	if($status=="statusSortid")
	{
		$id=$_POST['id'];
		$sql="update ".$TableBbs_category." set sortid=".$_POST['sortid_'.$id]."  where id=".$id;
	    $db->query($sql);
	}
	
	
	if($status=="show")
	{
	  $checkednums=array();
	  $checkednums=explode('.',$ids);
	  $filter="";
	  for($i=0;$i<count($checkednums)-2;$i++)
	  {
	     	$filter=$filter.$checkednums[$i].",";
	  }
	  $filter=$filter.$checkednums[count($checkednums)-2].")";
	  $sql="update  ".$TableBbs_category." set is_show=1  where id in (".$filter;
	  $query=$db->query($sql);
	}

	if($status=="unshow")
	{
	  $checkednums=array();
	  $checkednums=explode('.',$ids);
	  $filter="";
	  for($i=0;$i<count($checkednums)-2;$i++)
	  {
	     	$filter=$filter.$checkednums[$i].",";
	  }
	  $filter=$filter.$checkednums[count($checkednums)-2].")";
	  $sql="update  ".$TableBbs_category." set is_show=2   where id in (".$filter;
	  $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>
<body>
<form name="form1" method="post" >
  <table border="0" cellpadding="0"  cellspacing="0" class="firsttable">
    <tr>
      <td align="center" valign="top">
	  	<table   class="centertable">
      		<tr> 
            	<td>&nbsp; 
            	</td>
       		</tr>
        	<tr> 
       		  <td align="center" valign="top">
				  <table class="containContentsTable">
              			<tr>
               				 <td ><input name="button2" type='button'  class='button' onClick="javascript:add()" value='添加'>
               				   <input name="button" type='button'  class='button' onClick="javascript:show()" value='显示'>
                               <input name="button" type='button'  class='button' style='width:80px' onClick="javascript:unshow()" value='隐藏' ></td>
               				 <td align="right" >&nbsp; </td>
              			</tr>
              			<tr>
               				 <td colspan="2">
								<?
									$sql="select * from ".$TableBbs_category." where pid=0 order by sortid" ;
									$query=$db->query($sql);
									$sql1="select * from ".$TableBbs_category." where pid<>0 order by pid,sortid" ;
									$result=$db->getAll($sql1);
		        					echo "<table  class='contentsTable'  border='0'  cellpadding='0'  cellspacing='1' >";
									echo "<tr class='tr1' align=center ><td width=10% ></td><td width=30% >论坛分类名称</td><td width=15%  >图标</td><td width=10% >排序号</td><td  width=15%>版主</td><td  width=10%>显示</td>";
									echo "<td width=10% >&nbsp;</td>";
								echo "</tr>";
									while($object=$db->fetch_object($query))
									{
				  						echo "<tr   onMouseOver=\"old_bg=this.getAttribute('bgcolor');this.setAttribute('bgcolor', '".$T_Bgcolor[1]."', 0);\" onMouseOut=\"this.setAttribute('bgcolor', old_bg, 0);\" bgColor='".$T_Bgcolor[2]."' >";
										echo "<td><input type='checkbox' name=checkvalue value='$object->id'></td>";
				  						echo "<td>$object->name</td>";
										//echo "<td></td>";
										echo "<td></td>";
										echo "<td align='center' ><input  style='width:40px; text-align:center;'  type='text' name='sortid_".$object->id."'  id='sortid_".$object->id."' value='".$object->sortid."'><a href='javascript:editSortid(".$object->id.")'>修改</a></td>";
										echo "<td></td>";
										echo "<td  align='center' >".$T_Is_YesNO[$object->is_show]."</td>";
											echo "<td align=center>";
												echo "<a   href='javascript:remove(".$object->id.")'>删除</a>";
												echo " <a href='javascript:edit(".$object->id.")'>修改</a>";
											echo "</td>";
										echo "</tr>";											
										for($i=0;$i<count($result);$i++)
										{
										    if($object->id==$result[$i][pid])
											{
												echo "<tr   onMouseOver=\"old_bg=this.getAttribute('bgcolor');this.setAttribute('bgcolor', '".$T_Bgcolor[1]."', 0);\" onMouseOut=\"this.setAttribute('bgcolor', old_bg, 0);\" bgColor='".$T_Bgcolor[2]."' >";
												echo "<td align='right'><input type='checkbox' name=checkvalue value='".$result[$i][id]."'></td>";
				  								echo "<td>".$result[$i][name]."</td>";
												//echo "<td >".$result[$i][description]."</td>";
												$pic="default.gif";
												if(!empty($result[$i][picture]))
													$pic=$result[$i][id].$result[$i][picture];
												echo "<td  align=center ><img src='../../upload/bbs/category/".$pic."' border=0 width=80 height=50></td>";
												echo "<td  align='center' ><input style='width:40px;text-align:center;' type='text' name='sortid_".$result[$i][id]."'  id='sortid_".$result[$i][id]."' value='".$result[$i]['sortid']."'><a href='javascript:editSortid(".$result[$i][id].")'>修改</a></td>";
												echo "<td align=center>";
														$admin_user=explode(",",$result[$i]["admin_user"]);
														echo "<select style='width:80px;'>";
														for($j=0;$j<count($admin_user);$j++)
														{
															echo "<option value='".$admin_user[$j]."'>".$admin_user[$j]."</option>";
														}
														echo "</select>";
												echo "</td>";
												echo "<td  align='center' >".$T_Is_YesNO[$result[$i]['is_show']]."</td>";
													echo "<td align=center>";
														echo "<a   href='javascript:remove(".$result[$i][id].")'>删除</a>";
														echo " <a href='javascript:edit(".$result[$i][id].")'>修改</a><br>";
														echo " <a href='javascript:config(".$result[$i][id].")'>分配版主</a>";
													echo "</td>";
												echo "</tr>";											
											}
										}
									}
				 					echo "</table>";
			 					?>
                			        </td>
              			</tr>
              			<tr>
						<td>						    <input name="button2" type='button'  class='button' onClick="javascript:add()" value='添加'>
						  <input name="button22" type='button'  class='button' onClick="javascript:show()" value='显示'>
                          <input name="button23" type='button'  class='button' style='width:80px' onClick="javascript:unshow()" value='隐藏' ></td>
       			          <td align="right">&nbsp;						</td>
              			</tr>
                        </table>
                        </td>
                        </tr>
                        <tr>
                             <td></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=<?=$page_num?>>
   <input type="hidden" name="id" value="">
   <input type="hidden" name="ids" value="">
</form>
</body>
</html>
<script language="JavaScript" type="text/JavaScript">
 function checkBoxAll()//全选
 {
    	var form = form1;
     for(i=0; i<form.elements.length; i++)
    	{
        	if(form.elements[i].type=="checkbox" &&  form.elements[i].name=="checkvalue")
        	{
                	form.elements[i].checked = form.cboAll.checked;
       	}
    	}
  }
  
  function config(id){
     var form=form1;
	location="config_user.php?id="+id;
  }

 function edit(id){
     var form=form1;
     form.id.value=id;
	form.action="bbs_categoryedit.php";
	form.submit();
  }

  function look(id){
     var form=form1;
     form.id.value=id;
	form.action="bbs_categorylook.php";
	form.submit();
  }

  function remove(id){
     if(confirm("真的想要删除吗?")==true){
  		var form=form1;
  		form.id.value=id;
		form.status.value="remove";
		form.submit();
	}
  }

  function removeSelect(){
  	var form=form1;
  	
  	for(i=0; i<form.elements.length; i++)
    {
        if(form.elements[i].type=="checkbox" &&  form.elements[i].name=="checkvalue")
        {
                if(form.elements[i].checked==true)
		   {
			form.ids.value+=form.elements[i].value+".";
		   }
        }
    }
	if(form.ids.value=="")
    {
		alert("请选择要删除的记录");
		return;
	}
	if(confirm("是否要删除选择的记录")==false)
		return;
	form.status.value="removeSelect";
	form.submit();
  }

  function add(){
  	location="bbs_categoryadd.php";
  }
  
    function editSortid(id){
  		var form=form1;
  		form.id.value=id;
		obj_sortid=document.getElementById("sortid_"+id);
		if(!isIntegerPlus(obj_sortid.value))
		{
			alert("排序号必须为整数!");
			obj_sortid.focus();
			return;
		}
		form.status.value="statusSortid";
		form.submit();
  }

  function show(){
  	var form=form1;
  	
  	for(i=0; i<form.elements.length; i++)
    {
        if(form.elements[i].type=="checkbox" &&  form.elements[i].name=="checkvalue")
        {
                if(form.elements[i].checked==true)
		   {
			form.ids.value+=form.elements[i].value+".";
		   }
        }
    }
	if(form.ids.value=="")
    {
		alert("请选择记录!");
		return;
	}
	form.status.value="show";
	form.submit();
  }
  
   function unshow(){
  	var form=form1;
  	
  	for(i=0; i<form.elements.length; i++)
    {
        if(form.elements[i].type=="checkbox" &&  form.elements[i].name=="checkvalue")
        {
                if(form.elements[i].checked==true)
		   {
			form.ids.value+=form.elements[i].value+".";
		   }
        }
    }
	if(form.ids.value=="")
    {
		alert("请选择记录");
		return;
	}
	form.status.value="unshow";
	form.submit();
  }


  function query()
  {
  	   var form=form1;
       form.submit();
  }

  function first()
  {
       var form=form1;
       if(eval(form.page.value)==1)
	   	return;
       form.page.value=1;
       form.submit();
  }

  function next()
  {
      var form=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=form1;
       if(eval(form.page.value)==eval(form.totalpage.value))
	   	  return;
       form.page.value=eval(form.totalpage.value);
       form.submit();
  }

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

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

