<?php

/*-----------------------------------------------------

*                本程序为zchain.net提供

*            零点留言簿多用户版 ZGB version 3.00

* ----------------------------------------------------*/



require "setup.php";

require "core/class_basic_record_file.php";

require "core/class_book_list.php";

require "core/class_message_list.php";

$notices=@file("$filepath/notice");

list($upstp,$notice)=split("\t",$notices[0]);

if (($timestamp-$upstp) > (3600*24*7)){

 $notices=@file("http://www.zchain.net/zgb/orgnote");

 $notice=$notices[0];

 if($TMP=fopen("$filepath/notice","w")) {

  fwrite($TMP,"$timestamp\t$notice");

  fclose($TMP);

 }

}



$id=str_replace(".","",$id);

if ($id == "") {errorview("id错误！");exit;}



$oBooks=new CBookList;

if(!$oBooks->open()){errorview("book list file open error!");exit;}

if(!$oBooks->find($id)){errorview("id错误！");exit;}



$oMsgs=new CMessageList;

if(!$oMsgs->open($id)){errorview("guest book open error!");exit;};



if ($f_pass=="") {$f_pass=$ck_pass;}

$ck_pass = ($f_pass == $oBooks->pass) ? $f_pass : "";

if($action=="logout"){$ck_pass="";}

setcookie("ck_pass",$ck_pass);



$rawcomment=stripslashes($f_comment);

$f_comment=htmlspecialchars($f_comment);

$f_comment=stripslashes($f_comment);

$f_comment=str_replace("\t","--",$f_comment);

$f_comment=str_replace("\n","<br>",$f_comment);

$f_comment=str_replace("\r","",$f_comment);



if($action == "addmsg"){AddMessage($id);JumpTo("$gburl?id=$id");}

elseif($action == "delmsg"){DelMessage($id,$mid);ShowBook($id,$search,$page);}

elseif($action == "find"){ShowBook($id,$search,$page);}

elseif($action == "reply"){ReplyForm($id,$mid);}

elseif($action == "replycommit"){Reply($id,$mid);JumpTo("$gburl?id=$id");}

else{ShowBook($id,"",$page);}



$oBooks->close();

$oMsgs->close();

exit;



##########

function AddMessage($id){

 global $filepath,$f_user,$rawcomment,$f_comment,$f_email,$f_url,$userip,$f_secret,$f_icon;

 global $prgurl,$gburl,$hostname,$hosturl,$thistime,$ftime;

 global $oBooks,$oMsgs; 



 if($f_user == ""){errorview("您的名字不能没有填写哦！");exit;}

 if($f_comment == ""){errorview("您的留言内容不能没有填写哦！");exit;}

 if(strlen($f_comment) > 2000 ){errorview("您的留言内容不能大于1000个汉字！");exit;}

 if($f_email != ""){

   if(!eregi(".*\@.*\..*",$f_email)){errorview("您的Email输入错误！");exit;}

 }



 if(CheckRepeat($f_user.$f_comment)){errorview("同一则留言可不能发2次以上哦！");exit;}



 $f_user=stripslashes($f_user);

 $f_user=htmlspecialchars($f_user);

 $f_url=stripslashes($f_url);

 $f_url=htmlspecialchars($f_url);



 $oMsgs->appendNew();

 $oMsgs->user=$f_user; $oMsgs->email=$f_email; $oMsgs->icon=$f_icon;

 $oMsgs->url=(trim($f_url)!="http://") ? $f_url : "";

 $oMsgs->comment=$f_comment; $oMsgs->ip=$userip; $oMsgs->time=$thistime;

 $oMsgs->secret=$f_secret; $oMsgs->reply=""; $oMsgs->replysecret="";

 $oMsgs->update();

  

 $emsg = "姓名: $f_user 於 $thistime\n";

 if ($f_email != "") $emsg .= "邮箱: $f_email\n";

 if ($oMsgs->url != "") $emsg .= "主页: $f_url\n";

 $emsg .= "留言内容: \n$rawcomment\n\n";

 $emsg .= "$oBooks->title($prgurl/$gburl?id=$id)\n\n\n";

 $emsg .= "程序制作：zChain.net(http://www.zchain.net)\n";

 $emsg .= "免费留言簿服务由 $hostname($hosturl) 提供\n\n";

 @mail($oBooks->email,"Subject: $oBooks->title 新留言通知",$emsg,"From: $f_email");

}



