<?php
	!defined('DIRCMS_MANAGE') && exit('Access Denied!');
	$r=cache_read('module.cache.php',DIRCMS_ROOT.'data/cache_module/');
	$r=$r['guestbook']['roleid']; 
	if(!in_array($_roleid,$r) && $_userid!=ADMIN_FOUNDERS)showmsg_nourl('您没有该操作的权限!');
	$action=empty($action)?'manage':trim($action);
	require_once(DIRCMS_ROOT.'include/list.class.php');
	$l=new dircmslist();
	require_once(DIRCMS_ROOT.'include/form.class.php');	
	$form=new form();
	switch($action)
	{
		case 'manage':
			if($do_submit)
			{
				if(!$id)showmsg('请选择需要删除的留言!');
				$id=!is_array($id)?array($id):$id;
				$db->mysql_delete(DB_PRE.'guestbook',array_map('intval',$id));
				showmsg($LANG['MANAGE_SUCEESS'],ADMIN_FILE.'?file=guestbook&action=manage');
			}
			$where=1;
			$where=isset($hidden)?$where." AND hidden=".intval($hidden):$where;
			$where=isset($passed)?$where." AND passed=".intval($passed):$where;
			$k=trim(preg_replace('/[!@#\$%\^&\*\(\):\'\"\{\}\[\]\.\?\,\/`\;]+/i','',$k));
			$where=!empty($k)?$where." AND content like '%".$k."%'":$where;
			$orderby="id DESC";
			$page=max(isset($page)?intval($page):1,1);
			$result=$l->getlist(DB_PRE.'guestbook',$where,$orderby,$page,15);
			$pages=$l->pages;
			include admin_tlp('guestbook_manage');	
			break;
		case 'delete':
			if(!$id)showmsg('请选择需要删除的留言!');
			$id=!is_array($id)?array($id):$id;
			$db->mysql_delete(DB_PRE.'guestbook',array_map('intval',$id));
			showmsg($LANG['MANAGE_SUCEESS'],ADMIN_FILE.'?file=guestbook&action=manage');
			break;
		case 'pass':
			if(!$id)showmsg('请选择需要审核的留言!');
			$id=!is_array($id)?array($id):$id;
			$db->update(DB_PRE.'guestbook',array('passed'=>intval($passed)),'id IN('.implode(',',array_map('intval',$id)).')');
			showmsg($LANG['MANAGE_SUCEESS'],ADMIN_FILE.'?file=guestbook&action=manage');
			break;
		case 'hidden':
			$hidden=intval($hidden);
			$db->update(DB_PRE.'guestbook',array('hidden'=>$hidden),'id ='.intval($id));
			showmsg($LANG['MANAGE_SUCEESS'],ADMIN_FILE.'?file=guestbook&action=manage');
			break;
		case 'reply':
			if($do_submit)
			{
				$info['replyer']=$_username;
				$info['replytime']=TIME;
				$db->update(DB_PRE.'guestbook',$info,'id ='.intval($id));
				showmsg($LANG['MANAGE_SUCEESS'],ADMIN_FILE.'?file=guestbook&action=manage');
			}
			include admin_tlp('guestbook_reply');
			break;
	}
?>
