Beispiel #1
0
 function validation($data, $files)
 {
     global $COURSE, $CFG;
     $errors = parent::validation($data, $files);
     $textlib = textlib_get_instance();
     $name = trim(stripslashes($data['name']));
     if ($data['id'] and $group = get_record('groups', 'id', $data['id'])) {
         if ($textlib->strtolower($group->name) != $textlib->strtolower($name)) {
             if (groups_get_group_by_name($COURSE->id, $name)) {
                 $errors['name'] = get_string('groupnameexists', 'group', $name);
             }
         }
         if (!empty($CFG->enrol_manual_usepasswordpolicy) and $data['enrolmentkey'] != '' and $group->enrolmentkey !== $data['enrolmentkey']) {
             // enforce password policy only if changing password
             $errmsg = '';
             if (!check_password_policy($data['enrolmentkey'], $errmsg)) {
                 $errors['enrolmentkey'] = $errmsg;
             }
         }
     } else {
         if (groups_get_group_by_name($COURSE->id, $name)) {
             $errors['name'] = get_string('groupnameexists', 'group', $name);
         }
     }
     return $errors;
 }
Beispiel #2
0
 function definition()
 {
     global $CFG, $USER;
     $mform =& $this->_form;
     $mform->addElement('header', 'settingsheader', get_string('upload'));
     $mform->addElement('filepicker', 'userfile', get_string('file'));
     $mform->addRule('userfile', null, 'required');
     $choices = csv_import_reader::get_delimiter_list();
     $mform->addElement('select', 'delimiter_name', get_string('csvdelimiter', 'admin'), $choices);
     if (array_key_exists('cfg', $choices)) {
         $mform->setDefault('delimiter_name', 'cfg');
     } else {
         if (get_string('listsep', 'langconfig') == ';') {
             $mform->setDefault('delimiter_name', 'semicolon');
         } else {
             $mform->setDefault('delimiter_name', 'comma');
         }
     }
     $textlib = textlib_get_instance();
     $choices = $textlib->get_encodings();
     $mform->addElement('select', 'encoding', get_string('encoding', 'admin'), $choices);
     $mform->setDefault('encoding', 'UTF-8');
     $choices = array('10' => 10, '20' => 20, '100' => 100, '1000' => 1000, '100000' => 100000);
     $mform->addElement('select', 'previewrows', get_string('rowpreviewnum', 'admin'), $choices);
     $mform->setType('previewrows', PARAM_INT);
     $choices = array(UU_ADDNEW => get_string('uuoptype_addnew', 'admin'), UU_ADDINC => get_string('uuoptype_addinc', 'admin'), UU_ADD_UPDATE => get_string('uuoptype_addupdate', 'admin'), UU_UPDATE => get_string('uuoptype_update', 'admin'));
     $mform->addElement('select', 'uutype', get_string('uuoptype', 'admin'), $choices);
     $this->add_action_buttons(false, get_string('uploadusers', 'admin'));
 }
 private static function sort_ignore_case($a, $b)
 {
     $tl = textlib_get_instance();
     $alower = $tl->strtolower($a);
     $blower = $tl->strtolower($b);
     return $alower > $blower ? 1 : $alower < $blower ? -1 : 0;
 }
Beispiel #4
0
 function definition()
 {
     global $CFG, $USER;
     $mform =& $this->_form;
     $this->set_upload_manager(new upload_manager('userfile', false, false, null, false, 0, true, true, false));
     $mform->addElement('header', 'settingsheader', get_string('upload'));
     $mform->addElement('file', 'userfile', get_string('file'), 'size="40"');
     $mform->addRule('userfile', null, 'required');
     $choices = csv_import_reader::get_delimiter_list();
     $mform->addElement('select', 'delimiter_name', get_string('csvdelimiter', 'admin'), $choices);
     if (array_key_exists('cfg', $choices)) {
         $mform->setDefault('delimiter_name', 'cfg');
     } else {
         if (get_string('listsep') == ';') {
             $mform->setDefault('delimiter_name', 'semicolon');
         } else {
             $mform->setDefault('delimiter_name', 'comma');
         }
     }
     $textlib = textlib_get_instance();
     $choices = $textlib->get_encodings();
     $mform->addElement('select', 'encoding', get_string('encoding', 'admin'), $choices);
     $mform->setDefault('encoding', 'UTF-8');
     $choices = array('10' => 10, '20' => 20, '100' => 100, '1000' => 1000, '100000' => 100000);
     $mform->addElement('select', 'previewrows', get_string('rowpreviewnum', 'admin'), $choices);
     $mform->setType('previewrows', PARAM_INT);
     $this->add_action_buttons(false, get_string('uploadusers'));
 }
