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




header("Cache-control: private");



require_once "../admin/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];
if($lang==""){
$lang="Chinese";
}

$sql = 'select max(id) from notes';
$rs1=$DB->query($sql);
$maxID=mysql_fetch_array($rs1);
$maxid=$maxID['max(id)'];

//$notes = '';  
//$left='';  
//$top='';  
//$zindex='';  
//$width='';  
//$height=''; 

//$sql = 'select * from notes order by id desc';
//$rs=$DB->query($sql);
//while($row=mysql_fetch_array($rs)){
	//list($left,$top,$zindex) = explode('|',$row['xyz']); 
//$content =html_entity_decode($row['content']);

	//$notes.= '

	//<div  class="note '.$row['color'].'" ID='.$row['id'].' style="left:'.$left.'px;top:'.$top.'px;z//-index:'.$zindex.';width:'.$row['width'].';height:'.$row['height'].';">
		
//<h3 >标题栏</h3>

//<span class="data">'.$row['id'].'.</span>'.$content.'
	//</div>';
//}


function cutStr($str,$len){
	$str=trim(strip_tags($str));
	$str=str_replace("　","",$str);
	$str=str_replace("&nbsp;","",$str);
	$str=mb_substr($str,0,$len,'gbk');
	return $str;
}


$arProType = array();
$proType = new ProductType4();
$tree = $proType->ShowmenuTree('0',0,$arProType);


	      $treestring .= "<ul id='nav_all'>";


	  for($i=0;$i<count($tree);$i++){
	
		if($tree[$i]['showindex']==1& $tree[$i]['lang']==$lang){
          $treestring .="".$tree[$i]['Disp']."";
}
		
		
	  }
   	
	 $treestring .= "</ul>";


$arProType_lang = array();
$proType_lang = new ProductType5();
$tree_lang = $proType_lang->ShowProTypeTree1('0',0,$arProType_lang);
 $treestringlang .= "<span class='select-box select'   ><select id='menu_lang'  onchange='pagelang()' name='lang' >";

   $treestringlang .="<option value='Chinese' $selected>默认中文</option>";
	  for($i=0;$i<count($tree_lang);$i++){
	
		$selected = ($lang==$tree_lang[$i]['ProductName'])?"selected":"";
if($tree_lang[$i]['ProductName']!="Chinese"){
   $treestringlang .="<option value='".$tree_lang[$i]['Disp']."' $selected>".$tree_lang[$i]['Disp']."</option>";


		
		
		 }
		 $name_lang1="|";
		if($tree_lang[$i]['ProductName']=="Chinese"){
			if($lang=="Chinese"){
				$name_lang="中文";
				$name_lang1="|";
			}
			else{
$name_lang="中文";

			}
}
else
		  {
$name_lang=$tree_lang[$i]['ProductName'];
}
		  $treestringlang1.="<a href='index.php?lang=".$tree_lang[$i]['ProductName']."'> ".$name_lang1." ".$name_lang."</a>";
	  }
   	
	 $treestringlang .= "</select></span>";




$sql = "select * from menu   where isindex=1 and lang='$lang' ";
$isindexInfo  = $DB->getdata($sql);

if($_GET[page_id]){

$page_id=$_GET[page_id];
}

else
{
$page_id=$isindexInfo[IDProduct] ;

}
$sqlpageinfo = "select * from menu  where IDProduct='$page_id' and lang='$lang'  ORDER BY IDProduct DESC";
$pageInfo  = $DB->getdata($sqlpageinfo);
$head_width=$pageInfo[head_width];
$head_height=$pageInfo[head_height];
$main_width=$pageInfo[main_width];
$main_height=$pageInfo[main_height];
$foot_width=$pageInfo[foot_width];
$foot_height=$pageInfo[foot_height];
$foot_css=$pageInfo[foot_css];
$head_css=$pageInfo[head_css];
$main_css=$pageInfo[main_css];
$title_new=$pageInfo[title];
$keywords=$pageInfo[keywords];
 $treestringParentID=$pageInfo['ParentID'];
$description=$pageInfo[description];
$menu_name=$pageInfo[ProductName];
$head_width_mobile=$pageInfo[head_width_mobile];
$head_height_mobile=$pageInfo[head_height_mobile];
$main_width_mobile=$pageInfo[main_width_mobile];
$main_height_mobile=$pageInfo[main_height_mobile];
$foot_width_mobile=$pageInfo[foot_width_mobile];
$foot_height_mobile=$pageInfo[foot_height_mobile];
$foot_css_mobile=$pageInfo[foot_css_mobile];
$head_css_mobile=$pageInfo[head_css_mobile];
$main_css_mobile=$pageInfo[main_css_mobile];



