<?php 

require(ROOT_PATH.'/include/Action.php');

class Action extends mainAction
{
	
	public $adminid		= 0;
	public $adminname	= '';
	public $adminrs;
	public $admintype	= 0;
	public $loginback	= '';
	public $maxwidth 	= '80%';
	public $deflogin 	= '?m=login';//默认登录页地址
	
	public $lang 		= 'zh-CN';//当前语言
	
	
	public function loginCheck()
	{
		$loginbo  = false;
		if($this->adminid>0){
			$dlur = m('login')->getone("`uid`='$this->adminid'");
			if($dlur){
				$loginbo = true;
			}
		}
		if(!$loginbo){
			if($this->adminid>0)m('login')->exitlogin();
			$url = $this->deflogin;
			if($this->loginback)$url.='&backurl='.$this->jm->base64encode($this->loginback).'';
			$this->rock->location($url);
			return;
		}
		$this->getAdmininfo($this->adminid);
	}
	
	public function initProject()
	{
		$this->assign('maxwidth', getconfig('maxwidth', $this->maxwidth));
		$this->adminid		= (int)$this->getsession('adminid',0);
		$this->loginCheck();
	}
	
	public function getAdmininfo($uid)
	{
		$this->adminid  = $uid;
		$this->adminrs	= m('users')->getone("`id`='$uid' and `status`=1");
		if(!$this->adminrs)$this->showreturn('','无效登录了', 199);
		$this->adminrs['face'] = m('users')->getface($this->adminrs['face']);
		$this->admintype= $this->adminrs['type'];
		$this->adminname= $this->adminrs['name'];
		$this->rock->adminid 	= $this->adminid;
		$this->rock->adminname 	= $this->adminname;
		$this->assign('adminrs', $this->adminrs);
	}
	
	public function returnerror($msg='')
	{
		return returnerror($msg);
	}
	
	public function returndata($data=array())
	{
		return returnsuccess($data);
	}
	
	
	
	public function savecellAction()
	{
		$tab 	= (int)$this->post('tablename','0');
		$id 	= (int)$this->post('id','0');
		$fields = $this->post('fieldname');
		$value 	= $this->post('value');
		$tabla	= array('agent','users','wenti');
		$table  = arrvalue($tabla, $tab);
		if(isempt($table) || $id<=0)return returnsuccess('没有找到表');
		m($table)->update(array($fields => $value), $id);	
		return returnsuccess();
	}
	
	public function deljiluAction()
	{
		$tab 	= (int)$this->post('tablename','0');
		$id 	= (int)$this->post('id','0');
		$tabla	= array('agent','users','wenti');
		$table  = arrvalue($tabla, $tab);
		if(isempt($table) || $id<=0)return returnsuccess('没有找到表');
		m($table)->delete($id);	
		return returnsuccess();
	}
}

class ActionNot extends Action
{
	public function loginCheck()
	{
		
	}
}