function my_link_sort($a, $b)
{
    $tl = textlib_get_instance();
    $a = $tl->strtolower(substr($a->link, strpos($a->link, '>') + 1));
    $b = $tl->strtolower(substr($b->link, strpos($b->link, '>') + 1));
    return strcmp($a, $b);
}
Beispiel #6
0
 function test_format_text_email()
 {
     $this->assertEqual('This is a test', format_text_email('<p>This is a <strong>test</strong></p>', FORMAT_HTML));
     $this->assertEqual('This is a test', format_text_email('<p class="frogs">This is a <strong class=\'fishes\'>test</strong></p>', FORMAT_HTML));
     $this->assertEqual('& so is this', format_text_email('<p>&amp; so is this</p>', FORMAT_HTML));
     $tl = textlib_get_instance();
     $this->assertEqual('Two bullets: ' . $tl->code2utf8(8226) . ' ' . $tl->code2utf8(8226), format_text_email('<p>Two bullets: &#x2022; &#8226;</p>', FORMAT_HTML));
     $this->assertEqual($tl->code2utf8(0x7fd2) . $tl->code2utf8(0x7fd2), format_text_email('<p>&#x7fd2;&#x7FD2;</p>', FORMAT_HTML));
 }
Beispiel #7
0
function csv_quote($value) {
    global $excel;
    if($excel) {
        $tl=textlib_get_instance();
        return $tl->convert('"'.str_replace('"',"'",$value).'"','UTF-8','UTF-16LE');
    } else {
        return '"'.str_replace('"',"'",$value).'"';
    }
}
 public function format_title($title, $max = 64)
 {
     $textlib = textlib_get_instance();
     if ($textlib->strlen($title) <= $max) {
         return s($title);
     } else {
         return s($textlib->substr($title, 0, $max - 3) . '...');
     }
 }
 /**
  * Gets quoted csv variable string.
  *
  * @param string $varstr csv variable string
  * @return quoted csv variable string 
  */
 public function quote($varstr)
 {
     if ($this->_excelcsv) {
         $tl = textlib_get_instance();
         return $tl->convert('"' . str_replace('"', "'", $varstr) . '"', 'UTF-8', 'UTF-16LE');
     } else {
         return '"' . str_replace('"', "'", $varstr) . '"';
     }
 }
function game_cross_continue($id, $game, $attempt, $cross, $g = '', $endofgame = '')
{
    if ($endofgame) {
        if ($g == '') {
            game_updateattempts($game, $attempt, -1, true);
            $endofgame = false;
        }
    }
    if ($attempt != false and $cross != false) {
        return game_cross_play($id, $game, $attempt, $cross, $g, false, false, $endofgame, false, false, false, false);
    }
    if ($attempt == false) {
        $attempt = game_addattempt($game);
    }
    $textlib = textlib_get_instance();
    $cross = new CrossDB();
    $questions = array();
    $infos = array();
    $answers = array();
    $recs = game_questions_shortanswer($game);
    if ($recs == false) {
        error('game_cross_continue: ' . get_string('cross_nowords', 'game'));
    }
    $infos = array();
    foreach ($recs as $rec) {
        if ($game->param7 == false) {
            if ($textlib->strpos($rec->answertext, ' ')) {
                continue;
                //spaces not allowed
            }
        }
        $rec->answertext = game_upper($rec->answertext);
        $answers[$rec->answertext] = game_repairquestion($rec->questiontext);
        $infos[$rec->answertext] = array($game->sourcemodule, $rec->questionid, $rec->glossaryentryid, $rec->attachment);
    }
    $cross->setwords($answers, $game->param1);
    if ($cross->computedata($crossm, $crossd, $game->param2)) {
        $new_crossd = array();
        foreach ($crossd as $rec) {
            $info = $infos[$rec->answertext];
            if ($info != false) {
                $rec->sourcemodule = $info[0];
                $rec->questionid = $info[1];
                $rec->glossaryentryid = $info[2];
                $rec->attachment = $info[3];
            }
            $new_crossd[] = $rec;
        }
        $cross->save($game, $crossm, $new_crossd, $attempt->id);
        game_updateattempts($game, $attempt, 0, 0);
        return game_cross_play($id, $game, $attempt, $crossm, '', false, false, false, false, false, false, false);
    }
    if (count($crossd) == 0) {
        error('game_cross_continue: ' . get_string('cross_nowords', 'game'));
    }
}
/**
 * @uses LABEL_MAX_NAME_LENGTH
 * @param object $label
 * @return string
 */
