X-Git-Url: https://delta.frontaccounting.com/gitweb/?a=blobdiff_plain;f=admin%2Finst_module.php;h=5c3603d94a65e3ac3fbad120b7993f498ce806d8;hb=20c9b5846824f0489c6791d74a6c78e2bfb0b2fc;hp=00ab1adc90f5a08b4bc378b5c6e69c4125ffda8b;hpb=902f1015d874c33bd7946b17de2ad80b4f2144b6;p=fa-stable.git
diff --git a/admin/inst_module.php b/admin/inst_module.php
index 00ab1adc..5c3603d9 100644
--- a/admin/inst_module.php
+++ b/admin/inst_module.php
@@ -12,138 +12,47 @@
$page_security = 'SA_CREATEMODULES';
$path_to_root="..";
include_once($path_to_root . "/includes/session.inc");
+include_once($path_to_root."/includes/packages.inc");
-page(_("Install/Update Modules"));
+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");
include_once($path_to_root . "/admin/db/company_db.inc");
include_once($path_to_root . "/admin/db/maintenance_db.inc");
-include_once($path_to_root . "/modules/installed_modules.php");
include_once($path_to_root . "/includes/ui.inc");
+simple_page_mode(true);
//---------------------------------------------------------------------------------------------
-
-if (isset($_GET['selected_id']))
-{
- $selected_id = $_GET['selected_id'];
-}
-elseif (isset($_POST['selected_id']))
+// Check third-party extension parameters
+//
+function check_data($id, $exts)
{
- $selected_id = $_POST['selected_id'];
-}
-else
- $selected_id = -1;
-
-//---------------------------------------------------------------------------------------------
-
-function check_data()
-{
- if ($_POST['name'] == "" || $_POST['path'] == "")
+ if ($_POST['name'] == "") {
+ display_error(_("Extension name cannot be empty."));
return false;
- return true;
-}
-
-/**
- * @return Returns the array sorted as required
- * @param $aryData Array containing data to sort
- * @param $strIndex name of column to use as an index
- * @param $strSortBy Column to sort the array by
- * @param $strSortType String containing either asc or desc [default to asc]
- * @desc Naturally sorts an array using by the column $strSortBy
- */
-function array_natsort($aryData, $strIndex, $strSortBy, $strSortType=false)
-{
- // if the parameters are invalid
- if (!is_array($aryData) || !$strIndex || !$strSortBy)
- // return the array
- return $aryData;
-
- // create our temporary arrays
- $arySort = $aryResult = array();
-
- // loop through the array
- foreach ($aryData as $aryRow)
- // set up the value in the array
- $arySort[$aryRow[$strIndex]] = $aryRow[$strSortBy];
-
- // apply the natural sort
- natsort($arySort);
-
- // if the sort type is descending
- if ($strSortType=="desc")
- // reverse the array
- arsort($arySort);
-
- // loop through the sorted and original data
- foreach ($arySort as $arySortKey => $arySorted)
- foreach ($aryData as $aryOriginal)
- // if the key matches
- if ($aryOriginal[$strIndex]==$arySortKey)
- // add it to the output array
- array_push($aryResult, $aryOriginal);
-
- // return the return
- return $aryResult;
-}
-
-function write_modules()
-{
- global $path_to_root, $installed_modules;
-
- $mods = array_natsort($installed_modules, 'tab', 'tab');
- $installed_modules = $mods;
- //reset($installed_languages);
- $n = count($installed_modules);
- $msg = " 0)
- $msg .= "\t0 => ";
- for ($i = 0; $i < $n; $i++)
- {
- if ($i > 0)
- $msg .= "\t\tarray ";
- else
- $msg .= "array ";
- $msg .= "('tab' => '" . $installed_modules[$i]['tab'] . "', ";
- $msg .= "'name' => '" . $installed_modules[$i]['name'] . "', ";
- $msg .= "'path' => '" . $installed_modules[$i]['path'] . "', ";
- $msg .= "'filename' => '" . $installed_modules[$i]['filename'] . "'";
- $msg .= "),\n";
}
- $msg .= "\t);\n?>";
-
- $filename = $path_to_root . "/modules/installed_modules.php";
- // Check if the file exists and is writable first.
- if (file_exists($filename) && is_writable($filename))
- {
- if (!$zp = fopen($filename, 'w'))
- {
- display_error(_("Cannot open the modules file - ") . $filename);
+ foreach($exts as $n =>$ext) {
+ if ($_POST['name'] == $ext['name'] && $id != $n) {
+ display_error(_("Extension name have to be unique."));
return false;
}
- else
- {
- if (!fwrite($zp, $msg))
- {
- display_error(_("Cannot write to the modules file - ") . $filename);
- fclose($zp);
- return false;
- }
- // Close file
- fclose($zp);
- }
}
- else
- {
- display_error(_("The modules file ") . $filename . _(" is not writable. Change its permissions so it is, then re-run the operation."));
+
+ if ($_POST['title'] == "") {
+ display_error(_("Extension title cannot be empty."));
+ return false;
+ }
+ if ($_POST['path'] == "") {
+ display_error(_("Extension folder name cannot be empty."));
return false;
}
+ if ($id == -1 && !is_uploaded_file($_FILES['uploadfile']['tmp_name'])) {
+ display_error(_("You have to select extension file to upload"));
+ return false;
+ }
return true;
}
@@ -151,16 +60,32 @@ function write_modules()
function handle_submit()
{
- global $path_to_root, $installed_modules, $db_connections;
+ global $path_to_root, $db_connections, $selected_id, $next_extension_id;
- if (!check_data())
+ $extensions = get_company_extensions();
+ if (!check_data($selected_id, $extensions))
return false;
+ $id = $selected_id==-1 ? $next_extension_id : $selected_id;
- $id = $_GET['id'];
+ 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;
+ }
- $installed_modules[$id]['tab'] = $_POST['tab'];
- $installed_modules[$id]['name'] = $_POST['name'];
- $installed_modules[$id]['path'] = $_POST['path'];
+ $extensions[$id]['name'] = $_POST['name'];
+ $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
+
+ // 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))
{
@@ -168,7 +93,7 @@ function handle_submit()
}
if (is_uploaded_file($_FILES['uploadfile']['tmp_name']))
{
- $installed_modules[$id]['filename'] = $_FILES['uploadfile']['name'];
+ $entry['url'] = $_FILES['uploadfile']['name'];
$file1 = $_FILES['uploadfile']['tmp_name'];
$file2 = $directory . "/".$_FILES['uploadfile']['name'];
if (file_exists($file2))
@@ -176,173 +101,301 @@ function handle_submit()
move_uploaded_file($file1, $file2);
}
else
- $installed_modules[$id]['filename'] = $_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'];
+ $db_name = $_SESSION["wa_current_user"]->company;
+ db_import($file1, $db_connections[$db_name]);
+ }
+
+ if (is_uploaded_file($_FILES['uploadfile3']['tmp_name']))
+ {
+ $extensions[$id]['acc_file'] = $_FILES['uploadfile3']['name'];
+ $file1 = $_FILES['uploadfile3']['tmp_name'];
+ $file2 = $directory . "/".$_FILES['uploadfile3']['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]);
}
- if (!write_modules())
+ else
+ $extensions[$id]['acc_file'] = get_post('acc_file');
+
+ // security area guess for plugins
+ $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++;
+ }
+ if (!update_extensions($extensions))
return false;
return true;
}
-//---------------------------------------------------------------------------------------------
+function handle_delete($id)
+{
+ global $path_to_root;
+
+ $extensions = get_company_extensions();
-function handle_delete()
+ if ($extensions[$id]['package'] != '') {
+ if (!uninstall_package($extensions[$id]['package']))
+ return false;
+ } else {
+
+ $dirname = $extensions[$id]['path'];
+ if ($dirname) {
+ $dirname = $path_to_root.'/'.$dirname;
+ flush_dir($dirname, true);
+ rmdir($dirname);
+ }
+ }
+ unset($extensions[$id]);
+ 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 $path_to_root, $installed_modules;
- $id = $_GET['id'];
+ div_start('ext_tbl');
+ start_table(TABLESTYLE);
- $path = $installed_modules[$id]['path'];
- $filename = "$path_to_root/modules/$path";
- if ($h = opendir($filename))
+ $th = array(_("Extension"),_("Modules provided"), _("Options provided"),
+ _("Installed"), _("Available"), "", "");
+ table_header($th);
+
+ $k = 0;
+ $mods = get_extensions_list('extension');
+
+ foreach($mods as $pkg_name => $ext)
{
- while (($file = readdir($h)) !== false)
- {
- if (is_file("$filename/$file"))
- unlink("$filename/$file");
- }
- closedir($h);
- }
- rmdir($filename);
+ $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
+ label_cell('');
- unset($installed_modules[$id]);
- $mods = array_values($installed_modules);
- $installed_modules = $mods;
+ 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('');
- if (!write_modules())
- return;
- meta_forward($_SERVER['PHP_SELF']);
-}
+ end_row();
+ }
-//---------------------------------------------------------------------------------------------
+ end_table(1);
-function display_modules()
+ 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, $installed_modules, $tabs;
-
- echo "
- ";
- start_table($table_style);
- $th = array(_("Tab"), _("Name"), _("Folder"), _("Filename"), "", "");
+ start_table(TABLESTYLE);
+
+ $th = array(_("Extension"),_("Modules provided"), _("Options provided"), _("Active"));
+
+ $mods = get_company_extensions();
+ $exts = get_company_extensions($id);
+ foreach($mods as $key => $ins) {
+ foreach($exts as $ext)
+ if ($ext['name'] == $ins['name']) {
+ $mods[$key]['active'] = @$ext['active'];
+ continue 2;
+ }
+ }
+ $mods = array_natsort($mods, null, 'name');
table_header($th);
-
$k = 0;
- $mods = $installed_modules;
- $n = count($mods);
- for ($i = 0; $i < $n; $i++)
+ foreach($mods as $i => $mod)
{
+ if ($mod['type'] != 'extension') continue;
alt_table_row_color($k);
-
- label_cell($tabs[$mods[$i]['tab']]);
- label_cell($mods[$i]['name']);
- label_cell($mods[$i]['path']);
- label_cell($mods[$i]['filename']);
- $edit = _("Edit");
- $delete = _("Delete");
- if (user_graphic_links())
- {
- $edit = set_icon(ICON_EDIT, $edit);
- $delete = set_icon(ICON_DELETE, $delete);
- }
- label_cell("$edit");
- label_cell("$delete");
+ label_cell($mod['name']);
+ $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();
+ end_table(1);
+ submit_center('Refresh', _('Update'), true, false, 'default');
}
//---------------------------------------------------------------------------------------------
-
-function display_module_edit($selected_id)
+//
+// Third-party plugin installation
+//
+function display_ext_edit($selected_id)
{
- global $installed_modules, $table_style2;
+ global $Mode;
- if ($selected_id != -1)
- $n = $selected_id;
- else
- $n = count($installed_modules);
+ $extensions = get_company_extensions();
- start_form(true);
+ start_table(TABLESTYLE2);
- echo "
- ";
-
- start_table($table_style2);
-
- if ($selected_id != -1)
+ if ($selected_id != -1 && $extensions[$selected_id]['type'] == 'extension')
{
- $mod = $installed_modules[$selected_id];
- $_POST['tab'] = $mod['tab'];
- $_POST['name'] = $mod['name'];
- $_POST['path'] = $mod['path'];
- $_POST['filename'] = $mod['filename'];
+ if ($Mode == 'Edit') {
+ $mod = $extensions[$selected_id];
+ $entry = $mod['entries'][0];
+
+ $_POST['name'] = $mod['name'];
+ $_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);
- hidden('filename', $_POST['filename']);
}
- tab_list_row(_("Menu Tab"), 'tab', null);
text_row_ex(_("Name"), 'name', 30);
- text_row_ex(_("Folder"), 'path', 20);
+ text_row_ex(_("Subfolder (in modules directory)"), 'path', 20);
- label_row(_("Module File"), "");
- label_row(_("SQL File"), "");
+ tab_list_row(_("Menu Tab"), 'tab', null, true);
+ text_row_ex(_("Menu Link Text"), 'title', 30);
- end_table(0);
- display_note(_("Select your module PHP file from your local harddisk."), 0, 1);
- echo "