ok

Mini Shell

Direktori : /proc/thread-self/root/proc/self/root/home/ngwcolle/public_html/LIBRARY-NGWC/admin/
Upload File :
Current File : //proc/thread-self/root/proc/self/root/home/ngwcolle/public_html/LIBRARY-NGWC/admin/borrow_book.php

<?php session_start();
//DB conncetion
date_default_timezone_set('Asia/Kolkata');
include_once('includes/config.php');
error_reporting(0);
//validating Session
if (strlen($_SESSION['aid']==0)) {
  header('location:logout.php');
  } else{

//Code for record deletion
if($_GET['teamid']){
$tid=$_GET['teamid'];
mysqli_query($con,"delete from tblteams where id ='$tid'");
echo "<script>alert('Data Deleted');</script>";
echo "<script>window.location.href='manage-teams.php'</script>";
          }
          
          $school_number = $_GET['school_number'];
          $user_query = mysqli_query($con,"SELECT * FROM tbl_students WHERE rollno = '$school_number' ");
          $user_row = mysqli_fetch_array($user_query);
          //get current login user name
          $adid=$_SESSION['aid'];
$ret1=mysqli_query($con,"select AdminName from tbladmin where ID='$adid'");
while($row1=mysqli_fetch_array($ret1)){
    $cuser=$row1['AdminName'];
}
          // add deprmtnet
          if(isset($_POST['submit']))
          {
            $tname=strtoupper($_POST['dname']);
            $tlname=$_POST['cno'];
          $mobno=strtoupper($_POST['scode']);
        //   $tmember=$_POST['teammember'];
        $query=mysqli_query($con, "insert into tbl_department(name,shortcode,classno) values('$tname','$mobno','$tlname')");
        if ($query) {
        echo '<script>alert("Department Created.")</script>';
        echo "<script>window.location.href ='manage-department.php'</script>";
          }else{
        echo '<script>alert("Something Went Wrong. Please try again.")</script>';
            }
        }
          //end addition
?>
<!DOCTYPE html>
<html lang="en">

<head>

    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <meta name="description" content="">
    <meta name="author" content="">

    <title>Add New Department</title>
    <link rel="icon" type="image/x-icon" href="../assets/favicon.ico" /> 
    <!-- Custom fonts for this template -->
    <link href="vendor/fontawesome-free/css/all.min.css" rel="stylesheet" type="text/css">
    <link
        href="https://fonts.googleapis.com/css?family=Nunito:200,200i,300,300i,400,400i,600,600i,700,700i,800,800i,900,900i"
        rel="stylesheet">

    <!-- Custom styles for this template -->
    <link href="css/sb-admin-2.min.css" rel="stylesheet">

    <!-- Custom styles for this page -->
    <link href="vendor/datatables/dataTables.bootstrap4.min.css" rel="stylesheet">

</head>

<body id="page-top">

    <!-- Page Wrapper -->
    <div id="wrapper">

        <!-- Sidebar -->
  <?php include_once('includes/sidebar.php');?>
        <!-- End of Sidebar -->

        <!-- Content Wrapper -->
        <div id="content-wrapper" class="d-flex flex-column">

            <!-- Main Content -->
            <div id="content">

                <!-- Topbar -->
<?php include_once('includes/topbar.php');?>
                <!-- End of Topbar -->

                <!-- Begin Page Content -->
                <div class="container-fluid">

                    <!-- Page Heading -->
                       <div class="d-sm-flex align-items-center justify-content-between mb-4">
                        <h1 class="h3 mb-0 text-gray-800">Issue Material to Patron</h1>
                
                    </div>
                        <!-- DataTales Example -->
                        <?php
						$sql = mysqli_query($con,"SELECT  tbl_students.*,tbl_department.* FROM tbl_students INNER JOIN tbl_department ON tbl_students.department=tbl_department.id WHERE tbl_students.rollno = '$school_number' ");
						$row = mysqli_fetch_array($sql);
					?>
                    <div class="card shadow mb-4">
                        <div class="card-header py-3">
                          <div class="float-left">  <h6 class="m-0 py-2 font-weight-bold text-primary">
                          Borrower Name : <span style="color:maroon;"><?php echo strtoupper($row['stname'])."//".strtoupper($row['rollno'])."//".strtoupper($row['name']); ?></span>
                          </h6>
                        <input type="hidden" name="cuser" value="<?php echo $cuser;?>"/>  
                        </div>
                            <div class="float-right"><a href="manage-department.php" class="float-right mt-0 btn btn-success">Back</a></div>
                        </div>
                        
                        <div class="card-body">
                       <!-- outstanding area -->
                       <div class="table-responsive">
                                <table class="table table-bordered" id="dataTable" width="100%" cellspacing="0">
                                    <thead>
                                        <tr>
                                            <th>Barcode</th>
                                            <th>Book Title</th>
                                            <th>Author </th>
                                            <th>ISBN</th>
                                            <th>Date Borrowed</th>
                                            <th>Due Date</th>
                                            <th>Penalty</th>
                                             <!-- <th>Reporting Time</th> -->
                                            <th>Action</th>
                                        </tr>
                                    </thead>
                                    <!-- <tfoot>
                                     <tr>
                                            <th>Sno.</th>
                                            <th>Name</th>
                                            <th>Mobile Number</th>
                                            <th>Location </th>
                                             <th>Message</th>
                                             <th>Reporting Time</th>
                                            <th>Action</th>
                                        </tr>
                                    </tfoot> -->
                                    <tbody>
<?php $query=mysqli_query($con,"select tbl_book.*,borrow_book.* from borrow_book inner join tbl_book on borrow_book.book_id=tbl_book.barcode where user_id='$school_number' and borrowed_status='borrowed'");
$cnt=1;
$borrow_count = mysqli_num_rows($query);
while($row=mysqli_fetch_array($query)){
    $timezone = "Asia/Kolkata";
	if(function_exists('date_default_timezone_set')) date_default_timezone_set($timezone);
    $due_date= $row['due_date'];
    $date_returned = date("Y-m-d H:i:s");
    $penalty_amount_query= mysqli_query($con,"select * from settings") or die (mysqli_error());
	$penalty_amount = mysqli_fetch_assoc($penalty_amount_query);
	if($date_returned > $due_date) {
	$penalty = round((float)(strtotime($date_returned) - strtotime($due_date)) / (60 * 60 *24) * ($penalty_amount['penalty_amount']));
	} elseif ($date_returned < $due_date) {
	$penalty = 'No Penalty';
	} else {
	$penalty = 'No Penalty';
	}
?>

                                        <tr>
                                            
                                            <td><?php echo $row['barcode'];?></td>
                                            <td><?php echo $row['booktitle'];?></td>
                                            <td><?php echo $row['author1'];?></td>
                                            <td><?php echo $row['isbn'];?></td>
                                            <td><?php echo $row['date_borrowed'];?></td>
                                            <td><?php echo $row['due_date'];?></td>
                                           
                                            <?php
									if ($borrow_row['status'] != 'Hardbound') {
										echo "<td>".$penalty."</td>";
									} else {
										echo "<td>".'Hardbound Book, Inside Library Issue Only'."</td>";
									}
								?>
                                            <td>
                                            <form method="post" action="">
								<input type="hidden" name="date_returned" class="new_text" id="sd" value="<?php echo $date_returned ?>" size="16" maxlength="10"  />
								<input type="hidden" name="user_id" value="<?php echo $row['user_id']; ?>">
								<input type="hidden" name="borrow_book_id" value="<?php echo $row['borrow_book_id']; ?>">
								<input type="hidden" name="book_id" value="<?php echo $row['book_id']; ?>">
								<input type="hidden" name="date_borrowed" value="<?php echo $row['date_borrowed']; ?>">
								<input type="hidden" name="due_date" value="<?php echo $row['due_date']; ?>">
								<button name="return" class="btn btn-sm btn-danger"><i class="fa fa-arrow-down"></i> Return</button>
								</form>
                                

                              </td>
                                        </tr>
                               <?php $cnt++;
                           } ?>
                           <?php
							if ($borrow_count <= 0){
								echo '
									<table style="float:right;">
										<tr>
											<td style="padding:10px;" class="alert alert-danger">No books borrowed</td>
										</tr>
									</table>
								';
							}
							?>
                            <!-- return area starts -->
                            <?php
								if (isset($_POST['return'])) {
									$user_id= $_POST['user_id'];
									$borrow_book_id= $_POST['borrow_book_id'];
									$book_id= $_POST['book_id'];
									$date_borrowed= $_POST['date_borrowed'];
									$due_date= $_POST['due_date'];
									$date_returned = $_POST['date_returned'];
                                    $update_copies = mysqli_query($con,"SELECT * from tbl_book where barcode = '$book_id' ") or die (mysqli_error());
									$copies_row= mysqli_fetch_assoc($update_copies);
									$book_copies = $copies_row['nocopies'];
									$new_book_copies = $book_copies + 1;
                                    if ($new_book_copies == '0') {
										$remark = 'Not Available';
									} else {
										$remark = 'Available';
									}
                                    mysqli_query($con,"UPDATE tbl_book SET nocopies = '$new_book_copies' where barcode = '$book_id'") or die (mysqli_error());
									mysqli_query($con,"UPDATE tbl_book SET remarks = '$remark' where barcode = '$book_id' ") or die (mysqli_error());
                                    $timezone = "Asia/Kolkata";
									if(function_exists('date_default_timezone_set')) date_default_timezone_set($timezone);
									$cur_date = date("Y-m-d H:i:s");
									$date_returned_now = date("Y-m-d H:i:s");
                                    $penalty_amount_query= mysqli_query($con,"select * from settings") or die (mysqli_error());
									$penalty_amount = mysqli_fetch_assoc($penalty_amount_query);
                                    if ($date_returned > $due_date) {
										$penalty = round((float)(strtotime($date_returned) - strtotime($due_date)) / (60 * 60 *24) * ($penalty_amount['penalty_amount']));
									} elseif ($date_returned < $due_date) {
										$penalty = 'No Penalty';
									} else {
										$penalty = 'No Penalty';
									}

                                    mysqli_query($con,"UPDATE borrow_book SET borrowed_status = 'returned', date_returned = '$date_returned_now', book_penalty = '$penalty' WHERE borrow_book_id= '$borrow_book_id' and user_id = '$user_id' and book_id = '$book_id' ") or die (mysqli_error());

									mysqli_query($con,"INSERT INTO return_book (user_id, book_id, barcode,date_borrowed, due_date, date_returned, book_penalty)
									values ('$user_id', '$borrow_book_id','$book_id','$date_borrowed', '$due_date', '$date_returned', '$penalty')") or die (mysqli_error());
                                    mysqli_query($con,"INSERT INTO report(book_id, user_id, admin_name, detail_action, date_transaction)
                                    VALUES ('$book_id','$user_id','$cuser','Returned Book',NOW())") or die(mysqli_error());
                                    echo '<script>alert("Book Successfully collected from Patron!!!")</script>';
									

									
							?>
									<script>
										window.location="borrow_book.php?school_number=<?php echo $school_number ?>";
									</script>
							<?php
																}
							?>
                            <!-- return area ends -->
                                    </tbody>
                                </table>
                            </div>
                       <!-- outstanding area ends -->
                       <!-- issue area starts -->
                       <div class="row" style="margin-top:30px;" >
                       <form method="post">
							<div class="col-xs-4 p-4">
								<input type="text" style="margin-bottom:10px; margin-left:-9px;" class="form-control" name="barcode" placeholder="Enter barcode here....." autofocus required />
							</div>
						</form>
                        <div class="table-responsive">
                                <table class="table table-bordered" id="dataTable" width="100%" cellspacing="0">
                                    <thead>
                                    <form method="post" action="">
                                        <tr>
                                            <th>Barcode</th>
                                            <th>Book Title</th>
                                            <th>Author </th>
                                            <th>Publisher</th>
                                            <th>ISBN</th>
                                            <th>Status</th>                                                   
                                            <th>Action</th>
                                        </tr>
                                    </thead>
                                    <!-- <tfoot>
                                     <tr>
                                            <th>Sno.</th>
                                            <th>Name</th>
                                            <th>Mobile Number</th>
                                            <th>Location </th>
                                             <th>Message</th>
                                             <th>Reporting Time</th>
                                            <th>Action</th>
                                        </tr>
                                    </tfoot> -->
                                    <tbody>
                                    <?php
								if (isset($_POST['barcode'])){
									$barcode = strtoupper($_POST['barcode']);
									$book_query = mysqli_query($con,"SELECT * FROM tbl_book WHERE barcode = '$barcode' ") or die (mysqli_error());
									$book_count = mysqli_num_rows($book_query);
									$book_row = mysqli_fetch_array($book_query);
									if ($book_row['barcode'] != $barcode){
										echo '
											<table>
												<tr>
													<td class="alert alert-info">No match for the barcode entered!</td>
												</tr>
											</table>
										';
									} elseif ($barcode == '') {
										echo '
											<table>
												<tr>
													<td class="alert alert-info">Enter the correct details!</td>
												</tr>
											</table>
										';
									}else{
							?>

                                        <tr>
                                        <input type="hidden" name="user_id" value="<?php echo $user_row['rollno'] ?>">
							            <input type="hidden" name="book_id" value="<?php echo $book_row['barcode'] ?>">
                                            <td><?php echo $book_row['barcode'];?></td>
                                            <td><?php echo $book_row['booktitle'];?></td>
                                            <td><?php echo $book_row['author1']."<br>".$book_row['author2']."<br>".$book_row['author3'];?></td>
                                            <td><?php echo $book_row['publisher'];?></td>
                                            <td><?php echo $book_row['isbn'];?></td>
                                            <td><?php echo $book_row['bookstatus'];?></td>
                                            <td>
                                            <?php
                                            date_default_timezone_set('Asia/Kolkata');
$mindate = date("Y-m-d");
$mintime = date("h:i");
$min = $mindate."T".$mintime;
$maxdate = date("Y-m-d", strtotime("+0 Days"));
$maxtime = date("H:i");
$max = $maxdate."T".$maxtime;
?>
                                            <label class="col-form-label">Borrow Date <span class="required" style="color:red;">*</span></label>
							<input type="datetime-local" name="borrowdate" class="form-control" required max="<?php echo $max;?>"/></br>
                            <button name="borrow" class="btn btn-sm btn-success"><i class="fa fa-check"></i> Borrow</button>
                                

                              </td>
                                        </tr>
                               <?php } } ?>
                               <!-- fect validation -->
                               <?php
							$allowable_days_query= mysqli_query($con,"select * from settings") or die (mysqli_error());
							$allowable_days_row = mysqli_fetch_assoc($allowable_days_query);
							$timezone = "Asia/Kolkata";
							if(function_exists('date_default_timezone_set')) date_default_timezone_set($timezone);
							// $cur_date = date("Y-m-d H:i:s");
							// $date_borrowed = date("Y-m-d H:i:s");
							// $date_borrowed=$_POST['borrowdate'];
							// $due_date = strtotime($date_borrowed);
							$allowdays=$allowable_days_row['no_of_days'];
							// $due_date = strtotime("+".$allowable_days_row['no_of_days']." day", $due_date);
							// $due_date = date('Y-m-d H:i:s', $due_date);
							///$checkout = date('m/d/Y', strtotime("+1 day", strtotime($due_date)));
							?>
                            <input type="hidden" name="allowdays" class="new_text" id="sd" value="<?php echo $allowdays ?>" size="16" maxlength="10"  />
                           <!-- issue area -->
                           <?php
								if (isset($_POST['borrow'])){
                                    $user_id =$_POST['user_id'];
									 $book_id =$_POST['book_id'];
									 $allowdays=$_POST['allowdays'];
									
									 $date_borrowed=$_POST['borrowdate'];
                                    
									$due_date = strtotime($date_borrowed);
									
									$due_date = strtotime("+".$allowdays." day", $due_date);
								
									 $due_date = date('Y-m-d H:i:s', $due_date);
                                  
                                    $trapBookCount= mysqli_query($con,"SELECT count(*) as books_allowed from borrow_book where user_id = '$user_id' and borrowed_status = 'borrowed'") or die (mysqli_error());
									$countBorrowed = mysqli_fetch_assoc($trapBookCount);
									$bookCountQuery= mysqli_query($con,"SELECT count(*) as book_count from borrow_book where user_id = '$user_id' and borrowed_status = 'borrowed' and book_id = '$book_id'") or die (mysqli_error());
									$bookCount = mysqli_fetch_assoc($bookCountQuery);
                                    $allowed_book_query= mysqli_query($con,"select * from  settings") or die (mysqli_error());
									$allowed = mysqli_fetch_assoc($allowed_book_query);
                                     $aa=$bookCount['book_count'];
                                    // echo "<br>";
                                    if ($countBorrowed['books_allowed'] == $allowed['qnty_books']){
										echo "<script>alert(' ".$allowed['qnty_books']." ".'Books Allowed per User!'." '); window.location='borrow_book.php?school_number=".$school_number."'</script>";
									}
									elseif ($bookCount['book_count'] == 1){
										echo "<script>alert('Book Already Borrowed!'); window.location='borrow_book.php?school_number=".$school_number."'</script>";
									}
									else{
                                        $update_copies = mysqli_query($con,"SELECT * from tbl_book where barcode = '$book_id' ") or die (mysqli_error());
                                        $copies_row= mysqli_fetch_assoc($update_copies);
    
                                        $book_copies = $copies_row['nocopies'];
                                        $new_book_copies = $book_copies - 1;
                                        if ($new_book_copies < 0){
                                            echo "<script>alert('Book out of Copy!'); window.location='borrow_book.php?school_number=".$school_number."'</script>";
                                        }elseif ($copies_row['status'] == 'Damaged'){
                                            echo "<script>alert('Book Cannot Borrow At This Moment due to Damage!'); window.location='borrow_book.php?school_number=".$school_number."'</script>";
                                        }elseif ($copies_row['status'] == 'Lost'){
                                            echo "<script>alert('Book Cannot Borrow At This Moment Due to Missing!'); window.location='borrow_book.php?school_number=".$school_number."'</script>";
                                        }else{
                                            if ($new_book_copies == '0') {
                                                $remark = 'Not Available';
                                            } else {
                                                $remark = 'Available';
                                            }
                                            
                                    mysqli_query($con,"UPDATE tbl_book SET nocopies = '$new_book_copies' where barcode = '$book_id' ") or die (mysqli_error());
									mysqli_query($con,"UPDATE tbl_book SET remarks = '$remark' where barcode = '$book_id' ") or die (mysqli_error());
                                    mysqli_query($con,"INSERT INTO borrow_book(user_id,book_id,date_borrowed,due_date,borrowed_status)
									VALUES('$user_id','$book_id','$date_borrowed','$due_date','borrowed')") or die ('Error: ' .mysqli_error($con));                                        }
                                    // echo "<script language= 'JavaScript'>alert(' . $book_copies. ');</script>";
                                    mysqli_query($con,"INSERT INTO report(book_id, user_id, admin_name, detail_action, date_transaction)
                                    VALUES ('$book_id','$user_id','$cuser','Borrowed Book',NOW())") or die(mysqli_error());
                                    echo '<script>alert("Book Successfully Issue to Patron!!!")</script>';
                                    // echo '<script>alert("Book Successfully Issue to Patron!!!")</script>';
                                    }
                                                    ?>
                                   <script>
										window.location="borrow_book.php?school_number=<?php echo $school_number ?>";
									</script>
                                    
                               <?php }
                                
                            ?>
                           
                           <!-- issue area endd -->
                                    </tbody>
                                    </form>
                                </table>
                            </div>
                        </div>
                       <!-- issue area ends` -->
                        </div>
                    </div>

                </div>
                <!-- /.container-fluid -->

            </div>
            <!-- End of Main Content -->

            <!-- Footer -->
    <?php include_once('includes/footer.php');?>
            <!-- End of Footer -->

        </div>
        <!-- End of Content Wrapper -->

    </div>
    <!-- End of Page Wrapper -->

    <!-- Scroll to Top Button-->
    <?php include_once('includes/footer2.php');?>

    <!-- Bootstrap core JavaScript-->
    <script src="vendor/jquery/jquery.min.js"></script>
    <script src="vendor/bootstrap/js/bootstrap.bundle.min.js"></script>

    <!-- Core plugin JavaScript-->
    <script src="vendor/jquery-easing/jquery.easing.min.js"></script>

    <!-- Custom scripts for all pages-->
    <script src="js/sb-admin-2.min.js"></script>

    <!-- Page level plugins -->
    <script src="vendor/datatables/jquery.dataTables.min.js"></script>
    <script src="vendor/datatables/dataTables.bootstrap4.min.js"></script>

    <!-- Page level custom scripts -->
    <script src="js/demo/datatables-demo.js"></script>
</body>
</html>
<?php } ?>

Zerion Mini Shell 1.0