<?
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);
//read_user_zl($user_login_id);
if($cjadmin==$user_login_id)$yncjadmin="1";else $yncjadmin="0";
if($admin1==$user_login_id||$admin2==$user_login_id||$admin3==$user_login_id)$ynadmin="1";else $ynadmin="0";
if($yncjadmin=="1")$step1="1";
else if($ynadmin=="1")$step2="2";else{errorview("对不起，你没权进入！！");exit;}
$ynhead2="1";
$ynhead3="1";
include"header.php";
if($adpage=="main")adminpage();
if($admin_gg_xiu!="")admin_gg();
if($upadmin!="")upadmin();
if($deluserid!="")deluser();
############
function adminpage()
{
global $perpage,$myclass,$step,$user_login_id,$page,$user_id,$username,$disadmin,$upuser;
print<<<eot
<script language=JavaScript1.2>
var x =0
var y=0
drag = 0
move = 0
window.document.onmousemove = mouseMove
window.document.onmousedown = mouseDown
window.document.onmouseup = mouseUp
function Show(divid) {
divid.filters.revealTrans.apply();
divid.style.visibility = "visible";
divid.filters.revealTrans.play();
}
function Hide(divid) {
divid.filters.revealTrans.apply();
divid.style.visibility = "hidden";
divid.filters.revealTrans.play();
}
function mouseUp() {
move = 0;
}
function mouseDown() {
if (drag) {
clickleft = window.event.x - parseInt(dragObj.style.left);
clicktop = window.event.y - parseInt(dragObj.style.top);
dragObj.style.zIndex += 1;
move = 1;
}
}
function mouseMove() {
if (move) {
dragObj.style.left = window.event.x - clickleft;
dragObj.style.top = window.event.y - clicktop;
}
}
function mouseStop() {
window.event.returnValue = false;
}
</script>
<table width="750" border="1" cellspacing="0" cellpadding="2" align="center" bordercolorlight="#B5E1F7" bordercolordark="#FFFFFF">
 <tr>
  <td align="center" bgcolor="#B5E1F7" colspan="2"><font color="#000066"><b>管理页面</b></font></td>
 </tr>
 <tr>
  <td valign="top" width="375">
   <table width="100%" border="0" cellspacing="0" cellpadding="2">
    <tr align="center">
     <td width="28%">用户ID</td>
     <td width="34%">姓名</td>
     <td width="18%">升为管理员</td>
     <td width="20%">踢出本班</td>
    </tr>
eot;
$lines=file("class/$myclass/list");
$size=count($lines);
$ii=1; $j=$size;
while($j>0){$j=$j-$perpage;}
if ($page==""){$page=$ii;}
$pages=$page-1;
$pages=$page*$perpage-$perpage;
for($i=$pages; $i<$pages+$perpage; $i++)
    {
    $linea=$lines[$i];
    $linea=ereg_replace("\n","", $linea);
    if ($linea != "")
        {
        $lines1a=file("class/$myclass/list");
        while(list($tmpkey, $line1a) = each($lines1a))
              {
              $line1=ereg_replace("\n","", $line1);
              list($c_u_id,$c_add_date,$vi_count)=split("\t",$linea);
              }
         read_user_zl($c_u_id);
         print" <tr>
     <td width=28% align=center>$user_id</td>
     <td width=34% align=center>$username</td>
     <td width=18% align=center><a href=admin.php?myclass=$myclass&upuser=$user_id&disadmin=1&adpage=main>升为管理员</a></td>
     <td width=20% align=center><a href=admin.php?myclass=$myclass&deluserid=$user_id>踢出本班</a></td>
    </tr>";
    }
}
print"<tr><td colspan=4 align=right>";
 print"";
 $j=$size;
while ($j>0) {
 if ($page != $ii) {print "<a href=admin.php?myclass=$myclass&adpage=main&page=$ii>";};
 print "[$ii]";
 if ($page != $ii) {print "</a>";};
 $j=$j-$perpage;
 $ii++;
}
print<<<eot
</td>
    </tr>
   </table>
  </td>
  <td valign="top" width="361">
   <form name="form" method="post" action="admin.php?myclass=$myclass">
    <table width="100%" border="0" cellspacing="0" cellpadding="2">
     <tr>
      <td>公告牌内容：</td>
     </tr>
     <tr>
      <td>
       <textarea name="newgg" cols="50" rows="10" class=text>
eot;
$ggcontent=read_file("class/$myclass/news");
$ggcontent=explode("\n",$ggcontent);
         print $ggcontent[0];
print<<<eot
       </textarea>
      </td>
     </tr>
     <tr>
      <td align="center">
       <input type="submit" name="admin_gg_xiu" value="提 交" class=text>
       <input type="reset" name="Submit2" value="重 置" class=text>
      </td>
     </tr>
    </table>
   </form>
  </td>
 </tr>
 <tr>
  <td colspan="2">&nbsp;</td>
 </tr>
</table>
eot;
?>
<div align=center id="messanger" style="FILTER: revealTrans(transition=23,duration=0.5) blendTrans(duration=0.5); POSITION: absolute; z-index:1; background-color: #FFFFFF; border: 1px none #500000; top:82px;left:200;width:400px; visibility:<?if($disadmin==1)echo "visible";else echo "hidden";?>">
<table width="300" border="1" cellspacing="0" cellpadding="3" align="center" bordercolorlight="#B5E1F7" bordercolordark="#FFFFFF" onMouseOver="dragObj=messanger; drag=1;move=0" style="WIDTH: 100%; CURSOR: move" onMouseOut="drag=0">
 <tr>
  <td bgcolor="#B5E1F7" align="center">
   <table width="100%" border="0" cellspacing="0" cellpadding="2">
    <tr>
     <td width="86%" align="center"><b><font color="#FF0000">　　　升用户为管理员</font></b></td>
     <td width="14%" align="center"><span style="CURSOR:hand" onClick="Hide(messanger);">关闭</span></td>
    </tr>
   </table>
  </td>
 </tr>
 <tr>
  <form name="form1" method="post" action="admin.php?myclass=<?echo $myclass;?>"><td valign="top">
 <table width="100%" border="0" cellspacing="0" cellpadding="2">
     <tr>
      <td width="34%">选择序号：</td>
      <td width="66%">
       <select name="whichno">
        <option value="0" selected>请选择</option>
        <option value="1">第一个</option>
        <option value="2">第二个</option>
        <option value="3">第三个</option>
       </select>
      </td>
     </tr>
     <tr>
      <td width="34%">用户ID：</td>
      <td width="66%">
       <input type="text" name="willupid" size="15" class=text value=<?echo $upuser;?>>
      </td>
     </tr>
     <tr>
      <td colspan="2" align="center">
       <input type="submit" name="upadmin" value="提交" class=text>
       <input type="submit" name="Submit2" value="提交" class=text>
      </td>
     </tr>
    </table>
 </td> </form>
 </tr>
</table>
</div>
<?
}
###########
function admin_gg()
{
global $myclass,$user_login_id,$newgg;
$fp=fopen("class/$myclass/news","w") or die("file open error");
$newgg=str($newgg);
fwrite($fp,$newgg."\n");
fclose($fp);
print"<META HTTP-EQUIV=REFRESH CONTENT=0;URL=admin.php?myclass=$myclass&adpage=main>";
}
###########
function upadmin()
{
global $myclass,$user_login_id,$whichno,$step1,$willupid;
if($whichno==""||$whichno=="0"){errorview("请选择管员理序号！");exit;}
$lines = file("class/$myclass/config.php");
while (list($tmpkey,$line) = each($lines))
   {
   $line=ereg_replace("\n","",$line);
   list($to,$cname,$schoolfrom,$schoolcity,$schoolname,$classname,$add_day,$admin1,$admin2,$admin3)=split("\t",$line);
   }
if($whichno=="1")$admin1=$willupid;
if($whichno=="2")$admin2=$willupid;
if($whichno=="3")$admin3=$willupid;
   if($step1=="1")
   {
   $fp2=fopen("class/$myclass/config.php", "w+");
         $writedata="<?exit;\t".$cname."\t".$schoolfrom."\t".$schoolcity."\t".$schoolname."\t".$classname."\t".$add_day."\t".$admin1."\t".$admin2."\t".$admin3."\n";
         fwrite($fp2,"$writedata");
         fclose($fp2);
   errorview("用户升级成功！！");exit;
   }else {errorview("你没权修改管理员！！");exit;}
}
#############
function deluser()
{
global $myclass,$user_login_id,$deluserid,$step1,$step2,$cjadmin;
if($cjadmin==$deluserid){errorview("不能将班级创始人踢走！");exit;}
if($step1=="1"||$step2=="1")
   {
   $hastitles = file("class/$myclass/list");
   $ccc=count($hastitles);
   $fp = fopen("class/$myclass/list","w");
   for ($i=0;$i<$ccc;$i++){
    list($class_user,$user_date,$user_enter)=explode("\t",$hastitles[$i]);
    if($deluserid!=$class_user){fputs($fp,$hastitles[$i]);}
      }
    fclose($fp);
   $hastitles1 = file("user/$deluserid.cla");
   $ccc1=count($hastitles1);
   $fp1 = fopen("user/$deluserid.cla","w");
   for ($i=0;$i<$ccc1;$i++){
    list($class_id,$class_date,$class_enter)=explode("\t",$hastitles1[$i]);
    if($class_id!=$myclass){fputs($fp1,$hastitles1[$i]);}
      }
    fclose($fp1);
    errorview("踢走用户成功！！");
   }
if(file_exists("class/$myclass/msg/$deluserid.rec"))
unlink("class/$myclass/msg/$deluserid.rec");
if(file_exists("class/$myclass/msg/$deluserid.snd"))
unlink("class/$myclass/msg/$deluserid.snd");
print"<META HTTP-EQUIV=REFRESH CONTENT=0;URL=admin.php?myclass=$myclass&adpage=main>";
}
include"footer.php";
?>