<?php
/**
 * sendsms($mobile,$msg)
 *
 *  ���Ͷ���
 * @param      none
 * @global     none
 * @return     void
 * @update    2011-10-25
*/
function sendsms($mobile,$msg,$type='ad',$yzm="")
{
	get_api(API_ESF_SENDSMS."?conf_cityflag=nj&mobile=".$mobile."&msg=".urlencode($msg)."&type=".$type."&ymz=".$yzm);
}

/**
 * get_api($url, $nocache = 0)
 *
 * �ӿں��� Fisher 2013-1-12
*/
if(!function_exists('get_api'))
{
	function get_api($url,$nocache = 0)
	{

		return curl_get_contents($url,$nocache);
	}
}

function curl_get_contents($str,$t_url="")
	{
		$ch = curl_init();
		$t_url = $t_url ? $t_url : "http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
		curl_setopt($ch, CURLOPT_URL, $str);
		curl_setopt($ch, CURLOPT_REFERER, $t_url);
		curl_setopt($ch,CURLOPT_RETURNTRANSFER, 1);

		$str = curl_exec($ch);
		curl_close($ch);
		return $str;
	}

function curl_get_contents_new($str,$t_url="", $cookie = '')
{
    $ch = curl_init();
    $t_url = $t_url ? $t_url : "http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
    curl_setopt($ch, CURLOPT_URL, $str);
    curl_setopt($ch, CURLOPT_COOKIE, $cookie);
    curl_setopt($ch, CURLOPT_REFERER, $t_url);
    curl_setopt($ch,CURLOPT_RETURNTRANSFER, 1);

    $str = curl_exec($ch);
    curl_close($ch);
    if ( empty( $str ) ) {
        return array();
    }

    return json_decode( $str, 1 );
}

/**
 * random($length)
 *
 *  �������������
 * @param      none
 * @global     none
 * @return     void
 * @update    2011-10-25
*/
function random($length) {
	$hash = '';
	$chars = '123456789';
	$max = strlen($chars) - 1;
	for($i = 0; $i < $length; $i++) {
	$hash .= $chars[mt_rand(0, $max)];
	}
	return $hash;
}



if(!function_exists('jumpto'))
{
	function jumpto($url, $sec = 1000)
	{
		echo "<script>setTimeout(function(){window.location.href='".$url."';}, ".$sec.");</script>";
		exit;
	}
}

if(!function_exists('jumptotk'))
{
	function jumptotk($url, $message = "ִ����ϣ�", $sec = 3000, $template = "tips")
	{
        if($template == 'tips')
        {
        echo '<div class="pop" style="width:390px;height:160px; position:absolute;left:50%;top:50%;margin-left:-200px;margin-top:-120px;-moz-box-shadow: 0 0 34px #cacaca;-webkit-box-shadow: 0 0 34px #cacaca;box-shadow: 0 0 34px #cacaca;border:1px solid #ccc;">
        <div class="hd" style="height:40px;background:#FF8400">
        <h2 style="font-size:14px;color:#fff;font-weight:800; position:absolute;left:10px;top:10px">��ʾ</h2>
        <a href="javascript:void(0)" class="close-pop" style="display:block;width:30px;height:30px;background:url('.USER_CENTER.'images/pop-ico.gif) 0 -80px no-repeat; position:absolute;right:10px;top:6px; text-indent:-999px; overflow:hidden" onclick="location.href=\''.$url.'\'">�ر�</a>
        </div>
        <div class="bd" style="background:#fff;height:120px">
        <div style="width:70px;height:80px;background:url('.USER_CENTER.'images/pop-ico.gif) no-repeat; position:absolute;left:70px;top:60px"></div>
        <p style="position:absolute;left:160px;top:85px;font-size:14px">'.$message.'</p>
        </div>
        </div>';
        }elseif($template == 'tipswaring'){
        echo '<div class="pop" style="width:390px;height:160px;border:1px solid #ccc; position:absolute;left:50%;top:50%;margin-left:-200px;margin-top:-120px;-moz-box-shadow: 0 0 34px #cacaca;-webkit-box-shadow: 0 0 34px #cacaca;box-shadow: 0 0 34px #cacaca;">
        <div class="hd" style="height:40px;background:#FF8400">
        <h2 style="font-size:14px;color:#fff;font-weight:800; position:absolute;left:10px;top:10px">��ʾ</h2>
        <a href="javascript:void(0)" class="close-pop" style="display:block;width:30px;height:30px;background:url('.USER_CENTER.'images/pop-ico.gif) 0 -80px no-repeat; position:absolute;right:10px;top:6px; text-indent:-999px; overflow:hidden" onclick="location.href=\''.$url.'\'">�ر�</a>
        </div>
        <div style="width:70px;height:80px;background:url('.USER_CENTER.'images/pop-ico.gif) no-repeat -2px -113px; position:absolute;left:70px;top:60px"></div>
        <p style="position:absolute;left:160px;top:85px;font-size:14px">'.$message.'</p>
        </div>
        </div>';
        }
		echo "<script>setTimeout(function(){window.location.href='".$url."';}, ".$sec.");</script>";
		exit;
	}
}


