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