function get_label_name($label)
{
    $textlib = textlib_get_instance();
    $name = strip_tags(format_string($label->intro, true));
    if ($textlib->strlen($name) > LABEL_MAX_NAME_LENGTH) {
        $name = $textlib->substr($name, 0, LABEL_MAX_NAME_LENGTH) . "...";
    }
    if (empty($name)) {
        // arbitrary name
        $name = get_string('modulename', 'label');
    }
    return $name;
}
Beispiel #12
0
 /**
  * Use internal moodles own textlib to encode mimeheaders.
  * Fall back to phpmailers inbuilt functions if not 
  */
 public function EncodeHeader($str, $position = 'text')
 {
     $textlib = textlib_get_instance();
     $encoded = $textlib->encode_mimeheader($str, $this->CharSet);
     if ($encoded !== false) {
         $encoded = str_replace("\n", $this->LE, $encoded);
         if ($position == 'phrase') {
             return "\"{$encoded}\"";
         }
         return $encoded;
     }
     return parent::EncodeHeader($str, $position);
 }
Beispiel #13
0
function label_update_instance($label)
{
    /// Given an object containing all the necessary data,
    /// (defined by the form in mod.html) this function
    /// will update an existing instance with new data.
    $textlib = textlib_get_instance();
    $label->name = addslashes(strip_tags(format_string(stripslashes($label->content), true)));
    if ($textlib->strlen($label->name) > LABEL_MAX_NAME_LENGTH) {
        $label->name = $textlib->substr($label->name, 0, LABEL_MAX_NAME_LENGTH) . "...";
    }
    $label->timemodified = time();
    $label->id = $label->instance;
    return update_record("label", $label);
}
Beispiel #14
0
function get_ezproxy_name($ezproxy)
{
    $textlib = textlib_get_instance();
    //$name = addslashes(strip_tags(format_string(stripslashes($ezproxy->name),true)));
    $name = addslashes(strip_tags(format_string(stripslashes($ezproxy->name), true)));
    if ($textlib->strlen($name) > EZPROXY_MAX_NAME_LENGTH) {
        $name = $textlib->substr($name, 0, EZPROXY_MAX_NAME_LENGTH) . "...";
    }
    if (empty($name)) {
        // arbitrary name
        $name = get_string('modulename', 'ezproxy');
    }
    return $name;
}
function accordion_update_instance($accordion)
{
    /// Given an object containing all the necessary data,
    /// (defined by the form in mod.html) this function
    /// will update an existing instance with new data.
    $textlib = textlib_get_instance();
    $accordion->name = addslashes(strip_tags(format_string(stripslashes($accordion->content), true)));
    $accordion->title = addslashes(strip_tags(format_string(stripslashes($accordion->title), true)));
    if ($textlib->strlen($accordion->name) > ACCORDION_MAX_NAME_LENGTH) {
        $accordion->name = $textlib->substr($accordion->name, 0, ACCORDION_MAX_NAME_LENGTH) . "...";
    }
    $accordion->timemodified = time();
    $accordion->id = $accordion->instance;
    return update_record("accordion", $accordion);
}
function game_cross_new($game, $attemptid, &$crossm)
{
    global $DB, $USER;
    $textlib = textlib_get_instance();
    $cross = new CrossDB();
    $questions = array();
    $infos = array();
    $answers = array();
    $recs = game_questions_shortanswer($game);
    if ($recs == false) {
        print_error('game_cross_continue: ' . get_string('no_words', 'game'));
    }
    $infos = array();
    $reps = array();
    foreach ($recs as $rec) {
        if ($game->param7 == false) {
            if ($textlib->strpos($rec->answertext, ' ')) {
                continue;
                //spaces not allowed
            }
        }
        $rec->answertext = game_upper($rec->answertext);
        $answers[$rec->answertext] = $rec->questiontext;
        $infos[$rec->answertext] = array($game->sourcemodule, $rec->questionid, $rec->glossaryentryid, $rec->attachment);
        $a = array('gameid' => $game->id, 'userid' => $USER->id, 'questionid' => $rec->questionid, 'glossaryentryid' => $rec->glossaryentryid);
        if (($rec2 = $DB->get_record('game_repetitions', $a, 'id,repetitions r')) != false) {
            $reps[$rec->answertext] = $rec2->r;
        }
    }
    $cross->setwords($answers, $game->param1, $reps);
    if ($cross->computedata($crossm, $crossd, $game->param2)) {
        $new_crossd = array();
        foreach ($crossd as $rec) {
            $info = $infos[$rec->answertext];
            if ($info != false) {
                $rec->sourcemodule = $info[0];
                $rec->questionid = $info[1];
                $rec->glossaryentryid = $info[2];
                $rec->attachment = $info[3];
            }
            $new_crossd[] = $rec;
        }
        $cross->save($game, $crossm, $new_crossd, $attemptid);
    }
    if (count($crossd) == 0) {
        print_error('game_cross_continue: ' . get_string('no_words', 'game'));
    }
}
Beispiel #17
0
 function output()
 {
     global $CFG;
     $stradd = get_string('add');
     $manualform = '<input type="text" name="tag" /><input type="submit" value="' . $stradd . '" />';
     $manualform = $this->enclose_in_form($manualform);
     $iptcform = '';
     $deleteform = '';
     $tags = array();
     if ($tagrecords = get_records_select('lightboxgallery_image_meta', $this->sql_select(), 'description', 'id,description')) {
         $errorlevel = error_reporting(E_PARSE);
         $textlib = textlib_get_instance();
         foreach ($tagrecords as $tagrecord) {
             $tags[$tagrecord->id] = $tagrecord->description;
             //$textlib->typo3cs->utf8_decode($tagrecord->description, 'iso-8859-1');
         }
         error_reporting($errorlevel);
     }
     $path = $CFG->dataroot . '/' . $this->gallery->course . '/' . $this->gallery->folder . '/' . $this->image;
     $size = getimagesize($path, $info);
     if (isset($info['APP13'])) {
         $iptc = iptcparse($info['APP13']);
         if (isset($iptc['2#025'])) {
             $iptcform = '<input type="hidden" name="iptc" value="1" />';
             sort($iptc['2#025']);
             foreach ($iptc['2#025'] as $tag) {
                 $tag = strtolower($tag);
                 $exists = $tags && in_array($tag, array_values($tags));
                 //eric 將 htmlentities($tag); 改為htmlentities($tag,ENT_QUOTES,'UTF-8')
                 $tag = htmlentities($tag, ENT_QUOTES, 'UTF-8');
                 $iptcform .= '<label ' . ($exists ? 'class="tag-exists"' : '') . '><input type="checkbox" name="iptctags[]" value="' . $tag . '" />' . $tag . '</label><br />';
             }
             $iptcform .= '<input type="submit" value="' . $stradd . '" />';
             $iptcform = '<span class="tag-head"> ' . get_string('tagsiptc', 'lightboxgallery') . '</span>' . $this->enclose_in_form($iptcform);
         }
     }
     $iptcform .= print_single_button($CFG->wwwroot . '/mod/lightboxgallery/edit/tag/import.php', array('id' => $this->gallery->id), get_string('tagsimport', 'lightboxgallery'), 'post', '_self', true);
     if ($tags) {
         $deleteform = '<input type="hidden" name="delete" value="1" />';
         foreach ($tags as $tagid => $tagname) {
             //eric 將 htmlentities($tagname)  改為 htmlentities($tagname, ENT_QUOTES,'UTF-8')
             $deleteform .= '<label><input type="checkbox" name="deletetags[]" value="' . $tagid . '" />' . htmlentities($tagname, ENT_QUOTES, 'UTF-8') . '</label><br />';
         }
         $deleteform .= '<input type="submit" value="' . get_string('remove') . '" />';
         $deleteform = '<span class="tag-head"> ' . get_string('tagscurrent', 'lightboxgallery') . '</span>' . $this->enclose_in_form($deleteform);
     }
     return $manualform . $iptcform . $deleteform;
 }