function ShowBook($id,$keyword,$page) {

 global $imgurl,$copyright,$perpage,$gburl,$ck_pass,$notice;

 global $oBooks, $oMsgs; 



 if($keyword) {$lines=$oMsgs->search($keyword);}

 $size=($keyword) ? count($lines) : $oMsgs->getRecordCount();



 PrintHeader();



 $pages = ceil($size/$perpage);

 if($page == ""){$page=1;}elseif($page>$pages){$page=$pages;}

 $firstitem=($page-1)*$perpage;

 $lastitem=$firstitem+$perpage;

 if($lastitem>$size){$lastitem=$size;}

 if(!$keyword){$oMsgs->moveTo($firstitem, false);}

 for($i=$firstitem; $i<$lastitem; $i++) {

  if($keyword){

   $oMsgs->setAbsolutePosition($lines[$i]);

   PrintMessage($size-$i, &$oMsgs);

  }else{

   PrintMessage($size-$i, &$oMsgs);

   $oMsgs->movePrev();

  }

 }



 $promptMsg=($keyword!="") ? "搜索结果" : "留言总数";

 $prompt=($keyword!="") ? "&action=find&search=$keyword" : "";

 $prevPg=($page>1)?$page-1:0;

 $prevMsg=($prevPg>0)?"href=$gburl?id=$id&page=$prevPg{$prompt}":"";

 $nextPg=($page<$pages)?$page+1:0;

 $nextMsg=($nextPg>0)?"href=$gburl?id=$id&page=$nextPg{$prompt}":"";

 print <<<EOT

 <br>

<table border="0" cellpadding="0" cellspacing="0" width="100%" class="bookNavigator">

<tr><td><form method=post action=$gburl?action=find&id=$id>

搜索关键字：<input name="search" size="20" class="plainInput">

<input class="plainButton" type="submit" value="搜索" name="submit"></form></td>

<td align="right">

 <form action=$gburl?id=$id{$prompt} method=post>

 <a $prevMsg>&lt;&lt;</a>

 第 <input size="2" value="$page" name="page" class="plainInput"> / $pages 页

 <a $nextMsg>&gt;&gt;</a>

 [{$promptMsg}：<em>$size</em>]</form></td></tr>

</table>

$oBooks->htmlb

</body></html>

EOT;

//加入显示底部

require "include/footer.php";

}



function DelMessage($id,$msgid) {

 global $ck_pass, $oMsgs;



 if(!$ck_pass){errorview("您的密码错误！");exit;}



 if(!$oMsgs->setAbsolutePosition($msgid)){errorview("指定留言错误！");exit;}

 if(!$oMsgs->delete()){errorview("留言删除错误！");exit;}

}



function PrintHeader()

