X-Git-Url: https://delta.frontaccounting.com/gitweb/?a=blobdiff_plain;f=admin%2Finst_module.php;h=5c3603d94a65e3ac3fbad120b7993f498ce806d8;hb=884c36eec7dbaae89e1f5532cc2c2f8033b010fd;hp=067e83f0281aba94f5d4d0975ac569ef216d5b30;hpb=d2cc0860eccf02eaefcd90731ac3af141a841529;p=fa-stable.git
diff --git a/admin/inst_module.php b/admin/inst_module.php
index 067e83f0..5c3603d9 100644
--- a/admin/inst_module.php
+++ b/admin/inst_module.php
@@ -12,7 +12,11 @@
$page_security = 'SA_CREATEMODULES';
$path_to_root="..";
include_once($path_to_root . "/includes/session.inc");
+include_once($path_to_root."/includes/packages.inc");
+if ($use_popup_windows) {
+ $js = get_js_open_window(900, 500);
+}
page(_($help_context = "Install/Activate extensions"));
include_once($path_to_root . "/includes/date_functions.inc");
@@ -21,38 +25,9 @@ include_once($path_to_root . "/admin/db/maintenance_db.inc");
include_once($path_to_root . "/includes/ui.inc");
simple_page_mode(true);
-
//---------------------------------------------------------------------------------------------
-function update_extensions($extensions) {
- global $db_connections;
-
- if (!write_extensions($extensions)) {
- display_notification(_("Cannot update system extensions list."));
- return false;
- }
-
- // update per company files
- $cnt = count($db_connections);
- for($i = 0; $i < $cnt; $i++)
- {
- $newexts = $extensions;
- // update 'active' status
- $exts = get_company_extensions($i);
- foreach ($exts as $key => $ext)
- {
- if (isset($newexts[$key]))
- $newexts[$key]['active'] = $exts[$key]['active'];
- }
- if(!write_extensions($newexts, $i))
- {
- display_notification(sprintf(_("Cannot update extensions list for company '%s'."),
- $db_connections[$i]['name']));
- return false;
- }
- }
- return true;
-}
-
+// Check third-party extension parameters
+//
function check_data($id, $exts)
{
if ($_POST['name'] == "") {
@@ -75,7 +50,7 @@ function check_data($id, $exts)
return false;
}
if ($id == -1 && !is_uploaded_file($_FILES['uploadfile']['tmp_name'])) {
- display_error(_("You have to select plugin file to upload"));
+ display_error(_("You have to select extension file to upload"));
return false;
}
return true;
@@ -92,19 +67,25 @@ function handle_submit()
return false;
$id = $selected_id==-1 ? $next_extension_id : $selected_id;
- if ($selected_id != -1 && $extensions[$id]['type'] != 'plugin') {
- display_error(_('Module installation support is not implemented yet. You have to do it manually.'));
+ if ($selected_id != -1 && $extensions[$id]['type'] != 'extension'
+ || (isset($extensions[$id]['tabs']) && count($extensions[$id]['tabs']))) {
+ display_error(_('Module installation support is not implemented.'));
return;
}
- $extensions[$id]['tab'] = $_POST['tab'];
$extensions[$id]['name'] = $_POST['name'];
- $extensions[$id]['path'] = $_POST['path'];
- $extensions[$id]['title'] = $_POST['title'];
+ $extensions[$id]['package'] = '';
+ $extensions[$id]['version'] = '';
$extensions[$id]['active'] = check_value('active');
+ $entry = $selected_id == -1 ? array() : $extensions[$id]['entries'][0];
+
+ $entry['tab_id'] = $_POST['tab'];
+ $entry['title'] = $_POST['title'];
+ $entry['section'] = 2; // menu section aka module
- // Currently we support only plugin extensions here.
- $extensions[$id]['type'] = 'plugin';
+ // Only simple plugin type extensions can be installed manually.
+ $extensions[$id]['type'] = 'extension';
+ $extensions[$id]['path'] = 'modules/'.$_POST['path'];
$directory = $path_to_root . "/modules/" . $_POST['path'];
if (!file_exists($directory))
{
@@ -112,7 +93,7 @@ function handle_submit()
}
if (is_uploaded_file($_FILES['uploadfile']['tmp_name']))
{
- $extensions[$id]['filename'] = $_FILES['uploadfile']['name'];
+ $entry['url'] = $_FILES['uploadfile']['name'];
$file1 = $_FILES['uploadfile']['tmp_name'];
$file2 = $directory . "/".$_FILES['uploadfile']['name'];
if (file_exists($file2))
@@ -120,16 +101,13 @@ function handle_submit()
move_uploaded_file($file1, $file2);
}
else
- $extensions[$id]['filename'] = get_post('filename');
+ $entry['url'] = get_post('filename');
+
if (is_uploaded_file($_FILES['uploadfile2']['tmp_name']))
{
$file1 = $_FILES['uploadfile2']['tmp_name'];
- $file2 = $directory . "/".$_FILES['uploadfile2']['name'];
- if (file_exists($file2))
- unlink($file2);
- move_uploaded_file($file1, $file2);
$db_name = $_SESSION["wa_current_user"]->company;
- db_import($file2, $db_connections[$db_name]);
+ db_import($file1, $db_connections[$db_name]);
}
if (is_uploaded_file($_FILES['uploadfile3']['tmp_name']))
@@ -145,16 +123,15 @@ function handle_submit()
$extensions[$id]['acc_file'] = get_post('acc_file');
// security area guess for plugins
- if ($extensions[$id]['type'] == 'plugin'){
- $exttext = file_get_contents($path_to_root.'/modules/'
- .$extensions[$id]['path'].'/'.$extensions[$id]['filename']);
- $area = 'SA_OPEN';
- if (preg_match('/.*\$page_security\s*=\s*[\'"]([^\'"]*)/', $exttext, $match)) {
- $area = trim($match[1]);
- }
- $extensions[$id]['access'] = $area;
+ $exttext = file_get_contents($path_to_root.'/'.$extensions[$id]['path'].'/'.$entry['url']);
+ $area = 'SA_OPEN';
+ if (preg_match('/.*\$page_security\s*=\s*[\'"]([^\'"]*)/', $exttext, $match)) {
+ $area = trim($match[1]);
}
+ $entry['access'] = $area;
+ $extensions[$id]['entries'] = array($entry);
+
if ($selected_id == -1)
{
$next_extension_id++;
@@ -164,80 +141,116 @@ function handle_submit()
return true;
}
-function handle_delete()
+function handle_delete($id)
{
- global $path_to_root, $db_connections, $selected_id;
+ global $path_to_root;
$extensions = get_company_extensions();
- $id = $selected_id;
-
- $filename = $path_to_root
- . ($extensions[$id]['type']=='plugin' ? "/modules/": '/')
- . $extensions[$id]['path'];
+ if ($extensions[$id]['package'] != '') {
+ if (!uninstall_package($extensions[$id]['package']))
+ return false;
+ } else {
- flush_dir($filename);
- rmdir($filename);
+ $dirname = $extensions[$id]['path'];
+ if ($dirname) {
+ $dirname = $path_to_root.'/'.$dirname;
+ flush_dir($dirname, true);
+ rmdir($dirname);
+ }
+ }
unset($extensions[$id]);
- if (update_extensions($extensions))
+ if (update_extensions($extensions)) {
display_notification(_("Selected extension has been successfully deleted"));
+ }
return true;
}
-
+//
+// Helper for formating menu tabs/entries to be displayed in extension table
+//
+function fmt_titles($defs)
+{
+ if (!$defs) return '';
+ foreach($defs as $def) {
+ $str[] = access_string($def['title'], true);
+ }
+ return implode('
', array_values($str));
+}
//---------------------------------------------------------------------------------------------
-
+//
+// Display list of all extensions - installed and available from repository
+//
function display_extensions()
{
- global $table_style;
- start_table($table_style);
- $th = array(_("Name"),_("Tab"), _("Link text"), _("Folder"), _("Filename"),
- _("Access extensions"),"", "");
+ div_start('ext_tbl');
+ start_table(TABLESTYLE);
+
+ $th = array(_("Extension"),_("Modules provided"), _("Options provided"),
+ _("Installed"), _("Available"), "", "");
table_header($th);
$k = 0;
- $mods = get_company_extensions();
- $mods = array_natsort($mods, null, 'name');
+ $mods = get_extensions_list('extension');
- foreach($mods as $i => $mod)
+ foreach($mods as $pkg_name => $ext)
{
- $is_mod = $mod['type'] == 'module';
- alt_table_row_color($k);
- label_cell($mod['name']);
- label_cell( $is_mod ?
- $mod['title'] : access_string($_SESSION['App']->applications[$mod['tab']]->name, true));
- $ttl = access_string($mod['title']);
- label_cell($ttl[0]);
- label_cell($mod['path']);
- label_cell($mod['filename']);
- label_cell(@$mod['acc_file']);
- if ($is_mod)
- {
- label_cell(''); // not implemented (yet)
- }
+ $available = @$ext['available'];
+ $installed = @$ext['version'];
+ $id = @$ext['local_id'];
+ $is_mod = $ext['type'] == 'module';
+
+ $entries = fmt_titles(@$ext['entries']);
+ $tabs = fmt_titles(@$ext['tabs']);
+
+ alt_table_row_color($k);
+// label_cell(is_array($ext['Descr']) ? $ext['Descr'][0] : $ext['Descr']);
+ label_cell($available ? get_package_view_str($pkg_name, $ext['name']) : $ext['name']);
+ label_cell($tabs);
+ label_cell($entries);
+
+ label_cell($id === null ? _("None") :
+ ($available && $installed ? $installed : _("Unknown")));
+ label_cell($available ? $available : _("None"));
+
+ if (!$available && $ext['type'] == 'extension' && !count(@$ext['tabs'])) // third-party plugin
+ button_cell('Edit'.$id, _("Edit"), _('Edit third-party extension parameters.'),
+ ICON_EDIT);
+ elseif (check_pkg_upgrade($installed, $available)) // outdated or not installed extension in repo
+ button_cell('Update'.$pkg_name, $installed ? _("Update") : _("Install"),
+ _('Upload and install latest extension package'), ICON_DOWN);
else
- {
- edit_button_cell("Edit".$i, _("Edit"));
- }
- delete_button_cell("Delete".$i, _("Delete"));
- submit_js_confirm('Delete'.$i, _('You are about to delete this extension\nDo you want to continue?'));
+ label_cell('');
+
+ if ($id !== null) {
+ delete_button_cell('Delete'.$id, _('Delete'));
+ submit_js_confirm('Delete'.$id,
+ sprintf(_("You are about to remove package \'%s\'.\nDo you want to continue ?"),
+ $ext['name']));
+ } else
+ label_cell('');
+
end_row();
}
end_table(1);
-}
+ submit_center_first('Refresh', _("Update"), '', null);
+ submit_center_last('Add', _("Add third-party extension"), '', false);
+
+ div_end();
+}
+//---------------------------------------------------------------------------------
+//
+// Get all installed extensions and display
+// with current status stored in company directory.
+//
function company_extensions($id)
{
- global $table_style;
-
- start_table($table_style);
+ start_table(TABLESTYLE);
- $th = array(_("Name"),_("Tab"), _("Link text"), _("Active"));
+ $th = array(_("Extension"),_("Modules provided"), _("Options provided"), _("Active"));
- // get all available extensions and display
- // with current status stored in company directory.
-
$mods = get_company_extensions();
$exts = get_company_extensions($id);
foreach($mods as $key => $ins) {
@@ -252,62 +265,69 @@ function company_extensions($id)
$k = 0;
foreach($mods as $i => $mod)
{
+ if ($mod['type'] != 'extension') continue;
alt_table_row_color($k);
label_cell($mod['name']);
- label_cell( $mod['type'] == 'module' ?
- $mod['title'] : access_string($_SESSION['App']->applications[$mod['tab']]->name, true));
- $ttl = access_string($mod['title']);
- label_cell($ttl[0]);
+ $entries = fmt_titles(@$mod['entries']);
+ $tabs = fmt_titles(@$mod['tabs']);
+ label_cell($tabs);
+ label_cell($entries);
+
check_cells(null, 'Active'.$i, @$mod['active'] ? 1:0,
false, false, "align='center'");
end_row();
}
end_table(1);
- submit_center('Update', _('Update'), true, false, 'default');
+ submit_center('Refresh', _('Update'), true, false, 'default');
}
//---------------------------------------------------------------------------------------------
-
+//
+// Third-party plugin installation
+//
function display_ext_edit($selected_id)
{
- global $table_style2, $Mode;
-
+ global $Mode;
$extensions = get_company_extensions();
- start_table($table_style2);
+ start_table(TABLESTYLE2);
- if ($selected_id != -1 && $extensions[$selected_id]['type'] == 'plugin')
+ if ($selected_id != -1 && $extensions[$selected_id]['type'] == 'extension')
{
if ($Mode == 'Edit') {
$mod = $extensions[$selected_id];
- $_POST['tab'] = $mod['tab'];
+ $entry = $mod['entries'][0];
+
$_POST['name'] = $mod['name'];
- $_POST['title'] = $mod['title'];
- $_POST['path'] = $mod['path'];
- $_POST['filename'] = $mod['filename'];
- $_POST['acc_file'] = @$mod['acc_file'];
+ $_POST['tab'] = $entry['tab_id'];
+ $_POST['title'] = $entry['title'];
+ $_POST['path'] = substr(dirname($mod['path']), 9); //strip '/modules/'
+ $_POST['filename'] = basename($entry['url']);
+ $_POST['acc_file'] = @$mod['acc_file'] ? basename($mod['acc_file']) : null;
hidden('filename', $_POST['filename']);
hidden('acc_file', $_POST['acc_file']);
}
hidden('selected_id', $selected_id);
}
text_row_ex(_("Name"), 'name', 30);
- text_row_ex(_("Folder"), 'path', 20);
+ text_row_ex(_("Subfolder (in modules directory)"), 'path', 20);
tab_list_row(_("Menu Tab"), 'tab', null, true);
text_row_ex(_("Menu Link Text"), 'title', 30);
record_status_list_row(_("Default status"), 'active');
- label_row(_("Module File"), "");
- label_row(_("Access Levels Extensions"), "");
- label_row(_("SQL File"), "");
+ file_row(_("Extension File"), 'uploadfile');
+ file_row(_("Access Levels File"), 'uploadfile3');
+ file_row(_("SQL File"), 'uploadfile2');
end_table(0);
- display_note(_("Select your module PHP file from your local harddisk."), 0, 1);
- submit_add_or_update_center($selected_id == -1, '', 'both');
+ display_note(_("Select your extension PHP files from your local harddisk."), 0, 1);
+ echo '