<?php

defined('BASEPATH') OR exit('No direct script access allowed');



class Client_fun extends Mocuzfun_Controller{



    public $show_rules = array(7,14,30,0);//最热显示规则  7天 14天 30天 0全局

    public function __construct()

    {

        parent::__construct();

        $this->load->model('mocuz/setting_model', 'setting');        

    }



    /**

     * [broke 爆料显示   BIU功能]

     * @author 刘厚望

     * @return [type] [description]

     */

    public function biu()

    {

        $data['biu_switch'] = $this->setting->get('biu_switch');//Biu功能开关



        $data['biu_data_source'] = $this->setting->get('biu_data_source');//调用板块ID

        $data['biu_placard'] = $this->setting->get('biu_placard');//Biu 公告

        $data['biu_show_rule'] = $this->setting->get('biu_show_rule');//最热显示规则



        $data['show_rules'] = $this->show_rules;

        $this->load->view('common/innerheader',$data);

        $this->load->view('admin/mocuzfun/biu',$data);

    }



    /**

     * [savebiu biu设置保存]

     * @author  刘厚望

     * @return [type] [description]

     */

    public  function savebiu()

    {

        $config = array(

            array(

                'field' => 'biu_data_source',

                'label' => '调用板块ID',

                'rules' => 'trim|required|regex_match[/^\d+$/]'

            ),

            array(

                'field' => 'biu_block_name',

                'label' => '板块名称',

                'rules' => 'trim|regex_match[/^([\x{4e00}-\x{9fa5}]|\w|-){1,4}$/u]'

            ),

            array(

                'field' => 'biu_header_name',

                'label' => 'biu头部名称',

                'rules' => 'trim|regex_match[/^([\x{4e00}-\x{9fa5}]|\w|-){1,5}$/u]'

            ),

            array(

                'field' => 'biu_placard',

                'label' => 'biu公告',

                'rules' => 'trim|max_length[200]'

            )                                     

        );    

        $this->load->library('form_validation', $config);

        if($this->form_validation->run() == FALSE)

        {

            print_r($this->form_validation->error_array());

        }

        else

        {

            $this->setting->set('biu_switch', $this->input->post('biu_switch'));



            //关闭状态不进行内容更新

            if($this->input->post('biu_switch') == 1)

            {

                $this->setting->set('biu_data_source', $this->input->post('biu_data_source'));



                //如果为空 填入默认 biu

                $biu_block_name = $this->input->post('biu_block_name');

                $biu_block_name = empty($biu_block_name)?'Biu':$biu_block_name;

                $this->setting->set('biu_block_name', $biu_block_name);



                //如果为空 填入默认 biu

                $biu_header_name = $this->input->post('biu_header_name');

                $biu_header_name = empty($biu_header_name)?'Biu':$biu_header_name;

                $this->setting->set('biu_header_name', $biu_header_name);



                $this->setting->set('biu_placard', $this->input->post('biu_placard'));

                $this->setting->set('biu_show_rule', $this->input->post('biu_show_rule'));

            }             

        }

        redirect('mocuzfun/client_fun/biu');

    }



    /**

     * [selColor 调色版功能]

     * @author 刘厚望

     * @return [type] [description]

     */

    public function sel_color()

    {

        $data['color_switch'] = $this->setting->get('color_switch');

		$this->load->view('common/innerheader',$data);

		$this->load->view('admin/mocuzfun/color',$data);

    }

    /**

     * [saveColor 调色版保存]

     * @author 刘厚望

     * @return [type] [description]

     */

    public function save_color()

    {

        $config = array(

            array(

                'field' => 'color',

                'label' => '颜色值',

                'rules' => 'trim|required|regex_match[/^(#[0-9a-zA-Z]{6})|white$/]'

            )                                   

        );  

        $this->load->library('form_validation', $config);

        if($this->form_validation->run() == FALSE)

        {

            print_r($this->form_validation->error_array());

        }

        else

        {

            $this->setting->set('color_switch',$this->input->post('color'));          

        } 

        redirect('mocuzfun/client_fun/sel_color');

    }



    /**

     * [invite_fun 邀请好友功能]

     * @return [type] [description]

     */

    public function invite_fun()

