<?php
include_once("../includes/page_utf_class.php");
include_once("../config/usergroup.php");
include_once("module/company/includes/companyfen_class.php");
$companyfen=new companyfen();
//====================================
if(!empty($_POST['de'])&&empty($_POST['passall']))
{
	del_user($_POST['de']);
}

function get_country($id)
{
	global $db,$config;
	if($config['language']=='cn')
		$sql="select cname as name from ".COUNTRY." where id='$id'";
	else
		$sql="select ename as name from ".COUNTRY." where id='$id'";
	$db->query($sql);
	return $db->fetchField('name');
}

function del_user($ar)
{
	global $db,$config;
	foreach($ar as $v)
	{	
		$company_id=$v;
		ext_all('delete_by_uid',array('company_id'=>$company_id));
		
		$db->query("update ".ALLUSER." set company_id=0 where company_id='$company_id'");
	}
}

$categorys['company']=lang_show('company_name');
$categorys['contact']=lang_show('contact');
$categorys['tel']=lang_show('company_tel');
$categorys['email']='Email';

$companyType=explode('|',$config['companyType']);
$country=country_list();
?>
<!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">
<link href="main.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="main.js"></script>
<script type="text/javascript" src="../script/jquery-1.4.4.min.js"></script>
<script type="text/javascript" src="../script/my_lightbox.js"></script>
<script type="text/javascript" src="../script/artdialog/artDialog.source.js?skin=default"></script>
<script type="text/javascript" src="../script/artdialog/plugins/iframeTools.source.js"></script>
<script>
function edit(url,width,height)
{
	var wid=width!=''?width:'90%';
	var heig=height!=''?height:'400px';
	art.dialog.open(url,{title:'公司信息预览编辑',drag:false,lock:true,resize: false, fixed:true,width:wid,height:heig,button: [{
		name: '预览',
		callback: function () {	
		      edit(url+"&show=",'650px','400px');
			this.close();
		 },
		focus: true
		},{
		name: '编辑',
		callback: function () {	
		   
		       edit(url+"&show=1",'','');
			this.close();
		 },
		focus: true
		},{
		name: 'close',
		callback: function () {
				 this.close();
			return false;
		 },
		focus: true
		}]
	}
	);
}
</script>
<title><?php echo lang_show('admin_system');?></title>
</head>
<body>
<div class="bigbox">
  <div class="bigboxhead"><?php echo lang_show('query');?></div>
  <div class="bigboxbody">
    <table width="100%" border="0" align="center" cellpadding="0" cellspacing="0">
      <form name="frmuser" method="get" action="">
        <?php if($config['identity']){?>
        <tr>
          <td width="10%"><?php echo lang_show('membership');?></td>
          <td width="90%"><select class="select" name="identity">
              <option value=""><?php echo lang_show('all_company_type');?></option>
              <?php
			$identity=explode('|',$config['identity']);
			foreach($identity as $keys=>$v)
			{
			?>
              <option value="<?php echo $keys;?>" <?php if($keys==$_GET['identity']&&$_GET['identity']!='') echo "selected"; ?>><?php echo $v?></option>
              <?php
			}
			?>
            </select>
          </td>
        </tr>
        <?php } ?>
        <tr>
          <td><?php echo lang_show('admin');?></td>
          <td><select class="select" name="invite">
              <option value=""><?php echo lang_show('all');?></option>
            <?php
		  	$sql="select name from ".ADMIN." where name!='' order by name";
			$db->query($sql);
			$invite=$db->getRows();
			foreach($invite as $v)
			{
		    ?>
              <option value="<?php echo $v['name']; ?>" <?php if($_GET['invite']==$v['name']) echo "selected"; ?>><?php echo $v['name']; ?></option>
             <?php
			 }
			 ?>
            </select>
			</td>
        </tr>
        <tr>
          <td><?php echo lang_show('country');?></td>
          <td><select class="select" name="country">
              <option value=""><?php echo lang_show('all');?></option>
              <?php foreach($country as $v){?>
              <option value="<?php echo $v['id'];?>" <?php if($_GET['country']==$v['id']) echo 'selected="selected"';?>><?php echo $v['name'];?></option>
              <?php } ?>
            </select>
          </td>
        </tr>
        <tr>
          <td width="10%"><?php echo lang_show('belong_industry');?></td>
          <td width="90%"><select class="select" name="catid" >
              <option value="0" style='font-weight:bold; font-size:14px;'><?php echo lang_show('all_industry');?></option>
              <?php
				$slectid=isset($_GET["catid"])?$_GET["catid"]:'';
				$db->query("select catid,cat from  ".COMPANYCAT."  where catid<=9999 order by nums asc");
				$catList=$db->getRows();
				foreach($catList as $v)
				{
					if($v['catid']==$slectid)
						echo "<option style='color:red;font-weight:bold;padding-left:20px;' value=".$v['catid']." selected=selected >|_".$v['cat']."</option>";
					else
						echo "<option style='color:red;font-weight:bold;padding-left:20px;' value=".$v['catid']." >|_".$v['cat']."</option>";
					$s=$v['catid'].'00';
					$b=$v['catid'].'99';
					$sql="select catid,cat from  ".COMPANYCAT."  where catid<=$b and catid>=$s order by nums asc";
					$db->query($sql);
					$scat=$db->getRows();
					foreach($scat as $sv)
					{
						if($sv['catid']==$slectid)
							echo "<option style='font-weight:bold;padding-left:40px;' value=".$sv['catid']." selected=selected >|____".$sv['cat']."</option>";
						else
							echo "<option style='font-weight:bold;padding-left:40px;' value=".$sv['catid']." >|____".$sv['cat']."</option>";
						$s=$sv['catid'].'00';
						$b=$sv['catid'].'99';
						$sql="select catid,cat from  ".COMPANYCAT."  where catid<=$b and catid>=$s order by nums asc";
						$db->query($sql);
						$tcat=$db->getRows();
						foreach($tcat as $tv)
						{
							if($tv['catid']==$slectid)
								echo "<option style='padding-left:60px;' value=".$tv['catid']." selected=selected >|________".$tv['cat']."</option>";
							else
								echo "<option style='padding-left:60px;' value=".$tv['catid']." >|________".$tv['cat']."</option>";
						}

					}
				}
				?>
            </select></td>
        </tr>
        <tr>
          <td width="10%"><?php echo lang_show('member_type');?></td>
          <td width="90%">
          <select class="select" name="only" id="only">
              <option value="" selected><?php echo lang_show('all_member');?></option>
              <?php
				$sql="select * from ".USERGROUP." order by group_id asc";
				$db->query($sql);
				$re=$db->getRows();
				foreach($re as $v)
	          	{
			   	?>
              <option value="<?php echo $v['group_id']; ?>" <?php if($_GET['only']==$v['group_id']) echo "selected"; ?>><?php echo $v['name']; ?></option>
              <?php
				  }
			  ?>
            </select>
          </td>
        </tr>
        <tr>
          <td width="10%"><?php echo lang_show('display');?></td>
          <td width="90%"><select class="select" name="ordrby">
              <option <?php if ($_GET['ordrby']=='uptime') echo "selected";?> value="uptime"><?php echo lang_show('updated');?></option>
              <option <?php if ($_GET['ordrby']=='rank') echo "selected";?> value="rank"><?php echo lang_show('by_rating');?></option>
              <option <?php if ($_GET['ordrby']=='statu') echo "selected";?> value="statu"><?php echo lang_show('by_rec');?></option>
            </select>
            <input type="radio" class="radio" name="order" value="" <?php echo $_GET['order']==""?"checked":""?> />
            <?php echo lang_show('desc');?>
            <input type="radio" class="radio" name="order" value="desc" <?php echo $_GET['order']=="desc"?"checked":""?> />
            <?php echo lang_show('asc');?></td>
        </tr>
        <tr>
          <td><?php echo lang_show('bylastlogotime');?></td>
          <td><select class="select" name="lastlogotime" id="lastlogotime">
              <option value=""><?php echo lang_show('alllogotime');?></option>
              <option value="1" <?php if (!empty($_GET['lastlogotime'])&&$_GET['lastlogotime']=='1') echo "selected";?>><?php echo lang_show('oneh');?></option>
              <option value="2" <?php if (!empty($_GET['lastlogotime'])&&$_GET['lastlogotime']=='2') echo "selected";?>><?php echo lang_show('twoh');?></option>
              <option value="12" <?php if (!empty($_GET['lastlogotime'])&&$_GET['lastlogotime']=='12') echo "selected";?>><?php echo lang_show('halfd');?></option>
              <option value="24" <?php if (!empty($_GET['lastlogotime'])&&$_GET['lastlogotime']=='24') echo "selected";?>><?php echo lang_show('oneday');?></option>
              <option value="48" <?php if (!empty($_GET['lastlogotime'])&&$_GET['lastlogotime']=='48') echo "selected";?>><?php echo lang_show('twoday');?></option>
              <option value="72" <?php if (!empty($_GET['lastlogotime'])&&$_GET['lastlogotime']=='72') echo "selected";?>><?php echo lang_show('threeday');?></option>
              <option value="168" <?php if (!empty($_GET['lastlogotime'])&&$_GET['lastlogotime']=='168') echo "selected";?>><?php echo lang_show('oneweek');?></option>
              <option value="336" <?php if (!empty($_GET['lastlogotime'])&&$_GET['lastlogotime']=='336') echo "selected";?>><?php echo lang_show('twoweek');?></option>
              <option value="720" <?php if (!empty($_GET['lastlogotime'])&&$_GET['lastlogotime']=='720') echo "selected";?>><?php echo lang_show('onemonth');?></option>
            </select></td>
        </tr>
        <tr>
          <td><?php echo lang_show('key_world');?></td>
          <td><select class="lselect" name="category">
              <?php foreach($categorys as $keys=>$v){ ?>
              <option value="<?php echo $keys;?>" <?php if($_GET['category']==$keys ) echo "selected";?> ><?php echo $v; ?></option>
              <?php } ?>
            </select>
            --
            <input class="rtext" name="keyword" type="text" value="<?php echo $_GET['keyword'];?>" size="40" /></td>
        </tr>
        <tr>
          <td>&nbsp;</td>
          <td><script>
			$(document).ready(
				function()
				{
					$("#export_excel").click(
						function()
						{	
							if(confirm('确定吗'))
							{
								$('#s').val('exportexcel.php');
							}
						}
					);
					$("#search_btn").click(
						function()
						{
							$('#s').val('company.php');
						}
					);
				}
			);</script>
            <input class="btn" type="submit" id="search_btn" name="Submit" value="<?php echo lang_show('search');?>" />
            <input type="submit" id="export_excel" class="btn" value="<?php echo lang_show('Search_and_export');?>">
            <input id="m" name="m" type="hidden" value="company" />
            <input id="s" name="s" type="hidden" value="company.php" />
          </td>
        </tr>
      </form>
    </table>
  </div>
