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

[  Home  ][  C0mmand  ][  Upload File  ]

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

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

class OBESConfig extends CI_Controller {

    public function __construct() {
        parent::__construct();
        $this->load->model("admin/OBESManagement");
        $this->load->model("admin/CourseManagement");
        $this->load->model("admin/SubjectManagement");
        $this->load->model("admin/SessionManagement");
    }

    public function index() {
        if ($this->sessionvalidator->isLoggedIn() && $this->sessionvalidator->isAccessGranted()) {
            $viewdata["criteria"] = $this->OBESManagement->getAllCriteria()->result();
            $this->load->view("admin/obes/criteria", $viewdata);
        } else {
            redirect("admin/");
        }
    }

    public function createCriteria() {
        if ($this->sessionvalidator->isLoggedIn()) {
            $this->load->view("admin/obes/createCriterion");
        } else {
            redirect("admin/");
        }
    }

    public function saveNewCriteria() {
        if ($this->sessionvalidator->isLoggedIn()) {
            $this->form_validation->set_rules("cr_name", "Criteria Name", "trim|required", array("required" => "Criteria Name Is Required."));
            $this->form_validation->set_rules("cr_marks", "Criteria Marks", "trim|required|numeric", array("required" => "Criteria Marks Is Required."));
            $this->form_validation->set_rules("cr_order", "Criteria Order", "trim|required|numeric", array("required" => "Criteria Order Is Required."));
            $criteriaInfoByName = $this->OBESManagement->getCriteriaByName(trim($this->input->post("cr_name")))->result();
            $criteriaInfoByOrder = $this->OBESManagement->getCriteriaByOrder(trim($this->input->post("cr_order")))->result();
            if ($this->form_validation->run() == false) {
                $this->createCriteria();
            } else if (sizeof($criteriaInfoByName)) {
                $this->session->set_flashdata("errorMessage", "Entered Criteria (" . addslashes(trim($this->input->post("cr_name"))) . ") Already Exist. Please Choose A Different Criteria Name.");
                $this->createCriteria();
            } else if (sizeof($criteriaInfoByOrder)) {
                $this->session->set_flashdata("errorMessage", "Entered Criteria Order Is Already In Use. Please Enter A Different Order.");
                $this->createCriteria();
            } else {
                $newCriteriaInfo = array(
                    "cr_name" => addslashes(trim($this->input->post("cr_name"))),
                    "cr_marks" => trim($this->input->post("cr_marks")),
                    "cr_order" => trim($this->input->post("cr_order")),
                    "cr_added_by" => $this->session->userdata("adminData")["smember_id"],
                    "cr_added_on" => date("Y-m-d H:i:s"),
                    "cr_update_by" => $this->session->userdata("adminData")["smember_id"],
                    "cr_update_on" => date("Y-m-d H:i:s")
                );
                if ($cr_id = $this->OBESManagement->createNewCriteria($newCriteriaInfo)) {
                    $this->session->set_flashdata("successMessage", "Criteria Created Successfully.");
                    redirect("admin/OBESConfig");
                } else {
                    $this->session->set_flashdata("errorMessage", "An Error Occured While Creating Criteria. Try Later.");
                    $this->createCriteria();
                }
            }
        } else {
            redirect("admin/");
        }
    }

    public function editCriteria($cr_id) {
        if ($this->sessionvalidator->isLoggedIn()) {
            $viewData["route"] = $this->OBESManagement->getCriteriaById($cr_id)->result()[0];
            $this->load->view("admin/obes/editCriterion", $viewData);
        } else {
            redirect("admin/");
        }
    }

    public function updateCriteria() {
        if ($this->sessionvalidator->isLoggedIn()) {
            $cr_id = trim($this->input->post("cr_id"));
            $this->form_validation->set_rules("cr_name", "Criteria name", "trim|required", array("required" => "Criteria Name Is Required."));
            $this->form_validation->set_rules("cr_marks", "Criteria Marks", "trim|required|numeric", array("required" => "Criteria Marks Is Required."));
            $this->form_validation->set_rules("cr_order", "Criteria Order", "trim|required|numeric", array("required" => "Criteria Order Is Required."));
            if ($this->form_validation->run() == false) {
                $this->editCriteria($cr_id);
            } else if (!$this->OBESManagement->isCriteriaNameSafeUpdate($cr_id, addslashes(trim($this->input->post('cr_name'))))) {
                $this->session->set_flashdata("errorMessage", "Entered Criteria (" . addslashes(trim($this->input->post("cr_name"))) . ") Already Exist. Please Choose Different Criteria Name.");
                $this->editCriteria($cr_id);
            } else if (!$this->OBESManagement->isCriteriaOrderSafeUpdate($cr_id, addslashes(trim($this->input->post('cr_order'))))) {
                $this->session->set_flashdata("errorMessage", "Entered Criteria Order Already Exist.");
                $this->editCriteria($cr_id);
            } else {
                $criteriaDetails = array(
                    "cr_name" => addslashes(trim($this->input->post("cr_name"))),
                    "cr_marks" => trim($this->input->post("cr_marks")),
                    "cr_order" => trim($this->input->post("cr_order")),
                    "cr_update_on" => date("Y-m-d H:i:s"),
                    "cr_update_by" => $this->session->userdata("adminData")["smember_id"]
                );
                if ($this->OBESManagement->updateCriteriaInfo($criteriaDetails, $cr_id)) {
                    $this->session->set_flashdata("successMessage", "Criteria Updated Successfully.");
                    redirect("admin/OBESConfig");
                } else {
                    $this->session->set_flashdata("errorMessage", "An Error Occured While Updating Criteria. Try Later.");
                    redirect(current_url());
                }
            }
        } else {
            redirect("admin/");
        }
    }

    public function toggleCriteriaStatus($cr_id, $changedStatus) {
        if ($this->sessionvalidator->isLoggedIn()) {
            $criteriaData = array(
                'cr_update_on' => date("Y-m-d H:i:s"),
                'cr_update_by' => $this->session->userdata("adminData")["smember_id"],
                'cr_active_status' => $changedStatus
            );
            if ($this->OBESManagement->updateCriteriaInfo($criteriaData, $cr_id)) {
                $this->session->set_flashdata('successMessage', 'Criteria Status Updated Successfully.');
                redirect("admin/OBESConfig");
            } else {
                $this->session->set_flashdata('errorMessage', 'Some Error Occurred While Updating Criteria Status. Try Later.');
                redirect(current_url());
            }
        } else {
            redirect("admin/");
        }
    }

    public function toggleCriteriaDeleteStatus($cr_id, $changeStatus) {
        if ($this->sessionvalidator->isLoggedIn()) {
            $routeUpdateData = array(
                'cr_update_on' => date("Y-m-d H:i:s"),
                'cr_update_by' => $this->session->userdata("adminData")["smember_id"],
                'cr_delete_status' => $changeStatus
            );
            if ($this->OBESManagement->updateCriteriaInfo($routeUpdateData, $cr_id)) {
                $this->session->set_flashdata('successMessage', 'Criteria Delete Status Updated Successfully.');
                redirect("admin/OBESConfig");
            } else {
                $this->session->set_flashdata('errorMessage', 'Some Error Occurred While Updating Delete Status Of Criteria. Try Later.');
                redirect(current_url());
            }
        } else {
            redirect("admin/");
        }
    }

    /* Request Handlers For Sub-Criterias */

    public function subCriteria() {
        if ($this->sessionvalidator->isLoggedIn() && $this->sessionvalidator->isAccessGranted()) {
            $viewdata["subCriteria"] = $this->OBESManagement->getAllSubCriteria()->result();
            $this->load->view("admin/obes/subCriteria", $viewdata);
        } else {
            redirect("admin/");
        }
    }

    public function createSubCriteria() {
        if ($this->sessionvalidator->isLoggedIn()) {
            $viewdata["criteria"] = $this->OBESManagement->getAllNonDeletedCriteria()->result();
            $this->load->view("admin/obes/createSubCriteria", $viewdata);
        } else {
            redirect("admin/");
        }
    }

    public function saveNewSubCriteria() {
        if ($this->sessionvalidator->isLoggedIn()) {
            $this->form_validation->set_rules("cr_name", "Criteria", "trim|required", array("required" => "Please Select Any Criteria."));
            $this->form_validation->set_rules("csm_name", "Sub Criteria Name", "trim|required", array("required" => "Enter Sub-Criteria Name."));
            $this->form_validation->set_rules("csm_marks", "Sub Criteria Marks", "trim|required|numeric", array("required" => "Enter Sub-Criteria Marks."));
            $subCriteriaInfoByName = $this->OBESManagement->getSubCriteriaInfoByName(addslashes(trim($this->input->post("csm_name"))))->result();
            if ($this->form_validation->run() == false) {
                $this->createSubCriteria();
            } else if (sizeof($subCriteriaInfoByName)) {
                $this->session->set_flashdata("errorMessage", "Entered Sub-Criteria (" . addslashes(trim($this->input->post("csm_name"))) . ") Already Exist. Please Choose Different Sub-Criteria Name.");
                $this->createSubCriteria();
            } else {
                $newSubCriteriaInfo = array(
                    "cr_id" => trim($this->input->post("cr_name")),
                    "csm_name" => addslashes(trim($this->input->post("csm_name"))),
                    "csm_marks" => trim($this->input->post("csm_marks")),
                    "csm_added_by" => $this->session->userdata("adminData")["smember_id"],
                    "csm_added_on" => date("Y-m-d H:i:s"),
                    "csm_update_by" => $this->session->userdata("adminData")["smember_id"],
                    "csm_update_on" => date("Y-m-d H:i:s")
                );
                if ($this->OBESManagement->createNewSubCriteria($newSubCriteriaInfo)) {
                    $this->session->set_flashdata("successMessage", "Sub-Criteria Created Successfully.");
                    redirect("admin/OBESConfig/subCriteria");
                } else {
                    $this->session->set_flashdata("errorMessage", "An Error Occured While Creating Sub-Criteria. Try Later.");
                    redirect(current_url());
                }
            }
        } else {
            redirect("admin/");
        }
    }

    public function editSubCriteria($csm_id) {
        if ($this->sessionvalidator->isLoggedIn()) {
            $viewData["subCriteriaInfo"] = $this->OBESManagement->getSubCriteriaById($csm_id)->result()[0];
            $viewData["criteria"] = $this->OBESManagement->getAllNonDeletedCriteria()->result();
            $this->load->view("admin/obes/editSubCriteria", $viewData);
        } else {
            redirect("admin/");
        }
    }

    public function updateSubCriteria() {
        if ($this->sessionvalidator->isLoggedIn()) {
            $csm_id = addslashes(trim($this->input->post("csm_id")));
            $this->form_validation->set_rules("csm_name", "Criteria name", "trim|required", array("required" => "Enter Sub Criteria Name."));
            $this->form_validation->set_rules("csm_marks", "Marks", "trim|required|numeric", array("required" => "Enter Sub Criteria marks"));
            if ($this->form_validation->run() == false) {
                $this->editSubCriteria($csm_id);
            } else if (!$this->OBESManagement->isSubCriteriaNameSafeUpdate($csm_id, addslashes(trim($this->input->post('csm_name'))))) {
                $this->session->set_flashdata("errorMessage", "Entered Sub Criteria (" . addslashes(trim($this->input->post('csm_name'))) . ") Already Exist. Please Choose A Different Sub-Criteria Name.");
                $this->editSubCriteria($csm_id);
            } else {
                $subCriteriaUpdateInfo = array(
                    "cr_id" => trim($this->input->post('cr_name')),
                    "csm_name" => addslashes(trim($this->input->post('csm_name'))),
                    "csm_marks" => trim($this->input->post('csm_marks')),
                    "csm_update_on" => date("Y-m-d H:i:s"),
                    "csm_update_by" => $this->session->userdata("adminData")["smember_id"]
                );
                if ($this->OBESManagement->updateSubCriteriaInfo($subCriteriaUpdateInfo, $csm_id)) {
                    $this->session->set_flashdata("successMessage", "Sub-Criteria Updated Successfully.");
                    redirect("admin/OBESConfig/subCriteria");
                } else {
                    $this->session->set_flashdata("errorMessage", "An Error Occured While Updating Sub-Criteria. Try Later.");
                    redirect(current_url());
                }
            }
        } else {
            redirect("admin/");
        }
    }

    public function toggleSubCriteriaStatus($csm_id, $toUpdateStatus) {
        if ($this->sessionvalidator->isLoggedIn()) {
            $criteriaData = array(
                'csm_update_on' => date("Y-m-d H:i:s"),
                "csm_update_by" => $this->session->userdata("adminData")["smember_id"],
                'csm_active_status' => $toUpdateStatus
            );
            if ($this->OBESManagement->updateSubCriteriaInfo($criteriaData, $csm_id)) {
                $this->session->set_flashdata('successMessage', 'Sub-Criteria Status Updated Successfully.');
                redirect("admin/OBESConfig/subCriteria");
            } else {
                $this->session->set_flashdata('errorMessage', 'Some Error Occurred While Updating Criteria Status. Try Later.');
                redirect(current_url());
            }
        } else {
            redirect("admin/");
        }
    }

    public function toggleSubCriteriaDeleteStatus($csm_id, $toUpdateStatus) {
        if ($this->sessionvalidator->isLoggedIn()) {
            $csmUpdateData = array(
                'csm_update_on' => date("Y-m-d H:i:s"),
                "csm_update_by" => $this->session->userdata("adminData")["smember_id"],
                'csm_delete_status' => $toUpdateStatus
            );
            if ($this->OBESManagement->updateSubCriteriaInfo($csmUpdateData, $csm_id)) {
                $this->session->set_flashdata('successMessage', 'Sub-Criteria Delete Status Updated Successfully.');
                redirect("admin/OBESConfig/subCriteria");
            } else {
                $this->session->set_flashdata('errorMessage', 'Some Error Occurred While Updating Delete Status Of Sub-Criteria. Try Later.');
                redirect(current_url());
            }
        } else {
            redirect("admin/");
        }
    }

