<?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('union_web',$authoritys,$rank);
$action=$_REQUEST["action"];
$id=$_REQUEST["id"];
if($action=="ok"){
     $array=array('arcrank'=>1,'dtime'=>time());
	 $db->update("ve123_webunion",$array,"id='$id'");
	 jsalert("审核成功");
	 header("location:union.php");
}
if($action=="no"){
     $array=array('arcrank'=>-1,'dtime'=>time());
	 $db->update("ve123_webunion",$array,"id='$id'");
	 jsalert("审核失败");
	 header("location:union.php");
}
if($action=="save"){
	 $mid=$_POST["mid"];
	 $webname=trim(HtmlReplace($_POST["webname"]));
	 $webbody=trim(HtmlReplace($_POST["webbody"]));
	 $webtype=trim(HtmlReplace($_POST["webtype"]));
	 $arcrank=trim(HtmlReplace($_POST["arcrank"]));
     $array=array('mid'=>$mid,'arcrank'=>$arcrank,'webname'=>$webname,'webbody'=>$webbody,'webtype'=>$webtype,'dtime'=>time());
	 $db->update("ve123_webunion",$array,"id='$id'");
	 jsalert("修改成功");
	 header("location:union.php");
}


if($action=="addurl"){
	 $url=trim($_GET["url"]);
	 $url= GetSiteUrl($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("收录成功");
		   header("location:union.php");
	 }else{
		   jsalert ("该网站未收录，请不要重复操作!");
           exit();
	 }
}

if($action=="delurl"){
	 $url=trim(GetSiteUrl($_GET["url"]));
     $row2 = $db->get_one("select * from ve123_sites where url like '%".$url."%' ");
	 if(!is_array($row2))
	 {
	   jsalert ("该网站未收录，请不要重复操作!");
       exit();
	 }
	 $db->query("DELETE FROM ve123_sites WHERE url like '%".$url."%'");
	 $db->query("DELETE FROM ve123_links WHERE url like '%".$url."%'");
	 $db->query("DELETE FROM ve123_links_temp WHERE url like '%".$url."%'");
	 $db->query("DELETE FROM ve123_sites_temp WHERE url like '%".$url."%'");
	 jsalert("收录删除成功");
	 header("location:union.php");
}

if($action=="del"){
	 $db->query("DELETE FROM ve123_webunion WHERE id=$id");
	 $db->query("DELETE FROM ve123_webunion_log WHERE urlid=".$id."");
	 jsalert ("成功删除指定的记录!");
	 exit(); 
}
if($action=="dellog"){
	 $db->query("DELETE FROM ve123_webunion_log where YEAR(FROM_UNIXTIME(c_time)) <> YEAR(NOW())");
	 jsalert ("成功删除非当年IP记录!");
	 exit(); 
}
$dopost=$_GET["dopost"];
$aids=$_GET["aids"];
if($dopost=="delete"){
    $ids = explode(',',$aids);
    foreach($ids as $id){
		$db->query("DELETE FROM ve123_webunion WHERE id=".$id."");
		$db->query("DELETE FROM ve123_webunion_log WHERE urlid=".$id."");
    }
	jsalert ("成功删除指定的记录!");
}

function shoulucheck($url)
{
    global $db;
	 $row2 = $db->get_one("select * from ve123_sites where url like '%".$url."%' ");
	 if(is_array($row2))
	 {
	   return true;
	 }else{
	   return false; 
	}
} 
?>
<!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" />
<script language="javascript">
//获得选中项
function getCheckboxItem()
{
	var allSel="";
	if(document.form1.aids.value) return document.form1.aids.value;
	for(i=0;i<document.form1.aids.length;i++)
	{
		if(document.form1.aids[i].checked)
		{
			if(allSel=="")
				allSel=document.form1.aids[i].value;
			else
				allSel=allSel+","+document.form1.aids[i].value;
		}
	}
	return allSel;
}
function ReSel()
{
	for(i=0;i<document.form1.aids.length;i++)
	{
		if(document.form1.aids[i].checked) document.form1.aids[i].checked = false;
		else document.form1.aids[i].checked = true;
	}
}
function DelSel()
{
	var nid = getCheckboxItem();
	
	location.href="union.php?dopost=delete&aids="+nid;
}
</script>
</head>
<body>
<div class="container">
  <div class="floattop">
    <div class="itemtitle"><h3>联盟网站列表</h3>
      <ul class="tab1">
        <li <?php if($action=="" or $action=="search"){echo 'class="current"';}?>><a href="union.php"><span>网站列表</span></a></li>
      </ul>
     </div>
   </div>
 <div class="floattopempty"></div>
