163 lines
4.5 KiB
PHP
Executable File
163 lines
4.5 KiB
PHP
Executable File
<?php
|
|
|
|
namespace App\Controllers;
|
|
|
|
use App\Controllers\BaseController;
|
|
|
|
use CodeIgniter\Validation\Exceptions\ValidationException;
|
|
|
|
use App\Models\Config_model;
|
|
|
|
/**
|
|
* Module : Configuration
|
|
* Configurationctrl Class to control all Configuration related operations.
|
|
* @author : Surendar
|
|
* @version : 1.1
|
|
* @since : 26 July 2017
|
|
* @example : Revised at 15th april 2024
|
|
*/
|
|
class Configurationctrl extends BaseController
|
|
{
|
|
protected $configmodel;
|
|
protected $session;
|
|
/**
|
|
* This is default constructor of the class
|
|
*/
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
|
|
helper('form'); //$this->load->library('form_validation');
|
|
$this->configmodel = new Config_model();
|
|
$this->session = session();
|
|
|
|
$this->isLoggedIn();
|
|
}
|
|
|
|
public function index()
|
|
{
|
|
|
|
$searchText = $this->request->getPost('searchText');
|
|
$data['searchText'] = $searchText;
|
|
|
|
|
|
$data['userRecords'] = $this->configmodel->Configlisting();
|
|
|
|
$this->global['pageTitle'] = 'Config Listing';
|
|
|
|
$this->loadViews("configlisting", $this->global, $data, NULL);
|
|
}
|
|
|
|
|
|
function addconfig()
|
|
{
|
|
$this->global['pageTitle'] = 'Add New Config';
|
|
$this->loadViews("addconfig", $this->global, [], NULL);
|
|
}
|
|
|
|
function saveconfig()
|
|
{
|
|
// echo "<pre>";
|
|
// dd($this->request->getPost());
|
|
$ConfigName = $this->request->getPost('configurationname');
|
|
$Rowcount = $this->request->getPost('txtRowCount');
|
|
$Comments = $this->request->getPost('Comments');
|
|
$chked = $this->request->getPost('IsActive');
|
|
|
|
$config = array('ConfigName' => $ConfigName, 'Comments' => $Comments);
|
|
$id = $this->configmodel->addconfigmaster($config);
|
|
|
|
if($id){
|
|
for ($i = 1; $i <= $Rowcount; $i++) {
|
|
$ConfigValue = $this->request->getPost('ConfigValue' . $i);
|
|
$configvalue = array('Config_ID' => $id, 'ConfigValue' => $ConfigValue);
|
|
$result = $this->configmodel->addconfigdetails($configvalue);
|
|
}
|
|
$this->session->setFlashdata('success', 'New Configuration Created successfully!');
|
|
}else{
|
|
$this->session->setFlashdata('error', 'Configuration Record Not Created!');
|
|
|
|
}
|
|
return redirect()->route('configlisting');
|
|
}
|
|
|
|
function editconfig($ConfigID = '')
|
|
{
|
|
$ConfigID = $this->request->getVar('ConfigID');
|
|
$data['master'] = $this->configmodel->GetConfigCenterMaster($ConfigID);
|
|
$data['child'] = $this->configmodel->GetConfigCenterDetails($ConfigID);
|
|
|
|
$this->global['pageTitle'] = 'Edit Config';
|
|
// echo "<pre>";
|
|
// print_r($data);die;
|
|
$this->loadViews("editconfig", $this->global, $data, NULL);
|
|
|
|
}
|
|
|
|
function updateconfig()
|
|
{
|
|
// dd($this->request->getPost());
|
|
$ConfigId = $this->request->getPost('ConfigId');
|
|
$ConfigName = $this->request->getPost('ConfigName');
|
|
$Comments = $this->request->getPost('Remarks');
|
|
$Rowcount = $this->request->getPost('txtRowCount');
|
|
|
|
$config = array('Config_ID' => $ConfigId, 'ConfigName' => $ConfigName, 'Comments' => $Comments);
|
|
$result = $this->configmodel->updateconfig($config, $ConfigId);
|
|
|
|
|
|
for ($i = 1; $i <= $Rowcount; $i++) {
|
|
$child_primary_key = $this->request->getPost('DbKey' . $i);
|
|
$config_value = $this->request->getPost('configVal' . $i);
|
|
$child_arr = array('ConfigValue' => $config_value);
|
|
if((int)$child_primary_key != 0){
|
|
$child_result = $this->configmodel->updateconfigdetails($child_arr, $child_primary_key);
|
|
}
|
|
if((int)$child_primary_key == 0){
|
|
$child_arr['Config_ID'] = $ConfigId;
|
|
$child_result = $this->configmodel->addconfigdetails($child_arr);
|
|
}
|
|
}
|
|
|
|
if ($result || $child_result) {
|
|
$this->session->setFlashdata('success', 'Configuration Updated successfully!');
|
|
} else {
|
|
$this->session->setFlashdata('error', 'Configuration Record Not Updated!');
|
|
}
|
|
return redirect()->route('configlisting');
|
|
}
|
|
|
|
|
|
function deleteConfig(){
|
|
|
|
$ConfigID = $this->request->getVar('ConfigID');
|
|
$result = $this->configmodel->updateconfig(['isActive' => 0],$ConfigID);
|
|
|
|
if ($result > 0) {
|
|
$this->session->setFlashdata('success', 'Configuration Deleted successfully!');
|
|
} else {
|
|
$this->session->setFlashdata('error', 'Configuration Record Not Deleted!');
|
|
}
|
|
|
|
return redirect()->route('configlisting');
|
|
|
|
}
|
|
|
|
function reActivateConfig(){
|
|
|
|
$ConfigID = $this->request->getVar('ConfigID');
|
|
$result = $this->configmodel->updateconfig(['isActive' => 1],$ConfigID);
|
|
|
|
if ($result > 0) {
|
|
$this->session->setFlashdata('success', 'Configuration Re Activated successfully!');
|
|
} else {
|
|
$this->session->setFlashdata('error', 'Configuration Record Not Re Activated!');
|
|
}
|
|
|
|
return redirect()->route('configlisting');
|
|
|
|
}
|
|
|
|
|
|
}
|