    public function getActiveSubCriteriaByCriteria() {
        $cr_id = $this->input->post("cr_name");
        $csm_id = $this->input->post("csm_id");
        $query = $this->OBESManagement->getAllSubCriteriaUnderGivenCriteria($cr_id);
        $data = $query->result();
        $options = "<option value=''>Select Sub Criteria</option>";
        for ($i = 0; $i < (sizeof($data)); $i++) {
            $selected = ($csm_id == $data[$i]->csm_id) ? "selected" : "";
            $options .= "<option " . $selected . " value=" . $data[$i]->csm_id . ">" . $data[$i]->csm_name . "</option>";
        }
        $responseData = array(
            'csrfName' => $this->security->get_csrf_token_name(),
            'csrfHash' => $this->security->get_csrf_hash(),
            'csm_list' => $options
        );
        echo json_encode($responseData);
    }

    /* Request Handlers For Sub-Criteria Guidelines */

    public function guidelines() {
        if ($this->sessionvalidator->isLoggedIn() && $this->sessionvalidator->isAccessGranted()) {
            $viewdata["guidelines"] = $this->OBESManagement->getAllSubCriteriaGuidelines()->result();
            $this->load->view("admin/obes/guidelines", $viewdata);
        } else {
            redirect("admin/");
        }
    }

    public function createGuideline() {
        if ($this->sessionvalidator->isLoggedIn()) {
            $viewdata["criteria"] = $this->OBESManagement->getAllNonDeletedCriteria()->result();
            $this->load->view("admin/obes/createGuideline", $viewdata);
        } else {
            redirect("admin/");
        }
    }

    public function saveNewGuideline() {
        if ($this->sessionvalidator->isLoggedIn()) {
            $this->form_validation->set_rules("csgm_name", "Guideline Name", "trim|required", array("required" => "Please Enter Guideline Name."));
            $this->form_validation->set_rules("csgm_marks", "Guideline Marks", "trim|required|numeric", array("required" => "Please Enter Guideline Marks."));
            $this->form_validation->set_rules("cr_name", "Criteria name", "trim|required", array("required" => "Please Select Any Criteria."));
            $this->form_validation->set_rules("csm_name", "Sub Criteria name", "trim|required", array("required" => "Please Select Any Sub-Criteria."));
            $this->form_validation->set_rules("up_type", "Upload Type", "trim|required", array("required" => "Please Select File Upload Type."));
            $guidelineInfoByName = $this->OBESManagement->getGuidelineByInfoByName(addslashes(trim($this->input->post("csgm_name"))))->result();
            if ($this->form_validation->run() == false) {
                $this->createGuideline();
            } else if (sizeof($guidelineInfoByName)) {
                $this->session->set_flashdata("errorMessage", "Entered Guideline (" . addslashes(trim($this->input->post("csgm_name"))) . ") Already Exist. Please Choose Different Name.");
                $this->createGuideline();
            } else {
                $newGuidelineInfo = array(
                    "csm_id" => trim($this->input->post("csm_name")),
                    "csgm_name" => addslashes(trim($this->input->post("csgm_name"))),
                    "csgm_marks" => trim($this->input->post("csgm_marks")),
                    "csgm_upload_type" => trim($this->input->post("up_type")),
                    "csgm_withsession" => trim($this->input->post("ifSession")),
                    "csgm_added_by" => $this->session->userdata("adminData")["smember_id"],
                    "csgm_added_on" => date("Y-m-d H:i:s"),
                    "csgm_update_by" => $this->session->userdata("adminData")["smember_id"],
                    "csgm_update_on" => date("Y-m-d H:i:s")
                );
                if ($this->OBESManagement->createNewGuideline($newGuidelineInfo)) {
                    $this->session->set_flashdata("successMessage", "Guideline Created Successfully.");
                    redirect("admin/OBESConfig/guidelines");
                } else {
                    $this->session->set_flashdata("errorMessage", "An Error Occured While Creating Guideline. Try Later.");
                    redirect(current_url());
                }
            }
        } else {
            redirect("admin/");
        }
    }

    public function editGuideline($csgm_id) {
        if ($this->sessionvalidator->isLoggedIn()) {
            $viewData["criteria"] = $this->OBESManagement->getAllNonDeletedCriteria()->result();
            $viewData["guidelineInfo"] = $this->OBESManagement->getGuidelineByInfoBy($csgm_id)->result()[0];
            $this->load->view("admin/obes/editGuideline", $viewData);
        } else {
            redirect("admin/");
        }
    }

    public function updateGuideline() {
        if ($this->sessionvalidator->isLoggedIn()) {
            $csgm_id = addslashes(trim($this->input->post("csgm_id")));
            $this->form_validation->set_rules("csgm_name", "Criteria name", "trim|required", array("required" => "Enter Sub criteria Name."));
            $this->form_validation->set_rules("csgm_marks", "Marks", "trim|required|numeric", array("required" => "Enter Sub Criteria marks"));
            $this->form_validation->set_rules("cr_name", "Criteria name", "trim|required", array("required" => "Please Select Any Criteria."));
            $this->form_validation->set_rules("csm_name", "Sub Criteria name", "trim|required", array("required" => "Please Select Any Sub-Criteria."));
            $this->form_validation->set_rules("up_type", "Upload Type", "trim|required", array("required" => "Please Select File Upload Type."));
            if ($this->form_validation->run() == false) {
                $this->editGuideline($csgm_id);
            } else if (!$this->OBESManagement->isGuidelineNameSafeUpdate($csgm_id, addslashes(trim($this->input->post('csgm_name'))))) {
                $this->session->set_flashdata("errorMessage", "Entered Sub Criteria (" . addslashes(trim($this->input->post('csgm_name'))) . ") Already Exist. Please Choose A Different Sub-Criteria Name.");
                $this->editGuideline($csgm_id);
            } else {
                $guidelineUpdateData = array(
                    "csm_id" => trim($this->input->post("csm_name")),
                    "csgm_name" => addslashes(trim($this->input->post("csgm_name"))),
                    "csgm_marks" => trim($this->input->post("csgm_marks")),
                    "csgm_upload_type" => trim($this->input->post("up_type")),
                    "csgm_withsession" => trim($this->input->post("ifSession")),
                    "csgm_update_on" => date("Y-m-d H:i:s"),
                    "csgm_update_by" => $this->session->userdata("adminData")["smember_id"]
                );
                if ($this->OBESManagement->updateGuidelineInfo($guidelineUpdateData, $csgm_id)) {
                    $this->session->set_flashdata("successMessage", "Guideline Updated Successfully.");
                    redirect("admin/OBESConfig/guidelines");
                } else {
                    $this->session->set_flashdata("errorMessage", "An Error Occured While Updating Guideline. Try Later.");
                    redirect(current_url());
                }
            }
        } else {
            redirect("admin/");
        }
    }

    public function toggleGudelineStatus($csgm_id, $toUpdateStatus) {
        if ($this->sessionvalidator->isLoggedIn()) {
            $guidelineUpdateData = array(
                'csgm_update_on' => date("Y-m-d H:i:s"),
                'csgm_update_by' => $this->session->userdata("adminData")["smember_id"],
                'csgm_active_status' => $toUpdateStatus
            );
            if ($this->OBESManagement->updateGuidelineInfo($guidelineUpdateData, $csgm_id)) {
                $this->session->set_flashdata('successMessage', 'Guideline Status Updated Successfully.');
                redirect("admin/OBESConfig/guidelines");
            } else {
                $this->session->set_flashdata('errorMessage', 'Some Error Occurred While Updating Guideline Status. Try Later.');
                redirect(current_url());
            }
        } else {
            redirect("admin/");
        }
    }

    public function toggleGuidlineDeleteStatus($csgm_id, $toUpdateStatus) {
        if ($this->sessionvalidator->isLoggedIn()) {
            $guidelineUpdateData = array(
                'csgm_update_on' => date("Y-m-d H:i:s"),
                'csgm_update_by' => $this->session->userdata("adminData")["smember_id"],
                'csgm_delete_status' => $toUpdateStatus
            );
            if ($this->OBESManagement->updateGuidelineInfo($guidelineUpdateData, $csgm_id)) {
                $this->session->set_flashdata('successMessage', 'Guideline Delete Status Updated Successfully.');
                redirect("admin/OBESConfig/guidelines");
            } else {
                $this->session->set_flashdata('errorMessage', 'Some Error Occurred While Updating Delete Status Of Guideline. Try Later.');
                redirect(current_url());
            }
        } else {
            redirect("admin/");
        }
    }

    /* Request Handlers For Programme Outcome Module */

    public function programOutcomes() {
        if ($this->sessionvalidator->isLoggedIn() && $this->sessionvalidator->isAccessGranted()) {
            $viewData["programOutcomes"] = $this->OBESManagement->getAllProgramOutcomes()->result();
            $this->load->view("admin/obes/programOutcomes", $viewData);
        } else {
            redirect("admin/");
        }
    }

    public function createProgramOutcome() {
        if ($this->sessionvalidator->isLoggedIn()) {
            $viewData["courses"] = $this->CourseManagement->getNonDeletedCoursesWithFullInfo()->result();
            $this->load->view("admin/obes/createProgramOutcome", $viewData);
        } else {
            redirect("admin/");
        }
    }

    public function saveNewProgramOutcome() {
        if ($this->sessionvalidator->isLoggedIn()) {
            $this->form_validation->set_rules("course_name", "Course Name", "trim|required", array("required" => "Select Course Name."));
            $this->form_validation->set_rules("po_name", "Program Outcome Name", "trim|required", array("required" => "Enter Program Outcome Name."));
            $this->form_validation->set_rules("po_description", "Program Outcome Description", "trim|required", array("required" => "Enter Program Outcome Description."));
            $poInfoByNameAndCourse = $this->OBESManagement->getProgramOutcomeByNameAndCourse(addslashes(trim($this->input->post("po_name"))), trim($this->input->post("course_name")))->result();
            if ($this->form_validation->run() == false) {
                $this->createProgramOutcome();
            } else if (sizeof($poInfoByNameAndCourse)) {
                $this->session->set_flashdata('errorMessage', "A PO With Selected Course And Name Already Exits. Please Choose A Different Name/Course Combination.");
                $this->createProgramOutcome();
            } else {
                $newPOdata = array(
                    "course_id" => trim($this->input->post("course_name")),
                    "po_name" => addslashes(trim($this->input->post("po_name"))),
                    "po_total_session" => trim($this->input->post("po_total_session")),
                    "po_description" => addslashes(trim($this->input->post("po_description"))),
                    "po_added_by" => $this->session->userdata("adminData")["smember_id"],
                    "po_added_on" => date("Y-m-d H:i:s"),
                    "po_updated_by" => $this->session->userdata("adminData")["smember_id"],
                    "po_updated_on" => date("Y-m-d H:i:s")
                );
                if ($this->OBESManagement->createNewProgramOutcome($newPOdata)) {
                    $this->session->set_flashdata("successMessage", "Program Outcome Created Successfully.");
                    redirect("admin/OBESConfig/programOutcomes");
                } else {
                    $this->session->set_flashdata("errorMessage", "An Error Occured While Creating Program Outcome. Try Later.");
                    redirect(current_url());
                }
            }
        } else {
            redirect("admin/");
        }
    }

    public function editProgramOutcome($po_id) {
        if ($this->sessionvalidator->isLoggedIn()) {
            $viewData["courses"] = $this->CourseManagement->getAllCourses()->result();
            $viewData["poInfo"] = $this->OBESManagement->getProgramOutcomeById($po_id)->result()[0];
            $this->load->view("admin/obes/editProgramOutcome", $viewData);
        } else {
            redirect("admin/");
        }
    }

    public function updateProgramOutcome() {
        if ($this->sessionvalidator->isLoggedIn()) {
            $po_id = addslashes(trim($this->input->post("po_id")));
            $this->form_validation->set_rules("course_name", "Course Name", "trim|required", array("required" => "Select Course Name."));
            $this->form_validation->set_rules("po_name", "Program Outcome Name", "trim|required", array("required" => "Enter Program Outcome Name."));
            $this->form_validation->set_rules("po_mdescription", "Program Outcome Description", "trim|required", array("required" => "Enter Program Outcome Description."));
            if ($this->form_validation->run() == false) {
                $this->editProgramOutcome($po_id);
            } else if (sizeof($this->OBESManagement->isProgramOutcomeSafeUpdate(addslashes(trim($this->input->post("po_name"))), trim($this->input->post("course_name")), $po_id)->result())) {
                $this->session->set_flashdata('errorMessage', "A PO With Selected Course And Name (" . trim($this->input->post('po_name')) . ") Already Exits. Please Choose A Different Name/Course Combination.");
                $this->editProgramOutcome($po_id);
            } else {
                $poUpdatedData = array(
                    "course_id" => trim($this->input->post("course_name")),
                    "po_name" => addslashes(trim($this->input->post("po_name"))),
                    "po_total_session" => trim($this->input->post("po_total_session")),
                    "po_description" => addslashes(trim($this->input->post("po_description"))),
                    "po_updated_by" => $this->session->userdata("adminData")["smember_id"],
                    "po_updated_on" => date("Y-m-d H:i:s")
                );
                if ($this->OBESManagement->updateProgramOutcome($poUpdatedData, $po_id)) {
                    $this->session->set_flashdata("successMessage", "Program Outcome Updated Successfully.");
                    redirect("admin/OBESConfig/programOutcomes");
                } else {
                    $this->session->set_flashdata("errorMessage", "An Error Occured While Updating Program Outcome. Try Later.");
                    redirect(current_url());
                }
            }
        } else {
            redirect("admin/");
        }
    }

    public function toggleProgramOutcomeStatus($po_id, $changedStatus) {
        if ($this->sessionvalidator->isLoggedIn()) {
            $poUpdatedData = array(
                'po_updated_on' => date("Y-m-d H:i:s"),
                'po_updated_by' => $this->session->userdata("adminData")["smember_id"],
                'po_active_status' => $changedStatus
            );
            if ($this->OBESManagement->updateProgramOutcome($poUpdatedData, $po_id)) {
                $this->session->set_flashdata('successMessage', 'Program Outcome Status Updated Successfully.');
                redirect("admin/OBESConfig/programOutcomes");
            } else {
                $this->session->set_flashdata('errorMessage', 'Failed To Update Program Outcome Status. Try Later.');
                redirect(current_url());
            }
        } else {
            redirect("admin/");
        }
    }