//$sql = "select * from notes   where note_class!='news' and  note_class!='product' and showIndex=1 and page_id='$page_id' //or share=1  ORDER BY id DESC";

//$result = $db->query($sql);
//$notesItems = array();
//while($notesI=$db->fetch_array($result)){

 //$notesI['Content'] = $notesI['Content'];
	  
	 // list($notesI['left'],$notesI['top'],$notesI['zindex']) = explode('|',$notesI['xyz']); 
	 // $notesItems[] = $notesI;	  
//}





//这是什么

//$sql = "select * from doc ORDER BY dtCreate DESC limit 3";
//$result = $db->query($sql);
//$pageList = GetPageList($_SERVER[PHP_SELF],"page","15",$totalPage,$page);
//$DocItems = array();
//while($DocI=$db->fetch_array($result)){
	//$DocI['dtCreate'] = date("Y-m-d",strtotime($DocI['dtCreate']));
	//$DocI['Content'] = cutStr($DocI['Content'],70)."...";
	//if(strlen($DocI['Title'])>28)$DocI['Title'] = msubstr($DocI['Title'],0,16)."...";
	 // $DocItems[] = $DocI;	  
//};

if($_GET[page_id]){
$query1 ="select * from notes  where showIndex=1  and mobile='1' or  share=2 and mobile='1' or   share='1' and mobile='1' ORDER BY id DESC";}
else
{
$query1 ="select * from notes  where showIndex=1  and mobile='1' or  share=1 and mobile='1'  ORDER BY id DESC";

}
$rs1=$DB->query($query1);

//循环所有模块

