<?php
include_once("$config[webroot]/module/buy/buy_config.inc.php");
include_once("$config[webroot]/module/buy/includes/buy_class.php");
//===========================================================
$buy=new buy();
if($_GET['ajax']==1)
{
	$buy->del_pro_buy($_POST['id']);
	die;
}
if(!empty($submit)&&empty($_POST['editID']))
{	

    //========================================================
	$pactidlist=!empty($_POST['catid'])?$_POST['catid']:NULL;
	if(!empty($_POST['tcatid']))
		$pactidlist.= ",".$_POST['tcatid'];
	if(!empty($_POST['scatid']))
		$pactidlist.=",".$_POST['scatid'];
	if(!empty($_POST['sscatid']))
		$pactidlist.=",".$_POST['sscatid'];
	$buy->add_user_common_cat($pactidlist);//增加会员常用类别
	//=======================================================
	$buy_id = $buy->add_buy();
	if($buy_id)
		$admin->msg("main.php?m=buy&s=admin_buy_list");
}

$_POST['editID']*=1;
if($_POST['editID'])
{
	$re=$buy->edit_buy();
	if($re)
		$admin->msg("main.php?m=buy&s=admin_buy_list");
}

if(isset($_GET['edit']))
{   
	$de = $buy->buy_detail($_GET['edit']);
	$pactidlist=$de['catid'];
	if(!empty($de['tcatid']))
		$pactidlist.=",".$de['tcatid'];
	if(!empty($de['scatid']))
		$pactidlist.=",".$de['scatid'];	
	if(!empty($de['sscatid']))
		$pactidlist.=",".$de['sscatid'];
	$tpl->assign("typenames",$buy->getProTypeName($pactidlist));
	$buy->add_user_common_cat($pactidlist);//增加会员常用类别
	$tpl->assign("de",$de);
}

$tpl->assign("seller_need",array("With sample pictures", "the need for value-added tax invoices", "provide specifications"));
$tpl->assign("buyType",explode('|',$config['buyType']));	
$tpl->assign("unit",explode('|',$config['unit']));
$tpl->assign("prov",get_province());
$sql="select  id,ename as coname from ".COUNTRY;
$db->query($sql);
$tpl->assign("country",$db->getRows());
//==================================
$tpl->assign("config",$config);
$tpl->assign("lang",$lang);
$output=tplfetch("admin_buy.htm");
?>