]> git.mjollnir.org Git - moodle.git/commitdiff
Widespread changes throughout Moodle to make sure it works on
authormartin <martin>
Tue, 6 Aug 2002 17:23:45 +0000 (17:23 +0000)
committermartin <martin>
Tue, 6 Aug 2002 17:23:45 +0000 (17:23 +0000)
servers that have register_globals turned off (this is the
default setting on newer version of PHP).

In fact it's partly a hack that globalises all GET, POST, FILES
AND COOKIE variables.  Unfortunately though the SESSION and
USER global session variables are only available as $_SESSION["USER"]
and $_SESSION["SESSION"], which is cumbersome to use.

So, for every request I now make a copy of these two session variables
into $USER and $SESSION.  Whenever I update them thoughout Moodle I
now have to call save_session("USER") which copies them back to the
session variable.  This seems to be working well now.

Because I'm using $_SESSION etc now this will raise
the required minimum version of PHP to 4.1.0

27 files changed:
admin/user.php
course/enrol.php
course/loginas.php
course/mod.php
course/social.php
course/topics.php
course/unenrol.php
course/view.php
course/weeks.php
doc/install.html
index.php
lib/moodlelib.php
lib/setup.php
login/change_password.php
login/confirm.php
login/index.php
login/logout.php
mod/forum/discuss.php
mod/forum/index.php
mod/forum/lib.php
mod/forum/post.php
mod/forum/rate.php
mod/forum/search.php
mod/forum/subscribers.php
mod/forum/view.php
user/edit.php
user/lib.php

index 64b42bc636014cfd2d3783e2f5d2933922ef3578..2f31ce983efbc2c3d6924d74642abaee8f4484a7 100644 (file)
@@ -44,7 +44,7 @@
         $USER->loggedin = true;
         $USER->admin = true;
         $USER->teacher["$course->id"] = true;
-
+        save_session("USER");
     }
 
     require_login();
                 if ($usernew->id == $USER->id) {  // Reload admin
                     $USER = get_user_info_from_db("id", $usernew->id);
                     $USER->loggedin = true;
+                    save_session("USER");
                            set_moodle_cookie($USER->username);
                 }
                        redirect("index.php", "Changes saved");
index 6455e25d0cb4ddb116c17e5c4375bf838ce511d1..68c8870ca28d3688290de7d739d9104168a82831 100644 (file)
             }
 
             $USER->student["$id"] = true;
+            save_session("USER");
             
             if ($SESSION->wantsurl) {
                 $destination = $SESSION->wantsurl;
                 unset($SESSION->wantsurl);
+                save_session("SESSION");
             } else {
                 $destination = "$CFG->wwwroot/course/view.php?id=$id";
             }
         }
 
         $USER->student["$id"] = true;
+        save_session("USER");
         
         if ($SESSION->wantsurl) {
             $destination = $SESSION->wantsurl;
             unset($SESSION->wantsurl);
+            save_session("SESSION");
         } else {
             $destination = "$CFG->wwwroot/course/view.php?id=$id";
         }
index febaf7f866cab29957e93a2372dd3bfc79577672..c011b19f0d86840941e9e25adbcdc0bc71ebaff1 100644 (file)
@@ -36,4 +36,6 @@
 
     notice("You are now logged in as $student_name", "$CFG->wwwroot/course/view.php?id=$course->id");
 
+    save_session("USER");
+
 ?>
