<?php
	if($_POST['Submit'])
	{
		$sql="select title from ".INFO;
		$db->query($sql);
		$re=$db->getRows();
		foreach($re as $key=>$v)
		{
			$sql="select id from ".INFO." where title='$v[title]'";
			$db->query($sql);
			if($id=$db->fetchField('id'))
			{
				$sql="delete from ".INFO." where title='$v[title]' and id!='$id'";
				$db->query($sql);
			}
		}
		admin_msg("module.php?m=offer&s=offer_clear.php",'操作成功');
	}
	
	if($_POST['clear_user'])
	{
		$sql="select userid from ".INFO;
		$db->query($sql);
		$re=$db->getRows();
		foreach($re as $key=>$v)
		{
			$sql="select userid from ".ALLUSER." where userid='$v[userid]'";
			$db->query($sql);
			if($id=$db->fetchField('userid'))
			{
				$sql="delete from ".INFO." where userid='$v[id]'";
				$db->query($sql);
			}
		}
		admin_msg("module.php?m=offer&s=offer_clear.php",'操作成功');
	}
	
	if(!empty($_POST['put_in_order']))
	{
		$sql="select * from ".SHOPSETTING." where rec_pro='' or rec_pro is Null limit 0,200";
		$db->query($sql);
		$re=$db->getRows();
		foreach($re as $v)
		{
			$sql="select id from ".INFO." where userid='$v[userid]' limit 0,20";
			$db->query($sql);
			$sre=$db->getRows();
			foreach($sre as $sv)
			{
				$ids[]=$sv['id'];
			}
			if(is_array($ids))
			{
				$idstr=implode(",",$ids);
				$sql="update ".SHOPSETTING." set rec_pro='$idstr' where userid='$v[userid]'";
				$db->query($sql);
			}
		}
	}
?>
<!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 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="main.js"></script>
</head>
<body>
<div class="bigbox">
  <div class="bigboxhead"><?php echo lang_show('clear_product');?></div>
  <div class="bigboxbody">
    <form id="form1" name="form1" method="post" action="">
      <table width="100%" border="0" cellspacing="0" cellpadding="0">
        <tr>
          <td><?php echo lang_show('clear_forone');?>
            <input class="btn" type="submit" name="Submit" value="<?php echo lang_show('clear');?>" /></td>
        </tr>
        <tr>
          <td><?php echo lang_show('clear_no_supplier');?>
            <input class="btn" type="submit" name="clear_user" value="<?php echo lang_show('clear');?>" /></td>
        </tr>
        <tr>
          <td><?php echo lang_show('clear_shop_home');?>
            <input class="btn" type="submit" name="put_in_order" value="<?php echo lang_show('execution');?>" /></td>
        </tr>
      </table>
    </form>
  </div>
</div>