/** * Form validation * * @param array $data * @param array $files * @return array $errors An array of errors */ function validation($data, $files) { global $COURSE, $DB, $CFG; $errors = parent::validation($data, $files); $name = trim($data['name']); if ($data['id'] and $group = $DB->get_record('groups', array('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->groupenrolmentkeypolicy) 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; }
function definition() { $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', 'local_users'), $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'); } $choices = textlib::get_encodings(); $mform->addElement('select', 'encoding', get_string('encoding', 'local_users'), $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', 'local_users'), $choices); $mform->setType('previewrows', PARAM_INT); $this->add_action_buttons(true, get_string('upload')); }
/** * Form validation * * @param array $data * @param array $files * @return array $errors An array of validataion errors for the form. */ function validation($data, $files) { global $COURSE, $DB; $errors = parent::validation($data, $files); $name = trim($data['name']); if (isset($data['idnumber'])) { $idnumber = trim($data['idnumber']); } else { $idnumber = ''; } if ($data['id'] and $grouping = $DB->get_record('groupings', array('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); } } if (!empty($idnumber) && $grouping->idnumber != $idnumber) { if (groups_get_grouping_by_idnumber($COURSE->id, $idnumber)) { $errors['idnumber'] = get_string('idnumbertaken'); } } } else { if (groups_get_grouping_by_name($COURSE->id, $name)) { $errors['name'] = get_string('groupingnameexists', 'group', $name); } else { if (!empty($idnumber) && groups_get_grouping_by_idnumber($COURSE->id, $idnumber)) { $errors['idnumber'] = get_string('idnumbertaken'); } } } return $errors; }
public 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', 'tool_uploaduser'), $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'); } } $choices = textlib::get_encodings(); $mform->addElement('select', 'encoding', get_string('encoding', 'tool_uploaduser'), $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', 'tool_uploaduser'), $choices); $mform->setType('previewrows', PARAM_INT); $choices = array(UU_ADDNEW => get_string('uuoptype_addnew', 'tool_uploaduser'), UU_ADDINC => get_string('uuoptype_addinc', 'tool_uploaduser'), UU_ADD_UPDATE => get_string('uuoptype_addupdate', 'tool_uploaduser'), UU_UPDATE => get_string('uuoptype_update', 'tool_uploaduser')); $mform->addElement('select', 'uutype', get_string('uuoptype', 'tool_uploaduser'), $choices); $this->add_action_buttons(false, get_string('uploadusers', 'tool_uploaduser')); }
function definition() { global $CFG; $mform = & $this->_form; $course = $this->_customdata['course']; $context = $this->_customdata['context']; // the upload manager is used directly in post precessing, moodleform::save_files() is not used yet //$this->set_upload_manager(new upload_manager('attachment')); $mform->addElement('header', 'general', ''); //fill in the data depending on page params //later using set_data $mform->addElement('filepicker', 'attachment', get_string('location', 'enrol_flatfile')); $mform->addRule('attachment', null, 'required'); $choices = csv_import_reader::get_delimiter_list(); $mform->addElement('select', 'delimiter_name', get_string('csvdelimiter', 'tool_uploaduser'), $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'); } $choices = textlib::get_encodings(); $mform->addElement('select', 'encoding', get_string('encoding', 'tool_uploaduser'), $choices); $mform->setDefault('encoding', 'UTF-8'); $roles = get_assignable_roles($context); $mform->addElement('select', 'roleassign', get_string('roleassign', 'local_mass_enroll'), $roles); $mform->setDefault('roleassign', 5); //student $ids = array ( 'idnumber' => get_string('idnumber', 'local_mass_enroll'), 'username' => get_string('username', 'local_mass_enroll'), 'email' => get_string('email') ); $mform->addElement('select', 'firstcolumn', get_string('firstcolumn', 'local_mass_enroll'), $ids); $mform->setDefault('firstcolumn', 'idnumber'); $mform->addElement('selectyesno', 'creategroups', get_string('creategroups', 'local_mass_enroll')); $mform->setDefault('creategroups', 1); $mform->addElement('selectyesno', 'creategroupings', get_string('creategroupings', 'local_mass_enroll')); $mform->setDefault('creategroupings', 1); $mform->addElement('selectyesno', 'mailreport', get_string('mailreport', 'local_mass_enroll')); $mform->setDefault('mailreport', 1); //------------------------------------------------------------------------------- // buttons $this->add_action_buttons(true, get_string('enroll', 'local_mass_enroll')); $mform->addElement('hidden', 'id', $course->id); $mform->setType('id', PARAM_INT); }
function csv_quote($value) { global $excel; if ($excel) { return textlib::convert('"'.str_replace('"',"'",$value).'"','UTF-8','UTF-16LE'); } else { return '"'.str_replace('"',"'",$value).'"'; } }
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('& so is this', FORMAT_HTML)); $this->assertEqual('Two bullets: ' . textlib::code2utf8(8226) . ' *', format_text_email('Two bullets: • •', FORMAT_HTML)); $this->assertEqual(textlib::code2utf8(0x7fd2) . textlib::code2utf8(0x7fd2), format_text_email('習習', FORMAT_HTML)); }
function definition() { $mform =& $this->_form; $mform->addElement('file', 'userfile', get_string('csvtextfile', 'facetoface')); $mform->setType('userfile', PARAM_FILE); $mform->addRule('userfile', null, 'required'); $encodings = textlib::get_encodings(); $mform->addElement('select', 'encoding', get_string('encoding', 'grades'), $encodings); $mform->addElement('checkbox', 'suppressemail', '', get_string('suppressemailforattendees', 'facetoface')); }
/** * Validates a value using a range comparison * * @param string $value Value to be checked * @param mixed $options Int for length, array for range * @access public * @return boolean true if value is valid */ function validate($value, $options = null) { $length = textlib::strlen($value); switch ($this->name) { case 'minlength': return $length >= $options; case 'maxlength': return $length <= $options; default: return $length >= $options[0] && $length <= $options[1]; } }
/** * Use internal moodles own textlib to encode mimeheaders. * Fall back to phpmailers inbuilt functions if not */ public function EncodeHeader($str, $position = 'text') { $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); }
/** * @uses LABEL_MAX_NAME_LENGTH * @param object $label * @return string */ function get_label_name($label) { $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; }
function game_cross_new($game, $attemptid, &$crossm) { global $DB, $USER; $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] = game_repairquestion($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); //game->param2 is maximum words in crossword if ($cross->computedata($crossm, $crossd, $lettets, $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->savecross($game, $crossm, $new_crossd, $attemptid); } if (count($crossd) == 0) { print_error('game_cross_continue: ' . get_string('no_words', 'game')); } }
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', 0, PARAM_INT)); $mform->setType('id', PARAM_INT); $mform->addElement('header', 'general', get_string('importfile', 'grades')); // Restrict the possible upload file types. if (!empty($features['acceptedtypes'])) { $acceptedtypes = $features['acceptedtypes']; } else { $acceptedtypes = '*'; } // File upload. $mform->addElement('filepicker', 'userfile', get_string('file'), null, array('accepted_types' => $acceptedtypes)); $mform->addRule('userfile', null, 'required'); $encodings = textlib::get_encodings(); $mform->addElement('select', 'encoding', get_string('encoding', 'grades'), $encodings); if (!empty($features['includeseparator'])) { $radio = array(); $radio[] = $mform->createElement('radio', 'separator', null, get_string('septab', 'grades'), 'tab'); $radio[] = $mform->createElement('radio', 'separator', null, get_string('sepcomma', 'grades'), 'comma'); $radio[] = $mform->createElement('radio', 'separator', null, get_string('sepcolon', 'grades'), 'colon'); $radio[] = $mform->createElement('radio', 'separator', null, get_string('sepsemicolon', 'grades'), 'semicolon'); $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['guestpassword'] !== $instance->password) { $plugin = enrol_get_plugin('guest'); if ($plugin->get_config('showhint')) { $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; }
protected function action($message, $level, $options = null) { $columns = $this->columns; if ($this->datecol) { $columns[$this->datecol] = time(); } if ($this->levelcol) { $columns[$this->levelcol] = $level; } $message = clean_param($message, PARAM_NOTAGS); // Check if the message exceeds the 255 character limit in the database, // if it does, shorten it so that it can be inserted successfully. if (textlib::strlen($message) > 255) { $message = textlib::substr($message, 0, 252) . '...'; } $columns[$this->messagecol] = $message; return $this->insert_log_record($this->logtable, $columns); }
protected function check_table(xmldb_table $xmldb_table, array $metacolumns) { global $DB; $o = ''; $wrong_fields = array(); // Get and process XMLDB fields if ($xmldb_fields = $xmldb_table->getFields()) { $o .= '<ul>'; foreach ($xmldb_fields as $xmldb_field) { // Get the type of the column, we only will process CHAR (VARCHAR2) ones if ($xmldb_field->getType() != XMLDB_TYPE_CHAR) { continue; } $o .= '<li>' . $this->str['field'] . ': ' . $xmldb_field->getName() . ' '; // Get current semantic from dictionary, we only will process B (BYTE) ones // suplying the SQL code to change them to C (CHAR) semantic $params = array('table_name' => textlib::strtoupper($DB->get_prefix() . $xmldb_table->getName()), 'column_name' => textlib::strtoupper($xmldb_field->getName()), 'data_type' => 'VARCHAR2'); $currentsemantic = $DB->get_field_sql(' SELECT char_used FROM user_tab_columns WHERE table_name = :table_name AND column_name = :column_name AND data_type = :data_type', $params); // If using byte semantics, we'll need to change them to char semantics if ($currentsemantic == 'B') { $info = '(' . $this->str['expected'] . " 'CHAR', " . $this->str['actual'] . " 'BYTE')"; $o .= '<font color="red">' . $this->str['wrong'] . " {$info}</font>"; // Add the wrong field to the list $obj = new stdClass(); $obj->table = $xmldb_table; $obj->field = $xmldb_field; $wrong_fields[] = $obj; } else { $o .= '<font color="green">' . $this->str['ok'] . '</font>'; } $o .= '</li>'; } $o .= '</ul>'; } return array($o, $wrong_fields); }
/** * Update a user with a user object (will compare against the ID) * * @param object $user the user to update */ function user_update_user($user) { global $DB; // set the timecreate field to the current time if (!is_object($user)) { $user = (object) $user; } //check username if (isset($user->username)) { if ($user->username !== textlib::strtolower($user->username)) { throw new moodle_exception('usernamelowercase'); } else { if ($user->username !== clean_param($user->username, PARAM_USERNAME)) { throw new moodle_exception('invalidusername'); } } } // unset password here, for updating later if (isset($user->password)) { //check password toward the password policy if (!check_password_policy($user->password, $errmsg)) { throw new moodle_exception($errmsg); } $passwd = $user->password; unset($user->password); } $user->timemodified = time(); $DB->update_record('user', $user); // trigger user_updated event on the full database user row $updateduser = $DB->get_record('user', array('id' => $user->id)); // if password was set, then update its hash if (isset($passwd)) { $authplugin = get_auth_plugin($updateduser->auth); if ($authplugin->can_change_password()) { $authplugin->user_update_password($updateduser, $passwd); } } events_trigger('user_updated', $updateduser); add_to_log(SITEID, 'user', get_string('update'), '/view.php?id=' . $updateduser->id, fullname($updateduser)); }
function definition() { global $CFG; $mform = & $this->_form; //$mform->addElement('header', 'general', get_string('bulkenrol','block_learning_plan')); //fill in the data depending on page params //later using set_data $mform->addElement('filepicker', 'attachment', get_string('location', 'enrol_flatfile')); $mform->addRule('attachment', null, 'required'); $choices = csv_import_reader::get_delimiter_list(); $mform->addElement('select', 'delimiter_name', get_string('csvdelimiter', 'tool_uploaduser'), $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'); } $choices = textlib::get_encodings(); $mform->addElement('select', 'encoding', get_string('encoding', 'tool_uploaduser'), $choices); $mform->setDefault('encoding', 'UTF-8'); $mform->addElement('hidden','roleassign'); $mform->setDefault('roleassign', 5); //student $mform->setType('roleassign','int'); $ids = array ( 'username' => get_string('username', 'local_mass_enroll'), 'idnumber' => get_string('idnumber', 'local_mass_enroll'), 'email' => get_string('email') ); $mform->addElement('select', 'firstcolumn', get_string('firstcolumn', 'block_learning_plan'), $ids); $mform->setDefault('firstcolumn', 'username'); //$mform->addElement('selectyesno', 'mailreport', get_string('mailreport', 'local_mass_enroll')); //$mform->setDefault('mailreport', 1); $this->add_action_buttons(true, get_string('enroll_lp', 'block_learning_plan')); }
function rfc2445_fold($string) { if (textlib::strlen($string, 'utf-8') <= RFC2445_FOLDED_LINE_LENGTH) { return $string; } $retval = ''; $i = 0; $len_count = 0; //multi-byte string, get the correct length $section_len = textlib::strlen($string, 'utf-8'); while ($len_count < $section_len) { //get the current portion of the line $section = textlib::substr($string, $i * RFC2445_FOLDED_LINE_LENGTH, RFC2445_FOLDED_LINE_LENGTH, 'utf-8'); //increment the length we've processed by the length of the new portion $len_count += textlib::strlen($section, 'utf-8'); /* Add the portion to the return value, terminating with CRLF.HTAB As per RFC 2445, CRLF.HTAB will be replaced by the processor of the data */ $retval .= $section . RFC2445_CRLF . RFC2445_WSP; $i++; } return $retval; }
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')); $choices = textlib::get_encodings(); $mform->addElement('select', 'encoding', get_string('fileencoding', 'mod_data'), $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); }
/** * Migrate giportfolio files stored in moddata folders. * * Please note it was a big mistake to store the files there in the first place! * * @param stdClass $giportfolio * @param stdClass $context * @param string $path * @return void */ function mod_giportfolio_migrate_moddata_dir_to_legacy($giportfolio, $context, $path) { global $OUTPUT, $CFG; $base = "{$CFG->dataroot}/{$giportfolio->course}/{$CFG->moddata}/giportfolio/{$giportfolio->id}"; $fulldir = $base . $path; if (!is_dir($fulldir)) { // Does not exist. return; } $fs = get_file_storage(); $items = new DirectoryIterator($fulldir); foreach ($items as $item) { if ($item->isDot()) { unset($item); // Release file handle. continue; } if ($item->isLink()) { // Do not follow symlinks - they were never supported in moddata, sorry. unset($item); // Release file handle. continue; } if ($item->isFile()) { if (!$item->isReadable()) { echo $OUTPUT->notification(" File not readable, skipping: " . $fulldir . $item->getFilename()); unset($item); // Release file handle. continue; } $filepath = clean_param("/{$CFG->moddata}/giportfolio/{$giportfolio->id}" . $path, PARAM_PATH); $filename = clean_param($item->getFilename(), PARAM_FILE); if ($filename === '') { // Unsupported chars, sorry. unset($item); // Release file handle. continue; } if (textlib::strlen($filepath) > 255) { echo $OUTPUT->notification(" File path longer than 255 chars, skipping: " . $fulldir . $item->getFilename()); unset($item); // Release file handle. continue; } if (!$fs->file_exists($context->id, 'course', 'legacy', '0', $filepath, $filename)) { $filerecord = array('contextid' => $context->id, 'component' => 'course', 'filearea' => 'legacy', 'itemid' => 0, 'filepath' => $filepath, 'filename' => $filename, 'timecreated' => $item->getCTime(), 'timemodified' => $item->getMTime()); $fs->create_file_from_pathname($filerecord, $fulldir . $item->getFilename()); } $oldpathname = $fulldir . $item->getFilename(); unset($item); // Release file handle. @unlink($oldpathname); } else { // Migrate recursively all subdirectories. $oldpathname = $base . $item->getFilename() . '/'; $subpath = $path . $item->getFilename() . '/'; unset($item); // Release file handle. giportfolio_migrate_moddata_dir_to_legacy($giportfolio, $context, $subpath); @rmdir($oldpathname); // Deletes dir if empty. } } unset($items); // Release file handles. }
/** * Update categories * * @param array $categories The list of categories to update * @return null * @since Moodle 2.3 */ public static function update_categories($categories) { global $CFG, $DB; require_once $CFG->dirroot . "/course/lib.php"; // Validate parameters. $params = self::validate_parameters(self::update_categories_parameters(), array('categories' => $categories)); $transaction = $DB->start_delegated_transaction(); foreach ($params['categories'] as $cat) { if (!($category = $DB->get_record('course_categories', array('id' => $cat['id'])))) { throw new moodle_exception('unknowcategory'); } $categorycontext = context_coursecat::instance($cat['id']); self::validate_context($categorycontext); require_capability('moodle/category:manage', $categorycontext); if (!empty($cat['name'])) { if (textlib::strlen($cat['name']) > 255) { throw new moodle_exception('categorytoolong'); } $category->name = $cat['name']; } if (!empty($cat['idnumber'])) { if (textlib::strlen($cat['idnumber']) > 100) { throw new moodle_exception('idnumbertoolong'); } $category->idnumber = $cat['idnumber']; } if (!empty($cat['description'])) { $category->description = $cat['description']; $category->descriptionformat = external_validate_format($cat['descriptionformat']); } if (!empty($cat['theme'])) { $category->theme = $cat['theme']; } if (!empty($cat['parent']) && $category->parent != $cat['parent']) { // First check if parent exists. if (!($parent_cat = $DB->get_record('course_categories', array('id' => $cat['parent'])))) { throw new moodle_exception('unknowcategory'); } // Then check if we have capability. self::validate_context(get_category_or_system_context((int) $cat['parent'])); require_capability('moodle/category:manage', get_category_or_system_context((int) $cat['parent'])); // Finally move the category. move_category($category, $parent_cat); $category->parent = $cat['parent']; // Get updated path by move_category(). $category->path = $DB->get_field('course_categories', 'path', array('id' => $category->id)); } $DB->update_record('course_categories', $category); } $transaction->allow_commit(); }
message_send($eventdata); message_paypal_error_to_admin("Payment pending", $data); die; } // If our status is not completed or not pending on an echeck clearance then ignore and die // This check is redundant at present but may be useful if paypal extend the return codes in the future if (!($data->payment_status == "Completed" or $data->payment_status == "Pending" and $data->pending_reason == "echeck")) { die; } // At this point we only proceed with a status of completed or pending with a reason of echeck if ($existing = $DB->get_record("enrol_paypal", array("txn_id" => $data->txn_id))) { // Make sure this transaction doesn't exist already message_paypal_error_to_admin("Transaction {$data->txn_id} is being repeated!", $data); die; } if (textlib::strtolower($data->business) !== textlib::strtolower($plugin->get_config('paypalbusiness'))) { // Check that the email is the one we want it to be message_paypal_error_to_admin("Business email is {$data->business} (not " . $plugin->get_config('paypalbusiness') . ")", $data); die; } if (!($user = $DB->get_record('user', array('id' => $data->userid)))) { // Check that user exists message_paypal_error_to_admin("User {$data->userid} doesn't exist", $data); die; } if (!($course = $DB->get_record('course', array('id' => $data->courseid)))) { // Check that course exists message_paypal_error_to_admin("Course {$data->courseid} doesn't exist", $data); die; } $coursecontext = context_course::instance($course->id, IGNORE_MISSING);
print_course_search('', false, 'short'); } break; case FRONTPAGECATEGORYNAMES: echo html_writer::tag('a', get_string('skipa', 'access', textlib::strtolower(get_string('categories'))), array('href'=>'#skipcategories', 'class'=>'skip-block')); echo $OUTPUT->heading(get_string('categories'), 2, 'headingblock header'); echo $OUTPUT->box_start('generalbox categorybox'); print_whole_category_list(NULL, NULL, NULL, -1, false); echo $OUTPUT->box_end(); print_course_search('', false, 'short'); echo html_writer::tag('span', '', array('class'=>'skip-block-to', 'id'=>'skipcategories')); break; case FRONTPAGECATEGORYCOMBO: echo html_writer::tag('a', get_string('skipa', 'access', textlib::strtolower(get_string('courses'))), array('href'=>'#skipcourses', 'class'=>'skip-block')); echo $OUTPUT->heading(get_string('courses'), 2, 'headingblock header'); $renderer = $PAGE->get_renderer('core','course'); // if there are too many courses, budiling course category tree could be slow, // users should go to course index page to see the whole list. $coursecount = $DB->count_records('course'); if (empty($CFG->numcoursesincombo)) { // if $CFG->numcoursesincombo hasn't been set, use default value 500 $CFG->numcoursesincombo = 500; } if ($coursecount > $CFG->numcoursesincombo) { $link = new moodle_url('/course/'); echo $OUTPUT->notification(get_string('maxnumcoursesincombo', 'moodle', array('link'=>$link->out(), 'maxnumofcourses'=>$CFG->numcoursesincombo, 'numberofcourses'=>$coursecount))); } else { echo $renderer->course_category_tree(get_course_category_tree()); }
function my_link_sort($a, $b) { $a = textlib::strtolower(substr($a->link, strpos($a->link, '>') + 1)); $b = textlib::strtolower(substr($b->link, strpos($b->link, '>') + 1)); return strcmp($a, $b); }
protected function db_decode($text) { $dbenc = $this->get_config('dbencoding'); if (empty($dbenc) or $dbenc == 'utf-8') { return $text; } if (is_array($text)) { foreach ($text as $k => $value) { $text[$k] = $this->db_decode($value); } return $text; } else { return textlib::convert($text, $dbenc, 'utf-8'); } }
} $permissiongranted = 1; if ( $newentry->concept and $newentry->definition ) { if ( !$glossary->allowduplicatedentries ) { // checking if the entry is valid (checking if it is duplicated when should not be) if ( $newentry->casesensitive ) { $dupentry = $DB->record_exists_select('glossary_entries', 'glossaryid = :glossaryid AND concept = :concept', array( 'glossaryid' => $glossary->id, 'concept' => $newentry->concept)); } else { $dupentry = $DB->record_exists_select('glossary_entries', 'glossaryid = :glossaryid AND LOWER(concept) = :concept', array( 'glossaryid' => $glossary->id, 'concept' => textlib::strtolower($newentry->concept))); } if ($dupentry) { $permissiongranted = 0; } } } else { $permissiongranted = 0; } if ($permissiongranted) { $newentry->glossaryid = $glossary->id; $newentry->sourceglossaryid = 0; $newentry->approved = 1; $newentry->userid = $USER->id; $newentry->teacherentry = 1; $newentry->definitionformat = $xmlentry['#']['FORMAT'][0]['#'];
/** * Prints the page list tab content * * */ private function print_page_list_content() { global $OUTPUT; $page = $this->page; if ($page->timerendered + WIKI_REFRESH_CACHE_TIME < time()) { $fresh = wiki_refresh_cachedcontent($page); $page = $fresh['page']; } $pages = wiki_get_page_list($this->subwiki->id); $stdaux = new stdClass(); $strspecial = get_string('special', 'wiki'); foreach ($pages as $page) { // We need to format the title here to account for any filtering $letter = format_string($page->title, true, array('context' => $this->modcontext)); $letter = textlib::substr($letter, 0, 1); if (preg_match('/^[a-zA-Z]$/', $letter)) { $letter = textlib::strtoupper($letter); $stdaux->{$letter}[] = wiki_parser_link($page); } else { $stdaux->{$strspecial}[] = wiki_parser_link($page); } } $table = new html_table(); $table->head = array(get_string('pagelist', 'wiki') . $OUTPUT->help_icon('pagelist', 'wiki')); $table->attributes['class'] = 'wiki_editor generalbox'; $table->align = array('center'); foreach ($stdaux as $key => $elem) { $table->data[] = array($key); foreach ($elem as $e) { $table->data[] = array(html_writer::link($e['url'], format_string($e['content'], true, array('context' => $this->modcontext)))); } } echo html_writer::table($table); }
/** * Adds branches and links to the settings navigation to add course activities * and resources. * * @param stdClass $course */ protected function add_course_editing_links($course) { global $CFG; require_once $CFG->dirroot . '/course/lib.php'; // Add `add` resources|activities branches $structurefile = $CFG->dirroot . '/course/format/' . $course->format . '/lib.php'; if (file_exists($structurefile)) { require_once $structurefile; $requestkey = call_user_func('callback_' . $course->format . '_request_key'); $formatidentifier = optional_param($requestkey, 0, PARAM_INT); } else { $requestkey = get_string('section'); $formatidentifier = optional_param($requestkey, 0, PARAM_INT); } $modinfo = get_fast_modinfo($course); $sections = $modinfo->get_section_info_all(); $addresource = $this->add(get_string('addresource')); $addactivity = $this->add(get_string('addactivity')); if ($formatidentifier !== 0) { $addresource->force_open(); $addactivity->force_open(); } $this->get_course_modules($course); foreach ($sections as $section) { if ($formatidentifier !== 0 && $section->section != $formatidentifier) { continue; } $sectionurl = new moodle_url('/course/view.php', array('id' => $course->id, $requestkey => $section->section)); if ($section->section == 0) { $sectionresources = $addresource->add(get_string('course'), $sectionurl, self::TYPE_SETTING); $sectionactivities = $addactivity->add(get_string('course'), $sectionurl, self::TYPE_SETTING); } else { $sectionname = get_section_name($course, $section); $sectionresources = $addresource->add($sectionname, $sectionurl, self::TYPE_SETTING); $sectionactivities = $addactivity->add($sectionname, $sectionurl, self::TYPE_SETTING); } foreach ($resources as $value => $resource) { $url = new moodle_url('/course/mod.php', array('id' => $course->id, 'sesskey' => sesskey(), 'section' => $section->section)); $pos = strpos($value, '&type='); if ($pos !== false) { $url->param('add', textlib::substr($value, 0, $pos)); $url->param('type', textlib::substr($value, $pos + 6)); } else { $url->param('add', $value); } $sectionresources->add($resource, $url, self::TYPE_SETTING); } $subbranch = false; foreach ($activities as $activityname => $activity) { if ($activity === '--') { $subbranch = false; continue; } if (strpos($activity, '--') === 0) { $subbranch = $sectionactivities->add(trim($activity, '-')); continue; } $url = new moodle_url('/course/mod.php', array('id' => $course->id, 'sesskey' => sesskey(), 'section' => $section->section)); $pos = strpos($activityname, '&type='); if ($pos !== false) { $url->param('add', textlib::substr($activityname, 0, $pos)); $url->param('type', textlib::substr($activityname, $pos + 6)); } else { $url->param('add', $activityname); } if ($subbranch !== false) { $subbranch->add($activity, $url, self::TYPE_SETTING); } else { $sectionactivities->add($activity, $url, self::TYPE_SETTING); } } } }
/** * Add a link to the session to the courses calendar. * * @param class $session Record from the facetoface_sessions table * @param class $eventname Name to display for this event * @param string $calendartype Which calendar to add the event to (user, course, site) * @param int $userid Optional param for user calendars * @param string $eventtype Optional param for user calendar (booking/session) */ function facetoface_add_session_to_calendar($session, $facetoface, $calendartype = 'none', $userid = 0, $eventtype = 'session') { global $CFG, $DB; if (empty($session->datetimeknown)) { return true; //date unkown, can't add to calendar } if (empty($facetoface->showoncalendar) && empty($facetoface->usercalentry)) { return true; //facetoface calendar settings prevent calendar } $description = ''; if (!empty($facetoface->description)) { $description .= html_writer::tag('p', clean_param($facetoface->description, PARAM_CLEANHTML)); } $description .= facetoface_print_session($session, false, true, true); $linkurl = new moodle_url('/mod/facetoface/signup.php', array('s' => $session->id)); $linktext = get_string('signupforthissession', 'facetoface'); if ($calendartype == 'site' && $facetoface->showoncalendar == F2F_CAL_SITE) { $courseid = SITEID; $description .= html_writer::link($linkurl, $linktext); } else if ($calendartype == 'course' && $facetoface->showoncalendar == F2F_CAL_COURSE) { $courseid = $facetoface->course; $description .= html_writer::link($linkurl, $linktext); } else if ($calendartype == 'user' && $facetoface->usercalentry) { $courseid = 0; $urlvar = ($eventtype == 'session') ? 'attendees' : 'signup'; $linkurl = $CFG->wwwroot . "/mod/facetoface/" . $urlvar . ".php?s=$session->id"; $description .= get_string("calendareventdescription{$eventtype}", 'facetoface', $linkurl); } else { return true; } $shortname = $facetoface->shortname; if (empty($shortname)) { $shortname = textlib::substr($facetoface->name, 0, CALENDAR_MAX_NAME_LENGTH); } $result = true; foreach ($session->sessiondates as $date) { $newevent = new stdClass(); $newevent->name = $shortname; $newevent->description = $description; $newevent->format = FORMAT_HTML; $newevent->courseid = $courseid; $newevent->groupid = 0; $newevent->userid = $userid; $newevent->uuid = "{$session->id}"; $newevent->instance = $session->facetoface; $newevent->modulename = 'facetoface'; $newevent->eventtype = "facetoface{$eventtype}"; $newevent->timestart = $date->timestart; $newevent->timeduration = $date->timefinish - $date->timestart; $newevent->visible = 1; $newevent->timemodified = time(); if ($calendartype == 'user' && $eventtype == 'booking') { //Check for and Delete the 'created' calendar event to reduce multiple entries for the same event $DB->delete_records('event', array('userid' => $userid, 'instance' => $session->facetoface, 'eventtype' => 'facetofacesession')); } $result = $result && $DB->insert_record('event', $newevent); } return $result; }