<?php
class AdminAction extends Action {
	function _initialize(){
		if(!$_SESSION['NR_ADMIN_ID']){
			$this->error('请先登录!','/Admin_login.html',3);
		}
    }
    public function index(){
        $this->display();
    }
	function settings(){
		if(isset($_POST['sub'])){
			$html   = new UserModel();
			if($_POST['webname'] != C('WEB_TITLE')){
				$html->strconf("WEB_TITLE",C('WEB_TITLE'),$_POST['webname']);
				$this->success('修改成功!','',3);
			}
			if($_POST['keywords'] != C('WEB_KEYWORDS')){
				$html->strconf("WEB_KEYWORDS",C('WEB_KEYWORDS'),$_POST['keywords']);
				$this->success('修改成功!','',3);
			}
			if($_POST['description'] != C('WEB_DESCRIPTION')){
				$html->strconf("WEB_DESCRIPTION",C('WEB_DESCRIPTION'),$_POST['description']);
				$this->success('修改成功!','',3);
			}
			if($_POST['tongji'] != C('WEB_TONGJI')){
				$html->strconf("WEB_TONGJI",C('WEB_TONGJI'),$_POST['tongji']);
				$this->success('修改成功!','',3);
			}
		}
		$this->display();
	}
	function user(){
		$User = M("user"); 
		import("ORG.Util.Page"); // 导入分页类
		$count = $User->count(); 
		$Page  = new Page($count,12);
		$show  = $Page->show(); // 分页显示输出
		$list  = $User->order("id desc")->limit($Page->firstRow.','.$Page->listRows)->select();
		$this->assign("user",$list);
		$this->assign("page",$show);
		$this->display();
	}
	function forum(){
		$User = M("forum"); 
		import("ORG.Util.Page"); // 导入分页类
		$count = $User->count(); 
		$Page  = new Page($count,12);
		$show  = $Page->show(); // 分页显示输出
		$list  = $User->order("id desc")->limit($Page->firstRow.','.$Page->listRows)->select();

		$this->assign("forum",$list);
		$this->assign("page",$show);
		$this->display();
	}
	function fclass(){
		$cate=M('memu');
		$memu=$cate->field("id,fid,title,path,concat(path,'-',id) as bpath")->order('bpath')->select();
		foreach($memu as $key=>$value){
			$memu[$key]['count']=count(explode('-',$value['bpath']));
		}
		$this->assign("memu",$memu);
		$this->display();
	}
	function password(){
		$this->display();
	}
	function isok(){
		if($_GET['id']){
			$id  = $_GET['id'];
			M("user")->where('id= '.$id)->setInc('isok');
			$this->success('锁定成功!','',3);
		}elseif($_GET['sid']){
			$sid = $_GET['sid'];
			M("user")->where('id= '.$sid)->setDec('isok');
			$this->success('解锁成功!','',3);
		}else{
			exit();
		}
	}
	function delforum(){
		if(!$_GET['id']){
			exit();
		}
		M("forum")->delete($_GET['id']);
		M("user_date")->where('uid= '.$_GET['uid'])->setDec('money',5);
		M("reply")->where("fid = ".$_GET['id'])->delete();
		$this->success('删除成功!','/Main.html',3);
	}
	function deluser(){
		if(!$_GET['id']){
			exit();
		}
		M("user")->delete($_GET['id']);
		M("user_date")->where("uid = ".$_GET['id'])->delete();
		if(file_exists("Uploads/avatar/".$_GET['id']."_big.jpg")){
			unlink("Uploads/avatar/".$_GET['id']."_big.jpg");
			unlink("Uploads/avatar/".$_GET['id']."_middle.jpg");
			unlink("Uploads/avatar/".$_GET['id']."_small.jpg");
		}
		$this->success('删除成功!','',3);
	}
	function edclass(){
		if(!$_GET['id']){
			exit();
		}
		if($_POST['submit']){
			$date['title'] = $_POST['title'];
			M("memu")->where("id = ".$_GET['id'])->save($date);
			$this->success('修改成功!','/Admin_fclass.html',3);
		}
		$m = M("memu")->select($_GET['id']);
		$this->assign("m",$m);
		$this->display();
	}
	function delclass(){
		if(!$_GET['id']){
			exit();
		}
		$f = M("forum")->where("memu = ".$_GET['id'])->count();
		if($f){
			$this->error('删除失败，该分类下还有 '.$f.' 条话题!','/Admin_fclass.html',3);
		}else{
			M("memu")->delete($_GET['id']);
			$this->success('删除成功!','',3);
		}
	}
	function addclass(){
		if($_POST['submit']){
			if($_POST['fid'] != 0){
				$f = M("memu")->where("fid = ".$_POST['fid'])->count();
				$path = "0-".$_POST['fid'];
				$date['title']		= $_POST['title'];
				$date['fid']		= $_POST['fid'];
				$date['path']		= $path;
				M("memu")->add($date);
				$this->success('添加成功!','',3);
			}else{
				$date['title']		= $_POST['title'];
				$date['path']		= 0;
				M("memu")->add($date);
				$this->success('添加成功!','',3);
			}
		}
		$m = M("memu")->where("fid = 0")->select();
		$this->assign("m",$m);
		$this->display();
	}
	function xunzhang(){
		$User = M("xunzhang_list"); 
		import("ORG.Util.Page"); // 导入分页类
		$count = $User->count(); 
		$Page  = new Page($count,6);
		$show  = $Page->show(); // 分页显示输出
		$list  = $User->order("id desc")->limit($Page->firstRow.','.$Page->listRows)->select();

		$this->assign("xz",$list);
		$this->assign("page",$show);
		$this->display();
	}
	function addxz(){
		if($_POST['submit']){
			$date['url']  	= $_POST['img'];
			$date['about']  = $_POST['title'];
			M("xunzhang_list")->add($date);
			$this->success('添加成功!','',3);
		}
		$this->display();
	}
	function xzdata(){
		$User = M("xunzhang"); 
		import("ORG.Util.Page"); // 导入分页类
		$count = $User->count(); 
		$Page  = new Page($count,6);
		$show  = $Page->show(); // 分页显示输出
		$list  = $User->order("id desc")->limit($Page->firstRow.','.$Page->listRows)->select();

		$this->assign("xz",$list);
		$this->assign("page",$show);
		$this->display();
	}
	function bfxz(){
		if($_GET['cid']){
			M("xunzhang")->delete($_GET['cid']);
			$this->success('取消成功!','',3);
			exit();
		}elseif($_GET['did']){
			M("xunzhang_list")->delete($_GET['did']);
			$this->success('删除成功!','',3);
		}elseif($_GET['id']){
			if($_POST['submit']){
				$x = M("xunzhang")->where("uid = ".$_POST['uid']." and imgid = ".$_GET['id'])->count();
				if(!$x){
					$date['uid'] 	= $_POST['uid'];
					$date['imgid']	= $_GET['id'];
					$date['date']   = time();
					M("xunzhang")->add($date);
					$this->success('颁发成功!','/Admin_xzdata.html',3);
				}else{
					$this->success('请勿重复颁发!','/Admin_xzdata.html',3);
				}
			}
			$this->display();
		}
	}
}
?>