    public function toggleProgramOutcomeDeleteStatus($po_id, $changeStatus) {
        if ($this->sessionvalidator->isLoggedIn()) {
            $poUpdatedData = array(
                'po_updated_on' => date("Y-m-d H:i:s"),
                'po_updated_by' => $this->session->userdata("adminData")["smember_id"],
                'po_delete_status' => $changeStatus
            );
            if ($this->OBESManagement->updateProgramOutcome($poUpdatedData, $po_id)) {
                $this->session->set_flashdata('successMessage', 'Program Outcome Delete Status Updated Successfully.');
                redirect("admin/OBESConfig/programOutcomes");
            } else {
                $this->session->set_flashdata('errorMessage', 'Failed To Update Program Outcome Delete Status. Try Later.');
                redirect(current_url());
            }
        } else {
            redirect("admin/");
        }
    }

    public function getPOByCourseForDropdown() {
        $course_id = $this->input->post("course_id");
        $po_id = $this->input->post("po_id");
        $query = $this->OBESManagement->getActiveNonDeletedProgramOutcomeByCourse($course_id);
        $data = $query->result();
        $options = "<option value=''>Select PO</option>";
        for ($i = 0; $i < (sizeof($data)); $i++) {
            $selected = ($po_id == $data[$i]->po_id) ? "selected" : "";
            $options .= "<option " . $selected . " value=" . $data[$i]->po_id . ">" . $data[$i]->po_name . "</option>";
        }
        $responseData = array(
            'csrfName' => $this->security->get_csrf_token_name(),
            'csrfHash' => $this->security->get_csrf_hash(),
            'po_list' => $options,
        );
        echo json_encode($responseData);
    }

    /* Request Handlers For Course Outcome Module */

    public function courseOutcomes() {
        if ($this->sessionvalidator->isLoggedIn() && $this->sessionvalidator->isAccessGranted()) {
            $viewData["courseOutcomes"] = $this->OBESManagement->getAllCourseOutcomes()->result();
            $this->load->view("admin/obes/courseOutcomes", $viewData);
        } else {
            redirect("admin/");
        }
    }

    public function createCourseOutcome() {
        if ($this->sessionvalidator->isLoggedIn()) {
            $viewData["subjects"] = $this->SubjectManagement->getAllActiveNonDeletedSubjects()->result();
            $this->load->view("admin/obes/createCourseOutcome", $viewData);
        } else {
            redirect("admin/");
        }
    }

    public function saveNewCourseOutcome() {
        if ($this->sessionvalidator->isLoggedIn()) {
            $this->form_validation->set_rules("sm_name", "Subject Name", "trim|required", array("required" => "Select Subject Name."));
            $this->form_validation->set_rules("co_name", "Course Outcome Name", "trim|required", array("required" => "Enter Course Outcome Name."));
            $this->form_validation->set_rules("co_total_session", "Total Lecture", "trim|required", array("required" => "Enter Total Lecture."));
            $coInfoByNameAndSubject = $this->OBESManagement->getCourseOutcomeByNameAndSubject(addslashes(trim($this->input->post("co_name"))), trim($this->input->post("sm_name")))->result();
            if ($this->form_validation->run() == false) {
                $this->createCourseOutcome();
            } else if (sizeof($coInfoByNameAndSubject)) {
                $this->session->set_flashdata('errorMessage', "A CO With Selected Subject And Name Already Exits. Please Choose A Different Name/Subject Combination.");
                $this->createCourseOutcome();
            } else {
                $newCOData = array(
                    "sm_id" => trim($this->input->post("sm_name")),
                    "co_name" => addslashes(trim($this->input->post("co_name"))),
                    "co_total_session" => addslashes(trim($this->input->post("co_total_session"))),
                    "co_description" => addslashes(trim($this->input->post("co_description"))),
                    "co_added_by" => $this->session->userdata("adminData")["smember_id"],
                    "co_added_on" => date("Y-m-d H:i:s"),
                    "co_updated_by" => $this->session->userdata("adminData")["smember_id"],
                    "co_updated_on" => date("Y-m-d H:i:s")
                );
                if ($this->OBESManagement->createNewCourseOutcome($newCOData)) {
                    $this->session->set_flashdata("successMessage", "Course Outcome Created Successfully.");
                    redirect("admin/OBESConfig/courseOutcomes");
                } else {
                    $this->session->set_flashdata("errorMessage", "An Error Occured While Creating Course Outcome. Try Later.");
                    redirect(current_url());
                }
            }
        } else {
            redirect("admin/");
        }
    }

    public function editCourseOutcome($co_id) {
        if ($this->sessionvalidator->isLoggedIn()) {
            $viewData["subjects"] = $this->SubjectManagement->getAllActiveNonDeletedSubjects()->result();
            $viewData["coInfo"] = $this->OBESManagement->getCourseOutcomeById($co_id)->result()[0];
            $this->load->view("admin/obes/editCourseOutcome", $viewData);
        } else {
            redirect("admin/");
        }
    }

    public function updateCourseOutcome() {
        if ($this->sessionvalidator->isLoggedIn()) {
            $co_id = trim($this->input->post("co_id"));
            $this->form_validation->set_rules("sm_name", "Subject Name", "trim|required", array("required" => "Select Subject Name."));
            $this->form_validation->set_rules("co_name", "Course Outcome Name", "trim|required", array("required" => "Enter Course Outcome Name."));
            $this->form_validation->set_rules("co_total_session", "Total Lecture", "trim|required", array("required" => "Enter Total Lecture."));
            if ($this->form_validation->run() == false) {
                $this->editCourseOutcome($co_id);
            } else if (sizeof($this->OBESManagement->isCouresOutcomeSafeUpdate(addslashes(trim($this->input->post("co_name"))), trim($this->input->post("sm_name")), $co_id)->result())) {
                $this->session->set_flashdata('errorMessage', "A CO With Selected Subject And Name (" . addslashes(trim($this->input->post('co_name'))) . ") Already Exits. Please Choose A Different Name/Subject Combination.");
                $this->editCourseOutcome($co_id);
            } else {
                $coUpdatedData = array(
                    "sm_id" => trim($this->input->post("sm_name")),
                    "co_name" => addslashes(trim($this->input->post("co_name"))),
                    "co_total_session" => addslashes(trim($this->input->post("co_total_session"))),
                    "co_description" => addslashes(trim($this->input->post("co_description"))),
                    "co_updated_by" => $this->session->userdata("adminData")["smember_id"],
                    "co_updated_on" => date("Y-m-d H:i:s")
                );
                if ($this->OBESManagement->updateCourseOutcome($coUpdatedData, $co_id)) {
                    $this->session->set_flashdata("successMessage", "Course Outcome Updated Successfully.");
                    redirect("admin/OBESConfig/courseOutcomes");
                } else {
                    $this->session->set_flashdata("errorMessage", "An Error Occured While Updating Course Outcome. Try Later.");
                    redirect(current_url());
                }
            }
        } else {
            redirect("admin/");
        }
    }

    public function toggleCourseOutcomeStatus($co_id, $changedStatus) {
        if ($this->sessionvalidator->isLoggedIn()) {
            $coUpdatedData = array(
                'co_updated_on' => date("Y-m-d H:i:s"),
                'co_updated_by' => $this->session->userdata("adminData")["smember_id"],
                'co_active_status' => $changedStatus
            );
            if ($this->OBESManagement->updateCourseOutcome($coUpdatedData, $co_id)) {
                $this->session->set_flashdata('successMessage', 'Course Outcome Status Updated Successfully.');
                redirect("admin/OBESConfig/courseOutcomes");
            } else {
                $this->session->set_flashdata('errorMessage', 'Failed To Update Course Outcome Status. Try Later.');
                redirect(current_url());
            }
        } else {
            redirect("admin/");
        }
    }

    public function toggleCourseOutcomeDeleteStatus($co_id, $changeStatus) {
        if ($this->sessionvalidator->isLoggedIn()) {
            $coUpdatedData = array(
                'co_updated_on' => date("Y-m-d H:i:s"),
                'co_updated_by' => $this->session->userdata("adminData")["smember_id"],
                'co_delete_status' => $changeStatus
            );
            if ($this->OBESManagement->updateCourseOutcome($coUpdatedData, $co_id)) {
                $this->session->set_flashdata('successMessage', 'Course Outcome Delete Status Updated Successfully.');
                redirect("admin/OBESConfig/courseOutcomes");
            } else {
                $this->session->set_flashdata('errorMessage', 'Failed To Update Course Outcome Delete Status. Try Later.');
                redirect(current_url());
            }
        } else {
            redirect("admin/");
        }
    }

    public function getCOBySubjectForDropdown() {
        $co_id = $this->input->post("co_id");
        $sm_id = $this->input->post("sm_id");
        $query = $this->OBESManagement->getActiveNonDeletedCourseOutcomeBySubject($sm_id);
        $data = $query->result();
        $options = "";
        for ($i = 0; $i < (sizeof($data)); $i++) {
            $selected = ($co_id == $data[$i]->co_id) ? "selected" : "";
            $options .= "<option " . $selected . " value=" . $data[$i]->co_id . ">" . $data[$i]->co_name . "</option>";
        }
        $responseData = array(
            'csrfName' => $this->security->get_csrf_token_name(),
            'csrfHash' => $this->security->get_csrf_hash(),
            'co_list' => $options
        );
        echo json_encode($responseData);
    }

    /* Request Handlers For CO-PO Mapping Module */

    public function copoMapping() {
        if ($this->sessionvalidator->isLoggedIn() && $this->sessionvalidator->isAccessGranted()) {
            $viewData["copoMappings"] = $this->OBESManagement->getAllCOPOMappings()->result();
            $this->load->view("admin/obes/copoMappings", $viewData);
        } else {
            redirect("admin/");
        }
    }

    public function createCOPOMapping() {
        if ($this->sessionvalidator->isLoggedIn()) {
            $viewData["courses"] = $this->CourseManagement->getNonDeletedCoursesWithFullInfo()->result();
            $this->load->view("admin/obes/createCOPOMapping", $viewData);
        } else {
            redirect("admin/");
        }
    }

    public function saveNewCOPOMapping() {
        if ($this->sessionvalidator->isLoggedIn()) {
            $this->form_validation->set_rules("po_name", "PO Name", "trim|required", array("required" => "Please Select Any PO."));
            $this->form_validation->set_rules("co_name", "CO Name", "trim|required", array("required" => "Please Select Any CO."));
            if ($this->form_validation->run() == false) {
                $this->createCOPOMapping();
            } else if ($this->OBESManagement->getCOPOMappingBy(trim($this->input->post("po_name")), trim($this->input->post("co_name")))->result()) {
                $this->session->set_flashdata("errorMessage", "Select CO-PO Are Already Mapped. Please Try A Different Combination.");
                $this->createCOPOMapping();
            } else {
                $newCOPOMappingInfo = array(
                    "po_id" => trim($this->input->post("po_name")),
                    "co_id" => trim($this->input->post("co_name")),
                    "co_po_added_by" => $this->session->userdata("adminData")["smember_id"],
                    "co_po_added_on" => date("Y-m-d H:i:s"),
                    "co_po_updated_by" => $this->session->userdata("adminData")["smember_id"],
                    "co_po_updated_on" => date("Y-m-d H:i:s")
                );
                if ($this->OBESManagement->createNewCOPOMapping($newCOPOMappingInfo)) {
                    $this->session->set_flashdata("successMessage", "CO-PO Mapped Successfully.");
                    redirect("admin/OBESConfig/copoMapping");
                } else {
                    $this->session->set_flashdata("errorMessage", "An Error Occured While Mapping CO-PO. Try Later.");
                    redirect(current_url());
                }
            }
        } else {
            redirect("admin/");
        }
    }

    public function editCOPOMapping($co_po_id) {
        if ($this->sessionvalidator->isLoggedIn()) {
            $viewData["courses"] = $this->CourseManagement->getAllCourses()->result();
            $viewData["copoMappingInfo"] = $this->OBESManagement->getCOPOMappingById($co_po_id)->result()[0];
            $this->load->view("admin/obes/editCOPOMapping", $viewData);
        } else {
            redirect("admin/");
        }
    }

    public function updateCOPOMapping() {
        if ($this->sessionvalidator->isLoggedIn()) {
            $co_po_id = trim($this->input->post("co_po_id"));
            $this->form_validation->set_rules("po_name", "PO Name", "trim|required", array("required" => "Please Select Any PO."));
            $this->form_validation->set_rules("co_name", "CO Name", "trim|required", array("required" => "Please Select Any CO."));
            if ($this->form_validation->run() == false) {
                $this->editCOPOMapping($co_po_id);
            } else if (sizeof($this->OBESManagement->isCOPOMappingSafeUpdate(addslashes(trim($this->input->post("po_name"))), trim($this->input->post("co_name")), $co_po_id)->result())) {
                $this->session->set_flashdata("errorMessage", "Select CO-PO Are Already Mapped. Please Try A Different Combination.");
                $this->editCOPOMapping($co_po_id);
            } else {
                $copoUpdatedData = array(
                    "po_id" => trim($this->input->post("po_name")),
                    "co_id" => trim($this->input->post("co_name")),
                    "co_po_updated_by" => $this->session->userdata("adminData")["smember_id"],
                    "co_po_updated_on" => date("Y-m-d H:i:s")
                );
                if ($this->OBESManagement->updateCOPOMapping($copoUpdatedData)) {
                    $this->session->set_flashdata("successMessage", "CO-PO Mapping Updated Successfully.");
                    redirect("admin/OBESConfig/copoMapping");
                } else {
                    $this->session->set_flashdata("errorMessage", "An Error Occured While Updating CO-PO Mapping. Try Later.");
                    redirect(current_url());
                }
            }
        } else {
            redirect("admin/");
        }
    }

    public function toggleCOPOMappingStatus($copo_id, $changedStatus) {
        if ($this->sessionvalidator->isLoggedIn()) {
            $copoUpdatedData = array(
                'co_po_updated_on' => date("Y-m-d H:i:s"),
                'co_po_updated_by' => $this->session->userdata("adminData")["smember_id"],
                'co_po_active_status' => $changedStatus
            );
            if ($this->OBESManagement->updateCOPOMapping($copoUpdatedData, $copo_id)) {
                $this->session->set_flashdata('successMessage', 'CO-PO Mapping Status Updated Successfully.');
                redirect("admin/OBESConfig/copoMapping");
            } else {
                $this->session->set_flashdata('errorMessage', 'Failed To Update CO-PO Mapping Status. Try Later.');
                redirect(current_url());
            }
        } else {
            redirect("admin/");
        }
    }