{

 global $imgurl,$gburl,$useicon,$numicon,$id,$oBooks,$ck_pass;



 $mgrPrompt=($ck_pass)?"<a href='$gburl?action=logout&id=$id'>[注销]</a>":"<a onclick=showDlg(); href='#'>[管理]</a>";

 print <<<EOT

<HTML><HEAD>

<meta http-equiv="Content-Type" content="text/html; charset=gb2312">

<link rel="stylesheet" type="text/css" href="style/default.css">

<title>$oBooks->title</title>

<script language=JavaScript>

function get_cookie(Name) {

 var search = Name + "="

 var returnvalue = "";

 if (document.cookie.length > 0) {

  offset = document.cookie.indexOf(search)

  if (offset != -1) { 

   offset += search.length

   end = document.cookie.indexOf(";", offset);

   if (end == -1) end = document.cookie.length;

   returnvalue=unescape(document.cookie.substring(offset, end))

  }

 }

 return returnvalue;

}

function showDlg() {

 if(document.layers){document.layers['passForm'].visibility="show";}

 if(document.all){

  document.all.passForm.style.visibility="visible";

  document.all.passForm.style.left=window.event.clientX-10;

  document.all.passForm.style.top=window.event.clientY+10;

 }

}

function hideDlg() {

 if(document.layers){document.layers['passForm'].visibility="hide";}

 if(document.all){document.all.passForm.style.visibility="hidden";}

}

function showForm(disp) {

 document.all.simpForm.style.display=(disp==0)?"":"none";

 document.all.fullForm.style.display=(disp==0)?"none":"";

 document.cookie="ck_disp="+disp;

}

</script>

</HEAD>

<BODY class="book">

EOT;

//加入显示头

require "include/header.php";

print <<<EOT

$oBooks->htmlt

<DIV ID="passForm" align="center" class="manageForm">

<form method=post action='$gburl?id=$id'>

<table cellspacing=1 bgcolor=#000000 cellpadding=3>

<tr><td width=100% bgcolor=#F0F0F0 align=right style="font-size:9pt;">

输入管理密码：<input type=password class="plainInput" name=f_pass size=20><br><br>

<input type=submit value="确认" class="plainButton">

<input type="button" onclick="hideDlg();" value="关闭" class="plainButton">

</td></tr></table></form>

</DIV>

<?php

//上部表格设计，就是留言部分

?>

<class="bookFrame">

<center>

<TABLE ID="simpForm" cellPadding=0 cellSpacing=1 width=100% class="msgForm">

<TR><TD>

 <TABLE border=0 width="100%" class="msgFormCaption">

 <TR><TD>&gt;&gt;&gt; <a href="$oBooks->url">$oBooks->urlname</a>

 &gt;&gt; <a href="$gburl?id=$id">$oBooks->title</a></TD>

 <TD align=right>

  $mgrPrompt

  <a target="_blank" href="regedit.php">[修改]</a>

  <a target=_blank href="reg.php">[申请]</a>

  <a target=_blank href="http://www.zchain.net">[下载]</a>

  <a href="#" onclick="showForm(1);">&darr;[留言]</a>

 </TD></TR></TABLE>

</TD></TR>

</TABLE>



<FORM action="$gburl?id=$id" method=post>

<input type="hidden" name="action" value="addmsg">

<TABLE ID="fullForm" border=0 cellPadding=0 cellSpacing=1 width=100% class="msgForm">

<TR><TD>

 <TABLE border=0 width="100%" class="msgFormCaption">

 <TR><TD align=left vAlign=center>&gt;&gt;&gt; <a href="$oBooks->url">$oBooks->urlname</a>

 &gt;&gt; <a href="$gburl?id=$id">$oBooks->title</a></TD>

 <TD align=right class=fgfont vAlign=center>

 $mgrPrompt

 <a target="_blank" href="regedit.php">[修改]</a>

 <a target=_blank href="reg.php">[申请]</a>

 <a target=_blank href="http://www.zchain.net">[下载]</a>

 <a href="#" onclick="showForm(0);">&uarr;[留言]</a>

</TD></TR></TABLE></TD></TR>

<TR><TD vAlign=top width="50%">

 <TABLE width="100%" class="msgFormBody">

 <TR><TD vAlign=top>

  <TABLE class="msgFormBody">

  <TR><TD><IMG height=16 src="$imgurl/y.gif" width=16></TD>

  <TD>姓名</TD>

  <TD><INPUT class=plainInput maxLength=12 name=f_user onmouseover=this.focus()> *</TD></TR>

  <TR><TD><IMG border=0 height=16 src="$imgurl/mail.gif" width=16></TD>

  <TD>Email</TD>

  <TD><INPUT class=plainInput maxLength=30 name=f_email onmouseover=this.focus()></TD></TR>

  <TR><TD><IMG border=0 height=16 src="$imgurl/home.gif" width=16></TD>

  <TD>主页</TD>

  <TD><INPUT class=plainInput maxLength=40 name=f_url value="http://" size=28 onmouseover=this.focus()></TD></TR>

  <TR><TD><IMG border=0 src="$imgurl/ren.gif"></TD>

  <TD>悄悄话</TD>

  <TD><INPUT name=f_secret type=radio value=1> 是 <INPUT CHECKED name=f_secret type=radio value=0> 否 </TD></TR>

EOT;



 if($useicon==1){

  print "<TR><TD align=left><IMG height=16 src='$imgurl/oicq.gif' width=16></TD>";

  print "<TD>选头像</TD><TD><SELECT class=plainInput name=f_icon size=1>";

  for($i=1;$i<=$numicon;$i++){

   print "<OPTION value=$i select>头像{$i}</OPTION>";

  }

  print "</SELECT> <A target=_blank href='iconlist.php'>头像列表</A></TD></TR>";

 }



 print <<<EOT

  </TABLE></TD>

  <TD align=left valign=top>

   <IMG height=15 width=15 src="$imgurl/pen.gif"> 留言 *<BR>

   <TEXTAREA class=plainInput cols=70 name=f_comment rows=8 title=最大留言字数1000 type="text"></TEXTAREA>

  </TD></TR></TABLE>

 </TD></TR>

 <TR><TD>

  <TABLE align=center border=0 cellPadding=0 cellSpacing=0 width="100%" class="msgFormCaption">

  <TR><TD align=center>

   &nbsp;&nbsp;&nbsp;&nbsp;<INPUT class=plainButton name=Submit type=submit value="发送留言">

   &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;<INPUT class=plainButton name=Submit2 type=reset value="清除留言">

  </TD></TR></TABLE>

</TD></TR></TABLE></FORM>

<script language=JavaScript>

var disp=get_cookie("disp"); if(disp=="")disp=1;

showForm(disp);</script>

EOT;

}



