Recurrent Invoices: fixed buggy call to non existing function and payment terms type...
[fa-stable.git] / admin / inst_upgrade.php
1 <?php
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_SOFTWAREUPGRADE';
13 $path_to_root="..";
14 include_once($path_to_root . "/includes/session.inc");
15
16 if ($SysPrefs->use_popup_windows) {
17         $js = get_js_open_window(900, 500);
18 }
19 page(_($help_context = "Software Upgrade"), false, false, "", $js);
20
21 include_once($path_to_root . "/includes/date_functions.inc");
22 include_once($path_to_root . "/admin/db/company_db.inc");
23 include_once($path_to_root . "/admin/db/maintenance_db.inc");
24 include_once($path_to_root . "/includes/ui.inc");
25 include_once($path_to_root . "/admin/includes/fa_patch.class.inc");
26
27 $site_status = get_site_status($db_connections);
28 $installers = get_installers();
29
30 if (get_post('Upgrade')) 
31 {
32         $comp = get_post('select_comp');
33
34     if ($comp === '')
35                 display_error(_('Select company to be upgraded.'));
36         else {
37                 $patch = @$installers[$site_status[$comp]['version']];
38                 if ($patch)
39                 {
40                         if (!$patch->upgrade_company($comp, check_value('force')))
41                                 display_error(implode('<hr>', $patch->errors));
42                         else
43                                 display_notification(_("Company upgraded successfully."));
44
45                         $site_status = get_site_status($db_connections); // update info
46                     $Ajax->activate('_page_body');
47                 }
48         }
49 }
50 $i = find_submit('Clear');
51 if ($i != -1)
52 {
53   unlink(VARLOG_PATH.'/upgrade.'.$i.'.log');
54   $Ajax->activate('_page_body');
55 }
56 if (get_post('_select_comp_update'))
57 {
58   $Ajax->activate('_page_body');
59 }
60
61 start_form();
62
63 $th = array(_("Company"), _("Table set"), _("Current version"), _("Last log"), _('Upgrade'));
64 start_table(TABLESTYLE);
65 table_header($th);
66 $k = 0; //row colour counter
67
68 $uptodate = true;
69 foreach($site_status as $i => $comp)
70 {
71         $status = $comp['version']==$db_version;
72
73         alt_table_row_color($k);
74
75         label_cell($comp['name']);
76         label_cell($comp['table_set']);
77
78         label_cell($comp['version'], 'align=center' .($status ? '':' class=redfg')/*, 'class='.( $status ? 'ok' : 'error')*/);
79
80         $log = VARLOG_PATH.'/upgrade.'.$i.'.log';
81         if (file_exists($log))
82         {
83                 label_cell(viewer_link(_('View log'), "admin/view/view_upgrade_log.php?id=$i", null, $i, 'log.png')
84                   .button('Clear'.$i, _('Clear'), _('Clear log'), ICON_DELETE), 'align=center');
85                 submit_js_confirm('Clear'.$i, _("Do you really want to clear this upgrade log?"));
86         } else
87                 label_cell('-', 'align=center');
88
89         if (!$status)
90         {
91                 label_cell(radio(null, 'select_comp', $i, null, true), 'align=center');
92                 $uptodate = false;
93         } else
94                 label_cell(_('Up to date'));
95         end_row();
96 }
97
98 end_table();
99 br();
100
101 div_start('upgrade_args');
102 if (get_post('select_comp') !== '')
103 {
104         $patch = @$installers[$site_status[get_post('select_comp')]['version']];
105         if ($patch) {
106                 if (!set_global_connection(get_post('select_comp'))) // create page in target database context
107                         display_error(_("Cannot connect to company database for database restore."));
108                 else {
109                         $patch->show_params(get_post('select_comp'));
110                         set_global_connection(); // switch back
111                 }
112         }
113 }
114 div_end();
115
116 if ($uptodate)
117         display_note(_('All company database schemes are up to date.'));
118 else {
119         if (get_post('select_comp') === '')
120                 display_note(_("Select company for incremental upgrade."), 0, 1, "class='stockmankofg'");
121         submit_center('Upgrade', _('Upgrade'), true, _('Save database and perform upgrade'), 'nonajax');
122 }
123 end_form();
124
125 end_page();
126