Пример #1
0
 public function __actionEdit()
 {
     if (array_key_exists('delete', $_POST['action'])) {
         return $this->__actionDelete($this->_context[1], extension_Members::baseURL() . 'roles/');
     }
     if (array_key_exists('save', $_POST['action'])) {
         $isNew = $this->_context[0] !== "edit";
         $fields = $_POST['fields'];
         // If we are editing, we need to make sure the current `$role_id` exists
         if (!$isNew) {
             if (!($role_id = $this->_context[1])) {
                 redirect(extension_Members::baseURL() . 'roles/');
             }
             if (!($existing = RoleManager::fetch($role_id))) {
                 throw new SymphonyErrorPage(__('The role you requested to edit does not exist.'), __('Role not found'));
             }
         }
         $name = trim($fields['name']);
         if (strlen($name) == 0) {
             $this->_errors['name'] = __('This is a required field');
             return false;
         }
         $handle = Lang::createHandle($name);
         // Make sure there isn't already a Role with the same name.
         if ($isNew) {
             if (RoleManager::fetchRoleIDByHandle($handle)) {
                 $this->_errors['name'] = __('A role with the name <code>%s</code> already exists.', array($name));
                 return false;
             }
         } else {
             if ($handle != $existing->get('handle') && RoleManager::fetchRoleIDByHandle($handle)) {
                 $this->_errors['name'] = __('A role with the name <code>%s</code> already exists.', array($name));
                 return false;
             }
         }
         $data['roles'] = array('name' => $name, 'handle' => $handle);
         $data['roles_forbidden_pages'] = array('page_access' => $fields['page_access']);
         $data['roles_event_permissions'] = array('permissions' => $fields['permissions']);
         if ($isNew) {
             if ($role_id = RoleManager::add($data)) {
                 redirect(extension_members::baseURL() . 'roles/edit/' . $role_id . '/created/');
             }
         } else {
             if (RoleManager::edit($role_id, $data)) {
                 redirect(extension_members::baseURL() . 'roles/edit/' . $role_id . '/saved/');
             }
         }
     }
 }