<?
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($yesupload!="")up_photo();
if($delphotoid!="")delphoto();
##############
function up_photo()
{
global $myclass,$user_login_id,$stemp,$todate,$phototitle,$ynhead2,$ynhead3,$schooln,$classn;
global $photofile,$photofile_size,$photofile_name;
if(empty($phototitle)||empty($photofile_name)){errorview("请填好所有资料！");exit;}
 if(strlen($phototitle)>=30){errorview("图片标题超出15字！");exit;}
if(($photofile_size>300000)){errorview("图片太大！");exit;}
$imagename=explode(".",$photofile_name);
//if($imagename[1]!="jpg"||$imagename[1]!="gif"){errorview("图片类型错误！");exit;}
$upload_name="class/$myclass/photo/$stemp.$imagename[1]";
copy($photofile,$upload_name);
$oldlist=read_file("class/$myclass/photo/list");
$oldlist=explode("\n",$oldlist);
$listcount=count($oldlist);
for ($j=0;$j<$listcount;$j++)
{
$listdetail=explode("\t",$oldlist[$j]);
}
$oldlist=implode("\n",$oldlist);
$new_line[0]=$stemp;
$new_line[1]=$stemp.".".$imagename[1];
$new_line[2]=$phototitle;
$new_line[3]=$todate;
$new_line[4]=$user_login_id;
$newlist=implode("\t",$new_line)."\n".$oldlist;
write_file("class/$myclass/photo/list",$newlist);
$ynrefresh="1";
$gopage="classphoto.php?myclass=$myclass";
$title="上传图片成功";
include"header.php";
print<<<eot
<table width="500" border="1" cellspacing="0" cellpadding="4"  bordercolorlight="#B5E1F7" bordercolordark="#FFFFFF" align="center">
  <tr>
    <td height="70">
      <div align="left"><a href="classphoto.php?myclass=$myclass">&gt;&gt;点击返回同学录</a></div>
    </td>
  </tr>
</table>
eot;
}
########
function delphoto()
{
global $user_login_id,$myclass,$delphotoid,$ynhead2,$ynhead3,$schooln,$classn,$admin1,$admin2,$admin3,$cjadmin;
$photofile=read_file("class/$myclass/photo/list");
$photofile=explode("\n",$photofile);
$listcount=count($photofile);
    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++)
    {
    $photodetail=explode("\t",$photofile[$j]);
    if($photodetail[0]==$delphotoid&&$photodetail[4]==$user_login_id){$delyn=1;break;}
    }
if($delyn==1||$del_ynadmin==1)
{
$hastitles=file("class/$myclass/photo/list");
$ccc=count($hastitles);
$fp=fopen("class/$myclass/photo/list","w");
for ($i=0;$i<$ccc;$i++)
 {
 list($photo_id,$photo_name,$photo_title,$photo_date,$photo_user)=explode("\t",$hastitles[$i]);
  if($delphotoid!=$photo_id){fputs($fp,$hastitles[$i]);}
 }
fclose($fp);
unlink("class/$myclass/photo/$photodetail[1]");
}else{errorview("非法删除照片！");exit;}
$ynrefresh="1";
$gopage="classphoto.php?myclass=$myclass";
$title="删除图片成功";
include"header.php";
print<<<eot
<table width="500" border="1" cellspacing="0" cellpadding="4"  bordercolorlight="#B5E1F7" bordercolordark="#FFFFFF" align="center">
  <tr>
    <td height="70">
      <div align="left"><a href="classphoto.php?myclass=$myclass">&gt;&gt;点击返回同学录</a></div>
    </td>
  </tr>
</table>
eot;
}
include"footer.php";
?>