293 lines
9.7 KiB
PHP
293 lines
9.7 KiB
PHP
<?php
|
|
defined('BASEPATH') or exit('No direct script access allowed');
|
|
|
|
class Acl_WhiteList extends Admin_Controller {
|
|
public $viewData = [];
|
|
private $options_array = [];
|
|
|
|
public function __construct() {
|
|
parent::__construct();
|
|
|
|
$this->load->library('table');
|
|
$this->table->set_template($this->template);
|
|
$this->load->model('combo_model');
|
|
$this->load->model('Acl_Whitelist_model', 'acl_whitelist');
|
|
$this->load->model('Acl_Whitelist_Extra_model', 'acl_whitelist_extra');
|
|
// Load Pagination library
|
|
$this->load->library('pagination');
|
|
|
|
$this->options_array = $this->acl_whitelist->getControllerAndMethod();
|
|
|
|
$this->viewData['class_method'] = $this->combo_model->getControllerCombo('class_method', $this->options_array, '');
|
|
$this->viewData['msg'] = null;
|
|
|
|
// filter
|
|
$controller = $this->getController();
|
|
$options_array = array_combine($controller, $controller);
|
|
$options_array = array_merge($options_array, ['' => 'Select']);
|
|
ksort($options_array);
|
|
|
|
$this->viewData['card_class_filter'] = $this->combo_model->getControllerCombo('card_class_filter', $options_array, '');
|
|
$this->viewData['card_permission_level_filter'] = $this->combo_model->getPermissionLevel('card_permission_level_filter', '');
|
|
}
|
|
|
|
private function getController() {
|
|
$path = __DIR__;
|
|
$controller = array();
|
|
|
|
$allFiles = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path));
|
|
$phpFiles = new RegexIterator($allFiles, '/\.php$/');
|
|
|
|
foreach ($phpFiles as $phpFile) {
|
|
$content = file_get_contents($phpFile->getRealPath());
|
|
$tokens = token_get_all($content);
|
|
$namespace = '';
|
|
|
|
for ($index = 0; isset($tokens[$index]); $index++) {
|
|
if (!isset($tokens[$index][0])) {
|
|
continue;
|
|
}
|
|
|
|
if (T_CLASS === $tokens[$index][0]) {
|
|
$index += 2; // Skip class keyword and whitespace
|
|
$controller[] = $tokens[$index][1];
|
|
}
|
|
}
|
|
}
|
|
sort($controller);
|
|
return $controller;
|
|
}
|
|
|
|
protected function renderToolsPage($page_name, $data) {
|
|
$this->load->view('admin/view_admin_header', $data);
|
|
$this->load->view('acl_whitelist/' . $page_name, $data);
|
|
$this->load->view('admin/view_admin_footer', $data);
|
|
}
|
|
|
|
public function index()
|
|
{
|
|
$this->renderToolsPage("view_acl_whitelist", $this->viewData);
|
|
}
|
|
|
|
private function setFormRuleCreate()
|
|
{
|
|
$this->form_validation->set_rules('class_method', 'Class and Method', 'required|callback_existsAclWhitelist');
|
|
$this->form_validation->set_rules('parameter_name', 'Parameter name', 'required|max_length[50]|callback_checkDuplicateAclWhiltelistExtra');
|
|
$this->form_validation->set_rules('parameter_value', 'Parameter value', 'required|max_length[50]');
|
|
}
|
|
|
|
public function existsAclWhitelist() {
|
|
$id = $this->input->post('class_method');
|
|
|
|
if (!$id) {
|
|
$this->form_validation->set_message('existsAclWhitelist', 'Please enter an existing class and method');
|
|
return FALSE;
|
|
}
|
|
|
|
if (!$this->acl_whitelist->getRecordAclWhitelistById(['id' => $id])) {
|
|
$this->form_validation->set_message('existsAclWhitelist', 'Please enter an existing class and method');
|
|
return FALSE;
|
|
} else {
|
|
return TRUE;
|
|
}
|
|
}
|
|
|
|
public function checkDuplicateAclWhiltelistExtra() {
|
|
|
|
if ($this->acl_whitelist_extra->getRecordAclWhiteListExtraByParamNameAndParamValueAndAclWhiteListID($this->getFormValue())) {
|
|
$this->form_validation->set_message('checkDuplicateAclWhiltelistExtra', 'Oops !!! The value you entered is already in the list');
|
|
return FALSE;
|
|
} else {
|
|
return TRUE;
|
|
}
|
|
}
|
|
|
|
private function getFormValue()
|
|
{
|
|
return [
|
|
'bko_acl_whitelist_id' => $this->input->post('class_method'),
|
|
'parameter_name' => $this->input->post('parameter_name'),
|
|
'parameter_value' => $this->input->post('parameter_value')
|
|
];
|
|
}
|
|
|
|
public function create() {
|
|
$this->load->helper(array('form', 'url'));
|
|
$this->load->database();
|
|
$this->load->library('form_validation');
|
|
$this->setFormRuleCreate();
|
|
|
|
$params = $this->getFormValue();
|
|
|
|
if ($this->form_validation->run() == false) {
|
|
$this->viewData['class_method'] = $this->combo_model->getControllerCombo('class_method', $this->options_array, $params['bko_acl_whitelist_id']);
|
|
$this->viewData = array_merge($this->viewData, $params);
|
|
|
|
$this->viewData['msg'] = validation_errors();
|
|
$this->renderToolsPage('view_acl_whitelist', $this->viewData);
|
|
return;
|
|
}
|
|
|
|
if (!$this->acl_whitelist_extra->insertAclWhitelistExtra($params)) {
|
|
$this->viewData['msg'] = "Insert Failed";
|
|
}
|
|
else {
|
|
$this->viewData['msg'] = "Insert Succesful";
|
|
}
|
|
|
|
$this->renderToolsPage('view_acl_whitelist', $this->viewData);
|
|
}
|
|
|
|
private function setFormRuleSearchForm() {
|
|
$this->form_validation->set_rules(
|
|
'card_permission_level_filter',
|
|
'Permission Level',
|
|
'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->acl_whitelist->getrecordCount($filters);
|
|
|
|
// Get records
|
|
$users_record = $this->acl_whitelist->getData($rowno,$rowperpage,$filters);
|
|
|
|
// Pagination Configuration
|
|
$config['base_url'] = '/Acl_Whitelist/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);
|
|
}
|
|
|
|
private function setFormRuleUpdate()
|
|
{
|
|
$this->form_validation->set_rules('id', 'White list Extra', 'required|callback_existsAclWhitelistExtra');
|
|
$this->form_validation->set_rules('parameter_name', 'Parameter name', 'required|max_length[50]|callback_checkDuplicateAclWhiltelistExtra');
|
|
$this->form_validation->set_rules('parameter_value', 'Parameter value', 'required|max_length[50]');
|
|
}
|
|
|
|
public function existsAclWhitelistExtra($id) {
|
|
if (!$id || !is_numeric($id)) {
|
|
$this->form_validation->set_message('existsAclWhitelistExtra', 'Please enter an existing white list extra');
|
|
return FALSE;
|
|
}
|
|
|
|
if (!$this->acl_whitelist_extra->getRecordAclWhitelistExtraByID(['id' => $id]))
|
|
{
|
|
$this->form_validation->set_message('existsAclWhitelistExtra', 'Please enter an existing white list extra');
|
|
return FALSE;
|
|
}
|
|
else
|
|
{
|
|
return TRUE;
|
|
}
|
|
}
|
|
|
|
public function update($id) {
|
|
$this->load->helper(array('form', 'url'));
|
|
$this->load->database();
|
|
$this->load->library('form_validation');
|
|
|
|
$params = $this->getFormValue();
|
|
$params = array_merge($params, ['id' => $id]);
|
|
$this->form_validation->set_data($params);
|
|
|
|
$this->setFormRuleUpdate();
|
|
|
|
if ($this->form_validation->run() == false) {
|
|
$this->viewData['class_method'] = $this->combo_model->getControllerCombo('class_method', $this->options_array, $params['bko_acl_whitelist_id']);
|
|
$this->viewData = array_merge($this->viewData, $params);
|
|
|
|
$this->viewData['msg'] = validation_errors();
|
|
$this->renderToolsPage('view_acl_whitelist', $this->viewData);
|
|
return;
|
|
}
|
|
|
|
$result = $this->acl_whitelist_extra->updateAclWhitelistExtra($params);
|
|
|
|
$this->viewData['msg'] = $result === 0 ? "Update Failed" : "Update Succesful";
|
|
|
|
$this->renderToolsPage('view_acl_whitelist', $this->viewData);
|
|
}
|
|
|
|
private function setFormRuleDelete()
|
|
{
|
|
$this->form_validation->set_rules('id', 'White list Extra', 'required|callback_existsAclWhitelistExtra');
|
|
}
|
|
|
|
public function destroy($id) {
|
|
$this->load->helper(array('form', 'url'));
|
|
$this->load->database();
|
|
$this->load->library('form_validation');
|
|
|
|
$params = $this->getFormValue();
|
|
|
|
$this->form_validation->set_data(['id' => $id]);
|
|
$this->setFormRuleDelete();
|
|
|
|
if ($this->form_validation->run() == false) {
|
|
$this->viewData['class_method'] = $this->combo_model->getControllerCombo('class_method', $this->options_array, $params['bko_acl_whitelist_id']);
|
|
$this->viewData = array_merge($this->viewData, $params);
|
|
|
|
$this->viewData['msg'] = validation_errors();
|
|
$this->renderToolsPage('view_acl_whitelist', $this->viewData);
|
|
return;
|
|
}
|
|
|
|
$result = $this->acl_whitelist_extra->deleteAclWhitelistExtra($id);
|
|
|
|
$this->viewData['msg'] = $result === 0 ? "Delete Failed" : "Delete Successful";
|
|
|
|
$this->renderToolsPage('view_acl_whitelist', $this->viewData);
|
|
}
|
|
}
|