2 /**********************************************************************
3 Copyright (C) FrontAccounting, LLC.
4 Released under the terms of the GNU General Public License, GPL,
5 as published by the Free Software Foundation, either version 3
6 of the License, or (at your option) any later version.
7 This program is distributed in the hope that it will be useful,
8 but WITHOUT ANY WARRANTY; without even the implied warranty of
9 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10 See the License here <http://www.gnu.org/licenses/gpl-3.0.html>.
11 ***********************************************************************/
12 $page_security = 'SA_OPEN';
15 if (file_exists($path_to_root.'/config_db.php'))
16 header("Location: $path_to_root/index.php");
18 include($path_to_root . "/install/isession.inc");
20 page(_("FrontAccouting ERP Installation Wizard"), true, false, "", '', false, 'stylesheet.css');
22 include($path_to_root . "/includes/ui.inc");
23 include($path_to_root . "/includes/system_tests.inc");
24 include($path_to_root . "/admin/db/maintenance_db.inc");
25 include($path_to_root . "/includes/packages.inc");
26 @include($path_to_root . "/installed_extensions.php");
27 //-------------------------------------------------------------------------------------------------
29 function subpage_title($txt)
33 echo '<center><img src="'.$path_to_root.'/themes/default/images/logo_frontaccounting.png" width="250" height="50" alt="Logo" />
36 $page = @$_POST['Page'] ? $_POST['Page'] : 1;
40 _("FrontAccouting ERP Installation Wizard").'<br>'
41 . sprintf(_('Step %d: %s'), $page , $txt));
45 function display_coas()
47 start_table(TABLESTYLE);
48 $th = array(_("Chart of accounts"), _("Encoding"), _("Description"), _("Install"));
52 $charts = get_charts_list();
54 foreach($charts as $pkg_name => $coa)
56 $available = @$coa['available'];
57 $installed = @$coa['version'];
58 $id = @$coa['local_id'];
60 alt_table_row_color($k);
61 label_cell($coa['name']);
62 label_cell($coa['encoding']);
63 label_cell(is_array($coa['Descr']) ? implode('<br>', $coa['Descr']) : $coa['Descr']);
64 label_cell($installed ?
65 _("Installed") : checkbox(null, 'coas['.$coa['package'].']'), "align='center'");
72 function display_langs()
74 start_table(TABLESTYLE);
75 $th = array(_("Language"), _("Encoding"), _("Description"), _("Install"));
79 $langs = get_languages_list();
81 foreach($langs as $pkg_name => $lang)
83 $available = @$lang['available'];
84 $installed = @$lang['version'];
85 $id = @$lang['local_id'];
86 if (!$available) continue;
88 alt_table_row_color($k);
89 label_cell($lang['name']);
90 label_cell($lang['encoding']);
91 label_cell(is_array($lang['Descr']) ? implode('<br>', $lang['Descr']) : $lang['Descr']);
92 label_cell($installed ?
93 _("Installed") : checkbox(null, 'langs['.$lang['package'].']'), "align='center'");
99 function instlang_list_row($label, $name, $value=null) {
104 foreach ($inst_langs as $n => $lang)
105 $langs[$n] = $lang['name'];
107 echo "<td>$label</td>\n" . "<td>\n"
108 .array_selector($name, $value, $langs,
110 'select_submit' => true,
115 function install_connect_db() {
119 $conn = $_SESSION['inst_set'];
121 $db = mysql_connect($conn["host"] , $conn["dbuser"], $conn["dbpassword"]);
123 display_error('Cannot connect to database server. Host name, username and/or password incorrect.');
126 if (!defined('TB_PREF'))
127 define('TB_PREF', '&TB_PREF&');
129 if (!mysql_select_db($conn["dbname"], $db)) {
130 $sql = "CREATE DATABASE " . $conn["dbname"];
131 if (!mysql_query($sql)) {
132 display_error('Cannot create database. Check your permissions to database creation or selct already created database.');
135 return mysql_select_db($conn["dbname"], $db);
140 function do_install() {
142 global $path_to_root, $db_connections, $def_coy, $installed_extensions,
143 $dflt_lang, $installed_languages;
145 $coa = $_SESSION['inst_set']['coa'];
146 if (install_connect_db() && db_import($path_to_root.'/sql/'.$coa, $_SESSION['inst_set'])) {
147 $con = $_SESSION['inst_set'];
148 $table_prefix = $con['tbpref'];
151 $tb_pref_counter = 0;
152 $db_connections = array (0=> array (
153 'name' => $con['name'],
154 'host' => $con['host'],
155 'dbuser' => $con['dbuser'],
156 'dbpassword' => $con['dbpassword'],
157 'dbname' => $con['dbname'],
158 'tbpref' => $table_prefix
161 $_SESSION['wa_current_user']->cur_con = 0;
163 update_company_prefs(array('coy_name'=>$con['name']));
164 $admin = get_user_by_login('admin');
165 // update_admin_password($con, md5($con['pass']));
166 update_user_prefs($admin['id'], array('language' => $_POST['lang'],
167 'password' => md5($con['pass'])));
169 if (!copy($path_to_root. "/config.default.php", $path_to_root. "/config.php")) {
170 display_error(_("Cannot save system configuration file 'config.php'."));
174 $err = write_config_db($table_prefix != "");
177 display_error(_("Cannot open 'config_db.php' configuration file."));
179 } else if ($err == -2) {
180 display_error(_("Cannot write to the 'config_db.php' configuration file."));
182 } else if ($err == -3) {
183 display_error(_("Configuration file 'config_db.php' is not writable. Change its permissions so it is, then re-run installation step."));
186 // update default language
187 include_once($path_to_root . "/lang/installed_languages.inc");
188 $dflt_lang = $_POST['lang'];
190 if (!isset($installed_extensions))
191 write_extensions(array());
197 if (!isset($_SESSION['inst_set'])) // default settings
198 $_SESSION['inst_set'] = array(
202 'username' => 'admin',
208 if (!@$_POST['Tests'])
209 $_POST['Page'] = 1; // set to start page
211 if (isset($_POST['back']) && (@$_POST['Page']>1)) {
212 if ($_POST['Page'] == 5)
217 elseif (isset($_POST['continue'])) {
220 elseif (isset($_POST['db_test'])) {
221 if (get_post('host')=='') {
222 display_error(_('Host name cannot be empty.'));
225 elseif ($_POST['dbuser']=='') {
226 display_error(_('Database user name cannot be empty.'));
229 elseif ($_POST['dbname']=='') {
230 display_error(_('Database name cannot be empty.'));
234 $_SESSION['inst_set'] = array_merge($_SESSION['inst_set'], array(
235 'host' => $_POST['host'],
236 'dbuser' => $_POST['dbuser'],
237 'dbpassword' => $_POST['dbpassword'],
238 'dbname' => $_POST['dbname'],
239 'tbpref' => $_POST['tbpref'] ? '0_' : '',
240 'sel_langs' => check_value('sel_langs'),
241 'sel_coas' => check_value('sel_coas'),
243 if (install_connect_db()) {
244 $_POST['Page'] = check_value('sel_langs') ? 3 :
245 (check_value('sel_coas') ? 4 : 5);
248 if (!file_exists($path_to_root . "/lang/installed_languages.inc")) {
249 $installed_languages = array (
250 0 => array ('code' => 'C', 'name' => 'English', 'encoding' => 'iso-8859-1'));
255 elseif(get_post('install_langs'))
258 if (isset($_POST['langs']))
259 foreach($_POST['langs'] as $package => $ok) {
260 $ret &= install_language($package);
263 $_POST['Page'] = $_SESSION['inst_set']['sel_coas'] ? 4 : 5;
266 elseif(get_post('install_coas'))
269 $next_extension_id = 0;
271 if (isset($_POST['coas']))
272 foreach($_POST['coas'] as $package => $ok) {
273 $ret &= install_extension($package);
276 @include($path_to_root.'/installed_extensions.php');
280 elseif (isset($_POST['set_admin'])) {
281 // check company settings
282 if (get_post('name')=='') {
283 display_error(_('Company name cannot be empty.'));
286 elseif (get_post('admin')=='') {
287 display_error(_('Company admin name cannot be empty.'));
290 elseif (get_post('pass')=='') {
291 display_error(_('Company admin password cannot be empty.'));
294 elseif (get_post('pass')!=get_post('repass')) {
295 display_error(_('Company admin passwords differ.'));
296 unset($_POST['pass'],$_POST['repass']);
301 $_SESSION['inst_set'] = array_merge($_SESSION['inst_set'], array(
302 'coa' => $_POST['coa'],
303 'pass' => $_POST['pass'],
304 'name' => $_POST['name'],
305 'admin' => $_POST['admin'],
313 if (list_updated('inst_lang')) {
314 $_SESSION['inst_set']['inst_lang'] = get_post('inst_lang');
315 $Ajax->setEncoding($inst_langs[get_post('inst_lang')]['encoding']);
316 $Ajax->activate('welcome');
320 switch(@$_POST['Page']) {
322 // include ('../install.html');
323 // submit_center('continue', _('Continue >>'));
326 div_start('welcome');
327 subpage_title(_('System Diagnostics'));
329 instlang_list_row(_("Select install wizard language:"), 'inst_lang',
330 $_SESSION['inst_set']['inst_lang']);
332 $_POST['Tests'] = display_system_tests(true);
334 if (@$_POST['Tests']) {
335 display_notification(_('All application preliminary requirements seems to be correct. Please press Continue button below.'));
336 submit_center('continue', _('Continue >>'));
338 display_error(_('Application cannot be installed. Please fix problems listed below in red, and press Refresh button.'));
339 submit_center('refresh', _('Refresh'));
345 if (!isset($_POST['host'])) {
346 foreach($_SESSION['inst_set'] as $name => $val)
347 $_POST[$name] = $val;
349 subpage_title(_('Database Server Settings'));
350 start_table(TABLESTYLE);
351 text_row_ex(_("Server Host:"), 'host', 30);
352 text_row_ex(_("Database User:"), 'dbuser', 30);
353 text_row_ex(_("Database Password:"), 'dbpassword', 30);
354 text_row_ex(_("Database Name:"), 'dbname', 30);
355 yesno_list_row(_("Use '0_' Table Prefix:"), 'tbpref', 1, _('Yes'), _('No'), false);
356 check_row(_("Install Additional Language Packs from FA Repository:"), 'sel_langs');
357 check_row(_("Install Additional COAs from FA Repository:"), 'sel_coas');
359 display_note(_('Use table prefix if you share selected database for more than one FA company.'));
360 display_note(_("Do not select additional langs nor COAs if you have no working internet connection right now. You can install them later."));
361 submit_center_first('back', _('<< Back'));
362 submit_center_last('db_test', _('Continue >>'));
365 case '3': // select langauges
366 subpage_title(_('User Interface Languages Selection'));
368 submit_center_first('back', _('<< Back'));
369 submit_center_last('install_langs', _('Continue >>'));
372 case '4': // select COA
373 subpage_title(_('Charts of Accounts Selection'));
375 submit_center_first('back', _('<< Back'));
376 submit_center_last('install_coas', _('Continue >>'));
380 if (!isset($_POST['name'])) {
381 foreach($_SESSION['inst_set'] as $name => $val)
382 $_POST[$name] = $val;
385 subpage_title(_('Company Settings'));
386 start_table(TABLESTYLE);
387 text_row_ex(_("Company Name:"), 'name', 30);
388 text_row_ex(_("Admin Login:"), 'admin', 30);
389 password_row(_("Admin Password:"), 'pass', @$_POST['pass']);
390 password_row(_("Reenter Password:"), 'repass', @$_POST['repass']);
391 coa_list_row(_("Select Chart of Accounts:"), 'coa');
392 languages_list_row(_("Select Default Language:"), 'lang');
394 submit_center_first('back', _('<< Back'));
395 submit_center_last('set_admin', _('Continue >>'));
398 case '6': // final screen
399 subpage_title(_('FrontAccounting ERP has been installed successsfully.'));
400 display_note(_('Please do not forget to remove install wizard folder.'));
401 $install_done = true;
402 hyperlink_no_params($path_to_root.'/index.php', _('Click here to start.'));
411 end_page(false, false, true);