function nvweb_permissions_rows($website_id, $object_type, $object_id)
{
    global $DB;
    $naviforms = new naviforms();
    $object = new stdClass();
    if ($object_type == 'user') {
        $object = new user();
        $object->load($object_id);
    } else {
        if ($object_type == 'profile') {
            $object = new profile();
            $object->load($object_id);
        }
    }
    $permissions_definitions = permission::get_definitions();
    $permissions_values = permission::get_values($object_type, $object, $permissions_definitions, $website_id);
    $permissions_definitions = array_merge($permissions_definitions['system'], $permissions_definitions['functions'], $permissions_definitions['settings'], $permissions_definitions['extensions']);
    $out = array();
    $iRow = 0;
    for ($i = 0; $i < count($permissions_definitions); $i++) {
        $control = '';
        $type = '';
        $scope = t(470, 'System');
        $field_name = "wid" . $website_id . "." . $permissions_definitions[$i]['name'];
        if ($permissions_definitions[$i]['scope'] == 'functions') {
            $scope = t(240, 'Functions');
        } else {
            if ($permissions_definitions[$i]['scope'] == 'settings') {
                $scope = t(459, 'Settings');
            } else {
                if ($permissions_definitions[$i]['scope'] == 'extensions') {
                    $scope = t(327, 'Extensions');
                }
            }
        }
        switch ($permissions_definitions[$i]['type']) {
            case 'boolean':
                $type = t(206, 'Boolean');
                $control = $naviforms->buttonset($field_name, array('true' => '<span class="ui-icon ui-icon-circle-check"></span>', 'false' => '<span class="ui-icon ui-icon-circle-close"></span>'), $permissions_values[$permissions_definitions[$i]['name']], "navigate_permission_change_boolean(this);");
                break;
            case 'integer':
                $type = t(468, 'Integer');
                $control = $naviforms->textfield($field_name, $permissions_values[$permissions_definitions[$i]['name']], '99%', 'navigate_permission_change_text(this);');
                break;
            case 'option':
            case 'moption':
                $options = $permissions_definitions[$i]['options'];
                switch ($options) {
                    case "websites":
                        $options = array();
                        $DB->query("SELECT id, name FROM nv_websites");
                        $websites = $DB->result();
                        foreach ($websites as $ws) {
                            $options[$ws->id] = $ws->name;
                        }
                        break;
                    case "extensions":
                        $options = array();
                        $extensions = extension::list_installed(null, true);
                        foreach ($extensions as $ext) {
                            $options[$ext['code']] = $ext['title'];
                        }
                        break;
                    case "structure":
                        $options = array();
                        $categories = $permissions_values[$permissions_definitions[$i]['name']];
                        if (!is_array($categories)) {
                            $categories = array();
                        }
                        $categories = array_filter($categories);
                        $control = '<button data-permission-name="' . $permissions_definitions[$i]['name'] . '" 
                                                    data-action="structure" data-value="' . json_encode($categories) . '" 
                                                    title="' . count($categories) . '"><i class="fa fa-sitemap fa-fw"></i> ' . t(611, "Choose") . '</button>';
                        break;
                    default:
                }
                $type = t(200, 'Options');
                if (empty($control)) {
                    $control = $naviforms->selectfield($field_name, array_keys($options), array_values($options), $permissions_values[$permissions_definitions[$i]['name']], 'navigate_permission_change_option(this);', $permissions_definitions[$i]['type'] == 'moption');
                }
                break;
            case 'color':
                $type = t(441, 'Color');
                $control = $naviforms->colorfield($field_name, $permissions_values[$permissions_definitions[$i]['name']], array(), 'navigate_permission_change_text');
                break;
            case 'string':
            default:
                $type = t(469, 'String');
                $control = $naviforms->textfield($field_name, $permissions_values[$permissions_definitions[$i]['name']], '99%', 'navigate_permission_change_text(this);');
                break;
        }
        // search filters
        if (!empty($_REQUEST['filters'])) {
            $include = navitable::jqgridCheck(array('name' => $permissions_definitions[$i]['name'], 'scope' => $scope, 'type' => $type, 'value' => $permissions_values[$permissions_definitions[$i]['name']]), $_REQUEST['filters']);
            if (!$include) {
                continue;
            }
        }
        $out[$iRow] = array(0 => $permissions_definitions[$i]['name'], 1 => '<div data-description="' . $permissions_definitions[$i]['description'] . '">' . '<span class="ui-icon ui-icon-float ui-icon-info"></span>&nbsp;' . '<span>' . $permissions_definitions[$i]['name'] . '</span></div>', 2 => $scope, 3 => $type, 4 => $control);
        $iRow++;
    }
    return $out;
}
Exemplo n.º 2
0
 public static function get_values($who = 'user', $obj, $definitions = NULL, $ws = null)
 {
     global $DB;
     global $website;
     if (empty($ws)) {
         $ws = $website->id;
     }
     // load all permission definitions: system, functions, extensions
     $scopes = array('system', 'functions', 'settings', 'extensions');
     if (empty($definitions)) {
         $definitions = permission::get_definitions();
     }
     // load permissions with values set on database
     if ($who == 'user') {
         $DB->query('
             SELECT *
             FROM nv_permissions
             WHERE profile = ' . protect($obj->profile) . '
               AND (website = 0 OR website = ' . protect($ws) . ')');
         $permissions_profile = $DB->result();
         $DB->query('
             SELECT *
               FROM nv_permissions
              WHERE user = '******'
                AND (website = 0 OR website = ' . protect($ws) . ')');
         $permissions_user = $DB->result();
     } else {
         if ($who == 'profile') {
             $DB->query('
             SELECT * FROM nv_permissions
              WHERE profile = ' . protect($obj->id) . '
              AND (website = 0 OR website = ' . protect($ws) . ')');
             $permissions_profile = $DB->result();
             $permissions_user = array();
         }
     }
     // now combine definitions with custom values
     $permissions = array();
     foreach ($scopes as $scope) {
         for ($i = 0; $i < count($definitions[$scope]); $i++) {
             $def = $definitions[$scope][$i];
             $permissions[$def['name']] = isset($def['dvalue']) ? $def['dvalue'] : "";
             // search for a custom value on PROFILE permissions
             for ($pp = 0; $pp < count($permissions_profile); $pp++) {
                 if ($permissions_profile[$pp]->name == $def['name']) {
                     $permissions[$def['name']] = json_decode($permissions_profile[$pp]->value, true);
                     break;
                     // no need to look further
                 }
             }
             // search for a custom value on USER permissions
             for ($pu = 0; $pu < count($permissions_user); $pu++) {
                 if ($permissions_user[$pu]->name == $def['name']) {
                     $permissions[$def['name']] = json_decode($permissions_user[$pu]->value, true);
                     break;
                     // no need to look further
                 }
             }
         }
     }
     return $permissions;
 }
Exemplo n.º 3
0
 /**
  * Return a permission value applied to this user (or profile)
  *
  * @param string $name Code of the permission
  * @return string Value of the permission
  */
 public function permission($name)
 {
     global $website;
     // first call, we need to load the current user permissions
     if (empty($this->permissions)) {
         $this->permissions = array();
         $this->permissions['definitions'] = permission::get_definitions();
         $this->permissions['values'] = permission::get_values('user', $this, $this->permissions['definitions'], $website->id);
     }
     return $this->permissions['values'][$name];
 }