Added tax information
[fa-stable.git] / admin / inst_theme.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_CREATEMODULES';
13 $path_to_root="..";
14 include_once($path_to_root . "/includes/session.inc");
15 include_once($path_to_root."/includes/packages.inc");
16
17 page(_($help_context = "Install Themes"));
18
19 include_once($path_to_root . "/includes/date_functions.inc");
20 include_once($path_to_root . "/admin/db/company_db.inc");
21 include_once($path_to_root . "/admin/db/maintenance_db.inc");
22 include_once($path_to_root . "/includes/ui.inc");
23
24 //---------------------------------------------------------------------------------------------
25 // If theme is used in customer record set to default
26 //
27 function clean_user_themes($id)
28 {
29         global $db_connections, $db, $installed_extensions;
30
31         $theme = $installed_extensions[$id]['package'];
32         $db_sav = $db;
33
34         foreach ($db_connections as $n => $conn) {
35                 $db = $_SESSION["wa_current_user"]->get_db_connection($n);
36                 $sql = "UPDATE {$conn['tbpref']}users SET theme='default' WHERE theme='$theme'";
37                 if (!db_query($sql, 'Cannot update user theme settings'))
38                         return false;
39         }
40         $db = $db_sav;
41         $_SESSION['wa_current_user']->prefs->theme = 'default';
42         return true;
43 }
44
45 if (($id = find_submit('Delete', false)) && clean_user_themes($id))
46 {
47         $extensions = get_company_extensions();
48         $theme = $extensions[$id]['package'];
49         if (uninstall_package($theme)) {
50                 $dirname = $path_to_root.'/themes/'.$theme;
51                 flush_dir($dirname, true);
52                 rmdir($dirname);
53                 unset($extensions[$id]);
54                 if (update_extensions($extensions)) {
55                         display_notification(_("Selected theme has been successfully deleted"));
56                         meta_forward($_SERVER['PHP_SELF']);
57                 }
58         }
59 }
60
61 if ($id = find_submit('Update', false))
62         install_extension($id);
63
64 //---------------------------------------------------------------------------------------------
65 start_form(true);
66
67         div_start('ext_tbl');
68         start_table(TABLESTYLE);
69
70         $th = array(_("Theme"),  _("Installed"), _("Available"), "", "");
71         table_header($th);
72
73         $k = 0;
74         $mods = get_themes_list();
75
76         foreach($mods as $pkg_name => $ext)
77         {
78                 $available = @$ext['available'];
79                 $installed = @$ext['version'];
80                 $id = @$ext['local_id'];
81
82                 alt_table_row_color($k);
83
84 //              label_cell(is_array($ext['Descr']) ? $ext['Descr'][0] : $ext['Descr']);
85                 label_cell($available ? get_package_view_str($pkg_name, $ext['name']) : $ext['name']);
86
87                 label_cell($id === null ? _("None") :
88                         ($available && $installed ? $installed : _("Unknown")));
89                 label_cell($available ? $available : _("None"));
90
91                 if ($available && check_pkg_upgrade($installed, $available)) // outdated or not installed theme in repo
92                         button_cell('Update'.$pkg_name, $installed ? _("Update") : _("Install"),
93                                 _('Upload and install latest extension package'), ICON_DOWN);
94                 else
95                         label_cell('');
96
97                 if ($id !== null) {
98                         delete_button_cell('Delete'.$id, _('Delete'));
99                         submit_js_confirm('Delete'.$id, 
100                                 sprintf(_("You are about to remove package \'%s\'.\nDo you want to continue ?"), 
101                                         $ext['name']));
102                 } else
103                         label_cell('');
104
105                 end_row();
106         }
107
108         end_table(1);
109
110         div_end();
111
112 //---------------------------------------------------------------------------------------------
113 end_form();
114
115 end_page();
116 ?>