index adcf63d8bb14888c87354a93d0ae6cf6b4cb8ae8..2b5512a350f218a3e2cbaceb0e277a110251b0d4 100644 (file)
@@ -70,6 +70,7 @@
         if ($SESSION->returnpage) {
             $return = $SESSION->returnpage;
             unset($SESSION->returnpage);
+            save_session("SESSION");
             redirect($return);
         } else {
             redirect("view.php?id=$mod->course");
@@ -79,6 +80,7 @@
 
     if (isset($return)) {  
         $SESSION->returnpage = $HTTP_REFERER;
+        save_session("SESSION");
     }
 
     if (isset($move)) {  
index a034d47a3e33fac3b304f3834951139cac6264e4..979036a98b804fe81acb4fe91837024b6eea8b37 100644 (file)
@@ -48,7 +48,7 @@
       echo "</DIV>";
 
       // Print Admin links for teachers and admin.
-      if (isteacher($USER->id) || isadmin()) {
+      if (isteacher($course->id) || isadmin()) {
           print_simple_box("Admin", $align="CENTER", $width="100%", $color="$THEME->cellheading");
           $adminicon[]="<IMG SRC=\"../pix/i/edit.gif\" HEIGHT=16 WIDTH=16 ALT=\"Edit\">";
           if (isediting($course->id)) {
@@ -82,6 +82,7 @@
     
           forum_print_latest_discussions($social->id, 10, "plain", "DESC", false);
           $SESSION->fromdiscussion = "$CFG->wwwroot/course/view.php?id=$course->id";
+          save_session("SESSION");
 
       } else {
           notify("Could not find or create a social forum here");
index ae18b931366121a0d35127b178c5268ba4ac2d00..0728aea501ea0c502a900c7157077732cb407796 100644 (file)
@@ -23,6 +23,7 @@
         } else {
             $USER->topic = $topic;
         }
+        save_session("USER");
     }
 
     if (isteacher($course->id) and isset($marker)) {
index 36f3102743a48a33b457d6c78fe6a3391c4c0e3a..ab538c702ee624dea958baca224adad3122a93c6 100644 (file)
@@ -37,6 +37,7 @@
 
         if ($user->id == $USER->id) {
             unset($USER->student["$id"]);
+            save_session("USER");
             redirect("$CFG->wwwroot");
         }
         
index 6cbe7bf6bdee2a345f484f079b101f7358021275..44f778f07023ac795778cf4b4f25a677c11ff5b0 100644 (file)
@@ -39,6 +39,8 @@
         $USER->help = false;
     }
 
+    save_session("USER");
+
     if (! $course->category) {      // This course is not a real course.
         redirect("$CFG->wwwroot");
     }
index d4d0e89785463d58cdae995c821f742a067e466d..fa3f6b7a732cf2fbf735e2f2f95f44cca0310a02 100644 (file)
@@ -19,6 +19,7 @@
         } else {
             $USER->section = $week;
         }
+        save_session("USER");
     }
 
 
index 2729865505f0b8dc1b2d1621bf54f329d5b3af14..e4c61ee95c164e447684425e423603bd694c7641 100755 (executable)
@@ -26,7 +26,8 @@
 <UL>\r
   <LI>a working installation of <A HREF="http://www.php.net/">PHP</A> (version \r
     4.0.6 or better), including the <A HREF="http://www.boutell.com/gd/">GD</A> \r
-    library for manipulating images.</LI>\r
+    library for manipulating images and with the "register_globals" variable \r
+    turned ON (for now).</LI>\r
   <LI>a working database server (<A HREF="http://www.mysql.com/">MySQL</A>, PostgreSQL, \r
     MSSQL, Oracle, Interbase, Foxpro, Access, ADO, Sybase, DB2 or ODBC).</LI>\r
 </UL>\r
@@ -56,6 +57,7 @@
     <LI>course/ - code to display and manage courses </LI>\r
     <LI>doc/ - help documentation for Moodle (eg this page)</LI>\r
     <LI>files/ - code to display and manage uploaded files</LI>\r
+    <LI>lang/ - texts in different languages, one directory per language </LI>\r
     <LI>lib/ - libraries of core Moodle code </LI>\r
     <LI>login/ - code to handle login and account creation </LI>\r
     <LI>mod/ - all Moodle course modules</LI>\r
   </P>\r
 </BLOCKQUOTE>\r
 <P>If you don't see this, then there must have been some problem with the database \r
-  or the configuration settings you defined in config.php. Check these and try \r
-  this page again.</P>\r
+  or the configuration settings you defined in config.php. Check also that your \r
+  PHP installation has "register_globals" turned on (recent versions have this \r
+  off by default).  You can check PHP variables by creating a little file containing\r
+  &lt? phpinfo ?&gt and looking at it through a browser.  Check all these and try this page again.</P>\r
 <P>Press the &quot;Continue&quot; link at the bottom of the page.</P>\r
 <P>Next you will see a similar page that sets up all the tables required by each \r
   Moodle module. As before, they should all be green, otherwise you may be a problem \r
index 1a69752989c2df61e9fd54e52a2cea542a679f49..47afd3e69e7963bcc436d64e4a73ab8252086092 100644 (file)
--- a/index.php
+++ b/index.php
@@ -91,6 +91,7 @@
 
              if (isset($USER->id)) {
                  $SESSION->fromdiscussion = "$CFG->wwwroot";
+                 save_session($SESSION);
                  if (forum_is_subscribed($USER->id, $newsforum->id)) {
                      $subtext = get_string("unsubscribe", "forum");
                  } else {
index e67d3a34eefd0614992c769aa47fe31a0d2bcbe9..3c501466d6aa23aee28a650de47ab3a51a176c3c 100644 (file)
@@ -393,6 +393,7 @@ function error ($message, $link="") {
         if ( !empty($SESSION->fromurl) ) {
             $link = "$SESSION->fromurl";
             unset($SESSION->fromurl);
+            save_session("SESSION");
         } else {
             $link = "$CFG->wwwroot";
         }
@@ -455,7 +456,6 @@ function notice_yesno ($message, $linkyes, $linkno) {
 
 function redirect($url, $message="", $delay=0) {
 // Uses META tags to redirect the user, after printing a notice
-    global $THEME;
 
     echo "<META HTTP-EQUIV='Refresh' CONTENT='$delay; URL=$url'>";
 
@@ -895,6 +895,7 @@ function require_login($courseid=0) {
     if (! (isset( $USER->loggedin ) && $USER->confirmed) ) { 
         $SESSION->wantsurl = $FULLME;
         $SESSION->fromurl = $HTTP_REFERER;
+        save_session("SESSION");
         if ($PHPSESSID) { // Cookies not enabled.
             redirect("$CFG->wwwroot/login/?PHPSESSID=$PHPSESSID");
         } else {
@@ -920,6 +921,7 @@ function require_login($courseid=0) {
         // Not allowed in the course, so see if they want to enrol
 
         $SESSION->wantsurl = $FULLME;
+        save_session("SESSION");
         redirect("$CFG->wwwroot/course/enrol.php?id=$courseid");
         die;
     }
@@ -937,9 +939,11 @@ function update_login_count() {
     } else {
         $SESSION->logincount++;
     }
+    save_session("SESSION");
 
     if ($SESSION->logincount > $max_logins) {
         unset($SESSION->wantsurl);
+        save_session("SESSION");
         error("Sorry, you have exceeded the allowed number of login attempts. Restart your browser.");
     }
 }
@@ -1004,6 +1008,7 @@ function reset_login_count() {
     global $SESSION;
 
     $SESSION->logincount = 0;
+    save_session("SESSION");
 }
 
 
@@ -1023,6 +1028,13 @@ function get_moodle_cookie() {
 }
 
 
+function save_session($VAR) {
+// Copies temporary session variable to permanent sesson variable
+// eg $_SESSION["USER"] = $USER;
+    global $$VAR;
+    $_SESSION[$VAR] = $$VAR;
+}
+
 
 function verify_login($username, $password) {
 
index c3a0641908cc3f2b5f03635cd0dd3f1079f77016..90af95571c4facfa659c67b6316d0d596676d72a 100644 (file)
         setlocale ("LC_TIME", $CFG->lang);
     }
 
+// The following is a big hack to get around the problem of PHP installations
+// that have "register_globals" turned off (default since PHP 4.1.0).
+// Eventually I'll go through and upgrade all the code to make this unnecessary
+
+   if (isset($_REQUEST)) {
+       extract($_REQUEST);
+   }
+   if (isset($_SERVER)) { 
+       extract($_SERVER);
+   }
+
 // Load up theme variables (colours etc)
 
     require("$CFG->dirroot/theme/$CFG->theme/config.php");
     require("$CFG->libdir/adodb/adodb.inc.php"); // Database access functions
     require("$CFG->libdir/adodb/tohtml.inc.php");// Database display functions
     require("$CFG->libdir/moodlelib.php");       // Various Moodle functions
+
     
 // Load up global environment variables
 
     class object {};
     
     session_start();
-    session_register("SESSION");    // Current session info 
-    session_register("USER");       // Current user info
-    if (! isset($SESSION)) $SESSION = new object;
-    if (! isset($USER))    $USER = new object;
+    if (! isset($_SESSION["SESSION"])) { $_SESSION["SESSION"] = new object; }
+    if (! isset($_SESSION["USER"]))    { $_SESSION["USER"]    = new object; }
+    extract($_SESSION);  // Makes $SESSION and $USER available for read-only access
 
     $FULLME = qualified_me();
     $ME     = strip_querystring($FULLME);
@@ -70,5 +81,4 @@
     $db->PConnect($CFG->dbhost,$CFG->dbuser,$CFG->dbpass,$CFG->dbname); 
 
 
-
 ?>
index 9f8a5ec78ab7e7797febbf4139682fca76a337b0..ccd5a9b9da7a42496d59ba5860f067f6f4cae326 100644 (file)
@@ -27,9 +27,9 @@
                                error("Could not set the new password");
             }
 
-                       unset($USER);
                        $USER = $user;
                        $USER->loggedin = true;
+            save_session("USER");
 
                        set_moodle_cookie($USER->username);
 
index 235887ad56157cfa29c7979494e49cebc38cdebe..45fa7b193ffcaa19f790102ff46fb6a5f93b6301 100644 (file)
                                $USER->loggedin = true;
                                $USER->confirmed = 1;
 
-                               if ( ! empty($SESSION["wantsurl"]) ) {
-                                       $goto = $SESSION["wantsurl"];
+                save_session("USER");
+
+                               if ( ! empty($SESSION->wantsurl) ) {
+                                       $goto = $SESSION->wantsurl;
+                    unset($SESSION->wantsurl);
+                    save_session("SESSION");
                                        redirect("$goto");
                        }
  
index 0319c998e12b8aeb71e59adaf7cf625c16b0f63f..3bb4499c7fb53cc41c846f1d220ee61ec11144c4 100644 (file)
@@ -36,6 +36,7 @@
     
             $USER = $user;
             $USER->loggedin = true;
+            save_session("USER");
     
             if (!update_user_in_db()) {
                 error("Weird error: User not found");
@@ -44,7 +45,7 @@
             if (!update_user_login_times()) {
                 error("Wierd error: could not update login records");
             }
-    
+
                    set_moodle_cookie($USER->username);
 
     
@@ -53,6 +54,7 @@
                    } else {
                    header("Location: $SESSION->wantsurl");
                            unset($SESSION->wantsurl);
+                save_session("SESSION");
                    }
     
                    reset_login_count();
             $errormsg = get_string("invalidlogin");
         }
     }
+
     
     if (empty($SESSION->wantsurl)) {
-           $SESSION->wantsurl = $HTTP_REFERER;  
+           $SESSION->wantsurl = $HTTP_REFERER;
+        save_session("SESSION");
     }
     
     if (!$frm->username) 
@@ -92,6 +96,7 @@ function update_user_login_times() {
 
     $USER->lastlogin = $USER->currentlogin;
     $USER->currentlogin = time();
+    save_session("USER");
 
     return $db->Execute("UPDATE user 
                          SET lastlogin='$USER->lastlogin', currentlogin='$USER->currentlogin'
index 3f0aadcafcccc37f896d1eaace4eebbb74df190f..c0fda928eb789c2b284ec31c13fb8410eb6ae249 100644 (file)
@@ -4,6 +4,7 @@
     require("../config.php");
 
     $USER = NULL;
+    save_session("USER");
     redirect($HTTP_REFERER);
     exit;
 
index b6090c46cea06c7b6893e79874db8f0b1ae2d9a4..520d13a9fa3bf974901c1114ac01b622cab8952d 100644 (file)
@@ -29,6 +29,7 @@
     add_to_log($course->id, "forum", "view discussion", "discuss.php?".$_SERVER["QUERY_STRING"], "$discussion->id");
 
     unset($SESSION->fromdiscussion);
+    save_session("SESSION");
 
     forum_set_display_mode($mode);
 
index aadf4ff08a2d0f5bdc3337ab1691ccb5c0c1ff2f..b5a4df34123e0628fe0d43f7e4e00de9e7bfde0a 100644 (file)
@@ -20,6 +20,7 @@
     }
 
     unset($SESSION->fromdiscussion);
+    save_session("SESSION");
 
     add_to_log($course->id, "forum", "view forums", "index.php?id=$course->id");
 
index 06040877b988e21a6224c1f4461e04fcc3157387..76dffb553d6526c81693f977b30801097831bd12 100644 (file)
@@ -348,6 +348,7 @@ function forum_set_return() {
 
     if (! $SESSION->fromdiscussion) {
         $SESSION->fromdiscussion = $HTTP_REFERER;
+        save_session("SESSION");
     }
 }
 
@@ -358,6 +359,7 @@ function forum_go_back_to($default) {
     if ($SESSION->fromdiscussion) {
         $returnto = $SESSION->fromdiscussion;
         unset($SESSION->fromdiscussion);
+        save_session("SESSION");
         return $returnto;
     } else {
         return $default;
@@ -1026,8 +1028,10 @@ function forum_set_display_mode($mode=0) {
 
     if ($mode) {
         $USER->mode = $mode;
+        save_session("USER");
     } else if (!$USER->mode) {
         $USER->mode = $FORUM_DEFAULT_DISPLAY_MODE;
+        save_session("USER");
     }
 }
 
index 9ddaf2284870e073af4757d28bd99861e12e30fe..c01470ea0309a741b39679e1303627996a247ac5 100644 (file)
@@ -61,6 +61,7 @@
     if (isset($forum)) {      // User is starting a new discussion in a forum
 
         $SESSION->fromurl = $HTTP_REFERER;
+        save_session("SESSION");
 
         if (! $forum = get_record("forum", "id", $forum)) {
             error("The forum number was incorrect ($forum)");
index 740c63c72a6df0f5402f35ef407bbde958257450..e2540b2f4ebcc39a175ee26787293f309aad8c27 100644 (file)
@@ -1,8 +1,6 @@
 <?PHP // $Id$
 
 //  Collect ratings, store them, then return to where we came from
-//  Need to do some tricky business and store variables in the 
-//  SESSION variable, just in case 
 
 
     require("../../config.php");
index 9773bebac861fee286afc8b1a5c9cebbd2137ee8..1ee32b5aecb2a5cce91168ebb61f96e29b2c5f78 100644 (file)
                 if (! $forum = get_record("forum", "id", "$discussion->forum")) {
                     error("Could not find forum $discussion->forum");
                 }
-                $post->subject = "<A HREF=\"index.php?id=$course->id&forum=$forum->id\">$forum->name</A> -> ".
-                                 "<A HREF=\"discuss.php?d=$discussion->id\">$discussion->name</A> -> ".
-                                 "<A HREF=\"discuss.php?d=$post->discussion&parent=$post->id\">$post->subject</A>";
 
+                $fullsubject = "<A HREF=\"view.php?f=$forum->id\">$forum->name</A>";
+                if ($forum->type != "single") {
+                    $fullsubject .= " -> <A HREF=\"discuss.php?d=$discussion->id\">$discussion->name</A>";
+                    if ($post->parent != 0) {
+                        $fullsubject .= " -> <A HREF=\"discuss.php?d=$post->discussion&parent=$post->id\">$post->subject</A>";
+                    }
+                }
+
+                $post->subject = $fullsubject;
                 $post->message = highlight("$search", $post->message);
 
                 $fulllink = "<P ALIGN=right><A HREF=\"discuss.php?d=$post->discussion&parent=$post->id\">See this post in context</A></P>";
index 955e956b53e5b6b208c8b466cbab6826d98a660c..3617a2018cefe92543a96e88596aa640e1357627 100644 (file)
@@ -20,6 +20,7 @@
     }
 
     unset($SESSION->fromdiscussion);
+    save_session("SESSION");
 
     add_to_log($course->id, "forum", "view subscribers", "subscribers.php?id=$forum->id", "");
 
index b21c6c6e279e10bc59ebbeb2a9c9259c96903f1a..87ce3709143f33658c69f1b13cbd6c4e5f31ac42 100644 (file)
@@ -58,6 +58,7 @@
 
     if ($USER) {
         $SESSION->fromdiscussion = "$FULLME";
+        save_session("SESSION");
         if (forum_is_forcesubscribed($forum->id)) {
             $subtext = "Everyone is subscribed to this forum";
             if (isteacher($course->id)) {
index ad93d579f80a350da2aebaf70d93fd8b47a796ac..57686b2108612250b881ab41091b8cfd8e4a7c29 100644 (file)
 
                    $timenow = time();
 
-            if ($imagefile && $imagefile!="none") { 
-                $imageinfo = GetImageSize($imagefile);
+            if ($filename = valid_uploaded_file($imagefile)) { 
+                $imageinfo = GetImageSize($filename);
                 $image->width  = $imageinfo[0];
                 $image->height = $imageinfo[1];
                 $image->type   = $imageinfo[2];
     
                 switch ($image->type) {
-                    case 2: $im = ImageCreateFromJPEG($imagefile); break;
-                    case 3: $im = ImageCreateFromPNG($imagefile); break;
+                    case 2: $im = ImageCreateFromJPEG($filename); break;
+                    case 3: $im = ImageCreateFromPNG($filename); break;
                     default: error("Image must be in JPG or PNG format");
                 }
                 if (function_exists("ImageCreateTrueColor") and $CFG->gdversion >= 2) {
                 foreach ($usernew as $variable => $value) {
                     $USER->$variable = $value;
                 }
+                save_session("USER");
                        redirect("view.php?id=$user->id&course=$course->id", "Changes saved");
             } else {
                 error("Could not update the user record ($user->id)");
index a6efe6a7c1348749e56b931ff12c9a842846a4d4..42c0c00557af5824b7dad3f0090a205cfbfb6a7c 100644 (file)
@@ -84,4 +84,13 @@ function print_user($user, $course, $string) {
     echo "</TD></TR></TABLE></TD></TR></TABLE>";
 }
 
+function valid_uploaded_file($newfile) {
+// Returns current name of file on disk if true
+    if (is_uploaded_file($newfile['tmp_name']) and $newfile['size'] > 0) {
+        return $newfile['tmp_name'];
+    } else {
+        return "";
+    }
+}
+
 ?>