|
Server : Apache System : Linux server.mata-lashes.com 3.10.0-1160.90.1.el7.x86_64 #1 SMP Thu May 4 15:21:22 UTC 2023 x86_64 User : matalashes ( 1004) PHP Version : 8.1.29 Disable Function : NONE Directory : /home/matalashes/.trash/app.bak.12/Controllers/Store/ |
Upload File : |
<?php
namespace App\Controllers\Store;
use \App\Controllers\Ps\PS_Controller;
use CodeIgniter\HTTP\RequestInterface;
use CodeIgniter\HTTP\ResponseInterface;
use Psr\Log\LoggerInterface;
class Storeuser extends PS_Controller
{
private $id_column_name = 'ps_su_id';
public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger)
{
parent::initController($request, $response, $logger); // TODO: Change the autogenerated stub
parent::setPageTitleBreadcrumb(true, 'Store User', array('l1' => 'Store', 'l2' => 'Store User'));
parent::setURLActionTable($this->class);
parent::setContentView($this->class);
parent::setBaseContAndModel($this->class, 'PsStoreUser');
$this->validation_input = $this->validation->setRules([
"username" => [
'label' => 'Username',
'rules' => 'required|username_is_unique[username,PsStoreUser]',
'errors' => [
'username_is_unique' => 'Username is already used.'
]
]
]);
}
public function index()
{
parent::filterStoreLoad();
parent::indexLoad();
}
public function action($state = '', $id = '')
{
$id = $this->myLib->reveal_id($id);
if ($id == 'override404') {
return redirect()->route('override404');
}
$role = new \App\Models\PsStoreRole();
$this->view_data['_role'] = $role->where('ps_sr_id!=', 1)->where('deleted_at', null)->findAll();
if ($state == 'add') {
$this->view_data['state'] = 'add';
$this->view_data['button'] = 'Simpan';
if ($_POST) {
if (!$this->validation_input->withRequest($this->request)->run()) {
$this->view_data['error'] = true;
$this->view_data['message'] = 'Ada kesalahan dalam pengisian form!';
$this->view_data['error_list'] = $this->validation_input->getErrors();
} else {
unset($_POST['id']);
$_mdl = $this->myLib->getNewModel($this->models['base_model']);
$_datamodel = array();
foreach ($_POST as $index => $arr) {
if ($index == 'password') {
if ($this->request->getVar($index) != '') {
$pass = $_mdl::hash_password($this->request->getVar($index));
$_datamodel[$index] = $pass;
} else {
$pass = $_mdl::hash_password('password123');
$_datamodel[$index] = $pass;
}
} else {
$_datamodel[$index] = $this->request->getVar($index);
}
if ($_mdl->fieldExist('ps_store_id') && $this->session->has('ps_store_id')) {
$ps_store_id = $this->session->get('ps_store_id');
$_datamodel['ps_store_id'] = $ps_store_id;
}
}
try {
if (!$_mdl->save($_datamodel)) {
throw new \CodeIgniter\Database\Exceptions\DatabaseException();
} else {
$this->setMessage(false, true, $this->msgLib->scs_add());
}
} catch (Exception $e) {
$this->setMessage(true, false, $this->msgLib->err_add());
}
}
}
$this->render->viewAdmin($this->content_views['form_add_view'], $this);
} else if ($state == 'edit') {
$mdl = $this->myLib->getNewModel($this->models['base_model']);
$_data = $mdl->find($id);
$this->view_data['state'] = 'edit';
$this->view_data['button'] = 'Simpan';
$this->view_data['id'] = $id;
$this->view_data['_data'] = $_data;
if ($_POST) {
if (!$this->validation_input->withRequest($this->request)->run()) {
$this->view_data['error'] = true;
$this->view_data['message'] = 'Ada kesalahan dalam pengisian form!';
$this->view_data['error_list'] = $this->validation_input->getErrors();
} else {
unset($_POST['id']);
$_datamodel = array();
foreach ($_POST as $index => $arr) {
if ($index == 'password') {
if ($this->request->getVar($index) != '') {
$pass = $mdl::hash_password($this->request->getVar($index));
$_datamodel[$index] = $pass;
} else {
$pass = $mdl::hash_password('password123');
$_datamodel[$index] = $pass;
}
} else {
$_datamodel[$index] = $this->request->getVar($index);
}
}
try {
if (!$mdl->update($id, $_datamodel)) {
throw new \CodeIgniter\Database\Exceptions\DatabaseException();
} else {
$this->setMessage(false, true, $this->msgLib->scs_edit());
}
} catch (Exception $e) {
$this->setMessage(true, false, $this->msglib->err_edit());
}
}
}
$this->render->viewAdmin($this->content_views['form_edit_view'], $this);
} else if ($state == 'delete') {
parent::stateDelete($id);
} else if ($state == 'restore') {
parent::stateRestore($this->id_column_name, $id);
} else if ($state == 'deletepermanent') {
parent::stateDeletePermanent($this->id_column_name, $id);
}else if ($state == 'view') {
parent::stateView($id);
} else {
return redirect()->route('override404');
}
}
public function trash()
{
parent::filterStoreLoad();
parent::trashView();
}
}