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

Annotation of /moodle/admin/index.php

Parent Directory Parent Directory | Revision Log Revision Log


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

Moodle CVS Admin
ViewVC Help
Powered by ViewVC 1.0.7