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
+134
View File
@@ -0,0 +1,134 @@
<?php defined('BASEPATH') OR exit ('No direct script access allowed!');
class AuthAssignment_model extends CI_Model
{
private $_table = "auth_assignment";
public $item_name, $user_id, $created_at;
public function delete_auth($user_id)
{
$success = true;
$message = 'Berhasil Hapus Role Lama!';
$delete = $this->db->delete('auth_assignment', array('user_id' => $user_id));
if (!$delete) {
$success = false;
$message = 'Gagal Hapus Role Lama!';
}
return ['success' => $success, 'message' => $message];
}
public function save($user_id, $menu)
{
$success = true;
$message = 'Auth Assignment Berhasil Disimpan!';
$date = new DateTime();
$this->item_name = $menu;
$this->user_id = $user_id;
$this->created_at = $date->getTimestamp();
$save = $this->db->insert($this->_table, $this);
if (!$save) {
$success = false;
$message = 'Auth Assignment Gagal Disimpan!';
}
return ['success' => $success, 'message' => $message];
}
public function dataRole()
{
$data = [];
$sql = $this->db->query("select a.user_id, a.name, b.username, c.value as typeuser, f.name as name_menu, f.slug, e.item_name, f.id, a.typeuser_id
from profile a
left join user b on b.id = a.user_id
left join typeuser c on c.id = a.typeuser_id
left join auth_assignment e on e.user_id = a.user_id
left join menu f on concat('GROUPMENU-',f.slug)= e.item_name or SUBSTRING_INDEX(e.item_name, '[', 1) = f.slug");
$menus = $sql->result_array();
if (count($menus) > 0) {
foreach ($menus as $ind => $item) {
$menuact = $this->menuAct($item['user_id'], $item['slug']);
$data[$item['user_id']]['user_id'] = $item['user_id'];
$data[$item['user_id']]['name'] = $item['name'];
$data[$item['user_id']]['typeuser'] = $item['typeuser'];
$data[$item['user_id']]['typeuser_id'] = $item['typeuser_id'];
$data[$item['user_id']]['username'] = $item['username'];
$data[$item['user_id']]['details'] = $menuact;
}
}
return $data;
}
public function menuAct($user_id, $slug)
{
$sql_group_menus = $this->db->query("select slug, name from menu where level = 1 and type = 3");
$groupMenus = $sql_group_menus->result_array();
$ind_group = [];
foreach ($groupMenus as $menu) {
$ind_group[$menu['slug']] = $menu['name'];
}
$menu = ['group' => [], 'menu' => []];
$sql_group = $this->db->query("select item_name from auth_assignment where user_id ='" . $user_id . "' and SUBSTRING(item_name,1,10)= 'GROUPMENU-'");
$_group = $sql_group->result_array();
$groupmenus = [];
$groupmenus_role = [];
foreach ($_group as $item) {
if (isset($ind_group[str_replace('GROUPMENU-', '', $item['item_name'])])) {
$nm = $ind_group[str_replace('GROUPMENU-', '', $item['item_name'])];
if (isset($nm)) {
$groupmenus[] = $nm;
$groupmenus_role[$item['item_name']] = $item['item_name'];
}
}
}
$sql_menu = $this->db->query("select item_name from auth_assignment where user_id ='" . $user_id . "' and SUBSTRING(item_name,1,10)<>'GROUPMENU-'");
$_menu = $sql_menu->result_array();
$menus = [];
$menus_role = [];
foreach ($_menu as $role) {
$key = explode('[', $role['item_name']);
$slug = $key[0];
if (isset($key[1])) {
$act = substr($key[1], 0, 1);
$this->db->where('slug', $slug);
$mn = $this->db->get('menu')->row();
if (isset($mn)) {
$menus[$mn->name][] = $act;
$menus_role[$role['item_name']] = $role['item_name'];
}
}
}
return ['group' => $groupmenus, 'menu' => $menus, 'menu_role' => $menus_role, 'group_role' => $groupmenus_role];
}
public function access($user_id)
{
$access = $this->menuAct($user_id, '');
$arr_access = '';
$menus = $access['menu_role'];
$groups = $access['group_role'];
$group = [];
if (!empty($groups)) {
foreach ($groups as $item) {
$sql_group = $this->db->query("select child from auth_item_child where parent ='" . $item . "'");
$_group = $sql_group->result_array();
if (!empty($_group)) {
foreach ($_group as $gr) {
$group[$gr['child']] = $gr['child'];
}
}
}
}
$arr_access = array_merge($group, $menus);
return $arr_access;
}
}
+101
View File
@@ -0,0 +1,101 @@
<?php defined('BASEPATH') OR exit ('No direct script access allowed!');
class AuthItemChild_model extends CI_Model
{
private $_table = "auth_item_child";
private $_table_menu = "menu";
public $parent, $child;
public function getAll()
{
$sql = $this->db->query("select a.id, a.name, a.slug, b.parent, b.child from menu a
inner join auth_item_child b on b.parent = concat('GROUPMENU-', a.slug)
where a.type = 3");
$menus = $sql->result_array();
return $menus;
}
public function save($slug)
{
$post = $this->input->post();
$role_menu = $post['MenuRoleForm']['menus'];
if (isset($post)) {
$this->db->where('slug', $slug);
$menu = $this->db->get('menu')->row();
if (isset($menu)) {
$this->db->where('name', 'GROUPMENU-' . $slug);
$auth_item = $this->db->get('auth_item')->row();
if (isset($auth_item)) {
foreach ($role_menu as $ind => $val) {
$this->parent = $auth_item->name;
$this->child = $val;
$this->db->insert($this->_table, $this);
}
}
}
}
}
public function dataMenu()
{
$data = [];
$sql = $this->db->query("select a.id, a.name, a.slug, b.name as name_auth from menu a
inner join auth_item b on b.name = concat('GROUPMENU-',a.slug)");
$menus = $sql->result_array();
if (count($menus) > 0) {
foreach ($menus as $ind => $item) {
$menuact = $this->menuAct($item['name_auth'], $item['slug']);
$data[$item['id']]['id'] = $item['id'];
$data[$item['id']]['name'] = $item['name'];
$data[$item['id']]['details'] = $menuact;
}
}
return $data;
}
public function menuAct($name, $slug)
{
$sql_group_menus = $this->db->query("select name from menu where level = 1 and type = 3");
$groupMenus = $sql_group_menus->result_array();
$menu = ['group' => [], 'menu' => []];
$sql_group = $this->db->query("select child from auth_item_child where parent ='" . $name . "' and SUBSTRING(child,1,10)= 'GROUPMENU-'");
$_group = $sql_group->result_array();
foreach ($_group as $role) {
$nm = isset($groupMenus[str_replace('GROUPMENU-', '', $role['child'])]) ? $groupMenus[str_replace('GROUPMENU-', '', $role['child'])] : '';
if (!empty($nm)) {
$menu['group'][] = $nm;
}
}
$sql_menu = $this->db->query("select child from auth_item_child where parent ='" . $name . "' and SUBSTRING(child,1,10)<>'GROUPMENU-'");
$_menu = $sql_menu->result_array();
foreach ($_menu as $role) {
$key = explode('[', $role['child']);
$slug = $key[0];
if (isset($key[1])) {
$act = substr($key[1], 0, 1);
$this->db->where('slug', $slug);
$mn = $this->db->get('menu')->row();
if (isset($mn)) {
$menu['menu'][$mn->name][] = $act;
}
}
}
return $menu;
}
public function delete_auth($parent)
{
$success = true;
$message = 'Berhasil Hapus Role Lama!';
$delete = $this->db->delete('auth_item_child', array('parent' => 'GROUPMENU-' . $parent));
if (!$delete) {
$success = false;
$message = 'Gagal Hapus Role Lama!';
}
return ['success' => $success, 'message' => $message];
}
}
+18
View File
@@ -0,0 +1,18 @@
<?php defined('BASEPATH') OR exit ('No direct script access allowed!');
class Authitem_model extends CI_Model
{
private $_table = "auth_item";
public $name, $type, $created_at, $updated_at;
public function create_role($slug)
{
$date = new DateTime();
$this->name = $slug;
$this->type = 1;
$this->created_at = $date->getTimestamp();
$this->updated_at = $date->getTimestamp();
$this->db->insert($this->_table, $this);
}
}
@@ -0,0 +1,61 @@
<?php defined('BASEPATH') OR exit ('No direct script access allowed!');
class CompanyProfile_model extends CI_Model
{
private $_table = "company_profile";
public $name, $alias, $description, $company, $address, $website, $year, $logo, $version, $id;
public function __construct()
{
parent::__construct();
$this->load->library('upload');
$this->load->library('helper');
}
public function company_profile()
{
$data = $this->db->query("select * from company_profile")->row();
return $data;
}
public function save()
{
$success = true;
$message = 'Update Company Profile Berhasil!';
$post = $this->input->post();
$data = $this->company_profile();
if (!empty($_FILES['logo']['name'])) {
if ($data->logo != $_FILES['logo']['name']) {
$helper_upload = $this->helper->upload_image($_FILES['logo'], 'company_profile');
$this->upload->initialize($helper_upload);
if ($this->upload->do_upload('logo')) {
$foto = $this->upload->data();
$this->logo = $foto['file_name'];
}
} else {
$this->logo = $data->logo;
}
} else {
$this->logo = $data->logo;
}
$this->name = $post['name'];
$this->alias = $post['alias'];
$this->description = $post['description'];
$this->company = $post['company'];
$this->address = $post['address'];
$this->website = $post['website'];
$this->year = $post['year'];
$this->version = $post['version'];
$this->id = $post['id'];
$save = $this->db->update($this->_table, $this, array('id' => $post['id']));
if (!$save) {
$success = false;
$message = 'Update Company Profile Gagal!';
}
return ['success' => $success, 'message' => $message];
}
}
+169
View File
@@ -0,0 +1,169 @@
<?php defined('BASEPATH') OR exit ('No direct script access allowed!');
class Menu_model extends CI_Model
{
private $_table = "menu";
public $id, $name, $slug, $level, $link, $icon, $parent_id, $urutan, $type;
public function __construct()
{
parent::__construct();
$this->load->model(array('authitem_model'));
}
public function getAll()
{
$this->db->order_by('id', 'asc');
return $this->db->get($this->_table)->result();
}
public function save()
{
$post = $this->input->post();
if ($post['isNewRecord'] == 'true') {
$this->name = isset($post['name']) ? $post['name'] : '';
$this->icon = isset($post['icon']) ? $post['icon'] : '';
$this->urutan = isset($post['urutan']) ? $post['urutan'] : '';
$this->type = isset($post['position']) ? $post['position'] : '';
$this->parent_id = null;
$this->level = 1;
$this->link = isset($post['link']) ? $post['link'] : '';
if (isset($post['level_1'])) {
if (!empty($post['level_1'])) {
$this->parent_id = $post['level_1'];
$this->level = 2;
if (!empty($post['level_2'])) {
$this->parent_id = $post['level_2'];
$this->level = 3;
}
}
}
$this->slug = $this->generate_url_slug($post['name'], 'menu');
if (isset($post['link'])) {
if (empty($post['link'])) {
$this->link = '#';
}
}
$data = $this->db->insert($this->_table, $this);
if ($data == true) {
if ($post['position'] == 3) {
$auth = $this->authitem_model->create_role('GROUPMENU-' . $this->slug);
} else {
foreach ($this->cruda() as $ind => $val) {
$auth = $this->authitem_model->create_role($this->slug . '[' . $ind . ']');
}
}
}
} else {
$this->id = $post['id'];
$this->name = $post['name'];
$this->icon = $post['icon'];
$this->urutan = $post['urutan'];
$this->type = $post['position'];
$this->parent_id = null;
$this->level = 1;
$this->link = $post['link'];
if (!empty($post['level_1'])) {
$this->parent_id = $post['level_1'];
$this->level = 2;
if (!empty($post['level_2'])) {
$this->parent_id = $post['level_2'];
$this->level = 3;
}
}
$this->slug = $post['name'];
if (empty($post['link'])) {
$this->link = '#';
}
$this->db->update($this->_table, $this, array('id' => $post['id']));
}
return $this->slug;
}
public function delete($id)
{
return $this->db->delete($this->_table, array('id' => $id));
}
public function getAllIndex()
{
$this->db->select('a.id, a.name, a.type, a.level, a.urutan, a.link, a.icon, a.parent_id, b.name as parent');
$this->db->from('menu a');
$this->db->join('menu b', 'a.parent_id = b.id', 'left');
$this->db->order_by('a.id', 'asc');
$query = $this->db->get()->result();
return $query;
}
public function getParent()
{
$this->db->select('id, name, slug');
$this->db->from('menu');
$this->db->where('level', 1);
$this->db->where_not_in('type', 3);
$this->db->order_by('name', 'asc');
$query = $this->db->get()->result();
return $query;
}
public function getByID($id)
{
return $this->db->get_where($this->_table, ["id" => $id])->row();
}
function generate_url_slug($string, $table, $field = 'slug', $key = NULL, $value = NULL)
{
$t =& get_instance();
$slug = url_title($string);
$slug = strtolower($slug);
$i = 0;
$params = array();
$params[$field] = $slug;
if ($key) $params["$key !="] = $value;
while ($t->db->where($params)->get($table)->num_rows()) {
if (!preg_match('/-{1}[0-9]+$/', $slug))
$slug .= '-' . ++$i;
else
$slug = preg_replace('/[0-9]+$/', ++$i, $slug);
$params [$field] = $slug;
}
return $slug;
}
function find_parent($parent, $level)
{
$arr_parent = [
1 => '',
2 => ''
];
if ($level == 2) {
$arr_parent = [
1 => $parent,
2 => '',
];
} else if ($level == 3) {
$parent_2 = $this->db->get_where($this->_table, ["id" => $parent])->row();
$arr_parent = [
1 => $parent_2->parent_id,
2 => $parent,
];
}
return $arr_parent;
}
function cruda()
{
return ['C' => 'CREATE', 'R' => 'READ', 'U' => 'UPDATE', 'D' => 'DELETE', 'A' => 'APPROVAL'];
}
public function getGroupMenu()
{
$data = $this->db->query("select * from menu where level = 1 and type = 3")->result_array();
return $data;
}
}
+104
View File
@@ -0,0 +1,104 @@
<?php defined('BASEPATH') OR exit ('No direct script access allowed!');
class Profile_model extends CI_Model
{
private $_table = "profile";
public $user_id, $name, $email, $phone, $typeuser_id, $foto;
public function __construct()
{
parent::__construct();
$this->load->model(array('user_model'));
$this->load->library(array('upload'));
$this->load->library(array('helper'));
}
public function save()
{
$success = true;
$message = 'Create Profile Berhasil!';
$post = $this->input->post();
if ($post['isNewRecord'] == 'true') {
$user = $this->user_model->save($post['User'], $post['isNewRecord'], $post['user_id'], $post['email']);
} else {
$user['success'] = true;
}
if ($user['success'] == true) {
$this->name = $post['name'];
$this->email = $post['email'];
$this->phone = $post['phone'];
$this->typeuser_id = $post['typeuser_id'];
if ($post['isNewRecord'] == 'true') {
if (!empty($_FILES['foto']['name'])) {
$helper_upload = $this->helper->upload_image($_FILES['foto'], 'profile');
$this->upload->initialize($helper_upload);
if ($this->upload->do_upload('foto')) {
$foto = $this->upload->data();
$this->foto = $foto['file_name'];
}
}
$this->user_id = $user['user_id'];
$save = $this->db->insert($this->_table, $this);
if (!$save) {
$success = false;
$message = 'Create Profile Gagal!';
}
} else {
$data = $this->getById($post['user_id']);
if (!empty($_FILES['foto']['name'])) {
if ($data->foto != $_FILES['foto']['name']) {
$helper_upload = $this->helper->upload_image($_FILES['foto'], 'profile');
$this->upload->initialize($helper_upload);
if ($this->upload->do_upload('foto')) {
$foto = $this->upload->data();
$this->foto = $foto['file_name'];
}
} else {
$this->foto = $data->foto;
}
} else {
$this->foto = $data->foto;
}
$this->user_id = $post['user_id'];
$save = $this->db->update($this->_table, $this, array('user_id' => $post['user_id']));
if (!$save) {
$success = false;
$message = 'Update Profile Gagal!';
}
}
} else {
$success = false;
$message = $user['message'];
}
return ['success' => $success, 'message' => $message, 'user_id' => $this->user_id];
}
public function getAllData()
{
$sql = $this->db->query("
select a.user_id, a.name, a.email, a.phone, b.username, b.status, c.value as typeuser, a.typeuser_id from profile a
inner join user b on b.id = a.user_id
inner join typeuser c on c.id = a.typeuser_id");
$data = $sql->result_array();
return $data;
}
public function getById($id)
{
$sql = $this->db->query("
select a.user_id, a.name, a.email, a.phone, b.username, b.status, c.value as typeuser,
b.status, a.typeuser_id, b.password_hash as password, a.foto from profile a
inner join user b on b.id = a.user_id
inner join typeuser c on c.id = a.typeuser_id where a.user_id = '" . $id . "'");
$data = $sql->row();
return $data;
}
}
+62
View File
@@ -0,0 +1,62 @@
<?php
defined('BASEPATH') or exit('No direct script access allowed!');
class Typeuser_model extends CI_Model
{
private $_table = "typeuser";
public $id, $code, $value, $description;
public function __construct()
{
parent::__construct();
$this->load->model(array('authitem_model'));
}
public function getAll()
{
$this->db->order_by('id', 'asc');
return $this->db->get($this->_table)->result();
}
public function getById($id)
{
$data = $this->db->query("select * from typeuser where id ='" . $id . "'")->row();
return $data;
}
public function add()
{
$post = $this->input->post();
if ($post['isNewRecord'] == 'true') {
$this->code = isset($post['code']) ? $post['code'] : '';
$this->value = isset($post['value']) ? $post['value'] : '';
$this->description = isset($post['description']) ? $post['description'] : '';
$data = $this->db->insert($this->_table, $this);
} else {
$this->id = $post['id'];
$this->code = $post['code'];
$this->value = $post['value'];
$this->description = $post['description'];
// print_r($this);die();
$this->db->update($this->_table, $this, array('id' => $post['id']));
}
}
public function delete($id)
{
return $this->db->delete($this->_table, array('id' => $id));
}
public function getType()
{
$this->db->select('id, code, value, description');
$this->db->from('typeuser');
$this->db->order_by('value', 'asc');
$query = $this->db->get()->result();
return $query;
}
}
+107
View File
@@ -0,0 +1,107 @@
<?php defined('BASEPATH') OR exit ('No direct script access allowed!');
class User_model extends CI_Model
{
private $_table = "user";
public $id, $username, $email, $password_hash, $auth_key, $confirmed_at, $unconfirmed_email, $blocked_at, $created_at, $updated_at, $flags, $last_login_at, $status;
public function save($post, $isNewRecord, $user_id, $email)
{
$success = false;
$message = 'Gagal Create User!';
$date = new DateTime();
$this->username = $post['username'];
$this->email = $email;
$this->created_at = $date->getTimestamp();
$this->status = 1;
if ($isNewRecord == 'true') {
$this->updated_at = $date->getTimestamp();
$this->password_hash = password_hash($post['password'], PASSWORD_DEFAULT);
$this->db->insert($this->_table, $this);
$user_id = $this->db->insert_id();
$success = true;
$message = 'Berhasil Create User!';
} else {
$this->id = $user_id;
$this->updated_at = $date->getTimestamp();
$this->db->update($this->_table, $this, array('id' => $user_id));
$success = true;
$message = 'Berhasil Update User!';
}
return ['success' => $success, 'message' => $message, 'user_id' => $user_id];
}
public function blocked($id)
{
$date = new DateTime();
$update_status = array(
'status' => 0,
'blocked_at' => $date->getTimestamp()
);
$this->db->where('id', $id);
$this->db->update($this->_table, $update_status);
}
public function reset($id, $password)
{
$date = new DateTime();
$reset_password = array(
'password_hash' => password_hash($password, PASSWORD_DEFAULT),
'updated_at' => $date->getTimestamp()
);
$this->db->where('id', $id);
$this->db->update($this->_table, $reset_password);
}
public function getAllUser()
{
$data = $this->db->query("select a.id as user_id, a.username, b.name, c.value as typeuser, b.typeuser_id, b.email from user a
inner join profile b on b.user_id = a.id
left join typeuser c on c.id = b.typeuser_id")->result_array();
return $data;
}
public function getById($id)
{
$data = $this->db->query("select a.id as user_id, a.username, b.name, c.value as typeuser, b.typeuser_id, a.status, a.password_hash
from user a
inner join profile b on b.user_id = a.id
left join typeuser c on c.id = b.typeuser_id
where a.id = '" . $id . "' ")->row();
return $data;
}
public function check_account($username, $password, $switch)
{
$user = $this->db->query("select a.id as user_id, a.username, b.name, c.value as typeuser, b.typeuser_id, a.status, a.password_hash, b.foto from user a
inner join profile b on b.user_id = a.id
left join typeuser c on c.id = b.typeuser_id
where a.username = '" . $username . "' ")->row();
if (!$switch) {
if (!$user) {
return 1;
}
if ($user->status == 0) {
return 2;
}
if (!hash_verified($password, $user->password_hash)) {
return 3;
}
}
return $user;
}
public function last_login($id, $time)
{
$update_status = array(
'last_login_at' => $time,
);
$this->db->where('id', $id);
$this->db->update($this->_table, $update_status);
}
}
+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>