<?php
/*
 +----------------------------------------------------------------------
 | TEMMOKUMVC [ NO BEST, ONLY BETTER ]
 +----------------------------------------------------------------------
 | Copyright (c) 2018~2019 https://www.temmoku.cn All rights reserved.
 +----------------------------------------------------------------------
 | Author: 张宗强 Email:webmaster@temmoku.cn QQ:158726877 516669373 TEL:17895221001 微信:temmokumvc
 +---------------------------------------------------------------------- 
*/
namespace user\controller;
use \temmoku\user;
use \temmoku\db;
use \user\model\index AS model;
class index extends user{
	public function index(){
		
		extract(db::select('COUNT(*)  AS smsnum ')->from(jab.'station_message')->where('is_read=0 AND uid='.C('MYDB.uid'))->row());
		$modular = db::from(jab.'modular')->select('*')->where("state != 0 AND user_show=1")->query();
	    if($modular){
	    	foreach((array)$modular AS $R){
				$powerfile=APP_PATH.$R['dir']."/user/power.php";
				if(is_file($powerfile)){
					$R['rute']=include_once $powerfile;
					$Modular_DB[]=$R;
				}
		    }
	   	}
	    $plugin = db::from(jab.'plugin')->select('*')->where("state != 0 AND user_show=1")->query();
	    if($plugin){
	    	foreach((array)$plugin AS $p){
				$powerfile=APP_PATH.'plugin/'.$p['dir']."/user/power.php";
				if(is_file($powerfile)){
					$p['rute']=@include_once $powerfile;
					$pluginDB[]=$p;
				}
		   	}
	   	}
		//判断一下是否存在后台定义的模块会员maps
		$file=APP_PATH.c('index')."/user/controller/maps.php";
		$maps=is_file($file) ?  "/user/index/modular/".c('index')."/maps" :  '/user/index/maps/';
		$this->assign('maps', $maps);
	   	$this->assign('pluginDB', $pluginDB);
	   	$this->assign('smsnum', $smsnum);
	    $this->assign('Modular_DB', $Modular_DB);
		$this->display(tpl('index'));
	}
	public function maps(){
		if(C('index')!='home'){
			$index=db::from(jab.'modular')->select('*')->where("dir  LIKE '".C('index')."'")->row();
			$module=C('index');
		}else{
			$module=MODULE;
		}
		extract(db::select('COUNT(*)  AS comment_NUM ')->from(jab.$index['table'].'comment')->where('uid='.C('MYDB.uid'))->row());
		extract(db::select('COUNT(*)  AS comment_NUM_Noyz ')->from(jab.$index['table'].'comment')->where('uid='.C('MYDB.uid').' AND state=0')->row());
		extract(db::select('COUNT(*)  AS Article_NUM ')->from(jab.$index['table'].'article')->where('uid='.C('MYDB.uid'))->row());
		extract(db::select('COUNT(*)  AS Article_NUM_Noyz ')->from(jab.$index['table'].'article')->where('uid='.C('MYDB.uid').' AND state=0')->row());
		
		$login_list_file=APP_PATH."plugin/login/conf/more_login_list.php";
		if(is_file($login_list_file)){
			extract(include_once $login_list_file);
		}
		$this->assign('more_login_list',$more_login_list);
		$this->assign('index',$index);
		$this->assign('module',$module);
		$this->assign('comment_NUM',$comment_NUM);
		$this->assign('comment_NUM_Noyz',$comment_NUM_Noyz);
		$this->assign('Article_NUM_Noyz',$Article_NUM_Noyz);
		$this->assign('Article_NUM',$Article_NUM);
		$this->display(tpl('maps'));
	}
	public function modular(){
		
		$_REDIRECT_URL=explode("/",$_SERVER['PATH_INFO'],6);
		
		define('M_MODULE',strtolower($_REDIRECT_URL[2]));
	    define('M_CONTROLLER',strtolower($_REDIRECT_URL[3]) ? strtolower($_REDIRECT_URL[3]) : 'index');
	    define('M_METHOD',$_REDIRECT_URL[4] ? $_REDIRECT_URL[4] : 'index');
		
	    //主后台视图位置常量
	    define('ADMIN_VIEW', "/admin/view/");
	    define('is_home','user');
		$data = db::select('*')->from(jab.'modular')->where("dir= '".M_MODULE."' ")->row();
		if(!$data){
			$this->err('不存在的模块');
		}
		if(!$data['user_show']){
			$this->err('模块已经关闭，禁止访问');
		}
		$function= APP_PATH.M_MODULE."/function.php";
		if(is_file($function)){
			include_once $function;
		}
		$data[domain] ? $url=HTTP.$data[domain] : $url=WEBURL.'/'.M_MODULE;
		define('M_WEBURL',$url);
		$_REDIRECT_URL_=explode("/",$_REDIRECT_URL[5]);
		//解析参数
		foreach($_REDIRECT_URL_ AS $_paths_k=>$V){
			if($_paths_k%2==1){
				$_GET[$_REDIRECT_URL_[$_paths_k-1]]=$_REDIRECT_URL_[$_paths_k];
			}
		}
		isset($data['table']) && define('M_jab',jab.$data['table']);
		
		//模块地址
		define('user_module_url', USER_URL."index/modular/".M_MODULE."/");
		$dir=APP_PATH.M_MODULE.'/conf';
	    Load_conf($dir);
	   	$url= C('setting.domain') ? HTTP.C('setting.domain') : WEBURL.'/'.M_MODULE;
	    define('M_WEBURL',$url); 
	    //文件所在位置
	    $file= APP_PATH.M_MODULE.'/user/controller/'.M_CONTROLLER.'.php';
	   	@include_once $file;
		$Modular_Class= M_MODULE.'\user\controller\\'.M_CONTROLLER;
	    //加载类
	    $Class=new $Modular_Class();
	    //加载方法
	    Load_Method($Class,M_METHOD,$Modular_Class);
	}
	public function plugin(){
	
		$_REDIRECT_URL=explode("/",$_SERVER['PATH_INFO'],6);
		define('P_MODULE',strtolower($_REDIRECT_URL[2]));
	    define('P_CONTROLLER',strtolower($_REDIRECT_URL[3]) ? strtolower($_REDIRECT_URL[3]) : 'index');
	    define('P_METHOD',$_REDIRECT_URL[4] ? $_REDIRECT_URL[4] : 'index');
	    $_REDIRECT_URL_=explode("/",$_REDIRECT_URL[5]);
	    	
	    define('is_plugin',true);
	    define('is_home','user');
	    	
		//解析参数
		foreach($_REDIRECT_URL_ AS $_paths_k=>$V){
			if($_paths_k%2==1){
				$_GET[$_REDIRECT_URL_[$_paths_k-1]]=$_REDIRECT_URL_[$_paths_k];
			}
		}
	    $data = db::select('*')->from(jab.'plugin')->where("dir= '".P_MODULE."' ")->row();
		if(!$data){
			$this->err('不存在的插件');
		}
		if(!$data['user_show']){
			$this->err('插件已经关闭，禁止访问');
		}
		$function= APP_PATH.'plugin/'.P_MODULE."/function.php";
		if(is_file($function)){
			include_once $function;
		}
		define('P_WEBURL',WEBURL.'/'.P_MODULE);
	    $setting_files=APP_PATH.P_MODULE."/conf/setting.php";
	    isset($data['table']) && define('P_jab',jab.'plugin_'.$data['table']);
	    $CONF=APP_PATH.'plugin/'.P_MODULE.'/conf';
	   	Load_conf($CONF);
	   	//定义一个插件试图所在目录的常量
	    define('PLUGIN_VIEW', 'plugin/'.P_MODULE."/user/view/");
	    //定义一个插件所在目录的常量
	    define('PLUGIN', 'plugin/'.P_MODULE."/");
	    //定义一个插件操作方法常量
	    define('PLUGIN_ACTION', '/user/index/plugin/'.P_MODULE."/");
	    define('user_plugin_url', USER_URL."index/plugin/".P_MODULE."/");
	    //文件所在位置
	    $file= APP_PATH.'plugin/'.P_MODULE.'/user/controller/'.P_CONTROLLER.'.php';
	    @include_once $file;
		$Modular_Class= plugin.'\\'.P_MODULE.'\user\controller\\'.P_CONTROLLER;
	    //加载类
	    $Class=new $Modular_Class();
	    //加载方法
	    Load_Method($Class,P_METHOD,$Modular_Class);
    }
}
?>
