176 lines
6.4 KiB
PHP
176 lines
6.4 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use Illuminate\Http\Request;
|
|
use App\Models\MenuModel;
|
|
use Response;
|
|
use Auth, Session;
|
|
use Yajra\DataTables\DataTables;
|
|
use Illuminate\Support\Facades\Hash;
|
|
use Request as Req;
|
|
use DB;
|
|
|
|
use Illuminate\Database\QueryException;
|
|
|
|
class MenuController extends Controller
|
|
{
|
|
|
|
public function admin_index($id)
|
|
{
|
|
|
|
if (Auth::guard('admin')->user()->role != 1) {
|
|
return view('errors.404');
|
|
}
|
|
|
|
if ($id == 'admin') {
|
|
$datas['title'] = 'Menu Management';
|
|
$datas['getMenu'] = \DB::select("SELECT * from menu order by seq");
|
|
}
|
|
|
|
$datas['table'] = route('data.menu',$id);
|
|
$datas['admin_menu_get'] = route('menu.menu_get',$id);
|
|
$datas['admin_menu_store'] = route('menu.store',$id);
|
|
|
|
|
|
return $this->bsGetView('content.menu_admin.index',$datas);
|
|
}
|
|
|
|
public function admin_data($id)
|
|
{
|
|
|
|
if (Auth::guard('admin')->user()->role != 1) {
|
|
return view('errors.404');
|
|
}
|
|
|
|
if ($id == 'admin') {
|
|
$data = \DB::select("SELECT *,id as list_menu FROM groups_admin order by id desc");
|
|
}else{
|
|
$data = \DB::select("SELECT user_type_name as description,user_type_uid as list_menu FROM reff_user_type order by user_type_uid desc");
|
|
}
|
|
|
|
return DataTables::of($data)
|
|
->addColumn('action', function ($data) {
|
|
|
|
return '
|
|
<div class="dropdown dropdown-inline">
|
|
<a href="javascript:;" class="btn btn-sm btn-clean btn-icon mr-2" data-toggle="dropdown">
|
|
<span class="svg-icon svg-icon-md">
|
|
<svg width="24px" height="24px" viewBox="0 0 24 24" version="1.1">
|
|
<g stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
|
|
<rect x="0" y="0" width="24" height="24"/>
|
|
<path d="M5,8.6862915 L5,5 L8.6862915,5 L11.5857864,2.10050506 L14.4852814,5 L19,5 L19,9.51471863 L21.4852814,12 L19,14.4852814 L19,19 L14.4852814,19 L11.5857864,21.8994949 L8.6862915,19 L5,19 L5,15.3137085 L1.6862915,12 L5,8.6862915 Z M12,15 C13.6568542,15 15,13.6568542 15,12 C15,10.3431458 13.6568542,9 12,9 C10.3431458,9 9,10.3431458 9,12 C9,13.6568542 10.3431458,15 12,15 Z" fill="#000000"/>
|
|
</g>
|
|
</svg>
|
|
</span>
|
|
</a>
|
|
<div class="dropdown-menu dropdown-menu-sm dropdown-menu-right">
|
|
<ul class="navi flex-column navi-hover py-2">
|
|
<li class="navi-header font-weight-bolder text-uppercase font-size-xs text-primary pb-2">
|
|
Choose an action:
|
|
</li>
|
|
<li class="navi-item">
|
|
<a onclick="modalMenu('.$data->list_menu.',`'.$data->description.'`)" class="navi-link">
|
|
<span class="navi-icon"><i class="la la-list-ul"></i></span>
|
|
<span class="navi-text">Akses Menu</span>
|
|
</a>
|
|
</li>
|
|
</ul>
|
|
</div>
|
|
</div>
|
|
';
|
|
})
|
|
->editColumn('list_menu',function($data) use($id) {
|
|
|
|
if ($id == 'admin') {
|
|
$getMenu = \DB::select("SELECT * from menu_privilege rrm
|
|
join menu rm on rm.menu_uid = rrm.menu_uid
|
|
where group_id = ? and has_children = 't' order by rm.menu_uid",[$data->list_menu]);
|
|
|
|
$menu_list = '';
|
|
foreach ($getMenu as $key => $v) {
|
|
$menu_list .= '<span class="label label-lg label-success label-inline mr-2 mb-2">'.$v->menu.'</span>';
|
|
}
|
|
|
|
}else{
|
|
|
|
$getMenu = \DB::select("SELECT * from privilege rrm
|
|
join menu_cms rm on rm.menu_cms_uid = rrm.menu_cms_uid
|
|
where user_type_uid = ? and has_children = 't' order by rm.menu_cms_uid",[$data->list_menu]);
|
|
|
|
$menu_list = '';
|
|
foreach ($getMenu as $key => $v) {
|
|
$menu_list .= '<span class="label label-lg label-success label-inline mr-2 mb-2">'.$v->menu_cms.'</span>';
|
|
}
|
|
}
|
|
|
|
return $menu_list;
|
|
|
|
})
|
|
|
|
->rawColumns(['list_menu','action'])
|
|
->make(true);
|
|
|
|
}
|
|
|
|
public function admin_menu_get(Request $request,$id)
|
|
{
|
|
if (Auth::guard('admin')->user()->role != 1) {
|
|
return view('errors.404');
|
|
}
|
|
|
|
if ($id == 'admin') {
|
|
$data = \DB::select("SELECT * FROM menu_privilege where group_id = ?",[$request->post('id')]);
|
|
}else{
|
|
$data = \DB::select("SELECT *,menu_cms_uid as menu_uid FROM privilege where user_type_uid = ?",[$request->post('id')]);
|
|
}
|
|
|
|
return json_encode($data);
|
|
}
|
|
|
|
public function admin_store(Request $request,$id)
|
|
{
|
|
|
|
if (Auth::guard('admin')->user()->role != 1) {
|
|
return view('errors.404');
|
|
}
|
|
|
|
if ($id == 'admin') {
|
|
DB::table('menu_privilege')->where('group_id', $request->post('get_id'))->delete();
|
|
$menu_id = $request->post('menu_id');
|
|
if ($menu_id) {
|
|
foreach ($menu_id as $key => $v) {
|
|
// $seq = DB::table('menu_privilege')->max('id');
|
|
|
|
DB::table('menu_privilege')->insert([
|
|
// 'id' => $seq+1,
|
|
'group_id' => $request->post('get_id'),
|
|
'menu_uid' => $v
|
|
|
|
]);
|
|
}
|
|
}
|
|
}else{
|
|
DB::table('privilege')->where('user_type_uid', $request->post('get_id'))->delete();
|
|
$menu_id = $request->post('menu_id');
|
|
if ($menu_id) {
|
|
foreach ($menu_id as $key => $v) {
|
|
// $seq = DB::table('menu_privilege')->max('id');
|
|
|
|
DB::table('privilege')->insert([
|
|
// 'id' => $seq+1,
|
|
'user_type_uid' => $request->post('get_id'),
|
|
'menu_cms_uid' => $v
|
|
]);
|
|
}
|
|
}
|
|
}
|
|
|
|
return response()->json([
|
|
'rc' => 0,
|
|
'rm' => "Berhasil"
|
|
]);
|
|
}
|
|
|
|
}
|