Commit f9903ed0 authored by martin's avatar martin
Browse files

Initial revision

parents
All the documention is in the "doc" subdirectory. :-)
All the documention is in the "doc" subdirectory. :-)
<?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";
?>
<?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();
?>
<?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>";
?>
# 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';
<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>
<?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;
}
?>
<?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);
}
?>
<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>