<?
require"ygl.php";
if(!isset($ses_user_id)||!isset($ses_user_psd)){errorview("对不起，你没有登陆！！");exit;}
$user_login_id=$ses_user_id;
$user_login_psd=$ses_user_psd;
if(!ynjoinclass($user_login_id)){errorview("对不起，你没有加入该班！！");exit;}
readclass();
read_user_zl($user_login_id);
$ynhead1="1";
$ynhead2="1";
$ynhead3="1";
$title="班级留言簿";
include"header.php";
if($gbpage==""||$gbpage=="gblist")gblist();
if($postgb!="")postgb();
if($delgb!="")delgb();
#######
function gblist()
{
global $page,$perpage;
$gbfile=file("data/gbook.gb");
$size=count($gbfile);
$ii=1; $j=$size;
while ($j>0) {
 $j=$j-$perpage;
}
print<<<EOT
<table width=600 border=1 cellspacing=0 cellpadding=0 align=center bordercolorlight=#B5E1F7 bordercolordark=#FFFFFF>
 <tr>
  <td width=132 bgcolor=#2f5e8c><b><font color=#FFFFFF>作者信息：</font></b></td>
  <td width=454 bgcolor=#2f5e8c>
   <table width="100%" border=0 cellspacing=0 cellpadding=3>
    <tr>
     <td width="56%"><b><font color=#FFFFFF>留言内容：</font></b></td>
     <td width="44%"><b><font color=#FFFF00>共有留言 $size 条</font></b></td>
    </tr>
   </table>
  </td>
 </tr>
EOT;
if ($page == "") {$page=$ii;}
$pages=$page-1;
$pages=$page*$perpage-$perpage;
for($i=$pages; $i<$pages+$perpage; $i++) {
 $linea=$gbfile[$i];
 $linea=ereg_replace("\n", "", $linea);
 if ($linea != "") {
 $lines1a=file("data/gbook.gb");
 while (list($tmpkey, $line1a) = each($lines1a))
  {
  $line1=ereg_replace("\n", "", $line1);
  list($cid,$userid,$usname,$posttime,$face,$gbcontent)=split("\t",$linea);
   }
      print"
<tr><td bgcolor=#f7f7f7 valign=top align=center width=132 rowspan=3><img src=$face><br>
   <br>$usname</td>
  <td width=454 valign=top><img src=face/post.gif>发表于：$posttime
  </td></tr><tr><td width=454 valign=top height=74>$gbcontent</td>
 </tr><tr>
  <td width=454 valign=top align=right><a href=gbook.php?delgb=$cid><img src=face/del.gif alt=删除 border=0></a></td>
 </tr><tr><td colspan=2 height=3 bgcolor=#336699></td></tr>
 ";
 }
 }
 print"</table><div align=center>";
 $j=$size;
while ($j>0) {
 if ($page != $ii) {print "<a href=gbook.php?page=$ii>";};
 print "[$ii]";
 if ($page != $ii) {print "</a>";};
 $j=$j-$perpage;
 $ii++;
}
 print"</div>";
print<<<EOT
<a name="add"></a><hr size="1" width="80%" color=#2f5e8c noshade>
<form name="form1" method="post" action="gbook.php">
 <table width="600" border="1" cellspacing="0" cellpadding="3" align="center" bordercolorlight="#B5E1F7" bordercolordark="#FFFFFF">
  <tr bgcolor="#2f5e8c">
   <td colspan="2">
    <div align="center"><b><font color="#FFFFFF">发表留言</font></b></div>
   </td>
  </tr>
  <tr>
   <td width="400">
    <table width="100%" border="0" cellspacing="0" cellpadding="2">
     <tr>
      <td width="200">留言内容：</td>
      <td width="200">请选择头像：
       <select name=face size=1 onChange="document.images['face'].src=options[selectedIndex].value;">
        <option value="face/01.gif" selected>Image1</option>
        <option value="face/02.gif">Image2</option>
        <option value="face/03.gif">Image3</option>
        <option value="face/04.gif">Image4</option>
        <option value="face/05.gif">Image5</option>
        <option value="face/06.gif">Image6</option>
        <option value="face/07.gif">Image7</option>
        <option value="face/08.gif">Image8</option>
        <option value="face/09.gif">Image9</option>
        <option value="face/10.gif">Image10</option>
        <option value="face/11.gif">Image11</option>
        <option value="face/12.gif">Image12</option>
        <option value="face/13.gif">Image13</option>
        <option value="face/14.gif">Image14</option>
        <option value="face/15.gif">Image15</option>
        <option value="face/16.gif">Image16</option>
        <option value="face/17.gif">Image17</option>
        <option value="face/18.gif">Image18</option>
        <option value="face/19.gif">Image19</option>
        <option value="face/20.gif">Image20</option>
        <option value="face/21.gif">Image21</option>
        <option value="face/22.gif">Image22</option>
        <option value="face/23.gif">Image23</option>
        <option value="face/24.gif">Image24</option>
       </select>
      </td>
     </tr>
     <tr>
      <td colspan="2" align="center">
        <textarea name="gbcontent" cols="60" rows="5" class=text></textarea>
      </td>
     </tr>
    </table>
   </td>
   <td width="100" align="center"><img id=face src="face/01.gif"></td>
  </tr>
  <tr align="center">
   <td colspan="2">
    <input type="submit" name="postgb" value="发 表" class=text>
    <input type="reset" name="Submit" value="重 置" class=text>
   </td>
  </tr>
 </table>
EOT;
}
###########
function nowtime(){
  $date=date("Y-m-d.G:i:s");
  return $date;
}
############
function postgb()
{
global $user_login_id,$face,$gbcontent,$stemp,$username;
if(empty($gbcontent)){errorview("请填写留言！！");exit;}
$gbcontent=str($gbcontent);
$time=nowtime();
$file="data/gbook.gb";
$data=fopen("data/gbook.gb","r");
$old=fread($data,filesize($file));
fclose($data);
$writegbcontent=$stemp."\t".$user_login_id."\t".$username."\t".$time."\t".$face."\t".$gbcontent."\n".$old;
$data=fopen($file,"w");
fwrite($data,$writegbcontent);
fclose($data);
print"<META HTTP-EQUIV=REFRESH CONTENT=0;URL=gbook.php>";
}
#############
function delgb()
{
global $delgb,$user_login_id,$admin1,$admin2,$admin3,$cjadmin;
if(empty($delgb)){errorview("没有该留言！！");exit;}
$gbfile=read_file("data/gbook.gb");
$gbfile=explode("\n",$gbfile);
$listcount=count($gbfile);
    if($user_login_id==$cjadmin||$user_login_id==$admin1||$user_login_id==$admin2||$user_login_id==$admin3)
       $del_ynadmin=1;else $del_ynadmin=0;
for ($j=0;$j<$listcount;$j++)
    {
    $gbdetail=explode("\t",$gbfile[$j]);
    if($gbdetail[0]==$delgb&&$gbdetail[1]==$user_login_id){$delyn=1;break;}
    }
if($del_ynadmin==1||$delyn==1)
{
$hastitles = file("data/gbook.gb");
$ccc=count($hastitles);
$fp=fopen("data/gbook.gb","w");
for($i=0;$i<$ccc;$i++){
 list($cid,$userid,$usname,$posttime,$face,$gbcontent)=explode("\t",$hastitles[$i]);
 if($cid!=$delgb){fputs($fp,$hastitles[$i]);}
 }
 fclose($fp);
}else {errorview("删除留言出错！！");exit;}
print"<META HTTP-EQUIV=REFRESH CONTENT=0;URL=gbook.php>";
}
include"footer.php";
?>