Beispiel #18
0
 /**
  *
  */
 function setupPersonalStorage()
 {
     global $CFG;
     $textlib = textlib_get_instance();
     // Finally, create the default user filesystem folder, if not available
     $user = run('users:instance', array('user_id' => $this->owner));
     $this->username = $user->getUserName();
     $base_folder = $CFG->dataroot . 'files/' . $textlib->substr($this->username, 0, 1);
     $personal_folder = $base_folder . "/" . $this->username;
     if (!file_exists($base_folder)) {
         mkdir($base_folder);
     }
     if (!file_exists($personal_folder)) {
         mkdir($personal_folder);
     }
 }
 function get_content()
 {
     global $CFG, $DB, $OUTPUT;
     if ($this->content !== NULL) {
         return $this->content;
     }
     $this->content = new stdClass();
     $this->content->items = array();
     $this->content->icons = array();
     $this->content->footer = '';
     $course = $this->page->course;
     require_once $CFG->dirroot . '/course/lib.php';
     $modinfo = get_fast_modinfo($course);
     $modfullnames = array();
     $archetypes = array();
     foreach ($modinfo->cms as $cm) {
         // Exclude activities which are not visible or have no link (=label)
         if (!$cm->uservisible or !$cm->has_view()) {
             continue;
         }
         if (array_key_exists($cm->modname, $modfullnames)) {
             continue;
         }
         if (!array_key_exists($cm->modname, $archetypes)) {
             $archetypes[$cm->modname] = plugin_supports('mod', $cm->modname, FEATURE_MOD_ARCHETYPE, MOD_ARCHETYPE_OTHER);
         }
         if ($archetypes[$cm->modname] == MOD_ARCHETYPE_RESOURCE) {
             if (!array_key_exists('resources', $modfullnames)) {
                 $modfullnames['resources'] = get_string('resources');
             }
         } else {
             $modfullnames[$cm->modname] = $cm->modplural;
         }
     }
     textlib_get_instance()->asort($modfullnames);
     foreach ($modfullnames as $modname => $modfullname) {
         if ($modname === 'resources') {
             $icon = '<img src="' . $OUTPUT->pix_url('f/html') . '" class="icon" alt="" />&nbsp;';
             $this->content->items[] = '<a href="' . $CFG->wwwroot . '/course/resources.php?id=' . $course->id . '">' . $icon . $modfullname . '</a>';
         } else {
             $icon = '<img src="' . $OUTPUT->pix_url('icon', $modname) . '" class="icon" alt="" />&nbsp;';
             $this->content->items[] = '<a href="' . $CFG->wwwroot . '/mod/' . $modname . '/index.php?id=' . $course->id . '">' . $icon . $modfullname . '</a>';
         }
     }
     return $this->content;
 }
