when inserting 'Give Up' button, if site encoding is not iso-8859-1, then set page...
[moodle.git] / admin / environment.php
blob8b59eb8981d5a9923d705e89dd51e74f34afe905
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.'/environmentlib.php');
34 require_once($CFG->libdir.'/componentlib.class.php');
37 /// Parameters
38 $action = optional_param('action', '', PARAM_ACTION);
39 $version = optional_param('version', '', PARAM_FILE); //
41 /// Security checks
42 require_login();
44 if (!isadmin()) {
45 error('You need to be admin to use this page');
48 if (!$site = get_site()) {
49 error("Site isn't defined!");
52 /// Get some strings
53 $stradmin = get_string('administration');
54 $stradminhelpenvironment = get_string("adminhelpenvironment");
55 $strenvironment = get_string('environment', 'admin');
56 $strerror = get_string('error');
57 $strmoodleversion = get_string('moodleversion');
58 $strupdate = get_string('updatecomponent', 'admin');
59 $strupwards = get_string('upwards', 'admin');
60 $strmisc = get_string('miscellaneous');
62 /// Print the header stuff
63 print_header("$SITE->shortname: $strenvironment", $SITE->fullname,
64 "<a href=\"index.php\">$stradmin</a> -> <a href=\"misc.php\">$strmisc</a> -> "
65 .$strenvironment);
67 /// Print the component download link
68 echo '<div class="reportlink"><a href="environment.php?action=updatecomponent&amp;sesskey='.$USER->sesskey.'">'.$strupdate.'</a></div>';
70 print_heading($strenvironment);
72 /// Handle the 'updatecomponent' action
73 if ($action == 'updatecomponent' && confirm_sesskey()) {
74 /// Create component installer and execute it
75 if ($cd = new component_installer('http://download.moodle.org',
76 'environment',
77 'environment.zip')) {
78 $status = $cd->install(); //returns ERROR | UPTODATE | INSTALLED
79 switch ($status) {
80 case ERROR:
81 if ($cd->get_error() == 'remotedownloadnotallowed') {
82 $a = new stdClass();
83 $a->url = 'http://download.moodle.org/environment/environment.zip';
84 $a->dest= $CFG->dataroot.'/';
85 print_simple_box(get_string($cd->get_error(), 'error', $a), 'center', '', '', 5, 'errorbox');
86 } else {
87 print_simple_box(get_string($cd->get_error(), 'error'), 'center', '', '', 5, 'errorbox');
89 break;
90 case UPTODATE:
91 print_simple_box(get_string($cd->get_error(), 'error'), 'center');
92 break;
93 case INSTALLED:
94 print_simple_box(get_string('componentinstalled', 'admin'), 'center');
95 break;
100 /// Start of main box
101 print_simple_box_start('center');
103 echo "<center>".$stradminhelpenvironment."</center><br />";
105 /// Get current Moodle version
106 $current_version = $CFG->release;
108 /// Calculate list of versions
109 $versions = array();
110 if ($contents = load_environment_xml()) {
111 if ($env_versions = get_list_of_environment_versions($contents)) {
112 /// Set the current version at the beginning
113 $env_version = normalize_version($current_version); //We need this later (for the upwards)
114 $versions[$env_version] = $current_version;
115 /// If no version has been previously selected, default to $current_version
116 if (empty($version)) {
117 $version = $env_version;
119 ///Iterate over each version, adding bigged than current
120 foreach ($env_versions as $env_version) {
121 if (version_compare(normalize_version($current_version), $env_version, '<')) {
122 $versions[$env_version] = $env_version;
125 /// Add 'upwards' to the last element
126 $versions[$env_version] = $env_version.' '.$strupwards;
127 } else {
128 $versions = array('error' => $strerror);
132 /// Print form and popup menu
133 echo '<center><form method="post" action="environment.php">';
134 echo $strmoodleversion.' ';
135 choose_from_menu ($versions, 'version', $version, null, 'this.form.submit();' );
136 echo '<input type="hidden" name="sesskey" value="'.$USER->sesskey.'" />';
137 echo '</form></center>';
138 /// End of main box
139 print_simple_box_end();
141 /// Gather and show results
142 $status = check_moodle_environment($version, $environment_results);
144 /// Other links
145 echo '<div align="center">';
146 print_single_button('phpinfo.php', NULL, get_string('phpinfo'));
147 echo '</div>';
149 /// Print footer
150 print_footer();