<?
define('THIS_SCRIPT', 'menpai');
include_once 'global.php';
$lang = load_lang($lang,'menpai');
checklogin();
header("content-Type: text/html; charset=".$charset);
head();
if ( strpos($sysinfo['flag'],'8,') === false ){
	show_msg($lang['readme_tit'],$lang['error.str1'],0,'','','','');
	exit;
}
PageLoad();
footer();
function Pageload(){
	global $dv,$db,$lang,$action,$id,$pai_name,$info_list;
	switch ($action){
		case "add":
			add();
		break;
		case "del":
			del();
		break;
		case "editok":
			editok();
		break;
		default:
			menpai_list();
		break;
	}
include printout('menpai');
}
function add(){
	global $db,$dv,$lang,$id,$pai_name;
	$pai_name=str_replace(" ","",$pai_name);
	$total=intval($db->scalar("select count(1) from {$dv}groupname where groupname='".$pai_name."'"));
	if($total>=1){
		show_msg($lang['sys.info'],$lang['add.info1'],0,'','','menpai.php',$lang['comback']);
	exit;	
	}
	else{
		if($result=$db->query("insert into {$dv}groupname set groupname='$pai_name'")){
		
			show_msg($lang['sys.info'],$lang['add.info2'],1,'','','menpai.php',$lang['comback']);
		exit;
		}
		else{
			show_msg($lang['sys.info'],$lang['add.info3'],0,'','','menpai.php',$lang['comback']);
		exit;
		}
	}
}
function menpai_list(){
	global $dv,$db,$lang,$info_list;
	$info_list=array();
	$result=$db->query("select id,groupname from {$dv}groupname order by id desc");
	while ($arr=$db->fetch_array($result)){
		
		$info_list[]=$arr;
	}
$db->free_result($result);
}
function del(){
	global $dv,$lang,$db,$id;
	if($result=$db->query("delete from {$dv}groupname where id=".intval($id))){
		show_msg($lang['sys.info'],$lang['del.info1'],1,'','','menpai.php',$lang['comback']);
	exit;
	}
	else{
		show_msg($lang['sys.info'],$lang['del.info2'],0,'','','menpai.php',$lang['comback']);
	exit;
	}
}
function editok(){
	global $dv,$db,$lang,$id,$pai_name;
	$pai_name=str_replace(" ","",$pai_name);
	if($result=$db->query("update {$dv}groupname set groupname='$pai_name' where id=".intval($id))){
		show_msg($lang['sys.info'],$lang['edit.info1'],1,'','','menpai.php',$lang['comback']);
	exit;	
	}
	else{
		show_msg($lang['sys.info'],$lang['edit.info2'],1,'','','menpai.php',$lang['comback']);
	exit;
	}
}

?>