    {

        $data['invite_self_num'] = $this->setting->get('invite_self_num');

        $data['invite_user_num'] = $this->setting->get('invite_user_num');

        $data['invite_score_type'] = $this->setting->get('invite_score_type');

        $data['invite_rule'] = $this->setting->get('invite_rule');//邀请规则

        $data['invite_comments'] = $this->setting->get('invite_comments');//评论

        $data['extcredits'] = $this->get_score_type();



        $this->load->view('common/innerheader');

        $this->load->view('admin/mocuzfun/yq_gnpz',$data);        

    }

    /**

     * [saveinte_func 邀请好友保存]

     * @return [type] [description]

     */

    public function saveinte_func()

    {

        $config = array(           

            array(

                'field' => 'invite_self_num',

                'label' => '增加积分',

                'rules' => 'trim|regex_match[/^\d*$/]'

            ),

            array(

                'field' => 'invite_user_num',

                'label' => '增加积分',

                'rules' => 'trim|regex_match[/^\d*$/]'

            ),

            array(

                'field' => 'invite_score_type',

                'label' => '邀请积分类型',

                'rules' => 'trim|required'

            )                                                  

        );  

        $this->load->library('form_validation', $config);

        if($this->form_validation->run() == FALSE)

        {

            print_r($this->form_validation->error_array());exit;

        }





        $invite_keys = array('invite_self_num', 'invite_user_num', 'invite_comments','invite_score_type', 'invite_rule');



        foreach($invite_keys as $key){

            if($key != 'invite_comments' && $key != 'invite_rule'){

                $value = intval($this->input->post($key));

            }else{



                $value = $this->input->post($key);

            }



            $this->setting->set($key , $value);

        }

        redirect('mocuzfun/client_fun/invite_fun');         

    }

    /**

     * [integral 积分设置]

     * @author [刘厚望]

     * @return [type] [description]

     */

    public function integral()

    {



        $data['integral_share_switch'] = $this->setting->get("integral_share_switch");//分享积分开关

        $share = $this->setting->get("integral_article_share");//文章分享增加积分

        $data["share_integral"] = unserialize($share['value']);



        $data['extcredits'] = $this->get_score_type();



        $this->load->view('common/innerheader');

        $this->load->view('admin/mocuzfun/integral',$data);       

    }



    public  function saveinte()

    {

        $config = array(

            array(

                'field' => 'integral_share_switch',

                'label' => '分享积分开关',

                'rules' => 'trim|required'

            ),           

            array(

                'field' => 'share_integral',

                'label' => '增加积分',

                'rules' => 'trim|regex_match[/^\d*$/]'

            ),

            array(

                'field' => 'share_integral_type',

                'label' => '分享积分类型',

                'rules' => 'trim|required'

            )                                                 

        );  

        $this->load->library('form_validation', $config);

        if($this->form_validation->run() == FALSE)

        {

            print_r($this->form_validation->error_array());exit;

        }



        $this->setting->set('integral_share_switch',$this->input->post('integral_share_switch'));

        if($this->input->post('integral_share_switch'))

        {

            /////////////////文章分享积分增加保存//////////////////////////

            $share_integral = $this->input->post('share_integral');

            $share_integral = empty($share_integral)?'0':intval($share_integral);

            $share_integral = serialize(array('score'=>$share_integral,'type'=>$this->input->post('share_integral_type')));



            $this->setting->set('integral_article_share',$share_integral);

        }

        redirect('mocuzfun/client_fun/integral');          

    }



    /**

     * [groupbuy 团购模块]

     * @author [name] <[<email address>]>

     * @return [type] [description]

     */

    public function groupbuy(){      

        $data['groupbuy_switch'] = $this->setting->get('groupbuy_switch');

        $this->load->view('common/innerheader');

        $this->load->view('admin/mocuzfun/groupbuy',$data);              

    }



    public function save_groupbuy()

    {

        $config = array(

            array(

                'field' => 'groupbuy_switch',

                'label' => '团购模块',

                'rules' => 'trim|required'

            )                                         

        );    

        $this->load->library('form_validation', $config);

        if($this->form_validation->run() == FALSE)

        {

            print_r($this->form_validation->error_array());exit;

        }      

        

        $this->setting->set('groupbuy_switch',$this->input->post('groupbuy_switch'));

        redirect('mocuzfun/client_fun/groupbuy');       

    }

