first commit

This commit is contained in:
2024-01-08 09:33:24 +07:00
commit ed1d4a2b08
2369 changed files with 875560 additions and 0 deletions
@@ -0,0 +1,64 @@
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class CompanyProfile extends CI_Controller
{
var $js_page = 'profile/company_profile';
public function __construct()
{
parent::__construct();
$this->load->model('companyProfile_model');
$this->load->library('form_validation');
$this->load->helper('url');
}
public function index()
{
$data['title'] = 'Company Profile';
$data['breadcrumbs'][] = ['label' => 'Company', 'active' => 'active'];
$data['main_content'] = 'company_profile/index';
$data['data'] = $this->companyProfile_model->company_profile();
$data['js_page'] = $this->js_page;
$this->load->view('layouts/main_layout', $data);
}
public function load_setting()
{
$data['data'] = $this->companyProfile_model->company_profile();
$this->load->view('company_profile/_form', $data);
}
public function update()
{
$success = false;
$message = '';
if ($this->input->post()) {
$post = $this->input->post();
$model = $this->companyProfile_model;
$this->db->trans_begin();
$company = $model->save();
if ($company['success'] == true) {
if ($this->db->trans_status() === FALSE) {
$this->db->trans_rollback();
$success = false;
$message = "Data Gagal Disimpan!";
$this->session->set_flashdata('failed', $message);
} else {
$this->db->trans_commit();
$success = true;
$message = "Data Berhasil Ditambahkan!";
$this->session->set_flashdata('success', $message);
}
} else {
$this->db->trans_rollback();
$success = false;
$message = "Data Gagal Disimpan!";
$this->session->set_flashdata('failed', $message);
}
}
redirect(site_url('companyProfile'));
}
}
+205
View File
@@ -0,0 +1,205 @@
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class GroupMenu extends CI_Controller
{
var $js_page = 'menu/group_menu';
public function __construct()
{
parent::__construct();
$this->load->model('authItemChild_model');
$this->load->model('menu_model');
$this->load->library('form_validation');
$this->load->helper('url');
}
public function index($error = NULL)
{
$data['error'] = $error;
$data['title'] = 'Group Menu';
$data['breadcrumbs'][] = ['label' => 'Group Menu', 'active' => 'active'];
$data['main_content'] = 'group-menu/index';
$data['data'] = $this->authItemChild_model->dataMenu();
$this->load->view('layouts/main_layout', $data);
}
public function create($error = NULL)
{
$success = false;
$message = '';
$menu = '';
$arr_menu = '';
if ($this->input->post()) {
$post = $this->input->post();
$this->db->trans_begin();
$model_menu = $this->menu_model;
$model_groupmenu = $this->authItemChild_model;
$model_menu = $model_menu->save();
$model_groupmenu = $model_groupmenu->save($model_menu);
if ($this->db->trans_status() === FALSE) {
$this->db->trans_rollback();
$success = false;
$message = "Data Gagal Disimpan!";
$this->session->set_flashdata('failed', $message);
redirect(site_url('groupMenu/index'));
} else {
$this->db->trans_commit();
$success = true;
$message = "Data Berhasil Ditambahkan!";
$this->session->set_flashdata('success', $message);
redirect(site_url('groupMenu/index'));
}
}
$data['error'] = $error;
$data['title'] = 'Create Group Menu';
$data['main_content'] = 'group-menu/_form';
$data['js_page'] = $this->js_page;
$data['breadcrumbs'][] = ['label' => 'Group Menu', 'url' => 'index'];
$data['breadcrumbs'][] = ['label' => 'Create', 'active' => 'active'];
$data['isNewRecord'] = true;
$data['data'] = $menu;
$data['arr_menu'] = $arr_menu;
$data['data_menu'] = $this->menu_model->getParent();
$data['cruda'] = $this->menu_model->cruda();
$this->load->view('layouts/main_layout', $data);
}
public function getChecked()
{
$post = $this->input->post();
$idArr = array();
if (isset($post['key']) && isset($post['ket'])) {
$key_post = explode('[', $_POST['key']);
$slug_post = $key_post[0];
$act_post = substr($key_post[1], 0, 1);
$this->db->where('slug', $slug_post);
$menu = $this->db->get('menu')->row();
if (isset($menu)) {
$idArr[] = $menu->slug . "[" . $act_post . "]";
// Jika di CHECKED Kecuali R ==> Maka R juga iKut
if (($act_post == 'C' || $act_post == 'U' || $act_post == 'D' || $act_post == 'A') && $_POST['ket'] == 1) {
$idArr[] = $menu->slug . "[R]";
} // Jika di UN-CHECK R ==> Maka yang lain Ikut Un-check
elseif ($act_post == 'R' && $_POST['ket'] == 0) {
foreach ($this->menu_model->cruda() as $ind => $val) {
$idArr[] = $menu->slug . "[" . $ind . "]";
}
}
// Get Child menu ==> Jika parent checked, maka child-nya semua ikut checked
foreach ($this->menu_model->cruda() as $ind => $val) {
$this->db->where('parent_id', $menu->id);
$menu_child = $this->db->get('menu')->result();
foreach ($menu_child as $child) {
if ($_POST['ket'] == 0 && $act_post == 'R') { // Jika yang di UNCHECK adalah Parent (R)
$idArr[] = $child->slug . "[" . $ind . "]";
}
$this->db->where('parent_id', $child->id);
$menu_child_2 = $this->db->get('menu')->result();
foreach ($menu_child_2 as $child2) {
if ($_POST['ket'] == 0 && $act_post == 'R') { // Jika yang di UNCHECK adalah Parent (R)
$idArr[] = $child2->slug . "[" . $ind . "]";
}
}
}
}
// Ket = 1 adalah checked
if ($_POST['ket'] == 1) {
// Jika childnya checked, maka parent atas2-nya juga di checked
$this->db->where('id', $menu->parent_id);
$parent_child = $this->db->get('menu')->row();
if (isset($parent_child)) {
$idArr[] = $parent_child->slug . "[R]";
$this->db->where('id', $parent_child->parent_id);
$parent = $this->db->get('menu')->row();
if (isset($parent)) {
$idArr[] = $parent->slug . "[R]";
}
}
}
}
echo json_encode($idArr);
}
}
public function update($id = null)
{
$id = decrypt_url($id);
$success = false;
$message = '';
$arr_group = [];
$data = [];
if ($this->input->post()) {
$post = $this->input->post();
$this->db->trans_begin();
$menu = $this->db->query("select * from menu where id = '" . $post['id'] . "'")->row();
if (isset($menu)) {
$delete_auth = $this->authItemChild_model->delete_auth($menu->slug);
if ($delete_auth['success']) {
$success = true;
if (isset($post['MenuRoleForm']['menus'])) {
foreach ($post['MenuRoleForm']['menus'] as $ind => $item) {
$this->authItemChild_model->save($menu->slug);
if ($this->db->trans_status() === FALSE) {
$this->db->trans_rollback();
$success = false;
$message = "Data Gagal Disimpan!";
$this->session->set_flashdata('failed', $message);
redirect(site_url('groupMenu/index'));
} else {
$this->db->trans_commit();
$success = true;
$message = "Data Berhasil Ditambahkan!";
$this->session->set_flashdata('success', $message);
redirect(site_url('groupMenu/index'));
}
}
} else {
$this->db->trans_rollback();
$this->session->set_flashdata('failed', 'Group Menu Tidak Memiliki Role!');
}
} else {
$this->db->trans_rollback();
$success = false;
$this->session->set_flashdata('failed', $delete_auth['message']);
}
} else {
$this->session->set_flashdata('failed', 'Menu Tidak Ditemukan!');
}
} else {
$this->db->from('menu');
$this->db->where('id', $id);
$menu = $this->db->get()->row();
if (isset($menu)) {
$_menu = $this->db->query("select * from auth_item_child where parent = CONCAT('GROUPMENU-','" . $menu->slug . "') and SUBSTRING(child,1,10)<>'GROUPMENU-'")->result_array();
foreach ($_menu as $ind => $item) {
$arr_menu[$item['child']] = $item['child'];
}
}
}
$data['title'] = 'Update Group Menu';
$data['main_content'] = 'group-menu/_form';
$data['js_page'] = $this->js_page;
$data['breadcrumbs'][] = ['label' => 'Group Menu', 'url' => 'index'];
$data['breadcrumbs'][] = ['label' => 'Update', 'active' => 'active'];
$data['isNewRecord'] = false;
$data['data'] = $menu;
$data['arr_menu'] = $arr_menu;
$data['data_menu'] = $this->menu_model->getParent();
$data['cruda'] = $this->menu_model->cruda();
$this->load->view('layouts/main_layout', $data);
}
}
+137
View File
@@ -0,0 +1,137 @@
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Menu extends CI_Controller
{
var $js_page = 'menu/menu';
public function __construct()
{
parent::__construct();
$this->load->model('menu_model');
$this->load->library('form_validation');
$this->load->helper('url');
}
public function index($error = NULL)
{
$data['error'] = $error;
$data['title'] = 'Menu';
$data['breadcrumbs'][] = ['label' => 'Menu', 'active' => 'active'];
$data['main_content'] = 'menu/index';
$data['data'] = $this->menu_model->getAllIndex();
$this->load->view('layouts/main_layout', $data);
}
public function create($error = NULL)
{
$success = false;
$message = '';
if ($this->input->post()) {
$model = $this->menu_model;
$this->db->trans_begin();
$model->save();
if ($this->db->trans_status() === FALSE) {
$this->db->trans_rollback();
$success = false;
$message = "Data Gagal Disimpan!";
$this->session->set_flashdata('failed', $message);
redirect(site_url('menu/index'));
} else {
$this->db->trans_commit();
$success = true;
$message = "Data Berhasil Ditambahkan!";
$this->session->set_flashdata('success', $message);
redirect(site_url('menu/index'));
}
}
$data['error'] = $error;
$data['title'] = 'Create Menu';
$data['main_content'] = 'menu/_form';
$data['js_page'] = $this->js_page;
$data['breadcrumbs'][] = ['label' => 'Menu', 'url' => 'index'];
$data['breadcrumbs'][] = ['label' => 'Create', 'active' => 'active'];
$data['parent'] = $this->menu_model->getParent();
$data['isNewRecord'] = true;
$this->load->view('layouts/main_layout', $data);
}
public function update($id = null)
{
$id = decrypt_url($id);
$success = false;
$message = '';
if ($this->input->post()) {
$model = $this->menu_model;
$this->db->trans_begin();
$model->save();
if ($this->db->trans_status() === FALSE) {
$this->db->trans_rollback();
$success = false;
$message = "Data Gagal Diupdate!";
$this->session->set_flashdata('failed', $message);
redirect(site_url('menu/index'));
} else {
$this->db->trans_commit();
$success = true;
$message = "Data Berhasil Diupdate!";
$this->session->set_flashdata('success', $message);
redirect(site_url('menu/index'));
}
}
$model = $this->menu_model->getById($id);
$data['title'] = 'Update Menu';
$data['main_content'] = 'menu/_form';
$data['js_page'] = $this->js_page;
$data['breadcrumbs'][] = ['label' => 'Menu', 'url' => 'index'];
$data['breadcrumbs'][] = ['label' => 'Update', 'active' => 'active'];
$data['parent'] = $this->menu_model->getParent();
$data['isNewRecord'] = false;
$data['data'] = $model;
$data['parent'] = $this->menu_model->find_parent($model->parent_id, $model->level);
$this->load->view('layouts/main_layout', $data);
}
public function delete($id)
{
$id = decrypt_url($id);
$model = $this->menu_model;
if ($model->delete($id)) {
$this->session->set_flashdata('success', 'Data Berhasil Dihapus!');
redirect(site_url('menu/index'));
}
}
function getParent()
{
$return = '';
if (isset($_POST['key'])) {
$this->db->select('id, name, type, level');
$this->db->from('menu');
$this->db->where('type', $_POST['key']);
$this->db->where('level', 1);
$return = $this->db->get()->result();
}
echo json_encode($return);
}
function getChild()
{
$return = '';
if (isset($_POST['key'])) {
$this->db->select('id, name, type, level');
$this->db->from('menu');
$this->db->where('parent_id', $_POST['key']);
$this->db->where('level', 2);
$return = $this->db->get()->result();
}
echo json_encode($return);
}
}
+171
View File
@@ -0,0 +1,171 @@
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Profile extends CI_Controller
{
var $js_page = 'profile/profile';
public function __construct()
{
parent::__construct();
$this->load->model('profile_model');
$this->load->model('user_model');
$this->load->model('typeuser_model');
$this->load->library('form_validation');
$this->load->helper('url');
}
public function index($error = NULL)
{
$data['error'] = $error;
$data['title'] = 'Profile';
$data['breadcrumbs'][] = ['label' => 'Profile', 'active' => 'active'];
$data['main_content'] = 'profile/index';
$data['data'] = $this->profile_model->getAllData();
$this->load->view('layouts/main_layout', $data);
}
public function create($error = NULL)
{
$success = false;
$message = '';
if ($this->input->post()) {
$post = $this->input->post();
$model = $this->profile_model;
$this->db->trans_begin();
$profile = $model->save();
if ($profile['success'] = true) {
if ($this->db->trans_status() === FALSE) {
$this->db->trans_rollback();
$success = false;
$message = "Data Gagal Disimpan!";
$this->session->set_flashdata('failed', $message);
} else {
$this->db->trans_commit();
$success = true;
$message = "Data Berhasil Ditambahkan!";
$this->session->set_flashdata('success', $message);
redirect(site_url('profile/view/' . encrypt_url($profile['user_id'])));
}
} else {
$this->db->trans_rollback();
$success = false;
$message = "Data Gagal Disimpan!";
$this->session->set_flashdata('failed', $message);
}
redirect(site_url('profile/index'));
}
$data['error'] = $error;
$data['title'] = 'Create Profile';
$data['main_content'] = 'profile/_form';
$data['js_page'] = $this->js_page;
$data['breadcrumbs'][] = ['label' => 'Profile', 'url' => 'index'];
$data['breadcrumbs'][] = ['label' => 'Create', 'active' => 'active'];
$data['isNewRecord'] = true;
$data['typeuser'] = $this->typeuser_model->getType();
$this->load->view('layouts/main_layout', $data);
}
public function view($id = NULL)
{
$id = decrypt_url($id);
$data['title'] = 'Profile';
$data['breadcrumbs'][] = ['label' => 'View', 'active' => 'active'];
$data['main_content'] = 'profile/view';
$data['js_page'] = $this->js_page;
$data['data'] = $this->profile_model->getById($id);
$this->load->view('layouts/main_layout', $data);
}
public function update($id = NULL)
{
$id = decrypt_url($id);
if ($this->input->post()) {
$post = $this->input->post();
$model = $this->profile_model;
$this->db->trans_begin();
$profile = $model->save();
if ($profile['success'] = true) {
if ($this->db->trans_status() === FALSE) {
$this->db->trans_rollback();
$success = false;
$message = "Data Gagal Disimpan!";
$this->session->set_flashdata('failed', $message);
redirect(site_url('profile/index'));
} else {
$this->db->trans_commit();
$success = true;
$message = "Data Berhasil Ditambahkan!";
$this->session->set_flashdata('success', $message);
redirect(site_url('profile/view/' . encrypt_url($profile['user_id'])));
}
} else {
$this->db->trans_rollback();
$success = false;
$message = "Data Gagal Disimpan!";
$this->session->set_flashdata('failed', $message);
redirect(site_url('profile/index'));
}
}
$data['title'] = 'Profile';
$data['breadcrumbs'][] = ['label' => 'View', 'active' => 'active'];
$data['main_content'] = 'profile/_form';
$data['isNewRecord'] = false;
$data['data'] = $this->profile_model->getById($id);
$data['typeuser'] = $this->typeuser_model->getType();
$this->load->view('layouts/main_layout', $data);
}
public function blocked($id)
{
$id = decrypt_url($id);
$this->db->trans_begin();
$model = $this->user_model;
$model->blocked($id);
if ($this->db->trans_status() === FALSE) {
$this->db->trans_rollback();
$success = false;
$message = "Blocked Gagal!";
$this->session->set_flashdata('failed', $message);
} else {
$this->db->trans_commit();
$success = true;
$message = "Blocked Success!";
$this->session->set_flashdata('success', $message);
}
redirect(site_url('profile/index'));
}
function load_modal()
{
$id = decrypt_url($_POST['key']);
$data['js_page'] = $this->js_page;
$data['user_id'] = $id;
$this->load->view('profile/_modal_reset_password', $data);
}
public function reset_password()
{
$this->db->trans_begin();
$this->user_model->reset($_POST['user_id'], $_POST['password']);
if ($this->db->trans_status() === FALSE) {
$this->db->trans_rollback();
$success = false;
$message = "Reset Gagal!";
} else {
$this->db->trans_commit();
$success = true;
$message = "Reset Success!";
}
$return = ['success' => $success, 'message' => $message];
echo json_encode($return);
}
}
+118
View File
@@ -0,0 +1,118 @@
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Role extends CI_Controller
{
var $js_page = 'menu/group_menu';
public function __construct()
{
parent::__construct();
$this->load->model('authItemChild_model');
$this->load->model('authAssignment_model');
$this->load->model('menu_model');
$this->load->model('user_model');
$this->load->library('form_validation');
$this->load->helper('url');
}
public function index()
{
$data['title'] = 'Role Access';
$data['breadcrumbs'][] = ['label' => 'Role Access', 'active' => 'active'];
$data['main_content'] = 'role/index';
$data['user'] = $this->user_model->getAllUser();
$data['model'] = $this->authAssignment_model->dataRole();
$this->load->view('layouts/main_layout', $data);
}
public function update($id = null)
{
$id = decrypt_url($id);
$success = false;
$message = '';
$arr_group = [];
$arr_menu = [];
if ($this->input->post()) {
$post = $this->input->post();
$this->db->trans_begin();
$delete_auth = $this->authAssignment_model->delete_auth($post['user_id']);
if ($delete_auth['success'] == true) {
$success = true;
if (isset($post['MenuRoleForm']['groupmenus'])) {
foreach ($post['MenuRoleForm']['groupmenus'] as $group) {
$assign_groupmenu = $this->authAssignment_model->save($post['user_id'], 'GROUPMENU-' . $group);
if ($assign_groupmenu['success'] == true) {
$success = true;
} else {
$success = false;
$message = $assign_groupmenu['message'];
}
}
}
if (isset($post['MenuRoleForm']['menus'])) {
foreach ($post['MenuRoleForm']['menus'] as $ind => $menu) {
$assign_menu = $this->authAssignment_model->save($post['user_id'], $menu);
if ($assign_menu['success'] == true) {
$success = true;
} else {
$success = false;
$message = $assign_menu['message'];
}
}
}
} else {
$success = false;
$message = $delete_auth['message'];
}
if ($success) {
if ($this->db->trans_status() === FALSE) {
$this->db->trans_rollback();
$success = false;
$message = "Role Access User Gagal!";
$this->session->set_flashdata('failed', $message);
} else {
$this->db->trans_commit();
$success = true;
$message = "Role Access User Berhasil!";
$this->session->set_flashdata('success', $message);
}
} else {
$this->session->set_flashdata('failed', $message);
}
redirect(site_url('role/index'));
} else {
$_group = $this->db->query("select * from auth_assignment where user_id = '" . $id . "' and SUBSTRING(item_name,1,10)='GROUPMENU-'")->result_array();
foreach ($_group as $ind => $item) {
$arr_group[str_replace('GROUPMENU-','',$item['item_name'])] = $item['item_name'];
}
$_menu = $this->db->query("select * from auth_assignment where user_id = '" . $id . "' and SUBSTRING(item_name,1,10)<>'GROUPMENU-'")->result_array();
foreach ($_menu as $ind => $item) {
$arr_menu[$item['item_name']] = $item['item_name'];
}
}
$data['title'] = 'Role Access';
$data['main_content'] = 'role/_form';
$data['js_page'] = $this->js_page;
$data['breadcrumbs'][] = ['label' => 'Role', 'url' => 'index'];
$data['breadcrumbs'][] = ['label' => 'Create', 'active' => 'active'];
$data['isNewRecord'] = false;
$data['user_id'] = $id;
$data['arr_menu'] = $arr_menu;
$data['arr_group'] = $arr_group;
$data['model'] = $this->user_model->getById($id);
$data['data_menu'] = $this->menu_model->getParent();
$data['group_menu'] = $this->menu_model->getGroupMenu();
$data['cruda'] = $this->menu_model->cruda();
$this->load->view('layouts/main_layout', $data);
}
}
+112
View File
@@ -0,0 +1,112 @@
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Site extends CI_Controller
{
var $js_page = 'site/site';
public function __construct()
{
parent::__construct();
$this->load->database();
$this->load->model('user_model');
$this->load->model('authAssignment_model');
}
public function login($error = NULL)
{
if ($this->session->userdata('is_login') == true) {
redirect('site/dashboard');
}
if ($this->input->post()) {
$this->form_validation->set_rules('username', 'Username', 'trim|required|min_length[5]|max_length[50]');
$this->form_validation->set_rules('password', 'Password', 'trim|required|min_length[5]|max_length[22]');
$is_check = $this->check_account();
if ($this->form_validation->run() && $is_check === true) {
$this->user_model->last_login($this->session->userdata('id'), $this->session->userdata('__ci_last_regenerate'));
redirect('site/dashboard');
}
}
$data['error'] = $error;
$data['title'] = 'Login';
$data['js_page'] = $this->js_page;
$data['breadcrumbs'][] = '';
$this->load->view('site/login', $data);
}
public function dashboard($error = NULL)
{
$data['error'] = $error;
$data['title'] = 'Dashboard';
$data['breadcrumbs'][] = ['label' => 'Dashboard', 'active' => 'active'];
$data['main_content'] = 'site/dashboard';
$this->load->view('layouts/main_layout', $data);
}
public function check_account()
{
$username = $this->input->post('username');
$password = $this->input->post('password');
$query = $this->user_model->check_account($username, $password, false);
if ($query === 1) {
$this->session->set_flashdata('alert', '<div class="info-box bg-gradient-danger">
<span class="info-box-icon"><i class="fas fa-exclamation-circle"></i></span>
<div class="info-box-content">
<span class="info-box-text">FAILED</span>
<span class="progress-description">Username is not Registered</span>
</div>
</div>');
} elseif ($query === 2) {
$this->session->set_flashdata('alert', '<div class="info-box bg-gradient-danger">
<span class="info-box-icon"><i class="fas fa-exclamation-circle"></i></span>
<div class="info-box-content">
<span class="info-box-text">FAILED</span>
<span class="progress-description">Your Account is not Active!, Please Contact Admin</span>
</div>
</div>');
} elseif ($query === 3) {
$this->session->set_flashdata('alert', '<div class="info-box bg-gradient-danger">
<span class="info-box-icon"><i class="fas fa-exclamation-circle"></i></span>
<div class="info-box-content">
<span class="info-box-text">FAILED</span>
<span class="progress-description">Your Password is Wrong!</span>
</div>
</div>');
} else {
$auth = $this->authAssignment_model->access($query->user_id);
$userdata = array(
'is_login' => true,
'is_developer' => ($query->typeuser_id == 1) ? true : false,
'id' => $query->user_id,
'typeuser_id' => $query->typeuser_id,
'name' => $query->name,
'foto' => $query->foto,
'typeuser' => $query->typeuser,
'username' => $query->username,
'switch' => false,
'you_can' => $auth,
'user_initial' => ''
);
$this->session->set_userdata($userdata);
return true;
}
}
public function logout()
{
$id = $this->session->userdata('id');
$user_data = $this->session->userdata();
foreach ($user_data as $key => $value) {
if ($key != '__ci_last_regenerate' && $key != '__ci_vars')
$this->session->unset_userdata($key);
}
redirect('site/login');
}
}
+110
View File
@@ -0,0 +1,110 @@
<?php
defined('BASEPATH') or exit('No direct script access allowed');
class Typeuser extends CI_Controller
{
var $js_page = 'typeuser/typeuser';
public function __construct()
{
parent::__construct();
$this->load->model('typeuser_model');
$this->load->library('form_validation');
$this->load->helper('url');
}
public function index()
{
$data['title'] = 'Typeuser';
$data['breadcrumbs'][] = ['label' => 'Typeuser', 'active' => 'active'];
$data['main_content'] = 'typeuser/index';
$data['data'] = $this->typeuser_model->getAll();
$this->load->view('layouts/main_layout', $data);
}
public function create()
{
$success = false;
$message = '';
if ($this->input->post()) {
//print_r($_POST);die();
if ($this->input->post()) {
$model = $this->typeuser_model;
$this->db->trans_begin();
$model->add();
if ($this->db->trans_status() === FALSE) {
$this->db->trans_rollback();
$success = false;
$message = "Data Gagal Disimpan!";
$this->session->set_flashdata('failed', $message);
redirect(site_url('typeuser/index'));
} else {
$this->db->trans_commit();
$success = true;
$message = "Data Berhasil Ditambahkan!";
$this->session->set_flashdata('success', $message);
redirect(site_url('typeuser/index'));
}
}
}
$data['title'] = 'Create Typeuser';
$data['main_content'] = 'typeuser/_form';
$data['breadcrumbs'][] = ['label' => 'Typeuser', 'url' => 'index'];
$data['breadcrumbs'][] = ['label' => 'Create', 'active' => 'active'];
$data['isNewRecord'] = true;
$this->load->view('layouts/main_layout', $data);
}
public function update($id = null)
{
$id = decrypt_url($id);
$success = false;
$message = '';
if ($this->input->post()) {
$model = $this->typeuser_model;
$this->db->trans_begin();
$model->add();
if ($this->db->trans_status() === FALSE) {
$this->db->trans_rollback();
$success = false;
$message = "Data Gagal Diupdate!";
$this->session->set_flashdata('failed', $message);
redirect(site_url('typeuser/index'));
} else {
$this->db->trans_commit();
$success = true;
$message = "Data Berhasil Diupdate!";
$this->session->set_flashdata('success', $message);
redirect(site_url('typeuser/index'));
}
}
$model = $this->typeuser_model->getById($id);
$data['title'] = 'Update Type User';
$data['main_content'] = 'typeuser/_form';
$data['js_page'] = $this->js_page;
$data['breadcrumbs'][] = ['label' => 'typeuser', 'url' => 'index'];
$data['breadcrumbs'][] = ['label' => 'Update', 'active' => 'active'];
$data['isNewRecord'] = false;
$data['data'] = $model;
$this->load->view('layouts/main_layout', $data);
}
public function delete($id)
{
$id = decrypt_url($id);
$model = $this->typeuser_model;
if ($model->delete($id)) {
$this->session->set_flashdata('success', 'Data Berhasil Dihapus!');
redirect(site_url('typeuser/index'));
}
}
}
+137
View File
@@ -0,0 +1,137 @@
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class User extends CI_Controller
{
var $js_page = 'user/user';
public function __construct()
{
parent::__construct();
$this->load->model('user_model');
$this->load->model('authAssignment_model');
$this->load->library('form_validation');
$this->load->helper('url');
}
public function index()
{
$data['title'] = 'List User';
$data['breadcrumbs'][] = ['label' => 'List User', 'active' => 'active'];
$data['main_content'] = 'user/index';
$data['js_page'] = $this->js_page;
$data['model'] = $this->user_model->getAllUser();
$this->load->view('layouts/main_layout', $data);
}
public function switch_user($id = NULL)
{
$id = $this->input->post('id');
$initialId = $this->session->userdata('id');
if ($id == $initialId) {
$this->session->set_flashdata('failed', "Can't swicth, same user !");
$array_respon = [
'status' => FALSE,
];
echo json_encode($array_respon);
// redirect('user/index');
} else {
$user = $this->user_model->getById($id);
$user_initial = $this->user_model->getById($initialId);
if (!empty($user)) {
if ($user->status == 1) {
$query = $this->user_model->check_account($user->username, $user->password_hash, true);
if (!empty($query)) {
$user_initial = [
'id' => $user_initial->user_id,
'username' => $user_initial->username,
'password' => $user_initial->password_hash,
'name' => $user_initial->name,
'typeuser_id' => $user_initial->typeuser_id,
];
$auth = $this->authAssignment_model->access($query->user_id);
$userdata = array(
'is_login' => true,
'is_developer' => ($query->typeuser_id == 1) ? true : false,
'id' => $query->user_id,
'typeuser_id' => $query->typeuser_id,
'name' => $query->name,
'typeuser' => $query->typeuser,
'username' => $query->username,
'switch' => true,
'you_can' => $auth,
'user_initial' => $user_initial
);
$this->session->set_userdata($userdata);
$this->user_model->last_login($this->session->userdata('id'), $this->session->userdata('__ci_last_regenerate'));
$array_respon = [
'status' => TRUE,
];
echo json_encode($array_respon);
// redirect('site/dashboard');
}
} else {
$this->session->set_flashdata('failed', 'Switch Failed, user "' . $user->name . '" is already blocked');
$array_respon = [
'status' => FALSE,
];
echo json_encode($array_respon);
// redirect('user/index');
}
} else {
$this->session->set_flashdata('failed', "User not found!");
$array_respon = [
'status' => FALSE,
];
echo json_encode($array_respon);
// redirect('user/index');
}
}
}
public function switch_user_back($id = NULL)
{
$id = $this->input->post('id');
$initialId = $this->session->userdata('id');
$user = $this->user_model->getById($id);
if (!empty($user)) {
$query = $this->user_model->check_account($user->username, $user->password_hash, true);
if (!empty($query)) {
$auth = $this->authAssignment_model->access($query->user_id);
$userdata = array(
'is_login' => true,
'is_developer' => ($query->typeuser_id == 1) ? true : false,
'id' => $query->user_id,
'typeuser_id' => $query->typeuser_id,
'name' => $query->name,
'typeuser' => $query->typeuser,
'username' => $query->username,
'switch' => false,
'you_can' => $auth,
'user_initial' => ''
);
$this->session->set_userdata($userdata);
$this->user_model->last_login($this->session->userdata('id'), $this->session->userdata('__ci_last_regenerate'));
$array_respon = [
'status' => TRUE,
];
echo json_encode($array_respon);
// redirect('site/dashboard');
}
} else {
$this->session->set_flashdata('failed', "User not found!");
$array_respon = [
'status' => FALSE,
];
echo json_encode($array_respon);
// redirect('user/index');
}
}
}
+25
View File
@@ -0,0 +1,25 @@
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Welcome extends CI_Controller {
/**
* Index Page for this controller.
*
* Maps to the following URL
* http://example.com/index.php/welcome
* - or -
* http://example.com/index.php/welcome/index
* - or -
* Since this controller is set as the default controller in
* config/routes.php, it's displayed at http://example.com/
*
* So any other public methods not prefixed with an underscore will
* map to /index.php/welcome/<method_name>
* @see https://codeigniter.com/userguide3/general/urls.html
*/
public function index()
{
$this->load->view('welcome_message');
}
}
+11
View File
@@ -0,0 +1,11 @@
<!DOCTYPE html>
<html>
<head>
<title>403 Forbidden</title>
</head>
<body>
<p>Directory access is forbidden.</p>
</body>
</html>