<? include ("sess.php");
 if($id_sent){
$sql="select * from tbl_member where id ='$id_sent' ";
$re=mysql_query($sql);
$data=mysql_fetch_array($re);
	$sql_type=mysql_query("select * from type_program where id='$data[depart]' ");
	$data_type=mysql_fetch_array($sql_type);
}
 if($id_sent2){
$sql2="select * from tbl_book where id ='$id_sent2' ";

$re2=mysql_query($sql2);
$data2=mysql_fetch_array($re2);
	$sql2_type=mysql_query("select * from type_book where id='$data2[book_type]' ");
	//echo  $sql2_type; exit();
	$data2_type=mysql_fetch_array($sql2_type);
	$sql="select * from tbl_member where id ='$id_sent2_' ";
$re=mysql_query($sql);
$data=mysql_fetch_array($re);
	$sql_type=mysql_query("select * from type_program where id='$data[depart]' ");
	$data_type=mysql_fetch_array($sql_type);
}
 ?><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;
}
.style4 {color: #006600}
.style41 {
	font-family: "Microsoft Sans Serif";
	font-size: 14px;
	font-weight: normal;
	color: #000000;
	background-color: #FFFFFF;
	text-align: center;
}
.style42 {color: #FF0000}
-->
</style>

<table width="800" border="0" align="center">
    <tr>
      <td height="102"><fieldset>
        <legend class="textstyle3">ข้อมูลสมาชิก</legend>
<table width="800" border="0">
          <tr>
            <td width="166" height="38" class="text1"><div align="right" class="style4"><span class="style41">รหัสนักศึกษา</span> :</div></td>
            <td width="236"><div align="left">
                <form id="form1" name="form1" method="post" action="index.php?module=BookBorow">
                  <label>
                  <input name="id_sent" type="text" id="id_sent" value="<?=$data[no_id]?>" readonly="readonly"/>
                  </label>
                  <? if($sent_id!=""){?>
                  <label>
                  <input type="submit" class="menuclick2" name="submit" value="5" id="submit" />
                  </label>
                  <? }?>
                  &nbsp;&nbsp;<a href="javascript:NewWindow('<? echo"search_member.php";?>','newpopup','600','300','center','front');"><span class="menuclick">&nbsp;ค้นหา&nbsp; </span></a>
              </form>
                <label></label>
            </div></td>
            <td width="89" class="text1"><div align="right"><span class="style41">ชื่อ - สกุล</span> :</div></td>
            <td width="291"><div align="left">
              <input name="name" type="text" disabled="disabled" id="name" value="<? echo "$data[intro]$data[name] ";?>" />
            </div></td>
          </tr>
          <tr>
            <td height="33" class="text1"><div align="right"><span class="style41">โปรแกรมวิชา</span> :</div></td>
            <td><div align="left">
                <input name="textfield4" type="text" disabled="disabled" id="textfield4" value="<?=$data_type[name]?>" />
            </div></td>
            <td class="text1"><div align="right"><span class="style41">สถานะ</span> :</div></td>
            <td><div align="left">
                <input name="textfield3" type="text"  disabled="disabled" id="textfield3" value="<?=$data[status_]?>"/>
            </div></td>
          </tr>
      </table>
      </fieldset></td>
    </tr>
    <tr>
      <td></td>
    </tr>
    <tr>
      <td>
      <?
	  function DateDiff($strDate1,$strDate2)
	 {
				return (strtotime($strDate2) - strtotime($strDate1))/  ( 60 * 60 * 24 );  // 1 day = 60*60*24
	 }
$num_ber=1;
      	   $se="select * from bookborow where member_id= '$id_sent' and (status_borrow='1' or status_borrow='2') ";
	 //echo $se;
	  $se_=mysql_query($se);
	  $d_d=date("d-m-Y");
		while ($be_=mysql_fetch_array($se_)){
		//$d=date('d-m-Y',strtotime("+3 day"));
		$date_cal= DateDiff("$be_[date_sent]","$d_d");
		if($date_cal > 0 ){
		$a1=1;
		$num_cal+=$date_cal;
		$date_cal_+=$date_cal * 5;
		}
	}   if($a1!=1){?>
 
      <fieldset>
        <legend class="textstyle3">ข้อมูลหนังสือ</legend>
    <table width="800" border="0">
          <tr>
            <td width="165" height="32" class="text1"><div align="right"><span class="style41">รหัสหนังสือ</span> :</div></td>
            <td width="245"><div align="left">
              <form id="form2" name="form2" method="post" action="index.php?module=BookBorow">
                  <label>
                  <input type="hidden" name="id_sent2_" id="id_sent2_" value="<?=$id_sent2_?>"  />
                  <input name="id_sent2" type="text" class="style41" id="id_sent2" value="<?=$data2[no_id]?>" readonly="readonly"/>
                  </label>
                  <? if($sent_id2!=""){?>
                  <label>
                  
                  <input type="submit" class="menuclick2" value=" " />
                  </label>
                  <? }?>
                  &nbsp;&nbsp;
                  <? if ($id_sent!="" or $id_sent2!="" ){
				  if($id_sent){
                  $bb="search_book.php?id_sent1=$id_sent";}
				  if($id_sent2_){
				    $bb="search_book.php?id_sent1=$id_sent2_";}
				  ?>
                <a href="javascript:NewWindow('<? echo $bb;?>','newpopup','600','300','center','front');"><span class="menuclick">&nbsp;ค้นหา&nbsp; </span></a><? }?>
              </form>
              <label></label>
            </div></td>
            <td width="83" class="text1"><div align="right"><span class="style41">ชื่อหนังสือ</span> :</div></td>
            <td width="289"><div align="left">
              <input name="name2" type="text" disabled="disabled" class="style41" id="name2" value="<? echo "$data2[book_name] ";?>" />
            </div></td>
          </tr>
          <tr>
            <td height="38" class="text1"><div align="right"><span class="style41">ประเภทหนังสือ</span> :</div></td>
            <td><div align="left">
              <input name="textfield4" type="text" disabled="disabled" class="style41" id="textfield4" value="<?=$data2_type[name]?>" />
            </div></td>
            <td class="text1"><div align="right"><span class="style41">ผู้แต่ง</span> :</div></td>
            <td><div align="left">
              <input name="name3" type="text" disabled="disabled" class="style41" id="name3" value="<? echo "$data2[book_author] ";?>" />
            </div></td>
          </tr>
          <tr>
            <td height="34" class="text1"><div align="right"><span class="style41">จำนวน</span> :</div></td>
            <td><div align="left">
              <input name="name5" type="text" disabled="disabled" class="style41" id="name5" value="<? echo "$data2[book_num] ";?>" size="10" />
            </div></td>
            <td class="text1"><div align="right"><span class="style41">กำหนดคืน</span> :</div></td>
            <td><div align="left">
			<? //$d=date("d-m-Y");
			if($id_sent2){ $d=date('d-m-Y',strtotime("+3 day"));}
			?>
              <input name="date_sent" type="text" disabled="disabled" class="style41" id="date_sent" value="<?=$d ;?>" />
            </div></td>
          </tr>
          <tr>
            <td height="31" class="text1"></td>
            <td colspan="2">
              <form id="form3" name="form3" method="post" action="">
                <div align="left">
                  <input type="hidden" name="but" value="1"  />
                  <input type="hidden" name="id1" value="<?=$id_sent2_;?>"  />
                  <input type="hidden" name="id2" value="<?=$id_sent2;?>"  />
             
                  <? if($id_sent2!=""){?>
                  <input name="button" type="submit" class="menuclick" id="button" value="เพิ่มรายการ" />
                  <? }?>
                </div>
              </form>
            </td>
            <td>&nbsp;</td>
        </tr>
      </table>
      </fieldset>
      <? }?>
      </td>
    </tr>
    <tr>
      <td height="21">   
      <?
if($a1==1){
	  ?>
      <fieldset>
      <legend class="menuclick">ข้อมูลการค้างชำระค่าปรับ</legend>
        <span class="inputproject">คืนหนังสือช้ากว่าระยะเวลาที่กำหนดต้องชำระค่าปรับ</span>&nbsp;
     &nbsp;&nbsp;    
       <a href="javascript:NewWindow('<? echo"pay.php?pay=$id_sent";?>','newpopup','650','400','center','front');">
     <span class="menuclick">&nbsp;ดูรายละเอียดยอดค้างชำระ&nbsp;</span></a>
      </fieldset><? }?></td>
    </tr>

</table>
<? if($a1!=1){?>
<table width="800" border="0" align="center">
  <tr>
    <td>
    <fieldset>
    <legend class="textstyle3">รายการยืม</legend>
    <table width="800" border="0">
      <tr bgcolor="#E7F4FF">
        <td width="73" height="28" bgcolor="#E7F4FF" class="menuclick"><div align="center" class="inputproject">
          <div align="center">รายการที่</div>
        </div></td>
        <td width="82" class="menuclick"><div align="center" class="inputproject">
          <div align="center">รหัสหนังสือ</div>
        </div></td>
        <td width="210" bgcolor="#E7F4FF" class="menuclick"><div align="center" class="inputproject">
          <div align="center">ชื่อหนังสือ</div>
        </div></td>
        <td width="182" class="menuclick"><div align="center" class="inputproject">
          <div align="center">ประเภทหนังสือ</div>
        </div></td>
        <td width="58" bgcolor="#E7F4FF" class="menuclick"><div align="center" class="inputproject">
          <div align="center">จำนวน</div>
        </div></td>
        <td width="105" bgcolor="#E7F4FF" class="menuclick"><div align="center" class="inputproject">
          <div align="center">กำหนดคืน</div>
        </div></td>
        <td width="60" class="menuclick"><div align="center" class="inputproject">
          <div align="center">ยกเลิก</div>
        </div></td>
      </tr>
      <? // echo  $real ;exit();

	  	if($id_sent2_){
          $sql_="select * from bookborow where member_id= '$id_sent2_'  and status_borrow='1'  ";
		  //echo sql_  ; exit();
		  }else if($id_sent){
		   $sql_="select * from bookborow where member_id= '$id_sent' and status_borrow='1'  ";
		   }else{
		    $sql_="select * from bookborow where 0 ";
		   }
		   
		//  echo $sql_  ; exit();
		  $re_=mysql_query($sql_);$i=1;
		while (  $data_=mysql_fetch_array($re_)){
				$sql_book=mysql_query("select * from tbl_book where id='$data_[book_id]' ");
				$data_book=mysql_fetch_array($sql_book);
								$sql_type=mysql_query("select * from type_book where id='$data_book[book_type]' ");
								$data_type=mysql_fetch_array($sql_type);
		  ?>
      <tr>
        <td height="28" bgcolor="#FFFFCC" class="inputtext"><div align="center">
          <?=$i;?>
        </div></td>
        <td height="28" bgcolor="#FFFFCC" class="inputtext"><div align="center">
          <?=$data_book[no_id];?>
        </div></td>
        <td bgcolor="#FFFFCC" class="inputtext"><div align="left">
          <?=$data_book[book_name];?>
        </div></td>
        <td bgcolor="#FFFFCC" class="inputtext"><div align="left">
          <?=$data_type[name];?>
        </div></td>
        <td bgcolor="#FFFFCC" class="inputtext"><div align="center">1</div></td>
        <td bgcolor="#FFFFCC" class="inputtext"><div align="center">
          <?=$data_[date_sent];?>
        </div></td>
        <td bgcolor="#FFFFCC" class="inputtext"><div align="center">
        <a href="<? echo"index.php?module=BookBorow&chk=$data_[id]&id_sent=$data_[member_id]&id_book=$data_[book_id]";?> ">
        <img src="images/cancel.gif" width="16" height="16"  border="0"/></a>
        </div></td>
      </tr> <? $i++;  }?>
      <tr>
        <td height="28" colspan="7" bgcolor="#FFFFCC" class="menuclick"><div align="right"><span class="style42">รวมหนังสือที่ยืมทั่งหมด</span> :<span class="style42">
          <?=$i-1;?>
          เล่ม  </span></div>          <div align="left"></div></td>
        </tr>
    </table>
    </fieldset>
    </td>
  </tr>
</table>
<? }?>
<div align="center"></div>
<? if($but==1){
$d=date('d-m-Y',strtotime("+3 day"));
$date_borrow=date("d-m-Y");
 $sql_in="insert bookborow values('','$id1','$id2','$date_borrow','$d','1')";
 //echo $sql_in ; exit();
 $sql_insert=mysql_query($sql_in);
 ////
 $sq="select * from tbl_book where id='$id2'";
 $sqa=mysql_query($sq);
 $data=mysql_fetch_array($sqa);
 $sql_up="update tbl_book set book_num=$data[book_num]-1 where id='$id2' ";
  //echo $sq ; exit();
mysql_query($sql_up);
 /////
if($sql_insert){echo"<script>alert('เพิ่มรายการหนังสือเรียบร้อยแล้ว')</script>"; echo "<script>window.location='index.php?module=BookBorow& id_sent=$id1 '</script>";}
}?>
<? if($chk!=""){
 $sql_insert=mysql_query("delete  from  bookborow where id='$chk' ");
  $sq="select * from tbl_book where id='$id_book'";
 // 
  $sqa=mysql_query($sq);
 $data=mysql_fetch_array($sqa);
 $sql_up="update tbl_book set book_num=$data[book_num]+1 where id='$id_book' ";
mysql_query($sql_up);
//echo $sql_up ; exit();
if($sql_insert){echo"<script>alert('ระบบได้ลบรายการที่เลือกเรียบร้อยแล้ว')</script>"; echo "<script>window.location='index.php?module=BookBorow& id_sent=$id_sent '</script>";}
}?>
<?
////// ชำระค่าปรับ
 if($pay!=""){
 $sql_up="update bookborow set status_borrow=3 where member_id='$pay' and status_borrow=2 ";echo $sql_up ; exit();
mysql_query($sql_up);
//
if($sql_insert){echo"<script>alert('ระบบได้รับเรื่องการชำระเงินเงินเรียบร้อยแล้ว')</script>"; echo "<script>window.location='index.php?module=BookBorow& id_sent=$pay '</script>";}
}?>