<?php
	!defined('IN_MANAGE') && exit('Access Denied!');
	$action=empty($action)?'manage':trim($action);
	$moduleid=$moduleobj->getmoduleid($mod);
	$settings=$configobj->getconfig($_SESSION['siteid'],$moduleid);

	switch($action)
	{
		case 'role':
			if(isset($job))
			{
				if($job=='edit')
				{
					if(isset($do_submit))
					{
						if($adminobj->role_edit($info,$id))
						{
							admin_success($adminlang['manage_success']);
						}
						else
						{
							admin_error($adminlang['manage_error']);
						}
					}
					$info=$adminobj->getrole($id);
					include admin_tlp('admin-role-edit');
				}
			}
			else
			{
				$result=$adminobj->rolelist();
				include admin_tlp('admin-role');
			}
			break;
		case 'manage':
			if(isset($job))
			{
				if($job=='edit')
				{
					if(isset($do_submit))
					{
						if(!preg_match('/^[\x80-\xff_a-zA-Z0-9]{1,64}$/i',$info['username']))
						{
							showjsmsg('管理账号格式不正确！');
						}

						if(preg_match('/[\x80-\xff]/i',$info['password']) && trim($info['password']))
						{
							showjsmsg('登陆密码格式不正确！');
						}

						if($adminobj->getbyusername($info['username']) && $info['username']!=$_username)
						{
							admin_error('管理员账号已存在请更换！');
						}
						
						if($adminobj->admin_edit($info,$id))
						{
							admin_success($adminlang['manage_success']);
						}
						else
						{
							admin_error($adminlang['manage_error']);
						}
					}
					$info=$adminobj->get($id);
					$admrole=$configobj->getadminrole();
					$sitelist=$siteidobj->sitelist();
					include admin_tlp('admin-edit');
				}
				else if($job=='add')
				{
					if(isset($do_submit))
					{
						if(!preg_match('/^[\x80-\xff_a-zA-Z0-9]{1,64}$/i',$info['username']))
						{
							showjsmsg('管理账号格式不正确！');
						}

						if(preg_match('/[\x80-\xff]/i',$info['password']) && trim($info['password']))
						{
							showjsmsg('登陆密码格式不正确！');
						}

						if($adminobj->getbyusername($info['username']))
						{
							admin_error('管理员账号已存在请更换！');
						}
						
						if($adminobj->admin_add($info))
						{
							admin_success($adminlang['manage_success']);
						}
						else
						{
							admin_error($adminlang['manage_error']);
						}
					}
					$admrole=$configobj->getadminrole();
					$sitelist=$siteidobj->sitelist(1);
					include admin_tlp('admin-add');
				}
				else if($job=='delete')
				{
					if($adminobj->admin_delete($id))
					{
						admin_success($adminlang['manage_success']);
					}
					else
					{
						admin_error($adminlang['manage_error']);
					}
				}
				else if($job=='set')
				{
					if($adminobj->admin_set($id,$status))
					{
						admin_success($adminlang['manage_success']);
					}
					else
					{
						admin_error($adminlang['manage_error']);
					}
				}
			}
			else
			{
				$result=$adminobj->adminlist(isset($roleid)?intval($roleid):-1);
				include admin_tlp('admin-manage');
			}
			break;
		case 'log':
			if(isset($job))
			{
				if($job=='delete')
				{
					if($adminobj->log_delete($id))
					{
						admin_success($adminlang['manage_success']);
					}
					else
					{
						admin_error($adminlang['manage_error']);
					}
				}
			}
			else
			{
				$result=$adminobj->loglist();
				include admin_tlp('admin-log');
			}
			break;
	}
?>