</div>
<div style="float:left; height:20px; width:80%;">&nbsp;</div>
<?php if(isset($_GET['Submit'])){ ?>
<form method="post">
  <div class="bigbox">
    <div class="bigboxhead"><?php echo lang_show('member_list');?></div>
    <div class="bigboxbody">
      <table width="100%" border="0" cellspacing="0" cellpadding="1" align="center" class="menu">
        <tr class="theader">
          <td width="26"  align="center" ><input name="checkbox" type="checkbox" class="checkbox" onClick="do_select()" value="checkbox"></td>
          <td width="436" align="left"><?php echo lang_show('company_name');?></td>
          <td width="76" align="left"><?php echo lang_show('country');?></td>
          <td width="75" align="left"><?php echo lang_show('invite');?></td>
          <td width="77" align="left"><?php echo lang_show('valid');?></td>
          <td width="60" align="left"><?php echo lang_show('rank');?></td>
          <td width="66" align="left"><?php echo lang_show('updated');?></td>
          <td width="85" align="center"><?php echo lang_show('manager');?></td>
        </tr>
        <?php
  	$get=$_GET;
  	unset($get['userid']);unset($get['s']);
  	$getstr=implode('&',convert($get));
  	
	if(!empty($_GET['ordrby']))
		$ordrby='u.'.$_GET['ordrby'];
	else
		$ordrby='u.uptime';
		
	if(!empty($_GET['keyword']))
	{
		if($_GET['category']=='email')
			$scl.=" and a.email='$_GET[keyword]' ";
		else
			$scl.=" and (u.$_GET[category] regexp '$_GET[keyword]')  ";
	}
	if(!empty($_GET['only']))
		$scl.=" and u.ifpay='".$_GET['only']."'";
	if($_SESSION['province'])
		$scl.=" and u.province='$_SESSION[province]'";
	if($_SESSION['city'])
		$scl.=" and u.city='$_SESSION[city]'";
	if(!empty($_GET['catid']))
		$scl.=" and u.catid like '%,$_GET[catid]%'";
	if($_GET['country']!='')
		$scl.=" and u.country='$_GET[country]'";
	if($_GET['identity']!='')
		$scl.=" and u.identity='$_GET[identity]'";
	if(!empty($_GET['invite']))
		$scl.=" and a.invite='$_GET[invite]'";
	if(!empty($_GET['endtime']))
	{
		$time=time()-3600*24*7;
		$scl.=" and u.etime<=$time";
	}
	
	//==================================
	$sql="SELECT u.*,a.email,a.invite from ".COMPANY." u left join ".ALLUSER." a on u.company_id=a.company_id  WHERE 1 $scl";
	if($_GET['order']) 
	   $sql.=" order by $ordrby asc";  
	else 
	   $sql.=" order by $ordrby desc ";

	//=============================	
	$page = new Page;
	$page->listRows=100;
	if (!$page->__get('totalRows')){
		$db->query($sql);
		$page->totalRows = $db->num_rows();
	}
	$sql .= "  limit ".$page->firstRow.",100";
	$pages = $page->prompt();
	//=====================
	$db->query($sql);
	$i=0;
	foreach($db->getRows() as $v)
	{
		$ifpay=$v['ifpay'];
		if(!empty($group[$ifpay]['minilogo']))
			$ifpay="<img src='".$group[$ifpay]['minilogo']."' alt='".$group[$ifpay]['name']."' >";
		else
			$ifpay=NULL;
	?>
        <tr onMouseOver="mouseOver(this)" onMouseOut="mouseOut(this,'odd')">
          <td width="26" align="center"><input name="de[]" type="checkbox" class="checkbox" id="de<?php echo $i++?>" value="<?php echo $v['company_id']; ?>"></td>
          <td align="left"><?php if($v['statu']>0) echo '<img src="../image/default/'.$v['statu'].'.jpg">'; ?>
            <a   href="javascript:edit('module.php?m=company&s=company_edit.php&userid=<?php echo $v['company_id'].'&'.$getstr; ?>','650px','400px','<?php echo $v['company_id'];?>');" > <?php echo $ifpay.htmlspecialchars($v['company']); ?></a> (信息完善度:<?php echo $companyfen->get_all($v['company_id']);?>/100)<br>
            <?php 
			echo lang_show('contact').':'.$v['contact']; 
			if(!empty($v['tel'])){ echo '&nbsp;'.lang_show('tel').':'. $v['tel'];}
			if(!empty($v['fax'])){ echo '&nbsp;'.lang_show('fax').':'. $v['fax'];}
			if(!empty($v['email'])){ echo '&nbsp;'.lang_show('email').':'. $v['email'];}
			?>
          </td>
          <td align="left"><?php echo get_country($v['country']);?></td>
          <td align="left"><?php echo $v['invite'];?></td>
          <td align="left"><?php 
		  	if($v['stime'])
			{
				if($v['etime']-time()<=3600*24*7&&$v['etime']>0)
					echo "<font color='red'>*</font>";
				echo date("Y-m-d",$v['stime']);
			}
			if($v['etime'])
			{
				echo '<br>'.date("Y-m-d",$v['etime']);
			}
		?></td>
          <td align="left"><?php echo $v['rank']; ?></td>
          <td align="left"><?php echo date("Y-m-d",$v['uptime']); ?></td>
          <td align="center"><a href="javascript:window.parent.alertWin('<?php echo lang_show('mem_send_mail');?>','','650','530','sendmail.php?userid=<?php echo $v['admin']; ?>');" title="<?php echo lang_show('send_mail');?>"><?php echo $mailimg;?></a> <a  href="javascript:edit('module.php?m=company&s=company_edit.php&userid=<?php echo $v['company_id'].'&'.$getstr; ?>&show=1','','','<?php echo $v['company_id'];?>');"><?php echo $editimg;?></a> <a title="<?php echo lang_show('enteroffice');?>" href="to_login.php?action=submit&user=<?php echo $v['domain']; ?>" target="_blank"><?php echo $setimg;?></a></td>
        </tr>
        <?php
	}
	?>
      </table>
      <table width="100%" border="0" align="center" cellpadding="0" cellspacing="0">
        <tr>
          <td width="45%" height="24"><input class="btn" type="submit" name="Submit2" value="<?php echo lang_show('delete');?>" onClick='return confirm("<?php echo lang_show('are_you_sure');?>");'></td>
          <td width="65%" align="right"><div class="page"><?php echo $pages?></div></td>
        </tr>
      </table>
    </div>
  </div>
</form>
<?php } ?>
</body>
</html>
