95feaf96 |
1 | <?php |
2 | |
3 | // This file is part of Moodle - http://moodle.org/ |
4 | // |
5 | // Moodle is free software: you can redistribute it and/or modify |
6 | // it under the terms of the GNU General Public License as published by |
7 | // the Free Software Foundation, either version 3 of the License, or |
8 | // (at your option) any later version. |
9 | // |
10 | // Moodle is distributed in the hope that it will be useful, |
11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13 | // GNU General Public License for more details. |
14 | // |
15 | // You should have received a copy of the GNU General Public License |
16 | // along with Moodle. If not, see <http://www.gnu.org/licenses/>. |
2f13f94c |
17 | |
2f13f94c |
18 | /** |
9d068cd6 |
19 | * Functions to support installation process |
95feaf96 |
20 | * |
21 | * @package moodlecore |
22 | * @subpackage install |
23 | * @copyright 2009 Petr Skoda (http://skodak.org) |
24 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later |
2f13f94c |
25 | */ |
2f13f94c |
26 | |
3b093310 |
27 | define('INSTALL_WELCOME', 0); |
64c368e3 |
28 | define('INSTALL_ENVIRONMENT', 1); |
29 | define('INSTALL_PATHS', 2); |
30 | define('INSTALL_DOWNLOADLANG', 3); |
31 | define('INSTALL_DATABASETYPE', 4); |
32 | define('INSTALL_DATABASE', 5); |
33 | define('INSTALL_SAVE', 6); |
3b093310 |
34 | |
11e7b506 |
35 | /** |
36 | *Tries to detect the right www root setting. |
11e7b506 |
37 | * @return string detected www root |
38 | */ |
39 | function install_guess_wwwroot() { |
40 | $wwwroot = ''; |
41 | if (empty($_SERVER['HTTPS']) or $_SERVER['HTTPS'] == 'off') { |
42 | $wwwroot .= 'http://'; |
43 | } else { |
44 | $wwwroot .= 'https://'; |
45 | } |
46 | $hostport = explode(':', $_SERVER['HTTP_HOST']); |
47 | $wwwroot .= reset($hostport); |
48 | if ($_SERVER['SERVER_PORT'] != 80 and $_SERVER['SERVER_PORT'] != '443') { |
49 | $wwwroot .= ':'.$_SERVER['SERVER_PORT']; |
50 | } |
51 | $wwwroot .= $_SERVER['SCRIPT_NAME']; |
52 | |
53 | list($wwwroot, $xtra) = explode('/install.php', $wwwroot); |
54 | |
55 | return $wwwroot; |
56 | } |
57 | |
95feaf96 |
58 | /** |
59 | * Copy of @see{ini_get_bool()} |
60 | * @param string $ini_get_arg |
61 | * @return bool |
62 | */ |
3b093310 |
63 | function install_ini_get_bool($ini_get_arg) { |
64 | $temp = ini_get($ini_get_arg); |
65 | |
66 | if ($temp == '1' or strtolower($temp) == 'on') { |
67 | return true; |
68 | } |
69 | return false; |
70 | } |
71 | |
95feaf96 |
72 | /** |
73 | * Print help button |
74 | * @param string $url |
75 | * @param string $titel |
76 | * @return void |
77 | */ |
3b093310 |
78 | function install_helpbutton($url, $title='') { |
79 | if ($title == '') { |
80 | $title = get_string('help'); |
81 | } |
82 | echo "<a href=\"javascript:void(0)\" "; |
83 | echo "onclick=\"return window.open('$url','Help','menubar=0,location=0,scrollbars,resizable,width=500,height=400')\""; |
84 | echo ">"; |
85 | echo "<img src=\"pix/help.gif\" class=\"iconhelp\" alt=\"$title\" title=\"$title\"/>"; |
86 | echo "</a>\n"; |
87 | } |
88 | |
95feaf96 |
89 | /** |
90 | * This is in function because we want the /install.php to parse in PHP4 |
91 | */ |
768408e8 |
92 | function install_db_validate($database, $dbhost, $dbuser, $dbpass, $dbname, $prefix, $dboptions) { |
3b093310 |
93 | try { |
94 | try { |
95 | $database->connect($dbhost, $dbuser, $dbpass, $dbname, $prefix, $dboptions); |
96 | } catch (moodle_exception $e) { |
97 | // let's try to create new database |
98 | if ($database->create_database($dbhost, $dbuser, $dbpass, $dbname, $dboptions)) { |
99 | $database->connect($dbhost, $dbuser, $dbpass, $dbname, $prefix, $dboptions); |
100 | } else { |
101 | throw $e; |
102 | } |
103 | } |
104 | return ''; |
105 | } catch (dml_exception $ex) { |
106 | return get_string($ex->errorcode, $ex->module, $ex->a).'<br />'.$ex->debuginfo; |
107 | } |
108 | } |
109 | |
2f13f94c |
110 | /** |
9d068cd6 |
111 | * This function returns a list of languages and their full names. The |
112 | * list of available languages is fetched from install/lang/xx/installer.php |
113 | * and it's used exclusively by the installation process |
2f13f94c |
114 | * @return array An associative array with contents in the form of LanguageCode => LanguageName |
115 | */ |
3b093310 |
116 | function install_get_list_of_languages() { |
2f13f94c |
117 | global $CFG; |
118 | |
119 | $languages = array(); |
120 | |
9d068cd6 |
121 | /// Get raw list of lang directories |
2f13f94c |
122 | $langdirs = get_list_of_plugins('install/lang'); |
123 | asort($langdirs); |
9d068cd6 |
124 | /// Get some info from each lang |
2f13f94c |
125 | foreach ($langdirs as $lang) { |
3b093310 |
126 | if ($lang == 'en') { |
127 | continue; |
128 | } |
129 | if (file_exists($CFG->dirroot.'/install/lang/'.$lang.'/installer.php')) { |
130 | $string = array(); |
131 | include($CFG->dirroot.'/install/lang/'.$lang.'/installer.php'); |
132 | if (substr($lang, -5) === '_utf8') { //Remove the _utf8 suffix from the lang to show |
2f13f94c |
133 | $shortlang = substr($lang, 0, -5); |
134 | } else { |
135 | $shortlang = $lang; |
136 | } |
2f13f94c |
137 | if (!empty($string['thislanguage'])) { |
3b093310 |
138 | $languages[$lang] = $string['thislanguage'].' ('.$shortlang.')'; |
2f13f94c |
139 | } |
2f13f94c |
140 | } |
141 | } |
9d068cd6 |
142 | /// Return array |
2f13f94c |
143 | return $languages; |
144 | } |
2f13f94c |
145 | |
95feaf96 |
146 | /** |
147 | * Prints complete help page used during installation. |
148 | * Does not return. |
149 | * @param string $help |
150 | */ |
3b093310 |
151 | function install_print_help_page($help) { |
152 | global $CFG; |
153 | |
154 | @header('Content-Type: text/html; charset=UTF-8'); |
155 | @header('Cache-Control: no-store, no-cache, must-revalidate'); |
156 | @header('Cache-Control: post-check=0, pre-check=0', false); |
157 | @header('Pragma: no-cache'); |
158 | @header('Expires: Mon, 20 Aug 1969 09:23:00 GMT'); |
159 | @header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT'); |
160 | |
161 | echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">'; |
162 | echo '<html dir="'.(right_to_left() ? 'rtl' : 'ltr').'"> |
163 | <head> |
164 | <link rel="shortcut icon" href="theme/standard/favicon.ico" /> |
165 | <link rel="stylesheet" type="text/css" href="'.$CFG->wwwroot.'/install.php?css=1" /> |
166 | <title>'.get_string('installation','install').'</title> |
167 | <meta http-equiv="content-type" content="text/html; charset=UTF-8" /> |
168 | <meta http-equiv="pragma" content="no-cache" /> |
169 | <meta http-equiv="expires" content="0" />'; |
170 | |
171 | echo '</head><body>'; |
172 | switch ($help) { |
173 | case 'phpversionhelp': |
174 | print_string($help, 'install', phpversion()); |
175 | break; |
176 | case 'memorylimithelp': |
177 | print_string($help, 'install', get_memory_limit()); |
178 | break; |
179 | default: |
180 | print_string($help, 'install'); |
2f13f94c |
181 | } |
3b093310 |
182 | close_window_button(); |
183 | echo '</body></html>'; |
184 | die; |
2f13f94c |
185 | } |
186 | |
95feaf96 |
187 | /** |
188 | * Prints installation page header, we can no use weblib yet in isntaller. |
189 | * @param array $config |
190 | * @param string $stagename |
191 | * @param string $heading |
192 | * @param string $stagetext |
193 | * @return void |
194 | */ |
3b093310 |
195 | function install_print_header($config, $stagename, $heading, $stagetext) { |
196 | global $CFG; |
2f13f94c |
197 | |
3b093310 |
198 | @header('Content-Type: text/html; charset=UTF-8'); |
199 | @header('Cache-Control: no-store, no-cache, must-revalidate'); |
200 | @header('Cache-Control: post-check=0, pre-check=0', false); |
201 | @header('Pragma: no-cache'); |
202 | @header('Expires: Mon, 20 Aug 1969 09:23:00 GMT'); |
203 | @header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT'); |
204 | |
205 | echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">'; |
206 | echo '<html dir="'.(right_to_left() ? 'rtl' : 'ltr').'"> |
207 | <head> |
208 | <link rel="shortcut icon" href="theme/standard/favicon.ico" />'; |
209 | |
210 | $sheets = array('styles_layout', 'styles_fonts', 'styles_color', 'styles_moz'); |
211 | $csss = array(); |
212 | foreach ($sheets as $sheet) { |
213 | $csss[] = $CFG->wwwroot.'/theme/standard/'.$sheet.'.css'; |
214 | } |
215 | $sheets = array('gradients'); |
216 | foreach ($sheets as $sheet) { |
217 | $csss[] = $CFG->wwwroot.'/theme/standardwhite/'.$sheet.'.css'; |
2f13f94c |
218 | } |
3b093310 |
219 | foreach ($csss as $css) { |
220 | echo '<link rel="stylesheet" type="text/css" href="'.$css.'" />'."\n"; |
221 | } |
222 | |
223 | echo '<link rel="stylesheet" type="text/css" href="'.$CFG->wwwroot.'/install.php?css=1" /> |
9ace5094 |
224 | <title>'.get_string('installation','install').' - Moodle '.$CFG->target_release.'</title> |
3b093310 |
225 | <meta http-equiv="content-type" content="text/html; charset=UTF-8" /> |
226 | <meta http-equiv="pragma" content="no-cache" /> |
227 | <meta http-equiv="expires" content="0" />'; |
228 | |
229 | echo '</head><body class="notloggedin"> |
230 | <div id="page" class="stage'.$config->stage.'"> |
231 | <div id="header" class=" clearfix"><h1 class="headermain">'.get_string('installation','install').'</h1> |
232 | <div class="headermenu"> </div></div><div class="navbar clearfix"> |
233 | <div class="breadcrumb"> |
234 | <ul><li class="first">'.$stagename.'</li></ul> |
235 | </div> |
236 | <div class="navbutton"> </div> |
237 | </div> |
238 | <!-- END OF HEADER --> |
239 | <div id="installdiv">'; |
2f13f94c |
240 | |
3b093310 |
241 | echo '<h2>'.$heading.'</h2>'; |
242 | |
243 | if ($stagetext !== '') { |
244 | echo '<div class="stage generalbox box">'; |
245 | echo $stagetext; |
246 | echo '</div>'; |
247 | } |
248 | // main |
249 | echo '<form id="installform" method="post" action="install.php"><fieldset>'; |
250 | foreach ($config as $name=>$value) { |
251 | echo '<input type="hidden" name="'.$name.'" value="'.s($value).'" />'; |
252 | } |
2f13f94c |
253 | } |
254 | |
95feaf96 |
255 | /** |
256 | * Prints installation page header, we can no use weblib yet in isntaller. |
257 | * @param array $config |
258 | * @param bool $reload print reload button instead of next |
259 | * @return void |
260 | */ |
3b093310 |
261 | function install_print_footer($config, $reload=false) { |
262 | global $CFG; |
263 | |
264 | if ($config->stage > INSTALL_WELCOME) { |
4d928665 |
265 | $first = '<input type="submit" id="previousbutton" name="previous" value="« '.s(get_string('previous')).'" />'; |
3b093310 |
266 | } else { |
4d928665 |
267 | $first = '<input type="submit" id="previousbutton" name="next" value="'.s(get_string('reload', 'admin')).'" />'; |
268 | $first .= '<script type="text/javascript"> |
269 | //<![CDATA[ |
270 | var first = document.getElementById("previousbutton"); |
271 | first.style.visibility = "hidden"; |
272 | //]]> |
273 | </script> |
274 | '; |
3b093310 |
275 | } |
276 | |
277 | if ($reload) { |
4d928665 |
278 | $next = '<input type="submit" id="nextbutton" name="next" value="'.s(get_string('reload', 'admin')).'" />'; |
3b093310 |
279 | } else { |
4d928665 |
280 | $next = '<input type="submit" id="nextbutton" name="next" value="'.s(get_string('next')).' »" />'; |
3b093310 |
281 | } |
282 | |
283 | echo '</fieldset><fieldset id="nav_buttons">'.$first.$next.'</fieldset>'; |
284 | |
285 | $homelink = '<div class="sitelink">'. |
9ace5094 |
286 | '<a title="Moodle '. $CFG->target_release .'" href="http://docs.moodle.org/en/Administrator_documentation" onclick="this.target=\'_blank\'">'. |
3b093310 |
287 | '<img style="width:100px;height:30px" src="pix/moodlelogo.gif" alt="moodlelogo" /></a></div>'; |
288 | |
289 | echo '</form></div>'; |
290 | echo '<div id="footer"><hr />'.$homelink.'</div>'; |
291 | echo '</div></body></html>'; |
292 | } |
293 | |
294 | |
95feaf96 |
295 | /** |
296 | * Prints css needed on installation page, tries to look like the rest of installation. |
297 | * Does not return. |
298 | */ |
3b093310 |
299 | function install_css_styles() { |
300 | global $CFG; |
301 | |
302 | @header('Content-type: text/css'); // Correct MIME type |
303 | @header('Cache-Control: no-store, no-cache, must-revalidate'); |
304 | @header('Cache-Control: post-check=0, pre-check=0', false); |
305 | @header('Pragma: no-cache'); |
306 | @header('Expires: Mon, 20 Aug 1969 09:23:00 GMT'); |
307 | @header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT'); |
308 | |
309 | //TODO: add rtl support here |
310 | |
311 | echo ' |
312 | |
313 | h2 { |
314 | text-align:center; |
315 | } |
316 | |
317 | #installdiv { |
318 | width: 800px; |
319 | margin-left:auto; |
320 | margin-right:auto; |
321 | } |
322 | |
323 | #installdiv dt { |
324 | font-weight: bold; |
325 | } |
326 | |
327 | #installdiv dd { |
328 | padding-bottom: 0.5em; |
329 | } |
330 | |
331 | .stage { |
332 | margin-top: 2em; |
333 | margin-bottom: 2em; |
334 | width: 100%; |
335 | padding:25px; |
336 | } |
337 | |
338 | #installform { |
339 | width: 100%; |
340 | } |
341 | |
342 | #nav_buttons input { |
343 | margin: 5px; |
344 | } |
345 | |
346 | #envresult { |
347 | text-align:left; |
348 | width: auto; |
349 | margin-left:10em; |
350 | } |
351 | |
352 | #envresult dd { |
353 | color: red; |
354 | } |
355 | |
356 | .formrow { |
357 | clear:both; |
358 | text-align:left; |
359 | padding: 8px; |
360 | } |
361 | |
362 | .formrow label.formlabel { |
363 | display:block; |
364 | float:left; |
365 | width: 260px; |
366 | margin-right:5px; |
367 | text-align:right; |
368 | } |
369 | |
370 | .formrow .forminput { |
371 | display:block; |
372 | float:left; |
373 | } |
374 | |
375 | fieldset { |
376 | text-align:center; |
377 | border:none; |
378 | } |
379 | |
380 | .hint { |
381 | display:block; |
382 | clear:both; |
383 | padding-left: 265px; |
384 | color: red; |
385 | } |
386 | |
387 | .configphp { |
388 | text-align:left; |
389 | background-color:white; |
390 | padding:1em; |
391 | width:95%; |
392 | } |
393 | |
64c368e3 |
394 | .stage6 .stage { |
3b093310 |
395 | font-weight: bold; |
396 | color: red; |
397 | } |
398 | |
399 | '; |
400 | |
401 | die; |
2f13f94c |
402 | } |