function xmldb_qtype_match_upgrade($oldversion) { global $CFG, $DB, $QTYPES; $dbman = $DB->get_manager(); if ($oldversion < 2009072100) { // Define field questiontextformat to be added to question_match_sub $table = new xmldb_table('question_match_sub'); $field = new xmldb_field('questiontextformat', XMLDB_TYPE_INTEGER, '2', null, XMLDB_NOTNULL, null, '0', 'questiontext'); // Conditionally launch add field questiontextformat if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field); } // In the past, question_match_sub.questiontext assumed to contain // content of the same form as question.questiontextformat. If we are // using the HTML editor, then convert FORMAT_MOODLE content to FORMAT_HTML. $rs = $DB->get_recordset_sql(' SELECT qms.*, q.oldquestiontextformat FROM {question_match_sub} qms JOIN {question} q ON qms.question = q.id'); foreach ($rs as $record) { if ($CFG->texteditors !== 'textarea' && $record->oldquestiontextformat == FORMAT_MOODLE) { $record->questiontext = text_to_html($record->questiontext, false, false, true); $record->questiontextformat = FORMAT_HTML; } else { $record->questiontextformat = $record->oldquestiontextformat; } $DB->update_record('question_match_sub', $record); } $rs->close(); // match savepoint reached upgrade_plugin_savepoint(true, 2009072100, 'qtype', 'match'); } return true; }
/** * Converts /MOODLE_BACKUP/COURSE/MODULES/MOD/FORUM data */ public function process_forum($data) { global $CFG; // get the course module id and context id $instanceid = $data['id']; $cminfo = $this->get_cminfo($instanceid); $this->moduleid = $cminfo['id']; $contextid = $this->converter->get_contextid(CONTEXT_MODULE, $this->moduleid); // get a fresh new file manager for this instance $this->fileman = $this->converter->get_file_manager($contextid, 'mod_forum'); // convert course files embedded into the intro $this->fileman->filearea = 'intro'; $this->fileman->itemid = 0; $data['intro'] = moodle1_converter::migrate_referenced_files($data['intro'], $this->fileman); // Convert the introformat if necessary. if ($CFG->texteditors !== 'textarea') { $data['intro'] = text_to_html($data['intro'], false, false, true); $data['introformat'] = FORMAT_HTML; } // start writing forum.xml $this->open_xml_writer("activities/forum_{$this->moduleid}/forum.xml"); $this->xmlwriter->begin_tag('activity', array('id' => $instanceid, 'moduleid' => $this->moduleid, 'modulename' => 'forum', 'contextid' => $contextid)); $this->xmlwriter->begin_tag('forum', array('id' => $instanceid)); foreach ($data as $field => $value) { if ($field != 'id') { $this->xmlwriter->full_tag($field, $value); } } $this->xmlwriter->begin_tag('discussions'); return $data; }
/** * Converts the multichoice info and writes it into the question.xml * * @param array $multichoices the grouped structure * @param int $oldquestiontextformat - {@see moodle1_question_bank_handler::process_question()} */ protected function write_multichoice(array $multichoices, $oldquestiontextformat) { global $CFG; // the grouped array is supposed to have just one element - let us use foreach anyway // just to be sure we do not loose anything foreach ($multichoices as $multichoice) { // append an artificial 'id' attribute (is not included in moodle.xml) $multichoice['id'] = $this->converter->get_nextid(); // replay the upgrade step 2009021801 $multichoice['correctfeedbackformat'] = 0; $multichoice['partiallycorrectfeedbackformat'] = 0; $multichoice['incorrectfeedbackformat'] = 0; if ($CFG->texteditors !== 'textarea' and $oldquestiontextformat == FORMAT_MOODLE) { $multichoice['correctfeedback'] = text_to_html($multichoice['correctfeedback'], false, false, true); $multichoice['correctfeedbackformat'] = FORMAT_HTML; $multichoice['partiallycorrectfeedback'] = text_to_html($multichoice['partiallycorrectfeedback'], false, false, true); $multichoice['partiallycorrectfeedbackformat'] = FORMAT_HTML; $multichoice['incorrectfeedback'] = text_to_html($multichoice['incorrectfeedback'], false, false, true); $multichoice['incorrectfeedbackformat'] = FORMAT_HTML; } else { $multichoice['correctfeedbackformat'] = $oldquestiontextformat; $multichoice['partiallycorrectfeedbackformat'] = $oldquestiontextformat; $multichoice['incorrectfeedbackformat'] = $oldquestiontextformat; } $this->write_xml('multichoice', $multichoice, array('/multichoice/id')); } }
function xmldb_survey_upgrade($oldversion) { global $CFG, $DB; $dbman = $DB->get_manager(); //===== 1.9.0 upgrade line ======// if ($oldversion < 2009042002) { /// Define field introformat to be added to survey $table = new xmldb_table('survey'); $field = new xmldb_field('introformat', XMLDB_TYPE_INTEGER, '4', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'intro'); /// Conditionally launch add field introformat if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field); } // conditionally migrate to html format in intro if ($CFG->texteditors !== 'textarea') { $rs = $DB->get_recordset('survey', array('introformat' => FORMAT_MOODLE), '', 'id,intro,introformat'); foreach ($rs as $s) { $s->intro = text_to_html($s->intro, false, false, true); $s->introformat = FORMAT_HTML; $DB->update_record('survey', $s); upgrade_set_timeout(); } $rs->close(); } /// survey savepoint reached upgrade_mod_savepoint(true, 2009042002, 'survey'); } return true; }
protected function process_rcontent($data) { global $DB; $data = (object) $data; $oldid = $data->id; $data->levelid = $this->get_level($data->levelcode, $data->name); $this->current_isbn = isset($data->isbn) ? $data->isbn : false; $data->bookid = $this->get_book_id($this->current_isbn, $data->name); $this->current_book_id = $data->bookid; $data->unitid = $this->get_unit_id($data->unitcode); $data->activityid = $this->get_activity_id($data->activitycode, $data->unitid); if (!isset($data->intro) && isset($data->summary)) { $data->intro = $data->summary; if ($CFG->texteditors !== 'textarea') { $data->intro = text_to_html($data->intro, false, false, true); } $data->introformat = FORMAT_HTML; } $data->course = $this->get_courseid(); $data->timecreated = $this->apply_date_offset($data->timecreated); $data->timemodified = $this->apply_date_offset($data->timemodified); // insert the scorm record $newitemid = $DB->insert_record('rcontent', $data); // immediately after inserting "activity" record, call this $this->apply_activity_instance($newitemid); }
/** * Appends the match specific information to the question */ public function process_question(array $data, array $raw) { global $CFG; // populate the list of matches first to get their ids // note that the field is re-populated on restore anyway but let us // do our best to produce valid backup files $matchids = array(); if (isset($data['matchs']['match'])) { foreach ($data['matchs']['match'] as $match) { $matchids[] = $match['id']; } } // convert match options $matchoptions = $data['matchoptions'][0]; $matchoptions['id'] = $this->converter->get_nextid(); $matchoptions['subquestions'] = implode(',', $matchids); $this->write_xml('matchoptions', $matchoptions, array('/matchoptions/id')); // convert matches $this->xmlwriter->begin_tag('matches'); if (isset($data['matchs']['match'])) { foreach ($data['matchs']['match'] as $match) { // replay the upgrade step 2009072100 $match['questiontextformat'] = 0; if ($CFG->texteditors !== 'textarea' and $data['oldquestiontextformat'] == FORMAT_MOODLE) { $match['questiontext'] = text_to_html($match['questiontext'], false, false, true); $match['questiontextformat'] = FORMAT_HTML; } else { $match['questiontextformat'] = $data['oldquestiontextformat']; } $this->write_xml('match', $match, array('/match/id')); } } $this->xmlwriter->end_tag('matches'); }
function save_text_to_html($string) { //$string = strip_tags(trim($string)); //$string= htmlspecialchars(trim($string)); $string= text_to_html($string); $string = preg_replace("/\r\n|\r|\n/", "\n<br />\n", $string); return $string; }
/** * This is executed every time we have one /MOODLE_BACKUP/COURSE/MODULES/MOD/giportfolio * data available * @param array $data */ public function process_giportfolio($data) { global $CFG; // Get the course module id and context id. $instanceid = $data['id']; $cminfo = $this->get_cminfo($instanceid); $this->moduleid = $cminfo['id']; $contextid = $this->converter->get_contextid(CONTEXT_MODULE, $this->moduleid); // Replay the upgrade step 2009042006. if ($CFG->texteditors !== 'textarea') { $data['intro'] = text_to_html($data['intro'], false, false, true); $data['introformat'] = FORMAT_HTML; } // Get a fresh new file manager for this instance. $this->fileman = $this->converter->get_file_manager($contextid, 'mod_giportfolio'); // Convert course files embedded into the intro. $this->fileman->filearea = 'intro'; $this->fileman->itemid = 0; $data['intro'] = moodle1_converter::migrate_referenced_files($data['intro'], $this->fileman); // Start writing giportfolio.xml. $this->open_xml_writer("activities/giportfolio_{$this->moduleid}/giportfolio.xml"); $this->xmlwriter->begin_tag('activity', array('id' => $instanceid, 'moduleid' => $this->moduleid, 'modulename' => 'giportfolio', 'contextid' => $contextid)); $this->xmlwriter->begin_tag('giportfolio', array('id' => $instanceid)); foreach ($data as $field => $value) { if ($field != 'id') { $this->xmlwriter->full_tag($field, $value); } } }
/** * This is executed every time we have one /MOODLE_BACKUP/COURSE/MODULES/MOD/ASSIGNMENT * data available */ public function process_assignment($data) { global $CFG; // get the course module id and context id $instanceid = $data['id']; $cminfo = $this->get_cminfo($instanceid); $this->moduleid = $cminfo['id']; $contextid = $this->converter->get_contextid(CONTEXT_MODULE, $this->moduleid); //store assignment type for possible subplugin conversions. $this->currentsubpluginname = $data['assignmenttype']; // get a fresh new file manager for this instance $this->fileman = $this->converter->get_file_manager($contextid, 'mod_assignment'); // convert course files embedded into the intro $this->fileman->filearea = 'intro'; $this->fileman->itemid = 0; $data['intro'] = moodle1_converter::migrate_referenced_files($data['intro'], $this->fileman); // convert the introformat if necessary if ($CFG->texteditors !== 'textarea') { $data['intro'] = text_to_html($data['intro'], false, false, true); $data['introformat'] = FORMAT_HTML; } // start writing assignment.xml $this->open_xml_writer("activities/assignment_{$this->moduleid}/assignment.xml"); $this->xmlwriter->begin_tag('activity', array('id' => $instanceid, 'moduleid' => $this->moduleid, 'modulename' => 'assignment', 'contextid' => $contextid)); $this->xmlwriter->begin_tag('assignment', array('id' => $instanceid)); foreach ($data as $field => $value) { if ($field != 'id') { $this->xmlwriter->full_tag($field, $value); } } //after writing the assignment type element, let the subplugin add on whatever it wants. $this->handle_assignment_subplugin($data); $this->xmlwriter->begin_tag('submissions'); return $data; }
function xmldb_qtype_numerical_upgrade($oldversion) { global $CFG, $DB; $dbman = $DB->get_manager(); //===== 1.9.0 upgrade line ======// if ($oldversion < 2009100100) { //New version in version.php /// Define table question_numerical_options to be created $table = new xmldb_table('question_numerical_options'); /// Adding fields to table question_numerical_options $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null); $table->add_field('question', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0'); $table->add_field('instructions', XMLDB_TYPE_TEXT, 'small', null, null, null, null); $table->add_field('showunits', XMLDB_TYPE_INTEGER, '4', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0'); $table->add_field('unitsleft', XMLDB_TYPE_INTEGER, '4', null, XMLDB_NOTNULL, null, '0'); $table->add_field('unitgradingtype', XMLDB_TYPE_INTEGER, '4', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0'); $table->add_field('unitpenalty', XMLDB_TYPE_NUMBER, '12, 7', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0.1'); /// Adding keys to table question_numerical_options $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); $table->add_key('question', XMLDB_KEY_FOREIGN, array('question'), 'question', array('id')); /// Conditionally launch create table for question_calculated_options if (!$dbman->table_exists($table)) { // $dbman->create_table doesnt return a result, we just have to trust it $dbman->create_table($table); } //else upgrade_plugin_savepoint(true, 2009100100, 'qtype', 'numerical'); } if ($oldversion < 2009100101) { // Define field instructionsformat to be added to question_numerical_options $table = new xmldb_table('question_numerical_options'); $field = new xmldb_field('instructionsformat', XMLDB_TYPE_INTEGER, '2', null, XMLDB_NOTNULL, null, '0', 'instructions'); // Conditionally launch add field instructionsformat if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field); } // In the past, question_match_sub.questiontext assumed to contain // content of the same form as question.questiontextformat. If we are // using the HTML editor, then convert FORMAT_MOODLE content to FORMAT_HTML. $rs = $DB->get_recordset_sql(' SELECT qno.*, q.oldquestiontextformat FROM {question_numerical_options} qno JOIN {question} q ON qno.question = q.id'); foreach ($rs as $record) { if ($CFG->texteditors !== 'textarea' && $record->oldquestiontextformat == FORMAT_MOODLE) { $record->instructions = text_to_html($record->questiontext, false, false, true); $record->instructionsformat = FORMAT_HTML; } else { $record->instructionsformat = $record->oldquestiontextformat; } $DB->update_record('question_numerical_options', $record); } $rs->close(); // numerical savepoint reached upgrade_plugin_savepoint(true, 2009100101, 'qtype', 'numerical'); } return true; }
function links_summary_fill_smarty(&$vars) { if (get_misc_data('links_stories')) { $vars['smarty']->_vars['story_content'] = text_to_html($vars['smarty']->_vars['story_content']); } if (get_misc_data('links_nofollow')) { $vars['smarty']->_vars['story_content'] = preg_replace('/<a ([^>]+)>/i', '<a rel="nofollow" $1>', $vars['smarty']->_vars['story_content']); } }
/** * Unserialize attempt useranswer and add missing responseformat if needed * for compatibility with old records. * * @param string $useranswer serialized object * @return object */ public static function extract_useranswer($useranswer) { $essayinfo = unserialize($useranswer); if (!isset($essayinfo->responseformat)) { $essayinfo->response = text_to_html($essayinfo->response, false, false); $essayinfo->responseformat = FORMAT_HTML; } return $essayinfo; }
/** * This is executed every time we have one /MOODLE_BACKUP/COURSE/MODULES/MOD/SCORM * data available */ public function process_scorm($data) { global $CFG; // get the course module id and context id $instanceid = $data['id']; $currentcminfo = $this->get_cminfo($instanceid); $this->moduleid = $currentcminfo['id']; $contextid = $this->converter->get_contextid(CONTEXT_MODULE, $this->moduleid); // conditionally migrate to html format in intro if ($CFG->texteditors !== 'textarea') { $data['intro'] = text_to_html($data['intro'], false, false, true); $data['introformat'] = FORMAT_HTML; } // get a fresh new file manager for this instance $this->fileman = $this->converter->get_file_manager($contextid, 'mod_scorm'); // convert course files embedded into the intro $this->fileman->filearea = 'intro'; $this->fileman->itemid = 0; $data['intro'] = moodle1_converter::migrate_referenced_files($data['intro'], $this->fileman); // check 1.9 version where backup was created $backupinfo = $this->converter->get_stash('backup_info'); if ($backupinfo['moodle_version'] < 2007110503) { // as we have no module version data, assume $currmodule->version <= $module->version // - fix data as the source 1.9 build hadn't yet at time of backing up. $data['grademethod'] = $data['grademethod'] % 10; } // update scormtype (logic is consistent as done in scorm/db/upgrade.php) $ismanifest = preg_match('/imsmanifest\\.xml$/', $data['reference']); $iszippif = preg_match('/.(zip|pif)$/', $data['reference']); $isurl = preg_match('/^((http|https):\\/\\/|www\\.)/', $data['reference']); if ($isurl) { if ($ismanifest) { $data['scormtype'] = 'external'; } else { if ($iszippif) { $data['scormtype'] = 'localtype'; } } } // migrate scorm package file $this->fileman->filearea = 'package'; $this->fileman->itemid = 0; $this->fileman->migrate_file('course_files/' . $data['reference']); // start writing scorm.xml $this->open_xml_writer("activities/scorm_{$this->moduleid}/scorm.xml"); $this->xmlwriter->begin_tag('activity', array('id' => $instanceid, 'moduleid' => $this->moduleid, 'modulename' => 'scorm', 'contextid' => $contextid)); $this->xmlwriter->begin_tag('scorm', array('id' => $instanceid)); foreach ($data as $field => $value) { if ($field != 'id') { $this->xmlwriter->full_tag($field, $value); } } $this->xmlwriter->begin_tag('scoes'); return $data; }
public function desc($id) { if (!is_valid_id($id)) { exit('Missing an ID'); } $this->Product_model->set_id($id); $info = $this->Product_model->get_product_info(); $data['name'] = $info['name']; $data['desc'] = text_to_html($info['desc']); $this->display_ajax('ajax_desc', $data); }
function xmldb_facetoface_install() { global $DB; //Create default notification templates $tpl_confirmation = new stdClass(); $tpl_confirmation->status = 1; $tpl_confirmation->title = get_string('setting:defaultconfirmationsubjectdefault', 'facetoface'); $tpl_confirmation->body = text_to_html(get_string('setting:defaultconfirmationmessagedefault', 'facetoface')); $tpl_confirmation->managerprefix = text_to_html(get_string('setting:defaultconfirmationinstrmngrdefault', 'facetoface')); $DB->insert_record('facetoface_notification_tpl', $tpl_confirmation); $tpl_cancellation = new stdClass(); $tpl_cancellation->status = 1; $tpl_cancellation->title = get_string('setting:defaultcancellationsubjectdefault', 'facetoface'); $tpl_cancellation->body = text_to_html(get_string('setting:defaultcancellationmessagedefault', 'facetoface')); $tpl_cancellation->managerprefix = text_to_html(get_string('setting:defaultcancellationinstrmngrdefault', 'facetoface')); $DB->insert_record('facetoface_notification_tpl', $tpl_cancellation); $tpl_waitlist = new stdClass(); $tpl_waitlist->status = 1; $tpl_waitlist->title = get_string('setting:defaultwaitlistedsubjectdefault', 'facetoface'); $tpl_waitlist->body = text_to_html(get_string('setting:defaultwaitlistedmessagedefault', 'facetoface')); $DB->insert_record('facetoface_notification_tpl', $tpl_waitlist); $tpl_reminder = new stdClass(); $tpl_reminder->status = 1; $tpl_reminder->title = get_string('setting:defaultremindersubjectdefault', 'facetoface'); $tpl_reminder->body = text_to_html(get_string('setting:defaultremindermessagedefault', 'facetoface')); $tpl_reminder->managerprefix = text_to_html(get_string('setting:defaultreminderinstrmngrdefault', 'facetoface')); $DB->insert_record('facetoface_notification_tpl', $tpl_reminder); $tpl_request = new stdClass(); $tpl_request->status = 1; $tpl_request->title = get_string('setting:defaultrequestsubjectdefault', 'facetoface'); $tpl_request->body = text_to_html(get_string('setting:defaultrequestmessagedefault', 'facetoface')); $tpl_request->managerprefix = text_to_html(get_string('setting:defaultrequestinstrmngrdefault', 'facetoface')); $DB->insert_record('facetoface_notification_tpl', $tpl_request); $tpl_decline = new stdClass(); $tpl_decline->status = 1; $tpl_decline->title = get_string('setting:defaultdeclinesubjectdefault', 'facetoface'); $tpl_decline->body = text_to_html(get_string('setting:defaultdeclinemessagedefault', 'facetoface')); $tpl_decline->managerprefix = text_to_html(get_string('setting:defaultdeclineinstrmngrdefault', 'facetoface')); $DB->insert_record('facetoface_notification_tpl', $tpl_decline); // Setting room, building, and address as default filters. set_config('facetoface_calendarfilters', 'room,building,address'); }
/** * This is executed every time we have one /MOODLE_BACKUP/COURSE/MODULES/MOD/DATA * data available */ public function process_data($data) { global $CFG; // get the course module id and context id $instanceid = $data['id']; $cminfo = $this->get_cminfo($instanceid); $this->moduleid = $cminfo['id']; $contextid = $this->converter->get_contextid(CONTEXT_MODULE, $this->moduleid); // replay the upgrade step 2007101512 if (!array_key_exists('asearchtemplate', $data)) { $data['asearchtemplate'] = null; } // replay the upgrade step 2007101513 if (is_null($data['notification'])) { $data['notification'] = 0; } // conditionally migrate to html format in intro if ($CFG->texteditors !== 'textarea') { $data['intro'] = text_to_html($data['intro'], false, false, true); $data['introformat'] = FORMAT_HTML; } // get a fresh new file manager for this instance $this->fileman = $this->converter->get_file_manager($contextid, 'mod_data'); // convert course files embedded into the intro $this->fileman->filearea = 'intro'; $this->fileman->itemid = 0; $data['intro'] = moodle1_converter::migrate_referenced_files($data['intro'], $this->fileman); // @todo: user data - upgrade content to new file storage // add 'export' tag to list and single template. $pattern = '/\\#\\#delete\\#\\#(\\s+)\\#\\#approve\\#\\#/'; $replacement = '##delete##$1##approve##$1##export##'; $data['listtemplate'] = preg_replace($pattern, $replacement, $data['listtemplate']); $data['singletemplate'] = preg_replace($pattern, $replacement, $data['singletemplate']); //@todo: user data - move data comments to comments table //@todo: user data - move data ratings to ratings table // start writing data.xml $this->open_xml_writer("activities/data_{$this->moduleid}/data.xml"); $this->xmlwriter->begin_tag('activity', array('id' => $instanceid, 'moduleid' => $this->moduleid, 'modulename' => 'data', 'contextid' => $contextid)); $this->xmlwriter->begin_tag('data', array('id' => $instanceid)); foreach ($data as $field => $value) { if ($field != 'id') { $this->xmlwriter->full_tag($field, $value); } } $this->xmlwriter->begin_tag('fields'); return $data; }
/** * Display the 'Do you acknowledge the terms of the GPL' page. The first page * during install. * @return string HTML to output. */ public function install_licence_page() { global $CFG; $output = ''; $copyrightnotice = text_to_html(get_string('gpl3')); $copyrightnotice = str_replace('target="_blank"', 'onclick="this.target=\'_blank\'"', $copyrightnotice); // extremely ugly validation hack $continue = new single_button(new moodle_url($this->page->url, array('lang' => $CFG->lang, 'agreelicense' => 1)), get_string('continue'), 'get'); $output .= $this->header(); $output .= $this->heading('<a href="http://moodle.org">Moodle</a> - Modular Object-Oriented Dynamic Learning Environment'); $output .= $this->heading(get_string('copyrightnotice')); $output .= $this->box($copyrightnotice, 'copyrightnotice'); $output .= html_writer::empty_tag('br'); $output .= $this->confirm(get_string('doyouagree'), $continue, "http://docs.moodle.org/dev/License"); $output .= $this->footer(); return $output; }
function send($link) { if (empty($this->url)) { return; } $title = urlencode($this->title); // Convert everything to HTML and the strip all html tags. $excerpt = urlencode(strip_tags(text_to_html($this->content))); $blog_name = urlencode(get_server_name()); $tb_url = $this->url; $url = urlencode($link->get_permalink()); $query_string = "charset=UTF-8&title={$title}&url={$url}&blog_name={$blog_name}&excerpt={$excerpt}"; $trackback_url = parse_url($this->url); $http_request = 'POST ' . $trackback_url['path'] . ($trackback_url['query'] ? '?' . $trackback_url['query'] : '') . " HTTP/1.0\r\n"; $http_request .= 'Host: ' . $trackback_url['host'] . "\r\n"; $http_request .= 'Content-Type: application/x-www-form-urlencoded; charset=UTF-8' . "\r\n"; $http_request .= 'Content-Length: ' . strlen($query_string) . "\r\n"; $http_request .= "User-Agent: MNM (http://meneame.net) "; $http_request .= "\r\n\r\n"; $http_request .= $query_string; if ('' == $trackback_url['port']) { $trackback_url['port'] = 80; } $fs = @fsockopen($trackback_url['host'], $trackback_url['port'], $errno, $errstr, 5); if ($fs && ($res = @fputs($fs, $http_request))) { /*********** DEBUG ********** $debug_file = '/tmp/trackback.log'; $fp = fopen($debug_file, 'a'); fwrite($fp, "\n*****\nRequest:\n\n$http_request\n\nResponse:\n\n"); while(!@feof($fs)) { fwrite($fp, @fgets($fs, 4096)); } fwrite($fp, "\n\n"); fclose($fp); /*********** DEBUG ************/ @fclose($fs); $this->status = 'ok'; $this->store(); return true; } $this->status = 'error'; $this->store(); return $false; }
function send_batch_activiation($f2fid){ global $DB; $batchuser=$DB->get_records('local_batch_users',array('f2fid'=>$f2fid)); //print_object($batchuser); foreach($batchuser as $batchusers){ $sessions=getsession_list($f2fid); $subject='Active Notification'; $messagetext = get_string('batchactivemessage', 'facetoface'); $messagetext .=$sessions; $messagehtml = text_to_html($messagetext, null, false, true); // echo $sessions; $user=$DB->get_record('user',array('id'=>$batchusers->userid)); $from = $DB->get_record('user',array('id'=>2)); echo $messagehtml; $sent= email_to_user($user, $from, $subject, $messagetext, $messagehtml); echo "mail sent"; } }
/** * This is executed every time we have one /MOODLE_BACKUP/COURSE/MODULES/MOD/RCONTENT * data available */ public function process_rcontent($data) { global $CFG; // get the course module id and context id $instanceid = $data['id']; $currentcminfo = $this->get_cminfo($instanceid); $this->moduleid = $currentcminfo['id']; $contextid = $this->converter->get_contextid(CONTEXT_MODULE, $this->moduleid); // conditionally migrate to html format in summary if ($CFG->texteditors !== 'textarea') { $data['intro'] = text_to_html($data['intro'], false, false, true); } // get a fresh new file manager for this instance $this->fileman = $this->converter->get_file_manager($contextid, 'mod_rcontent'); // convert course files embedded into the summary $this->fileman->filearea = 'intro'; $this->fileman->itemid = 0; $data['intro'] = moodle1_converter::migrate_referenced_files($data['intro'], $this->fileman); // check 1.9 version where backup was created $backupinfo = $this->converter->get_stash('backup_info'); if ($backupinfo['moodle_version'] < 2007110503) { // as we have no module version data, assume $currmodule->version <= $module->version // - fix data as the source 1.9 build hadn't yet at time of backing up. if (isset($data['grademethod'])) { $data['grademethod'] = $data['grademethod'] % 10; } } // start writing rcontent.xml $this->open_xml_writer("activities/rcontent_{$this->moduleid}/rcontent.xml"); $this->xmlwriter->begin_tag('activity', array('id' => $instanceid, 'moduleid' => $this->moduleid, 'modulename' => 'rcontent', 'contextid' => $contextid)); $this->xmlwriter->begin_tag('rcontent', array('id' => $instanceid)); foreach ($data as $field => $value) { if ($field != 'id') { $this->xmlwriter->full_tag($field, $value); } } $this->xmlwriter->begin_tag('grades'); return $data; }
/** * This is executed every time we have one /MOODLE_BACKUP/COURSE/MODULES/MOD/QUIZ * data available */ public function process_quiz($data) { global $CFG; // replay the upgrade step 2008081501 if (is_null($data['sumgrades'])) { $data['sumgrades'] = 0; //@todo for user data: quiz_attempts SET sumgrades=0 WHERE sumgrades IS NULL //@todo for user data: quiz_grades.grade should be not be null , convert to default 0 } // replay the upgrade step 2009042000 if ($CFG->texteditors !== 'textarea') { $data['intro'] = text_to_html($data['intro'], false, false, true); $data['introformat'] = FORMAT_HTML; } // replay the upgrade step 2009031001 $data['timelimit'] *= 60; // get the course module id and context id $instanceid = $data['id']; $cminfo = $this->get_cminfo($instanceid); $this->moduleid = $cminfo['id']; $contextid = $this->converter->get_contextid(CONTEXT_MODULE, $this->moduleid); // get a fresh new file manager for this instance $this->fileman = $this->converter->get_file_manager($contextid, 'mod_quiz'); // convert course files embedded into the intro $this->fileman->filearea = 'intro'; $this->fileman->itemid = 0; $data['intro'] = moodle1_converter::migrate_referenced_files($data['intro'], $this->fileman); // start writing quiz.xml $this->open_xml_writer("activities/quiz_{$this->moduleid}/quiz.xml"); $this->xmlwriter->begin_tag('activity', array('id' => $instanceid, 'moduleid' => $this->moduleid, 'modulename' => 'quiz', 'contextid' => $contextid)); $this->xmlwriter->begin_tag('quiz', array('id' => $instanceid)); foreach ($data as $field => $value) { if ($field != 'id') { $this->xmlwriter->full_tag($field, $value); } } return $data; }
/** * @package mod * @subpackage adobeconnect * @author Akinsaya Delamarre (adelamarre@remote-learner.net) * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ function xmldb_adobeconnect_upgrade($oldversion = 0) { global $CFG, $DB; $dbman = $DB->get_manager(); //===== 1.9.0 upgrade line ======// if ($oldversion < 2010120800) { /// Define field introformat to be added to survey $table = new xmldb_table('adobeconnect'); $field = new xmldb_field('introformat', XMLDB_TYPE_INTEGER, '4', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'intro'); /// Conditionally launch add field introformat if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field); } // conditionally migrate to html format in intro if ($CFG->texteditors !== 'textarea') { $rs = $DB->get_recordset('adobeconnect', array('introformat' => FORMAT_MOODLE), '', 'id,intro,introformat'); foreach ($rs as $s) { $s->intro = text_to_html($s->intro, false, false, true); $s->introformat = FORMAT_HTML; $DB->update_record('adobeconnect', $s); upgrade_set_timeout(); } $rs->close(); } /// adobeconnect savepoint reached upgrade_mod_savepoint(true, 2010120800, 'adobeconnect'); } if ($oldversion < 2011041400) { // Changing precision of field meeturl on table adobeconnect to (60) $table = new xmldb_table('adobeconnect'); $field = new xmldb_field('meeturl', XMLDB_TYPE_CHAR, '60', null, null, null, null, 'templatescoid'); // Launch change of precision for field meeturl $dbman->change_field_precision($table, $field); // adobeconnect savepoint reached upgrade_mod_savepoint(true, 2011041400, 'adobeconnect'); } return true; }
print_header(get_string("summaryof", "", $course->fullname)); print_heading(format_string($course->fullname) . '<br />(' . format_string($course->shortname) . ')'); if ($course->guest || $course->password) { print_box_start('generalbox icons'); if ($course->guest) { $strallowguests = get_string('allowguests'); echo "<div><img alt=\"\" class=\"icon guest\" src=\"{$CFG->pixpath}/i/guest.gif\" /> {$strallowguests}</div>"; } if ($course->password) { $strrequireskey = get_string('requireskey'); echo "<div><img alt=\"\" class=\"icon key\" src=\"{$CFG->pixpath}/i/key.gif\" /> {$strrequireskey}</div>"; } print_box_end(); } print_box_start('generalbox info'); echo filter_text(text_to_html($course->summary), $course->id); if ($managerroles = get_config('', 'coursemanager')) { $coursemanagerroles = split(',', $managerroles); foreach ($coursemanagerroles as $roleid) { $role = get_record('role', 'id', $roleid); $canseehidden = has_capability('moodle/role:viewhiddenassigns', $context); $roleid = (int) $roleid; if ($users = get_role_users($roleid, $context, true, '', 'u.lastname ASC', $canseehidden)) { foreach ($users as $teacher) { $fullname = fullname($teacher, has_capability('moodle/site:viewfullnames', $context)); $namesarray[] = format_string($role->name) . ': <a href="' . $CFG->wwwroot . '/user/view.php?id=' . $teacher->id . '&course=' . SITEID . '">' . $fullname . '</a>'; } } } if (!empty($namesarray)) { echo "<ul class=\"teachers\">\n<li>";
/** * Send welcome email to specified user. * * @param stdClass $instance * @param stdClass $user user record * @return void */ protected function email_welcome_message($instance, $user) { global $CFG, $DB; $course = $DB->get_record('course', array('id' => $instance->courseid), '*', MUST_EXIST); $context = context_course::instance($course->id); $a = new stdClass(); $a->coursename = format_string($course->fullname, true, array('context' => $context)); $a->profileurl = "{$CFG->wwwroot}/user/view.php?id={$user->id}&course={$course->id}"; if (trim($instance->customtext1) !== '') { $message = $instance->customtext1; $key = array('{$a->coursename}', '{$a->profileurl}', '{$a->fullname}', '{$a->email}'); $value = array($a->coursename, $a->profileurl, fullname($user), $user->email); $message = str_replace($key, $value, $message); if (strpos($message, '<') === false) { // Plain text only. $messagetext = $message; $messagehtml = text_to_html($messagetext, null, false, true); } else { // This is most probably the tag/newline soup known as FORMAT_MOODLE. $messagehtml = format_text($message, FORMAT_MOODLE, array('context' => $context, 'para' => false, 'newlines' => true, 'filter' => true)); $messagetext = html_to_text($messagehtml); } } else { $messagetext = get_string('welcometocoursetext', 'enrol_self', $a); $messagehtml = text_to_html($messagetext, null, false, true); } $subject = get_string('welcometocourse', 'enrol_self', format_string($course->fullname, true, array('context' => $context))); $rusers = array(); if (!empty($CFG->coursecontact)) { $croles = explode(',', $CFG->coursecontact); list($sort, $sortparams) = users_order_by_sql('u'); // We only use the first user. $i = 0; do { $rusers = get_role_users($croles[$i], $context, true, '', 'r.sortorder ASC, ' . $sort, null, '', '', '', '', $sortparams); $i++; } while (empty($rusers) && !empty($croles[$i])); } if ($rusers) { $contact = reset($rusers); } else { $contact = core_user::get_support_user(); } // Directly emailing welcome message rather than using messaging. email_to_user($user, $contact, $subject, $messagetext, $messagehtml); }
function print_item_dropdown($presentation, $item, $value, $info, $align) { ?> <select name="<?php echo $item->typ . '_' . $item->id; ?> " size="1"> <option value="0"> </option> <?php $index = 1; $checked = ''; foreach ($presentation as $dropdown) { if ($value == $index) { $selected = 'selected="selected"'; } else { $selected = ''; } ?> <option value="<?php echo $index; ?> " <?php echo $selected; ?> ><?php echo text_to_html($dropdown, true, false, false); ?> </option> <?php $index++; } ?> </select> <?php }
/** * Given text in a variety of format codings, this function returns * the text as safe HTML. * * This function should mainly be used for long strings like posts, * answers, glossary items etc. For short strings @see format_string(). * * <pre> * Options: * trusted : If true the string won't be cleaned. Default false required noclean=true. * noclean : If true the string won't be cleaned. Default false required trusted=true. * nocache : If true the strign will not be cached and will be formatted every call. Default false. * filter : If true the string will be run through applicable filters as well. Default true. * para : If true then the returned string will be wrapped in div tags. Default true. * newlines : If true then lines newline breaks will be converted to HTML newline breaks. Default true. * context : The context that will be used for filtering. * overflowdiv : If set to true the formatted text will be encased in a div * with the class no-overflow before being returned. Default false. * allowid : If true then id attributes will not be removed, even when * using htmlpurifier. Default false. * </pre> * * @todo Finish documenting this function * * @staticvar array $croncache * @param string $text The text to be formatted. This is raw text originally from user input. * @param int $format Identifier of the text format to be used * [FORMAT_MOODLE, FORMAT_HTML, FORMAT_PLAIN, FORMAT_MARKDOWN] * @param object/array $options text formatting options * @param int $courseid_do_not_use deprecated course id, use context option instead * @return string */ function format_text($text, $format = FORMAT_MOODLE, $options = NULL, $courseid_do_not_use = NULL) { global $CFG, $COURSE, $DB, $PAGE; static $croncache = array(); if ($text === '' || is_null($text)) { return ''; // no need to do any filters and cleaning } $options = (array) $options; // detach object, we can not modify it if (!isset($options['trusted'])) { $options['trusted'] = false; } if (!isset($options['noclean'])) { if ($options['trusted'] and trusttext_active()) { // no cleaning if text trusted and noclean not specified $options['noclean'] = true; } else { $options['noclean'] = false; } } if (!isset($options['nocache'])) { $options['nocache'] = false; } if (!isset($options['filter'])) { $options['filter'] = true; } if (!isset($options['para'])) { $options['para'] = true; } if (!isset($options['newlines'])) { $options['newlines'] = true; } if (!isset($options['overflowdiv'])) { $options['overflowdiv'] = false; } // Calculate best context if (empty($CFG->version) or $CFG->version < 2010072800 or during_initial_install()) { // do not filter anything during installation or before upgrade completes $context = null; } else { if (isset($options['context'])) { // first by explicit passed context option if (is_object($options['context'])) { $context = $options['context']; } else { $context = get_context_instance_by_id($options['context']); } } else { if ($courseid_do_not_use) { // legacy courseid $context = get_context_instance(CONTEXT_COURSE, $courseid_do_not_use); } else { // fallback to $PAGE->context this may be problematic in CLI and other non-standard pages :-( $context = $PAGE->context; } } } if (!$context) { // either install/upgrade or something has gone really wrong because context does not exist (yet?) $options['nocache'] = true; $options['filter'] = false; } if ($options['filter']) { $filtermanager = filter_manager::instance(); } else { $filtermanager = new null_filter_manager(); } if (!empty($CFG->cachetext) and empty($options['nocache'])) { $hashstr = $text . '-' . $filtermanager->text_filtering_hash($context) . '-' . $context->id . '-' . current_language() . '-' . (int) $format . (int) $options['trusted'] . (int) $options['noclean'] . (int) $options['para'] . (int) $options['newlines']; $time = time() - $CFG->cachetext; $md5key = md5($hashstr); if (CLI_SCRIPT) { if (isset($croncache[$md5key])) { return $croncache[$md5key]; } } if ($oldcacheitem = $DB->get_record('cache_text', array('md5key' => $md5key), '*', IGNORE_MULTIPLE)) { if ($oldcacheitem->timemodified >= $time) { if (CLI_SCRIPT) { if (count($croncache) > 150) { reset($croncache); $key = key($croncache); unset($croncache[$key]); } $croncache[$md5key] = $oldcacheitem->formattedtext; } return $oldcacheitem->formattedtext; } } } switch ($format) { case FORMAT_HTML: if (!$options['noclean']) { $text = clean_text($text, FORMAT_HTML, $options); } $text = $filtermanager->filter_text($text, $context, array('originalformat' => FORMAT_HTML, 'noclean' => $options['noclean'])); break; case FORMAT_PLAIN: $text = s($text); // cleans dangerous JS $text = rebuildnolinktag($text); $text = str_replace(' ', ' ', $text); $text = nl2br($text); break; case FORMAT_WIKI: // this format is deprecated $text = '<p>NOTICE: Wiki-like formatting has been removed from Moodle. You should not be seeing this message as all texts should have been converted to Markdown format instead. Please post a bug report to http://moodle.org/bugs with information about where you saw this message.</p>' . s($text); break; case FORMAT_MARKDOWN: $text = markdown_to_html($text); if (!$options['noclean']) { $text = clean_text($text, FORMAT_HTML, $options); } $text = $filtermanager->filter_text($text, $context, array('originalformat' => FORMAT_MARKDOWN, 'noclean' => $options['noclean'])); break; default: // FORMAT_MOODLE or anything else $text = text_to_html($text, null, $options['para'], $options['newlines']); if (!$options['noclean']) { $text = clean_text($text, FORMAT_HTML, $options); } $text = $filtermanager->filter_text($text, $context, array('originalformat' => $format, 'noclean' => $options['noclean'])); break; } if ($options['filter']) { // at this point there should not be any draftfile links any more, // this happens when developers forget to post process the text. // The only potential problem is that somebody might try to format // the text before storing into database which would be itself big bug. $text = str_replace("\"{$CFG->httpswwwroot}/draftfile.php", "\"{$CFG->httpswwwroot}/brokenfile.php#", $text); } // Warn people that we have removed this old mechanism, just in case they // were stupid enough to rely on it. if (isset($CFG->currenttextiscacheable)) { debugging('Once upon a time, Moodle had a truly evil use of global variables ' . 'called $CFG->currenttextiscacheable. The good news is that this no ' . 'longer exists. The bad news is that you seem to be using a filter that ' . 'relies on it. Please seek out and destroy that filter code.', DEBUG_DEVELOPER); } if (!empty($options['overflowdiv'])) { $text = html_writer::tag('div', $text, array('class' => 'no-overflow')); } if (empty($options['nocache']) and !empty($CFG->cachetext)) { if (CLI_SCRIPT) { // special static cron cache - no need to store it in db if its not already there if (count($croncache) > 150) { reset($croncache); $key = key($croncache); unset($croncache[$key]); } $croncache[$md5key] = $text; return $text; } $newcacheitem = new stdClass(); $newcacheitem->md5key = $md5key; $newcacheitem->formattedtext = $text; $newcacheitem->timemodified = time(); if ($oldcacheitem) { // See bug 4677 for discussion $newcacheitem->id = $oldcacheitem->id; try { $DB->update_record('cache_text', $newcacheitem); // Update existing record in the cache table } catch (dml_exception $e) { // It's unlikely that the cron cache cleaner could have // deleted this entry in the meantime, as it allows // some extra time to cover these cases. } } else { try { $DB->insert_record('cache_text', $newcacheitem); // Insert a new record in the cache table } catch (dml_exception $e) { // Again, it's possible that another user has caused this // record to be created already in the time that it took // to traverse this function. That's OK too, as the // call above handles duplicate entries, and eventually // the cron cleaner will delete them. } } } return $text; }
/** * Upgrade code for the multiple choice question type. * @param int $oldversion the version we are upgrading from. */ function xmldb_qtype_multichoice_upgrade($oldversion) { global $CFG, $DB; $dbman = $DB->get_manager(); // This upgrade actually belongs to the random question type, // but that does not have a DB upgrade script. Therefore, multichoice // is doing it. // Rename random questions to give them more helpful names. if ($oldversion < 2008021800) { require_once $CFG->dirroot . '/question/type/random/questiontype.php'; $randomqtype = new qtype_random(); // Get all categories containing random questions. $categories = $DB->get_recordset_sql("\n SELECT qc.id, qc.name\n FROM {question_categories} qc\n JOIN {question} q ON q.category = qc.id\n WHERE q.qtype = 'random'\n GROUP BY qc.id, qc.name"); // Rename the random qusetions in those categories. $where = "qtype = 'random' AND category = ? AND " . $DB->sql_compare_text('questiontext') . " = " . $DB->sql_compare_text('?'); foreach ($categories as $cat) { $randomqname = $randomqtype->question_name($cat, false); $DB->set_field_select('question', 'name', $randomqname, $where, array($cat->id, '0')); $randomqname = $randomqtype->question_name($cat, true); $DB->set_field_select('question', 'name', $randomqname, $where, array($cat->id, '1')); } upgrade_plugin_savepoint(true, 2008021800, 'qtype', 'multichoice'); } if ($oldversion < 2009021801) { // Define field correctfeedbackformat to be added to question_multichoice $table = new xmldb_table('question_multichoice'); $field = new xmldb_field('correctfeedbackformat', XMLDB_TYPE_INTEGER, '2', null, XMLDB_NOTNULL, null, '0', 'correctfeedback'); // Conditionally launch add field correctfeedbackformat if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field); } // Define field partiallycorrectfeedbackformat to be added to question_multichoice $field = new xmldb_field('partiallycorrectfeedbackformat', XMLDB_TYPE_INTEGER, '2', null, XMLDB_NOTNULL, null, '0', 'partiallycorrectfeedback'); // Conditionally launch add field partiallycorrectfeedbackformat if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field); } // Define field incorrectfeedbackformat to be added to question_multichoice $field = new xmldb_field('incorrectfeedbackformat', XMLDB_TYPE_INTEGER, '2', null, XMLDB_NOTNULL, null, '0', 'incorrectfeedback'); // Conditionally launch add field incorrectfeedbackformat if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field); } // In the past, the correctfeedback, partiallycorrectfeedback, // incorrectfeedback columns were assumed to contain content of the same // form as questiontextformat. If we are using the HTML editor, then // convert FORMAT_MOODLE content to FORMAT_HTML. $rs = $DB->get_recordset_sql(' SELECT qm.*, q.oldquestiontextformat FROM {question_multichoice} qm JOIN {question} q ON qm.question = q.id'); foreach ($rs as $record) { if ($CFG->texteditors !== 'textarea' && $record->oldquestiontextformat == FORMAT_MOODLE) { $record->correctfeedback = text_to_html($record->correctfeedback, false, false, true); $record->correctfeedbackformat = FORMAT_HTML; $record->partiallycorrectfeedback = text_to_html($record->partiallycorrectfeedback, false, false, true); $record->partiallycorrectfeedbackformat = FORMAT_HTML; $record->incorrectfeedback = text_to_html($record->incorrectfeedback, false, false, true); $record->incorrectfeedbackformat = FORMAT_HTML; } else { $record->correctfeedbackformat = $record->oldquestiontextformat; $record->partiallycorrectfeedback = $record->oldquestiontextformat; $record->incorrectfeedbackformat = $record->oldquestiontextformat; } $DB->update_record('question_multichoice', $record); } $rs->close(); // multichoice savepoint reached upgrade_plugin_savepoint(true, 2009021801, 'qtype', 'multichoice'); } // Add new shownumcorrect field. If this is true, then when the user gets a // multiple-response question partially correct, tell them how many choices // they got correct alongside the feedback. if ($oldversion < 2011011200) { // Define field shownumcorrect to be added to question_multichoice $table = new xmldb_table('question_multichoice'); $field = new xmldb_field('shownumcorrect', XMLDB_TYPE_INTEGER, '2', null, XMLDB_NOTNULL, null, '0', 'answernumbering'); // Launch add field shownumcorrect if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field); } // multichoice savepoint reached upgrade_plugin_savepoint(true, 2011011200, 'qtype', 'multichoice'); } // Moodle v2.1.0 release upgrade line // Put any upgrade step following this return true; }
function print_item_radio($item, $value, $info, $align, $showrating, $lines) { $index = 1; $checked = ''; if ($info->horizontal) { $hv = 'h'; } else { $hv = 'v'; } echo '<ul>'; if (!$this->hidenoselect($item)) { ?> <li class="feedback_item_radio_<?php echo $hv . '_' . $align; ?> "> <span class="feedback_item_radio_<?php echo $hv . '_' . $align; ?> "> <input type="radio" name="<?php echo $item->typ . '_' . $item->id; ?> " id="<?php echo $item->typ . '_' . $item->id . '_xxx'; ?> " value="" checked="checked" /> </span> <span class="feedback_item_radiolabel_<?php echo $hv . '_' . $align; ?> "> <label for="<?php echo $item->typ . '_' . $item->id . '_xxx'; ?> "><?php print_string('not_selected', 'feedback'); ?> </label> </span> </li> <?php } foreach ($lines as $line) { if ($value == $index) { $checked = 'checked="checked"'; } else { $checked = ''; } $radio_value = explode(FEEDBACK_MULTICHOICERATED_VALUE_SEP, $line); $inputname = $item->typ . '_' . $item->id; $inputid = $inputname . '_' . $index; ?> <li class="feedback_item_radio_<?php echo $hv . '_' . $align; ?> "> <span class="feedback_item_radio_<?php echo $hv . '_' . $align; ?> "> <input type="radio" name="<?php echo $inputname; ?> " id="<?php echo $inputid; ?> " value="<?php echo $index; ?> " <?php echo $checked; ?> /> </span> <span class="feedback_item_radiolabel_<?php echo $hv . '_' . $align; ?> "> <label for="<?php echo $inputid; ?> "> <?php if ($showrating) { echo text_to_html('(' . $radio_value[0] . ') ' . $radio_value[1], true, false, false); } else { echo text_to_html($radio_value[1], true, false, false); } ?> </label> </span> </li> <?php $index++; } echo '</ul>'; }
function xmldb_data_upgrade($oldversion) { global $CFG, $DB, $OUTPUT; $dbman = $DB->get_manager(); //===== 1.9.0 upgrade line ======// if ($oldversion < 2007101512) { /// Launch add field asearchtemplate again if does not exists yet - reported on several sites $table = new xmldb_table('data'); $field = new xmldb_field('asearchtemplate', XMLDB_TYPE_TEXT, 'small', null, null, null, null, 'jstemplate'); if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field); } upgrade_mod_savepoint(true, 2007101512, 'data'); } if ($oldversion < 2007101513) { // Upgrade all the data->notification currently being // NULL to 0 $sql = "UPDATE {data} SET notification=0 WHERE notification IS NULL"; $DB->execute($sql); $table = new xmldb_table('data'); $field = new xmldb_field('notification', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'editany'); // First step, Set NOT NULL $dbman->change_field_notnull($table, $field); // Second step, Set default to 0 $dbman->change_field_default($table, $field); upgrade_mod_savepoint(true, 2007101513, 'data'); } if ($oldversion < 2008081400) { $pattern = '/\#\#delete\#\#(\s+)\#\#approve\#\#/'; $replacement = '##delete##$1##approve##$1##export##'; $rs = $DB->get_recordset('data'); foreach ($rs as $data) { $data->listtemplate = preg_replace($pattern, $replacement, $data->listtemplate); $data->singletemplate = preg_replace($pattern, $replacement, $data->singletemplate); $DB->update_record('data', $data); } $rs->close(); upgrade_mod_savepoint(true, 2008081400, 'data'); } if ($oldversion < 2008091400) { ///////////////////////////////////// /// new file storage upgrade code /// ///////////////////////////////////// $fs = get_file_storage(); $empty = $DB->sql_empty(); // silly oracle empty string handling workaround $sqlfrom = "FROM {data_content} c JOIN {data_fields} f ON f.id = c.fieldid JOIN {data_records} r ON r.id = c.recordid JOIN {data} d ON d.id = r.dataid JOIN {modules} m ON m.name = 'data' JOIN {course_modules} cm ON (cm.module = m.id AND cm.instance = d.id) WHERE ".$DB->sql_compare_text('c.content', 2)." <> '$empty' AND c.content IS NOT NULL AND (f.type = 'file' OR f.type = 'picture')"; $count = $DB->count_records_sql("SELECT COUNT('x') $sqlfrom"); $rs = $DB->get_recordset_sql("SELECT c.id, f.type, r.dataid, c.recordid, f.id AS fieldid, r.userid, c.content, c.content1, d.course, r.userid, cm.id AS cmid $sqlfrom ORDER BY d.course, d.id"); if ($rs->valid()) { $pbar = new progress_bar('migratedatafiles', 500, true); $i = 0; foreach ($rs as $content) { $i++; upgrade_set_timeout(60); // set up timeout, may also abort execution $pbar->update($i, $count, "Migrating data entries - $i/$count."); $filepath = "$CFG->dataroot/$content->course/$CFG->moddata/data/$content->dataid/$content->fieldid/$content->recordid/$content->content"; $context = get_context_instance(CONTEXT_MODULE, $content->cmid); if (!file_exists($filepath)) { continue; } $filearea = 'content'; $oldfilename = $content->content; $filename = clean_param($oldfilename, PARAM_FILE); if ($filename === '') { continue; } if (!$fs->file_exists($context->id, 'mod_data', $filearea, $content->id, '/', $filename)) { $file_record = array('contextid'=>$context->id, 'component'=>'mod_data', 'filearea'=>$filearea, 'itemid'=>$content->id, 'filepath'=>'/', 'filename'=>$filename, 'userid'=>$content->userid); if ($fs->create_file_from_pathname($file_record, $filepath)) { unlink($filepath); if ($oldfilename !== $filename) { // update filename if needed $DB->set_field('data_content', 'content', $filename, array('id'=>$content->id)); } if ($content->type == 'picture') { // migrate thumb $filepath = "$CFG->dataroot/$content->course/$CFG->moddata/data/$content->dataid/$content->fieldid/$content->recordid/thumb/$content->content"; if (file_exists($filepath)) { if (!$fs->file_exists($context->id, 'mod_data', $filearea, $content->id, '/', 'thumb_'.$filename)) { $file_record['filename'] = 'thumb_'.$file_record['filename']; $fs->create_file_from_pathname($file_record, $filepath); } unlink($filepath); } } } } // remove dirs if empty @rmdir("$CFG->dataroot/$content->course/$CFG->moddata/data/$content->dataid/$content->fieldid/$content->recordid/thumb"); @rmdir("$CFG->dataroot/$content->course/$CFG->moddata/data/$content->dataid/$content->fieldid/$content->recordid"); @rmdir("$CFG->dataroot/$content->course/$CFG->moddata/data/$content->dataid/$content->fieldid"); @rmdir("$CFG->dataroot/$content->course/$CFG->moddata/data/$content->dataid"); @rmdir("$CFG->dataroot/$content->course/$CFG->moddata/data"); @rmdir("$CFG->dataroot/$content->course/$CFG->moddata"); } } $rs->close(); upgrade_mod_savepoint(true, 2008091400, 'data'); } if ($oldversion < 2008112700) { if (!get_config('data', 'requiredentriesfixflag')) { $databases = $DB->get_records_sql("SELECT d.*, c.fullname FROM {data} d, {course} c WHERE d.course = c.id AND (d.requiredentries > 0 OR d.requiredentriestoview > 0) ORDER BY c.fullname, d.name"); if (!empty($databases)) { $a = new stdClass(); $a->text = ''; foreach($databases as $database) { $a->text .= $database->fullname." - " .$database->name. " (course id: ".$database->course." - database id: ".$database->id.")<br/>"; } //TODO: MDL-17427 send this info to "upgrade log" which will be implemented in 2.0 echo $OUTPUT->notification(get_string('requiredentrieschanged', 'admin', $a)); } } unset_config('requiredentriesfixflag', 'data'); // remove old flag upgrade_mod_savepoint(true, 2008112700, 'data'); } if ($oldversion < 2009042000) { /// Define field introformat to be added to data $table = new xmldb_table('data'); $field = new xmldb_field('introformat', XMLDB_TYPE_INTEGER, '4', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'intro'); /// Launch add field introformat if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field); } // conditionally migrate to html format in intro if ($CFG->texteditors !== 'textarea') { $rs = $DB->get_recordset('data', array('introformat'=>FORMAT_MOODLE), '', 'id,intro,introformat'); foreach ($rs as $d) { $d->intro = text_to_html($d->intro, false, false, true); $d->introformat = FORMAT_HTML; $DB->update_record('data', $d); upgrade_set_timeout(); } $rs->close(); } /// data savepoint reached upgrade_mod_savepoint(true, 2009042000, 'data'); } if ($oldversion < 2009111701) { upgrade_set_timeout(60*20); /// Define table data_comments to be dropped $table = new xmldb_table('data_comments'); /// Conditionally launch drop table for data_comments if ($dbman->table_exists($table)) { $sql = "SELECT d.id AS dataid, d.course AS courseid, c.userid, r.id AS itemid, c.id AS commentid, c.content AS commentcontent, c.format AS format, c.created AS timecreated FROM {data_comments} c, {data_records} r, {data} d WHERE c.recordid=r.id AND r.dataid=d.id ORDER BY dataid, courseid"; /// move data comments to comments table $lastdataid = null; $lastcourseid = null; $modcontext = null; $rs = $DB->get_recordset_sql($sql); foreach($rs as $res) { if ($res->dataid != $lastdataid || $res->courseid != $lastcourseid) { $cm = get_coursemodule_from_instance('data', $res->dataid, $res->courseid); if ($cm) { $modcontext = get_context_instance(CONTEXT_MODULE, $cm->id); } $lastdataid = $res->dataid; $lastcourseid = $res->courseid; } $cmt = new stdClass(); $cmt->contextid = $modcontext->id; $cmt->commentarea = 'database_entry'; $cmt->itemid = $res->itemid; $cmt->content = $res->commentcontent; $cmt->format = $res->format; $cmt->userid = $res->userid; $cmt->timecreated = $res->timecreated; // comments class will throw an exception if error occurs $cmt_id = $DB->insert_record('comments', $cmt); if (!empty($cmt_id)) { $DB->delete_records('data_comments', array('id'=>$res->commentid)); } } $rs->close(); // the default exception handler will stop the script if error occurs before $dbman->drop_table($table); } /// data savepoint reached upgrade_mod_savepoint(true, 2009111701, 'data'); } if ($oldversion < 2010031602) { //add assesstimestart and assesstimefinish columns to data $table = new xmldb_table('data'); $field = new xmldb_field('assesstimestart'); if (!$dbman->field_exists($table, $field)) { $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, 0, 'assessed'); $dbman->add_field($table, $field); } $field = new xmldb_field('assesstimefinish'); if (!$dbman->field_exists($table, $field)) { $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, 0, 'assesstimestart'); $dbman->add_field($table, $field); } upgrade_mod_savepoint(true, 2010031602, 'data'); } if ($oldversion < 2010042800) { //migrate data ratings to the central rating table $table = new xmldb_table('data_ratings'); if ($dbman->table_exists($table)) { //data ratings didnt store time created and modified so Im using the times from the record the rating was attached to $sql = "INSERT INTO {rating} (contextid, scaleid, itemid, rating, userid, timecreated, timemodified) SELECT cxt.id, d.scale, r.recordid AS itemid, r.rating, r.userid, re.timecreated AS timecreated, re.timemodified AS timemodified FROM {data_ratings} r JOIN {data_records} re ON r.recordid=re.id JOIN {data} d ON d.id=re.dataid JOIN {course_modules} cm ON cm.instance=d.id JOIN {context} cxt ON cxt.instanceid=cm.id JOIN {modules} m ON m.id=cm.module WHERE m.name = :modname AND cxt.contextlevel = :contextlevel"; $params['modname'] = 'data'; $params['contextlevel'] = CONTEXT_MODULE; $DB->execute($sql, $params); //now drop data_ratings $dbman->drop_table($table); } upgrade_mod_savepoint(true, 2010042800, 'data'); } //rerun the upgrade see MDL-24470 if ($oldversion < 2010100101) { // Upgrade all the data->notification currently being // NULL to 0 $sql = "UPDATE {data} SET notification=0 WHERE notification IS NULL"; $DB->execute($sql); $table = new xmldb_table('data'); $field = new xmldb_field('notification', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'editany'); // First step, Set NOT NULL $dbman->change_field_notnull($table, $field); // Second step, Set default to 0 $dbman->change_field_default($table, $field); upgrade_mod_savepoint(true, 2010100101, 'data'); } if ($oldversion < 2011052300) { // rating.component and rating.ratingarea have now been added as mandatory fields. // Presently you can only rate data entries so component = 'mod_data' and ratingarea = 'entry' // for all ratings with a data context. // We want to update all ratings that belong to a data context and don't already have a // component set. // This could take a while reset upgrade timeout to 5 min upgrade_set_timeout(60 * 20); $sql = "UPDATE {rating} SET component = 'mod_data', ratingarea = 'entry' WHERE contextid IN ( SELECT ctx.id FROM {context} ctx JOIN {course_modules} cm ON cm.id = ctx.instanceid JOIN {modules} m ON m.id = cm.module WHERE ctx.contextlevel = 70 AND m.name = 'data' ) AND component = 'unknown'"; $DB->execute($sql); upgrade_mod_savepoint(true, 2011052300, 'data'); } // Moodle v2.1.0 release upgrade line // Put any upgrade step following this // Moodle v2.2.0 release upgrade line // Put any upgrade step following this return true; }
/** * Sends the student their issued certificate from moddata as an email * attachment. * * @param stdClass $user * @param stdClass $course * @param stdClass $certificate * @param stdClass $certrecord * @param stdClass $context */ function certificate_email_students($user, $course, $certificate, $certrecord, $context) { global $DB, $USER; if ($certrecord->mailed > 0) { return; } // Get teachers if ($users = get_users_by_capability($context, 'moodle/course:update', 'u.*', 'u.id ASC', '', '', '', '', false, true)) { $users = sort_by_roleassignment_authority($users, $context); $teacher = array_shift($users); } // If we haven't found a teacher yet, look for a non-editing teacher in this course. if (empty($teacher) && ($users = get_users_by_capability($context, 'moodle/course:update', 'u.*', 'u.id ASC', '', '', '', '', false, true))) { $users = sort_by_roleassignment_authority($users, $context); $teacher = array_shift($users); } $info = new stdClass(); $info->username = fullname($user); $info->certificate = format_string($certificate->name, true); $info->course = format_string($course->fullname, true); $from = fullname($teacher); $subject = $info->course . ': ' . $info->certificate; $message = get_string('emailstudenttext', 'certificate', $info) . "\n"; // Make the HTML version more XHTML happy (&) $messagehtml = text_to_html(get_string('emailstudenttext', 'certificate', $info)); $user->mailformat = 0; // Always send HTML version as well $filename = clean_filename($certificate->name . '.pdf'); // Get hashed pathname $fs = get_file_storage(); $component = 'mod_certificate'; $filearea = 'issue'; $filepath = '/'; $files = $fs->get_area_files($context->id, $component, $filearea, $certrecord->id); foreach ($files as $f) { $filepathname = $f->get_contenthash(); } $attachment = 'filedir/' . certificate_path_from_hash($filepathname) . '/' . $filepathname; $attachname = $filename; $DB->set_field('certificate_issues', 'mailed', '1', array('certificateid' => $certificate->id, 'userid' => $user->id)); return email_to_user($user, $from, $subject, $message, $messagehtml, $attachment, $attachname); }