array () );
	
	private $userinfo = array ('uid' => '0' );
	
	function __construct() {
		
		//parent::__construct ();
		
		Load::controller ( "BaseController" );
		$base = new BaseController ();
		
		$rs = $base->admin_init ();
		
		$this->userinfo = $rs ['userinfo'];
		
		$this->menu = $rs ['menu'];
		Load::logic ( 'User' );
		Load::logic ( 'Ask' );
		Load::logic ( 'Admin' );
		
		$this->userlogic = new UserLogic ();
		$this->asklogic = new AskLogic ();
		$this->adminlogic = new AdminLogic ();
		
	}
	
	/**
	 * 进入后台登录页面
	 */
	function login() {
		$data ['user_info'] = $this->userinfo;
		$this->render ( '/admin/login', $data );
	}
	
	/**
	 * 用户登出
	 */
	function admin_user_exit() {
		setcookie ( "auth_main", "", time () + 3600 * 24, "/", COOKIE_WEB_SITE );
		$this->Messager ( "登出成功", "/" );
	}
	
	/**
	 * 进入后台
	 */
	function do_login() {
		
		$data ['name'] = $this->get_args ( 'name' );
		
		$data ['password'] = $this->get_args ( 'password' );
		
		$user = $this->userlogic->get_users_by_name ( $data ['name'] );
		
		require_once (SITE_PATH . '/protected/plugin/client.php');
		
		$client = new client ( ZHSSO );
		
		$is_login = $client->zhsso_member_login ( $data ['name'], $data ['password'] );
		$is_login = explode ( "\r", $is_login );
		
		if (is_numeric ( $is_login [0] )) {
			if ($is_login [0] == USERNAME_ONFINE) {
				
				$this->Messager ( "您输入的帐号或者密码有误", "/login" );
				
				//删除用户相关记录--是否有同步删除功能
				if ($user) {
					//$this->userlogic->delete_user_tem( $user['uid']);
				}
			} elseif ($is_login [0] == PASSWORD_ERROR)
				$this->Messager ( "您输入的帐号或者密码有误", "/login" );
			elseif ($is_login [0] == - 3) //USER_NOACTION
				$this->Messager ( "用户未激活", "http://sso.smartcost.com.cn/" );
		} elseif (! empty ( $is_login [0] )) {
			$group = $this->userlogic->get_group_by_id ( $user ['groupid'] );
			if ($group ['grouptype'] != 1) {
				
				setcookie ( "auth_main", "", time () + 3600 * 24, "/", COOKIE_WEB_SITE );
				header ( 'Content-Type:text/html;charset=utf-8' );
				@header ( "Location: " . WEB_SITE . "/messager?content=无权进入后台&url=/" );
			}
			
			$userinfo = authcode ( $user ['username'], "tr" );
			
			setcookie ( "auth_main", $userinfo, time () + 3600 * 24, "/", COOKIE_WEB_SITE );
			
			//define ( 'MEMBER_NAME', $user ['username'] );
			
			//define ( "MASTER_ID", $user ['uid'] );
			
			$data ['now'] = 'use';
			
			$data ['li'] = $this->menu ['navon'];
			
			$data ['map'] = '';
			
			header ( 'Content-Type:text/html;charset=utf-8' );
			@header ( "Location: " . WEB_SITE . "/index/main_navon" );
		}
	
		//		//对登录用户认证
	//		if (empty ( $data ['name'] ) || empty ( $data ['password'] ) || $user_info ['username'] != $data ['name'] || $user_info ['password'] != md5 ( $data ['password'] )) {
	//			
	//			$this->Messager ( "请输入正确的账号密码", "/index/main_admin" );
	//		} else {
	//			//登录成功-写入session
	//			$data ['now'] = 'use';
	//			
	//			$data ['li'] = $this->menu ['navon'];
	//			
	//			$data ['map'] = '';
	//			
	//			$this->render ( '/admin/index', $data );
	//		
	//		}
	}
	
	/**
	 * 常用操作
	 */
	function navon() {
		$data ['now'] = 'use';
		
		$list=$this->adminlogic->get_examine_list();
		
		if(!empty($list)){
			$this->menu ['navon'][4]='审批问题 '.count($list).'';
		}
		
		
		$data ['li'] = $this->menu ['navon'];
		
		$data ['map'] = '';
		
		$this->render ( '/admin/index', $data );
	}
	
	/**
	 * 获取后台欢迎页
	 */
	function welcome() {
		
		$this->render ( '/admin/welcome' );
	}
	
	/**
	 * 获取用户管理
	 */
	function user_manage() {
		$u = "";
		$n = "";
		$e = "";
		$i = "";
		$t = "";
		
		$on_page = is_numeric ( $this->params ['on_page'] ) ? $this->params ['on_page'] : 1;
		
		if ($on_page <= 0)
			$on_page = 1;
		
		$uid = $this->get_args ( 'uid' );
		
		$uid = is_numeric ( $uid ) ? $uid : 0;
		
		$name = $this->get_args ( 'name' );
		
		$email = $this->get_args ( 'email' );
		
		$regip = $this->get_args ( 'regip' );
		
		$srchregdatestart = $this->get_args ( 'srchregdatestart' );
		
		$srchregdateend = $this->get_args ( 'srchregdateend' );
		
		$page_size = 18;
		//检索条件
		if ($uid)
			$u = " and uid=" . $uid;
		if (! empty ( $name ))
			$n = " and username like '%" . $name . "%'";
		if (! empty ( $email ))
			$e = " and email like '%" . $email . "%'";
		if (! empty ( $regip ))
			$e = " and regip like '%" . $regip . "%'";
		if (! empty ( $srchregdatestart ) && ! empty ( $srchregdateend )) {
			
			$srchregdatestart = get_time ( $srchregdatestart );
			
			$srchregdateend = get_time ( $srchregdateend );
			
			$t = " and regtime between " . $srchregdatestart . " and " . $srchregdateend;
		}
		
		$condition = " and uid!= 1 " . $u . $n . $e . $i . $t;
		
		$action = "/index/main_user_manage/";
		
		//获取分页相关数据
		$page = $this->adminlogic->get_page ( t_user, $condition, $on_page, $page_size, $action, "", "admin" );
		
		$limit = " order by regtime desc limit " . $page ['lower'] . " , " . $page_size . " ";
		
		$page ['user_list'] = $this->userlogic->get_users_list ( array (), $condition, $limit );
		
		$data ['map'] = '用户管理';
		
		$data ['user'] = $page;
		
		$this->render ( '/admin/user_manage', $data );
	}
	
	/**
	 * 添加用户-需要推送用户到通行证
	 */
	function user_manage_add() {
		
		$data ['map'] = '用户管理 » 添加用户';
		
		$this->render ( '/admin/user_manage_add', $data );
	}
	
	/**
	 * 进入编辑用户基本信息
	 */
	function user_manage_edit() {
		$uid = $this->check_params ( "uid" );
		
		if (is_numeric ( $uid )) {
			if ($uid == SUPER_ADMIN_UID || $uid <= 0) {
				echo "请输入正确请求";
				die ();
			}
		} else {
			echo "请输入正确请求";
			die ();
		}
		
		$data ['user'] = $this->userlogic->get_users_information ( $uid );
		
		$data ['group'] = $this->userlogic->get_group ();
		
		$data ['categoryinfo'] = $this->asklogic->get_category_list ();
		
		$data ['map'] = '用户管理 » 编辑用户';
		
		$data ['success'] = "";
		
		$this->render ( '/admin/user_manage_edit', $data );
	}
	
	/**
	 * 修改用户信息
	 */
	function user_manage_update() {
		
		$params ['uid'] = $this->get_args ( 'uid' );
		
		$params ['password'] = $this->get_args ( 'password' );
		
		$confirmpw = $this->get_args ( 'confirmpw' );
		
		$params ['email'] = $this->get_args ( 'email' );
		
		$params ['groupid'] = $this->get_args ( 'groupid' );
		
		$params ['credits'] = $this->get_args ( 'credits' );
		
		$params ['credit1'] = $this->get_args ( 'credit1' );
		
		$params ['gender'] = $this->get_args ( 'gender' );
		
		$params ['bday'] = $this->get_args ( 'bday' );
		
		$params ['phone'] = $this->get_args ( 'phone' );
		
		$params ['qq'] = $this->get_args ( 'qq' );
		
		$params ['msn'] = $this->get_args ( 'msn' );
		
		$params ['signature'] = $this->get_args ( 'signature' );
		
		$params ['expert'] = $this->get_args ( 'expert' );
		
		$params ['cids'] = json_encode ( $_POST ['cids'] );
		
		if ($params ['password'] != $confirmpw) {
			echo "密码不一致";
			die ();
		}
		
		if (is_numeric ( $params ['uid'] )) {
			if ($params ['uid'] == SUPER_ADMIN_UID || $params ['uid'] <= 0) {
				echo "请输入正确请求";
				die ();
			}
		} else {
			echo "请输入正确请求";
			die ();
		}
		
		$this->userlogic->update_user ( $params );
		
		$data ['user'] = $this->userlogic->get_users_information ( $params ['uid'] );
		
		$data ['group'] = $this->userlogic->get_group ();
		
		$data ['map'] = '用户管理 » 编辑用户';
		
		$data ['success'] = "编辑成功";
		
		header ( 'Content-Type:text/html;charset=utf-8' );
		@header ( "Location: /index/main_user_manage_edit/" . $params ['uid'] );
	
	}
	
	/**
	 * 删除用户
	 */
	function user_manage_delete() {
		$type = $this->check_params ( "type" );
		
		$uid = $this->get_args ( 'uid' );
		
		if ($type == "all") {
			$this->userlogic->delete_user_and_QA ( $uid );
		} else {
			$this->userlogic->delete_user ( $uid );
		}
		
		Header ( "Location:/index/main_user_manage" );
	}
	
	/**
	 * 用户积分明细
	 */
	function user_manage_credit() {
		$uid = $this->check_params ( "uid" );
		
		$data ['map'] = '用户管理 » 用户积分明细';
		
		$data ['creditList'] = $this->asklogic->get_credit_details ( $uid );
		
		$this->render ( '/admin/user_manage_credits', $data );
	}
	
	/**
	 * 专家用户
	 */
	function user_manage_expert() {
		
		$data ['map'] = '专家管理 ';
		
		$param ['expert'] = 1;
		
		$data ['userExpert'] = $this->userlogic->get_users_list ( $param, '', "" );
		
		$this->render ( '/admin/user_manage_expert', $data );
	}
	
	/**
	 * 进入用户组管理
	 */
	function group_manage() {
		
		$data ['group'] = $this->userlogic->get_group ();
		
		$data ['map'] = '用户组管理 ';
		
		$data ['success'] = "";
		
		$this->render ( '/admin/group_manage', $data );
	}
	
	/**
	 * 用户组管理-添加
	 */
	function group_manage_add() {
		
		$params ['grouptitle'] = $this->get_args ( 'grouptitle' );
		
		if (empty ( $params ['grouptitle'] ))
			die ( '用户组名称为空' );
		
		$this->userlogic->add_group ( $params );
		
		$data ['group'] = $this->userlogic->get_group ();
		
		$data ['map'] = '用户组管理 ';
		
		$data ['success'] = "添加成功";
		
		$this->render ( '/admin/group_manage', $data );
	}
	
	/**
	 * 用户组管理-编辑
	 */
	function group_manage_edit() {
		
		$params ['groupid'] = $this->get_args ( 'groupid' );
		
		$params ['grouptitle'] = $this->get_args ( 'grouptitle' );
		
		$params ['creditslower'] = $this->get_args ( 'scorelower' );
		
		$this->userlogic->update_group_list ( $params );
		
		$data ['group'] = $this->userlogic->get_group ();
		
		$data ['map'] = '用户组管理';
		
		$data ['success'] = "编辑成功 ";
		
		$this->render ( '/admin/group_manage', $data );
	}
	
	/**
	 * 用户组管理-删除
	 */
	function group_manage_delete() {
		
		$groupid = $this->check_params ( "groupid" );
		
		if (is_numeric ( $groupid )) {
			if ($groupid == SUPER_ADMIN_ID || $groupid <= 0) {
				echo "请输入正确请求";
				die ();
			}
		} else {
			echo "请输入正确请求";
			die ();
		}
		
		$this->userlogic->delete_group ( $groupid );
		
		$data ['group'] = $this->userlogic->get_group ();
		
		$data ['map'] = '用户组管理 ';
		
		$data ['success'] = "删除成功 ";
		
		$this->render ( '/admin/group_manage', $data );
	}
	
	/**
	 * 用户组管理-权限设置 
	 */
	function group_manage_set() {
		$data ['map'] = '用户组权限设置 ';
		
		$data ['success'] = " ";
		
		$data ['groupid'] = $this->check_params ( 'groupid' );
		
		$data ['group'] = $this->userlogic->get_group_by_id ( $data ['groupid'] );
		
		$data ['PERMISSIONS'] = Doo::conf ()->PERMISSIONS_ACTION;
		include SITE_PATH . '/protected/config/permissions.conf.php';
		
		$data ['PERMISSIONS_user'] = "";
		
		if (isset ( $config ['GENERAL_USER_lv' . $data ['groupid']] ))
			$data ['PERMISSIONS_user'] = $config ['GENERAL_USER_lv' . $data ['groupid']];
		
		$this->render ( '/admin/group_manage_set', $data );
	}
	
	/**
	 * 为用户组设置权限
	 */
	function group_manage_update_set() {
		$permissions=$this->get_args('permissons_key');
		
		$b=array('##USER7','##/USER7');
		
		$Content="
\$config['GENERAL_USER_lv7']=array('index', 
'show_ask_page', 
'login', 
'show_into_home', 
'show_home_answer', 
'show_home_question', 
'do_login', 
'upload_question_img', 
'show_home_per_info', 
'show_home_avatar', 
'show_home_message', 
'show_vip_ask_post', 
'show_ask_post', 
'show_post_enter', 
'show_search', 
'do_support_answer', 
'do_edit_answer', 
'do_edit_question', 
'do_up_price', 
'do_add_supply', 
'upload_avatar', 
'do_update_vip_question', 
'do_add_vip_question', 
'do_delete_answer', 
'do_delete_question', 
'do_question_close', 
'do_update_user_info', 
'do_update_avatar', 
'answer_again', 
'do_reply_question', 
'to_ask_question', 
'do_add_vip_question', 
'do_add_question',
'show_advisory_page',
'user_exit',
//编辑问题
'do_edit_vip_question',
//设置满意
'set_vip_question_satisfy',
//设置不满意
'set_vip_question_nosatisfy',
//追加回答
'do_add_vip_tag', 
//评价回答
'do_comment_vip_answer',
//添加评论
'do_add_discuss',
//获取退款机会
'get_vip_refunds',
//交易
'show_my_pay_oder', 
//充值
'show_my_recharge',
//登录
'do_login_index',
//充值记录
'show_recharge_oder',
//编辑邮件
'do_add_email_config',
'do_best_answer',
'show_article_page',
'show_messager',
'show_tip2',
'get_search_works',
);
";
		$Content="fsdfsdfsdfwerewr";
		preg_match("(.*)",$Content,$kk);
		//ereg_replace("PHP","",$temp)
		//preg_replace("^##USER7 ##USER7$", " \$config['GENERAL_USER_lv7']=array() ", $Content);
		
		echo $kk;
		
//		foreach ($permissions as $value){
//			
//		}
		
		//print_r($permissions);
	}
	
	/**
	 * 进去问题管理-
	 */
	function question_manage() {
		
		$u = "";
		$n = "";
		$e = "";
		$i = "";
		$t = "";
		
		$on_page = $this->check_params ( 'on_page' );
		
		$on_page = is_numeric ( $on_page ) ? $on_page : 1;
		
		$authorid = $this->get_args ( 'authorid' );
		
		$title = $this->get_args ( 'title' );
		
		$status = $this->get_args ( 'status' );
		
		$srchregdatestart = $this->get_args ( 'srchregdatestart' );
		
		$srchregdateend = $this->get_args ( 'srchregdateend' );
		
		$page_size = 18;
		//检索条件
		if ($authorid)
			$u = " and author like '%" . $authorid . "%'";
		if (! empty ( $title ))
			$n = " and title like '%" . $title . "%'";
		if ($status >= 1)
			$e = " and status = " . $status;
		if (! empty ( $srchregdatestart ) && ! empty ( $srchregdateend )) {
			
			$srchregdatestart = get_time ( $srchregdatestart );
			
			$srchregdateend = get_time ( $srchregdateend );
			
			$t = " and time between " . $srchregdatestart . " and " . $srchregdateend;
		}
		
		$condition = ' and 1 ' . $u . $n . $e . $i . $t;
		
		$action = "/index/main_question_manage/";
		
		$get = "?status=" . $status . "&authorid=" . $authorid . "&title=" . $title . "&srchregdatestart=" . $srchregdatestart . "&srchregdateend=" . $srchregdateend;
		
		//获取分页相关数据
		$page = $this->adminlogic->get_page ( t_question, $condition, $on_page, $page_size, $action, $get, "admin" );
		
		$limit = " order by time desc limit " . $page ['lower'] . " , " . $page_size . " ";
		
		$data ['category'] = $this->asklogic->get_category_list ();
		
		$page ['question_list'] = $this->asklogic->get_questions_list_tem ( array (), $condition, $limit );
		
		$data ['question'] = $page;
		
		$data ['status'] = $status;
		$data ['authorid'] = $authorid;
		$data ['title'] = $title;
		$data ['srchregdatestart'] = $srchregdatestart;
		$data ['srchregdateend'] = $srchregdateend;
		
		$data ['map'] = '问题管理 ';
		
		$data ['success'] = " ";
		
		$this->render ( '/admin/question_manage', $data );
	}
	
	/**
	 * 移动问题分类
	 */
	function question_manage_move_category() {
	
	}
	
	/**
	 * 批量关闭问题
	 */
	function question_manage_close() {
		
		$id = $this->get_args ( 'id' );
		
		$status = array ();
		
		$params ['id'] = $id;
		
		for($i = 0; $i < count ( $id ); $i ++) {
			array_push ( $status, 9 );
		}
		
		$params ['status'] = $status;
		
		$this->userlogic->update_list ( $params, t_question, "id" );
		
		Header ( "Location:/index/main_question_manage" );
	}
	
	/**
	 * 批量删除问题
	 */
	function question_manage_delete() {
		
		$id = $this->get_args ( 'id' );
		
		if (empty ( $id ))
			return "/index/main_question_manage";
		
		//推广
		//;$id = implode ( ",", $id );
		$fundstr=file_get_contents(SITE_PATH . '/protected/config/fund.conf.php') ;
		
		if($fundstr){
			
			foreach ($id as $value){
				Doo::loadModel ( 'QuestionDao' );
				
				$questionDao = new QuestionDao ();
				
				$question=$questionDao->get_question_by_id($value);
				
				if($question['price']==1&&$question['status']=1){
					Doo::loadModel ( 'FundDao' );
				
					$funddao = new FundDao ();
					
					$fund=$funddao->get_fund_by_amount();
					
					if(!empty($fund)){
						$funddao->set_fund_amount_spread("+1",$fund['id']);
					}
				}
			}
		
		}
		$this->userlogic->delete_question_list ( $id );
		
		Header ( "Location:/index/main_question_manage" );
	}
	
	/**
	 * 批量设置问题为待解决
	 */
	function question_manage_set_status() {
		//只针对已关闭的问题进行操作--是否还有RMB问题
		$id = $this->get_args ( 'id' );
		
		$this->userlogic->update_question_list ( $id );
		
		return "/index/main_question_manage";
	}
	
	/**
	 * 进去回答管理-
	 */
	function answer_manage() {
		
		$u = "";
		$n = "";
		$e = "";
		$i = "";
		$t = "";
		
		$on_page = $this->check_params ( 'on_page' );
		
		$on_page = is_numeric ( $on_page ) ? $on_page : 1;
		
		$authorid = $this->get_args ( 'author' );
		
		$title = $this->get_args ( 'title' );
		
		$srchregdatestart = $this->get_args ( 'srchregdatestart' );
		
		$srchregdateend = $this->get_args ( 'srchregdateend' );
		
		$page_size = 18;
		//检索条件
		if ($authorid)
			$u = " and author like '%" . $authorid . "%'";
		if (! empty ( $title ))
			$n = " and title like '%" . $title . "%'";
		
		if (! empty ( $srchregdatestart ) && ! empty ( $srchregdateend )) {
			
			$srchregdatestart = get_time ( $srchregdatestart );
			
			$srchregdateend = get_time ( $srchregdateend );
			
			$t = " and time between " . $srchregdatestart . " and " . $srchregdateend;
		}
		
		$condition = $u . $n . $t;
		
		$action = "/index/main_answer_manage/";
		
		$get = "?author=" . $authorid . "&title=" . $title . "&srchregdatestart=" . $srchregdatestart . "&srchregdateend=" . $srchregdateend;
		
		//获取分页相关数据
		$page = $this->adminlogic->get_page ( t_answer, $condition, $on_page, $page_size, $action, $get, "admin" );
		
		$limit = " order by time desc limit " . $page ['lower'] . " , " . $page_size . " ";
		
		$data ['category'] = $this->asklogic->get_category_list ();
		
		$answer_list = $this->asklogic->get_answers_list_tem ( array (), $condition, $limit );
		
		foreach ( $answer_list as $key => $value ) {
			
			$answer_list [$key] ['content'] = strip_tags ( $value ['content'] );
		}
		
		$page ['answer_list'] = $answer_list;
		
		$data ['answer'] = $page;
		
		$data ['author'] = $authorid;
		$data ['title'] = $title;
		$data ['srchregdatestart'] = $srchregdatestart;
		$data ['srchregdateend'] = $srchregdateend;
		
		$data ['map'] = '回答管理 ';
		
		$data ['success'] = " ";
		
		$this->render ( '/admin/answer_manage', $data );
	}
	
	/**
	 * 回答管理-删除回答
	 */
	function answer_manage_delete() {
		$data ['map'] = '回答管理 ';
		
		$data ['success'] = " ";
		
		$id = $this->get_args ( 'id' );
		
		if (empty ( $id ))
			return "/index/main_answer_manage";
		
		$this->userlogic->delete_answer_list ( $id );
		
		return "/index/main_answer_manage";
	}
	
	/**
	 * 名师答疑管理
	 */
	function vip_question_manage() {
		
		$u = "";
		$n = "";
		$e = "";
		$i = "";
		$t = "";
		
		$on_page = $this->check_params ( 'on_page' );
		
		$on_page = is_numeric ( $on_page ) ? $on_page : 1;
		
		$authorid = $this->get_args ( 'authorid' );
		
		$title = $this->get_args ( 'title' );
		
		$status = $this->get_args ( 'status' );
		
		$srchregdatestart = $this->get_args ( 'srchregdatestart' );
		
		$srchregdateend = $this->get_args ( 'srchregdateend' );
		
		$page_size = 18;
		//检索条件
		if ($authorid)
			$u = " and author like '%" . $authorid . "%'";
		if (! empty ( $title ))
			$n = " and title like '%" . $title . "%'";
		if ($status >= 1)
			$e = " and status = " . $status;
		if (! empty ( $srchregdatestart ) && ! empty ( $srchregdateend )) {
			
			$srchregdatestart = get_time ( $srchregdatestart );
			
			$srchregdateend = get_time ( $srchregdateend );
			
			$t = " and time between " . $srchregdatestart . " and " . $srchregdateend;
		}
		
		$nowtime = get_time ();
		
		$condition = " " . $u . $n . $e . $i . $t;
		
		$action = "/index/main_vip_question_manage/";
		
		$get = "?status=" . $status . "&authorid=" . $authorid . "&title=" . $title . "&srchregdatestart=" . $srchregdatestart . "&srchregdateend=" . $srchregdateend;
		
		//获取分页相关数据
		$page = $this->adminlogic->get_page ( t_vipquestion, $condition, $on_page, $page_size, $action, $get, "admin" );
		
		$limit = " order by time desc limit " . $page ['lower'] . " , " . $page_size . " ";
		
		$data ['category'] = $this->asklogic->get_category_list ();
		
		$page ['question_list'] = $this->asklogic->get_vip_questions_list_admin ( array (), $condition, $limit, "vip" );
		
		$data ['question'] = $page;
		
		$data ['status'] = $status;
		$data ['authorid'] = $authorid;
		$data ['title'] = $title;
		$data ['srchregdatestart'] = $srchregdatestart;
		$data ['srchregdateend'] = $srchregdateend;
		
		$data ['map'] = '名师答疑管理 ';
		
		$data ['success'] = " ";
		
		$this->render ( '/admin/vip_question_manage', $data );
	}
	
	/**
	 * 编辑回答
	 */
	function vip_question_edit_manage() {
		$id = $this->check_params ( 'id' );
		
		$id = is_numeric ( $id ) && $id > 0 ? $id : 1;
		
		$data ['vip_question'] = $this->asklogic->get_vip_questions_by_id ( $id );
		
		//获取回答
		$data ['vip_answer'] = $this->asklogic->get_vip_answer_by_id ( $id );
		
		$data ['map'] = '名师答疑管理 ';
		
		$this->render ( '/admin/vip_question_page_manage', $data );
	}
	
	/**
	 * 回答名师答疑
	 */
	function vip_question_add_answer_manage() {
		$id = $this->get_args ( 'qid' );
		
		$aid = $this->get_args ( 'aid' );
		
		$content = stripcslashes ( $this->get_args ( 'content_text' ) );
		
		$id = is_numeric ( $id ) && $id > 0 ? $id : 0;
		
		$data ['vip_question'] = $this->asklogic->get_vip_questions_by_id ( $id );
		
		$params ['id'] = array (0 => $aid );
		
		$params ['qid'] = array (0 => $id );
		
		$params ['content'] = array (0 => $content );
		
		$params ['title'] = array (0 => $data ['vip_question'] ['title'] );
		
		$params ['time'] = array (0 => get_date () );
		
		$params ['ip'] = array (0 => client_ip () );
		
		//加入回答
		$this->userlogic->update_list ( $params, t_vipanswer, "qid" );
		
		//发邮件
		$this->userlogic->send_email ( $data ['vip_question'] ['authorid'], "VIP_NEW_ANSWER", $id, 0 );
		
		//更新检索库
		$params ['vip_question'] = $data ['vip_question'];
		
		$ans ['time'] = get_date ();
		
		$ans ['content'] = $content;
		
		$answer = serialize ( array (0 => $ans ) );
		
		$params ['answer'] = $answer;
		
		$this->userlogic->update_vip_question_search ( $params );
		
		//发送系统信息
		$this->userlogic->update_vip_question_by_answers ( $id );
		
		$subject = "您的" . $data ['vip_question'] ['title'] . "问题有了新的回答";
		
		$content = "名师答疑-问题 " . $data ['vip_question'] ['title'] . " 有了新的回答";
		
		$this->userlogic->send_sys_message ( $subject, $content, $data ['vip_question'] ['authorid'] );
		
		//获取回答
		$data ['vip_answer'] = $this->asklogic->get_vip_answer_by_id ( $id );
		
		$data ['map'] = '名师答疑管理 ';
		
		$this->render ( '/admin/vip_question_page_manage', $data );
	}
	
	/**
	 * 回答追问--加入检索库
	 */
	function vip_question_add_answeragain_manage() {
		$id = $this->get_args ( 'qid' );
		
		$content = stripcslashes ( $this->get_args ( 'answer_again_text' ) );
		
		$id = is_numeric ( $id ) && $id > 0 ? $id : 0;
		
		$data ['vip_question'] = $this->asklogic->get_vip_questions_by_id ( $id );
		
		//获取回答
		$data ['vip_answer'] = $this->asklogic->get_vip_answer_by_id ( $id );
		
		//加入追问
		$this->userlogic->update_vip_answer ( $content, $data ['vip_answer'] ['id'], $data ['vip_answer'] ['tag'] );
		
		//发邮件
		$this->userlogic->send_email ( $data ['vip_question'] ['authorid'], "VIP_FOLLOW_ANSWER", $id, 0 );
		
		//加入检索库
		$params ['vip_question'] = $data ['vip_question'];
		
		$answer = $data ['vip_answer'];
		
		$ans ['aid'] = $answer ['id'];
		$ans ['time'] = $answer ['time'];
		$ans ['content'] = $answer ['content'];
		$ans ['comment'] = $answer ['comment'];
		$tag_list = unserialize ( $answer ['tag'] );
		array_push ( $tag_list, $content );
		
		$tag = serialize ( $tag_list );
		$ans ['tag'] = $tag;
		$answer = serialize ( array (0 => $ans ) );
		
		$params ['answer'] = $answer;
		
		$this->userlogic->update_vip_question_search ( $params );
		
		//发送系统信息
		$this->userlogic->update_vip_question_by_answers ( $id );
		
		$subject = "您的" . $data ['vip_question'] ['title'] . "问题回答了您的追问";
		
		$content = "名师答疑-问题 " . $data ['vip_question'] ['title'] . " 回答了追问";
		
		$this->userlogic->send_sys_message ( $subject, $content, $data ['vip_question'] ['authorid'] );
		
		$data ['map'] = '名师答疑管理 ';
		
		$this->render ( '/admin/vip_question_page_manage', $data );
	}
	
	/**
	 * 公告管理
	 */
	function article_manage() {
		
		$n = "";
		
		$t = "";
		
		$on_page = $this->check_params ( 'on_page' );
		
		$on_page = is_numeric ( $on_page ) ? $on_page : 1;
		
		$title = $this->get_args ( 'title' );
		
		$srchregdatestart = $this->get_args ( 'srchregdatestart' );
		
		$srchregdateend = $this->get_args ( 'srchregdateend' );
		
		$page_size = 18;
		//检索条件
		if (! empty ( $title ))
			$n = " and title like '%" . $title . "%'";
		
		if (! empty ( $srchregdatestart ) && ! empty ( $srchregdateend )) {
			
			$srchregdatestart = get_time ( $srchregdatestart );
			
			$srchregdateend = get_time ( $srchregdateend );
			
			$t = " and time between " . $srchregdatestart . " and " . $srchregdateend;
		}
		
		$condition = $n . $t;
		
		$action = "/index/main_article_manage/";
		
		$get = "?title=" . $title . "&srchregdatestart=" . $srchregdatestart . "&srchregdateend=" . $srchregdateend;
		
		//获取分页相关数据
		$page = $this->adminlogic->get_page ( t_article, $condition, $on_page, $page_size, $action, $get, "admin" );
		
		$limit = " order by time desc limit " . $page ['lower'] . " , " . $page_size . " ";
		
		$page ['question_list'] = $this->asklogic->get_article_list ( array (), $condition, $limit );
		
		$data ['question'] = $page;
		
		$data ['title'] = $title;
		$data ['srchregdatestart'] = $srchregdatestart;
		$data ['srchregdateend'] = $srchregdateend;
		
		$data ['map'] = '公告管理 ';
		
		$data ['success'] = " ";
		
		$this->render ( '/admin/article_manage', $data );
	}
	
	/**
	 * 文章添加
	 */
	function article_manage_add() {
		
		$params ['title'] = $this->get_args ( 'title' );
		
		$params ['content'] = stripcslashes ( $this->get_args ( 'content_text' ) );
		
		$is_add = $this->get_args ( 'is_add' );
		
		if (! empty ( $is_add )) {
			if (empty ( $params ['title'] ))
				die ( '标题为空' );
			if (empty ( $params ['content'] ))
				die ( '内容为空' );
			
			$this->userlogic->add_article ( $params );
			echo "添加成功 点击进入公告";
			die ();
		}
		
		$data ['map'] = '公告管理-添加 ';
		
		$data ['success'] = "";
		
		$this->render ( '/admin/article_manage_add', $data );
	}
	
	/**
	 * 编辑公告
	 */
	function article_manage_edit() {
		
		$params ['id'] = $this->check_params ( 'id' );
		
		$params ['title'] = $this->get_args ( 'title' );
		
		$params ['content'] = stripcslashes ( $this->get_args ( 'content_text' ) );
		
		$is_edit = $this->get_args ( 'is_edit' );
		
		if (! empty ( $is_edit )) {
			if (empty ( $params ['title'] ))
				die ( '标题为空' );
			if (empty ( $params ['content'] ))
				die ( '内容为空' );
			
			$params ['id'] = $this->get_args ( 'id' );
			
			$this->userlogic->update_article ( $params );
			echo "更新成功 点击进入公告";
			die ();
		}
		
		$data ['article'] = $this->userlogic->get_article_by_id ( $params ['id'] );
		
		$data ['map'] = '公告管理-编辑 ';
		
		$data ['success'] = "";
		
		$this->render ( '/admin/article_manage_edit', $data );
	}
	
	/**
	 * 删除公告
	 */
	function article_manage_delete() {
		
		$id = $this->get_args ( 'id' );
		
		$this->userlogic->delete_article ( $id );
		
		Header ( "Location:/index/main_article_manage" );
	}
	
	/**
	 * 分类管理
	 */
	function category_manage() {
		
		$n = "";
		
		$on_page = $this->check_params ( 'on_page' );
		
		$on_page = is_numeric ( $on_page ) ? $on_page : 1;
		
		if ($on_page <= 0)
			$on_page = 1;
		
		$title = $this->get_args ( 'title' );
		
		$page_size = 18;
		//检索条件
		if (! empty ( $title ))
			$n = " and name like '%" . $title . "%'";
		
		$condition = $n;
		
		$action = "/index/main_category_manage/";
		
		$get = "?title=" . $title;
		
		//获取分页相关数据
		$page = $this->adminlogic->get_page ( t_category, $condition, $on_page, $page_size, $action, $get, "admin" );
		
		$limit = " limit " . $page ['lower'] . " , " . $page_size . " ";
		
		$page ['question_list'] = $this->asklogic->get_list ( array (), $condition, $limit, t_category );
		
		$data ['question'] = $page;
		
		$data ['title'] = $title;
		
		$data ['map'] = '分类管理 ';
		
		$data ['success'] = " ";
		
		$this->render ( '/admin/category_manage', $data );
	}
	
	/**
	 * 进入添加分类页面
	 */
	function category_manage_add() {
		
		//获取顶级分类
		$data ['category'] = $this->asklogic->get_category_list ();
		
		$data ['map'] = '添加分类 ';
		
		$data ['success'] = " ";
		
		$this->render ( '/admin/category_manage_add', $data );
	}
	
	/**
	 * 添加分类
	 */
	function category_manage_doadd() {
		$params ['name'] = $this->get_args ( 'name' );
		
		$params ['pid'] = $this->get_args ( 'pid' );
		
		if (empty ( $params ['name'] ))
			die ( '填写分类名称' );
		
		$this->userlogic->add_category ( $params );
		
		Header ( "Location:/index/main_category_manage" );
	}
	
	/**
	 * 分类管理-删除
	 */
	function category_manage_delete() {
		
		$id = $this->get_args ( 'id' );
		
		$this->userlogic->delete_category_list ( $id );
		
		Header ( "Location:/index/main_category_manage" );
	}
	
	/**
	 * 编辑分类
	 */
	function category_manage_edit() {
		
		$id = $this->check_params ( 'id' );
		
		$data ['categoryinfo'] = $this->asklogic->get_category_by_id ( $id );
		
		//获取顶级分类
		$data ['category'] = $this->asklogic->get_category_list ();
		
		$data ['map'] = '添加分类 ';
		
		$data ['success'] = " ";
		
		$this->render ( '/admin/category_manage_edit', $data );
	}
	
	/**
	 * 更新分类信息
	 */
	function category_manage_update() {
		
		$id = $this->get_args ( 'id' );
		
		$name = $this->get_args ( 'name' );
		
		$pid = $this->get_args ( 'pid' );
		
		if (empty ( $name ))
			die ( '填写分类名称' );
		
		$this->userlogic->update_category ( $id, $name, $pid );
		
		Header ( "Location:/index/main_category_manage" );
	}
	
	/**
	 * 进入系统设置
	 */
	function system_manage() {
		
		$data ['map'] = '系统管理 ';
		
		include SITE_PATH . '/protected/config/set_email_to_admin.conf.php';
		
		$data ['email'] = $sys ['set_email'];
		
		$fundstr=file_get_contents(SITE_PATH . '/protected/config/fund.conf.php') ;
		
		$data['fund']=$fundstr;
		
		$this->render ( '/admin/system_manage', $data );
	}
	
	function system_fund_do(){
		
		$string=$this->get_args('fund');
		
		file_put_contents(SITE_PATH . '/protected/config/fund.conf.php', $string);
		
		Header ( "Location:/index/main_system_manage" );
	}
	
	/**
	 * 系统设置
	 */
	function system_manage_do() {
		$email = $this->get_args ( 'set_email_to_admin' );
		
		$string="'".$email."'";
		$string.=");";
		
		file_put_contents(SITE_PATH . '/protected/config/set_email_to_admin.conf.php', $string);
		
		Header ( "Location:/index/main_system_manage" );
	}
	
	/**
	 * 问题审批
	 */
	function examine_manage(){
		
		$data ['examine_list'] = $this->adminlogic->get_examine_list ();
		
		$data ['map'] = '审批管理 ';
		$data ['success'] = " ";
		$this->render ( '/admin/examine_manage', $data );
	}
	
	/**
	 * 清空审批列表
	 */
	function examine_manage_clear(){
		
		$this->adminlogic->examine_clear();
		
		$data ['examine_list']= $this->adminlogic->get_examine_list ();
		
		$data ['map'] = '审批管理 ';
		$data ['success'] = " ";
		$this->render ( '/admin/examine_manage', $data );
	}
	
	function examine_add(){
		$idKey = $this->check_params ( "id" );
		$data=$this->adminlogic->get_examine ($idKey);
		
		if(empty($data))
			die('illegal request');
		
		$data ['category_id']=$data['cid'];
		$id = $this->userlogic->add_question ( $data );
		
		if (empty($id)){//金钱不够 发送站内通知---暂停开发站内通知
			//$this->send_email ( $data ['authorid'], "PAY_FORMONEY", $result, 0 );
			/*			 
			 //发送系统信息-发送给发回答用户  
			$subject = "回答 " . $rs ['title'] . " 追问后有新的回答";		
			$content = "回答 " . $rs ['title'] . " 追问后有新的回答";		
			$this->messagedao->send_message ( ADMIN_NAME, 0, $question ['authorid'], $subject, $content );
			 */
		}
		$this->adminlogic->examine_delete ($idKey);
		return '/index/main_examine_manage';
		//$rs=$this->adminlogic->examine_add ($idKey);
		
	}
	
	/**
	 * 获取get或者POST值
	 * @param string $name 属性名称
	 * @return fixed 值
	 */
	function get_args($name) {
		if (isset ( $_GET [$name] )) {
			if (is_array ( $_GET [$name] ))
				return $_GET [$name];
			else
				return addslashes ( $_GET [$name] );
		
		} elseif (isset ( $_POST [$name] )) {
			if (is_array ( $_POST [$name] ))
				return $_POST [$name];
			else
				return addslashes ( $_POST [$name] );
		} else {
			
			return false;
		}
	}
	
	/**
	 * 检测数据输入的非法字符和转义非法字符
	 */
	function check_params($name = "") {
		if (isset ( $this->params [$name] )) {
			
			return addslashes ( $this->params [$name] );
		} else {
			
			return false;
		}
	}
	
	/**
	 * 限时跳转
	 * @param unknown_type $message
	 * @param unknown_type $redirectto
	 * @param unknown_type $time
	 * @param unknown_type $return_msg
	 * @param unknown_type $js
	 */
	function Messager($message, $redirectto = '', $time = -1, $return_msg = false, $js = null) {
		global $rewriteHandler;
		$data ['redirectto'] = $redirectto;
		$data ['message'] = $message;
		
		if ($time === - 1) {
			//配置文件
			//$time=(is_numeric($this->Config['msg_time'])?$this->Config['msg_time']:5);
			$data ['time'] = 5;
		}
		
		$data ['to_title'] = ($data ['redirectto'] === '' or $data ['redirectto'] == - 1) ? "返回上一页" : "跳转到指定页面";
		
		if ($data ['redirectto'] === null) {
			$return_msg = $return_msg === false ? " " : $return_msg;
		} else {
			$data ['redirectto'] = ($data ['redirectto'] !== '') ? $data ['redirectto'] : ($from_referer = referer ());
			//			if(str_exists($data['redirectto'],'mod=login','code=register','/login','/register'))
			//			{
			//				$referer='&referer='.urlencode('index.php?'.$_SERVER['QUERY_STRING']);
			//				$this->CookieHandler->Setvar('referer','index.php?'.$_SERVER['QUERY_STRING']);
			//			}
			
			if (is_numeric ( $data ['redirectto'] ) !== false and $data ['redirectto'] !== 0) {
				if ($data ['time'] !== null) {
					$data ['url_redirect'] = "\r\n";
				
				}
				
				$data ['redirectto'] = "javascript:history.go({$data['redirectto']})";
			} else {
				if ($rewriteHandler && null !== $data ['message']) {
					$data ['redirectto'] .= $referer;
					if (! $from_referer && ! $referer) {
						$data ['redirectto'] = $rewriteHandler->formatURL ( $data ['redirectto'], true );
					}
				}
				
				if ($data ['message'] === null) {
					$data ['redirectto'] = rawurldecode ( stripslashes ( ($data ['redirectto']) ) );
					@header ( "Location: " . $data ['redirectto'] ); #HEADER跳转
				}
				if ($data ['time'] !== null) {
					$data ['url_redirect'] = ($data ['redirectto'] ? '' : null);
				}
			}
		}
		$title = "消息提示:" . (is_array ( $data ['message'] ) ? implode ( ',', $data ['message'] ) : $data ['message']);
		
		$title = strip_tags ( $title );
		if ($js != "") {
			$js = "";
		}
		$additional_str = $data ['url_redirect'] . $js;
		
		$this->render ( 'messager', $data );
		
		exit ();
	}
}
?>