<?
require"ygl.php";
if(!isset($myclass)){errorview("对不起，没有该班级！！");exit;}
if(!isset($ses_user_id)||!isset($ses_user_psd)){errorview("对不起，你没有登陆！！");exit;}
$user_login_id=$ses_user_id;
$user_login_psd=$ses_user_psd;
if(!haveclass($myclass)){errorview("对不起，没有该班级！！");exit;}
if(!ynjoinclass($myclass,$user_login_id)){errorview("对不起，你没有加入该班！！");exit;}
readclass($myclass);
$ynhead2="1";
$ynhead3="1";
if($photopage==""||$photopage=="photolist")photolist();
if($photopage=="photoshow")photoshow();
if($photopage=="addphoto")addphoto();
##########
function photolist()
{
global $ynhead2,$ynhead3,$myclass,$user_login_id,$schooln,$classn,$page,$perpage;
$title="班级相簿";
include"header.php";
if(file_exists("class/$myclass/photo/list"))
$photo_file=file("class/$myclass/photo/list");
$size=count($photo_file);
$ii=1; $j=$size;
while ($j>0) {
 $j=$j-$perpage;
}
print<<<eot
<table width="750" border="1" cellspacing="0" cellpadding="3" align="center" bordercolorlight="#B5E1F7" bordercolordark="#FFFFFF">
 <tr bgcolor="#B5E1F7" align="center">
  <td width="445">照片标题</td>
  <td width="116">照片主人</td>
  <td width="99">上传时间</td>
  <td width="56">删除</td>
 </tr>
eot;
if ($page == "") {$page=$ii;}
$pages=$page-1;
$pages=$page*$perpage-$perpage;
for($i=$pages; $i<$pages+$perpage; $i++) {
 $linea=$photo_file[$i];
 $linea=ereg_replace("\n", "", $linea);
 if ($linea != "") {
 $lines1a=file("class/$myclass/photo/list");
 while (list($tmpkey, $line1a) = each($lines1a))
  {
  $line1=ereg_replace("\n", "", $line1);
  list($photoid,$photofilename,$phototle,$photodate,$photoowner)=split("\t",$linea);
   }
 print"<tr>
  <td width=445><a href=classphoto.php?myclass=$myclass&photopage=photoshow&photo_id=$photoid target=_blank>$phototle</a></td>
  <td width=116 align=center>$photoowner</td>
  <td width=99 align=center>$photodate</td>
  <td width=56 align=center><a href=upphoto.php?myclass=$myclass&delphotoid=$photoid>删除</a></td>
 </tr>";
  }
  }
 print"<tr><td colspan=4>
   <table width=100% border=0 cellspacing=0 cellpadding=0>
    <tr>
     <td width=100 align=center><a href=classphoto.php?myclass=$myclass&photopage=addphoto>上传照片</a></td> <td align=right>共有<font color=red>$size</font>张照片　　　";
 $j=$size;
while ($j>0) {
 if ($page != $ii) {print "<a href=classphoto.php?myclass=$myclass&page=$ii>";};
 print "[$ii]";
 if ($page != $ii) {print "</a>";};
 $j=$j-$perpage;
 $ii++;
}
print<<<eot
</td>
    </tr>
   </table>
  </td>
 </tr>
</table>
eot;
}
##########
function photoshow()
{
global $ynhead2,$ynhead3,$myclass,$user_login_id,$schooln,$classn,$photo_id;
$photofile=read_file("class/$myclass/photo/list");
$photofile=explode("\n",$photofile);
$listcount=count($photofile);
for ($j=0;$j<$listcount;$j++)
    {
    $photodetail=explode("\t",$photofile[$j]);
    if($photodetail[0]==$photo_id){$photoseek=$j;break;}
    }
$title=$photodetail[2];
include"header.php";
print<<<eot
<table width="600" border="1" cellspacing="0" cellpadding="3" align="center" bordercolorlight="#B5E1F7" bordercolordark="#FFFFFF">
 <tr>
  <td>图片标题：$photodetail[2]  　　　上传时间：$photodetail[3]  　　　照片主人：$photodetail[4] </td>
 </tr>
 <tr>
  <td align=center><img src="class/$myclass/photo/$photodetail[1]"></td>
 </tr>
</table>
eot;
}
##########
function addphoto()
{
global $ynhead2,$ynhead3,$myclass,$user_login_id,$schooln,$classn;
$title="上传照片";
include"header.php";
print<<<EOT
<form name="form1" method="post" action="upphoto.php?myclass=$myclass" enctype="multipart/form-data">
 <table width="400" border="1" cellspacing="0" cellpadding="3" bordercolorlight="#B5E1F7" bordercolordark="#FFFFFF" align="center">
  <tr>
   <td align="center" bgcolor="#B5E1F7"><b><font color="#000066">上传照片</font></b></td>
  </tr>
  <tr>
   <td>
    <input type="file" name="photofile" size="30" class=text>
   </td>
  </tr>
  <tr>
   <td><font color="#FF0000">注意：图片为jpg,gif,小于300k！照片标题少于15个字！</font></td>
  </tr>
  <tr>
   <td>图片标题：
    <input type="text" name="phototitle" size="30" class=text>
   </td>
  </tr>
  <tr>
   <td align="center">
    <input type="submit" name="yesupload" value="上 传" class=text>
   </td>
  </tr>
 </table>
</form>
EOT;
}
include"footer.php";
?>