| 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/simbada_2018/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)
{
$this->CI->db->select('a.id, a.title, a.link');
$this->CI->db->from('menu a');
$this->CI->db->join('m_privilege b', 'b.id = a.id and b.group_id = '.$id_group);
$this->CI->db->where('a.parent_id', $id_parent);
$this->CI->db->where('a.id <>','1');
$this->CI->db->where('a.aktif', '1');
$this->CI->db->where('b.aksi > 0');
$this->CI->db->where('a.appid', $appid);
$this->CI->db->order_by('a.order_by');
$result = $this->CI->db->get();
$x = 0;
$menu = array();
if (!$result) return $menu;
$res_menu = $result->result();
foreach($res_menu as $hasil){
$menu[$x]['ID'] = $hasil->ID;
$menu[$x]['TITLE'] = $hasil->TITLE;
$menu[$x]['LINK'] = $hasil->LINK;
$menu[$x]['child'] = $this->get_menu($hasil->ID, $id_group, $appid); //ambil menu anak
$x++;
}
return $menu;
}
}