<?php
session_start
();
 if (
session_is_registered("valid_user"))
{
$Username $valid_user;
include(
"../../include/FunctionDB.php");
include(
"../../include/Function.php");
include(
"admin_menu.php");
 
ConnectDB();
$sql "SELECT * FROM  bookmant_tb  Where  Year='$Year'  ";
$result mysql_query($sql) ;
$rs mysql_fetch_array($result);
$strSQL "SELECT * FROM  bookmant_tb  Where  Faculty_code='$Faculty_code'   and  Year='$Year'   and  Book_code='1'  Order By  Date_buy DESC ";
if (! 
$Page)
$Page 1;
$Pre_Page $Page 1;
$Next_Page $Page +1;
$Per_Page 50;
$result mysql_query($strSQL);

$Page_start = ($Per_Page*$Page) - $Per_Page;
$Num_Rows mysql_num_rows($result);
if( 
$Num_Rows <= $Per_Page)
   
$Num_Pages 1;
else if ((
$Num_Rows $Per_Page) == 0)
       
$Num_Pages = ($Num_Rows $Per_Page);
else
        
$Num_Pages = ($Num_Rows $Per_Page) + 1;
$Num_Pages = (int)$Num_Pages;

if (( 
$Page $Num_Pages) || ($Page 0))
  echo
"Page $Page More than $Num_Pages";
$strSQL .=" LIMIT $Page_start,$Per_Page" ;
$result mysql_query($strSQL); 
$num mysql_num_rows($result );
?>
<meta http-equiv="Content-Type" content="text/html; charset=TIS-620">
<style type="text/css">
<!--
.style6 {font-size: 14px}
-->
</style>
<script type="text/JavaScript">
<!--
function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}
//-->
</script>
<table width="842" border="0" cellpadding="0" cellspacing="0">
    <tr>
        <td><br><fieldset>
            <legend><font size="2" color="<?php echo $GLOBALS["COLOR_FONT_3"]; ?>"><a href="../menu_personal.php" >หน้าหลัก</a></font><font size="2" color="<?php echo $GLOBALS["COLOR_FONT_3"]; ?>"><img src="../../picture/ico3.gif" width="10" height="10" border="0" align="absmiddle" />แสดงข้อมูลรายการหนังสือรับ-ส่ง</font></legend>
            <label><div align="center">
              <form id="form1" name="form1" method="get" action="SearchbookList.php">
                <table width="833" border="0" cellspacing="0">
                  <tr>
                    <td width="589"><font size="2" face="Tahoma"><img src="../../picture/previous.gif" onclick="window.history.back()"  width="85" height="22" border="0" /></font></td>
                    <td width="214"><div align="right">ส่งรายงานออกเป็น</div></td>
                    <td width="24"><font size="2" face="Tahoma"><a href="Repbook.php?Year=<? echo $row[Year]?>"><img src="../../picture/excel.gif" onclick="window.history.back()"  width="18" height="18" border="0" /></a></font></td>
                  </tr>
                </table><br />
                <table width="100%" border="0" cellspacing="1" cellpadding="0" style="border:1px solid #CCCCFF">
                  <tr>
                    <td height="24" bgcolor="#DFDFFF"><div align="center"><font size="2" face="Tahoma">&nbsp;</font><font size="2" face="Tahoma"><strong>ชื่อที่ต้องการค้นหา</strong></font> <font size="2" face="Tahoma"> <img src="../../picture/search.gif" width="15" height="19" align="absmiddle" border="0" />&nbsp;
                              <input name="keyword" type="text" style="background-color:#F0FFD2;" value="<? echo"$keyword"?>" size="30">
                              <strong>จาก</strong></font> <font size="2" face="Tahoma">
                              <select name="fields" style="background-color:#F0FFD2;" >
                                <option value="<? echo "$fields"?>">เลือกรายการ</option>
                                <option value="Book_code">ชนิดหนังสือ</option>
                                <option value="No_in">เลขที่หนังสือ</option>
                                <option value="Date_buy">วัน-เดือน-ปี </option>
                                <option value="No">เลขทะเบียนหนังสือ</option>
                                <option value="Status">เรื่อง</option>
                              </select>
                              <input type="submit" name="Submit" value="ค้นหา" />
                          </font></div></td>
                  </tr>
                </table>
              </form>
              <table width="100%" border="0" align="center" cellpadding="0" cellspacing="1" style="background-color:#eeeeee; border:0px solid gray">
                <tr bgcolor="#CCCCFF">
                  <td height="24" colspan="5" bgcolor="#FFFFFF" ><div align="center"><font color="#000000" size="4" face="Tahoma">รายการหนังสือรับ-ส่ง ปี</font><strong><font color="#990099" size="2" face="Tahoma"> </font><font color="#000000" size="2" face="Tahoma">
                      <?php
            
