Merge branch 'MDL-33682_21' of git://github.com/timhunt/moodle into MOODLE_21_STABLE
[moodle.git] / admin / environment.php
blob66ccbea55d19596a47474d2f337d4550314e02fc
1 <?php
3 ///////////////////////////////////////////////////////////////////////////
4 // //
5 // NOTICE OF COPYRIGHT //
6 // //
7 // Moodle - Modular Object-Oriented Dynamic Learning Environment //
8 // http://moodle.com //
9 // //
10 // Copyright (C) 1999 onwards Martin Dougiamas http://dougiamas.com //
11 // (C) 2001-3001 Eloy Lafuente (stronk7) http://contiento.com //
12 // //
13 // This program is free software; you can redistribute it and/or modify //
14 // it under the terms of the GNU General Public License as published by //
15 // the Free Software Foundation; either version 2 of the License, or //
16 // (at your option) any later version. //
17 // //
18 // This program is distributed in the hope that it will be useful, //
19 // but WITHOUT ANY WARRANTY; without even the implied warranty of //
20 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
21 // GNU General Public License for more details: //
22 // //
23 // http://www.gnu.org/copyleft/gpl.html //
24 // //
25 ///////////////////////////////////////////////////////////////////////////
27 // This file is the admin frontend to execute all the checks available
28 // in the environment.xml file. It includes database, php and
29 // php_extensions. Also, it's possible to update the xml file
30 // from moodle.org be able to check more and more versions.
32 require_once('../config.php');
33 require_once($CFG->libdir.'/adminlib.php');
34 require_once($CFG->libdir.'/environmentlib.php');
35 require_once($CFG->libdir.'/componentlib.class.php');
37 admin_externalpage_setup('environment');
39 /// Parameters
40 $action = optional_param('action', '', PARAM_ACTION);
41 $version = optional_param('version', '', PARAM_FILE); //
44 /// Get some strings
45 $stradmin = get_string('administration');
46 $stradminhelpenvironment = get_string("adminhelpenvironment");
47 $strenvironment = get_string('environment', 'admin');
48 $strerror = get_string('error');
49 $strmoodleversion = get_string('moodleversion');
50 $strupdate = get_string('updatecomponent', 'admin');
51 $strupwards = get_string('upwards', 'admin');
52 $strmisc = get_string('miscellaneous');
54 /// Print the header stuff
55 echo $OUTPUT->header();
57 /// Print the component download link
58 echo '<div class="reportlink"><a href="environment.php?action=updatecomponent&amp;sesskey='.sesskey().'">'.$strupdate.'</a></div>';
60 echo $OUTPUT->heading($strenvironment);
62 /// Handle the 'updatecomponent' action
63 if ($action == 'updatecomponent' && confirm_sesskey()) {
64 /// Create component installer and execute it
65 if ($cd = new component_installer('http://download.moodle.org',
66 'environment',
67 'environment.zip')) {
68 $status = $cd->install(); //returns COMPONENT_(ERROR | UPTODATE | INSTALLED)
69 switch ($status) {
70 case COMPONENT_ERROR:
71 if ($cd->get_error() == 'remotedownloaderror') {
72 $a = new stdClass();
73 $a->url = 'http://download.moodle.org/environment/environment.zip';
74 $a->dest= $CFG->dataroot.'/';
75 echo $OUTPUT->box(get_string($cd->get_error(), 'error', $a), 'errorbox');
76 } else {
77 echo $OUTPUT->box(get_string($cd->get_error(), 'error'), 'errorbox');
79 break;
80 case COMPONENT_UPTODATE:
81 echo $OUTPUT->box(get_string($cd->get_error(), 'error'));
82 break;
83 case COMPONENT_INSTALLED:
84 echo $OUTPUT->box(get_string('componentinstalled', 'admin'));
85 break;
90 /// Start of main box
91 echo $OUTPUT->box_start();
93 echo "<div style=\"text-align:center\">".$stradminhelpenvironment."</div><br />";
95 /// Get current Moodle version
96 $current_version = $CFG->release;
98 /// Calculate list of versions
99 $versions = array();
100 if ($contents = load_environment_xml()) {
101 if ($env_versions = get_list_of_environment_versions($contents)) {
102 /// Set the current version at the beginning
103 $env_version = normalize_version($current_version); //We need this later (for the upwards)
104 $versions[$env_version] = $current_version;
105 /// If no version has been previously selected, default to $current_version
106 if (empty($version)) {
107 $version = $env_version;
109 ///Iterate over each version, adding bigger than current
110 foreach ($env_versions as $env_version) {
111 if (version_compare(normalize_version($current_version), $env_version, '<')) {
112 $versions[$env_version] = $env_version;
115 /// Add 'upwards' to the last element
116 $versions[$env_version] = $env_version.' '.$strupwards;
117 } else {
118 $versions = array('error' => $strerror);
122 /// Print form and popup menu
123 echo '<div style="text-align:center"> ';
124 $select = new single_select(new moodle_url('/admin/environment.php'), 'version', $versions, $version, null);
125 $select->label = $strmoodleversion;
126 echo $OUTPUT->render($select);
127 echo '</div>';
129 /// End of main box
130 echo $OUTPUT->box_end();
132 /// Gather and show results
133 $status = check_moodle_environment($version, $environment_results);
135 /// Print footer
136 echo $OUTPUT->footer();