コード例 #1
0
ファイル: lib.php プロジェクト: vinoth4891/clinique
 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();
 }
コード例 #2
0
 /**
  * Tries to convert $localname into another encoding,
  * please note that it may fail really badly.
  *
  * @param string $localname name of file in utf-8 encoding
  * @return string
  */
 protected function mangle_pathname($localname)
 {
     if ($this->encoding === 'utf-8') {
         return $localname;
     }
     $converted = textlib::convert($localname, 'utf-8', $this->encoding);
     $original = textlib::convert($converted, $this->encoding, 'utf-8');
     if ($original === $localname) {
         $result = $converted;
     } else {
         // try ascii conversion
         $converted2 = textlib::specialtoascii($localname);
         $converted2 = textlib::convert($converted2, 'utf-8', $this->encoding);
         $original2 = textlib::convert($converted, $this->encoding, 'utf-8');
         if ($original2 === $localname) {
             //this looks much better
             $result = $converted2;
         } else {
             //bad luck - the file name may not be usable at all
             $result = $converted;
         }
     }
     $result = preg_replace('/\\.\\.+/', '', $result);
     $result = ltrim($result);
     // no leading /
     if ($result === '.') {
         $result = '';
     }
     return $result;
 }
コード例 #3
0
 /**
  * Tests the static specialtoascii method
  * @return void
  */
 public function test_specialtoascii()
 {
     $str = "Žluťoučký koníček";
     $this->assertSame(textlib::specialtoascii($str), 'Zlutoucky konicek');
 }
コード例 #4
0
if ($roles_in_file = roles_migration_get_incoming_roles()) {
    foreach ($roles_in_file as $role) {
        if (!isset($actions[$role->shortname])) {
            echo '<p>', get_string('role_ignored', 'report_rolesmigration', $role), '</p>';
            continue;
        }

        switch ($actions[$role->shortname]) {
            case 'skip':
                echo '<p>', get_string('role_ignored', 'report_rolesmigration', $role), '</p>';
                break;
            case 'create':
                if (!array_key_exists($role->shortname, $roles['create'])) {
                    print_error('new_shortname_undefined');
                }
                $new_role_shortname = textlib::specialtoascii($roles['create'][$role->shortname]['shortname']);
                $new_role_shortname = textlib::strtolower(clean_param($new_role_shortname, PARAM_ALPHANUMEXT));
                $new_role_name = $roles['create'][$role->shortname]['name'];

                // Code to make new role name/short name if same role name or shortname exists
                $fullname = $new_role_name;
                $shortname = $new_role_shortname;
                $currentfullname = "";
                $currentshortname = "";
                $counter = 0;

                do {
                    if ($counter) {
                        $suffixfull = " ".get_string("copyasnoun")." ".$counter;
                        $suffixshort = "_".$counter;
                    } else {