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

[  Home  ][  C0mmand  ][  Upload File  ]

Current File : /home/jnclnmuac/public_html/web/../admission/../cas/application/controllers/admin/Student.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 Student extends CI_Controller {

    public function __construct() {
        parent::__construct();
        $this->load->model('admin/StudentManagement');
        $this->load->model('admin/BranchManagement');
        $this->load->model('admin/CourseManagement');
        $this->load->model('admin/SessionManagement');
        $this->load->model('admin/UCSMappingManagement');
        $this->load->model('admin/LocationManagement');
        $this->load->model('admin/IDProofManagement');
        $this->load->model('admin/RelationManagement');
        $this->load->model('admin/ExamManagement');
        $this->load->model('admin/DocumentManagement');
        $this->load->model('admin/DocumentInfoManagement');
        $this->load->model('admin/AttendanceManagement');
        $this->load->model('admin/TaskAndQuizManagement');
        $this->load->model('admin/FeeManagement');
        $this->load->library('util/CSVHandler');
        $this->load->library('util/JSONHandler');
        $this->load->library('util/FileHandler');
    }

    public function index() {
        if ($this->sessionvalidator->isLoggedIn() && $this->sessionvalidator->isAccessGranted()) {
            $selectedPattern = "";
            $selectedSession = "";
            $selectedEntryType = "";
            $filteredRecords = array();
            if (isset($_POST['filterSubmitBtn'])) {
                $filterPattern = $this->input->post('filterPattern');
                $selectedPattern = $filterPattern;
                if ($filterPattern != "") {
                    if ($filterPattern == 'FNW') {
                        $reqFormNumber = $this->input->post('stuFormNo');
                        if ($reqFormNumber == "") {
                            $this->session->set_flashdata('errorMessage', "Enter Form Number To Search.");
                        } else {
                            $this->session->set_flashdata('errorMessage', NULL);
                            $studentsInfo = $this->StudentManagement->getStudentPersonalInfoByFormNumber($reqFormNumber)->result();
                            for ($i = 0; $i < sizeof($studentsInfo); $i++) {
                                $fathersName = "";
                                if (sizeof($this->StudentManagement->getStudentFatherInfoBy($studentsInfo[$i]->tspi_id)->result())) {
                                    $fathersName = $this->StudentManagement->getStudentFatherInfoBy($studentsInfo[$i]->tspi_id)->result()[0]->tfbi_name;
                                }
                                array_push($filteredRecords, array(
                                    'tspi_id' => $studentsInfo[$i]->tspi_id,
                                    'tspi_form_no' => stripslashes($studentsInfo[$i]->tspi_form_no),
                                    'tspi_enrollment_no' => stripslashes($studentsInfo[$i]->tspi_enrollment_no),
                                    'tspi_rollNumber' => stripslashes($studentsInfo[$i]->tspi_rollNumber),
                                    'tspi_name' => stripslashes($studentsInfo[$i]->tspi_name),
                                    'tspi_gender' => $studentsInfo[$i]->tspi_gender,
                                    'course_name' => stripslashes($studentsInfo[$i]->course_name),
                                    'session_name' => stripslashes($studentsInfo[$i]->session_name),
                                    'tcsm_course_type' => stripslashes($studentsInfo[$i]->tcsm_course_type),
                                    'tspi_status' => $studentsInfo[$i]->tspi_status,
                                    'tspi_delete_status' => $studentsInfo[$i]->tspi_delete_status,
                                    'tspi_father_name' => $fathersName
                                ));
                            }
                        }
                    } else if ($filterPattern == 'RNW') {
                        $reqRollNumber = $this->input->post('stuRollNo');
                        if ($reqRollNumber == "") {
                            $this->session->set_flashdata('errorMessage', "Enter Roll Number/Enrl. No. To Search.");
                        } else {
                            $this->session->set_flashdata('errorMessage', NULL);
                            $studentsInfo = $this->StudentManagement->getStudentPersonalInfoByRollNumberOrEnrollmentNo($reqRollNumber)->result();
                            for ($i = 0; $i < sizeof($studentsInfo); $i++) {
                                $fathersName = "";
                                if (sizeof($this->StudentManagement->getStudentFatherInfoBy($studentsInfo[$i]->tspi_id)->result())) {
                                    $fathersName = $this->StudentManagement->getStudentFatherInfoBy($studentsInfo[$i]->tspi_id)->result()[0]->tfbi_name;
                                }
                                array_push($filteredRecords, array(
                                    'tspi_id' => $studentsInfo[$i]->tspi_id,
                                    'tspi_form_no' => stripslashes($studentsInfo[$i]->tspi_form_no),
                                    'tspi_enrollment_no' => stripslashes($studentsInfo[$i]->tspi_enrollment_no),
                                    'tspi_rollNumber' => stripslashes($studentsInfo[$i]->tspi_rollNumber),
                                    'tspi_name' => stripslashes($studentsInfo[$i]->tspi_name),
                                    'tspi_gender' => $studentsInfo[$i]->tspi_gender,
                                    'course_name' => stripslashes($studentsInfo[$i]->course_name),
                                    'session_name' => stripslashes($studentsInfo[$i]->session_name),
                                    'tcsm_course_type' => stripslashes($studentsInfo[$i]->tcsm_course_type),
                                    'tspi_status' => $studentsInfo[$i]->tspi_status,
                                    'tspi_delete_status' => $studentsInfo[$i]->tspi_delete_status,
                                    'tspi_father_name' => $fathersName
                                ));
                            }
                        }
                    } else {
                        $reqCourse = $this->input->post('stuCourse');
                        if ($reqCourse == "") {
                            $this->session->set_flashdata('errorMessage', "Please Select Course To Search Students.");
                        } else {
                            $selectedSession = $this->input->post('stuSession');
                            $selectedEntryType = $this->input->post('stuEntryType');
                            $studentsInfo = $this->StudentManagement->getStudentPersonalInfoByCourseSessionAndEntryType($reqCourse, trim($selectedSession), trim($selectedEntryType))->result();
                            for ($i = 0; $i < sizeof($studentsInfo); $i++) {
                                $fathersName = "";
                                if (sizeof($this->StudentManagement->getStudentFatherInfoBy($studentsInfo[$i]->tspi_id)->result())) {
                                    $fathersName = $this->StudentManagement->getStudentFatherInfoBy($studentsInfo[$i]->tspi_id)->result()[0]->tfbi_name;
                                }
                                array_push($filteredRecords, array(
                                    'tspi_id' => $studentsInfo[$i]->tspi_id,
                                    'tspi_form_no' => stripslashes($studentsInfo[$i]->tspi_form_no),
                                    'tspi_enrollment_no' => stripslashes($studentsInfo[$i]->tspi_enrollment_no),
                                    'tspi_rollNumber' => stripslashes($studentsInfo[$i]->tspi_rollNumber),
                                    'tspi_name' => stripslashes($studentsInfo[$i]->tspi_name),
                                    'tspi_gender' => $studentsInfo[$i]->tspi_gender,
                                    'course_name' => stripslashes($studentsInfo[$i]->course_name),
                                    'session_name' => stripslashes($studentsInfo[$i]->session_name),
                                    'tcsm_course_type' => stripslashes($studentsInfo[$i]->tcsm_course_type),
                                    'tspi_status' => $studentsInfo[$i]->tspi_status,
                                    'tspi_delete_status' => $studentsInfo[$i]->tspi_delete_status,
                                    'tspi_father_name' => $fathersName
                                ));
                            }
                        }
                    }
                } else {
                    $filteredRecords = array();
                }
            }
            $viewData['branches'] = $this->BranchManagement->getAllNonDeletedActiveBrances()->result();
            $viewData['courses'] = $this->CourseManagement->getActiveAndNonDeletedCourses()->result();
            $viewData['selectedPattern'] = $selectedPattern;
            $viewData['selectedSession'] = $selectedSession;
            $viewData['selectedEntryType'] = $selectedEntryType;
            $viewData['filteredRecords'] = $filteredRecords;
            $this->load->view('admin/student/students', $viewData);
        } else {
            redirect("admin/");
        }
    }

    public function enrollStudent() {
        if ($this->sessionvalidator->isLoggedIn() && $this->sessionvalidator->isAccessGranted()) {
            $viewData['branches'] = $this->BranchManagement->getAllNonDeletedActiveBrances()->result();
            $viewData['courses'] = $this->CourseManagement->getActiveAndNonDeletedCourses()->result();
            $viewData['states'] = $this->LocationManagement->getAllNonDeletedActiveStates()->result();
            $viewData['relations'] = $this->RelationManagement->getAllNonDeletedActiveRelations()->result();
            $viewData['categories'] = json_decode(file_get_contents(base_url('assets/admin/json/categories.json')), true);
            $viewData['religions'] = json_decode(file_get_contents(base_url('assets/admin/json/religions.json')), true);
            $this->load->view('admin/student/enrollStudent', $viewData);
        } else {
            redirect("admin/");
        }
    }

    public function saveNewStudent() {
        if ($this->sessionvalidator->isLoggedIn() && $this->sessionvalidator->isAccessGranted()) {
            $this->form_validation->set_rules('stuBranch', 'Branch', 'trim|required', array('required' => 'Branch Is Required.'));
            $this->form_validation->set_rules('stuFormNo', 'Form Number', 'trim|required', array('required' => 'Form Number Is Required.'));
            $this->form_validation->set_rules('stuCourse', 'Course', 'trim|required', array('required' => 'Please Select Course.'));
            $this->form_validation->set_rules('stuSession', 'Session', 'trim|required', array('required' => 'Please Select Session.'));
            $this->form_validation->set_rules('stuEntryType', 'Entry Type', 'trim|required', array('required' => 'Please Select Entry Type.'));
            $this->form_validation->set_rules('stuName', 'Student Name', 'trim|required', array('required' => 'Student Name Is Required.'));
            $this->form_validation->set_rules('stuMobile', 'Student Mobile Number', 'trim|required|numeric|min_length[10]|max_length[10]', array('required' => 'Student Mobile Is Required.'));
            $this->form_validation->set_rules('stuGen', 'Student Gender', 'trim|required', array('required' => 'Please Select Gender Of Student.'));
            $this->form_validation->set_rules('stuDOB', 'Student D.O.B', 'trim|required', array('required' => 'Please Select D.O.B. Of Student.'));
            $this->form_validation->set_rules('stuCategory', 'Student Category', 'trim|required', array('required' => 'Please Select Student Category.'));
            $this->form_validation->set_rules('stuReligion', 'Student Religion', 'trim|required', array('required' => 'Please Select Student Religion.'));
            $queryByStudentFormNumber = $this->StudentManagement->getStudentPersonalInfoByFormNumber(trim($this->input->post('stuFormNo')));
            $studentInfoFormNumber = $queryByStudentFormNumber->result();
            $queryByRollNumber = $this->StudentManagement->getStudentPersonalInfoByRollNumber(trim($this->input->post('stuRollNo')));
            $studentInfoByRollNumber = $queryByRollNumber->result();
            $queryByEnrollmentNumber = $this->StudentManagement->getStudentPersonalInfoByEnrollmentNumber(trim($this->input->post('stuEnrlNo')));
            $studentInfoByEnrollmentNumber = $queryByEnrollmentNumber->result();
            if ($this->form_validation->run() == FALSE) {
                $this->enrollStudent();
            } else if (sizeof($studentInfoFormNumber)) {
                $this->session->set_flashdata('errorMessage', "A Student Record With This Form Number (" . trim($this->input->post('stuFormNo')) . ") Already Exits! Please Enter Correct Form Number.");
                $this->enrollStudent();
            } else if ((sizeof($studentInfoByEnrollmentNumber)) && (trim($this->input->post('stuEnrlNo')) != "")) {
                $this->session->set_flashdata('errorMessage', "A Student Record With This Enrl. No. (" . trim($this->input->post('stuRollNo')) . ") Already Exits! Please Enter Correct Enrl. No..");
                $this->enrollStudent();
            } else if ((sizeof($studentInfoByRollNumber)) && (trim($this->input->post('stuRollNo')) != "")) {
                $this->session->set_flashdata('errorMessage', "A Student Record With This Roll Number (" . trim($this->input->post('stuRollNo')) . ") Already Exits! Please Enter Correct Roll Number.");
                $this->enrollStudent();
            } else {
                $studentPersonalInfo = array(
                    'tspi_name' => addslashes(trim($this->input->post('stuName'))),
                    'tspi_form_no' => addslashes(trim($this->input->post('stuFormNo'))),
                    'ucs_map_id' => trim($this->input->post('stuEntryType')),
                    'tspi_enrollment_no' => (trim($this->input->post('stuEnrlNo') == '')) ? addslashes(trim($this->input->post('stuFormNo'))) : addslashes(trim($this->input->post('stuEnrlNo'))),
                    'tspi_mobile' => trim($this->input->post('stuMobile')),
                    'tspi_email' => trim($this->input->post('stuEmail')),
                    'tspi_gender' => trim($this->input->post('stuGen')),
                    'tspi_category' => trim($this->input->post('stuCategory')),
                    'tspi_religion' => trim($this->input->post('stuReligion')),
                    'tspi_dob' => ($this->input->post('stuDOB') == "" ) ? NULL : date("Y-m-d", strtotime(str_replace('/', '-', $this->input->post('stuDOB')))),
                    'tspi_added_by' => $this->session->userdata("adminData")["smember_id"],
                    'tspi_added_on' => date("Y-m-d H:i:s"),
                    'tspi_updated_by' => $this->session->userdata("adminData")["smember_id"],
                    'tspi_updated_on' => date("Y-m-d H:i:s"),
                    'tspi_status' => trim($this->input->post('stuStatus')),
                    'tspi_rollNumber' => (trim($this->input->post('stuRollNo') == '')) ? addslashes(trim($this->input->post('stuFormNo'))) : addslashes(trim($this->input->post('stuRollNo'))),
                    'tspi_enrollment_date' => ($this->input->post('stuEnrlDate') == "" ) ? NULL : date("Y-m-d", strtotime(str_replace('/', '-', $this->input->post('stuEnrlDate')))),
                    'tspi_univ_rollNumber' => (trim($this->input->post('stuRollNo') == '')) ? addslashes(trim($this->input->post('stuFormNo'))) : addslashes(trim($this->input->post('stuRollNo'))),
                    'tspi_admission_date' => ($this->input->post('stuAdmFormDate') == "" ) ? NULL : date("Y-m-d", strtotime(str_replace('/', '-', $this->input->post('stuAdmFormDate')))),
                    'tspi_is_diff_abled' => trim($this->input->post('stuDiffAbled')),
                    'tspi_parent_annual_income' => trim($this->input->post('stuParentIncome')),
                    'tspi_remarks' => addslashes(trim($this->input->post('stuRemarks'))),
                    'tspi_ygap_applied' => (trim($this->input->post('stuYearGap')) == "") ? NULL : trim($this->input->post('stuYearGap')),
                    'tspi_scholarship_eligible' => (trim($this->input->post('stuClgSch')) == "") ? NULL : trim($this->input->post('stuClgSch')),
                    'tspi_scholarship_percentage' => (trim($this->input->post('stuSchPercentage')) == "") ? NULL : trim($this->input->post('stuSchPercentage')),
                    'tspi_password' => MD5('12345'),
                    'tspi_is_reg_fee_applicable' => trim($this->input->post('stuRegFeeApplicable'))
                );
                $studentContactInfo = array(
                    'tsci_perma_state' => trim($this->input->post('stuPermaAddrState')),
                    'tsci_perma_city' => trim($this->input->post('stuPermaAddrCity')),
                    'tsci_perma_zipcode' => trim($this->input->post('stuPermaAddrZipCode')),
                    'tsci_resid_state' => trim($this->input->post('stuMailingAddrState')),
                    'tsci_resid_city' => trim($this->input->post('stuMailingAddrCity')),
                    'tsci_resid_zipcode' => trim($this->input->post('stuMailingAddrZipCode')),
                    'tsci_parent_landline' => trim($this->input->post('stuParentLandline')),
                    'tsci_parent_mobile' => trim($this->input->post('stuParentMobile')),
                    'tsci_added_on' => date("Y-m-d H:i:s"),
                    'tsci_added_by' => $this->session->userdata("adminData")["smember_id"],
                    'tsci_updated_on' => date("Y-m-d H:i:s"),
                    'tsci_updated_by' => $this->session->userdata("adminData")["smember_id"],
                    'tspi_id' => '',
                    'tsci_perma_address_line_one' => addslashes(trim($this->input->post('stuPermaAddrLineOne'))),
                    'tsci_perma_address_line_two' => addslashes(trim($this->input->post('stuPermaAddrLineTwo'))),
                    'tsci_perma_address_line_three' => addslashes(trim($this->input->post('stuPermaAddrLineThree'))),
                    'tsci_resid_address_line_one' => addslashes(trim($this->input->post('stuMailingAddrLineOne'))),
                    'tsci_resid_address_line_two' => addslashes(trim($this->input->post('stuMailingAddrLineTwo'))),
                    'tsci_resid_address_line_three' => addslashes(trim($this->input->post('stuMailingAddrLineThree')))
                );
                $studentEntranceProfAndExtraCurricularInfo = array(
                    'tsevi_is_prof_exp' => trim($this->input->post('stuProfExp')),
                    'tsevi_no_of_years' => trim($this->input->post('stuProfExpInYears')),
                    'tsevi_organization' => addslashes(trim($this->input->post('stuProfOrgName'))),
                    'tsevi_job_desc' => addslashes(trim($this->input->post('stuProfJobDesc'))),
                    'tsevi_extra_activities' => addslashes(trim($this->input->post('stuExtraCurricularAct'))),
                    'tsevi_how_know_sms' => (trim($this->input->post('stuHowKnowSMS')) == "O") ? trim($this->input->post('stuHowKnowSMSOtherDesc')) : addslashes(trim($this->input->post('stuHowKnowSMS'))),
                    'tsevi_entrance_through' => trim($this->input->post('stuEntranceExam')),
                    'tsevi_form_no' => trim($this->input->post('stuEntranceExamRegNo')),
                    'tsevi_composite_score' => trim($this->input->post('stuEntranceExamComScore')),
                    'tsevi_percnt_obtained' => trim($this->input->post('stuEntranceExamPercentileObt')),
                    'tsevi_rank' => trim($this->input->post('stuEntranceExamRank')),
                    'tsevi_added_on' => date("Y-m-d H:i:s"),
                    'tsevi_updated_on' => date("Y-m-d H:i:s"),
                    'tsevi_added_by' => $this->session->userdata("adminData")["smember_id"],
                    'tsevi_updated_by' => $this->session->userdata("adminData")["smember_id"],
                    'tspi_id' => '',
                    'tsevi_percntage' => trim($this->input->post('stuEntranceExamPercentage')),
                );
                $studentHostelAndResidenceInfo = array(
                    'tshri_is_hostel_opted' => (trim($this->input->post('stuResidChoice')) == "H") ? "T" : "F",
                    'tshri_resid_choice' => trim($this->input->post('stuResidChoice')),
                    'tshri_comm_state' => trim($this->input->post('stuCommAddrState')),
                    'tshri_comm_city' => trim($this->input->post('stuCommAddrCity')),
                    'tshri_comm_zipcode' => trim($this->input->post('stuCommAddrZipCode')),
                    'tshri_comm_tel_no' => trim($this->input->post('stuCommLandline')),
                    'tshri_comm_mobile' => trim($this->input->post('stuCommMobile')),
                    'tshri_loc_guard_name' => addslashes(trim($this->input->post('stuLocGuardName'))),
                    'tshri_loc_guard_state' => trim($this->input->post('stuLocGuardAddrState')),
                    'tshri_loc_guard_city' => trim($this->input->post('stuLocGuardAddrCity')),
                    'tshri_loc_guard_tel_no' => trim($this->input->post('stuLocGuardLandline')),
                    'tshri_loc_guard_mob' => trim($this->input->post('stuLocGuardMobile')),
                    'tshri_added_on' => date("Y-m-d H:i:s"),
                    'tshri_updated_on' => date("Y-m-d H:i:s"),
                    'tshri_added_by' => $this->session->userdata("adminData")["smember_id"],
                    'tshri_updated_by' => $this->session->userdata("adminData")["smember_id"],
                    'tspi_id' => '',
                    'tshri_loc_guard_zipcode' => addslashes(trim($this->input->post('stuLocGuardAddrZipCode'))),
                    'tshri_comm_address_line_one' => addslashes(trim($this->input->post('stuCommAddrLineOne'))),
                    'tshri_comm_address_line_two' => addslashes(trim($this->input->post('stuCommAddrLineTwo'))),
                    'tshri_comm_address_line_three' => addslashes(trim($this->input->post('stuCommAddrLineThree'))),
                    'tshri_loc_guard_address_line_one' => addslashes(trim($this->input->post('stuLocGuardAddrLineOne'))),
                    'tshri_loc_guard_address_line_two' => addslashes(trim($this->input->post('stuLocGuardAddrLineTwo'))),
                    'tshri_loc_guard_address_line_three' => addslashes(trim($this->input->post('stuLocGuardAddrLineThree')))
                );
                $aadharIdInfo = $this->IDProofManagement->getIDProofAndSubIdProofInfoBy(2, "S")->result()[0];
                $studentAadharInfo = array(
                    'tipi_number' => trim($this->input->post('stuAadharNo')),
                    'rel_id' => 0,
                    'tipsm_id' => $aadharIdInfo->tipsm_id,
                    'tipi_added_on' => date("Y-m-d H:i:s"),
                    'tipi_updated_on' => date("Y-m-d H:i:s"),
                    'tipi_added_by' => $this->session->userdata("adminData")["smember_id"],
                    'tipi_updated_by' => $this->session->userdata("adminData")["smember_id"],
                    'tipi_for' => ''
                );
                $PANInfo = $this->IDProofManagement->getIDProofAndSubIdProofInfoBy(1, "S")->result()[0];
                $studentPANInfo = array(
                    'tipi_number' => trim($this->input->post('stuPAN')),
                    'rel_id' => 0,
                    'tipsm_id' => $PANInfo->tipsm_id,
                    'tipi_added_on' => date("Y-m-d H:i:s"),
                    'tipi_updated_on' => date("Y-m-d H:i:s"),
                    'tipi_added_by' => $this->session->userdata("adminData")["smember_id"],
                    'tipi_updated_by' => $this->session->userdata("adminData")["smember_id"],
                    'tipi_for' => ''
                );
                $casteCertificateInfo = $this->IDProofManagement->getIDProofAndSubIdProofInfoBy(5, "S")->result()[0];
                $studentCasteCertificateInfo = array(
                    'tipi_number' => trim($this->input->post('stuCSTCNumber')),
                    'rel_id' => 0,
                    'tipsm_id' => $casteCertificateInfo->tipsm_id,
                    'tipi_added_on' => date("Y-m-d H:i:s"),
                    'tipi_updated_on' => date("Y-m-d H:i:s"),
                    'tipi_added_by' => $this->session->userdata("adminData")["smember_id"],
                    'tipi_updated_by' => $this->session->userdata("adminData")["smember_id"],
                    'tipi_for' => ''
                );
                $incomeCertificateInfo = $this->IDProofManagement->getIDProofAndSubIdProofInfoBy(6, "S")->result()[0];
                $studentIncomeCertificateInfo = array(
                    'tipi_number' => trim($this->input->post('stuAICNumber')),
                    'rel_id' => 0,
                    'tipsm_id' => $incomeCertificateInfo->tipsm_id,
                    'tipi_added_on' => date("Y-m-d H:i:s"),
                    'tipi_updated_on' => date("Y-m-d H:i:s"),
                    'tipi_added_by' => $this->session->userdata("adminData")["smember_id"],
                    'tipi_updated_by' => $this->session->userdata("adminData")["smember_id"],
                    'tipi_for' => ''
                );
                $studentIdProofInfo = array($studentAadharInfo, $studentPANInfo, $studentCasteCertificateInfo, $studentIncomeCertificateInfo);
                $studentFamilyBackgroundInfo = array();
                $studentFamilyBGName = $this->input->post('stuFamBGName');
                $studentFamilyBGDesig = $this->input->post('stuFamBGDesignation');
                $studentFamilyBGOrg = $this->input->post('stuFamBGOrganization');
                $studentFamilyBGRel = $this->input->post('stuFamBGRelation');
                for ($i = 0; $i < 3; $i++) {
                    $thisFamilyBGInfo = array(
                        'tfbi_relation' => trim($studentFamilyBGRel[$i]),
                        'tfbi_name' => addslashes(trim($studentFamilyBGName[$i])),
                        'tfbi_organization' => addslashes(trim($studentFamilyBGOrg[$i])),
                        'tfbi_designation' => addslashes(trim($studentFamilyBGDesig[$i])),
                        'tfbi_user_type_flag' => 'S',
                        'tfbi_mapping_id' => '',
                        'tfbi_added_on' => date("Y-m-d H:i:s"),
                        'tfbi_updated_on' => date("Y-m-d H:i:s"),
                        'tfbi_added_by' => $this->session->userdata("adminData")["smember_id"],
                        'tfbi_updated_by' => $this->session->userdata("adminData")["smember_id"]
                    );
                    array_push($studentFamilyBackgroundInfo, $thisFamilyBGInfo);
                }
                $fatherRelId = $this->RelationManagement->getRelationInfoByName("FATHER")->result()[0];
                $studentFatherFamBGInfo = array(
                    'tfbi_relation' => $fatherRelId->rel_id,
                    'tfbi_name' => addslashes(trim($this->input->post('stuFatherName'))),
                    'tfbi_organization' => "NA",
                    'tfbi_designation' => "NA",
                    'tfbi_user_type_flag' => 'S',
                    'tfbi_mapping_id' => '',
                    'tfbi_added_on' => date("Y-m-d H:i:s"),
                    'tfbi_updated_on' => date("Y-m-d H:i:s"),
                    'tfbi_added_by' => $this->session->userdata("adminData")["smember_id"],
                    'tfbi_updated_by' => $this->session->userdata("adminData")["smember_id"]
                );
                $motherRelId = $this->RelationManagement->getRelationInfoByName("MOTHER")->result()[0];
                $studentMotherFamBGInfo = array(
                    'tfbi_relation' => $motherRelId->rel_id,
                    'tfbi_name' => addslashes(trim($this->input->post('stuMotherName'))),
                    'tfbi_organization' => "NA",
                    'tfbi_designation' => "NA",
                    'tfbi_user_type_flag' => 'S',
                    'tfbi_mapping_id' => '',
                    'tfbi_added_on' => date("Y-m-d H:i:s"),
                    'tfbi_updated_on' => date("Y-m-d H:i:s"),
                    'tfbi_added_by' => $this->session->userdata("adminData")["smember_id"],
                    'tfbi_updated_by' => $this->session->userdata("adminData")["smember_id"]
                );
                array_push($studentFamilyBackgroundInfo, $studentFatherFamBGInfo);
                array_push($studentFamilyBackgroundInfo, $studentMotherFamBGInfo);
                $studentEducationQualificatioInfo = array();
                $studentEduQualiExamIds = $this->input->post('stuEduQualiExamId');
                $studentEduQualiBoardUniv = $this->input->post('stuEduQualiBoardUniv');
                $studentEduQualiStream = $this->input->post('stuEduQualiStream');
                $studentEduQualiYearOfExam = $this->input->post('stuEduQualiYearOfExam');
                $studentEduQualiMaxMarks = $this->input->post('stuEduQualiMaxMarks');
                $studentEduQualiMarksObtnd = $this->input->post('stuEduQualiMarksObt');
                $studentEduQualiPrcntObtnd = $this->input->post('stuEduQualiPercntCGPA');
                $studentEduQualiDiv = $this->input->post('stuEduQualiDiv');
                $totalEduQualisInfo = sizeof($studentEduQualiExamIds);
                for ($i = 0; $i < $totalEduQualisInfo; $i++) {
                    $thisEduQualiInfo = array(
                        'tesi_exam' => $studentEduQualiExamIds[$i],
                        'tesi_board' => $studentEduQualiBoardUniv[$i],
                        'tesi_university' => $studentEduQualiBoardUniv[$i],
                        'tesi_stream' => $studentEduQualiStream[$i],
                        'tesi_passing_year' => $studentEduQualiYearOfExam[$i],
                        'tesi_percnt' => $studentEduQualiPrcntObtnd[$i],
                        'tesi_cgpa' => $studentEduQualiMarksObtnd[$i],
                        'tesi_division' => $studentEduQualiDiv[$i],
                        'tesi_added_on' => date("Y-m-d H:i:s"),
                        'tesi_updated_on' => date("Y-m-d H:i:s"),
                        'tesi_added_by' => $this->session->userdata("adminData")["smember_id"],
                        'tesi_updated_by' => $this->session->userdata("adminData")["smember_id"],
                        'tspi_id' => '',
                        'tesi_max_marks_cgpa' => $studentEduQualiMaxMarks[$i]
                    );
                    array_push($studentEducationQualificatioInfo, $thisEduQualiInfo);
                }
                $this->load->library('upload');
                $studentDocumentInfo = array();
                $studentPhotographDocId = $this->DocumentManagement->getDocumentByFlag("SP")->result()[0]->doc_id;
                if (!empty($_FILES['stuPhotograph']['name'])) {
                    $studentImg['upload_path'] = './assets/admin/uploads/studentData/';
                    $studentImg['allowed_types'] = 'jpeg|jpg|png';
                    $studentImg['max_size'] = '500';
                    $studentImg['file_ext_tolower'] = TRUE;
                    $studentImg['encrypt_name'] = TRUE;
                    $this->upload->initialize($studentImg);
                    if (!$this->upload->do_upload('stuPhotograph')) {
                        $this->session->set_flashdata('errorMessage', "Student Photo Can Not Be Uploaded As It Violates Upload File Criteria. File Size 500 KB Max. & Allowed Extension: Only *.png,*.jpg,*.jpeg.");
                        $this->enrollStudent();
                    } else {
                        $studentPhotoInfo = array(
                            'tddi_doc_id' => $studentPhotographDocId,
                            'tddi_doc_file_path' => $this->upload->data()['file_name'],
                            'tddi_code' => $studentPhotographDocId,
                            'tddi_user_type_flag' => 'S',
                            'tddi_mapping_id' => '',
                            'tddi_semester' => 'NA',
                            'ucs_map_id' => trim($this->input->post('stuEntryType')),
                            'tddi_added_on' => date("Y-m-d H:i:s"),
                            'tddi_updated_on' => date("Y-m-d H:i:s"),
                            'tddi_added_by' => $this->session->userdata("adminData")["smember_id"],
                            'tddi_updated_by' => $this->session->userdata("adminData")["smember_id"]
                        );
                        array_push($studentDocumentInfo, $studentPhotoInfo);
                    }
                } else {
                    $studentPhotoInfo = array(
                        'tddi_doc_id' => $studentPhotographDocId,
                        'tddi_doc_file_path' => "picnotavail.jpg",
                        'tddi_code' => $studentPhotographDocId,
                        'tddi_user_type_flag' => 'S',
                        'tddi_mapping_id' => '',
                        'tddi_semester' => 'NA',
                        'ucs_map_id' => trim($this->input->post('stuEntryType')),
                        'tddi_added_on' => date("Y-m-d H:i:s"),
                        'tddi_updated_on' => date("Y-m-d H:i:s"),
                        'tddi_added_by' => $this->session->userdata("adminData")["smember_id"],
                        'tddi_updated_by' => $this->session->userdata("adminData")["smember_id"]
                    );
                    array_push($studentDocumentInfo, $studentPhotoInfo);
                }
                $studentSignDocId = $this->DocumentManagement->getDocumentByFlag("SS")->result()[0]->doc_id;
                if (!empty($_FILES['stuSignature']['name'])) {
                    $studentSignImg['upload_path'] = './assets/admin/uploads/studentData/';
                    $studentSignImg['allowed_types'] = 'jpeg|jpg|png';
                    $studentSignImg['max_size'] = '500';
                    $studentSignImg['file_ext_tolower'] = TRUE;
                    $studentSignImg['encrypt_name'] = TRUE;
                    $this->upload->initialize($studentSignImg);
                    if (!$this->upload->do_upload('stuSignature')) {
                        $this->session->set_flashdata('errorMessage', "Student Signature Can Not Be Uploaded As It Violates Upload File Criteria. File Size 500 KB Max. & Allowed Extension: Only *.png,*.jpg,*.jpeg.");
                        $this->enrollStudent();
                    } else {
                        $studentSignInfo = array(
                            'tddi_doc_id' => $studentSignDocId,
                            'tddi_doc_file_path' => $this->upload->data()['file_name'],
                            'tddi_code' => $studentSignDocId,
                            'tddi_user_type_flag' => 'S',
                            'tddi_mapping_id' => '',
                            'tddi_semester' => 'NA',
                            'ucs_map_id' => trim($this->input->post('stuEntryType')),
                            'tddi_added_on' => date("Y-m-d H:i:s"),
                            'tddi_updated_on' => date("Y-m-d H:i:s"),
                            'tddi_added_by' => $this->session->userdata("adminData")["smember_id"],
                            'tddi_updated_by' => $this->session->userdata("adminData")["smember_id"]
                        );
                        array_push($studentDocumentInfo, $studentSignInfo);
                    }
                } else {
                    $studentSignInfo = array(
                        'tddi_doc_id' => $studentSignDocId,
                        'tddi_doc_file_path' => "signnotavail.png",
                        'tddi_code' => $studentSignDocId,
                        'tddi_user_type_flag' => 'S',
                        'tddi_mapping_id' => '',
                        'tddi_semester' => 'NA',
                        'ucs_map_id' => trim($this->input->post('stuEntryType')),
                        'tddi_added_on' => date("Y-m-d H:i:s"),
                        'tddi_updated_on' => date("Y-m-d H:i:s"),
                        'tddi_added_by' => $this->session->userdata("adminData")["smember_id"],
                        'tddi_updated_by' => $this->session->userdata("adminData")["smember_id"]
                    );
                    array_push($studentDocumentInfo, $studentSignInfo);
                }
                $submittedDocuments = $this->input->post('stuDocumentFileId');
                for ($i = 0; $i < sizeof($submittedDocuments); $i++) {
                    $doc_id = $submittedDocuments[$i];
                    $thisFileInputName = "stuDocumentFile" . $doc_id;
                    $ifNotApplicable = ($this->input->post("stuDocumentFileApplicable" . $doc_id) != NULL) ? 1 : 0;
                    if ($ifNotApplicable) {
                        $thisDocumentInfo = array(
                            'tddi_doc_id' => $submittedDocuments[$i],
                            'tddi_doc_file_path' => "na.png",
                            'tddi_code' => $submittedDocuments[$i],
                            'tddi_user_type_flag' => 'S',
                            'tddi_mapping_id' => '',
                            'tddi_semester' => 'NA',
                            'ucs_map_id' => trim($this->input->post('stuEntryType')),
                            'tddi_added_on' => date("Y-m-d H:i:s"),
                            'tddi_updated_on' => date("Y-m-d H:i:s"),
                            'tddi_added_by' => $this->session->userdata("adminData")["smember_id"],
                            'tddi_updated_by' => $this->session->userdata("adminData")["smember_id"]
                        );
                        array_push($studentDocumentInfo, $thisDocumentInfo);
                    } else {
                        if (!empty($_FILES[$thisFileInputName]['name'])) {
                            $studentDocFile['upload_path'] = './assets/admin/uploads/studentData/';
                            $studentDocFile['allowed_types'] = 'pdf|jpeg|jpg|png';
                            $studentDocFile['max_size'] = '4096';
                            $studentDocFile['file_ext_tolower'] = TRUE;
                            $studentDocFile['encrypt_name'] = TRUE;
                            $this->upload->initialize($studentDocFile);
                            if (!$this->upload->do_upload($thisFileInputName)) {
                                $this->session->set_flashdata('errorMessage', "Any Of The Uploaded Document File Violates Document Upload File Criteria. File Size 4 MB Max. & Allowed Extension: Only *.png,*.jpg,*.jpeg,*.pdf.");
                                redirect("admin/Student/enrollStudent");
                            } else {
                                $thisDocumentInfo = array(
                                    'tddi_doc_id' => $submittedDocuments[$i],
                                    'tddi_doc_file_path' => $this->upload->data()['file_name'],
                                    'tddi_code' => $submittedDocuments[$i],
                                    'tddi_user_type_flag' => 'S',
                                    'tddi_mapping_id' => '',
                                    'tddi_semester' => 'NA',
                                    'ucs_map_id' => trim($this->input->post('stuEntryType')),
                                    'tddi_added_on' => date("Y-m-d H:i:s"),
                                    'tddi_updated_on' => date("Y-m-d H:i:s"),
                                    'tddi_added_by' => $this->session->userdata("adminData")["smember_id"],
                                    'tddi_updated_by' => $this->session->userdata("adminData")["smember_id"]
                                );
                                array_push($studentDocumentInfo, $thisDocumentInfo);
                            }
                        }
                    }
                }
                $this->db->trans_start();
                $tspi_id = $this->StudentManagement->createNewStudentPersonalInfoEntry($studentPersonalInfo);
                if ($tspi_id) {
                    $studentContactInfo['tspi_id'] = $tspi_id;
                    $studentEntranceProfAndExtraCurricularInfo['tspi_id'] = $tspi_id;
                    $studentHostelAndResidenceInfo['tspi_id'] = $tspi_id;
                    $studentPANInfo['tipi_for'] = $tspi_id;
                    $studentAadharInfo['tipi_for'] = $tspi_id;
                    for ($i = 0; $i < sizeof($studentIdProofInfo); $i++) {
                        $studentIdProofInfo[$i]['tipi_for'] = $tspi_id;
                    }
                    for ($i = 0; $i < sizeof($studentEducationQualificatioInfo); $i++) {
                        $studentEducationQualificatioInfo[$i]['tspi_id'] = $tspi_id;
                    }
                    for ($i = 0; $i < sizeof($studentFamilyBackgroundInfo); $i++) {
                        $studentFamilyBackgroundInfo[$i]['tfbi_mapping_id'] = $tspi_id;
                    }
                    for ($i = 0; $i < sizeof($studentDocumentInfo); $i++) {
                        $studentDocumentInfo[$i]['tddi_mapping_id'] = $tspi_id;
                    }
                    $this->StudentManagement->createNewStudentContactInfoEntry($studentContactInfo);
                    $this->StudentManagement->createNewStudentEntranceExamProfExpAndExtraCurricularInfoEntry($studentEntranceProfAndExtraCurricularInfo);
                    $this->StudentManagement->createNewStudentHostelAndResidenceChoiceInfoEntry($studentHostelAndResidenceInfo);
                    $this->IDProofManagement->createNewIDProofInfoMulti($studentIdProofInfo);
                    $this->StudentManagement->createNewStudentEducationalQualificationInfoMulti($studentEducationQualificatioInfo);
                    $this->StudentManagement->createNewStudentFamilyBackgroundInfoMulti($studentFamilyBackgroundInfo);
                    $this->DocumentInfoManagement->createNewDocumentInfoMulti($studentDocumentInfo);
                    $this->db->trans_complete();
                    $this->session->set_flashdata('successMessage', 'Student Enrolled Successfully.');
                    redirect("admin/Student/");
                } else {
                    $this->session->set_flashdata('successMessage', 'An Error Occured While Student Enrollment. Try Again.');
                    redirect("admin/Student/enrollStudent");
                }
            }
        } else {
            redirect("admin/");
        }
    }

    public function editStudent($tspi_id) {
        if ($this->sessionvalidator->isLoggedIn() && $this->sessionvalidator->isAccessGranted()) {
            $viewData['branches'] = $this->BranchManagement->getAllNonDeletedActiveBrances()->result();
            $viewData['courses'] = $this->CourseManagement->getActiveAndNonDeletedCourses()->result();
            $viewData['states'] = $this->LocationManagement->getAllNonDeletedActiveStates()->result();
            $viewData['relations'] = $this->RelationManagement->getAllNonDeletedActiveRelations()->result();
            $viewData['categories'] = json_decode(file_get_contents(base_url('assets/admin/json/categories.json')), true);
            $viewData['religions'] = json_decode(file_get_contents(base_url('assets/admin/json/religions.json')), true);
            $viewData['stuPersonalInfoWithPicAndSign'] = $this->StudentManagement->getStudentPersonalInfoAndPhotoSignBy($tspi_id)->result()[0];
            $viewData['stuContactInfo'] = $this->StudentManagement->getStudentContactInfoBy($tspi_id)->result()[0];
            $viewData['stuEntranceExamAndProfExpInfo'] = $this->StudentManagement->getStudentStudentEntranceExamProfExpAndExtraCurricularInfoBy($tspi_id)->result()[0];
            $viewData['stuHostelAndResidInfo'] = $this->StudentManagement->getStudentHostelAndResidenceChoiceInfoBy($tspi_id)->result()[0];
            $viewData['stuFamilyBGInfo'] = $this->StudentManagement->getStudentFamilyBackgroundInfoBy($tspi_id)->result();
            $viewData['stuEduQualifInfo'] = $this->StudentManagement->getStudentEducationalQualificationInfo($tspi_id)->result();
            $studentCourseInfo = $this->CourseManagement->getCoursesBy($viewData['stuPersonalInfoWithPicAndSign']->course_id)->result()[0];
            $allowedDocuments = $this->DocumentManagement->getAllDocumentsUptoCategory($studentCourseInfo->course_category)->result();
            $uploadedDocsInfo = array();
            for ($i = 0; $i < sizeof($allowedDocuments); $i++) {
                if ($this->DocumentInfoManagement->isDocumentUploaded($tspi_id, $allowedDocuments[$i]->doc_id, "S")) {
                    $uploadedDocumentInfo = $this->DocumentInfoManagement->getUploadedDocumentOfStudentBy($tspi_id, $allowedDocuments[$i]->doc_id)->result()[0];
                    $thisDocInfo = array(
                        'is_uploaded' => 1,
                        'tddi_id' => $uploadedDocumentInfo->tddi_id,
                        'doc_id' => $allowedDocuments[$i]->doc_id,
                        'doc_name' => $allowedDocuments[$i]->doc_name,
                        'file_name' => $uploadedDocumentInfo->tddi_doc_file_path
                    );
                } else {
                    $thisDocInfo = array(
                        'is_uploaded' => 0,
                        'tddi_id' => -1,
                        'doc_id' => $allowedDocuments[$i]->doc_id,
                        'doc_name' => $allowedDocuments[$i]->doc_name,
                        'file_name' => ''
                    );
                }
                array_push($uploadedDocsInfo, $thisDocInfo);
            }
            $viewData['stuDocumentInfo'] = $uploadedDocsInfo;
            $viewData['stuFatherName'] = $this->StudentManagement->getStudentFatherInfoBy($tspi_id)->result()[0]->tfbi_name;
            $viewData['stuFatherFamBGId'] = $this->StudentManagement->getStudentFatherInfoBy($tspi_id)->result()[0]->tfbi_id;
            $viewData['stuMotherName'] = $this->StudentManagement->getStudentMotherInfoBy($tspi_id)->result()[0]->tfbi_name;
            $viewData['stuMotherFamBGId'] = $this->StudentManagement->getStudentMotherInfoBy($tspi_id)->result()[0]->tfbi_id;
            $aadharIdInfo = $this->IDProofManagement->getIDProofAndSubIdProofInfoBy(2, "S")->result()[0];
            $PANInfo = $this->IDProofManagement->getIDProofAndSubIdProofInfoBy(1, "S")->result()[0];
            $CSTCInfo = $this->IDProofManagement->getIDProofAndSubIdProofInfoBy(5, "S")->result()[0];
            $AICInfo = $this->IDProofManagement->getIDProofAndSubIdProofInfoBy(6, "S")->result()[0];
            $viewData['stuAadharNumber'] = $this->IDProofManagement->getIdProofInfoBy($tspi_id, $aadharIdInfo->tipsm_id)->result()[0]->tipi_number;
            $viewData['stuAadharInfoId'] = $this->IDProofManagement->getIdProofInfoBy($tspi_id, $aadharIdInfo->tipsm_id)->result()[0]->tipi_id;
            $viewData['stuPANNumber'] = $this->IDProofManagement->getIdProofInfoBy($tspi_id, $PANInfo->tipsm_id)->result()[0]->tipi_number;
            $viewData['stuPANInfoId'] = $this->IDProofManagement->getIdProofInfoBy($tspi_id, $PANInfo->tipsm_id)->result()[0]->tipi_id;
            $viewData['stuCSTCNumber'] = $this->IDProofManagement->getIdProofInfoBy($tspi_id, $CSTCInfo->tipsm_id)->result()[0]->tipi_number;
            $viewData['stuCSTCInfoId'] = $this->IDProofManagement->getIdProofInfoBy($tspi_id, $CSTCInfo->tipsm_id)->result()[0]->tipi_id;
            $viewData['stuAICNumber'] = $this->IDProofManagement->getIdProofInfoBy($tspi_id, $AICInfo->tipsm_id)->result()[0]->tipi_number;
            $viewData['stuAICInfoId'] = $this->IDProofManagement->getIdProofInfoBy($tspi_id, $AICInfo->tipsm_id)->result()[0]->tipi_id;
            $this->load->view('admin/student/editStudent', $viewData);
        } else {
            redirect("admin/");
        }
    }

    public function updateStudent() {
        if ($this->sessionvalidator->isLoggedIn()) {
            $tspi_id = $this->input->post('tspiId');
            $this->form_validation->set_rules('stuBranch', 'Branch', 'trim|required', array('required' => 'Branch Is Required.'));
            $this->form_validation->set_rules('stuFormNo', 'Form Number', 'trim|required', array('required' => 'Form Number Is Required.'));
            $this->form_validation->set_rules('stuCourse', 'Course', 'trim|required', array('required' => 'Please Select Course.'));
            $this->form_validation->set_rules('stuSession', 'Session', 'trim|required', array('required' => 'Please Select Session.'));
            $this->form_validation->set_rules('stuEntryType', 'Entry Type', 'trim|required', array('required' => 'Please Select Entry Type.'));
            $this->form_validation->set_rules('stuName', 'Student Name', 'trim|required', array('required' => 'Student Name Is Required.'));
            $this->form_validation->set_rules('stuMobile', 'Student Mobile Number', 'trim|required|numeric|min_length[10]|max_length[10]', array('required' => 'Student Mobile Is Required.'));
            $this->form_validation->set_rules('stuGen', 'Student Gender', 'trim|required', array('required' => 'Please Select Gender Of Student.'));
            $this->form_validation->set_rules('stuDOB', 'Student D.O.B', 'trim|required', array('required' => 'Please Select D.O.B. Of Student.'));
            $this->form_validation->set_rules('stuCategory', 'Student Category', 'trim|required', array('required' => 'Please Select Student Category.'));
            $this->form_validation->set_rules('stuReligion', 'Student Religion', 'trim|required', array('required' => 'Please Select Student Religion.'));
            if ($this->form_validation->run() == FALSE) {
                $this->editStudent($tspi_id);
            } else if (!$this->StudentManagement->isFormNumberSafeUpdate($tspi_id, trim($this->input->post('stuFormNo')))) {
                $this->session->set_flashdata('errorMessage', "A Student Record With This Form Number (" . trim($this->input->post('stuFormNo')) . ") Already Exits! Please Enter Correct Form Number.");
                $this->editStudent($tspi_id);
            } else if ((!$this->StudentManagement->isEnrollmentNumberSafeUpdate($tspi_id, trim($this->input->post('stuEnrlNo')))) && (trim($this->input->post('stuEnrlNo')) != "")) {
                $this->session->set_flashdata('errorMessage', "A Student Record With This Enrl. No. (" . trim($this->input->post('stuEnrlNo')) . ") Already Exits! Please Enter Correct Enrl. No..");
                $this->editStudent($tspi_id);
            } else if ((!$this->StudentManagement->isRollNumberSafeUpdate($tspi_id, trim($this->input->post('stuRollNo')))) && (trim($this->input->post('stuRollNo')) != "")) {
                $this->session->set_flashdata('errorMessage', "A Student Record With This Roll Number (" . trim($this->input->post('stuRollNo')) . ") Already Exits! Please Enter Correct Roll Number.");
                $this->editStudent($tspi_id);
            } else {
                $studentPersonalInfo = array(
                    'tspi_id' => $tspi_id,
                    'tspi_name' => addslashes(trim($this->input->post('stuName'))),
                    'tspi_form_no' => addslashes(trim($this->input->post('stuFormNo'))),
                    'ucs_map_id' => trim($this->input->post('stuEntryType')),
                    'tspi_enrollment_no' => (trim($this->input->post('stuEnrlNo') == '')) ? addslashes(trim($this->input->post('stuFormNo'))) : addslashes(trim($this->input->post('stuEnrlNo'))),
                    'tspi_mobile' => trim($this->input->post('stuMobile')),
                    'tspi_email' => trim($this->input->post('stuEmail')),
                    'tspi_gender' => trim($this->input->post('stuGen')),
                    'tspi_category' => trim($this->input->post('stuCategory')),
                    'tspi_religion' => trim($this->input->post('stuReligion')),
                    'tspi_dob' => (trim($this->input->post('stuDOB')) == "" ) ? NULL : date("Y-m-d", strtotime(str_replace('/', '-', $this->input->post('stuDOB')))),
                    'tspi_updated_by' => $this->session->userdata("adminData")["smember_id"],
                    'tspi_updated_on' => date("Y-m-d H:i:s"),
                    'tspi_status' => trim($this->input->post('stuStatus')),
                    'tspi_rollNumber' => (trim($this->input->post('stuRollNo') == '')) ? addslashes(trim($this->input->post('stuFormNo'))) : addslashes(trim($this->input->post('stuRollNo'))),
                    'tspi_enrollment_date' => ($this->input->post('stuEnrlDate') == "" ) ? NULL : date("Y-m-d", strtotime(str_replace('/', '-', $this->input->post('stuEnrlDate')))),
                    'tspi_univ_rollNumber' => (trim($this->input->post('stuRollNo') == '')) ? addslashes(trim($this->input->post('stuFormNo'))) : addslashes(trim($this->input->post('stuRollNo'))),
                    'tspi_admission_date' => ($this->input->post('stuAdmFormDate') == "" ) ? NULL : date("Y-m-d", strtotime(str_replace('/', '-', $this->input->post('stuAdmFormDate')))),
                    'tspi_is_diff_abled' => trim($this->input->post('stuDiffAbled')),
                    'tspi_parent_annual_income' => trim($this->input->post('stuParentIncome')),
                    'tspi_remarks' => addslashes(trim($this->input->post('stuRemarks'))),
                    'tspi_ygap_applied' => (trim($this->input->post('stuYearGap')) == "") ? NULL : trim($this->input->post('stuYearGap')),
                    'tspi_scholarship_eligible' => (trim($this->input->post('stuClgSch')) == "") ? NULL : trim($this->input->post('stuClgSch')),
                    'tspi_scholarship_percentage' => (trim($this->input->post('stuSchPercentage')) == "") ? NULL : trim($this->input->post('stuSchPercentage')),
                    'tspi_log_date' => (trim($this->input->post('stuDropOutDate')) == "" ) ? NULL : date("Y-m-d", strtotime(str_replace('/', '-', $this->input->post('stuDropOutDate')))),
                    'tspi_is_reg_fee_applicable' => trim($this->input->post('stuRegFeeApplicable'))
                );
                $studentContactInfo = array(
                    'tsci_perma_state' => trim($this->input->post('stuPermaAddrState')),
                    'tsci_perma_city' => trim($this->input->post('stuPermaAddrCity')),
                    'tsci_perma_zipcode' => trim($this->input->post('stuPermaAddrZipCode')),
                    'tsci_resid_state' => trim($this->input->post('stuMailingAddrState')),
                    'tsci_resid_city' => trim($this->input->post('stuMailingAddrCity')),
                    'tsci_resid_zipcode' => trim($this->input->post('stuMailingAddrZipCode')),
                    'tsci_parent_landline' => trim($this->input->post('stuParentLandline')),
                    'tsci_parent_mobile' => trim($this->input->post('stuParentMobile')),
                    'tsci_updated_on' => date("Y-m-d H:i:s"),
                    'tsci_updated_by' => $this->session->userdata("adminData")["smember_id"],
                    'tspi_id' => $tspi_id,
                    'tsci_perma_address_line_one' => addslashes(trim($this->input->post('stuPermaAddrLineOne'))),
                    'tsci_perma_address_line_two' => addslashes(trim($this->input->post('stuPermaAddrLineTwo'))),
                    'tsci_perma_address_line_three' => addslashes(trim($this->input->post('stuPermaAddrLineThree'))),
                    'tsci_resid_address_line_one' => addslashes(trim($this->input->post('stuMailingAddrLineOne'))),
                    'tsci_resid_address_line_two' => addslashes(trim($this->input->post('stuMailingAddrLineTwo'))),
                    'tsci_resid_address_line_three' => addslashes(trim($this->input->post('stuMailingAddrLineThree')))
                );
                $studentEntranceProfAndExtraCurricularInfo = array(
                    'tsevi_is_prof_exp' => trim($this->input->post('stuProfExp')),
                    'tsevi_no_of_years' => trim($this->input->post('stuProfExpInYears')),
                    'tsevi_organization' => addslashes(trim($this->input->post('stuProfOrgName'))),
                    'tsevi_job_desc' => addslashes(trim($this->input->post('stuProfJobDesc'))),
                    'tsevi_extra_activities' => addslashes(trim($this->input->post('stuExtraCurricularAct'))),
                    'tsevi_how_know_sms' => (trim($this->input->post('stuHowKnowSMS')) == "O") ? trim($this->input->post('stuHowKnowSMSOtherDesc')) : addslashes(trim($this->input->post('stuHowKnowSMS'))),
                    'tsevi_entrance_through' => trim($this->input->post('stuEntranceExam')),
                    'tsevi_form_no' => trim($this->input->post('stuEntranceExamRegNo')),
                    'tsevi_composite_score' => trim($this->input->post('stuEntranceExamComScore')),
                    'tsevi_percnt_obtained' => trim($this->input->post('stuEntranceExamPercentileObt')),
                    'tsevi_rank' => trim($this->input->post('stuEntranceExamRank')),
                    'tsevi_updated_on' => date("Y-m-d H:i:s"),
                    'tsevi_updated_by' => $this->session->userdata("adminData")["smember_id"],
                    'tspi_id' => $tspi_id,
                    'tsevi_percntage' => trim($this->input->post('stuEntranceExamPercentage')),
                );
                $studentHostelAndResidenceInfo = array(
                    'tshri_is_hostel_opted' => (trim($this->input->post('stuResidChoice')) == "H") ? "T" : "F",
                    'tshri_resid_choice' => trim($this->input->post('stuResidChoice')),
                    'tshri_comm_state' => trim($this->input->post('stuCommAddrState')),
                    'tshri_comm_city' => trim($this->input->post('stuCommAddrCity')),
                    'tshri_comm_zipcode' => trim($this->input->post('stuCommAddrZipCode')),
                    'tshri_comm_tel_no' => trim($this->input->post('stuCommLandline')),
                    'tshri_comm_mobile' => trim($this->input->post('stuCommMobile')),
                    'tshri_loc_guard_name' => addslashes(trim($this->input->post('stuLocGuardName'))),
                    'tshri_loc_guard_state' => trim($this->input->post('stuLocGuardAddrState')),
                    'tshri_loc_guard_city' => trim($this->input->post('stuLocGuardAddrCity')),
                    'tshri_loc_guard_tel_no' => trim($this->input->post('stuLocGuardLandline')),
                    'tshri_loc_guard_mob' => trim($this->input->post('stuLocGuardMobile')),
                    'tshri_updated_on' => date("Y-m-d H:i:s"),
                    'tshri_updated_by' => $this->session->userdata("adminData")["smember_id"],
                    'tspi_id' => $tspi_id,
                    'tshri_loc_guard_zipcode' => addslashes(trim($this->input->post('stuLocGuardAddrZipCode'))),
                    'tshri_comm_address_line_one' => addslashes(trim($this->input->post('stuCommAddrLineOne'))),
                    'tshri_comm_address_line_two' => addslashes(trim($this->input->post('stuCommAddrLineTwo'))),
                    'tshri_comm_address_line_three' => addslashes(trim($this->input->post('stuCommAddrLineThree'))),
                    'tshri_loc_guard_address_line_one' => addslashes(trim($this->input->post('stuLocGuardAddrLineOne'))),
                    'tshri_loc_guard_address_line_two' => addslashes(trim($this->input->post('stuLocGuardAddrLineTwo'))),
                    'tshri_loc_guard_address_line_three' => addslashes(trim($this->input->post('stuLocGuardAddrLineThree')))
                );
                $studentAadharInfo = array(
                    'tipi_id' => trim($this->input->post('stuAadharInfoId')),
                    'tipi_number' => trim($this->input->post('stuAadharNo')),
                    'tipi_updated_on' => date("Y-m-d H:i:s"),
                    'tipi_updated_by' => $this->session->userdata("adminData")["smember_id"],
                );
                $studentPANInfo = array(
                    'tipi_id' => trim($this->input->post('stuPANInfoId')),
                    'tipi_number' => trim($this->input->post('stuPAN')),
                    'tipi_updated_on' => date("Y-m-d H:i:s"),
                    'tipi_updated_by' => $this->session->userdata("adminData")["smember_id"],
                );
                $studentCSTCInfo = array(
                    'tipi_id' => trim($this->input->post('stuCSTCInfoId')),
                    'tipi_number' => trim($this->input->post('stuCSTCNumber')),
                    'tipi_updated_on' => date("Y-m-d H:i:s"),
                    'tipi_updated_by' => $this->session->userdata("adminData")["smember_id"],
                );
                $studentAICInfo = array(
                    'tipi_id' => trim($this->input->post('stuAICInfoId')),
                    'tipi_number' => trim($this->input->post('stuAICNumber')),
                    'tipi_updated_on' => date("Y-m-d H:i:s"),
                    'tipi_updated_by' => $this->session->userdata("adminData")["smember_id"],
                );
                $studentIdProofInfo = array($studentAadharInfo, $studentPANInfo, $studentCSTCInfo, $studentAICInfo);
                $studentFamilyBackgroundInfoUpdate = array();
                $studentFamilyBackgroundInfoCreate = array();
                $studentFamilyBGIds = $this->input->post('famBGId');
                $studentFamilyBGName = $this->input->post('stuFamBGName');
                $studentFamilyBGDesig = $this->input->post('stuFamBGDesignation');
                $studentFamilyBGOrg = $this->input->post('stuFamBGOrganization');
                $studentFamilyBGRel = $this->input->post('stuFamBGRelation');
                for ($i = 0; $i < 3; $i++) {
                    if ($studentFamilyBGIds[$i] == "-1" || $studentFamilyBGIds[$i] == -1) {
                        $thisFamilyBGInfo = array(
                            'tfbi_relation' => trim($studentFamilyBGRel[$i]),
                            'tfbi_name' => addslashes(trim($studentFamilyBGName[$i])),
                            'tfbi_organization' => addslashes(trim($studentFamilyBGOrg[$i])),
                            'tfbi_designation' => addslashes(trim($studentFamilyBGDesig[$i])),
                            'tfbi_user_type_flag' => 'S',
                            'tfbi_mapping_id' => '',
                            'tfbi_added_on' => date("Y-m-d H:i:s"),
                            'tfbi_updated_on' => date("Y-m-d H:i:s"),
                            'tfbi_added_by' => $this->session->userdata("adminData")["smember_id"],
                            'tfbi_updated_by' => $this->session->userdata("adminData")["smember_id"]
                        );
                        array_push($studentFamilyBackgroundInfoCreate, $thisFamilyBGInfo);
                    } else {
                        $thisFamilyBGInfo = array(
                            'tfbi_id' => $studentFamilyBGIds[$i],
                            'tfbi_relation' => trim($studentFamilyBGRel[$i]),
                            'tfbi_name' => addslashes(trim($studentFamilyBGName[$i])),
                            'tfbi_organization' => addslashes(trim($studentFamilyBGOrg[$i])),
                            'tfbi_designation' => addslashes(trim($studentFamilyBGDesig[$i])),
                            'tfbi_mapping_id' => $tspi_id,
                            'tfbi_updated_on' => date("Y-m-d H:i:s"),
                            'tfbi_updated_by' => $this->session->userdata("adminData")["smember_id"]
                        );
                        array_push($studentFamilyBackgroundInfoUpdate, $thisFamilyBGInfo);
                    }
                }
                $studentFatherFamBGInfo = array(
                    'tfbi_id' => $this->input->post('stuFatherFamBGId'),
                    'tfbi_name' => addslashes(trim($this->input->post('stuFatherName'))),
                    'tfbi_mapping_id' => $tspi_id,
                    'tfbi_updated_on' => date("Y-m-d H:i:s"),
                    'tfbi_updated_by' => $this->session->userdata("adminData")["smember_id"]
                );
                $studentMotherFamBGInfo = array(
                    'tfbi_id' => $this->input->post('stuMotherFamBGId'),
                    'tfbi_name' => addslashes(trim($this->input->post('stuMotherName'))),
                    'tfbi_mapping_id' => $tspi_id,
                    'tfbi_updated_on' => date("Y-m-d H:i:s"),
                    'tfbi_updated_by' => $this->session->userdata("adminData")["smember_id"]
                );
                array_push($studentFamilyBackgroundInfoUpdate, $studentFatherFamBGInfo);
                array_push($studentFamilyBackgroundInfoUpdate, $studentMotherFamBGInfo);
                $studentEducationQualificatioInfoUpdate = array();
                $studentEduQualiInfoIds = $this->input->post('stuEduQualiInfoId');
                $studentEduQualiBoardUniv = $this->input->post('stuEduQualiBoardUniv');
                $studentEduQualiStream = $this->input->post('stuEduQualiStream');
                $studentEduQualiYearOfExam = $this->input->post('stuEduQualiYearOfExam');
                $studentEduQualiMaxMarks = $this->input->post('stuEduQualiMaxMarks');
                $studentEduQualiMarksObtnd = $this->input->post('stuEduQualiMarksObt');
                $studentEduQualiPrcntObtnd = $this->input->post('stuEduQualiPercntCGPA');
                $studentEduQualiDiv = $this->input->post('stuEduQualiDiv');
                $totalEduQualisInfo = sizeof($studentEduQualiInfoIds);
                for ($i = 0; $i < $totalEduQualisInfo; $i++) {
                    $thisEduQualiInfo = array(
                        'tesi_id' => $studentEduQualiInfoIds[$i],
                        'tesi_board' => $studentEduQualiBoardUniv[$i],
                        'tesi_university' => $studentEduQualiBoardUniv[$i],
                        'tesi_stream' => $studentEduQualiStream[$i],
                        'tesi_passing_year' => $studentEduQualiYearOfExam[$i],
                        'tesi_percnt' => $studentEduQualiPrcntObtnd[$i],
                        'tesi_cgpa' => $studentEduQualiMarksObtnd[$i],
                        'tesi_division' => $studentEduQualiDiv[$i],
                        'tesi_updated_on' => date("Y-m-d H:i:s"),
                        'tesi_updated_by' => $this->session->userdata("adminData")["smember_id"],
                        'tspi_id' => $tspi_id,
                        'tesi_max_marks_cgpa' => $studentEduQualiMaxMarks[$i]
                    );
                    array_push($studentEducationQualificatioInfoUpdate, $thisEduQualiInfo);
                }
                $this->load->library('upload');
                $studentDocumentInfoCreate = array();
                $studentDocumentInfoUpdate = array();
                if (!empty($_FILES['stuPhotograph']['name'])) {
                    $studentImg['upload_path'] = './assets/admin/uploads/studentData/';
                    $studentImg['allowed_types'] = 'jpeg|jpg|png';
                    $studentImg['max_size'] = '500';
                    $studentImg['file_ext_tolower'] = TRUE;
                    $studentImg['encrypt_name'] = TRUE;
                    $this->upload->initialize($studentImg);
                    if (!$this->upload->do_upload('stuPhotograph')) {
                        $this->session->set_flashdata('errorMessage', "Student Photo Can Not Be Uploaded As It Violates Upload File Criteria. File Size 500 KB Max. & Allowed Extension: Only *.png,*.jpg,*.jpeg.");
                        $this->editStudent($tspi_id);
                    } else {
                        if (file_exists("./assets/admin/uploads/studentData/" . trim($this->input->post('stuPhotoPrevFile'))) && (trim($this->input->post('stuPhotoPrevFile')) != "picnotavail.jpg")) {
                            unlink("./assets/admin/uploads/studentData/" . trim($this->input->post('stuPhotoPrevFile')));
                        }
                        $studentPhotoInfo = array(
                            'tddi_id' => $this->input->post('stuPhotoDocInfoId'),
                            'tddi_doc_file_path' => $this->upload->data()['file_name'],
                            'tddi_user_type_flag' => 'S',
                            'tddi_mapping_id' => $tspi_id,
                            'tddi_semester' => 'NA',
                            'ucs_map_id' => trim($this->input->post('stuEntryType')),
                            'tddi_updated_on' => date("Y-m-d H:i:s"),
                            'tddi_updated_by' => $this->session->userdata("adminData")["smember_id"]
                        );
                        array_push($studentDocumentInfoUpdate, $studentPhotoInfo);
                    }
                }
                if (!empty($_FILES['stuSignature']['name'])) {
                    $studentSignImg['upload_path'] = './assets/admin/uploads/studentData/';
                    $studentSignImg['allowed_types'] = 'jpeg|jpg|png';
                    $studentSignImg['max_size'] = '500';
                    $studentSignImg['file_ext_tolower'] = TRUE;
                    $studentSignImg['encrypt_name'] = TRUE;
                    $this->upload->initialize($studentSignImg);
                    if (!$this->upload->do_upload('stuSignature')) {
                        $this->session->set_flashdata('errorMessage', "Student Signature Can Not Be Uploaded As It Violates Upload File Criteria. File Size 500 KB Max. & Allowed Extension: Only *.png,*.jpg,*.jpeg.");
                        $this->editStudent($tspi_id);
                    } else {
                        if (file_exists("./assets/admin/uploads/studentData/" . trim($this->input->post('stuSignPrevFile'))) && (trim($this->input->post('stuSignPrevFile')) != "signnotavail.png")) {
                            unlink("./assets/admin/uploads/studentData/" . trim($this->input->post('stuSignPrevFile')));
                        }
                        $studentSignInfo = array(
                            'tddi_id' => $this->input->post('stuSignDocInfoId'),
                            'tddi_doc_file_path' => $this->upload->data()['file_name'],
                            'tddi_user_type_flag' => 'S',
                            'tddi_mapping_id' => $tspi_id,
                            'tddi_semester' => 'NA',
                            'ucs_map_id' => trim($this->input->post('stuEntryType')),
                            'tddi_updated_on' => date("Y-m-d H:i:s"),
                            'tddi_updated_by' => $this->session->userdata("adminData")["smember_id"]
                        );
                        array_push($studentDocumentInfoUpdate, $studentSignInfo);
                    }
                }
                $submittedDocuments = $this->input->post('stuDocumentFileId');
                $docInfoIds = $this->input->post('docInfoId');
                $docPrevFile = $this->input->post('docPrevFile');
                for ($i = 0; $i < sizeof($submittedDocuments); $i++) {
                    if ($docInfoIds[$i] == "-1" || $docInfoIds[$i] == -1) {
                        $doc_id = $submittedDocuments[$i];
                        $thisFileInputName = "stuDocumentFile" . $doc_id;
                        $ifNotApplicable = ($this->input->post("stuDocumentFileApplicable" . $doc_id) != NULL) ? 1 : 0;
                        if ($ifNotApplicable) {
                            $thisDocumentInfo = array(
                                'tddi_doc_id' => $submittedDocuments[$i],
                                'tddi_doc_file_path' => "na.png",
                                'tddi_code' => $submittedDocuments[$i],
                                'tddi_user_type_flag' => 'S',
                                'tddi_mapping_id' => $tspi_id,
                                'tddi_semester' => 'NA',
                                'ucs_map_id' => trim($this->input->post('stuEntryType')),
                                'tddi_added_on' => date("Y-m-d H:i:s"),
                                'tddi_updated_on' => date("Y-m-d H:i:s"),
                                'tddi_added_by' => $this->session->userdata("adminData")["smember_id"],
                                'tddi_updated_by' => $this->session->userdata("adminData")["smember_id"]
                            );
                            array_push($studentDocumentInfoCreate, $thisDocumentInfo);
                        } else {
                            if (!empty($_FILES[$thisFileInputName]['name'])) {
                                $studentDocFile['upload_path'] = './assets/admin/uploads/studentData/';
                                $studentDocFile['allowed_types'] = 'pdf|jpeg|jpg|png';
                                $studentDocFile['max_size'] = '4096';
                                $studentDocFile['file_ext_tolower'] = TRUE;
                                $studentDocFile['encrypt_name'] = TRUE;
                                $this->upload->initialize($studentDocFile);
                                if (!$this->upload->do_upload($thisFileInputName)) {
                                    $this->session->set_flashdata('errorMessage', "Any Of The Uploaded Document File Violates Document Upload File Criteria. File Size 4 MB Max. & Allowed Extension: Only *.png,*.jpg,*.jpeg,*.pdf.");
                                    $this->editStudent($tspi_id);
                                } else {
                                    $thisDocumentInfo = array(
                                        'tddi_doc_id' => $submittedDocuments[$i],
                                        'tddi_doc_file_path' => $this->upload->data()['file_name'],
                                        'tddi_code' => $submittedDocuments[$i],
                                        'tddi_user_type_flag' => 'S',
                                        'tddi_mapping_id' => $tspi_id,
                                        'tddi_semester' => 'NA',
                                        'ucs_map_id' => trim($this->input->post('stuEntryType')),
                                        'tddi_added_on' => date("Y-m-d H:i:s"),
                                        'tddi_updated_on' => date("Y-m-d H:i:s"),
                                        'tddi_added_by' => $this->session->userdata("adminData")["smember_id"],
                                        'tddi_updated_by' => $this->session->userdata("adminData")["smember_id"]
                                    );
                                    array_push($studentDocumentInfoCreate, $thisDocumentInfo);
                                }
                            }
                        }
                    } else {
                        $doc_id = $submittedDocuments[$i];
                        $thisFileInputName = "stuDocumentFile" . $doc_id;
                        $ifNotApplicable = ($this->input->post("stuDocumentFileApplicable" . $doc_id) != NULL) ? 1 : 0;
                        if ($ifNotApplicable) {
                            $thisDocumentInfo = array(
                                'tddi_id' => $docInfoIds[$i],
                                'tddi_doc_file_path' => "na.png",
                                'tddi_mapping_id' => $tspi_id,
                                'ucs_map_id' => trim($this->input->post('stuEntryType')),
                                'tddi_updated_on' => date("Y-m-d H:i:s"),
                                'tddi_updated_by' => $this->session->userdata("adminData")["smember_id"]
                            );
                            if ($docPrevFile[$i] != "na.png") {
                                if (file_exists("./assets/admin/uploads/studentData/" . trim($docPrevFile[$i]))) {
                                    unlink("./assets/admin/uploads/studentData/" . trim($docPrevFile[$i]));
                                }
                            }
                            array_push($studentDocumentInfoUpdate, $thisDocumentInfo);
                        } else {
                            if (!empty($_FILES[$thisFileInputName]['name'])) {
                                $studentDocFile['upload_path'] = './assets/admin/uploads/studentData/';
                                $studentDocFile['allowed_types'] = 'pdf|jpeg|jpg|png';
                                $studentDocFile['max_size'] = '4096';
                                $studentDocFile['file_ext_tolower'] = TRUE;
                                $studentDocFile['encrypt_name'] = TRUE;
                                $this->upload->initialize($studentDocFile);
                                if (!$this->upload->do_upload($thisFileInputName)) {
                                    $this->session->set_flashdata('errorMessage', "Any Of The Uploaded Document File Violates Document Upload File Criteria. File Size 4 MB Max. & Allowed Extension: Only *.png,*.jpg,*.jpeg,*.pdf.");
                                    $this->editStudent($tspi_id);
                                } else {
                                    $thisDocumentInfo = array(
                                        'tddi_id' => $docInfoIds[$i],
                                        'tddi_doc_file_path' => $this->upload->data()['file_name'],
                                        'tddi_mapping_id' => $tspi_id,
                                        'ucs_map_id' => trim($this->input->post('stuEntryType')),
                                        'tddi_updated_on' => date("Y-m-d H:i:s"),
                                        'tddi_updated_by' => $this->session->userdata("adminData")["smember_id"]
                                    );
                                    if ($docPrevFile[$i] != "na.png") {
                                        if (file_exists("./assets/admin/uploads/studentData/" . trim($docPrevFile[$i]))) {
                                            unlink("./assets/admin/uploads/studentData/" . trim($docPrevFile[$i]));
                                        }
                                    }
                                    array_push($studentDocumentInfoUpdate, $thisDocumentInfo);
                                }
                            }
                        }
                    }
                }
                $this->db->trans_start();
                $this->StudentManagement->updateStudentPersonalInfo($studentPersonalInfo);
                $this->StudentManagement->updateStudentContactInfo($studentContactInfo);
                $this->StudentManagement->updateStudentEntranceExamProfExpAndExtraCurricularInfo($studentEntranceProfAndExtraCurricularInfo);
                $this->StudentManagement->updateHostelAndResidenceInfo($studentHostelAndResidenceInfo);
                $this->StudentManagement->updateFamilyBackgroundInfoMulti($studentFamilyBackgroundInfoUpdate);
                $this->IDProofManagement->updateIDProofInfoMulti($studentIdProofInfo);
                if (sizeof($studentFamilyBackgroundInfoCreate)) {
                    $this->StudentManagement->createNewStudentFamilyBackgroundInfoMulti($studentFamilyBackgroundInfoCreate);
                }
                $this->StudentManagement->updateStudentEducationalQualificationInfoMulti($studentEducationQualificatioInfoUpdate);
                if (sizeof($studentDocumentInfoUpdate)) {
                    $this->DocumentInfoManagement->updateStudentDocumentInfoMulti($studentDocumentInfoUpdate);
                }
                if (sizeof($studentDocumentInfoCreate)) {
                    $this->DocumentInfoManagement->createNewDocumentInfoMulti($studentDocumentInfoCreate);
                }
                /* Identification & Setting Of Fee Structure Of Student Goes Here */
                if (trim($this->input->post('stuStatus')) == "DV") {
                    if (!sizeof($this->FeeManagement->getFeeStructureOfStudentBy($tspi_id)->result())) {
                        $toCreateFeeStructureInfo = array();
                        if (trim($this->input->post('stuGen')) == "F") {
                            $eligibleStructureForPayment = $this->FeeManagement->getFeeStructureForFeePaymentBy('', trim($this->input->post('stuEntryType')), '', "Female")->result();
                            if (sizeof($eligibleStructureForPayment)) {
                                for ($dFeeStruct = 0; $dFeeStruct < sizeof($eligibleStructureForPayment); $dFeeStruct++) {
                                    $thisFeeStructure = $eligibleStructureForPayment[$dFeeStruct];
                                    $amount = "";
                                    if (trim($this->input->post('stuRegFeeApplicable')) == "F") {
                                        $amount = (strcasecmp("REGISTRATION FEE", strtoupper(stripslashes($thisFeeStructure->fhm_name))) == 0) ? "0.0" : $thisFeeStructure->fsm_amount;
                                    } else {
                                        $amount = $thisFeeStructure->fsm_amount;
                                    }
                                    array_push($toCreateFeeStructureInfo, array(
                                        'course_id' => trim($this->input->post('stuCourse')),
                                        'ucs_map_id' => trim($this->input->post('stuEntryType')),
                                        'session_id' => trim($this->input->post('stuSession')),
                                        'fhm_id' => $thisFeeStructure->fhm_id,
                                        'fssm_semester' => $thisFeeStructure->fsm_semester,
                                        'fssm_amount' => $amount,
                                        'fssm_remarks' => "This Structure Is Automatically Set After Document Verification",
                                        'tspi_id' => $tspi_id,
                                        'fssm_added_by' => $this->session->userdata("adminData")["smember_id"],
                                        'fssm_added_on' => date("Y-m-d H:i:s"),
                                        'fssm_updated_by' => $this->session->userdata("adminData")["smember_id"],
                                        'fssm_updated_on' => date("Y-m-d H:i:s")
                                    ));
                                }
                            }
                        } else {
                            $eligibleStructureForPayment = $this->FeeManagement->getFeeStructureForFeePaymentBy('', trim($this->input->post('stuEntryType')), '', trim($this->input->post('stuCategory')))->result();
                            if (sizeof($eligibleStructureForPayment)) {
                                for ($dFeeStruct = 0; $dFeeStruct < sizeof($eligibleStructureForPayment); $dFeeStruct++) {
                                    $thisFeeStructure = $eligibleStructureForPayment[$dFeeStruct];
                                    $amount = "";
                                    if (trim($this->input->post('stuRegFeeApplicable')) == "F") {
                                        $amount = (strcasecmp("REGISTRATION FEE", strtoupper(stripslashes($thisFeeStructure->fhm_name))) == 0) ? "0.0" : $thisFeeStructure->fsm_amount;
                                    } else {
                                        $amount = $thisFeeStructure->fsm_amount;
                                    }
                                    array_push($toCreateFeeStructureInfo, array(
                                        'course_id' => trim($this->input->post('stuCourse')),
                                        'ucs_map_id' => trim($this->input->post('stuEntryType')),
                                        'session_id' => trim($this->input->post('stuSession')),
                                        'fhm_id' => $thisFeeStructure->fhm_id,
                                        'fssm_semester' => $thisFeeStructure->fsm_semester,
                                        'fssm_amount' => $amount,
                                        'fssm_remarks' => "This Structure Is Automatically Set After Document Verification",
                                        'tspi_id' => $tspi_id,
                                        'fssm_added_by' => $this->session->userdata("adminData")["smember_id"],
                                        'fssm_added_on' => date("Y-m-d H:i:s"),
                                        'fssm_updated_by' => $this->session->userdata("adminData")["smember_id"],
                                        'fssm_updated_on' => date("Y-m-d H:i:s")
                                    ));
                                }
                            }
                        }
                        /* Creating The Set Structure For Student */
                        if (sizeof($toCreateFeeStructureInfo)) {
                            $this->FeeManagement->createNewFeeStructureOfStudentMulti($toCreateFeeStructureInfo);
                        } else {
                            $this->session->set_flashdata('errorMessage', 'Student Fee Structure Has Not Been Setup As Default Fee Structure Was Not Found As To Course/Session/Gender/Category Of This Student.');
                        }
                    }
                }
                /* Identification & Setting Of Fee Structure Of Student Ends Here */
                $this->db->trans_complete();
                if (($this->input->post('saveAndMove')) !== NULL) {
                    $this->session->set_flashdata('successMessage', 'Student Info Updated Successfully.');
                    redirect("admin/Student/");
                } else {
                    $this->session->set_flashdata('successMessage', 'Student Info Updated Successfully.');
                    redirect("admin/Student/editStudent/" . $tspi_id);
                }
            }
        } else {
            redirect("admin/");
        }
    }

    public function updateSectionSemesterRollNumber() {
        if ($this->sessionvalidator->isLoggedIn() && $this->sessionvalidator->isAccessGranted()) {
            if (isset($_POST['updateSubmitBtn'])) {
                if (empty($_FILES['bulkSecSemRollNoFile']['name'])) {
                    $this->session->set_flashdata('errorMessage', "Please Upload Any CSV File.");
                    redirect("admin/Student/updateSectionSemesterRollNumber");
                } else {
                    $bulkSecSemRollNoFileNameWithPath = "";
                    $configBulkFile['upload_path'] = './assets/admin/uploads/bulkfiles/clgsecsemrollnos/';
                    $configBulkFile['allowed_types'] = 'csv';
                    $configBulkFile['max_size'] = '1024';
                    $configBulkFile['file_ext_tolower'] = TRUE;
                    $configBulkFile['encrypt_name'] = TRUE;
                    $this->load->library('upload', $configBulkFile);
                    if (!$this->upload->do_upload('bulkSecSemRollNoFile')) {
                        $this->session->set_flashdata('errorMessage', "Error! Only CSV Files With Max. Size 1MB Is Allowed.");
                        redirect("admin/Student/updateSectionSemesterRollNumber");
                    } else {
                        $bulkSecSemRollNoFileNameWithPath = base_url("assets/admin/uploads/bulkfiles/clgsecsemrollnos/" . $this->upload->data()['file_name']);
                        $csvFileContent = $this->csvhandler->readCSV($bulkSecSemRollNoFileNameWithPath);
                        if (trim($csvFileContent[0][0]) == "FORM_NO" && trim($csvFileContent[0][1]) == "ROLL_NO" && trim($csvFileContent[0][2]) == "SEMESTER" && trim($csvFileContent[0][3]) == "SECTION") {
                            $studentRollNumberFormNumberArray = array();
                            $studentSectionSemesterArray = array();
                            $notFoundFormNumbers = array("Not Found Form Numbers");
                            $alreadyExistingRollNumbersForFormNumbers = array("Already Exisiting Roll Numbers");
                            $notUpdatedSectionSemesterFormNumbers = array("Not Updated Section/Semester Info");
                            for ($i = 1; $i < sizeof($csvFileContent); $i++) {
                                $studentInfo = $this->StudentManagement->getStudentPersonalInfoByFormNumber(trim($csvFileContent[$i][0]))->result();
                                if (sizeof($studentInfo)) {
                                    $section = (trim($csvFileContent[$i][3]) == "") ? "NA" : trim($csvFileContent[$i][3]);
                                    $semester = (trim($csvFileContent[$i][2]) == "") ? "0" : trim($csvFileContent[$i][2]);
                                    $formNumberInfo = array(
                                        'tspi_id' => $studentInfo[0]->tspi_id,
                                        'tspi_enrollment_no' => trim($csvFileContent[$i][1]),
                                        'tspi_rollNumber' => trim($csvFileContent[$i][1]),
                                        'tspi_updated_by' => $this->session->userdata("adminData")["smember_id"],
                                        'tspi_updated_on' => date("Y-m-d H:i:s")
                                    );
                                    $sectionSemesterInfo = array(
                                        'tsssi_semester' => $semester,
                                        'tsssi_section' => $section,
                                        'tsssi_updated_on' => date("Y-m-d H:i:s"),
                                        'tsssi_updated_by' => $this->session->userdata("adminData")["smember_id"],
                                        'tspi_id' => $studentInfo[0]->tspi_id
                                    );
                                    if ($this->StudentManagement->isRollNumberSafeUpdate($studentInfo[0]->tspi_id, trim($csvFileContent[$i][1]))) {
                                        array_push($studentRollNumberFormNumberArray, $formNumberInfo);
                                        if (!sizeof($this->StudentManagement->getStudentSectionSemesterInfoBy($studentInfo[0]->tspi_id, $section, $semester)->result())) {
                                            array_push($studentSectionSemesterArray, $sectionSemesterInfo);
                                        } else {
                                            array_push($notUpdatedSectionSemesterFormNumbers, trim($csvFileContent[$i][0]));
                                        }
                                    } else {
                                        array_push($alreadyExistingRollNumbersForFormNumbers, "Form No:" . trim($csvFileContent[$i][0]) . " Roll No.:" . trim($csvFileContent[$i][1]));
                                    }
                                } else {
                                    array_push($notFoundFormNumbers, trim($csvFileContent[$i][0]));
                                }
                            }
                            $this->db->trans_start();
                            if (sizeof($studentRollNumberFormNumberArray)) {
                                $this->StudentManagement->updateStudentPersonalInfoMulti($studentRollNumberFormNumberArray);
                            }
                            if (sizeof($studentSectionSemesterArray)) {
                                $this->StudentManagement->createNewStudentSectionSemesterInfoMulti($studentSectionSemesterArray);
                            }
                            $this->db->trans_complete();
                            $totalNotUpdatedRollNumbers = (sizeof($alreadyExistingRollNumbersForFormNumbers) - 1) + (sizeof($notFoundFormNumbers) - 1);
                            $totalNotUpdatedSecSemInfo = (sizeof($notUpdatedSectionSemesterFormNumbers) - 1);
                            $totalUpdatedRollNumbers = (((sizeof($csvFileContent) - 1) - $totalNotUpdatedRollNumbers) < 0 ) ? 0 : ((sizeof($csvFileContent) - 1) - $totalNotUpdatedRollNumbers);
                            if ($totalNotUpdatedRollNumbers + $totalNotUpdatedSecSemInfo) {
                                $errorFileNameWithPath = "./assets/admin/downloads/errorfiles/notupdatedrollsecsems/notupdatedsecsemrollnos_" . date("d_m_Y_h_i_s_a") . ".csv";
                                $this->filehandler->createFile($errorFileNameWithPath, "All Form Numbers Where Either Roll Numbers Or Section Semester Info Has Not Been Updated");
                                $this->csvhandler->writeCSV($errorFileNameWithPath, $notFoundFormNumbers, true);
                                $this->csvhandler->writeCSV($errorFileNameWithPath, $alreadyExistingRollNumbersForFormNumbers, false);
                                $this->csvhandler->writeCSV($errorFileNameWithPath, $notUpdatedSectionSemesterFormNumbers, false);
                                $this->session->set_flashdata('successMessage', $totalUpdatedRollNumbers . ' Roll Number(s) Has Been Updated.');
                                $this->session->set_flashdata('errorMessage', $totalNotUpdatedRollNumbers . " Roll Number(s) And " . $totalNotUpdatedSecSemInfo . " Section/Semester Info Has Not Been Updated. Click <a href='" . base_url($errorFileNameWithPath) . "'>Here To Download <i class='fa fa-download'></i></a> Error File.");
                            } else {
                                $this->session->set_flashdata('successMessage', $totalUpdatedRollNumbers . ' Roll Number(s) (All) Has Been Updated.');
                            }
                            redirect("admin/Student/updateSectionSemesterRollNumber");
                        } else {
                            $this->session->set_flashdata('errorMessage', "Error! Uploaded CSV Contains Invalid Column Name(s)/No. Of Columns.");
                            redirect("admin/Student/updateSectionSemesterRollNumber");
                        }
                    }
                }
            } else {
                $this->load->view('admin/student/updateSecSemRoll');
            }
        } else {
            redirect("admin/");
        }
    }

    public function updateUniversityRollNumber() {
        if ($this->sessionvalidator->isLoggedIn() && $this->sessionvalidator->isAccessGranted()) {
            if (isset($_POST['updateSubmitBtn'])) {
                if (empty($_FILES['bulkUnivRollNoFile']['name'])) {
                    $this->session->set_flashdata('errorMessage', "Please Upload Any CSV File.");
                    redirect("admin/Student/updateUniversityRollNumber");
                } else {
                    $bulkUniversityRollNoFileNameWithPath = "";
                    $configBulkFile['upload_path'] = './assets/admin/uploads/bulkfiles/universityrollnos/';
                    $configBulkFile['allowed_types'] = 'csv';
                    $configBulkFile['max_size'] = '1024';
                    $configBulkFile['file_ext_tolower'] = TRUE;
                    $configBulkFile['encrypt_name'] = TRUE;
                    $this->load->library('upload', $configBulkFile);
                    if (!$this->upload->do_upload('bulkUnivRollNoFile')) {
                        $this->session->set_flashdata('errorMessage', "Error! Only CSV Files With Max. Size 1MB Is Allowed.");
                        redirect("admin/Student/updateUniversityRollNumber");
                    } else {
                        $bulkUniversityRollNoFileNameWithPath = base_url("assets/admin/uploads/bulkfiles/universityrollnos/" . $this->upload->data()['file_name']);
                        $csvFileContent = $this->csvhandler->readCSV($bulkUniversityRollNoFileNameWithPath);
                        if (trim($csvFileContent[0][0]) == "COLLEGE_ROLL_NO" && trim($csvFileContent[0][1]) == "UNIV_ROLL_NO") {
                            $studentUnivRollNumberClgRollNoArray = array();
                            $notFoundCollegeRollNumbers = array("Not Found College Roll Numbers");
                            $alreadyExistingUnivRollNumbersForCollegeRollNumbers = array("Already Existing University Roll Numbers");
                            for ($i = 1; $i < sizeof($csvFileContent); $i++) {
                                $studentInfo = $this->StudentManagement->getStudentPersonalInfoByRollNumber(trim($csvFileContent[$i][0]))->result();
                                if (sizeof($studentInfo)) {
                                    $univRollNumberUpdateInfo = array(
                                        'tspi_id' => $studentInfo[0]->tspi_id,
                                        'tspi_univ_rollNumber' => trim($csvFileContent[$i][1]),
                                        'tspi_updated_by' => $this->session->userdata("adminData")["smember_id"],
                                        'tspi_updated_on' => date("Y-m-d H:i:s")
                                    );
                                    if ($this->StudentManagement->isUniversityRollNumberSafeUpdate($studentInfo[0]->tspi_id, trim($csvFileContent[$i][1]))) {
                                        array_push($studentUnivRollNumberClgRollNoArray, $univRollNumberUpdateInfo);
                                    } else {
                                        array_push($alreadyExistingUnivRollNumbersForCollegeRollNumbers, "Clg. Roll No:" . trim($csvFileContent[$i][0]) . " Univ. Roll No.:" . trim($csvFileContent[$i][1]));
                                    }
                                } else {
                                    array_push($notFoundCollegeRollNumbers, trim($csvFileContent[$i][0]));
                                }
                            }
                            $this->db->trans_start();
                            if (sizeof($studentUnivRollNumberClgRollNoArray)) {
                                $this->StudentManagement->updateStudentPersonalInfoMulti($studentUnivRollNumberClgRollNoArray);
                            }
                            $this->db->trans_complete();
                            $totalNotUpdatedRollNumbers = (sizeof($alreadyExistingUnivRollNumbersForCollegeRollNumbers) - 1) + (sizeof($notFoundCollegeRollNumbers) - 1);
                            $totalUpdatedUnivRollNumbers = (((sizeof($csvFileContent) - 1) - $totalNotUpdatedRollNumbers) < 0 ) ? 0 : ((sizeof($csvFileContent) - 1) - $totalNotUpdatedRollNumbers);
                            if ($totalNotUpdatedRollNumbers) {
                                $errorFileNameWithPath = "./assets/admin/downloads/errorfiles/notupdatedunivrollnos/notupdatedunivrollnos_" . date("d_m_Y_h_i_s_a") . ".csv";
                                $this->filehandler->createFile($errorFileNameWithPath, "All College Roll Numbers Where University Roll Numbers Has Not Been Updated");
                                $this->csvhandler->writeCSV($errorFileNameWithPath, $notFoundCollegeRollNumbers, true);
                                $this->csvhandler->writeCSV($errorFileNameWithPath, $alreadyExistingUnivRollNumbersForCollegeRollNumbers, false);
                                $this->session->set_flashdata('successMessage', $totalUpdatedUnivRollNumbers . ' University Roll Number(s) Has Been Updated.');
                                $this->session->set_flashdata('errorMessage', $totalNotUpdatedRollNumbers . " University Roll Number(s) Has Not Been Updated. Click <a href='" . base_url($errorFileNameWithPath) . "'>Here To Download <i class='fa fa-download'></i></a> Error File.");
                            } else {
                                $this->session->set_flashdata('successMessage', $totalUpdatedUnivRollNumbers . ' University Roll Number(s) (All) Has Been Updated.');
                            }
                            redirect("admin/Student/updateUniversityRollNumber");
                        } else {
                            $this->session->set_flashdata('errorMessage', "Error! Uploaded CSV Contains Invalid Column Name(s)/No. Of Columns.");
                            redirect("admin/Student/updateUniversityRollNumber");
                        }
                    }
                }
            } else {
                $this->load->view('admin/student/updateUniversityRollNo');
            }
        } else {
            redirect("admin/");
        }
    }

    public function getSemesterOrYearInfo($tspi_id = '') {
        if ($this->sessionvalidator->isLoggedIn() && $this->sessionvalidator->isAccessGranted()) {
            $selectedPattern = "";
            $studentData = array();
            $studentSemesterInfo = array();
            if (isset($_POST['fetchStudentInfo'])) {
                $formEnrlRollNo = addslashes(trim($this->input->post('formEnrlRollNo')));
                if ($formEnrlRollNo != "") {
                    $this->session->set_flashdata('errorMessage', NULL);
                    $studentData = $this->StudentManagement->getStudentInfoByFormEnrollmentOrRollNo($formEnrlRollNo)->result();
                    if (sizeof($studentData)) {
                        $student_info = $studentData[0];
                        $studentFatherName = $this->StudentManagement->getStudentFatherInfoBy($student_info->tspi_id)->result()[0]->tfbi_name;
                        $gender = "";
                        $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";
                        }
                        $studentData = 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_category' => stripslashes($student_info->tspi_category),
                            'stu_religion' => stripslashes($student_info->tspi_religion),
                            'stu_email' => stripslashes($student_info->tspi_email),
                            'stu_mobile' => stripslashes($student_info->tspi_mobile),
                            'stu_diff_abled' => ($student_info->tspi_is_diff_abled == "T") ? "Yes <i class='fa fa-wheelchair'></i>" : "No",
                            'stu_course' => stripslashes($student_info->course_name),
                            'stu_max_sem_year' => stripslashes($student_info->course_no_of_sems),
                            '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,
                        );
                        $studentSemesterInfo = $this->StudentManagement->getStudentAllSemesterInfoBy($student_info->tspi_id)->result();
                    }
                } else {
                    $this->session->set_flashdata('errorMessage', "Enter Form No./Enrl. No./Roll No. Of Student.");
                    $studentData = array();
                }
            } else if ($tspi_id != '') {
                $this->session->set_flashdata('errorMessage', NULL);
                $studentData = $this->StudentManagement->getStudentPersonalInfoAndPhotoSignBy($tspi_id)->result();
                if (sizeof($studentData)) {
                    $student_info = $studentData[0];
                    $studentFatherName = $this->StudentManagement->getStudentFatherInfoBy($student_info->tspi_id)->result()[0]->tfbi_name;
                    $gender = "";
                    $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";
                    }
                    $studentData = 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_category' => stripslashes($student_info->tspi_category),
                        'stu_religion' => stripslashes($student_info->tspi_religion),
                        'stu_email' => stripslashes($student_info->tspi_email),
                        'stu_mobile' => stripslashes($student_info->tspi_mobile),
                        'stu_diff_abled' => ($student_info->tspi_is_diff_abled == "T") ? "Yes <i class='fa fa-wheelchair'></i>" : "No",
                        'stu_course' => stripslashes($student_info->course_name),
                        'stu_max_sem_year' => stripslashes($student_info->course_no_of_sems),
                        '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,
                    );
                    $studentSemesterInfo = $this->StudentManagement->getStudentAllSemesterInfoBy($student_info->tspi_id)->result();
                }
            }
            $viewData['selectedPattern'] = $selectedPattern;
            $viewData['studentInfo'] = $studentData;
            $viewData['studentSemesterInfo'] = $studentSemesterInfo;
            $this->load->view('admin/student/updateSemesterInfo', $viewData);
        } else {
            redirect("admin/");
        }
    }

    public function saveNewSemesterOrYearInfoAndReturn() {
        if ($this->sessionvalidator->isLoggedIn()) {
            if (trim($this->input->post('semesterOrYear')) == "" || trim($this->input->post('maxMarks')) == "" || trim($this->input->post('obtMarks')) == "" || trim($this->input->post('passingStatus')) == "") {
                $responseData = array(
                    'csrfName' => $this->security->get_csrf_token_name(),
                    'csrfHash' => $this->security->get_csrf_hash(),
                    'sem_info_id' => -1
                );
                echo json_encode($responseData);
            } else if (sizeof($this->StudentManagement->getStudentSemesterInfoBy(trim($this->input->post('tspi_id')), trim($this->input->post('semesterOrYear')))->result())) {
                $responseData = array(
                    'csrfName' => $this->security->get_csrf_token_name(),
                    'csrfHash' => $this->security->get_csrf_hash(),
                    'sem_info_id' => 0
                );
                echo json_encode($responseData);
            } else {
                $newSemesterYearInfo = array(
                    'tssi_semester' => addslashes(trim($this->input->post('semesterOrYear'))),
                    'tssi_max_marks' => addslashes(trim($this->input->post('maxMarks'))),
                    'tssi_marks_obt' => trim($this->input->post('obtMarks')),
                    'tssi_percnt' => trim($this->input->post('percentage')),
                    'tssi_division' => trim($this->input->post('division')),
                    'tssi_univ_enrollment_no' => NULL,
                    'tssi_univ_roll_no' => NULL,
                    'tssi_admit_card_status' => 'T',
                    'tssi_back_papers' => trim($this->input->post('backSubjects')),
                    'tssi_passing_status' => trim($this->input->post('passingStatus')),
                    'tssi_univ_enrollment_no' => trim($this->input->post('univEnrlNo')),
                    'tssi_univ_roll_no' => trim($this->input->post('univRollNo')),
                    'tspi_id' => trim($this->input->post('tspi_id')),
                    'tssi_added_by' => $this->session->userdata("adminData")["smember_id"],
                    'tssi_updated_by' => $this->session->userdata("adminData")["smember_id"],
                    'tssi_added_on' => date("Y-m-d H:i:s"),
                    'tssi_updated_on' => date("Y-m-d H:i:s")
                );
                $sem_info_id = $this->StudentManagement->createNewStudentSemesterInfo($newSemesterYearInfo);
                $sem_year_info = $this->StudentManagement->getStudentSemesterInfoById($sem_info_id)->result()[0];
                $responseData = array(
                    'csrfName' => $this->security->get_csrf_token_name(),
                    'csrfHash' => $this->security->get_csrf_hash(),
                    'tspi_id' => trim($this->input->post('tspi_id')),
                    'sem_info_id' => $sem_year_info->tssi_id,
                    'tssi_semester' => $sem_year_info->tssi_semester,
                    'tssi_max_marks' => $sem_year_info->tssi_max_marks,
                    'tssi_marks_obt' => $sem_year_info->tssi_marks_obt,
                    'tssi_percnt' => $sem_year_info->tssi_percnt . "%",
                    'tssi_division' => $sem_year_info->tssi_division,
                    'tssi_back_papers' => ($sem_year_info->tssi_back_papers == "") ? "-" : stripslashes($sem_year_info->tssi_back_papers),
                    'tssi_passing_status' => stripslashes($sem_year_info->tssi_passing_status),
                    'tssi_univ_enrollment_no' => stripslashes($sem_year_info->tssi_univ_enrollment_no),
                    'tssi_univ_roll_no' => stripslashes($sem_year_info->tssi_univ_roll_no),
                    'tssi_added_by' => stripslashes($sem_year_info->addedByAdmin) . " On " . date("d-m-Y h:i:s A", strtotime($sem_year_info->tssi_added_on)),
                    'tssi_updated_by' => stripslashes($sem_year_info->updatedByAdmin) . " On " . date("d-m-Y h:i:s A", strtotime($sem_year_info->tssi_updated_on)),
                );
                echo json_encode($responseData);
            }
        } else {
            redirect("admin/");
        }
    }

    public function deleteSemesterOrYearInfo($tssi_id, $tspi_id) {
        if ($this->sessionvalidator->isLoggedIn()) {
            $semYearUpdateData = array(
                'tssi_id' => $tssi_id,
                'tssi_updated_on' => date("Y-m-d H:i:s"),
                'tssi_updated_by' => $this->session->userdata("adminData")["smember_id"],
                'tssi_delete_status' => 'T'
            );
            if ($this->StudentManagement->updateStudentSemesterInfo($semYearUpdateData)) {
                $this->session->set_flashdata('successMessage', 'Semester/Year Info Deleted Successfully.');
                redirect("admin/Student/getSemesterOrYearInfo/" . $tspi_id);
            } else {
                $this->session->set_flashdata('errorMessage', 'Some Error Occurred While Deleting Semester/Year Info. Try Later.');
                redirect("admin/Student/getSemesterOrYearInfo/" . $tspi_id);
            }
        } else {
            redirect("admin/");
        }
    }

    public function updateSemesterOrYearInfo() {
        if ($this->sessionvalidator->isLoggedIn()) {
            $semYearUpdateData = array(
                'tssi_id' => addslashes(trim($this->input->post('tssi_id'))),
                'tssi_max_marks' => addslashes(trim($this->input->post('maxMarksEdit'))),
                'tssi_marks_obt' => trim($this->input->post('obtMarksEdit')),
                'tssi_percnt' => trim($this->input->post('percentageEdit')),
                'tssi_division' => trim($this->input->post('divisionEdit')),
                'tssi_back_papers' => trim($this->input->post('backSubjectsEdit')),
                'tssi_passing_status' => trim($this->input->post('passingStatusEdit')),
                'tssi_univ_enrollment_no' => trim($this->input->post('univEnrlNoEdit')),
                'tssi_univ_roll_no' => trim($this->input->post('univRollNoEdit'))
            );
            if ($this->StudentManagement->updateStudentSemesterInfo($semYearUpdateData)) {
                $this->session->set_flashdata('successMessage', 'Semester/Year Info Updated Successfully.');
                redirect("admin/Student/getSemesterOrYearInfo/" . trim($this->input->post('tspi_id_edit')));
            } else {
                $this->session->set_flashdata('errorMessage', 'Some Error Occurred While Deleting Semester/Year Info. Try Later.');
                redirect("admin/Student/getSemesterOrYearInfo/" . trim($this->input->post('tspi_id_edit')));
            }
        } else {
            redirect("admin/");
        }
    }

    public function updateSemesterInfoBulk() {
        if ($this->sessionvalidator->isLoggedIn() && $this->sessionvalidator->isAccessGranted()) {
            if (isset($_POST['updateSubmitBtn'])) {
                if (empty($_FILES['bulkSemesterInfoFile']['name'])) {
                    $this->session->set_flashdata('errorMessage', "Please Upload Any CSV File.");
                    redirect("admin/Student/updateSemesterInfoBulk");
                } else {
                    $bulkSemesterInfoFileNameWithPath = "";
                    $configBulkFile['upload_path'] = './assets/admin/uploads/bulkfiles/semesterinfo/';
                    $configBulkFile['allowed_types'] = 'csv';
                    $configBulkFile['max_size'] = '1024';
                    $configBulkFile['file_ext_tolower'] = TRUE;
                    $configBulkFile['encrypt_name'] = TRUE;
                    $this->load->library('upload', $configBulkFile);
                    if (!$this->upload->do_upload('bulkSemesterInfoFile')) {
                        $this->session->set_flashdata('errorMessage', "Error! Only CSV Files With Max. Size 1MB Is Allowed.");
                        redirect("admin/Student/updateSemesterInfoBulk");
                    } else {
                        $bulkSemesterInfoFileNameWithPath = base_url("assets/admin/uploads/bulkfiles/semesterinfo/" . $this->upload->data()['file_name']);
                        $csvFileContent = $this->csvhandler->readCSV($bulkSemesterInfoFileNameWithPath);
                        if (trim($csvFileContent[0][0]) == "UNIV_ROLL_NO" && trim($csvFileContent[0][1]) == "UNIV_ENRL_NO" && trim($csvFileContent[0][2]) == "SEMESTER" && trim($csvFileContent[0][3]) == "MAX_MARKS" && trim($csvFileContent[0][4]) == "OBT_MARKS" && trim($csvFileContent[0][5]) == "STATUS" && trim($csvFileContent[0][6]) == "BACK_SUBJECTS") {
                            $studentSemInfoUnivRollNoArray = array();
                            $toDeleteSemInfos = array();
                            $notFoundUnivRollNumbers = array("Not Found University Roll Numbers");
                            for ($i = 1; $i < sizeof($csvFileContent); $i++) {
                                $studentInfo = $this->StudentManagement->getStudentPersonalInfoByUniversityRollNumber(trim($csvFileContent[$i][0]))->result();
                                if (sizeof($studentInfo)) {
                                    $percentage = round(($csvFileContent[$i][4] / $csvFileContent[$i][3]) * 100, 2);
                                    $division = "0";
                                    if ($percentage >= 60) {
                                        $division = "1";
                                    } else if ($percentage >= 50 && $percentage < 60) {
                                        $division = "2";
                                    } else if ($percentage >= 40 && $percentage < 50) {
                                        $division = "3";
                                    } else {
                                        $division = "0";
                                    }
                                    $univSemInfoUpdateInfo = array(
                                        'tspi_id' => $studentInfo[0]->tspi_id,
                                        'tssi_univ_roll_no' => trim($csvFileContent[$i][0]),
                                        'tssi_univ_enrollment_no' => trim($csvFileContent[$i][1]),
                                        'tssi_semester' => trim($csvFileContent[$i][2]),
                                        'tssi_max_marks' => trim($csvFileContent[$i][3]),
                                        'tssi_marks_obt' => trim($csvFileContent[$i][4]),
                                        'tssi_passing_status' => trim($csvFileContent[$i][5]),
                                        'tssi_back_papers' => trim($csvFileContent[$i][6]),
                                        'tssi_percnt' => $percentage,
                                        'tssi_division' => $division,
                                        'tssi_admit_card_status' => 'T',
                                        'tssi_admit_card_issue_date' => date("Y-m-d H:i:s"),
                                        'tssi_added_by' => $this->session->userdata("adminData")["smember_id"],
                                        'tssi_added_on' => date("Y-m-d H:i:s"),
                                        'tssi_updated_by' => $this->session->userdata("adminData")["smember_id"],
                                        'tssi_updated_on' => date("Y-m-d H:i:s")
                                    );
                                    $thisSemesterInfo = $this->StudentManagement->getStudentSemesterInfoBy($studentInfo[0]->tspi_id, trim($csvFileContent[$i][2]))->result();
                                    if (sizeof($thisSemesterInfo)) {
                                        $toUpdateSemInfoToDeleted = array(
                                            'tssi_id' => $thisSemesterInfo[0]->tssi_id,
                                            'tssi_delete_status' => 'T',
                                            'tssi_updated_by' => $this->session->userdata("adminData")["smember_id"],
                                            'tssi_updated_on' => date("Y-m-d H:i:s")
                                        );
                                        array_push($studentSemInfoUnivRollNoArray, $univSemInfoUpdateInfo);
                                        array_push($toDeleteSemInfos, $toUpdateSemInfoToDeleted);
                                    } else {
                                        array_push($studentSemInfoUnivRollNoArray, $univSemInfoUpdateInfo);
                                    }
                                } else {
                                    array_push($notFoundUnivRollNumbers, trim($csvFileContent[$i][0]));
                                }
                            }
                            $this->db->trans_start();
                            if (sizeof($toDeleteSemInfos)) {
                                $this->StudentManagement->updateStudentSemesterInfoMulti($toDeleteSemInfos);
                            }
                            if (sizeof($studentSemInfoUnivRollNoArray)) {
                                $this->StudentManagement->createNewStudentSemesterInfoMulti($studentSemInfoUnivRollNoArray);
                            }
                            $this->db->trans_complete();
                            $totalNotUpdatedSemInfo = (sizeof($notFoundUnivRollNumbers) - 1);
                            $totalUpdatedSemesterInfo = (((sizeof($csvFileContent) - 1) - $totalNotUpdatedSemInfo) < 0 ) ? 0 : ((sizeof($csvFileContent) - 1) - $totalNotUpdatedSemInfo);
                            if ($totalNotUpdatedSemInfo) {
                                $errorFileNameWithPath = "./assets/admin/downloads/errorfiles/notupdatedseminfo/notupdatedseminfo_" . date("d_m_Y_h_i_s_a") . ".csv";
                                $this->filehandler->createFile($errorFileNameWithPath, "All University Roll Numbers Whose Semester Info Has Not Been Updated");
                                $this->csvhandler->writeCSV($errorFileNameWithPath, $notFoundUnivRollNumbers, true);
                                $this->session->set_flashdata('successMessage', $totalUpdatedSemesterInfo . ' Semester Info Has Been Updated.');
                                $this->session->set_flashdata('errorMessage', $notFoundUnivRollNumbers . " Semester Info Has Not Been Updated. Click <a href='" . base_url($errorFileNameWithPath) . "'>Here To Download <i class='fa fa-download'></i></a> Error File.");
                            } else {
                                $this->session->set_flashdata('successMessage', 'All ' . $totalUpdatedSemesterInfo . ' Semester Info Has Been Updated.');
                            }
                            redirect("admin/Student/updateSemesterInfoBulk");
                        } else {
                            $this->session->set_flashdata('errorMessage', "Error! Uploaded CSV Contains Invalid Column Name(s)/No. Of Columns.");
                            redirect("admin/Student/updateSemesterInfoBulk");
                        }
                    }
                }
            } else {
                $this->load->view('admin/student/updateSemesterInfoBulk');
            }
        } else {
            redirect("admin/");
        }
    }

    public function allotSectionSemesterAndRollNumber() {
        if ($this->sessionvalidator->isLoggedIn() && $this->sessionvalidator->isAccessGranted()) {
            $selectedSession = "";
            $selectedEntryType = "";
            $filteredRecords = array();
            if (isset($_POST['filterSubmitBtn'])) {
                $reqCourse = trim($this->input->post('stuCourse'));
                $selectedSession = $this->input->post('stuSession');
                if ($reqCourse == "") {
                    $this->session->set_flashdata('errorMessage', "Please Select Course To Fetch Student Records.");
                } else if ($selectedSession == "") {
                    $this->session->set_flashdata('errorMessage', "Please Select Session To Fetch Student Records.");
                } else {
                    $selectedEntryType = $this->input->post('stuEntryType');
                    $enrolledStudents = $this->StudentManagement->getEnrolledStudentPersonalInfoByCourseSessionAndEntryType($reqCourse, trim($selectedSession), trim($selectedEntryType))->result();
                    for ($i = 0; $i < sizeof($enrolledStudents); $i++) {
                        $thisStudentInfo = $enrolledStudents[$i];
                        $currentSectionSemesterInfo = $this->StudentManagement->getStudentCurrentSectionSemesterInfoBy($thisStudentInfo->tspi_id)->result();
                        if (sizeof($currentSectionSemesterInfo)) {
                            $tsssi_id = $currentSectionSemesterInfo[0]->tsssi_id;
                            $currentSection = $currentSectionSemesterInfo[0]->tsssi_section;
                            $currentSemester = $currentSectionSemesterInfo[0]->tsssi_semester;
                        } else {
                            $tsssi_id = "-1";
                            $currentSection = "";
                            $currentSemester = ($thisStudentInfo->tcsm_course_type == "Regular") ? "1" : "3";
                        }
                        $thisRecord = array(
                            'tspi_id' => $thisStudentInfo->tspi_id,
                            'tspi_form_no' => $thisStudentInfo->tspi_form_no,
                            'tspi_name' => stripslashes($thisStudentInfo->tspi_name),
                            'tspi_gender' => $thisStudentInfo->tspi_gender,
                            'tspi_dob' => $thisStudentInfo->tspi_dob,
                            'tspi_rollNumber' => ($thisStudentInfo->tspi_rollNumber == $thisStudentInfo->tspi_form_no) ? "" : stripslashes($thisStudentInfo->tspi_rollNumber),
                            'tspi_enrollment_no' => ($thisStudentInfo->tspi_enrollment_no == $thisStudentInfo->tspi_form_no) ? "" : stripslashes($thisStudentInfo->tspi_enrollment_no),
                            'tsssi_id' => $tsssi_id,
                            'tsssi_semester' => $currentSemester,
                            'tsssi_section' => $currentSection
                        );
                        array_push($filteredRecords, $thisRecord);
                    }
                }
            }
            if (isset($_POST['updateSubmitBtn'])) {
                $submittedStudentId = $this->input->post('tspiIds');
                $enrollmentNumbers = $this->input->post('stuEnrollNo');
                $rollNumbers = $this->input->post('stuRollNo');
                $semesters = $this->input->post('stuSemester');
                $sections = $this->input->post('stuSection');
                $secSemsIds = $this->input->post('secSemIds');
                $updatedEnrollmentNumbers = 0;
                $notUpdatedEnrollmentRollNumbers = array();
                for ($i = 0; $i < sizeof($submittedStudentId); $i++) {
                    $thisStudentInfo = $this->StudentManagement->getStudentPersonalInfoAndPhotoSignBy($submittedStudentId[$i])->result()[0];
                    $toCreateSectionSemesterInfo = array();
                    $toUpdateSectionSemesterInfo = array();
                    $enrollmentRollNumberUpdatedInfo = array(
                        'tspi_id' => trim($submittedStudentId[$i]),
                        'tspi_enrollment_no' => (trim($enrollmentNumbers[$i]) == "") ? $thisStudentInfo->tspi_form_no : trim($enrollmentNumbers[$i]),
                        'tspi_rollNumber' => (trim($rollNumbers[$i]) == "") ? $thisStudentInfo->tspi_form_no : trim($rollNumbers[$i]),
                        'tspi_univ_rollNumber' => (trim($rollNumbers[$i]) == "") ? $thisStudentInfo->tspi_form_no : trim($rollNumbers[$i]),
                        'tspi_updated_by' => $this->session->userdata("adminData")["smember_id"],
                        'tspi_updated_on' => date("Y-m-d H:i:s")
                    );
                    if ($secSemsIds[$i] == "-1" || $secSemsIds[$i] == -1) {
                        $toCreateSectionSemesterInfo = array(
                            'tsssi_section' => (trim($sections[$i]) == "") ? "NA" : trim($sections[$i]),
                            'tsssi_semester' => (trim($semesters[$i]) == "") ? "0" : trim($semesters[$i]),
                            'tspi_id' => trim($submittedStudentId[$i]),
                            'tsssi_updated_on' => date("Y-m-d H:i:s"),
                            'tsssi_updated_by' => $this->session->userdata("adminData")["smember_id"]
                        );
                    } else {
                        $toUpdateSectionSemesterInfo = array(
                            'tsssi_id' => trim($secSemsIds[$i]),
                            'tsssi_section' => (trim($sections[$i]) == "") ? "NA" : trim($sections[$i]),
                            'tsssi_semester' => (trim($semesters[$i]) == "") ? "0" : trim($semesters[$i]),
                            'tsssi_updated_on' => date("Y-m-d H:i:s"),
                            'tsssi_updated_by' => $this->session->userdata("adminData")["smember_id"]
                        );
                    }
                    $this->db->trans_start();
                    /* Updating Enrollment Nos. & Roll Nos. */
                    if (($this->StudentManagement->isEnrollmentNumberSafeUpdate(trim($submittedStudentId[$i]), trim($enrollmentNumbers[$i])))) {
                        if ($this->StudentManagement->updateStudentPersonalInfo($enrollmentRollNumberUpdatedInfo)) {
                            $updatedEnrollmentNumbers++;
                        }
                    } else {
                        array_push($notUpdatedEnrollmentRollNumbers, trim($enrollmentNumbers[$i]));
                    }
                    /* Updating Enrollment Nos. & Roll Nos. */
                    if (sizeof($toUpdateSectionSemesterInfo)) {
                        if (!$this->StudentManagement->updateStudentSectionSemesterInfo($toUpdateSectionSemesterInfo)) {
                            array_push($notUpdatedEnrollmentRollNumbers, trim($enrollmentNumbers[$i]));
                        }
                    }
                    if (sizeof($toCreateSectionSemesterInfo)) {
                        if (!$this->StudentManagement->createNewStudentSectionSemesterInfo($toCreateSectionSemesterInfo)) {
                            array_push($notUpdatedEnrollmentRollNumbers, trim($enrollmentNumbers[$i]));
                        }
                    }
                    $this->db->trans_complete();
                }

                if ((sizeof($toCreateSectionSemesterInfo) == sizeof($submittedStudentId)) || (sizeof($toUpdateSectionSemesterInfo) == sizeof($submittedStudentId))) {
                    if ((sizeof($notUpdatedEnrollmentRollNumbers) == 0)) {
                        $this->session->set_flashdata('successMessage', 'All Enrl. No.s, Roll Nos, Section & Semester Has Been Updated Successfully.');
                    } else {
                        $this->session->set_flashdata('successMessage', 'All Section & Semester Has Been Updated Successfully But Only ' . $updatedEnrollmentNumbers . ' Enrl. No.s, Roll Nos. Has Been Updated.');
                        $this->session->set_flashdata('errorMessage', 'Either Of These Enrl. No.s, Roll Nos. Are Already Exists With Some Other Student: ' . implode(",", $notUpdatedEnrollmentRollNumbers));
                    }
                } else if ((sizeof($toCreateSectionSemesterInfo) + sizeof($toUpdateSectionSemesterInfo) == sizeof($submittedStudentId))) {
                    if ((sizeof($notUpdatedEnrollmentRollNumbers) == 0)) {
                        $this->session->set_flashdata('successMessage', 'All Enrl. No.s, Roll Nos, Section & Semester Has Been Updated Successfully.');
                    } else {
                        $this->session->set_flashdata('successMessage', 'All Section & Semester Has Been Updated Successfully But Only ' . $updatedEnrollmentNumbers . ' Enrl. No.s, Roll Nos. Has Been Updated.');
                        $this->session->set_flashdata('errorMessage', 'Either Of These Enrl. No.s, Roll Nos. Are Already Exists With Some Other Student: ' . implode(",", $notUpdatedEnrollmentRollNumbers));
                    }
                } else {
                    if ((sizeof($notUpdatedEnrollmentRollNumbers) == 0)) {
                        $this->session->set_flashdata('successMessage', 'All Enrl. No.s, Roll Nos, Section & Semester Has Been Updated Successfully.');
                    } else {
                        $this->session->set_flashdata('errorMessage', 'Some Section & Semester Could Not Be Updated And Only ' . $updatedEnrollmentNumbers . ' Enrl. No.s, Roll Nos. Has Been Updated.');
                        $this->session->set_flashdata('errorMessage', 'Either Of These Enrl. No.s, Roll Nos. Are Already Exists With Some Other Student: ' . implode(",", $notUpdatedEnrollmentRollNumbers));
                    }
                }
            }
            $viewData['branches'] = $this->BranchManagement->getAllNonDeletedActiveBrances()->result();
            $viewData['courses'] = $this->CourseManagement->getActiveAndNonDeletedCourses()->result();
            $viewData['selectedSession'] = $selectedSession;
            $viewData['selectedEntryType'] = $selectedEntryType;
            $viewData['filteredRecords'] = $filteredRecords;
            $this->load->view('admin/student/allotSecSemRollNumber', $viewData);
        } else {
            redirect("admin/");
        }
    }

    public function upgradeSemesterYear() {
        if ($this->sessionvalidator->isLoggedIn() && $this->sessionvalidator->isAccessGranted()) {
            $selectedSession = "";
            $selectedEntryType = "";
            $viewData['branches'] = $this->BranchManagement->getAllNonDeletedActiveBrances()->result();
            $viewData['courses'] = $this->CourseManagement->getActiveAndNonDeletedCourses()->result();
            $viewData['selectedSession'] = $selectedSession;
            $viewData['selectedEntryType'] = $selectedEntryType;
            $this->load->view('admin/student/upgradeSemYear', $viewData);
        } else {
            redirect("admin/");
        }
    }

    public function saveUpgradeSemesterYear() {
        if ($this->sessionvalidator->isLoggedIn()) {
            $reqCourse = trim($this->input->post('stuCourse'));
            $selectedSession = trim($this->input->post('stuSession'));
            $selectedEntryType = trim($this->input->post('stuEntryType'));
            $selectedStudents = $this->input->post('selectedStudents');
            if ($reqCourse == "") {
                $this->session->set_flashdata('errorMessage', "Please Select Course.");
                redirect("admin/Student/upgradeSemesterYear");
            } else if ($selectedSession == "") {
                $this->session->set_flashdata('errorMessage', "Please Select Session.");
                redirect("admin/Student/upgradeSemesterYear");
            } else if ($selectedEntryType == "") {
                $this->session->set_flashdata('errorMessage', "Please Select Entry Type.");
                redirect("admin/Student/upgradeSemesterYear");
            } else if (!sizeof($selectedStudents)) {
                $this->session->set_flashdata('errorMessage', "Please Select At Least One Student To Upgrade Semester.");
                redirect("admin/Student/upgradeSemesterYear");
            } else {
                $courseInfo = $this->CourseManagement->getCoursesBy($reqCourse)->result()[0];
                $courseDuration = $courseInfo->course_no_of_sems;
                $studentSectionSemesterArray = array();
                for ($i = 0; $i < sizeof($selectedStudents); $i++) {
                    $curSemInfo = $this->StudentManagement->getStudentCurrentSectionSemesterInfoBy($selectedStudents[$i])->result();
                    if (sizeof($curSemInfo)) {
                        $currentSemester = $curSemInfo[0]->tsssi_semester;
                        if ($currentSemester < $courseDuration) {
                            $nextSemester = ($currentSemester < $courseDuration) ? ++$currentSemester : $courseDuration;
                            $sectionSemesterInfo = array(
                                'tsssi_semester' => $nextSemester,
                                'tsssi_section' => $curSemInfo[0]->tsssi_section,
                                'tsssi_updated_on' => date("Y-m-d H:i:s"),
                                'tsssi_updated_by' => $this->session->userdata("adminData")["smember_id"],
                                'tspi_id' => $selectedStudents[$i]
                            );
                            array_push($studentSectionSemesterArray, $sectionSemesterInfo);
                        } else {
                            break;
                        }
                    }
                }
                if ($i == 0) {
                    $studentStatusUpdateInfo = array();
                    for ($i = 0; $i < sizeof($selectedStudents); $i++) {
                        array_push($studentStatusUpdateInfo, array(
                            'tspi_id' => $selectedStudents[$i],
                            'tspi_updated_by' => $this->session->userdata("adminData")["smember_id"],
                            'tspi_updated_on' => date("Y-m-d H:i:s"),
                            'tspi_status' => 'P'
                        ));
                    }
                    $this->StudentManagement->updateStudentPersonalInfoMulti($studentStatusUpdateInfo);
                    $this->session->set_flashdata('successMessage', sizeof($studentStatusUpdateInfo) . " Student(s) Records Has Been Set As Passout/Alumni.");
                    redirect("admin/Student/upgradeSemesterYear");
                } else {
                    if (sizeof($studentSectionSemesterArray)) {
                        $this->StudentManagement->createNewStudentSectionSemesterInfoMulti($studentSectionSemesterArray);
                    }
                    if (sizeof($studentSectionSemesterArray)) {
                        $this->session->set_flashdata('successMessage', sizeof($studentSectionSemesterArray) . " Student Records Has Been Upgraded To " . $nextSemester . " Semester.");
                        redirect("admin/Student/upgradeSemesterYear");
                    } else if (!sizeof($studentSectionSemesterArray)) {
                        $this->session->set_flashdata('errorMessage', "Selected Student(s) Can Not Be Upgraded As They Are Not Enrolled In Any Semester/Year.");
                        redirect("admin/Student/upgradeSemesterYear");
                    } else {
                        $this->session->set_flashdata('errorMessage', 'No Student Records Found In The Selected/Course/Entry Type To Upgrade.');
                        redirect(current_url());
                    }
                }
            }
        } else {
            redirect("admin/");
        }
    }

    public function enrollStudentBulk() {
        if ($this->sessionvalidator->isLoggedIn() && $this->sessionvalidator->isAccessGranted()) {
            if (isset($_POST['enrollSubmitBtn'])) {
                if (empty($_FILES['bulkJSONFile']['name'])) {
                    $this->session->set_flashdata('errorMessage', "Please Upload A JSON File.");
                    redirect("admin/Student/enrollStudentBulk");
                } else if (strcasecmp(pathinfo($_FILES["bulkJSONFile"]["name"], PATHINFO_EXTENSION), "json") != 0) {
                    $this->session->set_flashdata('errorMessage', "Error! Only JSON Files Is Allowed.");
                    redirect("admin/Student/enrollStudentBulk");
                } else {
                    $bulkStudentEnrollmentJSONFileNameWithPath = "";
                    $configBulkJSONFile['upload_path'] = './assets/admin/uploads/bulkfiles/studentinfo/';
                    $configBulkJSONFile['allowed_types'] = '*';
                    $configBulkJSONFile['detect_mime'] = TRUE;
                    $configBulkJSONFile['max_size'] = '5120';
                    $configBulkJSONFile['file_ext_tolower'] = TRUE;
                    $configBulkJSONFile['encrypt_name'] = TRUE;
                    $this->load->library('upload', $configBulkJSONFile);
                    if (!$this->upload->do_upload('bulkJSONFile')) {
                        $this->session->set_flashdata('errorMessage', "Error! Only JSON Files With Max. Size 5 MB Is Allowed." . $this->upload->display_errors());
                        redirect("admin/Student/enrollStudentBulk");
                    } else {
                        $bulkStudentEnrollmentJSONFileNameWithPath = base_url("assets/admin/uploads/bulkfiles/studentinfo/" . $this->upload->data()['file_name']);
                        $notAvailableCourseOrUCSMapId = array("Not Available Course Or UCS Map Id");
                        $alreadyExistingFormNumber = array("Already Existing Form Numbers");
                        $jsonFileContent = $this->jsonhandler->readJSON($bulkStudentEnrollmentJSONFileNameWithPath);
                        $bulkStudentInfo = $jsonFileContent[2]->data;
                        for ($i = 0; $i < sizeof($bulkStudentInfo); $i++) {
                            $record = $bulkStudentInfo[$i];
                            if ((!empty(trim($record->formno))) && (sizeof($this->StudentManagement->getStudentPersonalInfoByFormNumber(trim($record->formno))->result()) == 0)) {
                                $currentSessionInfo = $this->SessionManagement->getCurrentSessionInfo()->result()[0];
                                if (trim($record->course) == "") {
                                    continue;
                                }
                                $thisCourseInfo = $this->CourseManagement->getCourseByAlias(trim($record->course))->result();
                                if (sizeof($thisCourseInfo)) {
                                    $thisCourseRegularSubCourseInfo = $this->CourseManagement->getSubCourseInfoBy($thisCourseInfo[0]->course_id, "Regular")->result()[0];
                                    $ucsMapIdInfo = $this->UCSMappingManagement->getAllUCSMappingBySessionAndSubCourse($currentSessionInfo->session_id, $thisCourseRegularSubCourseInfo->tcsm_id)->result();
                                    if (sizeof($ucsMapIdInfo)) {
                                        $uscMapId = $ucsMapIdInfo[0]->ucs_map_id;
                                        $gender = "";
                                        $category = "";
                                        $religion = "";
                                        /* Fixing Gender Flag */
                                        if (trim($record->sex) == "male") {
                                            $gender = "M";
                                        } else if (trim($record->sex) == "female") {
                                            $gender = "F";
                                        } else {
                                            $gender = "T";
                                        }
                                        /* Fixing Gender Flag */
                                        /* Fixing Category Text */
                                        switch (trim($record->category)) {
                                            case 'obc':
                                                $category = "OBC";
                                                break;
                                            case 'general':
                                                $category = "General";
                                                break;
                                            case 'st':
                                                $category = "ST";
                                                break;
                                            case 'sc':
                                                $category = "SC";
                                                break;
                                            case 'minority':
                                                $category = "Minority";
                                                break;
                                            case 'other':
                                                $category = "Other";
                                            default:
                                                $category = "";
                                                break;
                                        }
                                        /* Fixing Category Text */
                                        /* Fixing Religion Text */
                                        switch (trim($record->reli)) {
                                            case 'HINDUISM':
                                                $religion = "Hinduism";
                                                break;
                                            case 'SIKHISM':
                                                $religion = "Sikkhism";
                                                break;
                                            case 'ISLAM':
                                                $religion = "Islam";
                                                break;
                                            case 'CHRISTIANITY':
                                                $religion = "Christianity";
                                                break;
                                            case 'BUDDHISM':
                                                $religion = "Buddhism";
                                                break;
                                            case 'JAINISM':
                                                $religion = "Jainism";
                                                break;
                                            case 'OTHER':
                                                $religion = "Other";
                                                break;
                                            default:
                                                $religion = "Other";
                                                break;
                                        }
                                        /* Fixing Religion Text */
                                        $studentPersonalInfo = array(
                                            'tspi_name' => addslashes(trim($record->cname)),
                                            'tspi_form_no' => trim($record->formno),
                                            'ucs_map_id' => $uscMapId,
                                            'tspi_enrollment_no' => trim($record->formno),
                                            'tspi_mobile' => trim($record->cmob),
                                            'tspi_email' => trim($record->cemail),
                                            'tspi_gender' => $gender,
                                            'tspi_category' => $category,
                                            'tspi_religion' => $religion,
                                            'tspi_dob' => trim($record->dob),
                                            'tspi_added_by' => 0,
                                            'tspi_added_on' => date("Y-m-d H:i:s"),
                                            'tspi_updated_by' => 0,
                                            'tspi_updated_on' => date("Y-m-d H:i:s"),
                                            'tspi_status' => "NA",
                                            'tspi_rollNumber' => trim($record->formno),
                                            'tspi_enrollment_date' => NULL,
                                            'tspi_admission_date' => NULL,
                                            'tspi_is_diff_abled' => (trim($record->da) == "Y") ? "T" : "F",
                                            'tspi_parent_annual_income' => trim($record->paincome),
                                            'tspi_remarks' => "This Entry Has Been Synched From Web Server. Remove This Remark After Your Acknowledgement."
                                        );
                                        $studentContactInfo = array(
                                            'tsci_perma_state' => 0,
                                            'tsci_perma_city' => 0,
                                            'tsci_perma_zipcode' => trim($record->ppin),
                                            'tsci_resid_state' => 0,
                                            'tsci_resid_city' => 0,
                                            'tsci_resid_zipcode' => trim($record->mpin),
                                            'tsci_parent_landline' => trim($record->plandline),
                                            'tsci_parent_mobile' => trim($record->pmobile),
                                            'tsci_added_on' => date("Y-m-d H:i:s"),
                                            'tsci_added_by' => 0,
                                            'tsci_updated_on' => date("Y-m-d H:i:s"),
                                            'tsci_updated_by' => 0,
                                            'tspi_id' => '',
                                            'tsci_perma_address_line_one' => addslashes(trim($record->paddr1)),
                                            'tsci_resid_address_line_two' => addslashes(trim($record->paddr2)),
                                            'tsci_resid_address_line_three' => addslashes(trim($record->paddr3)),
                                            'tsci_resid_address_line_one' => addslashes(trim($record->maddr1)),
                                            'tsci_resid_address_line_two' => addslashes(trim($record->maddr2)),
                                            'tsci_resid_address_line_three' => addslashes(trim($record->maddr3))
                                        );
                                        $entranceExamName = "";
                                        switch ($record->entrance) {
                                            case 'cat':
                                                $entranceExamName = "CAT";
                                                break;
                                            case 'xat':
                                                $entranceExamName = "XAT";
                                                break;
                                            case 'mat':
                                                $entranceExamName = "MAT";
                                                break;
                                            case 'cmat':
                                                $entranceExamName = "CMAT";
                                                break;
                                            case 'upsee':
                                                $entranceExamName = "UPSEE";
                                                break;
                                            case '':
                                                $entranceExamName = "";
                                                break;
                                            default:
                                                $entranceExamName = "NA";
                                        }
                                        $howKnowSMS = "";
                                        if (trim($record->know1) == "friends | relatives") {
                                            $howKnowSMS = "F";
                                        } else if (trim($record->know2) == "Advertisement") {
                                            $howKnowSMS = "A";
                                        } else if (trim($record->know3) == "Teachers") {
                                            $howKnowSMS = "T";
                                        } else if (trim($record->know4) == "Internet") {
                                            $howKnowSMS = "I";
                                        } else {
                                            $howKnowSMS = $record->know5;
                                        }
                                        $studentEntranceProfAndExtraCurricularInfo = array(
                                            'tsevi_is_prof_exp' => (trim($record->profession) == "" || trim($record->profession) == "no") ? "F" : "T",
                                            'tsevi_no_of_years' => trim($record->professionyear),
                                            'tsevi_organization' => addslashes(trim($record->professionorg)),
                                            'tsevi_job_desc' => addslashes(trim($record->professiondesc)),
                                            'tsevi_extra_activities' => addslashes(trim($record->extra)),
                                            'tsevi_how_know_sms' => $howKnowSMS,
                                            'tsevi_entrance_through' => $entranceExamName,
                                            'tsevi_form_no' => trim($record->entranceregno),
                                            'tsevi_composite_score' => trim($record->entrancescore),
                                            'tsevi_percnt_obtained' => trim($record->entrancepercentile),
                                            'tsevi_rank' => trim($record->entrancerank),
                                            'tsevi_added_on' => date("Y-m-d H:i:s"),
                                            'tsevi_updated_on' => date("Y-m-d H:i:s"),
                                            'tsevi_added_by' => 0,
                                            'tsevi_updated_by' => 0,
                                            'tspi_id' => '',
                                            'tsevi_percntage' => trim($record->entrancepercentage)
                                        );
                                        $studentHostelAndResidenceInfo = array(
                                            'tshri_is_hostel_opted' => (trim($record->hostel) == "H") ? "T" : "F",
                                            'tshri_added_on' => date("Y-m-d H:i:s"),
                                            'tshri_updated_on' => date("Y-m-d H:i:s"),
                                            'tshri_added_by' => 0,
                                            'tshri_updated_by' => 0,
                                            'tshri_comm_state' => 0,
                                            'tshri_comm_city' => 0,
                                            'tshri_loc_guard_state' => 0,
                                            'tshri_loc_guard_city' => 0,
                                            'tspi_id' => ''
                                        );
                                        $aadharIdInfo = $this->IDProofManagement->getIDProofAndSubIdProofInfoBy(2, "S")->result()[0];
                                        //$aadharIdInfo = $this->IDProofManagement->getIDProofAndSubIdProofInfoBy(2, "B")->result()[0];
                                        $studentAadharInfo = array(
                                            'tipi_number' => trim($record->adhno),
                                            'rel_id' => 0,
                                            'tipsm_id' => $aadharIdInfo->tipsm_id,
                                            'tipi_added_on' => date("Y-m-d H:i:s"),
                                            'tipi_updated_on' => date("Y-m-d H:i:s"),
                                            'tipi_added_by' => 0,
                                            'tipi_updated_by' => 0,
                                            'tipi_for' => ''
                                        );
                                        $PANInfo = $this->IDProofManagement->getIDProofAndSubIdProofInfoBy(1, "S")->result()[0];
                                        //$PANInfo = $this->IDProofManagement->getIDProofAndSubIdProofInfoBy(1, "B")->result()[0];
                                        $studentPANInfo = array(
                                            'tipi_number' => trim($record->panno),
                                            'rel_id' => 0,
                                            'tipsm_id' => $PANInfo->tipsm_id,
                                            'tipi_added_on' => date("Y-m-d H:i:s"),
                                            'tipi_updated_on' => date("Y-m-d H:i:s"),
                                            'tipi_added_by' => 0,
                                            'tipi_updated_by' => 0,
                                            'tipi_for' => ''
                                        );
                                        $studentIdProofInfo = array($studentAadharInfo, $studentPANInfo);
                                        $studentFamilyBackgroundInfo = array();
                                        for ($j = 0; $j < 3; $j++) {
                                            switch ($j) {
                                                case 0:
                                                    $thisFamilyBGInfo = array(
                                                        'tfbi_relation' => NULL,
                                                        'tfbi_name' => addslashes(trim($record->fbname1)),
                                                        'tfbi_organization' => addslashes(trim($record->fborg1)),
                                                        'tfbi_designation' => addslashes(trim($record->fbdesig1)),
                                                        'tfbi_user_type_flag' => 'S',
                                                        'tfbi_mapping_id' => '',
                                                        'tfbi_added_on' => date("Y-m-d H:i:s"),
                                                        'tfbi_updated_on' => date("Y-m-d H:i:s"),
                                                        'tfbi_added_by' => 0,
                                                        'tfbi_updated_by' => 0
                                                    );
                                                    array_push($studentFamilyBackgroundInfo, $thisFamilyBGInfo);
                                                    break;
                                                case 1:
                                                    $thisFamilyBGInfo = array(
                                                        'tfbi_relation' => NULL,
                                                        'tfbi_name' => addslashes(trim($record->fbname2)),
                                                        'tfbi_organization' => addslashes(trim($record->fborg2)),
                                                        'tfbi_designation' => addslashes(trim($record->fbdesig2)),
                                                        'tfbi_user_type_flag' => 'S',
                                                        'tfbi_mapping_id' => '',
                                                        'tfbi_added_on' => date("Y-m-d H:i:s"),
                                                        'tfbi_updated_on' => date("Y-m-d H:i:s"),
                                                        'tfbi_added_by' => 0,
                                                        'tfbi_updated_by' => 0
                                                    );
                                                    array_push($studentFamilyBackgroundInfo, $thisFamilyBGInfo);
                                                    break;
                                                case 2:
                                                    $thisFamilyBGInfo = array(
                                                        'tfbi_relation' => NULL,
                                                        'tfbi_name' => addslashes(trim($record->fbname3)),
                                                        'tfbi_organization' => addslashes(trim($record->fborg3)),
                                                        'tfbi_designation' => addslashes(trim($record->fbdesig3)),
                                                        'tfbi_user_type_flag' => 'S',
                                                        'tfbi_mapping_id' => '',
                                                        'tfbi_added_on' => date("Y-m-d H:i:s"),
                                                        'tfbi_updated_on' => date("Y-m-d H:i:s"),
                                                        'tfbi_added_by' => 0,
                                                        'tfbi_updated_by' => 0
                                                    );
                                                    array_push($studentFamilyBackgroundInfo, $thisFamilyBGInfo);
                                                    break;
                                            }
                                        }
                                        $fatherRelId = $this->RelationManagement->getRelationInfoByName("FATHER")->result()[0];
                                        $studentFatherFamBGInfo = array(
                                            'tfbi_relation' => $fatherRelId->rel_id,
                                            'tfbi_name' => addslashes(trim($record->fsalu . " " . $record->fname)),
                                            'tfbi_organization' => "NA",
                                            'tfbi_designation' => "NA",
                                            'tfbi_user_type_flag' => 'S',
                                            'tfbi_mapping_id' => '',
                                            'tfbi_added_on' => date("Y-m-d H:i:s"),
                                            'tfbi_updated_on' => date("Y-m-d H:i:s"),
                                            'tfbi_added_by' => 0,
                                            'tfbi_updated_by' => 0
                                        );
                                        $motherRelId = $this->RelationManagement->getRelationInfoByName("MOTHER")->result()[0];
                                        $studentMotherFamBGInfo = array(
                                            'tfbi_relation' => $motherRelId->rel_id,
                                            'tfbi_name' => addslashes(trim($record->msalu . " " . $record->mname)),
                                            'tfbi_organization' => "NA",
                                            'tfbi_designation' => "NA",
                                            'tfbi_user_type_flag' => 'S',
                                            'tfbi_mapping_id' => '',
                                            'tfbi_added_on' => date("Y-m-d H:i:s"),
                                            'tfbi_updated_on' => date("Y-m-d H:i:s"),
                                            'tfbi_added_by' => 0,
                                            'tfbi_updated_by' => 0
                                        );
                                        array_push($studentFamilyBackgroundInfo, $studentFatherFamBGInfo);
                                        array_push($studentFamilyBackgroundInfo, $studentMotherFamBGInfo);
                                        $studentEducationQualificatioInfo = array();
                                        $examInfo = $this->ExamManagement->getAllExamsUptoCategory($thisCourseInfo[0]->course_category)->result();
                                        for ($exam = 0; $exam < sizeof($examInfo); $exam++) {
                                            $thisExam = $examInfo[$exam];
                                            $division = "";
                                            switch ($exam) {
                                                case 0:
                                                    if (trim($record->div10) == '1' || trim($record->div10) == 1) {
                                                        $division = "I-Div";
                                                    } else if (trim($record->div10) == '2' || trim($record->div10) == 2) {
                                                        $division = "II-Div";
                                                    } else {
                                                        $division = "III-Div";
                                                    }
                                                    $thisEduQualiInfo = array(
                                                        'tesi_exam' => $thisExam->exam_id,
                                                        'tesi_board' => trim($record->board10),
                                                        'tesi_university' => trim($record->board10),
                                                        'tesi_stream' => trim($record->stream10),
                                                        'tesi_passing_year' => trim($record->examyear10),
                                                        'tesi_percnt' => trim($record->permarks10),
                                                        'tesi_cgpa' => trim($record->marks10),
                                                        'tesi_division' => $division,
                                                        'tesi_added_on' => date("Y-m-d H:i:s"),
                                                        'tesi_updated_on' => date("Y-m-d H:i:s"),
                                                        'tesi_added_by' => 0,
                                                        'tesi_updated_by' => 0,
                                                        'tspi_id' => '',
                                                        'tesi_max_marks_cgpa' => trim($record->maxm10)
                                                    );
                                                    array_push($studentEducationQualificatioInfo, $thisEduQualiInfo);
                                                    break;
                                                case 1:
                                                    if (trim($record->div12) == '1' || trim($record->div12) == 1) {
                                                        $division = "I-Div";
                                                    } else if (trim($record->div12) == '2' || trim($record->div12) == 2) {
                                                        $division = "II-Div";
                                                    } else {
                                                        $division = "III-Div";
                                                    }
                                                    $thisEduQualiInfo = array(
                                                        'tesi_exam' => $thisExam->exam_id,
                                                        'tesi_board' => trim($record->board12),
                                                        'tesi_university' => trim($record->board12),
                                                        'tesi_stream' => trim($record->stream12),
                                                        'tesi_passing_year' => trim($record->examyear12),
                                                        'tesi_percnt' => trim($record->permarks12),
                                                        'tesi_cgpa' => trim($record->marks12),
                                                        'tesi_division' => $division,
                                                        'tesi_added_on' => date("Y-m-d H:i:s"),
                                                        'tesi_updated_on' => date("Y-m-d H:i:s"),
                                                        'tesi_added_by' => 0,
                                                        'tesi_updated_by' => 0,
                                                        'tspi_id' => '',
                                                        'tesi_max_marks_cgpa' => trim($record->maxm12)
                                                    );
                                                    array_push($studentEducationQualificatioInfo, $thisEduQualiInfo);
                                                    break;
                                                case 2:
                                                    if (trim($record->graddiv) == '1' || trim($record->graddiv) == 1) {
                                                        $division = "I-Div";
                                                    } else if (trim($record->graddiv) == '2' || trim($record->graddiv) == 2) {
                                                        $division = "II-Div";
                                                    } else {
                                                        $division = "III-Div";
                                                    }
                                                    $thisEduQualiInfo = array(
                                                        'tesi_exam' => $thisExam->exam_id,
                                                        'tesi_board' => trim($record->gradboard),
                                                        'tesi_university' => trim($record->gradboard),
                                                        'tesi_stream' => trim($record->gradstream),
                                                        'tesi_passing_year' => trim($record->gradexamyear),
                                                        'tesi_percnt' => trim($record->gradpermarks),
                                                        'tesi_cgpa' => trim($record->gradmarks),
                                                        'tesi_division' => $division,
                                                        'tesi_added_on' => date("Y-m-d H:i:s"),
                                                        'tesi_updated_on' => date("Y-m-d H:i:s"),
                                                        'tesi_added_by' => 0,
                                                        'tesi_updated_by' => 0,
                                                        'tspi_id' => '',
                                                        'tesi_max_marks_cgpa' => trim($record->gradmaxm)
                                                    );
                                                    array_push($studentEducationQualificatioInfo, $thisEduQualiInfo);
                                                    break;
                                                case 3:
                                                    if (trim($record->graddiv) == '1' || trim($record->graddiv) == 1) {
                                                        $division = "I-Div";
                                                    } else if (trim($record->graddiv) == '2' || trim($record->graddiv) == 2) {
                                                        $division = "II-Div";
                                                    } else {
                                                        $division = "III-Div";
                                                    }
                                                    $thisEduQualiInfo = array(
                                                        'tesi_exam' => $thisExam->exam_id,
                                                        'tesi_board' => trim($record->pgradboard),
                                                        'tesi_university' => trim($record->pgradboard),
                                                        'tesi_stream' => trim($record->pgradstream),
                                                        'tesi_passing_year' => trim($record->pgradexamyear),
                                                        'tesi_percnt' => trim($record->pgradpermarks),
                                                        'tesi_cgpa' => trim($record->pgradmarks),
                                                        'tesi_division' => $division,
                                                        'tesi_added_on' => date("Y-m-d H:i:s"),
                                                        'tesi_updated_on' => date("Y-m-d H:i:s"),
                                                        'tesi_added_by' => 0,
                                                        'tesi_updated_by' => 0,
                                                        'tspi_id' => '',
                                                        'tesi_max_marks_cgpa' => trim($record->pgradmaxm)
                                                    );
                                                    array_push($studentEducationQualificatioInfo, $thisEduQualiInfo);
                                                    break;
                                            }
                                        }
                                        $studentDocumentInfo = array();
                                        $studentPhotographDocId = $this->DocumentManagement->getDocumentByFlag("SP")->result()[0]->doc_id;
                                        $studentPhotoInfo = array(
                                            'tddi_doc_id' => $studentPhotographDocId,
                                            'tddi_doc_file_path' => "picnotavail.jpg",
                                            'tddi_code' => $studentPhotographDocId,
                                            'tddi_user_type_flag' => 'S',
                                            'tddi_mapping_id' => '',
                                            'tddi_semester' => 'NA',
                                            'ucs_map_id' => $uscMapId,
                                            'tddi_added_on' => date("Y-m-d H:i:s"),
                                            'tddi_updated_on' => date("Y-m-d H:i:s"),
                                            'tddi_added_by' => 0,
                                            'tddi_updated_by' => 0
                                        );
                                        array_push($studentDocumentInfo, $studentPhotoInfo);
                                        $studentSignDocId = $this->DocumentManagement->getDocumentByFlag("SS")->result()[0]->doc_id;
                                        $studentSignInfo = array(
                                            'tddi_doc_id' => $studentSignDocId,
                                            'tddi_doc_file_path' => "signnotavail.png",
                                            'tddi_code' => $studentSignDocId,
                                            'tddi_user_type_flag' => 'S',
                                            'tddi_mapping_id' => '',
                                            'tddi_semester' => 'NA',
                                            'ucs_map_id' => $uscMapId,
                                            'tddi_added_on' => date("Y-m-d H:i:s"),
                                            'tddi_updated_on' => date("Y-m-d H:i:s"),
                                            'tddi_added_by' => 0,
                                            'tddi_updated_by' => 0
                                        );
                                        array_push($studentDocumentInfo, $studentSignInfo);
                                        $this->db->trans_start();
                                        $tspi_id = $this->StudentManagement->createNewStudentPersonalInfoEntry($studentPersonalInfo);
                                        if ($tspi_id) {
                                            $studentContactInfo['tspi_id'] = $tspi_id;
                                            $studentEntranceProfAndExtraCurricularInfo['tspi_id'] = $tspi_id;
                                            $studentHostelAndResidenceInfo['tspi_id'] = $tspi_id;
                                            $studentPANInfo['tipi_for'] = $tspi_id;
                                            $studentAadharInfo['tipi_for'] = $tspi_id;
                                            for ($k = 0; $k < sizeof($studentIdProofInfo); $k++) {
                                                $studentIdProofInfo[$k]['tipi_for'] = $tspi_id;
                                            }
                                            for ($l = 0; $l < sizeof($studentEducationQualificatioInfo); $l++) {
                                                $studentEducationQualificatioInfo[$l]['tspi_id'] = $tspi_id;
                                            }
                                            for ($m = 0; $m < sizeof($studentFamilyBackgroundInfo); $m++) {
                                                $studentFamilyBackgroundInfo[$m]['tfbi_mapping_id'] = $tspi_id;
                                            }
                                            for ($n = 0; $n < sizeof($studentDocumentInfo); $n++) {
                                                $studentDocumentInfo[$n]['tddi_mapping_id'] = $tspi_id;
                                            }
                                            $this->StudentManagement->createNewStudentContactInfoEntry($studentContactInfo);
                                            $this->StudentManagement->createNewStudentEntranceExamProfExpAndExtraCurricularInfoEntry($studentEntranceProfAndExtraCurricularInfo);
                                            $this->StudentManagement->createNewStudentHostelAndResidenceChoiceInfoEntry($studentHostelAndResidenceInfo);
                                            $this->IDProofManagement->createNewIDProofInfoMulti($studentIdProofInfo);
                                            $this->StudentManagement->createNewStudentEducationalQualificationInfoMulti($studentEducationQualificatioInfo);
                                            $this->StudentManagement->createNewStudentFamilyBackgroundInfoMulti($studentFamilyBackgroundInfo);
                                            $this->DocumentInfoManagement->createNewDocumentInfoMulti($studentDocumentInfo);
                                            $this->db->trans_complete();
                                        }
                                    } else {
                                        /* This Course-Sub Course/Session Mapping Does Not Exist In Local ERP Database */
                                        array_push($notAvailableCourseOrUCSMapId, trim($record->formno) . "/-" . trim($record->course));
                                    }
                                } else {
                                    /* Course Not Available In Local ERP Database */
                                    array_push($notAvailableCourseOrUCSMapId, trim($record->formno) . "/-" . trim($record->course));
                                }
                            } else {
                                /* For Logging Already Existing Form Nos./Blank Entries */
                                array_push($alreadyExistingFormNumber, trim($record->formno) . "/-" . trim($record->cname) . "/-S(/D)/O " . trim($record->fname));
                            }
                        }
                        $totalRecords = sizeof($bulkStudentInfo);
                        $totalNotUpdatedRecords = (sizeof($alreadyExistingFormNumber) - 1) + (sizeof($notAvailableCourseOrUCSMapId) - 1);
                        $totalEnrolledRecords = $totalRecords - $totalNotUpdatedRecords;
                        if ($alreadyExistingFormNumber || $notAvailableCourseOrUCSMapId) {
                            $errorFileNameWithPath = "./assets/admin/downloads/errorfiles/notupdatedbulkstudents/notupdatedbulkstudents_" . date("d_m_Y_h_i_s_a") . ".csv";
                            $this->filehandler->createFile($errorFileNameWithPath, "All Students That Has Not Been Enrolled");
                            $this->csvhandler->writeCSV($errorFileNameWithPath, $notAvailableCourseOrUCSMapId, true);
                            $this->csvhandler->writeCSV($errorFileNameWithPath, $alreadyExistingFormNumber, false);
                            $this->session->set_flashdata('successMessage', $totalEnrolledRecords . ' Out Of ' . $totalRecords . ' Student Records Has Been Synched.');
                            $this->session->set_flashdata('errorMessage', $totalNotUpdatedRecords . " Student Records Has Not Been Synched. Click <a href='" . base_url($errorFileNameWithPath) . "'>Here To Download <i class='fa fa-download'></i></a> Error File.");
                        } else {
                            $this->session->set_flashdata('successMessage', $totalEnrolledRecords . ' Out Of ' . $totalRecords . ' Student Records (All) Has Been Synched.');
                        }
                        redirect("admin/Student/enrollStudentBulk");
                    }
                }
            } else {
                $this->load->view('admin/student/enrollBulkStudents');
            }
        } else {
            redirect("admin/");
        }
    }

    public function courseTransfer() {
        if ($this->sessionvalidator->isLoggedIn() && $this->sessionvalidator->isAccessGranted()) {
            $selectedSession = "";
            $selectedEntryType = "";
            $studentInfo = array(
                'stu_id' => NULL,
                'stu_name' => NULL,
                'stu_dob' => NULL,
                'stu_father_name' => NULL,
                'stu_course' => NULL
            );
            $studentInfoAvailable = 0;
            if (isset($_POST['filterSubmitBtn'])) {
                $reqFormNo = trim($this->input->post('stuFormNo'));
                if ($reqFormNo == "") {
                    $this->session->set_flashdata('errorMessage', "Please Enter Form Number.");
                } else {
                    $student_info = $this->StudentManagement->getStudentPersonalInfoByFormNumber($reqFormNo)->result();
                    if (sizeof($student_info)) {
                        $studentFatherInfo = $this->StudentManagement->getStudentFatherInfoBy($student_info[0]->tspi_id)->result()[0];
                        $studentInfo = array(
                            'stu_id' => $student_info[0]->tspi_id,
                            'stu_name' => stripslashes($student_info[0]->tspi_name),
                            'stu_dob' => date('d-m-Y', strtotime($student_info[0]->tspi_dob)),
                            'stu_father_name' => stripslashes($studentFatherInfo->tfbi_name),
                            'stu_course' => $student_info[0]->course_id
                        );
                        $selectedSession = $student_info[0]->session_id;
                        $selectedEntryType = $student_info[0]->ucs_map_id;
                        $studentInfoAvailable = 1;
                    } else {
                        $this->session->set_flashdata('errorMessage', "Invalid Form Number. No Data Found On This Form Number.");
                    }
                }
            }
            if (isset($_POST['updateSubmitBtn'])) {
                $tspi_id = $this->input->post('stuId');
                $currentCourse = $this->input->post('currentCourse');
                $reqNewFormNo = trim($this->input->post('stuNewFormNo'));
                $reqCourse = trim($this->input->post('stuCourse'));
                $reqSession = trim($this->input->post('stuSession'));
                $reqEntryType = trim($this->input->post('stuEntryType'));
                if ($reqNewFormNo == "") {
                    $this->session->set_flashdata('errorMessage', "Please Enter New Form Number (If Any).");
                } else if ($reqCourse == "") {
                    $this->session->set_flashdata('errorMessage', "Please Select Any Course.");
                } else if ($reqSession == "") {
                    $this->session->set_flashdata('errorMessage', "Please Select Any Session.");
                } else if ($reqEntryType == "") {
                    $this->session->set_flashdata('errorMessage', "Please Select Any Entry Type.");
                } else if (!$this->StudentManagement->isFormNumberSafeUpdate($tspi_id, trim($this->input->post('$reqNewFormNo')))) {
                    $this->session->set_flashdata('errorMessage', "This Form Number Already Exists. Please Try With Other/Correct Form Number.");
                } else {
                    $currentCourseInfo = $this->CourseManagement->getCoursesBy($currentCourse)->result();
                    $requestedCourseInfo = $this->CourseManagement->getCoursesBy($reqCourse)->result();
                    if (sizeof($requestedCourseInfo) && sizeof($currentCourseInfo)) {
                        $toCreateNewExams = array();
                        $toDeleteExams = array();
                        $currentCourseCategory = $currentCourseInfo[0]->course_category;
                        $requestedCourseCategory = $requestedCourseInfo[0]->course_category;
                        if ($currentCourseCategory == "UG" && $requestedCourseCategory == "PG") {
                            $allExams = $this->ExamManagement->getAllExamsByCategory($requestedCourseCategory)->result();
                            for ($i = 0; $i < sizeof($allExams); $i++) {
                                $thisExam = $allExams[$i];
                                $thisEduQualiInfo = array(
                                    'tesi_exam' => $thisExam->exam_id,
                                    'tesi_board' => '',
                                    'tesi_university' => '',
                                    'tesi_stream' => '',
                                    'tesi_passing_year' => '',
                                    'tesi_percnt' => '',
                                    'tesi_cgpa' => '',
                                    'tesi_division' => '',
                                    'tesi_added_on' => date("Y-m-d H:i:s"),
                                    'tesi_updated_on' => date("Y-m-d H:i:s"),
                                    'tesi_added_by' => $this->session->userdata("adminData")["smember_id"],
                                    'tesi_updated_by' => $this->session->userdata("adminData")["smember_id"],
                                    'tspi_id' => $tspi_id,
                                    'tesi_max_marks_cgpa' => ''
                                );
                                array_push($toCreateNewExams, $thisEduQualiInfo);
                            }
                            $studentUpdatedPersonalInfo = array(
                                'tspi_id' => $tspi_id,
                                'tspi_form_no' => $reqNewFormNo,
                                'ucs_map_id' => $reqEntryType,
                                'tspi_updated_by' => $this->session->userdata("adminData")["smember_id"],
                                'tspi_updated_on' => date("Y-m-d H:i:s")
                            );
                        } else if ($currentCourseCategory == "PG" && $requestedCourseCategory == "UG") {
                            $allExams = $this->ExamManagement->getAllExamsByCategory($currentCourseCategory)->result();
                            for ($j = 0; $j < sizeof($allExams); $j++) {
                                $stuThisExamInfo = $this->StudentManagement->getStudentEducationalQualificationInfoBy($tspi_id, $allExams[$j]->exam_id)->result();
                                if (sizeof($stuThisExamInfo)) {
                                    array_push($toDeleteExams, $stuThisExamInfo[0]->tesi_id);
                                }
                            }
                            $studentUpdatedPersonalInfo = array(
                                'tspi_id' => $tspi_id,
                                'tspi_form_no' => $reqNewFormNo,
                                'ucs_map_id' => $reqEntryType,
                                'tspi_updated_by' => $this->session->userdata("adminData")["smember_id"],
                                'tspi_updated_on' => date("Y-m-d H:i:s")
                            );
                        } else {
                            $studentUpdatedPersonalInfo = array(
                                'tspi_id' => $tspi_id,
                                'tspi_form_no' => $reqNewFormNo,
                                'ucs_map_id' => $reqEntryType,
                                'tspi_updated_by' => $this->session->userdata("adminData")["smember_id"],
                                'tspi_updated_on' => date("Y-m-d H:i:s")
                            );
                        }
                        $this->db->trans_start();
                        if (sizeof($toCreateNewExams)) {
                            $this->StudentManagement->createNewStudentEducationalQualificationInfoMulti($toCreateNewExams);
                        }
                        if (sizeof($toDeleteExams)) {
                            for ($delExams = 0; $delExams < sizeof($toDeleteExams); $delExams++) {
                                $this->StudentManagement->deleteStudentEducationalQualificationInfoEntryBy($toDeleteExams[$delExams]);
                            }
                        }
                        $this->StudentManagement->updateStudentPersonalInfo($studentUpdatedPersonalInfo);
                        $this->db->trans_complete();
                        $this->session->set_flashdata('successMessage', "Course Transfer & Update Successful.");
                    } else {
                        $this->session->set_flashdata('errorMessage', "Either Selected Course Or The Current Course Does Not Exits Any More.");
                    }
                }
            }
            $viewData['branches'] = $this->BranchManagement->getAllNonDeletedActiveBrances()->result();
            $viewData['courses'] = $this->CourseManagement->getActiveAndNonDeletedCourses()->result();
            $viewData['selectedSession'] = $selectedSession;
            $viewData['selectedEntryType'] = $selectedEntryType;
            $viewData['doStudentInfoAvailable'] = $studentInfoAvailable;
            $viewData['studentInfo'] = $studentInfo;
            $this->load->view('admin/student/transferCourse', $viewData);
        } else {
            redirect("admin/");
        }
    }

    public function deleteStudent($tspi_id) {
        if ($this->sessionvalidator->isLoggedIn()) {
            $studentPersonalnfoUpdateData = array(
                'tspi_id' => $tspi_id,
                'tspi_updated_on' => date("Y-m-d H:i:s"),
                'tspi_updated_by' => $this->session->userdata("adminData")["smember_id"],
                'tspi_delete_status' => 'T'
            );
            if ($this->StudentManagement->updateStudentPersonalInfo($studentPersonalnfoUpdateData)) {
                $this->session->set_flashdata('successMessage', 'Student Entry Deleted Successfully.');
                redirect("admin/Student/");
            } else {
                $this->session->set_flashdata('errorMessage', 'Some Error Occurred While Deleting Student Entry. Try Later.');
                redirect("admin/Student/");
            }
        } else {
            redirect("admin/");
        }
    }

    public function deleteStudentDocument($tddi_id, $tspi_id) {
        if ($this->sessionvalidator->isLoggedIn()) {
            $documentInfo = $this->DocumentInfoManagement->getDocumentInfoBy($tddi_id)->result()[0];
            if (file_exists("./assets/admin/uploads/studentData/" . $documentInfo->tddi_doc_file_path)) {
                unlink("./assets/admin/uploads/studentData/" . $documentInfo->tddi_doc_file_path);
                $this->DocumentInfoManagement->deleteDocumentInfoEntryBy($tddi_id);
            } else {
                $this->DocumentInfoManagement->deleteDocumentInfoEntryBy($tddi_id);
            }
            $studentPersonalnfoUpdateData = array(
                'tspi_id' => $tspi_id,
                'tspi_updated_on' => date("Y-m-d H:i:s"),
                'tspi_updated_by' => $this->session->userdata("adminData")["smember_id"]
            );
            if ($this->StudentManagement->updateStudentPersonalInfo($studentPersonalnfoUpdateData)) {
                $this->session->set_flashdata('successMessage', 'Document Deleted Successfully.');
                redirect("admin/Student/editStudent/" . $tspi_id);
            } else {
                $this->session->set_flashdata('errorMessage', 'Some Error Occurred While Deleting Document. Try Later.');
                redirect("admin/Student/editStudent/" . $tspi_id);
            }
        } else {
            redirect("admin/");
        }
    }

    public function checkFormNumberAvailability() {
        $requested_formno = $_POST['form_no'];
        $query = $this->StudentManagement->getStudentPersonalInfoByFormNumber($requested_formno);
        $studentInfo = $query->result();
        if (sizeof($studentInfo)) {
            $responseData = array(
                'csrfName' => $this->security->get_csrf_token_name(),
                'csrfHash' => $this->security->get_csrf_hash(),
                'doFormNoAvailable' => 1
            );
        } else {
            $responseData = array(
                'csrfName' => $this->security->get_csrf_token_name(),
                'csrfHash' => $this->security->get_csrf_hash(),
                'doFormNoAvailable' => 0
            );
        }
        echo json_encode($responseData);
    }

    public function checkRollNumberAvailability() {
        $requested_rollno = $_POST['roll_no'];
        $query = $this->StudentManagement->getStudentPersonalInfoByRollNumber($requested_rollno);
        $studentInfo = $query->result();
        if (sizeof($studentInfo)) {
            $responseData = array(
                'csrfName' => $this->security->get_csrf_token_name(),
                'csrfHash' => $this->security->get_csrf_hash(),
                'doRollNoAvailable' => 1
            );
        } else {
            $responseData = array(
                'csrfName' => $this->security->get_csrf_token_name(),
                'csrfHash' => $this->security->get_csrf_hash(),
                'doRollNoAvailable' => 0
            );
        }
        echo json_encode($responseData);
    }

    public function checkEnrollmentNumberAvailability() {
        $requested_enrollmentNumber = $_POST['enrollment_no'];
        $query = $this->StudentManagement->getStudentPersonalInfoByEnrollmentNumber($requested_enrollmentNumber);
        $studentInfo = $query->result();
        if (sizeof($studentInfo)) {
            $responseData = array(
                'csrfName' => $this->security->get_csrf_token_name(),
                'csrfHash' => $this->security->get_csrf_hash(),
                'doEnrlmntAvailable' => 1
            );
        } else {
            $responseData = array(
                'csrfName' => $this->security->get_csrf_token_name(),
                'csrfHash' => $this->security->get_csrf_hash(),
                'doEnrlmntAvailable' => 0
            );
        }
        echo json_encode($responseData);
    }

    public function checkFormNumberAvailabilityForEdit() {
        $requested_formno = $_POST['form_no'];
        $tspi_id = $_POST['tspi_id'];
        if (!$this->StudentManagement->isFormNumberSafeUpdate($tspi_id, $requested_formno)) {
            $responseData = array(
                'csrfName' => $this->security->get_csrf_token_name(),
                'csrfHash' => $this->security->get_csrf_hash(),
                'doFormNoAvailable' => 1
            );
        } else {
            $responseData = array(
                'csrfName' => $this->security->get_csrf_token_name(),
                'csrfHash' => $this->security->get_csrf_hash(),
                'doFormNoAvailable' => 0
            );
        }
        echo json_encode($responseData);
    }

    public function checkRollNumberAvailabilityForEdit() {
        $requested_rollno = $_POST['roll_no'];
        $tspi_id = $_POST['tspi_id'];
        if (!$this->StudentManagement->isRollNumberSafeUpdate($tspi_id, $requested_rollno)) {
            $responseData = array(
                'csrfName' => $this->security->get_csrf_token_name(),
                'csrfHash' => $this->security->get_csrf_hash(),
                'doRollNoAvailable' => 1
            );
        } else {
            $responseData = array(
                'csrfName' => $this->security->get_csrf_token_name(),
                'csrfHash' => $this->security->get_csrf_hash(),
                'doRollNoAvailable' => 0
            );
        }
        echo json_encode($responseData);
    }

    public function checkEnrollmentNumberAvailabilityForEdit() {
        $requested_enrollmentNumber = $_POST['enrollment_no'];
        $tspi_id = $_POST['tspi_id'];
        if (!$this->StudentManagement->isEnrollmentNumberSafeUpdate($tspi_id, $requested_enrollmentNumber)) {
            $responseData = array(
                'csrfName' => $this->security->get_csrf_token_name(),
                'csrfHash' => $this->security->get_csrf_hash(),
                'doEnrlmntAvailable' => 1
            );
        } else {
            $responseData = array(
                'csrfName' => $this->security->get_csrf_token_name(),
                'csrfHash' => $this->security->get_csrf_hash(),
                'doEnrlmntAvailable' => 0
            );
        }
        echo json_encode($responseData);
    }

    public function resetStudentPassword() {
        $tspi_id = $_POST['tspi_id'];
        $updatedPasswordStudentInfo = array(
            'tspi_id' => $tspi_id,
            'tspi_updated_on' => date("Y-m-d H:i:s"),
            'tspi_updated_by' => $this->session->userdata("adminData")["smember_id"],
            'tspi_password' => MD5('12345')
        );
        if ($this->StudentManagement->updateStudentPersonalInfo($updatedPasswordStudentInfo)) {
            $responseData = array(
                'csrfName' => $this->security->get_csrf_token_name(),
                'csrfHash' => $this->security->get_csrf_hash(),
                'doUpdated' => 1
            );
        } else {
            $responseData = array(
                'csrfName' => $this->security->get_csrf_token_name(),
                'csrfHash' => $this->security->get_csrf_hash(),
                'doUpdated' => 0
            );
        }
        echo json_encode($responseData);
    }

    public function viewStudent($tspi_id) {
        if ($this->sessionvalidator->isLoggedIn()) {
            $aadharIdInfo = $this->IDProofManagement->getIDProofAndSubIdProofInfoBy(2, "S")->result()[0];
            $PANInfo = $this->IDProofManagement->getIDProofAndSubIdProofInfoBy(1, "S")->result()[0];
            $CSTCInfo = $this->IDProofManagement->getIDProofAndSubIdProofInfoBy(5, "S")->result()[0];
            $AICInfo = $this->IDProofManagement->getIDProofAndSubIdProofInfoBy(6, "S")->result()[0];
            $viewData['stuPersonalInfoWithPicAndSign'] = $this->StudentManagement->getStudentPersonalInfoAndPhotoSignBy($tspi_id)->result()[0];
            $viewData['stuAadharNumber'] = $this->IDProofManagement->getIdProofInfoBy($tspi_id, $aadharIdInfo->tipsm_id)->result()[0]->tipi_number;
            $viewData['stuPANNumber'] = $this->IDProofManagement->getIdProofInfoBy($tspi_id, $PANInfo->tipsm_id)->result()[0]->tipi_number;
            $viewData['stuCSTCNumber'] = $this->IDProofManagement->getIdProofInfoBy($tspi_id, $CSTCInfo->tipsm_id)->result()[0]->tipi_number;
            $viewData['stuAICNumber'] = $this->IDProofManagement->getIdProofInfoBy($tspi_id, $AICInfo->tipsm_id)->result()[0]->tipi_number;
            $viewData['stuFatherName'] = $this->StudentManagement->getStudentFatherInfoBy($tspi_id)->result()[0]->tfbi_name;
            $viewData['stuMotherName'] = $this->StudentManagement->getStudentMotherInfoBy($tspi_id)->result()[0]->tfbi_name;
            $viewData['stuContactInfo'] = $this->StudentManagement->getStudentContactInfoBy($tspi_id)->result()[0];
            $viewData['stuEduQualifInfo'] = $this->StudentManagement->getStudentEducationalQualificationInfo($tspi_id)->result();
            $viewData['stuFamilyBGInfo'] = $this->StudentManagement->getStudentFamilyBackgroundInfoBy($tspi_id)->result();
            $viewData['stuHostelAndResidInfo'] = $this->StudentManagement->getStudentHostelAndResidenceChoiceInfoBy($tspi_id)->result()[0];
            $viewData['stuEntranceExamAndProfExpInfo'] = $this->StudentManagement->getStudentStudentEntranceExamProfExpAndExtraCurricularInfoBy($tspi_id)->result()[0];
            $allowedDocuments = $this->DocumentManagement->getAllDocumentsUptoCategory($viewData['stuPersonalInfoWithPicAndSign']->course_category)->result();
            $uploadedDocsInfo = array();
            for ($i = 0; $i < sizeof($allowedDocuments); $i++) {
                if ($this->DocumentInfoManagement->isDocumentUploaded($tspi_id, $allowedDocuments[$i]->doc_id, "S")) {
                    $uploadedDocumentInfo = $this->DocumentInfoManagement->getUploadedDocumentOfStudentBy($tspi_id, $allowedDocuments[$i]->doc_id)->result()[0];
                    $thisDocInfo = array(
                        'is_uploaded' => 1,
                        'tddi_id' => $uploadedDocumentInfo->tddi_id,
                        'doc_id' => $allowedDocuments[$i]->doc_id,
                        'doc_name' => $allowedDocuments[$i]->doc_name,
                        'file_name' => $uploadedDocumentInfo->tddi_doc_file_path
                    );
                } else {
                    $thisDocInfo = array(
                        'is_uploaded' => 0,
                        'tddi_id' => -1,
                        'doc_id' => $allowedDocuments[$i]->doc_id,
                        'doc_name' => $allowedDocuments[$i]->doc_name,
                        'file_name' => ''
                    );
                }
                array_push($uploadedDocsInfo, $thisDocInfo);
            }
            $viewData['stuDocumentInfo'] = $uploadedDocsInfo;
            $this->load->view('admin/student/viewStudent', $viewData);
        } else {
            redirect("admin/");
        }
    }

    public function getStudentFullInfo() {
        $tspi_id = $_POST['tspi_id'];
        $student_info = $this->StudentManagement->getStudentPersonalInfoAndPhotoSignBy($tspi_id)->result()[0];
        $studentFatherName = $this->StudentManagement->getStudentFatherInfoBy($student_info->tspi_id)->result()[0]->tfbi_name;
        $studentCurrentSemesterInfo = $this->StudentManagement->getStudentCurrentSectionSemesterInfoBy($student_info->tspi_id)->result();
        $gender = "";
        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";
        }
        $responseData = array(
            'csrfName' => $this->security->get_csrf_token_name(),
            'csrfHash' => $this->security->get_csrf_hash(),
            'stu_id' => $student_info->tspi_id,
            'stu_name' => stripslashes($student_info->tspi_name),
            'stu_father_name' => stripslashes($studentFatherName),
            'stu_gender' => $gender,
            'stu_category' => stripslashes($student_info->tspi_category),
            'stu_religion' => stripslashes($student_info->tspi_religion),
            '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_email' => $student_info->tspi_email,
            'stu_mobile' => $student_info->tspi_mobile,
            'stu_course' => stripslashes($student_info->course_name),
            'stu_session' => stripslashes($student_info->session_name),
            'stu_entry_type' => stripslashes($student_info->tcsm_course_type),
            'stu_status' => $student_info->status_text,
            'stu_admission_date' => ($student_info->tspi_admission_date == "" || $student_info->tspi_admission_date == NULL) ? "-" : date('d-m-Y', strtotime($student_info->tspi_admission_date)),
            'stu_enrollment_date' => ($student_info->tspi_enrollment_date == "" || $student_info->tspi_enrollment_date == NULL) ? "-" : date('d-m-Y', strtotime($student_info->tspi_enrollment_date)),
            'stu_diff_abled' => ($student_info->tspi_is_diff_abled == "T") ? "<i class='fa fa-wheelchair' style='color:#FF0000;'></i> Yes" : "No",
            'stu_parent_aincome' => ($student_info->tspi_parent_annual_income == "") ? "-" : "INR <i class='fa fa-inr'></i>" . $student_info->tspi_parent_annual_income . "/-",
            'stu_remarks' => ($student_info->tspi_remarks == "" || $student_info->tspi_remarks == NULL) ? "" : stripslashes($student_info->tspi_remarks),
            'stu_delete_status' => ($student_info->tspi_delete_status == "T") ? "<i class='fa fa-user-times' style='color:#FF0000;'></i> Deleted By Operator" : "<i class='fa fa-check-circle' style='color:#00FF00;'></i> Not Deleted",
            'stu_year_gap' => ($student_info->tspi_ygap_applied == "T") ? "Yes" : "No",
            'stu_sch_elgbl' => ($student_info->tspi_scholarship_eligible == "T") ? "Yes" : "No",
            'stu_sch_prcnt' => ($student_info->tspi_scholarship_percentage == '0' || $student_info->tspi_scholarship_percentage == '' || $student_info->tspi_scholarship_percentage == NULL) ? "-" : $student_info->tspi_scholarship_percentage . "%",
            'stu_univ_roll' => ($student_info->tspi_univ_rollNumber == "" || $student_info->tspi_univ_rollNumber == NULL) ? "-" : $student_info->tspi_univ_rollNumber,
            'stu_photograph' => base_url("assets/admin/uploads/studentData/") . $student_info->studentPhoto,
            'stu_added_by' => $student_info->addedByAdmin . " On " . date("d-m-Y h:i:s A", strtotime($student_info->tspi_added_on)),
            'stu_updated_by' => $student_info->updatedByAdmin . " On " . date("d-m-Y h:i:s A", strtotime($student_info->tspi_updated_on)),
            'stu_current_semester' => (sizeof($studentCurrentSemesterInfo)) ? $studentCurrentSemesterInfo[0]->tsssi_semester : "-"
        );
        echo json_encode($responseData);
    }

    public function getSemesterYearForSemYearInfoUpdate() {
        $tspi_id = $_POST['tspi_id'];
        $sem_year = $_POST['sem_year'];
        $student_info = $this->StudentManagement->getStudentPersonalInfoAndPhotoSignBy($tspi_id)->result()[0];
        $course_time_mgmt_flag = ($student_info->course_time_mgmt_flag == 'Y') ? "Year" : "Semester";
        $sem_year_start_from = $student_info->tcsm_sem_start_from;
        $tot_sem_year = $student_info->course_no_of_sems;
        $options = "<option value=''>Select Semester/Year</option>";
        for ($i = $sem_year_start_from; $i <= $tot_sem_year; $i++) {
            $disabled = "";
            if (sizeof($this->StudentManagement->getStudentSemesterInfoBy($tspi_id, $i)->result())) {
                $disabled = "disabled";
            }
            $selected = ($i == $sem_year) ? "selected" : "";
            $options .= "<option value=" . $i . " " . $selected . " " . $disabled . ">" . $i . " " . $course_time_mgmt_flag . "</option>";
        }
        $responseData = array(
            'csrfName' => $this->security->get_csrf_token_name(),
            'csrfHash' => $this->security->get_csrf_hash(),
            'sem_year_list' => $options,
            'univ_roll_number' => $student_info->tspi_univ_rollNumber
        );
        echo json_encode($responseData);
    }

    public function getStudentFullSemesterInfo() {
        $sem_info_id = $_POST['tssi_id'];
        $tspi_id = $_POST['tspi_id'];
        $sem_year_info = $this->StudentManagement->getStudentSemesterInfoById($sem_info_id)->result()[0];
        $responseData = array(
            'csrfName' => $this->security->get_csrf_token_name(),
            'csrfHash' => $this->security->get_csrf_hash(),
            'tspi_id' => $tspi_id,
            'sem_info_id' => $sem_year_info->tssi_id,
            'tssi_semester' => $sem_year_info->tssi_semester,
            'tssi_max_marks' => $sem_year_info->tssi_max_marks,
            'tssi_marks_obt' => $sem_year_info->tssi_marks_obt,
            'tssi_percnt' => $sem_year_info->tssi_percnt,
            'tssi_division' => $sem_year_info->tssi_division,
            'tssi_back_papers' => stripslashes($sem_year_info->tssi_back_papers),
            'tssi_passing_status' => stripslashes($sem_year_info->tssi_passing_status),
            'tssi_univ_enrollment_no' => stripslashes($sem_year_info->tssi_univ_enrollment_no),
            'tssi_univ_roll_no' => stripslashes($sem_year_info->tssi_univ_roll_no),
            'tssi_added_by' => stripslashes($sem_year_info->addedByAdmin) . " On " . date("d-m-Y h:i:s A", strtotime($sem_year_info->tssi_added_on)),
            'tssi_updated_by' => stripslashes($sem_year_info->updatedByAdmin) . " On " . date("d-m-Y h:i:s A", strtotime($sem_year_info->tssi_updated_on)),
        );
        echo json_encode($responseData);
    }

    public function getEnrolledStudentsByCourseSessionEntryType() {
        $ucsMapId = $_POST['entryType'];
        $student_info = $this->StudentManagement->getEnrolledStudentPersonalInfoByCourseSessionAndEntryType('', '', $ucsMapId, '')->result();
        $studentList = array();
        if (sizeof($student_info)) {
            for ($i = 0; $i < sizeof($student_info); $i++) {
                $gender = "";
                if ($student_info[$i]->tspi_gender == "M") {
                    $gender = "<i class='fa fa-male'></i>|Male";
                } else if ($student_info[$i]->tspi_gender == "F") {
                    $gender = "<i class='fa fa-female'></i>|Female";
                } else {
                    $gender = "<i class='fa fa-transgender'></i>|Transgender";
                }
                $thisStudentInfo = array(
                    'stu_id' => $student_info[$i]->tspi_id,
                    'stu_name' => stripslashes($student_info[$i]->tspi_name),
                    'stu_gender' => $gender,
                    'stu_form_no' => stripslashes($student_info[$i]->tspi_form_no),
                    'stu_roll_no' => ($student_info[$i]->tspi_rollNumber == $student_info[$i]->tspi_form_no) ? "-" : stripslashes($student_info[$i]->tspi_rollNumber),
                    'stu_enroll_no' => ($student_info[$i]->tspi_enrollment_no == $student_info[$i]->tspi_form_no) ? "-" : stripslashes($student_info[$i]->tspi_enrollment_no),
                    'stu_dob' => date('d-m-Y', strtotime($student_info[$i]->tspi_dob)),
                    'stu_course' => stripslashes($student_info[$i]->course_name),
                    'stu_session' => stripslashes($student_info[$i]->session_name),
                    'stu_entry_type' => stripslashes($student_info[$i]->tcsm_course_type)
                );
                array_push($studentList, $thisStudentInfo);
            }
            $responseData = array(
                'csrfName' => $this->security->get_csrf_token_name(),
                'csrfHash' => $this->security->get_csrf_hash(),
                'available_students' => sizeof($student_info),
                'student_list' => $studentList,
                'message' => 'Students Available'
            );
        } else {
            $responseData = array(
                'csrfName' => $this->security->get_csrf_token_name(),
                'csrfHash' => $this->security->get_csrf_hash(),
                'available_students' => 0,
                'student_list' => $studentList,
                'message' => 'No Students Available For Set Allotment'
            );
        }
        echo json_encode($responseData);
    }

    public function getEnrolledStudentsInSemesterForSubjectAllotment() {
        $semester = $_POST['semester'];
        $course = $_POST['course'];
        $student_info = $this->StudentManagement->getAllEnrolledStudentsForSetAllotmentBy($course, $semester)->result();
        $studentList = array();
        if (sizeof($student_info)) {
            for ($i = 0; $i < sizeof($student_info); $i++) {
                $gender = "";
                if ($student_info[$i]->tspi_gender == "M") {
                    $gender = "<i class='fa fa-male'></i>|Male";
                } else if ($student_info[$i]->tspi_gender == "F") {
                    $gender = "<i class='fa fa-female'></i>|Female";
                } else {
                    $gender = "<i class='fa fa-transgender'></i>|Transgender";
                }
                $thisStudentInfo = array(
                    'stu_id' => $student_info[$i]->tspi_id,
                    'stu_name' => stripslashes($student_info[$i]->tspi_name),
                    'stu_gender' => $gender,
                    'stu_roll_no' => stripslashes($student_info[$i]->tspi_rollNumber),
                    'stu_dob' => date('d-m-Y', strtotime($student_info[$i]->tspi_dob)),
                    'stu_course' => stripslashes($student_info[$i]->course_name),
                    'stu_session' => stripslashes($student_info[$i]->session_name),
                    'stu_entry_type' => stripslashes($student_info[$i]->tcsm_course_type),
                    'stu_section' => $student_info[$i]->tsssi_section
                );
                array_push($studentList, $thisStudentInfo);
            }
            $responseData = array(
                'csrfName' => $this->security->get_csrf_token_name(),
                'csrfHash' => $this->security->get_csrf_hash(),
                'available_students' => sizeof($student_info),
                'student_list' => $studentList,
                'message' => 'Students Available'
            );
        } else {
            $responseData = array(
                'csrfName' => $this->security->get_csrf_token_name(),
                'csrfHash' => $this->security->get_csrf_hash(),
                'available_students' => 0,
                'student_list' => $studentList,
                'message' => 'No Students Available For Set Allotment'
            );
        }
        echo json_encode($responseData);
    }

    public function getEnrolledStudentsInSemesterForTeacherSubjectAllotment() {
        $semester = $_POST['semester'];
        $course = $_POST['course'];
        $subject = $_POST['sm_id'];
        $session = $_POST['session'];
        $emp = $_POST['emp'];
        $student_info = $this->StudentManagement->getAllEnrolledStudentsForTeacherSubjectAllotmentBy($course, $semester, $subject, $session, $emp)->result();
        $studentList = array();
        if (sizeof($student_info)) {
            for ($i = 0; $i < sizeof($student_info); $i++) {
                $gender = "";
                if ($student_info[$i]->tspi_gender == "M") {
                    $gender = "<i class='fa fa-male'></i>|Male";
                } else if ($student_info[$i]->tspi_gender == "F") {
                    $gender = "<i class='fa fa-female'></i>|Female";
                } else {
                    $gender = "<i class='fa fa-transgender'></i>|Transgender";
                }
                $thisStudentInfo = array(
                    'stu_id' => $student_info[$i]->tspi_id,
                    'stu_name' => stripslashes($student_info[$i]->tspi_name),
                    'stu_gender' => $gender,
                    'stu_roll_no' => stripslashes($student_info[$i]->tspi_rollNumber),
                );
                array_push($studentList, $thisStudentInfo);
            }
            $responseData = array(
                'csrfName' => $this->security->get_csrf_token_name(),
                'csrfHash' => $this->security->get_csrf_hash(),
                'available_students' => sizeof($student_info),
                'student_list' => $studentList,
                'message' => 'Students Available'
            );
        } else {
            $responseData = array(
                'csrfName' => $this->security->get_csrf_token_name(),
                'csrfHash' => $this->security->get_csrf_hash(),
                'available_students' => 0,
                'student_list' => $studentList,
                'message' => 'No Students Available For Allotment'
            );
        }
        echo json_encode($responseData);
    }

    public function getStudentsAllotedToTeacherBy() {
        $sta_id = $_POST['sta_id'];
        $mepm_id = (isset($_POST['mepm_id'])) ? $_POST['mepm_id'] : "";
        $mepsch_id = (isset($_POST['mepsch_id'])) ? $_POST['mepsch_id'] : "";
        $alloted_student_info = $this->StudentManagement->getAllAllotedStudentsToTeacher($sta_id)->result();
        $studentList = array();
        if (sizeof($alloted_student_info)) {
            for ($i = 0; $i < sizeof($alloted_student_info); $i++) {
                $gender = "";
                $if_mepm_sch = false;
                if ($alloted_student_info[$i]->tspi_gender == "M") {
                    $gender = "<i class='fa fa-male'></i>|Male";
                } else if ($alloted_student_info[$i]->tspi_gender == "F") {
                    $gender = "<i class='fa fa-female'></i>|Female";
                } else {
                    $gender = "<i class='fa fa-transgender'></i>|Transgender";
                }
                if (sizeof($this->TaskAndQuizManagement->getAllottedModelPapersBySchedule($mepsch_id, $mepm_id, $alloted_student_info[$i]->tspi_id)->result())) {
                    $if_mepm_sch = true;
                }
                if (sizeof($this->TaskAndQuizManagement->getAssignedEContentsBySchedule($mepsch_id, $mepm_id, $alloted_student_info[$i]->tspi_id)->result())) {
                    $if_mepm_sch = true;
                }
                $thisStudentInfo = array(
                    'stu_id' => $alloted_student_info[$i]->tspi_id,
                    'stu_name' => stripslashes($alloted_student_info[$i]->tspi_name),
                    'stu_gender' => $gender,
                    'stu_roll_no' => ($alloted_student_info[$i]->tspi_rollNumber == $alloted_student_info[$i]->tspi_form_no) ? "-" : stripslashes($alloted_student_info[$i]->tspi_rollNumber),
                    'stu_clg_id' => ($alloted_student_info[$i]->tspi_enrollment_no == $alloted_student_info[$i]->tspi_form_no) ? "-" : stripslashes($alloted_student_info[$i]->tspi_enrollment_no),
                    'stu_dob' => date('d-m-Y', strtotime($alloted_student_info[$i]->tspi_dob)),
                    'stu_course' => stripslashes($alloted_student_info[$i]->course_name),
                    'stu_session' => stripslashes($alloted_student_info[$i]->session_name),
                    'stu_entry_type' => stripslashes($alloted_student_info[$i]->tcsm_course_type),
                    'stta_id' => $alloted_student_info[$i]->stta_id,
                    'if_mepm_sch' => $if_mepm_sch
                );
                array_push($studentList, $thisStudentInfo);
            }
            $responseData = array(
                'csrfName' => $this->security->get_csrf_token_name(),
                'csrfHash' => $this->security->get_csrf_hash(),
                'available_students' => sizeof($alloted_student_info),
                'student_list' => $studentList,
                'message' => 'Students Available'
            );
        } else {
            $responseData = array(
                'csrfName' => $this->security->get_csrf_token_name(),
                'csrfHash' => $this->security->get_csrf_hash(),
                'available_students' => 0,
                'student_list' => $studentList,
                'message' => 'No Students Available For Allotment'
            );
        }
        echo json_encode($responseData);
    }

    public function getAllStudentAllotedToSubject() {
        $subjectAllotmentID = $_POST['subject'];
        $student_info = $this->StudentManagement->getAllStudentAllotedToSubject($subjectAllotmentID)->result();
        $studentList = array();
        if (sizeof($student_info)) {
            for ($i = 0; $i < sizeof($student_info); $i++) {
                $gender = "";
                if ($student_info[$i]->tspi_gender == "M") {
                    $gender = "<i class='fa fa-male'></i>|Male";
                } else if ($student_info[$i]->tspi_gender == "F") {
                    $gender = "<i class='fa fa-female'></i>|Female";
                } else {
                    $gender = "<i class='fa fa-transgender'></i>|Transgender";
                }
                $thisStudentInfo = array(
                    'stu_id' => $student_info[$i]->tspi_id,
                    'stu_name' => stripslashes($student_info[$i]->tspi_name),
                    'stu_gender' => $gender,
                    'stu_form_no' => stripslashes($student_info[$i]->tspi_form_no),
                    'stu_enroll_no' => ($student_info[$i]->tspi_enrollment_no == $student_info[$i]->tspi_form_no) ? "-" : stripslashes($student_info[$i]->tspi_enrollment_no),
                    'stu_dob' => date('d-m-Y', strtotime($student_info[$i]->tspi_dob)),
                    'stu_course' => stripslashes($student_info[$i]->course_name),
                    'stu_semester' => stripslashes($student_info[$i]->student_semester),
                    'stu_session' => stripslashes($student_info[$i]->session_name),
                    'stu_entry_type' => stripslashes($student_info[$i]->tcsm_course_type)
                );
                array_push($studentList, $thisStudentInfo);
            }
            $responseData = array(
                'csrfName' => $this->security->get_csrf_token_name(),
                'csrfHash' => $this->security->get_csrf_hash(),
                'available_students' => sizeof($student_info),
                'student_list' => $studentList,
                'message' => 'Students Available'
            );
        } else {
            $responseData = array(
                'csrfName' => $this->security->get_csrf_token_name(),
                'csrfHash' => $this->security->get_csrf_hash(),
                'available_students' => 0,
                'student_list' => $studentList,
                'message' => 'No Students Available'
            );
        }
        echo json_encode($responseData);
    }

    public function feedStudentSubjectSemMarks() {
        if ($this->sessionvalidator->isLoggedIn()) {
            $viewData['sessions'] = $this->SessionManagement->getNonDeletedActiveSessions()->result();
            if (isset($_POST["filterTestBtn"])) {
                $session = $this->input->post("session");
                $subject = $this->input->post("sm_name");
                $viewData["selectedSubject"] = $subject;
                $viewData["studentAllottedData"] = $this->StudentManagement->getAllStudentAllotedToSubjectForSemMarksFeeding($subject, $session)->result();
                if (sizeof($viewData["studentAllottedData"]) == 0) {
                    $this->session->set_flashdata("errorMessage", "No Student are Available in this Subject.");
                }
            } else if (isset($_POST["allotBtn"])) {
                $session = $this->input->post("session");
                $subject = $this->input->post("sm_name");
                $newStudentQuesMarkData = array();
                $viewData["selectedSubject"] = $subject;
                $viewData["studentAllottedData"] = $this->StudentManagement->getAllStudentAllotedToSubjectForSemMarksFeeding($subject, $session)->result();
                $studentAllottedData = $this->StudentManagement->getAllStudentAllotedToSubjectForSemMarksFeeding($subject, $session)->result();
                for ($i = 0; $i < sizeof($studentAllottedData); $i++) {
                    if ($this->input->post("box" . $studentAllottedData[$i]->tspi_rollNumber) == $studentAllottedData[$i]->tspi_rollNumber) {

                        array_push($newStudentQuesMarkData, array(
                            "session_id" => $session,
                            "sm_id" => $subject,
                            "sssm_max_marks" => $this->input->post("sssm_max_marks"),
                            "tspi_id" => $studentAllottedData[$i]->tspi_id,
                            "sssm_marks" => $this->input->post("obt" . $i),
                            "sssm_flag" => $this->input->post($studentAllottedData[$i]->tspi_rollNumber),
                            "sssm_added_by" => $this->session->userdata("adminData")["smember_id"],
                            "sssm_added_on" => date("Y-m-d H:i:s"),
                            "sssm_updated_by" => $this->session->userdata("adminData")["smember_id"],
                            "sssm_updated_on" => date("Y-m-d H:i:s")
                        ));
                    }
                }
                $this->db->trans_start();
                if ($this->StudentManagement->feedNewStudentSubjectSemObtainMarks($newStudentQuesMarkData)) {
                    $this->db->trans_complete();
                    $this->session->set_flashdata("successMessage", "Save Student Subject Semester Marks Successful.");
                    redirect("admin/Student/feedStudentSubjectSemMarks");
                } else {
                    $this->session->set_flashdata("errorMessage", "An Error Occured While Student Subject Semester Marks . Try Later.");
                    redirect(current_url());
                }
            } else {
                $viewData["selectedSubject"] = "";
                $viewData["studentAllottedData"] = array();
            }

            $this->load->view("admin/academics/feedStudentSubjectSemMarks", $viewData);
        } else {
            redirect("admin/");
        }
    }

    public function viewStudentSubjectSemMarks() {
        if ($this->sessionvalidator->isLoggedIn()) {
            $viewData['sessions'] = $this->SessionManagement->getNonDeletedActiveSessions()->result();
            if (isset($_POST["filterTestBtn"])) {
                $session = $this->input->post("session");
                $subject = $this->input->post("sm_name");
                $viewData["selectedSubject"] = $subject;
                $viewData["studentAllottedData"] = $this->StudentManagement->getAllStudentAllotedToSubjectForSemMarksView($subject, $session)->result();
                if (sizeof($viewData["studentAllottedData"]) == 0) {
                    $this->session->set_flashdata("errorMessage", "No Student are Available in this Subject.");
                }
            } else {
                $viewData["selectedSubject"] = "";
                $viewData["studentAllottedData"] = array();
            }

            $this->load->view("admin/academics/viewStudentSubjectSemMarks", $viewData);
        } else {
            redirect("admin/");
        }
    }

    public function editStudentSubjectSemMarks() {
        if ($this->sessionvalidator->isLoggedIn()) {
            $viewData['sessions'] = $this->SessionManagement->getNonDeletedActiveSessions()->result();
            if (isset($_POST["filterTestBtn"])) {
                $session = $this->input->post("session");
                $subject = $this->input->post("sm_name");
                $viewData["selectedSubject"] = $subject;
                $viewData["studentAllottedData"] = $this->StudentManagement->getAllStudentAllotedToSubjectForSemMarksView($subject, $session)->result();
                if (sizeof($viewData["studentAllottedData"]) == 0) {
                    $this->session->set_flashdata("errorMessage", "No Student are Available in this Subject.");
                }
            } else if (isset($_POST["allotBtn"])) {
                $session = $this->input->post("session");
                $subject = $this->input->post("sm_name");
                $newStudentQuesMarkData = array();
                $viewData["selectedSubject"] = $subject;
                $viewData["studentAllottedData"] = $this->StudentManagement->getAllStudentAllotedToSubjectForSemMarksView($subject, $session)->result();
                $studentAllottedData = $this->StudentManagement->getAllStudentAllotedToSubjectForSemMarksView($subject, $session)->result();
                $subjectMaxMarkData = array(
                    "sssm_max_marks" => $this->input->post("sssm_max_marks"),
                    "sssm_updated_by" => $this->session->userdata("adminData")["smember_id"],
                    "sssm_updated_on" => date("Y-m-d H:i:s")
                );
                $this->StudentManagement->updateFeedNewStudentSubjectSemMaxMarks($subjectMaxMarkData, $session, $subject);

                for ($i = 0; $i < sizeof($studentAllottedData); $i++) {
                    if ($this->input->post("box" . $studentAllottedData[$i]->tspi_rollNumber) == $studentAllottedData[$i]->tspi_rollNumber) {

                        array_push($newStudentQuesMarkData, array(
                            "sssm_id" => $this->input->post("obt-mm" . $i),
                            "tspi_id" => $studentAllottedData[$i]->tspi_id,
                            "sssm_flag" => $this->input->post($studentAllottedData[$i]->tspi_rollNumber),
                            "sssm_marks" => $this->input->post("obt" . $i),
                            "sssm_added_by" => $this->session->userdata("adminData")["smember_id"],
                            "sssm_added_on" => date("Y-m-d H:i:s"),
                            "sssm_updated_by" => $this->session->userdata("adminData")["smember_id"],
                            "sssm_updated_on" => date("Y-m-d H:i:s")
                        ));
                    }
                }
                $this->db->trans_start();
                $this->StudentManagement->updateFeedNewStudentSubjectSemMaxMarks($subjectMaxMarkData, $session, $subject);
                if ($this->StudentManagement->updateFeedNewStudentSubjectSemObtainMarks($newStudentQuesMarkData)) {
                    $this->db->trans_complete();
                    $this->session->set_flashdata("successMessage", "Save Student Subject Semester Marks Successful.");
                    redirect("admin/Student/editStudentSubjectSemMarks");
                } else {
                    $this->session->set_flashdata("errorMessage", "An Error Occured While Student Subject Semester Marks . Try Later.");
                    redirect(current_url());
                }
            } else {
                $viewData["selectedSubject"] = "";
                $viewData["studentAllottedData"] = array();
            }
            $this->load->view("admin/academics/editStudentSubjectSemMarks", $viewData);
        } else {
            redirect("admin/");
        }
    }

    public function getAttendanceToSubject() {
        $adminData = $this->session->userdata("adminData");
        $subject = $_POST['subject'];
        $slot = $_POST['slot'];
        $attDate = $_POST['attDate'];
        $session = $_POST['session'];
        $student_info = $this->AttendanceManagement->getAttendanceBy($subject, $slot, $session, $adminData["smember_id"], date('Y-m-d', strtotime(str_replace('/', '-', $attDate))))->result();
        $studentList = array();
        if (sizeof($student_info)) {
            for ($i = 0; $i < sizeof($student_info); $i++) {
                $gender = "";
                if ($student_info[$i]->tspi_gender == "M") {
                    $gender = "<i class='fa fa-male'></i>|Male";
                } else if ($student_info[$i]->tspi_gender == "F") {
                    $gender = "<i class='fa fa-female'></i>|Female";
                } else {
                    $gender = "<i class='fa fa-transgender'></i>|Transgender";
                }
                $thisStudentInfo = array(
                    'stu_id' => $student_info[$i]->tspi_id,
                    'stu_name' => stripslashes($student_info[$i]->tspi_name),
                    'stu_gender' => $gender,
                    'stu_form_no' => stripslashes($student_info[$i]->tspi_form_no),
                    'stu_enroll_no' => ($student_info[$i]->tspi_enrollment_no == $student_info[$i]->tspi_form_no) ? "-" : stripslashes($student_info[$i]->tspi_enrollment_no),
                    'stu_roll_no' => stripslashes($student_info[$i]->tspi_enrollment_no),
                    'stu_semester' => stripslashes($student_info[$i]->student_semester),
                    'sam_flag' => stripslashes($student_info[$i]->sam_flag),
                    'sam_remark' => stripslashes($student_info[$i]->sam_remark)
                );
                array_push($studentList, $thisStudentInfo);
            }
            $responseData = array(
                'csrfName' => $this->security->get_csrf_token_name(),
                'csrfHash' => $this->security->get_csrf_hash(),
                'available_students' => sizeof($student_info),
                'student_list' => $studentList,
                'message' => 'Students Available'
            );
        } else {
            $responseData = array(
                'csrfName' => $this->security->get_csrf_token_name(),
                'csrfHash' => $this->security->get_csrf_hash(),
                'available_students' => 0,
                'student_list' => $studentList,
                'message' => 'No Students Available'
            );
        }
        echo json_encode($responseData);
    }

    public function uploadCounsellingData() {
        if ($this->sessionvalidator->isLoggedIn() && $this->sessionvalidator->isAccessGranted()) {
            if (isset($_POST['updateSubmitBtn'])) {
                if (empty($_FILES['bulkCounsellingInfoFile']['name'])) {
                    $this->session->set_flashdata('errorMessage', "Please Upload Any Excel File.");
                    redirect("admin/Student/uploadCounsellingData");
                } else {
                    $configBulkFile['upload_path'] = './assets/admin/uploads/bulkfiles/counsellinginfo/';
                    $configBulkFile['allowed_types'] = 'csv';
                    $configBulkFile['max_size'] = '2048';
                    $configBulkFile['file_ext_tolower'] = TRUE;
                    $configBulkFile['file_name'] = "counsellingData.csv";
                    $this->load->library('upload', $configBulkFile);
                    $this->upload->overwrite = true;
                    if (!$this->upload->do_upload('bulkCounsellingInfoFile')) {
                        $this->session->set_flashdata('errorMessage', "Error! Only CSV (With *.csv Extension) Files With Max. Size 2MB Is Allowed.");
                        redirect("admin/Student/uploadCounsellingData");
                    } else {
                        $this->session->set_flashdata('successMessage', "Counselling Data CSV File Uploaded Successfully.");
                        redirect("admin/Student/uploadCounsellingData");
                    }
                }
            } else {
                $this->load->view('admin/student/uploadCounsellingData');
            }
        } else {
            redirect("admin/");
        }
    }

}

KBHT - 2023