<?php include_once "EMS_Top.php";?>
<?
$pars = $_GET;
?>
<style>
span
{
	color:#F00;
	
	}
input,textarea
{
	
	border: 1px solid #ccc; font-size:12px; background-color:#fff;}	
</style>
<script language="javascript" type="text/javascript">
//去左空格; 
function ltrim(s){ 
    return s.replace( /^\s*/,""); 
} 
//去右空格; 
function rtrim(s){ 
    return s.replace( /\s*$/,""); 
} 
//去左右空格; 
function trim(s){ 
    return ltrim(rtrim(s)); 
}


function Submit_Check(){
	var notnull;
	notnull=true;
    if (document.form1.name.value == ""){
		window.alert("提示：请输入姓名！");
		document.form1.name.focus();
		notnull=false;
		}
	else if (document.form1.tel.value =="" ){
		window.alert("提示：请输入联系电话！");
		document.form1.tel.focus();
		notnull=false;
		}
	else if (document.form1.address.value =="" ){
		window.alert("提示：请输入联系地址！");
		document.form1.address.focus();
		notnull=false;
		}		
	else if (document.form1.title.value =="" ){
		window.alert("提示：请输入标题！");
		document.form1.title.focus();
		notnull=false;
		}
	else if (trim(document.getElementById("chkcode").value) == "") 	
	{
		   alert('提示:请输入验证码');
		   document.getElementById("chkcode").focus();
		   return false; 
		}
	else if (trim(document.getElementById("chkcode").value) != trim(document.form1.checkcode.value))	
	 {
		   alert('提示:请核实验证码');
		   return false; 
		 }		
	return notnull;
	}
</script>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr>
   <td>
     <table width="960" border="0" align="center" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF" style="padding-top:10px; padding-bottom:10px;">
  <tr>
    <td width="200" valign="top" style="padding-left:5px;"><?php include_once("EMS_Left.php");?></td>
    <td width="780" valign="top"><table width="98%" border="0" align="center" cellpadding="0" cellspacing="0"  style="border:1px solid #a1d0ec;">
      <tr>
        <td>
        
        
        <table width="100%" border="0" cellpadding="0" cellspacing="0" background="images/appimages/news_bg.jpg">
              <tr>
                <td width="4%" height="34" style="padding-left:20px; font-size:12px; font-weight:bold; color:#43a6df"><img src="images/appimages/home.jpg" width="19" height="17" /></td>
                <td width="11%" align="left" style="padding-left:5px; font-size:12px; font-weight:bold; color:#43a6df"><?php echo Sublm($pars,0);?></td>
                <td width="65%" align="right" style=" padding-right:20px; font-size:12px;color:#43a6df">您的位置：
                  <?php Sublm($pars["bid"],1); ?>
                  <?php Sublm($pars["sid"],1); ?>
                  <?php Sublm($pars["tid"],1); ?>
                  <?php Sublm($pars["fid"],1); ?></td>
                 <td width="20%" align="center" ><input type="button" name="button" id="button" value="我要留言" onclick="location.href='EMS_Gbook.php?bid=<?php echo $_GET["bid"]?>&sid=<?php echo $_GET["sid"]?>&tid=<?php echo $_GET["tid"]?>&fid=<?php echo $_GET["fid"];?>&act=showadd'" /></td>  
              </tr>
            </table>
        
        
        
        
        </td>
      </tr>
      <tr>
        <td><?php
		if ($_GET["act"] == "showadd")
		{
			gbook_add($pars);
		}
		elseif ($_GET["act"] == "add")
		{
			$pattern = "/\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/"; #判断邮件是否合法

			 if(trim($_POST["emial"]) != NULL)
			 {
			  if (preg_match($pattern,$_POST["email"]) == false)
			  { 
			    die(ShowMessage("history","邮件地址不合法!",""));
			  }
			 }
			mysql_query("insert into `web_gbook` (name,tel,fax,address,qq,email,title,content,bid,sid,tid,fid,addtime) values ('".Checkstr($_POST["name"])."','".Checkstr($_POST["tel"])."','".Checkstr($_POST["fax"])."','".Checkstr($_POST["address"])."','".Checkstr($_POST["qq"])."','".Checkstr($_POST["email"])."','".Checkstr($_POST["title"])."','".Checkstr($_POST["content"])."',".(int)$_GET["bid"].",".(int)$_GET["sid"].",".(int)$_GET["tid"].",".(int)$_GET["fid"].",'".date("Y-m-d")."')");
		  if (mysql_affected_rows() >=  1) {	
			ShowMessage("address","留言成功，请等待管理员审核！","EMS_Gbook.php?bid=".$_GET["bid"]."&sid=".$_GET["sid"]."&tid=".$_GET["tid"]."&fid=".$_GET["fid"]);
		  }
		  else
		  {
			  die(ShowMessage("history","检查字符是否存在单引号!",""));
			  }
		}
		else
		{
		
			$result = pagelists(0,12,"select count(*) from `web_gbook` where bid=".$pars["bid"]." and replay <>'' and sid=".$pars["sid"]." and tid=".$pars["tid"]." and fid=".$pars["fid"],"select * from `web_gbook` where bid=".$pars["bid"]." and replay <>'' and sid=".$pars["sid"]." and tid=".$pars["tid"]." and fid=".$pars["fid"]." order by id desc ");
 $page =  pagelists(1,12,"select count(*) from `web_gbook` where bid=".$pars["bid"]." and replay <>'' and sid=".$pars["sid"]." and tid=".$pars["tid"]." and fid=".$pars["fid"],"select * from `web_gbook` where bid=".$pars["bid"]." and replay <>'' and sid=".$pars["sid"]." and tid=".$pars["tid"]." and fid=".$pars["fid"]." order by id desc ");
 $totalNumber = pagelists(2,12,"select count(*) from `web_gbook` where bid=".$pars["bid"]." and replay <>'' and sid=".$pars["sid"]." and tid=".$pars["tid"]." and fid=".$pars["fid"],"select * from `web_gbook` where bid=".$pars["bid"]." and replay <>'' and sid=".$pars["sid"]." and tid=".$pars["tid"]." and fid=".$pars["fid"]." order by id desc ");
 $totalPage=  pagelists(3,12,"select count(*) from `web_gbook` where bid=".$pars["bid"]."  and replay <>'' and sid=".$pars["sid"]." and tid=".$pars["tid"]." and fid=".$pars["fid"],"select * from `web_gbook` where bid=".$pars["bid"]." and replay <>'' and sid=".$pars["sid"]."  and tid=".$pars["tid"]." and fid=".$pars["fid"]." order by id desc ");
			
			
			while ($rs = @mysql_fetch_array($result))
			 {
				 ?>
            <table width="93%" border="0" align="center" cellpadding="2" cellspacing="1" style="font-size:12px; margin-top:8px; border:1px solid #ccc;">
  <tr style="background:#f7f5f5">
    <td width="72%" height="22" bgcolor="#FFFFFF"><?php echo $rs["name"];?>：<?php echo $rs["title"];?></td>
    <td width="28%" align="center" bgcolor="#FFFFFF"></td>
  </tr>
  <tr>
    <td height="50" colspan="2" bgcolor="#FFFFFF"><?php echo $rs["content"];?> 留言时间：<?php echo $rs["addtime"];?></td>
  </tr>
 <?php
 if ($rs["replay"] != NULL)
  {
 ?>
  <tr><td colspan="2" style="color:#F00;" ><b>管理员回复：</b> <?php echo $rs["replay"];?></td></tr>
<?php
  }
?>
</table>
                 <?php
			}
			?>
            <table width="93%" border="0" align="center" cellpadding="0" cellspacing="0" style="font-size:12px;">
              <tr>
                <td width="32%" height="40" class="STYLE4">&nbsp;&nbsp; 共有<strong><?php echo $totalNumber ;?></strong> 条记录，当前第<strong><?php echo $page ;?></strong> 页，共 <strong><?php echo $totalPage ;?></strong> 页</td>
                <td width="53%" height="20" align="right" class="STYLE4"><a href="EMS_Gbook.php?bid=<?php echo $pars["bid"]?>&amp;sid=<?php echo $pars["sid"];?>&amp;tid=<?php echo $pars["tid"];?>&amp;fid=<?php echo $pars["fid"];?>&amp;page=1" style="color:#000;">第一页</a> &nbsp;|&nbsp; <a href="EMS_Gbook.php?bid=<?php echo $pars["bid"]?>&amp;sid=<?php echo $pars["sid"];?>&amp;tid=<?php echo $pars["tid"];?>&amp;fid=<?php echo $pars["fid"];?>&amp;page=<?php echo $page-1 ?>" style="color:#000;">上一页</a> &nbsp;|&nbsp; <a href="EMS_Gbook.php?bid=<?php echo $pars["bid"]?>&amp;sid=<?php echo $pars["sid"];?>&amp;tid=<?php echo $pars["tid"];?>&amp;fid=<?php echo $pars["fid"];?>&amp;page=<?php echo $page+1 ?>" style="color:#000;">下一页</a> &nbsp;|&nbsp; <a href="EMS_Gbook.php?bid=<?php echo $pars["bid"]?>&amp;sid=<?php echo $pars["sid"];?>&amp;tid=<?php echo $pars["tid"];?>&amp;fid=<?php echo $pars["fid"];?>&amp;page=<?php echo $totalPage ?>" style="color:#000;">最后一页</a></td>
                <td width="15%" align="center"><span class="STYLE1">转到第 </span>
                  <select name="jumpMenu" id="jumpMenu" onchange="MM_jumpMenu('self',this,0)" style="font-size:12px;border:#b5d6e6 solid 1px;">
                    <?php
                        for($p=1;$p<=$totalPage;$p++)
                        {
						?>
                    <option value="EMS_Gbook.php?bid=<?php echo $pars["bid"]?>&amp;sid=<?php echo $pars["sid"];?>&amp;tid=<?php echo $pars["tid"];?>&amp;fid=<?php echo $pars["fid"];?>&amp;page=<?php echo $p;?>" 
					  <?php 
					  if ($_GET["page"] == $p) :
					  echo "selected=selected";
					  endif; ?> 
                      ><?php echo $p; ?></option>
                    <?php 
                        }
                        ?>
                  </select>
                  <span class="STYLE1"> 页 </span></td>
              </tr>
    </table>
            <?php
		}
	?>
       
          <?php
	 function gbook_add($pars)
	 {
		 ?>
         <table width="100%" border="0" cellpadding="2" cellspacing="1" style="font-size:12px;">
        <form action="?act=add&bid=<?php echo $pars["bid"];?>&sid=<?php echo $pars["sid"];?>&tid=<?php echo $pars["tid"];?>&fid=<?php echo $pars["fid"];?>" method="post"  name="form1" onsubmit="return Submit_Check();">
    <tr>
      <td width="21%" height="24" align="center">您的姓名：</td>
      <td width="79%"><input name="name" type="text" id="name" size="15" maxlength="10">
        <span>* 姓名不能为空</span></td>
    </tr>
    <tr>
      <td height="24" align="center">联系电话：</td>
      <td><input name="tel" type="text" id="tel" maxlength="20"> <span>* 必填项，务必真实填写 此项不公开</span></td>
    </tr>
    <tr>
      <td height="24" align="center">传&nbsp;&nbsp;&nbsp; 真：</td>
      <td><input name="fax" type="text" id="fax"> <span>务必真实填写 此项不公开</span></td>
    </tr>
    <tr>
      <td height="24" align="center">联系地址：</td>
      <td><input name="address" type="text" id="address" size="30" maxlength="30"> 
        <span>* 必填项，务必真实填写 此项不公开</span></td>
    </tr>
    <tr>
      <td height="24" align="center">联 系 QQ：</td>
      <td><input name="qq" type="text" id="qq" size="15" maxlength="10"> <span>5位到至10位之间的数字</span></td>
    </tr>
    <tr>
      <td height="24" align="center">电子邮件：</td>
      <td><input name="email" type="text" id="email" size="30" maxlength="30"></td>
    </tr>
    <tr>
      <td height="24" align="center">留言标题：</td>
      <td><input name="title" type="text" id="title" size="40" maxlength="30">
      <span>* 留言标题不可为空</span></td>
    </tr>
    <tr>
      <td height="24" align="center">留言内容：</td>
      <td><textarea name="content" cols="45" title="内容请控制在300字以内" rows="7" id="content"></textarea></td>
    </tr>
    <tr>
      <td height="24" align="center">验 证 码：</td>
      <td><input name="chkcode" type="text" id="chkcode" size="4" maxlength="4" />
        <input type="hidden" name="checkcode" /><script language="javascript">
var num1=Math.round(Math.random()*10000000);
var num=num1.toString().substr(0,4);
document.write("<img name=codeimg4 style='cursor:pointer;' src='admin/code.php?num="+num+"' onClick=\"this.src='admin/code.php?num='+Math.round(Math.random()*10000000).toString().substr(0,4);\"   >");
document.form1.checkcode.value = num;
</script>       		 <span>*</span></td>
    </tr>
    <tr>
      <td height="37" align="center"></td>
      <td height="37" align="left"><input type="submit" style="height:23px;font-size:12px;"  name="Submit" value="提 交"  />
        &nbsp; <input type="reset" name="Submit2" onclick="history.go(-1)" style="height:23px;font-size:12px;" value="返 回" /></td>
    </tr>
    </form>
  </table>
    
         <?php
		}
	 
	?></td>
      </tr>
    </table></td>
  </tr>
</table>
   </td>
  </tr>
</table>

<?php include_once "EMS_Bottom.php";?>