echo"$rss[Year] ";
      
?>
                  </font><font color="#990099" size="2" face="Tahoma"></font></strong><font size="4" face="Tahoma"><font color="#003399"><? echo $Year?></font></font></div></td>
                </tr>
                <tr bgcolor="#E6E6E6">
                  <td width="27" align="center" style="border:1px solid gray"><font color="#000000" size="2" face="Tahoma">No.</font></td>
                  <td width="38" align="center" style="border:1px solid gray"><font size="2" face="Tahoma">เลขที่</font></td>
                  <td width="75" align="center" style="border:1px solid gray"><div align="center"><font size="2" face="Tahoma"> วันที่</font></div></td>
                  <td width="215" align="center" style="border:1px solid gray"><font size="2" face="Tahoma">เลขหนังสือ</font></td>
                  <td width="438" align="center" style="border:1px solid gray"><font color="#000000" size="2" face="Tahoma">เรื่อง</font></td>
                </tr>
                <?php
$i 
1;
 while(
$row mysql_fetch_array($result))
 {

     if(
$count==0)
     {
?>
                <tr bgcolor="#F7F7F7" >
                  <td align="center" ><strong><font color="#996600" size="1" face="Tahoma">
                    <?=$i?>
                  </font></strong></td>
                  <td align="center" bgcolor="#F7F7F7" ><div align="left"><font color="#336600" size="2" face="Tahoma"><? echo $row["No"]?></font></div></td>
                  <td align="center" bgcolor="#F7F7F7" ><div align="left"><font color="#336600" size="2" face="Tahoma"> </font><font color="#003366" size="2" face="Tahoma"> </font><font color="#336600" size="2" face="Tahoma"> </font><font color="#003366" size="2" face="Tahoma">
                      <?php 
       $sday 
$row[Date_buy];
    
$yearthai explode("-",$sday);
    
$day =      intval($yearthai[2]);
    
$month =  intval($yearthai[1]);
    
$year =     intval($yearthai[0]);     
          
//////////////////
 //   $yearthai =  $day ;
  
$m getThaiSubMonth($month);
     echo
"$day"." "."$m"." "."$year";
    
?>
                  </font><font color="#336600" size="2" face="Tahoma"> </font><font color="#003366" size="2" face="Tahoma"> </font><font color="#336600" size="2" face="Tahoma"> </font></div></td>
                  <td><div align="left"><font color="#336600" size="2" face="Tahoma"> </font>
                          <div align="left">
                            <div align="center" onclick="MM_openBrWindow('BookDetail.php?code=<?=$row["code"]?>','Detail','width=520,height=300,scrollbars=yes')">
                              <div align="left"><font color="#996600" size="2" face="Tahoma"><a href="#"><? echo $row["No_in"]?></a></font></div>
                            </div>
                          </div>
                  </div></td>
                  <td><div align="left"><font color="#336600" size="2" face="Tahoma"> </font>
                          <div align="left">
                            <div align="center" onclick="MM_openBrWindow('<?=$row["Img1"]?>','Detail','scrollbars=yes,width=850,height=600,scrollbars=yes')">
                              <div align="left"><font color="#996600" size="2" face="Tahoma"><a href="#"><? echo $row["Status"]?></a></font></div>
                            </div>
                          </div>
                  </div></td>
                </tr>
                <?
    $count
=1;
     }
else
{
?>
                <tr bgcolor="#FFFFFF">
                  <td align="center" bordercolor="#FFFFFF" ><strong><font color="#996600" size="1" face="Tahoma">
                    <?=$i?>
                  </font></strong></td>
                  <td align="center" bordercolor="#FFFFFF" ><div align="left"><font color="#336600" size="2" face="Tahoma"> <? echo $row["No"]?></font></div></td>
                  <td align="center" bordercolor="#FFFFFF" ><div align="left"><font color="#336600" size="2" face="Tahoma"> </font><font color="#003366" size="2" face="Tahoma"> </font><font color="#336600" size="2" face="Tahoma"> </font><font color="#003366" size="2" face="Tahoma">
                      <?php 
       $sday 
$row[Date_buy];
    
$yearthai explode("-",$sday);
    
$day =      intval($yearthai[2]);
    
$month =  intval($yearthai[1]);
    
$year =     intval($yearthai[0]);     
          
//////////////////
 //   $yearthai =  $day ;
  
$m getThaiSubMonth($month);
     echo
"$day"." "."$m"." "."$year";
    
?>
                  </font><font color="#336600" size="2" face="Tahoma"> </font><font color="#003366" size="2" face="Tahoma"> </font><font color="#336600" size="2" face="Tahoma"> </font></div></td>
                  <td bordercolor="#FFFFFF"><div align="left"><font color="#336600" size="2" face="Tahoma"> </font>
                          <div align="left">
                            <div align="center" onclick="MM_openBrWindow('BookDetail.php?code=<?=$row["code"]?>','Detail','scrollbars=yes,width=520,height=300')">
                              <div align="left"><font color="#996600" size="2" face="Tahoma"><a href="#"><? echo $row["No_in"]?></a></font></div>
                            </div>
                          </div>
                  </div></td>
                  <td height="18" bordercolor="#FFFFFF"><div align="left"><font color="#336600" size="2" face="Tahoma"> </font>
                          <div align="left">
                            <div align="center" onclick="MM_openBrWindow('<?=$row["Img1"]?>','Detail','scrollbars=yes,width=850,height=600')">
                              <div align="left"><font color="#996600" size="2" face="Tahoma"><a href="#"><? echo $row["Status"]?></a></font></div>
                            </div>
                          </div>
                  </div></td>
                </tr>
                <?
$count
=0;
}
$i++;
 }    