<table class="tb tb2 " id="tips">
<tr><th  class="partition" colspan="10">联盟流量统计</th></tr>
  <tr>
    <td valign="top">
       <table width="100%" border="0">
          <tr>
           <td>
                 贡献流量IP数（
                 今日：<?php 
				  $rows=$db->get_one("select count(*) as dd from ve123_webunion_log where type=1 and TO_DAYS(FROM_UNIXTIME(c_time))=TO_DAYS(NOW()) ");
				  echo $rows['dd'];
				  ?>
				  当月：<?php 
				  $rows=$db->get_one("select count(*) as dd from ve123_webunion_log where type=1 and  MONTH(FROM_UNIXTIME(c_time)) = MONTH(NOW())");
				  echo $rows['dd'];
				  ?>
                  当年：<?php 
				  $rows=$db->get_one("select count(*) as dd from ve123_webunion_log where type=1  and YEAR(FROM_UNIXTIME(c_time)) = YEAR(NOW()) ");
				  echo $rows['dd'];
				  ?>
                  ）
                  
                  得到流量IP数 （
                  今日：<?php 
				  $rows=$db->get_one("select count(*) as dd from ve123_webunion_log where type=2 and TO_DAYS(FROM_UNIXTIME(c_time))=TO_DAYS(NOW()) ");
				  echo $rows['dd'];
				  ?>
				  当月：<?php 
				  $rows=$db->get_one("select count(*) as dd from ve123_webunion_log where type=2 and  MONTH(FROM_UNIXTIME(c_time)) = MONTH(NOW())");
				  echo $rows['dd'];
				  ?>
                  当年：<?php 
				  $rows=$db->get_one("select count(*) as dd from ve123_webunion_log where type=2 and  YEAR(FROM_UNIXTIME(c_time)) = YEAR(NOW()) ");
				  echo $rows['dd'];
				  ?>
                  ）
                  <a href="union.php?action=dellog">清空非当年统计数据</a>
           </td>
           <td>
           <form id="form1" name="form1" method="get" action="">
            关键词:<input type="text" name="keywords" value="<?php echo $keywords;?>"/>
	               <input type="hidden" name="action" value="search" />
	              <input type="submit" name="Submit2" value="查找" />
              </form>
           </td>
          </tr>
       </table>
    </td>
  </tr>
