<?php

session_start();

require_once('./ls_admin/inc/ls_syscode.php');

require_once('./ls_admin/inc/constant.php');

$_SESSION['feedback']="";

$hidden=$_POST['business'];

$str=trim(strtolower($_POST['Comments']));

if(strtolower($_POST['code'])!=strtolower($_SESSION['code'])){

	if($hidden=="select.php")

	{

	echo "<script>

	alert('verify code is error!');

	history.go(-2);

	</script>";

	}

	else{

		echo "<script>

	alert('verify code is error!');

	history.go(-1);

	</script>";

	}

}

$b=$_POST['ls2']=="sendmail" || $_POST['submit']!="";

foreach($filterWords as $v){

	if($str!=$v)

	{

		if($b){

			$ls_msg=sendmail($_POST);

			$b=false;

		}

	}

	else{

		if($hidden=="select.php")

		{

			echo "<script>

			alert('Invalid message information.');

			history.go(-2);

			</script>";

		}

		else{

		echo "<script>

		alert('Invalid message information.');

		history.go(-1);

		</script>";}

	}

}

/*if(strtolower($_POST['code'])!=strtolower($_SESSION['code'])){

	echo "<script>

	alert('Verification code error.');

	history.go(-1);

	</script>";

}else{

	if($_POST['ls2']=="sendmail" || $_POST['submit']!=""){

		$ls_msg=sendmail($_POST);

	}

}*/



//------------------------------------------------------

//  发送邮件的函数，适用于webmotor,从数据库获得反馈邮箱

//　在一般php文件中，用于php文件头的下面，适用于一个form反馈

//　使用方法：sendmail($_POST)  返回相关信息

//------------------------------------------------------

function sendmail($postvars){



require_once('./ls_admin/inc/conn.php');

$opendb=new mydb();

require_once('./ls_admin/inc/char_set.php');

require('./ls_admin/inc/constant.php');

global $sendmailOKMsg,$sendmailFailMsg,$sendmailFailMsgcn,$sendmailOKMsgcn;



if($lang != "en"){

	$lan = $lang_cn;

}else{

	

	$lan = $lang_en;

}



$Back=$HTTP_REFERER;      //返回路径

$Subject="Information from ".$_SERVER['HTTP_HOST'];  // 标题

$gifo = new get_gust_info();

$config_sql="select * from ls_config ";

$config_query=$opendb->query($config_sql);

$config_row=mysqli_fetch_assoc($config_query);

$emailAddress=$config_row['feedbackEmail'];

		//禁用词

		$select_sql="select * from ls_banword  ";

		$select_query=$opendb->query($select_sql);

		$select_rows=mysqli_fetch_assoc($select_query);

		

		$banword_vars=explode(',',$select_rows['banword']);

		$nobanword=0;

		$message=trim(strtolower($_POST['Comments']));

		//禁用ip

		$selectip_sql="select * from ls_config  ";

		$selectip_query=$opendb->query($selectip_sql);

		$selectip_rows=mysqli_fetch_assoc($selectip_query);

		$banwordip_vars=explode(',',$selectip_rows['shieldIP']);

		$ip=$gifo->Getip();

	

		$nobanwordip=0;

		$ip=$gifo->Getip();

		$a=strrpos($ip,'.');

		$delip3= substr($ip,0,$a+1);

		$delip3star=$delip3.'*';

		

		$selectip_sql="select * from ls_config";

		$selectip_query=$opendb->query($selectip_sql);

		$selectip_rows=mysqli_fetch_assoc($selectip_query);

		//循环判断要警用的ip是否存在于所在网段

		$allip=trim($selectip_rows['shieldIP']);

		$allip3star=$allip.'*';

		

		if(strpos($allip,$delip3)!==false)

		{

			if(strpos($allip,$delip3star)===false)

			{

				if(strpos($allip,$ip)===false)

				{

					$nobanwordip=0;

				}

				else{

						$nobanwordip=1;

						echo "<script>

						alert('You can not leave a message.');

						history.go(-1);

						</script>";

				}

			}

			else{

						$nobanwordip=1;

						echo "<script>

						alert('You can not leave a message.');

						history.go(-1);

						</script>";

			}

		}  

		

				/*禁用词*/

		else if($select_rows!=""){

			for($i=(count($banword_vars)-1);$i>=0;$i--)

			{	

					$varname1=trim($banword_vars[$i]);

					if($varname1=='')continue;

					if($varname1!=''){

					if(strpos($message,$varname1)!==false)

					{

						$nobanword=1;

						echo "<script>

						alert('含有违禁词，无法添加留言。');

						history.go(-1);

						</script>";

						break;

					}  

				}

			}

		}

		else 

		{

				$nobanwordip=0;

		}

	if(count($postvars)!=0)  //pass vars fron URL

	{

		while(list($akey,$avalue)=each($postvars))

		{

			if(strpos($akey,"mail")!==false)  //获得客户邮件地址

			{$email_from=trim($avalue);}

    		switch ($akey){

    		case "inlineRadioOptions":

       		$Mr=$avalue;

       		break;



    		case "Submit":

        	break;

    		case "submit":

        	break;

    		case "ec_cid":

        	break;

    		case "guid":

        	break;

    		case "ls2":

        	break;

			case "code":

        	break;

			

   			default:

			if(strpos($akey,"select")===0||strpos($akey,"button")===0){break;}

			

	    	$Content.=urldecode($akey).":  ";

	    	$Content.=urldecode($avalue)."<br/>\r\n";

        	break;

    		}

		}

	}

	

	$headers = "MIME-Version:1.0\r\n"; 

	$headers .= "Content-type:text/html; charset=utf-8" . "\r\n"; 

	$headers .= "From:$email_from"; 

	$Content .="<br/>\r\n".date('Y-m-d');

	
	
	if(mail($emailAddress,$Subject,$Content, $headers))

	{

		$openck=new cktb();

		if($openck->checktable("ls_pro_feedback","CREATE TABLE IF NOT EXISTS `ls_pro_feedback` (

  `ID` int(4) NOT NULL AUTO_INCREMENT,

  `requirement` text,

  `name` varchar(100) DEFAULT NULL,

  `company` varchar(200) DEFAULT NULL,

  `tel` varchar(100) DEFAULT NULL,

  `email` varchar(150) DEFAULT NULL,

  `date` varchar(200) DEFAULT NULL,

  `proName` varchar(1000) DEFAULT NULL,

  `path` varchar(1000) DEFAULT NULL,

  `address` varchar(500) DEFAULT NULL,

  `fax` varchar(100) DEFAULT NULL,

  `http` varchar(100) DEFAULT NULL,

  `proID` int(4) DEFAULT NULL,

  `ip` varchar(50) DEFAULT NULL,

  `explorer` varchar(100) DEFAULT NULL,

  `home` varchar(300) DEFAULT NULL,

  `system` varchar(50) DEFAULT NULL,

  `enable` int(1) DEFAULT '1',

  `cateNameID` int(4) DEFAULT NULL,

  PRIMARY KEY (`ID`)

) ENGINE=InnoDB  DEFAULT CHARSET=utf8 AUTO_INCREMENT=5 ;"))	$ls_msg = $ls_msg .$openck->ls_msg;



		foreach($postvars  as $akey => $avalue){

			

			switch (urldecode($akey)){

			case "Interested_Products":

       		$subject=$avalue;
			
       		break;

    		case "Comments":

       		$comments=$avalue;

       		break;

    		case "Name":

        	$username=$avalue;
			
			/*case "inlineRadioOptions":*/
			
			
       		break;
			case "inlineRadioOptions":
			
			$Mr=$avalue;
       		break;
			
			
    		case "Companyname":

			$companyname=$avalue;

        	break;

			case "Address":

			$address=$avalue;

        	break;

    		case "Tel":

			$tel=$avalue;

        	break;

			case "Fax":

			$fax=$avalue;

        	break;

    		case "Mail":

			$mail=$avalue;

        	break;

			case "Web":

			$http=$avalue;

        	break;

    		case "path":

			$path=$avalue;

        	break;

    		case "pro_id":

			$pro_id=$avalue;

        	break;

			case "guid":

			$guid=$avalue;

        	break;

			case "business":

			$business=$avalue;

        	break;

    		}

		}

		//反馈写入数据库

		require_once('ls_admin/inc/conn.php');

		$opendb=new mydb();

		require_once('ls_admin/inc/char_set.php');

		require_once('ls_admin/inc/ls_syscode.php');

		

		date_default_timezone_set('Asia/Shanghai');//设置时区为中国时间

		

		

		$ip_home = '';

		$ipadds = $gifo->Getaddress();

		foreach($ipadds[0] as $value){

			 $ip_home .= " ".iconv("utf-8","utf-8",$value);    

		}

		if($ip_home == NULL)

			 $ip_home = "本地";

		if($nobanword==0 && $nobanwordip==0)	{

		if($pro_id != null){

			$insert_pro_feedback_sql=sprintf("insert into ls_pro_feedback(requirement,name,company,tel,email,proName,path,date,ip,explorer,home,system,proID,cateNameID) values (%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)",

						GetSQLValueString($comments,"text"),

						GetSQLValueString($Mr.".".$username,"text"),

						GetSQLValueString($companyname,"text"),

						GetSQLValueString($tel,"text"),

						GetSQLValueString($mail,"text"),

						GetSQLValueString($subject,"text"),

						GetSQLValueString($path,"text"),

						GetSQLValueString(date("Y-m-d H:i:s"),"text"),

						GetSQLValueString($gifo->Getip(),"text"),

						GetSQLValueString($gifo->GetBrowser()." - ".$gifo->GetLang(),"text"),

						GetSQLValueString($ip_home,"text"),

						GetSQLValueString($gifo->GetOs(),"text"),

						GetSQLValueString($pro_id,"int"),

						GetSQLValueString($business,"int")

						);

			$insert_query=$opendb->query($insert_pro_feedback_sql);



		}else{

			

			$insert_pro_feedback_sql=sprintf("insert into ls_pro_feedback(requirement,name,company,tel,http,fax,email,proName,path,address,date,ip,explorer,home,system,proID,cateNameID) values (%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)",

						GetSQLValueString($comments,"text"),

						GetSQLValueString($Mr.".".$username,"text"),

						GetSQLValueString($companyname,"text"),

						GetSQLValueString($tel,"text"),

						GetSQLValueString($http,"text"),

						GetSQLValueString($fax,"text"),

						GetSQLValueString($mail,"text"),

						GetSQLValueString($subject,"text"),

						GetSQLValueString($path,"text"),

						GetSQLValueString($address,"text"),

						GetSQLValueString(date("Y-m-d H:i:s"),"text"),

						GetSQLValueString($gifo->Getip(),"text"),

						GetSQLValueString($gifo->GetBrowser()." - ".$gifo->GetLang(),"text"),

						GetSQLValueString($ip_home,"text"),

						GetSQLValueString($gifo->GetOs(),"text"),

						GetSQLValueString($pro_id,"int"),

						GetSQLValueString($business,"int")

						);

			$insert_query=$opendb->query($insert_pro_feedback_sql);

		}

		//return($sendmailOKMsgcn==""?$lan['sendmailOKMsg']:$sendmailOKMsgcn);//成功 

		return($lang=="en"?$lan['sendmailOKMsg']:$sendmailOKMsgcn);//成功 

		}

	}

	else

	{

		//return($sendmailFailMsgcn==""?$lan['sendmailFailMsg']:$sendmailFailMsgcn);// 失败给提示

		return($lang=="en"?$lan['sendmailFailMsg']:$sendmailFailMsgcn);// 失败给提示

	}

}



?>