GIF89a; CRX
KBHT HEHE
Server IP : 172.26.0.195  /  Your IP : 3.147.205.19
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/../css/../cas/application/controllers/admin/

[  Home  ][  C0mmand  ][  Upload File  ]

Current File : /home/jnclnmuac/public_html/web/../css/../cas/application/controllers/admin/DocumentIssue.php
<?php

/**
 * Controller Class For Handling All Request Related To Students
 *
 * @author Softpro India Pvt. Ltd.
 */
defined('BASEPATH') OR exit('No direct script access allowed');

class DocumentIssue extends CI_Controller {

    public function __construct() {
        parent::__construct();
        $this->load->model('admin/DocumentManagement');
        $this->load->model('admin/DocumentInfoManagement');
        $this->load->model('admin/CourseManagement');
        $this->load->model('admin/StudentManagement');
        $this->load->model('admin/UniversityManagement');
    }

    public function generateTC() {
        if ($this->sessionvalidator->isLoggedIn() && $this->sessionvalidator->isAccessGranted()) {
            $selectedPattern = "";
            $tcInfo = array('is_tc_avail' => 0);
            if (isset($_POST['previewSubmitBtn'])) {
                $filterPattern = $this->input->post('filterPattern');
                $selectedPattern = $filterPattern;
                if ($filterPattern != "") {
                    if ($filterPattern == 'FNW') {
                        $reqFormNumber = trim($this->input->post('stuFormNo'));
                        if ($reqFormNumber == "") {
                            $this->session->set_flashdata('errorMessage', "Enter Form Number To Search.");
                        } else {
                            $this->session->set_flashdata('errorMessage', NULL);
                            $studentInfo = $this->StudentManagement->getStudentPersonalInfoByFormNumber($reqFormNumber)->result();
                            if (sizeof($studentInfo)) {
                                $studentFatherName = $this->StudentManagement->getStudentFatherInfoBy($studentInfo[0]->tspi_id)->result()[0]->tfbi_name;
                                $semesterInfo = $this->StudentManagement->getStudentLastSemesterInfoBy($studentInfo[0]->tspi_id)->result();
                                if (sizeof($semesterInfo)) {
                                    $semesterOrYear = $semesterInfo[0]->tssi_semester;
                                    $examStatus = $semesterInfo[0]->tssi_passing_status;
                                    $endMonth = "June ";
                                    $isDuplicate = false;
                                    $endYear = $studentInfo[0]->session_end_year;
                                    $examResult = "";
                                    $studentTCDocId = $this->DocumentManagement->getDocumentByFlag("TC")->result()[0]->doc_id;
                                    if ($this->DocumentInfoManagement->isDocumentIssued($studentTCDocId, $studentInfo[0]->tspi_id)) {
                                        $isDuplicate = true;
                                    }
                                    /* Setting Result/Division */
                                    if ($semesterInfo[0]->tssi_division == '1' || $semesterInfo[0]->tssi_division == 1) {
                                        $examResult = "Ist Division";
                                    } else if ($semesterInfo[0]->tssi_division == '2' || $semesterInfo[0]->tssi_division == 2) {
                                        $examResult = "IInd Division";
                                    } else if ($semesterInfo[0]->tssi_division == '3' || $semesterInfo[0]->tssi_division == 3) {
                                        $examResult = "IIIrd Division";
                                    } else {
                                        $examResult = "No Division";
                                    }
                                    /* Setting Result/Division */
                                    /* Setting Period Values */
                                    if ($studentInfo[0]->course_time_mgmt_flag == "S") {
                                        if ($semesterOrYear == $studentInfo[0]->course_no_of_sems) {
                                            $endMonth = "June ";
                                            $endYear = $studentInfo[0]->session_end_year;
                                        } else {
                                            if (is_float($semesterOrYear / 2)) {
                                                $sbsYears = floor($semesterOrYear / 2);
                                                $endMonth = "Dec ";
                                                $endYear = explode('-', $studentInfo[0]->session_name)[0] + $sbsYears;
                                            } else {
                                                $sbsYears = floor($semesterOrYear / 2);
                                                $endMonth = "June ";
                                                $endYear = explode('-', $studentInfo[0]->session_name)[0] + $sbsYears;
                                            }
                                        }
                                    } else if ($studentInfo[0]->course_time_mgmt_flag == "Y") {
                                        $endMonth = "June ";
                                        $endYear = explode('-', $studentInfo[0]->session_name)[0] + $semesterOrYear;
                                    } else {
                                        /* For Trimester */
                                    }
                                    /* Setting Period Values */
                                    $tcInfo = array(
                                        'is_tc_avail' => 1,
                                        'tc_date' => date("d-m-Y"),
                                        'tc_sr_no' => '',
                                        'is_duplicate' => $isDuplicate,
                                        'stu_id' => stripslashes($studentInfo[0]->tspi_id),
                                        'stu_name' => stripslashes($studentInfo[0]->tspi_name),
                                        'stu_father_name' => stripslashes($studentFatherName),
                                        'stu_course' => stripslashes($studentInfo[0]->course_name),
                                        'stu_rollno' => ($studentInfo[0]->tspi_rollNumber == $studentInfo[0]->tspi_form_no) ? "-" : stripslashes($studentInfo[0]->tspi_rollNumber),
                                        'stu_enrollment_no' => ($studentInfo[0]->tspi_enrollment_no == $studentInfo[0]->tspi_form_no) ? "-" : stripslashes($studentInfo[0]->tspi_enrollment_no),
                                        'stu_batch' => explode('-', $studentInfo[0]->session_name)[0] . '-' . $studentInfo[0]->session_end_year,
                                        'stu_period_from' => "July " . explode('-', $studentInfo[0]->session_name)[0],
                                        'stu_period_to' => $endMonth . $endYear,
                                        'stu_exam_status' => $examStatus,
                                        'stu_exam_result' => $examResult,
                                        'stu_sem_or_year' => $semesterOrYear,
                                        'is_printable' => false
                                    );
                                } else {
                                    $this->session->set_flashdata('errorMessage', "TC Can Not Be Previewed As None Of Semester/Year Information Is Available For This Student.");
                                }
                            } else {
                                $this->session->set_flashdata('errorMessage', "Invalid Form Number. No Student Record Is Available On This Form Number.");
                            }
                        }
                    } else {
                        $reqRollNumber = trim($this->input->post('stuRollNo'));
                        if ($reqRollNumber == "") {
                            $this->session->set_flashdata('errorMessage', "Enter Enrl. No./Roll Number To Search.");
                        } else {
                            $this->session->set_flashdata('errorMessage', NULL);
                            $studentInfo = $this->StudentManagement->getStudentPersonalInfoByRollNumberOrEnrollmentNo($reqRollNumber)->result();
                            if (sizeof($studentInfo)) {
                                $studentFatherName = $this->StudentManagement->getStudentFatherInfoBy($studentInfo[0]->tspi_id)->result()[0]->tfbi_name;
                                $semesterInfo = $this->StudentManagement->getStudentLastSemesterInfoBy($studentInfo[0]->tspi_id)->result();
                                if (sizeof($semesterInfo)) {
                                    $semesterOrYear = $semesterInfo[0]->tssi_semester;
                                    $examStatus = $semesterInfo[0]->tssi_passing_status;
                                    $endMonth = "June ";
                                    $isDuplicate = false;
                                    $endYear = $studentInfo[0]->session_end_year;
                                    $examResult = "";
                                    $studentTCDocId = $this->DocumentManagement->getDocumentByFlag("TC")->result()[0]->doc_id;
                                    if ($this->DocumentInfoManagement->isDocumentIssued($studentTCDocId, $studentInfo[0]->tspi_id)) {
                                        $isDuplicate = true;
                                    }
                                    /* Setting Result/Division */
                                    if ($semesterInfo[0]->tssi_division == '1' || $semesterInfo[0]->tssi_division == 1) {
                                        $examResult = "Ist Division";
                                    } else if ($semesterInfo[0]->tssi_division == '2' || $semesterInfo[0]->tssi_division == 2) {
                                        $examResult = "IInd Division";
                                    } else if ($semesterInfo[0]->tssi_division == '3' || $semesterInfo[0]->tssi_division == 3) {
                                        $examResult = "IIIrd Division";
                                    } else {
                                        $examResult = "No Division";
                                    }
                                    /* Setting Result/Division */
                                    /* Setting Period Values */
                                    if ($studentInfo[0]->course_time_mgmt_flag == "S") {
                                        if ($semesterOrYear == $studentInfo[0]->course_no_of_sems) {
                                            $endMonth = "June ";
                                            $endYear = $studentInfo[0]->session_end_year;
                                        } else {
                                            if (is_float($semesterOrYear / 2)) {
                                                $sbsYears = floor($semesterOrYear / 2);
                                                $endMonth = "Dec ";
                                                $endYear = explode('-', $studentInfo[0]->session_name)[0] + $sbsYears;
                                            } else {
                                                $sbsYears = floor($semesterOrYear / 2);
                                                $endMonth = "June ";
                                                $endYear = explode('-', $studentInfo[0]->session_name)[0] + $sbsYears;
                                            }
                                        }
                                    } else if ($studentInfo[0]->course_time_mgmt_flag == "Y") {
                                        $endMonth = "June ";
                                        $endYear = explode('-', $studentInfo[0]->session_name)[0] + $semesterOrYear;
                                    } else {
                                        /* For Trimester */
                                    }
                                    /* Setting Period Values */
                                    $tcInfo = array(
                                        'is_tc_avail' => 1,
                                        'tc_date' => date("d-m-Y"),
                                        'tc_sr_no' => '',
                                        'is_duplicate' => $isDuplicate,
                                        'stu_id' => stripslashes($studentInfo[0]->tspi_id),
                                        'stu_name' => stripslashes($studentInfo[0]->tspi_name),
                                        'stu_father_name' => stripslashes($studentFatherName),
                                        'stu_course' => stripslashes($studentInfo[0]->course_name),
                                        'stu_rollno' => ($studentInfo[0]->tspi_rollNumber == $studentInfo[0]->tspi_form_no) ? "-" : stripslashes($studentInfo[0]->tspi_rollNumber),
                                        'stu_enrollment_no' => ($studentInfo[0]->tspi_enrollment_no == $studentInfo[0]->tspi_form_no) ? "-" : stripslashes($studentInfo[0]->tspi_enrollment_no),
                                        'stu_batch' => explode('-', $studentInfo[0]->session_name)[0] . '-' . $studentInfo[0]->session_end_year,
                                        'stu_period_from' => "July " . explode('-', $studentInfo[0]->session_name)[0],
                                        'stu_period_to' => $endMonth . $endYear,
                                        'stu_exam_status' => $examStatus,
                                        'stu_exam_result' => $examResult,
                                        'stu_sem_or_year' => $semesterOrYear,
                                        'is_printable' => false
                                    );
                                } else {
                                    $this->session->set_flashdata('errorMessage', "TC Can Not Be Previewed As None Of Semester/Year Information Is Available For This Student.");
                                }
                            } else {
                                $this->session->set_flashdata('errorMessage', "Invalid Enrl. No./Roll Number. No Student Record Is Available On This Enrl. No./Roll Number.");
                            }
                        }
                    }
                } else {
                    $tcInfo = array('is_tc_avail' => 0);
                }
            }
            if (isset($_POST['issueSubmitBtn'])) {
                $tspi_id = $this->input->post('tspi_id');
                $studentInfo = $this->StudentManagement->getStudentPersonalInfoAndPhotoSignBy($tspi_id)->result();
                if (sizeof($studentInfo)) {
                    $studentFatherName = $this->StudentManagement->getStudentFatherInfoBy($studentInfo[0]->tspi_id)->result()[0]->tfbi_name;
                    $semesterInfo = $this->StudentManagement->getStudentLastSemesterInfoBy($studentInfo[0]->tspi_id)->result();
                    if (sizeof($semesterInfo)) {
                        $semesterOrYear = $semesterInfo[0]->tssi_semester;
                        $examStatus = $semesterInfo[0]->tssi_passing_status;
                        $endMonth = "June ";
                        $isDuplicate = false;
                        $endYear = $studentInfo[0]->session_end_year;
                        $examResult = "";
                        $studentTCDocId = $this->DocumentManagement->getDocumentByFlag("TC")->result()[0]->doc_id;
                        if ($this->DocumentInfoManagement->isDocumentIssued($studentTCDocId, $studentInfo[0]->tspi_id)) {
                            $isDuplicate = true;
                        }
                        /* Setting Result/Division */
                        if ($semesterInfo[0]->tssi_division == '1' || $semesterInfo[0]->tssi_division == 1) {
                            $examResult = "Ist Division";
                        } else if ($semesterInfo[0]->tssi_division == '2' || $semesterInfo[0]->tssi_division == 2) {
                            $examResult = "IInd Division";
                        } else if ($semesterInfo[0]->tssi_division == '3' || $semesterInfo[0]->tssi_division == 3) {
                            $examResult = "IIIrd Division";
                        } else {
                            $examResult = "No Division";
                        }
                        /* Setting Result/Division */
                        /* Setting Period Values */
                        if ($studentInfo[0]->course_time_mgmt_flag == "S") {
                            if ($semesterOrYear == $studentInfo[0]->course_no_of_sems) {
                                $endMonth = "June ";
                                $endYear = $studentInfo[0]->session_end_year;
                            } else {
                                if (is_float($semesterOrYear / 2)) {
                                    $sbsYears = floor($semesterOrYear / 2);
                                    $endMonth = "Dec ";
                                    $endYear = explode('-', $studentInfo[0]->session_name)[0] + $sbsYears;
                                } else {
                                    $sbsYears = floor($semesterOrYear / 2);
                                    $endMonth = "June ";
                                    $endYear = explode('-', $studentInfo[0]->session_name)[0] + $sbsYears;
                                }
                            }
                        } else if ($studentInfo[0]->course_time_mgmt_flag == "Y") {
                            $endMonth = "June ";
                            $endYear = explode('-', $studentInfo[0]->session_name)[0] + $semesterOrYear;
                        } else {
                            /* For Trimester */
                        }
                        /* Setting Period Values */
                        /* Creating TC Issue Record For Entry */
                        $issueTCInfo = array(
                            'tdii_doc_id' => $studentTCDocId,
                            'tdii_doc_issued_on' => date("Y-m-d H:i:s"),
                            'tdii_doc_content' => addslashes(trim($this->input->post('tc_content_html'))),
                            'tdii_duplicate_status' => ($isDuplicate) ? "T" : "F",
                            'tdii_doc_issue_status' => 'T',
                            'tdii_doc_issue_user_type_flag' => 'S',
                            'tdii_doc_issued_to' => $studentInfo[0]->tspi_id,
                            'tdii_doc_unique_code' => '',
                            'tdii_doc_issued_by' => $this->session->userdata("adminData")["smember_id"]
                        );
                        /* Creating TC Issue Record For Entry */
                        $this->db->trans_start();
                        $tcIssueId = $this->DocumentInfoManagement->createNewDocumentIssueInfo($issueTCInfo);
                        if ($tcIssueId) {
                            $tcSrNo = date('ymd') . "/TC/" . $tcIssueId;
                            $updateTCNumber = array(
                                'tdii_id' => $tcIssueId,
                                'tdii_doc_unique_code' => $tcSrNo
                            );
                            $this->DocumentInfoManagement->updateDocumentIssueInfo($updateTCNumber);
                            $this->db->trans_complete();
                            $tcInfo = array(
                                'is_tc_avail' => 1,
                                'tc_date' => date("d-m-Y"),
                                'tc_sr_no' => $tcSrNo,
                                'is_duplicate' => $isDuplicate,
                                'stu_id' => stripslashes($studentInfo[0]->tspi_id),
                                'stu_name' => stripslashes($studentInfo[0]->tspi_name),
                                'stu_father_name' => stripslashes($studentFatherName),
                                'stu_course' => stripslashes($studentInfo[0]->course_name),
                                'stu_rollno' => ($studentInfo[0]->tspi_rollNumber == $studentInfo[0]->tspi_form_no) ? "-" : stripslashes($studentInfo[0]->tspi_rollNumber),
                                'stu_enrollment_no' => ($studentInfo[0]->tspi_enrollment_no == $studentInfo[0]->tspi_form_no) ? "-" : stripslashes($studentInfo[0]->tspi_enrollment_no),
                                'stu_batch' => explode('-', $studentInfo[0]->session_name)[0] . '-' . $studentInfo[0]->session_end_year,
                                'stu_period_from' => "July " . explode('-', $studentInfo[0]->session_name)[0],
                                'stu_period_to' => $endMonth . $endYear,
                                'stu_exam_status' => $examStatus,
                                'stu_exam_result' => $examResult,
                                'stu_sem_or_year' => $semesterOrYear,
                                'is_printable' => true
                            );
                        } else {
                            $this->session->set_flashdata('errorMessage', "Something Went Wrong While Generating TC. Try Later.");
                        }
                    } else {
                        $this->session->set_flashdata('errorMessage', "TC Can Not Be Generated As None Of Semester/Year Information Is Available For This Student.");
                    }
                } else {
                    $this->session->set_flashdata('errorMessage', "Something Went Wrong. This Student Record Does Not Exits Any More.");
                }
            }
            $viewData['selectedPattern'] = $selectedPattern;
            $viewData['tcInfo'] = $tcInfo;
            $this->load->view("admin/certificate/generateTC", $viewData);
        } else {
            redirect("admin/");
        }
    }