    /**

     * [reward 打赏功能]

     * @author [刘厚望] <[<email address>]>

     * @return [type] [description]

     */

    public function reward()

    {      

        $data['reward_switch'] = $this->setting->get('reward_switch');

        $data['reward_score_type'] = $this->setting->get('reward_score_type');

        $data['reward_score1'] = $this->setting->get('reward_score1');

        $data['reward_score2'] = $this->setting->get('reward_score2');

        $data['reward_score3'] = $this->setting->get('reward_score3');

        $data['reward_score4'] = $this->setting->get('reward_score4');

        $data['extcredits'] = $this->get_score_type();



        $this->load->view('common/innerheader');

        $this->load->view('admin/mocuzfun/reward',$data);

    }

    /**

     * [save_reward 打赏功能保存]

     * @author [刘厚望] <[<email address>]>

     * @return [type] [description]

     */

    public function save_reward()

    {

        $config = array(

            array(

                'field' => 'reward_switch',

                'label' => '打赏功能',

                'rules' => 'trim|required'

            ),

            array(

                'field' => 'reward_score_type',

                'label' => '打赏积分种类',

                'rules' => 'trim|required'

            ),

            array(

                'field' => 'reward_score1',

                'label' => '自定义分值1',

                'rules' => 'trim|required|regex_match[/^[1-9]\d*$/]'

            ),

            array(

                'field' => 'reward_score2',

                'label' => '自定义分值2',

                'rules' => 'trim|required|regex_match[/^[1-9]\d*$/]'

            ),

            array(

                'field' => 'reward_score3',

                'label' => '自定义分值3',

                'rules' => 'trim|required|regex_match[/^[1-9]\d*$/]'

            ),

            array(

                'field' => 'reward_score4',

                'label' => '自定义分值4',

                'rules' => 'trim|required|regex_match[/^[1-9]\d*$/]'

            )                               

        );  

        $this->load->library('form_validation', $config);

        if($this->form_validation->run() == FALSE)

        {

            print_r($this->form_validation->error_array());exit;

        }

        $this->setting->set('reward_switch',$this->input->post('reward_switch'));

        $this->setting->set('reward_score_type',$this->input->post('reward_score_type'));



        $this->setting->set('reward_score1',$this->input->post('reward_score1'));

        $this->setting->set('reward_score2',$this->input->post('reward_score2'));

        $this->setting->set('reward_score3',$this->input->post('reward_score3'));

        $this->setting->set('reward_score4',$this->input->post('reward_score4'));

        redirect('mocuzfun/client_fun/reward');

    }



    /**

     * [get_score_type 从discuz中获取积分种类]

     * @author [刘厚望]

     * @return [type] [description]

     */

    public function get_score_type()

    {

        $this->load->helper('discuz_helper');

        return get_extcredits();

    }



    /**

     * [page 分页配置]

     * @param  [type] $con [传入的参数]

     * @author [刘厚望] <[<email address>]>

     * @return [type]      [连接字符]

     */

    public function page($con)

    {

        $this->load->library('pagination');

        $config['base_url'] = $con['base_url'];

        $config['total_rows'] = $con['total_rows'];

        $config['per_page'] = $con['per_page'];

        $config['uri_segment'] = $con['uri_segment'];



        $config['first_link'] = '首页';

        $config['first_tag_open'] = '<li id="first">';

        $config['first_tag_close'] = '</li>';



        $config['last_link'] = '末页';

        $config['last_tag_open'] = '<li id="last">';

        $config['last_tag_close'] = '</li>';



        $config['next_link'] = '下一页';

        $config['next_tag_open'] = '<li id="down">';

        $config['next_tag_close'] = '</li>';



        $config['prev_link'] = '上一页';

        $config['prev_tag_open'] = '<li id="top">';

        $config['prev_tag_close'] = '</li>';

        $config['num_links'] = 5;



        $config['full_tag_open'] = '<div class="wrap"><div class="fenye"><ul>';

        $config['full_tag_close'] = '</ul></div></div>';

        #初始化分页类

        $this->pagination->initialize($config);

        #生成分页信息

        return $this->pagination->create_links();        

    }



