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"));
93 // Helper for formating menu tabs/entries to be displayed in extension table
95 function fmt_titles($defs)
97 if (!$defs) return '';
98 foreach($defs as $def) {
99 $str[] = access_string($def['title'], true);
101 return implode('<br>', array_values($str));
103 //---------------------------------------------------------------------------------------------
105 // Display list of all extensions - installed and available from repository
107 function display_extensions($mods)
109 global $installed_extensions;
111 div_start('ext_tbl');
112 start_table(TABLESTYLE);
114 $th = array(_("Extension"),_("Modules provided"), _("Options provided"),
115 _("Installed"), _("Available"), "", "");
120 foreach($mods as $pkg_name => $ext)
122 $available = @$ext['available'];
123 $installed = @$ext['version'];
124 $id = @$ext['local_id'];
126 $entries = fmt_titles(@$ext['entries']);
127 $tabs = fmt_titles(@$ext['tabs']);
129 alt_table_row_color($k);
131 label_cell($available ? get_package_view_str($pkg_name, $ext['name']) : $ext['name']);
133 label_cell($entries);
135 label_cell($id === null ? _("None") :
136 (($installed && ($installed != '-' || $installed != '')) ? $installed : _("Unknown")));
137 label_cell($available ? $available : _("Unknown"));
139 if (!$available && $ext['type'] == 'extension') {// third-party plugin
141 button_cell('Local'.$ext['package'], _("Install"), _('Install third-party extension.'),
145 } elseif (check_pkg_upgrade($installed, $available)) // outdated or not installed extension in repo
146 button_cell('Update'.$pkg_name, $installed ? _("Update") : _("Install"),
147 _('Upload and install latest extension package'), ICON_DOWN);
152 delete_button_cell('Delete'.$id, _('Delete'));
153 submit_js_confirm('Delete'.$id,
154 sprintf(_("You are about to remove package \'%s\'.\nDo you want to continue ?"),
164 submit_center_first('Refresh', _("Update"), '', null);
168 //---------------------------------------------------------------------------------
170 // Get all installed extensions and display
171 // with current status stored in company directory.
173 function company_extensions($id)
175 start_table(TABLESTYLE);
177 $th = array(_("Extension"),_("Modules provided"), _("Options provided"), _("Active"));
179 $mods = get_company_extensions();
180 $exts = get_company_extensions($id);
181 foreach($mods as $key => $ins) {
182 foreach($exts as $ext)
183 if ($ext['name'] == $ins['name']) {
184 $mods[$key]['active'] = @$ext['active'];
188 $mods = array_natsort($mods, null, 'name');
191 foreach($mods as $i => $mod)
193 if ($mod['type'] != 'extension') continue;
194 alt_table_row_color($k);
195 label_cell($mod['name']);
196 $entries = fmt_titles(@$mod['entries']);
197 $tabs = fmt_titles(@$mod['tabs']);
199 label_cell($entries);
201 check_cells(null, 'Active'.$i, @$mod['active'] ? 1:0,
202 false, false, "align='center'");
207 submit_center('Refresh', _('Update'), true, false, 'default');
210 //---------------------------------------------------------------------------------------------
211 if ($Mode == 'Delete')
213 handle_delete($selected_id);
217 if (get_post('Refresh')) {
218 $comp = get_post('extset');
219 $exts = get_company_extensions($comp);
222 foreach($exts as $i => $ext) {
223 if ($ext['package'] && ($ext['active'] ^ check_value('Active'.$i)))
225 if (check_value('Active'.$i) && !check_src_ext_version($ext['version']))
227 display_warning(sprintf(_("Package '%s' is incompatible with current application version and cannot be activated.\n")
228 . _("Check Install/Activate page for newer package version."), $ext['name']));
231 $activated = activate_hooks($ext['package'], $comp, !$ext['active']); // change active state
233 if ($activated !== null)
234 $result &= $activated;
235 if ($activated || ($activated === null))
236 $exts[$i]['active'] = check_value('Active'.$i);
239 write_extensions($exts, get_post('extset'));
240 if (get_post('extset') == user_company())
241 $installed_extensions = $exts;
244 display_error(_('Status change for some extensions failed.'));
245 $Ajax->activate('ext_tbl'); // refresh settings display
247 display_notification(_('Current active extensions set has been saved.'));
250 if ($id = find_submit('Update', false))
251 install_extension($id);
253 if ($id = find_submit('Local', false))
254 local_extension($id);
256 if ($Mode == 'RESET')
262 //---------------------------------------------------------------------------------------------
264 if (list_updated('extset'))
265 $Ajax->activate('_page_body');
267 $set = get_post('extset', -1);
269 echo "<center>" . _('Extensions:') . " ";
270 echo extset_list('extset', null, true);
271 echo "</center><br>";
275 $mods = get_extensions_list('extension');
277 display_note(_("No optional extension module is currently available."));
279 display_extensions($mods);
281 company_extensions($set);
283 //---------------------------------------------------------------------------------------------