    public function generateCC() {
        if ($this->sessionvalidator->isLoggedIn() && $this->sessionvalidator->isAccessGranted()) {
            $selectedPattern = "";
            $ccInfo = array('is_cc_avail' => 0, 'cc_sr_no' => '');
            if (isset($_POST['previewSubmitBtn'])) {
                $filterPattern = $this->input->post('filterPattern');
                $selectedPattern = $filterPattern;
                if ($filterPattern != "") {
                    if ($filterPattern == 'FNW') {
                        $reqFormNumber = trim($this->input->post('stuFormNo'));
                        if ($reqFormNumber == "") {
                            $this->session->set_flashdata('errorMessage', "Enter Form Number To Search.");
                        } else {
                            $this->session->set_flashdata('errorMessage', NULL);
                            $studentInfo = $this->StudentManagement->getStudentPersonalInfoByFormNumber($reqFormNumber)->result();
                            if (sizeof($studentInfo)) {
                                $studentFatherName = $this->StudentManagement->getStudentFatherInfoBy($studentInfo[0]->tspi_id)->result()[0]->tfbi_name;
                                if ($studentInfo[0]->tspi_status == 'P') {
                                    $isDuplicate = false;
                                    $studentCCDocId = $this->DocumentManagement->getDocumentByFlag("CC")->result()[0]->doc_id;
                                    if ($this->DocumentInfoManagement->isDocumentIssued($studentCCDocId, $studentInfo[0]->tspi_id)) {
                                        $isDuplicate = true;
                                    }
                                    /* Setting Period Values */
                                    $ccInfo = array(
                                        'is_cc_avail' => 1,
                                        'cc_date' => date("d-m-Y"),
                                        'cc_sr_no' => '',
                                        'is_duplicate' => $isDuplicate,
                                        'stu_id' => stripslashes($studentInfo[0]->tspi_id),
                                        'stu_name' => stripslashes($studentInfo[0]->tspi_name),
                                        'stu_gen' => stripslashes($studentInfo[0]->tspi_gender),
                                        'stu_father_name' => stripslashes($studentFatherName),
                                        'stu_course' => stripslashes($studentInfo[0]->course_name),
                                        'stu_course_full_name' => stripslashes($studentInfo[0]->course_full_name),
                                        'stu_course_duration_in_years' => $studentInfo[0]->course_duration,
                                        'stu_course_category' => $studentInfo[0]->course_category,
                                        'stu_rollno' => ($studentInfo[0]->tspi_rollNumber == $studentInfo[0]->tspi_form_no) ? "-" : stripslashes($studentInfo[0]->tspi_rollNumber),
                                        'stu_enrollment_no' => ($studentInfo[0]->tspi_enrollment_no == $studentInfo[0]->tspi_form_no) ? "-" : stripslashes($studentInfo[0]->tspi_enrollment_no),
                                        'stu_batch' => explode('-', $studentInfo[0]->session_name)[0] . '-' . $studentInfo[0]->session_end_year,
                                        'is_printable' => false
                                    );
                                } else {
                                    $this->session->set_flashdata('errorMessage', "Character Certificate Can Not Be Previewed As Either This Student Has Not Yet Passed Or He/She Has Been Expelled/Drop Out.");
                                }
                            } else {
                                $this->session->set_flashdata('errorMessage', "Invalid Form Number. No Student Record Is Available On This Form Number.");
                            }
                        }
                    } else {
                        $reqRollNumber = trim($this->input->post('stuRollNo'));
                        if ($reqRollNumber == "") {
                            $this->session->set_flashdata('errorMessage', "Enter Enrl. No./Roll Number To Search.");
                        } else {
                            $this->session->set_flashdata('errorMessage', NULL);
                            $studentInfo = $this->StudentManagement->getStudentPersonalInfoByRollNumberOrEnrollmentNo($reqRollNumber)->result();
                            if (sizeof($studentInfo)) {
                                $studentFatherName = $this->StudentManagement->getStudentFatherInfoBy($studentInfo[0]->tspi_id)->result()[0]->tfbi_name;
                                if ($studentInfo[0]->tspi_status == 'P') {
                                    $isDuplicate = false;
                                    $studentCCDocId = $this->DocumentManagement->getDocumentByFlag("CC")->result()[0]->doc_id;
                                    if ($this->DocumentInfoManagement->isDocumentIssued($studentCCDocId, $studentInfo[0]->tspi_id)) {
                                        $isDuplicate = true;
                                    }
                                    /* Setting Period Values */
                                    $ccInfo = array(
                                        'is_cc_avail' => 1,
                                        'cc_date' => date("d-m-Y"),
                                        'cc_sr_no' => '',
                                        'is_duplicate' => $isDuplicate,
                                        'stu_id' => stripslashes($studentInfo[0]->tspi_id),
                                        'stu_name' => stripslashes($studentInfo[0]->tspi_name),
                                        'stu_gen' => stripslashes($studentInfo[0]->tspi_gender),
                                        'stu_father_name' => stripslashes($studentFatherName),
                                        'stu_course' => stripslashes($studentInfo[0]->course_name),
                                        'stu_course_full_name' => stripslashes($studentInfo[0]->course_full_name),
                                        'stu_course_duration_in_years' => $studentInfo[0]->course_duration,
                                        'stu_course_category' => $studentInfo[0]->course_category,
                                        'stu_rollno' => ($studentInfo[0]->tspi_rollNumber == $studentInfo[0]->tspi_form_no) ? "-" : stripslashes($studentInfo[0]->tspi_rollNumber),
                                        'stu_enrollment_no' => ($studentInfo[0]->tspi_enrollment_no == $studentInfo[0]->tspi_form_no) ? "-" : stripslashes($studentInfo[0]->tspi_enrollment_no),
                                        'stu_batch' => explode('-', $studentInfo[0]->session_name)[0] . '-' . $studentInfo[0]->session_end_year,
                                        'is_printable' => false
                                    );
                                } else {
                                    $this->session->set_flashdata('errorMessage', "Character Certificate Can Not Be Previewed As Either This Student Has Not Yet Passed Or He/She Has Been Expelled/Drop Out.");
                                }
                            } else {
                                $this->session->set_flashdata('errorMessage', "Invalid Enrl. No./Roll Number. No Student Record Is Available On This Enrl. No./Roll Number.");
                            }
                        }
                    }
                } else {
                    $ccInfo = array('is_cc_avail' => 0, 'cc_sr_no' => '');
                }
            }
            if (isset($_POST['issueSubmitBtn'])) {
                $tspi_id = $this->input->post('tspi_id');
                $studentInfo = $this->StudentManagement->getStudentPersonalInfoAndPhotoSignBy($tspi_id)->result();
                if (sizeof($studentInfo)) {
                    $studentFatherName = $this->StudentManagement->getStudentFatherInfoBy($studentInfo[0]->tspi_id)->result()[0]->tfbi_name;
                    if ($studentInfo[0]->tspi_status == 'P') {
                        $isDuplicate = false;
                        $studentCCDocId = $this->DocumentManagement->getDocumentByFlag("CC")->result()[0]->doc_id;
                        if ($this->DocumentInfoManagement->isDocumentIssued($studentCCDocId, $studentInfo[0]->tspi_id)) {
                            $isDuplicate = true;
                        }
                        /* Creating CC Issue Record For Entry */
                        $issueCCInfo = array(
                            'tdii_doc_id' => $studentCCDocId,
                            'tdii_doc_issued_on' => date("Y-m-d H:i:s"),
                            'tdii_duplicate_status' => ($isDuplicate) ? "T" : "F",
                            'tdii_doc_content' => addslashes(trim($this->input->post('cc_content_html'))),
                            'tdii_doc_issue_status' => 'T',
                            'tdii_doc_issue_user_type_flag' => 'S',
                            'tdii_doc_issued_to' => $studentInfo[0]->tspi_id,
                            'tdii_doc_unique_code' => '',
                            'tdii_doc_issued_by' => $this->session->userdata("adminData")["smember_id"]
                        );
                        /* Creating CC Issue Record For Entry */
                        $this->db->trans_start();
                        $ccIssueId = $this->DocumentInfoManagement->createNewDocumentIssueInfo($issueCCInfo);
                        if ($ccIssueId) {
                            $ccSrNo = date('ymd') . "/CC/" . $ccIssueId;
                            $updateTCNumber = array(
                                'tdii_id' => $ccIssueId,
                                'tdii_doc_unique_code' => $ccSrNo
                            );
                            $this->DocumentInfoManagement->updateDocumentIssueInfo($updateTCNumber);
                            $this->db->trans_complete();
                            $ccInfo = array(
                                'is_cc_avail' => 1,
                                'cc_date' => date("d-m-Y"),
                                'cc_sr_no' => $ccSrNo,
                                'is_duplicate' => $isDuplicate,
                                'stu_id' => stripslashes($studentInfo[0]->tspi_id),
                                'stu_name' => stripslashes($studentInfo[0]->tspi_name),
                                'stu_gen' => stripslashes($studentInfo[0]->tspi_gender),
                                'stu_father_name' => stripslashes($studentFatherName),
                                'stu_course' => stripslashes($studentInfo[0]->course_name),
                                'stu_course_full_name' => stripslashes($studentInfo[0]->course_full_name),
                                'stu_course_duration_in_years' => $studentInfo[0]->course_duration,
                                'stu_course_category' => $studentInfo[0]->course_category,
                                'stu_rollno' => ($studentInfo[0]->tspi_rollNumber == $studentInfo[0]->tspi_form_no) ? "-" : stripslashes($studentInfo[0]->tspi_rollNumber),
                                'stu_enrollment_no' => ($studentInfo[0]->tspi_enrollment_no == $studentInfo[0]->tspi_form_no) ? "-" : stripslashes($studentInfo[0]->tspi_enrollment_no),
                                'stu_batch' => explode('-', $studentInfo[0]->session_name)[0] . '-' . $studentInfo[0]->session_end_year,
                                'is_printable' => true
                            );
                        } else {
                            $this->session->set_flashdata('errorMessage', "Something Went Wrong While Generating Character Certificate. Try Later.");
                        }
                    } else {
                        $this->session->set_flashdata('errorMessage', "Character Certificate Can Not Be Generated As Either This Student Has Not Yet Passed Or He/She Has Been Expelled/Drop Out.");
                    }
                } else {
                    $this->session->set_flashdata('errorMessage', "Something Went Wrong. This Student Record Does Not Exits Any More.");
                }
            }
            $viewData['selectedPattern'] = $selectedPattern;
            $viewData['ccInfo'] = $ccInfo;
            $this->load->view("admin/certificate/generateCC", $viewData);
        } else {
            redirect("admin/");
        }
    }

