<?php
session_start();
require_once("../common/init.php");


if ($_GET[lang]=="")
{

$sqllanginfo = "select * from ch_lang  where AutoDo='1'   ";
}
else
{
	

$lang=$_GET[lang];
$sqllanginfo = "select * from ch_lang  where ProductName='$lang'  ";
}
$langInfo  = $DB->getdata($sqllanginfo);
$lang_agentname=$langInfo[ProductIntro];

$lang=$langInfo[ProductName];

$smarty->assign('lang_sj',$langInfo[sj]);
$smarty->assign('lang_zc',$langInfo[zc]);
$smarty->assign('lang_wjmm',$langInfo[wjmm]);
$smarty->assign('lang_sjb',$langInfo[sjb]);

$smarty->assign('lang_dl',$langInfo[dl]);
$smarty->assign('lang_jrsc',$langInfo[jrsc]);
$smarty->assign('lang_jg',$langInfo[jg]);
$smarty->assign('lang_ckxq',$langInfo[ckxq]);

$smarty->assign('lang_rmb',$langInfo[rmb]);
$smarty->assign('lang_yuan',$langInfo[yuan]);
$smarty->assign('lang_sjtime',$langInfo[sjtime]);
$smarty->assign('lang_zz',$langInfo[zz]);
$smarty->assign('lang_sl',$langInfo[sl]);
$smarty->assign('lang_cpjs',$langInfo[cpjs]);
$smarty->assign('lang_cply',$langInfo[cply]);
$smarty->assign('lang_dqwz',$langInfo[dqwz]);
$smarty->assign('lang_syindex',$langInfo[syindex]);

$smarty->assign('lang_soshuo',$langInfo[soshuo]);
$smarty->assign('lang_cpsoshuo',$langInfo[cpsoshuo]);
$smarty->assign('lang_wzsoshuo',$langInfo[wzsoshuo]);

$smarty->assign('lang_tjwt',$langInfo[tjwt]);
$smarty->assign('lang_wtlx',$langInfo[wtlx]);

$smarty->assign('lang_lxr',$langInfo[lxr]);
$smarty->assign('lang_lybt',$langInfo[lybt]);
$smarty->assign('lang_lylr',$langInfo[lylr]);
$smarty->assign('lang_yzm',$langInfo[yzm]);
$smarty->assign('lang_yzmzq',$langInfo[yzmzq]);
$smarty->assign('lang_yzmcw',$langInfo[yzmcw]);
$smarty->assign('lang_wtlb',$langInfo[wtlb]);
$smarty->assign('lang_gong',$langInfo[gong]);
$smarty->assign('lang_gong1',$langInfo[gong1]);
$smarty->assign('lang_gong2',$langInfo[gong2]);
$smarty->assign('lang_gong3',$langInfo[gong3]);
$smarty->assign('lang_oprice',$langInfo[oprice]);
$smarty->assign('lang_nprice',$langInfo[nprice]);

$smarty->assign('lang_welcome',$langInfo[welcome]);
$smarty->assign('lang_logout',$langInfo[logout]);
$smarty->assign('lang_gl',$langInfo[gl]);

$smarty->assign('lang_lb',$langInfo[lb]);
$smarty->assign('lang_ljgm',$langInfo[ljgm]);
$smarty->assign('lang_cz',$langInfo[cz]);
$smarty->assign('lang_more',$langInfo[more]);
$smarty->assign('lang_fh',$langInfo[fh]);
$smarty->assign('lang_wdl',$langInfo[wdl]);
$smarty->assign('lang_ydl',$langInfo[ydl]);
$smarty->assign('lang_yhm',$langInfo[yhm]);
$smarty->assign('lang_mm',$langInfo[mm]);
$smarty->assign('lang_qrmm',$langInfo[qrmm]);
$smarty->assign('lang_lxrz',$langInfo[lxrz]);
$smarty->assign('lang_lxry',$langInfo[lxry]);
$smarty->assign('lang_gsmz',$langInfo[gsmz]);
$smarty->assign('lang_gsmy',$langInfo[gsmy]);
$smarty->assign('lang_gj',$langInfo[gj]);
$smarty->assign('lang_sf',$langInfo[sf]);
$smarty->assign('lang_cs',$langInfo[cs]);
$smarty->assign('lang_txdzz',$langInfo[txdzz]);
$smarty->assign('lang_txdzy',$langInfo[txdzy]);
$smarty->assign('lang_yb',$langInfo[yb]);
$smarty->assign('lang_czh',$langInfo[czh]);
$smarty->assign('lang_email',$langInfo[email]);

