<? include ("sess.php"); 
if($user_sess  != "admin" ){
echo "<script>alert('Sorry .. !!..Modules Admin..!!')</script>";
echo "<script>window.location='index.php'</script>";exit();
} 
?>
 <meta http-equiv="Content-Type" content="text/html; charset=windows-874" />
<link rel="stylesheet" type="text/css" href="../style.css">
<style type="text/css">
<!--
#Layer1 {
	position:absolute;
	left:13px;
	top:48px;
	width:87px;
	height:28px;
	z-index:1;
}
#Layer2 {
	position:absolute;
	left:11px;
	top:67px;
	width:715px;
	height:159px;
	z-index:1;
}
.style114 {
	font-family: "Microsoft Sans Serif";
	font-size: 14px;
	font-weight: normal;
	color: #000000;
	background-color: #FFFFFF;
	text-align: center;
}
.menuclick1 {background-color:#33CCFF; color: #FFFFFF; font-size:14px; font-family:Microsoft Sans Serif; font-weight:bold;}
.style11 {	font-family: "Microsoft Sans Serif";
	font-size: 14px; 
	color: #666666;
}
.style13 {color: #0000FF}
-->
</style>

<table width="600" border="0" align="center">
  <tr>
    <td><br />
    <p>
    <a href="<? echo" index.php?module=Admin_";?>">
    <span class="menuclick">&nbsp;<span class="style13">จัดการข้อมูลประเภทหนังสือ</span>&nbsp;</span></a>
    &nbsp; &nbsp;
        <a href="<? echo" index.php?module=Admin_2";?>">
    <span class="menuclick">&nbsp;<span class="style13">จัดการข้อมูลโปรแกรมวิชา</span>&nbsp;</span></a> &nbsp;&nbsp;&nbsp; <a href="<? echo" index.php?module=Admin_staff";?>"> <span class="menuclick">&nbsp;<span class="style13">จัดการข้อมูลเจ้าหน้าที่&nbsp;</span></span></a> &nbsp;&nbsp;&nbsp;</p></td>
  </tr>
</table><br />
<table width="600" border="0" align="center" height="250">
  <tr>
    <td><fieldset>
    <legend class="menuclick">จัดการข้อมูลเจ้าหน้าที่ </legend>
    <br />
    <?
    if($edit!==""){
	$sql_ed=mysql_query("select * from  tbl_admin where id='$id_name'");
	$data_ed=mysql_fetch_array($sql_ed);
	}
	
	?>
    <form id="form1" name="form1" method="post" action="">
      <table width="523" border="0" align="center">
        <tr height="50">
          <td width="176" height="27" class="style11"><div align="right"><span class="style114">เพิ่มข้อมูล User</span> :</div></td>
          <td width="302"><div align="left">
              <label>
              <input name="username" type="text" id="username" size="20" value="<?=$data_ed[username]?>"/>
              </label>
          </div></td>
        </tr>
        <tr height="50">
          <td height="27" class="style11"><div align="right"><span class="style114">เพิ่มข้อมูล Password</span> :</div></td>
          <td><div align="left">
              <label>
              <input name="pass" type="password" id="pass" size="20"  value="<?=$data_ed[password]?>" />
              </label>
          </div></td>
        </tr>
        <tr height="50">
          <td height="27" class="style11"><div align="right" class="inputtextCopy">
            <div align="right"><span class="style114">ชื่อ - สกุล :</span></div>
          </div></td>
          <td><div align="left">
              <label>
              <input name="name" type="text" id="name3" size="40"  value="<?=$data_ed[name]?>" />
              </label>
          </div></td>
        </tr>
        <tr height="50">
          <td height="27" class="style11"><div align="right"><span class="style114">ตำแหน่ง :</span></div></td>
          <td><div align="left">
              <label>
              <input name="position" type="text" id="name4" size="30"value="<?=$data_ed[position]?>"/>
              </label>
          </div></td>
        </tr>
        <tr>
          <td height="36">&nbsp;</td>
          <td><div align="left">
            <? if($edit){ ?>
            <input type="hidden" name="data1" value="2" />
            <input name="button" type="submit" class="textstyle3" id="button" value="แก้ไขข้อมูล" />
            <? }else{ ?>
            <input type="hidden" name="data1" value="1" />
            <input name="button" type="submit" class="textstyle3" id="button" value="เพิ่มข้อมูล" />
            <?       } ?>
          </div></td>
          </tr>
      </table>
      </form>
    <br />
    <table width="500" border="0" align="center">
      <tr>
        <td width="57" height="28" bgcolor="#FFFFCC" class="menuclick"><div align="center">รหัส</div></td>
        <td width="129" bgcolor="#FFFFCC" class="menuclick"><div align="center">ชื่อ - สกุล</div></td>
        <td width="101" bgcolor="#FFFFCC" class="menuclick"><div align="center">Username</div></td>
        <td width="111" bgcolor="#FFFFCC" class="menuclick"><div align="center">ตำแหน่ง</div></td>
        <td width="80" bgcolor="#FFFFCC" class="menuclick"><div align="center">จัดการ</div></td>
      </tr>
      <? // echo  $real ;exit();


		    $sql_="select * from tbl_admin ";
		//  echo $sql_  ; exit();
		  $re_=mysql_query($sql_);
		  
		while (  $data_=mysql_fetch_array($re_)){?>
      <tr>
        <td height="28" bgcolor="#FFFFCC" class="inputtext"><div align="center"><? echo"$data_[id]";?>

        </div></td>
        <td height="28" bgcolor="#FFFFCC" class="inputtext"><? echo"$data_[name]";?></td>
        <td height="28" bgcolor="#FFFFCC" class="inputtext"><? echo"$data_[username]";?></td>
        <td height="28" bgcolor="#FFFFCC" class="inputtext"><? echo"$data_[position]";?></td>
        <td bgcolor="#FFFFCC" class="inputtext"><div align="center">
          <div align="center"> <a href="<? echo"index.php?module=Admin_staff&id_name=$data_[id]&edit=$data_[name]";?>"> <img src="images/validate.png" width="16" height="16" border="0" /></a>
 &nbsp;<a href="<? echo" index.php?module=Admin_staff&id_name=$data_[id]&del=del";?>"><img src="images/cancel.gif" width="16" height="16" border="0" /></a></div></td>
      </tr> <?  }?>
    </table>
    </fieldset>
    </td>
  </tr>
</table>
  <? 
					  if($data1==1){
					
				
					  $sql="insert into tbl_admin values ('','$username','$pass','$name','$position')";
			//	 echo $sql ; exit();
					  $re=mysql_query($sql);
					  if($re){
					  echo "<script>alert('ระบบได้เพิ่มข้อมูลของเจ้าหน้าที่เรียบร้อยแล้ว')</script>";
					  echo "<script>window.location='index.php?module=Admin_staff'</script>";exit();
			}
					  }?>
 <? 

 if($del=='del'){
$sql="delete from  tbl_admin where id ='$id_name' ";
//echo $sql ; exit();
$re=mysql_query($sql);
			if($re){
			  echo "<script>alert('ระบบได้ทำการลบข้อมูลเรียบร้อยแล้ว')</script>";
				  echo "<script>window.location='index.php?module=Admin_staff'</script>";exit();
			}		
	}?>
 <? if($data1==2){
$sql="update   tbl_admin  set name ='$name',username ='$username',password ='$pass' ,position='$position' where id ='$id_name' ";
//echo $sql ; exit();
$re=mysql_query($sql);
			if($re){
			  echo "<script>alert('ระบบได้ทำการแก้ไขข้อมูลเรียบร้อยแล้ว')</script>";
				  echo "<script>window.location='index.php?module=Admin_staff&edit=edit&id_name=$id_name'</script>";exit();
			}		
	}?>