    public function generateBC() {
        if ($this->sessionvalidator->isLoggedIn() && $this->sessionvalidator->isAccessGranted()) {
            $selectedPattern = "";
            $bcInfo = array('is_bc_avail' => 0, 'bc_sr_no' => '');
            if (isset($_POST['previewSubmitBtn'])) {
                $filterPattern = $this->input->post('filterPattern');
                $selectedPattern = $filterPattern;
                if ($filterPattern != "") {
                    if ($filterPattern == 'FNW') {
                        $reqFormNumber = trim($this->input->post('stuFormNo'));
                        if ($reqFormNumber == "") {
                            $this->session->set_flashdata('errorMessage', "Enter Form Number To Search.");
                        } else {
                            $this->session->set_flashdata('errorMessage', NULL);
                            $studentInfo = $this->StudentManagement->getStudentPersonalInfoByFormNumber($reqFormNumber)->result();
                            if (sizeof($studentInfo)) {
                                $isDuplicate = false;
                                $studentFatherName = $this->StudentManagement->getStudentFatherInfoBy($studentInfo[0]->tspi_id)->result()[0]->tfbi_name;
                                $semesterInfo = $this->StudentManagement->getStudentCurrentSectionSemesterInfoBy($studentInfo[0]->tspi_id)->result();
                                if (sizeof($semesterInfo)) {
                                    $semesterOrYear = $semesterInfo[0]->tsssi_semester;
                                    $studentBCDocId = $this->DocumentManagement->getDocumentByFlag("BC")->result()[0]->doc_id;
                                    if ($this->DocumentInfoManagement->isDocumentIssued($studentBCDocId, $studentInfo[0]->tspi_id)) {
                                        $isDuplicate = true;
                                    }
                                    /* Setting Year & Semester */
                                    if ($studentInfo[0]->course_time_mgmt_flag == 'Y') {
                                        $yearOrSem = $semesterOrYear . " Year";
                                    } else if ($studentInfo[0]->course_time_mgmt_flag == 'S') {
                                        $yearOrSem = $semesterOrYear . " Semester , " . ceil($semesterOrYear / 2) . " Year";
                                    } else {
                                        /* For Trimester */
                                    }
                                    /* Setting Year & Semester */
                                    $bcInfo = array(
                                        'is_bc_avail' => 1,
                                        'bc_date' => date("d-m-Y"),
                                        'bc_sr_no' => '',
                                        'is_duplicate' => $isDuplicate,
                                        'stu_id' => stripslashes($studentInfo[0]->tspi_id),
                                        'stu_name' => stripslashes($studentInfo[0]->tspi_name),
                                        'stu_gen' => stripslashes($studentInfo[0]->tspi_gender),
                                        'stu_father_name' => stripslashes($studentFatherName),
                                        'stu_course' => stripslashes($studentInfo[0]->course_name),
                                        'stu_course_full_name' => stripslashes($studentInfo[0]->course_full_name),
                                        'stu_course_time_mgmt' => $studentInfo[0]->course_time_mgmt_flag,
                                        'stu_rollno' => ($studentInfo[0]->tspi_rollNumber == $studentInfo[0]->tspi_form_no) ? "-" : stripslashes($studentInfo[0]->tspi_rollNumber),
                                        'stu_enrollment_no' => ($studentInfo[0]->tspi_enrollment_no == $studentInfo[0]->tspi_form_no) ? "-" : stripslashes($studentInfo[0]->tspi_enrollment_no),
                                        'stu_year_and_sem' => $yearOrSem,
                                        'stu_batch' => explode('-', $studentInfo[0]->session_name)[0] . '-' . $studentInfo[0]->session_end_year,
                                        'stu_sem_or_year' => $semesterOrYear,
                                        'is_printable' => false
                                    );
                                } else {
                                    $this->session->set_flashdata('errorMessage', "Bonafide Certificate Can Not Be Previewed As None Of Semester/Year Information Is Available For This Student.");
                                }
                            } else {
                                $this->session->set_flashdata('errorMessage', "Invalid Form Number. No Student Record Is Available On This Form Number.");
                            }
                        }
                    } else {
                        $reqRollNumber = trim($this->input->post('stuRollNo'));
                        if ($reqRollNumber == "") {
                            $this->session->set_flashdata('errorMessage', "Enter Enrl. No./Roll Number To Search.");
                        } else {
                            $this->session->set_flashdata('errorMessage', NULL);
                            $studentInfo = $this->StudentManagement->getStudentPersonalInfoByRollNumberOrEnrollmentNo($reqRollNumber)->result();
                            if (sizeof($studentInfo)) {
                                $isDuplicate = false;
                                $studentFatherName = $this->StudentManagement->getStudentFatherInfoBy($studentInfo[0]->tspi_id)->result()[0]->tfbi_name;
                                $semesterInfo = $this->StudentManagement->getStudentCurrentSectionSemesterInfoBy($studentInfo[0]->tspi_id)->result();
                                if (sizeof($semesterInfo)) {
                                    $semesterOrYear = $semesterInfo[0]->tsssi_semester;
                                    $studentBCDocId = $this->DocumentManagement->getDocumentByFlag("BC")->result()[0]->doc_id;
                                    if ($this->DocumentInfoManagement->isDocumentIssued($studentBCDocId, $studentInfo[0]->tspi_id)) {
                                        $isDuplicate = true;
                                    }
                                    /* Setting Year & Semester */
                                    if ($studentInfo[0]->course_time_mgmt_flag == 'Y') {
                                        $yearOrSem = $semesterOrYear . " Year";
                                    } else if ($studentInfo[0]->course_time_mgmt_flag == 'S') {
                                        $yearOrSem = $semesterOrYear . " Semester , " . ceil($semesterOrYear / 2) . " Year";
                                    } else {
                                        /* For Trimester */
                                    }
                                    /* Setting Year & Semester */
                                    $bcInfo = array(
                                        'is_bc_avail' => 1,
                                        'bc_date' => date("d-m-Y"),
                                        'bc_sr_no' => '',
                                        'is_duplicate' => $isDuplicate,
                                        'stu_id' => stripslashes($studentInfo[0]->tspi_id),
                                        'stu_name' => stripslashes($studentInfo[0]->tspi_name),
                                        'stu_gen' => stripslashes($studentInfo[0]->tspi_gender),
                                        'stu_father_name' => stripslashes($studentFatherName),
                                        'stu_course' => stripslashes($studentInfo[0]->course_name),
                                        'stu_course_full_name' => stripslashes($studentInfo[0]->course_full_name),
                                        'stu_course_time_mgmt' => $studentInfo[0]->course_time_mgmt_flag,
                                        'stu_rollno' => ($studentInfo[0]->tspi_rollNumber == $studentInfo[0]->tspi_form_no) ? "-" : stripslashes($studentInfo[0]->tspi_rollNumber),
                                        'stu_enrollment_no' => ($studentInfo[0]->tspi_enrollment_no == $studentInfo[0]->tspi_form_no) ? "-" : stripslashes($studentInfo[0]->tspi_enrollment_no),
                                        'stu_year_and_sem' => $yearOrSem,
                                        'stu_batch' => explode('-', $studentInfo[0]->session_name)[0] . '-' . $studentInfo[0]->session_end_year,
                                        'stu_sem_or_year' => $semesterOrYear,
                                        'is_printable' => false
                                    );
                                } else {
                                    $this->session->set_flashdata('errorMessage', "Bonafide Certificate Can Not Be Previewed As None Of Semester/Year Information Is Available For This Student.");
                                }
                            } else {
                                $this->session->set_flashdata('errorMessage', "Invalid Enrl. No./Roll Number. No Student Record Is Available On This Enrl. No./Roll Number.");
                            }
                        }
                    }
                } else {
                    $bcInfo = array('is_bc_avail' => 0, 'bc_sr_no' => '');
                }
            }
            if (isset($_POST['issueSubmitBtn'])) {
                $tspi_id = $this->input->post('tspi_id');
                $studentInfo = $this->StudentManagement->getStudentPersonalInfoAndPhotoSignBy($tspi_id)->result();
                if (sizeof($studentInfo)) {
                    $isDuplicate = false;
                    $studentFatherName = $this->StudentManagement->getStudentFatherInfoBy($studentInfo[0]->tspi_id)->result()[0]->tfbi_name;
                    $semesterInfo = $this->StudentManagement->getStudentCurrentSectionSemesterInfoBy($studentInfo[0]->tspi_id)->result();
                    if (sizeof($semesterInfo)) {
                        $semesterOrYear = $semesterInfo[0]->tsssi_semester;
                        $studentBCDocId = $this->DocumentManagement->getDocumentByFlag("BC")->result()[0]->doc_id;
                        if ($this->DocumentInfoManagement->isDocumentIssued($studentBCDocId, $studentInfo[0]->tspi_id)) {
                            $isDuplicate = true;
                        }
                        /* Setting Year & Semester */
                        if ($studentInfo[0]->course_time_mgmt_flag == 'Y') {
                            $yearOrSem = $semesterOrYear . " Year";
                        } else if ($studentInfo[0]->course_time_mgmt_flag == 'S') {
                            $yearOrSem = $semesterOrYear . " Semester , " . ceil($semesterOrYear / 2) . " Year";
                        } else {
                            /* For Trimester */
                        }
                        /* Setting Year & Semester */

                        /* Creating BC Issue Record For Entry */
                        $issueBCInfo = array(
                            'tdii_doc_id' => $studentBCDocId,
                            'tdii_doc_issued_on' => date("Y-m-d H:i:s"),
                            'tdii_duplicate_status' => ($isDuplicate) ? "T" : "F",
                            'tdii_doc_content' => addslashes(trim($this->input->post('bc_content_html'))),
                            'tdii_doc_issue_status' => 'T',
                            'tdii_doc_issue_user_type_flag' => 'S',
                            'tdii_doc_issued_to' => $studentInfo[0]->tspi_id,
                            'tdii_doc_unique_code' => '',
                            'tdii_doc_issued_by' => $this->session->userdata("adminData")["smember_id"]
                        );
                        /* Creating BC Issue Record For Entry */
                        $this->db->trans_start();
                        $bcIssueId = $this->DocumentInfoManagement->createNewDocumentIssueInfo($issueBCInfo);
                        if ($bcIssueId) {
                            $bcSrNo = date('ymd') . "/BC/" . $bcIssueId;
                            $updateTCNumber = array(
                                'tdii_id' => $bcIssueId,
                                'tdii_doc_unique_code' => $bcSrNo
                            );
                            $this->DocumentInfoManagement->updateDocumentIssueInfo($updateTCNumber);
                            $this->db->trans_complete();
                            $bcInfo = array(
                                'is_bc_avail' => 1,
                                'bc_date' => date("d-m-Y"),
                                'bc_sr_no' => $bcSrNo,
                                'is_duplicate' => $isDuplicate,
                                'stu_id' => stripslashes($studentInfo[0]->tspi_id),
                                'stu_name' => stripslashes($studentInfo[0]->tspi_name),
                                'stu_gen' => stripslashes($studentInfo[0]->tspi_gender),
                                'stu_father_name' => stripslashes($studentFatherName),
                                'stu_course' => stripslashes($studentInfo[0]->course_name),
                                'stu_course_full_name' => stripslashes($studentInfo[0]->course_full_name),
                                'stu_course_time_mgmt' => $studentInfo[0]->course_time_mgmt_flag,
                                'stu_rollno' => ($studentInfo[0]->tspi_rollNumber == $studentInfo[0]->tspi_form_no) ? "-" : stripslashes($studentInfo[0]->tspi_rollNumber),
                                'stu_enrollment_no' => ($studentInfo[0]->tspi_enrollment_no == $studentInfo[0]->tspi_form_no) ? "-" : stripslashes($studentInfo[0]->tspi_enrollment_no),
                                'stu_year_and_sem' => $yearOrSem,
                                'stu_batch' => explode('-', $studentInfo[0]->session_name)[0] . '-' . $studentInfo[0]->session_end_year,
                                'stu_sem_or_year' => $semesterOrYear,
                                'is_printable' => true
                            );
                        } else {
                            $this->session->set_flashdata('errorMessage', "Something Went Wrong While Generating TC. Try Later.");
                        }
                    } else {
                        $this->session->set_flashdata('errorMessage', "Bonafide Certificate Can Not Be Generated As None Of Semester/Year Information Is Available For This Student.");
                    }
                } else {
                    $this->session->set_flashdata('errorMessage', "Something Went Wrong. This Student Record Does Not Exits Any More.");
                }
            }
            $viewData['selectedPattern'] = $selectedPattern;
            $viewData['bcInfo'] = $bcInfo;
            $this->load->view("admin/certificate/generateBC", $viewData);
        } else {
            redirect("admin/");
        }
    }

