<?php
if(!$_SESSION['admin_id']){
	pe_goto("index.php");
}
$menumark = "package_list";
$arr = $db->pe_selectall('packagetype');
		if(is_array($arr) and !empty($arr)){
			foreach($arr as $r){
				$types[$r['id']]=$r;
			}
		}
switch ($act) {
	//#####################@ 增加套餐 @#####################//
	case 'add':
		$package_tpl = pe_dirlist("{$pe['path_root']}template/default/index/diy_*.html");
		$package_list = $db->index('package_id')->pe_selectall('package','', '`package_id`, `package_name`');
		$seo = pe_seo('增加套餐', '', '', 'admin');
		$action = "admin.php?mod=package&act=addsql";
		include(pe_tpl('package_add.html'));
	break;
	//#####################@ 增加套餐sql @#####################//
	case 'addsql':
		$_p_info['package_zjtime'] = time();
		$_p_pck['package_id']=$db->pe_insert('package', pe_dbhold($_p_info, array('package_text', 'package_notice')));
		if ($_p_pck['package_id']) {
			//更新缓存
			cache::write('package');
			$db->pe_insert('product', pe_dbhold($_p_pck));
			pe_success('套餐增加成功!', "admin.php?mod=package&act=list");
		}
		else {
			pe_error('套餐增加失败!');
		}
	break;
	//#####################@ 修改套餐 @#####################//
	case 'edit':
		$package_tpl = pe_dirlist("{$pe['path_root']}template/default/index/diy_*.html");
		$info = $db->pe_select('package', array('package_id'=>$_g_id));
		$seo = pe_seo('修改套餐', '', '', 'admin');
		$action = "admin.php?mod=package&act=editsql&id={$_g_id}";
		include(pe_tpl('package_add.html'));
	break;
	//#####################@ 修改套餐sql @#####################//
	case 'editsql':
		$_p_info['package_zjtime'] = time();
		if ($_FILES['thumb']['size']) {
				pe_lead('include/class/upload.class.php');
				$upload = new upload($_FILES['thumb']);
				$_p_info['thumb'] = $upload->fileurl;
		}
		if ($db->pe_update('package', array('package_id'=>$_g_id), pe_dbhold($_p_info, array('package_text', 'package_notice')))) {
			//更新缓存
			cache::write('package');
			pe_success('套餐修改成功!', "admin.php?mod=package&act=list");
		}
		else {
			pe_error('套餐修改失败!');
		}
	break;
	//#####################@ 套餐删除sql @#####################//
	case 'delsql':
		if ($db->pe_delete('package', array('package_id'=>is_array($_p_package_id) ? $_p_package_id : $_g_id))) {
			$db->pe_delete('comment', array('package_id'=>is_array($_p_package_id) ? $_p_package_id : $_g_id));
			//更新缓存
			cache::write('package');
			pe_success('套餐删除成功!');
		}
		else {
			pe_error('套餐删除失败...');
		}
	break;
	//#####################@ 广告代码 @#####################//
	case 'tgpic':
	case 'tgword':
		if (isset($_p_pesubmit)) {
			foreach ($_p_info as $k => &$v) {
				$v = trim($v);
			}
			$package_tgtext = serialize($_p_info);
			if ($db->pe_update('package', array('package_id'=>$_g_id), array("package_{$act}"=>$package_tgtext))) {
				//更新缓存
				cache::write('package');
				pe_success('广告代码修改成功!');
			}
			else {
				pe_error('广告代码修改失败...');
			}		
		}
		$info = $db->pe_select('package', array('package_id'=>$_g_id));
		$info_list = (array)unserialize($info["package_{$act}"]);

		include(pe_tpl('package_tgdialog.html'));
	break;
	//#####################@ 套餐列表 @#####################//
	default :
		$info_list = $db->pe_selectall('package');
		$seo = pe_seo('套餐列表', '', '', 'admin');
		include(pe_tpl('package_list.html'));
	break;
}
pe_result();
?>