define('MOODLE_INTERNAL', true);
// Check that PHP is of a sufficient version
-if (version_compare(phpversion(), "5.2.8") < 0) {
+if (version_compare(phpversion(), "5.3.2") < 0) {
$phpversion = phpversion();
// do NOT localise - lang strings would not work here and we CAN NOT move it after installib
- echo "Sorry, Moodle 2.0 requires PHP 5.2.8 or later (currently using version $phpversion).\n";
- echo "Please upgrade your server software or install latest Moodle 1.9.x instead.";
- die;
+ fwrite(STDERR, "Moodle 2.1 or later requires at least PHP 5.3.2 (currently using version $phpversion).\n");
+ fwrite(STDERR, "Please upgrade your server software or install older Moodle version.\n");
+ exit(1);
}
// set up configuration
";
// Check that PHP is of a sufficient version
-if (version_compare(phpversion(), "5.2.8") < 0) {
+if (version_compare(phpversion(), "5.3.2") < 0) {
$phpversion = phpversion();
// do NOT localise - lang strings would not work here and we CAN NOT move it after installib
- fwrite(STDERR, "Sorry, Moodle 2.0 requires PHP 5.2.8 or later (currently using version $phpversion).\n");
- fwrite(STDERR, "Please upgrade your server software or install latest Moodle 1.9.x instead.\n");
- die(1);
+ fwrite(STDERR, "Moodle 2.1 or later requires at least PHP 5.3.2 (currently using version $phpversion).\n");
+ fwrite(STDERR, "Please upgrade your server software or install older Moodle version.\n");
+ exit(1);
}
// Nothing to do if config.php does not exist
if (!file_exists($configfile)) {
fwrite(STDERR, 'config.php does not exist, can not continue'); // do not localize
fwrite(STDERR, "\n");
- die(1);
+ exit(1);
}
// Include necessary libs
}
// Check that PHP is of a sufficient version as soon as possible
-if (version_compare(phpversion(), '5.2.0') < 0) {
+if (version_compare(phpversion(), '5.3.2') < 0) {
$phpversion = phpversion();
// do NOT localise - lang strings would not work here and we CAN NOT move it to later place
- echo "Sorry, Moodle 2.0 requires PHP 5.2.8 or later (currently using version $phpversion). ";
- echo "Please upgrade your server software or use latest Moodle 1.9.x instead.";
+ echo "Moodle 2.1 or later requires at least PHP 5.3.2 (currently using version $phpversion).<br />";
+ echo "Please upgrade your server software or install older Moodle version.";
+ die;
+}
+
+// make sure iconv is available and actually works
+if (!function_exists('iconv')) {
+ // this should not happen, this must be very borked install
+ echo 'Moodle requires the iconv PHP extension. Please install or enable the iconv extension.';
+ die();
+}
+if (iconv('UTF-8', 'UTF-8//IGNORE', 'abc') !== 'abc') {
+ // known to be broken in mid-2011 MAMP installations
+ echo 'Broken iconv PHP extension detected, installation/upgrade can not continue.';
die;
}
900 => get_string('numminutes', '', 15),
300 => get_string('numminutes', '', 5))));
$temp->add(new admin_setting_configtext('sessioncookie', get_string('sessioncookie', 'admin'), get_string('configsessioncookie', 'admin'), '', PARAM_ALPHANUM));
-$temp->add(new admin_setting_configtext('sessioncookiepath', get_string('sessioncookiepath', 'admin'), get_string('configsessioncookiepath', 'admin'), '/', PARAM_LOCALURL));
-$temp->add(new admin_setting_configtext('sessioncookiedomain', get_string('sessioncookiedomain', 'admin'), get_string('configsessioncookiedomain', 'admin'), '', PARAM_TEXT, 50));
+$temp->add(new admin_setting_configtext('sessioncookiepath', get_string('sessioncookiepath', 'admin'), get_string('configsessioncookiepath', 'admin'), '', PARAM_RAW));
+$temp->add(new admin_setting_configtext('sessioncookiedomain', get_string('sessioncookiedomain', 'admin'), get_string('configsessioncookiedomain', 'admin'), '', PARAM_RAW, 50));
$ADMIN->add('server', $temp);
$oldctxid, $this->task->get_userid(), 'question_answer', null, $newctxid, true);
restore_dbops::send_files_to_pool($this->get_basepath(), $this->get_restoreid(), 'question', 'hint',
$oldctxid, $this->task->get_userid(), 'question_hint', null, $newctxid, true);
+ restore_dbops::send_files_to_pool($this->get_basepath(), $this->get_restoreid(), 'question', 'correctfeedback',
+ $oldctxid, $this->task->get_userid(), 'question_created', $question->itemid, $newctxid, true);
+ restore_dbops::send_files_to_pool($this->get_basepath(), $this->get_restoreid(), 'question', 'partiallycorrectfeedback',
+ $oldctxid, $this->task->get_userid(), 'question_created', $question->itemid, $newctxid, true);
+ restore_dbops::send_files_to_pool($this->get_basepath(), $this->get_restoreid(), 'question', 'incorrectfeedback',
+ $oldctxid, $this->task->get_userid(), 'question_created', $question->itemid, $newctxid, true);
// Add qtype dependent files
$components = backup_qtype_plugin::get_components_and_fileareas($question->qtype);
foreach ($components as $component => $fileareas) {
}
$manager = has_capability('moodle/cohort:manage', $context);
+$canassign = has_capability('moodle/cohort:assign', $context);
if (!$manager) {
require_capability('moodle/cohort:view', $context);
}
$line[] = get_string('pluginname', $cohort->component);
}
- if ($manager) {
- if (empty($cohort->component)) {
- $buttons = html_writer::link(new moodle_url('/cohort/edit.php', array('id'=>$cohort->id, 'delete'=>1)), html_writer::empty_tag('img', array('src'=>$OUTPUT->pix_url('t/delete'), 'alt'=>get_string('delete'), 'class'=>'iconsmall')));
- $buttons .= ' ' . html_writer::link(new moodle_url('/cohort/edit.php', array('id'=>$cohort->id)), html_writer::empty_tag('img', array('src'=>$OUTPUT->pix_url('t/edit'), 'alt'=>get_string('edit'), 'class'=>'iconsmall')));
- $buttons .= ' ' . html_writer::link(new moodle_url('/cohort/assign.php', array('id'=>$cohort->id)), html_writer::empty_tag('img', array('src'=>$OUTPUT->pix_url('i/users'), 'alt'=>get_string('assign', 'core_cohort'), 'class'=>'iconsmall')));
- } else {
- $buttons = '';
+ $buttons = array();
+ if (empty($cohort->component)) {
+ if ($manager) {
+ $buttons[] = html_writer::link(new moodle_url('/cohort/edit.php', array('id'=>$cohort->id, 'delete'=>1)), html_writer::empty_tag('img', array('src'=>$OUTPUT->pix_url('t/delete'), 'alt'=>get_string('delete'), 'class'=>'iconsmall')));
+ $buttons[] = html_writer::link(new moodle_url('/cohort/edit.php', array('id'=>$cohort->id)), html_writer::empty_tag('img', array('src'=>$OUTPUT->pix_url('t/edit'), 'alt'=>get_string('edit'), 'class'=>'iconsmall')));
+ }
+ if ($manager or $canassign) {
+ $buttons[] = html_writer::link(new moodle_url('/cohort/assign.php', array('id'=>$cohort->id)), html_writer::empty_tag('img', array('src'=>$OUTPUT->pix_url('i/users'), 'alt'=>get_string('assign', 'core_cohort'), 'class'=>'iconsmall')));
}
- } else {
- $buttons = '';
}
- $line[] = $buttons;
+ $line[] = implode(' ', $buttons);
$data[] = $line;
}
if (version_compare(phpversion(), "5.2.0") < 0) {
$phpversion = phpversion();
// do NOT localise - lang strings would not work here and we CAN not move it after installib
- echo "Sorry, Moodle 2.0 requires PHP 5.2.8 or later (currently using version $phpversion).<br />";
- echo "Please upgrade your server software or install latest Moodle 1.9.x instead.";
+ echo "Moodle 2.1 or later requires at least PHP 5.3.2 (currently using version $phpversion).<br />";
+ echo "Please upgrade your server software or install older Moodle version.";
+ die;
+}
+
+// make sure iconv is available and actually works
+if (!function_exists('iconv')) {
+ // this should not happen, this must be very borked install
+ echo 'Moodle requires the iconv PHP extension. Please install or enable the iconv extension.';
+ die();
+}
+if (iconv('UTF-8', 'UTF-8//IGNORE', 'abc') !== 'abc') {
+ // known to be broken in mid-2011 MAMP installations
+ echo 'Broken iconv PHP extension detected, installation can not continue.';
die;
}
if (!empty($memlimit) and $memlimit != -1) {
if (get_real_size($memlimit) < get_real_size($minrequiredmemory)) {
// do NOT localise - lang strings would not work here and we CAN not move it to later place
- echo "Sorry, Moodle 2.0 requires at least {$minrequiredmemory}B of PHP memory.<br />";
+ echo "Moodle requires at least {$minrequiredmemory}B of PHP memory.<br />";
echo "Please contact server administrator to fix PHP.ini memory settings.";
die;
}
if ($config->stage == INSTALL_ENVIRONMENT or $config->stage == INSTALL_PATHS) {
- $version_fail = (version_compare(phpversion(), "5.2.8") < 0);
+ $version_fail = (version_compare(phpversion(), "5.3.2") < 0);
$curl_fail = ($lang !== 'en' and !extension_loaded('curl')); // needed for lang pack download
$zip_fail = ($lang !== 'en' and !extension_loaded('zip')); // needed for lang pack download
echo '<div id="envresult"><dl>';
if ($version_fail) {
- $a = (object)array('needed'=>'5.2.8', 'current'=>phpversion());
+ $a = (object)array('needed'=>'5.3.2', 'current'=>phpversion());
echo '<dt>'.get_string('phpversion', 'install').'</dt><dd>'.get_string('environmentrequireversion', 'admin', $a).'</dd>';
}
if ($curl_fail) {
$instanceids[] = $blockinstance->id;
// If we have more than 1000 block instances now remove all block positions
// and empty the array
- if (count($contextids) > 1000) {
+ if (count($instanceids) > 1000) {
$instanceidstring = join(',',$instanceids);
$DB->delete_records_select('block_positions', 'blockinstanceid IN ('.$instanceidstring.')');
$instanceids = array();
upgrade_cleanup_unwanted_block_contexts($contextids);
- $instanceidstring = join(',',$instanceids);
- $DB->delete_records_select('block_positions', 'blockinstanceid IN ('.$instanceidstring.')');
+ if ($instanceids) {
+ $instanceidstring = join(',',$instanceids);
+ $DB->delete_records_select('block_positions', 'blockinstanceid IN ('.$instanceidstring.')');
+ }
unset($allblockinstances);
unset($contextids);
return $this->tables;
}
$this->tables = array();
- $prefix = str_replace('_', '\\\\_', $this->prefix);
+ $prefix = str_replace('_', '|_', $this->prefix);
// Get them from information_schema instead of catalog as far as
// we want to get only own session temp objects (catalog returns all)
$sql = "SELECT table_name
FROM information_schema.tables
- WHERE table_name LIKE '$prefix%'
+ WHERE table_name LIKE '$prefix%' ESCAPE '|'
AND table_type IN ('BASE TABLE', 'LOCAL TEMPORARY')";
$this->query_start($sql, null, SQL_QUERY_AUX);
$result = pg_query($this->pgsql, $sql);
* @param $filename
*/
public function get_file_info($component, $filearea, $itemid, $filepath, $filename) {
+ // try to emulate require_login() tests here
+ if (!isloggedin()) {
+ return null;
+ }
+
if (!$this->course->visible and !has_capability('moodle/course:viewhiddencourses', $this->context)) {
return null;
}
+ if (!is_viewing($this->context) and !is_enrolled($this->context)) {
+ // no peaking here if not enrolled or inspector
+ return null;
+ }
+
if (empty($component)) {
return $this;
}
* @param $filename
*/
public function get_file_info($component, $filearea, $itemid, $filepath, $filename) {
- if (!is_enrolled($this->context) and !is_viewing($this->context)) {
+ // try to emulate require_login() tests here
+ if (!isloggedin()) {
+ return null;
+ }
+
+ $coursecontext = get_course_context($this->context);
+ if (!$this->course->visible and !has_capability('moodle/course:viewhiddencourses', $coursecontext)) {
+ return null;
+ }
+
+ if (!is_viewing($this->context) and !is_enrolled($this->context)) {
// no peaking here if not enrolled or inspector
return null;
}
+ $modinfo = get_fast_modinfo($this->course);
+ $cminfo = $modinfo->get_cm($this->cm->id);
+ if (!$cminfo->uservisible) {
+ // activity hidden sorry
+ return null;
+ }
+
if (empty($component)) {
return $this;
}
* @return void
*/
function _group_verify_activegroup($courseid, $groupmode, $groupingid, array $allowedgroups) {
- global $SESSION;
+ global $SESSION, $USER;
// init activegroup array if necessary
if (!isset($SESSION->activegroup)) {
$SESSION->activegroup[$courseid][$groupmode][$groupingid] = 0; // all groups by default if user has accessallgroups
} else if ($allowedgroups) {
- $firstgroup = reset($allowedgroups);
+ if ($groupmode != SEPARATEGROUPS and $mygroups = groups_get_all_groups($courseid, $USER->id, $groupingid)) {
+ $firstgroup = reset($mygroups);
+ } else {
+ $firstgroup = reset($allowedgroups);
+ }
$SESSION->activegroup[$courseid][$groupmode][$groupingid] = $firstgroup->id;
} else {
// last course access not necessary either
$DB->delete_records('user_lastaccess', array('userid'=>$user->id));
+ // force logout - may fail if file based sessions used, sorry
+ session_kill_user($user->id);
+
// now do a final accesslib cleanup - removes all role assignments in user context and context itself
delete_context(CONTEXT_USER, $user->id);
if (!isset($CFG->sessioncookie)) {
$CFG->sessioncookie = '';
}
+
+ // make sure cookie domain makes sense for this wwwroot
if (!isset($CFG->sessioncookiedomain)) {
$CFG->sessioncookiedomain = '';
+ } else if ($CFG->sessioncookiedomain !== '') {
+ $host = parse_url($CFG->wwwroot, PHP_URL_HOST);
+ if ($CFG->sessioncookiedomain !== $host) {
+ if (substr($CFG->sessioncookiedomain, 0, 1) === '.') {
+ if (!preg_match('|^.*'.preg_quote($CFG->sessioncookiedomain, '|').'$|', $host)) {
+ // invalid domain - it must be end part of host
+ $CFG->sessioncookiedomain = '';
+ }
+ } else {
+ if (!preg_match('|^.*\.'.preg_quote($CFG->sessioncookiedomain, '|').'$|', $host)) {
+ // invalid domain - it must be end part of host
+ $CFG->sessioncookiedomain = '';
+ }
+ }
+ }
}
+
+ // make sure the cookiepath is valid for this wwwroot or autodetect if not specified
if (!isset($CFG->sessioncookiepath)) {
- $CFG->sessioncookiepath = '/';
+ $CFG->sessioncookiepath = '';
+ }
+ if ($CFG->sessioncookiepath !== '/') {
+ $path = parse_url($CFG->wwwroot, PHP_URL_PATH).'/';
+ if ($CFG->sessioncookiepath === '') {
+ $CFG->sessioncookiepath = $path;
+ } else {
+ if (strpos($path, $CFG->sessioncookiepath) !== 0 or substr($CFG->sessioncookiepath, -1) !== '/') {
+ $CFG->sessioncookiepath = $path;
+ }
+ }
}
//discard session ID from POST, GET and globals to tighten security,
*/
function quiz_grade_item_update($quiz, $grades = null) {
global $CFG, $OUTPUT;
+ require_once($CFG->dirroot . '/mod/quiz/locallib.php');
require_once($CFG->libdir.'/gradelib.php');
if (array_key_exists('cmidnumber', $quiz)) { // may not be always present
/**
* @return bool whether this analysis has a response class more than one
- * different acutal response.
+ * different acutal response, or if the actual response is different from
+ * the model response.
*/
public function has_actual_responses() {
foreach ($this->responseclasses as $subpartid => $partclasses) {
- foreach ($partclasses as $responseclassid => $notused) {
- if (count($this->responses[$subpartid][$responseclassid]) > 1) {
+ foreach ($partclasses as $responseclassid => $modelresponse) {
+ $numresponses = count($this->responses[$subpartid][$responseclassid]);
+ if ($numresponses > 1) {
+ return true;
+ }
+ $actualresponse = key($this->responses[$subpartid][$responseclassid]);
+ if ($numresponses == 1 && $actualresponse != $modelresponse->responseclass) {
return true;
}
}
$fs->move_area_files_to_new_context($oldcontextid,
$newcontextid, 'qtype_match', 'subquestion', $subquestionid);
}
+
+ $this->move_files_in_combined_feedback($questionid, $oldcontextid, $newcontextid);
}
protected function delete_files($questionid, $contextid) {
$fs->delete_area_files($contextid, 'qtype_match', 'subquestion', $subquestionid);
}
- $fs->delete_area_files($contextid, 'qtype_multichoice',
- 'correctfeedback', $questionid);
- $fs->delete_area_files($contextid, 'qtype_multichoice',
- 'partiallycorrectfeedback', $questionid);
- $fs->delete_area_files($contextid, 'qtype_multichoice',
- 'incorrectfeedback', $questionid);
+ $this->delete_files_in_combined_feedback($questionid, $contextid);
}
}
return $plugin;
}
-
- /**
- * Returns one array with filearea => mappingname elements for the qtype
- *
- * Used by {@link get_components_and_fileareas} to know about all the qtype
- * files to be processed both in backup and restore.
- */
- public static function get_qtype_fileareas() {
- return array(
- 'correctfeedback' => 'question_created',
- 'partiallycorrectfeedback' => 'question_created',
- 'incorrectfeedback' => 'question_created');
- }
}
}
public function move_files($questionid, $oldcontextid, $newcontextid) {
- $fs = get_file_storage();
-
parent::move_files($questionid, $oldcontextid, $newcontextid);
$this->move_files_in_answers($questionid, $oldcontextid, $newcontextid, true);
-
- $fs->move_area_files_to_new_context($oldcontextid,
- $newcontextid, 'qtype_multichoice', 'correctfeedback', $questionid);
- $fs->move_area_files_to_new_context($oldcontextid,
- $newcontextid, 'qtype_multichoice', 'partiallycorrectfeedback', $questionid);
- $fs->move_area_files_to_new_context($oldcontextid,
- $newcontextid, 'qtype_multichoice', 'incorrectfeedback', $questionid);
+ $this->move_files_in_combined_feedback($questionid, $oldcontextid, $newcontextid);
}
protected function delete_files($questionid, $contextid) {
- $fs = get_file_storage();
-
parent::delete_files($questionid, $contextid);
$this->delete_files_in_answers($questionid, $contextid, true);
-
- $fs->delete_area_files($contextid,
- 'qtype_multichoice', 'correctfeedback', $questionid);
- $fs->delete_area_files($contextid,
- 'qtype_multichoice', 'partiallycorrectfeedback', $questionid);
- $fs->delete_area_files($contextid,
- 'qtype_multichoice', 'incorrectfeedback', $questionid);
+ $this->delete_files_in_combined_feedback($questionid, $contextid);
}
}
}
public static function no_response() {
- return new question_classified_response(null, null, null);
+ return new question_classified_response(null, get_string('noresponse', 'question'), null);
}
}
}
}
+ /**
+ * Move all the files belonging to this question's answers when the question
+ * is moved from one context to another.
+ * @param int $questionid the question being moved.
+ * @param int $oldcontextid the context it is moving from.
+ * @param int $newcontextid the context it is moving to.
+ * @param bool $answerstoo whether there is an 'answer' question area,
+ * as well as an 'answerfeedback' one. Default false.
+ */
+ protected function move_files_in_combined_feedback($questionid, $oldcontextid,
+ $newcontextid) {
+ global $DB;
+ $fs = get_file_storage();
+
+ $fs->move_area_files_to_new_context($oldcontextid,
+ $newcontextid, 'question', 'correctfeedback', $questionid);
+ $fs->move_area_files_to_new_context($oldcontextid,
+ $newcontextid, 'question', 'partiallycorrectfeedback', $questionid);
+ $fs->move_area_files_to_new_context($oldcontextid,
+ $newcontextid, 'question', 'incorrectfeedback', $questionid);
+ }
+
/**
* Delete all the files belonging to this question.
* @param int $questionid the question being deleted.
}
}
+ /**
+ * Delete all the files belonging to this question's answers.
+ * @param int $questionid the question being deleted.
+ * @param int $contextid the context the question is in.
+ * @param bool $answerstoo whether there is an 'answer' question area,
+ * as well as an 'answerfeedback' one. Default false.
+ */
+ protected function delete_files_in_combined_feedback($questionid, $contextid) {
+ global $DB;
+ $fs = get_file_storage();
+
+ $fs->delete_area_files($contextid,
+ 'question', 'correctfeedback', $questionid);
+ $fs->delete_area_files($contextid,
+ 'question', 'partiallycorrectfeedback', $questionid);
+ $fs->delete_area_files($contextid,
+ 'question', 'incorrectfeedback', $questionid);
+ }
+
public function import_file($context, $component, $filearea, $itemid, $file) {
$fs = get_file_storage();
$record = new stdClass();
die;
}
-function combo_not_found() {
+function combo_not_found($message = '') {
header('HTTP/1.0 404 not found');
- die('Combo resource not found, sorry.');
+ if ($message) {
+ echo $message;
+ } else {
+ echo 'Combo resource not found, sorry.';
+ }
+ die;
}
function combo_params() {
- if (!empty($_SERVER['REQUEST_URI'])) {
- $parts = explode('?', $_SERVER['REQUEST_URI']);
- if (count($parts) != 2) {
- return '';
- }
+ // note: buggy or misconfigured IIS does return the query string in REQUEST_URL
+ if (isset($_SERVER['REQUEST_URI']) and strpos($_SERVER['REQUEST_URI'], '?') !== false) {
+ $parts = explode('?', $_SERVER['REQUEST_URI'], 2);
return $parts[1];
- } else if (!empty($_SERVER['QUERY_STRING'])) {
+ } else if (isset($_SERVER['QUERY_STRING'])) {
return $_SERVER['QUERY_STRING'];
} else {
- return '';
+ // unsupported server, sorry!
+ combo_not_found('Unsupported server - query string can not be determined, try disabling YUI combo loading in admin settings.');
}
}