Fixes bug MDL-8234, "New groups code & AS keyword"
[moodle-pu.git] / admin / environment.php
blob9e78d283dd7d123d7043da3e14bc144d1495d5ea
1 <?php //$Id$
3 ///////////////////////////////////////////////////////////////////////////
4 // //
5 // NOTICE OF COPYRIGHT //
6 // //
7 // Moodle - Modular Object-Oriented Dynamic Learning Environment //
8 // http://moodle.com //
9 // //
10 // Copyright (C) 2001-3001 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 $adminroot = admin_get_root();
38 admin_externalpage_setup('environment', $adminroot);
40 /// Parameters
41 $action = optional_param('action', '', PARAM_ACTION);
42 $version = optional_param('version', '', PARAM_FILE); //
45 /// Get some strings
46 $stradmin = get_string('administration');
47 $stradminhelpenvironment = get_string("adminhelpenvironment");
48 $strenvironment = get_string('environment', 'admin');
49 $strerror = get_string('error');
50 $strmoodleversion = get_string('moodleversion');
51 $strupdate = get_string('updatecomponent', 'admin');
52 $strupwards = get_string('upwards', 'admin');
53 $strmisc = get_string('miscellaneous');
55 /// Print the header stuff
56 admin_externalpage_print_header($adminroot);
58 /// Print the component download link
59 echo '<div class="reportlink"><a href="environment.php?action=updatecomponent&amp;sesskey='.$USER->sesskey.'">'.$strupdate.'</a></div>';
61 print_heading($strenvironment);
63 /// Handle the 'updatecomponent' action
64 if ($action == 'updatecomponent' && confirm_sesskey()) {
65 /// Create component installer and execute it
66 if ($cd = new component_installer('http://download.moodle.org',
67 'environment',
68 'environment.zip')) {
69 $status = $cd->install(); //returns ERROR | UPTODATE | INSTALLED
70 switch ($status) {
71 case ERROR:
72 if ($cd->get_error() == 'remotedownloadnotallowed') {
73 $a = new stdClass();
74 $a->url = 'http://download.moodle.org/environment/environment.zip';
75 $a->dest= $CFG->dataroot.'/';
76 print_simple_box(get_string($cd->get_error(), 'error', $a), 'center', '', '', 5, 'errorbox');
77 } else {
78 print_simple_box(get_string($cd->get_error(), 'error'), 'center', '', '', 5, 'errorbox');
80 break;
81 case UPTODATE:
82 print_simple_box(get_string($cd->get_error(), 'error'), 'center');
83 break;
84 case INSTALLED:
85 print_simple_box(get_string('componentinstalled', 'admin'), 'center');
86 break;
91 /// Start of main box
92 print_simple_box_start('center');
94 echo "<center>".$stradminhelpenvironment."</center><br />";
96 /// Get current Moodle version
97 $current_version = $CFG->release;
99 /// Calculate list of versions
100 $versions = array();
101 if ($contents = load_environment_xml()) {
102 if ($env_versions = get_list_of_environment_versions($contents)) {
103 /// Set the current version at the beginning
104 $env_version = normalize_version($current_version); //We need this later (for the upwards)
105 $versions[$env_version] = $current_version;
106 /// If no version has been previously selected, default to $current_version
107 if (empty($version)) {
108 $version = $env_version;
110 ///Iterate over each version, adding bigged than current
111 foreach ($env_versions as $env_version) {
112 if (version_compare(normalize_version($current_version), $env_version, '<')) {
113 $versions[$env_version] = $env_version;
116 /// Add 'upwards' to the last element
117 $versions[$env_version] = $env_version.' '.$strupwards;
118 } else {
119 $versions = array('error' => $strerror);
123 /// Print form and popup menu
124 echo '<div align="center">'.$strmoodleversion.' ';
125 popup_form("$CFG->wwwroot/$CFG->admin/environment.php?version=",
126 $versions, 'selectversion', $version, '');
127 echo '</div>';
129 /// End of main box
130 print_simple_box_end();
132 /// Gather and show results
133 $status = check_moodle_environment($version, $environment_results);
135 /// Print footer
136 admin_externalpage_print_footer($adminroot);