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 if (file_exists($path_to_root . "/installed_extensions.php"))
27 include($path_to_root . "/installed_extensions.php");
28 //-------------------------------------------------------------------------------------------------
30 function subpage_title($txt)
34 echo '<center><img src="'.$path_to_root.'/themes/default/images/logo_frontaccounting.png" width="250" height="50" alt="Logo" />
37 $page = @$_POST['Page'] ? $_POST['Page'] : 1;
41 _("FrontAccouting ERP Installation Wizard").'<br>'
42 . sprintf(_('Step %d: %s'), $page , $txt));
46 function display_coas()
48 start_table(TABLESTYLE);
49 $th = array(_("Chart of accounts"), _("Encoding"), _("Description"), _("Install"));
53 $charts = get_charts_list();
55 foreach($charts as $pkg_name => $coa)
57 $available = @$coa['available'];
58 $installed = @$coa['version'];
59 $id = @$coa['local_id'];
61 alt_table_row_color($k);
62 label_cell($coa['name']);
63 label_cell($coa['encoding']);
64 label_cell(is_array($coa['Descr']) ? implode('<br>', $coa['Descr']) : $coa['Descr']);
65 label_cell($installed ?
66 _("Installed") : checkbox(null, 'coas['.$coa['package'].']'), "align='center'");
73 function display_langs()
75 start_table(TABLESTYLE);
76 $th = array(_("Language"), _("Encoding"), _("Description"), _("Install"));
80 $langs = get_languages_list();
82 foreach($langs as $pkg_name => $lang)
84 $available = @$lang['available'];
85 $installed = @$lang['version'];
86 $id = @$lang['local_id'];
87 if (!$available) continue;
89 alt_table_row_color($k);
90 label_cell($lang['name']);
91 label_cell($lang['encoding']);
92 label_cell(is_array($lang['Descr']) ? implode('<br>', $lang['Descr']) : $lang['Descr']);
93 label_cell($installed ?
94 _("Installed") : checkbox(null, 'langs['.$lang['package'].']'), "align='center'");
100 function instlang_list_row($label, $name, $value=null) {
105 foreach ($inst_langs as $n => $lang)
106 $langs[$n] = $lang['name'];
108 echo "<td>$label</td>\n" . "<td>\n"
109 .array_selector($name, $value, $langs,
111 'select_submit' => true,
116 function install_connect_db() {
120 $conn = $_SESSION['inst_set'];
122 $db = db_create_db($conn);
124 display_error(_("Cannot connect to database. User or password is invalid or you have no permittions to create database."));
126 if (strncmp(db_get_version(), "5.6", 3) >= 0)
127 db_query("SET sql_mode = ''");
132 function do_install() {
134 global $path_to_root, $db_connections, $def_coy, $installed_extensions, $tb_pref_counter,
135 $dflt_lang, $installed_languages;
137 $coa = $_SESSION['inst_set']['coa'];
138 if (install_connect_db() && db_import($path_to_root.'/sql/'.$coa, $_SESSION['inst_set'])) {
139 $con = $_SESSION['inst_set'];
140 $table_prefix = $con['tbpref'];
143 $tb_pref_counter = 0;
144 $db_connections = array (0=> array (
145 'name' => $con['name'],
146 'host' => $con['host'],
147 'dbuser' => $con['dbuser'],
148 'dbpassword' => $con['dbpassword'],
149 'dbname' => $con['dbname'],
150 'tbpref' => $table_prefix
153 $_SESSION['wa_current_user']->cur_con = 0;
155 update_company_prefs(array('coy_name'=>$con['name']));
156 $admin = get_user_by_login('admin');
157 update_user_prefs($admin['id'], array(
158 'language' => $con['lang'],
159 'password' => md5($con['pass']),
160 'user_id' => $con['admin']));
162 if (!copy($path_to_root. "/config.default.php", $path_to_root. "/config.php")) {
163 display_error(_("Cannot save system configuration file 'config.php'."));
167 $err = write_config_db($table_prefix != "");
170 display_error(_("Cannot open 'config_db.php' configuration file."));
172 } else if ($err == -2) {
173 display_error(_("Cannot write to the 'config_db.php' configuration file."));
175 } else if ($err == -3) {
176 display_error(_("Configuration file 'config_db.php' is not writable. Change its permissions so it is, then re-run installation step."));
179 // update default language
180 if (file_exists($path_to_root . "/lang/installed_languages.inc"))
181 include_once($path_to_root . "/lang/installed_languages.inc");
182 $dflt_lang = $_POST['lang'];
189 if (!isset($_SESSION['inst_set'])) // default settings
190 $_SESSION['inst_set'] = array(
194 'username' => 'admin',
200 if (!@$_POST['Tests'])
201 $_POST['Page'] = 1; // set to start page
203 if (isset($_POST['back']) && (@$_POST['Page']>1)) {
204 if ($_POST['Page'] == 5)
209 elseif (isset($_POST['continue'])) {
212 elseif (isset($_POST['db_test'])) {
213 if (get_post('host')=='') {
214 display_error(_('Host name cannot be empty.'));
217 elseif ($_POST['dbuser']=='') {
218 display_error(_('Database user name cannot be empty.'));
221 elseif ($_POST['dbname']=='') {
222 display_error(_('Database name cannot be empty.'));
226 $_SESSION['inst_set'] = array_merge($_SESSION['inst_set'], array(
227 'host' => $_POST['host'],
228 'dbuser' => $_POST['dbuser'],
229 'dbpassword' => $_POST['dbpassword'],
230 'dbname' => $_POST['dbname'],
231 'tbpref' => $_POST['tbpref'] ? '0_' : '',
232 'sel_langs' => check_value('sel_langs'),
233 'sel_coas' => check_value('sel_coas'),
235 if (install_connect_db()) {
236 $_POST['Page'] = check_value('sel_langs') ? 3 :
237 (check_value('sel_coas') ? 4 : 5);
240 if (!file_exists($path_to_root . "/lang/installed_languages.inc")) {
241 $installed_languages = array (
242 0 => array ('code' => 'C', 'name' => 'English', 'encoding' => 'iso-8859-1'));
247 elseif(get_post('install_langs'))
250 if (isset($_POST['langs']))
251 foreach($_POST['langs'] as $package => $ok) {
252 $ret &= install_language($package);
255 $_POST['Page'] = $_SESSION['inst_set']['sel_coas'] ? 4 : 5;
258 elseif(get_post('install_coas'))
261 $next_extension_id = 0;
263 if (isset($_POST['coas']))
264 foreach($_POST['coas'] as $package => $ok) {
265 $ret &= install_extension($package);
268 if (file_exists($path_to_root . '/installed_extensions.php'))
269 include($path_to_root.'/installed_extensions.php');
272 } elseif (isset($_POST['set_admin'])) {
273 // check company settings
274 if (get_post('name')=='') {
275 display_error(_('Company name cannot be empty.'));
278 elseif (get_post('admin')=='') {
279 display_error(_('Company admin name cannot be empty.'));
282 elseif (get_post('pass')=='') {
283 display_error(_('Company admin password cannot be empty.'));
286 elseif (get_post('pass')!=get_post('repass')) {
287 display_error(_('Company admin passwords differ.'));
288 unset($_POST['pass'],$_POST['repass']);
293 $_SESSION['inst_set'] = array_merge($_SESSION['inst_set'], array(
294 'coa' => $_POST['coa'],
295 'pass' => $_POST['pass'],
296 'name' => $_POST['name'],
297 'admin' => $_POST['admin'],
298 'lang' => $_POST['lang']
306 if (list_updated('inst_lang')) {
307 $_SESSION['inst_set']['inst_lang'] = get_post('inst_lang');
308 $Ajax->setEncoding($inst_langs[get_post('inst_lang')]['encoding']);
309 $Ajax->activate('welcome');
313 switch(@$_POST['Page']) {
315 // include ('../install.html');
316 // submit_center('continue', _('Continue >>'));
319 div_start('welcome');
320 subpage_title(_('System Diagnostics'));
322 instlang_list_row(_("Select install wizard language:"), 'inst_lang',
323 $_SESSION['inst_set']['inst_lang']);
325 $_POST['Tests'] = display_system_tests(true);
327 if (@$_POST['Tests']) {
328 display_notification(_('All application preliminary requirements seems to be correct. Please press Continue button below.'));
329 submit_center('continue', _('Continue >>'));
331 display_error(_('Application cannot be installed. Please fix problems listed below in red, and press Refresh button.'));
332 submit_center('refresh', _('Refresh'));
338 if (!isset($_POST['host'])) {
339 foreach($_SESSION['inst_set'] as $name => $val)
340 $_POST[$name] = $val;
342 subpage_title(_('Database Server Settings'));
343 start_table(TABLESTYLE);
344 text_row_ex(_("Server Host:"), 'host', 30, 60);
345 text_row_ex(_("Database User:"), 'dbuser', 30);
346 text_row_ex(_("Database Password:"), 'dbpassword', 30);
347 text_row_ex(_("Database Name:"), 'dbname', 30);
348 yesno_list_row(_("Use '0_' Table Prefix:"), 'tbpref', 1, _('Yes'), _('No'), false);
349 check_row(_("Install Additional Language Packs from FA Repository:"), 'sel_langs');
350 check_row(_("Install Additional COAs from FA Repository:"), 'sel_coas');
352 display_note(_('Use table prefix if you share selected database for more than one FA company.'));
353 display_note(_("Do not select additional langs nor COAs if you have no working internet connection right now. You can install them later."));
354 submit_center_first('back', _('<< Back'));
355 submit_center_last('db_test', _('Continue >>'));
358 case '3': // select langauges
359 subpage_title(_('User Interface Languages Selection'));
361 submit_center_first('back', _('<< Back'));
362 submit_center_last('install_langs', _('Continue >>'));
365 case '4': // select COA
366 subpage_title(_('Charts of Accounts Selection'));
368 submit_center_first('back', _('<< Back'));
369 submit_center_last('install_coas', _('Continue >>'));
373 if (!isset($_POST['name'])) {
374 foreach($_SESSION['inst_set'] as $name => $val)
375 $_POST[$name] = $val;
378 if (!isset($installed_extensions)) {
379 $installed_extensions = array();
380 update_extensions($installed_extensions);
383 subpage_title(_('Company Settings'));
384 start_table(TABLESTYLE);
385 text_row_ex(_("Company Name:"), 'name', 30);
386 text_row_ex(_("Admin Login:"), 'admin', 30);
387 password_row(_("Admin Password:"), 'pass', @$_POST['pass']);
388 password_row(_("Reenter Password:"), 'repass', @$_POST['repass']);
389 coa_list_row(_("Select Chart of Accounts:"), 'coa');
390 languages_list_row(_("Select Default Language:"), 'lang');
392 submit_center_first('back', _('<< Back'));
393 submit_center_last('set_admin', _('Continue >>'));
396 case '6': // final screen
397 subpage_title(_('FrontAccounting ERP has been installed successsfully.'));
398 display_note(_('Please do not forget to remove install wizard folder.'));
401 hyperlink_no_params($path_to_root.'/index.php', _('Click here to start.'));
410 end_page(false, false, true);