Beispiel #20
0
 public function validation($data, $files)
 {
     global $DB, $CFG;
     $errors = parent::validation($data, $files);
     $instance = $this->instance;
     if ($instance->password !== '') {
         if ($data['guestpassword'] !== $instance->password) {
             $plugin = enrol_get_plugin('guest');
             if ($plugin->get_config('showhint')) {
                 $textlib = textlib_get_instance();
                 $hint = $textlib->substr($instance->password, 0, 1);
                 $errors['guestpassword'] = get_string('passwordinvalidhint', 'enrol_guest', $hint);
             } else {
                 $errors['guestpassword'] = get_string('passwordinvalid', 'enrol_guest');
             }
         }
     }
     return $errors;
 }
Beispiel #21
0
 public function test_asort()
 {
     global $SESSION;
     $SESSION->lang = 'en';
     // make sure we test en language to get consistent results, hopefully all systems have this locale
     $arr = array('b' => 'ab', 1 => 'aa', 0 => 'cc');
     textlib_get_instance()->asort($arr);
     $this->assertIdentical(array_keys($arr), array(1, 'b', 0));
     $this->assertIdentical(array_values($arr), array('aa', 'ab', 'cc'));
     if (extension_loaded('intl')) {
         $error = 'Collation aware sorting not supported';
     } else {
         $error = 'Collation aware sorting not supported, PHP extension "intl" is not available.';
     }
     $arr = array('a' => 'áb', 'b' => 'ab', 1 => 'aa', 0 => 'cc');
     textlib_get_instance()->asort($arr);
     $this->assertIdentical(array_keys($arr), array(1, 'b', 'a', 0), $error);
     unset($SESSION->lang);
 }
 function validation($data, $files)
 {
     global $COURSE;
     $errors = parent::validation($data, $files);
     $textlib = textlib_get_instance();
     $name = trim(stripslashes($data['name']));
     if ($data['id'] and $grouping = get_record('groupings', 'id', $data['id'])) {
         if ($textlib->strtolower($grouping->name) != $textlib->strtolower($name)) {
             if (groups_get_grouping_by_name($COURSE->id, $name)) {
                 $errors['name'] = get_string('groupingnameexists', 'group', $name);
             }
         }
     } else {
         if (groups_get_grouping_by_name($COURSE->id, $name)) {
             $errors['name'] = get_string('groupingnameexists', 'group', $name);
         }
     }
     return $errors;
 }
 function definition()
 {
     $mform =& $this->_form;
     // course id needs to be passed for auth purposes
     $mform->addElement('hidden', 'id', optional_param('id'));
     $mform->setType('id', PARAM_INT);
     $mform->addElement('header', 'general', get_string('importfile', 'grades'));
     // file upload
     $mform->addElement('file', 'userfile', get_string('file'));
     $mform->setType('userfile', PARAM_FILE);
     $mform->addRule('userfile', null, 'required');
     $textlib = textlib_get_instance();
     $encodings = $textlib->get_encodings();
     $mform->addElement('select', 'encoding', get_string('encoding', 'grades'), $encodings);
     $options = array('10' => 10, '20' => 20, '100' => 100, '1000' => 1000, '100000' => 100000);
     $mform->addElement('select', 'previewrows', get_string('rowpreviewnum', 'grades'), $options);
     // TODO: localize
     $mform->setType('previewrows', PARAM_INT);
     $this->add_action_buttons(false, get_string('uploadgrades', 'grades'));
 }