    /**

     * [invite 邀请注册]

     * @param  string $offset [description]

     * @author [刘厚望]<[<email address>]>

     * @return [type]         [description]

     */

    public function invite($search = 0,$offset ='')

    {

        $this->load->model('mocuz/set_invite_model','invite');



        $search = $search == 0 ? $this->input->post('search') : $search;

        $search = empty($search) ? 0 : $search;



        preg_match('/^\d*$/', $search)?$this->invite->invite_where('uid', $search):$this->invite->invite_where('username', $search);



        #配置分页信息



        $limit = 50;

        $uri_segment=5;

        $con = array(

                'base_url'=>site_url("mocuzfun/client_fun/invite/$search"),

                'total_rows'=>$this->invite->count(),

                'per_page'=>$limit,

                'uri_segment'=>$uri_segment

            );

        $data['pageinfo'] = $this->page($con);

        $data['listInfo'] = $listInfo = $this->invite->get_invite($limit,$offset);

        $data['search'] = $search;        

        $this->load->view('common/innerheader');

        $this->load->view('admin/mocuzfun/invite',$data);

    }



    public function invite_user($uid='',$offset ='')

    {

        $data['device_type'] = array(1 => 'ios', 2 => 'Android');

        $this->load->model('mocuz/set_invite_model','invite');

        #配置分页信息

        $limit = 50;

        $uri_segment = 5;

        $con = array(

                'base_url'=>site_url('mocuzfun/client_fun/invite_user/'.$uid),

                'total_rows'=>$this->invite->count_user($uid),

                'per_page'=>$limit,

                'uri_segment'=>$uri_segment

            );

        $data['pageinfo'] = $this->page($con);

        $data['listInfo'] = $this->invite->get_invite_user($uid,$limit,$offset);

   

        $data['uid'] = $uid;

        $this->load->view('common/innerheader');

        $this->load->view('admin/mocuzfun/invite_user',$data);

    }





    /**

     * [name_setting 名称管理]

     * @author  冯阳

     * @return [type] [description]

     */

    public function name_setting()

    { 

       $data['index_header_name'] =  $this->setting->get('index_header_name');   

       $data['index_block_name'] =  $this->setting->get('index_block_name');   

       $data['community_header_name'] = $this->setting->get('community_header_name');   

       $data['community_block_name'] = $this->setting->get('community_block_name'); 

	   $data['biu_block_name'] = $this->setting->get('biu_block_name');//板块名称

       $data['biu_header_name'] = $this->setting->get('biu_header_name');//板块头部名称



        $data['title']='名称管理';

        $this->data['now'] = 'name_setting';

		$this->load->view('common/innerheader',$data);

		$this->load->view('admin/mocuzfun/name_setting',$data);	

    }



    /**

     * [name_set 名称管理设置]

     * @author  冯阳

     * @return [type] [description]

     */

    public function name_set()

    {

        

        $config = array(

            array(

                'field' => 'index_header_name',

                'label' => '首页头部名称',

                'rules' => 'trim|regex_match[/^([\x{4e00}-\x{9fa5}]|\w|-){1,8}$/u]'

            ),

            array(

                'field' => 'index_block_name',

                'label' => '首页版块名称',

                'rules' => 'trim|regex_match[/^([\x{4e00}-\x{9fa5}]|\w|-){1,8}$/u]'

            ),            

            array(

                'field' => 'community_header_name',

                'label' => '社区头部名称',

                'rules' => 'trim|regex_match[/^([\x{4e00}-\x{9fa5}]|\w|-){1,8}$/u]'

            ),

            array(

                'field' => 'community_block_name',

                'label' => '社区板块名称',

                'rules' => 'trim|regex_match[/^([\x{4e00}-\x{9fa5}]|\w|-){1,8}$/u]'

            ),

			array(

                'field' => 'biu_block_name',

                'label' => 'biu板块名称',

                'rules' => 'trim|regex_match[/^([\x{4e00}-\x{9fa5}]|\w|-){1,8}$/u]'

            ),

            array(

                'field' => 'biu_header_name',

                'label' => 'biu头部名称',

                'rules' => 'trim|regex_match[/^([\x{4e00}-\x{9fa5}]|\w|-){1,8}$/u]'

			)



        );  

        $this->load->library('form_validation', $config);

        if($this->form_validation->run() == FALSE)

        {

            print_r($this->form_validation->error_array());exit;

        }



        $index_header_name=$this->input->post('index_header_name');

        $index_block_name=$this->input->post('index_block_name');

        $community_header_name=$this->input->post('community_header_name');

        $community_block_name=$this->input->post('community_block_name');



        $biu_block_name=$this->input->post('biu_block_name');

        $biu_header_name=$this->input->post('biu_header_name');



        $this->setting->set('index_header_name',$index_header_name);   

        $this->setting->set('index_block_name',$index_block_name);   

        $this->setting->set('community_header_name',$community_header_name);   

        $this->setting->set('community_block_name',$community_block_name); 

        $this->setting->set('biu_block_name',$biu_block_name);   

        $this->setting->set('biu_header_name',$biu_header_name);  

        redirect('mocuzfun/client_fun/name_setting');

    }





