$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");
}
$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";
}
notice("You are now logged in as $student_name", "$CFG->wwwroot/course/view.php?id=$course->id");
+ save_session("USER");
+
?>
if ($SESSION->returnpage) {
$return = $SESSION->returnpage;
unset($SESSION->returnpage);
+ save_session("SESSION");
redirect($return);
} else {
redirect("view.php?id=$mod->course");
if (isset($return)) {
$SESSION->returnpage = $HTTP_REFERER;
+ save_session("SESSION");
}
if (isset($move)) {
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)) {
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");
} else {
$USER->topic = $topic;
}
+ save_session("USER");
}
if (isteacher($course->id) and isset($marker)) {
if ($user->id == $USER->id) {
unset($USER->student["$id"]);
+ save_session("USER");
redirect("$CFG->wwwroot");
}
$USER->help = false;
}
+ save_session("USER");
+
if (! $course->category) { // This course is not a real course.
redirect("$CFG->wwwroot");
}
} else {
$USER->section = $week;
}
+ save_session("USER");
}
<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
<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
+ <? phpinfo ?> and looking at it through a browser. Check all these and try this page again.</P>\r
<P>Press the "Continue" 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
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 {
if ( !empty($SESSION->fromurl) ) {
$link = "$SESSION->fromurl";
unset($SESSION->fromurl);
+ save_session("SESSION");
} else {
$link = "$CFG->wwwroot";
}
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'>";
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 {
// 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;
}
} 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.");
}
}
global $SESSION;
$SESSION->logincount = 0;
+ save_session("SESSION");
}
}
+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) {
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);
$db->PConnect($CFG->dbhost,$CFG->dbuser,$CFG->dbpass,$CFG->dbname);
-
?>
error("Could not set the new password");
}
- unset($USER);
$USER = $user;
$USER->loggedin = true;
+ save_session("USER");
set_moodle_cookie($USER->username);
$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");
}
$USER = $user;
$USER->loggedin = true;
+ save_session("USER");
if (!update_user_in_db()) {
error("Weird error: User not found");
if (!update_user_login_times()) {
error("Wierd error: could not update login records");
}
-
+
set_moodle_cookie($USER->username);
} 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)
$USER->lastlogin = $USER->currentlogin;
$USER->currentlogin = time();
+ save_session("USER");
return $db->Execute("UPDATE user
SET lastlogin='$USER->lastlogin', currentlogin='$USER->currentlogin'
require("../config.php");
$USER = NULL;
+ save_session("USER");
redirect($HTTP_REFERER);
exit;
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);
}
unset($SESSION->fromdiscussion);
+ save_session("SESSION");
add_to_log($course->id, "forum", "view forums", "index.php?id=$course->id");
if (! $SESSION->fromdiscussion) {
$SESSION->fromdiscussion = $HTTP_REFERER;
+ save_session("SESSION");
}
}
if ($SESSION->fromdiscussion) {
$returnto = $SESSION->fromdiscussion;
unset($SESSION->fromdiscussion);
+ save_session("SESSION");
return $returnto;
} else {
return $default;
if ($mode) {
$USER->mode = $mode;
+ save_session("USER");
} else if (!$USER->mode) {
$USER->mode = $FORUM_DEFAULT_DISPLAY_MODE;
+ save_session("USER");
}
}
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)");
<?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");
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>";
}
unset($SESSION->fromdiscussion);
+ save_session("SESSION");
add_to_log($course->id, "forum", "view subscribers", "subscribers.php?id=$forum->id", "");
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)) {
$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)");
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 "";
+ }
+}
+
?>