3
* Xibo - Digitial Signage - http://www.xibo.org.uk
4
* Copyright (C) 2009 Alex Harrington
6
* This file is part of Xibo.
8
* Xibo is free software: you can redistribute it and/or modify
9
* it under the terms of the GNU Affero General Public License as published by
10
* the Free Software Foundation, either version 3 of the License, or
13
* Xibo is distributed in the hope that it will be useful,
14
* but WITHOUT ANY WARRANTY; without even the implied warranty of
15
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
* GNU Affero General Public License for more details.
18
* You should have received a copy of the GNU Affero General Public License
19
* along with Xibo. If not, see <http://www.gnu.org/licenses/>.
25
die('Xibo requires PHP 5.2.4 or later');
28
include('lib/app/kit.class.php');
29
include('install/header.inc');
30
include('config/config.class.php');
31
include('config/db_config.php');
33
// Setup for the Translations using Gettext.
34
// There is normally a class that will do this for us - but it requires a DB object (which we do not have at install time)
35
// Would be nice to include a method on the TranslationEngine that did this for us - but without the debugging
36
// The actual translation function __() is included later in this file.
37
$langs = Kit::GetParam('HTTP_ACCEPT_LANGUAGE', $_SERVER, _STRING);
38
$lang = 'en-gb'; // Default language
39
$encoding = ''; // We do not seem to need an encoding, but I read somewhere that we might - left as a reminder of this.
43
$langs = explode(',', $langs);
48
putenv('LANG='.$lang.'.'.$encoding);
49
putenv('LANGUAGE='.$lang.'.'.$encoding);
50
putenv('LC_ALL='.$lang.'.'.$encoding);
53
setlocale(LC_ALL, $lang.'.'.$encoding);
55
// Translations have been setup.
59
$xibo_step = Kit::GetParam('xibo_step',_POST,_INT,'0');
61
if (!isset($xibo_step) || $xibo_step == 0) {
62
# First step of the process.
63
# Show a welcome screen and next button
65
<?php echo __("Welcome to the Xibo Installer!"); ?><br /><br />
66
<?php echo __("The installer will take you through setting up Xibo one step at a time."); ?><br /><br />
67
<?php echo __("Lets get started!"); ?><br /><br />
68
<form action="install.php" method="POST">
69
<input type="hidden" name="xibo_step" value="1" />
70
<div class="loginbutton"><button type="submit"><?php echo __("Next"); ?> ></button></div>
74
elseif ($xibo_step == 1) {
77
$cObj = new Config($db);
79
<p><?php echo __("First we need to check if your server meets Xibo's requirements."); ?></p>
82
echo $cObj->CheckEnvironment();
83
if ($cObj->EnvironmentFault()) {
85
<form action="install.php" method="POST">
86
<input type="hidden" name="xibo_step" value="1" />
87
<div class="loginbutton"><button type="submit"><?php echo __("Retest"); ?></button></div>
3
* Xibo - Digitial Signage - http://www.xibo.org.uk
4
* Copyright (C) 2009 Alex Harrington
6
* This file is part of Xibo.
8
* Xibo is free software: you can redistribute it and/or modify
9
* it under the terms of the GNU Affero General Public License as published by
10
* the Free Software Foundation, either version 3 of the License, or
13
* Xibo is distributed in the hope that it will be useful,
14
* but WITHOUT ANY WARRANTY; without even the implied warranty of
15
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
* GNU Affero General Public License for more details.
18
* You should have received a copy of the GNU Affero General Public License
19
* along with Xibo. If not, see <http://www.gnu.org/licenses/>.
25
die('Xibo requires PHP 5.2.4 or later');
28
include('lib/app/kit.class.php');
29
include('install/header.inc');
30
include('config/config.class.php');
31
include('config/db_config.php');
33
// Setup for the Translations using Gettext.
34
// There is normally a class that will do this for us - but it requires a DB object (which we do not have at install time)
35
// Would be nice to include a method on the TranslationEngine that did this for us - but without the debugging
36
// The actual translation function __() is included later in this file.
37
$langs = Kit::GetParam('HTTP_ACCEPT_LANGUAGE', $_SERVER, _STRING);
38
$lang = 'en-gb'; // Default language
39
$encoding = ''; // We do not seem to need an encoding, but I read somewhere that we might - left as a reminder of this.
43
$langs = explode(',', $langs);
48
putenv('LANG='.$lang.'.'.$encoding);
49
putenv('LANGUAGE='.$lang.'.'.$encoding);
50
putenv('LC_ALL='.$lang.'.'.$encoding);
53
setlocale(LC_ALL, $lang.'.'.$encoding);
55
// Translations have been setup.
59
$xibo_step = Kit::GetParam('xibo_step',_POST,_INT,'0');
61
if (!isset($xibo_step) || $xibo_step == 0) {
62
# First step of the process.
63
# Show a welcome screen and next button
65
<?php echo __("Welcome to the Xibo Installer!"); ?><br /><br />
66
<?php echo __("The installer will take you through setting up Xibo one step at a time."); ?><br /><br />
67
<?php echo __("Lets get started!"); ?><br /><br />
68
<form action="install.php" method="POST">
69
<input type="hidden" name="xibo_step" value="1" />
70
<div class="loginbutton"><button type="submit"><?php echo __("Next"); ?> ></button></div>
74
elseif ($xibo_step == 1) {
77
$cObj = new Config($db);
79
<p><?php echo __("First we need to check if your server meets Xibo's requirements."); ?></p>
82
echo $cObj->CheckEnvironment();
83
if ($cObj->EnvironmentFault()) {
85
<form action="install.php" method="POST">
86
<input type="hidden" name="xibo_step" value="1" />
87
<div class="loginbutton"><button type="submit"><?php echo __("Retest"); ?></button></div>
91
91
else if ($cObj->EnvironmentWarning()) {
93
<form action="install.php" method="POST">
94
<input type="hidden" name="xibo_step" value="1" />
95
<div class="loginbutton"><button type="submit"><?php echo __("Retest"); ?></button></div>
97
<form action="install.php" method="POST">
98
<input type="hidden" name="xibo_step" value="2" />
99
<div class="loginbutton"><button type="submit"><?php echo __("Next"); ?> ></button></div>
105
<form action="install.php" method="POST">
106
<input type="hidden" name="xibo_step" value="2" />
107
<div class="loginbutton"><button type="submit"><?php echo __("Next"); ?> ></button></div>
112
elseif ($xibo_step == 2) {
114
## Does database exist already?
118
<p><?php echo __("Xibo needs to setup a new database."); ?></p>
119
<p><?php echo __("If you have not yet created an empty database and database user for Xibo to use, and know the username/password of a MySQL administrator, click the \"Create New\" button, otherwise click \"Use Existing\"."); ?></p>
120
<p><i><?php echo __("Note that any existing database must be empty"); ?></i></p>
122
<form action="install.php" method="POST">
123
<input type="hidden" name="xibo_step" value="3" />
124
<button type="submit"><?php echo __("Create New"); ?></button>
126
<form action="install.php" method="POST">
127
<input type="hidden" name="xibo_step" value="4" />
128
<button type="submit"><?php echo __("Use Existing"); ?></button>
132
elseif ($xibo_step == 3) {
133
## If not, gather admin password and use to create empty db and new user.
136
<p><?php echo __("Since no empty database has been created for Xibo to use, we need the username and password of a MySQL administrator to create a new database, and database user for Xibo."); ?></p>
137
<p><?php echo __("Additionally, please give us a new username and password to create in MySQL for Xibo to use. Xibo will create this automatically for you."); ?></p>
138
<form action="install.php" method="POST">
139
<input type="hidden" name="xibo_step" value="5" />
140
<input type="hidden" name="db_create" value="On" />
141
<div class="install_table">
142
<p><label for="host"><?php echo __("Host:"); ?> </label><input class="username" type="text" id="host" name="host" size="12" value="localhost" /></p>
143
<p><label for="admin_username"><?php echo __("Admin Username:"); ?> </label><input class="username" type="text" id="admin_username" name="admin_username" size="12" /></p>
144
<p><label for="admin_password"><?php echo __("Admin Password:"); ?> </label><input class="username" type="password" id="admin_password" name="admin_password" size="12" /></p>
145
<p><label for="db_name"><?php echo __("Xibo Database Name:"); ?> </label><input class="username" type="text" id="db_name" name="db_name" size="12" value="xibo" /></p>
146
<p><label for="db_username"><?php echo __("Xibo Database Username:"); ?> </label><input class="username" type="text" id="db_username" name="db_username" size="12" value="xibo" /></p>
147
<p><label for="db_password"><?php echo __("Xibo Database Password:"); ?> </label><input class="username" type="password" id="db_password" name="db_password" size="12" /></p>
150
<button type="submit"><?php echo __("Create"); ?></button>
154
elseif ($xibo_step == 4) {
155
## Get details of db that's been created already for us
158
<p><?php echo __("Please enter the details of the database and user you have created for Xibo."); ?></p>
159
<form action="install.php" method="POST">
160
<input type="hidden" name="xibo_step" value="5" />
161
<input type="hidden" name="db_create" value="Off" />
162
<div class="install_table">
163
<p><label for="host"><?php echo __("Host:"); ?> </label><input class="username" type="text" id="host" name="host" size="12" value="localhost" /></p>
164
<p><label for="db_name"><?php echo __("Xibo Database Name:"); ?> </label><input class="username" type="text" id="db_name" name="db_name" size="12" value="xibo" /></p>
165
<p><label for="db_username"><?php echo __("Xibo Database Username:"); ?> </label><input class="username" type="text" id="db_username" name="db_username" size="12" value="xibo" /></p>
166
<p><label for="db_password"><?php echo __("Xibo Database Password:"); ?> </label><input class="username" type="password" id="db_password" name="db_password" size="12" /></p>
169
<button type="submit"><?php echo __("Create"); ?></button>
173
elseif ($xibo_step == 5) {
175
$db_create = Kit::GetParam('db_create',_POST,_STRING);
177
if (!isset($db_create)) {
178
reportError("2",__("Something went wrong"));
181
$db_host = Kit::GetParam('host',_POST,_STRING,'localhost');
182
$db_user = Kit::GetParam('db_username',_POST,_USERNAME);
183
$db_pass = Kit::GetParam('db_password',_POST,_PASSWORD);
184
$db_name = Kit::GetParam('db_name',_POST,_USERNAME);
188
if ($db_create == 'On') {
189
$db_admin_user = Kit::GetParam('admin_username',_POST,_USERNAME);
190
$db_admin_pass = Kit::GetParam('admin_password',_POST,_PASSWORD);
192
if (! ($db_host && $db_name && $db_user && $db_pass && $db_admin_user && $db_admin_pass)) {
193
# Something was blank.
195
reportError("3", __("A field was blank. Please fill in all fields."));
198
$db = @mysql_connect($db_host,$db_admin_user,$db_admin_pass);
201
reportError("3", __("Could not connect to MySQL with the administrator details. Please check and try again.") . "<br /><br />" . __("MySQL Error:") . "<br />" . mysql_error());
205
<p><?php echo __("Creating new database."); ?></p>
209
$SQL = sprintf("CREATE DATABASE `%s`",
210
mysql_real_escape_string($db_name));
211
if (! @mysql_query($SQL, $db)) {
212
# Create database and user
213
reportError("3", __("Could not create a new database with the administrator details. Please check and try again.") . "<br /><br />" . "MySQL Error:" . "<br />" . mysql_error());
216
# Choose the MySQL DB to create a user
217
@mysql_select_db("mysql", $db);
219
# Make $db_host lowercase so it matches "localhost" if required.
220
$db_host = strtolower($db_host);
223
<p><?php echo __("Creating new user"); ?></p>
227
if ($db_host == 'localhost') {
228
$SQL = sprintf("GRANT ALL PRIVILEGES ON `%s`.* to '%s'@'%s' IDENTIFIED BY '%s'",
229
mysql_real_escape_string($db_name),
230
mysql_real_escape_string($db_user),
231
mysql_real_escape_string($db_host),
232
mysql_real_escape_string($db_pass));
235
$SQL = sprintf("GRANT ALL PRIVILEGES ON `%s`.* to '%s'@'%%' IDENTIFIED BY '%s'",
236
mysql_real_escape_string($db_name),
237
mysql_real_escape_string($db_user),
238
mysql_real_escape_string($db_pass));
240
if (! @mysql_query($SQL, $db)) {
241
reportError("3", __("Could not create a new user with the administrator details. Please check and try again.") . "<br /><br />" . __("MySQL Error:") . "<br />" . mysql_error());
245
@mysql_query("FLUSH PRIVILEGES", $db);
250
if (! ($db_host && $db_name && $db_user && $db_pass)) {
251
# Something was blank
253
reportError("4", __("A field was blank. Please fill in all fields.") . " " . $db_host . " " . $db_name . " " . $db_user . " " . $db_pass);
258
$db = @mysql_connect($db_host,$db_user,$db_pass);
261
reportError("4", __("Could not connect to MySQL with the Xibo User account details. Please check and try again.") . "<br /><br />" . __("MySQL Error:") . "<br />" . mysql_error());
264
@mysql_select_db($db_name,$db);
267
<p>Populating the database</p>
271
# Load from sql files to db - HOW?
272
$sql_files = ls('*.sql','install/database',false,array('return_files'));
274
// Sort the files in to sensible order, ie
285
// NB this is broken for 0 padded files
286
// eg 01.sql would be incorrectly sorted in the above example.
93
<form action="install.php" method="POST">
94
<input type="hidden" name="xibo_step" value="1" />
95
<div class="loginbutton"><button type="submit"><?php echo __("Retest"); ?></button></div>
97
<form action="install.php" method="POST">
98
<input type="hidden" name="xibo_step" value="2" />
99
<div class="loginbutton"><button type="submit"><?php echo __("Next"); ?> ></button></div>
105
<form action="install.php" method="POST">
106
<input type="hidden" name="xibo_step" value="2" />
107
<div class="loginbutton"><button type="submit"><?php echo __("Next"); ?> ></button></div>
112
elseif ($xibo_step == 2) {
114
## Does database exist already?
118
<p><?php echo __("Xibo needs to setup a new database."); ?></p>
119
<p><?php echo __("If you have not yet created an empty database and database user for Xibo to use, and know the username/password of a MySQL administrator, click the \"Create New\" button, otherwise click \"Use Existing\"."); ?></p>
120
<p><i><?php echo __("Note that any existing database must be empty"); ?></i></p>
122
<form action="install.php" method="POST">
123
<input type="hidden" name="xibo_step" value="3" />
124
<button type="submit"><?php echo __("Create New"); ?></button>
126
<form action="install.php" method="POST">
127
<input type="hidden" name="xibo_step" value="4" />
128
<button type="submit"><?php echo __("Use Existing"); ?></button>
132
elseif ($xibo_step == 3) {
133
## If not, gather admin password and use to create empty db and new user.
136
<p><?php echo __("Since no empty database has been created for Xibo to use, we need the username and password of a MySQL administrator to create a new database, and database user for Xibo."); ?></p>
137
<p><?php echo __("Additionally, please give us a new username and password to create in MySQL for Xibo to use. Xibo will create this automatically for you."); ?></p>
138
<form action="install.php" method="POST">
139
<input type="hidden" name="xibo_step" value="5" />
140
<input type="hidden" name="db_create" value="On" />
141
<div class="install_table">
142
<p><label for="host"><?php echo __("Host:"); ?> </label><input class="username" type="text" id="host" name="host" size="12" value="localhost" /></p>
143
<p><label for="admin_username"><?php echo __("Admin Username:"); ?> </label><input class="username" type="text" id="admin_username" name="admin_username" size="12" /></p>
144
<p><label for="admin_password"><?php echo __("Admin Password:"); ?> </label><input class="username" type="password" id="admin_password" name="admin_password" size="12" /></p>
145
<p><label for="db_name"><?php echo __("Xibo Database Name:"); ?> </label><input class="username" type="text" id="db_name" name="db_name" size="12" value="xibo" /></p>
146
<p><label for="db_username"><?php echo __("Xibo Database Username:"); ?> </label><input class="username" type="text" id="db_username" name="db_username" size="12" value="xibo" /></p>
147
<p><label for="db_password"><?php echo __("Xibo Database Password:"); ?> </label><input class="username" type="password" id="db_password" name="db_password" size="12" /></p>
150
<button type="submit"><?php echo __("Create"); ?></button>
154
elseif ($xibo_step == 4) {
155
## Get details of db that's been created already for us
158
<p><?php echo __("Please enter the details of the database and user you have created for Xibo."); ?></p>
159
<form action="install.php" method="POST">
160
<input type="hidden" name="xibo_step" value="5" />
161
<input type="hidden" name="db_create" value="Off" />
162
<div class="install_table">
163
<p><label for="host"><?php echo __("Host:"); ?> </label><input class="username" type="text" id="host" name="host" size="12" value="localhost" /></p>
164
<p><label for="db_name"><?php echo __("Xibo Database Name:"); ?> </label><input class="username" type="text" id="db_name" name="db_name" size="12" value="xibo" /></p>
165
<p><label for="db_username"><?php echo __("Xibo Database Username:"); ?> </label><input class="username" type="text" id="db_username" name="db_username" size="12" value="xibo" /></p>
166
<p><label for="db_password"><?php echo __("Xibo Database Password:"); ?> </label><input class="username" type="password" id="db_password" name="db_password" size="12" /></p>
169
<button type="submit"><?php echo __("Create"); ?></button>
173
elseif ($xibo_step == 5) {
175
$db_create = Kit::GetParam('db_create',_POST,_STRING);
177
if (!isset($db_create)) {
178
reportError("2",__("Something went wrong"));
181
$db_host = Kit::GetParam('host',_POST,_STRING,'localhost');
182
$db_user = Kit::GetParam('db_username',_POST,_USERNAME);
183
$db_pass = Kit::GetParam('db_password',_POST,_PASSWORD);
184
$db_name = Kit::GetParam('db_name',_POST,_USERNAME);
188
if ($db_create == 'On') {
189
$db_admin_user = Kit::GetParam('admin_username',_POST,_USERNAME);
190
$db_admin_pass = Kit::GetParam('admin_password',_POST,_PASSWORD);
192
if (! ($db_host && $db_name && $db_user && $db_pass && $db_admin_user && $db_admin_pass)) {
193
# Something was blank.
195
reportError("3", __("A field was blank. Please fill in all fields."));
198
$db = @mysql_connect($db_host,$db_admin_user,$db_admin_pass);
201
reportError("3", __("Could not connect to MySQL with the administrator details. Please check and try again.") . "<br /><br />" . __("MySQL Error:") . "<br />" . mysql_error());
205
<p><?php echo __("Creating new database."); ?></p>
209
$SQL = sprintf("CREATE DATABASE `%s`",
210
mysql_real_escape_string($db_name));
211
if (! @mysql_query($SQL, $db)) {
212
# Create database and user
213
reportError("3", __("Could not create a new database with the administrator details. Please check and try again.") . "<br /><br />" . "MySQL Error:" . "<br />" . mysql_error());
216
# Choose the MySQL DB to create a user
217
@mysql_select_db("mysql", $db);
219
# Make $db_host lowercase so it matches "localhost" if required.
220
$db_host = strtolower($db_host);
223
<p><?php echo __("Creating new user"); ?></p>
227
if ($db_host == 'localhost') {
228
$SQL = sprintf("GRANT ALL PRIVILEGES ON `%s`.* to '%s'@'%s' IDENTIFIED BY '%s'",
229
mysql_real_escape_string($db_name),
230
mysql_real_escape_string($db_user),
231
mysql_real_escape_string($db_host),
232
mysql_real_escape_string($db_pass));
235
$SQL = sprintf("GRANT ALL PRIVILEGES ON `%s`.* to '%s'@'%%' IDENTIFIED BY '%s'",
236
mysql_real_escape_string($db_name),
237
mysql_real_escape_string($db_user),
238
mysql_real_escape_string($db_pass));
240
if (! @mysql_query($SQL, $db)) {
241
reportError("3", __("Could not create a new user with the administrator details. Please check and try again.") . "<br /><br />" . __("MySQL Error:") . "<br />" . mysql_error());
245
@mysql_query("FLUSH PRIVILEGES", $db);
250
if (! ($db_host && $db_name && $db_user && $db_pass)) {
251
# Something was blank
253
reportError("4", __("A field was blank. Please fill in all fields.") . " " . $db_host . " " . $db_name . " " . $db_user . " " . $db_pass);
258
$db = @mysql_connect($db_host,$db_user,$db_pass);
261
reportError("4", __("Could not connect to MySQL with the Xibo User account details. Please check and try again.") . "<br /><br />" . __("MySQL Error:") . "<br />" . mysql_error());
264
@mysql_select_db($db_name,$db);
267
<p>Populating the database</p>
271
# Load from sql files to db - HOW?
272
$sql_files = ls('*.sql','install/database',false,array('return_files'));
274
// Sort the files in to sensible order, ie
285
// NB this is broken for 0 padded files
286
// eg 01.sql would be incorrectly sorted in the above example.
288
288
$sqlStatementCount = 0;
289
natcasesort($sql_files);
291
foreach ($sql_files as $filename) {
293
<p>Loading from <?php print $filename; ?>
298
$sql_file = @file_get_contents('install/database/' . $filename);
299
$sql_file = remove_remarks($sql_file);
300
$sql_file = split_sql_file($sql_file, $delimiter);
302
foreach ($sql_file as $sql) {
289
natcasesort($sql_files);
291
foreach ($sql_files as $filename) {
293
<p>Loading from <?php print $filename; ?>
298
$sql_file = @file_get_contents('install/database/' . $filename);
299
$sql_file = remove_remarks($sql_file);
300
$sql_file = split_sql_file($sql_file, $delimiter);
302
foreach ($sql_file as $sql) {
304
$sqlStatementCount++;
306
if (! @mysql_query($sql,$db)) {
307
reportError("4", __("An error occured populating the database.") . "<br /><br />" . __("MySQL Error:") . "<br />" . mysql_error() . "<br /><br />SQL executed:<br />" . $sql . "<br /><br />Statement number: " . $sqlStatementCount);
314
# Write out a new settings.php
315
$fh = fopen("settings.php", 'wt');
318
reportError("0", __("Unable to write to settings.php. We already checked this was possible earlier, so something changed."));
323
$settings_content = '$dbhost = \'' . $db_host . '\';' . "\n";
324
$settings_content .= '$dbuser = \'' . $db_user . '\';' . "\n";
325
$settings_content .= '$dbpass = \'' . $db_pass . '\';' . "\n";
326
$settings_content .= '$dbname = \'' . $db_name . '\';' . "\n\n";
327
$settings_content .= 'define(\'SECRET_KEY\',\'' . gen_secret() . '\');' . "\n";
329
if (! fwrite($fh, $settings_header . $settings_content . $settings_footer)) {
330
reportError("0", __("Unable to write to settings.php. We already checked this was possible earlier, so something changed."));
337
<div class="install_table">
338
<form action="install.php" method="POST">
339
<input type="hidden" name="xibo_step" value="6" />
341
<button type="submit"><?php echo __("Next"); ?> ></button>
345
elseif ($xibo_step == 6) {
346
# Form to get new admin password
349
<p><?php echo __("Xibo needs to set the \"xibo_admin\" user password. Please enter a password for this account below."); ?></p>
351
<div class="install_table">
352
<form action="install.php" method="POST">
353
<input type="hidden" name="xibo_step" value="7" />
354
<p><label for="password1"><?php echo __("Password:"); ?> </label><input type="password" name="password1" size="12" /></p>
355
<p><label for="password2"><?php echo __("Retype Password:"); ?> </label><input type="password" name="password2" size="12" /></p>
357
<button type="submit"><?php echo __("Next"); ?> ></button>
361
elseif ($xibo_step == 7) {
362
# Setup xibo_admin password
363
$password1 = Kit::GetParam('password1',_POST,_PASSWORD);
364
$password2 = Kit::GetParam('password2',_POST,_PASSWORD);
366
if (!(($password1 && $password2) && ($password1 == $password2))) {
367
reportError("6", __("Please input a new password. Ensure both password fields are identical."));
370
include('settings.php');
372
$password_hash = md5($password1);
374
$db = @mysql_connect($dbhost,$dbuser,$dbpass);
377
reportError("6", __("Could not connect to MySQL with the Xibo User account details saved in settings.php. Please check and try again.") . "<br /><br />" . __("MySQL Error:") . "<br />" . mysql_error());
380
@mysql_select_db($dbname,$db);
382
$SQL = sprintf("UPDATE `user` SET UserPassword = '%s' WHERE UserID = 1 LIMIT 1",
383
mysql_real_escape_string($password_hash));
384
if (! @mysql_query($SQL, $db)) {
385
reportError("6", __("An error occured changing the xibo_admin password.") . "<br /><br />" . __("MySQL Error:") . "<br />" . mysql_error());
392
<?php echo __("Successfully changed the xibo_admin password. We're nearly there now. Just a couple more steps!"); ?>
394
<form action="install.php" method="POST">
395
<input type="hidden" name="xibo_step" value="8" />
396
<button type="submit"><?php echo __("Next"); ?> ></button>
400
elseif ($xibo_step == 8) {
401
# Configure paths and keys
407
<p><b><?php echo __("Library Location"); ?></b></p>
408
<p><?php echo __("Xibo needs somewhere to store the things you upload to be shown. Ideally, this should be somewhere outside the root of your webserver - that is such that is not accessible by a web browser. Please input the full path to this folder. If the folder does not already exist, Xibo will attempt to create it for you."); ?></p>
409
<form action="install.php" method="POST">
410
<div class="install_table">
411
<p><label for="library_location"><?php echo __("Library Location:"); ?> </label><input type="text" name="library_location" value="" /></p>
413
<p><b><?php echo __("Server Key"); ?></b></p>
414
<p><?php echo __("Xibo needs you to choose a \"key\". This will be required each time you setup a new client. It should be complicated, and hard to remember. It is visible in the admin interface, so it need not be written down separately."); ?></p>
415
<div class="install_table">
416
<p><label for="server_key"><?php echo __("Server Key:"); ?> </label><input type="text" name="server_key" value="" /></p>
418
<p><b><?php echo __("Statistics"); ?></b></p>
419
<p><?php echo __("We'd love to know you're running Xibo. If you're happy for us to collect anonymous statistics (version number, number of displays) then please leave the box ticked. Please untick the box if your server does not have direct access to the internet."); ?></p>
420
<div class="install_table">
421
<p><label for="stats"><?php echo __("Anonymous Statistics:"); ?> </label><input type="checkbox" name="stats" value="true" checked /></p>
423
<input type="hidden" name="xibo_step" value="9" />
425
<button type="submit"><?php echo __("Next"); ?> ></button>
429
elseif ($xibo_step == 9) {
431
$server_key = Kit::GetParam('server_key',_POST,_WORD);
432
$library_location = Kit::GetParam('library_location',_POST,_STRING);
433
$stats = Kit::GetParam('stats',_POST,_BOOL);
435
// Remove trailing whitespace from the path given.
436
$library_location = trim($library_location);
438
// Check both fields were completed
439
if (! ($server_key && $library_location)) {
440
reportError("8", __("A field was blank. Please make sure you complete all fields"));
444
$stats="On"; // Fixme: translate ?
447
$stats="Off"; //Fixme : translate ?
450
// Does library_location exist already?
451
if (! is_dir($library_location)) {
452
if (is_file($library_location)) {
453
reportError("8", __("A file exists with the name you gave for the Library Location. Please choose another location"));
456
// Directory does not exist. Attempt to make it
457
// Using mkdir recursively, so it will attempt to make any
458
// intermediate folders required.
459
if (! mkdir($library_location,0755,true)) {
460
reportError("8", __("Could not create the Library Location directory for you. Please ensure the webserver has permission to create a folder in this location, or create the folder manually and grant permission for the webserver to write to the folder."));
465
// Is library_location writable?
466
if (! is_writable($library_location)) {
467
// Directory is not writable.
468
reportError("8", __("The Library Location you gave is not writable by the webserver. Please fix the permissions and try again."));
471
// Is library_location empty?
472
if (count(ls("*",$library_location,true)) > 0) {
473
reportError("8", __("The Library Location you gave is not empty. Please give the location of an empty folder"));
476
// Check if the user has added a trailing slash.
478
if (!((substr($library_location, -1) == '/') || (substr($library_location, -1) == '\\'))) {
479
$library_location = $library_location . '/';
482
include('settings.php');
484
$db = @mysql_connect($dbhost,$dbuser,$dbpass);
487
reportError("8", __("Could not connect to MySQL with the Xibo User account details saved in settings.php. Please check and try again.") . "<br /><br />" . __("MySQL Error:") . "<br />" . mysql_error());
490
@mysql_select_db($dbname,$db);
492
$SQL = sprintf("UPDATE `setting` SET `value` = '%s' WHERE `setting`.`setting` = 'LIBRARY_LOCATION' LIMIT 1",
493
mysql_real_escape_string($library_location));
494
if (! @mysql_query($SQL, $db)) {
495
reportError("8", __("An error occured changing the library location.") . "<br /><br />" . __("MySQL Error:") . "<br />" . mysql_error());
498
$SQL = sprintf("UPDATE `setting` SET `value` = '%s' WHERE `setting`.`setting` = 'SERVER_KEY' LIMIT 1",
499
mysql_real_escape_string($server_key));
500
if (! @mysql_query($SQL, $db)) {
501
reportError("8", __("An error occured changing the server key.") . "<br /><br />" . __("MySQL Error:") . "<br />" . mysql_error());
504
$SQL = sprintf("UPDATE `setting` SET `value` = '%s' WHERE `setting`.`setting` = 'defaultTimezone' LIMIT 1",
505
mysql_real_escape_string(date_default_timezone_get()));
506
if (! @mysql_query($SQL, $db)) {
507
reportError("8", __("An error occured setting the default timezone.") . "<br /><br />" . __("MySQL Error:") . "<br />" . mysql_error());
510
$SQL = sprintf("UPDATE `setting` SET `value` = '%s' WHERE `setting`.`setting` = 'PHONE_HOME' LIMIT 1",
511
mysql_real_escape_string($stats));
512
if (! @mysql_query($SQL, $db)) {
513
reportError("8", __("An error occured setting anonymous statistics.") . "<br /><br />" . __("MySQL Error:") . "<br />" . mysql_error());
515
$SQL = "UPDATE `setting` SET `value` = '" . md5(uniqid(rand(), true)) . "' WHERE `setting`.`setting` = 'PHONE_HOME_KEY' LIMIT 1";
516
if (! @mysql_query($SQL, $db)) {
517
reportError("8", __("An error occured setting anonymous statistics.") . "<br /><br />" . __("MySQL Error:") . "<br />" . mysql_error());
524
<p><?php echo __("Successfully set library location and server key."); ?></p>
526
<form action="install.php" method="POST">
527
<input type="hidden" name="xibo_step" value="10" />
528
<button type="submit"><?php echo __("Next"); ?> ></button>
532
elseif ($xibo_step == 10) {
534
# Redirect to login page.
535
if (! unlink('install.php')) {
536
reportError("10", __("Unable to delete install.php. Please ensure the webserver has permission to unlink this file and retry"), __("Retry")); // Fixme : translate "Retry" ?
538
if (! unlink('upgrade.php')) {
539
reportError("10", __("Unable to delete upgrade.php. Please ensure the webserver has permission to unlink this file and retry"), __("Retry")); // Fixme : translate "Retry" ?
543
<p><b><?php echo __("Xibo was successfully installed."); ?></b></p>
544
<p><?php echo __("Please click"); ?> <a href="index.php"><?php echo __("here"); ?></a> <?php echo __("to logon to Xibo as \"xibo_admin\" with the password you chose earlier."); ?></p>
549
reportError("0", __("A required parameter was missing. Please go through the installer sequentially!"), __("Start Again")); // Fixme : translate "Start Again" ?
552
include('install/footer.inc');
555
function checkFsPermissions() {
556
# Check for appropriate filesystem permissions
557
return ((is_writable("install.php") && (is_writable("settings.php")) && (is_writable("upgrade.php")) || is_writable(".")));
560
function checkMySQL() {
561
# Check PHP has MySQL module installed
562
return extension_loaded("mysql");
565
function checkJson() {
566
# Check PHP has JSON module installed
567
return extension_loaded("json");
571
# Check PHP has JSON module installed
572
return extension_loaded("gd");
575
function checkCal() {
576
# Check PHP has JSON module installed
577
return extension_loaded("calendar");
580
function reportError($step, $message, $button_text="< Back") { // fixme : translate ?
583
<?php print $message; ?>
585
<form action="install.php" method="POST">
586
<input type="hidden" name="xibo_step" value="<?php print $step; ?>"/>
587
<button type="submit"><?php print $button_text; ?></button>
590
include('install/footer.inc');
594
// Taken from http://forums.devshed.com/php-development-5/php-wont-load-sql-from-file-515902.html
597
* remove_remarks will strip the sql comment lines out of an uploaded sql file
599
function remove_remarks($sql){
600
$sql = preg_replace('/\n{2,}/', "\n", preg_replace('/^[-].*$/m', "\n", $sql));
601
$sql = preg_replace('/\n{2,}/', "\n", preg_replace('/^#.*$/m', "\n", $sql));
605
// Taken from http://forums.devshed.com/php-development-5/php-wont-load-sql-from-file-515902.html
608
* split_sql_file will split an uploaded sql file into single sql statements.
609
* Note: expects trim() to have already been run on $sql.
611
function split_sql_file($sql, $delimiter){
612
$sql = str_replace("\r" , '', $sql);
613
$data = preg_split('/' . preg_quote($delimiter, '/') . '$/m', $sql);
614
$data = array_map('trim', $data);
616
$end_data = end($data);
617
if (empty($end_data))
619
unset($data[key($data)]);
625
* This funtion will take a pattern and a folder as the argument and go thru it(recursivly if needed)and return the list of
626
* all files in that folder.
627
* Link : http://www.bin-co.com/php/scripts/filesystem/ls/
629
* Arguments : $pattern - The pattern to look out for [OPTIONAL]
630
* $folder - The path of the directory of which's directory list you want [OPTIONAL]
631
* $recursivly - The funtion will traverse the folder tree recursivly if this is true. Defaults to false. [OPTIONAL]
632
* $options - An array of values 'return_files' or 'return_folders' or both
633
* Returns : A flat list with the path of all the files(no folders) that matches the condition given.
635
function ls($pattern="*", $folder="", $recursivly=false, $options=array('return_files','return_folders')) {
637
$current_folder = realpath('.');
638
if(in_array('quiet', $options)) { // If quiet is on, we will suppress the 'no such folder' error
639
if(!file_exists($folder)) return array();
642
if(!chdir($folder)) return array();
646
$get_files = in_array('return_files', $options);
647
$get_folders= in_array('return_folders', $options);
651
// Get the all files and folders in the given directory.
652
if($get_files) $both = glob($pattern, GLOB_BRACE + GLOB_MARK);
653
if($recursivly or $get_folders) $folders = glob("*", GLOB_ONLYDIR + GLOB_MARK);
655
//If a pattern is specified, make sure even the folders match that pattern.
656
$matching_folders = array();
657
if($pattern !== '*') $matching_folders = glob($pattern, GLOB_ONLYDIR + GLOB_MARK);
659
//Get just the files by removing the folders from the list of all files.
660
$all = array_values(array_diff($both,$folders));
662
if($recursivly or $get_folders) {
663
foreach ($folders as $this_folder) {
665
//If a pattern is specified, make sure even the folders match that pattern.
666
if($pattern !== '*') {
667
if(in_array($this_folder, $matching_folders)) array_push($all, $this_folder);
669
else array_push($all, $this_folder);
673
// Continue calling this function for all the folders
674
$deep_items = ls($pattern, $this_folder, $recursivly, $options); # :RECURSION:
675
foreach ($deep_items as $item) {
676
array_push($all, $this_folder . $item);
682
if($folder) chdir($current_folder);
686
function gen_secret() {
687
# Generates a random 12 character alphanumeric string to use as a salt
688
mt_srand((double)microtime()*1000000);
690
for ($i=0; $i < 12; $i++) {
693
$key .= chr(mt_rand(65,90));
696
$key .= chr(mt_rand(97,122));
699
$key .= chr(mt_rand(48,57));
708
return (version_compare("5.2.4",phpversion(), "<="));
711
function CheckGettext()
713
return extension_loaded("gettext");
716
// Setup the translations for gettext
729
function settings_strings() {
730
global $settings_header;
731
global $settings_footer;
733
$settings_header = <<<END
737
* Xibo - Digital Signage - http://www.xibo.org.uk
739
* This file is part of Xibo - and is automatically generated by the installer
741
* You should not need to edit this file, unless your SQL connection details have changed.
744
defined('XIBO') or die(__("Sorry, you are not allowed to directly access this page.") . "<br />" . __("Please press the back button in your browser."));
754
$settings_footer = <<<END
304
$sqlStatementCount++;
306
if (! @mysql_query($sql,$db)) {
307
reportError("4", __("An error occured populating the database.") . "<br /><br />" . __("MySQL Error:") . "<br />" . mysql_error() . "<br /><br />SQL executed:<br />" . $sql . "<br /><br />Statement number: " . $sqlStatementCount);
314
# Write out a new settings.php
315
$fh = fopen("settings.php", 'wt');
318
reportError("0", __("Unable to write to settings.php. We already checked this was possible earlier, so something changed."));
323
$settings_content = '$dbhost = \'' . $db_host . '\';' . "\n";
324
$settings_content .= '$dbuser = \'' . $db_user . '\';' . "\n";
325
$settings_content .= '$dbpass = \'' . $db_pass . '\';' . "\n";
326
$settings_content .= '$dbname = \'' . $db_name . '\';' . "\n\n";
327
$settings_content .= 'define(\'SECRET_KEY\',\'' . gen_secret() . '\');' . "\n";
329
if (! fwrite($fh, $settings_header . $settings_content . $settings_footer)) {
330
reportError("0", __("Unable to write to settings.php. We already checked this was possible earlier, so something changed."));
337
<div class="install_table">
338
<form action="install.php" method="POST">
339
<input type="hidden" name="xibo_step" value="6" />
341
<button type="submit"><?php echo __("Next"); ?> ></button>
345
elseif ($xibo_step == 6) {
346
# Form to get new admin password
349
<p><?php echo __("Xibo needs to set the \"xibo_admin\" user password. Please enter a password for this account below."); ?></p>
351
<div class="install_table">
352
<form action="install.php" method="POST">
353
<input type="hidden" name="xibo_step" value="7" />
354
<p><label for="password1"><?php echo __("Password:"); ?> </label><input type="password" name="password1" size="12" /></p>
355
<p><label for="password2"><?php echo __("Retype Password:"); ?> </label><input type="password" name="password2" size="12" /></p>
357
<button type="submit"><?php echo __("Next"); ?> ></button>
361
elseif ($xibo_step == 7) {
362
# Setup xibo_admin password
363
$password1 = Kit::GetParam('password1',_POST,_PASSWORD);
364
$password2 = Kit::GetParam('password2',_POST,_PASSWORD);
366
if (!(($password1 && $password2) && ($password1 == $password2))) {
367
reportError("6", __("Please input a new password. Ensure both password fields are identical."));
370
include('settings.php');
372
$password_hash = md5($password1);
374
$db = @mysql_connect($dbhost,$dbuser,$dbpass);
377
reportError("6", __("Could not connect to MySQL with the Xibo User account details saved in settings.php. Please check and try again.") . "<br /><br />" . __("MySQL Error:") . "<br />" . mysql_error());
380
@mysql_select_db($dbname,$db);
382
$SQL = sprintf("UPDATE `user` SET UserPassword = '%s' WHERE UserID = 1 LIMIT 1",
383
mysql_real_escape_string($password_hash));
384
if (! @mysql_query($SQL, $db)) {
385
reportError("6", __("An error occured changing the xibo_admin password.") . "<br /><br />" . __("MySQL Error:") . "<br />" . mysql_error());
392
<?php echo __("Successfully changed the xibo_admin password. We're nearly there now. Just a couple more steps!"); ?>
394
<form action="install.php" method="POST">
395
<input type="hidden" name="xibo_step" value="8" />
396
<button type="submit"><?php echo __("Next"); ?> ></button>
400
elseif ($xibo_step == 8) {
401
# Configure paths and keys
407
<p><b><?php echo __("Library Location"); ?></b></p>
408
<p><?php echo __("Xibo needs somewhere to store the things you upload to be shown. Ideally, this should be somewhere outside the root of your webserver - that is such that is not accessible by a web browser. Please input the full path to this folder. If the folder does not already exist, Xibo will attempt to create it for you."); ?></p>
409
<form action="install.php" method="POST">
410
<div class="install_table">
411
<p><label for="library_location"><?php echo __("Library Location:"); ?> </label><input type="text" name="library_location" value="" /></p>
413
<p><b><?php echo __("Server Key"); ?></b></p>
414
<p><?php echo __("Xibo needs you to choose a \"key\". This will be required each time you setup a new client. It should be complicated, and hard to remember. It is visible in the admin interface, so it need not be written down separately."); ?></p>
415
<div class="install_table">
416
<p><label for="server_key"><?php echo __("Server Key:"); ?> </label><input type="text" name="server_key" value="" /></p>
418
<p><b><?php echo __("Statistics"); ?></b></p>
419
<p><?php echo __("We'd love to know you're running Xibo. If you're happy for us to collect anonymous statistics (version number, number of displays) then please leave the box ticked. Please untick the box if your server does not have direct access to the internet."); ?></p>
420
<div class="install_table">
421
<p><label for="stats"><?php echo __("Anonymous Statistics:"); ?> </label><input type="checkbox" name="stats" value="true" checked /></p>
423
<input type="hidden" name="xibo_step" value="9" />
425
<button type="submit"><?php echo __("Next"); ?> ></button>
429
elseif ($xibo_step == 9) {
431
$server_key = Kit::GetParam('server_key',_POST,_WORD);
432
$library_location = Kit::GetParam('library_location',_POST,_STRING);
433
$stats = Kit::GetParam('stats',_POST,_BOOL);
435
// Remove trailing whitespace from the path given.
436
$library_location = trim($library_location);
438
// Check both fields were completed
439
if (! ($server_key && $library_location)) {
440
reportError("8", __("A field was blank. Please make sure you complete all fields"));
444
$stats="On"; // Fixme: translate ?
447
$stats="Off"; //Fixme : translate ?
450
// Does library_location exist already?
451
if (! is_dir($library_location)) {
452
if (is_file($library_location)) {
453
reportError("8", __("A file exists with the name you gave for the Library Location. Please choose another location"));
456
// Directory does not exist. Attempt to make it
457
// Using mkdir recursively, so it will attempt to make any
458
// intermediate folders required.
459
if (! mkdir($library_location,0755,true)) {
460
reportError("8", __("Could not create the Library Location directory for you. Please ensure the webserver has permission to create a folder in this location, or create the folder manually and grant permission for the webserver to write to the folder."));
465
// Is library_location writable?
466
if (! is_writable($library_location)) {
467
// Directory is not writable.
468
reportError("8", __("The Library Location you gave is not writable by the webserver. Please fix the permissions and try again."));
471
// Is library_location empty?
472
if (count(ls("*",$library_location,true)) > 0) {
473
reportError("8", __("The Library Location you gave is not empty. Please give the location of an empty folder"));
476
// Check if the user has added a trailing slash.
478
if (!((substr($library_location, -1) == '/') || (substr($library_location, -1) == '\\'))) {
479
$library_location = $library_location . '/';
482
include('settings.php');
484
$db = @mysql_connect($dbhost,$dbuser,$dbpass);
487
reportError("8", __("Could not connect to MySQL with the Xibo User account details saved in settings.php. Please check and try again.") . "<br /><br />" . __("MySQL Error:") . "<br />" . mysql_error());
490
@mysql_select_db($dbname,$db);
492
$SQL = sprintf("UPDATE `setting` SET `value` = '%s' WHERE `setting`.`setting` = 'LIBRARY_LOCATION' LIMIT 1",
493
mysql_real_escape_string($library_location));
494
if (! @mysql_query($SQL, $db)) {
495
reportError("8", __("An error occured changing the library location.") . "<br /><br />" . __("MySQL Error:") . "<br />" . mysql_error());
498
$SQL = sprintf("UPDATE `setting` SET `value` = '%s' WHERE `setting`.`setting` = 'SERVER_KEY' LIMIT 1",
499
mysql_real_escape_string($server_key));
500
if (! @mysql_query($SQL, $db)) {
501
reportError("8", __("An error occured changing the server key.") . "<br /><br />" . __("MySQL Error:") . "<br />" . mysql_error());
504
$SQL = sprintf("UPDATE `setting` SET `value` = '%s' WHERE `setting`.`setting` = 'defaultTimezone' LIMIT 1",
505
mysql_real_escape_string(date_default_timezone_get()));
506
if (! @mysql_query($SQL, $db)) {
507
reportError("8", __("An error occured setting the default timezone.") . "<br /><br />" . __("MySQL Error:") . "<br />" . mysql_error());
510
$SQL = sprintf("UPDATE `setting` SET `value` = '%s' WHERE `setting`.`setting` = 'PHONE_HOME' LIMIT 1",
511
mysql_real_escape_string($stats));
512
if (! @mysql_query($SQL, $db)) {
513
reportError("8", __("An error occured setting anonymous statistics.") . "<br /><br />" . __("MySQL Error:") . "<br />" . mysql_error());
515
$SQL = "UPDATE `setting` SET `value` = '" . md5(uniqid(rand(), true)) . "' WHERE `setting`.`setting` = 'PHONE_HOME_KEY' LIMIT 1";
516
if (! @mysql_query($SQL, $db)) {
517
reportError("8", __("An error occured setting anonymous statistics.") . "<br /><br />" . __("MySQL Error:") . "<br />" . mysql_error());
524
<p><?php echo __("Successfully set library location and server key."); ?></p>
526
<form action="install.php" method="POST">
527
<input type="hidden" name="xibo_step" value="10" />
528
<button type="submit"><?php echo __("Next"); ?> ></button>
532
elseif ($xibo_step == 10) {
534
# Redirect to login page.
535
if (! unlink('install.php')) {
536
reportError("10", __("Unable to delete install.php. Please ensure the webserver has permission to unlink this file and retry"), __("Retry")); // Fixme : translate "Retry" ?
538
if (! unlink('upgrade.php')) {
539
reportError("10", __("Unable to delete upgrade.php. Please ensure the webserver has permission to unlink this file and retry"), __("Retry")); // Fixme : translate "Retry" ?
543
<p><b><?php echo __("Xibo was successfully installed."); ?></b></p>
544
<p><?php echo __("Please click"); ?> <a href="index.php"><?php echo __("here"); ?></a> <?php echo __("to logon to Xibo as \"xibo_admin\" with the password you chose earlier."); ?></p>
549
reportError("0", __("A required parameter was missing. Please go through the installer sequentially!"), __("Start Again")); // Fixme : translate "Start Again" ?
552
include('install/footer.inc');
555
function checkFsPermissions() {
556
# Check for appropriate filesystem permissions
557
return ((is_writable("install.php") && (is_writable("settings.php")) && (is_writable("upgrade.php")) || is_writable(".")));
560
function checkMySQL() {
561
# Check PHP has MySQL module installed
562
return extension_loaded("mysql");
565
function checkJson() {
566
# Check PHP has JSON module installed
567
return extension_loaded("json");
571
# Check PHP has JSON module installed
572
return extension_loaded("gd");
575
function checkCal() {
576
# Check PHP has JSON module installed
577
return extension_loaded("calendar");
580
function reportError($step, $message, $button_text="< Back") { // fixme : translate ?
583
<?php print $message; ?>
585
<form action="install.php" method="POST">
586
<input type="hidden" name="xibo_step" value="<?php print $step; ?>"/>
587
<button type="submit"><?php print $button_text; ?></button>
590
include('install/footer.inc');
594
// Taken from http://forums.devshed.com/php-development-5/php-wont-load-sql-from-file-515902.html
597
* remove_remarks will strip the sql comment lines out of an uploaded sql file
599
function remove_remarks($sql){
600
$sql = preg_replace('/\n{2,}/', "\n", preg_replace('/^[-].*$/m', "\n", $sql));
601
$sql = preg_replace('/\n{2,}/', "\n", preg_replace('/^#.*$/m', "\n", $sql));
605
// Taken from http://forums.devshed.com/php-development-5/php-wont-load-sql-from-file-515902.html
608
* split_sql_file will split an uploaded sql file into single sql statements.
609
* Note: expects trim() to have already been run on $sql.
611
function split_sql_file($sql, $delimiter){
612
$sql = str_replace("\r" , '', $sql);
613
$data = preg_split('/' . preg_quote($delimiter, '/') . '$/m', $sql);
614
$data = array_map('trim', $data);
616
$end_data = end($data);
617
if (empty($end_data))
619
unset($data[key($data)]);
625
* This funtion will take a pattern and a folder as the argument and go thru it(recursivly if needed)and return the list of
626
* all files in that folder.
627
* Link : http://www.bin-co.com/php/scripts/filesystem/ls/
629
* Arguments : $pattern - The pattern to look out for [OPTIONAL]
630
* $folder - The path of the directory of which's directory list you want [OPTIONAL]
631
* $recursivly - The funtion will traverse the folder tree recursivly if this is true. Defaults to false. [OPTIONAL]
632
* $options - An array of values 'return_files' or 'return_folders' or both
633
* Returns : A flat list with the path of all the files(no folders) that matches the condition given.
635
function ls($pattern="*", $folder="", $recursivly=false, $options=array('return_files','return_folders')) {
637
$current_folder = realpath('.');
638
if(in_array('quiet', $options)) { // If quiet is on, we will suppress the 'no such folder' error
639
if(!file_exists($folder)) return array();
642
if(!chdir($folder)) return array();
646
$get_files = in_array('return_files', $options);
647
$get_folders= in_array('return_folders', $options);
651
// Get the all files and folders in the given directory.
652
if($get_files) $both = glob($pattern, GLOB_BRACE + GLOB_MARK);
653
if($recursivly or $get_folders) $folders = glob("*", GLOB_ONLYDIR + GLOB_MARK);
655
//If a pattern is specified, make sure even the folders match that pattern.
656
$matching_folders = array();
657
if($pattern !== '*') $matching_folders = glob($pattern, GLOB_ONLYDIR + GLOB_MARK);
659
//Get just the files by removing the folders from the list of all files.
660
$all = array_values(array_diff($both,$folders));
662
if($recursivly or $get_folders) {
663
foreach ($folders as $this_folder) {
665
//If a pattern is specified, make sure even the folders match that pattern.
666
if($pattern !== '*') {
667
if(in_array($this_folder, $matching_folders)) array_push($all, $this_folder);
669
else array_push($all, $this_folder);
673
// Continue calling this function for all the folders
674
$deep_items = ls($pattern, $this_folder, $recursivly, $options); # :RECURSION:
675
foreach ($deep_items as $item) {
676
array_push($all, $this_folder . $item);
682
if($folder) chdir($current_folder);
686
function gen_secret() {
687
# Generates a random 12 character alphanumeric string to use as a salt
688
mt_srand((double)microtime()*1000000);
690
for ($i=0; $i < 12; $i++) {
693
$key .= chr(mt_rand(65,90));
696
$key .= chr(mt_rand(97,122));
699
$key .= chr(mt_rand(48,57));
708
return (version_compare("5.2.4",phpversion(), "<="));
711
function CheckGettext()
713
return extension_loaded("gettext");
716
// Setup the translations for gettext
729
function settings_strings() {
730
global $settings_header;
731
global $settings_footer;
733
$settings_header = <<<END
737
* Xibo - Digital Signage - http://www.xibo.org.uk
739
* This file is part of Xibo - and is automatically generated by the installer
741
* You should not need to edit this file, unless your SQL connection details have changed.
744
defined('XIBO') or die(__("Sorry, you are not allowed to directly access this page.") . "<br />" . __("Please press the back button in your browser."));
754
$settings_footer = <<<END
b'\\ No newline at end of file'