";
if ($teachers = get_records_sql("SELECT u.* FROM user u, user_teachers t
WHERE u.id = t.user AND t.course = '$course->id'
@@ -135,13 +136,23 @@ function print_course($course) {
echo "$course->teacher: id&course=$site->id\">$teacher->firstname $teacher->lastname ";
}
echo "";
- }
- echo "
";
+ echo "";
+
+ print_simple_box_end();
}
function print_headline($text, $size=2) {
diff --git a/lib/db/mysql.sql b/lib/db/mysql.sql
index ead64833985..efb3aa403ae 100644
--- a/lib/db/mysql.sql
+++ b/lib/db/mysql.sql
@@ -14,20 +14,21 @@
# Table structure for table `course`
#
-CREATE TABLE course (
- id int(10) unsigned NOT NULL auto_increment,
- category int(10) unsigned NOT NULL default '0',
- password varchar(50) NOT NULL default '',
- fullname varchar(254) NOT NULL default '',
- shortname varchar(15) NOT NULL default '',
- summary text NOT NULL,
- format tinyint(4) NOT NULL default '1',
- teacher varchar(100) NOT NULL default 'Teacher',
- student varchar(100) NOT NULL default 'Student',
- startdate int(10) unsigned NOT NULL default '0',
- enddate int(10) unsigned NOT NULL default '0',
- timemodified int(10) unsigned NOT NULL default '0',
- PRIMARY KEY (id)
+CREATE TABLE `course` (
+ `id` int(10) unsigned NOT NULL auto_increment,
+ `category` int(10) unsigned NOT NULL default '0',
+ `password` varchar(50) NOT NULL default '',
+ `fullname` varchar(254) NOT NULL default '',
+ `shortname` varchar(15) NOT NULL default '',
+ `summary` text NOT NULL,
+ `format` tinyint(4) NOT NULL default '1',
+ `teacher` varchar(100) NOT NULL default 'Teacher',
+ `student` varchar(100) NOT NULL default 'Student',
+ `guest` tinyint(1) unsigned NOT NULL default '0',
+ `startdate` int(10) unsigned NOT NULL default '0',
+ `enddate` int(10) unsigned NOT NULL default '0',
+ `timemodified` int(10) unsigned NOT NULL default '0',
+ PRIMARY KEY (`id`)
) TYPE=MyISAM;
# --------------------------------------------------------
@@ -165,11 +166,11 @@ CREATE TABLE user (
# Table structure for table `user_admins`
#
-CREATE TABLE user_admins (
- id int(10) unsigned NOT NULL auto_increment,
- user int(10) unsigned NOT NULL default '0',
- PRIMARY KEY (id),
- UNIQUE KEY id (id)
+CREATE TABLE `user_admins` (
+ `id` int(10) unsigned NOT NULL auto_increment,
+ `user` int(10) unsigned NOT NULL default '0',
+ PRIMARY KEY (`id`),
+ UNIQUE KEY `id` (`id`)
) TYPE=MyISAM COMMENT='One record per administrator user';
# --------------------------------------------------------
diff --git a/lib/moodlelib.php b/lib/moodlelib.php
index 52a8673b1ec..6cd2e0d457c 100644
--- a/lib/moodlelib.php
+++ b/lib/moodlelib.php
@@ -705,13 +705,14 @@ function update_user_in_db() {
}
}
-function require_login($course=0) {
-// if they aren't already logged in, then send them off to login
-// $course is optional - if left out then it just requires that
-// that they have an account on the system.
+function require_login($courseid=0) {
+// This function checks that the current user is logged in, and optionally
+// whether they are "logged in" or allowed to be in a particular course.
+// If not, then it redirects them to the site login or course enrolment.
global $CFG, $SESSION, $USER, $FULLME, $HTTP_REFERER, $PHPSESSID;
+ // First check that the user is logged in to the site.
if (! (isset( $USER->loggedin ) && $USER->confirmed) ) {
$SESSION->wantsurl = $FULLME;
$SESSION->fromurl = $HTTP_REFERER;
@@ -721,20 +722,28 @@ function require_login($course=0) {
redirect("$CFG->wwwroot/login/");
}
die;
-
- } else if ($course) {
- if (! ($USER->student[$course] || $USER->teacher[$course] || $USER->admin ) ) {
- if (!record_exists("course", "id", $course)) {
- error("That course doesn't exist");
- }
-
- $SESSION->wantsurl = $FULLME;
- redirect("$CFG->wwwroot/course/enrol.php?id=$course");
- die;
- }
}
+
+ // Next, check if the user can be in a particular course
+ if ($courseid) {
+ if ($USER->student[$courseid] || $USER->teacher[$courseid] || $USER->admin) {
+ update_user_in_db();
+ return; // user is a member of this course.
+ }
+ if (! $course = get_record("course", "id", $courseid)) {
+ error("That course doesn't exist");
+ }
+ if ($course->guest && ($USER->username == "guest")) {
+ update_user_in_db();
+ return; // user is a guest and this course allows guests
+ }
- update_user_in_db();
+ // Not allowed in the course, so see if they want to enrol
+
+ $SESSION->wantsurl = $FULLME;
+ redirect("$CFG->wwwroot/course/enrol.php?id=$courseid");
+ die;
+ }
}
@@ -794,6 +803,16 @@ function isstudent($course, $userid=0) {
return record_exists_sql("SELECT * FROM user_students WHERE user='$userid' AND course='$course'");
}
+function isguest($userid=0) {
+ global $USER;
+
+ if (!$userid) {
+ return ($USER->username == "guest");
+ }
+
+ return record_exists_sql("SELECT * FROM user WHERE user='$userid' AND username = 'guest' ");
+}
+
function reset_login_count() {
global $SESSION;
diff --git a/mod/journal/edit.php b/mod/journal/edit.php
index fdd575b09d8..d129fd6b162 100644
--- a/mod/journal/edit.php
+++ b/mod/journal/edit.php
@@ -14,6 +14,10 @@
require_login($course->id);
+ if (isguest()) {
+ error("Guests are not allowed to edit journals", $HTTP_REFERER);
+ }
+
if (! $journal = get_record("journal", "id", $cm->instance)) {
error("Course module is incorrect");
}
diff --git a/mod/journal/view.php b/mod/journal/view.php
index b5f94067764..62fe7197d33 100644
--- a/mod/journal/view.php
+++ b/mod/journal/view.php
@@ -15,7 +15,6 @@
require_login($course->id);
-
if (! $journal = get_record("journal", "id", $cm->instance)) {
error("Course module is incorrect");
}
@@ -51,7 +50,6 @@
if ($timenow > $timestart) {
-
print_simple_box_start("center");
if ($timenow < $timefinish) {
diff --git a/mod/survey/save.php b/mod/survey/save.php
index 665389b21f4..ab59327a01c 100644
--- a/mod/survey/save.php
+++ b/mod/survey/save.php
@@ -10,6 +10,10 @@
error("You are not supposed to use this script like that.");
}
+ if (isguest()) {
+ error("Guests are not allowed to answer surveys", $HTTP_REFERER);
+ }
+
require_variable($id); // Course Module ID
if (! $cm = get_record("course_modules", "id", $id)) {
diff --git a/pix/i/key.gif b/pix/i/key.gif
new file mode 100755
index 00000000000..b45a1db3ab6
Binary files /dev/null and b/pix/i/key.gif differ