function PrintMessage($msgNo, $oMsg) {

 global $imgurl,$id,$gburl,$ck_pass,$useicon;

//留言表格设计,我自己修改的

 print <<<EOT

 <center>

<table border="0" align="center" cellpadding="0" cellspacing="1" width="100%" class="msg">

<tr><td>

 <table border="0" align="center" cellpadding="0" cellspacing="0" width="100%" class="msgCaption">

 <tr><td bgcolor="$ly_left" width="100" align="center" valign="middle">第 $msgNo 条留言</td>

 <td bgcolor="$ly_center" valign="middle">发表于 $oMsg->time</td>

 <td bgcolor="$ly_right" align="right" valign="middle">

EOT;



 print "<a href=$gburl?action=find&id=$id&search=$oMsg->user><img src=$imgurl/find.gif style=border: 0px alt=搜索{$oMsg->user}所写过的留言></a> \n";

 if($oMsg->email != ""){

  print "<a href=mailto:$oMsg->email><img src=$imgurl/mail.gif style=border: 0px alt=E-mail></a> \n";

 }

 if($oMsg->url != ""){

  print "<a href=$oMsg->url target=_blank><img src=$imgurl/home.gif style=border: 0px alt=主页></a> \n";

 }

 print "<img src=$imgurl/ip.gif alt={$oMsg->user}的IP地址：$oMsg->ip></a> \n";

 print "<a href=$gburl?action=reply&id=$id&mid=$oMsg->msgid><img src=$imgurl/hf.gif style=border: 0px alt=回复留言></a> \n";

 if($ck_pass){

  print "<a href=$gburl?action=delmsg&id=$id&mid=$oMsg->msgid&search=$keyword&page=$page><img src=$imgurl/del.gif style=border: 0px alt=删除此留言></a>\n";

 }



 $tmpMsg1=(($oMsg->secret != "1") || ($ck_pass)) ? $oMsg->comment : "悄悄话...";

 $tmpMsg2=(($oMsg->replysecret != "1") || ($ck_pass)) ? $oMsg->reply : "<br><br>悄悄话回复...";



 $userMsg=($useicon==1)?

  "$oMsg->user<br><img border=0 src='$imgurl/icon{$oMsg->icon}.gif'>"

  :"<br>$oMsg->user<br><br>";



 print <<<EOT

 </td></tr>

 </table>

</td></tr>

<tr><td>

 <table width=100% class=msgBody>

  <tr><td width=100 align=center valign=middle class=table002><table valign="bottom" width="100%" height="50" align="center" border="0" cellspacing="0" cellpadding="0" class=theleft>

    <tr>

    <td valign="middle">$userMsg</td>

  </tr>

</table>

</td>

  <td align=left valign=top class=table002><table width="100%" height="100%" border="0" cellspacing="0" cellpadding="0" class=jnfont6>

<tr><td height=18 align=right style="width:660;color:cecece;filter:glow(color=red, strength=1)"><font color=#000000>管理员:land Mstong</font></td></tr>

  <tr>

    <td class=jnfont2><br>&nbsp;&nbsp;&nbsp;&nbsp;$tmpMsg1$tmpMsg2</td>

  </tr>

</table>

</td></tr>

 </table></td></tr>

</table>

EOT;

}