?>
                <tr bgcolor="#CCCCFF">
                  <td height="18" colspan="5" align="center" bgcolor="#FFFFFF" ><div align="center" class="style6"><font color="#000000" face="Tahoma">ทั้งหมด</font><font color="#003399" face="Tahoma"> <? echo $num ?> </font><font color="#FFFFFF" face="Tahoma"><font color="#003366">รายการ</font><font color="#FFFFFF">&nbsp;</font></font> </div></td>
                </tr>
              </table>
              <table width="100%" border="0" align="center" cellpadding="0" cellspacing="1" bordercolor="#CCCCCC">
                <tr>
                  <td align="right" bordercolor="#CCCCCC" class="Tahoma11"><div align="center"><font color="#FFFFFF"> <font color="#FFFFFF" size="3" face="MS Sans Serif"><strong> <font color="#0033CC"><font color="#FFFFFF"><font color="#FFFFFF" size="3" face="MS Sans Serif"><strong><font color="#0033CC" size="2" face="Tahoma"><?php echo $Num_Pages;?></font></strong></font></font><font size="2" face="Tahoma">&nbsp;</font></font></strong></font><font color="#000000" size="2" face="Tahoma"><strong> หน้า</strong></font> <font color="#0033CC" size="1" face="Tah<?php echo $Num_Pages;?>oma"><strong>
                      <?php
if ($Pre_Page)
   echo
"<a href=\"$PHP_SELF?Page=$Pre_Page&Year=$Year&Faculty_code=$Faculty_code\" class=\"PageLink\"><font =\"Ms San serif\" size=\"2\"><b>&lt;&lt; Previus</b> </font></a>";

   for(
$i=1;$i<=$Num_Pages;$i++)
   {
    if(
$i != $Page)
         echo
" [<a href=\"$PHP_SELF?Page=$i&Year=$Year&Faculty_code=$Faculty_code\" class=\"PageLink\"><font =\"Ms San serif\" size=\"2\"><b>$i</b></font></a>] ";
    else
        echo
"<b>$i</b>";
   }
if(
$Page != $Num_Pages)
 echo
"<a href=\"$PHP_SELF?Page=$Next_Page&Year=$Year&Faculty_code=$Faculty_code\" class=\"PageLink\"><font =\"Ms San serif\" size=\"2\"><b> Next &gt;&gt;</b> </font></a>";
 
?>
                  </strong></font> </font> </div></td>
                </tr>
              </table>
              </div>
            </label>
        </fieldset><br>
        <font color="<?php echo $GLOBALS["COLOR_FONT_3"];?>" size="2"><b>หมายเหตุ :</b> ใช้เมาส์คลิก<br>
        </font></td>
    </tr>
</table>
<?php 
    
}
else
{
    echo
"<meta http-equiv=\"refresh\" content=\"3;URL=../../login.php\">\n";
      echo
"Please Login ";
}
?>