function tel_yc($tel)
{
    //�����ֻ��Ų�������
    $pattern = "/(1\d{1,2})\d\d(\d{0,3})/";
    $replacement = "\$1****\$3";

    return preg_replace($pattern, $replacement, $tel);
}


/*���õ�¼cookie*/
function vbsetcookie($name,$value="",$permanent=1) {

      $cookiedomain=".house365.com";
      $cookiepath="/";

      if ($permanent) {
        $expire=time() + 60*60*24*365;
      } else {
        $expire = 0;
      }

    setcookie($name, $value, $expire, $cookiepath, $cookiedomain, 0);

}

/*����cookie,session*/
function setcoandsess($name,$value="",$permanent=1) {

      $cookiedomain=".house365.com";
      $cookiepath="/";

      if ($permanent) {
        $expire=time() + 60*60*24*365;
      } else {
        $expire = 0;
      }

    setcookie($name, $value, $expire, $cookiepath, $cookiedomain, 0);
    $_SESSION[$name] = $value;
}


function StrCode($string,$action='ENCODE'){
    $key	=substr(md5($_SERVER["HTTP_USER_AGENT"]),8,18);
    $string	=$action =='ENCODE' ? $string : base64_decode($string);
    $len	=strlen($key);
    $code	='';
    for($i=0; $i<strlen($string); $i++){
        $k		=$i % $len;
        $code  .=$string[$i] ^ $key[$k];
    }
    $code=$action =='DECODE' ? $code : base64_encode($code);
    return $code;
}


/**
 * GetIP - ��ȡ�ͻ���IP��ַ
 *
 * @access	public
 * @param	none
 * @return	string	IP��ַ
 */
if ( ! function_exists('get_ip'))
{
    function get_ip()
    {
        $ip = $_SERVER["REMOTE_ADDR"];

        if( !empty( $_SERVER["HTTP_X_FORWARDED_FOR"] ) )
        {
            $tip    = explode(",",$_SERVER["HTTP_X_FORWARDED_FOR"]);
            $ip = $tip[0];
        }

        return(trim($ip));
    }
}