    public function toggleCOPOMappingDeleteStatus($copo_id, $changedStatus) {
        if ($this->sessionvalidator->isLoggedIn()) {
            $copoUpdatedData = array(
                'co_po_updated_on' => date("Y-m-d H:i:s"),
                'co_po_updated_by' => $this->session->userdata("adminData")["smember_id"],
                'co_po_delete_status' => $changedStatus
            );
            if ($this->OBESManagement->updateCOPOMapping($copoUpdatedData, $copo_id)) {
                $this->session->set_flashdata('successMessage', 'CO-PO Mapping Delete Status Updated Successfully.');
                redirect("admin/OBESConfig/copoMapping");
            } else {
                $this->session->set_flashdata('errorMessage', 'Failed To Update CO-PO Mapping Delete Status. Try Later.');
                redirect(current_url());
            }
        } else {
            redirect("admin/");
        }
    }

    /* Request Handlers For Assessment Module */

    public function tests() {
        if ($this->sessionvalidator->isLoggedIn() && $this->sessionvalidator->isAccessGranted()) {
            $viewData["tests"] = $this->OBESManagement->getAllTests()->result();
            $this->load->view("admin/obes/tests", $viewData);
        } else {
            redirect("admin/");
        }
    }

    public function createTest() {
        if ($this->sessionvalidator->isLoggedIn()) {
            $viewData["subjects"] = $this->SubjectManagement->getAllActiveNonDeletedSubjects()->result();
            $this->load->view("admin/obes/createTest", $viewData);
        } else {
            redirect("admin/");
        }
    }

    public function saveNewTest() {
        if ($this->sessionvalidator->isLoggedIn()) {
            $this->form_validation->set_rules("sm_name", "Subject Name", "trim|required", array("required" => "Select Subject Name."));
            $this->form_validation->set_rules("test_name", "Assessment Name", "trim|required", array("required" => "Enter Assessment Name."));
            $this->form_validation->set_rules("test_type", "Assessment Type", "trim|required", array("required" => "Select Assessment Type."));
            $this->form_validation->set_rules("test_weightage", "Test Weightage", "trim|required", array("required" => "Enter Test Weightage."));
            $testInfoByNameAndSubject = $this->OBESManagement->getTestByNameAndSubject(addslashes(trim($this->input->post("test_name"))), trim($this->input->post("sm_name")))->result();
            if ($this->form_validation->run() == false) {
                $this->createTest();
            } else if (sizeof($testInfoByNameAndSubject)) {
                $this->session->set_flashdata('errorMessage', "A Assessment With Selected Subject And Name Already Exits. Please Choose A Different Assessment Name/Subject Combination.");
                $this->createTest();
            } else {
                $newTestInfo = array(
                    "sm_id" => trim($this->input->post("sm_name")),
                    "test_name" => addslashes(trim($this->input->post("test_name"))),
                    "test_type" => trim($this->input->post("test_type")),
                    "test_desc" => addslashes(trim($this->input->post("test_desc"))),
                    "test_weightage" => addslashes(trim($this->input->post("test_weightage"))),
                    "test_added_by" => $this->session->userdata("adminData")["smember_id"],
                    "test_added_on" => date("Y-m-d H:i:s"),
                    "test_updated_by" => $this->session->userdata("adminData")["smember_id"],
                    "test_updated_on" => date("Y-m-d H:i:s")
                );
                if ($this->OBESManagement->createNewTest($newTestInfo)) {
                    $this->session->set_flashdata("successMessage", "Assessment Created Successfully.");
                    redirect("admin/OBESConfig/tests");
                } else {
                    $this->session->set_flashdata("errorMessage", "An Error Occured While Creating Assessment. Try Later.");
                    redirect(current_url());
                }
            }
        } else {
            redirect("admin/");
        }
    }

    public function editTest($test_id) {
        if ($this->sessionvalidator->isLoggedIn()) {
            $viewData["subjects"] = $this->SubjectManagement->getAllActiveNonDeletedSubjects()->result();
            $viewData["testInfo"] = $this->OBESManagement->getTestById($test_id)->result()[0];
            $this->load->view("admin/obes/editTest", $viewData);
        } else {
            redirect("admin/");
        }
    }

    public function updateTest() {
        if ($this->sessionvalidator->isLoggedIn()) {
            $test_id = addslashes(trim($this->input->post("test_id")));
            $this->form_validation->set_rules("sm_name", "Subject Name", "trim|required", array("required" => "Select Subject Name."));
            $this->form_validation->set_rules("test_name", "Assessment Name", "trim|required", array("required" => "Enter Assessment Name."));
            $this->form_validation->set_rules("test_type", "Assessment Type", "trim|required", array("required" => "Select Assessment Type."));
            $this->form_validation->set_rules("test_weightage", "Test Weightage", "trim|required", array("required" => "Enter Test Weightage."));
            if ($this->form_validation->run() == false) {
                $this->editTest($test_id);
            } else if (sizeof($this->OBESManagement->isTestNameSafeUpdate(addslashes(trim($this->input->post("test_name"))), trim($this->input->post("sm_name")), $test_id)->result())) {
                $this->session->set_flashdata('errorMessage', "A Assessment With Selected Subject And Name (" . addslashes(trim($this->input->post('test_name'))) . ") Already Exits. Please Choose A Different Assessment Name/Subject Combination.");
                $this->editTest($test_id);
            } else {
                $testUpdatedData = array(
                    "sm_id" => trim($this->input->post("sm_name")),
                    "test_name" => addslashes(trim($this->input->post("test_name"))),
                    "test_type" => trim($this->input->post("test_type")),
                    "test_desc" => addslashes(trim($this->input->post("test_desc"))),
                    "test_weightage" => addslashes(trim($this->input->post("test_weightage"))),
                    "test_updated_by" => $this->session->userdata("adminData")["smember_id"],
                    "test_updated_on" => date("Y-m-d H:i:s")
                );
                if ($this->OBESManagement->updateTest($testUpdatedData, $test_id)) {
                    $this->session->set_flashdata("successMessage", "Assessment Updated Successfully.");
                    redirect("admin/OBESConfig/tests");
                } else {
                    $this->session->set_flashdata("errorMessage", "An Error Occured While Updating Assessment. Try Later.");
                    redirect(current_url());
                }
            }
        } else {
            redirect("admin/");
        }
    }

    public function toggleTestStatus($test_id, $changedStatus) {
        if ($this->sessionvalidator->isLoggedIn()) {
            $testUpdatedData = array(
                'test_updated_on' => date("Y-m-d H:i:s"),
                'test_updated_by' => $this->session->userdata("adminData")["smember_id"],
                'test_active_status' => $changedStatus
            );
            if ($this->OBESManagement->updateTest($testUpdatedData, $test_id)) {
                $this->session->set_flashdata('successMessage', 'Assessment Status Updated Successfully.');
                redirect("admin/OBESConfig/tests");
            } else {
                $this->session->set_flashdata('errorMessage', 'Failed To Update Assessment Status. Try Later.');
                redirect(current_url());
            }
        } else {
            redirect("admin/");
        }
    }

    public function toggleTestDeleteStatus($test_id, $changeStatus) {
        if ($this->sessionvalidator->isLoggedIn()) {
            $testUpdatedData = array(
                'test_updated_on' => date("Y-m-d H:i:s"),
                'test_updated_by' => $this->session->userdata("adminData")["smember_id"],
                'test_delete_status' => $changeStatus
            );
            if ($this->OBESManagement->updateTest($testUpdatedData, $test_id)) {
                $this->session->set_flashdata('successMessage', 'Assessment Delete Status Updated Successfully.');
                redirect("admin/OBESConfig/tests");
            } else {
                $this->session->set_flashdata('errorMessage', 'Failed To Update Assessment Delete Status. Try Later.');
                redirect(current_url());
            }
        } else {
            redirect("admin/");
        }
    }

    public function getTestsBySubjectForDropdown() {
        $sm_id = $this->input->post("sm_id");
        $test_id = $this->input->post("test_id");
        $query = $this->OBESManagement->getNonDeletedActiveTestsBySubject($sm_id);
        $data = $query->result();
        $options = "<option value=''>Select Assessment</option>";
        for ($i = 0; $i < (sizeof($data)); $i++) {
            $selected = ($test_id == $data[$i]->test_id) ? "selected" : "";
            $options .= "<option " . $selected . " value=" . $data[$i]->test_id . ">" . $data[$i]->test_name . "</option>";
        }
        $responseData = array(
            'csrfName' => $this->security->get_csrf_token_name(),
            'csrfHash' => $this->security->get_csrf_hash(),
            'test_list' => $options
        );
        echo json_encode($responseData);
    }

    /* Request Hanlders For CO-Question Mapping */

    public function coQuestionMap() {
        if ($this->sessionvalidator->isLoggedIn() && $this->sessionvalidator->isAccessGranted()) {
            $viewData["coMappings"] = $this->OBESManagement->getAllCOQuestionMappings()->result();
            $this->load->view("admin/obes/coQuestionMap", $viewData);
        } else {
            redirect("admin/");
        }
    }

    public function createCOQuestionMapping() {
        if ($this->sessionvalidator->isLoggedIn()) {
            $viewData["subjects"] = $this->SubjectManagement->getAllActiveNonDeletedSubjects()->result();
            $viewData["levels"] = $this->OBESManagement->getActiveAndNonDeletedLevelsAndKeywords()->result();
            $this->load->view("admin/obes/createCOQuestionMapping", $viewData);
        } else {
            redirect("admin/");
        }
    }

    public function saveNewCOQuestionMapping() {
        $this->form_validation->set_rules("sm_name", "Subject Name", "trim|required", array("required" => "Select Subject Name."));
        $this->form_validation->set_rules("test_name", "Assessment Name", "trim|required", array("required" => "Select Assessment Name."));
        $this->form_validation->set_rules("sco_qno", "Question No.", "trim|required", array("required" => "Enter Question No."));
        $this->form_validation->set_rules("sco_marks", "Question Marks", "trim|required", array("required" => "Enter Question Marks."));
        $this->form_validation->set_rules("level", "Question Level", "trim|required", array("required" => "Select Question Level."));

        $coSelection = $this->input->post('co_name');
        $newCOQuestionMappingData = array();
        if (is_array($coSelection)) {
            $isCoSelected = (sizeof($coSelection)) ? 1 : 0;
        } else {
            $isCoSelected = 0;
        }
        if ($this->form_validation->run() == false) {
            if (!$isCoSelected) {
                $this->session->set_flashdata('errorMessage', "At Least One CO Should Be Selected While Alloting Subject.");
            }
            if (empty($_FILES['qno_file']['name']) && $this->input->post("qno_desc") == "") {
                $this->session->set_flashdata('errorMessages', "Either Question Description Or Question File Is Mandatory.");
            }
            $this->createCOQuestionMapping();
        } else if (empty($_FILES['qno_file']['name']) && $this->input->post("qno_desc") == "") {
            $this->session->set_flashdata('errorMessages', "Either Question Description Or Question File Is Mandatory.");
            $this->createCOQuestionMapping();
        } else {
            $a = $this->OBESManagement->getTestQuestionBy(trim($this->input->post("sm_name")), trim($this->input->post("test_name")), addslashes(trim($this->input->post("sco_qno"))))->result();
            $newQuestionData = array();
            $file = null;
            if (!empty($_FILES['qno_file']['name'])) {
                $fileConfig["upload_path"] = "./assets/admin/uploads/obes/questionBank/";
                $fileConfig["allowed_types"] = "jpg|png|webp";
                $fileConfig["max_size"] = "1024";
                $fileConfig["file_ext_tolower"] = TRUE;
                $fileConfig["encrypt_name"] = TRUE;

                $this->load->library("upload", $fileConfig);
                if (!$this->upload->do_upload("qno_file")) {
                    $this->session->set_flashdata("errorMessage", $this->upload->display_errors());
                    redirect("admin/OBESConfig/createCOQuestionMapping");
                } else {
                    $file = "assets/admin/uploads/obes/questionBank/" . $this->upload->data()["file_name"];
                }
            }
            if (sizeof($a) <= 0) {
                $newQuestionData = array(
                    "test_id" => trim($this->input->post("test_name")),
                    "qno_name" => addslashes(trim($this->input->post("sco_qno"))),
                    "qno_marks" => addslashes(trim($this->input->post("sco_marks"))),
                    "qno_added_by" => $this->session->userdata("adminData")["smember_id"],
                    "qno_added_on" => date("Y-m-d H:i:s"),
                    "qno_updated_by" => $this->session->userdata("adminData")["smember_id"],
                    "qno_updated_on" => date("Y-m-d H:i:s"),
                    "qno_desc" => ($this->input->post("qno_desc") == "" ) ? null : addslashes(trim($this->input->post("qno_desc"))),
                    "qno_file" => $file,
                    "qno_level" => $this->input->post("level")
                );
                $qno_id = $this->OBESManagement->createNewQuestion($newQuestionData);
            } else {
                $qno_id = $a[0]->qno_id;
            }
            $b = 0;
            for ($i = 0; $i < sizeof($coSelection); $i++) {
                if (sizeof($this->OBESManagement->getCOQuestionMappingBy($coSelection[$i], trim($this->input->post("sm_name")), trim($this->input->post("test_name")), $qno_id)->result())) {
                    $b++;
                } else if (sizeof($coSelection) != $b) {
                    array_push($newCOQuestionMappingData, array(
                        "co_id" => $coSelection[$i],
                        "qno_id" => $qno_id,
                        "sco_added_by" => $this->session->userdata("adminData")["smember_id"],
                        "sco_added_on" => date("Y-m-d H:i:s"),
                        "sco_updated_by" => $this->session->userdata("adminData")["smember_id"],
                        "sco_updated_on" => date("Y-m-d H:i:s")
                    ));
                }
            }

            if (sizeof($coSelection) == $b) {
                $this->session->set_flashdata("errorMessage", "Selected Subject/Assessment & Question No. Combination Already Exits. Please Choose Different Combination.");
                $this->createCOQuestionMapping();
            } else {
                $this->db->trans_start();
                if ($this->OBESManagement->createNewCOQuestionMap($newCOQuestionMappingData)) {
                    $this->db->trans_complete();
                    $this->session->set_flashdata("successMessage", "CO-Question Mapping Successful.");
                    redirect("admin/OBESConfig/coQuestionMap");
                } else {
                    $this->session->set_flashdata("errorMessage", "An Error Occured While Mapping CO-Question. Try Later.");
                    redirect(current_url());
                }
            }
        }
    }

