<?
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();
##############
if($add_art!="")add_art();
if($xiu_art!="")xiu_art();
if($delartid!="")delart();
########
function add_art()
{
global $user_login_id,$stemp,$todate;
global $arttitle,$artcontent;
if (empty($arttitle)||empty($artcontent))
    {
    errorview("请认真填好文章资料！！");
    exit;
    }
$oldlist=read_file("data/read/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=$stemp;
$newlist=$new_line."\n".$oldlist;
write_file("data/read/list",$newlist); //ok, write to the list
$fp=fopen("data/read/$stemp","a+") or die("file open error");
$artdata=str($artcontent);
fwrite($fp,$arttitle."\t".$todate."\t".$user_login_id."\t".$artdata."\n");
fclose($fp);
$ynrefresh="1";
$gopage="classart.php";
$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="classart.php">&gt;&gt;点击返回同学录</a></div>
    </td>
  </tr>
</table>
eot;
include"footer.php";
}
#############
function xiu_art()
{
global $user_login_id,$artxiuid,$a_title,$a_date,$a_sendid,$a_content,$arttitle,$artcontent;
if(!file_exists("data/read/$artxiuid")){errorview("读取文章出错！");exit;}
else{
read_art($artxiuid);
if($user_login_id!=$a_sendid){errorview("非法修改文章！");exit;}
$fp=fopen("data/read/$artxiuid","w+");
fwrite($fp,$arttitle."\t".$a_date."\t".$user_login_id."\t".$artcontent."\n");
fclose($fp);
$ynrefresh="1";
$gopage="classart.php";
$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="classart.php">&gt;&gt;点击返回同学录</a></div>
    </td>
  </tr>
</table>
eot;
include"footer.php";
}
}
#########
function delart()
{
global $user_login_id,$delartid,$admin1,$admin2,$admin3,$cjadmin,$a_title,$a_date,$a_sendid,$a_content;
$artfile=read_file("data/read/list");
$artfile=explode("\n",$artfile);
$listcount=count($artfile);
   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++)
    {
    $artdetail=explode("\n",$artfile[$j]);
    read_art($artdetail);
    if($artdetail==$delartid&&$a_sendid==$user_login_id){$delyn=1;break;}
    }
if($delyn==1||$del_ynadmin==1)
{
$hastitles=file("data/read/list");
$ccc=count($hastitles);
$fp=fopen("data/read/list","w");
for ($i=0;$i<$ccc;$i++)
 {
 list($art_id)=explode("\n",$hastitles[$i]);
  if($delartid!=$art_id){fputs($fp,$hastitles[$i]);}
 }
fclose($fp);
unlink("data/read/$delartid");
}else{errorview("非法删除文章！");exit;}
$ynrefresh="1";
$gopage="classart.php";
$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="classart.php">&gt;&gt;点击返回同学录</a></div>
    </td>
  </tr>
</table>
eot;
include"footer.php";

}
?>