<?php
session_start();
//	echo $_SESSION["tendn"];
	if(@$_SESSION["tendn"] <> "admin")
		{echo "No accessright";
		exit();
}
 require("Connection.php");
 
$truongmn=@$_POST["truongmn"];
$trangthai=@$_POST["timtt"];

$tungay=@$_POST["tungay"];

if($tungay=="")
	{
	$now = getdate();
	$ng=$now["mday"]-1;
    $tungay = $now["year"] . "-" . $now["mon"] . "-" . $ng;
    }

$denngay=@$_POST["denngay"];
if($denngay=="")
	{
	$now = getdate();
    $denngay = $now["year"] . "-" . $now["mon"] . "-" . $now["mday"];
}

$chuoitim="";
if($truongmn<>"")
	$chuoitim=$chuoitim . " a.matruongmn = '".$truongmn."' and " ;

if($trangthai<>"")
	$chuoitim=$chuoitim . " a.trangthai = '".$trangthai."' and " ;

if($tungay<>"" and $denngay<>"")
	$chuoitim=$chuoitim . " a.ngaydexuat between '".$tungay."' and '".$denngay."' and " ;

if($chuoitim<> "")
// sql ="SELECT top 500 a.*,b.khoilop, b.tenlopmn FROM dexuatgiaotrinh a , lopmn b where " & chuoitim & " a.malopmn=b.malopmn  order by a.ngaydexuat desc"
 $sql ="SELECT  a.*,b.khoilop, b.tenlopmn FROM dexuatgiaotrinh a , lopmn b where " .$chuoitim . " a.malopmn=b.malopmn  order by a.ngaydexuat desc limit 0,500";
 //$sql ="SELECT * FROM chitietdexuatgiaotrinh where " . $chuoitim . "   1=1 order by ngaydexuat desc ";
