]> git.agnieray.net Git - galette.git/blob - galette/webroot/installer.php
Fix lang selector at install; closes #1366
[galette.git] / galette / webroot / installer.php
1 <?php
2
3 /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
4
5 /**
6 * Main Galette initialisation
7 *
8 * PHP version 5
9 *
10 * Copyright © 2013-2014 The Galette Team
11 *
12 * This file is part of Galette (http://galette.eu).
13 *
14 * Galette is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation, either version 3 of the License, or
17 * (at your option) any later version.
18 *
19 * Galette is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 *
24 * You should have received a copy of the GNU General Public License
25 * along with Galette. If not, see <http://www.gnu.org/licenses/>.
26 *
27 * @category Main
28 * @package Galette
29 *
30 * @author Johan Cwiklinski <johan@x-tnd.be>
31 * @copyright 2013-2014 The Galette Team
32 * @license http://www.gnu.org/licenses/gpl-3.0.html GPL License 3.0 or (at your option) any later version
33 * @version SVN: $Id$
34 * @link http://galette.tuxfamily.org
35 * @since Available since 0.8
36 */
37
38 use Galette\Core\Install as GaletteInstall;
39 use Galette\Core\Db as GaletteDb;
40 use Analog\Analog;
41
42 //set a flag saying we work from installer
43 //that way, in galette.inc.php, we'll only include relevant parts
44 $installer = true;
45 define('GALETTE_ROOT', __DIR__ . '/../');
46
47 // check PHP modules
48 require_once GALETTE_ROOT . '/vendor/autoload.php';
49 require_once GALETTE_ROOT . 'config/versions.inc.php';
50
51 if (version_compare(PHP_VERSION, GALETTE_PHP_MIN, '<') || !extension_loaded('intl')) {
52 header('location: compat_test.php');
53 die(1);
54 }
55
56 //specific logfile for installer
57 $logfile = 'galette_install';
58 define('GALETTE_BASE_PATH', '../');
59 define('GALETTE_THEME_DIR', './themes/default/');
60
61 require_once '../includes/galette.inc.php';
62
63 session_start();
64 $session_name = 'galette_install_' . str_replace('.', '_', GALETTE_VERSION);
65 $session = &$_SESSION['galette'][$session_name];
66
67 $app = new \Slim\App(
68 array(
69 'templates.path' => GALETTE_ROOT . 'templates/default/',
70 'mode' => 'INSTALL'
71 )
72 );
73 require_once '../includes/dependencies.php';
74
75 if (isset($_POST['abort_btn'])) {
76 if (isset($session[md5(GALETTE_ROOT)])) {
77 unset($session[md5(GALETTE_ROOT)]);
78 }
79 header('location: ' . GALETTE_BASE_PATH);
80 }
81
82 $install = null;
83 if (isset($session[md5(GALETTE_ROOT)]) && !isset($_GET['raz'])) {
84 $install = unserialize($session[md5(GALETTE_ROOT)]);
85 } else {
86 $install = new GaletteInstall();
87 }
88
89 $error_detected = array();
90
91 /**
92 * Initialize database constants to connect
93 *
94 * @param Install $install Installer
95 *
96 * @return void
97 */
98 function initDbConstants($install)
99 {
100 define('TYPE_DB', $install->getDbType());
101 define('PREFIX_DB', $install->getTablesPrefix());
102 define('USER_DB', $install->getDbUser());
103 define('PWD_DB', $install->getDbPass());
104 define('HOST_DB', $install->getDbHost());
105 define('PORT_DB', $install->getDbPort());
106 define('NAME_DB', $install->getDbName());
107 }
108
109 if ($install->isStepPassed(GaletteInstall::STEP_TYPE)) {
110 define('GALETTE_LOGGER_CHECKED', true);
111
112 $now = new \DateTime();
113 $dbg_log_path = GALETTE_LOGS_PATH . 'galette_debug_' .
114 $now->format('Y-m-d') . '.log';
115 $galette_debug_log = \Analog\Handler\File::init($dbg_log_path);
116
117 if (GALETTE_MODE === 'DEV') {
118 //logs everything in PHP logs (per chance /var/log/http/error_log or /var/log/php-fpm/error.log)
119 $galette_run_log = \Analog\Handler\Stderr::init();
120 } else {
121 $logfile = 'galette_install';
122 $log_path = GALETTE_LOGS_PATH . $logfile . '.log';
123 $galette_run_log = \Analog\Handler\File::init($log_path);
124 }
125
126 Analog::handler(
127 \Analog\Handler\Multi::init(
128 array (
129 Analog::NOTICE => \Analog\Handler\Threshold::init(
130 $galette_run_log,
131 GALETTE_LOG_LVL
132 ),
133 Analog::DEBUG => $galette_debug_log
134 )
135 )
136 );
137 }
138
139 if (isset($_POST['stepback_btn'])) {
140 $install->atPreviousStep();
141 } elseif (isset($_POST['install_permsok']) && $_POST['install_permsok'] == 1) {
142 $install->atTypeStep();
143 } elseif (isset($_POST['install_type'])) {
144 $install->setMode($_POST['install_type']);
145 $install->atDbStep();
146 } elseif (isset($_POST['install_dbtype'])) {
147 $install->setDbType($_POST['install_dbtype'], $error_detected);
148
149 if (empty($_POST['install_dbhost'])) {
150 $error_detected[] = _T("No host");
151 }
152 if (empty($_POST['install_dbport'])) {
153 $error_detected[] = _T("No port");
154 }
155 if (empty($_POST['install_dbuser'])) {
156 $error_detected[] = _T("No user name");
157 }
158 if (empty($_POST['install_dbpass'])) {
159 $error_detected[] = _T("No password");
160 }
161 if (empty($_POST['install_dbname'])) {
162 $error_detected[] = _T("No database name");
163 }
164
165 if (count($error_detected) == 0) {
166 $install->setDsn(
167 $_POST['install_dbhost'],
168 $_POST['install_dbport'],
169 $_POST['install_dbname'],
170 $_POST['install_dbuser'],
171 $_POST['install_dbpass']
172 );
173 $install->setTablesPrefix(
174 $_POST['install_dbprefix']
175 );
176 $install->atDbCheckStep();
177 }
178 } elseif (isset($_POST['install_dbperms_ok'])) {
179 if ($install->isInstall()) {
180 $install->atDbInstallStep();
181 } elseif ($install->isUpgrade()) {
182 $install->atVersionSelection();
183 }
184 } elseif (isset($_POST['previous_version'])) {
185 $install->setInstalledVersion($_POST['previous_version']);
186 $install->atDbUpgradeStep();
187 } elseif (isset($_POST['install_dbwrite_ok']) && $install->isInstall()) {
188 $install->atAdminStep();
189 } elseif (isset($_POST['install_dbwrite_ok']) && $install->isUpgrade()) {
190 $install->atGaletteInitStep();
191 } elseif (isset($_POST['install_adminlogin'])
192 && isset($_POST['install_adminpass'])
193 && $install->isInstall()
194 ) {
195 if ($_POST['install_adminlogin'] == '') {
196 $error_detected[] = _T("No user name");
197 }
198 if (strpos($_POST['install_adminlogin'], '@') != false) {
199 $error_detected[] = _T("The username cannot contain the @ character");
200 }
201 if ($_POST['install_adminpass'] == '') {
202 $error_detected[] = _T("No password");
203 }
204 if (! isset($_POST['install_passwdverified'])
205 && strcmp(
206 $_POST['install_adminpass'],
207 $_POST['install_adminpass_verif']
208 )
209 ) {
210 $error_detected[] = _T("Passwords mismatch");
211 }
212 if (count($error_detected) == 0) {
213 $install->setAdminInfos(
214 $_POST['install_adminlogin'],
215 $_POST['install_adminpass']
216 );
217 $install->atGaletteInitStep();
218 }
219 } elseif (isset($_POST['install_prefs_ok'])) {
220 $install->atEndStep();
221 }
222
223 if (!$install->isEndStep()
224 && ($install->postCheckDb() || $install->isDbCheckStep())
225 ) {
226 //if we have passed database configuration, define required constants
227 initDbConstants($install);
228
229 if ($install->postCheckDb()) {
230 //while before check db, connection is not checked
231 $zdb = new GaletteDb();
232 }
233 }
234
235 header('Content-Type: text/html; charset=UTF-8');
236 ?>
237 <!DOCTYPE html>
238 <html lang="<?php echo $i18n->getAbbrev(); ?>">
239 <head>
240 <title><?php echo _T("Galette Installation") . ' - ' . $install->getStepTitle(); ?></title>
241 <meta charset="UTF-8"/>
242 <link rel="stylesheet" type="text/css" href="./themes/default/galette.css"/>
243 <link rel="stylesheet" type="text/css" href="./themes/default/install.css"/>
244 <link rel="stylesheet" type="text/css" href="./themes/default/jquery-ui/jquery-ui-<?php echo JQUERY_UI_VERSION; ?>.custom.css"/>
245 <link rel="stylesheet" type="text/css" href="./js/selectize-0.12.6/css/selectize.css" />
246 <link rel="stylesheet" type="text/css" href="./js/selectize-0.12.6/css/selectize.default.css" />
247 <script type="text/javascript" src="./js/jquery/jquery-<?php echo JQUERY_VERSION; ?>.min.js"></script>
248 <script type="text/javascript" src="./js/jquery/jquery-migrate-<?php echo JQUERY_MIGRATE_VERSION; ?>.min.js"></script>
249 <script type="text/javascript" src="./js/jquery/jquery-ui-<?php echo JQUERY_UI_VERSION; ?>/jquery.ui.widget.min.js"></script>
250 <script type="text/javascript" src="./js//jquery/jquery-ui-<?php echo JQUERY_UI_VERSION; ?>/jquery.ui.button.min.js"></script>
251 <script type="text/javascript" src="./js/jquery/jquery-ui-<?php echo JQUERY_UI_VERSION; ?>/jquery.ui.tooltip.min.js"></script>
252 <script type="text/javascript" src="./js/selectize-0.12.6/js/standalone/selectize.min.js"></script>
253 <script type="text/javascript" src="./js/jquery/jquery.bgFade.js"></script>
254 <script type="text/javascript" src="./js/common.js"></script>
255 <link rel="shortcut icon" href="./themes/default/images/favicon.png" />
256 </head>
257 <body>
258 <section>
259 <header>
260 <h1 id="titre">
261 <?php echo _T("Galette installation") . ' - ' . $install->getStepTitle(); ?>
262 </h1>
263
264 <form action="">
265 <select id="lang_selector" name="ui_pref_lang">
266 <?php
267 foreach ($i18n->getList() as $langue) {
268 ?>
269 <option value="<?php echo $langue->getID(); ?>" lang="<?php echo $langue->getAbbrev(); ?>"<?php if ($i18n->getAbbrev() == $langue->getAbbrev()) { echo ' selected="selected"'; } ?>><?php echo $langue->getName(); ?></option>
270 <?php
271 }
272 ?>
273 </select>
274 <noscript>
275 <input type="submit" name="{_T string="Change language"}" />
276 </noscript>
277 </form>
278 </header>
279 <?php
280 if (count($error_detected) > 0) {
281 ?>
282
283 <div id="errorbox">
284 <h1><?php echo _T("- ERROR -"); ?></h1>
285 <ul>
286 <?php
287 foreach ($error_detected as $error) {
288 ?>
289 <li><?php echo $error; ?></li>
290 <?php
291 }
292 ?>
293 </ul>
294 </div>
295 <?php
296 }
297 ?>
298 <div>
299 <?php
300 if ($install->isCheckStep()) {
301 include_once __DIR__ . '/../install/steps/check.php';
302 } elseif ($install->isTypeStep()) {
303 include_once __DIR__ . '/../install/steps/type.php';
304 } elseif ($install->isDbStep()) {
305 include_once __DIR__ . '/../install/steps/db.php';
306 } elseif ($install->isDbCheckStep()) {
307 include_once __DIR__ . '/../install/steps/db_checks.php';
308 } elseif ($install->isVersionSelectionStep()) {
309 include_once __DIR__ . '/../install/steps/db_select_version.php';
310 } elseif ($install->isDbinstallStep() || $install->isDbUpgradeStep()) {
311 include_once __DIR__ . '/../install/steps/db_install.php';
312 } elseif ($install->isAdminStep()) {
313 include_once __DIR__ . '/../install/steps/admin.php';
314 } elseif ($install->isGaletteInitStep()) {
315 include_once __DIR__ . '/../install/steps/galette.php';
316 } elseif ($install->isEndStep()) {
317 include_once __DIR__ . '/../install/steps/end.php';
318 }
319 ?>
320 </div>
321 <footer>
322 <p><?php echo _T("Steps:"); ?></p>
323 <ol>
324 <li<?php if ($install->isCheckStep()) echo ' class="current"'; ?>><?php echo _T("Checks"); ?> - </li>
325 <li<?php if ($install->isTypeStep()) echo ' class="current"'; ?>><?php echo _T("Installation mode"); ?> - </li>
326 <li<?php if ($install->isDbStep()) echo ' class="current"'; ?>><?php echo _T("Database"); ?> - </li>
327 <li<?php if ($install->isDbCheckStep()) echo ' class="current"'; ?>><?php echo _T("Database access/permissions"); ?> - </li>
328 <?php
329 if ( $install->isUpgrade() ) {
330 ?>
331 <li<?php if ($install->isVersionSelectionStep()) echo ' class="current"'; ?>><?php echo _T("Version selection"); ?> - </li>
332 <li<?php if ($install->isDbUpgradeStep()) echo ' class="current"'; ?>><?php echo _T("Database upgrade"); ?> - </li>
333 <?php
334 } else {
335 ?>
336 <li<?php if ($install->isDbinstallStep()) echo ' class="current"'; ?>><?php echo _T("Database installation"); ?> - </li>
337 <?php
338 }
339
340 if ( !$install->isUpgrade() ) {
341 ?>
342 <li<?php if ($install->isAdminStep()) echo ' class="current"'; ?>><?php echo _T("Admin parameters"); ?> - </li>
343 <?php
344 }
345 ?>
346 <li<?php if ($install->isGaletteInitStep()) echo ' class="current"'; ?>><?php echo _T("Galette initialisation"); ?> - </li>
347 <li<?php if ($install->isEndStep()) echo ' class="current"'; ?>><?php echo _T("End!"); ?></li>
348 </ol>
349 </footer>
350 </section>
351 <a id="copyright" href="http://galette.eu/">Galette <?php echo GALETTE_VERSION; ?></a>
352 </body>
353 </html>
354 <?php
355 if (!$install->isEndStep()) {
356 $session[md5(GALETTE_ROOT)] = serialize($install);
357 }
358
359 if (isset($profiler)) {
360 $profiler->stop();
361 }
362 ?>