Initial revision

This commit is contained in:
martin
2001-11-22 06:23:56 +00:00
commit f9903ed0a4
175 changed files with 14908 additions and 0 deletions
+1
View File
@@ -0,0 +1 @@
All the documention is in the "doc" subdirectory. :-)
+1
View File
@@ -0,0 +1 @@
All the documention is in the "doc" subdirectory. :-)
+48
View File
@@ -0,0 +1,48 @@
<?PHP // $Id$
// This script looks through all the module directories for cron.php files
// and runs them. These files can contain cleanup functions, email functions
// or anything that needs to be run on a regular basis.
//
// This file is best run from cron on the host system (ie outside PHP).
// The script can either be invoked via the web server or via a standalone
// version of PHP compiled for CGI.
//
// The script does not require a valid Moodle login, but has it's own unique
// password, set below. These are passed to this script as parameters.
//
// eg wget -q -O /dev/null 'http://moodle.dougiamas.net/admin/cron.php?p=password'
// or php /web/moodle/admin/cron.php password
$PASSWORD = "fr0o6y";
require("../config.php");
echo "<PRE>\n";
if (!isset($p)) {
$p = $GLOBALS[argv][1];
}
if ($p <> $PASSWORD) {
add_to_log("Error: bad cron password!");
echo "Error: bad password.\n";
die;
}
$timenow = time();
if ($mods = get_records_sql("SELECT * FROM modules WHERE cron > 0 AND (($timenow - lastcron) > cron)")) {
foreach ($mods as $mod) {
$cronfile = "$CFG->dirroot/mod/$mod->name/cron.php";
if (file_exists($cronfile)) {
include($cronfile);
if (! set_field("modules", "lastcron", $timenow, "id", $mod->id)) {
echo "Error: could not update timestamp for $mod->fullname\n";
}
}
}
}
echo "Cron script completed correctly\n";
?>
+97
View File
@@ -0,0 +1,97 @@
<?PHP // $Id$
require("../config.php");
if (! $CFG->wwwroot == "http://example.com") {
error("Moodle has not been configured yet. You need to to edit config.php first.");
}
// Check databases and modules and install as needed.
if (! $db->Metatables() ) {
print_header("Setting up database", "Setting up database", "Setting up databases for the first time", "");
if (modify_database("$CFG->dirroot/admin/moodle-core.sql")) {
notify("Main databases set up successfully");
} else {
error("Error: Main databases NOT set up successfully");
}
print_heading("<A HREF=\"index.php\">Continue</A>");
die;
}
// Find and check all modules and load them up.
$dir = opendir("$CFG->dirroot/mod");
while ($mod = readdir($dir)) {
if ($mod == "." || $mod == "..") {
continue;
}
$fullmod = "$CFG->dirroot/mod/$mod";
if (filetype($fullmod) != "dir") {
continue;
}
unset($module);
include_once("$CFG->dirroot/mod/$mod/module.php"); # defines $module
if (!isset($module)) {
continue;
}
$module->name = $mod; // The name MUST match the directory
if ($currmodule = get_record("modules", "name", $module->name)) {
if ($currmodule->version == $module->version) {
// do nothing
} else if ($currmodule->version < $module->version) {
notify("$module->name module needs upgrading"); // XXX do the upgrade here
} else {
error("Version mismatch: $module->name can't downgrade $currmodule->version -> $module->version !");
}
} else { // module not installed yet, so install it
if (modify_database("$fullmod/install.sql")) {
if ($module->id = insert_record("modules", $module)) {
notify("$module->name tables have been set up correctly");
} else {
error("$module->name module could not be added to the module list!");
}
} else {
error("$module->name tables could NOT be set up successfully!");
}
}
}
// Set up the overall site name etc.
if (! $course = get_record("course", "category", 0)) {
redirect("site.php");
}
if (!isadmin()) {
if (record_exists_sql("SELECT * FROM user_admins")) {
require_login();
} else {
redirect("user.php");
}
}
// At this point, the databases exist, and the user is an admin
print_header("$course->fullname: Administration Page","$course->fullname: Administration Page", "Admin");
echo "<UL>";
echo "<LI><B><A HREF=\"site.php\">Site settings</A></B>";
echo "<LI><B><A HREF=\"../course/edit.php\">Create a new course</A></B>";
echo "<LI><B><A HREF=\"user.php\">Edit a user's account</A></B>";
echo "<LI><B>Assign teachers to courses</B>";
echo "<LI><B>Delete a course</B>";
echo "<LI><B>View Logs</B>";
echo "</UL>";
print_footer();
?>
+22
View File
@@ -0,0 +1,22 @@
<?PHP // $Id$
$logs = $db->Execute("SELECT l.*, u.firstname, u.lastname, u.email FROM log l, user u WHERE l.user = u.id ORDER BY l.time ASC");
echo "<TABLE>"
while (! $logs->EOF) {
$log = (object)$logs->fields;
echo "<TR>";
echo "<TD>".date("l, j F Y, g:i A T", $log->time);
echo "<TD><A HREF=\"mailto:$log->email\">$log->firstname $log->lastname</A>";
echo "<TD>$log->ip";
echo "<TD>$log->url";
echo "<TD>$log->message";
echo "</TR>";
$logs->MoveNext();
}
echo "</TABLE>";
?>
+189
View File
@@ -0,0 +1,189 @@
# phpMyAdmin MySQL-Dump
# version 2.2.1
# http://phpwizard.net/phpMyAdmin/
# http://phpmyadmin.sourceforge.net/ (download page)
#
# Host: localhost
# Generation Time: Nov 14, 2001 at 05:04 PM
# Server version: 3.23.36
# PHP Version: 4.0.6
# Database : `moodle`
# --------------------------------------------------------
#
# 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',
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;
# --------------------------------------------------------
#
# Table structure for table `course_categories`
#
CREATE TABLE course_categories (
id int(10) unsigned NOT NULL auto_increment,
name varchar(255) NOT NULL default '',
PRIMARY KEY (id),
UNIQUE KEY id (id)
) TYPE=MyISAM COMMENT='Course categories';
# --------------------------------------------------------
#
# Table structure for table `course_modules`
#
CREATE TABLE course_modules (
id int(10) unsigned NOT NULL auto_increment,
course int(10) unsigned NOT NULL default '0',
module int(10) unsigned NOT NULL default '0',
instance int(10) unsigned NOT NULL default '0',
week int(10) unsigned NOT NULL default '0',
added int(10) unsigned NOT NULL default '0',
deleted tinyint(1) unsigned NOT NULL default '0',
score tinyint(4) NOT NULL default '0',
PRIMARY KEY (id),
UNIQUE KEY id (id)
) TYPE=MyISAM;
# --------------------------------------------------------
#
# Table structure for table `course_weeks`
#
CREATE TABLE course_weeks (
id int(10) unsigned NOT NULL auto_increment,
course int(10) unsigned NOT NULL default '0',
week int(10) unsigned NOT NULL default '0',
summary varchar(255) NOT NULL default '',
sequence varchar(255) NOT NULL default '',
PRIMARY KEY (id)
) TYPE=MyISAM;
# --------------------------------------------------------
#
# Table structure for table `logs`
#
CREATE TABLE logs (
id int(10) unsigned NOT NULL auto_increment,
time int(10) unsigned NOT NULL default '0',
user int(10) unsigned NOT NULL default '0',
course int(10) unsigned NOT NULL default '0',
ip varchar(15) NOT NULL default '',
url varchar(200) NOT NULL default '',
message varchar(255) NOT NULL default '',
PRIMARY KEY (id)
) TYPE=MyISAM;
# --------------------------------------------------------
#
# Table structure for table `modules`
#
CREATE TABLE modules (
id int(10) unsigned NOT NULL auto_increment,
name varchar(20) NOT NULL default '',
fullname varchar(255) NOT NULL default '',
version int(10) NOT NULL default '0',
cron int(10) unsigned NOT NULL default '0',
lastcron int(10) unsigned NOT NULL default '0',
search varchar(255) NOT NULL default '',
PRIMARY KEY (id),
UNIQUE KEY id (id)
) TYPE=MyISAM;
# --------------------------------------------------------
#
# Table structure for table `user`
#
CREATE TABLE user (
id int(10) unsigned NOT NULL auto_increment,
confirmed tinyint(1) NOT NULL default '0',
username varchar(100) NOT NULL default '',
password varchar(32) NOT NULL default '',
idnumber varchar(12) default NULL,
firstname varchar(20) NOT NULL default '',
lastname varchar(20) NOT NULL default '',
email varchar(100) NOT NULL default '',
icq varchar(15) default NULL,
phone1 varchar(20) default NULL,
phone2 varchar(20) default NULL,
institution varchar(40) default NULL,
department varchar(30) default NULL,
address varchar(70) default NULL,
city varchar(20) default NULL,
country char(2) default NULL,
firstaccess int(10) unsigned NOT NULL default '0',
lastaccess int(10) unsigned NOT NULL default '0',
lastlogin int(10) unsigned NOT NULL default '0',
currentlogin int(10) unsigned NOT NULL default '0',
lastIP varchar(15) default NULL,
personality varchar(5) default NULL,
picture tinyint(1) default NULL,
url varchar(255) default NULL,
description text,
research tinyint(1) unsigned NOT NULL default '0',
forwardmail tinyint(1) unsigned NOT NULL default '0',
timemodified int(10) unsigned NOT NULL default '0',
PRIMARY KEY (id),
UNIQUE KEY username (username),
UNIQUE KEY id (id)
) TYPE=MyISAM COMMENT='One record for each person';
# --------------------------------------------------------
#
# 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)
) TYPE=MyISAM COMMENT='One record per administrator user';
# --------------------------------------------------------
#
# Table structure for table `user_students`
#
CREATE TABLE user_students (
id int(10) unsigned NOT NULL auto_increment,
user int(10) unsigned NOT NULL default '0',
course int(10) unsigned NOT NULL default '0',
start int(10) unsigned NOT NULL default '0',
end int(10) unsigned NOT NULL default '0',
time int(10) unsigned NOT NULL default '0',
PRIMARY KEY (id),
UNIQUE KEY id (id)
) TYPE=MyISAM;
# --------------------------------------------------------
#
# Table structure for table `user_teachers`
#
CREATE TABLE user_teachers (
id int(10) unsigned NOT NULL auto_increment,
user int(10) unsigned NOT NULL default '0',
course int(10) unsigned NOT NULL default '0',
authority varchar(10) default NULL,
PRIMARY KEY (id),
UNIQUE KEY id (id)
) TYPE=MyISAM COMMENT='One record per teacher per course';
+28
View File
@@ -0,0 +1,28 @@
<FORM METHOD="post" action="site.php" NAME="form">
<TABLE cellpadding=9 cellspacing=0 >
<tr valign=top>
<td><P>Full site name:</td>
<td><input type="text" name="fullname" size=50 value="<? p($form->fullname) ?>">
<? formerr($err["fullname"]) ?>
</td>
</tr>
<tr valign=top>
<td><P>Short name for site (eg single word):</td>
<td><input type="text" name="shortname" size=50 value="<? p($form->shortname) ?>">
<? formerr($err["shortname"]) ?>
</td>
</tr>
<tr valign=top>
<td><P>Front page description:</td>
<td><TEXTAREA NAME=summary COLS=50 ROWS=10 WRAP=virtual><? p($form->summary) ?></TEXTAREA>
<? formerr($err["summary"]) ?>
</td>
</tr>
<tr>
<td></td>
<td><input type="submit" value="Update the site"></td>
</tr>
</TABLE>
<INPUT type="hidden" name="id" value="<?=$form->id ?>">
<INPUT type="hidden" name="category" value="<?=$form->category ?>">
</FORM>
+84
View File
@@ -0,0 +1,84 @@
<?PHP // $Id$
require("../config.php");
$course = get_record("course", "category", 0);
/// If data submitted, then process and store.
if (match_referer() && isset($HTTP_POST_VARS)) {
$form = (object)$HTTP_POST_VARS;
validate_form($form, $err);
if (count($err) == 0) {
$form->timemodified = time();
if ($form->id) {
if (update_record("course", $form)) {
add_to_log("Updated site settings", $course->id);
redirect("$CFG->wwwroot/admin/", "Changes saved");
} else {
error("Serious Error! Could not update the course record! (id = $form->id)");
}
} else {
if ($newid = insert_record("course", $form)) {
$cat->name = "General";
if (insert_record("course_categories", $cat)) {
add_to_log("Inserted a new course # $newid", $newid);
redirect("$CFG->wwwroot/admin/", "Changes saved", "1");
} else {
error("Serious Error! Could not set up the default categories!");
}
} else {
error("Serious Error! Could not set up the site!");
}
}
die;
} else {
foreach ($err as $key => $value) {
$focus = "form.$key";
}
}
}
/// Otherwise fill and print the form.
if ($course && !$form) {
$form = $course;
} else {
$form->category = 0;
}
print_header("Admin: Setting up site", "Administration: Setting up site",
"<A HREF=\"$CFG->wwwroot/admin/\">Admin</A> -> Setting up site", "$focus");
print_simple_box_start("center", "", "$THEME->cellheading");
print_heading("Editing site settings");
include("site.html");
print_simple_box_end();
print_footer();
exit;
/// Functions /////////////////////////////////////////////////////////////////
function validate_form(&$form, &$err) {
if (empty($form->fullname))
$err["fullname"] = "Missing site name";
if (empty($form->shortname))
$err["shortname"] = "Missing short site name";
if (empty($form->summary))
$err["summary"] = "Missing site description";
return;
}
?>
+108
View File
@@ -0,0 +1,108 @@
<?PHP // $Id$
require("../config.php");
require("../user/lib.php");
optional_variable($id); // course id
if (! $site = get_site()) {
redirect("$CFG->wwwroot/admin/");
}
require_login();
if (!isadmin()) {
error("You must be an administrator to edit users this way.");
}
if (!$id) {
$courses = get_records_sql("SELECT * from course WHERE category > 0 ORDER BY fullname");
print_header("Add teachers to a course", "Add teachers to a course", "<A HREF=\"$CFG->wwwroot/admin\">Admin</A> -> Add teachers", "");
print_heading("Choose a course to add teachers to");
print_simple_box_start("CENTER");
foreach ($courses as $course) {
echo "<A HREF=\"teacher.php?id=$course->id\">$course->fullname</A><BR>";
}
print_simple_box_end();
print_footer();
exit;
}
if (! $course = get_record("course", "id", $id)) {
error("Course ID was incorrect (can't find it)");
}
/// If data submitted, then process and store.
if (match_referer() && isset($HTTP_POST_VARS)) {
$usernew = (object)$HTTP_POST_VARS;
if (find_form_errors($user, $usernew, $err) ) {
$user = $usernew;
} else {
$usernew->timemodified = time();
if (update_record("user", $usernew)) {
redirect("index.php", "Changes saved");
} else {
error("Could not update the user record ($user->id)");
}
}
}
/// Otherwise fill and print the form.
XXXXXXX
print_header("Edit user profile", "Edit user profile", "<A HREF=\"$CFG->wwwroot/admin\">Admin</A> -> Edit user", "");
print_simple_box_start("center", "", "$THEME->cellheading");
echo "<H2>User profile for $usernew->firstname $usernew->lastname</H2>";
include("user.html");
print_simple_box_end();
print_footer();
/// FUNCTIONS ////////////////////
function find_form_errors(&$user, &$usernew, &$err) {
if (empty($usernew->email))
$err["email"] = "Missing email address";
else if (! validate_email($usernew->email))
$err["email"] = "Invalid email address, check carefully";
else if ($otheruser = get_record("user", "email", $usernew->email)) {
if ($otheruser->id <> $user->id) {
$err["email"] = "Email address already in use by someone else.";
}
}
$user->email = $usernew->email;
if (empty($user->password) && empty($usernew->password)) {
$err["password"] = "Must have a password";
}
if (empty($usernew->username))
$err["username"] = "Must have a username";
if (empty($usernew->firstname))
$err["firstname"] = "Must enter your first name";
if (empty($usernew->lastname))
$err["lastname"] = "Must enter your last name";
return count($err);
}
?>
+82
View File
@@ -0,0 +1,82 @@
<FORM METHOD="post" ENCTYPE="multipart/form-data" action="user.php">
<table cellpadding=9 cellspacing=0 >
<tr valign=top>
<td><P>First name:</td>
<td><input type="text" name="firstname" size=25 value="<?=$usernew->firstname ?>">
<? formerr($err["firstname"]) ?>
</td>
</tr>
<tr valign=top>
<td><P>Last name:</td>
<td><input type="text" name="lastname" size=25 value="<?=$usernew->lastname ?>">
<? formerr($err["lastname"]) ?>
</td>
</tr>
<tr valign=top>
<td><P>Username:</td>
<td><input type="text" name="username" size=25 value="<?=$usernew->username ?>">
<? formerr($err["username"]) ?>
</td>
</tr>
<tr valign=top>
<td><P>New Password:</td>
<td><input type="text" name="password" size=25 value="<?=$usernew->password ?>">
<? formerr($err["password"]) ?>
</td>
</tr>
<tr valign=top>
<td><P>Email:</td>
<td><input type="text" name="email" size=25 value="<?=$usernew->email ?>">
<? formerr($err["email"]) ?>
</td>
</tr>
<tr valign=top>
<td><P>ICQ Number:</td>
<td><input type="text" name="icq" size=25 value="<?=$usernew->icq ?>">
<? formerr($err["icq"]) ?>
</td>
</tr>
<tr valign=top>
<td><P>Phone Number 1:</td>
<td><input type="text" name="phone1" size=25 value="<?=$usernew->phone1 ?>">
<? formerr($err["phone1"]) ?>
</td>
</tr>
<tr valign=top>
<td><P>Phone Number 2:</td>
<td><input type="text" name="phone2" size=25 value="<?=$usernew->phone2 ?>">
<? formerr($err["phone2"]) ?>
</td>
</tr>
<tr valign=top>
<td><P>Address:</td>
<td><input type="text" name="address" size=25 value="<?=$usernew->address ?>">
<? formerr($err["address"]) ?>
</td>
</tr>
<tr valign=top>
<td><P>Web Address:</td>
<td><input type="text" name="url" size=25 value="<?=$usernew->url ?>">
<? formerr($err["url"]) ?>
</td>
</tr>
<tr valign=top>
<td><P>Description:</td>
<td><TEXTAREA NAME=description COLS=50 ROWS=10 WRAP=virtual><?=$usernew->description ?></TEXTAREA>
</td>
</tr>
<tr valign=top>
<td><P>New picture:</td>
<td>
<INPUT type="hidden" name="MAX_FILE_SIZE" value="4000000">
<input type="file" name="imagefile">
( .jpg or .png )
<? formerr($err["firstname"]) ?>
</td>
</tr>
<tr>
<td></td>
<td><input type="submit" value="Update this user"></td>
</TABLE>
<INPUT type="hidden" name="id" value="<?=$usernew->id ?>">
</FORM>
+211
View File
@@ -0,0 +1,211 @@
<?PHP // $Id$
require("../config.php");
require("../user/lib.php");
optional_variable($id); // user id
if (! record_exists_sql("SELECT * FROM user_admins")) {
$user->firstname = "Admin";
$user->lastname = "User";
$user->username = "admin";
$user->password = "";
$user->email = "root@localhost";
$user->confirmed = 1;
$user->timemodified = time();
if (! $id = insert_record("user", $user)) {
error("Could not create admin user record !!!");
}
$admin->user = $id;
if (! insert_record("user_admins", $admin)) {
error("Could not make user $id an admin !!!");
}
if (! $user = get_record("user", "id", $id)) {
error("User ID was incorrect (can't find it)");
}
if (! $course = get_record("course", "category", 0)) {
error("Could not find site-level course");
}
$teacher->user = $user->id;
$teacher->course = $course->id;
$teacher->authority = 1;
if (! insert_record("user_teachers", $teacher)) {
error("Could not make user $id a teacher of site-level course !!!");
}
$USER = $user;
$USER->loggedin = true;
$USER->admin = true;
$USER->teacher["$course->id"] = true;
}
require_login();
if (!isadmin()) {
error("You must be an administrator to edit users this way.");
}
if (!$id) {
$users = get_records_sql("SELECT * from user ORDER BY firstname");
print_header("Edit users", "Edit users", "<A HREF=\"$CFG->wwwroot/admin\">Admin</A> -> Edit users", "");
echo "<CENTER>";
foreach ($users as $user) {
echo "<A HREF=\"user.php?id=$user->id\">$user->firstname $user->lastname</A><BR>";
}
echo "</CENTER>";
print_footer();
exit;
}
if (! $user = get_record("user", "id", $id)) {
error("User ID was incorrect (can't find it)");
}
/// If data submitted, then process and store.
if (match_referer() && isset($HTTP_POST_VARS)) {
$usernew = (object)$HTTP_POST_VARS;
if (find_form_errors($user, $usernew, $err) ) {
$user = $usernew;
} else {
$timenow = time();
if ($imagefile && $imagefile!="none") {
$imageinfo = GetImageSize($imagefile);
$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;
default: error("Image must be in JPG or PNG format");
}
if (function_exists("ImageCreateTrueColor")) {
$im1 = ImageCreateTrueColor(100,100);
$im2 = ImageCreateTrueColor(35,35);
} else {
$im1 = ImageCreate(100,100);
$im2 = ImageCreate(35,35);
}
$cx = $image->width / 2;
$cy = $image->height / 2;
if ($image->width < $image->height) {
$half = floor($image->width / 2.0);
} else {
$half = floor($image->height / 2.0);
}
if (!file_exists("$CFG->dataroot/users")) {
mkdir("$CFG->dataroot/users", 0777);
}
if (!file_exists("$CFG->dataroot/users/$USER->id")) {
mkdir("$CFG->dataroot/users/$USER->id", 0777);
}
ImageCopyBicubic($im1, $im, 0, 0, $cx-$half, $cy-$half, 100, 100, $half*2, $half*2);
ImageCopyBicubic($im2, $im, 0, 0, $cx-$half, $cy-$half, 35, 35, $half*2, $half*2);
// Draw borders over the top.
$black1 = ImageColorAllocate ($im1, 0, 0, 0);
$black2 = ImageColorAllocate ($im2, 0, 0, 0);
ImageLine ($im1, 0, 0, 0, 99, $black1);
ImageLine ($im1, 0, 99, 99, 99, $black1);
ImageLine ($im1, 99, 99, 99, 0, $black1);
ImageLine ($im1, 99, 0, 0, 0, $black1);
ImageLine ($im2, 0, 0, 0, 34, $black2);
ImageLine ($im2, 0, 34, 34, 34, $black2);
ImageLine ($im2, 34, 34, 34, 0, $black2);
ImageLine ($im2, 34, 0, 0, 0, $black2);
ImageJpeg($im1, "$CFG->dataroot/users/$USER->id/f1.jpg", 90);
ImageJpeg($im2, "$CFG->dataroot/users/$USER->id/f2.jpg", 95);
$usernew->picture = "1";
} else {
$usernew->picture = $user->picture;
}
if ($usernew->password) {
$usernew->password = md5($usernew->password);
} else {
unset($usernew->password);
}
$usernew->timemodified = time();
if (update_record("user", $usernew)) {
redirect("index.php", "Changes saved");
} else {
error("Could not update the user record ($user->id)");
}
}
}
/// Otherwise fill and print the form.
if (!$usernew) {
$usernew = $user;
$usernew->password = "";
}
print_header("Edit user profile", "Edit user profile", "<A HREF=\"$CFG->wwwroot/admin\">Admin</A> -> Edit user", "");
print_simple_box_start("center", "", "$THEME->cellheading");
echo "<H2>User profile for $usernew->firstname $usernew->lastname</H2>";
include("user.html");
print_simple_box_end();
print_footer();
/// FUNCTIONS ////////////////////
function find_form_errors(&$user, &$usernew, &$err) {
if (empty($usernew->email))
$err["email"] = "Missing email address";
else if (! validate_email($usernew->email))
$err["email"] = "Invalid email address, check carefully";
else if ($otheruser = get_record("user", "email", $usernew->email)) {
if ($otheruser->id <> $user->id) {
$err["email"] = "Email address already in use by someone else.";
}
}
$user->email = $usernew->email;
if (empty($user->password) && empty($usernew->password)) {
$err["password"] = "Must have a password";
}
if (empty($usernew->username))
$err["username"] = "Must have a username";
if (empty($usernew->firstname))
$err["firstname"] = "Must enter your first name";
if (empty($usernew->lastname))
$err["lastname"] = "Must enter your last name";
return count($err);
}
?>
+46
View File
@@ -0,0 +1,46 @@
<?PHP // $Id$
///////////////////////////////////////////////////////////////////////////
//
// Moodle configuration file
//
///////////////////////////////////////////////////////////////////////////
// Site configuration variables are all stored in the CFG object.
// First, we need to configure the database where all Moodle data
// will be stored. This database must already have been created
// and a username/password created to access it. See INSTALL doc.
$CFG->dbtype = "mysql"; // eg mysql, postgres, oracle, access etc
$CFG->dbhost = "localhost"; // eg localhost
$CFG->dbname = "moodle"; // eg moodle
$CFG->dbuser = "moodle";
$CFG->dbpass = "moodle";
// Next you need to tell Moodle where it is, and where it can save files.
$CFG->wwwroot = "http://server.dougiamas.net/moodle";
$CFG->dirroot = "/web/server/moodle";
$CFG->dataroot = "/web/moodledata"; // Web-server writeable
// Choose a theme from the "themes" folder. Default theme is "standard".
$CFG->theme = "standard";
// Give the full name (eg mail.example.com) of an SMTP server that the
// web server machine has access to (to send mail). Default: "localhost".
$CFG->smtphost = "dougiamas.com";
// You should not need to change anything below this line
///////////////////////////////////////////////////////////////////////////
$CFG->libdir = "$CFG->dirroot/lib";
require("$CFG->libdir/setup.php"); // Sets up all libraries, sessions etc
?>
+72
View File
@@ -0,0 +1,72 @@
<FORM METHOD="post" action="edit.php" NAME="form">
<table cellpadding=9 cellspacing=0 >
<tr valign=top>
<td><P>Full name:</td>
<td><input type="text" name="fullname" size=50 value="<? p($form->fullname) ?>">
<? formerr($err["fullname"]) ?>
</td>
</tr>
<tr valign=top>
<td><P>Short name:</td>
<td><input type="text" name="shortname" size=10 value="<? p($form->shortname) ?>">
<? formerr($err["shortname"]) ?>
</td>
</tr>
<tr valign=top>
<td><P>Password:</td>
<td><input type="text" name="password" size=25 value="<? p($form->password) ?>">
<? formerr($err["password"]) ?>
</td>
</tr>
<tr valign=top>
<td><P>Summary:</td>
<td><TEXTAREA NAME=summary COLS=50 ROWS=10 WRAP=virtual><? p($form->summary) ?></TEXTAREA>
<? formerr($err["summary"]) ?>
</td>
</tr>
<tr valign=top>
<td><P>Category:</td>
<td><?
choose_from_menu ($form->categories, "category", "$form->category");
formerr($err["category"]);
?>
</td>
</tr>
<tr valign=top>
<td><P>Format:</td>
<td><?
choose_from_menu ($FORMATS, "format", "$form->format");
formerr($err["format"]);
?>
</td>
</tr>
<tr valign=top>
<td><P>Word used to refer<BR>to your role:</td>
<td><input type="text" name="teacher" size=25 value="<? p($form->teacher) ?>">
<? formerr($err["teacher"]) ?>
</td>
</tr>
<tr valign=top>
<td><P>Start date:</td>
<td><?
choose_from_menu ($form->days, "startday", "$form->startday");
choose_from_menu ($form->months, "startmonth", "$form->startmonth");
choose_from_menu ($form->years, "startyear", "$form->startyear");
formerr($err["startdate"]);
?></td>
</tr>
<tr valign=top>
<td><P>End date:</td>
<td><?
choose_from_menu ($form->days, "endday", "$form->endday");
choose_from_menu ($form->months, "endmonth", "$form->endmonth");
choose_from_menu ($form->years, "endyear", "$form->endyear");
formerr($err["enddate"]);
?></td>
</tr>
<tr>
<td></td>
<td><input type="submit" value="Update this course"></td>
</TABLE>
<INPUT type="hidden" name="id" value="<?=$course->id ?>">
</FORM>
+168
View File
@@ -0,0 +1,168 @@
<?PHP // $Id$
require("../config.php");
require("lib.php");
optional_variable($id, 0); // course id
if ($id) {
if (! $course = get_record("course", "id", $id)) {
error("Course ID was incorrect");
}
require_login($course->id);
if (!isteacher($course->id)) {
error("Only teachers can edit the course!");
}
} else { // Admin is creating a new course
require_login();
if (!isadmin()) {
error("Only administrators can use this page");
}
}
/// If data submitted, then process and store.
if (match_referer() && isset($HTTP_POST_VARS)) {
$form = (object)$HTTP_POST_VARS;
$form->startdate = mktime(0,0,0,(int)$form->startmonth,(int)$form->startday,(int)$form->startyear);
$form->enddate = mktime(0,0,0,(int)$form->endmonth,(int)$form->endday,(int)$form->endyear);
validate_form($course, $form, $err);
if (count($err) == 0) {
$form->timemodified = time();
if ($course) {
if (update_record("course", $form)) {
add_to_log("Updated course settings", $course->id);
redirect("view.php?id=$course->id", "Changes saved");
} else {
error("Serious Error! Could not update the course record! (id = $form->id)");
}
} else {
if ($newid = insert_record("course", $form)) { // Set up new course
$week->course = $newid; // Create a default week.
$week->week = 0;
$week->timemodified = time();
$week->id = insert_record("course_weeks", $week);
add_to_log("Inserted a new course # $newid", $newid);
redirect("$CFG->wwwroot/admin/teacher.php?id=$newid", "Changes saved");
} else {
error("Serious Error! Could not create the new course!");
}
}
die;
} else {
foreach ($err as $key => $value) {
$focus = "form.$key";
}
}
}
/// Otherwise fill and print the form.
if (!$form) {
if ($course) {
$form = $course;
$ts = getdate($course->startdate);
$te = getdate($course->enddate);
} else {
$ts = getdate(time() + 3600 * 24);
$te = getdate(time() + 3600 * 24 * 7 * 16);
}
$form->startday = $ts[mday];
$form->startmonth = $ts[mon];
$form->startyear = $ts[year];
$form->endday = $te[mday];
$form->endmonth = $te[mon];
$form->endyear = $te[year];
if (!$course) {
$form->teacher = "Facilitator";
$form->fullname = "Course Fullname 101";
$form->shortname = "CF101";
$form->summary = "Write a concise and interesting paragraph here that explains what this course is about.";
$form->format = 0;
$form->category = 1;
}
}
for ($i=1;$i<=31;$i++) {
$form->days[$i] = "$i";
}
for ($i=1;$i<=12;$i++) {
$form->months[$i] = date("F", mktime(0,0,0,$i,1,2000));
}
for ($i=2000;$i<=2005;$i++) {
$form->years[$i] = $i;
}
$form->categories = get_records_sql_menu("SELECT id,name FROM course_categories");
//$form->owners = get_records_sql_menu("SELECT u.id, CONCAT(u.firstname, " ", u.lastname) FROM users u, teachers t WHERE t.user = u.id");
if (isadmin()) {
print_header("Admin: Creating a new course", "$CFG->sitename: Administration",
"<A HREF=\"$CFG->wwwroot/admin/\">Admin</A>
-> Create a new course", $focus);
} else {
print_header("Edit course settings", "$course->fullname",
"<A HREF=\"$CFG->wwwroot/course/view.php?id=$course->id\">$course->shortname</A>
-> Edit course settings", $focus);
}
print_simple_box_start("center", "", "$THEME->cellheading");
print_heading("Editing course settings");
include("edit.html");
print_simple_box_end();
print_footer($course);
exit;
/// Functions /////////////////////////////////////////////////////////////////
function validate_form($course, &$form, &$err) {
if (empty($form->fullname))
$err["fullname"] = "Missing full name";
if (empty($form->shortname))
$err["shortname"] = "Missing short name";
if (empty($form->summary))
$err["summary"] = "Missing summary";
if (empty($form->teacher))
$err["teacher"] = "Missing Teacher/Tutor/Instructor/Facilitator";
if ($form->startdate > $form->enddate)
$err["startdate"] = "Starts after it ends!";
if (($form->startdate < time()) && ($course->format <> $form->format)) {
$err["format"] = "Can't change the format now";
$form->format = $course->format;
}
if (! $form->category)
$err["category"] = "You need to choose a category";
return;
}
?>
+12
View File
@@ -0,0 +1,12 @@
<BLOCKQUOTE>
<FORM name="form" method="post" action="editweek.php">
<P><B>Summary of week <?=$form->week ?></B></P>
<TEXTAREA NAME=summary COLS=60 ROWS=4 WRAP=virtual><?=$form->summary ?></TEXTAREA>
<BR><FONT SIZE=1>(Maximum of 255 characters)</FONT>
<P>
<INPUT type="hidden" name=id value="<?=$form->id ?>">
<INPUT type="submit" value="Save all changes">
<INPUT type="reset" value="Revert">
</P>
</FORM>
</BLOCKQUOTE>
+50
View File
@@ -0,0 +1,50 @@
<?PHP // $Id$
require("../config.php");
require_variable($id); // Week ID
if (! $week = get_record("course_weeks", "id", $id)) {
error("Course week is incorrect");
}
if (! $course = get_record("course", "id", $week->course)) {
error("Could not find the course!");
}
require_login($course->id);
add_to_log("Edit week", $course->id);
if (!isteacher($course->id)) {
error("Only teachers can edit this!");
}
/// If data submitted, then process and store.
if (match_referer() && isset($HTTP_POST_VARS)) {
$timenow = time();
if (! set_field("course_weeks", "summary", $summary, "id", $week->id)) {
error("Could not update the summary!");
}
redirect("view.php?id=$course->id");
exit;
}
/// Otherwise fill and print the form.
if (! $form ) {
$form = $week;
}
print_header("Edit week $week->week", "Edit week $week->week", "", "form.summary");
include("editweek.html");
print_footer($course);
?>
+32
View File
@@ -0,0 +1,32 @@
<FORM name="form" method="post" action="email.php">
<TABLE cellpadding=10 CELLSPACING=0 ALIGN=CENTER>
<TR>
<TD valign=top align=right BGCOLOR="<?=$THEME->cellheading?>">
<P>Subject:</P>
</TD>
<TD valign=top align=left BGCOLOR="<?=$THEME->cellheading?>">
<FONT SIZE=2><INPUT TYPE=text SIZE=60 NAME=subject VALUE="<? p($form->subject); ?>">
</TD>
</TR>
<TR>
<TD valign=top align=right BGCOLOR="<?=$THEME->cellheading?>">
<P>Email:</P>
</TD>
<TD BGCOLOR="<?=$THEME->cellheading?>">
<FONT SIZE=2><TEXTAREA NAME=message COLS=60 ROWS=15 WRAP=hard><? p($form->message); ?></TEXTAREA>
</TD>
</TR>
<TR>
<TD BGCOLOR="<?=$THEME->cellheading?>">
&nbsp;
</TD>
<TD BGCOLOR="<?=$THEME->cellheading?>">
<P>
<INPUT type="hidden" name=id value="<?=$form->id ?>">
<INPUT type="submit" value="Send this email to everyone now">
<INPUT type="reset" value="Revert">
</P>
</TD>
</TABLE>
</FORM>
+48
View File
@@ -0,0 +1,48 @@
<?PHP // $Id$
require("../config.php");
require_variable($id); // Course ID
if (! $course = get_record("course", "id", $id)) {
error("Could not find the course!");
}
require_login($course->id);
if (!isteacher($course->id)) {
error("Only teachers can send mail this way!");
}
/// If data submitted, then process and store.
if (match_referer() && isset($HTTP_POST_VARS)) {
$link = "$CFG->wwwroot/course/view.php?id=$course->id";
if (! email_to_course($USER, $course, true, $subject, $message, "$link")) {
error("An error occurred while trying to send mail!");
}
add_to_log("Sent mail to everyone", $course->id);
redirect("view.php?id=$course->id", "Email sent", 1);
exit;
}
$form->id = $course->id;
print_header("$course->shortname: Mail", "$course->fullname",
"<A HREF=\"$CFG->wwwroot/course/view.php?id=$course->id\">$course->shortname</A> -> Send mail");
print_heading("Send an email to all participants");
include("email.html");
print_footer($course);
?>
+25
View File
@@ -0,0 +1,25 @@
<?PHP // $Id$
require("../config.php");
require("lib.php");
print_header("Courses", "Courses", "Courses", "");
optional_variable($cat, 1);
if ($courses = get_records("course", "category", $cat, "fullname ASC")) {
foreach ($courses as $key => $course) {
print_course($course);
echo "<BR>\n";
}
} else {
echo "<H3>No courses have been defined yet</H3>";
}
print_footer();
?>
+131
View File
@@ -0,0 +1,131 @@
<? // $Id$
$MAXNEWSDISPLAY = 4;
$FORMATS = array (
"0" => "Non-weekly layout",
"1" => "Weekly layout"
);
function logdate($date) {
return date("l, j F Y, g:i A", $date);
}
function print_log_selector_form($course, $selecteduser=0, $selecteddate="today") {
// Get all the possible users
$users = array();
if ($students = get_records_sql("SELECT u.* FROM user u, user_students s
WHERE s.course = '$course->id' AND s.user = u.id
ORDER BY u.lastaccess DESC")) {
foreach ($students as $student) {
$users["$student->id"] = "$student->firstname $student->lastname";
}
}
if ($teachers = get_records_sql("SELECT u.* FROM user u, user_teachers t
WHERE t.course = '$course->id' AND t.user = u.id
ORDER BY u.lastaccess DESC")) {
foreach ($teachers as $teacher) {
$users["$teacher->id"] = "$teacher->firstname $teacher->lastname";
}
}
asort($users);
// Get all the possible dates
$tt = getdate(time());
$timemidnight = $today = mktime (0, 0, 0, $tt["mon"], $tt["mday"], $tt["year"]);
$dates = array("$today" => "Today, ".date("j F Y", $today) );
while ($timemidnight > $course->startdate) {
$timemidnight = $timemidnight - 86400;
$dates["$timemidnight"] = date("l, j F Y", $timemidnight);
}
if ($selecteddate == "today") {
$selecteddate = $today;
}
echo "<CENTER>";
echo "<FORM ACTION=log.php METHOD=get>";
echo "<INPUT TYPE=hidden NAME=id VALUE=\"$course->id\">";
choose_from_menu ($users, "user", $selecteduser, "All participants");
choose_from_menu ($dates, "date", $selecteddate, "Any day");
echo "<INPUT TYPE=submit VALUE=\"Show these logs\">";
echo "</FORM>";
echo "</CENTER>";
}
function print_log($course, $user=0, $date=0, $order="ORDER BY l.time ASC") {
$selector = "WHERE l.course='$course->id' AND l.user = u.id";
if ($user) {
$selector .= " AND l.user = '$user'";
}
if ($date) {
$enddate = $date + 86400;
$selector .= " AND l.time > '$date' AND l.time < '$enddate'";
}
if (!$logs = get_records_sql("SELECT l.*, u.firstname, u.lastname, u.picture
FROM logs l, user u $selector $order")){
notify("No logs found!");
print_footer($course);
exit;
}
$count=0;
$tt = getdate(time());
$today = mktime (0, 0, 0, $tt["mon"], $tt["mday"], $tt["year"]);
echo "<P ALIGN=CENTER>Displaying ".count($logs)." records</P>";
echo "<TABLE BORDER=0 ALIGN=center CELLPADDING=3 CELLSPACING=3>";
foreach ($logs as $log) {
$count++;
echo "<TR>";
echo "<TD ALIGN=right><FONT SIZE=2>".date("l", $log->time)."</TD>";
echo "<TD><FONT SIZE=2>".date("j M Y, h:i A", $log->time)."</TD>";
echo "<TD><FONT SIZE=2><B>$log->firstname $log->lastname</B></TD>";
echo "<TD><FONT SIZE=2>";
$log->message = addslashes($log->message);
link_to_popup_window("$log->url","popup","$log->message", 400, 600);
echo "</TD>";
echo "</TR>";
}
echo "</TABLE>";
}
function print_course($course) {
if (! $site = get_record("course", "category", "0") ) {
error("Could not find a site!");
}
print_simple_box_start("CENTER", "80%");
echo "<TABLE WIDTH=100%>";
echo "<TR VALIGN=top><TD VALIGN=top WIDTH=50%>";
echo "<P><FONT SIZE=3><B><A HREF=\"view.php?id=$course->id\">$course->fullname</A></B></FONT></P>";
if ($teachers = get_records_sql("SELECT u.* FROM user u, user_teachers t
WHERE u.id = t.user AND t.course = '$course->id'
ORDER BY t.authority DESC")) {
echo "<P><FONT SIZE=1>\n";
foreach ($teachers as $teacher) {
echo "$course->teacher: <A HREF=\"../user/view.php?id=$teacher->id&course=$site->id\">$teacher->firstname $teacher->lastname</A><BR>";
}
echo "</FONT></P>";
}
echo "</TD><TD VALIGN=top WIDTH=50%>";
echo "<P><FONT SIZE=2>".text_to_html($course->summary)."</FONT></P>";
echo "</TD></TR>";
echo "</TABLE>";
print_simple_box_end();
}
?>
+65
View File
@@ -0,0 +1,65 @@
<?PHP // $Id$
// log.php - displays different views of the logs.
require("../config.php");
require("lib.php");
require_login($id);
if (! $course = get_record("course", "id", $id) ) {
error("That's an invalid course id");
}
if ( ! isteacher($course->id)) {
error("Only teachers can view logs");
}
if (isset($user) || isset($date)) {
$userinfo = "all users";
$dateinfo = "any day";
if ($user) {
if (!$u = get_record("user", "id", $user) ) {
error("That's an invalid user!");
}
$userinfo = "$u->firstname $u->lastname";
}
if ($date) {
$dateinfo = date("l, j F Y", $date);
}
print_header("$course->shortname: Logs", "$course->shortname : Logs",
"<A HREF=\"view.php?id=$course->id\">$course->shortname</A> ->
<A HREF=\"log.php?id=$course->id\">Logs</A> -> Logs for $userinfo, $dateinfo", "");
print_heading("Logs for $userinfo, $dateinfo");
print_log_selector_form($course, $user, $date);
print_log($course, $user, $date, "ORDER BY l.time DESC");
} else {
print_header("$course->shortname: Logs", "$course->shortname : Logs",
"<A HREF=\"view.php?id=$course->id\">$course->shortname</A> -> Logs", "");
print_heading("Choose which logs you want to look at");
print_log_selector_form($course);
print_heading("Or see what is happening right now");
echo "<CENTER><H3>";
link_to_popup_window("/course/loglive.php?id=$course->id","livelog","Live logs", 500, 800);
echo "</H3></CENTER>";
}
print_footer($course);
exit;
?>
+34
View File
@@ -0,0 +1,34 @@
<CENTER>
<table cellpadding=20>
<tr valign=top>
<td>
<P ALIGN=CENTER>This course requires a "course entry key" - a one-time<BR>
password that you should have got from <A HREF="../user/view.php?id=<?=$teacher->id?>&course=<?=$site->id?>"><? p("$teacher->firstname $teacher->lastname") ?></A>.</P>
</td>
</tr>
<tr valign=top>
<td bgcolor="<?=$THEME->cellheading?>"> <CENTER><? formerr($errormsg) ?> </CENTER>
<form name="form" method="post" action="login.php">
<table>
<tr>
<td width=50% align=right><P>Entry Key:</P></td>
<td width=50% >
<input type="password" name="password" size=20 value="<? p($password) ?>" >
<input type="hidden" name="id" value="<? p($id) ?>" >
</td>
<tr>
<td width=50%>&nbsp;</td>
<td width=50%>
<table cellpadding=1 cellspacing=0><tr>
<td><input type=submit value=Login></form></td>
<td><form action="<?=$CFG->wwwroot?>/" method=post>
<input type=submit value=Cancel></form></td>
</tr></table>
</td>
</table>
</td>
</tr>
</table>
+93
View File
@@ -0,0 +1,93 @@
<?PHP // $Id$
// Asks for a course pass key, once only
require("../config.php");
require("lib.php");
require_login();
require_variable($id);
if (match_referer() && isset($HTTP_POST_VARS)) { // form submitted
$actual_password = get_field("course", "password", "id", $id);
if ($password == $actual_password) {
enrol_student_in_course($USER->id, $id);
add_to_log("Enrolled in course", $id);
$USER->student["$id"] = true;
if ($SESSION->wantsurl) {
$destination = $SESSION->wantsurl;
unset($SESSION->wantsurl);
} else {
$destination = "$CFG->wwwroot/course/view.php?id=$id";
}
redirect($destination);
} else {
$errormsg = "That entry key was incorrect, please try again".
"<BR>(Here's a hint - it starts with \"".substr($actual_password,0,1)."\")";
}
}
if (! $course = get_record("course", "id", $id) ) {
error("That's an invalid course id");
}
if (! $site = get_record("course", "category", "0") ) {
error("Could not find a site!");
}
if ($course->password == "") { // no password, so enrol
if (! enrol_student_in_course($USER->id, $course->id)) {
error("An error occurred while trying to enrol you.");
}
add_to_log("Enrolled in course", $id);
$USER->student["$id"] = true;
if ($SESSION->wantsurl) {
$destination = $SESSION->wantsurl;
unset($SESSION->wantsurl);
} else {
$destination = "$CFG->wwwroot/course/view.php?id=$id";
}
redirect($destination);
}
$teacher = get_teacher($course->id);
print_header("Login to $course->shortname", "Login to $course->shortname", "<A HREF=\".\">Courses</A> -> Login to $course->shortname", "form.password");
print_course($course);
include("login.html");
print_footer();
//// FUNCTIONS /////////////////////////////////////////////
function enrol_student_in_course($user, $course) {
global $db;
$timenow = time();
$rs = $db->Execute("INSERT INTO user_students (user, course, start, end, time)
VALUES ($user, $course, 0, 0, $timenow)");
if ($rs) {
return true;
} else {
return false;
}
}
?>
+40
View File
@@ -0,0 +1,40 @@
<?PHP // $Id$
require("../config.php");
require("lib.php");
require_variable($id); // course id
require_variable($user); // login as this user
if (! $course = get_record("course", "id", $id)) {
error("Course ID was incorrect");
}
require_login($course->id);
if (!isteacher($course->id)) {
error("Only teachers can use this page!");
}
if (!isstudent($course->id, $user)) {
error("This student is not in your course!");
}
// Login as this student and return to course home page.
$teacher_name = "$USER->firstname $USER->lastname";
$USER = get_user_info_from_db("id", $user);
$USER->loggedin = true;
set_moodle_cookie($USER->username);
$student_name = "$USER->firstname $USER->lastname";
add_to_log("$teacher_name logged in as $student_name", $course->id);
notice("You are now logged in as $student_name", "$CFG->wwwroot/course/view.php?id=$course->id");
die;
?>
+29
View File
@@ -0,0 +1,29 @@
<?PHP // $Id$
// loglive.php - displays different views of the logs.
require("../config.php");
require("lib.php");
require_login($id);
if (! $course = get_record("course", "id", $id) ) {
error("That's an invalid course id");
}
if ( ! isteacher($course->id)) {
error("Only teachers can view logs");
}
print_header("Activity within the last hour (updates every 60 secs)",
"Activity within the last hour (updates every 60 secs)",
"", "", "<META HTTP-EQUIV='Refresh' CONTENT='60; URL=loglive.php?id=$id'>");
$user=0;
$date=time() - 3600;
print_log($course, $user, $date, "ORDER BY l.time DESC");
exit;
?>
+423
View File
@@ -0,0 +1,423 @@
<?PHP // $Id$
// Moves, adds, updates or deletes modules in a course
require("../config.php");
if (isset($course) && isset($HTTP_POST_VARS)) { // add or update form submitted
$mod = (object)$HTTP_POST_VARS;
require_login($mod->course);
if (!isteacher($mod->course)) {
error("You can't modify this course!");
}
$modcode = "../mod/$mod->modulename/mod.php";
if (file_exists($modcode)) {
include($modcode);
} else {
error("This module is missing important code! (mod.php)");
}
switch ($mod->mode) {
case "update":
if (! update_instance($mod)) {
error("Could not update the $mod->modulename");
}
add_to_log("Updated $mod->modulename $mod->instance", $mod->course);
break;
case "add":
if (! $mod->instance = add_instance($mod)) {
error("Could not add a new instance of $mod->modulename");
}
// course_modules and course_weeks each contain a reference
// to each other, so we have to update one of them twice.
if (! $mod->course_module = add_course_module($mod) ) {
error("Could not add a new course module");
}
if (! $weekid = add_mod_to_week($mod) ) {
error("Could not add the new course module to that week");
}
if (! set_field("course_modules", "week", $weekid, "id", $mod->course_module)) {
error("Could not update the course module with the correct week");
}
add_to_log("Added $mod->modulename $mod->instance", $mod->course);
break;
case "delete":
if (! delete_instance($mod->instance)) {
error("Could not delete the $mod->modulename");
}
if (! delete_course_module($mod->coursemodule)) {
error("Could not delete the $mod->modulename");
}
if (! delete_mod_from_week($mod->coursemodule, "$mod->week")) {
error("Could not delete the $mod->modulename from that week");
}
add_to_log("Deleted $mod->modulename $mod->instance", $mod->course);
break;
default:
error("No mode defined");
}
redirect("view.php?id=$mod->course");
exit;
}
if (isset($move)) {
require_variable($id);
move_module($id, $move);
redirect($HTTP_REFERER);
exit;
} else if (isset($delete)) { // value = course module
if (! $cm = get_record("course_modules", "id", $delete)) {
error("This course module doesn't exist");
}
if (! $course = get_record("course", "id", $cm->course)) {
error("This course doesn't exist");
}
if (! $module = get_record("modules", "id", $cm->module)) {
error("This module doesn't exist");
}
require_login($course->id);
if (!isteacher($course->id)) {
error("You can't modify this course!");
}
$form->coursemodule = $cm->id;
$form->week = $cm->week;
$form->course = $cm->course;
$form->instance = $cm->instance;
$form->modulename = $module->name;
include("mod_delete.html");
exit;
} else if (isset($update)) { // value = course module
if (! $cm = get_record("course_modules", "id", $update)) {
error("This course module doesn't exist");
}
if (! $course = get_record("course", "id", $cm->course)) {
error("This course doesn't exist");
}
if (! $module = get_record("modules", "id", $cm->module)) {
error("This module doesn't exist");
}
if (! $form = get_record($module->name, "id", $cm->instance)) {
error("The required instance of this module doesn't exist");
}
if (! $cw = get_record("course_weeks", "id", $cm->week)) {
error("This course week doesn't exist");
}
$form->week = $cm->week; // The week ID
$form->course = $course->id;
$form->module = $module->id;
$form->modulename = $module->name;
$form->instance = $cm->instance;
$form->mode = "update";
$pageheading = "Updating a $module->fullname in Week $cw->week";
} else if (isset($add)) {
if (!$add) {
redirect($HTTP_REFERER);
die;
}
require_variable($id);
require_variable($week);
if (! $course = get_record("course", "id", $id)) {
error("This course doesn't exist");
}
if (! $module = get_record("modules", "name", $add)) {
error("This module type doesn't exist");
}
$form->week = $week; // The week number itself
$form->course = $course->id;
$form->module = $module->id;
$form->modulename = $module->name;
$form->instance = $cm->instance;
$form->mode = "add";
if ($form->week) {
$pageheading = "Adding a new $module->fullname to Week $form->week";
} else {
$pageheading = "Adding a new $module->fullname";
}
} else {
error("No action was specfied");
}
require_login($course->id);
if (!isteacher($course->id)) {
error("You can't modify this course!");
}
print_header("$course->shortname: Editing a $module->fullname", "$course->shortname: Editing a $module->fullname",
"<A HREF=\"$CFG->wwwroot/course/view.php?id=$course->id\">$course->shortname</A> ->
Editing a $module->fullname", "form.name");
$modform = "../mod/$module->name/mod.html";
if (file_exists($modform)) {
print_heading($pageheading);
print_simple_box_start("center", "", "$THEME->cellheading");
include($modform);
print_simple_box_end();
} else {
notice("This module cannot be added to this course yet!", "$CFG->wwwroot/course/view.php?id=$course->id");
}
print_footer($course);
exit;
/// FUNCTIONS //////////////////////////////////////////////////////////////////////
function add_course_module($mod) {
GLOBAL $db;
$timenow = time();
if (!$rs = $db->Execute("INSERT into course_modules
SET course = '$mod->course',
module = '$mod->module',
instance = '$mod->instance',
week = '$mod->week',
added = '$timenow' ")) {
return 0;
}
// Get it out again - this is the most compatible way to determine the ID
if ($rs = $db->Execute("SELECT id FROM course_modules
WHERE module = $mod->module AND added = $timenow")) {
return $rs->fields[0];
} else {
return 0;
}
}
function add_mod_to_week($mod) {
// Returns the course_weeks ID where the mod is inserted
GLOBAL $db;
if ($cw = get_record_sql("SELECT * FROM course_weeks
WHERE course = '$mod->course' AND week = '$mod->week'") ) {
if ($cw->sequence) {
$newsequence = "$cw->sequence,$mod->course_module";
} else {
$newsequence = "$mod->course_module";
}
if (!$rs = $db->Execute("UPDATE course_weeks SET sequence = '$newsequence' WHERE id = '$cw->id'")) {
return 0;
} else {
return $cw->id; // Return course_weeks ID that was used.
}
} else { // Insert a new record
if (!$rs = $db->Execute("INSERT into course_weeks
SET course = '$mod->course',
week = '$mod->week',
summary = '',
sequence = '$mod->course_module' ")) {
return 0;
}
// Get it out again - this is the most compatible way to determine the ID
if ($rs = $db->Execute("SELECT id FROM course_weeks
WHERE course = '$mod->course' AND week = '$mod->week'")) {
return $rs->fields[0];
} else {
return 0;
}
}
}
function delete_course_module($mod) {
return set_field("course_modules", "deleted", 1, "id", $mod);
}
function delete_mod_from_week($mod, $week) {
GLOBAL $db;
if ($cw = get_record("course_weeks", "id", "$week") ) {
$modarray = explode(",", $cw->sequence);
if ($key = array_keys ($modarray, $mod)) {
array_splice($modarray, $key[0], 1);
$newsequence = implode(",", $modarray);
return set_field("course_weeks", "sequence", $newsequence, "id", $cw->id);
} else {
return false;
}
} else {
return false;
}
}
function move_module($id, $move) {
GLOBAL $db;
if (!$move) {
return true;
}
if (! $cm = get_record("course_modules", "id", $id)) {
error("This course module doesn't exist");
}
if (! $thisweek = get_record("course_weeks", "id", $cm->week)) {
error("This course week doesn't exist");
}
$mods = explode(",", $thisweek->sequence);
$len = count($mods);
$pos = array_keys($mods, $cm->id);
$thepos = $pos[0];
if ($len == 0 || count($pos) == 0 ) {
error("Very strange. Could not find the required module in this week.");
}
if ($len == 1) {
$first = true;
$last = true;
} else {
$first = ($thepos == 0);
$last = ($thepos == $len - 1);
}
if ($move < 0) { // Moving the module up
if ($first) {
if ($thisweek->week == 1) { // First week, do nothing
return true;
} else { // Push onto end of previous week
$prevweeknumber = $thisweek->week - 1;
if (! $prevweek = get_record_sql("SELECT * FROM course_weeks
WHERE course='$thisweek->course'
AND week='$prevweeknumber' ")) {
error("Previous week ($prevweek->id) doesn't exist");
}
if ($prevweek->sequence) {
$newsequence = "$prevweek->sequence,$cm->id";
} else {
$newsequence = "$cm->id";
}
if (! set_field("course_weeks", "sequence", $newsequence, "id", $prevweek->id)) {
error("Previous week could not be updated");
}
if (! set_field("course_modules", "week", $prevweek->id, "id", $cm->id)) {
error("Module could not be updated");
}
array_splice($mods, 0, 1);
$newsequence = implode(",", $mods);
if (! set_field("course_weeks", "sequence", $newsequence, "id", $thisweek->id)) {
error("Module could not be updated");
}
return true;
}
} else { // move up within this week
$swap = $mods[$thepos-1];
$mods[$thepos-1] = $mods[$thepos];
$mods[$thepos] = $swap;
$newsequence = implode(",", $mods);
if (! set_field("course_weeks", "sequence", $newsequence, "id", $thisweek->id)) {
error("This week could not be updated");
}
return true;
}
} else { // Moving the module down
if ($last) {
$nextweeknumber = $thisweek->week + 1;
if ($nextweek = get_record_sql("SELECT * FROM course_weeks
WHERE course='$thisweek->course'
AND week='$nextweeknumber' ")) {
if ($nextweek->sequence) {
$newsequence = "$cm->id,$nextweek->sequence";
} else {
$newsequence = "$cm->id";
}
if (! set_field("course_weeks", "sequence", $newsequence, "id", $nextweek->id)) {
error("Next week could not be updated");
}
if (! set_field("course_modules", "week", $nextweek->id, "id", $cm->id)) {
error("Module could not be updated");
}
array_splice($mods, $thepos, 1);
$newsequence = implode(",", $mods);
if (! set_field("course_weeks", "sequence", $newsequence, "id", $thisweek->id)) {
error("This week could not be updated");
}
return true;
} else { // There is no next week, so just return
return true;
}
} else { // move down within this week
$swap = $mods[$thepos+1];
$mods[$thepos+1] = $mods[$thepos];
$mods[$thepos] = $swap;
$newsequence = implode(",", $mods);
if (! set_field("course_weeks", "sequence", $newsequence, "id", $thisweek->id)) {
error("This week could not be updated");
}
return true;
}
}
}
?>
+16
View File
@@ -0,0 +1,16 @@
<table align=center cellpadding=20> <tr> <td colspan=2 bgcolor=#ffaaaa>
<CENTER>
<FORM name="form" method="post" action="<?=$ME ?>">
<? print_heading("Are you absolutely sure you want to delete the $form->modulename ?") ?>
<input type="hidden" name=mode value="delete">
<input type="hidden" name=week value="<? echo $form->week; ?>">
<input type="hidden" name=course value="<? p($form->course) ?>">
<input type="hidden" name=coursemodule value="<? p($form->coursemodule) ?>">
<input type="hidden" name=modulename value="<? p($form->modulename) ?>">
<input type="hidden" name=instance value="<? p($form->instance) ?>">
<input type="submit" value=" Yes "> <input type=button value=" No " onclick="javascript:history.go(-1);">
</FORM>
</td></tr></table>
+44
View File
@@ -0,0 +1,44 @@
<?PHP // $Id$
// This script prints all the new things that have happened since the last login
// To do this, it calls new.php in each module. It relies on $USER->lastlogin
require("../config.php");
require("lib.php");
require_variable($id); // Course ID
if (! $course = get_record("course", "id", $id)) {
error("Could not find the course!");
}
require_login($course->id);
add_to_log("View Whats New", $course->id);
print_header("$course->shortname: What's new", "$course->fullname",
"<A HREF=\"$CFG->wwwroot/course/view.php?id=$course->id\">$course->shortname</A> -> What's new");
print_heading("Recent activity since your last login");
print_heading(logdate($USER->lastlogin));
print_simple_box_start("center");
$modules = array ("users");
$mods = get_records_sql("SELECT * FROM modules");
foreach ($mods as $mod) {
$modules[] = "mod/$mod->name";
}
foreach ($modules as $module) {
$newfile = "$CFG->dirroot/$module/new.php";
if (file_exists($newfile)) {
include($newfile);
}
}
print_simple_box_end();
print_footer($course);
?>
+158
View File
@@ -0,0 +1,158 @@
<?PHP // $Id$
// This course doesn't contain weeks. Everything should be
// found under week 0. Present in non-weekly layout.
//
// Included from "view.php"
// Layout the whole page as two big columns.
echo "<TABLE BORDER=0 CELLPADDING=4>";
echo "<TR VALIGN=top><TD VALIGN=top WIDTH=200>";
echo "<IMG SRC=\"../pix/spacer.gif\" WIDTH=180 HEIGHT=1><BR>";
// Layout the left column
print_side_block("<A HREF=\"new.php?id=$course->id\">What's New!</A>",
"", "<FONT SIZE=1>...since your last login</FONT>");
// Then, print all the news items.
// XXXXX
// Admin links and controls
if ($USER->teacher[$course->id]) {
$admindata[]="<A HREF=\"edit.php?id=$course->id\">Course settings</A>";
$adminicon[]="<IMG SRC=\"../pix/i/settings.gif\" HEIGHT=16 WIDTH=16 ALT=\"Course\">";
$admindata[]="<A HREF=\"log.php?id=$course->id\">Logs</A>";
$adminicon[]="<IMG SRC=\"../pix/i/log.gif\" HEIGHT=16 WIDTH=16 ALT=\"Log\">";
$admindata[]="<A HREF=\"email.php?id=$course->id\">Send mail</A>";
$adminicon[]="<IMG SRC=\"../pix/i/email.gif\" HEIGHT=16 WIDTH=16 ALT=\"Email\">";
$admindata[]="<A HREF=\"../files/index.php?id=$course->id\">Files</A>";
$adminicon[]="<IMG SRC=\"../files/pix/files.gif\" HEIGHT=16 WIDTH=16 ALT=\"Files\">";
print_side_block("Administration", $admindata, "", $adminicon);
}
// Start main column
echo "</TD><TD WIDTH=100%>";
echo "<P><IMG SRC=\"../pix/spacer.gif\" WIDTH=100% HEIGHT=3><BR>";
echo "<TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0 WIDTH=100%>";
echo "<TR>";
echo "<TD NOWRAP ALIGN=RIGHT><P><FONT SIZE=1>";
if ($USER->teacher[$course->id]) {
if ($USER->editing) {
echo "<A HREF=\"view.php?id=$course->id&edit=off\">Turn editing off</A>";
} else {
echo "<A HREF=\"view.php?id=$course->id&edit=on\">Turn editing on</A>";
}
}
//if ($USER->help) {
//echo "&nbsp;&nbsp;&nbsp;<A HREF=\"view.php?id=$course->id&help=off\">Turn help off</A>";
//} else {
//echo "&nbsp;&nbsp;&nbsp;<A HREF=\"view.php?id=$course->id&help=on\">Turn help on</A>";
//}
echo "</TD></TR></TABLE>";
echo "<TABLE WIDTH=100% CELLPADDING=5 CELLSPACING=20 BORDER=0>";
// Forums
echo "<TR><TD VALIGN=top WIDTH=33% BGCOLOR=\"$THEME->cellheading\">";
echo "<H4>Forums</H4>";
echo "<TABLE BORDER=0>";
if ($forums = get_all_instances_in_course("forum", $course->id)) {
foreach ($forums as $key => $ff) {
$forum = (object)$ff;
echo "<TR><TD WIDTH=16 VALIGN=top>";
echo "<A HREF=\"../mod/forum/view.php?id=$forum->coursemodule\">";
echo "<IMG SRC=\"../mod/forum/icon.gif\" HEIGHT=16 WIDTH=16 ALT=\"Forum\" BORDER=0></A>";
echo "</TD><TD WIDTH=100%><P>";
echo "<A HREF=\"../mod/forum/view.php?id=$forum->coursemodule\">$forum->name</A>";
if ($USER->editing) {
echo "&nbsp;&nbsp;<A HREF=mod.php?delete=$forum->coursemodule><IMG
SRC=../pix/t/delete.gif BORDER=0 ALT=Delete></A>
<A HREF=mod.php?update=$forum->coursemodule><IMG
SRC=../pix/t/edit.gif BORDER=0 ALT=Update></A>";
}
echo "</TD></TR>\n";
}
}
if ($USER->editing) {
echo "<TR><TD>&nbsp;</TD><TD><P>";
echo "<FONT SIZE=1><A HREF=\"mod.php?id=$course->id&week=0&add=forum\">Add forum...</A></FONT>";
echo "</TD></TR>";
}
echo "</TABLE>";
// Readings
echo "</TD><TD VALIGN=top WIDTH=33% BGCOLOR=\"$THEME->cellheading\">";
echo "<H4>Readings</H4>";
echo "<TABLE BORDER=0>";
if ($readings = get_all_instances_in_course("reading", $course->id, "m.timemodified DESC")) {
$count = 0;
foreach ($readings as $key => $rr) {
$reading = (object)$rr;
echo "<TR><TD WIDTH=16 VALIGN=top>";
echo "<A HREF=\"../mod/reading/view.php?id=$reading->coursemodule\">";
echo "<IMG SRC=\"../mod/reading/icon.gif\" HEIGHT=16 WIDTH=16 ALT=\"Forum\" BORDER=0></A>";
echo "</TD><TD WIDTH=100%><P>";
echo "<A HREF=\"../mod/reading/view.php?id=$reading->coursemodule\">$reading->name</A>";
if ($USER->editing) {
echo "&nbsp;&nbsp;<A HREF=mod.php?delete=$reading->coursemodule><IMG
SRC=../pix/t/delete.gif BORDER=0 ALT=Delete></A>
<A HREF=mod.php?update=$reading->coursemodule><IMG
SRC=../pix/t/edit.gif BORDER=0 ALT=Update></A>";
}
echo "</TD></TR>\n";
if ($count++ > 5) {
echo "<TR><TD>&nbsp;</TD><TD><P>";
echo "<A HREF=\"../mod/reading/index.php?id=$course->id\">See all readings...</A></FONT>";
echo "</TD></TR>";
break;
}
}
}
if ($USER->editing) {
echo "<TR><TD>&nbsp;</TD><TD><P>";
echo "<FONT SIZE=1><A HREF=\"mod.php?id=$course->id&week=0&add=reading\">Add reading...</A></FONT>";
echo "</TD></TR>";
}
echo "</TABLE>";
// Participants
echo "</TD><TD VALIGN=top WIDTH=33% BGCOLOR=\"$THEME->cellheading\">";
echo "<H4>Participants</H4>";
echo "<TABLE BORDER=0>";
echo "<TR><TD WIDTH=16 VALIGN=top>";
echo "<A HREF=\"../user/index.php?id=$course->id\">";
echo "<IMG SRC=\"../user/users.gif\" HEIGHT=16 WIDTH=16 ALT=\"Participants\" BORDER=0></A>";
echo "</TD><TD WIDTH=100%><P>";
echo "<A HREF=\"../user/index.php?id=$course->id\">List of all participants</A>";
echo "</TD></TR>\n";
echo "<TR><TD WIDTH=16>";
echo "<A HREF=\"../user/view.php?id=$USER->id&course=$course->id\">";
echo "<IMG SRC=\"../user/user.gif\" HEIGHT=16 WIDTH=16 ALT=\"Participants\" BORDER=0></A>";
echo "</TD><TD WIDTH=100%><P>";
echo "<A HREF=\"../user/view.php?id=$USER->id&course=$course->id\">My details</A>";
echo "</TD></TR>\n";
echo "</TABLE>";
// Then all the links to module types
echo "</TABLE>";
echo "</TABLE>";
echo "</TD></TR></TABLE>";
?>
+46
View File
@@ -0,0 +1,46 @@
<?PHP // $Id$
require("../config.php");
require_variable($id); // course id
require_variable($user); // user id
if (! $course = get_record("course", "id", $id)) {
error("Course id is incorrect.");
}
require_login($course->id);
if (!isteacher($course->id)) {
error("Only teachers can look at this page");
}
if (! $user = get_record("user", "id", $user)) {
error("User ID is incorrect");
}
add_to_log("View total report of $user->firstname $user->lastname", $course->id);
print_header("$course->shortname: Report", "$course->fullname",
"<A HREF=\"../course/view.php?id=$course->id\">$course->shortname</A> ->
<A HREF=\"../user/index.php?id=$course->id\">Participants</A> ->
<A HREF=\"../user/view.php?id=$user->id&course=$course->id\">$user->firstname $user->lastname</A> ->
Full Report", "");
if ($mods = get_records_sql("SELECT * FROM modules ORDER BY fullname")) {
foreach ($mods as $mod) {
$userfile = "$CFG->dirroot/mod/$mod->name/user.php";
if (file_exists($userfile)) {
echo "<H2>".$mod->fullname."s</H2>";
echo "<BLOCKQUOTE>";
include($userfile);
echo "</BLOCKQUOTE>";
echo "<HR WIDTH=100%>";
}
}
}
print_footer($course);
?>
+102
View File
@@ -0,0 +1,102 @@
<?PHP // $Id$
// Display the course home page.
require("../config.php");
require("lib.php");
require_login($id);
if (! $course = get_record("course", "id", $id) ) {
error("That's an invalid course id");
}
if (! $course->category) { // This course is not a real course.
redirect("$CFG->wwwroot");
}
add_to_log("View course: $course->shortname", $id);
if ( $USER->teacher[$course->id] ) {
if ($edit == "on") {
$USER->editing = true;
} else if ($edit == "off") {
$USER->editing = false;
}
}
if ($help == "on") {
$USER->help = true;
} else if ($help == "off") {
$USER->help = false;
}
print_header("Course: $course->fullname", "$course->fullname", "$course->shortname", "");
if (! $modtypes = get_records_sql_menu("SELECT name,fullname FROM modules ORDER BY fullname") ) {
error("No modules are installed!");
}
if ( $rawmods = get_records_sql("SELECT cm.*, m.name as modname, m.fullname as modfullname
FROM modules m, course_modules cm
WHERE cm.course = '$course->id'
AND cm.deleted = '0'
AND cm.module = m.id") ) {
foreach($rawmods as $mod) { // Index the mods
$mods[$mod->id] = $mod;
$modtype[$mod->modname] = $mod->modfullname;
}
}
switch ($course->format) {
case 0:
include("noweeks.php");
break;
case 1:
include("weeks.php");
break;
}
print_footer($course);
/// FUNCTIONS ////////
function make_editing_buttons($moduleid) {
return "&nbsp; &nbsp;
<A HREF=mod.php?delete=$moduleid><IMG
SRC=../pix/t/delete.gif BORDER=0 ALT=Delete></A>
<A HREF=mod.php?id=$moduleid&move=-1><IMG
SRC=../pix/t/up.gif BORDER=0 ALT=\"Move up\"></A>
<A HREF=mod.php?id=$moduleid&move=1><IMG
SRC=../pix/t/down.gif BORDER=0 ALT=\"Move down\"></A>
<A HREF=mod.php?update=$moduleid><IMG
SRC=../pix/t/edit.gif BORDER=0 ALT=Update></A>";
}
function print_side_block($heading="", $list=NULL, $footer="", $icons=NULL) {
echo "<TABLE WIDTH=100%>\n";
echo "<TR><TD COLSPAN=2><P><B><FONT SIZE=2>$heading</TD></TR>\n";
if ($list) {
foreach($list as $key => $string) {
echo "<TR><TD VALIGN=top WIDTH=12>";
if ($icons[$key]) {
echo $icons[$key];
} else {
echo "";
}
echo "</TD>\n<TD WIDTH=100%>";
echo "<P><FONT SIZE=1>$string</FONT></P>";
echo "</TD></TR>\n";
}
}
if ($footer) {
echo "<TR><TD></TD><TD ALIGN=left><P><FONT SIZE=2>$footer</TD></TR>\n";
}
echo "</TABLE><BR>\n\n";
}
?>
+184
View File
@@ -0,0 +1,184 @@
<?PHP // $Id$
// Display the whole course as "weeks" made of of modules
// Included from "view.php"
if (! $rawweeks = get_records("course_weeks", "course", $course->id) ) {
$week->course = $course->id; // Create a default week.
$week->week = 0;
$week->id = insert_record("course_weeks", $week);
if (! $rawweeks = get_records("course_weeks", "course", $course->id) ) {
error("Error finding or creating week structures for this course");
}
}
foreach($rawweeks as $cw) { //Index the weeks
$weeks[$cw->week] = $cw;
}
// Layout the whole page as two big columns.
echo "<TABLE BORDER=0 CELLPADDING=4>";
echo "<TR VALIGN=top><TD VALIGN=top WIDTH=200>";
echo "<IMG SRC=\"../pix/spacer.gif\" WIDTH=180 HEIGHT=1><BR>";
// Layout the left column
print_side_block("<A HREF=\"new.php?id=$course->id\">What's New!</A>",
"", "<FONT SIZE=1>...since your last login</FONT>");
// Then, print all the news items.
include("../mod/discuss/lib.php");
if ($news = get_course_news_forum($course->id)) {
print_simple_box_start("CENTER", "100%", "#FFFFFF", 5);
echo "<P><B><FONT SIZE=2>Latest News</FONT></B><BR>";
echo "<FONT SIZE=1>";
forum_latest_topics($news->id, 5, "minimal", "DESC", false);
echo "</FONT>";
print_simple_box_end();
}
// Now, print all the course links on the side
// Then all the links to module types
$moddata = array();
$modicon = array();
if ($modtype) {
foreach ($modtype as $modname => $modfullname) {
$moddata[] = "<A HREF=\"../mod/$modname/index.php?id=$course->id\">".$modfullname."s</A>";
$modicon[] = "<IMG SRC=\"../mod/$modname/icon.gif\" HEIGHT=16 WIDTH=16 ALT=\"$modfullname\">";
}
}
$moddata[]="<A HREF=\"../user/index.php?id=$course->id\">Participants</A>";
$modicon[]="<IMG SRC=\"../user/users.gif\" HEIGHT=16 WIDTH=16 ALT=\"Participants\">";
print_side_block("Activities", $moddata, "", $modicon);
// Admin links and controls
$admindata[]="<A HREF=\"../user/view.php?id=$USER->id&course=$course->id\">My details</A>";
$adminicon[]="<IMG SRC=\"../user/user.gif\" HEIGHT=16 WIDTH=16 ALT=\"About me\">";
if ($USER->teacher[$course->id]) {
$admindata[]="<A HREF=\"edit.php?id=$course->id\">Course settings</A>";
$adminicon[]="<IMG SRC=\"../pix/i/settings.gif\" HEIGHT=16 WIDTH=16 ALT=\"Course\">";
$admindata[]="<A HREF=\"log.php?id=$course->id\">Logs</A>";
$adminicon[]="<IMG SRC=\"../pix/i/log.gif\" HEIGHT=16 WIDTH=16 ALT=\"Log\">";
$admindata[]="<A HREF=\"email.php?id=$course->id\">Send mail</A>";
$adminicon[]="<IMG SRC=\"../pix/i/email.gif\" HEIGHT=16 WIDTH=16 ALT=\"Email\">";
$admindata[]="<A HREF=\"../files/index.php?id=$course->id\">Files</A>";
$adminicon[]="<IMG SRC=\"../files/pix/files.gif\" HEIGHT=16 WIDTH=16 ALT=\"Files\">";
}
print_side_block("Administration", $admindata, "", $adminicon);
// Start main column
echo "</TD><TD WIDTH=100%>";
// Now all the weekly modules
$timenow = time();
$weekdate = $course->startdate; // this should be 0:00 Monday of that week
$week = 1;
$weekofseconds = 604800;
echo "<P><IMG SRC=\"../pix/spacer.gif\" WIDTH=100% HEIGHT=3><BR>";
echo "<TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0 WIDTH=100%>";
echo "<TR><TD>";
echo "<B><FONT SIZE=2>Weekly Outline</FONT></B>\n";
// Global switches
echo "</TD><TD NOWRAP ALIGN=RIGHT><P><FONT SIZE=1>";
if ($USER->teacher[$course->id]) {
if ($USER->editing) {
echo "<A HREF=\"view.php?id=$course->id&edit=off\">Turn editing off</A>";
} else {
echo "<A HREF=\"view.php?id=$course->id&edit=on\">Turn editing on</A>";
}
}
if ($USER->help) {
echo "&nbsp;&nbsp;&nbsp;<A HREF=\"view.php?id=$course->id&help=off\">Turn help off</A>";
} else {
echo "&nbsp;&nbsp;&nbsp;<A HREF=\"view.php?id=$course->id&help=on\">Turn help on</A>";
}
echo "</FONT></P></TD></TR></TABLE>";
echo "<TABLE BORDER=0 CELLPADDING=8 CELLSPACING=0 WIDTH=100%>";
while ($weekdate < $course->enddate) {
echo "<TR>";
$nextweekdate = $weekdate + ($weekofseconds);
$thisweek = (($weekdate <= $timenow) && ($timenow < $nextweekdate));
$weekday = date("j F", $weekdate);
$endweekday = date("j F", $weekdate+(6*24*3600));
if ($thisweek) {
$highlightcolor = $THEME->cellheading2;
} else {
$highlightcolor = $THEME->cellheading;
}
echo "<TD NOWRAP BGCOLOR=\"$highlightcolor\" VALIGN=top>";
echo "<P ALIGN=CENTER><FONT SIZE=3><B>$week</B></FONT></P>";
echo "</TD>";
echo "<TD VALIGN=top BGCOLOR=\"$THEME->cellcontent\">";
echo "<P><FONT SIZE=3 COLOR=\"$THEME->cellheading2\">$weekday - $endweekday</FONT></P>";
if (! $thisweek = $weeks[$week]) {
$thisweek->course = $course->id; // Create a new week structure
$thisweek->week = $week;
$thisweek->summary = "";
$thisweek->id = insert_record("course_weeks", $thisweek);
}
if ($USER->editing) {
$thisweek->summary .= "&nbsp;<A HREF=editweek.php?id=$thisweek->id><IMG SRC=\"../pix/t/edit.gif\" BORDER=0 ALT=\"Edit summary\"></A></P>";
}
echo text_to_html($thisweek->summary);
echo "<P>";
if ($thisweek->sequence) {
$thisweekmods = explode(",", $thisweek->sequence);
foreach ($thisweekmods as $modnumber) {
$mod = $mods[$modnumber];
$instancename = get_field("$mod->modname", "name", "id", "$mod->instance");
echo "<IMG SRC=\"../mod/$mod->modname/icon.gif\" HEIGHT=16 WIDTH=16 ALT=\"$mod->modfullname\"> <A HREF=\"../mod/$mod->modname/view.php?id=$mod->id\">$instancename</A>";
if ($USER->editing) {
echo make_editing_buttons($mod->id);
}
echo "<BR>\n";
}
}
echo "</UL></P>\n";
if ($USER->editing) {
echo "<DIV ALIGN=right>";
popup_form("$CFG->wwwroot/course/mod.php?id=$course->id&week=$week&add=",
$modtypes, "week$week", "", "Add...");
echo "</DIV>";
}
echo "</TD>";
echo "<TD NOWRAP BGCOLOR=\"$highlightcolor\" VALIGN=top>&nbsp;</TD>";
echo "</TR>";
echo "<TR><TD COLSPAN=3><IMG SRC=../pix/spacer.gif WIDTH=1 HEIGHT=1></TD></TR>";
$week++;
$weekdate = $nextweekdate;
}
echo "</TABLE>";
echo "</TABLE>";
echo "</TD></TR></TABLE>";
?>
+8
View File
@@ -0,0 +1,8 @@
0.1
---
Starting to look more complete.
Added news posting and email forwarding of news items.
Changed listing of modules to A,B,C,D
+20
View File
@@ -0,0 +1,20 @@
Moodle - Modular Object-Oriented Dynamic Learning Environment
http://moodle.com
Copyright (C) 2000, 2001 Martin Dougiamas [email protected]
http://dougiamas.com
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+95
View File
@@ -0,0 +1,95 @@
===========================================================================
== MOODLE
==
== OPEN-SOURCE SOFTWARE FOR INTERNET-BASED EDUCATION
==
== Copyright (c) Martin Dougiamas, 2001
==
== Freely available under the GNU License
==
===========================================================================
Directory structure
===================
config.php - the only file you need to edit to get started
lib - libraries of core Moodle code
user - code to display and manage users
course - code to display and manage courses
login - code to handle login and account creation
admin - code to administrate the whole server
pix - Generic site graphics are in here
mod - All Moodle modules are in here
theme - All Moodle themes are in here
HOW TO INSTALL MOODLE
=====================
1. SET UP A DATABASE
Create an empty database (eg "moodle") in your database system
along with a special user (eg "moodle") that has access to that
database. (Don't use the "root" user for the moodle database -
it's a security hazard).
eg for MySQL under a Unix system:
# mysql -u root -p
> CREATE DATABASE moodle;
> GRANT SELECT,INSERT,UPDATE,DELETE,CREATE,DROP,INDEX,ALTER ON moodle.*
TO moodle@localhost IDENTIFIED BY 'yourpassword';
> quit
# mysqladmin -p reload
2. EDIT config.php
Edit the configuration file, putting in the database details that you
just defined, as well as changing the site address and so on.
Make sure you specify what type of database you are using.
eg:
$CFG->wwwroot = "http://example.com";
$CFG->dbtype = "mysqlt"; // eg mysql, mysqlt, postgres ... etc
$CFG->dbhost = "localhost"; // eg localhost
$CFG->dbname = "moodle"; // eg moodle
$CFG->dbuser = "moodle";
$CFG->dbpass = "yourpassword";
3. GO TO THE ADMIN PAGE
The admin page should now be working at: http://example.com/admin
The first time you access this page, Moodle will automagically
create all the tables it needs within your database.
You will then be asked to create an administration user for
future access to the admin pages..
All your further configuration of Moodle can now be done using the
administration web pages, including:
- creating and deleting courses
- administering teacher accounts
- changing site-wide settings
- adding/deleting modules
Configuration of each course is done by the teachers of that course.
See the teacher documentation for more information about that.
Have fun and send me feedback so we can continue improving Moodle!
Cheers!
Martin Dougiamas
[email protected]
+281
View File
@@ -0,0 +1,281 @@
GNU GENERAL PUBLIC LICENSE
Version 2, June 1991
Copyright (C) 1989, 1991 Free Software Foundation, Inc.
59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
Preamble
The licenses for most software are designed to take away your
freedom to share and change it. By contrast, the GNU General Public
License is intended to guarantee your freedom to share and change free
software--to make sure the software is free for all its users. This
General Public License applies to most of the Free Software
Foundation's software and to any other program whose authors commit to
using it. (Some other Free Software Foundation software is covered by
the GNU Library General Public License instead.) You can apply it to
your programs, too.
When we speak of free software, we are referring to freedom, not
price. Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
this service if you wish), that you receive source code or can get it
if you want it, that you can change the software or use pieces of it
in new free programs; and that you know you can do these things.
To protect your rights, we need to make restrictions that forbid
anyone to deny you these rights or to ask you to surrender the rights.
These restrictions translate to certain responsibilities for you if you
distribute copies of the software, or if you modify it.
For example, if you distribute copies of such a program, whether
gratis or for a fee, you must give the recipients all the rights that
you have. You must make sure that they, too, receive or can get the
source code. And you must show them these terms so they know their
rights.
We protect your rights with two steps: (1) copyright the software, and
(2) offer you this license which gives you legal permission to copy,
distribute and/or modify the software.
Also, for each author's protection and ours, we want to make certain
that everyone understands that there is no warranty for this free
software. If the software is modified by someone else and passed on, we
want its recipients to know that what they have is not the original, so
that any problems introduced by others will not reflect on the original
authors' reputations.
Finally, any free program is threatened constantly by software
patents. We wish to avoid the danger that redistributors of a free
program will individually obtain patent licenses, in effect making the
program proprietary. To prevent this, we have made it clear that any
patent must be licensed for everyone's free use or not licensed at all.
The precise terms and conditions for copying, distribution and
modification follow.
GNU GENERAL PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. This License applies to any program or other work which contains
a notice placed by the copyright holder saying it may be distributed
under the terms of this General Public License. The "Program", below,
refers to any such program or work, and a "work based on the Program"
means either the Program or any derivative work under copyright law:
that is to say, a work containing the Program or a portion of it,
either verbatim or with modifications and/or translated into another
language. (Hereinafter, translation is included without limitation in
the term "modification".) Each licensee is addressed as "you".
Activities other than copying, distribution and modification are not
covered by this License; they are outside its scope. The act of
running the Program is not restricted, and the output from the Program
is covered only if its contents constitute a work based on the
Program (independent of having been made by running the Program).
Whether that is true depends on what the Program does.
1. You may copy and distribute verbatim copies of the Program's
source code as you receive it, in any medium, provided that you
conspicuously and appropriately publish on each copy an appropriate
copyright notice and disclaimer of warranty; keep intact all the
notices that refer to this License and to the absence of any warranty;
and give any other recipients of the Program a copy of this License
along with the Program.
You may charge a fee for the physical act of transferring a copy, and
you may at your option offer warranty protection in exchange for a fee.
2. You may modify your copy or copies of the Program or any portion
of it, thus forming a work based on the Program, and copy and
distribute such modifications or work under the terms of Section 1
above, provided that you also meet all of these conditions:
a) You must cause the modified files to carry prominent notices
stating that you changed the files and the date of any change.
b) You must cause any work that you distribute or publish, that in
whole or in part contains or is derived from the Program or any
part thereof, to be licensed as a whole at no charge to all third
parties under the terms of this License.
c) If the modified program normally reads commands interactively
when run, you must cause it, when started running for such
interactive use in the most ordinary way, to print or display an
announcement including an appropriate copyright notice and a
notice that there is no warranty (or else, saying that you provide
a warranty) and that users may redistribute the program under
these conditions, and telling the user how to view a copy of this
License. (Exception: if the Program itself is interactive but
does not normally print such an announcement, your work based on
the Program is not required to print an announcement.)
These requirements apply to the modified work as a whole. If
identifiable sections of that work are not derived from the Program,
and can be reasonably considered independent and separate works in
themselves, then this License, and its terms, do not apply to those
sections when you distribute them as separate works. But when you
distribute the same sections as part of a whole which is a work based
on the Program, the distribution of the whole must be on the terms of
this License, whose permissions for other licensees extend to the
entire whole, and thus to each and every part regardless of who wrote it.
Thus, it is not the intent of this section to claim rights or contest
your rights to work written entirely by you; rather, the intent is to
exercise the right to control the distribution of derivative or
collective works based on the Program.
In addition, mere aggregation of another work not based on the Program
with the Program (or with a work based on the Program) on a volume of
a storage or distribution medium does not bring the other work under
the scope of this License.
3. You may copy and distribute the Program (or a work based on it,
under Section 2) in object code or executable form under the terms of
Sections 1 and 2 above provided that you also do one of the following:
a) Accompany it with the complete corresponding machine-readable
source code, which must be distributed under the terms of Sections
1 and 2 above on a medium customarily used for software interchange; or,
b) Accompany it with a written offer, valid for at least three
years, to give any third party, for a charge no more than your
cost of physically performing source distribution, a complete
machine-readable copy of the corresponding source code, to be
distributed under the terms of Sections 1 and 2 above on a medium
customarily used for software interchange; or,
c) Accompany it with the information you received as to the offer
to distribute corresponding source code. (This alternative is
allowed only for noncommercial distribution and only if you
received the program in object code or executable form with such
an offer, in accord with Subsection b above.)
The source code for a work means the preferred form of the work for
making modifications to it. For an executable work, complete source
code means all the source code for all modules it contains, plus any
associated interface definition files, plus the scripts used to
control compilation and installation of the executable. However, as a
special exception, the source code distributed need not include
anything that is normally distributed (in either source or binary
form) with the major components (compiler, kernel, and so on) of the
operating system on which the executable runs, unless that component
itself accompanies the executable.
If distribution of executable or object code is made by offering
access to copy from a designated place, then offering equivalent
access to copy the source code from the same place counts as
distribution of the source code, even though third parties are not
compelled to copy the source along with the object code.
4. You may not copy, modify, sublicense, or distribute the Program
except as expressly provided under this License. Any attempt
otherwise to copy, modify, sublicense or distribute the Program is
void, and will automatically terminate your rights under this License.
However, parties who have received copies, or rights, from you under
this License will not have their licenses terminated so long as such
parties remain in full compliance.
5. You are not required to accept this License, since you have not
signed it. However, nothing else grants you permission to modify or
distribute the Program or its derivative works. These actions are
prohibited by law if you do not accept this License. Therefore, by
modifying or distributing the Program (or any work based on the
Program), you indicate your acceptance of this License to do so, and
all its terms and conditions for copying, distributing or modifying
the Program or works based on it.
6. Each time you redistribute the Program (or any work based on the
Program), the recipient automatically receives a license from the
original licensor to copy, distribute or modify the Program subject to
these terms and conditions. You may not impose any further
restrictions on the recipients' exercise of the rights granted herein.
You are not responsible for enforcing compliance by third parties to
this License.
7. If, as a consequence of a court judgment or allegation of patent
infringement or for any other reason (not limited to patent issues),
conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License. If you cannot
distribute so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you
may not distribute the Program at all. For example, if a patent
license would not permit royalty-free redistribution of the Program by
all those who receive copies directly or indirectly through you, then
the only way you could satisfy both it and this License would be to
refrain entirely from distribution of the Program.
If any portion of this section is held invalid or unenforceable under
any particular circumstance, the balance of the section is intended to
apply and the section as a whole is intended to apply in other
circumstances.
It is not the purpose of this section to induce you to infringe any
patents or other property right claims or to contest validity of any
such claims; this section has the sole purpose of protecting the
integrity of the free software distribution system, which is
implemented by public license practices. Many people have made
generous contributions to the wide range of software distributed
through that system in reliance on consistent application of that
system; it is up to the author/donor to decide if he or she is willing
to distribute software through any other system and a licensee cannot
impose that choice.
This section is intended to make thoroughly clear what is believed to
be a consequence of the rest of this License.
8. If the distribution and/or use of the Program is restricted in
certain countries either by patents or by copyrighted interfaces, the
original copyright holder who places the Program under this License
may add an explicit geographical distribution limitation excluding
those countries, so that distribution is permitted only in or among
countries not thus excluded. In such case, this License incorporates
the limitation as if written in the body of this License.
9. The Free Software Foundation may publish revised and/or new versions
of the General Public License from time to time. Such new versions will
be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.
Each version is given a distinguishing version number. If the Program
specifies a version number of this License which applies to it and "any
later version", you have the option of following the terms and conditions
either of that version or of any later version published by the Free
Software Foundation. If the Program does not specify a version number of
this License, you may choose any version ever published by the Free Software
Foundation.
10. If you wish to incorporate parts of the Program into other free
programs whose distribution conditions are different, write to the author
to ask for permission. For software which is copyrighted by the Free
Software Foundation, write to the Free Software Foundation; we sometimes
make exceptions for this. Our decision will be guided by the two goals
of preserving the free status of all derivatives of our free software and
of promoting the sharing and reuse of software generally.
NO WARRANTY
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
REPAIR OR CORRECTION.
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
POSSIBILITY OF SUCH DAMAGES.
END OF TERMS AND CONDITIONS
+3
View File
@@ -0,0 +1,3 @@
weeks dates start from 0:00 Monday morning
+15
View File
@@ -0,0 +1,15 @@
Roadmap
-------
Here are some of the directions I would like to take
Moodle now it has been released.
- Code audit and clean up. Standardise tabs, wordwrap.
Refactor a few bits.
- Full internationalisation. To start with I've hardcoded
all the strings just to get things started and reduce
obfuscation during development. Modular "language packs"
need to implemented instead. eg using STPhp.
+37
View File
@@ -0,0 +1,37 @@
<?PHP // $Id$
require("../config.php");
if (isset($text)) { // form submitted
if (!$user = get_record("users", "id", 1)) {
error("Could not find the admin user to mail to!");
}
email_to_user($user, $USER, "Error: $referer -> $requested", "$text");
redirect("$CFG->wwwroot/course/", "Message sent, thanks", 3);
die;
}
print_header("$CFG->sitename:Error", "$CFG->sitename: Error 404", "", "form.text");
add_to_log("Error: $HTTP_REFERER -> $REQUEST_URI");
print_simple_box("An unusual error occurred (tried to reach a page that doesn't exist).<P align=center>$REQUEST_URI", "center", "", "$THEME->cellheading");
?>
<CENTER>
<P>If you have time, please let us know what you were trying
to do when the error occurred:
<P><FORM action="<?=$CFG->wwwroot ?>/error/index.php" name=form method=post>
<TEXTAREA ROWS=3 COLS=50 NAME=text></TEXTAREA><BR>
<INPUT TYPE=hidden NAME=referer VALUE="<?=$HTTP_REFERER ?>">
<INPUT TYPE=hidden NAME=requested VALUE="<?=$REQUEST_URI ?>">
<INPUT TYPE=submit VALUE="Send this off">
</FORM>
<?
print_footer();
?>
+43
View File
@@ -0,0 +1,43 @@
<?PHP // $Id$
// This function fetches files from the data directory
// Syntax: file.php/courseid/dir/.../dir/filename.ext
require("config.php");
require("files/mimetypes.php");
$lifetime = 86400;
if (!$PATH_INFO) {
error("This script DEPENDS on $PATH_INFO being available. Read the README.");
}
$args = get_slash_arguments();
$numargs = count($args);
$courseid = (integer)$args[0];
if ($courseid > 0) {
require_login($courseid);
}
$pathname = "$CFG->dataroot$PATH_INFO";
$filename = $args[$numargs-1];
$mimetype = mimeinfo("type", $filename);
if (file_exists($pathname)) {
$lastmodified = filemtime($pathname);
header("Last-Modified: " . gmdate("D, d M Y H:i:s", $lastmodified) . " GMT");
header("Expires: " . gmdate("D, d M Y H:i:s", time() + $lifetime) . " GMT");
header("Cache-control: max_age = $lifetime"); // a day
header("Pragma: ");
header("Content-Length: ".filesize($pathname));
header("Content-type: $mimetype");
readfile("$pathname");
} else {
error("Sorry, but the file you are looking for was not found", "/course/view.php?id=$courseid");
}
exit;
?>
+646
View File
@@ -0,0 +1,646 @@
<?PHP // $Id$
// Manage all uploaded files in a course file area
// All the Moodle-specific stuff is in this top section
// Configuration and access control occurs here.
// Must define: USER, basedir, baseweb, html_header and html_footer
// USER is a persistent variable using sessions
require("../config.php");
require_variable($id);
if (! $course = get_record("course", "id", $id) ) {
error("That's an invalid course id");
}
require_login($course->id);
add_to_log("Files area", $course->id);
if (! isteacher($course->id) ) {
error("Only teachers can edit files");
}
function html_footer() {
global $course;
echo "</td></tr></table></body></html>";
print_footer($course);
}
function html_header($formfield=""){
global $course;
print_header("$course->shortname: Files", "$course->shortname: Files",
"<A HREF=\"../course/view.php?id=$course->id\">$course->shortname</A> -> Files", $formfield);
echo "<table border=0 align=center cellspacing=3 cellpadding=3 width=640>";
echo "<tr>";
echo "<td colspan=\"2\">";
}
if (! file_exists($CFG->dataroot)) {
if (! mkdir($CFG->dataroot, 0750)) {
error("You need to create the directory $CFG->dataroot with web server write access");
}
}
$basedir = "$CFG->dataroot/$course->id";
if (! file_exists($basedir)) {
if (! mkdir($basedir, 0750)) {
error("Could not create a directory for this course ($basedir)");
}
}
$baseweb = $CFG->wwwroot;
// End of configuration and access control
require("mimetypes.php");
$regexp="\\.\\.";
if (ereg( $regexp, $file, $regs )| ereg( $regexp, $wdir,$regs )) {
$message = "Error: Directories can not contain \"..\"";
$wdir = "/";
$action = "";
}
if (!match_referer("$baseweb/files/index.php")) { // To stop spoofing
$action="cancel";
$wdir="/";
}
if (!$wdir) {
$wdir="/";
}
switch ($action) {
case "upload":
html_header();
if ($save) {
if ($userfile == "none" || $userfile_size==0) {
echo "<P>Error: That was not a valid file.";
} else {
$userfile_name = clean_filename($userfile_name);
if ($userfile_name != "") {
$newfile = "$basedir$wdir/$userfile_name";
copy ($userfile, $newfile);
chmod ($newfile, 0750);
echo "Uploaded $userfile_name ($userfile_type) to $wdir";
}
}
displaydir($wdir);
} else {
echo "<P>Upload a file into <B>$wdir</B>:";
echo "<TABLE><TR><TD COLSPAN=2>";
echo "<FORM ENCTYPE=\"multipart/form-data\" METHOD=\"post\" ACTION=index.php>";
echo " <INPUT TYPE=hidden NAME=MAX_FILE_SIZE value=5000000>";
echo " <INPUT TYPE=hidden NAME=id VALUE=$id>";
echo " <INPUT TYPE=hidden NAME=wdir VALUE=$wdir>";
echo " <INPUT TYPE=hidden NAME=action VALUE=upload>";
echo " <INPUT NAME=\"userfile\" TYPE=\"file\" size=\"50\">";
echo " </TD><TR><TD WIDTH=10>";
echo " <INPUT TYPE=submit NAME=save VALUE=\"Upload this file\">";
echo "</FORM>";
echo "</TD><TD WIDTH=100%>";
echo "<FORM ACTION=index.php METHOD=get>";
echo " <INPUT TYPE=hidden NAME=id VALUE=$id>";
echo " <INPUT TYPE=hidden NAME=wdir VALUE=$wdir>";
echo " <INPUT TYPE=hidden NAME=action VALUE=cancel>";
echo " <INPUT TYPE=submit VALUE=\"Cancel\">";
echo "</FORM>";
echo "</TD></TR></TABLE>";
}
html_footer();
break;
case "delete":
if ($confirm) {
html_header();
foreach ($USER->filelist as $file) {
$fullfile = $basedir.$file;
if (! fulldelete($fullfile)) {
echo "<BR>Error: Could not delete: $fullfile";
}
}
clearfilelist();
displaydir($wdir);
html_footer();
} else {
html_header();
if (setfilelist($HTTP_POST_VARS)) {
echo "<P ALIGN=CENTER>You are about to delete:</P>";
print_simple_box_start("center");
printfilelist($USER->filelist);
print_simple_box_end();
echo "<BR>";
notice_yesno ("Are you sure you want to delete these?",
"index.php?id=$id&wdir=$wdir&action=delete&confirm=1",
"index.php?id=$id&wdir=$wdir&action=cancel");
} else {
displaydir($wdir);
}
html_footer();
}
break;
case "move":
html_header();
if ($count = setfilelist($HTTP_POST_VARS)) {
$USER->fileop = $action;
$USER->filesource = $wdir;
echo "<P align=center>$count files selected for moving. Now go to the destination and press \"Move files to here\".</P>";
}
displaydir($wdir);
html_footer();
break;
case "paste":
html_header();
if ($USER->fileop == "move") {
foreach ($USER->filelist as $file) {
$shortfile = basename($file);
$oldfile = $basedir.$file;
$newfile = $basedir.$wdir."/".$shortfile;
if (!rename($oldfile, $newfile)) {
echo "<P>Error: $shortfile not moved";
}
}
}
clearfilelist();
displaydir($wdir);
html_footer();
break;
case "rename":
if ($name) {
html_header();
$name = clean_filename($name);
if (file_exists($basedir.$wdir."/".$name)) {
echo "Error: $name already exists!";
} else if (!rename($basedir.$wdir."/".$oldname, $basedir.$wdir."/".$name)) {
echo "Error: could not rename $oldname to $name";
}
displaydir($wdir);
} else {
html_header("form.name");
echo "<P>Rename <B>$file</B> to:";
echo "<TABLE><TR><TD>";
echo "<FORM ACTION=index.php METHOD=post NAME=form>";
echo " <INPUT TYPE=hidden NAME=id VALUE=$id>";
echo " <INPUT TYPE=hidden NAME=wdir VALUE=$wdir>";
echo " <INPUT TYPE=hidden NAME=action VALUE=rename>";
echo " <INPUT TYPE=hidden NAME=oldname VALUE=\"$file\">";
echo " <INPUT TYPE=text NAME=name SIZE=35 VALUE=\"$file\">";
echo " <INPUT TYPE=submit VALUE=\"Rename\">";
echo "</FORM>";
echo "</TD><TD>";
echo "<FORM ACTION=index.php METHOD=get>";
echo " <INPUT TYPE=hidden NAME=id VALUE=$id>";
echo " <INPUT TYPE=hidden NAME=wdir VALUE=$wdir>";
echo " <INPUT TYPE=hidden NAME=action VALUE=cancel>";
echo " <INPUT TYPE=submit VALUE=\"Cancel\">";
echo "</FORM>";
echo "</TD></TR></TABLE>";
}
html_footer();
break;
case "mkdir":
if ($name) {
html_header();
$name = clean_filename($name);
if (file_exists($basedir.$wdir."/".$name)) {
echo "Error: $name already exists!";
} else if (!mkdir($basedir.$wdir."/".$name, 0750)) {
echo "Error: could not create $name";
}
displaydir($wdir);
} else {
html_header("form.name");
echo "<P>Create folder in $wdir:";
echo "<TABLE><TR><TD>";
echo "<FORM ACTION=index.php METHOD=post NAME=form>";
echo " <INPUT TYPE=hidden NAME=id VALUE=$id>";
echo " <INPUT TYPE=hidden NAME=wdir VALUE=$wdir>";
echo " <INPUT TYPE=hidden NAME=action VALUE=mkdir>";
echo " <INPUT TYPE=text NAME=name SIZE=35>";
echo " <INPUT TYPE=submit VALUE=\"Create\">";
echo "</FORM>";
echo "</TD><TD>";
echo "<FORM ACTION=index.php METHOD=get>";
echo " <INPUT TYPE=hidden NAME=id VALUE=$id>";
echo " <INPUT TYPE=hidden NAME=wdir VALUE=$wdir>";
echo " <INPUT TYPE=hidden NAME=action VALUE=cancel>";
echo " <INPUT TYPE=submit VALUE=\"Cancel\">";
echo "</FORM>";
echo "</TD></TR></TABLE>";
}
html_footer();
break;
case "edit":
html_header();
if (isset($text)) {
$fileptr = fopen($basedir.$file,"w");
fputs($fileptr, stripslashes($text));
fclose($fileptr);
displaydir($wdir);
} else {
$fileptr = fopen($basedir.$file, "r");
$contents = fread($fileptr, filesize($basedir.$file));
fclose($fileptr);
echo "<P>Editing <B>$file</B>:";
echo "<TABLE><TR><TD COLSPAN=2>";
echo "<FORM ACTION=index.php METHOD=post NAME=form>";
echo " <INPUT TYPE=hidden NAME=id VALUE=$id>";
echo " <INPUT TYPE=hidden NAME=wdir VALUE=\"$wdir\">";
echo " <INPUT TYPE=hidden NAME=file VALUE=\"$file\">";
echo " <INPUT TYPE=hidden NAME=action VALUE=edit>";
echo "<TEXTAREA ROWS=20 COLS=60 NAME=text>";
echo htmlspecialchars($contents);
echo "</TEXTAREA>";
echo "</TD></TR><TR><TD>";
echo " <INPUT TYPE=submit VALUE=\"Save changes\">";
echo "</FORM>";
echo "</TD><TD>";
echo "<FORM ACTION=index.php METHOD=get>";
echo " <INPUT TYPE=hidden NAME=id VALUE=$id>";
echo " <INPUT TYPE=hidden NAME=wdir VALUE=$wdir>";
echo " <INPUT TYPE=hidden NAME=action VALUE=cancel>";
echo " <INPUT TYPE=submit VALUE=\"Cancel\">";
echo "</FORM>";
echo "</TD></TR></TABLE>";
}
html_footer();
break;
case "zip":
if ($name) {
html_header();
$name = clean_filename($name);
$files = "";
foreach ($USER->filelist as $file) {
$files .= basename($file);
$files .= " ";
}
$command = "cd $basedir/$wdir ; /usr/bin/zip -r $name $files";
Exec($command);
clearfilelist();
displaydir($wdir);
} else {
html_header("form.name");
if (setfilelist($HTTP_POST_VARS)) {
echo "<P ALIGN=CENTER>You are about create a zip file containing:</P>";
print_simple_box_start("center");
printfilelist($USER->filelist);
print_simple_box_end();
echo "<BR>";
echo "<P ALIGN=CENTER>What do you want to call the zip file?";
echo "<TABLE><TR><TD>";
echo "<FORM ACTION=index.php METHOD=post NAME=form>";
echo " <INPUT TYPE=hidden NAME=id VALUE=$id>";
echo " <INPUT TYPE=hidden NAME=wdir VALUE=\"$wdir\">";
echo " <INPUT TYPE=hidden NAME=action VALUE=zip>";
echo " <INPUT TYPE=text NAME=name SIZE=35 VALUE=\"new.zip\">";
echo " <INPUT TYPE=submit VALUE=\"Create zip file\">";
echo "</FORM>";
echo "</TD><TD>";
echo "<FORM ACTION=index.php METHOD=get>";
echo " <INPUT TYPE=hidden NAME=id VALUE=$id>";
echo " <INPUT TYPE=hidden NAME=wdir VALUE=$wdir>";
echo " <INPUT TYPE=hidden NAME=action VALUE=cancel>";
echo " <INPUT TYPE=submit VALUE=\"Cancel\">";
echo "</FORM>";
echo "</TD></TR></TABLE>";
} else {
displaydir($wdir);
clearfilelist();
}
}
html_footer();
break;
case "unzip":
html_header();
if ($file) {
echo "<P ALIGN=CENTER>Unzipping $file:</P>";
print_simple_box_start("center");
echo "<PRE>";
$file = basename($file);
$command = "cd $basedir/$wdir ; /usr/bin/unzip -o $file 2>&1";
passthru($command);
echo "</PRE>";
print_simple_box_end();
echo "<CENTER><FORM ACTION=index.php METHOD=get>";
echo " <INPUT TYPE=hidden NAME=id VALUE=$id>";
echo " <INPUT TYPE=hidden NAME=wdir VALUE=$wdir>";
echo " <INPUT TYPE=hidden NAME=action VALUE=cancel>";
echo " <INPUT TYPE=submit VALUE=\"OK\">";
echo "</FORM>";
echo "</CENTER>";
} else {
displaydir($wdir);
}
html_footer();
break;
case "cancel";
clearfilelist();
default:
html_header();
displaydir($wdir);
html_footer();
break;
}
/// FILE FUNCTIONS ///////////////////////////////////////////////////////////
function fulldelete($location) {
if (is_dir($location)) {
$currdir = opendir($location);
while ($file = readdir($currdir)) {
if ($file <> ".." && $file <> ".") {
$fullfile = $location."/".$file;
if (is_dir($fullfile)) {
if (!fulldelete($fullfile)) {
return false;
}
} else {
if (!unlink($fullfile)) {
return false;
}
}
}
}
closedir($currdir);
if (! rmdir($location)) {
return false;
}
} else {
if (!unlink($location)) {
return false;
}
}
return true;
}
function clean_filename($string) {
$string = eregi_replace("\.\.", "", $string);
$string = eregi_replace("[^([:alnum:]|\.)]", "_", $string);
return eregi_replace("_+", "_", $string);
}
function setfilelist($VARS) {
global $USER;
$USER->filelist = array ();
$USER->fileop = "";
$count = 0;
foreach ($VARS as $key => $val) {
if (substr($key,0,4) == "file") {
$count++;
$USER->filelist[] = rawurldecode($val);
}
}
return $count;
}
function clearfilelist() {
global $USER;
$USER->filelist = array ();
$USER->fileop = "";
}
function printfilelist($filelist) {
global $basedir;
foreach ($filelist as $file) {
if (is_dir($basedir.$file)) {
echo "<IMG SRC=\"pix/folder.gif\" HEIGHT=16 WIDTH=16> $file<BR>";
$subfilelist = array();
$currdir = opendir($basedir.$file);
while ($subfile = readdir($currdir)) {
if ($subfile <> ".." && $subfile <> ".") {
$subfilelist[] = $file."/".$subfile;
}
}
printfilelist($subfilelist);
} else {
$icon = mimeinfo("icon", $file);
echo "<IMG SRC=\"pix/$icon\" HEIGHT=16 WIDTH=16> $file<BR>";
}
}
}
function display_size($file) {
$file_size = filesize($file);
if ($file_size >= 1073741824) {
$file_size = round($file_size / 1073741824 * 100) / 100 . "g";
} else if ($file_size >= 1048576) {
$file_size = round($file_size / 1048576 * 100) / 100 . "m";
} else if ($file_size >= 1024) {
$file_size = round($file_size / 1024 * 100) / 100 . "k";
} else {
$file_size = $file_size . "b";
}
return $file_size;
}
function print_cell($alignment="center", $text="&nbsp;") {
echo "<TD ALIGN=\"$alignment\" NOWRAP>";
echo "<FONT SIZE=\"-1\" FACE=\"Arial, Helvetica\">";
echo "$text";
echo "</FONT>";
echo "</TD>\n";
}
function displaydir ($wdir) {
// $wdir == / or /a or /a/b/c/d etc
global $basedir;
global $id;
global $USER;
$fullpath = $basedir.$wdir;
$directory = opendir($fullpath); // Find all files
while ($file = readdir($directory)) {
if ($file == "." || $file == "..") {
continue;
}
if (is_dir($fullpath."/".$file)) {
$dirlist[] = $file;
} else {
$filelist[] = $file;
}
}
closedir($directory);
echo "<FORM ACTION=\"index.php\" METHOD=post NAME=dirform>";
echo "<HR WIDTH=640 ALIGN=CENTER NOSHADE SIZE=1>";
echo "<TABLE BORDER=0 cellspacing=2 cellpadding=2 width=640>";
echo "<TR><TD>&nbsp;</TD><TD COLSPAN=5><P><B>Current folder: $wdir</B></P>";
echo "<TR>";
echo "<TH WIDTH=5></TH>";
echo "<TH ALIGN=left>Name</TH>";
echo "<TH ALIGN=right>Size</TH>";
echo "<TH ALIGN=right>Modified</TH>";
echo "<TH ALIGN=right>Action</TH>";
echo "</TR>\n";
if ($wdir == "/") {
$wdir = "";
} else {
$updir = dirname($wdir);
echo "<TR>";
print_cell("center", "");
print_cell("left", "<A HREF=\"index.php?id=$id&wdir=$updir\"><IMG SRC=\"pix/parent.gif\" HEIGHT=16 WIDTH=16 BORDER=0 ALT=\"Parent folder\"></A> <A HREF=\"index.php?id=$id&wdir=$updir\">Up to $updir</A>");
echo "</TR>\n";
}
$count = 0;
if ($dirlist) {
asort($dirlist);
foreach ($dirlist as $dir) {
$count++;
$filename = $fullpath."/".$dir;
$fileurl = rawurlencode($wdir."/".$dir);
$filesafe = rawurlencode($dir);
$filedate = date("d-m-Y H:i:s", filectime($filename));
echo "<TR>";
print_cell("center", "<INPUT TYPE=checkbox NAME=\"file$count\" VALUE=\"$fileurl\">");
print_cell("left", "<A HREF=\"index.php?id=$id&wdir=$fileurl\"><IMG SRC=\"pix/folder.gif\" HEIGHT=16 WIDTH=16 BORDER=0 ALT=\"Folder\"></A> <A HREF=\"index.php?id=$id&wdir=$fileurl\">".htmlspecialchars($dir)."</A>");
print_cell("right", "-");
print_cell("right", $filedate);
print_cell("right", "<A HREF=\"index.php?id=$id&wdir=$wdir&file=$filesafe&action=rename\">rename</A>");
echo "</TR>";
}
}
if ($filelist) {
asort($filelist);
foreach ($filelist as $file) {
$icon = mimeinfo("icon", $file);
$count++;
$filename = $fullpath."/".$file;
$fileurl = "$wdir/$file";
$filesafe = rawurlencode($file);
$fileurlsafe = rawurlencode($fileurl);
$filedate = date("d-m-Y H:i:s", filectime($filename));
echo "<TR>";
print_cell("center", "<INPUT TYPE=checkbox NAME=\"file$count\" VALUE=\"$fileurl\">");
echo "<TD ALIGN=left NOWRAP>";
link_to_popup_window ("/file.php/$id$fileurl", "display",
"<IMG SRC=\"pix/$icon\" HEIGHT=16 WIDTH=16 BORDER=0 ALT=\"File\">",
480, 640);
echo "<FONT SIZE=\"-1\" FACE=\"Arial, Helvetica\">";
link_to_popup_window ("/file.php/$id$fileurl", "display",
htmlspecialchars($file),
480, 640);
echo "</FONT></TD>";
print_cell("right", display_size($filename));
print_cell("right", $filedate);
if ($icon == "text.gif" || $icon == "html.gif") {
$edittext = "<A HREF=\"index.php?id=$id&wdir=$wdir&file=$fileurl&action=edit\">edit</A>";
} else if ($icon == "zip.gif") {
$edittext = "<A HREF=\"index.php?id=$id&wdir=$wdir&file=$fileurl&action=unzip\">unzip</A>";
} else {
$edittext = "";
}
print_cell("right", "$edittext <A HREF=\"index.php?id=$id&wdir=$wdir&file=$filesafe&action=rename\">rename</A>");
echo "</TR>";
}
}
echo "</TABLE>";
echo "<HR WIDTH=640 ALIGN=CENTER NOSHADE SIZE=1>";
if (!$wdir) {
$wdir = "/";
}
echo "<TABLE BORDER=0 cellspacing=2 cellpadding=2 width=640>";
echo "<TR><TD>";
echo "<INPUT TYPE=hidden NAME=id VALUE=\"$id\">";
echo "<INPUT TYPE=hidden NAME=wdir VALUE=\"$wdir\"> ";
$options = array (
"move" => "Move to another folder",
"delete" => "Delete completely",
"zip" => "Create zip archive"
);
if ($count) {
choose_from_menu ($options, "action", "", $nothing="With chosen files...", "javascript:document.dirform.submit()");
//echo "<INPUT TYPE=submit VALUE=Go>";
}
echo "</FORM>";
echo "<TD ALIGN=center>";
if (($USER->fileop == "move") && $USER->filesource <> $wdir) {
echo "<FORM ACTION=index.php METHOD=get>";
echo " <INPUT TYPE=hidden NAME=id VALUE=$id>";
echo " <INPUT TYPE=hidden NAME=wdir VALUE=\"$wdir\">";
echo " <INPUT TYPE=hidden NAME=action VALUE=paste>";
echo " <INPUT TYPE=submit VALUE=\"Move files to here\">";
echo "</FORM>";
}
echo "<TD ALIGN=right>";
echo "<FORM ACTION=index.php METHOD=get>";
echo " <INPUT TYPE=hidden NAME=id VALUE=$id>";
echo " <INPUT TYPE=hidden NAME=wdir VALUE=\"$wdir\">";
echo " <INPUT TYPE=hidden NAME=action VALUE=mkdir>";
echo " <INPUT TYPE=submit VALUE=\"Make a folder\">";
echo "</FORM>";
echo "</TD>";
echo "<TD ALIGN=right>";
echo "<FORM ACTION=index.php METHOD=get>";
echo " <INPUT TYPE=hidden NAME=id VALUE=$id>";
echo " <INPUT TYPE=hidden NAME=wdir VALUE=\"$wdir\">";
echo " <INPUT TYPE=hidden NAME=action VALUE=upload>";
echo " <INPUT TYPE=submit VALUE=\"Upload a file\">";
echo "</FORM>";
echo "</TD></TR>";
echo "</TABLE>";
echo "<HR WIDTH=640 ALIGN=CENTER NOSHADE SIZE=1>";
}
?>
+37
View File
@@ -0,0 +1,37 @@
<? // $Id$
$mimeinfo = array (
"xxx" => array ("type"=>"document/unknown", "icon"=>"unknown.gif"),
"zip" => array ("type"=>"application/zip", "icon"=>"zip.gif"),
"jpeg" => array ("type"=>"image/jpeg", "icon"=>"image.gif"),
"jpg" => array ("type"=>"image/jpeg", "icon"=>"image.gif"),
"gif" => array ("type"=>"image/gif", "icon"=>"image.gif"),
"png" => array ("type"=>"image/png", "icon"=>"image.gif"),
"bmp" => array ("type"=>"image/bmp", "icon"=>"image.gif"),
"html" => array ("type"=>"text/html", "icon"=>"html.gif"),
"htm" => array ("type"=>"text/html", "icon"=>"html.gif"),
"txt" => array ("type"=>"text/plain", "icon"=>"text.gif"),
"wav" => array ("type"=>"audio/wav", "icon"=>"audio.gif"),
"mp3" => array ("type"=>"audio/mp3", "icon"=>"audio.gif"),
"au" => array ("type"=>"audio/au", "icon"=>"audio.gif"),
"swf" => array ("type"=>"application/x-shockwave-flash", "icon"=>"image.gif"),
"pdf" => array ("type"=>"application/pdf", "icon"=>"pdf.gif"),
"doc" => array ("type"=>"application/msword", "icon"=>"word.gif"),
"xls" => array ("type"=>"application/vnd.ms-excel", "icon"=>"excel.gif")
);
function mimeinfo($element, $filename) {
global $mimeinfo;
if (eregi("\.([a-z0-9]+)$", $filename, $match)) {
$result = $mimeinfo[strtolower($match[1])][$element];
}
if ($result) {
return $result;
} else {
return $mimeinfo["xxx"][$element]; // By default
}
}
?>
BIN
View File
Binary file not shown.

After

Width:  |  Height:  |  Size: 182 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 969 B

BIN
View File
Binary file not shown.

After

Width:  |  Height:  |  Size: 954 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 272 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 943 B

BIN
View File
Binary file not shown.

After

Width:  |  Height:  |  Size: 171 B

BIN
View File
Binary file not shown.

After

Width:  |  Height:  |  Size: 910 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 941 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 128 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 583 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 871 B

BIN
View File
Binary file not shown.

After

Width:  |  Height:  |  Size: 915 B

BIN
View File
Binary file not shown.

After

Width:  |  Height:  |  Size: 137 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 97 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 246 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 272 B

BIN
View File
Binary file not shown.

After

Width:  |  Height:  |  Size: 106 B

+50
View File
@@ -0,0 +1,50 @@
<? // $Id$
// index.php - the front page.
require("config.php");
if (! $site = get_record("course", "category", 0)) {
redirect("$CFG->wwwroot/admin/");
}
print_header("$site->fullname", "$site->fullname", "", "");
?>
<TABLE WIDTH="100%" BORDER="0" CELLSPACING="5" CELLPADDING="5">
<TR>
<TD WIDTH="15%" VALIGN="TOP" NOWRAP>
<? print_simple_box("Main Menu", $align="CENTER", $width="100%", $color="$THEME->cellheading"); ?>
<LI>Home</LI>
<LI><A TITLE="Available courses on this server" HREF="course/">Courses</A></LI>
<? include("mod/reading/lib.php");
list_all_readings();
?>
</TD>
<TD WIDTH="55%" VALIGN="TOP">
<? print_simple_box("Site News", $align="CENTER", $width="100%", $color="$THEME->cellheading"); ?>
<BR>
<? include("mod/discuss/lib.php");
forum_latest_topics();
?>
</TD>
<TD WIDTH="30%" VALIGN="TOP">
<? print_simple_box($site->summary, $align="", $width="100%", $color="$THEME->cellheading"); ?>
</TD>
</TR>
</TABLE>
<HR SIZE=1 NOSHADE>
<P ALIGN=center>
<A WIDTH=85 HEIGHT=25 HREF="http://moodle.com/"><IMG SRC="pix/madewithmoodle.gif" BORDER=0></A>
</P>
+983
View File
@@ -0,0 +1,983 @@
<?php
////////////////////////////////////////////////////
// phpmailer - PHP email class
//
// Version 1.25, Created 07/02/2001
//
// Class for sending email using either
// sendmail, PHP mail(), or SMTP. Methods are
// based upon the standard AspEmail(tm) classes.
//
// Author: Brent R. Matzelle <[email protected]>
//
// License: LGPL, see LICENSE
////////////////////////////////////////////////////
/**
* phpmailer - PHP email transport class
* @author Brent R. Matzelle
*/
class phpmailer
{
/////////////////////////////////////////////////
// PUBLIC VARIABLES
/////////////////////////////////////////////////
/**
* Email priority (1 = High, 3 = Normal, 5 = low). Default value is 3.
* @public
* @type int
*/
var $Priority = 3;
/**
* Sets the CharSet of the message. Default value is "iso-8859-1".
* @public
* @type string
*/
var $CharSet = "iso-8859-1";
/**
* Sets the Content-type of the message. Default value is "text/plain".
* @public
* @type string
*/
var $ContentType = "text/plain";
/**
* Sets the Encoding of the message. Options for this are "8bit" (default),
* "7bit", "binary", "base64", and "quoted-printable".
* @public
* @type string
*/
var $Encoding = "8bit";
/**
* Holds the most recent mailer error message. Default value is "".
* @public
* @type string
*/
var $ErrorInfo = "";
/**
* Sets the From email of the message. Default value is "root@localhost".
* @public
* @type string
*/
var $From = "root@localhost";
/**
* Sets the From name of the message. Default value is "Root User".
* @public
* @type string
*/
var $FromName = "Root User";
/**
* Sets the Sender email of the message. If not empty, will be sent via -f to sendmail
* or as 'MAIL FROM' in smtp mode. Default value is "".
* @public
* @type string
*/
var $Sender = "";
/**
* Sets the Subject of the message. Default value is "".
* @public
* @type string
*/
var $Subject = "";
/**
* Sets the Body of the message. Default value is "".
* @public
* @type string
*/
var $Body = "";
/**
* Sets word wrapping on the message. Default value is false (off).
* @public
* @type string
*/
var $WordWrap = false;
/**
* Method to send mail: ("mail", "sendmail", or "smtp").
* Default value is "mail".
* @public
* @type string
*/
var $Mailer = "mail";
/**
* Sets the path of the sendmail program. Default value is
* "/usr/sbin/sendmail".
* @public
* @type string
*/
var $Sendmail = "/usr/sbin/sendmail";
/**
* Turns Microsoft mail client headers on and off. Default value is false (off).
* @public
* @type bool
*/
var $UseMSMailHeaders = false;
/**
* Holds phpmailer version.
* @public
* @type string
*/
var $Version = "phpmailer [version 1.25]";
/////////////////////////////////////////////////
// SMTP VARIABLES
/////////////////////////////////////////////////
/**
* Sets the SMTP host. Default value is "localhost".
* @public
* @type string
*/
var $Host = "localhost";
/**
* Sets the SMTP server port. Default value is 25.
* @public
* @type int
*/
var $Port = 25;
/**
* Sets the CharSet of the message. Default value is "localhost.localdomain".
* @public
* @type string
*/
var $Helo = "localhost.localdomain";
/**
* Sets the SMTP server timeout. Default value is 10.
* @public
* @type int
*/
var $Timeout = 10; // Socket timeout in sec.
/**
* Sets SMTP class debugging on or off. Default value is false (off).
* @public
* @type bool
*/
var $SMTPDebug = false;
/////////////////////////////////////////////////
// PRIVATE VARIABLES
/////////////////////////////////////////////////
/**
* Holds all "To" addresses.
* @type array
*/
var $to = array();
/**
* Holds all "CC" addresses.
* @type array
*/
var $cc = array();
/**
* Holds all "BCC" addresses.
* @type array
*/
var $bcc = array();
/**
* Holds all "Reply-To" addresses.
* @type array
*/
var $ReplyTo = array();
/**
* Holds all attachments.
* @type array
*/
var $attachment = array();
/**
* Holds all custom headers.
* @type array
*/
var $CustomHeader = array();
/**
* Holds the message boundary. Default is false.
* @type string
*/
var $boundary = false;
/////////////////////////////////////////////////
// VARIABLE METHODS
/////////////////////////////////////////////////
/**
* Sets message type to HTML. Returns void.
* @public
* @returns void
*/
function IsHTML($bool) {
if($bool == true)
$this->ContentType = "text/html";
else
$this->ContentType = "text/plain";
}
/**
* Sets Mailer to use SMTP. Returns void.
* @public
* @returns void
*/
function IsSMTP() {
$this->Mailer = "smtp";
}
/**
* Sets Mailer to use PHP mail() function. Returns void.
* @public
* @returns void
*/
function IsMail() {
$this->Mailer = "mail";
}
/**
* Sets Mailer to use $Sendmail program. Returns void.
* @public
* @returns void
*/
function IsSendmail() {
$this->Mailer = "sendmail";
}
/**
* Sets Mailer to use qmail MTA. Returns void.
* @public
* @returns void
*/
function IsQmail() {
//$this->Sendmail = "/var/qmail/bin/qmail-inject";
$this->Sendmail = "/var/qmail/bin/sendmail";
$this->Mailer = "sendmail";
}
/////////////////////////////////////////////////
// RECIPIENT METHODS
/////////////////////////////////////////////////
/**
* Adds a "to" address. Returns void.
* @public
* @returns void
*/
function AddAddress($address, $name = "") {
$cur = count($this->to);
$this->to[$cur][0] = trim($address);
$this->to[$cur][1] = $name;
}
/**
* Adds a "Cc" address. Returns void.
* @public
* @returns void
*/
function AddCC($address, $name = "") {
$cur = count($this->cc);
$this->cc[$cur][0] = trim($address);
$this->cc[$cur][1] = $name;
}
/**
* Adds a "Bcc" address. Note: this function works
* with the SMTP mailer on win32, not with the "mail"
* mailer. This is a PHP bug that has been submitted
* on the Zend web site. The UNIX version of PHP
* functions correctly.
* Returns void.
* @public
* @returns void
*/
function AddBCC($address, $name = "") {
$cur = count($this->bcc);
$this->bcc[$cur][0] = trim($address);
$this->bcc[$cur][1] = $name;
}
/**
* Adds a "Reply-to" address. Returns void.
* @public
* @returns void
*/
function AddReplyTo($address, $name = "") {
$cur = count($this->ReplyTo);
$this->ReplyTo[$cur][0] = trim($address);
$this->ReplyTo[$cur][1] = $name;
}
/////////////////////////////////////////////////
// MAIL SENDING METHODS
/////////////////////////////////////////////////
/**
* Creates message and assigns Mailer. If the message is
* not sent successfully then it returns false. Returns bool.
* @public
* @returns bool
*/
function Send() {
if(count($this->to) < 1)
{
$this->error_handler("You must provide at least one recipient email address");
return false;
}
$header = $this->create_header();
if(!$body = $this->create_body())
return false;
// Choose the mailer
if($this->Mailer == "sendmail")
{
if(!$this->sendmail_send($header, $body))
return false;
}
elseif($this->Mailer == "mail")
{
if(!$this->mail_send($header, $body))
return false;
}
elseif($this->Mailer == "smtp")
{
if(!$this->smtp_send($header, $body))
return false;
}
else
{
$this->error_handler(sprintf("%s mailer is not supported", $this->Mailer));
return false;
}
return true;
}
/**
* Sends mail using the $Sendmail program. Returns bool.
* @private
* @returns bool
*/
function sendmail_send($header, $body) {
if ($this->Sender != "")
$sendmail = sprintf("%s -f %s -t", $this->Sendmail, $this->Sender);
else
$sendmail = sprintf("%s -t", $this->Sendmail);
if(!@$mail = popen($sendmail, "w"))
{
$this->error_handler(sprintf("Could not execute %s", $this->Sendmail));
return false;
}
fputs($mail, $header);
fputs($mail, $body);
pclose($mail);
return true;
}
/**
* Sends mail using the PHP mail() function. Returns bool.
* @private
* @returns bool
*/
function mail_send($header, $body) {
//$to = substr($this->addr_append("To", $this->to), 4, -2);
// Cannot add Bcc's to the $to
$to = $this->to[0][0]; // no extra comma
for($i = 1; $i < count($this->to); $i++)
$to .= sprintf(",%s", $this->to[$i][0]);
if ($this->Sender != "" && PHP_VERSION >= "4.0")
{
$old_from = ini_get("sendmail_from");
ini_set("sendmail_from", $this->Sender);
}
if ($this->Sender != "" && PHP_VERSION >= "4.0.5")
{
// The fifth parameter to mail is only available in PHP >= 4.0.5
$params = sprintf("-f %s", $this->Sender);
$rt = @mail($to, $this->Subject, $body, $header, $params);
}
else
{
$rt = @mail($to, $this->Subject, $body, $header);
}
if (isset($old_from))
ini_set("sendmail_from", $old_from);
if(!$rt)
{
$this->error_handler("Could not instantiate mail()");
return false;
}
return true;
}
/**
* Sends mail via SMTP using PhpSMTP (Author:
* Chris Ryan). Returns bool.
* @private
* @returns bool
*/
function smtp_send($header, $body) {
// Include SMTP class code, but not twice
//include_once("class.smtp.php"); // Load code only if asked
$smtp = new SMTP;
$smtp->do_debug = $this->SMTPDebug;
// Try to connect to all SMTP servers
$hosts = explode(";", $this->Host);
$index = 0;
$connection = false;
// Retry while there is no connection
while($index < count($hosts) && $connection == false)
{
if($smtp->Connect($hosts[$index], $this->Port, $this->Timeout))
$connection = true;
//printf("%s host could not connect<br>", $hosts[$index]); //debug only
$index++;
}
if(!$connection)
{
$this->error_handler("SMTP Error: could not connect to SMTP host server(s)");
return false;
}
$smtp->Hello($this->Helo);
if ($this->Sender == "")
$smtp->Mail(sprintf("<%s>", $this->From));
else
$smtp->Mail(sprintf("<%s>", $this->Sender));
for($i = 0; $i < count($this->to); $i++)
$smtp->Recipient(sprintf("<%s>", $this->to[$i][0]));
for($i = 0; $i < count($this->cc); $i++)
$smtp->Recipient(sprintf("<%s>", $this->cc[$i][0]));
for($i = 0; $i < count($this->bcc); $i++)
$smtp->Recipient(sprintf("<%s>", $this->bcc[$i][0]));
if(!$smtp->Data(sprintf("%s%s", $header, $body)))
{
$this->error_handler("SMTP Error: Data not accepted");
return false;
}
$smtp->Quit();
return true;
}
/////////////////////////////////////////////////
// MESSAGE CREATION METHODS
/////////////////////////////////////////////////
/**
* Creates recipient headers. Returns string.
* @private
* @returns string
*/
function addr_append($type, $addr) {
$addr_str = "";
$addr_str .= sprintf("%s: %s <%s>", $type, $addr[0][1], $addr[0][0]);
if(count($addr) > 1)
{
for($i = 1; $i < count($addr); $i++)
{
$addr_str .= sprintf(", %s <%s>", $addr[$i][1], $addr[$i][0]);
}
$addr_str .= "\r\n";
}
else
$addr_str .= "\r\n";
return($addr_str);
}
/**
* Wraps message for use with mailers that don't
* automatically perform wrapping and for quoted-printable.
* Original written by philippe. Returns string.
* @private
* @returns string
*/
function wordwrap($message, $length, $qp_mode = false) {
if ($qp_mode)
$soft_break = " =\r\n";
else
$soft_break = "\r\n";
$message = $this->fix_eol($message);
if (substr($message, -1) == "\r\n")
$message = substr($message, 0, -2);
$line = explode("\r\n", $message);
$message = "";
for ($i=0 ;$i < count($line); $i++)
{
$line_part = explode(" ", trim($line[$i]));
$buf = "";
for ($e = 0; $e<count($line_part); $e++)
{
$word = $line_part[$e];
if ($qp_mode and (strlen($word) > $length))
{
$space_left = $length - strlen($buf) - 1;
if ($e != 0)
{
if ($space_left > 20)
{
$len = $space_left;
if (substr($word, $len - 1, 1) == "=")
$len--;
elseif (substr($word, $len - 2, 1) == "=")
$len -= 2;
$part = substr($word, 0, $len);
$word = substr($word, $len);
$buf .= " " . $part;
$message .= $buf . "=\r\n";
}
else
{
$message .= $buf . $soft_break;
}
$buf = "";
}
while (strlen($word) > 0)
{
$len = $length;
if (substr($word, $len - 1, 1) == "=")
$len--;
elseif (substr($word, $len - 2, 1) == "=")
$len -= 2;
$part = substr($word, 0, $len);
$word = substr($word, $len);
if (strlen($word) > 0)
$message .= $part . "=\r\n";
else
$buf = $part;
}
}
else
{
$buf_o = $buf;
if ($e == 0)
$buf .= $word;
else
$buf .= " " . $word;
if (strlen($buf) > $length and $buf_o != "")
{
$message .= $buf_o . $soft_break;
$buf = $word;
}
}
}
$message .= $buf . "\r\n";
}
return ($message);
}
/**
* Assembles message header. Returns a string if successful
* or false if unsuccessful.
* @private
* @returns string
*/
function create_header() {
$header = array();
$header[] = sprintf("Date: %s\r\n", $this->rfc_date());
// To be created automatically by mail()
if($this->Mailer != "mail")
$header[] = $this->addr_append("To", $this->to);
$header[] = sprintf("From: %s <%s>\r\n", $this->FromName, trim($this->From));
if(count($this->cc) > 0)
$header[] = $this->addr_append("Cc", $this->cc);
// sendmail and mail() extract Bcc from the header before sending
if((($this->Mailer == "sendmail") || ($this->Mailer == "mail")) && (count($this->bcc) > 0))
$header[] = $this->addr_append("Bcc", $this->bcc);
if(count($this->ReplyTo) > 0)
$header[] = $this->addr_append("Reply-to", $this->ReplyTo);
// mail() sets the subject itself
if($this->Mailer != "mail")
$header[] = sprintf("Subject: %s\r\n", trim($this->Subject));
$header[] = sprintf("X-Priority: %d\r\n", $this->Priority);
$header[] = sprintf("X-Mailer: %s\r\n", $this->Version);
$header[] = sprintf("Return-Path: %s\r\n", trim($this->From));
// Add custom headers
for($index = 0; $index < count($this->CustomHeader); $index++)
$header[] = sprintf("%s\r\n", $this->CustomHeader[$index]);
if($this->UseMSMailHeaders)
$header[] = $this->AddMSMailHeaders();
// Add all attachments
if(count($this->attachment) > 0)
{
// Set message boundary
$this->boundary = "_b" . md5(uniqid(time()));
$header[] = sprintf("Content-Type: Multipart/Mixed; charset = \"%s\";\r\n", $this->CharSet);
$header[] = sprintf(" boundary=\"Boundary-=%s\"\r\n", $this->boundary);
}
else
{
$header[] = sprintf("Content-Transfer-Encoding: %s\r\n", $this->Encoding);
$header[] = sprintf("Content-Type: %s; charset = \"%s\";\r\n", $this->ContentType, $this->CharSet);
}
$header[] = "MIME-Version: 1.0\r\n";
return(join("", $header));
}
/**
* Assembles the message body. Returns a string if successful
* or false if unsuccessful.
* @private
* @returns string
*/
function create_body() {
// wordwrap the message body if set
if($this->WordWrap)
$this->Body = $this->wordwrap($this->Body, $this->WordWrap);
$this->Body = $this->encode_string($this->Body, $this->Encoding);
if(count($this->attachment) > 0)
{
if(!$body = $this->attach_all())
return false;
}
else
$body = $this->Body;
return($body);
}
/////////////////////////////////////////////////
// ATTACHMENT METHODS
/////////////////////////////////////////////////
/**
* Checks if attachment is valid and then adds
* the attachment to the list.
* Returns false if the file was not found.
* @public
* @returns bool
*/
function AddAttachment($path, $name = "", $encoding = "base64", $type = "application/octet-stream") {
if(!@is_file($path))
{
$this->error_handler(sprintf("Could not find %s file on filesystem", $path));
return false;
}
$filename = basename($path);
if($name == "")
$name = $filename;
// Append to $attachment array
$cur = count($this->attachment);
$this->attachment[$cur][0] = $path;
$this->attachment[$cur][1] = $filename;
$this->attachment[$cur][2] = $name;
$this->attachment[$cur][3] = $encoding;
$this->attachment[$cur][4] = $type;
return true;
}
/**
* Attaches text and binary attachments to body. Returns a
* string if successful or false if unsuccessful.
* @private
* @returns string
*/
function attach_all() {
// Return text of body
$mime = array();
$mime[] = "This is a MIME message. If you are reading this text, you\r\n";
$mime[] = "might want to consider changing to a mail reader that\r\n";
$mime[] = "understands how to properly display MIME multipart messages.\r\n\r\n";
$mime[] = sprintf("--Boundary-=%s\r\n", $this->boundary);
$mime[] = sprintf("Content-Type: %s; charset = \"%s\";\r\n", $this->ContentType, $this->CharSet);
$mime[] = sprintf("Content-Transfer-Encoding: %s\r\n\r\n", $this->Encoding);
$mime[] = sprintf("%s\r\n", $this->Body);
// Add all attachments
for($i = 0; $i < count($this->attachment); $i++)
{
$path = $this->attachment[$i][0];
$filename = $this->attachment[$i][1];
$name = $this->attachment[$i][2];
$encoding = $this->attachment[$i][3];
$type = $this->attachment[$i][4];
$mime[] = sprintf("--Boundary-=%s\r\n", $this->boundary);
$mime[] = sprintf("Content-Type: %s;\r\n", $type);
$mime[] = sprintf("name=\"%s\"\r\n", $name);
$mime[] = sprintf("Content-Transfer-Encoding: %s\r\n", $encoding);
$mime[] = sprintf("Content-Disposition: attachment; filename=\"%s\"\r\n\r\n", $name);
if(!$mime[] = sprintf("%s\r\n\r\n", $this->encode_file($path, $encoding)))
return false;
}
$mime[] = sprintf("\r\n--Boundary-=%s--\r\n", $this->boundary);
return(join("", $mime));
}
/**
* Encodes attachment in requested format. Returns a
* string if successful or false if unsuccessful.
* @private
* @returns string
*/
function encode_file ($path, $encoding = "base64") {
if(!@$fd = fopen($path, "r"))
{
$this->error_handler(sprintf("File Error: Could not open file %s", $path));
return false;
}
$file = fread($fd, filesize($path));
$encoded = $this->encode_string($file, $encoding);
fclose($fd);
return($encoded);
}
/**
* Encodes string to requested format. Returns a
* string if successful or false if unsuccessful.
* @private
* @returns string
*/
function encode_string ($str, $encoding = "base64") {
switch(strtolower($encoding)) {
case "base64":
// chunk_split is found in PHP >= 3.0.6
$encoded = chunk_split(base64_encode($str));
break;
case "7bit":
case "8bit":
$encoded = $this->fix_eol($str);
if (substr($encoded, -2) != "\r\n")
$encoded .= "\r\n";
break;
case "binary":
$encoded = $str;
break;
case "quoted-printable":
$encoded = $this->encode_qp($str);
break;
default:
$this->error_handler(sprintf("Unknown encoding: %s", $encoding));
return false;
}
return($encoded);
}
/**
* Encode string to quoted-printable. Returns a string.
* @private
* @returns string
*/
function encode_qp ($str) {
$encoded = $this->fix_eol($str);
if (substr($encoded, -2) != "\r\n")
$encoded .= "\r\n";
// Replace every high ascii, control and = characters
$encoded = preg_replace("/([\001-\010\013\014\016-\037\075\177-\377])/e", "'='.sprintf('%02X', ord('\\1'))", $encoded);
// Replace every spaces and tabs when it's the last character on a line
$encoded = preg_replace("/([\011\040])\r\n/e", "'='.sprintf('%02X', ord('\\1')).'\r\n'", $encoded);
// Maximum line length of 76 characters before CRLF (74 + space + '=')
$encoded = $this->WordWrap($encoded, 74, true);
return $encoded;
}
/////////////////////////////////////////////////
// MESSAGE RESET METHODS
/////////////////////////////////////////////////
/**
* Clears all recipients assigned in the TO array. Returns void.
* @public
* @returns void
*/
function ClearAddresses() {
$this->to = array();
}
/**
* Clears all recipients assigned in the CC array. Returns void.
* @public
* @returns void
*/
function ClearCCs() {
$this->cc = array();
}
/**
* Clears all recipients assigned in the BCC array. Returns void.
* @public
* @returns void
*/
function ClearBCCs() {
$this->bcc = array();
}
/**
* Clears all recipients assigned in the ReplyTo array. Returns void.
* @public
* @returns void
*/
function ClearReplyTos() {
$this->ReplyTo = array();
}
/**
* Clears all recipients assigned in the TO, CC and BCC
* array. Returns void.
* @public
* @returns void
*/
function ClearAllRecipients() {
$this->to = array();
$this->cc = array();
$this->bcc = array();
}
/**
* Clears all previously set attachments. Returns void.
* @public
* @returns void
*/
function ClearAttachments() {
$this->attachment = array();
}
/**
* Clears all custom headers. Returns void.
* @public
* @returns void
*/
function ClearCustomHeaders() {
$this->CustomHeader = array();
}
/////////////////////////////////////////////////
// MISCELLANEOUS METHODS
/////////////////////////////////////////////////
/**
* Adds the error message to the error container.
* Returns void.
* @private
* @returns void
*/
function error_handler($msg) {
$this->ErrorInfo = $msg;
}
/**
* Returns the proper RFC 822 formatted date. Returns string.
* @private
* @returns string
*/
function rfc_date() {
$tz = date("Z");
$tzs = ($tz < 0) ? "-" : "+";
$tz = abs($tz);
$tz = $tz/36 + $tz % 3600;
$date = sprintf("%s %s%04d", date("D, j M Y H:i:s"), $tzs, $tz);
return $date;
}
/**
* Changes every end of line from CR or LF to CRLF. Returns string.
* @private
* @returns string
*/
function fix_eol($str) {
$str = str_replace("\r\n", "\n", $str);
$str = str_replace("\r", "\n", $str);
$str = str_replace("\n", "\r\n", $str);
return $str;
}
/**
* Adds a custom header. Returns void.
* @public
* @returns void
*/
function AddCustomHeader($custom_header) {
$this->CustomHeader[] = $custom_header;
}
/**
* Adds all the Microsoft message headers. Returns string.
* @private
* @returns string
*/
function AddMSMailHeaders() {
$MSHeader = "";
if($this->Priority == 1)
$MSPriority = "High";
elseif($this->Priority == 5)
$MSPriority = "Low";
else
$MSPriority = "Medium";
$MSHeader .= sprintf("X-MSMail-Priority: %s\r\n", $MSPriority);
$MSHeader .= sprintf("Importance: %s\r\n", $MSPriority);
return($MSHeader);
}
}
// End of class
?>
+939
View File
@@ -0,0 +1,939 @@
<?php
/*
* File: smtp.php
*
* Description: Define an SMTP class that can be used to connect
* and communicate with any SMTP server. It implements
* all the SMTP functions defined in RFC821 except TURN.
*
* Creator: Chris Ryan <[email protected]>
* Created: 03/26/2001
*
* TODO:
* - Move all the duplicate code to a utility function
* Most of the functions have the first lines of
* code do the same processing. If this can be moved
* into a utility function then it would reduce the
* overall size of the code significantly.
*/
/*
* STMP is rfc 821 compliant and implements all the rfc 821 SMTP
* commands except TURN which will always return a not implemented
* error. SMTP also provides some utility methods for sending mail
* to an SMTP server.
*/
class SMTP {
var $SMTP_PORT = 25; # the default SMTP PORT
var $CRLF = "\r\n"; # CRLF pair
var $smtp_conn; # the socket to the server
var $error; # error if any on the last call
var $helo_rply; # the reply the server sent to us for HELO
var $do_debug; # the level of debug to perform
/*
* SMTP()
*
* Initialize the class so that the data is in a known state.
*/
function SMTP() {
$this->smtp_conn = 0;
$this->error = null;
$this->helo_rply = null;
$this->do_debug = 0;
}
/************************************************************
* CONNECTION FUNCTIONS *
***********************************************************/
/*
* Connect($host, $port=0, $tval=30)
*
* Connect to the server specified on the port specified.
* If the port is not specified use the default SMTP_PORT.
* If tval is specified then a connection will try and be
* established with the server for that number of seconds.
* If tval is not specified the default is 30 seconds to
* try on the connection.
*
* SMTP CODE SUCCESS: 220
* SMTP CODE FAILURE: 421
*/
function Connect($host,$port=0,$tval=30) {
# set the error val to null so there is no confusion
$this->error = null;
# make sure we are __not__ connected
if($this->connected()) {
# ok we are connected! what should we do?
# for now we will just give an error saying we
# are already connected
$this->error =
array("error" => "Already connected to a server");
return false;
}
if(empty($port)) {
$port = $this->SMTP_PORT;
}
#connect to the smtp server
$this->smtp_conn = fsockopen($host, # the host of the server
$port, # the port to use
$errno, # error number if any
$errstr, # error message if any
$tval); # give up after ? secs
# verify we connected properly
if(empty($this->smtp_conn)) {
$this->error = array("error" => "Failed to connect to server",
"errno" => $errno,
"errstr" => $errstr);
if($this->do_debug >= 1) {
echo "SMTP -> ERROR: " . $this->error["error"] .
": $errstr ($errno)" . $this->CRLF;
}
return false;
}
# sometimes the SMTP server takes a little longer to respond
# so we will give it a longer timeout for the first read
//if(function_exists("socket_set_timeout"))
// socket_set_timeout($this->smtp_conn, 1, 0);
# get any announcement stuff
$announce = $this->get_lines();
# set the timeout of any socket functions at 1/10 of a second
//if(function_exists("socket_set_timeout"))
// socket_set_timeout($this->smtp_conn, 0, 100000);
if($this->do_debug >= 2) {
echo "SMTP -> FROM SERVER:" . $this->CRLF . $announce;
}
return true;
}
/*
* Connected()
*
* Returns true if connected to a server otherwise false
*/
function Connected() {
if(!empty($this->smtp_conn)) {
$sock_status = socket_get_status($this->smtp_conn);
if($sock_status["eof"]) {
# hmm this is an odd situation... the socket is
# valid but we aren't connected anymore
if($this->do_debug >= 1) {
echo "SMTP -> NOTICE:" . $this->CRLF .
"EOF caught while checking if connected";
}
$this->Close();
return false;
}
return true; # everything looks good
}
return false;
}
/*
* Close()
*
* Closes the socket and cleans up the state of the class.
* It is not considered good to use this function without
* first trying to use QUIT.
*/
function Close() {
$this->error = null; # so there is no confusion
$this->helo_rply = null;
if(!empty($this->smtp_conn)) {
# close the connection and cleanup
fclose($this->smtp_conn);
$this->smtp_conn = 0;
}
}
/**************************************************************
* SMTP COMMANDS *
*************************************************************/
/*
* Data($msg_data)
*
* Issues a data command and sends the msg_data to the server
* finializing the mail transaction. $msg_data is the message
* that is to be send with the headers. Each header needs to be
* on a single line followed by a <CRLF> with the message headers
* and the message body being seperated by and additional <CRLF>.
*
* Implements rfc 821: DATA <CRLF>
*
* SMTP CODE INTERMEDIATE: 354
* [data]
* <CRLF>.<CRLF>
* SMTP CODE SUCCESS: 250
* SMTP CODE FAILURE: 552,554,451,452
* SMTP CODE FAILURE: 451,554
* SMTP CODE ERROR : 500,501,503,421
*/
function Data($msg_data) {
$this->error = null; # so no confusion is caused
if(!$this->connected()) {
$this->error = array(
"error" => "Called Data() without being connected");
return false;
}
fputs($this->smtp_conn,"DATA" . $this->CRLF);
$rply = $this->get_lines();
$code = substr($rply,0,3);
if($this->do_debug >= 2) {
echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply;
}
if($code != 354) {
$this->error =
array("error" => "DATA command not accepted from server",
"smtp_code" => $code,
"smtp_msg" => substr($rply,4));
if($this->do_debug >= 1) {
echo "SMTP -> ERROR: " . $this->error["error"] .
": " . $rply . $this->CRLF;
}
return false;
}
# the server is ready to accept data!
# according to rfc 821 we should not send more than 1000
# including the CRLF
# characters on a single line so we will break the data up
# into lines by \r and/or \n then if needed we will break
# each of those into smaller lines to fit within the limit.
# in addition we will be looking for lines that start with
# a period '.' and append and additional period '.' to that
# line. NOTE: this does not count towards are limit.
# normalize the line breaks so we know the explode works
$msg_data = str_replace("\r\n","\n",$msg_data);
$msg_data = str_replace("\r","\n",$msg_data);
$lines = explode("\n",$msg_data);
# we need to find a good way to determine is headers are
# in the msg_data or if it is a straight msg body
# currently I'm assuming rfc 822 definitions of msg headers
# and if the first field of the first line (':' sperated)
# does not contain a space then it _should_ be a header
# and we can process all lines before a blank "" line as
# headers.
$field = substr($lines[0],0,strpos($lines[0],":"));
$in_headers = false;
if(!empty($field) && !strstr($field," ")) {
$in_headers = true;
}
$max_line_length = 998; # used below; set here for ease in change
while(list(,$line) = @each($lines)) {
$lines_out = null;
if($line == "" && $in_headers) {
$in_headers = false;
}
# ok we need to break this line up into several
# smaller lines
while(strlen($line) > $max_line_length) {
$pos = strrpos(substr($line,0,$max_line_length)," ");
$lines_out[] = substr($line,0,$pos);
$line = substr($line,$pos + 1);
# if we are processing headers we need to
# add a LWSP-char to the front of the new line
# rfc 822 on long msg headers
if($in_headers) {
$line = "\t" . $line;
}
}
$lines_out[] = $line;
# now send the lines to the server
while(list(,$line_out) = @each($lines_out)) {
if($line_out[0] == ".") {
$line_out = "." . $line_out;
}
fputs($this->smtp_conn,$line_out . $this->CRLF);
}
}
# ok all the message data has been sent so lets get this
# over with aleady
fputs($this->smtp_conn, $this->CRLF . "." . $this->CRLF);
$rply = $this->get_lines();
$code = substr($rply,0,3);
if($this->do_debug >= 2) {
echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply;
}
if($code != 250) {
$this->error =
array("error" => "DATA not accepted from server",
"smtp_code" => $code,
"smtp_msg" => substr($rply,4));
if($this->do_debug >= 1) {
echo "SMTP -> ERROR: " . $this->error["error"] .
": " . $rply . $this->CRLF;
}
return false;
}
return true;
}
/*
* Expand($name)
*
* Expand takes the name and asks the server to list all the
* people who are members of the _list_. Expand will return
* back and array of the result or false if an error occurs.
* Each value in the array returned has the format of:
* [ <full-name> <sp> ] <path>
* The definition of <path> is defined in rfc 821
*
* Implements rfc 821: EXPN <SP> <string> <CRLF>
*
* SMTP CODE SUCCESS: 250
* SMTP CODE FAILURE: 550
* SMTP CODE ERROR : 500,501,502,504,421
*/
function Expand($name) {
$this->error = null; # so no confusion is caused
if(!$this->connected()) {
$this->error = array(
"error" => "Called Expand() without being connected");
return false;
}
fputs($this->smtp_conn,"EXPN " . $name . $this->CRLF);
$rply = $this->get_lines();
$code = substr($rply,0,3);
if($this->do_debug >= 2) {
echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply;
}
if($code != 250) {
$this->error =
array("error" => "EXPN not accepted from server",
"smtp_code" => $code,
"smtp_msg" => substr($rply,4));
if($this->do_debug >= 1) {
echo "SMTP -> ERROR: " . $this->error["error"] .
": " . $rply . $this->CRLF;
}
return false;
}
# parse the reply and place in our array to return to user
$entries = explode($this->CRLF,$rply);
while(list(,$l) = @each($entries)) {
$list[] = substr($l,4);
}
return $rval;
}
/*
* Hello($host="")
*
* Sends the HELO command to the smtp server.
* This makes sure that we and the server are in
* the same known state.
*
* Implements from rfc 821: HELO <SP> <domain> <CRLF>
*
* SMTP CODE SUCCESS: 250
* SMTP CODE ERROR : 500, 501, 504, 421
*/
function Hello($host="") {
$this->error = null; # so no confusion is caused
if(!$this->connected()) {
$this->error = array(
"error" => "Called Hello() without being connected");
return false;
}
# if a hostname for the HELO wasn't specified determine
# a suitable one to send
if(empty($host)) {
# we need to determine some sort of appopiate default
# to send to the server
$host = "localhost";
}
fputs($this->smtp_conn,"HELO " . $host . $this->CRLF);
$rply = $this->get_lines();
$code = substr($rply,0,3);
if($this->do_debug >= 2) {
echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply;
}
if($code != 250) {
$this->error =
array("error" => "HELO not accepted from server",
"smtp_code" => $code,
"smtp_msg" => substr($rply,4));
if($this->do_debug >= 1) {
echo "SMTP -> ERROR: " . $this->error["error"] .
": " . $rply . $this->CRLF;
}
return false;
}
$this->helo_rply = $rply;
return true;
}
/*
* Help($keyword="")
*
* Gets help information on the keyword specified. If the keyword
* is not specified then returns generic help, ussually contianing
* A list of keywords that help is available on. This function
* returns the results back to the user. It is up to the user to
* handle the returned data. If an error occurs then false is
* returned with $this->error set appropiately.
*
* Implements rfc 821: HELP [ <SP> <string> ] <CRLF>
*
* SMTP CODE SUCCESS: 211,214
* SMTP CODE ERROR : 500,501,502,504,421
*
function Help($keyword="") {
$this->error = null; # to avoid confusion
if(!$this->connected()) {
$this->error = array(
"error" => "Called Help() without being connected");
return false;
}
$extra = "";
if(!empty($keyword)) {
$extra = " " . $keyword;
}
fputs($this->smtp_conn,"HELP" . $extra . $this->CRLF);
$rply = $this->get_lines();
$code = substr($rply,0,3);
if($this->do_debug >= 2) {
echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply;
}
if($code != 211 && $code != 214) {
$this->error =
array("error" => "HELP not accepted from server",
"smtp_code" => $code,
"smtp_msg" => substr($rply,4));
if($this->do_debug >= 1) {
echo "SMTP -> ERROR: " . $this->error["error"] .
": " . $rply . $this->CRLF;
}
return false;
}
return $rply;
}
/*
* Mail($from)
*
* Starts a mail transaction from the email address specified in
* $from. Returns true if successful or false otherwise. If True
* the mail transaction is started and then one or more Recipient
* commands may be called followed by a Data command.
*
* Implements rfc 821: MAIL <SP> FROM:<reverse-path> <CRLF>
*
* SMTP CODE SUCCESS: 250
* SMTP CODE SUCCESS: 552,451,452
* SMTP CODE SUCCESS: 500,501,421
*/
function Mail($from) {
$this->error = null; # so no confusion is caused
if(!$this->connected()) {
$this->error = array(
"error" => "Called Mail() without being connected");
return false;
}
fputs($this->smtp_conn,"MAIL FROM:" . $from . $this->CRLF);
$rply = $this->get_lines();
$code = substr($rply,0,3);
if($this->do_debug >= 2) {
echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply;
}
if($code != 250) {
$this->error =
array("error" => "MAIL not accepted from server",
"smtp_code" => $code,
"smtp_msg" => substr($rply,4));
if($this->do_debug >= 1) {
echo "SMTP -> ERROR: " . $this->error["error"] .
": " . $rply . $this->CRLF;
}
return false;
}
return true;
}
/*
* Noop()
*
* Sends the command NOOP to the SMTP server.
*
* Implements from rfc 821: NOOP <CRLF>
*
* SMTP CODE SUCCESS: 250
* SMTP CODE ERROR : 500, 421
*/
function Noop() {
$this->error = null; # so no confusion is caused
if(!$this->connected()) {
$this->error = array(
"error" => "Called Noop() without being connected");
return false;
}
fputs($this->smtp_conn,"NOOP" . $this->CRLF);
$rply = $this->get_lines();
$code = substr($rply,0,3);
if($this->do_debug >= 2) {
echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply;
}
if($code != 250) {
$this->error =
array("error" => "NOOP not accepted from server",
"smtp_code" => $code,
"smtp_msg" => substr($rply,4));
if($this->do_debug >= 1) {
echo "SMTP -> ERROR: " . $this->error["error"] .
": " . $rply . $this->CRLF;
}
return false;
}
return true;
}
/*
* Quit($close_on_error=true)
*
* Sends the quit command to the server and then closes the socket
* if there is no error or the $close_on_error argument is true.
*
* Implements from rfc 821: QUIT <CRLF>
*
* SMTP CODE SUCCESS: 221
* SMTP CODE ERROR : 500
*/
function Quit($close_on_error=true) {
$this->error = null; # so there is no confusion
if(!$this->connected()) {
$this->error = array(
"error" => "Called Quit() without being connected");
return false;
}
# send the quit command to the server
fputs($this->smtp_conn,"quit" . $this->CRLF);
# get any good-bye messages
$byemsg = $this->get_lines();
if($this->do_debug >= 2) {
echo "SMTP -> FROM SERVER:" . $this->CRLF . $byemsg;
}
$rval = true;
$e = null;
$code = substr($byemsg,0,3);
if($code != 221) {
# use e as a tmp var cause Close will overwrite $this->error
$e = array("error" => "SMTP server rejected quit command",
"smtp_code" => $code,
"smtp_rply" => substr($byemsg,4));
$rval = false;
if($this->do_debug >= 1) {
echo "SMTP -> ERROR: " . $e["error"] . ": " .
$byemsg . $this->CRLF;
}
}
if(empty($e) || $close_on_error) {
$this->Close();
}
return $rval;
}
/*
* Recipient($to)
*
* Sends the command RCPT to the SMTP server with the TO: argument of $to.
* Returns true if the recipient was accepted false if it was rejected.
*
* Implements from rfc 821: RCPT <SP> TO:<forward-path> <CRLF>
*
* SMTP CODE SUCCESS: 250,251
* SMTP CODE FAILURE: 550,551,552,553,450,451,452
* SMTP CODE ERROR : 500,501,503,421
*/
function Recipient($to) {
$this->error = null; # so no confusion is caused
if(!$this->connected()) {
$this->error = array(
"error" => "Called Recipient() without being connected");
return false;
}
fputs($this->smtp_conn,"RCPT TO:" . $to . $this->CRLF);
$rply = $this->get_lines();
$code = substr($rply,0,3);
if($this->do_debug >= 2) {
echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply;
}
if($code != 250 && $code != 251) {
$this->error =
array("error" => "RCPT not accepted from server",
"smtp_code" => $code,
"smtp_msg" => substr($rply,4));
if($this->do_debug >= 1) {
echo "SMTP -> ERROR: " . $this->error["error"] .
": " . $rply . $this->CRLF;
}
return false;
}
return true;
}
/*
* Reset()
*
* Sends the RSET command to abort and transaction that is
* currently in progress. Returns true if successful false
* otherwise.
*
* Implements rfc 821: RSET <CRLF>
*
* SMTP CODE SUCCESS: 250
* SMTP CODE ERROR : 500,501,504,421
*/
function Reset() {
$this->error = null; # so no confusion is caused
if(!$this->connected()) {
$this->error = array(
"error" => "Called Reset() without being connected");
return false;
}
fputs($this->smtp_conn,"RSET" . $this->CRLF);
$rply = $this->get_lines();
$code = substr($rply,0,3);
if($this->do_debug >= 2) {
echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply;
}
if($code != 250) {
$this->error =
array("error" => "RSET failed",
"smtp_code" => $code,
"smtp_msg" => substr($rply,4));
if($this->do_debug >= 1) {
echo "SMTP -> ERROR: " . $this->error["error"] .
": " . $rply . $this->CRLF;
}
return false;
}
return true;
}
/*
* Send($from)
*
* Starts a mail transaction from the email address specified in
* $from. Returns true if successful or false otherwise. If True
* the mail transaction is started and then one or more Recipient
* commands may be called followed by a Data command. This command
* will send the message to the users terminal if they are logged
* in.
*
* Implements rfc 821: SEND <SP> FROM:<reverse-path> <CRLF>
*
* SMTP CODE SUCCESS: 250
* SMTP CODE SUCCESS: 552,451,452
* SMTP CODE SUCCESS: 500,501,502,421
*/
function Send($from) {
$this->error = null; # so no confusion is caused
if(!$this->connected()) {
$this->error = array(
"error" => "Called Send() without being connected");
return false;
}
fputs($this->smtp_conn,"SEND FROM:" . $from . $this->CRLF);
$rply = $this->get_lines();
$code = substr($rply,0,3);
if($this->do_debug >= 2) {
echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply;
}
if($code != 250) {
$this->error =
array("error" => "SEND not accepted from server",
"smtp_code" => $code,
"smtp_msg" => substr($rply,4));
if($this->do_debug >= 1) {
echo "SMTP -> ERROR: " . $this->error["error"] .
": " . $rply . $this->CRLF;
}
return false;
}
return true;
}
/*
* SendAndMail($from)
*
* Starts a mail transaction from the email address specified in
* $from. Returns true if successful or false otherwise. If True
* the mail transaction is started and then one or more Recipient
* commands may be called followed by a Data command. This command
* will send the message to the users terminal if they are logged
* in and send them an email.
*
* Implements rfc 821: SAML <SP> FROM:<reverse-path> <CRLF>
*
* SMTP CODE SUCCESS: 250
* SMTP CODE SUCCESS: 552,451,452
* SMTP CODE SUCCESS: 500,501,502,421
*/
function SendAndMail($from) {
$this->error = null; # so no confusion is caused
if(!$this->connected()) {
$this->error = array(
"error" => "Called SendAndMail() without being connected");
return false;
}
fputs($this->smtp_conn,"SAML FROM:" . $from . $this->CRLF);
$rply = $this->get_lines();
$code = substr($rply,0,3);
if($this->do_debug >= 2) {
echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply;
}
if($code != 250) {
$this->error =
array("error" => "SAML not accepted from server",
"smtp_code" => $code,
"smtp_msg" => substr($rply,4));
if($this->do_debug >= 1) {
echo "SMTP -> ERROR: " . $this->error["error"] .
": " . $rply . $this->CRLF;
}
return false;
}
return true;
}
/*
* SendOrMail($from)
*
* Starts a mail transaction from the email address specified in
* $from. Returns true if successful or false otherwise. If True
* the mail transaction is started and then one or more Recipient
* commands may be called followed by a Data command. This command
* will send the message to the users terminal if they are logged
* in or mail it to them if they are not.
*
* Implements rfc 821: SOML <SP> FROM:<reverse-path> <CRLF>
*
* SMTP CODE SUCCESS: 250
* SMTP CODE SUCCESS: 552,451,452
* SMTP CODE SUCCESS: 500,501,502,421
*/
function SendOrMail($from) {
$this->error = null; # so no confusion is caused
if(!$this->connected()) {
$this->error = array(
"error" => "Called SendOrMail() without being connected");
return false;
}
fputs($this->smtp_conn,"SOML FROM:" . $from . $this->CRLF);
$rply = $this->get_lines();
$code = substr($rply,0,3);
if($this->do_debug >= 2) {
echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply;
}
if($code != 250) {
$this->error =
array("error" => "SOML not accepted from server",
"smtp_code" => $code,
"smtp_msg" => substr($rply,4));
if($this->do_debug >= 1) {
echo "SMTP -> ERROR: " . $this->error["error"] .
": " . $rply . $this->CRLF;
}
return false;
}
return true;
}
/*
* Turn()
*
* This is an optional command for SMTP that this class does not
* support. This method is here to make the RFC821 Definition
* complete for this class and __may__ be implimented in the future
*
* Implements from rfc 821: TURN <CRLF>
*
* SMTP CODE SUCCESS: 250
* SMTP CODE FAILURE: 502
* SMTP CODE ERROR : 500, 503
*/
function Turn() {
$this->error = array("error" => "This method, TURN, of the SMTP ".
"is not implemented");
if($this->do_debug >= 1) {
echo "SMTP -> NOTICE: " . $this->error["error"] . $this->CRLF;
}
return false;
}
/*
* Verify($name)
*
* Verifies that the name is recognized by the server.
* Returns false if the name could not be verified otherwise
* the response from the server is returned.
*
* Implements rfc 821: VRFY <SP> <string> <CRLF>
*
* SMTP CODE SUCCESS: 250,251
* SMTP CODE FAILURE: 550,551,553
* SMTP CODE ERROR : 500,501,502,421
*/
function Verify($name) {
$this->error = null; # so no confusion is caused
if(!$this->connected()) {
$this->error = array(
"error" => "Called Verify() without being connected");
return false;
}
fputs($this->smtp_conn,"VRFY " . $name . $this->CRLF);
$rply = $this->get_lines();
$code = substr($rply,0,3);
if($this->do_debug >= 2) {
echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply;
}
if($code != 250 && $code != 251) {
$this->error =
array("error" => "VRFY failed on name '$name'",
"smtp_code" => $code,
"smtp_msg" => substr($rply,4));
if($this->do_debug >= 1) {
echo "SMTP -> ERROR: " . $this->error["error"] .
": " . $rply . $this->CRLF;
}
return false;
}
return $rply;
}
/******************************************************************
* INTERNAL FUNCTIONS *
******************************************************************/
/*
* get_lines()
*
* __internal_use_only__: read in as many lines as possible
* either before eof or socket timeout occurs on the operation.
* With SMTP we can tell if we have more lines to read if the
* 4th character is '-' symbol. If it is a space then we don't
* need to read anything else.
*/
function get_lines() {
$data = "";
while($str = fgets($this->smtp_conn,515)) {
if($this->do_debug >= 4) {
echo "SMTP -> get_lines(): \$data was \"$data\"" .
$this->CRLF;
echo "SMTP -> get_lines(): \$str is \"$str\"" .
$this->CRLF;
}
$data .= $str;
if($this->do_debug >= 4) {
echo "SMTP -> get_lines(): \$data is \"$data\"" . $this->CRLF;
}
# if the 4th character is a space then we are done reading
# so just break the loop
if(substr($str,3,1) == " ") { break; }
}
return $data;
}
}
?>
BIN
View File
Binary file not shown.
BIN
View File
Binary file not shown.
+1704
View File
File diff suppressed because it is too large Load Diff
+19
View File
@@ -0,0 +1,19 @@
<SCRIPT LANGUAGE="JavaScript">
<!-- //hide
function fillmessagebox(text) {
document.form.message.value = text;
}
function openpopup(url,name,height,width) {
fullurl = "<?=$CFG->wwwroot ?>" + url;
options = "menubar=0,location=0,scrollbars,resizable,width="+width+",height="+height;
windowobj = window.open(fullurl,"name", options);
windowobj.focus();
}
<? if ($focus) { echo "function setfocus() { document.$focus.focus() }\n"; } ?>
// done hiding -->
</SCRIPT>
+1163
View File
File diff suppressed because it is too large Load Diff
+204
View File
@@ -0,0 +1,204 @@
<?php // $Id$
/****************************************************************
* Script : PHP Simple Excel File Generator - Base Class
* Project : PHP SimpleXlsGen
* Author : Erol Ozcan <[email protected]>
* Version : 0.3
* Copyright : GNU LGPL
* URL : http://psxlsgen.sourceforge.net
* Last modified : 13 Jun 2001
* Description : This class is used to generate very simple
* MS Excel file (xls) via PHP.
* The generated xls file can be obtained by web as a stream
* file or can be written under $default_dir path. This package
* is also included mysql, pgsql, oci8 database interaction to
* generate xls files.
* Limitations:
* - Max character size of a text(label) cell is 255
* ( due to MS Excel 5.0 Binary File Format definition )
*
* Credits : This class is based on Christian Novak's small
* Excel library functions.
******************************************************************/
if( !defined( "PHP_SIMPLE_XLS_GEN" ) ) {
define( "PHP_SIMPLE_XLS_GEN", 1 );
class PhpSimpleXlsGen {
var $class_ver = "0.3"; // class version
var $xls_data = ""; // where generated xls be stored
var $default_dir = ""; // default directory to be saved file
var $filename = "psxlsgen"; // save filename
var $fname = ""; // filename with full path
var $crow = 0; // current row number
var $ccol = 0; // current column number
var $totalcol = 0; // total number of columns
var $get_type = 0; // 0=stream, 1=file
var $errno = 0; // 0=no error
var $error = ""; // error string
var $dirsep = "/"; // directory separator
var $header = 1; // 0=no header, 1=header line for xls table
// Default constructor
function PhpSimpleXlsGen()
{
$os = getenv( "OS" );
$temp = getenv( "TEMP");
// check OS and set proper values for some vars.
if ( stristr( $os, "Windows" ) ) {
$this->default_dir = $temp;
$this->dirsep = "\\";
} else {
// assume that is Unix/Linux
$this->default_dir = "/tmp";
$this->dirsep = "/";
}
// begin of the excel file header
$this->xls_data = pack( "ssssss", 0x809, 0x08, 0x00,0x10, 0x0, 0x0 );
// check header text
if ( $this->header ) {
$this->Header();
}
}
function Header( $text="" ) {
if ( $text == "" ) {
$text = "This file was generated using PSXlsGen at ".date("D, d M Y H:i:s T");
}
if ( $this->totalcol < 1 ) {
$this->totalcol = 1;
}
$this->InsertText( $text );
$this->crow += 2;
$this->ccol = 0;
}
// end of the excel file
function End()
{
$this->xls_data .= pack("sssssssC", 0x7D, 11, 3, 4, 25600,0,0,0);
$this->xls_data .= pack( "ss", 0x0A, 0x00 );
return;
}
// write a Number (double) into row, col
function WriteNumber_pos( $row, $col, $value )
{
$this->xls_data .= pack( "sssss", 0x0203, 14, $row, $col, 0x00 );
$this->xls_data .= pack( "d", $value );
return;
}
// write a label (text) into Row, Col
function WriteText_pos( $row, $col, $value )
{
$len = strlen( $value );
$this->xls_data .= pack( "s*", 0x0204, 8 + $len, $row, $col, 0x00, $len );
$this->xls_data .= $value;
return;
}
// insert a number, increment row,col automatically
function InsertNumber( $value )
{
if ( $this->ccol == $this->totalcol ) {
$this->ccol = 0;
$this->crow++;
}
$this->WriteNumber_pos( $this->crow, $this->ccol, &$value );
$this->ccol++;
return;
}
// insert text, increment row,col automatically
function InsertText( $value )
{
if ( $this->ccol == $this->totalcol ) {
$this->ccol = 0;
$this->crow++;
}
$this->WriteText_pos( $this->crow, $this->ccol, &$value );
$this->ccol++;
return;
}
// Change position of row,col
function ChangePos( $newrow, $newcol )
{
$this->crow = $newrow;
$this->ccol = $newcol;
return;
}
// new line
function NewLine()
{
$this->ccol = 0;
$this->crow++;
return;
}
// send generated xls as stream file
function SendFile( $filename )
{
$this->filename = $filename;
$this->SendFile();
}
// send generated xls as stream file
function SendFile()
{
global $HTTP_USER_AGENT;
$this->End();
header ( "Expires: Mon, 1 Apr 1974 05:00:00 GMT" );
header ( "Last-Modified: " . gmdate("D,d M YH:i:s") . " GMT" );
header ( "Pragma: no-cache" );
if (!strstr($HTTP_USER_AGENT,"MSIE")) {
$attachment=" attachment;";
}
header("Content-Type: application/x-msexcel\r\n");
header("Content-Disposition:$attachment filename=$this->filename.xls\r\n\r\n");
header("Content-Transfer-Encoding: binary\r\n");
header("Content-Description: Excel Spreadsheet" );
print $this->xls_data;
}
// change the default saving directory
function ChangeDefaultDir( $newdir )
{
$this->default_dir = $newdir;
return;
}
// Save generated xls file
function SaveFile( $filename )
{
$this->filename = $filename;
$this->SaveFile();
}
// Save generated xls file
function SaveFile()
{
$this->End();
$this->fname = $this->default_dir."$this->dirsep".$this->filename;
if ( !stristr( $this->fname, ".xls" ) ) {
$this->fname .= ".xls";
}
$fp = fopen( $this->fname, "wb" );
fwrite( $fp, $this->xls_data );
fclose( $fp );
return;
}
// Get generated xls as specified type
function GetXls( $type = 0 ) {
if ( !$type && !$this->get_type ) {
$this->SendFile();
} else {
$this->SaveFile();
}
}
} // end of the class PHP_SIMPLE_XLS_GEN
}
// end of ifdef PHP_SIMPLE_XLS_GEN
+66
View File
@@ -0,0 +1,66 @@
<?PHP // $Id$
//
// setup.php
//
// Sets up sessions, connects to databases and so on
//
// Normally this is only called by the main config.php file
//
// Normally this file does not need to be edited.
//
// XXX this might need some rationalisation
//
//////////////////////////////////////////////////////////////
// Error reporting and bug hunting
error_reporting(7); // use 0=none 7=normal 15=all
// Default editing time for discussions and the like (in seconds)
$CFG->maxeditingtime = 1800;
// Location of standard files
$CFG->templatedir = "$CFG->dirroot/templates";
$CFG->imagedir = "$CFG->wwwroot/images";
$CFG->wordlist = "$CFG->libdir/wordlist.txt";
$CFG->javascript = "$CFG->libdir/javascript.php";
$CFG->stylesheet = "$CFG->wwwroot/theme/$CFG->theme/styles.css";
$CFG->header = "$CFG->dirroot/theme/$CFG->theme/header.html";
$CFG->footer = "$CFG->dirroot/theme/$CFG->theme/footer.html";
// Load up theme variables (colours etc)
require("$CFG->dirroot/theme/$CFG->theme/config.php");
// Load up standard libraries
require("$CFG->libdir/weblib.php"); // Standard web page functions
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;
$FULLME = qualified_me();
$ME = strip_querystring($FULLME);
// Connect to the database using adodb
ADOLoadCode($CFG->dbtype);
$db = &ADONewConnection();
$db->PConnect($CFG->dbhost,$CFG->dbuser,$CFG->dbpass,$CFG->dbname);
?>
+291
View File
@@ -0,0 +1,291 @@
<?PHP // $Id$
// weblib.php
//
// Library of useful PHP functions related to web pages.
//
//
function nvl(&$var, $default="") {
// if $var is undefined, return $default, otherwise return $var
return isset($var) ? $var : $default;
}
function ov(&$var) {
// returns $var with the HTML characters (like "<", ">", etc.) properly quoted,
// or if $var is undefined, will return an empty string. note this function
// must be called with a variable, for normal strings or functions use o()
return isset($var) ? htmlSpecialChars(stripslashes($var)) : "";
}
function pv(&$var) {
// prints $var with the HTML characters (like "<", ">", etc.) properly quoted,
// or if $var is undefined, will print an empty string. note this function
// must be called with a variable, for normal strings or functions use p()
echo isset($var) ? htmlSpecialChars(stripslashes($var)) : "";
}
function o($var) {
// returns $var with HTML characters (like "<", ">", etc.) properly quoted,
// or if $var is empty, will return an empty string.
return empty($var) ? "" : htmlSpecialChars(stripslashes($var));
}
function p($var) {
// prints $var with HTML characters (like "<", ">", etc.) properly quoted,
// or if $var is empty, will print an empty string.
echo empty($var) ? "" : htmlSpecialChars(stripslashes($var));
}
function strip_querystring($url) {
// takes a URL and returns it without the querystring portion
if ($commapos = strpos($url, '?')) {
return substr($url, 0, $commapos);
} else {
return $url;
}
}
function get_referer() {
// returns the URL of the HTTP_REFERER, less the querystring portion
$HTTP_REFERER = getenv("HTTP_REFERER");
return strip_querystring(nvl($HTTP_REFERER));
}
function me() {
// returns the name of the current script, WITH the querystring portion.
// this function is necessary because PHP_SELF and REQUEST_URI and PATH_INFO
// return different things depending on a lot of things like your OS, Web
// server, and the way PHP is compiled (ie. as a CGI, module, ISAPI, etc.)
if (getenv("REQUEST_URI")) {
$me = getenv("REQUEST_URI");
} elseif (getenv("PATH_INFO")) {
$me = getenv("PATH_INFO");
} elseif ($GLOBALS["PHP_SELF"]) {
$me = $GLOBALS["PHP_SELF"];
}
return $me;
}
function qualified_me() {
// like me() but returns a full URL
$HTTPS = getenv("HTTPS");
$SERVER_PROTOCOL = getenv("SERVER_PROTOCOL");
$HTTP_HOST = getenv("HTTP_HOST");
$protocol = (isset($HTTPS) && $HTTPS == "on") ? "https://" : "http://";
$url_prefix = "$protocol$HTTP_HOST";
return $url_prefix . me();
}
function match_referer($good_referer = "") {
// returns true if the referer is the same as the good_referer. If
// good_refer is not specified, use qualified_me as the good_referer
if ($good_referer == "") { $good_referer = qualified_me(); }
return $good_referer == get_referer();
}
function read_template($filename, &$var) {
// return a (big) string containing the contents of a template file with all
// the variables interpolated. all the variables must be in the $var[] array or
// object (whatever you decide to use).
//
// WARNING: do not use this on big files!!
$temp = str_replace("\\", "\\\\", implode(file($filename), ""));
$temp = str_replace('"', '\"', $temp);
eval("\$template = \"$temp\";");
return $template;
}
function checked(&$var, $set_value = 1, $unset_value = 0) {
// if variable is set, set it to the set_value otherwise set it to the
// unset_value. used to handle checkboxes when you are expecting them from
// a form
if (empty($var)) {
$var = $unset_value;
} else {
$var = $set_value;
}
}
function frmchecked(&$var, $true_value = "checked", $false_value = "") {
// prints the word "checked" if a variable is true, otherwise prints nothing,
// used for printing the word "checked" in a checkbox form input
if ($var) {
echo $true_value;
} else {
echo $false_value;
}
}
function link_to_popup_window ($url, $name="popup", $linkname="click here", $height=400, $width=500) {
// This will create a HTML link that will work on both
// Javascript and non-javascript browsers.
// Relies on the Javascript function openpopup in javascript.php
// $url must be relative to home page eg /mod/survey/stuff.php
echo "\n<SCRIPT language=\"Javascript\">";
echo "\n<!--";
echo "\ndocument.write('<A HREF=javascript:openpopup(\"$url\",\"$name\",\"$height\",\"$width\") >$linkname</A>');";
echo "\n//-->";
echo "\n</SCRIPT>";
echo "\n<NOSCRIPT>\n<A TARGET=\"$name\" HREF=\"$url\">$linkname</A>\n</NOSCRIPT>\n";
}
function close_window_button() {
echo "<FORM><CENTER>";
echo "<INPUT TYPE=button onClick=\"self.close();\" VALUE=\"Close this window\">";
echo "</CENTER></FORM>";
}
function choose_from_menu ($options, $name, $selected="", $nothing="Choose...", $script="") {
// $options["value"]["label"]
if ($script) {
$javascript = "onChange=\"$script\"";
}
echo "<SELECT NAME=$name $javascript>\n";
echo " <OPTION VALUE=0>$nothing</OPTION>\n";
foreach ($options as $value => $label) {
echo " <OPTION VALUE=\"$value\"";
if ($value == $selected) {
echo " SELECTED";
}
if ($label) {
echo ">$label</OPTION>\n";
} else {
echo ">$value</OPTION>\n";
}
}
echo "</SELECT>\n";
}
function popup_form ($common, $options, $formname, $selected="", $nothing="Choose...") {
// Implements a complete little popup form
// $common = the URL up to the point of the variable that changes
// $options = A list of value-label pairs for the popup list
// $formname = name must be unique on the page
// $selected = the option that is already selected
// $nothing = The label for the "no choice" option
echo "<FORM NAME=$formname>";
echo "<SELECT NAME=popup onChange=\"window.location=document.$formname.popup.options[document.$formname.popup.selectedIndex].value\">\n";
if ($nothing != "") {
echo " <OPTION VALUE=\"javascript:void(0)\">$nothing</OPTION>\n";
}
foreach ($options as $value => $label) {
echo " <OPTION VALUE=\"$common$value\"";
if ($value == $selected) {
echo " SELECTED";
}
if ($label) {
echo ">$label</OPTION>\n";
} else {
echo ">$value</OPTION>\n";
}
}
echo "</SELECT></FORM>\n";
}
function formerr($error) {
if (!empty($error)) {
echo "<font color=#ff0000>$error</font>";
}
}
function validate_email ($address) {
// Validates an email to make it makes sense.
return (ereg('^[-!#$%&\'*+\\./0-9=?A-Z^_`a-z{|}~]+'.
'@'.
'[-!#$%&\'*+\\/0-9=?A-Z^_`a-z{|}~]+\.'.
'[-!#$%&\'*+\\./0-9=?A-Z^_`a-z{|}~]+$',
$address));
}
function get_slash_arguments($i=0) {
// Extracts arguments from "/foo/bar/something"
// eg http://mysite.com/script.php/foo/bar/something
// Might only work on Apache
global $PATH_INFO;
if (!isset($PATH_INFO)) {
return false;
}
$args = explode("/", $PATH_INFO);
if ($i) { // return just the required argument
return $args[$i];
} else { // return the whole array
array_shift($args); // get rid of the empty first one
return $args;
}
}
function text_to_html($text) {
global $CFG;
// Given plain text, makes it into HTML as nicely as possible.
// Make URLs into links. eg http://moodle.com/
$text = eregi_replace("([[:alnum:]]+)://([^[:space:]]*)([[:alnum:]#?/&=])",
"<A HREF=\"\\1://\\2\\3\" TARGET=\"newpage\">\\1://\\2\\3</A>", $text);
// eg www.moodle.com
$text = eregi_replace("([[:space:]])www.([^[:space:]]*)([[:alnum:]#?/&=])",
"\\1<A HREF=\"http://www.\\2\\3\" TARGET=\"newpage\">www.\\2\\3</A>", $text);
// Make returns into HTML newlines.
$text = nl2br($text);
// Turn smileys into images.
$text = ereg_replace(":-)", "<IMG ALT=smile SRC=$CFG->wwwroot/pix/s/smiley.gif>", $text);
$text = ereg_replace(":-D", "<IMG ALT=grin SRC=$CFG->wwwroot/pix/s/biggrin.gif>", $text);
$text = ereg_replace(";-)", "<IMG ALT=wink SRC=$CFG->wwwroot/pix/s/wink.gif>", $text);
$text = ereg_replace("8-)", "<IMG ALT=wide-eyed SRC=$CFG->wwwroot/pix/s/wideeyes.gif>", $text);
$text = ereg_replace(":-\(", "<IMG ALT=sad SRC=$CFG->wwwroot/pix/s/sad.gif>", $text);
$text = ereg_replace(":-P", "<IMG ALT=tongue-out SRC=$CFG->wwwroot/pix/s/tongueout.gif>", $text);
$text = ereg_replace(":-/", "<IMG ALT=mixed SRC=$CFG->wwwroot/pix/s/mixed.gif>", $text);
$text = ereg_replace(":-o", "<IMG ALT=surprised SRC=$CFG->wwwroot/pix/s/surprise.gif>", $text);
$text = ereg_replace("B-)", "<IMG ALT=cool SRC=$CFG->wwwroot/pix/s/cool.gif>", $text);
return "<P>".$text."</P>";
}
?>
+17
View File
@@ -0,0 +1,17 @@
baby
bull
camel
car
cat
elephant
fence
flower
frog
gate
grass
music
peg
pillow
rabbit
rock
tree
+86
View File
@@ -0,0 +1,86 @@
<?PHP // $Id$
include("../config.php");
if (match_referer() && isset($HTTP_POST_VARS)) {
$frm = (object) $HTTP_POST_VARS;
validate_form($frm, $err);
update_login_count();
if (!count((array)$err)) {
$username = $frm->username;
$password = $frm->newpassword1;
if (! set_field("user", "password", md5($frm->newpassword1), "username", $frm->username)) {
error("Could not set the new password");
}
unset($USER);
$USER = get_user_info_from_db("username", $username);
$USER->loggedin = true;
set_moodle_cookie($USER->username);
add_to_log("Changed password");
reset_login_count();
print_header("Changed password", "Password changed successfully", "Changed Password", "");
notice("Password changed successfully", "$CFG->wwwroot/course/");
print_footer();
exit;
}
}
if (!$frm->username)
$frm->username = get_moodle_cookie();
if ($frm->username) {
$focus = "form.password";
} else {
$focus = "form.username";
}
print_header("Change password", "Change Password", "Change Password", "$focus");
print_simple_box_start("center", "", $THEME->cellheading);
include("change_password_form.html");
print_simple_box_end();
print_footer();
/******************************************************************************
* FUNCTIONS
*****************************************************************************/
function validate_form($frm, &$err) {
if (empty($frm->username))
$err->username = "Missing username";
else if (empty($frm->password))
$err->password = "Missing password";
else if (!verify_login($frm->username, $frm->password))
$err->password = "Incorrect password for this username";
if (empty($frm->newpassword1))
$err->newpassword1 = "Missing new password";
if (empty($frm->newpassword2))
$err->newpassword2 = "Missing new password";
else if ($frm->newpassword1 <> $frm->newpassword2)
$err->newpassword2 = "Passwords not the same";
return;
}
?>
+33
View File
@@ -0,0 +1,33 @@
<P><B>All fields are required</B></P>
<form name="form" method="post" action="change_password.php">
<table cellpadding=10>
<tr valign=top>
<td><P>Username:</P></td>
<td><input type="text" name="username" size=25 value="<? pv($frm->username) ?>">
<? formerr($err->username) ?>
</td>
</tr>
<tr valign=top>
<td><P>Password:</P></td>
<td><input type="text" name="password" size=25 value="<? pv($frm->password) ?>">
<? formerr($err->password) ?>
</td>
</tr>
<tr valign=top>
<td><P>New Password:</P></td>
<td><input type="text" name="newpassword1" size=25 value="<? pv($frm->newpassword1) ?>">
<? formerr($err->newpassword1) ?>
</td>
</tr>
<tr valign=top>
<td><P>New Password (again):</P></td>
<td><input type="text" name="newpassword2" size=25 value="<? pv($frm->newpassword2) ?>">
<? formerr($err->newpassword2) ?>
</td>
</tr>
<tr>
<td></td>
<td><input type="submit" value="Change Password"></td>
</table>
</form>
+54
View File
@@ -0,0 +1,54 @@
<?PHP // $Id$
require("../config.php");
if ( isset($x) && isset($s) ) { # x = user.id s = user.username
$user = get_user_info_from_db("id", "$x");
if ($user) {
if ($user->username == $s) {
if ($user->confirmed) {
print_header("Registration already confirmed", "Already confirmed", "Confirmed", "");
echo "<CENTER><H3>Thanks, ". $USER->firstname ." ". $USER->lastname . "</H3>\n";
echo "<H4>Your registration has already been confirmed.</H4>\n";
echo "<H3><A HREF=\"$CFG->wwwroot/course/\">Proceed to the courses</A></H3>\n";
print_footer();
exit;
}
$USER = $user;
$timenow = time();
$rs = $db->Execute("UPDATE user SET confirmed=1, lastIP='$REMOTE_ADDR',
firstaccess='$timenow', lastaccess='$timenow'
WHERE id = '$USER->id' ");
if (!$rs) error("Could not update this user while confirming");
set_moodle_cookie($USER->username);
$USER->loggedin = true;
$USER->confirmed = 1;
if ( ! empty($SESSION["wantsurl"]) ) {
$goto = $SESSION["wantsurl"];
redirect("$goto");
}
print_header("Registration confirmed", "Confirmed", "Confirmed", "");
echo "<CENTER><H3>Thanks, ". $USER->firstname ." ". $USER->lastname . "</H3>\n";
echo "<H4>Your registration is now confirmed.</H4>\n";
echo "<H3><A HREF=\"$CFG->wwwroot/course/\">Show me the courses</A></H3>\n";
print_footer();
} else {
error("Invalid confirmation data");
}
}
} else {
redirect("$CFG->wwwroot");
}
?>
+256
View File
@@ -0,0 +1,256 @@
<?PHP // $Id$
function print_country_menu($selected = "") {
$countries = array (
"" => "Select...",
"AF" => "Afghanistan",
"AL" => "Albania",
"DZ" => "Algeria",
"AS" => "American Samoa",
"AD" => "Andorra",
"AO" => "Angola",
"AI" => "Anguilla",
"AQ" => "Antarctica",
"AG" => "Antigua and Barbuda",
"AR" => "Argentina",
"AM" => "Armenia",
"AW" => "Aruba",
"AU" => "Australia",
"AT" => "Austria",
"AZ" => "Azerbaijan",
"BS" => "Bahamas",
"BH" => "Bahrain",
"BD" => "Bangladesh",
"BB" => "Barbados",
"BY" => "Belarus",
"BE" => "Belgium",
"BZ" => "Belize",
"BJ" => "Benin",
"BM" => "Bermuda",
"BT" => "Bhutan",
"BO" => "Bolivia",
"BA" => "Bosnia and Herzegowina",
"BW" => "Botswana",
"BV" => "Bouvet Island",
"BR" => "Brazil",
"IO" => "British Indian Ocean Territory",
"BN" => "Brunei Darussalam",
"BG" => "Bulgaria",
"BF" => "Burkina Faso",
"BI" => "Burundi",
"KH" => "Cambodia",
"CM" => "Cameroon",
"CA" => "Canada",
"CV" => "Cape Verde",
"KY" => "Cayman Islands",
"CF" => "Central African Republic",
"TD" => "Chad",
"CL" => "Chile",
"CN" => "China",
"CX" => "Christmas Island",
"CC" => "Cocos (Keeling) Islands",
"CO" => "Colombia",
"KM" => "Comoros",
"CG" => "Congo",
"CK" => "Cook Islands",
"CR" => "Costa Rica",
"CI" => "Cote D'Ivoire",
"HR" => "Croatia (Hrvatska)",
"CU" => "Cuba",
"CY" => "Cyprus",
"CZ" => "Czech Republic",
"DK" => "Denmark",
"DJ" => "Djibouti",
"DM" => "Dominica",
"DO" => "Dominican Republic",
"TP" => "East Timor",
"EC" => "Ecuador",
"EG" => "Egypt",
"SV" => "El Salvador",
"GQ" => "Equatorial Guinea",
"ER" => "Eritrea",
"EE" => "Estonia",
"ET" => "Ethiopia",
"FK" => "Falkland Islands (Malvinas)",
"FO" => "Faroe Islands",
"FJ" => "Fiji",
"FI" => "Finland",
"FR" => "France",
"FX" => "France, Metropolitan",
"GF" => "French Guiana",
"PF" => "French Polynesia",
"TF" => "French Southern Territories",
"GA" => "Gabon",
"GM" => "Gambia",
"GE" => "Georgia",
"DE" => "Germany",
"GH" => "Ghana",
"GI" => "Gibraltar",
"GR" => "Greece",
"GL" => "Greenland",
"GD" => "Grenada",
"GP" => "Guadeloupe",
"GU" => "Guam",
"GT" => "Guatemala",
"GN" => "Guinea",
"GW" => "Guinea-Bissau",
"GY" => "Guyana",
"HT" => "Haiti",
"HM" => "Heard and Mc Donald Islands",
"HN" => "Honduras",
"HK" => "Hong Kong",
"HU" => "Hungary",
"IS" => "Iceland",
"IN" => "India",
"ID" => "Indonesia",
"IR" => "Iran (Islamic Republic of)",
"IQ" => "Iraq",
"IE" => "Ireland",
"IL" => "Israel",
"IT" => "Italy",
"JM" => "Jamaica",
"JP" => "Japan",
"JO" => "Jordan",
"KZ" => "Kazakhstan",
"KE" => "Kenya",
"KI" => "Kiribati",
"KP" => "Korea, Democratic People's Republic of",
"KR" => "Korea, Republic of",
"KW" => "Kuwait",
"KG" => "Kyrgyzstan",
"LA" => "Lao People's Democratic Republic",
"LV" => "Latvia",
"LB" => "Lebanon",
"LS" => "Lesotho",
"LR" => "Liberia",
"LY" => "Libyan Arab Jamahiriya",
"LI" => "Liechtenstein",
"LT" => "Lithuania",
"LU" => "Luxembourg",
"MO" => "Macau",
"MK" => "Macedonia",
"MG" => "Madagascar",
"MW" => "Malawi",
"MY" => "Malaysia",
"MV" => "Maldives",
"ML" => "Mali",
"MT" => "Malta",
"MH" => "Marshall Islands",
"MQ" => "Martinique",
"MR" => "Mauritania",
"MU" => "Mauritius",
"YT" => "Mayotte",
"MX" => "Mexico",
"FM" => "Micronesia, Federated States of",
"MD" => "Moldova, Republic of",
"MC" => "Monaco",
"MN" => "Mongolia",
"MS" => "Montserrat",
"MA" => "Morocco",
"MZ" => "Mozambique",
"MM" => "Myanmar",
"NA" => "Namibia",
"NR" => "Nauru",
"NP" => "Nepal",
"NL" => "Netherlands",
"AN" => "Netherlands Antilles",
"NC" => "New Caledonia",
"NZ" => "New Zealand",
"NI" => "Nicaragua",
"NE" => "Niger",
"NG" => "Nigeria",
"NU" => "Niue",
"NF" => "Norfolk Island",
"MP" => "Northern Mariana Islands",
"NO" => "Norway",
"OM" => "Oman",
"PK" => "Pakistan",
"PW" => "Palau",
"PA" => "Panama",
"PG" => "Papua New Guinea",
"PY" => "Paraguay",
"PE" => "Peru",
"PH" => "Philippines",
"PN" => "Pitcairn",
"PL" => "Poland",
"PT" => "Portugal",
"PR" => "Puerto Rico",
"QA" => "Qatar",
"RE" => "Reunion",
"RO" => "Romania",
"RU" => "Russian Federation",
"RW" => "Rwanda",
"KN" => "Saint Kitts and Nevis",
"LC" => "Saint Lucia",
"VC" => "Saint Vincent and the Grenadines",
"WS" => "Samoa",
"SM" => "San Marino",
"ST" => "Sao Tome and Principe",
"SA" => "Saudi Arabia",
"SN" => "Senegal",
"SC" => "Seychelles",
"SL" => "Sierra Leone",
"SG" => "Singapore",
"SK" => "Slovakia (Slovak Republic)",
"SI" => "Slovenia",
"SB" => "Solomon Islands",
"SO" => "Somalia",
"ZA" => "South Africa",
"ES" => "Spain",
"LK" => "Sri Lanka",
"SH" => "St. Helena",
"PM" => "St. Pierre and Miquelon",
"SD" => "Sudan",
"SR" => "Suriname",
"SJ" => "Svalbard and Jan Mayen Islands",
"SZ" => "Swaziland",
"SE" => "Sweden",
"CH" => "Switzerland",
"SY" => "Syrian Arab Republic",
"TW" => "Taiwan",
"TJ" => "Tajikistan",
"TZ" => "Tanzania, United Republic of",
"TH" => "Thailand",
"TG" => "Togo",
"TK" => "Tokelau",
"TO" => "Tonga",
"TT" => "Trinidad and Tobago",
"TN" => "Tunisia",
"TR" => "Turkey",
"TM" => "Turkmenistan",
"TC" => "Turks and Caicos Islands",
"TV" => "Tuvalu",
"UG" => "Uganda",
"UA" => "Ukraine",
"AE" => "United Arab Emirates",
"GB" => "United Kingdom",
"US" => "United States of America",
"UY" => "Uruguay",
"UZ" => "Uzbekistan",
"VU" => "Vanuatu",
"VA" => "Vatican City State (Holy See)",
"VE" => "Venezuela",
"VN" => "Vietnam",
"VG" => "Virgin Islands (British)",
"VI" => "Virgin Islands (U.S.)",
"WF" => "Wallis And Futuna Islands",
"EH" => "Western Sahara",
"YE" => "Yemen",
"YU" => "Yugoslavia",
"ZR" => "Zaire",
"ZM" => "Zambia",
"ZW" => "Zimbabwe");
echo "<SELECT NAME=country>\n";
while (list($code, $country) = each ($countries) ) {
echo "<OPTION VALUE=\"$code\"";
if ($code == $selected) {
echo " SELECTED";
}
echo ">$country\n";
}
echo "</SELECT>\n";
}
+102
View File
@@ -0,0 +1,102 @@
<?PHP // $Id$
include("../config.php");
if (match_referer() && isset($HTTP_POST_VARS)) {
$frm = (object)$HTTP_POST_VARS;
validate_form($frm, $err);
update_login_count();
if (count((array)$err) == 0) {
if (!$user = get_user_info_from_db("email", $frm->email)) {
error("No such user with this address: $frm->email");
}
if (! reset_password_and_mail($user)) {
error("Could not reset password and mail the new one to you");
}
reset_login_count();
print_header("Password has been sent", "Password has been sent", "Password Sent", "");
include("forgot_password_change.html");
exit;
}
}
if ( empty($frm->email) ) {
if ( $username = get_moodle_cookie() ) {
$frm->email = get_field("user", "email", "username", "$username");
}
}
print_header("Forgot password?", "Have a new password sent to you", "", "form.email");
include("forgot_password_form.html");
/******************************************************************************
* FUNCTIONS
*****************************************************************************/
function validate_form($frm, &$err) {
if (empty($frm->email))
$err->email = "Missing email address";
else if (! validate_email($frm->email))
$err->email = "Invalid email address";
else if (! record_exists("user", "email", $frm->email))
$err->email = "No such email address on file";
}
function reset_password_and_mail($user) {
global $CFG;
$site = get_site();
$from = get_admin();
$newpassword = generate_password();
if (! set_field("user", "password", md5($newpassword), "id", $user->id) ) {
error("Could not set user password!");
}
$message = "Hi $user->firstname,\n\n";
$message .= "Your account password at '$site->fullname' has been reset\n";
$message .= "and you have been issued with a new temporary password.\n\n";
$message .= "Your current login information is now:\n\n";
$message .= " username: $user->username\n";
$message .= " password: $newpassword\n\n";
$message .= "Please go to this page to change your password:\n\n";
$message .= "$CFG->wwwroot/login/change_password.php\n\n";
$message .= "In most mail programs, this should appear as a blue link\n";
$message .= "which you can just click on. If that doesn't work, \n";
$message .= "then cut and paste the address into the address\n";
$message .= "line at the top of your web browser window.\n\n";
$message .= "Cheers from the '$site->fullname' administrator,\n";
$message .= "$from->firstname $from->lastname ($from->email)\n";
$subject = "$site->fullname: Changed password";
return email_to_user($user, $from, $subject, $message);
}
?>
+15
View File
@@ -0,0 +1,15 @@
<CENTER>
<P>An email has been sent to your address at <? pv($frm->email) ?> </P>
<P><B>Please check your email for your new password</B>
<P>The new password was automatically generated, so you might like to
<A HREF="<?=$CFG->wwwroot ?>/login/change_password.php">change it to something easier to remember</A>.
</P>
<HR>
<CENTER>
<P><A HREF="<?=$CFG->wwwroot ?>">Home</A></P>
+34
View File
@@ -0,0 +1,34 @@
<table cellpadding=20 align=center>
<tr valign=top>
<td width=300 class=normal>
<p>Enter in your email address to reset your password, and
have the new password sent to you via email.
<p>Otherwise, you can return to the
<a href="<?=$CFG->wwwroot ?>/login/">login screen</a> or the
<a href="<?=$CFG->wwwroot ?>">home page</a> now.
</td>
<td bgcolor="<?=$THEME->cellheading?>">
<form name="form" method="post" action="<?=$ME?>">
<table>
<tr>
<td class=label>Email:</td>
<td><input type="text" name="email" size=25 value="<? pv($frm->email) ?>">
<? formerr($err->email); ?>
</tr>
<tr>
<td></td>
<td><input type="submit" value="Submit">
<input type="button" value="Cancel" onClick="javascript: history.go(-1)">
</td>
</table>
</form>
</td>
</tr>
</table>
<HR>
<CENTER>
<P><A HREF="<?=$CFG->wwwroot ?>">Home</A></P>
+87
View File
@@ -0,0 +1,87 @@
<?PHP // $Id$
require("../config.php");
if (match_referer() && isset($HTTP_POST_VARS)) { // form submitted
$frm = (object)$HTTP_POST_VARS;
$user = verify_login($frm->username, $frm->password);
update_login_count();
if ($user) {
if (! $user->confirmed ) { // they never confirmed via email
print_header("Need to confirm", "Not confirmed yet", "", "");
include("index_confirm.html");
die;
}
$USER = $user;
$USER->loggedin = true;
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);
if (empty($SESSION->wantsurl)) {
header("Location: $CFG->wwwroot");
} else {
header("Location: $SESSION->wantsurl");
unset($SESSION->wantsurl);
}
reset_login_count();
add_to_log("Logged in");
if ($CFG->smsnotify) {
$time = date("H:i D j M", time());
$smstring = "$time - $USER->firstname $USER->lastname logged in to $CFG->sitename";
system("echo \"$smstring \" | /opt/bin/sendsms &> /dev/null &");
}
die;
} else {
$errormsg = "Invalid login, please try again";
}
}
if (empty($SESSION->wantsurl)) {
$SESSION->wantsurl = $HTTP_REFERER;
}
if (!$frm->username)
$frm->username = get_moodle_cookie();
if ($frm->username) {
$focus = "form.password";
} else {
$focus = "form.username";
}
print_header("Login to the site", "Login to the site", "Login", $focus);
include("index_form.html");
exit;
// No footer on this page
function update_user_login_times() {
global $db, $USER;
$USER->lastlogin = $USER->currentlogin;
$USER->currentlogin = time();
return $db->Execute("UPDATE user
SET lastlogin='$USER->lastlogin', currentlogin='$USER->currentlogin'
WHERE id = '$USER->id'");
}
?>
+20
View File
@@ -0,0 +1,20 @@
<CENTER>
<h2>Sorry, <? pv($user->firstname) ?>, but you can't log in until you have confirmed your registration</h2>
<h2>Please check your email!</h2>
<p class=normal>
An email should have been sent to your address at <? pv($user->email) ?>
</p>
<p class=normal>
It contains easy instructions to complete your registration.
</p>
<p>If you continue to have difficulty, contact the site administrator.
<HR>
<CENTER>
<P><A HREF="<?=$CFG->wwwroot ?>">Home</A></P>
+63
View File
@@ -0,0 +1,63 @@
<CENTER>
<TABLE WIDTH="90%" BORDER="0" CELLSPACING="10" CELLPADDING="5" ALIGN="CENTER">
<TR>
<TD WIDTH="50%" bgcolor=<?=$THEME->cellheading2?>>
<P ALIGN="CENTER"><B><FONT SIZE=3>Returning to this web site?</FONT></B></P>
</TD>
<TD WIDTH="50%" bgcolor=<?=$THEME->cellheading2?>>
<P ALIGN="CENTER"><B><FONT SIZE=3>Is this your first time here?</FONT></B></P>
</TD>
</TR>
<TR>
<TD WIDTH="50%" VALIGN="TOP" bgcolor="<?=$THEME->cellheading?>">
<FONT SIZE=2>
<P ALIGN="CENTER">Log in using your username and password:</P>
<P ALIGN="CENTER"><? formerr($errormsg) ?></P>
<FORM NAME="form" ACTION="<?=$CFG->wwwroot?>/login/" METHOD=post>
<CENTER>
<TABLE ALIGN=center>
<TR><TD align=right><P><FONT SIZE=2>Username:</FONT></P></TD>
<TD><INPUT TYPE="text" NAME="username" SIZE="15" value="<? p($frm->username) ?>">
</TD></TR>
<TR><TD align=right><P><FONT SIZE=2>Password:</FONT></P></TD>
<TD><INPUT TYPE="password" NAME="password" SIZE="15" value="<? p($frm->password) ?>">
</TD></TR>
</TABLE>
<BR>
<INPUT TYPE="submit" NAME="Submit" VALUE="Login">
</FORM>
</CENTER>
<P>&nbsp;</P>
<P>If you've logged in before but can't remember your username or password,
then you can <A HREF="forgot_password.php">have your details sent to you via email</A>.</P>
</FONT>
</TD>
<TD WIDTH="50%" VALIGN="TOP" bgcolor="<?=$THEME->cellheading?>">
<FONT SIZE=2>
<P>Hi! You need to create a new account for yourself on this server so we know who
you are. Each of the individual courses may also have a one-time
&quot;course entry key&quot;, which you won't need until later. Here are
the steps:</P>
<OL size=2>
<LI>Fill out the <A HREF="signup.php">New Account</A> form with your details.
<LI>An email will be immediately sent to your email address.
<LI>Read your email, and click on the web link it contains.
<LI>Your account will be confirmed and you will be logged in.
<LI>Now, select the course you want to participate in.
<LI>If you are prompted for a &quot;course entry key&quot; - use the one
that your teacher has given you. This will &quot;enrol&quot; you in the
course.
<LI>You can now access the full course. From now on you will only need
to enter your personal username and password (in the form on this page)
to log in and access any course you have enrolled in.
<P ALIGN="CENTER"><B><A HREF="signup.php">Start now by creating a new account!</A></B></P>
</FONT>
</TD>
</TR>
</TABLE>
<HR>
<CENTER>
<P><A HREF="<?=$CFG->wwwroot ?>">Home</A></P>
+11
View File
@@ -0,0 +1,11 @@
<?PHP // $Id$
// Logs the user out and sends them back where they came from
require("../config.php");
add_to_log("Logged out");
unset($USER);
redirect($HTTP_REFERER);
exit;
?>
+129
View File
@@ -0,0 +1,129 @@
<?PHP // $Id$
require("../config.php");
require("countries.php");
if (match_referer() && isset($HTTP_POST_VARS)) {
$user = (object) $HTTP_POST_VARS;
validate_form($user, $err);
if (count((array)$err) == 0) {
$user->password = md5($user->password);
$user->confirmed = 0;
$user->firstaccess = time();
if (! ($user->id = insert_record("user", $user)) ) {
error("Could not add your record to the database!");
}
if (! send_confirmation_email($user)) {
error("Tried to send you an email but failed!");
}
print_header("Check your email", "Check your email", "Confirm", "");
include("signup_confirm.html");
exit;
}
}
if ($err) {
foreach ((array)$err as $key => $value) {
$focus = "form.$key";
}
}
print_header("New account", "New account",
"<A HREF=\".\">Login</A> -> New Account", $focus);
include("signup_form.php");
/******************************************************************************
* FUNCTIONS
*****************************************************************************/
function validate_form($user, &$err) {
if (empty($user->username))
$err->username = "Missing username";
else if (record_exists("user", "username", $user->username))
$err->username = "This username already exists, choose another";
else {
$string = eregi_replace("[^([:alnum:])]", "", $user->username);
if (strcmp($user->username, $string))
$err->username = "Must only contain alphabetical characters";
}
if (empty($user->password))
$err->password = "Missing password";
if (empty($user->firstname))
$err->firstname = "Missing first name";
if (empty($user->lastname))
$err->lastname = "Missing last name";
if (empty($user->email))
$err->email = "Missing email address";
else if (! validate_email($user->email))
$err->email = "Invalid email address, check carefully";
else if (record_exists("user", "email", $user->email))
$err->email = "Email address already registered. <A HREF=forgot_password.php>New password?</A>";
if (empty($user->phone))
$err->phone = "Missing phone number";
if (empty($user->city))
$err->city = "Missing city";
if (empty($user->country))
$err->country = "Missing country";
return;
}
function send_confirmation_email($user) {
global $CFG;
$site = get_site();
$from = get_admin();
$message = "Hi $user->firstname,\n\n";
$message .= "A new account has been requested at '$site->fullname'\n";
$message .= "using your email address.\n\n";
$message .= "To confirm your new account, please go to the \n";
$message .= "following web address:\n\n";
$message .= "$CFG->wwwroot/login/confirm.php?x=$user->id&s=$user->username\n\n";
$message .= "In most mail programs, this should appear as a blue link\n";
$message .= "which you can just click on. If that doesn't work, \n";
$message .= "then cut and paste the address into the address\n";
$message .= "line at the top of your web browser window.\n\n";
$message .= "Cheers from the '$site->fullname' administrator,\n";
$message .= "$from->firstname $from->lastname ($from->email)\n";
$subject = "$site->fullname account confirmation";
return email_to_user($user, $from, $subject, $message);
}
?>
+19
View File
@@ -0,0 +1,19 @@
<CENTER>
<h2>Thanks, <? pv($user->firstname) ?></h2>
<h2>Your new account is almost finished</h2>
<h2>Please check your email!</h2>
<p class=normal>
An email has been sent to your address at <? pv($user->email) ?>
</p>
<p class=normal>
It contains easy instructions to confirm your new account.
</p>
<HR>
<CENTER>
<P><A HREF="<?=$CFG->wwwroot ?>">Home</A></P>
+77
View File
@@ -0,0 +1,77 @@
<CENTER>
<table cellpadding=20> <tr> <td bgcolor="<?=$THEME->cellheading ?>">
<form name="form" method="post" action="signup.php">
<table>
<tr valign=top>
<td colspan=2><P><B>Create a new username and password to log in with:</td>
</tr>
<tr valign=top>
<td><P>New username:</td>
<td><input type="text" name="username" size=12 value="<? pv($user->username) ?>">
<? formerr($err->username) ?>
</td>
</tr>
<tr valign=top>
<td><P>New password:</td>
<td><input type="text" name="password" size=12 value="<? pv($user->password) ?>">
<? formerr($err->password) ?>
</td>
</tr>
<tr valign=top>
<td colspan=2><BR><P><B>Please supply some information about yourself:</td>
</tr>
<tr valign=top>
<td><P>First name:</td>
<td><input type="text" name="firstname" size=25 value="<? pv($user->firstname) ?>">
<? formerr($err->firstname) ?>
</td>
</tr>
<tr valign=top>
<td><P>Last name:</td>
<td><input type="text" name="lastname" size=25 value="<? pv($user->lastname) ?>">
<? formerr($err->lastname) ?>
</td>
</tr>
<tr valign=top>
<td><P>Curtin ID Number:</td>
<td><input type="text" name="idnumber" size=25 value="<? pv($user->idnumber) ?>"> (optional)
<? formerr($err->idnumber) ?>
</td>
</tr>
<tr valign=top>
<td><P>Email address:</td>
<td><input type="text" name="email" size=25 value="<? pv($user->email) ?>">
<? formerr($err->email) ?>
</td>
</tr>
<tr valign=top>
<td><P>Phone number:</td>
<td><input type="text" name="phone" size=25 value="<? pv($user->phone) ?>">
<? formerr($err->phone) ?>
</td>
</tr>
<tr valign=top>
<td><P>City or town:</td>
<td><input type="text" name="city" size=25 value="<? pv($user->city) ?>">
<? formerr($err->city) ?>
</td>
</tr>
<tr valign=top>
<td><P>Country:</td>
<td><? print_country_menu($user->country) ?>
<? formerr($err->country) ?>
</td>
</tr>
<tr>
<td></td>
<td><input type="submit" value="Create my new account"></td>
</table>
</form>
</td></tr></table>
<HR>
<CENTER>
<P><A HREF="<?=$CFG->wwwroot ?>">Home</A></P>
+6
View File
@@ -0,0 +1,6 @@
Describes the assignment (eg an essay) that needs to be completed
then collects and datestamps it. Later, shows the grade.
Teacher view, show class list, allows download and grades.
+10
View File
@@ -0,0 +1,10 @@
<?PHP // $Id$
////////////////////////////////////////////////////////////////////////////////
// Code fragment to define the module version etc.
// This fragment is called by /admin/index.php
////////////////////////////////////////////////////////////////////////////////
?>
Binary file not shown.

After

Width:  |  Height:  |  Size: 206 B

+62
View File
@@ -0,0 +1,62 @@
<?PHP // $Id$
require("../../config.php");
require_variable($id); // course
if (! $course = get_record("course", "id", $id)) {
error("Course ID is incorrect");
}
require_login($course->id);
add_to_log("View list of all choices", $course->id);
print_header("$course->shortname: Choices", "$course->fullname",
"<A HREF=../../course/view.php?id=$course->id>$course->shortname</A> -> Choices", "");
if (! $choices = get_all_instances_in_course("choice", $course->id, "cw.week ASC")) {
notice("There are no choices", "../../course/view.php?id=$course->id");
}
if ( $allanswers = get_records_sql("SELECT * FROM choice_answers WHERE user='$USER->id'")) {
foreach ($allanswers as $aa) {
$answers[$aa->choice] = $aa;
}
} else {
$answers = array () ;
}
$timenow = time();
$table->head = array ("Week", "Question", "Answer");
$table->align = array ("CENTER", "LEFT", "CENTER");
foreach ($choices as $choice) {
$answer = $answers[$choice->id];
switch ($answer->answer) {
case 1:
$aa = "$choice->answer1";
break;
case 2:
$aa = "$choice->answer2";
break;
default:
$aa = "Undecided";
break;
}
$table->data[] = array ("<P>$choice->week</P>",
"<P><A HREF=\"view.php?id=$choice->coursemodule\">$choice->name</A></P>",
"<P>$aa</P>");
}
print_table($table);
print_footer($course);
?>
+43
View File
@@ -0,0 +1,43 @@
# phpMyAdmin MySQL-Dump
# version 2.2.1
# http://phpwizard.net/phpMyAdmin/
# http://phpmyadmin.sourceforge.net/ (download page)
#
# Host: localhost
# Generation Time: Nov 14, 2001 at 04:44 PM
# Server version: 3.23.36
# PHP Version: 4.0.6
# Database : `moodle`
# --------------------------------------------------------
#
# Table structure for table `choice`
#
CREATE TABLE choice (
id int(10) unsigned NOT NULL auto_increment,
course int(10) unsigned NOT NULL default '0',
name varchar(255) NOT NULL default '',
text text NOT NULL,
answer1 varchar(255) NOT NULL default 'Yes',
answer2 varchar(255) NOT NULL default 'No',
timemodified int(10) unsigned NOT NULL default '0',
PRIMARY KEY (id),
UNIQUE KEY id (id)
) TYPE=MyISAM;
# --------------------------------------------------------
#
# Table structure for table `choice_answers`
#
CREATE TABLE choice_answers (
id int(10) unsigned NOT NULL auto_increment,
choice int(10) unsigned NOT NULL default '0',
user int(10) unsigned NOT NULL default '0',
answer tinyint(4) NOT NULL default '0',
timemodified int(10) NOT NULL default '0',
PRIMARY KEY (id),
UNIQUE KEY id (id)
) TYPE=MyISAM;
+54
View File
@@ -0,0 +1,54 @@
<FORM NAME="form" METHOD="post" ACTION="<?=$ME ?>">
<table cellpadding=5>
<tr valign=top>
<td align=right><P><B>Choice Name:</B></P></TD>
<td>
<input type="text" name="name" size=30 value="<? p($form->name) ?>">
</td>
</tr>
<tr valign=top>
<td align=right><P><B>Choice Text:</B></P></TD>
<td>
<textarea name="text" rows=15 cols=30 wrap="virtual"><? p($form->text) ?></textarea>
</td>
</tr>
<tr valign=top>
<td align=right><P><B>First choice:</B></P></TD>
<td>
<input type="text" name="answer1" size=30 value="<?
if ($form->answer1) {
p($form->answer1);
} else {
echo "Yes";
} ?>">
</td>
</tr>
<tr valign=top>
<td align=right><P><B>Second choice:</B></P></TD>
<td>
<input type="text" name="answer2" size=30 value="<?
if ($form->answer2) {
p($form->answer2);
} else {
echo "No";
} ?>">
</td>
</tr>
</table>
<CENTER>
<input type="hidden" name=course value="<? p($form->course) ?>">
<input type="hidden" name=week value="<? p($form->week) ?>">
<input type="hidden" name=module value="<? p($form->module) ?>">
<input type="hidden" name=modulename value="<? p($form->modulename) ?>">
<input type="hidden" name=instance value="<? p($form->instance) ?>">
<input type="hidden" name=mode value="<? p($form->mode) ?>">
<input type="submit" value="Save these settings">
</CENTER>
</FORM>
+81
View File
@@ -0,0 +1,81 @@
<?PHP // $Id$
/////////////////////////////////////////////////////////////
//
// MOD.PHP - contains functions to add, update and delete
// an instance of this module
//
// Generally called from /course/mod.php
//
/////////////////////////////////////////////////////////////
function add_instance($form) {
// Given an object containing all the necessary data,
// (defined by the form in mod.html) this function
// will create a new instance and return the id number
// of the new instance.
//
GLOBAL $db;
$timenow = time();
if (!$rs = $db->Execute("INSERT into choice
SET course = '$form->course',
name = '$form->name',
text = '$form->text',
answer1 = '$form->answer1',
answer2 = '$form->answer2',
timemodified = '$timenow'")) {
return 0;
}
// Get it out again - this is the most compatible way to determine the ID
if ($rs = $db->Execute("SELECT id FROM choice
WHERE course = $form->course AND timemodified = '$timenow'")) {
return $rs->fields[0];
} else {
return 0;
}
}
function update_instance($form) {
// Given an object containing all the necessary data,
// (defined by the form in mod.html) this function
// will update an existing instance with new data.
//
GLOBAL $db;
$timenow = time();
if (!$rs = $db->Execute("UPDATE choice
SET course = '$form->course',
name = '$form->name',
text = '$form->text',
answer1 = '$form->answer1',
answer2 = '$form->answer2',
timemodified = '$timenow'
WHERE id = '$form->instance' ")) {
return false;
}
return true;
}
function delete_instance($id) {
// Given an ID of an instance of this module,
// this function will permanently delete the instance
// and any data that depends on it.
//
GLOBAL $db;
if (!$rs = $db->Execute("DELETE from choice WHERE id = '$id' ")) {
return false;
}
return true;
}
?>
+14
View File
@@ -0,0 +1,14 @@
<?PHP // $Id$
////////////////////////////////////////////////////////////////////////////////
// Code fragment to define the module version etc.
// This fragment is called by /admin/index.php
////////////////////////////////////////////////////////////////////////////////
$module->fullname = "Choice";
$module->version = "20011110";
$module->cron = 0;
$module->search = "";
?>
+94
View File
@@ -0,0 +1,94 @@
<?PHP // $Id$
require("../../config.php");
require_variable($id); // course module
if (! $cm = get_record("course_modules", "id", $id)) {
error("Course Module ID was incorrect");
}
if (! $course = get_record("course", "id", $cm->course)) {
error("Course module is misconfigured");
}
require_login($course->id);
if (!isteacher($course->id)) {
error("Only teachers can look at this page");
}
if (! $choice = get_record("choice", "id", $cm->instance)) {
error("Course module is incorrect");
}
add_to_log("View choices report", $course->id);
print_header("$course->shortname: $choice->name: Responses", "$course->fullname",
"<A HREF=/course/view.php?id=$course->id>$course->shortname</A> ->
<A HREF=index.php?id=$course->id>Choices</A> ->
<A HREF=view.php?id=$cm->id>$choice->name</A> -> Responses", "");
if (! $participants = get_records_sql("SELECT u.* FROM user u, user_students s, user_teachers t
WHERE (s.course = '$course->id' AND s.user = u.id)
OR (t.course = '$course->id' AND t.user = u.id)
ORDER BY u.lastaccess DESC")) {
notify("No participants (strange)", "/course/view.php?id=$course->id");
die;
}
if ( $allanswers = get_records_sql("SELECT * FROM choice_answers WHERE choice='$choice->id'")) {
foreach ($allanswers as $aa) {
$answers[$aa->user] = $aa;
}
} else {
$answers = array () ;
}
$timenow = time();
echo "<TABLE BORDER=1 CELLSPACING=0 valign=top align=center cellpadding=10>";
foreach ($participants as $user) {
$answer = $answers[$user->id];
echo "<TR>";
echo "<TD BGCOLOR=\"$THEME->body\" WIDTH=35 VALIGN=TOP>";
print_user_picture($user->id, $course->id, $user->picture);
echo "</TD>";
echo "<TD NOWRAP BGCOLOR=\"$THEME->cellheading\">$user->firstname $user->lastname</TD>";
echo "<TD><P>&nbsp;";
if ($answer->timemodified) {
echo moodledate($answer->timemodified);
}
echo "</P> </TD>";
echo "<TD ALIGN=CENTER BGCOLOR=\"$THEME->cellcontent\"><P>";
switch ($answer->answer) {
case 1:
echo "$choice->answer1";
break;
case 2:
echo "$choice->answer2";
break;
default:
echo "Undecided";
break;
}
echo "</P></TD></TR>";
}
echo "</TABLE>";
print_footer($course);
?>
+19
View File
@@ -0,0 +1,19 @@
<CENTER>
<P>
<FORM name="form" method="post" action="view.php">
<TABLE WIDTH=70% CELLPADDING=20 CELLSPACING=20><TR>
<TD ALIGN=CENTER NOWRAP WIDTH=50%>
<INPUT type="radio" name=answer value="1" <?=$answer1checked ?> >
<? p($choice->answer1) ?>
</TD>
<TD ALIGN=CENTER NOWRAP WIDTH=50%>
<INPUT type="radio" name=answer value="2" <?=$answer2checked ?> >
<? p($choice->answer2) ?>
</TD>
</TR></TABLE>
<P>
<INPUT type="hidden" name=id value="<?=$cm->id ?>">
<INPUT type="submit" value="Save my choice">
</P>
</FORM>
</CENTER>
+92
View File
@@ -0,0 +1,92 @@
<?PHP // $Id$
require("../../config.php");
require_variable($id); // Course Module ID
if (! $cm = get_record("course_modules", "id", $id)) {
error("Course Module ID was incorrect");
}
if (! $course = get_record("course", "id", $cm->course)) {
error("Course is misconfigured");
}
require_login($course->id);
if (! $choice = get_record("choice", "id", $cm->instance)) {
error("Course module is incorrect");
}
if ($current = get_record_sql("SELECT * FROM choice_answers
WHERE choice='$choice->id' AND user='$USER->id'")) {
if ($current->answer == "1") {
$answer1checked = "CHECKED";
} else if ($current->answer == "2") {
$answer2checked = "CHECKED";
}
}
if (match_referer() && isset($HTTP_POST_VARS)) { // form submitted
$form = (object)$HTTP_POST_VARS;
if ($current) {
add_to_log("Update choice: $choice->name", $course->id);
if (! update_choice_in_database($current, $form->answer)) {
error("Could not update your choice");
}
} else {
add_to_log("Save choice: $choice->name", $course->id);
if (! add_new_choice_to_database($choice, $form->answer)) {
error("Could not save your choice");
}
}
redirect("$CFG->wwwroot/course/view.php?id=$course->id");
exit;
}
add_to_log("View choice: $choice->name", $course->id);
print_header("$course->shortname: $choice->name", "$course->fullname",
"<A HREF=../../course/view.php?id=$course->id>$course->shortname</A> ->
<A HREF=index.php?id=$course->id>Choices</A> -> $choice->name", "");
if ($USER->editing) {
print_update_module_icon($cm->id);
}
if (isteacher($course->id)) {
echo "<P align=right><A HREF=\"report.php?id=$cm->id\">View all responses</A></P>";
}
print_simple_box( text_to_html($choice->text) , "center");
require("view.html");
print_footer($course);
// Functions /////////////////////////////////////////////////
function add_new_choice_to_database($choice, $answer) {
global $db;
global $USER;
$timenow = time();
$rs = $db->Execute("INSERT INTO choice_answers (choice, user, answer, timemodified)
VALUES ( '$choice->id', '$USER->id', '$answer', '$timenow')");
return $rs;
}
function update_choice_in_database($current, $answer) {
global $db;
$timenow = time();
$rs = $db->Execute("UPDATE choice_answers
SET answer='$answer', timemodified='$timenow'
WHERE id = '$current->id'");
return $rs;
}
?>
+10
View File
@@ -0,0 +1,10 @@
<BLOCKQUOTE>
<FORM name="form" method="post" action="edit.php">
<TEXTAREA NAME=text COLS=60 ROWS=10 WRAP="virtual"><? p($entry->text) ?></TEXTAREA>
<P>
<INPUT type="hidden" name=id value="<?=$cm->id ?>">
<INPUT type="submit" value="Save and continue">
<INPUT type="reset" value="Revert">
</P>
</FORM>
</BLOCKQUOTE>
+75
View File
@@ -0,0 +1,75 @@
<?PHP // $Id$
require("../../config.php");
require_variable($id); // Course Module ID
if (! $cm = get_record("course_modules", "id", $id)) {
error("Course Module ID was incorrect");
}
if (! $course = get_record("course", "id", $cm->course)) {
error("Course is misconfigured");
}
require_login($course->id);
if (! $journal = get_record("journal", "id", $cm->instance)) {
error("Course module is incorrect");
}
$entry = get_record_sql("SELECT * FROM journal_entries
WHERE user='$USER->id' AND journal='$journal->id'");
/// If data submitted, then process and store.
if (match_referer() && isset($HTTP_POST_VARS)) {
$timenow = time();
if ($entry) {
$newentry->id = $entry->id;
$newentry->text = $text;
$newentry->modified = $timenow;
if (! update_record("journal_entries", $newentry)) {
error("Could not update your journal");
}
add_to_log("Update journal: $journal->name", $course->id);
} else {
$newentry->user = $USER->id;
$newentry->journal = $journal->id;
$newentry->modified = $timenow;
$newentry->text = $text;
if (! insert_record("journal_entries", $newentry)) {
error("Could not insert a new journal entry");
}
add_to_log("Add journal: $journal->name", $course->id);
}
redirect("view.php?id=$cm->id");
die;
}
/// Otherwise fill and print the form.
if (! $entry ) {
$entry->text = "";
}
print_header("$course->shortname: $journal->name", "$course->fullname",
"<A HREF=/course/view.php?id=$course->id>$course->shortname</A> ->
<A HREF=/mod/journal/index.php?id=$course->id>Journals</A> ->
<A HREF=\"view.php?id=$cm->id\">$journal->name</A> -> Edit", "form.text");
echo "<CENTER>\n";
print_simple_box( text_to_html($journal->intro) , "center");
echo "<BR>";
include("edit.html");
print_footer($course);
?>
BIN
View File
Binary file not shown.

After

Width:  |  Height:  |  Size: 206 B

+60
View File
@@ -0,0 +1,60 @@
<?PHP // $Id$
require("../../config.php");
require("lib.php");
require_variable($id); // course
if (! $course = get_record("course", "id", $id)) {
error("Course ID is incorrect");
}
require_login($course->id);
add_to_log("View all journals", $course->id);
print_header("$course->shortname: Journals", "$course->fullname",
"<A HREF=../../course/view.php?id=$course->id>$course->shortname</A> -> Journals", "");
if (! $journals = get_all_instances_in_course("journal", $course->id, "cw.week ASC")) {
notice("There are no journals", "../../course/view.php?id=$course->id");
die;
}
$timenow = time();
$table->head = array ("Week", "Question", "Answer");
$table->align = array ("CENTER", "LEFT", "LEFT");
foreach ($journals as $journal) {
$entry = get_record_sql("SELECT text FROM journal_entries
WHERE user='$USER->id' AND journal='$journal->id'");
$journal->timestart = $course->startdate + (($journal->week - 1) * 608400);
if ($journal->daysopen) {
$journal->timefinish = $journal->timestart + (3600 * 24 * $journal->daysopen);
} else {
$journal->timefinish = 9999999999;
}
$journalopen = ($journal->timestart < $timenow && $timenow < $journal->timefinish);
$text = text_to_html($entry->text)."<P ALIGN=right><A HREF=\"view.php?id=$journal->coursemodule\">";
if ($journalopen) {
$text .= "Edit</A></P>";
} else {
$text .= "View</A></P>";
}
$table->data[] = array ("$journal->week",
text_to_html($journal->intro),
$text);
}
print_table($table);
print_footer($course);
?>

Some files were not shown because too many files have changed in this diff Show More