<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Opt extends CI_Controller {

	function __construct(){
		    parent::__construct();
        	$this->load->helper('url');
        	$this->load->helper('form');
            $this->load->library('session'); //加载session
		    $this->load->model('CsdjDB');
		    $this->load->model('CsdjSkins');
		    $this->load->model('CsdjUser');
		    //$this->CsdjUser->User_Login();
	}

    //认证MM
	public function privilege()
	{
                $data='';
                $page = intval($this->input->get('page', TRUE));   //page
                if($page==0) $page=1;

                $this->load->get_user_templates();
		        $template=$this->load->view('privilege-list.html',$data,true);
		        $template=$this->CsdjSkins->TopandBottom($template,'user');

		        $Mark_Text=str_replace("{cscms:title}","认证MM - ".Web_Name,$template);
		        $Mark_Text=str_replace("{cscms:keywords}",stripslashes(html_entity_decode(Web_Keywords)),$Mark_Text);
		        $Mark_Text=str_replace("{cscms:description}",stripslashes(html_entity_decode(Web_Description)),$Mark_Text);

		        //预先除了分页
				$recount=0;
		        $pagenum=$this->CsdjSkins->GetPageNum($Mark_Text);
		        preg_match_all('/{cscms:user(.*?pagesize=([\S]+).*?)}([\s\S]+?){\/cscms:user}/',$Mark_Text,$page_arr);//判断是否有分页标识
		        if(!empty($page_arr) && !empty($page_arr[2])){


                        $sqlstr="select * from ".CS_SqlPrefix."user where CS_YID=0 and CS_SID=0 and CS_RZID=1 and CS_Sex=1  order by CS_AddTime desc";
                        $data_content='';
			            $Arr=$this->CsdjSkins->SpanUsersPage($sqlstr,$page_arr[2][0],$pagenum,'user/opt/privilege',$page);//sql,每页显示条数
			            $result=$this->CsdjDB->db->query($Arr[2]);
		        	    $recount=$result->num_rows();
			            if($recount==0){
				              $data_content="";
			            }else{
			        	    if($result){
				        	    $sorti=1;
					            foreach ($result->result() as $row2) {
						            $datatmp=$this->CsdjSkins->DataUser($page_arr[0][0],$page_arr[3][0],$row2,$sorti);
						            $sorti=$sorti+1;
						            $data_content.=$datatmp;
					            }
				            }
			            }// end if recount
		        	    $Mark_Text=$this->CsdjSkins->Page_Mark($Mark_Text,$Arr);	
			            $Mark_Text=str_replace($page_arr[0][0],$data_content,$Mark_Text);
			            unset($Arr);
                }
		        unset($page_arr);
		        $Mark_Text=str_replace("[user:nums]",$recount,$Mark_Text);
	            $row=$this->CsdjDB->get_select ('user','CS_ID','*',''.$this->session->userdata('cs_id').'');
		        $Mark_Text=$this->CsdjUser->getuser($Mark_Text,$row);
		        $Mark_Text=$this->CsdjSkins->Common_Mark($Mark_Text,$this->session->userdata('cs_name'));
                $this->CsdjSkins->skins($Mark_Text,$data);
	}

	//活跃用户
	public function useractive()
	{
                $data='';
                $op = $this->input->get('op', TRUE);   
                $page = intval($this->input->get('page', TRUE));   //page
                if($page==0) $page=1;
				if(empty($op)) $op='all';
				$data['op']=$op;

                $this->load->get_user_templates();
		        $template=$this->load->view('useractive-list.html',$data,true);
		        $template=$this->CsdjSkins->TopandBottom($template,'user');

				if($op=='zx'){
                    $title='在线成员';
				}else{
                    $title='活跃会员';
				}
		        $Mark_Text=str_replace("{cscms:title}",$title." - ".Web_Name,$template);
		        $Mark_Text=str_replace("{cscms:keywords}",stripslashes(html_entity_decode(Web_Keywords)),$Mark_Text);
		        $Mark_Text=str_replace("{cscms:description}",stripslashes(html_entity_decode(Web_Description)),$Mark_Text);
		        $Mark_Text=str_replace("[user:op]",$op,$Mark_Text); //OP

		        //预先除了分页
				$recount=0;
		        $pagenum=$this->CsdjSkins->GetPageNum($Mark_Text);
		        preg_match_all('/{cscms:user(.*?pagesize=([\S]+).*?)}([\s\S]+?){\/cscms:user}/',$Mark_Text,$page_arr);//判断是否有分页标识
		        if(!empty($page_arr) && !empty($page_arr[2])){

                        if($op=='zx'){
                             $sqlstr="select * from ".CS_SqlPrefix."user where CS_YID=0 and CS_SID=0 and CS_ZX=1";
                        }else{
							 $sj=time()-86400;
                             $sqlstr="select * from ".CS_SqlPrefix."user where CS_YID=0 and CS_SID=0 and cs_logms>".$sj."";
                        }

                        $sqlstr.=" order by cs_logtime desc";
                        $data_content='';
			            $Arr=$this->CsdjSkins->SpanUsersPage($sqlstr,$page_arr[2][0],$pagenum,'user/opt/useractive?op='.$op,$page);//sql,每页显示条数
			            $result=$this->db->query($Arr[2]);
		        	    $recount=$result->num_rows();
			            if($recount==0){
				              $data_content="";
			            }else{
			        	    if($result){
				        	    $sorti=1;
					            foreach ($result->result() as $row2) {
						            $datatmp=$this->CsdjSkins->DataUser($page_arr[0][0],$page_arr[3][0],$row2,$sorti);
						            $data_content.=$datatmp;
						            $sorti=$sorti+1;
					            }
				            }
			            }// end if recount
		        	    $Mark_Text=$this->CsdjSkins->Page_Mark($Mark_Text,$Arr);	
			            $Mark_Text=str_replace($page_arr[0][0],$data_content,$Mark_Text);
			            unset($Arr);
                }
		        unset($page_arr);
		        $Mark_Text=str_replace("[user:nums]",$recount,$Mark_Text);
	            $row=$this->CsdjDB->get_select ('user','CS_ID','*',''.$this->session->userdata('cs_id').'');
		        $Mark_Text=$this->CsdjUser->getuser($Mark_Text,$row);
		        $Mark_Text=$this->CsdjSkins->Common_Mark($Mark_Text,$this->session->userdata('cs_name'));
                $this->CsdjSkins->skins($Mark_Text,$data);
	}

	//会员搜索
	public function search()
	{
                $data='';
                $key = $this->input->get('key');   
                $sex = intval($this->input->get('sex', TRUE));   
                $city = $this->input->get('city', TRUE);   
                $page = intval($this->input->get('page', TRUE));   //page
                if($page==0) $page=1;

	            $key = $this->CsdjSkins->safe_replace(trim($key));
	            $key = htmlspecialchars(strip_tags($key));
	            $key = str_replace('%', '', $key);	//过滤'%'，用户全文搜索
                $key=$this->CsdjSkins->rurlencode($key);


                $this->load->get_user_templates();
		        $template=$this->load->view('search-list.html',$data,true);
		        $template=$this->CsdjSkins->TopandBottom($template,'user');

		        $Mark_Text=str_replace("{cscms:title}","搜索用户 - ".Web_Name,$template);
		        $Mark_Text=str_replace("{cscms:keywords}",stripslashes(html_entity_decode(Web_Keywords)),$Mark_Text);
		        $Mark_Text=str_replace("{cscms:description}",stripslashes(html_entity_decode(Web_Description)),$Mark_Text);

		        //预先除了分页
				$recount=0;
				$so='';
		        $pagenum=$this->CsdjSkins->GetPageNum($Mark_Text);
		        preg_match_all('/{cscms:user(.*?pagesize=([\S]+).*?)}([\s\S]+?){\/cscms:user}/',$Mark_Text,$page_arr);//判断是否有分页标识
		        if(!empty($page_arr) && !empty($page_arr[2])){

                        $sqlstr="select * from ".CS_SqlPrefix."user where CS_YID=0 and CS_SID=0";
                        if(!empty($key)){
                             $sqlstr.=" and (CS_Name like '%".$key."%' or CS_Nichen like '%".$key."%')";
							 $so.='&key='.urlencode($key);
                        }
                        if($sex==1){
                             $sqlstr.=" and CS_Sex=0";
							 $so.='&sex=1';
                        }
                        if($sex==2){
                             $sqlstr.=" and CS_Sex=1";
							 $so.='&sex=2';
                        }
                        if(!empty($city)){
                             $sqlstr.=" and CS_City like '%".$city."%'";
							 $so.='&city='.urlencode($city);
                        }
						if(substr($so,0,1)=='&') $so='?'.substr($so,1);
						if($so=='') $so='?';
                        $sqlstr.=" order by cs_addtime desc";
                        $data_content='';
			            $Arr=$this->CsdjSkins->SpanUsersPage($sqlstr,$page_arr[2][0],$pagenum,'user/opt/search'.$so,$page);//sql,每页显示条数
			            $result=$this->db->query($Arr[2]);
		        	    $recount=$result->num_rows();
			            if($recount==0){
				              $data_content="";
			            }else{
			        	    if($result){
				        	    $sorti=1;
					            foreach ($result->result() as $row2) {
						            $datatmp=$this->CsdjSkins->DataUser($page_arr[0][0],$page_arr[3][0],$row2,$sorti);
						            $data_content.=$datatmp;
						            $sorti=$sorti+1;
					            }
				            }
			            }// end if recount
		        	    $Mark_Text=$this->CsdjSkins->Page_Mark($Mark_Text,$Arr);	
			            $Mark_Text=str_replace($page_arr[0][0],$data_content,$Mark_Text);
			            unset($Arr);
                }
		        unset($page_arr);
		        $Mark_Text=str_replace("[user:nums]",$recount,$Mark_Text);
		        $Mark_Text=str_replace("[user:so]",$so,$Mark_Text);
	            $row=$this->CsdjDB->get_select ('user','CS_ID','*',''.$this->session->userdata('cs_id').'');
		        $Mark_Text=$this->CsdjUser->getuser($Mark_Text,$row);
		        $Mark_Text=$this->CsdjSkins->Common_Mark($Mark_Text,$this->session->userdata('cs_name'));
                $this->CsdjSkins->skins($Mark_Text,$data);
	}

	//原创DJ人
	public function producer()
	{
                $data='';
                $op = $this->input->get('op', TRUE);   
                $page = intval($this->input->get('page', TRUE));   //page
                if($page==0) $page=1;
				if(empty($op)) $op='reco';

                $this->load->get_user_templates();
		        $template=$this->load->view('producer-list.html',$data,true);
		        $template=$this->CsdjSkins->TopandBottom($template,'user');

				if($op=='reco'){
                    $title='原创DJ推荐';
				}else{
                    $title='全部原创DJ';
				}
		        $Mark_Text=str_replace("{cscms:title}",$title." - ".Web_Name,$template);
		        $Mark_Text=str_replace("{cscms:keywords}",stripslashes(html_entity_decode(Web_Keywords)),$Mark_Text);
		        $Mark_Text=str_replace("{cscms:description}",stripslashes(html_entity_decode(Web_Description)),$Mark_Text);
		        $Mark_Text=str_replace("[user:op]",$op,$Mark_Text); //OP

		        //预先除了分页
				$recount=0;
		        $pagenum=$this->CsdjSkins->GetPageNum($Mark_Text);
		        preg_match_all('/{cscms:user(.*?pagesize=([\S]+).*?)}([\s\S]+?){\/cscms:user}/',$Mark_Text,$page_arr);//判断是否有分页标识
		        if(!empty($page_arr) && !empty($page_arr[2])){

                        if($op=='reco'){
                             $sqlstr="select * from ".CS_SqlPrefix."user where CS_YID=0 and CS_SID=0 and CS_Djid=1 and CS_TID=1";
                        }else{
                             $sqlstr="select * from ".CS_SqlPrefix."user where CS_YID=0 and CS_SID=0 and CS_Djid=1";
                        }

                        $sqlstr.=" order by CS_AddTime desc";
                        $data_content='';
			            $Arr=$this->CsdjSkins->SpanUsersPage($sqlstr,$page_arr[2][0],$pagenum,'user/opt/producer?op='.$op,$page);//sql,每页显示条数
			            $result=$this->CsdjDB->db->query($Arr[2]);
		        	    $recount=$result->num_rows();
			            if($recount==0){
				              $data_content="";
			            }else{
			        	    if($result){
				        	    $sorti=1;
					            foreach ($result->result() as $row2) {
						            $datatmp=$this->CsdjSkins->DataUser($page_arr[0][0],$page_arr[3][0],$row2,$sorti);
						            $sorti=$sorti+1;
						            $data_content.=$datatmp;
					            }
				            }
			            }// end if recount
		        	    $Mark_Text=$this->CsdjSkins->Page_Mark($Mark_Text,$Arr);	
			            $Mark_Text=str_replace($page_arr[0][0],$data_content,$Mark_Text);
			            unset($Arr);
                }
		        unset($page_arr);
		        $Mark_Text=str_replace("[user:nums]",$recount,$Mark_Text);
	            $row=$this->CsdjDB->get_select ('user','CS_ID','*',''.$this->session->userdata('cs_id').'');
		        $Mark_Text=$this->CsdjUser->getuser($Mark_Text,$row);
		        $Mark_Text=$this->CsdjSkins->Common_Mark($Mark_Text,$this->session->userdata('cs_name'));
                $this->CsdjSkins->skins($Mark_Text,$data);
	}

	//舞曲分享人
	public function usershare()
	{
                $data='';
                $op = $this->input->get('op', TRUE);   
                $page = intval($this->input->get('page', TRUE));   //page
                if($page==0) $page=1;
				if(empty($op)) $op='reco';

                $this->load->get_user_templates();
		        $template=$this->load->view('usershare-list.html',$data,true);
		        $template=$this->CsdjSkins->TopandBottom($template,'user');

				if($op=='reco'){
                    $title='舞曲分享人推荐';
				}else{
                    $title='全部舞曲分享人';
				}
		        $Mark_Text=str_replace("{cscms:title}",$title." - ".Web_Name,$template);
		        $Mark_Text=str_replace("{cscms:keywords}",stripslashes(html_entity_decode(Web_Keywords)),$Mark_Text);
		        $Mark_Text=str_replace("{cscms:description}",stripslashes(html_entity_decode(Web_Description)),$Mark_Text);
		        $Mark_Text=str_replace("[user:op]",$op,$Mark_Text); //OP

		        //预先除了分页
				$recount=0;
		        $pagenum=$this->CsdjSkins->GetPageNum($Mark_Text);
		        preg_match_all('/{cscms:user(.*?pagesize=([\S]+).*?)}([\s\S]+?){\/cscms:user}/',$Mark_Text,$page_arr);//判断是否有分页标识
		        if(!empty($page_arr) && !empty($page_arr[2])){

                        if($op=='reco'){
                             $sqlstr="select * from ".CS_SqlPrefix."user where CS_YID=0 and CS_SID=0 and CS_Music>0 and CS_TID=1";
                        }else{
                             $sqlstr="select * from ".CS_SqlPrefix."user where CS_YID=0 and CS_SID=0 and CS_Music>0";
                        }

                        $sqlstr.=" order by CS_AddTime desc";
                        $data_content='';
			            $Arr=$this->CsdjSkins->SpanUsersPage($sqlstr,$page_arr[2][0],$pagenum,'user/opt/usershare?op='.$op,$page);//sql,每页显示条数
			            $result=$this->CsdjDB->db->query($Arr[2]);
		        	    $recount=$result->num_rows();
			            if($recount==0){
				              $data_content="";
			            }else{
			        	    if($result){
				        	    $sorti=1;
					            foreach ($result->result() as $row2) {
						            $datatmp=$this->CsdjSkins->DataUser($page_arr[0][0],$page_arr[3][0],$row2,$sorti);
						            $sorti=$sorti+1;
						            $data_content.=$datatmp;
					            }
				            }
			            }// end if recount
		        	    $Mark_Text=$this->CsdjSkins->Page_Mark($Mark_Text,$Arr);	
			            $Mark_Text=str_replace($page_arr[0][0],$data_content,$Mark_Text);
			            unset($Arr);
                }
		        unset($page_arr);
		        $Mark_Text=str_replace("[user:nums]",$recount,$Mark_Text);
	            $row=$this->CsdjDB->get_select ('user','CS_ID','*',''.$this->session->userdata('cs_id').'');
		        $Mark_Text=$this->CsdjUser->getuser($Mark_Text,$row);
		        $Mark_Text=$this->CsdjSkins->Common_Mark($Mark_Text,$this->session->userdata('cs_name'));
                $this->CsdjSkins->skins($Mark_Text,$data);
	}

	//嗨友相册
	public function album()
	{
                $data='';
                $op = $this->input->get('op', TRUE);   
                $page = intval($this->input->get('page', TRUE));   //page
                if($page==0) $page=1;
				if(empty($op)) $op='all';

                $this->load->get_user_templates();
		        $template=$this->load->view('album-list.html',$data,true);
		        $template=$this->CsdjSkins->TopandBottom($template,'user');

				if($op=='mm'){
                    $title='MM照片';
				}elseif($op=='gg'){
                    $title='GG照片';
				}else{
                    $title='全部照片';
				}
		        $Mark_Text=str_replace("{cscms:title}",$title." - ".Web_Name,$template);
		        $Mark_Text=str_replace("{cscms:keywords}",stripslashes(html_entity_decode(Web_Keywords)),$Mark_Text);
		        $Mark_Text=str_replace("{cscms:description}",stripslashes(html_entity_decode(Web_Description)),$Mark_Text);
		        $Mark_Text=str_replace("[pic:op]",$op,$Mark_Text); //OP

		        //预先除了分页
		        $pagenum=$this->CsdjSkins->GetPageNum($Mark_Text);
		        preg_match_all('/{cscms:pic(.*?pagesize=([\S]+).*?)}([\s\S]+?){\/cscms:pic}/',$Mark_Text,$page_arr);//判断是否有分页标识
		        if(!empty($page_arr) && !empty($page_arr[2])){

                        if($op=='mm'){
                             $sqlstr="select * from ".CS_SqlPrefix."pic where CS_YID=0 and CS_Sex=1";
                        }elseif($op=='gg'){
                             $sqlstr="select * from ".CS_SqlPrefix."pic where CS_YID=0 and CS_Sex=0";
                        }else{
                             $sqlstr="select * from ".CS_SqlPrefix."pic where CS_YID=0";
                        }

                        $sqlstr.=" order by CS_AddTime desc";
                        $data_content='';
			            $Arr=$this->CsdjSkins->SpanUsersPage($sqlstr,$page_arr[2][0],$pagenum,'user/opt/album?op='.$op,$page);//sql,每页显示条数
			            $result=$this->CsdjDB->db->query($Arr[2]);
		        	    $recount=$result->num_rows();
			            if($recount==0){
				              $data_content="";
			            }else{
			        	    if($result){
				        	    $sorti=1;
					            foreach ($result->result() as $row2) {
						            $datatmp=$this->CsdjSkins->DataPic($page_arr[0][0],$page_arr[3][0],$row2,$sorti);
						            $sorti=$sorti+1;
						            $data_content.=$datatmp;
					            }
				            }
			            }// end if recount
		        	    $Mark_Text=$this->CsdjSkins->Page_Mark($Mark_Text,$Arr);	
			            $Mark_Text=str_replace($page_arr[0][0],$data_content,$Mark_Text);
			            unset($Arr);
                }
		        unset($page_arr);
		        $Mark_Text=str_replace("[pic:nums]",$recount,$Mark_Text);
	            $row=$this->CsdjDB->get_select ('user','CS_ID','*',''.$this->session->userdata('cs_id').'');
		        $Mark_Text=$this->CsdjUser->getuser($Mark_Text,$row);
		        $Mark_Text=$this->CsdjSkins->Common_Mark($Mark_Text,$this->session->userdata('cs_name'));
                $this->CsdjSkins->skins($Mark_Text,$data);
	}
}

