Add idnumber to list of course students
[moodle.git] / admin / index.php
blobfdee2a5980d85b3ffe65f73ea87db6457db739e7
1 <?PHP // $Id$
3 /// Check that config.php exists
4 if (!file_exists("../config.php")) {
5 echo "<H2 align=center>You need to create a config.php.<BR>
6 See the <A HREF=\"http://moodle.com/doc/?frame=install.html\">installation instructions</A>.</H2>";
7 die;
10 require_once("../config.php");
13 /// Check that PHP is of a sufficient version
15 if (!check_php_version("4.1.0")) {
16 $version = phpversion();
17 print_heading("Sorry, Moodle requires PHP 4.1.0 or later (currently using version $version)");
18 die;
21 /// Check some PHP server settings
23 $documentationlink = "please read the <A HREF=\"../doc/?frame=install.html&sub=webserver\">install documentation</A>";
26 if (ini_get_bool('session.auto_start')) {
27 error("The PHP server variable 'session.auto_start' should be Off - $documentationlink");
30 if (ini_get_bool('magic_quotes_runtime')) {
31 error("The PHP server variable 'magic_quotes_runtime' should be Off - $documentationlink");
34 if (!ini_get_bool('file_uploads')) {
35 error("The PHP server variable 'file_uploads' is not turned On - $documentationlink");
40 /// Check that sessions are supported
42 if (!is_readable(ini_get('session.save_path')) and !ini_get_bool('safe_mode')) {
43 $sessionpath = ini_get('session.save_path');
44 notify("Warning: It appears your server does not support sessions (session.save_path = '$sessionpath')");
48 /// Check that config.php has been edited
50 if ($CFG->wwwroot == "http://example.com/moodle") {
51 error("Moodle has not been configured yet. You need to to edit config.php first.");
55 /// Check settings in config.php
57 $dirroot = dirname(realpath("../index.php"));
58 if (!empty($dirroot) and $dirroot != $CFG->dirroot) {
59 error("Please fix your settings in config.php:
60 <P>You have:
61 <P>\$CFG->dirroot = \"".addslashes($CFG->dirroot)."\";
62 <P>but it should be:
63 <P>\$CFG->dirroot = \"".addslashes($dirroot)."\";",
64 "./");
67 /// Set some necessary variables during set-up to avoid PHP warnings later on this page
68 if (!isset($CFG->framename)) {
69 $CFG->framename = "_top";
71 if (!isset($CFG->release)) {
72 $CFG->release = "";
74 if (!isset($CFG->version)) {
75 $CFG->version = "";
78 /// Turn off time limits, sometimes upgrades can be slow.
80 set_time_limit(0);
82 /// Check if the main tables have been installed yet or not.
84 if (! $tables = $db->Metatables() ) { // No tables yet at all.
85 $maintables = false;
87 } else { // Check for missing main tables
88 $maintables = true;
89 $mtables = array("config", "course", "course_categories", "course_modules",
90 "course_sections", "log", "log_display", "modules",
91 "user", "user_admins", "user_students", "user_teachers");
92 foreach ($mtables as $mtable) {
93 if (!in_array($CFG->prefix.$mtable, $tables)) {
94 $maintables = false;
95 break;
100 if (! $maintables) {
101 if (empty($agreelicence)) {
102 $strlicense = get_string("license");
103 print_header($strlicense, $strlicense, $strlicense, "", "", false, "&nbsp;", "&nbsp;");
104 print_heading("<A HREF=\"http://moodle.org\">Moodle</A> - Modular Object-Oriented Dynamic Learning Environment");
105 print_heading(get_string("copyrightnotice"));
106 print_simple_box_start("center");
107 echo text_to_html(get_string("gpl"));
108 print_simple_box_end();
109 echo "<br />";
110 notice_yesno(get_string("doyouagree"), "index.php?agreelicence=true",
111 "http://moodle.org/doc/?frame=licence.html");
112 exit;
115 $strdatabasesetup = get_string("databasesetup");
116 $strdatabasesuccess = get_string("databasesuccess");
117 print_header($strdatabasesetup, $strdatabasesetup, $strdatabasesetup, "", "", false, "&nbsp;", "&nbsp;");
118 if (file_exists("$CFG->libdir/db/$CFG->dbtype.sql")) {
119 $db->debug = true;
120 if (modify_database("$CFG->libdir/db/$CFG->dbtype.sql")) {
121 $db->debug = false;
122 notify($strdatabasesuccess, "green");
123 } else {
124 $db->debug = false;
125 error("Error: Main databases NOT set up successfully");
127 } else {
128 error("Error: Your database ($CFG->dbtype) is not yet fully supported by Moodle. See the lib/db directory.");
130 print_continue("index.php");
131 die;
134 /// Check version of Moodle code on disk compared with database
135 /// and upgrade if possible.
137 include_once("$CFG->dirroot/version.php"); # defines $version
138 include_once("$CFG->dirroot/lib/db/$CFG->dbtype.php"); # defines upgrades
140 if ($CFG->version) {
141 if ($version > $CFG->version) { // upgrade
142 $a->oldversion = $CFG->version;
143 $a->newversion = $version;
144 $strdatabasechecking = get_string("databasechecking", "", $a);
145 $strdatabasesuccess = get_string("databasesuccess");
146 print_header($strdatabasechecking, $strdatabasechecking, $strdatabasechecking,
147 "", "", false, "&nbsp;", "&nbsp;");
148 print_heading($strdatabasechecking);
149 $db->debug=true;
150 if (main_upgrade($CFG->version)) {
151 $db->debug=false;
152 if (set_config("version", $version)) {
153 notify($strdatabasesuccess, "green");
154 print_continue("index.php");
155 die;
156 } else {
157 notify("Upgrade failed! (Could not update version in config table)");
159 } else {
160 $db->debug=false;
161 notify("Upgrade failed! See /version.php");
163 } else if ($version < $CFG->version) {
164 notify("WARNING!!! The code you are using is OLDER than the version that made these databases!");
167 } else {
168 $strcurrentversion = get_string("currentversion");
169 print_header($strcurrentversion, $strcurrentversion, $strcurrentversion,
170 "", "", false, "&nbsp;", "&nbsp;");
172 if (set_config("version", $version)) {
173 print_heading("You are currently using Moodle version $version (Release $release)");
174 print_continue("index.php");
175 die;
176 } else {
177 $db->debug=true;
178 if (main_upgrade(0)) {
179 print_continue("index.php");
180 } else {
181 error("A problem occurred inserting current version into databases");
183 $db->debug=false;
187 /// Updated human-readable release version if necessary
189 if ($release <> $CFG->release) { // Update the release version
190 $strcurrentrelease = get_string("currentrelease");
191 print_header($strcurrentrelease, $strcurrentrelease, $strcurrentrelease, "", "", false, "&nbsp;", "&nbsp;");
192 print_heading("Moodle $release");
193 if (!set_config("release", $release)) {
194 notify("ERROR: Could not update release version in database!!");
196 print_continue("index.php");
197 print_simple_box_start("CENTER");
198 include("$CFG->dirroot/lang/en/docs/release.html");
199 print_simple_box_end();
200 print_continue("index.php");
201 exit;
205 /// Upgrade backup/restore system if necessary
207 require_once("$CFG->dirroot/backup/lib.php");
208 upgrade_backup_db("$CFG->wwwroot/$CFG->admin/index.php"); // Return here afterwards
211 /// Find and check all modules and load them up or upgrade them if necessary
213 if (!$mods = get_list_of_plugins("mod") ) {
214 error("No modules installed!");
217 foreach ($mods as $mod) {
219 if ($mod == "NEWMODULE") { // Someone has unzipped the template, ignore it
220 continue;
223 $fullmod = "$CFG->dirroot/mod/$mod";
225 unset($module);
227 if ( is_readable("$fullmod/version.php")) {
228 include_once("$fullmod/version.php"); # defines $module with version etc
229 } else {
230 notify("Module $mod: $fullmod/version.php was not readable");
231 continue;
234 if ( is_readable("$fullmod/db/$CFG->dbtype.php")) {
235 include_once("$fullmod/db/$CFG->dbtype.php"); # defines upgrading function
236 } else {
237 notify("Module $mod: $fullmod/db/$CFG->dbtype.php was not readable");
238 continue;
241 if (!isset($module)) {
242 continue;
245 if (!empty($module->requires)) {
246 if ($module->requires > $CFG->version) {
247 $info->modulename = $mod;
248 $info->moduleversion = $module->version;
249 $info->currentmoodle = $CFG->version;
250 $info->requiremoodle = $module->requires;
251 notify(get_string('modulerequirementsnotmet', 'error', $info));
252 unset($info);
253 continue;
257 $module->name = $mod; // The name MUST match the directory
259 if ($currmodule = get_record("modules", "name", $module->name)) {
260 if ($currmodule->version == $module->version) {
261 // do nothing
262 } else if ($currmodule->version < $module->version) {
263 if (empty($updated_modules)) {
264 $strmodulesetup = get_string("modulesetup");
265 print_header($strmodulesetup, $strmodulesetup, $strmodulesetup, "", "", false, "&nbsp;", "&nbsp;");
267 print_heading("$module->name module needs upgrading");
268 $upgrade_function = $module->name."_upgrade";
269 if (function_exists($upgrade_function)) {
270 $db->debug=true;
271 if ($upgrade_function($currmodule->version, $module)) {
272 $db->debug=false;
273 // OK so far, now update the modules record
274 $module->id = $currmodule->id;
275 if (! update_record("modules", $module)) {
276 error("Could not update $module->name record in modules table!");
278 notify(get_string("modulesuccess", "", $module->name), "green");
279 echo "<HR>";
280 } else {
281 $db->debug=false;
282 notify("Upgrading $module->name from $currmodule->version to $module->version FAILED!");
285 $updated_modules = true;
286 } else {
287 error("Version mismatch: $module->name can't downgrade $currmodule->version -> $module->version !");
290 } else { // module not installed yet, so install it
291 if (empty($updated_modules)) {
292 $strmodulesetup = get_string("modulesetup");
293 print_header($strmodulesetup, $strmodulesetup, $strmodulesetup, "", "", false, "&nbsp;", "&nbsp;");
295 print_heading($module->name);
296 $updated_modules = true;
297 $db->debug = true;
298 set_time_limit(0); // To allow slow databases to complete the long SQL
299 if (modify_database("$fullmod/db/$CFG->dbtype.sql")) {
300 $db->debug = false;
301 if ($module->id = insert_record("modules", $module)) {
302 notify(get_string("modulesuccess", "", $module->name), "green");
303 echo "<HR>";
304 } else {
305 error("$module->name module could not be added to the module list!");
307 } else {
308 error("$module->name tables could NOT be set up successfully!");
313 if (!empty($updated_modules)) {
314 print_continue("index.php");
315 die;
319 /// Insert default values for any important configuration variables
321 include_once("$CFG->dirroot/lib/defaults.php");
323 foreach ($defaults as $name => $value) {
324 if (!isset($CFG->$name)) {
325 $CFG->$name = $value;
326 set_config($name, $value);
327 $configchange = true;
332 /// If any new configurations were found then send to the config page to check
334 if (!empty($configchange)) {
335 redirect("config.php");
338 /// Set up the overall site name etc.
339 if (! $site = get_site()) {
340 redirect("site.php");
343 /// Set up the admin user
344 if (! record_exists("user_admins")) { // No admin user yet
345 redirect("user.php");
348 /// Check for valid admin user
349 if (!isadmin()) {
350 error("You need to be an admin user to use this page.", "$CFG->wwwroot/login/index.php");
354 /// At this point everything is set up and the user is an admin, so print menu
356 $stradministration = get_string("administration");
357 print_header("$site->shortname: $stradministration","$site->fullname", "$stradministration");
358 print_simple_box_start("center", "100%", "$THEME->cellcontent2", 20);
359 print_heading($stradministration);
361 if (!empty($CFG->upgrade)) { // Print notice about extra upgrading that needs to be done
362 print_simple_box(get_string("upgrade$CFG->upgrade", "admin",
363 "$CFG->wwwroot/$CFG->admin/upgrade$CFG->upgrade.php"), "center");
364 print_spacer(10,10);
367 $table->tablealign = "right";
368 $table->align = array ("right", "left");
369 $table->wrap = array ("nowrap", "nowrap");
370 $table->cellpadding = 4;
371 $table->cellspacing = 3;
372 $table->width = "40%";
374 $configdata = "<font size=+1>&nbsp;</font><a href=\"config.php\">".get_string("configvariables")."</a> - <font size=1>".
375 get_string("adminhelpconfigvariables")."</font><br />";
376 $configdata .= "<font size=+1>&nbsp;</font><a href=\"site.php\">".get_string("sitesettings")."</a> - <font size=1>".
377 get_string("adminhelpsitesettings")."</font><br />";
378 $configdata .= "<font size=+1>&nbsp;</font><a href=\"../theme/index.php\">".get_string("themes")."</a> - <font size=1>".
379 get_string("adminhelpthemes")."</font><br />";
380 $configdata .= "<font size=+1>&nbsp;</font><a href=\"lang.php\">".get_string("language")."</a> - <font size=1>".
381 get_string("adminhelplanguage")."</font><br />";
382 $configdata .= "<font size=+1>&nbsp;</font><a href=\"modules.php\">".get_string("managemodules")."</a> - <font size=1>".
383 get_string("adminhelpmanagemodules")."</font><br />";
384 $configdata .= "<font size=+1>&nbsp;</font><a href=\"filters.php\">".get_string("managefilters")."</a> - <font size=1>".
385 get_string("adminhelpmanagefilters")."</font><br />";
386 if (!isset($CFG->disablescheduledbackups)) {
387 $configdata .= "<font size=+1>&nbsp;</font><a href=\"backup.php\">".get_string("backup")."</a> - <font size=1>".
388 get_string("adminhelpbackup")."</font><br />";
391 $table->data[] = array("<font size=+1><b><a href=\"configure.php\">".get_string("configuration")."</a></b>",
392 $configdata);
395 $userdata = "<font size=+1>&nbsp;</font><a href=\"auth.php\">".get_string("authentication")."</a> - <font size=1>".
396 get_string("adminhelpauthentication")."</font><br />";
398 if (is_internal_auth()) {
399 $userdata .= "<font size=+1>&nbsp;</font><a href=\"$CFG->wwwroot/$CFG->admin/user.php?newuser=true\">".
400 get_string("addnewuser")."</a> - <font size=1>".
401 get_string("adminhelpaddnewuser")."</font><br />";
402 $userdata .= "<font size=+1>&nbsp;</font><a href=\"$CFG->wwwroot/$CFG->admin/uploaduser.php\">".
403 get_string("uploadusers")."</a> - <font size=1>".
404 get_string("adminhelpuploadusers")."</font><br />";
406 $userdata .= "<font size=+1>&nbsp;</font><a href=\"user.php\">".get_string("edituser")."</a> - <font size=1>".
407 get_string("adminhelpedituser")."</font><br />";
408 $userdata .= "<font size=+1>&nbsp;</font><a href=\"admin.php\">".get_string("assignadmins")."</a> - <font size=1>".
409 get_string("adminhelpassignadmins")."</font><br />";
410 $userdata .= "<font size=+1>&nbsp;</font><a href=\"creators.php\">".get_string("assigncreators")."</a> - <font size=1>".
411 get_string("adminhelpassigncreators")."</font><br />";
412 $userdata .= "<font size=+1>&nbsp;</font><a href=\"../course/index.php?edit=on\">".get_string("assignteachers")."</a> - <font size=1>".
413 get_string("adminhelpassignteachers").
414 " <img src=\"../pix/t/user.gif\" height=11 width=11></font><br />";
415 $userdata .= "<font size=+1>&nbsp;</font><a href=\"../course/index.php?edit=off\">".get_string("assignstudents")."</a> - <font size=1>".
416 get_string("adminhelpassignstudents")."</font>";
418 $table->data[] = array("<font size=+1><b><a href=\"users.php\">".get_string("users")."</a></b>", $userdata);
420 $table->data[] = array("<font size=+1><b><a href=\"../course/index.php?edit=on\">".get_string("courses")."</a></b>",
421 "<font size=+1>&nbsp;</font>".get_string("adminhelpcourses"));
422 $table->data[] = array("<font size=+1><b><a href=\"../course/log.php?id=$site->id\">".get_string("logs")."</a></b>",
423 "<font size=+1>&nbsp;</font>".get_string("adminhelplogs"));
424 $table->data[] = array("<font size=+1><b><a href=\"../files/index.php?id=$site->id\">".get_string("sitefiles")."</a></b>",
425 "<font size=+1>&nbsp;</font>".get_string("adminhelpsitefiles"));
426 if (file_exists("$CFG->dirroot/$CFG->admin/$CFG->dbtype")) {
427 $table->data[] = array("<font size=+1><b><a href=\"$CFG->dbtype/frame.php\">".get_string("managedatabase")."</a></b>",
428 "<font size=+1>&nbsp;</font>".get_string("adminhelpmanagedatabase"));
431 print_table($table);
433 //////////////////////////////////////////////////////////////////////////////////////////////////
434 //// IT IS ILLEGAL AND A VIOLATION OF THE GPL TO REMOVE OR MODIFY THE COPYRIGHT NOTICE BELOW ////
435 $copyrighttext = "<a href=\"http://moodle.org/\">Moodle</a> ".
436 "<a href=\"../doc/?frame=release.html\">$CFG->release</a> ($CFG->version)<br />".
437 "Copyright &copy; 1999-2004 Martin Dougiamas<br />".
438 "<a href=\"../doc/?frame=licence.html\">GNU Public License</a>";
439 echo "<center><p><font size=1>$copyrighttext</font></p></center>";
440 //////////////////////////////////////////////////////////////////////////////////////////////////
443 echo "<table border=0 align=center width=100%><tr>";
444 echo "<td align=center width=33%>";
445 print_single_button("$CFG->wwwroot/doc", NULL, get_string("documentation"));
446 echo "</td>";
448 echo "<td align=center width=33%>";
449 print_single_button("phpinfo.php", NULL, get_string("phpinfo"));
450 echo "</td>";
452 echo "<td align=center width=33%>";
453 print_single_button("register.php", NULL, get_string("registration"));
454 echo "</td>";
455 echo "<tr></table>";
457 print_simple_box_end();
459 print_footer($site);