file SafeEmbed.php was added on branch MOODLE_19_STABLE on 2010-05-21 11:39:45 +0000
[moodle.git] / admin / environment.php
blob74eb8f04c13c0fd068db449b09adb8c4c8e343de
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) 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 admin_externalpage_print_header();
57 /// Print the component download link
58 echo '<div class="reportlink"><a href="environment.php?action=updatecomponent&amp;sesskey='.$USER->sesskey.'">'.$strupdate.'</a></div>';
60 print_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 print_simple_box(get_string($cd->get_error(), 'error', $a), 'center', '', '', 5, 'errorbox');
76 } else {
77 print_simple_box(get_string($cd->get_error(), 'error'), 'center', '', '', 5, 'errorbox');
79 break;
80 case COMPONENT_UPTODATE:
81 print_simple_box(get_string($cd->get_error(), 'error'), 'center');
82 break;
83 case COMPONENT_INSTALLED:
84 print_simple_box(get_string('componentinstalled', 'admin'), 'center');
85 break;
90 /// Start of main box
91 print_simple_box_start('center');
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 bigged 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">'.$strmoodleversion.' ';
124 popup_form("$CFG->wwwroot/$CFG->admin/environment.php?version=",
125 $versions, 'selectversion', $version, '');
126 echo '</div>';
128 /// End of main box
129 print_simple_box_end();
131 /// Gather and show results
132 $status = check_moodle_environment($version, $environment_results);
134 /// Print footer
135 admin_externalpage_print_footer();