
<html>
<head>
<title>Un title page</title>
<meta http-equiv="Content-Type" content="text/html; charset=windows-874">
 <style type="text/css">
<!--
.menuclick{background-color:#00CC33; color: #FFFFFF; font-size:14px; font-family:Microsoft Sans Serif; font-weight:bold;}
.inputdata{ border:0; border-bottom:thin dashed #999999;  background-color: #FFFFFF; color: #3399CC;font-family: "Microsoft Sans Serif";font-weight: normal; text-align: center; 
font-size:14px;   }
.inputtext{ border:0; border-bottom:thin dashed #999999;  background-color: #FFFFFF; color: #3399CC;font-family: "Microsoft Sans Serif";font-weight: normal; text-align: left; 
font-size:14px;  }
.inputproject{
	border:0;
	border-bottom:thin dashed #999999;
	background-color:#E7F4FF;
	color: #3399CC;
	font-family: "Microsoft Sans Serif";
	font-weight: normal;
	text-align: left;
	font-size: 14px;
}
.textstyle2 {
	font-family: "Microsoft Sans Serif";
	font-weight: bold;
	color: #999999;
}
.textstyle3 {
	font-family: "Microsoft Sans Serif";
	font-weight: normal;
	color:#FF0000;
}
.text1 {
	font-family: "Microsoft Sans Serif";
	font-weight: normal;
	color: #000000;
	text-align:center;
	font-size: 14px;
	background-color: #FFFFFF;
}

 </style>

</head>
<body bgcolor="#FFFFFF" >
<form action="" method="post" enctype="multipart/form-data" name="form1">
  <br><table width="683" border="0" align="center">
    <tr>
      <td><div align="left">
        <label></label>
        <label>
        <input name="search" type="submit" class="textstyle3" id="search" value="ค้นหาหนังสือ">
        </label>
        <label></label>
      </div>
      <label></label></td>
    </tr>
  </table>
<br>
  <table width="683" border="0" align="center">
    <tr>
      <td width="651"><table width="100%" border="0" cellspacing="5" cellpadding="0">
        <tr>
          <td width="21%"><label></label>
            <div align="right"><span class="text1">รหัสหนังสือ :</span>            </div>
            <label></label>
              <label></label>
              <label></label>
              <label></label>
            <div align="right"></div></td>
          <td width="29%"><div align="left">
            <input name="noID" type="text" id="noID" value="<?=$data_edit[no_id] ?>" />
          </div></td>
          <td width="18%"><div align="right"><span class="text1">ชื่อหนังสือ :</span>
          </div>
            <label></label>            </span></td>
          <td width="32%"><div align="left">
            <input name="name" type="text" id="name"  value="<?=$data_edit[book_name] ?>"/>
          </div></td>
        </tr>
      </table>
        <table width="100%" border="0" cellspacing="5" cellpadding="0">
          <tr>
            <td width="21%" height="38" bordercolor="#FFFFFF"><div align="right"><span class="text1">ประเภทหนังสือ : </span>
            </div>
              <label></label>
            <label></label></td>
            <td width="29%" bordercolor="#FFFFFF"><div align="left">
              <label>
              <select name="type_book" id="select" >
              <? $sql_select=mysql_query("select* from type_book");
			while($data_select=mysql_fetch_array($sql_select)){
			  ?>
                <option value="<?=$data_select[id] ?>" <? if($data_edit[book_type]==$data_select[id]){echo"selected";} ?>><?=$data_select[name] ?></option>
              <? }?>

              </select>
              </label>
            </div></td>
            <td width="18%" bordercolor="#FFFFFF" ><div align="right"><span class="text1">ผู้แต่งหนังสือ :</span></div></td>
            <td width="32%" bordercolor="#FFFFFF" ><div align="left">
              <input name="author" type="text" id="datepdfker2" value="<?=$data_edit[book_author] ?>" size="25">
            </div></td>
          </tr>
        </table>
        </td>
      <td width="22" valign="middle">&nbsp;</td>
    </tr>
  </table>

  <table width="683" border="0" align="center">
  <tr>
    <td width="651"><fieldset>
    <legend class="textstyle2">ข้อมูลหนังสือ</legend>
    <? include ("config.php");
	if($search){
$sql_search="select * from  tbl_book  where 1 ";
		if($noID){
		$sql_search .="and  no_id LIKE '%$noID' ";
		}
		if($name){
		$sql_search .="and  book_name LIKE '%$name%' ";
		}
		if($type_book){
		$sql_search .="and  book_type ='$type_book' ";
		}
				if($author){
		$sql_search .="and  book_author LIKE '%$author%' ";
		}

	}else{
	$sql_search="select * from tbl_book order by book_date desc ";
	}
	$sql_select=mysql_query($sql_search);
	$num=mysql_num_rows($sql_select);
	?>
    <div align="right"><span class="textstyle3">มีจำนวนหนังสือทั้งหมด <?=$num; ?> เรื่อง</span><br>
    </div>
    <table width="649" border="0" align="center">

      <tr>
        <td width="73" height="40" bgcolor="#E7F4FF" class="inputproject"><div align="center"><strong>รหัสหนังสือ</strong></div></td>
        <td width="133" bgcolor="#E7F4FF" class="inputproject"><div align="center"><strong>ชื่อหนังสือ</strong></div></td>
        <td width="116" bgcolor="#E7F4FF" class="inputproject"><div align="center"><strong>ประเภทหนังสือ</strong></div></td>
        <td width="119" bgcolor="#E7F4FF" class="inputproject"><div align="center"><strong>ผู้แต่ง</strong></div></td>
        <td width="77" bgcolor="#E7F4FF" class="inputproject"><div align="center"><strong>ไฟล์ PDF</strong></div></td>
        <td width="105" bgcolor="#E7F4FF" class="inputproject"><div align="center"><strong>จำนวน</strong></div></td>
      </tr>
          <? while ($data=mysql_fetch_array($sql_select)){
$sql_=mysql_query("select * from type_book where id=$data[book_type]");
$data_=mysql_fetch_array($sql_);
?>
      <tr>
        <td height="40" bgcolor="#FFFFCC" class="inputtext"><?=$data[no_id] ;?></td>
        <td bgcolor="#FFFFCC" class="inputtext"><? echo"$data[book_name]"; ?></td>
        <td bgcolor="#FFFFCC" class="inputtext"><?=$data_[name] ;?></td>
        <td bgcolor="#FFFFCC" class="inputtext"><div align="center">
          <?=$data[book_author] ;?>
        </div></td>
        <td bgcolor="#FFFFCC" class="inputtext"><div align="center"><a href="pdf/<?=$data[book_pdf]; ?> " target="_blank"> <img src="images/pdf.jpg" width="30" height="30" border="0"></a></div></td>
        <td bgcolor="#FFFFCC" class="inputtext"><div align="center">
          <?=$data[book_num] ;?>
        เล่ม</div></td>
      </tr>
      
            <? }?>
    </table>
    </fieldset>
    </td>
    </tr>
</table>
</form>
<?
if($add){
if($pdf!=""){
//echo "$pdf"; exit();
							 $pdf =$_FILES['pdf'] ['tmp_name'];
							  $pdf_name=$_FILES['pdf'] ['name'];
							  $pdf_size =$_FILES['pdf'] ['size'];
							  $pdf_type =$_FILES['pdf'] ['type'];
					//	echo $pdf_type ; exit();
						if ($pdf_type !="application/pdf") {
		echo "<script>alert('ระบบรองรับไฟล์นามสกุลเฉพาะ 	.gif  .jpeg  และ .png เท่านั้น')</script>";
		echo "<script>window.location='index.php?module=Book'</script>";  	 exit();
														
	}
				copy($_FILES["pdf"]["tmp_name"],"pdf/".$_FILES["pdf"]["name"]);
			}
			$date_book=date("d-m-Y");
$sql="insert into tbl_book values ('','$noID','$name','$detail','$type_book','$author','$price','$book_num','$pdf_name','$date_book')";

//echo $sql ; exit();
$re=mysql_query($sql);
if($re){
echo "<script>alert('ระบบได้ทำการเพิ่มข้อมูลหนังสือเรียบร้อยแล้ว')</script>";
echo "<script>window.location='index.php?module=Book'</script>";exit();
}
}
 ?>
<?
if($edit_data){

			if($pdf!=""){
					 $pdf =$_FILES['pdf'] ['tmp_name'];
							  $pdf_name=$_FILES['pdf'] ['name'];
							  $pdf_size =$_FILES['pdf'] ['size'];
							  $pdf_type =$_FILES['pdf'] ['type'];
					//	echo $pdf_type ; exit();
						if ($pdf_type !="application/pdf") {
		echo "<script>alert('ระบบรองรับไฟล์นามสกุลเฉพาะ 	.gif  .jpeg  และ .png เท่านั้น')</script>";
		echo "<script>window.location='index.php?module=Book'</script>";  	 exit();
														
	}
				copy($_FILES["pdf"]["tmp_name"],"pdf/".$_FILES["pdf"]["name"]);
				
$sql="update  tbl_book set no_id='$noID',book_name='$name',book_type='$type_book',book_pdf='$pdf_name',book_author='$author',book_price='$price',book_num='$book_num' ,
book_detail='$detail'  where id='$data_edit[id]' ";
//unlink("pdf/");

}else{
$sql="update  tbl_book set no_id='$noID',book_name='$name',book_type='$type_book',book_author='$author',book_price='$price',book_num='$book_num' ,book_detail='$detail'
where id='$data_edit[id]' ";
}
//echo $sql ; exit();
$re=mysql_query($sql);
if($re){
echo "<script>alert('ระบบได้ทำการแก้ไขข้อมูลหนังสือเรียบร้อยแล้ว')</script>";
echo "<script>window.location='index.php?module=Book& edit=$data_edit[id]'</script>";exit();
}
}
 ?>
<? if($delete){
$re=mysql_query("delete from tbl_book where id='$delete' ");
if($re){
unlink("pdf/$pdf_");
echo "<script>alert('ระบบได้ทำการลบข้อมูลหนังสือเรียบร้อยแล้ว')</script>";
echo "<script>window.location='index.php?module=Book'</script>";exit();
}
}?>
</body>
</html>