<?php
include_once("../includes/page_utf_class.php");
//==========================================
if($_POST['act']=='status')
{
	if($_POST[id])
	{
		$db->query("update   ".BUY."  set  statu='$_POST[statu]'   where id='$_POST[id]'");
		exit('ok');
	}
	else
		exit('修改失败');
}
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 ".BUY." where id='$v'");
			$re=$db->fetchRow();
			update_cat_nums($re['catid'],'del','offer');
			if($re['pic']!=''){
				$pic = explode(',',$re['pic']);
				if(is_array($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 ".BUY." where id in ($id)");
		$db->query("delete from ".BUYPRO." where buy_id in ($id)");
		$db->query("delete from ".BUYQPRO." where buy_id in ($id)");
	}
}
//======================================================
if(lang_show('okeyalli')==$_POST["action"])
{
	$db->query("update ".BUY." 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 src="../script/my_lightbox.js" language="javascript"></script>
<script type="text/javascript" src="../script/jquery-1.4.4.min.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 picvalue(str,id)
{
	document.getElementById('status_'+id).innerHTML=str;
	close_win();
}

function edit(url,width,height)
{
	
	var heig=height!=''?height:'400px';
	art.dialog.open(url,{title:"查看求购",drag:false,lock:true,resize: false,background:'#E8F2FF',fixed:true,width:'630px',height:heig,button: [{
		name: 'close',
		callback: function () {
				 this.close();
			return false;
		 },
		focus: true
		}]
	}
	);
}
var locat = window.location.href;
</script>
</HEAD>
<body>
<div class="bigbox">
  <div class="bigboxhead"><?php echo lang_show('buying_man');?> </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'),
			  );
		  	?>
            <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('user_g');?></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 name="m" id="m" type="hidden" value="buy">
            <input name="s" id="s" type="hidden" value="buylist.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="23"><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('buying_title');?></td>
          <td width="206" ><?php echo lang_show('tcatid');?></td>
          <td width="143"><?php echo lang_show('country');?></td>
          <td width="146" align="left" ><?php echo lang_show('update_date');?></td>
          <td width="80" align="left" ><?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"]!=''&&isset($_GET["statu"])&&$_GET["statu"]<4)
			$scl.=" AND a.statu=".intval($_GET['statu']);
		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";
		else
			$scl.=" order by id desc";

		$sql="select a.id,a.title,a.catid,a.uptime,a.id,b.company,a.statu,a.pic,a.userid,b.country
		from ".BUY." as a left join ".COMPANY." as b on a.userid=b.company_id  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="show_status_<?php echo $v['id']?>" title="<?php echo $v['statu']?>" onclick="changes_tatus($('#show_status_<?php echo $v['id']?>').attr('title'),'<?php echo $v['id']?>')"  style="cursor:pointer; text-decoration:underline;"><?php echo $status[$v['statu']];?></a> </a></td>
          <td><b><?php echo "<a  href=\"javascript:edit('module.php?m=buy&s=buymod.php&id=$v[id]&$getstr','750px','');\">$v[title]</a>"; ?></b></td>
          <td><?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><?php echo get_country($v['country']);?></td>
          <td><?php echo $v["uptime"];?></td>
          <?php
		       $db->query("select count(*) as num from  ".BUYQPRO." where  buy_id='$v[id]'");
			   $num=$db->fetchField('num');
		   ?>
          <td><a  href="javascript:edit('module.php?m=buy&s=buymod.php&id=<?php echo $v['id']."&$getstr"; ?>&show=1','','');"><?php echo lang_show('details');?></a>
            <?php if($num>0){?>
            | <a  href="javascript:show_id('<?php echo $v['id'];?>');"><?php echo $num;?> <?php echo lang_show('quoted_price');?></a>
            <?php } ?></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');?>');"></td>
          <td width="65%" align="right"><div class="page"><?php echo $pages?></div></td>
        </tr>
      </table>
    </form>
  </div>
</div>
<div id='status'  style="display:none;" >
  <?php  foreach($status as $key=>$val){ ?>
  <input title='<?php echo $val?>' type=radio name=status value='<?php echo $key?>'>
  <?php echo $val?> &nbsp; &nbsp;
  <?php }?>
</div>
<script language="javascript" type="text/jscript">
function show_id(id)
{
	art.dialog.open('<?php echo $config['weburl'];?>/admin/module.php?m=buy&s=qprice.php&id='+id,{title:'报价单',drag:false,resize: false, fixed:true,width:'720px',height:'400px',lock:true,id:'testID2',background:'#E8F2FF'});
}

function changes_tatus(status,id)
{	
   
	art.dialog({
	lock:true,
	drag:false,
	resize: false,
	fixed:true,
	background:'#E8F2FF',
	title: '修改状态',
	content:document.getElementById('status'),
	button: [{
		name: '提交',
		callback: function () {		
		   var  stau=$("#status :radio:checked[name=status]").val();
		   var  stau_str=$("#status :radio:checked[name=status]").attr('title');
			$.ajax({
			    type: "POST",
			    url: "module.php?m=buy&s=buylist.php",
			    data: "act=status&statu="+stau+"&id="+id, 
			    dataType:'text',
			    success: function(msg){
			    		if(msg=='ok')
						{	
							$("#show_status_"+id).html(stau_str);
							$("#show_status_"+id).attr('title',stau);
						}
						else
						  alert(msg);	
					},
					error: function (xmlHttp, textStatus){
						alert(textStatus);
					}
				});
				
			this.close();
		 },
		focus: true
		},{
		name: 'close',
		callback: function () {
				 this.close();
			return false;
		 },
		focus: true
		}]
	});
	$("#status :radio[value='"+status+"']").attr("checked",true);
	
}
</script>
</body>
</html>