//�Ͼ�վ���ݱ����ͷ�ԴID��ȡ��ԴͼƬ�洢�ı�����
if ( ! function_exists('get_upload_tblname'))
{
	function get_upload_tblname($tbl,$id){
		
		if(GB_CITY !='nj') return 'upload';

		if($tbl == 'sell' && $id < 23972101) return 'upload0';

		if($tbl == 'rent' && $id < 11907211) return 'upload0';

		if($tbl == 'sell' && ($id >= 23972101 && $id < 27029364)) return 'upload1';

		if($tbl == 'rent' && ($id >= 11907211 && $id < 13224200)) return 'upload1';

		if($tbl == 'sell' && ($id >= 27029364 && $id < 31695721)) return 'upload2';

		if($tbl == 'rent' && ($id >= 13224200 && $id < 14495163)) return 'upload2';

		if($tbl == 'sell' && ($id >= 31695721 && $id < 34963370)) return 'upload3';

		if($tbl == 'rent' && ($id >= 14495163 && $id < 15172611)) return 'upload3';

		if($tbl == 'sell' && ($id >= 34963370 && $id < 38640564)) return 'upload4';

		if($tbl == 'rent' && ($id >= 15172611 && $id < 15871631)) return 'upload4';

		if($tbl == 'sell' && ($id >= 38640564 && $id < 42138930)) return 'upload5';

		if($tbl == 'rent' && ($id >= 15871631 && $id < 16675751)) return 'upload5';

		if($tbl == 'sell' && ($id >= 42138930 && $id < 45947999)) return 'upload';

		if($tbl == 'rent' && ($id >= 16675751 && $id < 43871899)) return 'upload';

		if($tbl == 'sell' && ($id >= 45947999 && $id < 49830000)) return 'upload6';
													 //49825505
		if($tbl == 'rent' && ($id >= 43871899 && $id < 45040000)) return 'upload6';
													 //45038726

		if($tbl == 'sell' && ($id >= 49830000 && $id < 54705651)) return 'upload7';
													 //54703651 
		if($tbl == 'rent' && ($id >= 45040000 && $id < 45788862)) return 'upload7';
													 //45787862
		if($tbl == 'sell' && ($id >= 54705651 && $id < 58020733)) return 'upload8';
													 //58018737 
		if($tbl == 'rent' && ($id >= 45788862 && $id < 46230598)) return 'upload8';
													 //46229598
		if($tbl == 'sell' && ($id >= 58020733 && $id < 61223139)) return 'upload9';
                                                 //61221139
		if($tbl == 'rent' && ($id >= 46230598 && $id < 46633747)) return 'upload9';
													 //46633347
		if($tbl == 'sell' && ($id >= 61223139 && $id < 63983200)) return 'upload10';
                                                 //63981991
	    if($tbl == 'rent' && ($id >= 46633747 && $id < 46923000)) return 'upload10';
                                                 //46922654
	    if($tbl == 'sell' && ($id >= 63983200 && $id < 66893902)) return 'upload11';
                                                 //66892902
	    if($tbl == 'rent' && ($id >= 46923000 && $id < 47264784)) return 'upload11';
                                                 //47264284
	    if($tbl == 'sell' && ($id >= 66893902 && $id < 71182067)) return 'upload12';
                                                 //71181067
		if($tbl == 'rent' && ($id >= 47264784 && $id < 47951200)) return 'upload12';
													 //47950659
        if($tbl == 'sell' && ($id >= 71182067 && $id < 76015831)) return 'upload13';
                                                 //76014531
	    if($tbl == 'rent' && ($id >= 47951200 && $id < 48556731)) return 'upload13';                                                                             //48556231

	    if($tbl == 'sell' && ($id >= 76015831 && $id < 81507192)) return 'upload14';
                                                 //81506192 
		if($tbl == 'rent' && ($id >= 48556731 && $id < 49140972)) return 'upload14';                                                                        //49140466

		if($tbl == 'sell' && ($id >= 81507192 && $id < 88723014)) return 'upload15';
                                                 //88722131  
		if($tbl == 'rent' && ($id >= 49140972 && $id < 49884209)) return 'upload15';
													//49883609

		if($tbl == 'sell' && ($id >= 88723014 && $id < 95316101)) return 'upload16';
                                                 //95314101  
	    if($tbl == 'rent' && ($id >= 49884209 && $id < 50532293)) return 'upload16';
	                                            //50531293

	    if($tbl == 'sell' && ($id >= 95316101 && $id < 103859999)) return 'upload17';
                                                 //103819999  
		if($tbl == 'rent' && ($id >= 50532293 && $id < 51527468)) return 'upload17';
													//51527468
		

		if($tbl == 'sell' && ($id >= 103859999 && $id < 108815839)) return 'upload18';
                                                 //108806111  
		if($tbl == 'rent' && ($id >= 51527468 && $id < 52249156)) return 'upload18';
													//52239180
		if($tbl == 'sell' && ($id >= 108815839 && $id < 114379999)) return 'upload19';
                                               
		if($tbl == 'rent' && ($id >= 52249156 && $id < 53130499)) return 'upload19';
												   
		
		if($tbl == 'sell' && ($id >= 114379999 && $id < 119229999)) return 'upload20';
                                               
		if($tbl == 'rent' && ($id >= 53130499 && $id < 53780499)) return 'upload20';
												   
		
		
		if($tbl == 'sell' && ($id >= 119229999 && $id < 123619999)) return 'upload21';
												   
		if($tbl == 'rent' && ($id >= 53780499 && $id < 54659999)) return 'upload21';
												   
		
		if($tbl == 'sell' && ($id >= 123619999 && $id < 128434999)) return 'upload22';
                                               
		if($tbl == 'rent' && ($id >= 54659999 && $id < 55793999)) return 'upload22';
	                                           
	
		if($tbl == 'sell' && ($id >= 128434999 && $id < 132662039)) return 'upload23';
                                               
		if($tbl == 'rent' && ($id >= 55793999 && $id < 56609929)) return 'upload23';
	                                           
	
		if($tbl == 'sell' && ($id >= 132662039 && $id < 136312505)) return 'upload24';
                                               
		if($tbl == 'rent' && ($id >= 56609929 && $id < 57307409)) return 'upload24';
	                                           
	
		if($tbl == 'sell' && ($id >= 136312505 && $id < 140145507)) return 'upload25';
                                               
		if($tbl == 'rent' && ($id >= 57307409 && $id < 58017786)) return 'upload25';
	                                           
	
		if($tbl == 'sell' && ($id >= 140145507 && $id < 147125418)) return 'upload26';
                                               
		if($tbl == 'rent' && ($id >= 58017786 && $id < 59209979)) return 'upload26';
	
		if($tbl == 'sell' && ($id >= 147125418 && $id < 154138704)) return 'upload27';
                                               
		if($tbl == 'rent' && ($id >= 59209979 && $id < 60562010)) return 'upload27';
		
		if($tbl == 'sell' && ($id >= 154138704 && $id < 166754880)) return 'upload28';
                                               
		if($tbl == 'rent' && ($id >= 60562010 && $id < 63483875)) return 'upload28';
	
		if($tbl == 'sell' && ($id >= 166754880 && $id < 264744742)) return 'upload29';
                                               
		if($tbl == 'rent' && ($id >= 63483875 && $id < 84955643)) return 'upload29';
	
		return 'upload30';
	}
}



