| Server IP : 127.0.0.1 / Your IP : 192.168.99.1 Web Server : Apache/2.4.35 (Win64) OpenSSL/1.1.1b mod_fcgid/2.3.9 System : Windows NT WIN-JEJMB9EN0L0 10.0 build 14393 (Windows Server 2016) AMD64 User : Administrator ( 0) PHP Version : 7.4.33 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : OFF | Perl : OFF | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : /wamp/www/SIPBOS_2020/application/libraries/ |
Upload File : |
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/*
* Class build menu for backend and frontend
*/
class menu_builder
{
var $CI = null;
function __construct()
{
$this->CI = & get_instance();
}
function build_backend($menu)
{
$html = '';
$id = isset($menu['ID']) ? $menu['ID'] : '';
$aktif = isset($menu['AKTIF']) ? $menu['AKTIF'] : '';
$judul = isset($menu['TITLE']) ? $menu['TITLE'] : '';
$link = isset($menu['LINK']) ? $menu['LINK'] : '';
$aksi = isset($menu['AKSI']) ? $menu['AKSI'] : '';
$data = '';
$data .= isset($menu['ID']) ? 'data-id="'.$id.'" ' : '';
$data .= isset($menu['TITLE']) ? 'data-title="'.$judul.'" ' : '';
$data .= isset($menu['LINK']) ? 'data-link="'.$link.'" ' : '';
$data .= isset($menu['AKTIF']) ? 'data-aktif="'.$aktif.'" ' : '';
$data .= isset($menu['AKSI']) ? 'data-aksi="'.$aksi.'" ' : '';
$html .= '<li class="dd-item dd3-item" '.$data.' >';
$html .= '<div class="dd-handle dd3-handle">Drag</div>';
$html .= '<div class="dd3-content">';
$html .= '<div class="control-group pull-left menu-isi" style="margin-top:4px">'. $judul.'</div>';
$html .= '<div class="control-group pull-right menu-hover">';
$html .= '</div></div>';
if (count($menu['child']) > 0)
{
$html .= '<ol class="dd-list">';
foreach($menu['child'] as $x => $sub_menu)
{
$html .= $this->build_backend($sub_menu);
}
$html .= '</ol>';
}
$html .= '</li>';
return $html;
}
function build_backend_menu($arr_menu)
{
$menu_html = '<div class="dd" style="margin-top:10px">';
$menu_html .= '<ol class="dd-list">';
foreach($arr_menu as $x => $menu)
{
$menu_html .= $this->build_backend($menu);
}
$menu_html .= '</ol>';
$menu_html .= '</div>';
return $menu_html;
}
function build_frontend($menu)
{
$html = '';
$judul = isset($menu['TITLE']) ? $menu['TITLE'] : '';
$link = isset($menu['LINK']) ? $menu['LINK'] : '';
if ($judul == '===')
{
$html .= '<li class="divider"></li>';
}
else {
$dropdownClass = count($menu['child']) > 0 ? 'class="dropdown" ' : '';
$dropdownToggle = count($menu['child']) > 0 ? 'class="dropdown-toggle" data-toggle="dropdown" ' : '';
$html .= '<li '. $dropdownClass.'>';
$html .= count($menu['child']) > 0 ? '<a '.$dropdownToggle.' href="'.base_url().$link.'" ><i class="icon-th icon-large"></i>'.$judul.'<b class="caret"></b></a>' : '<a href="'.base_url().$link.'">'.$judul.'</a>';
if (count($menu['child']) > 0)
{
$html .= '<ul class="dropdown-menu">';
foreach($menu['child'] as $x => $sub_menu)
{
$html .= $this->build_frontend($sub_menu);
}
$html .= '</ul>';
}
$html .= '</li>';
}
return $html;
}
function build_frontend_menu($group, $appid)
{
$arr_menu = $this->get_menu(0, $group, $appid);
$menu_html = '<ul class="nav nav-pills">';
foreach($arr_menu as $x => $menu)
{
$menu_html .= $this->build_frontend($menu);
}
$menu_html .= '</ul>';
return $menu_html;
}
function get_menu($id_parent = 0, $id_group = 0, $appid)
{
$query_menu = "
with recursive menux as (
select 0 lvl, a.id, a.parent_id, a.title, a.link, a.order_by
from menu a
join m_privilege b on b.id = a.id and b.group_id = ".$id_group."
where a.parent_id = 0
and a.id <> 1
and a.aktif = 1
and b.aksi > 0
and a.appid = '".$appid."'
union all
select x.lvl + 1, a.id, a.parent_id, a.title, a.link, a.order_by
from menu a
join menux x on x.id = a.parent_id
join m_privilege b on b.id = a.id and b.group_id = ".$id_group."
where a.id <> 1
and a.aktif = 1
and b.aksi > 0
and a.appid = '".$appid."'
)
select *
from menux a
order by a.lvl, a.parent_id, a.order_by
";
$result = $this->CI->db->query( $query_menu );
$x = 0;
$menu = array();
if (!$result) return $menu;
$res_menu = $result->result();
foreach($res_menu as $hasil){
if ($hasil->LVL === 0) {
$menu[$hasil->ID]['ID'] = $hasil->ID;
$menu[$hasil->ID]['TITLE'] = $hasil->TITLE;
$menu[$hasil->ID]['LINK'] = $hasil->LINK;
$menu[$hasil->ID]['child'] = array();
}
else if ($hasil->LVL === 1){
$menu[$hasil->PARENT_ID]['child'][$hasil->ID]['ID'] = $hasil->ID;
$menu[$hasil->PARENT_ID]['child'][$hasil->ID]['TITLE'] = $hasil->TITLE;
$menu[$hasil->PARENT_ID]['child'][$hasil->ID]['LINK'] = $hasil->LINK;
$menu[$hasil->PARENT_ID]['child'][$hasil->ID]['child'] = array();
}
}
return $menu;
}
}