<?php include 'yanzheng.php';?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>管理中心</title>
<link rel="stylesheet" type="text/css" href="css/css.css" />

<script language="javascript" type="text/javascript">
function preg_match(regStr, str)
{
     var objRegExp = new RegExp(regStr);
     return objRegExp.test(str);
}
function SelectAll(form)
{
for(var j = 0;j < form.elements.length;j++)
     {
         var e = form.elements[j];
         if(preg_match(/del_id/, e.name))
         {
             e.checked = form.select_all.checked;
         }
         else
         {
             continue;
         }
     }
}
</script>
</head>

<body>

<?php require_once 'head.php';?>

<div class="box">
    

	<div class="right">
	  		 
		<table width="100%" height="30" border="0" cellpadding="10" cellspacing="0" class="bodernav">
		  <tr>
			<td width="122" style="padding-left:10px;">友情链接</td>  
		  </tr>
		</table>
	<form action="" method="post">
	 <table width="783" >
		 
		  <tr>
			<td width="96" height="30">链接名称</td>
			<td width="675"><input name="title" type="text"  /></td>			
		  </tr>
		   <tr>
			<td width="96" height="30">网站url</td>
			<td width="675"><input name="url" type="text" value="http://"  /></td>			
		  </tr>
		    <tr>
			<td width="96" height="30"></td>		
			<td width="675"><input name="submitadd" type="submit" class="reganniu"  value="添加" /></td>
		  </tr>		 
	  </table>
	 </form>
	 <!--上面是插入分类--> 
	 	<form name="del_form" action="" method="post"> 
	
	<table width="1161"  border="0" cellpadding="0" cellspacing="0"   class="borer" style=" margin-top:10px; margin-bottom:10px;">
	  <tr style="background-color:#EEEEEE;">
		<td width="67" height="31" class="tdtop">选择</td>
		<td width="150" class="tdtop">链接名称</td>
	
		<td width="659" class="tdtop">网站URL</td>
		
	  </tr>

	<!--list start-->	


<?php 
			require_once('page.class.php'); //分页类
			$showrow = 10; //一页显示的行数
			$curpage = empty($_GET['page']) ? 1 : $_GET['page']; //当前的页,还应该处理非数字的情况
			$url = "?page={page}"; //分页地址，如果有检索条件 ="?page={page}&q=".$_GET['q']
			//省略了链接mysql的代码，测试时自行添加
			$sql = "SELECT * FROM link ";
			$total = mysql_num_rows(mysql_query($sql)); //记录总条数
			if (!empty($_GET['page']) && $total != 0 && $curpage > ceil($total / $showrow))
				$curpage = ceil($total_rows / $showrow); //当前页数大于最后页数，取最后一页
			//获取数据
			$sql .= " order by id desc LIMIT " . ($curpage - 1) * $showrow . ",$showrow;";
		//	$query = mysql_query($sql);
			$arr=listquery($sql);

		
			foreach ($arr as $v){?>
	  <tr>
		<td width="67" class="td"><input name="del_id[]" type="checkbox" id="del_id[]" value="<?=$v['id']?>" /><input name="goodid[]" type="text"  value="<?=$v['id']?>" style="display:none;" /></td>
		<td width="149" class="td"><input name="title<?=$v[id]?>" id="title<?=$v[id]?>" type="text" style="width:140px; text-align:center;" value="<?=$v[title]?>" /></td>		
		<td width="659" class="td"><input name="url<?=$v[id]?>" id="url<?=$v[id]?>" type="text" style="width:240px; text-align:center;" value="<?=$v[url]?>" /></td>
		
	  </tr>
   
	<?php }?>
 </table>
 
 <table width="433" height="28" border="0" cellpadding="0" cellspacing="0" class="table">
	  <tr>
	    <td width="49">全选</td>
		<td width="49"><input id="select_all" name="select_all" type="checkbox" value="1" onClick="SelectAll(this.form)"/></td>
		<td width="130"><input name="submitup" type="submit" value="批量修改" class="reganniu" /></td>
		<td width="116" style="margin-left:10px;"><input name="submitdel" type="submit" value="批量删除" class="reganniu" /></td>
		<td width="88"></td>
	  </tr>
	</table>
 
    <?php
                   
                        $page = new page($total, $showrow, $curpage, $url, 2);
                        echo $page->myde_write();
                
                    ?>
	
	 <!--list end-->
	 </form>



<?php



if($_POST['submitadd']){
	$title=$_POST['title'];
	$url=$_POST['url'];

	 mysql_query("insert into link (title,url) values ('$title','$url')");
	 msg('添加成功',$onurl);
	

}
?>
<!--添加链接-->


<?php
if($_POST['submitup']){



$del_id=$_POST['del_id']; //数组 影藏的ID 用它来遍历所有input文本框对应数组内容

     if($del_id!=""){ 
             $del_num=count($del_id); 
             for($i=0;$i<$del_num;$i++){ 
			 
                 $title=$_POST['title'.$del_id[$i]];
				 $url=$_POST['url'.$del_id[$i]];		
			
                 mysql_query("update link set title='$title',url='$url' where id='$del_id[$i]'"); 				
             }  
            msg('修改成功',$onurl);
      }else{ 
            msg('请选择',$onurl);
      }

  }
?>  

<!--批量修改-->




  <?php
if($_POST['submitdel']){

$del_id=$_POST['del_id'];
     if($del_id!=""){ 
             $del_num=count($del_id); 
             for($i=0;$i<$del_num;$i++){ 
                 mysql_query("Delete from link where id='$del_id[$i]'"); 				
             }  
            msg('删除成功',$onurl);
      }else{ 
            msg('请选择',$onurl);
      }

  }
?>  

<!--批量删除-->
		
	
	</div>
</div>

<?php require_once 'foot.php';?>
</body>
</html>