<?php
	!defined('DIRCMS_MANAGE') && exit('Access Denied!');
	if(!$check_admin->roleid_check(7,$_roleid))showmsg_nourl($lang['RETURN_NOPRI']);
	$action=empty($action)?'manage':trim($action);
	require DIRCMS_ROOT.'include/admin/page.class.php';
	$page=new page();
	switch($action)
	{
		case 'manage':
			if(isset($do_submit))
			{
				if($page->setordeyby($orderby))
				{
					showmsg($lang['RETURN_SUCEESS']);
				}
				else
				{
					showmsg($lang['RETURN_ERROR']);
				}
				break;
			}
			include admin_tlp('page_manage');			
			break;
		case 'add':
			if(isset($do_submit))
			{
				/*

					检查单页名称
				*/
				if(!$info['pagename'])
				{
					showmsg($lang['PAGE-LANG-1']);
				}
				
				/*

					检查单页模板
				*/
				if(!$info['setting']['template'])
				{
					showmsg($lang['PAGE-LANG-3']);
				}

				if(isset($cnspell) && $cnspell==1)
				{
					require DIRCMS_ROOT.'include/cnspell.class.php';
					$cnspell=new cnspell();		
					$info['filename']=$cnspell->getCnSpell($info['pagename']);
				}
				else
				{
					$info['filename']=basename($info['filename'],HTMLEXT);
				}

				/*

					检查文件名称
				*/

				if(!$info['filename'])
				{
					showmsg($lang['PAGE-LANG-2']);
				}

				/*
					添加单页操作
				*/
				$re=$page->add($info);
				if($re===true)
				{
					showmsg($lang['RETURN_SUCEESS']);
				}
				else if($re==-1)
				{
					showmsg($lang['PAGE-LANG-4']);
				}
				else
				{
					showmsg($lang['RETURN_ERROR']);
				}
			}
			require DIRCMS_ROOT.'/include/options.class.php';
			$options=new options();

			$template=glob(DIRCMS_ROOT.'template/'.TLP_NAME.'/*.html');

			require DIRCMS_ROOT.'/include/form.class.php';
			$form=new form();
			
			if(isset($parentid) && intval($parentid))
			{
				$parinfo=$page->pageinfo($parentid);
			}
			else
			{
				$parentid=0;
			}
			include admin_tlp('page_add');
			break;
		case 'edit':
			if(isset($do_submit))
			{
				/*

					检查单页名称
				*/
				if(!$info['pagename'])
				{
					showmsg($lang['PAGE-LANG-1']);
				}
				
				/*

					检查单页模板
				*/
				if(!$info['setting']['template'])
				{
					showmsg($lang['PAGE-LANG-3']);
				}

				if(isset($cnspell) && $cnspell==1)
				{
					require DIRCMS_ROOT.'include/cnspell.class.php';
					$cnspell=new cnspell();		
					$info['filename']=$cnspell->getCnSpell($info['pagename']);
				}
				else
				{
					$info['filename']=basename($info['filename'],HTMLEXT);
				}

				/*

					检查文件名称
				*/

				if(!$info['filename'])
				{
					showmsg($lang['PAGE-LANG-2']);
				}

				/*
					编辑单页操作
				*/
				$re=$page->edit($info,$id);
				if($re===true)
				{
					showmsg($lang['RETURN_SUCEESS']);
				}
				else if($re==-1)
				{
					showmsg($lang['PAGE-LANG-4']);
				}
				else
				{
					showmsg($lang['RETURN_ERROR']);
				}
			}
			require DIRCMS_ROOT.'/include/options.class.php';
			$options=new options();

			$template=glob(DIRCMS_ROOT.'template/'.TLP_NAME.'/*.html');

			require DIRCMS_ROOT.'/include/form.class.php';
			$form=new form();
			
			$info=$page->pageallinfo($id);
			$info['setting']=string2array($info['setting']);
			include admin_tlp('page_edit');
			break;
		case 'setismenu':
			if($page->setismenu($id,$ismenu))
			{
				showmsg($lang['RETURN_SUCEESS']);
			}
			else
			{
				showmsg($lang['RETURN_ERROR']);
			}
			break;
		case 'delete':
			$page->delete($id);
			$c->cache_category();
			showmsg($lang['RETURN_SUCEESS']);	
			break;
	}
?>