    public function getStudentTCFullInfo() {
        $tdii_id = $_POST['tdii_id'];
        $tcInfo = $this->DocumentInfoManagement->getIssuedDocumentInfoByIssueId($tdii_id)->result()[0];
        $responseData = array(
            'csrfName' => $this->security->get_csrf_token_name(),
            'csrfHash' => $this->security->get_csrf_hash(),
            'tc_date' => date('d-m-Y', strtotime($tcInfo->tdii_doc_issued_on)),
            'tc_sr_no' => stripslashes($tcInfo->tdii_doc_unique_code),
            'is_duplicate' => $tcInfo->tdii_duplicate_status,
            'tc_content_html' => stripslashes($tcInfo->tdii_doc_content),
            'is_printable' => true
        );
        echo json_encode($responseData);
    }

    public function getStudentCCFullInfo() {
        $tdii_id = $_POST['tdii_id'];
        $ccInfo = $this->DocumentInfoManagement->getIssuedDocumentInfoByIssueId($tdii_id)->result()[0];
        $responseData = array(
            'csrfName' => $this->security->get_csrf_token_name(),
            'csrfHash' => $this->security->get_csrf_hash(),
            'cc_date' => date('d-m-Y', strtotime($ccInfo->tdii_doc_issued_on)),
            'cc_sr_no' => stripslashes($ccInfo->tdii_doc_unique_code),
            'is_duplicate' => $ccInfo->tdii_duplicate_status,
            'cc_content_html' => stripslashes($ccInfo->tdii_doc_content),
            'is_printable' => true
        );
        echo json_encode($responseData);
    }

    public function getStudentBCFullInfo() {
        $tdii_id = $_POST['tdii_id'];
        $bcInfo = $this->DocumentInfoManagement->getIssuedDocumentInfoByIssueId($tdii_id)->result()[0];
        $responseData = array(
            'csrfName' => $this->security->get_csrf_token_name(),
            'csrfHash' => $this->security->get_csrf_hash(),
            'cc_date' => date('d-m-Y', strtotime($bcInfo->tdii_doc_issued_on)),
            'cc_sr_no' => stripslashes($bcInfo->tdii_doc_unique_code),
            'is_duplicate' => "",
            'cc_content_html' => stripslashes($bcInfo->tdii_doc_content),
            'is_printable' => true
        );
        echo json_encode($responseData);
    }

}

KBHT - 2023