[moodle] / moodle / admin / index.php Repository:

Annotation of /moodle/admin/index.php

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.401 - (view) (download)

1 : skodak 1.384 <?php
2 :    
3 :     // This file is part of Moodle - http://moodle.org/
4 :     //
5 :     // Moodle is free software: you can redistribute it and/or modify
6 :     // it under the terms of the GNU General Public License as published by
7 :     // the Free Software Foundation, either version 3 of the License, or
8 :     // (at your option) any later version.
9 :     //
10 :     // Moodle is distributed in the hope that it will be useful,
11 :     // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 :     // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 :     // GNU General Public License for more details.
14 :     //
15 :     // You should have received a copy of the GNU General Public License
16 :     // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
17 :    
18 :     /**
19 :     * Main administration script.
20 :     *
21 :     * @package moodlecore
22 :     * @copyright 1999 onwards Martin Dougiamas (http://dougiamas.com)
23 :     * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
24 :     */
25 : moodler 1.55
26 : skodak 1.385 // Check that config.php exists, if not then call the install script
27 :     if (!file_exists('../config.php')) {
28 :     header('Location: ../install.php');
29 :     die;
30 :     }
31 :    
32 :     // Check that PHP is of a sufficient version as soon as possible
33 : skodak 1.386 if (version_compare(phpversion(), '5.2.0') < 0) {
34 : skodak 1.385 $phpversion = phpversion();
35 :     // do NOT localise - lang strings would not work here and we CAN NOT move it to later place
36 :     echo "Sorry, Moodle 2.0 requires PHP 5.2.8 or later (currently using version $phpversion). ";
37 :     echo "Please upgrade your server software or use latest Moodle 1.9.x instead.";
38 :     die;
39 :     }
40 :    
41 :     // try to flush everything all the time
42 :     @ob_implicit_flush(true);
43 : skodak 1.389 while(@ob_end_clean()); // ob_end_flush prevents sending of headers
44 : skodak 1.385
45 :     require('../config.php');
46 : skodak 1.386 require_once($CFG->libdir.'/adminlib.php'); // various admin-only functions
47 :     require_once($CFG->libdir.'/upgradelib.php'); // general upgrade/install related functions
48 : skodak 1.385
49 :     $id = optional_param('id', '', PARAM_TEXT);
50 :     $confirmupgrade = optional_param('confirmupgrade', 0, PARAM_BOOL);
51 :     $confirmrelease = optional_param('confirmrelease', 0, PARAM_BOOL);
52 :     $confirmplugins = optional_param('confirmplugincheck', 0, PARAM_BOOL);
53 :     $agreelicense = optional_param('agreelicense', 0, PARAM_BOOL);
54 :    
55 :     // Check some PHP server settings
56 :    
57 : tjhunt 1.394 $PAGE->set_url($CFG->admin . '/index.php');
58 :    
59 : skodak 1.385 $documentationlink = '<a href="http://docs.moodle.org/en/Installation">Installation docs</a>';
60 :    
61 :     if (ini_get_bool('session.auto_start')) {
62 :     print_error('phpvaroff', 'debug', '', (object)array('name'=>'session.auto_start', 'link'=>$documentationlink));
63 :     }
64 :    
65 :     if (ini_get_bool('magic_quotes_runtime')) {
66 :     print_error('phpvaroff', 'debug', '', (object)array('name'=>'magic_quotes_runtime', 'link'=>$documentationlink));
67 :     }
68 :    
69 :     if (!ini_get_bool('file_uploads')) {
70 :     print_error('phpvaron', 'debug', '', (object)array('name'=>'file_uploads', 'link'=>$documentationlink));
71 :     }
72 :    
73 :     if (is_float_problem()) {
74 :     print_error('phpfloatproblem', 'admin', '', $documentationlink);
75 :     }
76 :    
77 :     // Check settings in config.php
78 :    
79 : skodak 1.386 $dirroot = dirname(realpath('../index.php'));
80 : skodak 1.385 // Check correct dirroot, ignoring slashes (though should be always forward slashes). MDL-18195
81 :     if (!empty($dirroot) and str_replace('\\', '/', $dirroot) != str_replace('\\', '/', $CFG->dirroot)) {
82 :     print_error('fixsetting', 'debug', '', (object)array('current'=>$CFG->dirroot, 'found'=>str_replace('\\', '/', $dirroot)));
83 :     }
84 :    
85 :     // Set some necessary variables during set-up to avoid PHP warnings later on this page
86 :     if (!isset($CFG->framename)) {
87 : skodak 1.386 $CFG->framename = '_top';
88 : skodak 1.385 }
89 :     if (!isset($CFG->release)) {
90 : skodak 1.386 $CFG->release = '';
91 : skodak 1.385 }
92 :     if (!isset($CFG->version)) {
93 : skodak 1.386 $CFG->version = '';
94 : skodak 1.385 }
95 :    
96 :     $version = null;
97 :     $release = null;
98 :     require("$CFG->dirroot/version.php"); // defines $version and $release
99 :     $CFG->target_release = $release; // used during installation and upgrades
100 :    
101 :     if (!$version or !$release) {
102 :     print_error('withoutversion', 'debug'); // without version, stop
103 :     }
104 :    
105 :     // Turn off xmlstrictheaders during upgrade.
106 :     $origxmlstrictheaders = !empty($CFG->xmlstrictheaders);
107 :     $CFG->xmlstrictheaders = false;
108 :    
109 : skodak 1.387 if (!core_tables_exist()) {
110 : tjhunt 1.392 $PAGE->set_generaltype('maintenance');
111 : skodak 1.385
112 :     // fake some settings
113 :     $CFG->docroot = 'http://docs.moodle.org';
114 :    
115 :     $strinstallation = get_string('installation', 'install');
116 :    
117 :     // remove current session content completely
118 :     session_get_instance()->terminate_current();
119 :    
120 :     if (empty($agreelicense)) {
121 :     $strlicense = get_string('license');
122 :     $navigation = build_navigation(array(array('name'=>$strlicense, 'link'=>null, 'type'=>'misc')));
123 : skodak 1.386 print_header($strinstallation.' - Moodle '.$CFG->target_release, $strinstallation, $navigation, '', '', false, '&nbsp;', '&nbsp;');
124 : nicolasconnault 1.398 echo $OUTPUT->heading('<a href="http://moodle.org">Moodle</a> - Modular Object-Oriented Dynamic Learning Environment');
125 :     echo $OUTPUT->heading(get_string('copyrightnotice'));
126 : skodak 1.385 $copyrightnotice = text_to_html(get_string('gpl'));
127 :     $copyrightnotice = str_replace('target="_blank"', 'onclick="this.target=\'_blank\'"', $copyrightnotice); // extremely ugly validation hack
128 : nicolasconnault 1.400 echo $OUTPUT->box($copyrightnotice, 'copyrightnotice');
129 : skodak 1.386 echo '<br />';
130 : skodak 1.385 notice_yesno(get_string('doyouagree'), "index.php?agreelicense=1&lang=$CFG->lang",
131 :     "http://docs.moodle.org/en/License");
132 : nicolasconnault 1.399 echo $OUTPUT->footer();
133 : moodler 1.55 die;
134 :     }
135 : skodak 1.385 if (empty($confirmrelease)) {
136 : skodak 1.386 $strcurrentrelease = get_string('currentrelease');
137 : skodak 1.385 $navigation = build_navigation(array(array('name'=>$strcurrentrelease, 'link'=>null, 'type'=>'misc')));
138 : skodak 1.386 print_header($strinstallation.' - Moodle '.$CFG->target_release, $strinstallation, $navigation, '', '', false, '&nbsp;', '&nbsp;');
139 : nicolasconnault 1.398 echo $OUTPUT->heading("Moodle $release");
140 : skodak 1.385 $releasenoteslink = get_string('releasenoteslink', 'admin', 'http://docs.moodle.org/en/Release_Notes');
141 :     $releasenoteslink = str_replace('target="_blank"', 'onclick="this.target=\'_blank\'"', $releasenoteslink); // extremely ugly validation hack
142 : nicolasconnault 1.400 echo $OUTPUT->box($releasenoteslink, 'generalbox boxaligncenter boxwidthwide');
143 : skodak 1.385
144 :     require_once($CFG->libdir.'/environmentlib.php');
145 :     if (!check_moodle_environment($release, $environment_results, true, ENV_SELECT_RELEASE)) {
146 :     print_upgrade_reload("index.php?agreelicense=1&amp;lang=$CFG->lang");
147 :     } else {
148 : nicolasconnault 1.401 echo $OUTPUT->notification(get_string('environmentok', 'admin'), 'notifysuccess');
149 :     echo $OUTPUT->continue_button("index.php?agreelicense=1&confirmrelease=1&lang=$CFG->lang");
150 : skodak 1.385 }
151 : skodak 1.184
152 : nicolasconnault 1.399 echo $OUTPUT->footer();
153 : skodak 1.184 die;
154 :     }
155 :    
156 : skodak 1.386 $strdatabasesetup = get_string('databasesetup');
157 : skodak 1.385 $navigation = build_navigation(array(array('name'=>$strdatabasesetup, 'link'=>null, 'type'=>'misc')));
158 : tjhunt 1.391 upgrade_get_javascript();
159 :     print_header($strinstallation.' - Moodle '.$CFG->target_release, $strinstallation, $navigation, '', '', false, '&nbsp;', '&nbsp;');
160 : skodak 1.385
161 :     if (!$DB->setup_is_unicodedb()) {
162 :     if (!$DB->change_db_encoding()) {
163 :     // If could not convert successfully, throw error, and prevent installation
164 :     print_error('unicoderequired', 'admin');
165 : skodak 1.347 }
166 :     }
167 :    
168 : skodak 1.385 install_core($version, true);
169 :     }
170 : skodak 1.367
171 : skodak 1.347
172 : skodak 1.385 // Check version of Moodle code on disk compared with database
173 :     // and upgrade if possible.
174 : skodak 1.347
175 : skodak 1.385 $stradministration = get_string('administration');
176 :     $PAGE->set_context(get_context_instance(CONTEXT_SYSTEM));
177 :    
178 :     if (empty($CFG->version)) {
179 :     print_error('missingconfigversion', 'debug');
180 :     }
181 :    
182 :     if ($version > $CFG->version) { // upgrade
183 : tjhunt 1.392 $PAGE->set_generaltype('maintenance');
184 :    
185 : skodak 1.385 $a->oldversion = "$CFG->release ($CFG->version)";
186 :     $a->newversion = "$release ($version)";
187 : skodak 1.386 $strdatabasechecking = get_string('databasechecking', '', $a);
188 : skodak 1.385
189 :     if (empty($confirmupgrade)) {
190 :     $navigation = build_navigation(array(array('name'=>$strdatabasechecking, 'link'=>null, 'type'=>'misc')));
191 : skodak 1.386 print_header($strdatabasechecking, $stradministration, $navigation, '', '', false, '&nbsp;', '&nbsp;');
192 : nicolasconnault 1.397 $continueform = new html_form();
193 :     $continueform->method = 'get';
194 :     $continueform->url = new moodle_url('index.php', array('confirmupgrade' => 1));
195 :     echo $OUTPUT->confirm(get_string('upgradesure', 'admin', $a->newversion), $continueform, 'index.php');
196 : nicolasconnault 1.399 echo $OUTPUT->footer();
197 : skodak 1.385 exit;
198 :    
199 :     } else if (empty($confirmrelease)){
200 : skodak 1.386 $strcurrentrelease = get_string('currentrelease');
201 : skodak 1.385 $navigation = build_navigation(array(array('name'=>$strcurrentrelease, 'link'=>null, 'type'=>'misc')));
202 : skodak 1.386 print_header($strcurrentrelease, $strcurrentrelease, $navigation, '', '', false, '&nbsp;', '&nbsp;');
203 : nicolasconnault 1.398 echo $OUTPUT->heading("Moodle $release");
204 : skodak 1.385 $releasenoteslink = get_string('releasenoteslink', 'admin', 'http://docs.moodle.org/en/Release_Notes');
205 :     $releasenoteslink = str_replace('target="_blank"', 'onclick="this.target=\'_blank\'"', $releasenoteslink); // extremely ugly validation hack
206 : nicolasconnault 1.400 echo $OUTPUT->box($releasenoteslink);
207 : skodak 1.385
208 :     require_once($CFG->libdir.'/environmentlib.php');
209 :     if (!check_moodle_environment($release, $environment_results, true, ENV_SELECT_RELEASE)) {
210 :     print_upgrade_reload('index.php?confirmupgrade=1');
211 :     } else {
212 : nicolasconnault 1.401 echo $OUTPUT->notification(get_string('environmentok', 'admin'), 'notifysuccess');
213 : skodak 1.385 if (empty($CFG->skiplangupgrade)) {
214 : nicolasconnault 1.400 echo $OUTPUT->box_start('generalbox', 'notice');
215 : skodak 1.385 print_string('langpackwillbeupdated', 'admin');
216 : nicolasconnault 1.400 echo $OUTPUT->box_end();
217 : skodak 1.347 }
218 : nicolasconnault 1.401 echo $OUTPUT->continue_button('index.php?confirmupgrade=1&confirmrelease=1');
219 : skodak 1.347 }
220 :    
221 : nicolasconnault 1.399 echo $OUTPUT->footer();
222 : skodak 1.385 die;
223 : skodak 1.347
224 : skodak 1.385 } elseif (empty($confirmplugins)) {
225 :     $strplugincheck = get_string('plugincheck');
226 :     $navigation = build_navigation(array(array('name'=>$strplugincheck, 'link'=>null, 'type'=>'misc')));
227 : skodak 1.386 print_header($strplugincheck, $strplugincheck, $navigation, '', '', false, '&nbsp;', '&nbsp;');
228 : nicolasconnault 1.398 echo $OUTPUT->heading($strplugincheck);
229 : nicolasconnault 1.400 echo $OUTPUT->box_start('generalbox', 'notice');
230 : skodak 1.385 print_string('pluginchecknotice');
231 : nicolasconnault 1.400 echo $OUTPUT->box_end();
232 : skodak 1.385 print_plugin_tables();
233 :     print_upgrade_reload('index.php?confirmupgrade=1&amp;confirmrelease=1');
234 : nicolasconnault 1.401 echo $OUTPUT->continue_button('index.php?confirmupgrade=1&confirmrelease=1&confirmplugincheck=1');
235 : nicolasconnault 1.399 echo $OUTPUT->footer();
236 : skodak 1.385 die();
237 : skodak 1.347
238 : skodak 1.385 } else {
239 :     // Launch main upgrade
240 :     upgrade_core($version, true);
241 : skodak 1.365 }
242 : skodak 1.385 } else if ($version < $CFG->version) {
243 : nicolasconnault 1.401 echo $OUTPUT->notification('WARNING!!! The code you are using is OLDER than the version that made these databases!');
244 : skodak 1.385 }
245 :    
246 :     // Updated human-readable release version if necessary
247 :     if ($release <> $CFG->release) { // Update the release version
248 : skodak 1.386 set_config('release', $release);
249 : skodak 1.385 }
250 :    
251 :     // upgrade all plugins and other parts
252 :     upgrade_noncore(true);
253 :    
254 : tjhunt 1.390 // If this is the first install, indicate that this site is fully configured
255 :     // except the admin password
256 :     if (during_initial_install()) {
257 :     set_config('rolesactive', 1); // after this, during_initial_install will return false.
258 : skodak 1.385 set_config('adminsetuppending', 1);
259 :     // we neeed this redirect to setup proper session
260 :     upgrade_finished("index.php?sessionstarted=1&amp;lang=$CFG->lang");
261 :     }
262 :    
263 :     // make sure admin user is created - this is the last step because we need
264 :     // session to be working properly in order to edit admin account
265 :     if (!empty($CFG->adminsetuppending)) {
266 :     $sessionstarted = optional_param('sessionstarted', 0, PARAM_BOOL);
267 :     if (!$sessionstarted) {
268 :     redirect("index.php?sessionstarted=1&lang=$CFG->lang");
269 :     } else {
270 :     $sessionverify = optional_param('sessionverify', 0, PARAM_BOOL);
271 :     if (!$sessionverify) {
272 :     $SESSION->sessionverify = 1;
273 :     redirect("index.php?sessionstarted=1&sessionverify=1&lang=$CFG->lang");
274 : skodak 1.365 } else {
275 : skodak 1.385 if (empty($SESSION->sessionverify)) {
276 :     print_error('installsessionerror', 'admin', "index.php?sessionstarted=1&lang=$CFG->lang");
277 : skodak 1.365 }
278 : skodak 1.385 unset($SESSION->sessionverify);
279 : skodak 1.365 }
280 : skodak 1.385 }
281 : skodak 1.365
282 : skodak 1.385 $adminuser = get_complete_user_data('username', 'admin');
283 : skodak 1.365
284 : skodak 1.385 if ($adminuser->password === 'adminsetuppending') {
285 :     // prevent installation hijacking
286 :     if ($adminuser->lastip !== getremoteaddr()) {
287 :     print_error('installhijacked', 'admin');
288 : skodak 1.357 }
289 : skodak 1.385 // login user and let him set password and admin details
290 :     $adminuser->newadminuser = 1;
291 :     message_set_default_message_preferences($adminuser);
292 :     complete_user_login($adminuser, false);
293 :     redirect("$CFG->wwwroot/user/editadvanced.php?id=$adminuser->id"); // Edit thyself
294 : skodak 1.347
295 : skodak 1.348 } else {
296 : skodak 1.385 unset_config('adminsetuppending');
297 : skodak 1.347 }
298 : moodler 1.110
299 : skodak 1.385 } else {
300 :     // just make sure upgrade logging is properly terminated
301 :     upgrade_finished('upgradesettings.php');
302 :     }
303 :    
304 : skodak 1.365 // Turn xmlstrictheaders back on now.
305 : skodak 1.385 $CFG->xmlstrictheaders = $origxmlstrictheaders;
306 :     unset($origxmlstrictheaders);
307 : moodler 1.131
308 : skodak 1.385 // Check for valid admin user - no guest autologin
309 :     require_login(0, false);
310 :     $context = get_context_instance(CONTEXT_SYSTEM);
311 :     require_capability('moodle/site:config', $context);
312 :    
313 :     // check that site is properly customized
314 :     $site = get_site();
315 :     if (empty($site->shortname)) {
316 :     // probably new installation - lets return to frontpage after this step
317 :     // remove settings that we want uninitialised
318 :     unset_config('registerauth');
319 :     redirect('upgradesettings.php?return=site');
320 :     }
321 :    
322 :     // Check if we are returning from moodle.org registration and if so, we mark that fact to remove reminders
323 :     if (!empty($id) and $id == $CFG->siteidentifier) {
324 :     set_config('registered', time());
325 :     }
326 :    
327 :     // setup critical warnings before printing admin tree block
328 : skodak 1.386 $insecuredataroot = is_dataroot_insecure(true);
329 : skodak 1.385 $SESSION->admin_critical_warning = ($insecuredataroot==INSECURE_DATAROOT_ERROR);
330 :    
331 :     $adminroot = admin_get_root();
332 :    
333 :     // Check if there are any new admin settings which have still yet to be set
334 :     if (any_new_admin_settings($adminroot)){
335 :     redirect('upgradesettings.php');
336 :     }
337 :    
338 :     // Everything should now be set up, and the user is an admin
339 :    
340 :     // Print default admin page with notifications.
341 :     admin_externalpage_setup('adminnotifications');
342 :     admin_externalpage_print_header();
343 :    
344 :     if ($insecuredataroot == INSECURE_DATAROOT_WARNING) {
345 : nicolasconnault 1.400 echo $OUTPUT->box(get_string('datarootsecuritywarning', 'admin', $CFG->dataroot), 'generalbox adminwarning');
346 : skodak 1.385 } else if ($insecuredataroot == INSECURE_DATAROOT_ERROR) {
347 : nicolasconnault 1.400 echo $OUTPUT->box(get_string('datarootsecurityerror', 'admin', $CFG->dataroot), 'generalbox adminerror');
348 : skodak 1.385
349 :     }
350 :    
351 :     if (defined('WARN_DISPLAY_ERRORS_ENABLED')) {
352 : nicolasconnault 1.400 echo $OUTPUT->box(get_string('displayerrorswarning', 'admin'), 'generalbox adminwarning');
353 : skodak 1.385 }
354 :    
355 :     // If no recently cron run
356 :     $lastcron = $DB->get_field_sql('SELECT MAX(lastcron) FROM {modules}');
357 :     if (time() - $lastcron > 3600 * 24) {
358 :     $strinstallation = get_string('installation', 'install');
359 : nicolasconnault 1.401 $helpbutton = $OUTPUT->help_icon(moodle_help_icon::make('install', $strinstallation));
360 : nicolasconnault 1.400 echo $OUTPUT->box(get_string('cronwarning', 'admin').'&nbsp;'.$helpbutton, 'generalbox adminwarning');
361 : skodak 1.385 }
362 :    
363 :     // Print multilang upgrade notice if needed
364 :     if (empty($CFG->filter_multilang_converted)) {
365 : nicolasconnault 1.400 echo $OUTPUT->box(get_string('multilangupgradenotice', 'admin'), 'generalbox adminwarning');
366 : skodak 1.385 }
367 :    
368 :     // Alert if we are currently in maintenance mode
369 : skodak 1.388 if (!empty($CFG->maintenance_enabled)) {
370 : nicolasconnault 1.400 echo $OUTPUT->box(get_string('sitemaintenancewarning2', 'admin', "$CFG->wwwroot/$CFG->admin/settings.php?section=maintenancemode"), 'generalbox adminwarning');
371 : skodak 1.385 }
372 :    
373 :    
374 :     //////////////////////////////////////////////////////////////////////////////////////////////////
375 :     //// IT IS ILLEGAL AND A VIOLATION OF THE GPL TO HIDE, REMOVE OR MODIFY THIS COPYRIGHT NOTICE ///
376 :     $copyrighttext = '<a href="http://moodle.org/">Moodle</a> '.
377 :     '<a href="http://docs.moodle.org/en/Release" title="'.$CFG->version.'">'.$CFG->release.'</a><br />'.
378 :     'Copyright &copy; 1999 onwards, Martin Dougiamas<br />'.
379 :     'and <a href="http://docs.moodle.org/en/Credits">many other contributors</a>.<br />'.
380 :     '<a href="http://docs.moodle.org/en/License">GNU Public License</a>';
381 : nicolasconnault 1.400 echo $OUTPUT->box($copyrighttext, 'copyright');
382 : skodak 1.385 //////////////////////////////////////////////////////////////////////////////////////////////////
383 : moodler 1.78
384 : nicolasconnault 1.399 echo $OUTPUT->footer();
385 : martin 1.29

Moodle CVS Admin
ViewVC Help
Powered by ViewVC 1.0.7