<?php
include("../db.php");
$ch=$_REQUEST["type"];
if($ch=="getSubject"){
	$subjects = $db->getRows("select * from subject where school_id='".$_SESSION["admin"]["school_id"]."' and class='".$_REQUEST["id"]."'");
	?>
    <label class="control-label" for="class">Subject</label>
	<div class="controls">
    <select name="subject" id="subject">
	<option value="">select</option>
	<?php
	if(is_array($subjects) && count($subjects)>0){
		foreach($subjects as $sub){
			?><option><?php echo $sub["subject"] ?></option><?php 
		}
	}
	?></select></div><?php
}elseif($ch=="issuebook"){
	if($_REQUEST["idate"]==""){
		echo "Please Enter Issue Date";
	}elseif($_REQUEST["rdate"]==""){
		echo "Please Enter Return Date";
	}elseif(strtotime($_REQUEST["rdate"])<strtotime($_REQUEST["idate"])){
		echo "Return date should not be smaller then Issue date";
	}else{
		$sAry=array("idate"=>$_REQUEST["idate"],
					"rdate"=>$_REQUEST["rdate"],
					"sid"=>$_REQUEST["sid"],
					"school_id"=>$_SESSION["admin"]["school_id"],
					"added_by"=>$_SESSION["admin"]["uid"],
					"bid"=>$_REQUEST["bid"],
					"fine"=>0,
					"status"=>0
		);
		$c=$db->insertAry("issueBook",$sAry);
		if(!is_null($c)){
			
		sms(mydetail("mobile",$_REQUEST["sid"],"student"),"Dear ".mydetail("name",$_REQUEST["sid"],"student").", New Book is  successfully issue  on ".$_REQUEST["idate"],"library_issue");
		echo "Book has been issued..!";
		}
		echo $db->getErMsg(); 
	}
	
}

elseif($ch=="get_return_date"){

    $idate = $_POST['idate'];
    $days  = $_POST['days'];

    if($days!=""){
        $rdate = date('Y-m-d', strtotime($idate. " + $days days"));
    } else {
        $rdate = $idate;
    }

echo json_encode(array("rdate"=>$rdate));
    // echo trim($rdate);

}

?>