    /**

     * [login_register 登录注册]

     * @author 冯阳

     * @return [type] [description]

     */

    public function login_register()

    {

        

        $data['title']='登录与注册';

        $this->data['now'] = 'login_register';

        $data['tel_register'] = $this->setting->get('tel_register');

        $data['nick_register'] = $this->setting->get('nick_register');

        $data['qq_login'] = $this->setting->get('qq_login');

        $data['wexin_login'] = $this->setting->get('wexin_login');   

        $data['nopwd_login'] = $this->setting->get('not_password'); 

        //$this->_view('login_register',$data);

        $this->load->view('common/innerheader',$data);

        $this->load->view('admin/mocuzfun/login_register',$data); 

    }



    /**

     * [login_register_set 登录注册设置]

     * @author 冯阳

     * @return [type] [description]

     */

    public function login_register_set()

    {

        $config = array(

            array(

                'field' => 'tel_register',

                'label' => '手机号注册',

                'rules' => 'trim|required'

            ),

            array(

                'field' => 'nick_register',

                'label' => '用户名注册',

                'rules' => 'trim|required'

            ),            

            array(

                'field' => 'qq_login',

                'label' => '客户端QQ登录',

                'rules' => 'trim|required'

            ),

            array(

                'field' => 'wexin_login',

                'label' => '客户端微信登录',

                'rules' => 'trim|required'

            ),     

            array(

                'field' => 'nopwd_login',

                'label' => '手机免密登录',

                'rules' => 'trim|required'

            )                                           

        );  

        $this->load->library('form_validation', $config);

        if($this->form_validation->run() == FALSE)

        {

            print_r($this->form_validation->error_array());exit;

        }       



       $this->setting->set('tel_register',$this->input->post('tel_register') );  

       $this->setting->set('nick_register',$this->input->post('nick_register') ); 

       $this->setting->set('qq_login',$this->input->post('qq_login') ); 

       $this->setting->set('wexin_login',$this->input->post('wexin_login') );

       $this->setting->set('not_password',$this->input->post('nopwd_login') );

       redirect('mocuzfun/client_fun/login_register');

    }



    /**

     * [download_link 下载链接配置]

     * @return [type] [description]

     */

    public function download_link()

    {

        $linkswitch = $this->setting->get('link_switch');//1 是应用宝 2其他应用上架市场

        $data['switch']=$linkswitch['value'];

        $linkvalue = $this->setting->get('link_value');

        $sharecontent = $this->setting->get('share_content');

        $data['linkvalue'] = unserialize($linkvalue['value']);

        $data['sharecontent'] = $sharecontent['value'];

        $data['title'] = '下载链接配置';

        $this->load->view('common/innerheader',$data);

        $this->load->view('admin/mocuzfun/download_link',$data);        

    }



    public function save_link()

    {

       $link_value = $this->input->post('link_value');

       $share_content = $this->input->post('share_content');

       $link_value = serialize($link_value);

       $this->setting->set('link_switch',$this->input->post('link_switch'));  

       $this->setting->set('link_value',$link_value); 

       $this->setting->set('share_content',$share_content); 

       $this->json(1,'success');

    }

}