Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/admin/index.php
Go to the documentation of this file.
00001 <?php
00002 
00003 // This file is part of Moodle - http://moodle.org/
00004 //
00005 // Moodle is free software: you can redistribute it and/or modify
00006 // it under the terms of the GNU General Public License as published by
00007 // the Free Software Foundation, either version 3 of the License, or
00008 // (at your option) any later version.
00009 //
00010 // Moodle is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 // GNU General Public License for more details.
00014 //
00015 // You should have received a copy of the GNU General Public License
00016 // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
00017 
00026 // Check that config.php exists, if not then call the install script
00027 if (!file_exists('../config.php')) {
00028     header('Location: ../install.php');
00029     die();
00030 }
00031 
00032 // Check that PHP is of a sufficient version as soon as possible
00033 if (version_compare(phpversion(), '5.3.2') < 0) {
00034     $phpversion = phpversion();
00035     // do NOT localise - lang strings would not work here and we CAN NOT move it to later place
00036     echo "Moodle 2.1 or later requires at least PHP 5.3.2 (currently using version $phpversion).<br />";
00037     echo "Please upgrade your server software or install older Moodle version.";
00038     die();
00039 }
00040 
00041 // make sure iconv is available and actually works
00042 if (!function_exists('iconv')) {
00043     // this should not happen, this must be very borked install
00044     echo 'Moodle requires the iconv PHP extension. Please install or enable the iconv extension.';
00045     die();
00046 }
00047 if (iconv('UTF-8', 'UTF-8//IGNORE', 'abc') !== 'abc') {
00048     // known to be broken in mid-2011 MAMP installations
00049     echo 'Broken iconv PHP extension detected, installation/upgrade can not continue.';
00050     die();
00051 }
00052 
00053 define('NO_OUTPUT_BUFFERING', true);
00054 
00055 require('../config.php');
00056 require_once($CFG->libdir.'/adminlib.php');    // various admin-only functions
00057 require_once($CFG->libdir.'/upgradelib.php');  // general upgrade/install related functions
00058 
00059 $id             = optional_param('id', '', PARAM_TEXT);
00060 $confirmupgrade = optional_param('confirmupgrade', 0, PARAM_BOOL);
00061 $confirmrelease = optional_param('confirmrelease', 0, PARAM_BOOL);
00062 $confirmplugins = optional_param('confirmplugincheck', 0, PARAM_BOOL);
00063 $showallplugins = optional_param('showallplugins', 0, PARAM_BOOL);
00064 $agreelicense   = optional_param('agreelicense', 0, PARAM_BOOL);
00065 
00066 // Check some PHP server settings
00067 
00068 $PAGE->set_url('/admin/index.php');
00069 $PAGE->set_pagelayout('admin'); // Set a default pagelayout
00070 
00071 $documentationlink = '<a href="http://docs.moodle.org/en/Installation">Installation docs</a>';
00072 
00073 if (ini_get_bool('session.auto_start')) {
00074     print_error('phpvaroff', 'debug', '', (object)array('name'=>'session.auto_start', 'link'=>$documentationlink));
00075 }
00076 
00077 if (ini_get_bool('magic_quotes_runtime')) {
00078     print_error('phpvaroff', 'debug', '', (object)array('name'=>'magic_quotes_runtime', 'link'=>$documentationlink));
00079 }
00080 
00081 if (!ini_get_bool('file_uploads')) {
00082     print_error('phpvaron', 'debug', '', (object)array('name'=>'file_uploads', 'link'=>$documentationlink));
00083 }
00084 
00085 if (is_float_problem()) {
00086     print_error('phpfloatproblem', 'admin', '', $documentationlink);
00087 }
00088 
00089 // Set some necessary variables during set-up to avoid PHP warnings later on this page
00090 if (!isset($CFG->release)) {
00091     $CFG->release = '';
00092 }
00093 if (!isset($CFG->version)) {
00094     $CFG->version = '';
00095 }
00096 
00097 $version = null;
00098 $release = null;
00099 require("$CFG->dirroot/version.php");       // defines $version, $release and $maturity
00100 $CFG->target_release = $release;            // used during installation and upgrades
00101 
00102 if (!$version or !$release) {
00103     print_error('withoutversion', 'debug'); // without version, stop
00104 }
00105 
00106 if (!isset($maturity)) {
00107     // Fallback for now. Should probably be removed in the future.
00108     $maturity = MATURITY_STABLE;
00109 }
00110 
00111 // Turn off xmlstrictheaders during upgrade.
00112 $origxmlstrictheaders = !empty($CFG->xmlstrictheaders);
00113 $CFG->xmlstrictheaders = false;
00114 
00115 if (!core_tables_exist()) {
00116     $PAGE->set_pagelayout('maintenance');
00117     $PAGE->set_popup_notification_allowed(false);
00118 
00119     // fake some settings
00120     $CFG->docroot = 'http://docs.moodle.org';
00121 
00122     $strinstallation = get_string('installation', 'install');
00123 
00124     // remove current session content completely
00125     session_get_instance()->terminate_current();
00126 
00127     if (empty($agreelicense)) {
00128         $strlicense = get_string('license');
00129 
00130         $PAGE->navbar->add($strlicense);
00131         $PAGE->set_title($strinstallation.' - Moodle '.$CFG->target_release);
00132         $PAGE->set_heading($strinstallation);
00133         $PAGE->set_cacheable(false);
00134 
00135         $output = $PAGE->get_renderer('core', 'admin');
00136         echo $output->install_licence_page();
00137         die();
00138     }
00139     if (empty($confirmrelease)) {
00140         require_once($CFG->libdir.'/environmentlib.php');
00141         list($envstatus, $environment_results) = check_moodle_environment(normalize_version($release), ENV_SELECT_RELEASE);
00142         $strcurrentrelease = get_string('currentrelease');
00143 
00144         $PAGE->navbar->add($strcurrentrelease);
00145         $PAGE->set_title($strinstallation);
00146         $PAGE->set_heading($strinstallation . ' - Moodle ' . $CFG->target_release);
00147         $PAGE->set_cacheable(false);
00148 
00149         $output = $PAGE->get_renderer('core', 'admin');
00150         echo $output->install_environment_page($maturity, $envstatus, $environment_results, $release);
00151         die();
00152     }
00153 
00154     //TODO: add a page with list of non-standard plugins here
00155 
00156     $strdatabasesetup = get_string('databasesetup');
00157     upgrade_init_javascript();
00158 
00159     $PAGE->navbar->add($strdatabasesetup);
00160     $PAGE->set_title($strinstallation.' - Moodle '.$CFG->target_release);
00161     $PAGE->set_heading($strinstallation);
00162     $PAGE->set_cacheable(false);
00163 
00164     $output = $PAGE->get_renderer('core', 'admin');
00165     echo $output->header();
00166 
00167     if (!$DB->setup_is_unicodedb()) {
00168         if (!$DB->change_db_encoding()) {
00169             // If could not convert successfully, throw error, and prevent installation
00170             print_error('unicoderequired', 'admin');
00171         }
00172     }
00173 
00174     install_core($version, true);
00175 }
00176 
00177 
00178 // Check version of Moodle code on disk compared with database
00179 // and upgrade if possible.
00180 
00181 $stradministration = get_string('administration');
00182 $PAGE->set_context(get_context_instance(CONTEXT_SYSTEM));
00183 
00184 if (empty($CFG->version)) {
00185     print_error('missingconfigversion', 'debug');
00186 }
00187 
00188 if ($version > $CFG->version) {  // upgrade
00189     purge_all_caches();
00190     $PAGE->set_pagelayout('maintenance');
00191     $PAGE->set_popup_notification_allowed(false);
00192 
00193     if (empty($confirmupgrade)) {
00194         $a->oldversion = "$CFG->release ($CFG->version)";
00195         $a->newversion = "$release ($version)";
00196         $strdatabasechecking = get_string('databasechecking', '', $a);
00197 
00198         $PAGE->set_title($stradministration);
00199         $PAGE->set_heading($strdatabasechecking);
00200         $PAGE->set_cacheable(false);
00201 
00202         $output = $PAGE->get_renderer('core', 'admin');
00203         echo $output->upgrade_confirm_page($a->newversion, $maturity);
00204         die();
00205 
00206     } else if (empty($confirmrelease)){
00207         require_once($CFG->libdir.'/environmentlib.php');
00208         list($envstatus, $environment_results) = check_moodle_environment($release, ENV_SELECT_RELEASE);
00209         $strcurrentrelease = get_string('currentrelease');
00210 
00211         $PAGE->navbar->add($strcurrentrelease);
00212         $PAGE->set_title($strcurrentrelease);
00213         $PAGE->set_heading($strcurrentrelease);
00214         $PAGE->set_cacheable(false);
00215 
00216         $output = $PAGE->get_renderer('core', 'admin');
00217         echo $output->upgrade_environment_page($release, $envstatus, $environment_results);
00218         die();
00219 
00220     } else if (empty($confirmplugins)) {
00221         $strplugincheck = get_string('plugincheck');
00222 
00223         $PAGE->navbar->add($strplugincheck);
00224         $PAGE->set_title($strplugincheck);
00225         $PAGE->set_heading($strplugincheck);
00226         $PAGE->set_cacheable(false);
00227 
00228         $output = $PAGE->get_renderer('core', 'admin');
00229         echo $output->upgrade_plugin_check_page(plugin_manager::instance(), $version, $showallplugins,
00230                 new moodle_url('/admin/index.php', array('confirmupgrade' => 1, 'confirmrelease' => 1)),
00231                 new moodle_url('/admin/index.php', array('confirmupgrade'=>1, 'confirmrelease'=>1, 'confirmplugincheck'=>1)));
00232         die();
00233 
00234     } else {
00235         // Launch main upgrade
00236         upgrade_core($version, true);
00237     }
00238 } else if ($version < $CFG->version) {
00239     // better stop here, we can not continue with plugin upgrades or anything else
00240     throw new moodle_exception('downgradedcore', 'error', new moodle_url('/admin/'));
00241 }
00242 
00243 // Updated human-readable release version if necessary
00244 if ($release <> $CFG->release) {  // Update the release version
00245     set_config('release', $release);
00246 }
00247 
00248 if (moodle_needs_upgrading()) {
00249     if (!$PAGE->headerprinted) {
00250         // means core upgrade or installation was not already done
00251         if (!$confirmplugins) {
00252             $strplugincheck = get_string('plugincheck');
00253 
00254             $PAGE->set_pagelayout('maintenance');
00255             $PAGE->set_popup_notification_allowed(false);
00256             $PAGE->navbar->add($strplugincheck);
00257             $PAGE->set_title($strplugincheck);
00258             $PAGE->set_heading($strplugincheck);
00259             $PAGE->set_cacheable(false);
00260 
00261             $output = $PAGE->get_renderer('core', 'admin');
00262             echo $output->upgrade_plugin_check_page(plugin_manager::instance(), $version, $showallplugins,
00263                     new moodle_url('/admin/index.php'),
00264                     new moodle_url('/admin/index.php', array('confirmplugincheck'=>1)));
00265             die();
00266         }
00267     }
00268     // install/upgrade all plugins and other parts
00269     upgrade_noncore(true);
00270 }
00271 
00272 // If this is the first install, indicate that this site is fully configured
00273 // except the admin password
00274 if (during_initial_install()) {
00275     set_config('rolesactive', 1); // after this, during_initial_install will return false.
00276     set_config('adminsetuppending', 1);
00277     // we need this redirect to setup proper session
00278     upgrade_finished("index.php?sessionstarted=1&amp;lang=$CFG->lang");
00279 }
00280 
00281 // make sure admin user is created - this is the last step because we need
00282 // session to be working properly in order to edit admin account
00283  if (!empty($CFG->adminsetuppending)) {
00284     $sessionstarted = optional_param('sessionstarted', 0, PARAM_BOOL);
00285     if (!$sessionstarted) {
00286         redirect("index.php?sessionstarted=1&lang=$CFG->lang");
00287     } else {
00288         $sessionverify = optional_param('sessionverify', 0, PARAM_BOOL);
00289         if (!$sessionverify) {
00290             $SESSION->sessionverify = 1;
00291             redirect("index.php?sessionstarted=1&sessionverify=1&lang=$CFG->lang");
00292         } else {
00293             if (empty($SESSION->sessionverify)) {
00294                 print_error('installsessionerror', 'admin', "index.php?sessionstarted=1&lang=$CFG->lang");
00295             }
00296             unset($SESSION->sessionverify);
00297         }
00298     }
00299 
00300     // at this stage there can be only one admin - users may change username, so do not rely on that
00301     $adminuser = get_complete_user_data('id', $CFG->siteadmins);
00302 
00303     if ($adminuser->password === 'adminsetuppending') {
00304         // prevent installation hijacking
00305         if ($adminuser->lastip !== getremoteaddr()) {
00306             print_error('installhijacked', 'admin');
00307         }
00308         // login user and let him set password and admin details
00309         $adminuser->newadminuser = 1;
00310         complete_user_login($adminuser);
00311         redirect("$CFG->wwwroot/user/editadvanced.php?id=$adminuser->id"); // Edit thyself
00312 
00313     } else {
00314         unset_config('adminsetuppending');
00315     }
00316 
00317 } else {
00318     // just make sure upgrade logging is properly terminated
00319     upgrade_finished('upgradesettings.php');
00320 }
00321 
00322 // Turn xmlstrictheaders back on now.
00323 $CFG->xmlstrictheaders = $origxmlstrictheaders;
00324 unset($origxmlstrictheaders);
00325 
00326 // Check for valid admin user - no guest autologin
00327 require_login(0, false);
00328 $context = get_context_instance(CONTEXT_SYSTEM);
00329 require_capability('moodle/site:config', $context);
00330 
00331 // check that site is properly customized
00332 $site = get_site();
00333 if (empty($site->shortname)) {
00334     // probably new installation - lets return to frontpage after this step
00335     // remove settings that we want uninitialised
00336     unset_config('registerauth');
00337     redirect('upgradesettings.php?return=site');
00338 }
00339 
00340 // Check if we are returning from moodle.org registration and if so, we mark that fact to remove reminders
00341 if (!empty($id) and $id == $CFG->siteidentifier) {
00342     set_config('registered', time());
00343 }
00344 
00345 // setup critical warnings before printing admin tree block
00346 $insecuredataroot = is_dataroot_insecure(true);
00347 $SESSION->admin_critical_warning = ($insecuredataroot==INSECURE_DATAROOT_ERROR);
00348 
00349 $adminroot = admin_get_root();
00350 
00351 // Check if there are any new admin settings which have still yet to be set
00352 if (any_new_admin_settings($adminroot)){
00353     redirect('upgradesettings.php');
00354 }
00355 
00356 // Everything should now be set up, and the user is an admin
00357 
00358 // Print default admin page with notifications.
00359 $errorsdisplayed = defined('WARN_DISPLAY_ERRORS_ENABLED');
00360 
00361 $lastcron = $DB->get_field_sql('SELECT MAX(lastcron) FROM {modules}');
00362 $cronoverdue = ($lastcron < time() - 3600 * 24);
00363 $dbproblems = $DB->diagnose();
00364 $maintenancemode = !empty($CFG->maintenance_enabled);
00365 
00366 admin_externalpage_setup('adminnotifications');
00367 $output = $PAGE->get_renderer('core', 'admin');
00368 echo $output->admin_notifications_page($maturity, $insecuredataroot, $errorsdisplayed,
00369         $cronoverdue, $dbproblems, $maintenancemode);
 All Data Structures Namespaces Files Functions Variables Enumerations