<?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_make',$authoritys,$rank);
//生成随机ip
function randomip($length){
  for ($a = 0; $a < $length; $a++) {
  $output .=mt_rand(33, 255)."."; //生成php随机数
  }
  return rtrim($output,".");
}
//生成随机MAC
function randomMac($length){
  $size = array('A','B','C','D','E','F','G','H','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','0','1','2','3','4','5','6','7','8','9'); 
  for ($a = 0; $a < $length; $a++) {
  $output .=$size[rand(0,count($size)-1)].$size[rand(0,count($size)-1)]."-"; //生成php随机数
  }
  return rtrim($output,"-");
}
if($_POST['action']=="saveinfo"){
    $user_name=HtmlReplace(trim($_POST["user_name"]));
    $muns=HtmlReplace(trim($_POST["muns"]));
    $time = time();
	
      $mids = array_unique(explode(",",$user_name));
	  foreach($mids as $value){
			  $rs=$db->get_one("select * from ve123_member where user_name='$value'");
		      $mid=$rs['user_id'];
			  $startid=0;
			  for(;$startid<$muns;$startid++)
              {
		       $c_ip =randomip(4);
		       $mac=randomMac(6);
		       $c_time=mt_rand($time-18000,$time+36000);
		       $array3=array('mid'=>$mid,'type'=>2,'mac'=>$mac,'c_ip'=>$c_ip,'c_time'=>$c_time);
		       $db->insert("ve123_webunion_log",$array3);  	
              }
	  }
    jsalert("添加成功"); 
}
$type=$_GET['type']
?>
<!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 <?php if($type==""){echo 'class="current"';}?>><a href="union_ips.php"><span>流量管理</span></a></li>
        <li <?php if($type=="1"){echo 'class="current"';}?>><a href="?type=1"><span>贡献流量</span></a></li>
        <li <?php if($type=="2"){echo 'class="current"';}?>><a href="?type=2"><span>得到流量</span></a></li>
      </ul>
     </div>
   </div>
 <div class="floattopempty"></div>
<?php if($type==""){ ?>
<form name="form1" method="post" action="">
<input type="hidden" name="action" value="saveinfo">
<table class="tb tb2">
    <tr><th  class="partition"  colspan="5">批量添加流量信息</th></tr>
      <tr>
        <td width="100"><div align="right">用户名：</div></td>
        <td>
            <input name="user_name" type="text" value="" id="user_name" class="input" style="width:250px;"/> (添加多个用户,请将用户名用","隔开)
          </td>
      </tr>
      
      <tr>
        <td><div align="right">批量添加数据量：</div></td>
        <td>
            <input type="text" name="muns" style="width:50px;"/>(请填写整数，例如：填写8 就可以给用户增加8个IP)
          </td>
      </tr>

      <tr>
        <td height="32">&nbsp;</td>
        <td>
            <input type="submit" name="Button1" value=" 确 定 " id="Button1" class="button" />
          </td>
      </tr>
</table>
<?php }elseif($type=="1"){ ?>
<table class="tb tb2 ">
    <tr><th  class="partition"  colspan="5">流量信息 - 贡献流量</th></tr>
    <tr>
       <tr class="header">
        <th style="text-align:center">IP来源</th>
        <th>实际MAC地址</th>
        <th>时间</th>
        <th>用户ID</th>
     </tr>
  <?php
  $query=$db->query("select * from ve123_webunion_log where type=1 order by id desc limit 30");
  while($link=$db->fetch_array($query)){
  ?>
  <tr>
    <td height="30"  style="text-align:center"><?php echo $link["c_ip"];?></td>
    <td align=""><?php echo $link["mac"];?></td>
    <td align=""><?php echo MyDate('Y-m-d  H:i:s',$link["c_time"])?></td>
    <td align=""><?php echo $link["mid"];?></td>
  </tr>
  <?php
  }
  ?>
		           <tr>
                <td height="25" colspan="4">
                  今日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'];
				  ?>
				   / 总IP数：
				   <?php 
				  $rows=$db->get_one("select count(*) as dd from ve123_webunion_log where type=1  ");
				  echo $rows['dd'];
				  ?>
                  </td>
              </tr>

  </table>
<?php }elseif($type=="2"){ ?>
<table class="tb tb2 ">
    <tr><th  class="partition"  colspan="5">流量信息 - 得到流量</th></tr>
    <tr>
       <tr class="header">
        <th style="text-align:center">IP来源</th>
        <th>实际MAC地址</th>
        <th>时间</th>
        <th>用户ID</th>
     </tr>
  <?php
  $query=$db->query("select * from ve123_webunion_log where type=2 order by id desc limit 30");
  while($link=$db->fetch_array($query)){
  ?>
  <tr>
    <td height="30"  style="text-align:center"><?php echo $link["c_ip"];?></td>
    <td align=""><?php echo $link["mac"];?></td>
    <td align=""><?php echo MyDate('Y-m-d  H:i:s',$link["c_time"])?></td>
    <td align=""><?php echo $link["mid"];?></td>
  </tr>
  <?php
  }
  ?>
		           <tr>
                <td height="25" colspan="4">
                  今日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'];
				  ?>
				   / 总IP数：
				   <?php 
				  $rows=$db->get_one("select count(*) as dd from ve123_webunion_log where type=2  ");
				  echo $rows['dd'];
				  ?>
                  </td>
              </tr>

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