<?php
/*
		[FuShow.cn] (C) 2013-2014 HXWY Inc.
		FuShow Friend V3.0				Id: usadmin_majorManager.php
		Email <service@fushow.cn>		http://fushow.cn/
*/
include_once(S_ROOT.'./source/function_common.php');
include_once(S_ROOT.'./source/function_cache.php');
if(!defined('IN_FUSHOW') || !defined('IN_ADMINCP')) {
	exit('Access Denied');
}
//权限
if(!checkperm('manageprofield')) {
	cpmessage('no_authority_management_operation');
}
@include_once(S_ROOT.'./data/data_profield.php');

$id = empty($_GET['id'])?null:intval($_GET['id']);
//取得单个数据
if(empty($_GET['op'])) {
	if(!$id) {
		$navigategroups = array();
		$query = $_SGLOBAL['db']->query("SELECT * FROM ".tname('major_manager')." ORDER BY displayorder");
		while ($value = $_SGLOBAL['db']->fetch_array($query)) {
			$majorgroups[] = $value;
		}	
	}
//如果添加信息	
}elseif($_GET['op'] == 'add') {
	if(submitcheck('insertsubmit')) {
		//列表
	 	$setarr = array(
			'displayorder' => intval($_POST['displayorder']),
			'name' => getstr($_POST['name'],30,0,0,0,0,-1),
			'url' => getstr($_POST['url'],200,0,0,0,0,-1),
			'available' => intval($_POST['available'])
		   );
	 	inserttable('major_manager', $setarr);
	 	//更新缓存
		profield_cache();
		cpmessage('do_success', 'usadmin.php?ac=majorManager');
	}
//如果修改信息
} elseif($_GET['op'] == 'edit') {
	if($id) {
		$navigategroups = array();
		$query = $_SGLOBAL['db']->query("SELECT * FROM ".tname('major_manager')." WHERE id=$id");
		while ($value = $_SGLOBAL['db']->fetch_array($query)) {
			$majorgroups[] = $value;
		}			
	}
	if(submitcheck('updatasubmit')) {
	$setarr = array(
		'displayorder' => intval($_POST['displayorder']),
		'name' => getstr($_POST['name'],30,0,0,0,0,-1),
		'url' => getstr($_POST['url'],200,0,0,0,0,-1),
		'available' => intval($_POST['available'])
	);
	updatetable('major_manager', $setarr, array('id'=>$id));
	//更新缓存
	profield_cache();
	cpmessage('do_success', 'usadmin.php?ac=majorManager');
	}
//如果删除信息	
} elseif($_GET['op'] == 'delete') {	
	//$count = $_SGLOBAL['db']->result($_SGLOBAL['db']->query("SELECT COUNT(*) FROM ".tname(navigate).""), 0);	
	//至少保留一个栏目
	//if($count < 2) {
		//cpmessage('have_one_mtag', 'usadmin.php?ac=navigate');
	//}	
	if($id) {
		$navigategroups = array();
		$query = $_SGLOBAL['db']->query("SELECT * FROM ".tname('major_manager')." WHERE id=$id");
		while ($value = $_SGLOBAL['db']->fetch_array($query)) {
			$majorgroups[] = $value;
		}			
	}
	if(submitcheck('deletesubmit')) {
		$_SGLOBAL['db']->result($_SGLOBAL['db']->query("DELETE FROM ".tname('major_manager')." WHERE id=$id"), 0);
		//更新缓存
		profield_cache();
		cpmessage('do_success', 'usadmin.php?ac=majorManager');
	}
}
?>