/** * List all available system roles * * @param void * @return null */ function system_roles() { $default_role_id = ConfigOptions::getValue('default_role'); if ($this->logged_user->isAdministrator() || $this->logged_user->isProjectManager()) { $roles_data = array(); $system_permissions = Permissions::findSystem(); $roles = Roles::findSystemRoles(); if (is_foreachable($roles)) { foreach ($roles as $role) { $role_details = array('id' => $role->getId(), 'name' => $role->getName(), 'is_default' => $role->getId() == $default_role_id, 'permissions' => array()); foreach ($system_permissions as $permission) { $role_details['permissions'][$permission] = (bool) $role->getPermissionValue($permission, false); } // foreach $roles_data[] = $role_details; } // foreach } // if $this->serveData($roles_data, 'system_roles'); } else { $this->serveData($default_role_id, 'default_role_id'); $this->httpError(HTTP_ERR_FORBIDDEN); } // if }
/** * Render select role helper * * Params: * * - value - ID of selected role * - optional - Wether value is optional or not * - active_user - Set if we are changing role of existing user so we can * handle situations when administrator role is displayed or changed * * @param array $params * @param Smarty $smarty * @return string */ function smarty_function_select_role($params, &$smarty) { $value = array_var($params, 'value', null, true); $optional = array_var($params, 'optional', false, true); $active_user = array_var($params, 'active_user', false, true); $logged_user = get_logged_user(); if (!instance_of($logged_user, 'User')) { return new InvalidParamError('logged_user', $logged_user, '$logged_user is expected to be an instance of user class'); } // if if ($optional) { $options = array(option_tag(lang('-- None --'), ''), option_tag('', '')); } else { $options = array(); } // if $roles = Roles::findSystemRoles(); if (is_foreachable($roles)) { foreach ($roles as $role) { $show_role = true; $disabled = false; if ($role->getPermissionValue('admin_access') && !$logged_user->isAdministrator() && !$active_user->isAdministrator()) { $show_role = false; // don't show administration role to non-admins and for non-admins } // if if ($show_role) { $option_attributes = $value == $role->getId() ? array('selected' => true, 'disabled' => $disabled) : null; $options[] = option_tag($role->getName(), $role->getId(), $option_attributes); } // if } // foreach } // if return select_box($options, $params); }
/** * Show module details page * * @param void * @return null */ function module() { $this->smarty->assign('roles', Roles::findSystemRoles()); }
/** * Show module details page * * @param void * @return null */ function module() { js_assign('invoicing_precision', INVOICE_PRECISION); $this->smarty->assign('roles', Roles::findSystemRoles()); }
/** * Returns list of system roles which have can_see_private_objects set to Yes * * If $as_string is set to yes function returns list of names separated with * comma (like Adminstrator, Project Manager, People Manager or Member) * * @param boolean $as_string * @return array */ function who_can_see_private_objects($as_string = false, $separator = null) { $roles = Roles::findSystemRoles(); $result = array(); if (is_foreachable($roles)) { foreach ($roles as $role) { if ($role->getPermissionValue('admin_access') || $role->getPermissionValue('project_management') || $role->getPermissionValue('can_see_private_objects')) { $result[] = $as_string ? $role->getName() : $role; } // if } // foreach } // if if ($as_string) { if ($separator === null) { $separator = lang(' and '); } // if require_once SMARTY_PATH . '/plugins/function.join.php'; return smarty_function_join(array('items' => $result, 'final_separator' => $separator), $smarty); } else { return $result; } // if }
/** * Return number of administrators * * @param void * @return integer */ function countAdministrators() { $admin_role_ids = array(); $system_roles = Roles::findSystemRoles(); foreach ($system_roles as $system_role) { if ($system_role->isAdministrator()) { $admin_role_ids[] = $system_role->getId(); } // if } // foreach return count($admin_role_ids) > 0 ? Users::count(array("role_id IN (?)", $admin_role_ids)) : 0; }