    public function editCOQuestionMapping($sco_id) {
        if ($this->sessionvalidator->isLoggedIn()) {
            $viewData["subjects"] = $this->SubjectManagement->getAllActiveNonDeletedSubjects()->result();
            $viewData["coQuestionMapInfo"] = $this->OBESManagement->getCOQuestionMapBy($sco_id)->result()[0];
            $viewData["levels"] = $this->OBESManagement->getActiveAndNonDeletedLevelsAndKeywords()->result();
            $this->load->view("admin/obes/editCOQuestionMapping", $viewData);
        } else {
            redirect("admin/");
        }
    }

    public function updateCOQuestionMapping() {
        if ($this->sessionvalidator->isLoggedIn()) {
            $sco_id = trim($this->input->post("sco_id"));
            $qno_id = trim($this->input->post("qno_id"));
            $this->form_validation->set_rules("co_name", "Course Outcome Name", "trim|required", array("required" => "Select Course Outcome Name."));
            $this->form_validation->set_rules("sco_marks", "Question Marks", "trim|required", array("required" => "Enter Question Marks."));
            $this->form_validation->set_rules("level", "Question Level", "trim|required", array("required" => "Select Question Level."));

            if ($this->form_validation->run() == false) {
                if (empty($_FILES['qno_file']['name']) && $this->input->post("qno_desc") == "") {
                    $this->session->set_flashdata('errorMessage', "Either Question Description Or Question File Is Mandatory.");
                }
                $this->editCOQuestionMapping($sco_id);
            } else if (empty($_FILES['qno_file']['name']) && $this->input->post("qno_desc") == "") {
                $this->session->set_flashdata('errorMessage', "Either Question Description Or Question File Is Mandatory.");
                $this->editCOQuestionMapping($sco_id);
            } else {
                if (sizeof($this->OBESManagement->checkCOQuestionMappingIsSafeToUpdate(trim($this->input->post("co_name")), trim($this->input->post("sm_name")), trim($this->input->post("test_name")), $qno_id, trim($this->input->post("qno_name")))->result())) {
                    $this->session->set_flashdata("errorMessage", "Selected Subject/Assessment & Question No. Combination Already Exits. Please Choose Different Combination.");
                    $this->editCOQuestionMapping($sco_id);
                } else {
                    $file = null;
                    if (!empty($_FILES['qno_file']['name'])) {
                        $fileConfig["upload_path"] = "./assets/admin/uploads/obes/questionBank/";
                        $fileConfig["allowed_types"] = "jpg|png|webp";
                        $fileConfig["max_size"] = "1024";
                        $fileConfig["file_ext_tolower"] = TRUE;
                        $fileConfig["encrypt_name"] = TRUE;
                        $file = null;
                        $this->load->library("upload", $fileConfig);
                        if (!$this->upload->do_upload("qno_file")) {
                            $this->session->set_flashdata("errorMessage", $this->upload->display_errors());
                            redirect("admin/OBESConfig/createCOQuestionMapping");
                        } else {
                            $file = "assets/admin/uploads/obes/questionBank/" . $this->upload->data()["file_name"];
                            if (file_exists("./" . trim($this->input->post('old_file')))) {
                                unlink("./" . trim($this->input->post('old_file')));
                            }
                        }
                    } else {
                        $file = $this->input->post("old_file");
                    }
                    $scoUpdatedData = array(
                        "co_id" => trim($this->input->post("co_name")),
                        "sco_updated_by" => $this->session->userdata("adminData")["smember_id"],
                        "sco_updated_on" => date("Y-m-d H:i:s")
                    );
                    $qnoUpdatedData = array(
                        "qno_marks" => trim($this->input->post("sco_marks")),
                        "qno_updated_by" => $this->session->userdata("adminData")["smember_id"],
                        "qno_updated_on" => date("Y-m-d H:i:s"),
                        "qno_desc" => ($this->input->post("qno_desc") == "" ) ? null : addslashes(trim($this->input->post("qno_desc"))),
                        "qno_file" => $file,
                        "qno_level" => $this->input->post("level")
                    );
                    $this->db->trans_start();
                    if ($this->OBESManagement->updateCOQuestionMap($scoUpdatedData, $sco_id) && $this->OBESManagement->updateQuestionMap($qnoUpdatedData, $qno_id)) {
                        $this->db->trans_complete();
                        $this->session->set_flashdata("successMessage", "CO-Question Mapping Updated Successfully.");
                        redirect("admin/OBESConfig/coQuestionMap");
                    } else {
                        $this->session->set_flashdata("errorMessage", "An Error Occured While Updating CO-Question Mapping. Try Later.");
                        redirect(current_url());
                    }
                }
            }
        } else {
            redirect("admin/");
        }
    }

    public function toggleCOQuestionMapStatus($sco_id, $changeStatus) {
        if ($this->sessionvalidator->isLoggedIn()) {
            $scoUpdatedData = array(
                'sco_updated_on' => date("Y-m-d H:i:s"),
                'sco_updated_by' => $this->session->userdata("adminData")["smember_id"],
                'sco_active_status' => $changeStatus
            );
            if ($this->OBESManagement->updateCOQuestionMap($scoUpdatedData, $sco_id)) {
                $this->session->set_flashdata('successMessage', 'CO-Question Map Status Updated Successfully.');
                redirect("admin/OBESConfig/coQuestionMap");
            } else {
                $this->session->set_flashdata('errorMessage', 'Failed To Update CO-Question Map Status. Try Later.');
                redirect(current_url());
            }
        } else {
            redirect("admin/");
        }
    }

    public function toggleCOQuestionMapDeleteStatus($sco_id, $changeStatus) {
        if ($this->sessionvalidator->isLoggedIn()) {
            $scoUpdatedData = array(
                'sco_updated_on' => date("Y-m-d H:i:s"),
                'sco_updated_by' => $this->session->userdata("adminData")["smember_id"],
                'sco_delete_status' => $changeStatus
            );
            if ($this->OBESManagement->updateCOQuestionMap($scoUpdatedData, $sco_id)) {
                $this->session->set_flashdata('successMessage', 'CO-Question Map Delete Status Updated Successfully.');
                redirect("admin/OBESConfig/coQuestionMap");
            } else {
                $this->session->set_flashdata('errorMessage', 'Failed To Update CO-Question Map Delete Status. Try Later.');
                redirect(current_url());
            }
        } else {
            redirect("admin/");
        }
    }

    public function createCOAttainmentTargetPercentage() {
        if ($this->sessionvalidator->isLoggedIn()) {
            $viewData['sessions'] = $this->SessionManagement->getNonDeletedActiveSessions()->result();
            $this->load->view("admin/obes/createCOAttainmentTargetPercentage", $viewData);
        } else {
            redirect("admin/");
        }
    }

    public function saveCOAttainmentTargetPercentage() {
        if ($this->sessionvalidator->isLoggedIn()) {
            $this->form_validation->set_rules("session", "Session", "trim|required", array("required" => "Select Session."));
            $this->form_validation->set_rules("sm_name", "Subject Name", "trim|required", array("required" => "Select Subject Name."));
            $this->form_validation->set_rules("ocoops_percentage_flag", "Used As", "trim|required", array("required" => "Select Used As Flag."));
            $this->form_validation->set_rules("per", "Course Outcome Percentage", "trim|required", array("required" => "Enter Course Outcome Percentage."));
            if ($this->form_validation->run() == false) {
                $this->createCOAttainmentTargetPercentage();
            } else {
                if (sizeof($this->OBESManagement->getCOAttainmentPercentageSubjectby('', $this->input->post("sm_name"), trim($this->input->post("session")), $this->input->post("ocoops_percentage_flag"))->result())) {
                    $this->session->set_flashdata("errorMessage", "Session, Subject Combination Already Exits. Please Choose Different Combination.");
                    $this->createCOAttainmentTargetPercentage();
                } else {
                    $newCOAttainmentPercentageData = array(
                        "sm_id" => $this->input->post("sm_name"),
                        "session_id" => $this->input->post("session"),
                        "ocoops_percentage" => $this->input->post("per"),
                        "ocoops_percentage_flag" => $this->input->post("ocoops_percentage_flag"),
                        "ocoops_added_by" => $this->session->userdata("adminData")["smember_id"],
                        "ocoops_added_on" => date("Y-m-d H:i:s"),
                        "ocoops_updated_by" => $this->session->userdata("adminData")["smember_id"],
                        "ocoops_updated_on" => date("Y-m-d H:i:s")
                    );
                    if ($this->OBESManagement->createCOAttainmentPercentage($newCOAttainmentPercentageData)) {
                        $this->session->set_flashdata("successMessage", "Course Outcome Target Percentage Created Successful.");
                        redirect("admin/OBESConfig/coAttainmentPercentages");
                    } else {
                        $this->session->set_flashdata("errorMessage", "An Error Occured While Creating Course Outcome Target Percentage. Try Later.");
                        redirect(current_url());
                    }
                }
            }
        } else {
            redirect("admin/");
        }
    }

    public function coAttainmentPercentages() {
        if ($this->sessionvalidator->isLoggedIn()) {
            $viewData["coTargetPercentages"] = $this->OBESManagement->getAllCOAttainmentPercentages()->result();
            $this->load->view("admin/obes/coTargetPercentages", $viewData);
        } else {
            redirect("admin/");
        }
    }

    public function toggleCOAttainmentPercentageDeleteStatus($ocoops_id, $changeStatus) {
        if ($this->sessionvalidator->isLoggedIn()) {
            $array = array(
                'ocoops_updated_on' => date("Y-m-d H:i:s"),
                'ocoops_updated_by' => $this->session->userdata("adminData")["smember_id"],
                'ocoops_delete_status' => $changeStatus
            );
            if ($this->OBESManagement->updateCOAttainmentPercentage($ocoops_id, $array)) {
                $this->session->set_flashdata('successMessage', 'Course Outcome Target Percentage Delete Status Updated Successfully.');
                redirect("admin/OBESConfig/coAttainmentPercentages");
            } else {
                $this->session->set_flashdata('errorMessage', 'Failed To Update Course Outcome Target Percentage Delete Status. Try Later.');
                redirect(current_url());
            }
        } else {
            redirect("admin/");
        }
    }

    public function toggleCOAttainmentPercentageStatus($ocoops_id, $changeStatus) {
        if ($this->sessionvalidator->isLoggedIn()) {
            $array = array(
                'ocoops_updated_on' => date("Y-m-d H:i:s"),
                'ocoops_updated_by' => $this->session->userdata("adminData")["smember_id"],
                'ocoops_active_status' => $changeStatus
            );
            if ($this->OBESManagement->updateCOAttainmentPercentage($ocoops_id, $array)) {
                $this->session->set_flashdata('successMessage', 'Course Outcome Target Percentage Status Updated Successfully.');
                redirect("admin/OBESConfig/coAttainmentPercentages");
            } else {
                $this->session->set_flashdata('errorMessage', 'Failed To Update Course Outcome Target Percentage Status. Try Later.');
                redirect(current_url());
            }
        } else {
            redirect("admin/");
        }
    }

