<? require "../../admin_header.php"?>
<?
/**
 * @version		1.0
 * @package		HonoWeb->HonoBBS
 * @copyright	Copyright (C) HonoWeb. All rights reserved.
 * @Website		www.honoweb.com.
 */
 ?>
<?
	//删除
	$status=$_POST['status'];
	if($status=="remove")
	{
		$id=$_POST['id'];
		$sql=" select * from ".$TableBbs_link."  where id=".$id;
		$row=$db->getRow($sql);
		$FileName=$UploadPath."upload/bbs_link/".$row['picture'];
		if(file_exists($FileName)&&!empty($row['picture']))
		{
			 unlink($FileName);
		}
	    $sql="delete from ".$TableBbs_link."   where id=".$id;
	    $query=$db->query($sql);
	}
	//删除全部选择的
	if($status=="removeSelect")
	{
	  $checkednums=array();
	  $ids=$_POST['ids'];
	  $checkednums=explode('.',$ids);
	  $filter="";
	  for($i=0;$i<count($checkednums)-2;$i++)
	  {
	     	$filter=$filter.$checkednums[$i].",";
	  }
	  $filter=$filter.$checkednums[count($checkednums)-2].")";
	  $sql=" select * from ".$TableBbs_link."  where id in (".$filter;
	  $results=$db->getAll($sql);
	  for($i=0;$i<count($results);$i++)
	  {
	     	$FileName=$UploadPath."upload/bbs_link/".$results[$i]['picture'];
			if(file_exists($FileName)&&!empty($results[$i]['picture']))
			{ 
				 unlink($FileName);
			}
	  }
	  $sql="delete from  ".$TableBbs_link."  where id in (".$filter;
	  $query=$db->query($sql);
	}
	
	//审核
	if($status=="verify")
	{
	  $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_link." set is_verify=1  where id in (".$filter;
	  $query=$db->query($sql);
	}
	//不审核
	if($status=="unverify")
	{
	  $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_link." set is_verify=2   where id in (".$filter;
	  $query=$db->query($sql);
	}
	
	//修改排序号
	if($status=="statusSortid")
	{
		$id=$_POST['id'];
		$sql="update ".$TableBbs_link." set sortid=".$_POST['sortid_'.$id]."  where id=".$id;
	    $db->query($sql);
	}
	
	
	
	
			$page=$_POST['page'];
			if(empty($page))
				{$page=1;}
			else
			{
				 if($page<1){ $page=1;}
			}
             $b=false;
             $filter="";
             $booklet_type=$_POST['booklet_type'];
             $fvalue=$booklet_type;
             if(!empty($fvalue))
             {
                 if($b)
                     $filter.=" and";
                 $filter.=" booklet_type = ".$fvalue." ";
                 $b=true;
             }
             $booklet_name=$_POST['booklet_name'];
             $fvalue=$booklet_name;
             if(!empty($fvalue))
             {
                 if($b)
                     $filter.=" and";
                 $filter.=" booklet_name like '%".$fvalue."%' ";
                 $b=true;
             }
			   $is_verify=$_POST['is_verify'];
             $fvalue=$is_verify;
             if(!empty($fvalue))
             {
                 if($b)
                     $filter.=" and";
                 $filter.=" is_verify = ".$fvalue." ";
                 $b=true;
             }
	$sql="select * from  ".$TableBbs_link;
	$sql1="select count(*) as num from  ".$TableBbs_link;
	if($b)
	{
		$sql.=" where ".$filter."  order by sortid  limit ".(($page-1)*$pagenum).",$pagenum";
		$sql1.=" where ".$filter."  order by sortid  ";
	}
	else
	{
		$sql.="  order by sortid  limit ".(($page-1)*$pagenum).",$pagenum";
		$sql1.="   order by sortid ";
	}
	$result=$db->getAll($sql);
	$row=$db->getRow($sql1);
	$totalnum=$row['num'];
	$page_num=ceil($totalnum/$pagenum);
?>
<html>
<head>
<title><?=$TitleName?></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 align="right">
           				  <td colspan="2" >