while($row_c=$db->fetch_array($rs1)){


	  list($row_c['left'],$row_c['top'],$row_c['zindex']) = explode('|',$row_c['xyz']); 

if($row_c['note_class']=='search_news'){
$smarty->assign("news_search_page",$row_c['news_open_pageid']);
}

if($row_c['note_class']=='search_pro'){
$smarty->assign("pro_search_page",$row_c['pro_open_pageid']);
}

if($row_c['note_class']=='news' )
 {

//如果为新闻模块
$news_id=$row_c['news_id'];
if($row_c['news_nub']){
$news_nub=$row_c['news_nub'];}
else{
$news_nub=5;
}
$page=$_GET['page'];
$NewsID=$_GET['NewsID'];

if($news_id==0){
$sql3 = "select count(*) from news where showIndex=1  ";
}
else{
$sql3 = "select count(*) from news where showIndex=1 and  ClassName='$news_id' ";
}
if($_GET['news_fl']){
$news_fl=$_GET['news_fl'];
$sql3= "select  count(*) from  news where ClassName ='$news_fl'    ";

}

if($_POST['keyword_news']){
$keyword_news = $_POST['keyword_news'];

$keyword_news=trim($keyword_news);
if($keyword_news){
	$wheres_news=" AND (NewsID like '%$keyword_news%' or Title like '%$keyword_news%' or Content like '%$keyword_news%') ";
}
//得到总记录数
$sql3="select count(*) from news where 1 $wheres_news";
}

$rs3  = $db->query($sql3);
$pageSize = $news_nub;
$totalRecord = $db->result($rs3,0,0);
$totalPage = @ceil($totalRecord/$pageSize);

if(!$page)$page = 1;
$offset = ($page-1)*$pageSize;


if($news_id==0){
$query2 ="select * from news where showIndex=1   ORDER BY dtCreate DESC limit $offset,$pageSize";
}
else
{


$query2 ="select * from news where showIndex=1 and  ClassName='$news_id'  ORDER BY dtCreate DESC limit $offset,$pageSize";
}

if($_GET['news_fl']!=''){
$news_fl=$_GET['news_fl'];
$query2= "select * from news where ClassName ='$news_fl'    ORDER BY dtCreate DESC limit $offset,$pageSize";

}

$keyword_news = $_POST['keyword_news'];

$keyword_news=trim($keyword_news);
if($keyword_news){
	$where_news=" AND (NewsID like '%$keyword_news%' or Title like '%$keyword_news%' or Content like '%$keyword_news%') ";

	$query2 = "select * from news where 1 $where_news order by dtCreate desc limit $offset,$pageSize";


}

$rs2=$DB->query($query2);

$pageList = GetPageList($_SERVER[PHP_SELF],"page","15",$totalPage,$page);
$PNum = $DB->num_rows($rs2);
$pagers="共 $totalRecord 条记录,共 $totalPage 页,当前第 $page 页";
if($pageList) $pagers.= " <br>$pageList[0] $pageList[1]";

while($row_p=$db->fetch_array($rs2)){
	  /* $row_p['dtCreate'] = date("Y-m-d",strtotime($row_p['dtCreate']));*/
 $row_p['dtCreate'] = $row_p['dtCreate'];
	  $row_p['month'] = date("m",strtotime($row_p['dtCreate']));
	  $row_p['day'] = date("d",strtotime($row_p['dtCreate']));
	 $row_p['Content'] = cutStr($row_p['Content'],70)."...";
$Contentall=$row_p['Content'];
	  if(strlen($row_p['Title'])>28)$row_p['Title'] = msubstr($row_p['Title'],0,16)."...";
	  $produ[]=array("NewsID"=>$row_p['NewsID'],"Title"=>$row_p['Title'],"Content"=>$row_p['Content'],"dtCreate"=>$row_p['dtCreate'],"Pic"=>$row_p['pic'],"Contentall"=>$Contentall); 	
	  
	
}

if($row_c['news_fy']){
$pagers=$pagers;
}
else
{
$pagers="";
}

}
//如果为新闻完
if($row_c['note_class']=='product'){

//如果为产品模块

$pro_id=$row_c['pro_id'];
if($row_c['pro_nub']){
$pro_nub=$row_c['pro_nub'];}
else{
$pro_nub=15;
}
$page=$_GET['page'];
$proID=$_GET['proID'];

if($pro_id==0){
	

$sql3 = "select count(*) from products where show_index=0 and Type='product' ";

}
else{

	
$sql3 = "select count(*) from products where show_index=0 and  ParentID='$pro_id' and Type='product' ";


}
if($_GET['pro_fl']){
$pro_fl=$_GET['pro_fl'];
$sql3= "select  count(*) from products where ParentID ='$pro_fl' and Type='product'   ";

}
if($_POST['keyword_pro']){
$keyword_pro = $_POST['keyword_pro'];

$keyword_pro=trim($keyword_pro);
if($keyword_pro){
	$wheres_pro=" AND (ProductName like '%$keyword_pro%' or txtDetail like '%$keyword_pro%') ";
}
//得到总记录数
$sql3="select count(*) from products where 1 $wheres_pro";
}

$rs3  = $db->query($sql3);
$pageSize = $pro_nub;
$totalRecord = $db->result($rs3,0,0);
$totalPage = @ceil($totalRecord/$pageSize);

if(!$page)$page = 1;
$offset = ($page-1)*$pageSize;


if($pro_id==0){
$query2 ="select * from products where show_index=0   and Type='product' ORDER BY dtCreate DESC limit $offset,$pageSize";
}
else
{


$query2 ="select * from products where show_index=0 and  ParentID='$pro_id'  and Type='product' ORDER BY dtCreate DESC limit $offset,$pageSize";
}

if($_GET['pro_fl']!=''){
$pro_fl=$_GET['pro_fl'];
$query2= "select * from products where ParentID ='$pro_fl' and Type='product'  and show_index=0   ORDER BY dtCreate DESC";

}


if($_POST['keyword_pro']){
$keyword_pro = $_POST['keyword_pro'];

$keyword_pro=trim($keyword_pro);
if($keyword_pro){
	$wheres_pro=" AND (ProductName like '%$keyword_pro%' or txtDetail like '%$keyword_pro%') ";
}
//得到总记录数
$query2="select * from  products where 1 $wheres_pro order by dtCreate desc limit $offset,$pageSize";
}

$rs2=$DB->query($query2);



$pageList = GetPageList($_SERVER[PHP_SELF],"page","15",$totalPage,$page);
$PNum = $DB->num_rows($rs2);
$pagers="共 $totalRecord 条记录,共 $totalPage 页,当前第 $page 页";
if($pageList) $pagers.= " <br>$pageList[0] $pageList[1]";

while($row_p=$db->fetch_array($rs2)){
	   $row_p['dtCreate'] = date("Y-m-d",strtotime($row_p['dtCreate']));

	  $row_p['month'] = date("m",strtotime($row_p['dtCreate']));
	  $row_p['day'] = date("d",strtotime($row_p['dtCreate']));
	 $row_p['txtDetail'] = cutStr($row_p['txtDetail'],70)."...";
$txtDetailall=$row_p['txtDetail'];
	  if(strlen($row_p['ProductName'])>28)$row_p['ProductName'] = msubstr($row_p['ProductName'],0,16)."...";

$PInfo=PInfo($row_p['IDProduct']);


	  $produ[]=array("proID"=>$row_p['IDProduct'],"ProductName"=>$row_p['ProductName'],"Price"=> intval($PInfo['iPrice']),"txtDetail"=>$row_p['txtDetail'],"dtCreate"=>$row_p['dtCreate'],"Pic"=>$row_p['pic'],"txtDetailall"=>$txtDetailall); 	
	  
	
}

if($row_c['pro_fy']){
$pagers=$pagers;
}
else
{
$pagers="";
}

}




if($row_c['note_class']=='gongge'){


$pics = json_decode($row_c['pics'], true);


$resultpicinfo = iconv('gbk', 'utf-8', $row_c['picinfo']);

$picinfo = json_decode($resultpicinfo, true);

$alink = json_decode($row_c['alink'], true);

   if (isset($pics)) {
                                        foreach ($pics as $key=>$v) {
$picinfo[$key]=iconv('UTF-8', 'GBK', $picinfo[$key]);
$htmlgongge.="<a href='$alink[$key]'><span style='background:#e0e0e0 url($v) no-repeat  center;background-size:80px 80px;'></span>$picinfo[$key]</a>";


}
}

$smarty->assign('htmlgongge',$htmlgongge);




}







if($row_c['note_class']=='banner'){


$pics = json_decode($row_c['pics'], true);


$resultpicinfo = iconv('gbk', 'utf-8', $row_c['picinfo']);

$picinfo = json_decode($resultpicinfo, true);

$alink = json_decode($row_c['alink'], true);

   if (isset($pics)) {
                                        foreach ($pics as $key=>$v) {
$picinfo[$key]=iconv('UTF-8', 'GBK', $picinfo[$key]);
$html3.="<li><a href='$alink[$key]'><img style='background: url($v) no-repeat  center;' src='resources/jiaoben3555/images/alpha.png'  height='100%'  alt='$picinfo[$key]' /></a></li>";
if($key==0){
$html4.="<li  class='current'><a href='javascript:void(0)'><img src='$v' alt='$picinfo[$key]'  width='64' height='34' /></a></li>";
}
else
{

$html4.="<li  class='normal'><a href='javascript:void(0)'><img src='$v' alt='$ProductName'  width='64' height='34' /></a></li>";
}
if($key==0){
	$key=$key+1;
$html5.="<li  class='current'><a>$key</a></li>";}
else
{
	$key=$key+1;
$html5.="<li  class='normal'><a>$key</a></li>";}
}

}
$smarty->assign("UnitPrice",$PInfo['iPrice']);
$smarty->assign("IDProduct",$proID);
$smarty->assign('Price',$Price);
$smarty->assign('html4',$html4);
$smarty->assign('html5',$html5);
$smarty->assign('html3',$html3);




}




if($row_c['note_class']=='product_fl'){

$arProType = array();
$proType = new ProductType();
$tree = $proType->ShowProTypeTree('0',0,$arProType);
 for($i=0;$i<count($tree);$i++){
					if($tree[$i]['Type']=="class")	{	
                    $product_fl.= "<tr class='text-c' style='padding:10px;'><td><a href='index.php?page_id=".$row_c['pro_open_pageid']."&pro_fl=".$tree[$i]['IDProduct']."' >".$tree[$i]['Disp']."</a></td></tr>";}
}

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





if($row_c['note_class']=='news_fl'){
$arProType = array();
$proType = new ProductType1();
$tree = $proType->ShowProTypeTree('0',0,$arProType);

 for($i=0;$i<count($tree);$i++){
					if($tree[$i]['Type']=="class")	{	
                    $news_fl.= "<tr class='text-c' style='padding:10px;'><td><a href='index.php?page_id=".$row_c['news_open_pageid']."&news_fl=".$tree[$i]['IDProduct']."' >".$tree[$i]['Disp']."</a></td></tr>";
					
					}
}

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

   $class[]=array("border_ybj"=>$row_c['border_ybj'],"border_zbj"=>$row_c['border_zbj'],"border_xbj"=>$row_c['border_xbj'],"border_sbj"=>$row_c['border_sbj'],"font_color"=>$row_c['font_color'],"c_align"=>$row_c['c_align'],"note_class"=>$row_c['note_class'],"id"=>$row_c['id'],"note_weiz"=>$row_c['note_weiz'],"color"=>$row_c['color'],"produ"=>$produ,"left"=>$row_c['left'],"top"=>$row_c['top'],"zindex"=>$row_c['zindex'],"width"=>$row_c['width'],"height"=>$row_c['height'],"color"=>$row_c['color'],"Content"=>$row_c['Content'],"title"=>$row_c['title'],"pagers"=>$pagers,"news_fy"=>$news_fy,"pro_fy"=>$pro_fy,"title_right"=>$row_c['title_right'],"title_right_url"=>$row_c['title_right_url'],"$NewsID"=>$NewsID,"$proID"=>$proID,"news_open_pageid"=>$row_c['news_open_pageid'],"pro_open_pageid"=>$row_c['pro_open_pageid'],"note_css"=>$row_c['note_css']);  
    unset($produ);  	
  

};




//这是什么
if($_GET['proID']!=''){
$sql = "select * from products where IDProduct ='$proID' ";

$proinfo = $db->getdata($sql);
$pro_title=$proinfo[ProductName];
 $pro_description = cutStr($proinfo['txtDetail'],70)."...";
$ProductName=$proinfo[ProductName];
$txtDetail=$proinfo[txtDetail];
$PInfo=PInfo($proID);
$Price=$PInfo[iPrice];
$dtCreate=date("Y.m.d",strtotime($proinfo[dtCreate]));
$pics = json_decode($proinfo['pics'], true);
$resultpicinfo = iconv('gbk', 'utf-8', $proinfo['picinfo']);

$picinfo = json_decode($resultpicinfo, true);
$alink = json_decode($proinfo['alink'], true);
	$json_string = $PInfo['product_info'];//iconv("UTF-8", "GBK", $proInfo['product_info']);

							$json_string= iconv('GBK', 'UTF-8', $json_string);


				
							$product_info_arr = json_decode($json_string,true);
							//print_r($product_info_arr);
							if($product_info_arr)
							{
								foreach($product_info_arr as $key=>$info)
								{
$name_cs=iconv('UTF-8', 'GBK', $key);
$info_cs=iconv('UTF-8', 'GBK', $info);

$html_cs.="<li>$name_cs : $info_cs</li>";
$smarty->assign('html_cs',$html_cs);
	}
							}



   if (isset($pics)) {
                                        foreach ($pics as $key=>$v) {

$picinfo[$key]=iconv('UTF-8', 'GBK', $picinfo[$key]);
$html.="<li><a href='$alink[$key]'><img src='$v'  width='660' height='330' /></a></li>";
$html10="<a href='$pics[0]' class='MagicZoom' id='MagicZoom'><img src='$pics[0]'  width='100%' height='100%'  /></a>";

if($key==0){
$html1.="<li  class='current'><a href='javascript:void(0)'><img src='/admin/settings/$v' alt='$ProductName'  width='64' height='34' /></a></li>";
$html11.="<li onclick='showPic($key)' rel='MagicZoom' ><img src='$v' height='42' width='42' alt='$picinfo[$key]'  tsImgS='$v' /></a></li>";

}
else
{

$html1.="<li  class='normal'><a href='javascript:void(0)'><img src='/admin/settings/$v' alt='$ProductName'  width='64' height='34' /></a></li>";
$html11.="<li onclick='showPic($key)' rel='MagicZoom'  class='tsSelectImg'><img src='$v' height='42' width='42' alt='$picinfo[$key]'  tsImgS='$v' /></a></li>";

}
if($key==0){
$html2.="<li  class='current'> $picinfo[$key]</li>";}
else
{
$html2.="<li  class='normal'>$picinfo[$key]</li>";}
}

}
$smarty->assign("UnitPrice",$PInfo['iPrice']);
$smarty->assign("IDProduct",$proID);
$smarty->assign('Price',$Price);
$smarty->assign('html1',$html1);
$smarty->assign('html2',$html2);

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







//这是什么
if($_GET['NewsID']!=''){
$sql = "select * from news where NewsID = '$NewsID' ";
$result = $db->query($sql);
$NewsItems = array();
while($NewsI=$db->fetch_array($result)){
	  $NewsItems[] = $NewsI;	  
}
$newsinfo = $db->getdata($sql);
$news_title=$newsinfo[Title];
 $news_description = cutStr($newsinfo['Content'],70)."...";

}


if($_GET['edit']=='del')
{
$id = $_GET['ID'];
$key = $_GET['key'];
$sql = "select * from notes where ID='$id'";
$noteInfo  = $DB->getdata($sql);

$sql = "delete from notes where id='$id'";
$DB->query($sql);

}
if($_GET['action']=='login')
{
$UserName = $_POST['UserName'];
$Password = $_POST['Password'];
$GoUrl = $_GET['GoUrl'];
//die($GoUrl);
if($UserName != ''){
   $sql = "select * from users where UserName='$UserName'";
   $UInfo = $db->getdata($sql);
   if($UInfo && $UInfo['Password']==MD5($Password)){
	   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 {header("Location: /user/index.php");}
		  exit;
	   }else{
	      $mess = "<span>您的会员帐号被禁用,请与我们联系</span>";
 echo "<script>alert('您的会员帐号被禁用,请与我们联系');</script>";

	   }
   }else{
      $mess = "<span>用户名或密码错误</span>";
 echo "<script>alert('用户名或密码错误！请重新登陆。');</script>";
 
}
$action="login";

}

}

if($_GET['action']=='usereg')
{
/**
 * 兼容post函数
 *
 * date 2012-05-25 13:40:41
 */
$UserName = $_POST['UserName'];
$Password = $_POST['Password'];
$Password2 = $_POST['Password2'];
$Company_GB = $_POST['Company_GB'];
$Company_EN = $_POST['Company_EN'];
$Contact_GB = $_POST['Contact_GB'];
$Contact_EN = $_POST['Contact_EN'];
$Country = $_POST['Country'];
$Province_GB = $_POST['Province_GB'];
$City_GB = $_POST['City_GB'];
$Addr_GB = $_POST['Addr_GB'];
$Addr_EN = $_POST['Addr_EN'];
$PostCode = $_POST['PostCode'];
$Email = $_POST['Email'];
$Tel = $_POST['Tel'];
$Fax = $_POST['Fax'];
$QQ_openid = $_POST['openid'];

if($UserName == null || $Password == null || $Password2 == null || $Contact_GB == null||  $Addr_GB ==null ||  $Tel == null || $Email == null)
{
	echo "输入有空值，请检测。";
	exit();
}


$sql="select count(*) from users where UserName='$UserName'";
$rs=$db->query($sql);
$exist = $db->result($rs,0,0);
if($exist){
   $db->close();
   die("<script>alert('用户名 $UserName 已被占用，请另选一个');history.back();</script>");
}

$sql="insert into users set UserName='$UserName',Password=MD5('$Password'),Company_GB='$Company_GB',".
	"Company_EN='$Company_EN',Contact_GB='$Contact_GB',Contact_EN='$Contact_EN',Country='$Country',Province_GB='$Province_GB',".
	"City_GB='$City_GB',Addr_GB='$Addr_GB',Addr_EN='$Addr_EN',".
	"PostCode='$PostCode',Email='$Email',QQ_openid='$QQ_openid',Tel='$Tel',Fax='$Fax',iStatus ='1',dtCreate=now()";
$db->query($sql);
 echo "<script>alert('用户注册成功！请登陆。');</script>";

$mailvars['UserName'] = $UserName;
$mailvars['Password'] = $Password;

$smarty->assign('UserName',$UserName);
$smarty->assign('Password',$Password);
if($mailvars){
@SendTemplateMail("user_reg.htm",$mailvars,$Email,"欢迎注册成为".$_CFG['Company']."的会员");}


}




if($_GET['action']=='getpwd')
{
$UserName = $_POST['UserName'];
$UserMail = $_POST['UserMail'];

if($UserName!='' && $UserMail != ''){
    $sql="select * from users where UserName='$UserName'";
	$rs=$db->query($sql);
	$UserInfo=$db->fetch_array($rs);
	if(!$UserInfo || $UserInfo['Email'] != $UserMail) {
	   $message.= "<font color='red'>用户不存在或邮箱地址错误</font>";
  echo "<script>alert('用户不存在或邮箱地址错误');</script>";
	} else {
		$UserName = $UserInfo['UserName'];
	   	$Password = $UserInfo['Password'];
		$num = md5($UserName.$Password.rand());
		
		$sql = 'INSERT INTO `getpwd` (`id`, `user`, `key`, `istart`, `time`) VALUES (NULL, \''.$UserName.'\', \''.$num.'\', \'0\', UNIX_TIMESTAMP());';
		$db->query($sql);
		$ID=$db->insert_id();
		$mailvars['UserName'] = $UserInfo['UserName'];
		$mailvars['url'] = $parentpath.'/user/get_pwd.php?id='.$ID.'&key='.md5($num).'&sj='.time(); 
	  
	   $sent = SendTemplateMail("user_pass.htm",$mailvars,$UserInfo['Email'],"会员密码取回");
	   if($sent) {
		   $message = "<font color='#009900'>您的用户名和密码已经发往您注册时填写的邮箱 $UserInfo[Email] 中</font>";
	    echo "<script>alert('您的用户名和密码已经发往您注册时填写的邮箱');</script>";
	   }
	   else $message = "SMTP服务器不存在 或 SMTP认证失败";
	      echo "<script>alert('SMTP服务器不存在 或 SMTP认证失败');</script>";
	}
} elseif($submit) {
	$message = "用户名或邮箱不正确";
	   echo "<script>alert('用户名或邮箱不正确');</script>";
}

$smarty->assign("message",$message);

}






if($_GET['action']=='question')
{

$QuesType = $_POST['QuesType'];
$Subject = $_POST['Subject'];
$Content = $_POST['Content'];
$UserName = $_POST['UserName'];
$Password = $_POST['Password'];
$Contact = $_POST['Contact'];
$Email = $_POST['Email'];

if($_SESSION[User_S]){
	$UserName = $_SESSION[User_S];
	$sql="select * from users where UserName='$UserName'";
	$urow = $db->getRow($sql);
	$Contact = $urow[Contact_GB];
	$Email = $urow[Email];
}elseif($UserName){
	$sql="select count(*) from users where UserName='$UserName' AND Password='".md5($Password)."'";
	$exists=$db->result($db->query($sql),0,0);
	if(!$exists)$error=1;
	$errmsg .= "您输入的密码错误！<br><br>";
$errmsg1="您输入的密码错误!";
}
if($Contact==""){
	$error=1;
	$errmsg .= "请输入联系人姓名！<br><br>";
$errmsg2="请输入联系人姓名!";
}
if($Subject==""){
	$error=1;
	$errmsg .= "请输入标题！<br><br>";
$errmsg3="请输入标题!";
}
if($Content==""){
	$error=1;
	$errmsg .= "请输入问题内容！<br><br>";
$errmsg4="请输入问题内容!";
}
if($Email==""){
	$error=1;
	$errmsg .= "请输入您的邮件地址！<br><br>";
$errmsg5="请输入您的邮件地址!";
}
if(!$error){
	$sql="insert into question set UserName='$UserName',QuesType='$QuesType',Contact='$Contact',".
		 "Email='$Email',Subject='$Subject',Content='$Content',dtCreate=now()";
	$db->query($sql);
	$message = "您的问题已成功提交，我司的工作人员会尽快处理并Email通知您处理结果，谢谢！<br><br>";
	  echo "<script>alert('您的问题已成功提交，我司的工作人员会尽快处理并Email通知您处理结果，谢谢！'); window.parent.location.href='index.php?page_id=$page_id';</script>";
}else{
	$message = "";
	
}


$smarty->assign("message",$message);
$smarty->assign("errmsg5",$errmsg5);
$smarty->assign("errmsg4",$errmsg4);
$smarty->assign("errmsg3",$errmsg3);
$smarty->assign("errmsg2",$errmsg2);
$smarty->assign("errmsg1",$errmsg1);
}








$QuesType = GetQuestionTypes();
for($i=0;$i<count($QuesType);$i++){
   $option_type .= "<option value='".$QuesType[$i]."'>".$QuesType[$i]."</option>";
}

$smarty->assign("option_type",$option_type);
$smarty->assign("displayuser",$_SESSION['User_S']?false:true);


$openid = $_GET['openid'];
$smarty->assign('openid',$openid);
$smarty->assign('GoUrl',$GoUrl);
$smarty->assign('mess',$mess);








//得到总记录数
$sql         = "select count(*) from question where 1 $wheres";
$rs          = $db->query($sql);
$pageSize    = 30;
$totalRecord = $db->result($rs,0,0);
$totalPage   = ceil($totalRecord/$pageSize);
if(!$page)$page = 1;
$offset      = ($page-1) * $pageSize;
//查询
$sql         = "select * from question where 1 $wheres order by ID DESC limit $offset,$pageSize";
$result      = $db->query($sql);
$pageList    = GetPageList($_SERVER[PHP_SELF],"page","15",$totalPage,$page);
while($QuesI = $db->fetch_array($result)){
	  $bg          = $bg=="#FFFFFF"?"#EEEEEE":"#FFFFFF";
	  $QuesI['bg'] = $bg;
	  $QuesItems[] = $QuesI;
}
$pagers = "共<font color='red'> $totalRecord </font>条记录,".
          "共<font color='red'> $totalPage </font>页,".
		  "当前是第<font color='red'> $page </font>页";
if($pageList) $pagers .= "$pageList[0] <br> $pageList[1]";
/************* end of 查询财务信息 *******************/
//输出
$smarty->assign("QuesItems",$QuesItems);
$smarty->assign("pagers",$pagers);


	$sql = 'select * from question_class order by id desc';
$rs=$DB->query($sql);
while($row=mysql_fetch_array($rs)){
	

	$questionclass.= '<option value='.$row['QuesType'].'>'.$row['QuesType'].'</option>';
}


$edit=0;
$smarty->assign('head_width_mobile',$head_width_mobile);


$smarty->assign('head_height_mobile',$head_height_mobile);
$smarty->assign('head_css_mobile',$head_css_mobile);
$smarty->assign('main_width_mobile',$main_width_mobile);
$smarty->assign('main_height_mobile',$main_height_mobile);
$smarty->assign('main_css_mobile',$main_css_mobile);
$smarty->assign('foot_width_mobile',$foot_width_mobile);
$smarty->assign('foot_height_mobile',$foot_height_mobile);
$smarty->assign('foot_css_mobile',$foot_css_mobile);
$smarty->assign('questionclass',$questionclass);
$smarty->assign('head_width',$head_width);
$smarty->assign('head_height',$head_height);
$smarty->assign('head_css',$head_css);
$smarty->assign('main_width',$main_width);
$smarty->assign('main_height',$main_height);
$smarty->assign('main_css',$main_css);
$smarty->assign('foot_width',$foot_width);
$smarty->assign('foot_height',$foot_height);
$smarty->assign('foot_css',$foot_css);
$smarty->assign('menu_name',$menu_name);
$smarty->assign('title_new',$title_new);
$smarty->assign('keywords',$keywords);
$smarty->assign('description',$description);
$smarty->assign('maxid',$maxid);
$smarty->assign('NewsItems',$NewsItems);
$smarty->assign('treestringall',$treestringall);
$smarty->assign('treestring',$treestring);
$smarty->assign('class',$class);
$smarty->assign('admins',$adminS);
$smarty->assign('txtDetail',$txtDetail);
$smarty->assign('dtCreate',$dtCreate);
$smarty->assign('ProductName',$ProductName);
$smarty->assign('news_title',$news_title);
$smarty->assign('news_description',$news_description);
$smarty->assign('pro_title',$pro_title);
$smarty->assign('pro_description',$pro_description);

$smarty->assign('arrBoxNo',$arrBoxNo);
$smarty->assign('Price',$Price);
$smarty->assign('page_id',$page_id);
$smarty->assign('edit',$edit);
$smarty->assign('action',$action);
$smarty->assign('proID',$proID);
$smarty->assign('NewsID',$NewsID);
$smarty->assign('Content',$Content);
$smarty->assign('HProducts',$HProducts);

$smarty->assign('notesItems',$notesItems);









$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';</script>";

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

}
else{
 $mess_code = "<span>验证码错误</span>";
}
	      $mess = "<span>您的会员帐号被禁用,请与我们联系</span>";
	   }
   }else{
if($code==$_SESSION["helloweba_math"]){

}
else{
 $mess_code = "<span>验证码错误</span>";
}
if($UInfo && $UInfo['Password']==MD5($Password))
{
}
else
{
$mess = "<span>用户名或密码错误</span>";
}
      
   }
}
$smarty->assign('GoUrl',$GoUrl);
$smarty->assign('mess',$mess);
$smarty->assign('mess_code',$mess_code);
$smarty->display('user_login_mobile.html');
$db->close();
?>