Ejemplo n.º 1
0
function menu_apply_restrictions(&$menu_list_src, &$menu_list_updated)
{
    for ($idx = 0; $idx < count($menu_list_src); $idx++) {
        $srcEntry = $menu_list_src[$idx];
        $includeEntry = true;
        // If the entry has an ACL Requirements(currently only support loose), then test
        if (isset($srcEntry->acl_req)) {
            if (is_array($srcEntry->acl_req[0])) {
                $noneSet = true;
                for ($aclIdx = 0; $aclIdx < count($srcEntry->acl_req); $aclIdx++) {
                    $curSettingOne = $srcEntry->acl_req[$aclIdx][0];
                    $curSettingTwo = $srcEntry->acl_req[$aclIdx][1];
                    // ! at the start of the $curSettingOne means test the negation
                    if (substr($curSettingOne, 0, 1) === '!') {
                        $curSettingOne = substr($curSettingOne, 1);
                        // If the acl_check fails, then show it
                        if (!acl_check($curSettingOne, $curSettingTwo)) {
                            $noneSet = false;
                        }
                    } else {
                        // If the acl_check passes, then show it
                        if (acl_check($curSettingOne, $curSettingTwo)) {
                            $noneSet = false;
                        }
                    }
                }
                if ($noneSet) {
                    $includeEntry = false;
                }
            } else {
                if (!acl_check($srcEntry->acl_req[0], $srcEntry->acl_req[1])) {
                    $includeEntry = false;
                }
            }
        }
        // If the entry has loose global setting requirements, check
        // Note that global_req is a loose check (if more than 1 global, only 1 needs to pass to show the menu item)
        if (isset($srcEntry->global_req)) {
            if (is_array($srcEntry->global_req)) {
                $noneSet = true;
                for ($globalIdx = 0; $globalIdx < count($srcEntry->global_req); $globalIdx++) {
                    $curSetting = $srcEntry->global_req[$globalIdx];
                    // ! at the start of the string means test the negation
                    if (substr($curSetting, 0, 1) === '!') {
                        $curSetting = substr($curSetting, 1);
                        // If the global isn't set at all, or if it is false, then show it
                        if (!isset($GLOBALS[$curSetting]) || !$GLOBALS[$curSetting]) {
                            $noneSet = false;
                        }
                    } else {
                        // If the setting is both set and true, then show it
                        if (isset($GLOBALS[$curSetting]) && $GLOBALS[$curSetting]) {
                            $noneSet = false;
                        }
                    }
                }
                if ($noneSet) {
                    $includeEntry = false;
                }
            } else {
                // ! at the start of the string means test the negation
                if (substr($srcEntry->global_req, 0, 1) === '!') {
                    $globalSetting = substr($srcEntry->global_req, 1);
                    // If the setting is both set and true, then skip this entry
                    if (isset($GLOBALS[$globalSetting]) && $GLOBALS[$globalSetting]) {
                        $includeEntry = false;
                    }
                } else {
                    // If the global isn't set at all, or if it is false then skip the entry
                    if (!isset($GLOBALS[$srcEntry->global_req]) || !$GLOBALS[$srcEntry->global_req]) {
                        $includeEntry = false;
                    }
                }
            }
        }
        // If the entry has strict global setting requirements, check
        // Note that global_req_strict is a strict check (if more than 1 global, they all need to pass to show the menu item)
        if (isset($srcEntry->global_req_strict)) {
            if (is_array($srcEntry->global_req_strict)) {
                $allSet = true;
                for ($globalIdx = 0; $globalIdx < count($srcEntry->global_req_strict); $globalIdx++) {
                    $curSetting = $srcEntry->global_req_strict[$globalIdx];
                    // ! at the start of the string means test the negation
                    if (substr($curSetting, 0, 1) === '!') {
                        $curSetting = substr($curSetting, 1);
                        // If the setting is both set and true, then do not show it
                        if (isset($GLOBALS[$curSetting]) && $GLOBALS[$curSetting]) {
                            $allSet = false;
                        }
                    } else {
                        // If the global isn't set at all, or if it is false, then do not show it
                        if (!isset($GLOBALS[$curSetting]) || !$GLOBALS[$curSetting]) {
                            $allSet = false;
                        }
                    }
                }
                if (!$allSet) {
                    $includeEntry = false;
                }
            } else {
                // ! at the start of the string means test the negation
                if (substr($srcEntry->global_req_strict, 0, 1) === '!') {
                    $globalSetting = substr($srcEntry->global_req_strict, 1);
                    // If the setting is both set and true, then skip this entry
                    if (isset($GLOBALS[$globalSetting]) && $GLOBALS[$globalSetting]) {
                        $includeEntry = false;
                    }
                } else {
                    // If the global isn't set at all, or if it is false then skip the entry
                    if (!isset($GLOBALS[$srcEntry->global_req_strict]) || !$GLOBALS[$srcEntry->global_req_strict]) {
                        $includeEntry = false;
                    }
                }
            }
        }
        if (isset($srcEntry->children)) {
            // Iterate through and check the child elements
            $checked_children = array();
            menu_apply_restrictions($srcEntry->children, $checked_children);
            $srcEntry->children = $checked_children;
        }
        if (!isset($srcEntry->url)) {
            // If this is a header only entry, and there are no child elements, then don't include it in the list.
            if (count($srcEntry->children) === 0) {
                $includeEntry = false;
            }
        }
        if ($includeEntry) {
            array_push($menu_list_updated, $srcEntry);
        }
    }
}
Ejemplo n.º 2
0
 * along with this program. If not, see <http://opensource.org/licenses/gpl-license.php>;.
 *
 * @package OpenEMR
 * @author  Kevin Yeh <*****@*****.**>
 * @link    http://www.open-emr.org
 */
require_once "menu_data.php";
require_once "menu_updates.php";
require_once "menu_db.php";
$menu_parsed = load_menu("default");
if (count($menu_parsed) == 0) {
    $menu_parsed = json_decode($menu_json);
}
menu_update_entries($menu_parsed);
$menu_restrictions = array();
menu_apply_restrictions($menu_parsed, $menu_restrictions);
?>
<script type="text/javascript">
    
    function menu_entry(object)
    {
        var self=this;
        self.label=ko.observable(object.label);

        self.header=false;
        if('url' in object )
        {
            self.url=ko.observable(object.url);
            self.header=false;
        }
        else