<?php
include_once("../includes/page_utf_class.php");
//==========================================
if(!empty($_POST["action"])&&$_POST["action"]==lang_show('delete'))
{
	if(isset($_POST["de"]) && is_array($_POST["de"]))
	{
		foreach($_POST['de'] as $v)
		{
			$db->query("select catid,pic from ".INFO." where id='$v'");
			$re=$db->fetchRow();
			update_cat_nums($re['catid'],'del','offer');
			if($re['pic']!=''){
				$pic = explode(',',$re['pic']);
				foreach($pic as $i){
					@unlink($config['webroot'].'/'."$i");
					@unlink($config['webroot'].'/'.substr($i,0,strrpos($i,'/')+1).'big_'.substr($i,strrpos($i,'/')+1));
				}
			}
		}
		$id=implode(",",$_POST["de"]);
		$db->query("delete from ".INFO." where id in ($id)");
		$db->query("delete from  ".OFFERDETAIL." where offerid in ($id)");
	}
}
//======================================================
if(lang_show('okeyalli')==$_POST["action"])
{
	$db->query("update ".INFO." set statu=1 where statu=0");
}
function get_country($id)
{
	global $db;
	$sql="select cname from ".COUNTRY." where id='$id'";
	$db->query($sql);
	return $db->fetchField('cname');
}
?>
<!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" />
<script type="text/javascript" src="main.js"></script>
<script type="text/javascript" src="../script/jquery-1.4.4.min.js"></script>
<script>
function reloads()
{
	
}
</script>
</HEAD>
<body>
<div class="bigbox">
  <div class="bigboxhead"> <span class="cbox on"><a href="module.php?m=offer&s=offerlist.php"><?php echo lang_show('business_list');?></a></span> <span class="cbox"><a href="module.php?m=offer&s=offer_move.php"><?php echo lang_show('shift_product');?></a></span> </div>
  <div class="bigboxbody">
    <form method="get"  action="">
      <table width="100%" border="0" cellspacing="0" cellpadding="0">
        <tr>
          <td class="searh_left"><?php echo lang_show('statu');?></td>
          <td><?php
			  $status=array(
				  '-1'=>lang_show('notpass'),
				  '0'=>lang_show('wpass'),
				  '1'=>lang_show('auditpass'),
				  '2'=>lang_show('recom'),
			  );
			  $ext_rec=explode("|",$config['ext_rec']);
			  foreach($ext_rec as $key=>$v)
			  {
				$nums=count($status)-1+$key;
				$status[$nums]=$v;
			  }
		  	?>
            <select class="select" name="statu">
              <option value=""><?php echo lang_show('all');?></option>
              <?php
			foreach($status as $key=>$v)
			{
			?>
              <option value="<?php echo $key;?>" <?php if($_GET['statu']=="$key")echo "selected";?>><?php echo $v;?></option>
              <?php
			 } 
			?>
            </select></td>
        </tr>
        <tr>
          <td><?php echo lang_show('none');?></td>
          <td><select class="select" name="order">
              <option value="1"><?php echo lang_show('ptime');?></option>
              <option <?php if($_GET['order']==2) echo 'selected=selected';?> value="2"><?php echo lang_show('membership_level');?></option>
              <option <?php if($_GET['order']==3) echo 'selected=selected';?> value="3"><?php echo lang_show('ranking_index');?></option>
            </select></td>
        </tr>
        <tr>
          <td><?php echo lang_show('key_word');?></td>
          <td><?php
		  $title=array(
					  '1'=>lang_show('title'),
					  '2'=>lang_show('introduce'),
					  '3'=>lang_show('key_word'),
					  '4'=>lang_show('supplier')
				  );
			  ?>
            <select class="lselect" name="title">
              <?php
		foreach($title as $key=>$v)
		{
		?>
              <option value="<?php echo $key;?>" <?php if(!empty($_GET['title'])&&$_GET['title']==$key)echo "selected";?>> <?php echo $v;?> </option>
              <?php
		 }
		 ?>
            </select>
            --
            <input class="rtext" name="key" type="text" value="<?php if(!empty($_GET['key'])) echo $_GET['key'];?>" size="35"></td>
        </tr>
        <tr>
          <td>&nbsp;</td>
          <td><input class="btn" type="submit" 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 name="m" id="m" type="hidden" value="offer">
            <input name="s" id="s" type="hidden" value="offerlist.php"></td>
        </tr>
      </table>
    </form>
    <form action="" name='frm' method="POST">
      <table width="100%" border="0" cellpadding="2" cellspacing="0" >
        <tr class="theader">
          <td width="10"><input onClick="do_select()" type="checkbox" class="checkbox" name="checkbox" value="checkbox"></td>
          <td width="58" align="center" ><?php echo lang_show('statu');?></td>
          <td><?php echo lang_show('info_title');?></td>
          <td width="206" ><?php echo lang_show('tcatid');?></td>
          <td width="143" align="center" ><?php echo lang_show('country');?></td>
          <td width="146" align="center" ><?php echo lang_show('update_date');?></td>
          <td width="63" align="center" ><?php echo lang_show('rank');?></td>
          <td width="56" align="center" ><?php echo lang_show('option');?></td>
        </tr>
        <?php
		if(!empty($_GET["key"]))
		{
			if($_GET['title']==1)
				$scl=" and a.title like '%$_GET[key]%' ";
			elseif($_GET['title']==2)
				$scl=" and a.con like '%$_GET[key]%' ";
			elseif($_GET['title']==3)
				$scl=" and a.keyword='$_GET[key]' ";
			else
				$scl=" AND b.company like '%$_GET[key]%' ";
		}
	
		if($_GET["statu"]!='')
			$scl.=" AND a.statu=".intval($_GET['statu']);
		if(!empty($_GET['type']))
			$scl.=" and a.type='$_GET[type]' ";
		if($_SESSION["province"])
			$scl.=" and b.province='$_SESSION[province]'";
		if($_SESSION["city"])
			$scl.=" and b.city='$_SESSION[city]'";
			
		if($_GET['order']==1)
			$scl.=" order by uptime desc";
		elseif($_GET['order']==2)
			$scl.=" order by ifpay desc";
		elseif($_GET['order']==3)
			$scl.=" order by rank desc";
		else
			$scl.=" order by id desc";

		$sql="select a.id,a.title,a.catid,a.uptime,a.rank,a.id,b.company,a.ifpay,a.statu,a.pic,a.userid,b.country
		from ".INFO." as a left join ".ALLUSER." as b on a.userid=b.userid  where 1 $scl ";
		//=============================
		$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();
		
		unset($_GET['s']);
		$getstr=implode('&',convert($_GET));
		//--------------------------------
		foreach($re as $v)
		{
		?>
        <tr onMouseOver="mouseOver(this)" onMouseOut="mouseOut(this,'odd')">
          <td><input name="de[]" type="checkbox" class="checkbox" id="de" value="<?php echo $v['id']; ?>"></td>
          <td align="center"><a id="status_<?php echo $v['id']; ?>" href="javascript:window.parent.alertWin('<?php echo lang_show('statu');?>','',420,280,'module.php?m=offer&s=admin_audit.php&id=<?php echo $v['id']; ?>&amp;statu=<?php echo $v['statu'];?>');">
            <?php  echo $status[$v['statu']]; ?></a>
            </td>
          <td><b><?php echo $v[title];?></b></td>
          <td align="left"><?php 
			$db->query("select cat from ".OCAT." where catid='$v[catid]' order by nums asc,all_char asc");
			$re = $db->fetchRow();
			echo empty($re['cat'])?'Ohter':$re['cat'];
		?></td>
          <td align="center"><?php echo get_country($v['country']);?></td>
          <td align="center"><?php echo $v["uptime"];?></td>
          <td align="center"><?php echo $v['rank']; ?>&nbsp;</td>
          <td align="center"><a href="module.php?m=offer&s=offermod.php&id=<?php echo $v['id']."&$getstr"; ?>"><?php echo $editimg;?></a></td>
        </tr>
        <?php 
				$i++;
			}
		?>
      </table>
      <table width="100%" height="20" border="0" cellpadding="4" cellspacing="0">
        <tr>
          <td width="45%"><input class="btn" type="submit" name="action" value="<?php echo lang_show('delete');?>" onClick="return confirm('<?php echo lang_show('are_you_sure');?>');">
            <input type='hidden' value='' name='audit' id='audit' />
            <input type='hidden' value='' name='mail_con' id='mail_con' />
            <input type='hidden' value='' name='mail_title' id='mail_title' />
            <input class="btn" type="submit" name="action" value="<?php echo lang_show('okeyalli');?>" 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>
    </form>
  </div>
</div>
</body>
</html>
