File: /home/cafsindia/lms_cafsinfotech_in/application/controllers/admin/Branch.php
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Branch extends Admin_Controller {
function __construct() {
parent::__construct();
$this->add_css_theme('all.css');
$this->add_js_theme('jquery.multi-select.min.js');
$this->add_js_theme('branch_custome_script.js');
// load the language files
// load the branch model
$this->load->model('BranchModel');
//load the form validation
$this->load->library('form_validation');
// set constants
define('REFERRER', "referrer");
define('THIS_URL', base_url('admin/branch'));
define('DEFAULT_LIMIT', 10);
define('DEFAULT_OFFSET', 0);
define('DEFAULT_SORT', "last_name");
define('DEFAULT_DIR', "asc");
}
function index() {
$this->add_css_theme('sweetalert.css')->add_js_theme('sweetalert-dev.js')->add_js_theme('bootstrap-notify.min.js')->set_title(lang('branch_list'));
$data = $this->includes;
$content_data = array();
// load views
$data['content'] = $this->load->view('admin/branch/list', $content_data, TRUE);
$this->load->view($this->template, $data);
}
function form($id = null) {
$parentcat = $this->BranchModel->allbranch($id);
$editData = "";
if($id) {
$editData = $this->BranchModel->getfetch($id);
}
$this->form_validation->set_rules('branch_name', 'Branch Name', 'trim|required');
if ($this->form_validation->run() != false)
{
action_not_permitted();
$content = array();
$display_on_home = $this->input->post('display_on_home', TRUE) ? 1 : 0;
$branch_name_count = $this->BranchModel->branch_name_like_this($id, $this->input->post('branch_name', TRUE));
$count = $branch_name_count > 0 ? '-' . $branch_name_count : '';
$content['branch_name'] = $this->input->post('branch_name', TRUE);
if ($this->input->post(lang('core_button_save'), TRUE))
{
$this->BranchModel->insert($content);
$this->session->set_flashdata('message', lang('admin_record_added_successfully'));
redirect(base_url('admin/branch'));
}
if ($this->input->post(lang('core_button_update'), TRUE))
{
$this->BranchModel->update($content, $id);
$this->session->set_flashdata('message', lang('admin_record_updated_successfully'));
redirect(base_url('admin/branch'));
}
}
else
{
$fielderror = $this->form_validation->error_array();
}
$this->add_js_theme('bootstrap-iconpicker.bundle.min.js');
$this->add_js_theme('bootstrap.bundle.min.js');
$this->add_css_theme('bootstrap-iconpicker.min.css');
if ($id) {
$this->set_title(lang('branch_title_branch_edit'));
} else {
$this->set_title(lang('add_branch'));
}
$data = $this->includes;
$content_data = array('editData' => $editData, 'cat_title' => $parentcat);
// load views
$data['content'] = $this->load->view('admin/branch/form', $content_data, TRUE);
$this->load->view($this->template, $data);
}
function branch_list() {
$list = $this->BranchModel->get_branch();
$data = array();
$no = $_POST['start'];
foreach ($list as $branch) {
$no++;
$row = array();
$row[] = $no;
$row[] = ucfirst($branch->branch_name);
$checkvalue = ($branch->branch_status == 1 ? 'checked="checked"' : "");
$row[] = '<label class="custom-switch mt-2">
<input type="checkbox" data-id="' . $branch->branch_id . '" name="custom-switch-checkbox" class="custom-switch-input togle_switch" ' . $checkvalue . '>
<span class="custom-switch-indicator indication"></span>
</label>';
$row[] = '<a href="' . base_url("admin/branch/form/" . $branch->branch_id) . '" data-toggle="tooltip" title="'.lang("admin_copy_record").'" class="btn btn-primary btn-action mr-1"><i class="fas fa-pencil-alt"></i></a>
<a href="' . base_url("admin/branch/delete/" . $branch->branch_id) . '" data-toggle="tooltip" title="'.lang("admin_delete_record").'" class="btn btn-danger btn-action mr-1 cat_delete"><i class="fas fa-trash"></i></a>';
$data[] = $row;
}
$output = array("draw" => $_POST['draw'], "recordsTotal" => $this->BranchModel->count_all(), "recordsFiltered" => $this->BranchModel->count_filtered(), "data" => $data);
//output to json format
echo json_encode($output);
}
function update_status() {
$id = $_POST['branch_id'];
$status = $_POST['status'];
$this->BranchModel->updatestatus($id, $status);
$success = array('status' => $status, 'messages' => lang('admin_branch_status_updated_successfully'));
echo json_encode($success);
}
function delete($id = NULL) {
action_not_permitted();
$findImage = $this->BranchModel->deleteimage($id);
if (!empty($findImage)) {
$path = "./assets/images/branch_image/$findImage";
unlink($path);
}
$this->BranchModel->delete($id);
$this->session->set_flashdata('message', lang('admin_record_delete_successfully'));
redirect(base_url('admin/branch'));
}
}