/**
 * ��ȡ���ַ��ķ�Դ��ַ
 * @param array  $row ��Դ��Ϣ,���뺬��id
 * @return stirng
 */
if(!function_exists('get_sellinfo_url'))
{
	function get_sellinfo_url($row)
	{

		if(is_array($row)) {
			if(!empty($row['ID']))$row['id']=$row['ID'];
			$ss = GB_SELL_URL."/s_".$row['id'].".html";
		}else{
			$ss = GB_SELL_URL."/s_".$row.".html";
		}
		return $ss;
	}
}


/**
 * ��ȡ�󹺵�ַ
 * @param array  $row ��Դ��Ϣ,���뺬��id
 * @return stirng
 */
if(!function_exists('get_buyinfo_url'))
{
	function get_buyinfo_url($row)
	{
		if(is_array($row)) {
			if(!empty($row['ID']))$row['id']=$row['ID'];
			$ss = $GB_SELL_URL."/b_".$row['id'].".html";
		} else {
			$ss = $GB_SELL_URL."/b_".$row.".html";
		}
		return $ss;
	}
}

/**
 * ��ȡ�ⷿ�ķ�Դ��ַ
 * @param array  $row ��Դ��Ϣ,���뺬��id
 * @return stirng
 */
if(!function_exists('get_rentinfo_url'))
{
    function get_rentinfo_url($row,$pre = 'r') //��Դ��ַ
    {
        if(is_array($row)) {
            if(!empty($row['ID'])) $id = $row['ID'];
            else $id = $row['id'];
        }else{
            $id = $row;
        }

        $ss = GB_RENT_URL."/".$pre."_".$id.".html";

        return $ss;
    }
}

/**
 * ��ȡ�ʴ��ַ
 * @param array  $qid
 * @return stirng
 */
if(!function_exists('get_questioninfo_url'))
{
	function get_questioninfo_url($qid) //��Դ��ַ
	{
		$ss = GB_SELL_URL."/ask_".$qid.".html";
        return $ss;
	}
}



/**
 * ��ȡС����ַ
 * @param array  $id
 * @return stirng
 */
 function get_blockinfo_url($id)
 {
 $ss = GB_SELL_URL."/community_id".$id."/";

 return $ss;
 }

 /**
  *��ȡѧУ��ַ
  *@param int $id
  *@return string
  */
  function get_school_url($id){
	$url = GB_SELL_URL."/school_id".$id."/";
	return $url;
  }


 /**
  *��ȡѧУС����ַ
  *@param int $id
  *@return string
  */
  function get_schoolblock_url($id){
	$url = GB_SELL_URL."/school_id".$id."/community.html";
	return $url;
  }

  /**
  *��ȡѧУ���ַ���ַ
  *@param int $id
  *@return string
  */
  function get_schoolsell_url($id){
	$url = GB_SELL_URL."/school_id".$id."/sell.html";
	return $url;
  }

  /**
  *��ȡѧУ�ⷿ��ַ
  *@param int $id
  *@return string
  */
  function get_schoolrent_url($id){
	$url = GB_SELL_URL."/school_id".$id."/rent.html";
	return $url;
  }



/**
 * �ж�ֵ�Ƿ�Ϊ����
 * @param array $arrValue
 * @return bool true or false
 * @author sun
 */
function isFullArray($arrValue) {
    return is_array($arrValue) && !empty($arrValue) ? true : false;
}

