File: /home/dmstechonline/crm.chaitanyahospitalvirar.com/application/controllers/admin/Itemcategory.php
<?php
if (!defined('BASEPATH')) {
exit('No direct script access allowed');
}
class Itemcategory extends Admin_Controller
{
public function __construct()
{
parent::__construct();
$this->load->helper('url');
}
public function index()
{
$this->session->set_userdata('top_menu', 'setup');
$this->session->set_userdata('sub_menu', 'inventory/index');
$data['title'] = $this->lang->line('item_category_list');
$category_result = $this->itemcategory_model->get();
$data['categorylist'] = $category_result;
$this->load->view('layout/header', $data);
$this->load->view('admin/itemcategory/itemcategoryList', $data);
$this->load->view('layout/footer', $data);
}
public function delete($id)
{
if (!$this->rbac->hasPrivilege('item_category', 'can_delete')) {
access_denied();
}
$data['title'] = $this->lang->line('item_category_list');
$this->itemcategory_model->remove($id);
echo json_encode(array("status" => 1, "msg" => $this->lang->line("delete_message")));
}
public function create()
{
if (!$this->rbac->hasPrivilege('item_category', 'can_add')) {
access_denied();
}
$data['title'] = $this->lang->line('add_item_category');
$category_result = $this->itemcategory_model->get();
$data['categorylist'] = $category_result;
$this->form_validation->set_rules('itemcategory', $this->lang->line('item_category'), 'trim|required|xss_clean');
if ($this->form_validation->run() == false) {
$this->load->view('layout/header', $data);
$this->load->view('admin/itemcategory/itemcategoryList', $data);
$this->load->view('layout/footer', $data);
} else {
$data = array(
'item_category' => $this->input->post('itemcategory'),
'description' => $this->input->post('description'),
);
$this->itemcategory_model->add($data);
$this->session->set_flashdata('msg', '<div class="alert alert-success text-left">' . $this->lang->line('item_category_added_successfully') . '</div>');
redirect('admin/itemcategory/index');
}
}
/* this funtion is used to save multiple itemcategory */
public function add_multiple_itemcategory() {
$total_rows = $this->input->post('total_rows');
if (isset($total_rows) && !empty($total_rows)) {
//validation to check each input keeps the value or not
foreach ($total_rows as $row_key => $row_value) {
$this->form_validation->set_rules('itemcategory_'.$row_value, $this->lang->line('item_category'), 'trim|required');
if ($this->form_validation->run() == false) {
$msg = array(
'item_category' => form_error('itemcategory_'.$row_value),
);
$json_array = array('status' => 'fail', 'error' => $msg, 'message' => '');
echo json_encode($json_array);
return false;
}
}
//validation to check each input keeps the value or not
// save the multiple data
$total_rows = $this->input->post('total_rows');
foreach ($total_rows as $row_key => $row_values) {
$data = array(
'item_category' => $this->input->post('itemcategory_'.$row_values),
'description' => $this->input->post('description_'.$row_values));
$this->itemcategory_model->add($data);
}
// save the multiple data
$json_array = array('status' => 1, 'error' => '', 'message' => $this->lang->line('success_message'));
echo json_encode($json_array);
}else{
//validation if user not added any row
$message= $this->lang->line("please_add_at_least_one_item_category");
$json_array = array('status' => '2', 'error' => $message ,'message' => '');
//validation if user not added any row
echo json_encode($json_array);
}
}
public function edit()
{
if (!$this->rbac->hasPrivilege('item_category', 'can_edit')) {
access_denied();
}
$id = $this->input->post('cat_id');
$this->form_validation->set_rules('itemcategory', $this->lang->line('item_category'), 'trim|required|xss_clean');
if ($this->form_validation->run() == false) {
$msg = array(
'name' => form_error('itemcategory'),
);
$array = array('status' => 'fail', 'error' => $msg, 'message' => '');
} else {
$data = array(
'id' => $id,
'item_category' => $this->input->post('itemcategory'),
'description' => $this->input->post('description'),
);
$this->itemcategory_model->add($data);
$array = array('status' => 'success', 'error' => '', 'message' => $this->lang->line('update_message'));
}
echo json_encode($array);
}
public function get_data($id)
{
$category = $this->itemcategory_model->get($id);
echo json_encode($category);
}
}