else
//' sql ="SELECT top 500 a.*,b.khoilop, b.tenlopmn FROM dexuatgiaotrinh a , lopmn b where a.malopmn=b.malopmn  order by a.ngaydexuat desc"
//        $sql ="SELECT * FROM chitietdexuatgiaotrinh   order by ngaydexuat desc limit 0,500";
$sql ="SELECT a.*,b.khoilop, b.tenlopmn FROM dexuatgiaotrinh a , lopmn b where a.malopmn=b.malopmn  order by a.ngaydexuat desc limit 0,500";

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<HTML>
<HEAD><Title>De xuat giao trinh</Title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link href="css/default.css" rel="stylesheet" type="text/css" />
<style type="text/css">
<!--
body {
	margin-left: 00px;
	margin-top: 0px;
	margin-right: 0px;
	margin-bottom: 0px;
}
.style7 {
	font-size: 16pt;
	color:  #CC0000;
	font-weight: bold;
	font-family: Arial, Helvetica, sans-serif;
}
.style5 {	color: #009900;
	font-weight: bold;
	font-family: Arial, Helvetica, sans-serif;
	font-size: 14px;
}
.style8 {color: #993300}
-->
</style>
</HEAD>
<center>
	</head>
	<body>
<div align="center"><span class="style7">CẤP PHÁT GI&Aacute;O TR&Igrave;NH</Span></div>
	<form name=f1  method=POST >
<div align="center">
  <table width="70%"  border="0" cellpadding="0" cellspacing="0" class="khungbao1">
    <tr>
      <td width="21%" height="33" class="style5"><div align="right">Trư&#7901;ng MN : </div></td>
      <td width="40%"><select name="truongmn" class="box1">
        <option value="" >Tất cả</option>
		<?php
		$sql1="select * from truongmn";

	$result1=mysql_query($sql1,$link);
	$tongrec1= mysql_num_rows($result1);
	if ($tongrec1>0)
	{
	while ($row1=mysql_fetch_array($result1))
			{		$matrmn=$row1["matruongmn"];
				$tentruongmn=$row1["tentruongmn"];
		?>	
			<option value="<?php echo $matrmn;?>" <?php if($matrmn==$truongmn)echo " selected"; ?>>    <?php echo $tentruongmn;?>        </option>
		<?php
			}
	}
	?>
        
      </select></td>
      <td width="18%"><div align="right" class="style5">Tr&#7841;ng th&aacute;i:</div></td>
      <td width="21%"><select name="timtt" class="box1" id="timtt" ">
        <option value="" >Tất cả</option>
                 <option value="XK" <?php if($trangthai=="XK") echo " selected"; ?>>XUẤT KHO</option>
                <option value="DX" <?php if($trangthai=="DX") echo " selected"; ?>>ĐỀ XUẤT</option>
   
      </select></td>
    <td width="21%"><div align="right">
      <input name="cmd1" type="button" value="Tìm kiếm" onclick="kt()"/>
    </div></td>
    </tr>
    <tr>
      <td class="style5"><div align="right">Ng&agrave;y &#273;&#7873; xu&#7845;t :</div></td>
      <td colspan="4"><span class="style5"> &nbsp;<span class="style8">t&#7915; ng&agrave;y </span></span>
        <input name="tungay" type="text" value="<?php echo $tungay;?>"/>
        <span class="style5"><span class="style8">&#273;&#7871;n ng&agrave;y </span></span>
        <input name="denngay" type="text" value="<?php echo $denngay;?>"/></td>
      </tr>
  </table>

    </div>


	<div align="center">      
	  <br />
	  <input type="hidden" value="<%=malh%>" name="malh" />
</div>
	
<p align="center">&nbsp;</p>
	    <table width="100%" cellspacing="0" class="khungbao1">
          <tr>
            <td width="3%" align = "center" class="dkta1"><p align="center"><font color="#800000" face="Arial" size="2">M&atilde;QL</font></p></td>
            <td width="9%" align = "center" class="dkta1"><p align="center"><font color="#800000" face="Arial" size="2">Ng&agrave;y &#273;&#7873; xu&#7845;t</font></p></td>
            <td width="14%" align = "center" class="dkta1"><p align="center"><font color="#800000" face="Arial" size="2">Kh&#7889;i/Trư&#7901;ng</font></p></td>
            <td width="5%" align = "center" class="dkta1"><p align="center"><font color="#800000" face="Arial" size="2">L&#7899;p</font></p></td>
            <td width="7%" align = "center" class="dkta1"><p align="center"><font color="#800000" face="Arial" size="2">S&#7889; lư&#7907;ng b&eacute;</font></p></td>
            <td width="36%" align = "center" class="dkta1"><p align="center"><font color="#800000" face="Arial" size="2">Gi&aacute;o tr&igrave;nh &#273;&atilde; &#273;&#7873; xu&#7845;t</font></p></td>
            <td width="9%" align = "center" class="dkta1"><p align="center"><font color="#800000" size="2" face="Arial">Ngư&#7901;i &#273;&#7873; xu&#7845;t</font></p></td>
            <td width="9%" align = "center" class="dkta1"><p align="center"><font color="#800000" face="Arial" size="2">Tr&#7841;ng thái</font></p></td>
            <td width="8%" align = "center" class="dkta1"><p align="center"><font color="#800000" face="Arial" size="2">Trư&#7901;ng</font></p></td>
          </tr>
<?php
		 $result=mysql_query($sql,$link);
	$tongrec= mysql_num_rows($result);
	$i=0;
	if ($tongrec>0)
	{
	while ($row=mysql_fetch_array($result))
			{		
				$i++;
				$malopmn=$row1["malopmn"];
				?>
          <tr>
            <td align = "center" class="dkta1"><div align="center"><font  face="arial"  size="2"><?php echo $row["madx"];?></font>&nbsp;</div></td>
            <td align = "center" class="dkta1"><div align="center"><font  face="arial"  size="2"><?php echo $row["ngaydexuat"];?></font>&nbsp;</div></td>
            <td align = "center" class="dkta1"><div align="center"><font  face="arial"  size="2"><?php echo $row["khoilop"];?></font>&nbsp;</div></td>
            <td align = "center" class="dkta1"><div align="center"><font  face="arial"  size="2"><?php echo $row["tenlopmn"];?></font>&nbsp;</div></td>
            <td align = "center" class="dkta1"><div align="center"><font  face="arial"  size="2"><?php echo $row["soluongbe"];?></font>&nbsp;</div></td>
            <td align = "center" class="dkta1"><div align="center"><font  face="arial"  size="2"><?php echo $row["noidungdx"];?></font>&nbsp;</div></td>
            <td align = "center" class="dkta1"><div align="center"><font  face="arial"  size="2"><?php echo $row["nguoidx"];?></font>&nbsp;</div></td>
            <td align = "center" class="dkta1" ><div align="center"><strong>            
              <select name="trangthai<?php echo $row["madx"];?>"  class="box1">
                 <option value="XK" <?php if($row["trangthai"]=="XK") echo " selected"; ?>>XUẤT KHO</option>
                <option value="DX" <?php if($row["trangthai"]=="DX") echo " selected"; ?>>ĐỀ XUẤT</option>
              </select>
            &nbsp;</strong></div></td>
            <td align = "center" class="dkta1" ><div align="center"><font  face="arial"  size="2"><?php echo $row["matruongmn"];?></font>
            </div></td>
          </tr>
<?php 
}
}
?>
        </table>
	    <p align="center">
	      <input type="button" value="Cập nhật" name="cmd1" onclick="chuyenlop()"/>
&nbsp;&nbsp;
<input name="cmd12" type="button" value="Trở về" onclick="javascript:window.location.href='logout.php';" />
	    </p>
</form>
    </body>
</html>
		<script language="javascript">

	function checknum()
	{
		var a=window.event.keyCode;
		if(a<48 || a>57)
			window.event.keyCode=0;
		
	}

		function kt()
		{
		
	 {document.f1.action="capphatgiaotrinh.php";
			 document.f1.submit();}
		}
		 function chuyenlop()
		 {

			 document.f1.action="capnhatcapphatgt.php";
			 document.f1.submit();
			 }
			 
	
		</script>
<?php $tcok=@$_GET["tc"];
if($tcok=="1")
{?>
<script language="javascript">
alert("Cap nhat thanh cong !");
</script>
<?php } ?>