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

$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>";
}
if($Contact==""){
	$error=1;
	$errmsg .= "请输入联系人姓名！<br><br>";
}
if($Subject==""){
	$error=1;
	$errmsg .= "请输入标题！<br><br>";
}
if($Content==""){
	$error=1;
	$errmsg .= "请输入问题内容！<br><br>";
}
if($Email==""){
	$error=1;
	$errmsg .= "请输入您的邮件地址！<br><br>";
}
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>";
	$message .= "<a href='question.php' >返回</a>";
}else{
	$message = "$errmsg";
	$message .= "<a href='question.php' >返回</a>";
}


$smarty->assign("message",$message);
$smarty->display('customer_question_submit.html');
$db->close();
?>