function PrintTail(){

print <<<EOT

<table border="0" cellpadding="0" cellspacing="0" width="100%" class="bookNavigator">

<tr><td>搜索关键字：<input name="search" size="20" class="plainInput">

<input class="plainButton" type="submit" value="搜索" name="submit"></td>

<td align="right">

  <a href="#">&lt;&lt;</a> 第 <input size="2" value="1" name="page" class="plainInput"> / 1 页<a href="#"> &gt;&gt;</a>

  (留言总数<font color="red">&nbsp;</font>10)</td></tr>

</table>

<center>

<hr width="450" noShade SIZE="1">

服务提供：<a href="#">zChain.net</a> 程序提供：<a href="#">zChain.net</a><br>

Powered by zChain GuestBook v3.00

</center>

EOT;

}



function ReplyForm($id,$mid) {

 global $copyright,$gburl,$ck_pass;



 print <<<EOT

<HTML><HEAD><TITLE>【版主回复】</TITLE>

<META content=text/html; charset=gb2312 http-equiv=Content-Type>

<STYLE>

BODY {COLOR: black; FONT-FAMILY: 宋体, Arial; FONT-SIZE: 9pt; LINE-HEIGHT: 12pt; MARGIN-TOP: 0px}

TABLE {COLOR: black; FONT-FAMILY: 宋体, Arial; FONT-SIZE: 9pt; LINE-HEIGHT: 12pt}

INPUT {FONT-FAMILY: 宋体, Arial; FONT-SIZE: 9pt; LINE-HEIGHT: 12pt}

TEXTAREA {FONT-FAMILY: 宋体, Arial; FONT-SIZE: 9pt; LINE-HEIGHT: 12pt}

SELECT {FONT-FAMILY: 宋体, Arial; FONT-SIZE: 9pt; LINE-HEIGHT: 12pt}

A:link {COLOR: black; FONT-FAMILY: 宋体, Arial; FONT-SIZE: 9pt; LINE-HEIGHT: 12pt; TEXT-DECORATION: none}

A:visited {COLOR: blue; FONT-FAMILY: 宋体, Arial; FONT-SIZE: 9pt; LINE-HEIGHT: 12pt; TEXT-DECORATION: none}

A:active {COLOR: blue; FONT-FAMILY: 宋体, Arial; FONT-SIZE: 9pt; LINE-HEIGHT: 12pt; TEXT-DECORATION: underline}

A:hover {COLOR: blue; FONT-FAMILY: 宋体, Arial; FONT-SIZE: 9pt; LINE-HEIGHT: 12pt; TEXT-DECORATION: underline}

</STYLE>

</HEAD>

<BODY link=#ffff00 text=#00ffff vLink=#ffff00>

<P align=center><FONT color=black><BR>版主回复</FONT></P>

<form action=$gburl method=post>

<input type=hidden name=action value=replycommit>

<input type=hidden name=id value=$id>

<input type=hidden name=mid value=$mid>

<TABLE align=center border=1 borderColor=#ffffff borderColorDark=#ffffff

borderColorLight=#000000 cellSpacing=0 width=617>

<TR align=middle>

<TD align=left bgColor=#B0D0F0 borderColorDark=#ffffff

borderColorLight=#000000 height=8 width=98><font color=#000000>版主密码：</FONT></TD>

<TD align=left bgColor=#B0D0F0 borderColorDark=#ffffff

borderColorLight=#000000 height=8 width=203><FONT color=#0080ff><INPUT

maxLength=8 name=f_pass size=20 tabIndex=3 type=password value=$ck_pass> 长度1-8</FONT></TD>

</TR>

<TR align=middle>

<TD align=left vAlign=top bgColor=#B0D0F0 borderColorDark=#ffffff borderColorLight=#000000 width=97>

<FONT color=#000000><br>回复内容：<br>

<input type="checkbox" name="f_secret" value="1">保密</FONT></TD>

<TD align=left bgColor=#B0D0F0 borderColorDark=#ffffff

borderColorLight=#000000 width=508><TEXTAREA cols=70 name=f_comment rows=5 200 tabIndex=9></TEXTAREA>

</TD></TR>

<TR align=middle>

<TD align=left bgColor=#B0D0F0 borderColorDark=#ffffff

borderColorLight=#000000 colSpan=2 height=42 width=605>

<DIV align=center>

<P><input type=submit value=提交 name=B1><input type=reset value=重写 name=B2></P>

</DIV></TD></TR></TABLE></FORM>

<P align=center>$copyright</P>

</BODY></HTML>

EOT;

}



