<?php
if(!$_SESSION['admin_id']){
	pe_goto("index.php");
}
$menumark = "packagetype";
switch ($act) {
	case 'add':
		$action = "admin.php?mod=packagetype&act=add";
		if(isset($_POST['dosubmit'])){
			$_p_info['parentid']=0;
			if ($db->pe_insert('packagetype', $_p_info)) {
				//更新缓存
				cache::write('packagetype', $db->index('id')->pe_selectall('packagetype', array('order by'=>'listorder asc'), '*'));
				pe_success('分类增加成功!', "admin.php?mod=packagetype");
			}
			else {
				pe_error('分类增加失败!');
			}	
		}
		else{
			$info['listorder']=0;
			include(pe_tpl('packagetype_add.html'));
		}
	break;
	case 'edit':
		$action = 'admin.php?mod=packagetype&act=edit&id='.$_g_id;
		if(isset($_POST['dosubmit'])){
			if ($db->pe_update('packagetype', array('id'=>$_g_id), $_p_info)) {
				//更新缓存
				cache::write('packagetype', $db->index('id')->pe_selectall('packagetype', array('order by'=>'listorder asc'), '*'));
				pe_success('分类修改成功!', "admin.php?mod=packagetype");
			}
			else {
				pe_error('分类修改失败!');
			}	
		}
		else{
			$info = $db->pe_select('packagetype', array('id'=>$_g_id));
			include(pe_tpl('packagetype_add.html'));
		}
	break;
	case 'order':
		foreach ($_p_info as $k=>$v) {
			$result = $db->pe_update('packagetype', array('id'=>$k), array('listorder'=>$v));
		}
		if ($result) {
			//更新缓存
			cache::write('packagetype', $db->index('id')->pe_selectall('packagetype', array('order by'=>'listorder asc'), '*'));
			pe_success('分类排序成功!');
		}
		else {
			pe_error('分类排序失败!');
		}
	break;
	case 'delete':
		if ($db->pe_delete('packagetype', array('id'=>is_array($_p_id) ? $_p_id : $_g_id))) {
			//更新缓存
			cache::write('packagetype', $db->index('id')->pe_selectall('packagetype', array('order by'=>'listorder asc'), '`id`,`name`,`listorder`,`parentid`'));
			pe_success('分类删除成功!');
		}
		else {
			pe_error('分类删除失败...');
		}
	break;
	default :
		$type_list = $db->pe_selectall('packagetype');
		$seo = pe_seo('分类列表', '', '', 'admin');
		include(pe_tpl('packagetype_list.html'));
	break;
}
pe_result();
?>