if($lang==""){
$lang="Chinese";
}

$smarty->assign('lang',$lang);
$smarty->assign('lang_agentname',$langInfo[ProductIntro]);
$UserName = $_POST['UserName'];
$Password = $_POST['Password'];
$GoUrl = $_GET['GoUrl'];
//die($GoUrl);

$action = $_POST['act'];
$code = trim($_POST['code']);
if($action=='num'){ //检验数字验证码
	if($code==$_SESSION["helloweba_num"]){
       echo '1';
    }
}elseif($action=='char'){
	if($code==$_SESSION["helloweba_char"]){
       echo '1';
    }
}elseif($action=='zh'){
	$code = uniDecode($code,'utf-8');
	$ses = iconv('gbk','utf-8',$_SESSION["helloweba_zh"]);
	if($code==$ses){
       echo '1';
    }
}elseif($action=='gg'){
	//echo $_SESSION["helloweba_gg"];exit;
	if(strtolower($code)==$_SESSION["helloweba_gg"]){
       echo '1';
    }
}elseif($action=='math'){
	if($code==$_SESSION["helloweba_math"]){
       
    }
}else{

}

//处理接收中文字符串
function uniDecode($str, $charcode) {
	$text = preg_replace_callback("/%u[0-9A-Za-z]{4}/", toUtf8, $str);
	return mb_convert_encoding($text, $charcode, 'utf-8');
}
function toUtf8($ar) {
	foreach ($ar as $val) {
		$val = intval(substr($val, 2), 16);
		if ($val < 0x7F) { // 0000-007F
			$c .= chr($val);
		}
		elseif ($val < 0x800) { // 0080-0800
			$c .= chr(0xC0 | ($val / 64));
			$c .= chr(0x80 | ($val % 64));
		} else { // 0800-FFFF
			$c .= chr(0xE0 | (($val / 64) / 64));
			$c .= chr(0x80 | (($val / 64) % 64));
			$c .= chr(0x80 | ($val % 64));
		}
	}
	return $c;
}



if($UserName != ''){
   $sql = "select * from users where UserName='$UserName'";
   $UInfo = $db->getdata($sql);
   if($UInfo && $UInfo['Password']==MD5($Password) && $code==$_SESSION["helloweba_math"]){
	   if($UInfo['iStatus']==1){
		  $sql = "update users set dtLogin=now() where UserName='$UserName'";
		  $db->query($sql);
		  $db->close();
		  $_SESSION['User_S'] = $UInfo['UserName'];
		  $_SESSION['iLevel_S'] = $UInfo['iLevel'];
		  if($GoUrl){header("Location: $GoUrl");}
		  else {
echo "<script>window.parent.location.href='/user/index.php?lang=$lang';</script>";

}
		  exit;
	   }else{
if($code==$_SESSION["helloweba_math"]){

}
else{
 $mess_code = $langInfo[yzmcw];
}
	      $mess = $langInfo[zhjy];
	   }
   }else{
if($code==$_SESSION["helloweba_math"]){

}
else{
 $mess_code = $langInfo[yzmcw];
}
if($UInfo && $UInfo['Password']==MD5($Password))
{
}
else
{
$mess = $langInfo[mmcw];

}
      
   }
}
$smarty->assign('lang',$lang);

$smarty->assign('GoUrl',$GoUrl);
$smarty->assign('mess',$mess);
$smarty->assign('mess_code',$mess_code);
$smarty->display('user_login.html');
$db->close();
?>