</table>
<?php if($action=="" or $action=="search"){?>
<table class="tb tb2 ">
  <tr class="header">
    <th></th>
    <th style="text-align: center">ID</th>
    <th>站点名称</th>
    <th>站点域名</th>
    <th>站点类型</th>
    <th>贡献流量</th>
    <th>得到流量</th>
    <th>收录深度</th>
    <th>状态</th>
    <th>审核时间</th>
    <th>用户ID</th>
    <th>操作</th>
  </tr>
 <form name="form1" method="post">
  <?php
  $where=" where webname<>''";
  if($action=="search")
  { 
	$where.=" and CONCAT(webname,' ',weburl) like '%".$keywords."%'";

  }
  $sql="select * from ve123_webunion".$where;
  $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 id desc limit $offset,$pagesize");
  while($link=$db->fetch_array($result))
  {
  ?>
  <tr>
    <td  style="text-align: center"><input type='checkbox' name='aids' value='<?php echo $link["id"]?>' class='np'></td>
    <td height="30"><?php echo $link["id"];?></td>
    <td><a href="http://<?php echo $link["weburl"];?>" target="_blank"><?php echo $link["webname"];?></a></td>
    <td><a href="http://<?php echo $link["weburl"];?>" target="_blank"><?php echo $link["weburl"];?></a></td>
    <td><?php echo $link["webtype"];?></td>
    <td>今日：<?php echo countunion($link["id"],'day',1);?><br />总量：<?php echo countunion($link["id"],'',1);?></td>
    <td>今日：<?php echo countunion($link["id"],'day',2);?><br />总量：<?php echo countunion($link["id"],'',2);?></td>
    <td><?php echo countwebs($link["weburl"]);?></td>
    <td><?php if($link["arcrank"]>0){echo "已审核";}elseif($link["arcrank"]<0){echo "审核失败";}else{echo "未审核";};?></td>
    <td><?php echo MyDate('Y-m-d  H:i:s',$link["dtime"])?></td>
    <td><?php echo $link["mid"]?></td>
    <td>
      <?php if($link["arcrank"]>0){echo "<a href='?action=no&id=".$link["id"]."'>取消审核</a>";}elseif($link["arcrank"]<0){echo "<a href='?action=ok&id=".$link["id"]."'>审核</a>";}else{echo "<a href='?action=ok&id=".$link["id"]."'>审核中</a>";};?>  
      <a href="?action=edit&id=<?php echo $link["id"];?>">修改</a>
      
      <a href="?action=<?php if(shoulucheck($link["weburl"])){echo "delurl";}else{echo "addurl";}?>&url=<?php echo $link["weburl"];?>"><?php if(shoulucheck($link["weburl"])){echo "已收录";}else{echo "未收录";}?></a>
      
      <a href="?action=del&id=<?php echo $link["id"];?>">删除</a>
      </td>
  </tr>
  <?php
  }
  ?>
  </form>
   <tr>
    <td height="36" colspan="10" align="center" bgcolor="#F9FCEF">
<input type="button" class='np coolbg inputbut' name="b7" value="反选" style="width:40" onClick="ReSel();">
<input type="button" class='np coolbg inputbut' name="b7" value="删除" style="width:40" onClick="DelSel();">
<?php
echo pageshow($page,$totalpage,$total,"?keywords=".$keywords."&action=".$action."&");
?>
    </td>
  </tr>
</table>
<?php }if($action=="edit"){ 
     $id=$_REQUEST["id"];
     $row = $db->get_one("select * from ve123_webunion where id ='".$id."'");
	 if(!is_array($row))
	 {
	   jsalert ("该网站已审核验证过，请不要重复验证!");
       exit();
	 }

?>
<form name="ctl00" method="post" action="" id="ctl00">
<input type="hidden" name="action" value="save" />
<input type="hidden" name="id" value="<?php echo $row["id"];?>" />
<table class="tb tb2 ">
  <tr><th  class="partition" colspan="10">修改站点信息</th></tr>
  <tr>

      <tr>
        <td height="30"><div align="right">站点地址：</div></td>
        <td>http://<?php echo $row["weburl"];?></td>
      </tr>
	  
      <tr>
        <td height="30"><div align="right">站点名称：</div></td>
        <td>
            <input name="webname" type="text" id="webname" class="input" style="width:280px;"  value="<?php echo $row["webname"];?>"/> * (如 彩吧网) </td>
      </tr>
      <tr>
        <td height="30"><div align="right">站点介绍：</div></td>
        <td>
            <textarea name="webbody" rows="5" cols="20" id="webbody" class="input" style="width:280px;"><?php echo $row["webbody"];?></textarea> 
            * </td>
      </tr>
      <tr>
        <td height="30"><div align="right">站点类型：</div></td>
        <td><select name="webtype" id="webtype">
            <option value="<?php echo $row["webtype"];?>"><?php echo $row["webtype"];?></option>
			<option value="未分类">选择类型</option>
			<option value="综合网站">综合网站</option>
			<option value="论坛博客">论坛博客</option>
			<option value="网址大全">网址大全</option>
			<option value="游戏资讯">游戏资讯</option>
			<option value="视频电影">视频电影</option>
            <option value="其他类型">其他类型</option>
           </select></td>
      </tr>
      <tr>
        <td height="30"><div align="right">提交用户ID：</div></td>
        <td><input name="mid" type="text" id="mid" class="input" style="width:80px;"  value="<?php echo $row["mid"];?>"/>
		  </td>
      </tr>
      <tr>
        <td height="30"><div align="right">站点状态：</div></td>
        <td><select name="arcrank" id="arcrank">
            <option value="<?php echo $row["arcrank"];?>">
			   <?php if($row["arcrank"]>0){echo "已审核";}elseif($row["arcrank"]<0){echo "审核失败";}else{echo "未审核";};?>
            </option>
			<option value="0">未审核</option>
            <option value="1">已审核</option>
            <option value="-1">审核失败</option>
           </select>
      </tr>
      <tr>
        <td height="30">&nbsp;</td>
        <td>
            <input type="submit" name="Button1" value=" 确 定 " id="Button1" class="button"/></td>
      </tr>

</table>
</form>
<?php } ?>
</div>
</body>
</html>