<?php
include_once("../includes/page_utf_class.php");
//====================================
if(!empty($_GET['action'])&&$_GET['action']=='del'&&!empty($_GET['id']))
{
     $sql="delete from ".CDOMIN." where id='".trim($_GET['id'])."'";
	 $db->query($sql);
}
if(!empty($_POST['delete'])&&$_POST['delete']==lang_show('delete'))
{
	if(is_array($_POST["checktag"]))
	{
		$deltn=implode(",",$_POST["checktag"]);
		$sql="delete from ".CDOMIN."  where  id in (".$deltn.")";
		$db->query($sql);	
	}
}
if(!empty($_GET['binddomin'])&&$_GET['binddomin']==lang_show('bingd'))
{
	$sql="select userid,company_id from ".ALLUSER." where user='".trim($_GET['user'])."'";
	$db->query($sql);	
	$rss=$db->fetchRow();
	$company_id=$rss['company_id'];
	if($company_id)
	{
		$sql="select userid from ".CDOMIN." where company_id='$company_id'";
		$db->query($sql);	 
		if($db->num_rows()<=0)
			$sql="insert into ".CDOMIN." (`domin`,`company_id`,`time`) values ('".trim($_GET['userdomin'])."','$company_id',".time().")";
		else
			$sql="update ".CDOMIN." set domin='".trim($_GET['userdomin'])."',time=".time()." where company_id='$company_id'";
		$db->query($sql);
	}
}
if(!empty($_GET['userid']))
{
   $sql="select user from ".ALLUSER." where userid=".trim($_GET['userid']);
   $db->query($sql);	
   $rss=$db->fetchRow();
   $u=$rss['user'];
   $sql="select * from ".CDOMIN." where userid=".trim($_GET['userid']);
   $db->query($sql);	
   $rss=$db->fetchRow();
   $d=$rss['domin'];
}


$sql="select a.id,a.domin,a.company_id,a.time,b.domain from ".CDOMIN." a, ".COMPANY." b where a.company_id=b.company_id  order by a.time";
//=============================
	$page = new Page;
	$page->listRows=20;
	if (!$page->__get('totalRows')){
		$db->query($sql);
		$page->totalRows = $db->num_rows();
	}
	$sql .= "  limit ".$page->firstRow.",20";
	$pages = $page->prompt();
//=====================
$db->query($sql);
$re=$db->getRows();
?>
<!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>
<TITLE><?php echo lang_show('admin_system');?></TITLE>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=utf-8">
<link href="main.css" rel="stylesheet" type="text/css" />
</head>
<body>
<script type="text/javascript">
function checkall()
{
	 for(var j = 0 ; j < document.getElementsByName("checktag[]").length; j++)
	 {
	  	if(document.getElementsByName("checktag[]")[j].checked==true)
	  	  document.getElementsByName("checktag[]")[j].checked = false;
		else
		  document.getElementsByName("checktag[]")[j].checked = true;
	 }
}
</script>
<div class="bigbox">
  <div class="bigboxhead"><?php echo lang_show('udomin_b');?></div>
  <div class="bigboxbody">
    <table width="100%" border="0" cellspacing="0" cellpadding="0">
      <form name="userdomin" method="post">
        <tr>
          <td width="9%" align="left" ><?php echo lang_show('company');?></td>
          <td width="91%" align="left" ><input class="text" name="company" type="text" id="company" /></td>
        </tr>
        <tr>
          <td align="left" ><?php echo lang_show('bdominn');?></td>
          <td align="left" >http://
            <input name="userdomin" type="text" id="userdomin" size="38" maxlength="50" value="<?php if (isset($d)) echo $d;?>" /></td>
        </tr>
        <tr>
          <td align="left" >&nbsp;</td>
          <td align="left" ><input class="btn" type="submit" name="binddomin" id="binddomin" value="<?php echo lang_show('bingd');?>" />
            <input type="hidden" name="uid" id="uid" value="<?php echo $_GET['userid'];?>" /></td>
        </tr>
      </form>
    </table>
    
    <form name="userdomin" action="" method="POST">
      <table width="100%" border="0" cellspacing="0" cellpadding="0">
        <tr class="theader">
          <td width="35" align="left"  ><input type="checkbox" class="checkbox" name="checktagall" id="checktagall" onClick="checkall()"></td>
          <td width="46" align="left"  ><?php echo lang_show('uid');?></td>
          <td width="167" align="left" class="STYLE20"  ><?php echo lang_show('uname');?></td>
          <td width="515" align="left"  ><?php echo lang_show('bdominn');?></td>
          <td width="119" align="left"  ><?php echo lang_show('bdtime');?></td>
          <td width="99" align="left"  ><?php echo lang_show('op');?></td>
        </tr>
        <?php
	      foreach ($re as $v)
          {
        ?>
        <tr>
          <td align="left" ><input type="checkbox" class="checkbox" name="checktag[]" value="<?php echo $v['id'];?>"></td>
          <td align="left" ><?php echo $v['company_id'];?></td>
          <td align="left" ><?php echo $v['user'];?></td>
          <td align="left" ><?php echo $v['domin'];?></td>
          <td align="left" ><?php echo date('Y-m-d',$v['time']);?></td>
          <td  align="left" ><pre><a href="user_domin.php?action=del&id=<?php echo $v['id'];?>" onClick="return confirm('<?php echo lang_show('are_you_sure');?>');"><?php echo $delimg;?></a></pre></td>
        </tr>
        <?php
        }
        ?>
        <tr>
          <td  colspan="3" align="left"  ><input class="btn" type="submit" name="delete" value="<?php echo lang_show('delete');?>" onClick="return confirm('<?php echo lang_show('are_you_sure');?>');"></td>
          <td  colspan="3" align="right"  >&nbsp;
            <div class="page"><?php echo $pages?></div></td>
        </tr>
      </table>
    </form>
  </div>
</div>
</body>
</html>