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';
14 include_once($path_to_root . "/includes/session.inc");
15 include_once($path_to_root."/includes/packages.inc");
17 if ($SysPrefs->use_popup_windows) {
18 $js = get_js_open_window(900, 500);
20 page(_($help_context = "Install/Activate extensions"), false, false, "", $js);
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");
27 simple_page_mode(true);
29 //---------------------------------------------------------------------------------------------
30 function local_extension($id)
32 global $next_extension_id, $Ajax, $path_to_root;
34 $exts = get_company_extensions();
35 $exts[$next_extension_id++] = array(
40 'type' => 'extension',
41 'path' => 'modules/'.$id,
45 $local_module_path = $path_to_root.'/modules/'.clean_file_name($id);
46 $local_config_file = $local_module_path.'/_init/config';
47 $local_hook_file = $local_module_path.'/hooks.php';
49 if (file_exists($local_config_file)) {
50 $ctrl = get_control_file($local_config_file);
51 if (key_exists('Name', $ctrl)) $exts[$next_extension_id-1]['name'] = $ctrl['Name'];
52 if (key_exists('Version', $ctrl)) $exts[$next_extension_id-1]['version'] = $ctrl['Version'];
54 if (file_exists($local_hook_file)) {
55 include_once($local_hook_file);
58 $hooks_class = 'hooks_'.$id;
59 if (class_exists($hooks_class, false)) {
60 $hooks = new $hooks_class;
61 $hooks->install_extension(false);
63 $Ajax->activate('ext_tbl'); // refresh settings display
64 if (!update_extensions($exts))
69 function handle_delete($id)
73 $extensions = get_company_extensions();
74 $ext = $extensions[$id];
75 if ($ext['version'] != '-') {
76 if (!uninstall_package($ext['package']))
79 @include_once($path_to_root.'/'.$ext['path'].'/hooks.php');
80 $hooks_class = 'hooks_'.$ext['package'];
81 if (class_exists($hooks_class)) {
82 $hooks = new $hooks_class;
83 $hooks->uninstall_extension(false);
86 unset($extensions[$id]);
87 if (update_extensions($extensions)) {
88 display_notification(_("Selected extension has been successfully deleted"));
92 //---------------------------------------------------------------------------------------------
94 // Display list of all extensions - installed and available from repository
96 function display_extensions($mods)
98 global $installed_extensions;
100 div_start('ext_tbl');
101 start_table(TABLESTYLE);
103 $th = array(_("Extension"), _("Installed"), _("Available"), "", "");
108 foreach($mods as $pkg_name => $ext)
110 $available = @$ext['available'];
111 $installed = @$ext['version'];
112 $id = @$ext['local_id'];
114 alt_table_row_color($k);
116 label_cell($available ? get_package_view_str($pkg_name, $ext['name']) : $ext['name']);
118 label_cell($id === null ? _("None") :
119 (($installed && ($installed != '-' || $installed != '')) ? $installed : _("Unknown")));
120 label_cell($available ? $available : _("Unknown"));
122 if (!$available && $ext['type'] == 'extension') {// third-party plugin
124 button_cell('Local'.$ext['package'], _("Install"), _('Install third-party extension.'),
128 } elseif (check_pkg_upgrade($installed, $available)) // outdated or not installed extension in repo
129 button_cell('Update'.$pkg_name, $installed ? _("Update") : _("Install"),
130 _('Upload and install latest extension package'), ICON_DOWN);
135 delete_button_cell('Delete'.$id, _('Delete'));
136 submit_js_confirm('Delete'.$id,
137 sprintf(_("You are about to remove package \'%s\'.\nDo you want to continue ?"),
147 submit_center_first('Refresh', _("Update"), '', null);
151 //---------------------------------------------------------------------------------
153 // Get all installed extensions and display
154 // with current status stored in company directory.
156 function company_extensions($id)
158 start_table(TABLESTYLE);
160 $th = array(_("Extension"), _("Version"), _("Path"), _("Active"));
162 $mods = get_company_extensions();
163 $exts = get_company_extensions($id);
164 foreach($mods as $key => $ins) {
165 foreach($exts as $ext)
166 if ($ext['name'] == $ins['name']) {
167 $mods[$key]['active'] = @$ext['active'];
171 $mods = array_natsort($mods, null, 'name');
174 foreach($mods as $i => $mod)
176 if ($mod['type'] != 'extension') continue;
177 alt_table_row_color($k);
178 label_cell($mod['name']);
179 label_cell($mod['version']);
180 label_cell($mod['path']);
182 check_cells(null, 'Active'.$i, @$mod['active'] ? 1:0,
183 false, false, "align='center'");
189 submit_center('Refresh', _('Update'), true, false, 'default');
192 //---------------------------------------------------------------------------------------------
193 if ($Mode == 'Delete')
195 handle_delete($selected_id);
199 if (get_post('Refresh')) {
200 $comp = get_post('extset');
201 $exts = get_company_extensions($comp);
204 foreach($exts as $i => $ext) {
205 if ($ext['package'] && ($ext['active'] ^ check_value('Active'.$i)))
207 if (check_value('Active'.$i) && !check_src_ext_version($ext['version']))
209 display_warning(sprintf(_("Package '%s' is incompatible with current application version and cannot be activated.\n")
210 . _("Check Install/Activate page for newer package version."), $ext['name']));
213 $activated = activate_hooks($ext['package'], $comp, !$ext['active']); // change active state
215 if ($activated !== null)
216 $result &= $activated;
217 if ($activated || ($activated === null))
218 $exts[$i]['active'] = check_value('Active'.$i);
221 write_extensions($exts, get_post('extset'));
222 if (get_post('extset') == user_company())
223 $installed_extensions = $exts;
226 display_error(_('Status change for some extensions failed.'));
227 $Ajax->activate('ext_tbl'); // refresh settings display
229 display_notification(_('Current active extensions set has been saved.'));
232 if ($id = find_submit('Update', false))
233 install_extension($id);
235 if ($id = find_submit('Local', false))
236 local_extension($id);
238 if ($Mode == 'RESET')
244 //---------------------------------------------------------------------------------------------
246 if (list_updated('extset'))
247 $Ajax->activate('_page_body');
249 $set = get_post('extset', -1);
251 echo "<center>" . _('Extensions:') . " ";
252 echo extset_list('extset', null, true);
253 echo "</center><br>";
257 $mods = get_extensions_list('extension');
259 display_note(_("No optional extension module is currently available."));
261 display_extensions($mods);
263 company_extensions($set);
265 //---------------------------------------------------------------------------------------------