]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-8223 - last global $course hacks removed
authorskodak <skodak>
Fri, 19 Jan 2007 10:29:03 +0000 (10:29 +0000)
committerskodak <skodak>
Fri, 19 Jan 2007 10:29:03 +0000 (10:29 +0000)
enrol/authorize/enrol_form.php
grade/lib.php
lib/filelib.php
lib/moodlelib.php
lib/weblib.php
mod/chat/gui_header_js/chatinput.php
question/format/blackboard_6/format.php
question/format/hotpot/format.php

index 67439100942b4bdb9483d7722d0831f01f1513fe..2e14edd33327fe00bb45834e4e619d24c61f0e54 100755 (executable)
@@ -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', '', '<div align="right">' . $othermethodstr . '&nbsp;&nbsp;</div>', '');
         }
 
-        $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.'&amp;paymentmethod='.AN_METHOD_ECHECK;
+        $url = 'enrol.php?id='.$COURSE->id.'&amp;paymentmethod='.AN_METHOD_ECHECK;
         $stringtofetch = 'usingecheckmethod';
     }
     else {
         $otheravailable = in_array(AN_METHOD_CC, get_list_of_payment_methods());
-        $url = 'enrol.php?id='.$course->id.'&amp;paymentmethod='.AN_METHOD_CC;
+        $url = 'enrol.php?id='.$COURSE->id.'&amp;paymentmethod='.AN_METHOD_CC;
         $stringtofetch = 'usingccmethod';
     }
     if ($otheravailable) {
index 3978c7b1bf0ae5f621964c6861f5efc7e7c3e2fc..d4a1ae7b70a3ebdd22511356585771580a0f621c 100644 (file)
@@ -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)) {
index 2d4a3ff3a0e9ffd27d795c5cac3e58a3ed4996af..cbce2eaf111197f593c886dbe8d8b54f1d913ef4 100644 (file)
@@ -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 = '<pre>'. format_text($text, FORMAT_MOODLE, $options, $courseid) .'</pre>';
+            $output = '<pre>'. format_text($text, FORMAT_MOODLE, $options, $COURSE->id) .'</pre>';
             if (!empty($CFG->usesid) && empty($_COOKIE['MoodleSession'.$CFG->sessioncookie])) {
                 //cookieless mode - rewrite links
                 $output = sid_ob_rewrite($output);
index 98c318eff5224a517b889de241fd4bb998a05620..17624b99cc47a166ee9de64e7b31cbc4bebfcff0 100644 (file)
@@ -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;
         }
     }
 
index 08d4dea6a30031c23f9a3f1c7a0d52e3c9a6b9a0..9efb11db91b3051bca24c4201ba5f8a1f6c9eb02 100644 (file)
@@ -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')) {
index 208e6352c8552c713ce2e91bc4c01fb7f777a0d7..4fbf97affb5a6d63e3a246c7e9eccbc27b84a046 100644 (file)
     }
 
     //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();
index cd0f011e46b82dcd1fc0e6b5d1e167f13bd6e394..87d8e2eae0ca5a049f54ada4df6e28b37dcd501a 100644 (file)
@@ -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 '<table class="boxaligncenter" border="1">';
             print '<tr><td colspan="2" style="background-color:#FF8888;">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.</td></tr>'; 
         
@@ -853,7 +852,7 @@ function process_matching($quest, &$questions) {
             if (isset($quest->QUESTION_BLOCK->file)) {
                 print '<br/><font color="red">There is a subfile contained in the zipfile that has been copied to course files: bb_import/'.basename($quest->QUESTION_BLOCK->file).'</font>';
                 if (preg_match('/(gif|jpg|jpeg|png)$/i', $quest->QUESTION_BLOCK->file)) {
-                    print '<img src="'.$CFG->wwwroot.'/file.php/'.$course->id.'/bb_import/'.basename($quest->QUESTION_BLOCK->file).'" />';
+                    print '<img src="'.$CFG->wwwroot.'/file.php/'.$COURSE->id.'/bb_import/'.basename($quest->QUESTION_BLOCK->file).'" />';
                 }
             }
             print "</td></tr>";
index 0663f2f2d64d978e01b89840322b24f1ebc84d46..db33a3c3c3dcb236dc1b2326bc0e8d9b197a2987 100644 (file)
@@ -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
             }