function Reply($id,$mid) {

 global $copyright,$prgurl,$gburl,$hosturl,$hostname;

 global $thistime,$ck_pass,$f_secret,$f_comment,$rawcomment;

 global $oBooks,$oMsgs;



 if(!$ck_pass){errorview("对不起,您不是版主不能回复留言！");}

 if(!$oMsgs->setAbsolutePosition($mid)){errorview("error message id");}



 $oMsgs->reply.="<br><br><font color=#ab00ac>版主回复</font> - <i><FONT color=#777777>$thistime</font></i><br>$f_comment";

 $oMsgs->replysecret=$f_secret;

 $oMsgs->update();

 

 if ($oMsgs->email != "") {

  $emsg = "版主 於 $thistime 回复了您的留言\n";

  $emsg .= "回复内容: \n$rawcomment\n\n";

  $emsg .= "$oBooks->title($prgurl/$gburl?id=$id)\n\n\n";

  $emsg .= "程序制作：zChain.net(http://www.zchain.net)\n";

  $emsg .= "免费留言簿服务由 $hostname($hosturl) 提供\n\n";

  @mail("$oMsgs->email","Subject: {$oBooks->title} 回复留言通知",$emsg,"From $oBooks->title");

 }

}



function CheckRepeat($a_identity){

 global $filepath;

 $lasttxts=@file("$filepath/chklast");

 if($TMP=fopen("$filepath/chklast","w")){

  fwrite($TMP,$a_identity); fclose($TMP);

 }

 return ($lasttxts[0] == $a_identity);

}



function JumpTo($url)

{

 global $oBooks;



 print <<<EOT

<html><head><title>留 言 完 成 !</title>

<META content=text/html; charset=gb2312 http-equiv=Content-Type>

<meta HTTP-EQUIV="REFRESH" CONTENT=2;URL=$url>

<style><!--

{font-size: 12px;}

p {font-size:12px;}

a { text-decoration: none; color: rgb(40,40,180) }

a:hover {color:'#FF9900';text-decoration:none}

table {font-size:12px;}

td {font-size:12px;}

--></style>

</head>

<body><CENTER><br><br><br>

<table width=335 cellspacing=1 cellpadding=5>

<tr><td width=100% bgcolor='#ffffff' align=center>

<span style="font-size: 10.5pt;line-height: 13pt">- 留 言 完 成 -</span><BR></td></tr>

<tr><td align=center><a href=$url>[ 回 留 言 簿 ]</a>&nbsp;&nbsp;&nbsp;<a href=$oBooks->url>[ 回 到 主 页 ]</a></td></tr>

</table>2秒钟后自动返回......<br><br><br>

</body></html>

EOT;

}



?>