From: skodak Date: Fri, 19 Jan 2007 10:29:03 +0000 (+0000) Subject: MDL-8223 - last global $course hacks removed X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=60f9e36ee8402ee4f241f49ea7ad4ff293faee7d;p=moodle.git MDL-8223 - last global $course hacks removed --- diff --git a/enrol/authorize/enrol_form.php b/enrol/authorize/enrol_form.php index 6743910094..2e14edd333 100755 --- a/enrol/authorize/enrol_form.php +++ b/enrol/authorize/enrol_form.php @@ -6,7 +6,7 @@ class enrol_authorize_form extends moodleform { function definition() { - global $course; + global $COURSE; global $CFG, $USER; $paymentmethodsenabled = get_list_of_payment_methods(); @@ -22,7 +22,7 @@ class enrol_authorize_form extends moodleform $mform->addElement('static', '', '
' . $othermethodstr . '  
', ''); } - $mform->addElement('hidden', 'id', $course->id); + $mform->addElement('hidden', 'id', $COURSE->id); $mform->setType('id', PARAM_INT); $mform->addElement('hidden', 'paymentmethod', $paymentmethod); @@ -220,16 +220,16 @@ class enrol_authorize_form extends moodleform function other_method($currentmethod) { - global $course; + global $COURSE; if ($currentmethod == AN_METHOD_CC) { $otheravailable = in_array(AN_METHOD_ECHECK, get_list_of_payment_methods()); - $url = 'enrol.php?id='.$course->id.'&paymentmethod='.AN_METHOD_ECHECK; + $url = 'enrol.php?id='.$COURSE->id.'&paymentmethod='.AN_METHOD_ECHECK; $stringtofetch = 'usingecheckmethod'; } else { $otheravailable = in_array(AN_METHOD_CC, get_list_of_payment_methods()); - $url = 'enrol.php?id='.$course->id.'&paymentmethod='.AN_METHOD_CC; + $url = 'enrol.php?id='.$COURSE->id.'&paymentmethod='.AN_METHOD_CC; $stringtofetch = 'usingccmethod'; } if ($otheravailable) { diff --git a/grade/lib.php b/grade/lib.php index 3978c7b1bf..d4a1ae7b70 100644 --- a/grade/lib.php +++ b/grade/lib.php @@ -155,8 +155,9 @@ function grade_get_users_by_group($course, $group) { function grade_get_formatted_grades() { global $CFG; - global $course; + global $COURSE; global $preferences; + $course = $COURSE; $i = 2; // index to differentiate activities with the same name MDL-6876 $grades = grade_get_grades(); if (isset($grades)) { diff --git a/lib/filelib.php b/lib/filelib.php index 2d4a3ff3a0..cbce2eaf11 100644 --- a/lib/filelib.php +++ b/lib/filelib.php @@ -248,7 +248,7 @@ function get_mimetype_description($mimetype,$capitalise=false) { * @param string $mimetype Include to specify the MIME type; leave blank to have it guess the type from $filename */ function send_file($path, $filename, $lifetime=86400 , $filter=0, $pathisstring=false, $forcedownload=false, $mimetype='') { - global $CFG; + global $CFG, $COURSE; // Use given MIME type if specified, otherwise guess it using mimeinfo. // IE, Konqueror and Opera open html file directly in browser from web even when directed to save it to disk :-O @@ -369,18 +369,12 @@ function send_file($path, $filename, $lifetime=86400 , $filter=0, $pathisstring= readfile_chunked($path); } } else { // Try to put the file through filters - global $course; // HACK! - if (!empty($course->id)) { - $courseid = $course->id; - } else { - $courseid = SITEID; - } if ($mimetype == 'text/html') { $options = new object(); $options->noclean = true; $options->nocache = true; // temporary workaround for MDL-5136 $text = $pathisstring ? $path : implode('', file($path)); - $output = format_text($text, FORMAT_HTML, $options, $courseid); + $output = format_text($text, FORMAT_HTML, $options, $COURSE->id); if (!empty($CFG->usesid) && empty($_COOKIE['MoodleSession'.$CFG->sessioncookie])) { //cookieless mode - rewrite links $output = sid_ob_rewrite($output); @@ -392,10 +386,11 @@ function send_file($path, $filename, $lifetime=86400 , $filter=0, $pathisstring= echo $output; // only filter text if filter all files is selected } else if (($mimetype == 'text/plain') and ($filter == 1)) { + $options = new object(); $options->newlines = false; $options->noclean = true; $text = htmlentities($pathisstring ? $path : implode('', file($path))); - $output = '
'. format_text($text, FORMAT_MOODLE, $options, $courseid) .'
'; + $output = '
'. format_text($text, FORMAT_MOODLE, $options, $COURSE->id) .'
'; if (!empty($CFG->usesid) && empty($_COOKIE['MoodleSession'.$CFG->sessioncookie])) { //cookieless mode - rewrite links $output = sid_ob_rewrite($output); diff --git a/lib/moodlelib.php b/lib/moodlelib.php index 98c318eff5..17624b99cc 100644 --- a/lib/moodlelib.php +++ b/lib/moodlelib.php @@ -1583,7 +1583,7 @@ function require_login($courseorid=0, $autologinguest=true, $cm=null) { } else if (is_object($courseorid)) { $COURSE = clone($courseorid); } else { - global $course; // We use the global hack once here so it doesn't need to be used again + global $course; // used here only to prevent repeated fetching from DB if ($course->id == $courseorid) { $COURSE = clone($course); } else { @@ -3202,14 +3202,13 @@ function moodle_process_email($modargs,$body) { */ function email_to_user($user, $from, $subject, $messagetext, $messagehtml='', $attachment='', $attachname='', $usetrueaddress=true, $replyto='', $replytoname='') { - global $CFG, $FULLME; + global $CFG, $FULLME, $COURSE; - global $course; // This is a bit of an ugly hack to be gotten rid of later - if (!empty($course->lang)) { // Course language is defined - $CFG->courselang = $course->lang; + if (!empty($COURSE->lang)) { // Course language is defined + $CFG->courselang = $COURSE->lang; } - if (!empty($course->theme)) { // Course theme is defined - $CFG->coursetheme = $course->theme; + if (!empty($COURSE->theme)) { // Course theme is defined + $CFG->coursetheme = $COURSE->theme; } include_once($CFG->libdir .'/phpmailer/class.phpmailer.php'); @@ -4127,12 +4126,10 @@ function get_string($identifier, $module='', $a=NULL, $extralocations=NULL) { global $CFG; - global $course, $COURSE; + global $COURSE; if (empty($CFG->courselang)) { if (!empty($COURSE->lang)) { $CFG->courselang = $COURSE->lang; - } else if (!empty($course->lang)) { // ugly backwards compatibility hack - $CFG->courselang = $course->lang; } } diff --git a/lib/weblib.php b/lib/weblib.php index 08d4dea6a3..9efb11db91 100644 --- a/lib/weblib.php +++ b/lib/weblib.php @@ -2030,24 +2030,16 @@ function print_header ($title='', $heading='', $navigation='', $focus='', define('HEADER_PRINTED', 'true'); - global $course, $COURSE; + global $COURSE; if (!empty($COURSE->lang)) { $CFG->courselang = $COURSE->lang; moodle_setlocale(); - } else if (!empty($course->lang)) { // ugly backwards compatibility hack - $CFG->courselang = $course->lang; - moodle_setlocale(); } if (!empty($COURSE->theme)) { if (!empty($CFG->allowcoursethemes)) { $CFG->coursetheme = $COURSE->theme; theme_setup(); } - } else if (!empty($course->theme)) { // ugly backwards compatibility hack - if (!empty($CFG->allowcoursethemes)) { - $CFG->coursetheme = $course->theme; - theme_setup(); - } } /// We have to change some URLs in styles if we are in a $HTTPSPAGEREQUIRED page @@ -2093,11 +2085,7 @@ function print_header ($title='', $heading='', $navigation='', $focus='', } else { $wwwroot = str_replace('http:','https:',$CFG->wwwroot); } - if (isset($course->id)) { - $menu = user_login_string($course); - } else { - $menu = user_login_string($SITE); - } + $menu = user_login_string($COURSE); } if (isset($SESSION->justloggedin)) { @@ -2193,11 +2181,7 @@ function print_header ($title='', $heading='', $navigation='', $focus='', page_id_and_class($pageid, $pageclass); - if (isset($course->id)) { - $pageclass .= ' course-'.$course->id; - } else { - $pageclass .= ' course-'.SITEID; - } + $pageclass .= ' course-'.$COURSE->id; if (($pageid != 'site-index') && ($pageid != 'course-view') && ($pageid != 'admin-settings')) { diff --git a/mod/chat/gui_header_js/chatinput.php b/mod/chat/gui_header_js/chatinput.php index 208e6352c8..4fbf97affb 100644 --- a/mod/chat/gui_header_js/chatinput.php +++ b/mod/chat/gui_header_js/chatinput.php @@ -12,13 +12,10 @@ } //Get the course theme - $course = get_record('course','id',$chatuser->course,'','','','','id,theme'); - //Set the global course if necessary - if (!empty($course->theme)) { - global $course; - } + $COURSE = get_record('course','id',$chatuser->course); + //Get the user theme - $USER = get_record('user','id',$chatuser->userid,'','','','','id, theme'); + $USER = get_record('user','id',$chatuser->userid); //Adjust the prefered theme (main, course, user) theme_setup(); diff --git a/question/format/blackboard_6/format.php b/question/format/blackboard_6/format.php index cd0f011e46..87d8e2eae0 100644 --- a/question/format/blackboard_6/format.php +++ b/question/format/blackboard_6/format.php @@ -123,13 +123,12 @@ class qformat_blackboard_6 extends qformat_default { } function copy_file_to_course($filename) { - global $CFG; - global $course; + global $CFG, $COURSE; $filename = str_replace('\\','/',$filename); $fullpath = $this->temp_dir.'/res00001/'.$filename; $basename = basename($filename); - $copy_to = $CFG->dataroot.'/'.$course->id.'/bb_import'; + $copy_to = $CFG->dataroot.'/'.$COURSE->id.'/bb_import'; if ($this->check_dir_exists($copy_to,true)) { if(is_readable($fullpath)) { @@ -347,7 +346,7 @@ function create_raw_question($quest) { } function process_block($cur_block, &$block) { - global $course, $CFG; + global $COURSE, $CFG; $cur_type = $cur_block['@']['class']; switch($cur_type) { @@ -363,7 +362,7 @@ function process_block($cur_block, &$block) { if ($block->file != '') { // if we have a file copy it to the course dir and adjust its name to be visible over the web. $block->file = $this->copy_file_to_course($block->file); - $block->file = $CFG->wwwroot.'/file.php/'.$course->id.'/bb_import/'.basename($block->file); + $block->file = $CFG->wwwroot.'/file.php/'.$COURSE->id.'/bb_import/'.basename($block->file); } break; case 'Block': @@ -845,7 +844,7 @@ function process_matching($quest, &$questions) { $questions[] = $question; } else { - global $course, $CFG; + global $COURSE, $CFG; print ''; print ''; @@ -853,7 +852,7 @@ function process_matching($quest, &$questions) { if (isset($quest->QUESTION_BLOCK->file)) { print '
There is a subfile contained in the zipfile that has been copied to course files: bb_import/'.basename($quest->QUESTION_BLOCK->file).''; if (preg_match('/(gif|jpg|jpeg|png)$/i', $quest->QUESTION_BLOCK->file)) { - print ''; + print ''; } } print ""; diff --git a/question/format/hotpot/format.php b/question/format/hotpot/format.php index 0663f2f2d6..db33a3c3c3 100644 --- a/question/format/hotpot/format.php +++ b/question/format/hotpot/format.php @@ -124,8 +124,8 @@ class qformat_hotpot extends qformat_default { if ($moodle_14) { $question->answers = array(); } else { - global $course; // set in mod/quiz/import.php - $question->course = $course->id; + global $COURSE; // initialized in questions/import.php + $question->course = $COURSE->id; $question->options = new stdClass(); $question->options->questions = array(); // one for each gap }
This matching question is malformed. Please ensure there are no blank answers, no two questions have the same answer, and/or there are correct answers for each question. There must be at least as many subanswers as subquestions, and at least one subquestion.