225 lines
7.0 KiB
PHP
225 lines
7.0 KiB
PHP
<?php
|
|
defined('BASEPATH') or exit('No direct script access allowed');
|
|
|
|
class Global_settings extends Admin_Controller {
|
|
public $viewData = [];
|
|
|
|
public function __construct() {
|
|
parent::__construct();
|
|
|
|
$this->load->library('table');
|
|
$this->table->set_template($this->template);
|
|
$this->load->model('combo_model');
|
|
$this->load->model('Global_setting_model', 'global_setting');
|
|
// Load Pagination library
|
|
$this->load->library('pagination');
|
|
|
|
$this->viewData['card_status'] = $this->combo_model->getStatusCombo('card_status', $this->getFormValue()['status']);
|
|
$this->viewData['card_status_filter'] = $this->combo_model->getStatusCombo('card_status_filter', '');
|
|
|
|
$this->viewData['msg'] = null;
|
|
}
|
|
|
|
private function renderToolsPage($page_name, $data) {
|
|
$this->load->view('admin/view_admin_header', $data);
|
|
$this->load->view('global_setting/' . $page_name, $data);
|
|
$this->load->view('admin/view_admin_footer', $data);
|
|
}
|
|
|
|
public function index() {
|
|
$this->renderToolsPage("view_global_setting", $this->viewData);
|
|
}
|
|
|
|
private function setFormRuleSearchForm()
|
|
{
|
|
$this->form_validation->set_rules(
|
|
'card_status_filters',
|
|
'Status',
|
|
'numeric'
|
|
);
|
|
}
|
|
|
|
public function loadRecord(){
|
|
$rowno = $this->input->get('rowno');
|
|
parse_str($this->input->get('filters'), $filters);
|
|
$filters = array_filter($filters, function($val) {
|
|
return $val !== '';
|
|
});
|
|
|
|
$this->form_validation->set_data($filters);
|
|
$this->setFormRuleSearchForm();
|
|
$errors = [];
|
|
if ($this->form_validation->run() == false) {
|
|
$errors = $this->form_validation->error_array();
|
|
}
|
|
$filters = array_diff_key($filters, $errors);
|
|
|
|
// Row per page
|
|
$rowperpage = 10;
|
|
$cur_page = $rowno;
|
|
|
|
// Row position
|
|
if($rowno != 0){
|
|
$rowno = ($rowno-1) * $rowperpage;
|
|
}
|
|
|
|
// All records count
|
|
$allcount = $this->global_setting->getrecordCount($filters);
|
|
|
|
// Get records
|
|
$users_record = $this->global_setting->getData($rowno, $rowperpage, $filters);
|
|
|
|
// Pagination Configuration
|
|
$config['base_url'] = '/Global_settings/loadRecord';
|
|
$config['use_page_numbers'] = TRUE;
|
|
$config['total_rows'] = $allcount;
|
|
$config['per_page'] = $rowperpage;
|
|
$config['cur_page'] = $cur_page;
|
|
$config['full_tag_open'] = "<ul class='pagination'>";
|
|
$config['full_tag_close'] = "</ul>";
|
|
$config['num_tag_open'] = '<li>';
|
|
$config['num_tag_close'] = '</li>';
|
|
$config['cur_tag_open'] = "<li class='disabled'><li class='active'><a href='#'>";
|
|
$config['cur_tag_close'] = "<span class='sr-only'></span></a></li>";
|
|
$config['next_tag_open'] = "<li>";
|
|
$config['next_tagl_close'] = "</li>";
|
|
$config['prev_tag_open'] = "<li>";
|
|
$config['prev_tagl_close'] = "</li>";
|
|
$config['first_tag_open'] = "<li>";
|
|
$config['first_tagl_close'] = "</li>";
|
|
$config['last_tag_open'] = "<li>";
|
|
$config['last_tagl_close'] = "</li>";
|
|
|
|
// Initialize
|
|
$this->pagination->initialize($config);
|
|
|
|
// Initialize $data Array
|
|
$data['pagination'] = $this->pagination->create_links();
|
|
$data['result'] = $users_record;
|
|
$data['row'] = $rowno;
|
|
|
|
echo json_encode($data);
|
|
}
|
|
|
|
public function create() {
|
|
$this->load->helper(array('form', 'url'));
|
|
$this->load->database();
|
|
$this->load->library('form_validation');
|
|
$this->setFormRule();
|
|
|
|
$params = $this->getFormValue();
|
|
|
|
if ($this->form_validation->run() == false) {
|
|
$this->viewData = array_merge($this->viewData, $params);
|
|
$this->viewData['msg'] = validation_errors();
|
|
$this->renderToolsPage('view_global_setting', $this->viewData);
|
|
return;
|
|
}
|
|
|
|
if (!$this->global_setting->insertGlobalSetting($params)) {
|
|
$this->viewData['msg'] = "Insert Failed";
|
|
}
|
|
else {
|
|
$this->viewData['msg'] = "Insert Succesful";
|
|
}
|
|
|
|
$this->renderToolsPage('view_global_setting', $this->viewData);
|
|
}
|
|
|
|
public function update($id) {
|
|
$this->load->helper(array('form', 'url'));
|
|
$this->load->database();
|
|
$this->load->library('form_validation');
|
|
$this->setFormRule();
|
|
|
|
$params = $this->getFormValue();
|
|
|
|
if (strcmp($params['key'], $params['old_key']) === 0) {
|
|
$this->form_validation->set_rules('key', 'Key', 'required|max_length[50]');
|
|
}
|
|
|
|
if ($this->form_validation->run() == false) {
|
|
$this->viewData = array_merge($this->viewData, $params);
|
|
$this->viewData['msg'] = validation_errors();
|
|
$this->renderToolsPage('view_global_setting', $this->viewData);
|
|
return;
|
|
}
|
|
|
|
if (!$this->global_setting->updateGlobalSetting($id, $params)) {
|
|
$this->viewData['msg'] = "Update Failed";
|
|
}
|
|
else {
|
|
$this->viewData['msg'] = "Update Succesful";
|
|
}
|
|
|
|
$this->renderToolsPage('view_global_setting', $this->viewData);
|
|
}
|
|
|
|
private function setFormRule()
|
|
{
|
|
$this->form_validation->set_rules('key', 'Key', 'trim|required|max_length[50]|is_unique[global_settings.key]');
|
|
$this->form_validation->set_rules('value', 'Value', 'trim|required|max_length[50]');
|
|
$this->form_validation->set_rules('description', 'description', 'trim|required|max_length[350]');
|
|
$this->form_validation->set_rules('card_status', 'Status', 'trim|required|numeric|callback_isValidStatus');
|
|
$this->form_validation->set_message('isOutOfRangeInt4', 'The %s field is out of range');
|
|
}
|
|
|
|
public function isValidStatus($status) {
|
|
if (preg_match('/^[0-1]{1}$/', $status)) {
|
|
return TRUE;
|
|
} else {
|
|
$this->form_validation->set_message('isValidStatus', 'The Status is invalid');
|
|
return FALSE;
|
|
}
|
|
}
|
|
|
|
private function getFormValue()
|
|
{
|
|
return [
|
|
'key' => trim($this->input->post('key')),
|
|
'value' => trim($this->input->post('value')),
|
|
'old_key' => trim($this->input->post('old_key')),
|
|
'description' => trim($this->input->post('description')),
|
|
'status' => trim($this->input->post('card_status')),
|
|
];
|
|
}
|
|
|
|
public function destroy($id) {
|
|
|
|
$this->load->helper(array('form', 'url'));
|
|
$this->load->database();
|
|
$this->load->library('form_validation');
|
|
|
|
$this->form_validation->set_data(['id' => $id]);
|
|
$this->setFormRuleDelete();
|
|
|
|
if ($this->form_validation->run() == false) {
|
|
$this->viewData['msg'] = validation_errors();
|
|
$this->renderToolsPage('view_global_setting', $this->viewData);
|
|
return;
|
|
}
|
|
|
|
$this->viewData['msg'] = !$this->global_setting->deleteGlobalSettingById(['id' => $id])
|
|
? "Delete Failed"
|
|
: "Delete Successful" ;
|
|
|
|
$this->renderToolsPage('view_global_setting', $this->viewData);
|
|
}
|
|
|
|
private function setFormRuleDelete()
|
|
{
|
|
$this->form_validation->set_rules('id', 'Global Settings', 'required|numeric|callback_existsGlobalSetting');
|
|
}
|
|
|
|
public function existsGlobalSetting($id) {
|
|
if (!$this->global_setting->getGlobalSettingsByID(['id' => $id]))
|
|
{
|
|
$this->form_validation->set_message('existsGlobalSetting', 'Please choose an existing global settings');
|
|
return FALSE;
|
|
}
|
|
else
|
|
{
|
|
return TRUE;
|
|
}
|
|
}
|
|
} |