/**
* time_tran ��������ʱ����
*
* @param string $the_time ʱ�����
* @return string �����ַ���
*/
function time_tran ($the_time) {

    $now_time = time();
    $dur = $now_time - $the_time;

    if($dur < 0){
        $str =  $the_time;
    }else{
        if($dur < 60){
            $str = $dur.'��ǰ';
        }else if($dur < 3600){
            $str = floor($dur/60).'����ǰ';
        }else if($dur < 86400){
            $str = floor($dur/3600).'Сʱǰ';
        }else if($dur < 259200){
            $str = floor($dur/86400).'��ǰ';
        }else if($dur > 259200){
            $str = date('Y-m-d H:i',$the_time);
        }
    }

    return  $str;
 }

//���ܣ����ܺ���  FISHER 2014-3-5
function passport_encrypt($txt, $key='fisher.house365.com') {
    srand((double)microtime() * 1000000);
    $encrypt_key = md5(rand(0, 32000));
    $ctr = 0;
    $tmp = '';
    for($i = 0;$i < strlen($txt); $i++) {
        $ctr = $ctr == strlen($encrypt_key) ? 0 : $ctr;
        $tmp .= $encrypt_key[$ctr].($txt[$i] ^ $encrypt_key[$ctr++]);
    }
    return urlencode(base64_encode(passport_key($tmp, $key)));
}

function passport_decrypt($txt, $key='fisher.house365.com') {
    $txt = passport_key(urldecode(base64_decode($txt)), $key);
    $tmp = '';
    for($i = 0;$i < strlen($txt); $i++) {
        $md5 = $txt[$i];
        $tmp .= $txt[++$i] ^ $md5;
    }
    return $tmp;
}
function passport_key($txt, $encrypt_key) {
    $encrypt_key = md5($encrypt_key);
    $ctr = 0;
    $tmp = '';
    for($i = 0; $i < strlen($txt); $i++) {
        $ctr = $ctr == strlen($encrypt_key) ? 0 : $ctr;
        $tmp .= $txt[$i] ^ $encrypt_key[$ctr++];
    }
    return $tmp;
}

function check_input($value)
{
// ȥ��б��
if (get_magic_quotes_gpc())
  {
  $value = stripslashes($value);
  }
// ������������������
if (!is_numeric($value))
  {
  $value = "'" . mysql_real_escape_string($value) . "'";
  }
return $value;
}


/**
 * jsonNew �����ݽ���gbkתutf8��json���� json($data)
 * @param mixed $data ��Ҫ���������
 * @return mixed $data_json ����������
 * @ 2012-10-16 xz
**/
function jsonNew($data,$inChar="GBK",$outChar="UTF-8") {
	if(!$data) return $data;

	$data =	strIconv($data,$inChar,$outChar);
 	return json_encode($data); 
}


 /**
 * �滻�������(֧���ַ����Ͷ�ά����)
 * @param mixed $strInput
 * @param string $inChar
 * @param string $outChar
 * @return string
 */
function strIconv($strInput,$inChar="GBK",$outChar="UTF-8"){

	if(is_array($strInput)){
		$strOutput = array();
		foreach($strInput as $key=>$val){
			$key = strIconv($key,$inChar,$outChar);
			$strOutput[$key] = strIconv($val,$inChar,$outChar);
		}
	}else{
		$strOutput = iconv($inChar,$outChar,$strInput);
	}
	
	if($strOutput !== false)
		return $strOutput;
	else
		return $strInput;
}


//ͨ��curlģ��post������
function SendDataByCurl($url,$data=array()){
    //�Կո����ת��
    $url = str_replace(' ','+',$url);
    $ch = curl_init();
    //����ѡ�����URL
    curl_setopt($ch, CURLOPT_URL, "$url");
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_HEADER, 0);
    curl_setopt($ch,CURLOPT_TIMEOUT,3);  //���峬ʱ3����  
     // POST����
    curl_setopt($ch, CURLOPT_POST, 1);
    // ��post�ı�������
    curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));    //���贫��������http_bulid_query()��������һ�£���ok��
    
    //ִ�в���ȡurl��ַ������
    $output = curl_exec($ch);
    $errorCode = curl_errno($ch);
    //�ͷ�curl���
    curl_close($ch);
    if(0 !== $errorCode) {
        return false;
    }
    return $output;

}


function getJiaUserID($uid_str){
	$post['userid'] = $uid_str;
	$personal_api_url = "http://jia.wuhan.house365.com/api/index.php?app=get_passport_uid";
	$json = SendDataByCurl($personal_api_url,$post);
	$return = (json_decode($json, true));
	if($return['status']==1){
		return $return['data'][$uid_str];
	
	}




    
}





/* End of file function_helper.php */
/* Location: ./system/helpers/function_helper.php */