<?php
/**
 * @version        Somao_Search X1.0 9:23 2012-1-1 Somao $
 * @package        Somao_Search.Site
 * @copyright      Copyright (c) 2009 - 2012, Somao, Inc.
 * @license        http://www.somao123.com/
 * @link           http://www.somao.cc/
**/
require "global.php";
CheckPurview('s_url',$authoritys,$rank);

$action=HtmlReplace(trim($_GET["action"]));
$submit_id=intval($_GET["submit_id"]);
?>
<!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=gbk">
<meta http-equiv="x-ua-compatible" content="ie=7" />
<link href="css/admincp.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div class="container">
  <div class="floattop">
    <div class="itemtitle"><h3>提交网站</h3>
      <ul class="tab1">
        <li class="current"><a href="url_submit.php"><span>站点列表</span></a></li>
        <li><a href="?action=modify"><span>添加网站</span></a></li>
        <li><a onclick="if(!confirm('确认删除码?')) return false;" href="?action=dell_all_submit"><span>删除所有提交网站</span></a></li>
      </ul>
     </div>
   </div>
 <div class="floattopempty"></div>
<table class="tb tb2 " id="tips">
<tr><th  class="partition">提示</th></tr>
<tr><td class="tipsblock" s="1"><ul id="tipslis"><li>网页提交网站管理。</li></ul></td></tr>
</table>

<?php
switch ($action)
{
    case "saveform":
    saveform();
    break;

    case "addform":
	addform($action);
	break;
	
	case "modify":
	addform($action);
	break;
	
	case "dell_all_submit":
	      $db->query("delete from ve123_url_submit");
		  jsalert("清空成功");
	break;
	
	case "del":
		 $db->query("delete from ve123_url_submit where submit_id='".$submit_id."'");
		 jsalert("删除成功");
	break;
}
if($action=="checeken")
{
	$submiturl=$db->get_one("select * from ve123_url_submit where submit_id='$submit_id'");
	$url= GetSiteUrl(HtmlReplace(trim($submiturl['url'])));
	$site=$db->get_one("select * from ve123_sites where url='$url'");
	if(empty($site)){
	       $array=array('url'=>$url,'spider_depth'=>$config["spider_depth"],'indexdate'=>time(),'addtime'=>time());
		   $db->insert("ve123_sites",$array);
		   $row=$db->get_one("select * from ve123_links where url='".$url."'");
		   if(empty($row)){
					 AddAndUpdateUrl($url,"add");
  				     
		   }else{
					 AddAndUpdateUrl($url,"update");
		  }
	 $db->query("delete from ve123_url_submit where submit_id='".$submit_id."'");
	 jsalert("收录成功");
	}
}
?>
<?php
function addform($do_action){
global $db;
  if ($do_action=="modify")
  {
      $submit_id=$_GET["submit_id"];
	  $sql="select * from ve123_url_submit where submit_id='$submit_id'";
	  $rs=$db->get_one($sql);
	  $url=$rs["url"];
	  $ip=$rs["ip"];
	  $btn_txt="确定修改";
  }
  else
  {
     $btn_txt="确定提交";
  }
?>

<table class="tb tb2 ">
<form id="form1" name="form1" method="post" action="?action=saveform">
  <tr>
    <td width="100">链接地址:</td>
    <td><input name="url" type="text" value="<?php echo $url?>" /></td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td>
	<input type="hidden" name="submit_id" value="<?php echo $submit_id?>">
	<input type="hidden" name="do_action" value="<?php echo $do_action?>">
	<input type="submit" name="Submit" value="<?php echo $btn_txt?>" />	</td>
  </tr>
  </form>
</table>
<?php
}
?>
<table class="tb tb2 ">
  <tr class="header">
    <th></th>
    <th>网址</th>
    <th>网址</th>
    <th>提交时间</th>
    <th>IP</th>
    <th>操作</th>
  </tr>
<?php
  $sql="select * from ve123_url_submit";
  $result=$db->query($sql);
  $total=$db->num_rows($result);//记录总数
  $pagesize=30;//每页显示数
  $totalpage=ceil($total/$pagesize);
  $page=intval($_GET["page"]);
  if($page<=0){$page=1;}
  $offset=($page-1)*$pagesize;
  $result=$db->query($sql." order by submit_id desc limit $offset,$pagesize");
  while ($rs=$db->fetch_array($result))
  {
  ?>
  <tr>
    <td height="30" align="center"><?php echo $rs["submit_id"]?></td>
    <td height="30"><?php echo "<a href=\"".$rs["url"]."\" target=\"_blank\">".$rs["url"]."</a>";?></td>
    <td height="30"><?php echo date("Y-m-d H:i:s",$rs["addtime"]);?></td>
    <td height="30"><?php echo $rs["ip"];?></td>
    <td >
    <a href="?action=checeken&submit_id=<?php echo $rs["submit_id"]?>">收录</a>
    <a href="?action=modify&submit_id=<?php echo $rs["submit_id"]?>">修改</a>
	<a href="?action=del&submit_id=<?php echo $rs["submit_id"];?>" onclick="if(!confirm('确认删除码?')) return false;">删除</a></td>
  </tr>
  <?php
  }
  ?>
 <tr><td colspan="15"><?php echo pageshow($page,$totalpage,$total,"?");?></td></tr>
</table>

<?php
function saveform()
{
global $db;
   $url=trim(HtmlReplace($_POST["url"]));
   $submit_id=$_POST["submit_id"];
   $do_action=$_POST["do_action"];
   if($do_action=="modify")
   {
     $array=array('url'=>$url);
	 $db->update("ve123_url_submit",$array,"submit_id='$submit_id'");
	 jsalert("修改成功");
   }
   else
   {
	$url= GetSiteUrl(HtmlReplace(trim($url)));
	$site=$db->get_one("select * from ve123_sites where url='$url'");
	if(empty($site)){
	       $array=array('url'=>$url,'spider_depth'=>$config["spider_depth"],'indexdate'=>time(),'addtime'=>time());
		   $db->insert("ve123_sites",$array);
		   $row=$db->get_one("select * from ve123_links where url='".$url."'");
		   if(empty($row)){
					 AddAndUpdateUrl($url,"add");
  				     
		   }else{
					 AddAndUpdateUrl($url,"update");
		  }
	   jsalert("收录成功");
	 }else{
	   jsalert("该网站已经收录");	 
	 }
   }
}
?>
</div>
</body>
</html>