public function read_submitted_permissions() { global $DB; $this->errors = array(); // Role short name. We clean this in a special way. We want to end up // with only lowercase safe ASCII characters. $shortname = optional_param('shortname', null, PARAM_RAW); if (!is_null($shortname)) { $this->role->shortname = $shortname; $this->role->shortname = textlib::specialtoascii($this->role->shortname); $this->role->shortname = textlib::strtolower(clean_param($this->role->shortname, PARAM_ALPHANUMEXT)); if (empty($this->role->shortname)) { $this->errors['shortname'] = get_string('errorbadroleshortname', 'role'); } } if ($DB->record_exists_select('role', 'shortname = ? and id <> ?', array($this->role->shortname, $this->roleid))) { $this->errors['shortname'] = get_string('errorexistsroleshortname', 'role'); } // Role name. $name = optional_param('name', null, PARAM_TEXT); if (!is_null($name)) { $this->role->name = $name; // Hack: short names of standard roles are equal to archetypes, empty name means localised via lang packs. $archetypes = get_role_archetypes(); if (!isset($archetypes[$shortname]) and html_is_blank($this->role->name)) { $this->errors['name'] = get_string('errorbadrolename', 'role'); } } if ($this->role->name !== '' and $DB->record_exists_select('role', 'name = ? and id <> ?', array($this->role->name, $this->roleid))) { $this->errors['name'] = get_string('errorexistsrolename', 'role'); } // Description. $description = optional_param('description', null, PARAM_RAW); if (!is_null($description)) { $this->role->description = $description; } // Legacy type. $archetype = optional_param('archetype', null, PARAM_RAW); if (isset($archetype)) { $archetypes = get_role_archetypes(); if (isset($archetypes[$archetype])) { $this->role->archetype = $archetype; } else { $this->role->archetype = ''; } } // Assignable context levels. foreach ($this->allcontextlevels as $cl => $notused) { $assignable = optional_param('contextlevel' . $cl, null, PARAM_BOOL); if (!is_null($assignable)) { if ($assignable) { $this->contextlevels[$cl] = $cl; } else { unset($this->contextlevels[$cl]); } } } // Now read the permissions for each capability. parent::read_submitted_permissions(); }
public function read_submitted_permissions() { global $DB; $this->errors = array(); // Role name. $name = optional_param('name', null, PARAM_MULTILANG); if (!is_null($name)) { $this->role->name = $name; if (html_is_blank($this->role->name)) { $this->errors['name'] = get_string('errorbadrolename', 'role'); } } if ($DB->record_exists_select('role', 'name = ? and id <> ?', array($this->role->name, $this->roleid))) { $this->errors['name'] = get_string('errorexistsrolename', 'role'); } // Role short name. We clean this in a special way. We want to end up // with only lowercase safe ASCII characters. $shortname = optional_param('shortname', null, PARAM_RAW); if (!is_null($shortname)) { $this->role->shortname = $shortname; $this->role->shortname = textlib_get_instance()->specialtoascii($this->role->shortname); $this->role->shortname = moodle_strtolower(clean_param($this->role->shortname, PARAM_ALPHANUMEXT)); if (empty($this->role->shortname)) { $this->errors['shortname'] = get_string('errorbadroleshortname', 'role'); } } if ($DB->record_exists_select('role', 'shortname = ? and id <> ?', array($this->role->shortname, $this->roleid))) { $this->errors['shortname'] = get_string('errorexistsroleshortname', 'role'); } // Description. $description = optional_param('description', null, PARAM_CLEAN); if (!is_null($description)) { $this->role->description = $description; } // Legacy type. $legacytype = optional_param('legacytype', null, PARAM_RAW); if (!is_null($legacytype)) { if (array_key_exists($legacytype, $this->legacyroles)) { $this->role->legacytype = $legacytype; } else { $this->role->legacytype = ''; } } // Assignable context levels. foreach ($this->allcontextlevels as $cl => $notused) { $assignable = optional_param('contextlevel' . $cl, null, PARAM_BOOL); if (!is_null($assignable)) { if ($assignable) { $this->contextlevels[$cl] = $cl; } else { unset($this->contextlevels[$cl]); } } } // Now read the permissions for each capability. parent::read_submitted_permissions(); }