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

Annotation of /moodle/admin/index.php

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.405 - (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 : samhemelryk 1.404 $PAGE->navbar->add($strlicense);
123 :     $PAGE->set_title($strinstallation.' - Moodle '.$CFG->target_release);
124 :     $PAGE->set_heading($strinstallation);
125 :     $PAGE->set_cacheable(false);
126 :     echo $OUTPUT->header();
127 : nicolasconnault 1.398 echo $OUTPUT->heading('<a href="http://moodle.org">Moodle</a> - Modular Object-Oriented Dynamic Learning Environment');
128 :     echo $OUTPUT->heading(get_string('copyrightnotice'));
129 : skodak 1.385 $copyrightnotice = text_to_html(get_string('gpl'));
130 :     $copyrightnotice = str_replace('target="_blank"', 'onclick="this.target=\'_blank\'"', $copyrightnotice); // extremely ugly validation hack
131 : nicolasconnault 1.400 echo $OUTPUT->box($copyrightnotice, 'copyrightnotice');
132 : skodak 1.386 echo '<br />';
133 : nicolasconnault 1.402 echo $OUTPUT->confirm(get_string('doyouagree'), "index.php?agreelicense=1&lang=$CFG->lang", "http://docs.moodle.org/en/License");
134 : nicolasconnault 1.399 echo $OUTPUT->footer();
135 : moodler 1.55 die;
136 :     }
137 : skodak 1.385 if (empty($confirmrelease)) {
138 : skodak 1.386 $strcurrentrelease = get_string('currentrelease');
139 : samhemelryk 1.404 $PAGE->navbar->add($strcurrentrelease);
140 :     $PAGE->set_title($strinstallation.' - Moodle '.$CFG->target_release);
141 :     $PAGE->set_heading($strinstallation);
142 :     $PAGE->set_cacheable(false);
143 :     echo $OUTPUT->header();
144 : nicolasconnault 1.398 echo $OUTPUT->heading("Moodle $release");
145 : skodak 1.385 $releasenoteslink = get_string('releasenoteslink', 'admin', 'http://docs.moodle.org/en/Release_Notes');
146 :     $releasenoteslink = str_replace('target="_blank"', 'onclick="this.target=\'_blank\'"', $releasenoteslink); // extremely ugly validation hack
147 : nicolasconnault 1.400 echo $OUTPUT->box($releasenoteslink, 'generalbox boxaligncenter boxwidthwide');
148 : skodak 1.385
149 :     require_once($CFG->libdir.'/environmentlib.php');
150 :     if (!check_moodle_environment($release, $environment_results, true, ENV_SELECT_RELEASE)) {
151 :     print_upgrade_reload("index.php?agreelicense=1&amp;lang=$CFG->lang");
152 :     } else {
153 : nicolasconnault 1.401 echo $OUTPUT->notification(get_string('environmentok', 'admin'), 'notifysuccess');
154 :     echo $OUTPUT->continue_button("index.php?agreelicense=1&confirmrelease=1&lang=$CFG->lang");
155 : skodak 1.385 }
156 : skodak 1.184
157 : nicolasconnault 1.399 echo $OUTPUT->footer();
158 : skodak 1.184 die;
159 :     }
160 :    
161 : skodak 1.386 $strdatabasesetup = get_string('databasesetup');
162 : tjhunt 1.391 upgrade_get_javascript();
163 : samhemelryk 1.404 $PAGE->navbar->add($strdatabasesetup);
164 :     $PAGE->set_title($strinstallation.' - Moodle '.$CFG->target_release);
165 : samhemelryk 1.405 $PAGE->set_heading($strinstallation);
166 : samhemelryk 1.404 $PAGE->set_cacheable(false);
167 :     echo $OUTPUT->header();
168 : skodak 1.385
169 :     if (!$DB->setup_is_unicodedb()) {
170 :     if (!$DB->change_db_encoding()) {
171 :     // If could not convert successfully, throw error, and prevent installation
172 :     print_error('unicoderequired', 'admin');
173 : skodak 1.347 }
174 :     }
175 :    
176 : skodak 1.385 install_core($version, true);
177 :     }
178 : skodak 1.367
179 : skodak 1.347
180 : skodak 1.385 // Check version of Moodle code on disk compared with database
181 :     // and upgrade if possible.
182 : skodak 1.347
183 : skodak 1.385 $stradministration = get_string('administration');
184 :     $PAGE->set_context(get_context_instance(CONTEXT_SYSTEM));
185 :    
186 :     if (empty($CFG->version)) {
187 :     print_error('missingconfigversion', 'debug');
188 :     }
189 :    
190 :     if ($version > $CFG->version) { // upgrade
191 : tjhunt 1.392 $PAGE->set_generaltype('maintenance');
192 :    
193 : skodak 1.385 $a->oldversion = "$CFG->release ($CFG->version)";
194 :     $a->newversion = "$release ($version)";
195 : skodak 1.386 $strdatabasechecking = get_string('databasechecking', '', $a);
196 : skodak 1.385
197 :     if (empty($confirmupgrade)) {
198 : samhemelryk 1.404 $PAGE->navbar->add($strdatabasechecking);
199 :     $PAGE->set_title($strdatabasechecking);
200 :     $PAGE->heading($stradministration);
201 :     $PAGE->set_cacheable(false);
202 :     echo $OUTPUT->header();
203 : nicolasconnault 1.397 $continueform = new html_form();
204 :     $continueform->method = 'get';
205 :     $continueform->url = new moodle_url('index.php', array('confirmupgrade' => 1));
206 : nicolasconnault 1.403 $cancelform = new html_form();
207 :     $cancelform->url = new moodle_url('index.php');
208 :     $cancelform->button->text = get_string('no');
209 :     echo $OUTPUT->confirm(get_string('upgradesure', 'admin', $a->newversion), $continueform, $cancelform);
210 : nicolasconnault 1.399 echo $OUTPUT->footer();
211 : skodak 1.385 exit;
212 :    
213 :     } else if (empty($confirmrelease)){
214 : skodak 1.386 $strcurrentrelease = get_string('currentrelease');
215 : samhemelryk 1.404 $PAGE->navbar->add($strcurrentrelease);
216 :     $PAGE->set_title($strcurrentrelease);
217 :     $PAGE->heading($strcurrentrelease);
218 :     $PAGE->set_cacheable(false);
219 :     echo $OUTPUT->header();
220 : nicolasconnault 1.398 echo $OUTPUT->heading("Moodle $release");
221 : skodak 1.385 $releasenoteslink = get_string('releasenoteslink', 'admin', 'http://docs.moodle.org/en/Release_Notes');
222 :     $releasenoteslink = str_replace('target="_blank"', 'onclick="this.target=\'_blank\'"', $releasenoteslink); // extremely ugly validation hack
223 : nicolasconnault 1.400 echo $OUTPUT->box($releasenoteslink);
224 : skodak 1.385
225 :     require_once($CFG->libdir.'/environmentlib.php');
226 :     if (!check_moodle_environment($release, $environment_results, true, ENV_SELECT_RELEASE)) {
227 :     print_upgrade_reload('index.php?confirmupgrade=1');
228 :     } else {
229 : nicolasconnault 1.401 echo $OUTPUT->notification(get_string('environmentok', 'admin'), 'notifysuccess');
230 : skodak 1.385 if (empty($CFG->skiplangupgrade)) {
231 : nicolasconnault 1.400 echo $OUTPUT->box_start('generalbox', 'notice');
232 : skodak 1.385 print_string('langpackwillbeupdated', 'admin');
233 : nicolasconnault 1.400 echo $OUTPUT->box_end();
234 : skodak 1.347 }
235 : nicolasconnault 1.401 echo $OUTPUT->continue_button('index.php?confirmupgrade=1&confirmrelease=1');
236 : skodak 1.347 }
237 :    
238 : nicolasconnault 1.399 echo $OUTPUT->footer();
239 : skodak 1.385 die;
240 : skodak 1.347
241 : skodak 1.385 } elseif (empty($confirmplugins)) {
242 :     $strplugincheck = get_string('plugincheck');
243 : samhemelryk 1.404 $PAGE->navbar->add($strplugincheck);
244 :     $PAGE->set_title($strplugincheck);
245 :     $PAGE->heading($strplugincheck);
246 :     $PAGE->set_cacheable(false);
247 :     echo $OUTPUT->header();
248 : nicolasconnault 1.398 echo $OUTPUT->heading($strplugincheck);
249 : nicolasconnault 1.400 echo $OUTPUT->box_start('generalbox', 'notice');
250 : skodak 1.385 print_string('pluginchecknotice');
251 : nicolasconnault 1.400 echo $OUTPUT->box_end();
252 : skodak 1.385 print_plugin_tables();
253 :     print_upgrade_reload('index.php?confirmupgrade=1&amp;confirmrelease=1');
254 : nicolasconnault 1.401 echo $OUTPUT->continue_button('index.php?confirmupgrade=1&confirmrelease=1&confirmplugincheck=1');
255 : nicolasconnault 1.399 echo $OUTPUT->footer();
256 : skodak 1.385 die();
257 : skodak 1.347
258 : skodak 1.385 } else {
259 :     // Launch main upgrade
260 :     upgrade_core($version, true);
261 : skodak 1.365 }
262 : skodak 1.385 } else if ($version < $CFG->version) {
263 : nicolasconnault 1.401 echo $OUTPUT->notification('WARNING!!! The code you are using is OLDER than the version that made these databases!');
264 : skodak 1.385 }
265 :    
266 :     // Updated human-readable release version if necessary
267 :     if ($release <> $CFG->release) { // Update the release version
268 : skodak 1.386 set_config('release', $release);
269 : skodak 1.385 }
270 :    
271 :     // upgrade all plugins and other parts
272 :     upgrade_noncore(true);
273 :    
274 : tjhunt 1.390 // If this is the first install, indicate that this site is fully configured
275 :     // except the admin password
276 :     if (during_initial_install()) {
277 :     set_config('rolesactive', 1); // after this, during_initial_install will return false.
278 : skodak 1.385 set_config('adminsetuppending', 1);
279 :     // we neeed this redirect to setup proper session
280 :     upgrade_finished("index.php?sessionstarted=1&amp;lang=$CFG->lang");
281 :     }
282 :    
283 :     // make sure admin user is created - this is the last step because we need
284 :     // session to be working properly in order to edit admin account
285 :     if (!empty($CFG->adminsetuppending)) {
286 :     $sessionstarted = optional_param('sessionstarted', 0, PARAM_BOOL);
287 :     if (!$sessionstarted) {
288 :     redirect("index.php?sessionstarted=1&lang=$CFG->lang");
289 :     } else {
290 :     $sessionverify = optional_param('sessionverify', 0, PARAM_BOOL);
291 :     if (!$sessionverify) {
292 :     $SESSION->sessionverify = 1;
293 :     redirect("index.php?sessionstarted=1&sessionverify=1&lang=$CFG->lang");
294 : skodak 1.365 } else {
295 : skodak 1.385 if (empty($SESSION->sessionverify)) {
296 :     print_error('installsessionerror', 'admin', "index.php?sessionstarted=1&lang=$CFG->lang");
297 : skodak 1.365 }
298 : skodak 1.385 unset($SESSION->sessionverify);
299 : skodak 1.365 }
300 : skodak 1.385 }
301 : skodak 1.365
302 : skodak 1.385 $adminuser = get_complete_user_data('username', 'admin');
303 : skodak 1.365
304 : skodak 1.385 if ($adminuser->password === 'adminsetuppending') {
305 :     // prevent installation hijacking
306 :     if ($adminuser->lastip !== getremoteaddr()) {
307 :     print_error('installhijacked', 'admin');
308 : skodak 1.357 }
309 : skodak 1.385 // login user and let him set password and admin details
310 :     $adminuser->newadminuser = 1;
311 :     message_set_default_message_preferences($adminuser);
312 :     complete_user_login($adminuser, false);
313 :     redirect("$CFG->wwwroot/user/editadvanced.php?id=$adminuser->id"); // Edit thyself
314 : skodak 1.347
315 : skodak 1.348 } else {
316 : skodak 1.385 unset_config('adminsetuppending');
317 : skodak 1.347 }
318 : moodler 1.110
319 : skodak 1.385 } else {
320 :     // just make sure upgrade logging is properly terminated
321 :     upgrade_finished('upgradesettings.php');
322 :     }
323 :    
324 : skodak 1.365 // Turn xmlstrictheaders back on now.
325 : skodak 1.385 $CFG->xmlstrictheaders = $origxmlstrictheaders;
326 :     unset($origxmlstrictheaders);
327 : moodler 1.131
328 : skodak 1.385 // Check for valid admin user - no guest autologin
329 :     require_login(0, false);
330 :     $context = get_context_instance(CONTEXT_SYSTEM);
331 :     require_capability('moodle/site:config', $context);
332 :    
333 :     // check that site is properly customized
334 :     $site = get_site();
335 :     if (empty($site->shortname)) {
336 :     // probably new installation - lets return to frontpage after this step
337 :     // remove settings that we want uninitialised
338 :     unset_config('registerauth');
339 :     redirect('upgradesettings.php?return=site');
340 :     }
341 :    
342 :     // Check if we are returning from moodle.org registration and if so, we mark that fact to remove reminders
343 :     if (!empty($id) and $id == $CFG->siteidentifier) {
344 :     set_config('registered', time());
345 :     }
346 :    
347 :     // setup critical warnings before printing admin tree block
348 : skodak 1.386 $insecuredataroot = is_dataroot_insecure(true);
349 : skodak 1.385 $SESSION->admin_critical_warning = ($insecuredataroot==INSECURE_DATAROOT_ERROR);
350 :    
351 :     $adminroot = admin_get_root();
352 :    
353 :     // Check if there are any new admin settings which have still yet to be set
354 :     if (any_new_admin_settings($adminroot)){
355 :     redirect('upgradesettings.php');
356 :     }
357 :    
358 :     // Everything should now be set up, and the user is an admin
359 :    
360 :     // Print default admin page with notifications.
361 :     admin_externalpage_setup('adminnotifications');
362 :     admin_externalpage_print_header();
363 :    
364 :     if ($insecuredataroot == INSECURE_DATAROOT_WARNING) {
365 : nicolasconnault 1.400 echo $OUTPUT->box(get_string('datarootsecuritywarning', 'admin', $CFG->dataroot), 'generalbox adminwarning');
366 : skodak 1.385 } else if ($insecuredataroot == INSECURE_DATAROOT_ERROR) {
367 : nicolasconnault 1.400 echo $OUTPUT->box(get_string('datarootsecurityerror', 'admin', $CFG->dataroot), 'generalbox adminerror');
368 : skodak 1.385
369 :     }
370 :    
371 :     if (defined('WARN_DISPLAY_ERRORS_ENABLED')) {
372 : nicolasconnault 1.400 echo $OUTPUT->box(get_string('displayerrorswarning', 'admin'), 'generalbox adminwarning');
373 : skodak 1.385 }
374 :    
375 :     // If no recently cron run
376 :     $lastcron = $DB->get_field_sql('SELECT MAX(lastcron) FROM {modules}');
377 :     if (time() - $lastcron > 3600 * 24) {
378 :     $strinstallation = get_string('installation', 'install');
379 : nicolasconnault 1.401 $helpbutton = $OUTPUT->help_icon(moodle_help_icon::make('install', $strinstallation));
380 : nicolasconnault 1.400 echo $OUTPUT->box(get_string('cronwarning', 'admin').'&nbsp;'.$helpbutton, 'generalbox adminwarning');
381 : skodak 1.385 }
382 :    
383 :     // Print multilang upgrade notice if needed
384 :     if (empty($CFG->filter_multilang_converted)) {
385 : nicolasconnault 1.400 echo $OUTPUT->box(get_string('multilangupgradenotice', 'admin'), 'generalbox adminwarning');
386 : skodak 1.385 }
387 :    
388 :     // Alert if we are currently in maintenance mode
389 : skodak 1.388 if (!empty($CFG->maintenance_enabled)) {
390 : nicolasconnault 1.400 echo $OUTPUT->box(get_string('sitemaintenancewarning2', 'admin', "$CFG->wwwroot/$CFG->admin/settings.php?section=maintenancemode"), 'generalbox adminwarning');
391 : skodak 1.385 }
392 :    
393 :    
394 :     //////////////////////////////////////////////////////////////////////////////////////////////////
395 :     //// IT IS ILLEGAL AND A VIOLATION OF THE GPL TO HIDE, REMOVE OR MODIFY THIS COPYRIGHT NOTICE ///
396 :     $copyrighttext = '<a href="http://moodle.org/">Moodle</a> '.
397 :     '<a href="http://docs.moodle.org/en/Release" title="'.$CFG->version.'">'.$CFG->release.'</a><br />'.
398 :     'Copyright &copy; 1999 onwards, Martin Dougiamas<br />'.
399 :     'and <a href="http://docs.moodle.org/en/Credits">many other contributors</a>.<br />'.
400 :     '<a href="http://docs.moodle.org/en/License">GNU Public License</a>';
401 : nicolasconnault 1.400 echo $OUTPUT->box($copyrighttext, 'copyright');
402 : skodak 1.385 //////////////////////////////////////////////////////////////////////////////////////////////////
403 : moodler 1.78
404 : nicolasconnault 1.399 echo $OUTPUT->footer();
405 : martin 1.29

Moodle CVS Admin
ViewVC Help
Powered by ViewVC 1.0.7