<?php
require_once("checkstate.php");
?>

<?php
require("connect.php");
?>



<?php    //本程式碼是處理班級通訊錄之新增、刪除、修改

//刪除
if ($_GET['action']=="delete") {
//	echo "here";
	$schnum=$_GET['id'];
	$sql="delete from classmate where schnum='$schnum'";
//echo $sql; exit();
	mysql_query($sql) or die("delete error!");
}

//修改
if ($_POST['action']=="modify") {
	
	$schnum = $_POST['schnum'];
	$name = $_POST['name'];
	$gender = $_POST['gender'];
	$email = $_POST['email'];

	$sql="UPDATE classmate SET name='$name',gender='$gender',email='$email'";
	$sql.=" WHERE schnum='$schnum'";

//echo $sql; exit();

	mysql_query($sql) or die("ERROR insert");
	//echo "新增成功!";
}

//新增
if ($_POST['action']=="add_new") {
	$schnum = $_POST['schnum'];
	$name = $_POST['name'];
	$gender = $_POST['gender'];
	$email = $_POST['email'];

	$sql="INSERT INTO classmate(schnum,name,gender,email) VALUES ('$schnum','$name','$gender','$email')";
//echo $sql; exit();
	mysql_query($sql) or die("ERROR insert");
}
?>



<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>無標題文件</title>
<style type="text/css">
.aaa {
	font-size: 36px;
	color: #00F;
}
.bbb {
	font-size: 20px;
	color: #093;
	font-weight: bold;
}
</style></head>

<body>
<table width="980" height="818" border="1" align="center">
  <tr>
    <td height="112" colspan="2" align="center" class="aaa">後台管理程式</td>
  </tr>
  <tr>
    <td width="151" valign="baseline">&nbsp;<?php require_once("left_menu.php");?></td>
    <td width="813" align="center" valign="top"><p class="bbb">&nbsp;</p>
      <p class="bbb">班級通信錄 清單</p>
<?php 
$result=mysql_query("select * from classmate");

?>

      <p>總筆數：<?php echo mysql_num_rows($result);?></p>
      <table width="657" border="0" cellpadding="3" cellspacing="3">
        <tr>
          <td width="324">&nbsp;</td>
          <td width="323" align="right">　<a href="class_contact_add.php">新增</a></td>
        </tr>
      </table>
      <table width="657" height="78" border="1" align="center">
        <tr>
        <th width="132" height="34">學號</th>
        <th width="132">姓名</th>
        <th width="98">姓別</th>
        <th width="180">Email</th>
        <th width="81">功能</th>
      </tr>

<?php

while ($object=mysql_fetch_object($result)) {
?>
      <tr>
        <td align="center"><?php echo $object->schnum;?></td>
        <td align="center"><?php echo $object->name;?></td>
        <td align="center"><?php echo $object->gender=='b'?"男":"女";?></td>
        <td><?php echo $object->email;?></td>
        <td align="center"><a href="class_contact_modify.php?id=<?php echo $object->schnum;?>"><img src="images/b_edit.png" border=0 title='修改'></a> <a href="<?php echo $_SERVER['PHP_SELF'];?>?action=delete&id=<?php echo $object->schnum; ?>"><img src="images/b_drop.png" border=0 title='立即刪除'></a></td>
      </tr>
      <?php
}
?>
  </table>
  
  </td>
  </tr>
</table>
</body>
</html>