Beispiel #24
0
 function definition()
 {
     global $CFG;
     $mform =& $this->_form;
     $cmid = $this->_customdata['id'];
     $mform->addElement('filepicker', 'recordsfile', get_string('csvfile', 'data'));
     $delimiters = csv_import_reader::get_delimiter_list();
     $mform->addElement('select', 'fielddelimiter', get_string('fielddelimiter', 'data'), $delimiters);
     $mform->setDefault('fielddelimiter', 'comma');
     $mform->addElement('text', 'fieldenclosure', get_string('fieldenclosure', 'data'));
     $textlib = textlib_get_instance();
     $choices = $textlib->get_encodings();
     $mform->addElement('select', 'encoding', get_string('encoding', 'admin'), $choices);
     $mform->setDefault('encoding', 'UTF-8');
     $submit_string = get_string('submit');
     // data id
     $mform->addElement('hidden', 'd');
     $mform->setType('d', PARAM_INT);
     $this->add_action_buttons(false, $submit_string);
 }
function WF_initappletfilter()
{
    global $TAGS;
    global $CFG;
    // Builds searched strings table
    $charset = strtolower(get_string('thischarset'));
    $TAGS->lcharset = $charset;
    $TAGS->ucharset = strtoupper(get_string('thischarset'));
    /*
     * Converting all 'tags' (markups) to the current charset.
     * This php file is encoded in ISO-8859-1, so all the string defined 
     * in this file are also encoded in ISO-8859-1. For example, the 
     * string '«' has a length of 1 byte. 
     * Problems occured when the filtered content is encoded with another charset.
     * For example in UTF-8 the string '«' is encoded with two bytes. 
     * The searched strings (such as '«applet') must be encoded with the 
     * same charset as the filtered content.
     * 
     * To convert the string, a moolde function is used, this does not works
     * (I don't know why) with versions prior to 1.5.4
     */
    if ($CFG->version > 2005060240) {
        require_once $CFG->libdir . '/textlib.class.php';
        $convertor = textlib_get_instance();
        $TAGS->in_open = $convertor->convert('«', 'iso-8859-1', $charset);
        $TAGS->in_close = $convertor->convert('»', 'iso-8859-1', $charset);
        $TAGS->in_entity = $convertor->convert('§', 'iso-8859-1', $charset);
        $TAGS->in_appletopen = $convertor->convert('«applet', 'iso-8859-1', $charset);
        $TAGS->in_appletclose = $convertor->convert('«/applet»', 'iso-8859-1', $charset);
    } else {
        $TAGS->in_open = '«';
        $TAGS->in_close = '»';
        $TAGS->in_entity = '§';
        $TAGS->in_appletopen = '«applet';
        $TAGS->in_appletclose = '«/applet»';
    }
    $TAGS->out_open = '<';
    $TAGS->out_close = '>';
    $TAGS->out_entity = '&';
    $TAGS->out_amp = '&amp;';
}
function viewfolder($folderid, $userid, $level)
{
    $prefix = "";
    for ($i = 0; $i < $level; $i++) {
        $prefix .= "&gt;";
    }
    $fileprefix = $prefix . "&gt;";
    if ($folderid == -1) {
        $body = <<<END
                <option value="">ROOT</option>
END;
    } else {
        $current_folder = get_record('file_folders', 'owner', $userid, 'ident', $folderid);
        $textlib = textlib_get_instance();
        $name = htmlspecialchars($textlib->strtoupper($current_folder->name));
        $body = <<<END
                    <option value="" title="Folder">{$prefix} {$name}</option>
END;
    }
    if ($files = get_records_select('files', "owner = ? AND folder = ?", array($userid, $folderid))) {
        foreach ($files as $file) {
            $filetitle = htmlspecialchars($file->title);
            $filename = htmlspecialchars($file->originalname);
            if (run("users:access_level_check", $file->access)) {
                $body .= <<<END
                    
                    <option value="{$file->ident}" title="{$filename}">{$fileprefix} {$filetitle}</option>
END;
            }
        }
    }
    if ($folders = get_records_select('file_folders', "owner = ? AND parent = ? ", array($userid, $folderid))) {
        foreach ($folders as $folder) {
            if (run("users:access_level_check", $folder->access)) {
                $body .= viewfolder($folder->ident, $userid, $level + 1);
            }
        }
    }
    return $body;
}
 function definition()
 {
     global $COURSE;
     $mform =& $this->_form;
     if (isset($this->_customdata)) {
         // hardcoding plugin names here is hacky
         $features = $this->_customdata;
     } else {
         $features = array();
     }
     // course id needs to be passed for auth purposes
     $mform->addElement('hidden', 'id', optional_param('id'));
     $mform->setType('id', PARAM_INT);
     $mform->addElement('header', 'general', get_string('importfile', 'grades'));
     // file upload
     $mform->addElement('file', 'userfile', get_string('file'));
     $mform->setType('userfile', PARAM_FILE);
     $mform->addRule('userfile', null, 'required');
     $textlib = textlib_get_instance();
     $encodings = $textlib->get_encodings();
     $mform->addElement('select', 'encoding', get_string('encoding', 'grades'), $encodings);
     if (!empty($features['includeseparator'])) {
         $radio = array();
         $radio[] =& MoodleQuickForm::createElement('radio', 'separator', null, get_string('septab', 'grades'), 'tab');
         $radio[] =& MoodleQuickForm::createElement('radio', 'separator', null, get_string('sepcomma', 'grades'), 'comma');
         $mform->addGroup($radio, 'separator', get_string('separator', 'grades'), ' ', false);
         $mform->setDefault('separator', 'comma');
     }
     if (!empty($features['verbosescales'])) {
         $options = array(1 => get_string('yes'), 0 => get_string('no'));
         $mform->addElement('select', 'verbosescales', get_string('verbosescales', 'grades'), $options);
     }
     $options = array('10' => 10, '20' => 20, '100' => 100, '1000' => 1000, '100000' => 100000);
     $mform->addElement('select', 'previewrows', get_string('rowpreviewnum', 'grades'), $options);
     // TODO: localize
     $mform->setType('previewrows', PARAM_INT);
     $mform->addElement('hidden', 'groupid', groups_get_course_group($COURSE));
     $mform->setType('groupid', PARAM_INT);
     $this->add_action_buttons(false, get_string('uploadgrades', 'grades'));
 }
 public function validation($data, $files)
 {
     global $DB, $CFG;
     $errors = parent::validation($data, $files);
     $instance = $this->instance;
     if ($instance->password) {
         if ($data['enrolpassword'] !== $instance->password) {
             if ($instance->customint1) {
                 $groups = $DB->get_records('groups', array('courseid' => $instance->courseid), 'id ASC', 'id, enrolmentkey');
                 $found = false;
                 foreach ($groups as $group) {
                     if (empty($group->enrolmentkey)) {
                         continue;
                     }
                     if ($group->enrolmentkey === $data['enrolpassword']) {
                         $found = true;
                         break;
                     }
                 }
                 if (!$found) {
                     // We can not hint because there are probably multiple passwords.
                     $errors['enrolpassword'] = get_string('passwordinvalid', 'enrol_license');
                 }
             } else {
                 $plugin = enrol_get_plugin('license');
                 if ($plugin->get_config('showhint')) {
                     $textlib = textlib_get_instance();
                     $hint = $textlib->substr($instance->password, 0, 1);
                     $errors['enrolpassword'] = get_string('passwordinvalidhint', 'enrol_license', $hint);
                 } else {
                     $errors['enrolpassword'] = get_string('passwordinvalid', 'enrol_license');
                 }
             }
         }
     }
     return $errors;
 }
 function user_login($username, $password)
 {
     if (!isset($username) || !isset($password)) {
         return false;
     }
     echo $this->config->host;
     echo $this->config->user;
     echo $this->config->pass;
     $authdb = $this->db_init();
     $textlib = textlib_get_instance();
     $extusername = $textlib->convert(stripslashes($username), 'utf-8', $this->config->extencoding);
     $extpassword = $textlib->convert(stripslashes($password), 'utf-8', $this->config->extencoding);
     $rs = $authdb->Execute("SELECT * FROM {$this->config->table} \n                                WHERE {$this->config->fielduser} = '" . $this->ext_addslashes($extusername) . "' \n                                AND moodle_token = '" . $this->ext_addslashes($extpassword) . "' ");
     if (!$rs) {
         $authdb->Close();
         print_error('auth_dbcantconnect', 'auth');
         return false;
     }
     if (!$rs->EOF) {
         $rs->Close();
         $authdb->Close();
         return true;
     }
 }
Beispiel #30
0
function feedback_check_xml_utf8($text) {
    //find the encoding
    $searchpattern = '/^\<\?xml.+(encoding=\"([a-z0-9-]*)\").+\?\>/is';

    if (!preg_match($searchpattern, $text, $match)) {
        return false; //no xml-file
    }

    //$match[0] = \<\? xml ... \?\> (without \)
    //$match[1] = encoding="...."
    //$match[2] = ISO-8859-1 or so on
    if (isset($match[0]) AND !isset($match[1])) { //no encoding given. we assume utf-8
        return $text;
    }

    //encoding is given in $match[2]
    if (isset($match[0]) AND isset($match[1]) AND isset($match[2])) {
        $enc = $match[2];
        $textlib = textlib_get_instance();
        return $textlib->convert($text, $enc);
    }
}