<?php
include_once("../config/templateConfig.inc.php");
include_once("../config/databaseConfig.inc.php");
include_once("../adodb/mylib.inc.php");
$templateMain   = new SmartTemplate('tip.html');
$templateMenu   = new SmartTemplate('menu.html');
$templateTop    = new SmartTemplate('top.html');
$templateBottom = new SmartTemplate('copyRight.html');
/*
输出头部
*/
$templateTop->output();
/*
输出菜单
*/
$menu="访客留言";
$submenu="";
$templateMenu->assign('MENU',$menu);
$templateMenu->output();
/*
获取变量
*/
$Qname      = $_POST["Qname"];
$Qcompany   = $_POST["Qcompany"];
$Qemail     = $_POST["Qemail"];
$Qtelephone = $_POST["Qtelephone"];
$Qinfo      = $_POST["Qinfo"];
$hasbug     = false;
if (empty($Qname)==true || empty($Qinfo)==true){
	$hasbug = true;
    $thetip = "姓名和留言内容不能为空！";
}else{
	if (empty($Qemail)==false){
		if (checkEmail($Qemail)==false){
				$hasbug = true;
				$thetip = "电邮地址不正确！";
		}
	}
	$Qinfo      = mysubstr($Qinfo,0,250);
}
/*
写记录
输出主体部分
*/
if (!$hasbug){
$sql = "SELECT * FROM GuestBook WHERE ID = -1"; 
$rs = $db->Execute($sql); 
$record = array(); 
$record["Gname"]      = $Qname;
$record["Gcompany"]   = $Qcompany;
$record["Gemail"]     = $Qemail;
$record["Gtelephone"] = $Qtelephone;
$record["Ginfo"]      = strip_tags($Qinfo);
$insertSQL = $db->GetInsertSQL($rs, $record,true);
$db->Execute($insertSQL); 
$rs->close();
$db->close();
}
$thetip == "" ? $thetip="留言成功！" : $thetip = $thetip;
$templateMain->assign('THETIP',$thetip);
$templateMain->output();
/*
输出页脚
*/
$templateBottom->output();
?>