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

/**
* @author cxf
*/
class Dev_User_class
{

    public function __construct()
    {

    }

    function user_login($result,$password='',$telno='',$name='')
    {
        //隐藏手机号部分数字
        $pattern = "/(1\d{1,2})\d\d(\d{0,3})/";
        $replacement = "\$1*****\$3";
        $telno2 = preg_replace($pattern, $replacement, trim($telno));
        $showname = $telno2 ? $telno2 : $name ;
        $CI = &get_instance();

        $CI->load->model('user_model');
        
        $esfmesnum =  $CI->user_model->getmessagenumbyuidwd($result);

        if($telno=='')
        {
        $temp = $CI->user_model->getuserdetailUcenter($result);
        $telno = $temp['telno'];	
        }
        $password_encrypt = passport_encrypt($password);

        //设置COOKIE
        vbsetcookie("esfuserid","",1);
        vbsetcookie("esfpassword","",1);
        vbsetcookie("esfstyleid","",1);
        vbsetcookie("esfusertelno","",1);
        vbsetcookie("esfusername","",1);
        vbsetcookie("esfshowname","",1);
        vbsetcookie("esfmesnum","",1);
        vbsetcookie("ckinfo","",1);
        vbsetcookie("sessionhash","",1);
        vbsetcookie("esfuserid",$result);
        vbsetcookie("esfpassword",$password);
        vbsetcookie("esfusername",$name);
        vbsetcookie("esfusertelno",$telno);
        vbsetcookie("esfusercity",GB_CITY);
        vbsetcookie('lastvisit','',0);
        vbsetcookie("esfshowname",$showname);
        vbsetcookie("esf".GB_CITY."mesnum",$esfmesnum);
        //逐步替代password，最终去掉password的cookie，增加安全性
        vbsetcookie("esf_encrypt",$password_encrypt);



        //登录SESSION
        $array = array( 'esfuserid'=>$result , 'esfpassword'=>$password ,'esfusername'=>$name , 'esfusertelno'=>$telno ,'esfusercity'=>GB_CITY,'esfshowname'=>$showname,'esfmesnum'=>$esfmesnum);
        $CI->load->library('session');
        $CI->session->set_userdata($array);

        /* 登录日志记录 */
        $CI->load->model('user_statistic_model');

        //初始化用户信息
        $CI->user_statistic_model->set_uid($result);
        $CI->user_statistic_model->set_city(GB_CITY);

		//提交登录信息
        $CI->user_statistic_model->sub_login_log();

        $CI->load->model('user_model');
        //查询上次登录时间
        $last_logintime = $CI->user_model->getuserdetailUcenter($result);

        if(date("Y-m-d",$last_logintime['lastlogintime']) != date("Y-m-d"))
        {
			//查询小区是否有新房源
			$msg1 = $CI->user_model->getnewblockhouse($result,$last_logintime['lastlogintime']);
			$CI->load->library("apply_class");

			if(is_array($msg1) && !empty($msg1))
			{
				$string = implode(',',$msg1);
				//发送消息
				$subject = '您关注的小区有新的房源。';
				$msg = '您关注的小区“'.$string.'”有新的房源发布，<a href="'.USER_CENTER.'user/blocklist">点击查看</a>。';
				$CI->apply_class->send_systemmsg($result,$subject,$msg,2,GB_CITY);
			}

			//查询找房条件是否有新房源
			$result = $CI->user_model->getnewtjhouse($result,$last_logintime['lastlogintime']);

			if($result == 1)
			{
				//发送消息
				$subject = '您关注的找房条件有新的房源。';
				$msg = '您关注的找房条件有新的房源。<a href="'.USER_CENTER.'user/sell_condition">点击查看</a>。';
				$CI->apply_class->send_systemmsg($result,$subject,$msg,2,GB_CITY);
			}
        }

        return 1;
    }




}