链接类型:<select name="booklet_type" id="booklet_type">
	<option value=""></option>
	<?
		for($i=1;$i<=count($T_Booklet_type);$i++)
		{
			 if((int)$booklet_type==$i)
			 	echo "<option value=".$i." selected>".$T_Booklet_type[$i]."</option>";
			else
				echo "<option value=".$i.">".$T_Booklet_type[$i]."</option>";
		}
	?>
</select>
链接标题:<input type="text" size=10 name="booklet_name" value="<?=$booklet_name?>">
审核:
<select name="is_verify" id="select4">
  <option value=""></option>
  <?
		for($i=1;$i<=count($T_Is_YesNO);$i++)
		{
			 if((int)$is_verify==$i)
			 	echo "<option value=".$i." selected>".$T_Is_YesNO[$i]."</option>";
			else
				echo "<option value=".$i.">".$T_Is_YesNO[$i]."</option>";
		}
	?>
</select>
<input type='button'  class='button' onClick="javascript:query()" value='查询' ></td>
       				    </tr>
              			<tr>
               				 <td colspan="2">
								<?
								echo "<table  class='contentsTable' border='0'  cellpadding='0'  cellspacing='1'>";
								echo "<tr class='tr1'  align=center ><td width=5% ></td><td>链接类型</td><td>链接标题</td><td>链接地址</td><td >排序号</td><td>图片</td><td>审核</td>";
									echo "<td width=12% >&nbsp;</td>";
								echo "</tr>";
								for($i=0;$i<count($result);$i++)
								{
				  					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='".$result[$i]['id']."'></td>";
				  					for($j=1;$j<=count($T_Booklet_type);$j++)
				  					{
				  						if((int)$result[$i]['booklet_type']==$j)
				  						{
				  							echo "<td  align='center'>".$T_Booklet_type[$j]."</td>";
				  							break;
				  						}
				  					}
				  					echo "<td  align=center >".$result[$i]['booklet_name']."</td>";//链接标题
				  					echo "<td><a target='_blank' href='".$result[$i]['link_url']."'>".$result[$i]['link_url']."</a></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 ><a target='_blank' href='../../upload/bbs_link/".$result[$i]['picture']."'><img width='80' height='60'  src='../../upload/bbs_link/".$result[$i]['picture']."' border=0 ></a></td>";//图片
									
									echo "<td  align='center'>".$T_Is_YesNO[$result[$i]['is_verify']]."</td>";
									echo "<td align=center>";
										echo "<a   href='javascript:remove(".$result[$i]['id'].")'>删除</a>";
										echo " <a href='javascript:edit(".$result[$i]['id'].")'>修改</a>";
									echo "</td>";
									echo "</tr>";							
								}
				 				echo "</table>";
								?>
                			        </td>
              			</tr>
              			<tr>
						<td><input name="cboAll" type="checkbox" id="cboAll" value="checkbox" onClick="checkBoxAll()">
选择所有
  <input type='button'  class='button' onClick="javascript:add()" value='添加'>
  <input type='button'  class='button' onClick="javascript:removeSelect()"  value='删除' >
  <input name="button22" type='button'  class='button' onClick="javascript:verify()" value='审核'>
  <input name="button23" type='button'  class='button' style='width:80px' onClick="javascript:unverify()" value='不审核' ></td>
						<td align="right">共
                          <?=$totalnum?>
条, 共
<?=$page_num?>
页, 第
<?=$page?>
页 <a href="javascript:first()">第一页</a> <a href="javascript:next()">下一页</a> <a  href="javascript:pre()">上一页</a> <a  href="javascript:last()" >最后一页</a>
<select name="position" id="position"  onChange="goposition()">
  <option value=""></option>
  <?
					     			for($i=1;$i<=$page_num;$i++)
					     			{
						   			echo "<option ";
						   				if(page==$i){echo "selected";}
						   					echo " value=$i>";
						   					echo $i;
						   					echo "</option>" ;
					     			}
					     	?>
</select></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 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 verify(){
  	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="verify";
	form.submit();
  }
  
   function unverify(){
  	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="unverify";
	form.submit();
  }


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

	function look(id){
		var form=form1;
		form.id.value=id;
		form.action="bbs_linklook.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_linkadd.php";
	}

	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();?>
 

