<? 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;
}
.style1 {color: #FFFFFF}
#Layer2 {
	position:absolute;
	left:11px;
	top:67px;
	width:715px;
	height:159px;
	z-index:1;
}
.style2 {
	color: #CC6600;
	font-style: italic;
}
.style4 {color: #006600}
.style5 {color: #006600; font-style: italic; }
-->
</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"><span class="inputtextCopy">รหัสนักศึกษา</span> :</div></td>
            <td width="236"><div align="left">
                <form id="form1" name="form1" method="post" action="index.php?module=BookSent">
                  <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="inputtextCopy">ชื่อ - สกุล</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="inputtextCopy">โปรแกรมวิชา</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="inputtextCopy">สถานะ</span> :</div></td>
            <td><div align="left">
                <input name="textfield3" type="text" id="textfield3" value="<?=$data[status_]?>"  disabled="disabled"/>
            </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=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("+7 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="menuclick">ข้อมูลการค้างชำระค่าปรับ</legend>
        <span class="inputproject">คืนหนังสือช้ากว่าระยะเวลาที่กำหนดต้องชำระค่าปรับรวมทั้งหมด&nbsp;<?=$date_cal_;?>&nbsp; บาท</span>&nbsp;&nbsp;
  &nbsp;      <a href="javascript:NewWindow('<? echo"pay.php?pay=$id_sent";?>','newpopup','650','400','center','front');"><span class="menuclick">
      <span class="menuclick">ชำระค่าปรับ&nbsp;</span></a>
   &nbsp;&nbsp;
      </fieldset><? }?>

      </td>
    </tr>
    <tr>
      <td height="21"></td>
    </tr>

</table>

<table width="800" height="250" border="0" align="center">
  <tr>
    <td valign="top"><fieldset>
    <legend class="textstyle3">รายการคืน</legend>
    <table width="800" border="0">
      <tr>
        <td width="55" height="28" bgcolor="#FFFFCC" class="menuclick"><div align="center">รายการ</div></td>
        <td width="80" bgcolor="#FFFFCC" class="menuclick"><div align="center">รหัสหนังสือ</div></td>
        <td width="173" bgcolor="#FFFFCC" class="menuclick"><div align="center">ชื่อหนังสือ</div></td>
        <td width="137" bgcolor="#FFFFCC" class="menuclick"><div align="center">ประเภทหนังสือ</div></td>
        <td width="52" bgcolor="#FFFFCC" class="menuclick"><div align="center">จำนวน</div></td>
        <td width="81" bgcolor="#FFFFCC" class="menuclick"><div align="center">กำหนดคืน</div></td>
        <td width="111" bgcolor="#FFFFCC" class="menuclick"><div align="center">วันล่าช้า/ค่าปรับ</div></td>
        <td width="77" bgcolor="#FFFFCC" class="menuclick"><div align="center">คืนหนังสือ</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);
								
								//echo 
							//	echo $data_[date_sent];
		$date2= DateDiff("$data_[date_sent]","$d_d"); //echo $date2;
		if($date2 > 0 ){
		$num_cal=$date2;
		$date_cal_=$date2 * 5;
		//echo $date_cal_;
		}else{
		$num_cal=0;
		$date_cal_=0;
		}

		  ?>
      <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"><?=$num_cal?> วัน <?=$date_cal_?> บาท</div></td>
        <td bgcolor="#FFFFCC" class="inputtext"><div align="center">
        <a href="<? echo"index.php?module=BookSent&chk=$data_[id]&id_sent=$data_[member_id]&id_book=$data_[book_id]&book_num=$data_book[book_num]";?> ">
        <img src="images/books_024.gif" width="24" height="24"  border="0"/></a>
        </div></td>
      </tr> <? $i++;  }?>
      <tr>
        <td height="28" colspan="8" bgcolor="#FFFFCC" class="menuclick"><div align="right" class="textstyle3">รวมหนังสือที่ค้างส่งทั่งหมด :
          <?=$i-1;?>
          เล่ม  </div>          
        <div align="left"></div></td>
        </tr>
    </table>
    </fieldset></td>
  </tr>
</table>

<div align="center"></div>

<? if($chk!=""){
 $sql_up="update tbl_book set book_num=$book_num+1 where id='$id_book' ";
mysql_query("update bookborow set status_borrow=2 where id='$chk' ");
mysql_query($sql_up);
//echo $sql_up ; exit();
if($sql_up){echo"<script>alert('ระบบได้รับรายการที่คืนเรียบร้อยแล้ว')</script>"; echo "<script>window.location='index.php?module=BookSent& id_sent=$id_sent '</script>";}
}?>