|
1 <?php |
|
2 |
|
3 /* |
|
4 * Enano - an open-source CMS capable of wiki functions, Drupal-like sidebar blocks, and everything in between |
|
5 * Version 1.1.1 |
|
6 * Copyright (C) 2006-2007 Dan Fuhry |
|
7 * Installation package |
|
8 * libenanoinstall.php - Installation payload backend |
|
9 * |
|
10 * This program is Free Software; you can redistribute and/or modify it under the terms of the GNU General Public License |
|
11 * as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. |
|
12 * |
|
13 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied |
|
14 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for details. |
|
15 */ |
|
16 |
|
17 $neutral_color = 'C'; |
|
18 |
|
19 function run_installer_stage($stage_id, $stage_name, $function, $failure_explanation, $allow_skip = true) |
|
20 { |
|
21 static $resumed = false; |
|
22 static $resume_stack = array(); |
|
23 |
|
24 if ( empty($resume_stack) && isset($_POST['resume_stack']) && preg_match('/[a-z_]+((\|[a-z_]+)+)/', $_POST['resume_stack']) ) |
|
25 { |
|
26 $resume_stack = explode('|', $_POST['resume_stack']); |
|
27 } |
|
28 |
|
29 $already_run = false; |
|
30 if ( in_array($stage_id, $resume_stack) ) |
|
31 { |
|
32 $already_run = true; |
|
33 } |
|
34 |
|
35 if ( !$resumed ) |
|
36 { |
|
37 if ( !isset($_GET['sub']) ) |
|
38 $resumed = true; |
|
39 if ( isset($_GET['sub']) && $_GET['sub'] == $stage_id ) |
|
40 { |
|
41 $resumed = true; |
|
42 } |
|
43 } |
|
44 if ( !$resumed && $allow_skip ) |
|
45 { |
|
46 echo_stage_success($stage_id, $stage_name); |
|
47 return false; |
|
48 } |
|
49 if ( !function_exists($function) ) |
|
50 die('libenanoinstall: CRITICAL: function "' . $function . '" for ' . $stage_id . ' doesn\'t exist'); |
|
51 $result = @call_user_func($function, false, $already_run); |
|
52 if ( $result ) |
|
53 { |
|
54 echo_stage_success($stage_id, $stage_name); |
|
55 $resume_stack[] = $stage_id; |
|
56 return true; |
|
57 } |
|
58 else |
|
59 { |
|
60 echo_stage_failure($stage_id, $stage_name, $failure_explanation, $resume_stack); |
|
61 return false; |
|
62 } |
|
63 } |
|
64 |
|
65 function start_install_table() |
|
66 { |
|
67 echo '<table border="0" cellspacing="0" cellpadding="0" style="margin-top: 10px;">' . "\n"; |
|
68 } |
|
69 |
|
70 function close_install_table() |
|
71 { |
|
72 echo '</table>' . "\n\n"; |
|
73 flush(); |
|
74 } |
|
75 |
|
76 function echo_stage_success($stage_id, $stage_name) |
|
77 { |
|
78 global $neutral_color; |
|
79 $neutral_color = ( $neutral_color == 'A' ) ? 'C' : 'A'; |
|
80 echo '<tr><td style="width: 500px; background-color: #' . "{$neutral_color}{$neutral_color}FF{$neutral_color}{$neutral_color}" . '; padding: 0 5px;">' . htmlspecialchars($stage_name) . '</td><td style="padding: 0 5px;"><img alt="Done" src="../images/good.gif" /></td></tr>' . "\n"; |
|
81 flush(); |
|
82 } |
|
83 |
|
84 function echo_stage_failure($stage_id, $stage_name, $failure_explanation, $resume_stack) |
|
85 { |
|
86 global $neutral_color; |
|
87 global $lang; |
|
88 |
|
89 $neutral_color = ( $neutral_color == 'A' ) ? 'C' : 'A'; |
|
90 echo '<tr><td style="width: 500px; background-color: #' . "FF{$neutral_color}{$neutral_color}{$neutral_color}{$neutral_color}" . '; padding: 0 5px;">' . htmlspecialchars($stage_name) . '</td><td style="padding: 0 5px;"><img alt="Failed" src="../images/bad.gif" /></td></tr>' . "\n"; |
|
91 flush(); |
|
92 close_install_table(); |
|
93 $post_data = ''; |
|
94 $mysql_error = mysql_error(); |
|
95 foreach ( $_POST as $key => $value ) |
|
96 { |
|
97 // FIXME: These should really also be sanitized for double quotes |
|
98 $value = htmlspecialchars($value); |
|
99 $key = htmlspecialchars($key); |
|
100 $post_data .= " <input type=\"hidden\" name=\"$key\" value=\"$value\" />\n"; |
|
101 } |
|
102 echo '<form action="install.php?stage=install&sub=' . $stage_id . '" method="post"> |
|
103 ' . $post_data . ' |
|
104 <input type="hidden" name="resume_stack" value="' . htmlspecialchars(implode('|', $resume_stack)) . '" /> |
|
105 <h3>' . $lang->get('meta_msg_err_stagefailed_title') . '</h3> |
|
106 <p>' . $failure_explanation . '</p> |
|
107 ' . ( !empty($mysql_error) ? "<p>" . $lang->get('meta_msg_err_stagefailed_mysqlerror') . " $mysql_error</p>" : '' ) . ' |
|
108 <p>' . $lang->get('meta_msg_err_stagefailed_body') . '</p> |
|
109 <p style="text-align: center;"><input type="submit" value="' . $lang->get('meta_btn_retry_installation') . '" /></p> |
|
110 </form>'; |
|
111 global $ui; |
|
112 $ui->show_footer(); |
|
113 exit; |
|
114 } |
|
115 |
|
116 ?> |