    public function editCOAttainmentPercentage($ocoops_id) {
        if ($this->sessionvalidator->isLoggedIn()) {
            $viewData['sessions'] = $this->SessionManagement->getNonDeletedActiveSessions()->result();
            $viewData["oCOOPS"] = $this->OBESManagement->getCOOverAllAttainmentPercentagesBy($ocoops_id)->result()[0];

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

    public function updateCOTargetPercentage() {
        if ($this->sessionvalidator->isLoggedIn()) {
            $ocoops_id = trim($this->input->post("ocoops_id"));
            $this->form_validation->set_rules("session", "Session", "trim|required", array("required" => "Select Session."));
            $this->form_validation->set_rules("sm_name", "Subject Name", "trim|required", array("required" => "Select Subject Name."));
            $this->form_validation->set_rules("ocoops_percentage_flag", "Used As", "trim|required", array("required" => "Select Used As Flag."));
            if ($this->form_validation->run() == false) {
                $this->editCOTargetPercentage($ocoops_id);
            } else {
                if (sizeof($this->OBESManagement->getCOAttainmentPercentageSubjectby($ocoops_id, $this->input->post("sm_name"), trim($this->input->post("session")), $this->input->post("ocoops_percentage_flag"))->result())) {
                    $this->session->set_flashdata("errorMessage", "Data Already Exist. Try Again.");
                    redirect("admin/OBESConfig/editCOAttainmentPercentage/$ocoops_id");
                } else {
                    $array = array(
                        "sm_id" => $this->input->post("sm_name"),
                        "session_id" => $this->input->post("session"),
                        "ocoops_percentage" => $this->input->post("per"),
                        "ocoops_percentage_flag" => $this->input->post("ocoops_percentage_flag"),
                        "ocoops_updated_by" => $this->session->userdata("adminData")["smember_id"],
                        "ocoops_updated_on" => date("Y-m-d H:i:s")
                    );
                    if ($this->OBESManagement->updateCOAttainmentPercentage($ocoops_id, $array)) {
                        $this->session->set_flashdata("successMessage", "Course Outcome Target Percentage Updated Successful.");
                        redirect("admin/OBESConfig/coAttainmentPercentages");
                    } else {
                        $this->session->set_flashdata("errorMessage", "An Error Occured While Updating Course Outcome Target Percentage. Try Later.");
                        redirect(current_url());
                    }
                }
            }
        } else {
            redirect("admin/");
        }
    }

    /**/

    public function createCOTargetPercentage() {
        if ($this->sessionvalidator->isLoggedIn()) {
            $viewData['sessions'] = $this->SessionManagement->getNonDeletedActiveSessions()->result();
            $this->load->view("admin/obes/createCOTargetPercentage", $viewData);
        } else {
            redirect("admin/");
        }
    }

    public function saveCOTargetPercentage() {
        if ($this->sessionvalidator->isLoggedIn()) {
            $this->form_validation->set_rules("session", "Session", "trim|required", array("required" => "Select Session."));
            $this->form_validation->set_rules("sm_name", "Subject Name", "trim|required", array("required" => "Select Subject Name."));
            $this->form_validation->set_rules("per", "Course Outcome Percentage", "trim|required", array("required" => "Enter Course Outcome Percentage."));
            $coSelection = $this->input->post('co_name');
            $newCOTargetPercentageData = array();
            if (is_array($coSelection)) {
                $isCoSelected = (sizeof($coSelection)) ? 1 : 0;
            } else {
                $isCoSelected = 0;
            }
            if ($this->form_validation->run() == false) {
                if (!$isCoSelected) {
                    $this->session->set_flashdata('errorMessage', "At Least One CO Should Be Selected While Setting Percentage To Course Outcome.");
                }
                $this->createCOTargetPercentage();
            } else {
                $b = 0;
                for ($i = 0; $i < sizeof($coSelection); $i++) {
                    if (sizeof($this->OBESManagement->getCOTargetPercentageby('', $coSelection[$i], trim($this->input->post("session")))->result())) {
                        $b++;
                    } else {
                        array_push($newCOTargetPercentageData, array(
                            "co_id" => $coSelection[$i],
                            "session_id" => $this->input->post("session"),
                            'ocotp_percentage' => $this->input->post("per"),
                            "ocotp_added_by" => $this->session->userdata("adminData")["smember_id"],
                            "ocotp_added_on" => date("Y-m-d H:i:s"),
                            "ocotp_updated_by" => $this->session->userdata("adminData")["smember_id"],
                            "ocotp_updated_on" => date("Y-m-d H:i:s")
                        ));
                    }
                }
                if (sizeof($coSelection) == $b) {
                    $this->session->set_flashdata("errorMessage", "All Session, Subject & Course Outcome Combination Already Exits. Please Choose Different Combination.");
                    $this->createCOTargetPercentage();
                } else {
                    $this->db->trans_start();
                    if ($this->OBESManagement->createCOTargetPercentage($newCOTargetPercentageData)) {
                        $this->db->trans_complete();
                        $this->session->set_flashdata("successMessage", "Course Outcome Target Percentage Created Successful.");
                        redirect("admin/OBESConfig/coEachTargetPercentages");
                    } else {
                        $this->session->set_flashdata("errorMessage", "An Error Occured While Creating Course Outcome Target Percentage. Try Later.");
                        redirect(current_url());
                    }
                }
            }
        } else {
            redirect("admin/");
        }
    }

    public function coEachTargetPercentages() {
        if ($this->sessionvalidator->isLoggedIn() && $this->sessionvalidator->isAccessGranted()) {
            $viewData["coTargetPercentages"] = $this->OBESManagement->getAllCOTargetPercentages()->result();
            $this->load->view("admin/obes/coEachTargetPercentages", $viewData);
        } else {
            redirect("admin/");
        }
    }

    public function toggleCOTargetPercentageDeleteStatus($ocotp_id, $changeStatus) {
        if ($this->sessionvalidator->isLoggedIn()) {
            $array = array(
                'ocotp_updated_on' => date("Y-m-d H:i:s"),
                'ocotp_updated_by' => $this->session->userdata("adminData")["smember_id"],
                'ocotp_delete_status' => $changeStatus
            );
            if ($this->OBESManagement->updateCOTargetPercentage($ocotp_id, $array)) {
                $this->session->set_flashdata('successMessage', 'Course Outcome Target Percentage Delete Status Updated Successfully.');
                redirect("admin/OBESConfig/coEachTargetPercentages");
            } else {
                $this->session->set_flashdata('errorMessage', 'Failed To Update Course Outcome Target Percentage Delete Status. Try Later.');
                redirect(current_url());
            }
        } else {
            redirect("admin/");
        }
    }

    public function toggleCOTargetPercentageStatus($ocotp_id, $changeStatus) {
        if ($this->sessionvalidator->isLoggedIn()) {
            $array = array(
                'ocotp_updated_on' => date("Y-m-d H:i:s"),
                'ocotp_updated_by' => $this->session->userdata("adminData")["smember_id"],
                'ocotp_active_status' => $changeStatus
            );
            if ($this->OBESManagement->updateCOTargetPercentage($ocotp_id, $array)) {
                $this->session->set_flashdata('successMessage', 'Course Outcome Target Percentage Status Updated Successfully.');
                redirect("admin/OBESConfig/coEachTargetPercentages");
            } else {
                $this->session->set_flashdata('errorMessage', 'Failed To Update Course Outcome Target Percentage Status. Try Later.');
                redirect(current_url());
            }
        } else {
            redirect("admin/");
        }
    }

    public function editCOTargetPercentage($ocotp_id) {
        if ($this->sessionvalidator->isLoggedIn()) {
            $viewData['sessions'] = $this->SessionManagement->getNonDeletedActiveSessions()->result();
            $viewData["coTargetPercentageDetails"] = $this->OBESManagement->getCOTargetPercentagesBy($ocotp_id)->result()[0];
            $this->load->view("admin/obes/editCOTargetPercentage", $viewData);
        } else {
            redirect("admin/");
        }
    }

    public function updateCOEachTargetPercentage() {
        if ($this->sessionvalidator->isLoggedIn()) {
            $ocotp_id = trim($this->input->post("ocotp_id"));
            $this->form_validation->set_rules("session", "Session", "trim|required", array("required" => "Select Session."));
            $this->form_validation->set_rules("sm_name", "Subject Name", "trim|required", array("required" => "Select Subject Name."));
            $this->form_validation->set_rules("per", "Course Outcome Percentage", "trim|required", array("required" => "Enter Course Outcome Percentage."));
            $this->form_validation->set_rules("co_name", "Course Outcome", "trim|required", array("required" => "Select Course Outcome."));
            if ($this->form_validation->run() == false) {
                $this->editCOTargetPercentage($ocotp_id);
            } else {
                if (sizeof($this->OBESManagement->getCOTargetPercentageby($ocotp_id, trim($this->input->post("co_name")), trim($this->input->post("session")))->result())) {
                    $this->session->set_flashdata("errorMessage", "Data Already Exist. Try Again.");
                    redirect("admin/OBESConfig/editCOTargetPercentage/$ocotp_id");
                } else {
                    $array = array(
                        "co_id" => trim($this->input->post("co_name")),
                        "session_id" => $this->input->post("session"),
                        'ocotp_percentage' => $this->input->post("per"),
                        "ocotp_added_by" => $this->session->userdata("adminData")["smember_id"],
                        "ocotp_added_on" => date("Y-m-d H:i:s"),
                        "ocotp_updated_by" => $this->session->userdata("adminData")["smember_id"],
                        "ocotp_updated_on" => date("Y-m-d H:i:s")
                    );
                    $this->db->trans_start();
                    if ($this->OBESManagement->updateCOTargetPercentage($ocotp_id, $array)) {
                        $this->db->trans_complete();
                        $this->session->set_flashdata("successMessage", "Course Outcome Target Percentage Updated Successful.");
                        redirect("admin/OBESConfig/coEachTargetPercentages");
                    } else {
                        $this->session->set_flashdata("errorMessage", "An Error Occured While Updating Course Outcome Target Percentage. Try Later.");
                        redirect(current_url());
                    }
                }
            }
        } else {
            redirect("admin/");
        }
    }

    public function createCOSemesterExamTargetPercentage() {
        if ($this->sessionvalidator->isLoggedIn()) {
            $viewData['sessions'] = $this->SessionManagement->getNonDeletedActiveSessions()->result();
            $this->load->view("admin/obes/createCOSemesterExamTargetPercentage", $viewData);
        } else {
            redirect("admin/");
        }
    }

    public function saveCOSemesterExamTargetPercentage() {
        if ($this->sessionvalidator->isLoggedIn()) {
            $this->form_validation->set_rules("session", "Session", "trim|required", array("required" => "Select Session."));
            $this->form_validation->set_rules("sm_name", "Subject Name", "trim|required", array("required" => "Select Subject Name."));
            $this->form_validation->set_rules("per", "Course Outcome Percentage", "trim|required", array("required" => "Enter Target Percentage For Subject-Wise Semester Exam ."));
            if ($this->form_validation->run() == false) {
                $this->createCOSemesterExamTargetPercentage();
            } else {
                if (sizeof($this->OBESManagement->getCOSemesterExamTargetPercentageBy('', trim($this->input->post("sm_name")), trim($this->input->post("session")))->result())) {
                    $this->session->set_flashdata("errorMessage", "Data Already Exist. Try Again.");
                    redirect("admin/obes/createCOSemesterExamTargetPercentage");
                } else {
                    $array = array(
                        "sm_id" => trim($this->input->post("sm_name")),
                        "session_id" => $this->input->post("session"),
                        'osetp_percentage' => $this->input->post("per"),
                        "osetp_added_by" => $this->session->userdata("adminData")["smember_id"],
                        "osetp_added_on" => date("Y-m-d H:i:s"),
                        "osetp_updated_by" => $this->session->userdata("adminData")["smember_id"],
                        "osetp_updated_on" => date("Y-m-d H:i:s")
                    );
                    $this->db->trans_start();
                    if ($this->OBESManagement->createCOSemesterExamTargetPercentage($array)) {
                        $this->db->trans_complete();
                        $this->session->set_flashdata("successMessage", "Course Outcome Semester Exam Target Percentage Created Successful.");
                        redirect("admin/OBESConfig/coSemesterExamTargetPercentages");
                    } else {
                        $this->session->set_flashdata("errorMessage", "An Error Occured While Creating Course Outcome Semester Exam Target Percentage. Try Later.");
                        redirect(current_url());
                    }
                }
            }
        } else {
            redirect("admin/");
        }
    }

    public function coSemesterExamTargetPercentages() {
        if ($this->sessionvalidator->isLoggedIn() && $this->sessionvalidator->isAccessGranted()) {
            $viewData["coSemesterExamTargetPercentages"] = $this->OBESManagement->getAllCOSemesterExamTargetPercentages()->result();
            $this->load->view("admin/obes/coSemesterExamTargetPercentages", $viewData);
        } else {
            redirect("admin/");
        }
    }

    public function toggleCOSemesterExamTargetPercentageDeleteStatus($osetp_id, $changeStatus) {
        if ($this->sessionvalidator->isLoggedIn()) {
            $array = array(
                'osetp_updated_on' => date("Y-m-d H:i:s"),
                'osetp_updated_by' => $this->session->userdata("adminData")["smember_id"],
                'osetp_delete_status' => $changeStatus
            );
            if ($this->OBESManagement->updateCOSemesterExamTargetPercentage($osetp_id, $array)) {
                $this->session->set_flashdata('successMessage', 'Course Outcome Target Percentage Delete Status Updated Successfully.');
                redirect("admin/OBESConfig/coSemesterExamTargetPercentages");
            } else {
                $this->session->set_flashdata('errorMessage', 'Failed To Update Course Outcome Target Percentage Delete Status. Try Later.');
                redirect(current_url());
            }
        } else {
            redirect("admin/");
        }
    }

    public function toggleCOSemesterExamTargetPercentageStatus($osetp_id, $changeStatus) {
        if ($this->sessionvalidator->isLoggedIn()) {
            $array = array(
                'osetp_updated_on' => date("Y-m-d H:i:s"),
                'osetp_updated_by' => $this->session->userdata("adminData")["smember_id"],
                'osetp_active_status' => $changeStatus
            );
            if ($this->OBESManagement->updateCOSemesterExamTargetPercentage($osetp_id, $array)) {
                $this->session->set_flashdata('successMessage', 'Course Outcome Target Percentage Status Updated Successfully.');
                redirect("admin/OBESConfig/coSemesterExamTargetPercentages");
            } else {
                $this->session->set_flashdata('errorMessage', 'Failed To Update Course Outcome Target Percentage Status. Try Later.');
                redirect(current_url());
            }
        } else {
            redirect("admin/");
        }
    }

    public function editCOSemesterExamTargetPercentage($osetp_id) {
        if ($this->sessionvalidator->isLoggedIn()) {
            $viewData['sessions'] = $this->SessionManagement->getNonDeletedActiveSessions()->result();
            $viewData["coSemesterExamTargetPercentageDetails"] = $this->OBESManagement->getCOSemesterExamTargetPercentagesBy($osetp_id)->result()[0];
            $this->load->view("admin/obes/editCOSemesterExamTargetPercentage", $viewData);
        } else {
            redirect("admin/");
        }
    }

    public function updateCOSemesterExamTargetPercentage() {
        if ($this->sessionvalidator->isLoggedIn()) {
            $osetp_id = trim($this->input->post("osetp_id"));
            $this->form_validation->set_rules("session", "Session", "trim|required", array("required" => "Select Session."));
            $this->form_validation->set_rules("sm_name", "Subject Name", "trim|required", array("required" => "Select Subject Name."));
            $this->form_validation->set_rules("per", "Course Outcome Percentage", "trim|required", array("required" => "Enter Target Percentage For Subject-Wise Semester Exam ."));
            if ($this->form_validation->run() == false) {
                $this->createCOSemesterExamTargetPercentage();
            } else {
                if (sizeof($this->OBESManagement->getCOSemesterExamTargetPercentageBy($osetp_id, trim($this->input->post("sm_name")), trim($this->input->post("session")))->result())) {
                    $this->session->set_flashdata("errorMessage", "Data Already Exist. Try Again.");
                    redirect("admin/obes/createCOSemesterExamTargetPercentage");
                } else {
                    $array = array(
                        "sm_id" => trim($this->input->post("sm_name")),
                        "session_id" => $this->input->post("session"),
                        'osetp_percentage' => $this->input->post("per"),
                        "osetp_added_by" => $this->session->userdata("adminData")["smember_id"],
                        "osetp_added_on" => date("Y-m-d H:i:s"),
                        "osetp_updated_by" => $this->session->userdata("adminData")["smember_id"],
                        "osetp_updated_on" => date("Y-m-d H:i:s")
                    );
                    $this->db->trans_start();
                    if ($this->OBESManagement->updateCOSemesterExamTargetPercentage($osetp_id, $array)) {
                        $this->db->trans_complete();
                        $this->session->set_flashdata("successMessage", "Course Outcome Semester Exam Target Percentage Updated Successful.");
                        redirect("admin/OBESConfig/coSemesterExamTargetPercentages");
                    } else {
                        $this->session->set_flashdata("errorMessage", "An Error Occured While Updating Course Outcome Semester Exam Target Percentage. Try Later.");
                        redirect(current_url());
                    }
                }
            }
        } else {
            redirect("admin/");
        }
    }

    /* CO Attainment Level Subjetc Wise (Direct/Indirect) */

    public function createCOAttainmentLevelPercentage() {
        if ($this->sessionvalidator->isLoggedIn()) {
            $viewData['sessions'] = $this->SessionManagement->getNonDeletedActiveSessions()->result();
            $this->load->view("admin/obes/createCOAttainmentLevelPercentage", $viewData);
        } else {
            redirect("admin/");
        }
    }

    public function saveCOAttainmentLevelPercentage() {
        if ($this->sessionvalidator->isLoggedIn()) {
            $this->form_validation->set_rules("session", "Session", "trim|required", array("required" => "Select Session."));
            $this->form_validation->set_rules("sm_name", "Subject Name", "trim|required", array("required" => "Select Subject Name."));
            $this->form_validation->set_rules("level_name", "CO Attainment Level Name", "trim|required", array("required" => "Enter CO Attainment Level Name."));
            $this->form_validation->set_rules("level_value", "CO Attainment Level Value", "trim|required", array("required" => "Enter CO Attainment Level Value."));
            $this->form_validation->set_rules("per_from", "CO Attainment Level From", "trim|required", array("required" => "Enter CO Attainment Level Percentage (From) ."));
            $this->form_validation->set_rules("per_to", "CO Attainment Level To", "trim|required", array("required" => "Enter CO Attainment Level Percentage (To) ."));
            if ($this->form_validation->run() == false) {
                $this->createCOAttainmentLevelPercentage();
            } else {
                if (sizeof($this->OBESManagement->getCOAttainmentLevelPercentageBy('', trim($this->input->post("sm_name")), trim($this->input->post("session")), addslashes(trim($this->input->post("level_name"))), addslashes(trim($this->input->post("level_value"))), trim($this->input->post("ocoalp_DI_flag")))->result())) {
                    $this->session->set_flashdata("errorMessage", "Data Already Exist. Try Again.");
                    redirect("admin/OBESConfig/createCOAttainmentLevelPercentage");
                } else {
                    $array = array(
                        "sm_id" => trim($this->input->post("sm_name")),
                        "session_id" => $this->input->post("session"),
                        'ocoalp_level_value' => addslashes(trim($this->input->post("level_value"))),
                        'ocoalp_level_name' => addslashes(trim($this->input->post("level_name"))),
                        'ocoalp_percentage_from' => addslashes(trim($this->input->post("per_from"))),
                        'ocoalp_percentage_to' => addslashes(trim($this->input->post("per_to"))),
                        "ocoalp_added_by" => $this->session->userdata("adminData")["smember_id"],
                        "ocoalp_added_on" => date("Y-m-d H:i:s"),
                        "ocoalp_updated_by" => $this->session->userdata("adminData")["smember_id"],
                        "ocoalp_updated_on" => date("Y-m-d H:i:s"),
                        'ocoalp_DI_flag' => addslashes(trim($this->input->post("ocoalp_DI_flag")))
                    );
                    $this->db->trans_start();
                    if ($this->OBESManagement->createCOAttainmentLevelPercentage($array)) {
                        $this->db->trans_complete();
                        $this->session->set_flashdata("successMessage", "Course Outcome Attainment Level Percentage Created Successful.");
                        redirect("admin/OBESConfig/coAttainmentLevelPercentages");
                    } else {
                        $this->session->set_flashdata("errorMessage", "An Error Occured While Creating Course Outcome Attainment Level Percentage. Try Later.");
                        redirect(current_url());
                    }
                }
            }
        } else {
            redirect("admin/");
        }
    }

    public function coAttainmentLevelPercentages() {
        if ($this->sessionvalidator->isLoggedIn() && $this->sessionvalidator->isAccessGranted()) {
            $viewData["coAttainmentLevelPercentages"] = $this->OBESManagement->getAllCOAttainmentLevelPercentages()->result();
            $this->load->view("admin/obes/coAttainmentLevelPercentages", $viewData);
        } else {
            redirect("admin/");
        }
    }

    public function toggleCOAttainmentLevelPercentageDeleteStatus($osetp_id, $changeStatus) {
        if ($this->sessionvalidator->isLoggedIn()) {
            $array = array(
                'ocoalp_updated_on' => date("Y-m-d H:i:s"),
                'ocoalp_updated_by' => $this->session->userdata("adminData")["smember_id"],
                'ocoalp_delete_status' => $changeStatus
            );
            if ($this->OBESManagement->updateCOAttainmentLevelPercentage($osetp_id, $array)) {
                $this->session->set_flashdata('successMessage', 'Course Outcome Attainment Level Percentage Delete Status Updated Successfully.');
                redirect("admin/OBESConfig/coAttainmentLevelPercentages");
            } else {
                $this->session->set_flashdata('errorMessage', 'Failed To Update Course Outcome Attainment Level Percentage Delete Status. Try Later.');
                redirect(current_url());
            }
        } else {
            redirect("admin/");
        }
    }

    public function toggleCOAttainmentLevelPercentageStatus($osetp_id, $changeStatus) {
        if ($this->sessionvalidator->isLoggedIn()) {
            $array = array(
                'ocoalp_updated_on' => date("Y-m-d H:i:s"),
                'ocoalp_updated_by' => $this->session->userdata("adminData")["smember_id"],
                'ocoalp_active_status' => $changeStatus
            );
            if ($this->OBESManagement->updateCOAttainmentLevelPercentage($osetp_id, $array)) {
                $this->session->set_flashdata('successMessage', 'Course Outcome Attainment Level Percentage Status Updated Successfully.');
                redirect("admin/OBESConfig/coAttainmentLevelPercentages");
            } else {
                $this->session->set_flashdata('errorMessage', 'Failed To Update Course Outcome Attainment Level Percentage Status. Try Later.');
                redirect(current_url());
            }
        } else {
            redirect("admin/");
        }
    }

    public function editCOAttainmentLevelPercentage($ocoalp_id) {
        if ($this->sessionvalidator->isLoggedIn()) {
            $viewData['sessions'] = $this->SessionManagement->getNonDeletedActiveSessions()->result();
            $viewData["coAttainmentLevelPercentage"] = $this->OBESManagement->getCOAttainmentLevelPercentagesBy($ocoalp_id)->result()[0];
            $this->load->view("admin/obes/editCOAttainmentLevelPercentage", $viewData);
        } else {
            redirect("admin/");
        }
    }

    public function updateCOAttainmentLevelPercentage() {
        if ($this->sessionvalidator->isLoggedIn()) {
            $ocoalp_id = trim($this->input->post("ocoalp_id"));
            $this->form_validation->set_rules("session", "Session", "trim|required", array("required" => "Select Session."));
            $this->form_validation->set_rules("sm_name", "Subject Name", "trim|required", array("required" => "Select Subject Name."));
            $this->form_validation->set_rules("level_name", "CO Attainment Level Name", "trim|required", array("required" => "Enter CO Attainment Level Name."));
            $this->form_validation->set_rules("level_value", "CO Attainment Level Value", "trim|required", array("required" => "Enter CO Attainment Level Value."));
            $this->form_validation->set_rules("per_from", "CO Attainment Level From", "trim|required", array("required" => "Enter CO Attainment Level Percentage (From) ."));
            $this->form_validation->set_rules("per_to", "CO Attainment Level To", "trim|required", array("required" => "Enter CO Attainment Level Percentage (To) ."));
            if ($this->form_validation->run() == false) {
                $this->editCOAttainmentLevelPercentage($ocoalp_id);
            } else {
                if (sizeof($this->OBESManagement->getCOAttainmentLevelPercentageBy($ocoalp_id, trim($this->input->post("sm_name")), trim($this->input->post("session")), addslashes(trim($this->input->post("level_name"))), addslashes(trim($this->input->post("level_value"))), trim($this->input->post("ocoalp_DI_flag")))->result())) {
                    $this->session->set_flashdata("errorMessage", "Data Already Exist. Try Again.");
                    redirect("admin/OBESConfig/editCOAttainmentLevelPercentage/$ocoalp_id");
                } else {
                    $array = array(
                        "sm_id" => trim($this->input->post("sm_name")),
                        "session_id" => $this->input->post("session"),
                        'ocoalp_level_value' => addslashes(trim($this->input->post("level_value"))),
                        'ocoalp_level_name' => addslashes(trim($this->input->post("level_name"))),
                        'ocoalp_percentage_from' => addslashes(trim($this->input->post("per_from"))),
                        'ocoalp_percentage_to' => addslashes(trim($this->input->post("per_to"))),
                        "ocoalp_updated_by" => $this->session->userdata("adminData")["smember_id"],
                        "ocoalp_updated_on" => date("Y-m-d H:i:s"),
                        'ocoalp_DI_flag' => addslashes(trim($this->input->post("ocoalp_DI_flag")))
                    );
                    $this->db->trans_start();
                    if ($this->OBESManagement->updateCOAttainmentLevelPercentage($ocoalp_id, $array)) {
                        $this->db->trans_complete();
                        $this->session->set_flashdata("successMessage", "Course Outcome Attainment Level Percentage Updated Successful.");
                        redirect("admin/OBESConfig/coAttainmentLevelPercentages");
                    } else {
                        $this->session->set_flashdata("errorMessage", "An Error Occured While Updating Course Outcome Attainment Level Percentage. Try Later.");
                        redirect(current_url());
                    }
                }
            }
        } else {
            redirect("admin/");
        }
    }

    /* CO Attainment Level Subjetc Wise (Internal/External) */

    public function createCOAttainmentLevelPercentageIntExt() {
        if ($this->sessionvalidator->isLoggedIn()) {
            $viewData['sessions'] = $this->SessionManagement->getNonDeletedActiveSessions()->result();
            $this->load->view("admin/obes/createCOAttainmentLevelPercentageIntExt", $viewData);
        } else {
            redirect("admin/");
        }
    }

    public function saveCOAttainmentLevelPercentageIntExt() {
        if ($this->sessionvalidator->isLoggedIn()) {
            $this->form_validation->set_rules("session", "Session", "trim|required", array("required" => "Select Session."));
            $this->form_validation->set_rules("sm_name", "Subject Name", "trim|required", array("required" => "Select Subject Name."));
            $this->form_validation->set_rules("perIn", "CO Attainment Level Internal Percentage", "trim|required", array("required" => "Enter CO Attainment Level Internal Percentage."));
            $this->form_validation->set_rules("perEx", "CO Attainment Level External Percentage", "trim|required", array("required" => "Enter CO Attainment Level External Percentage."));
            if ($this->form_validation->run() == false) {
                $this->createCOAttainmentLevelPercentageIntExt();
            } else {
                if (sizeof($this->OBESManagement->getCOAttainmentLevelPercentageIntExtBy('', trim($this->input->post("sm_name")), trim($this->input->post("session")))->result())) {
                    $this->session->set_flashdata("errorMessage", "Data Already Exist. Try Again.");
                    redirect("admin/OBESConfig/createCOAttainmentLevelPercentageIntExt");
                } else {
                    $array = array(
                        array(
                            "sm_id" => trim($this->input->post("sm_name")),
                            "session_id" => $this->input->post("session"),
                            'ocoalpie_percentage' => addslashes(trim($this->input->post("perIn"))),
                            "ocoalpie_added_by" => $this->session->userdata("adminData")["smember_id"],
                            "ocoalpie_added_on" => date("Y-m-d H:i:s"),
                            "ocoalpie_updated_by" => $this->session->userdata("adminData")["smember_id"],
                            "ocoalpie_updated_on" => date("Y-m-d H:i:s"),
                            'ocoalpie_IE_flag' => "I"
                        ),
                        array(
                            "sm_id" => trim($this->input->post("sm_name")),
                            "session_id" => $this->input->post("session"),
                            'ocoalpie_percentage' => addslashes(trim($this->input->post("perEx"))),
                            "ocoalpie_added_by" => $this->session->userdata("adminData")["smember_id"],
                            "ocoalpie_added_on" => date("Y-m-d H:i:s"),
                            "ocoalpie_updated_by" => $this->session->userdata("adminData")["smember_id"],
                            "ocoalpie_updated_on" => date("Y-m-d H:i:s"),
                            'ocoalpie_IE_flag' => "E"
                        ),
                    );
                    $this->db->trans_start();
                    if ($this->OBESManagement->createCOAttainmentLevelPercentageIntExt($array)) {
                        $this->db->trans_complete();
                        $this->session->set_flashdata("successMessage", "Course Outcome Attainment Level Percentage For Internal & External Attainment Created Successful.");
                        redirect("admin/OBESConfig/coAttainmentLevelPercentagesIntExt");
                    } else {
                        $this->session->set_flashdata("errorMessage", "An Error Occured While Creating Course Outcome Attainment Level Percentage For Internal & External Attainment. Try Later.");
                        redirect(current_url());
                    }
                }
            }
        } else {
            redirect("admin/");
        }
    }

    public function coAttainmentLevelPercentagesIntExt() {
        if ($this->sessionvalidator->isLoggedIn() && $this->sessionvalidator->isAccessGranted()) {
            $viewData["coAttainmentLevelPercentagesIntExt"] = $this->OBESManagement->getAllCOAttainmentLevelPercentagesIntExt()->result();
            $this->load->view("admin/obes/coAttainmentLevelPercentagesIntExt", $viewData);
        } else {
            redirect("admin/");
        }
    }

    public function toggleCOAttainmentLevelPercentageIntExtDeleteStatus($ocoalpie_id, $changeStatus) {
        if ($this->sessionvalidator->isLoggedIn()) {
            $array = array(
                'ocoalpie_updated_on' => date("Y-m-d H:i:s"),
                'ocoalpie_updated_by' => $this->session->userdata("adminData")["smember_id"],
                'ocoalpie_delete_status' => $changeStatus
            );
            if ($this->OBESManagement->updateCOAttainmentLevelPercentageIntExt($ocoalpie_id, $array)) {
                $this->session->set_flashdata('successMessage', 'Course Outcome Attainment Level Percentage For Internal External Attainment Report For Internal & External Attainment Delete Status Updated Successfully.');
                redirect("admin/OBESConfig/coAttainmentLevelPercentagesIntExt");
            } else {
                $this->session->set_flashdata('errorMessage', 'Failed To Update Course Outcome Attainment Level Percentage For Internal & External Attainment Delete Status. Try Later.');
                redirect(current_url());
            }
        } else {
            redirect("admin/");
        }
    }

    public function toggleCOAttainmentLevelPercentageIntExtStatus($ocoalpie_id, $changeStatus) {
        if ($this->sessionvalidator->isLoggedIn()) {
            $array = array(
                'ocoalpie_updated_on' => date("Y-m-d H:i:s"),
                'ocoalpie_updated_by' => $this->session->userdata("adminData")["smember_id"],
                'ocoalpie_active_status' => $changeStatus
            );
            if ($this->OBESManagement->updateCOAttainmentLevelPercentageIntExt($ocoalpie_id, $array)) {
                $this->session->set_flashdata('successMessage', 'Course Outcome Attainment Level Percentage For Internal & External Attainment Status Updated Successfully.');
                redirect("admin/OBESConfig/coAttainmentLevelPercentagesIntExt");
            } else {
                $this->session->set_flashdata('errorMessage', 'Failed To Update Course Outcome Attainment Level Percentage For Internal & External Attainment Status. Try Later.');
                redirect(current_url());
            }
        } else {
            redirect("admin/");
        }
    }

    public function editCOAttainmentLevelPercentageIntExt($ocoalpie_id) {
        if ($this->sessionvalidator->isLoggedIn()) {
            $viewData['sessions'] = $this->SessionManagement->getNonDeletedActiveSessions()->result();
            $viewData["coAttainmentLevelPercentage"] = $this->OBESManagement->getCOAttainmentLevelPercentagesByIntExt($ocoalpie_id)->result()[0];
            $this->load->view("admin/obes/editCOAttainmentLevelPercentageIntExt", $viewData);
        } else {
            redirect("admin/");
        }
    }

    public function updateCOAttainmentLevelPercentageIntExt() {
        if ($this->sessionvalidator->isLoggedIn()) {
            $ocoalpie_id = trim($this->input->post("ocoalpie_id"));
            $this->form_validation->set_rules("session", "Session", "trim|required", array("required" => "Select Session."));
            $this->form_validation->set_rules("sm_name", "Subject Name", "trim|required", array("required" => "Select Subject Name."));
            $this->form_validation->set_rules("per", "CO Attainment Level Percentage", "trim|required", array("required" => "Enter CO Attainment Level Percentage."));

            if ($this->form_validation->run() == false) {
                $this->editCOAttainmentLevelPercentageIntExt($ocoalpie_id);
            } else {
                if (sizeof($this->OBESManagement->getCOAttainmentLevelPercentageIntExtBy($ocoalpie_id, trim($this->input->post("sm_name")), trim($this->input->post("session")), trim($this->input->post("ocoalpie_IE_flag")))->result())) {
                    $this->session->set_flashdata("errorMessage", "Data Already Exist. Try Again.");
                    redirect("admin/OBESConfig/editCOAttainmentLevelPercentageIntExt/$ocoalpie_id");
                } else {
                    $array = array(
                        "sm_id" => trim($this->input->post("sm_name")),
                        "session_id" => $this->input->post("session"),
                        'ocoalpie_percentage' => addslashes(trim($this->input->post("per"))),
                        "ocoalpie_updated_by" => $this->session->userdata("adminData")["smember_id"],
                        "ocoalpie_updated_on" => date("Y-m-d H:i:s"),
                        'ocoalpie_IE_flag' => addslashes(trim($this->input->post("ocoalpie_IE_flag")))
                    );
                    $this->db->trans_start();
                    if ($this->OBESManagement->updateCOAttainmentLevelPercentageIntExt($ocoalpie_id, $array)) {
                        $this->db->trans_complete();
                        $this->session->set_flashdata("successMessage", "Course Outcome Attainment Level Percentage For Internal & External Attainment Updated Successful.");
                        redirect("admin/OBESConfig/coAttainmentLevelPercentagesIntExt");
                    } else {
                        $this->session->set_flashdata("errorMessage", "An Error Occured While Updating Course Outcome Attainment Level Percentage For Internal & External Attainment. Try Later.");
                        redirect(current_url());
                    }
                }
            }
        } else {
            redirect("admin/");
        }
    }

        /* 01/06/2021 developer 1 code */
    
    public function createLevelsAndKeywords() {
        if ($this->sessionvalidator->isLoggedIn()) {
            $this->load->view("admin/obes/createLevelsAndKeywords");
        } else {
            redirect("admin/");
        }
    }



    public function saveLevelsAndKeywords() {
        if ($this->sessionvalidator->isLoggedIn()) {
            $this->form_validation->set_rules("level_abbre", "Level Abbreviation", "trim|required", array("required" => "Enter Level Abbreviation."));
            $this->form_validation->set_rules("level_name", "Level Name", "trim|required", array("required" => "Enter Level Name."));
            $this->form_validation->set_rules("keywords", "Keywords", "trim|required", array("required" => "Enter Keywords."));
            if ($this->form_validation->run() == false) {
                $this->createLevelsAndKeywords();
            } else {
                if (sizeof($this->OBESManagement->getLevelsAndKeywordsBy('', trim($this->input->post("level_abbre")))->result())) {
                    $this->session->set_flashdata("errorMessage", "Data Already Exist With Given Level Abbreviation. Try Again.");
                    redirect("admin/OBESConfig/createLevelsAndKeywords");
                } else if (sizeof($this->OBESManagement->getLevelsAndKeywordsBy('', '', trim($this->input->post("level_name")))->result())) {
                    $this->session->set_flashdata("errorMessage", "Data Already Exist With Given Level Name. Try Again.");
                    redirect("admin/OBESConfig/createLevelsAndKeywords");
                } else {
                    $array = array(
                        "olk_level_name" => addslashes(trim($this->input->post("level_name"))),
                        "olk_level_abbreviation" => addslashes(trim($this->input->post("level_abbre"))),
                        'olk_keywords' => addslashes(trim($this->input->post("keywords"))),
                        "olk_added_by" => $this->session->userdata("adminData")["smember_id"],
                        "olk_added_on" => date("Y-m-d H:i:s"),
                        "olk_updated_by" => $this->session->userdata("adminData")["smember_id"],
                        "olk_updated_on" => date("Y-m-d H:i:s")
                    );
                    $this->db->trans_start();
                    if ($this->OBESManagement->createLevelsAndKeywords($array)) {
                        $this->db->trans_complete();
                        $this->session->set_flashdata("successMessage", "Levels_& Keywords Created Successful.");
                        redirect("admin/OBESConfig/levelsAndKeywords");
                    } else {
                        $this->session->set_flashdata("errorMessage", "An Error Occured While Creating Levels_& Keywords. Try Later.");
                        redirect(current_url());
                    }
                }
            }
        } else {
            redirect("admin/");
        }
    }

    public function levelsAndKeywords() {
        if ($this->sessionvalidator->isLoggedIn() && $this->sessionvalidator->isAccessGranted()) {
            $viewData["levelsAndKeywords"] = $this->OBESManagement->getLevelsAndKeywords()->result();
            $this->load->view("admin/obes/levelsAndKeywords", $viewData);
        } else {
            redirect("admin/");
        }
    }

    public function togglelevelsAndKeywordsDeleteStatus($olk_id, $changeStatus) {
        if ($this->sessionvalidator->isLoggedIn()) {
            $array = array(
                'olk_updated_on' => date("Y-m-d H:i:s"),
                'olk_updated_by' => $this->session->userdata("adminData")["smember_id"],
                'olk_delete_status' => $changeStatus
            );
            if ($this->OBESManagement->updateLevelsAndKeywordst($olk_id, $array)) {
                $this->session->set_flashdata('successMessage', 'Levels And Keywords Delete Status Updated Successfully.');
                redirect("admin/OBESConfig/levelsAndKeywords");
            } else {
                $this->session->set_flashdata('errorMessage', 'Failed To Update Levels And Keywords Delete Status. Try Later.');
                redirect(current_url());
            }
        } else {
            redirect("admin/");
        }
    }

    public function togglelevelsAndKeywordsStatus($olk_id, $changeStatus) {
        if ($this->sessionvalidator->isLoggedIn()) {
            $array = array(
                'olk_updated_on' => date("Y-m-d H:i:s"),
                'olk_updated_by' => $this->session->userdata("adminData")["smember_id"],
                'olk_active_status' => $changeStatus
            );
            if ($this->OBESManagement->updateLevelsAndKeywordst($olk_id, $array)) {
                $this->session->set_flashdata('successMessage', 'Levels And Keywords Status Updated Successfully.');
                redirect("admin/OBESConfig/levelsAndKeywords");
            } else {
                $this->session->set_flashdata('errorMessage', 'Failed To Update Levels And Keywords Status. Try Later.');
                redirect(current_url());
            }
        } else {
            redirect("admin/");
        }
    }

    public function editLevelsAndKeywords($olk_id) {
        if ($this->sessionvalidator->isLoggedIn()) {
            $viewData["levelAndKeywords"] = $this->OBESManagement->getLevelsAndKeywordsByID($olk_id)->result()[0];
            $this->load->view("admin/obes/editLevelsAndKeywords", $viewData);
        } else {
            redirect("admin/");
        }
    }

    public function updateLevelsAndKeywords() {
        if ($this->sessionvalidator->isLoggedIn()) {
            $this->form_validation->set_rules("level_abbre", "Level Abbreviation", "trim|required", array("required" => "Enter Level Abbreviation."));
            $this->form_validation->set_rules("level_name", "Level Name", "trim|required", array("required" => "Enter Level Name."));
            $this->form_validation->set_rules("keywords", "Keywords", "trim|required", array("required" => "Enter Keywords."));
            $olk_id = $this->input->post("olk_id");
            if ($this->form_validation->run() == false) {
                $this->editLevelsAndKeywords($olk_id);
            } else {
                if (sizeof($this->OBESManagement->getLevelsAndKeywordsBy($olk_id, trim($this->input->post("level_abbre")))->result())) {
                    $this->session->set_flashdata("errorMessage", "Data Already Exist With Given Level Abbreviation. Try Again.");
                    redirect("admin/OBESConfig/editLevelsAndKeywords/$olk_id");
                } else if (sizeof($this->OBESManagement->getLevelsAndKeywordsBy($olk_id, '', trim($this->input->post("level_name")))->result())) {
                    $this->session->set_flashdata("errorMessage", "Data Already Exist With Given Level Name. Try Again.");
                    redirect("admin/OBESConfig/editLevelsAndKeywords/$olk_id");
                } else {
                    $array = array(
                        "olk_level_name" => addslashes(trim($this->input->post("level_name"))),
                        "olk_level_abbreviation" => addslashes(trim($this->input->post("level_abbre"))),
                        'olk_keywords' => addslashes(trim($this->input->post("keywords"))),
                        "olk_updated_by" => $this->session->userdata("adminData")["smember_id"],
                        "olk_updated_on" => date("Y-m-d H:i:s")
                    );
                    $this->db->trans_start();
                    if ($this->OBESManagement->updateLevelsAndKeywordst($olk_id, $array)) {
                        $this->db->trans_complete();
                        $this->session->set_flashdata("successMessage", "Levels_& Keywords Updated Successful.");
                        redirect("admin/OBESConfig/levelsAndKeywords");
                    } else {
                        $this->session->set_flashdata("errorMessage", "An Error Occured While Updating Levels_& Keywords. Try Later.");
                        redirect("admin/OBESConfig/editLevelsAndKeywords/") . $olk_id;
                    }
                }
            }
        } else {
            redirect("admin/");
        }
    }

    public function getModelQuestionPaper() {
        if ($this->sessionvalidator->isLoggedIn() && $this->sessionvalidator->isAccessGranted()) {
            if (isset($_POST["filterAttendanceBtn"])) {
                $viewData["selectedSession"] = $this->input->post("session");
                $viewData["selectedCourse"] = $this->input->post("subjectCourse");
                $viewData["selectedSubject"] = $this->input->post("sm_name");
                $viewData["selectedAssessment"] = $this->input->post("test_name");
                $questions = $this->OBESManagement->getModelQuestionPaper($this->input->post("subjectCourse"), $this->input->post("sm_name"), $this->input->post("test_name"))->result();
                $modelQuestions = array();
                for ($q = 0; $q < sizeof($questions); $q++) {

                    $coMappedToQuestion = $this->OBESManagement->getCOMappedToQuestion($questions[$q]->qno_id)->result();
                    $coArray = array();
                    $poArray = array();
                    for ($c = 0; $c < sizeof($coMappedToQuestion); $c++) {
                        
                        $poMappedToCo = $this->OBESManagement->getPOMappedToCO($coMappedToQuestion[$c]->co_id)->result();
                        for ($p = 0; $p < sizeof($poMappedToCo); $p++) {
                            array_push($poArray, $poMappedToCo[$p]->po_name);
                        }
                        array_push($coArray, $coMappedToQuestion[$c]->co_name);
                    }
                    array_push($modelQuestions, array(
                        'qno_name' => $questions[$q]->qno_name,
                        'qno_desc' => $questions[$q]->qno_desc,
                        'qno_marks' => $questions[$q]->qno_marks,
                        'co' => implode(", ",$coArray),
                        'po' => implode(", ",$poArray),
                        'qno_level' => $questions[$q]->olk_level_abbreviation,
                        'qno_file' => $questions[$q]->qno_file,
                    ));
                }

                $viewData["modelQuestionPaper"] = $modelQuestions;
                $viewData["selectedSubjectDetails"] = $this->SubjectManagement->getSubjectInfoBy($this->input->post("sm_name"))->result()[0];
                $viewData["testDetails"] = $this->OBESManagement->getTestById($this->input->post("test_name"))->result()[0];
                $viewData["coQuestionSummary"] = $this->OBESManagement->getModelQuestionPaperAndCOSummaryInJSON($this->input->post("test_name"));
                $viewData["levelWiseMarksDistributionSummary"] = $this->OBESManagement->getLevelWiseMarksDistributionSummaryInJSON($this->input->post("test_name"));
            } else {
                $viewData["selectedSession"] = "";
                $viewData["selectedCourse"] = "";
                $viewData["selectedSubject"] = "";
                $viewData["selectedAssessment"] = "";
                $viewData["modelQuestionPaper"] = array();
                $viewData["selectedSubjectDetails"] = array();
                $viewData["testDetails"] = array();
                $viewData["coQuestionSummary"] = null;
                $viewData["levelWiseMarksDistributionSummary"] = null;
            }
            $viewData['sessions'] = $this->SessionManagement->getNonDeletedActiveSessions()->result();
            $this->load->view("admin/obes/modelQuestionPaper", $viewData);
        } else {
            redirect("admin/");
        }
    }

}

KBHT - 2023