<?php
include_once("$config[webroot]/module/offer/offer_config.inc.php");
include_once("$config[webroot]/module/offer/includes/offer_class.php");
$offer=new offer();
//============================================================
if(empty($_GET['edit']))
{	
	//非编辑状态下再进行权限认定
	$re=$offer->check_access();
	if($re==false)
		msg("main.php?action=msg&type=access_dine");//权限不够，条数超过
}

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'];
	$offer->add_user_common_cat($pactidlist);//增加会员常用类别
	//###=======================================================
	$offer_id = $offer->add_info(1);
	if($offer_id)
		$admin->msg("main.php?m=offer&s=admin_offer_list");
}

if(isset($_POST['editID']))
{
	$re=$offer->edit_info(1);
	if($re)
		$admin->msg("main.php?m=offer&s=admin_offer_list");
}

if(isset($_GET['edit']))
{
	$tpl->assign("de",$de = $offer->info_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",$offer->getProTypeName($pactidlist));
	$offer->add_user_common_cat($pactidlist);//增加会员常用类别
	//--------------------------------扩展字段显示
	include_once("$config[webroot]/includes/plugin_add_field_class.php");
	$addfield = new AddField('offer');
	$extfiled=$addfield->addfieldinput($_GET['edit'],$de['ext_table']);//
	$tpl->assign("firstvalue",$extfiled);
	//##==============================
	if(file_exists("$config[webroot]/module/download/"))
	{
		include_once("$config[webroot]/module/download/includes/plugin_download_class.php");
		$download = new download();
		$downs = $download->offer_down_list( $_GET['edit'] );
		if($downs!=null){
			foreach($downs as $down)
			{
				if(in_array( $down['pic'],array('gif','jpg','jpeg','bmp','png'))){
					$down['thumb_img'] = $_OFFER_ATTACH['upload_dir'].'/'.$_OFFER_ATTACH['save_dir'].'/'.$down['file_path'].'/mid_'.$down['file_url'];
				}else{
					if( is_file($config['webroot'].'/image/default/file_icon/'.$down['pic'].'.png'))
						$down['thumb_img'] = 'image/default/file_icon/'.$down['pic'].'.png';
					else
						$down['thumb_img'] = "image/default/file_icon/file.png";
				}
				$down_list[] = $down;
			}
			$tpl->assign( "attach",$down_list );
		}
	}
}

$tpl->assign("infoType",explode('|',$config['infoType']));	
$tpl->assign("unit",explode('|',$config['unit']));
$tpl->assign("valid_time",explode('|',$config['valid_time']));
//==================================
$tpl->assign("prov",get_province());
$tpl->assign("custom_cat",$admin->get_custom_cat_list(1,0));
$tpl->assign("upload",$_OFFER_ATTACH  );
//==================================
$tpl->assign("config",$config);
$tpl->assign("lang",$lang);
$output=tplfetch("admin_offer.htm");
?>