/** * Render widgert * * @param array $params * @param Smarty $smarty * @return string */ function smarty_function_select_project_permissions($params, &$smarty) { static $counter = 1; $id = array_var($params, 'id'); if (empty($id)) { $id = 'select_project_permissions_' . $counter; $counter++; } // if $name = array_var($params, 'name'); $value = array_var($params, 'value', array()); $permissions = Permissions::findProject(); if (is_foreachable($permissions)) { $levels = array(PROJECT_PERMISSION_NONE => lang('No Access'), PROJECT_PERMISSION_ACCESS => lang('Has Access'), PROJECT_PERMISSION_CREATE => lang('and Can Create'), PROJECT_PERMISSION_MANAGE => lang('and Can Manage')); $result = '<table class="select_project_permissions" id="' . clean($id) . '"> <tr> <th>' . lang('Object') . '</th> <th colspan="4">' . lang('Permissions Level') . '</th> </tr>'; $counter = 1; foreach ($permissions as $permission => $permission_name) { $permission_value = array_var($value, $permission); if ($permission_value === null) { $permission_value = PROJECT_PERMISSION_NONE; } // if $result .= '<tr class="' . ($counter % 2 ? 'odd' : 'even') . ' hoverable"><td class="permission_name"><span>' . $permission_name . '</span></td>'; foreach ($levels as $level_value => $level_label) { $input_id = 'select_permission_' . $permission . '_' . $level_value; $input_attributes = array('name' => $name . '[' . $permission . ']', 'value' => $level_value, 'type' => 'radio', 'class' => 'inline', 'id' => $input_id); if ($level_value == $permission_value) { $input_attributes['checked'] = 'checked'; } // if $label_attributes = array('for' => $input_id, 'class' => 'inline'); $cell_class = $level_value == PROJECT_PERMISSION_NONE ? 'no_access' : 'has_access'; $result .= '<td class="permission_value ' . $cell_class . '">' . open_html_tag('input', $input_attributes, true) . ' ' . open_html_tag('label', $label_attributes) . clean($level_label) . '</label></td>'; } // if $result .= '</tr>'; $counter++; } // foreach return $result . '</table><script type="text/javascript">App.widgets.SelectProjectPermissions.init("' . clean($id) . '")</script>'; } // if }
/** * Show role details * * @param void * @return null */ function role() { $role_id = $this->request->getId('role_id'); if ($role_id) { $role = Roles::findById($role_id); if (instance_of($role, 'Role')) { if ($role->getType() == ROLE_TYPE_SYSTEM) { $default_role_id = ConfigOptions::getValue('default_role'); $serve_as = 'system_role'; $role_data = array('id' => $role->getId(), 'name' => $role->getName(), 'is_default' => $role->getId() == $default_role_id, 'permissions' => array()); $system_permissions = Permissions::findSystem(); foreach ($system_permissions as $permission) { $role_data['permissions'][$permission] = (bool) $role->getPermissionValue($permission, false); } // foreach } else { $serve_as = 'project_role'; $role_data = array('id' => $role->getId(), 'name' => $role->getName(), 'permissions' => array()); foreach (array_keys(Permissions::findProject()) as $permission) { $role_data['permissions'][$permission] = (int) $role->getPermissionValue($permission, 0); } // foreach } // if $this->serveData($role_data, $serve_as); } // if } // if $this->httpError(HTTP_ERR_NOT_FOUND); }
/** * Return top level types user can see in $project * * @param User $user * @param Project $project * @param boolean $use_cache * @return array */ function getVisibleTypesByProject($user, $project, $use_cache = true) { $project_id = $project->getId(); $cache_id = 'visible_project_types_for_' . $user->getId(); $cached_value = cache_get($cache_id); if (!is_array($cached_value)) { $cached_value = array(); } // if if ($use_cache && isset($cached_value[$project_id])) { return $cached_value[$project_id]; } // if if ($user->isAdministrator() || $user->isProjectManager() || $user->isProjectLeader($project)) { $cached_value[$project_id] = array_keys(Permissions::findProject()); cache_set($cache_id, $cached_value); return $cached_value[$project_id]; } // if $project_user = ProjectUsers::findById(array('user_id' => $user->getId(), 'project_id' => $project->getId())); if (instance_of($project_user, 'ProjectUser')) { $role = $project_user->getRole(); if (instance_of($role, 'Role')) { $permissions = $role->getPermissions(); } else { $permissions = $project_user->getPermissions(); } // if if (is_array($permissions)) { $types = array(); foreach ($permissions as $permission_name => $permission_value) { if ($permission_value >= PROJECT_PERMISSION_ACCESS) { $types[] = $permission_name; } // if } // foreach $cached_value[$project_id] = $types; cache_set($cache_id, $cached_value); return $cached_value[$project_id]; } // if } // if $cached_value[$project_id] = array(); cache_set($cache_id, $cached_value); return array(); }
/** * Update role * * @param void * @return null */ function edit() { $this->wireframe->print_button = false; if ($this->active_role->isNew()) { $this->httpError(HTTP_ERR_NOT_FOUND); } // if if ($this->active_role->getType() == ROLE_TYPE_PROJECT) { $permissions = array_keys(Permissions::findProject()); } else { $permissions = Permissions::findSystem(); } // if $role_data = $this->request->post('role'); if (!is_array($role_data)) { $role_data = array('name' => $this->active_role->getName(), 'permissions' => $this->active_role->getPermissions()); } // if // if it's admin role and if the user editing it is the only administrator in the system // we need to protect removing system or admin access from that role $protect_admin_role = $this->logged_user->isOnlyAdministrator() && $this->logged_user->getRoleId() == $this->active_role->getId(); $this->smarty->assign(array('role_data' => $role_data, 'permissions' => $permissions, 'protect_admin_role' => $protect_admin_role)); if ($this->request->isSubmitted()) { $old_name = $this->active_role->getName(); $permission_values = array_var($role_data, 'permissions'); if (!is_array($permission_values)) { $permission_values = array(); } // if if ($protect_admin_role) { // in case that someone removes "disabled" attribute, use brute force! $permission_values['admin_access'] = 1; $permission_values['system_access'] = 1; } // if $this->active_role->setName(array_var($role_data, 'name')); $this->active_role->setPermissions($permission_values); $save = $this->active_role->save(); if ($save && !is_error($save)) { clean_permissions_cache(); flash_success("Role ':name' has been updated", array('name' => $old_name)); $this->redirectTo('admin_roles'); } else { $this->smarty->assign('errors', $save); } // if } // if }
/** * Describe project * * @param User $user * @param array $additional * @return array */ function describe($user, $additional = null) { $result = array('id' => $this->getId(), 'name' => $this->getName(), 'overview' => $this->getOverview(), 'status' => $this->getStatus(), 'type' => $this->getType(), 'permalink' => $this->getOverviewUrl()); if (array_var($additional, 'describe_leader')) { $leader = $this->getLeader(); if (instance_of($leader, 'User')) { $result['leader'] = $leader->describe($user); } // if } // if if (!array_key_exists('leader', $result)) { $result['leader_id'] = $this->getLeaderId(); } // if if (array_var($additional, 'describe_company')) { $company = $this->getCompany(); if (instance_of($company, 'Company')) { $result['company'] = $company->describe($user); } // if } // if if (!array_key_exists('company', $result)) { $result['company_id'] = $this->getCompanyId(); } // if if (array_var($additional, 'describe_group')) { $group = $this->getGroup(); if (instance_of($group, 'ProjectGroup')) { $result['group'] = $group->describe($user); } // if } // if if (!array_key_exists('group', $result)) { $result['group_id'] = $this->getGroupId(); } // if if (array_var($additional, 'describe_permissions')) { $logged_user_permissions = array('role' => null, 'permissions' => array()); $permissions = array_keys(Permissions::findProject()); if ($user->isAdministrator()) { $logged_user_permissions['role'] = 'administrator'; } elseif ($user->isProjectManager()) { $logged_user_permissions['role'] = 'project-manager'; } elseif ($user->isProjectLeader($this)) { $logged_user_permissions['role'] = 'project-leader'; } // if if ($logged_user_permissions['role'] === null) { $project_role = $user->getProjectRole($this); if (instance_of($project_role, 'Role')) { $logged_user_permissions['role'] = $project_role->getId(); } else { $logged_user_permissions['role'] = 'custom'; } // if foreach ($permissions as $permission) { $logged_user_permissions['permissions'][$permission] = (int) $user->getProjectPermission($permission, $this); } // foreach } else { foreach ($permissions as $permission) { $logged_user_permissions['permissions'][$permission] = PROJECT_PERMISSION_MANAGE; } // foreach } // if $result['logged_user_permissions'] = $logged_user_permissions; } // if if (array_var($additional, 'describe_icon')) { $result['icon_url'] = $this->getIconUrl(true); } // if return $result; }
/** * Show people page * * @param void * @return null */ function index() { if ($this->active_project->isNew()) { $this->httpError(HTTP_ERR_NOT_FOUND); } // if $users = $this->active_project->getUsers(); // API if ($this->request->isApiCall()) { $project_users_data = array(); if (is_foreachable($users)) { foreach ($users as $user) { $user_data = array('user_id' => $user->getId(), 'role' => null, 'permissions' => array(), 'permalink' => $user->getViewUrl()); $permissions = array_keys(Permissions::findProject()); if ($user->isAdministrator()) { $user_data['role'] = 'administrator'; } elseif ($user->isProjectManager()) { $user_data['role'] = 'project-manager'; } elseif ($user->isProjectLeader($this->active_project)) { $user_data['role'] = 'project-leader'; } // if if ($user_data['role'] === null) { $project_role = $user->getProjectRole($this->active_project); if (instance_of($project_role, 'Role')) { $user_data['role'] = $project_role->getId(); } else { $user_data['role'] = 'custom'; } // if foreach ($permissions as $permission) { $user_data['permissions'][$permission] = (int) $user->getProjectPermission($permission, $this->active_project); } // foreach } else { foreach ($permissions as $permission) { $user_data['permissions'][$permission] = PROJECT_PERMISSION_MANAGE; } // foreach } // if $project_users_data[] = $user_data; } // foreach } // if $this->serveData($project_users_data, 'project_users'); // Regular interface } else { if (is_foreachable($users)) { $people = array(); $grouped_users = array(); //BOF:mod 20110712 ticketid237 $company_by_custom_sort = array(); foreach ($users as $user) { $company_id = $user->getCompanyId(); if (!in_array($company_id, $company_by_custom_sort)) { $company_by_custom_sort[] = $company_id; } } asort($company_by_custom_sort); foreach ($company_by_custom_sort as $company_id) { $people[$company_id] = array('users' => null, 'company' => null); } //EOF:mod 20110712 ticketid237 foreach ($users as $user) { $company_id = $user->getCompanyId(); if (!isset($people[$company_id])) { $people[$company_id] = array('users' => null, 'company' => null); } // if $people[$company_id]['users'][] = $user; } // foreach $companies = Companies::findByIds(array_keys($people)); foreach ($companies as $company) { $people[$company->getId()]['company'] = $company; } // foreach $this->smarty->assign('people', $people); } else { $this->smarty->assign('people', null); } // if } // if }