<?php

if (!defined('BASEPATH')) {
    exit('No direct script access allowed');
}

if (!function_exists('get_help_list')) {

    function get_help_list($files, $key = false, $current = '', $count = 0)
    {
        $html = '<ul>';
        foreach ($files as $k => $v) {
            $count++;
            if (!empty($v['acl_resource']) && !empty($v['acl_action']) && !get_instance()->rt_user->isAllowed($v['acl_resource'], $v['acl_action'])) {
                continue;
            } else {
                $page_key = ($key ? $key . '/' : '') . $k;
                $html .= '<li>' . (!empty($v['pages']) ? '<i id="' . $k . $count . '" class="fa fa-angle-down"></i>' : '&nbsp;&nbsp;&nbsp;')
                        . '<a href="' . base_url(get_instance()->uri->uri_string()) . '?page=' . $page_key . '">' . ($k == $current ? '<span class="active">' : '') . $v['label'] . ($k == $current ? '</span>' : '') . '</a>';
                if (!empty($v['pages']) && is_array($v['pages'])) {
                    $html .= get_help_list($v['pages'], $page_key, $current, $count);
                }
                $html .= '</li>';
            }
        }
        $html .= '</ul>';

        return $html;
    }

}
