Rewritten extensions system to enable per company module/plugin
authorJanusz Dobrowolski <janusz@frontaccounting.eu>
Mon, 28 Sep 2009 13:17:15 +0000 (13:17 +0000)
committerJanusz Dobrowolski <janusz@frontaccounting.eu>
Mon, 28 Sep 2009 13:17:15 +0000 (13:17 +0000)
activation.

18 files changed:
admin/create_coy.php
admin/db/maintenance_db.inc
admin/inst_module.php
applications/customers.php
applications/dimensions.php
applications/generalledger.php
applications/inventory.php
applications/manufacturing.php
applications/setup.php
applications/suppliers.php
frontaccounting.php
includes/access_levels.inc
includes/current_user.inc
includes/main.inc
includes/session.inc
includes/ui/ui_lists.inc
installed_extensions.php
sql/alter2.2.php

index 684369c5e618245d4ffceafc624c7c69279a2ce1..d1050f0e321f0ebd846624e5e9c9f637071eebf6 100644 (file)
@@ -151,6 +151,8 @@ function handle_submit()
        {
                create_comp_dirs("$comp_path/$id", $comp_subdirs);
        }
+       $exts = get_company_extensions();
+       write_extensions($exts, $id);
        return true;
 }
 
index e23595fc4c2ad27418bcb03e4d0dd725f80ee7fb..18bcf3aad4aec88c7dcd71e6a3649d4379e1b672 100644 (file)
     See the License here <http://www.gnu.org/licenses/gpl-3.0.html>.
 ***********************************************************************/
 
+/**
+ * @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_config_db($new = false)
 {
        global $path_to_root, $def_coy, $db_connections, $tb_pref_counter;
@@ -76,6 +120,85 @@ function write_config_db($new = false)
        return 0;
 }
 
+function write_extensions($extensions=null, $company = null)
+{
+       global $path_to_root, $installed_extensions;
+
+       if (!isset($extensions)) {
+               $extensions = $installed_extensions;
+       }
+       
+       $exts = array_natsort($extensions, 'name', 'name');
+       $extensions = $exts;
+
+       $n = count($exts);
+
+       $msg = "<?php\n\n";
+       if ($company != -1)
+               $msg .=
+"/* List of installed additional modules and plugins. If adding extensions at the beginning 
+       of the list, make sure it's index is set to 0 (it has ' 0 => ');
+       
+       'name' - name for identification purposes;
+       'type' - type of extension: 'module' or 'plugin'
+       'path' - FA root based installation path
+       'filename' - name of module menu file, or plugin filename; related to path.
+       'tab' - index of the module tab (new for module, or one of standard module names for plugin);
+       'title' - is the menu text (for plugin) or new tab name
+       'active' - current status of extension
+       'acc_file' - (optional) file name with \$security_areas/\$security_sections extensions; 
+               related to 'path'.
+*/\n\n";
+       else 
+               $msg .=
+"/*
+       Do not edit this file manually. This copy of global file is overwritten
+       by extensions editor.
+*/\n\n";
+
+       $msg .= "\$installed_extensions = array (\n";
+       if ($n > 0)
+           $msg .= "\t0 => ";
+       for ($i = 0; $i < $n; $i++)
+       {
+               if ($i > 0)
+                       $msg .= "\t\t";
+               $msg .= "array ( ";
+               $t = '';
+               foreach($extensions[$i] as $key => $val) {
+                       $msg .= $t."'$key' => '$val',\n";
+                       $t = "\t\t\t";
+               }
+               $msg .= "\t\t),\n";
+       }
+       $msg .= "\t);\n?>";
+
+       $filename = $path_to_root . (isset($company) ? '/company/'.$company : '')
+               .'/installed_extensions.php';
+
+       // Check if the file is writable first.
+       if (!$zp = @fopen($filename, 'w'))
+       {
+               display_error(sprintf(_("Cannot open the extension setup file '%s' for writing."),
+                        $filename));
+               return false;
+       }
+       else
+       {
+               if (!fwrite($zp, $msg))
+               {
+                       display_error(sprintf(_("Cannot write to the extensions setup file '%s'."),
+                               $filename));
+                       fclose($zp);
+                       return false;
+               }
+               // Close file
+               fclose($zp);
+       }
+       return true;
+}
+
+
 function db_create_db($connection)
 {
        $db = mysql_connect($connection["host"] ,
index 92ea632470648b26a0eab379946e953c9b3d7a8a..11c30bfa5d2f62a6c53093e53a73331e4d01cff8 100644 (file)
@@ -13,12 +13,11 @@ $page_security = 'SA_CREATEMODULES';
 $path_to_root="..";
 include_once($path_to_root . "/includes/session.inc");
 
-page(_("Install/Update Modules"));
+page(_("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");
 
 //---------------------------------------------------------------------------------------------
@@ -35,126 +34,43 @@ else
        $selected_id = -1;
 
 //---------------------------------------------------------------------------------------------
+function get_company_extensions($id = -1) {
 
-function check_data($id)
-{
-       if ($_POST['name'] == "") {
-               display_error(_("Module name cannot be empty."));
-               return false;
-       }
-       if ($_POST['path'] == "") {
-               display_error(_("Module folder name cannot be empty."));
-               return false;
-       }
-       if ($id == -1 && !is_uploaded_file($_FILES['uploadfile']['tmp_name'])) {
-               display_error(_("You have to select module file to upload"));
-               return false; 
-       }
-       return true;
-}
+       global $path_to_root;
 
-/**
- * @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;
+       $file = $path_to_root.($id == -1 ? '' : '/company/'.$id).'/installed_extensions.php';
+       $installed_extensions = array();
+       if (is_file($file)) {
+               include($file);
+       }
+       return $installed_extensions;
 }
 
-function write_modules()
+function check_data($id, $exts)
 {
-       global $path_to_root, $installed_modules;
-
-       $mods = array_natsort($installed_modules, 'tab', 'tab');
-       $installed_modules = $mods;
-       //reset($installed_languages);
-       $n = count($installed_modules);
-       $msg = "<?php\n\n";
-
-       $msg .= "/*****************************************************************\n";
-       $msg .= "External modules for FrontAccounting\n";
-       $msg .= "******************************************************************/\n";
-       $msg .= "\n\n";
-
-       $msg .= "\$installed_modules = array (\n";
-       if ($n > 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 .= "'acc_file' => '" . $installed_modules[$i]['acc_file'] . "'";
-               $msg .= "),\n";
+       if ($_POST['name'] == "") {
+               display_error(_("Extension name cannot be empty."));
+               return false;
        }
-       $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 plugin file to upload"));
+               return false; 
+       }
        return true;
 }
 
@@ -162,16 +78,22 @@ function write_modules()
 
 function handle_submit()
 {
-       global $path_to_root, $installed_modules, $db_connections, $selected_id;
+       global $path_to_root, $db_connections, $selected_id;
 
-       if (!check_data($selected_id))
+       $extensions = get_company_extensions();
+       if (!check_data($selected_id), $extensions)
                return false;
 
        $id = $_GET['id'];
 
-       $installed_modules[$id]['tab'] = $_POST['tab'];
-       $installed_modules[$id]['name'] = $_POST['name'];
-       $installed_modules[$id]['path'] = $_POST['path'];
+       $extensions[$id]['tab'] = $_POST['tab'];
+       $extensions[$id]['name'] = $_POST['name'];
+       $extensions[$id]['path'] = $_POST['path'];
+       $extensions[$id]['title'] = $_POST['title'];
+       $extensions[$id]['active'] = $_POST['active'];
+
+       // Currently we support only plugin extensions here.
+       $extensions[$id]['type'] = 'plugin';
        $directory = $path_to_root . "/modules/" . $_POST['path'];
        if (!file_exists($directory))
        {
@@ -179,7 +101,7 @@ function handle_submit()
        }
        if (is_uploaded_file($_FILES['uploadfile']['tmp_name']))
        {
-               $installed_modules[$id]['filename'] = $_FILES['uploadfile']['name'];
+               $extensions[$id]['filename'] = $_FILES['uploadfile']['name'];
                $file1 = $_FILES['uploadfile']['tmp_name'];
                $file2 = $directory . "/".$_FILES['uploadfile']['name'];
                if (file_exists($file2))
@@ -187,7 +109,7 @@ function handle_submit()
                move_uploaded_file($file1, $file2);
        }
        else
-               $installed_modules[$id]['filename'] = get_post('filename');
+               $extensions[$id]['filename'] = get_post('filename');
        if (is_uploaded_file($_FILES['uploadfile2']['tmp_name']))
        {
                $file1 = $_FILES['uploadfile2']['tmp_name'];
@@ -201,7 +123,7 @@ function handle_submit()
        
        if (is_uploaded_file($_FILES['uploadfile3']['tmp_name']))
        {
-               $installed_modules[$id]['acc_file'] = $_FILES['uploadfile3']['name'];
+               $extensions[$id]['acc_file'] = $_FILES['uploadfile3']['name'];
                $file1 = $_FILES['uploadfile3']['tmp_name'];
                $file2 = $directory . "/".$_FILES['uploadfile3']['name'];
                if (file_exists($file2))
@@ -209,9 +131,9 @@ function handle_submit()
                move_uploaded_file($file1, $file2);
        }
        else
-               $installed_modules[$id]['acc_file'] = get_post('acc_file');
+               $extensions[$id]['acc_file'] = get_post('acc_file');
        
-       if (!write_modules())
+       if (!write_extensions($extensions))
                return false;
        return true;
 }
@@ -220,11 +142,19 @@ function handle_submit()
 
 function handle_delete()
 {
-       global  $path_to_root, $installed_modules;
+       global  $path_to_root;
+       
+       $extensions = get_company_extensions();
 
        $id = $_GET['id'];
 
-       $path = $installed_modules[$id]['path'];
+       $path = $extensions[$id]['path'];
+
+       if ($extensions[$id]['type'] != 'plugin') {
+               display_error(_('Module installation support is not implemented yet. You have to do it manually.'));
+               return;
+       }
+       
        $filename = "$path_to_root/modules/$path";
        if ($h = opendir($filename))
        {
@@ -237,72 +167,126 @@ function handle_delete()
        }
        rmdir($filename);
 
-       unset($installed_modules[$id]);
-       $mods = array_values($installed_modules);
-       $installed_modules = $mods;
+       unset($extensions[$id]);
+       $mods = array_values($extensions);
+       $extensions = $mods;
 
-       if (!write_modules())
+       if (!write_extensions($extensions))
                return;
+       
+       // should we also delete module form per company extension files?
+       
        meta_forward($_SERVER['PHP_SELF']);
 }
 
 //---------------------------------------------------------------------------------------------
 
-function display_modules()
+function display_extensions()
 {
-       global $table_style, $installed_modules, $tabs;
+       global $table_style, $tabs;
 
        echo "
                <script language='javascript'>
-               function deleteModule(id, name) {
-                       if (!confirm('" . _("Are you sure you want to delete module: ") . "'+name))
+               function deleteExtension(id, name) {
+                       if (!confirm('" . _("Are you sure you want to delete extension: ") . "'+name))
                                return
                        document.location.replace('inst_module.php?c=df&id='+id)
                }
                </script>";
        start_table($table_style);
-       $th = array(_("Tab"), _("Name"), _("Folder"), _("Filename"), _("Access extensions"),"", "");
+       $th = array(_("Name"),_("Tab"), _("Link text"), _("Folder"), _("Filename"), 
+               _("Access extensions"),"", "");
        table_header($th);
 
        $k = 0;
-       $mods = $installed_modules;
+       $mods = get_company_extensions();
        $n = count($mods);
        for ($i = 0; $i < $n; $i++)
        {
+               $is_mod = $mods[$i]['type'] == 'module';
                alt_table_row_color($k);
-
-               label_cell($tabs[$mods[$i]['tab']]);
                label_cell($mods[$i]['name']);
+               label_cell( $is_mod ? $mods[$i]['title'] : $tabs[$mods[$i]['tab']]);
+               $ttl = access_string($mods[$i]['title']);
+               label_cell($ttl[0]);
                label_cell($mods[$i]['path']);
                label_cell($mods[$i]['filename']);
                label_cell(@$mods[$i]['acc_file']);
                $edit = _("Edit");
                $delete = _("Delete");
-               if (user_graphic_links())
+               if ($is_mod)
+               {
+                       label_cell(''); // not implemented (yet)
+                       label_cell('');
+               }
+               else
                {
-                       $edit = set_icon(ICON_EDIT, $edit);
-                       $delete = set_icon(ICON_DELETE, $delete);
+                       if (user_graphic_links())
+                       {
+                               $edit = set_icon(ICON_EDIT, $edit);
+                               $delete = set_icon(ICON_DELETE, $delete);
+                       }
+               label_cell("<a href='" . $_SERVER['PHP_SELF']. "?selected_id=$i'>$edit</a>");
+                       label_cell("<a href='javascript:deleteExtension(".$i.", \"" . $mods[$i]['name'] . "\")'>$delete</a>");
                }
-       label_cell("<a href='" . $_SERVER['PHP_SELF']. "?selected_id=$i'>$edit</a>");
-               label_cell("<a href='javascript:deleteModule(".$i.", \"" . $mods[$i]['name'] . "\")'>$delete</a>");
                end_row();
        }
 
        end_table();
 }
 
+function company_extensions($id)
+{
+       global $table_style, $tabs;
+
+       start_table($table_style);
+       
+       $th = array(_("Name"),_("Tab"), _("Link text"), _("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) {
+               foreach($exts as $ext)
+                       if ($ext['name'] == $ins['name']) {
+                               $mods[$key]['active'] = @$ext['active'];
+                               continue 2;
+                       }
+       }
+       
+       table_header($th);
+       $k = 0;
+       $n = count($mods);
+       for ($i = 0; $i < $n; $i++)
+       {
+               alt_table_row_color($k);
+               label_cell($mods[$i]['name']);
+               label_cell($mods[$i]['type'] == 'module' ? $mods[$i]['title'] : $tabs[$mods[$i]['tab']]);
+               $ttl = access_string($mods[$i]['title']);
+               label_cell($ttl[0]);
+               check_cells(null, 'Active'.$i, @$mods[$i]['active'] ? 1:0, 
+                       false, false, "align='center'");
+               end_row();
+       }
+
+       end_table(1);
+       submit_center('Update', _('Update'), true, false, 'default');
+}
+
 //---------------------------------------------------------------------------------------------
 
-function display_module_edit($selected_id)
+function display_ext_edit($selected_id)
 {
-       global $installed_modules, $table_style2;
+       global $table_style2;
 
+       $extensions = get_company_extensions();
        if ($selected_id != -1)
                $n = $selected_id;
        else
-               $n = count($installed_modules);
+               $n = count($extensions);
 
-       start_form(true);
 
        echo "
                <script language='javascript'>
@@ -314,11 +298,12 @@ function display_module_edit($selected_id)
 
        start_table($table_style2);
 
-       if ($selected_id != -1)
+       if ($selected_id != -1 && $extensions[$selected_id]['type'] == 'plugin')
        {
-               $mod = $installed_modules[$selected_id];
+               $mod = $extensions[$selected_id];
                $_POST['tab']  = $mod['tab'];
                $_POST['name'] = $mod['name'];
+               $_POST['title'] = $mod['title'];
                $_POST['path'] = $mod['path'];
                $_POST['filename'] = $mod['filename'];
                $_POST['acc_file'] = @$mod['acc_file'];
@@ -326,25 +311,36 @@ function display_module_edit($selected_id)
                hidden('filename', $_POST['filename']);
                hidden('acc_file', $_POST['acc_file']);
        }
-       tab_list_row(_("Menu Tab"), 'tab', null);
        text_row_ex(_("Name"), 'name', 30);
        text_row_ex(_("Folder"), 'path', 20);
 
+       tab_list_row(_("Menu Tab"), 'tab', null);
+       text_row_ex(_("Menu Link Text"), 'title', 30);
+       record_status_list_row(_("Default status"), 'active');
+
        label_row(_("Module File"), "<input name='uploadfile' type='file'>");
        label_row(_("Access Levels Extensions"), "<input name='uploadfile3' type='file'>");
        label_row(_("SQL File"), "<input name='uploadfile2' type='file'>");
 
        end_table(0);
        display_note(_("Select your module PHP file from your local harddisk."), 0, 1);
-       echo "<center><input onclick='javascript:updateModule()' type='button' style='width:150px' value='". _("Save"). "'></center>";
 
+       echo "<center><input onclick='javascript:updateModule()' type='button' style='width:150px' value='". _("Save"). "'></center>";
 
-       end_form();
 }
 
 //---------------------------------------------------------------------------------------------
-
-if (isset($_GET['c']))
+if (get_post('Update')) {
+       $exts = get_company_extensions();
+       for($i = 0; $i < count($exts); $i++) {
+               $exts[$i]['active'] = check_value('Active'.$i);
+       }
+       write_extensions($exts, get_post('extset'));
+       if (get_post('extset') == user_company())
+               $installed_extensions = $exts;
+       display_notification(_('Current active extensions set has been saved.'));
+}
+elseif (isset($_GET['c']))
 {
        if ($_GET['c'] == 'df')
        {
@@ -356,22 +352,35 @@ if (isset($_GET['c']))
                if (handle_submit())
                {
                        if ($selected_id != -1)
-                               display_notification(_("Module data has been updated."));
+                               display_notification(_("Extension data has been updated."));
                        else
-                               display_notification(_("Module has been installed."));
+                               display_notification(_("Extension has been installed."));
                }
        }
 }
 
 //---------------------------------------------------------------------------------------------
+start_form(true);
+if (list_updated('extset'))
+       $Ajax->activate('_page_body');
 
-display_modules();
+echo "<center>" . _('Extensions:') . "&nbsp;&nbsp;";
+extset_list('extset', null, true);
+echo "</center><br>";
 
-hyperlink_no_params($_SERVER['PHP_SELF'], _("Create a new module"));
+$set = get_post('extset');
 
-display_module_edit($selected_id);
+if ($set == -1) {
+       display_extensions();
 
+       hyperlink_no_params($_SERVER['PHP_SELF'], _("Add new extension"));
+
+       display_ext_edit($selected_id);
+} else {
+       company_extensions($set);
+}
 //---------------------------------------------------------------------------------------------
+end_form();
 
 end_page();
 
index c00b2f7640221ec13f2c24ec9e64bd88bdb7065d..eb3f9812671060a544cd150ca411a1f406d8a616 100644 (file)
@@ -13,7 +13,7 @@
        {
                function customers_app() 
                {
-                       global $installed_modules;
+                       global $installed_extensions;
                        $this->application("orders",_("&Sales"));
                
                        $this->add_module(_("Transactions"));
                        $this->add_rapp_function(2, _("Sales &Persons"),"sales/manage/sales_people.php?");
                        $this->add_rapp_function(2, _("Sales &Areas"),"sales/manage/sales_areas.php?");
                        $this->add_rapp_function(2, _("Credit &Status Setup"),"sales/manage/credit_status.php?");
-                       if (count($installed_modules) > 0)
+                       if (count($installed_extensions) > 0)
                        {
-                               foreach ($installed_modules as $mod)
+                               foreach ($installed_extensions as $mod)
                                {
-                                       if ($mod["tab"] == "orders")
-                                               $this->add_rapp_function(2, $mod["name"], "modules/".$mod["path"]."/".$mod["filename"]."?");
+                                       if (@$mod['active'] && $mod['type'] == 'plugin' && $mod["tab"] == "orders")
+                                               $this->add_rapp_function(2, $mod["title"], "modules/".$mod["path"]."/".$mod["filename"]."?");
                                }
                        }       
                }
index 4cbbb0650fe1a425f8b6e000ad87d3fe694df2fe..b30d11dc0053fbb720aef55c7dea40ecf075c7bb 100644 (file)
@@ -13,7 +13,7 @@
        {
                function dimensions_app()
                {
-                       global $installed_modules;
+                       global $installed_extensions;
                        $dim = get_company_pref('use_dimension');
                        $this->application("proj",_("&Dimensions"), $dim);
 
                                $this->add_lapp_function(1, _("Dimension &Inquiry"),"dimensions/inquiry/search_dimensions.php?");
 
                                $this->add_rapp_function(1, _("Dimension &Reports"),"reporting/reports_main.php?Class=4");
-                               if (count($installed_modules) > 0)
+                               if (count($installed_extensions) > 0)
                                {
                                        $i = 0;
-                                       foreach ($installed_modules as $mod)
+                                       foreach ($installed_extensions as $mod)
                                        {
-                                               if ($mod["tab"] == "proj")
+                                               if (@$mod['active'] && $mod['type'] == 'plugin' && $mod["tab"] == "proj")
                                                {
                                                        if ($i++ == 0)
                                                                $this->add_module(_("Maintenance"));
-                                                       $this->add_rapp_function(2, $mod["name"], "modules/".$mod["path"]."/".$mod["filename"]."?");
+                                                       $this->add_rapp_function(2, $mod["title"], "modules/".$mod["path"]."/".$mod["filename"]."?");
                                                }
                                        }
                                }
index 89a34a59a343dcc8f0c89896e4470dd7d89ad12c..4b72f8b80e1987c6d6f27eeb794554528ad84236 100644 (file)
@@ -13,7 +13,7 @@
        {
                function general_ledger_app() 
                {
-                       global $installed_modules;
+                       global $installed_extensions;
                        $this->application("GL",_("&Banking and General Ledger"));
 
                        $this->add_module(_("Transactions"));
                        $this->add_rapp_function(2, _("&GL Accounts"),"gl/manage/gl_accounts.php?");
                        $this->add_rapp_function(2, _("GL Account &Groups"),"gl/manage/gl_account_types.php?");
                        $this->add_rapp_function(2, _("GL Account &Classes"),"gl/manage/gl_account_classes.php?");
-                       if (count($installed_modules) > 0)
+                       if (count($installed_extensions) > 0)
                        {
-                               foreach ($installed_modules as $mod)
+                               foreach ($installed_extensions as $mod)
                                {
-                                       if ($mod["tab"] == "GL")
-                                               $this->add_rapp_function(2, $mod["name"], "modules/".$mod["path"]."/".$mod["filename"]."?");
+                                       if (@$mod['active'] && $mod['type'] == 'plugin' && $mod["tab"] == "GL")
+                                               $this->add_rapp_function(2, $mod["title"], "modules/".$mod["path"]."/".$mod["filename"]."?");
                                }
                        }       
                }
index 449095292b37d78c5b8409f555d0c28ab8ca20e7..caeaf378d446dcde4c11cdf2751c773c04e899a7 100644 (file)
@@ -13,7 +13,7 @@
        {
                function inventory_app() 
                {
-                       global $installed_modules;
+                       global $installed_extensions;
                        $this->application("stock",_("&Items and Inventory"));
 
                        $this->add_module(_("Transactions"));
                        $this->add_lapp_function(3, _("Sales &Pricing"),"inventory/prices.php?");
                        $this->add_lapp_function(3, _("Purchasing &Pricing"),"inventory/purchasing_data.php?");
                        $this->add_rapp_function(3, _("Standard &Costs"),"inventory/cost_update.php?");
-                       if (count($installed_modules) > 0)
+                       if (count($installed_extensions) > 0)
                        {
-                               foreach ($installed_modules as $mod)
+                               foreach ($installed_extensions as $mod)
                                {
-                                       if ($mod["tab"] == "stock")
-                                               $this->add_rapp_function(2, $mod["name"], "modules/".$mod["path"]."/".$mod["filename"]."?");
+                                       if (@$mod['active'] && $mod['type'] == 'plugin' && $mod["tab"] == "stock")
+                                               $this->add_rapp_function(2, $mod["title"], "modules/".$mod["path"]."/".$mod["filename"]."?");
                                }
                        }       
                }
index ffcfc021791153510409d1e068b1cc18e827aa41..fba05a7d7a824d8603890d752f1d4009d1e23cb4 100644 (file)
@@ -13,7 +13,7 @@
        {
                function manufacturing_app()
                {
-                       global $installed_modules;
+                       global $installed_extensions;
                        $this->application("manuf",_("&Manufacturing"));
 
                        $this->add_module(_("Transactions"));
                        $this->add_module(_("Maintenance"));
                        $this->add_lapp_function(2, _("&Bills Of Material"),"manufacturing/manage/bom_edit.php?");
                        $this->add_lapp_function(2, _("&Work Centres"),"manufacturing/manage/work_centres.php?");
-                       if (count($installed_modules) > 0)
+                       if (count($installed_extensions) > 0)
                        {
-                               foreach ($installed_modules as $mod)
+                               foreach ($installed_extensions as $mod)
                                {
-                                       if ($mod["tab"] == "manuf")
-                                               $this->add_rapp_function(2, $mod["name"], "modules/".$mod["path"]."/".$mod["filename"]."?");
+                                       if (@$mod['active'] && $mod['type'] == 'plugin' && $mod["tab"] == "manuf")
+                                               $this->add_rapp_function(2, $mod["title"], "modules/".$mod["path"]."/".$mod["filename"]."?");
                                }
                        }
                }
index 771851a56c2e300d1350d22f614999c0565e2fa2..747b23d8c6c8ba7247c655f1a1de3ac683c8bc0e 100644 (file)
@@ -13,7 +13,7 @@
        {
                function setup_app()
                {
-                       global $installed_modules;
+                       global $installed_extensions;
                        $this->application("system",_("S&etup"));
 
                        $this->add_module(_("Company Setup"));
                        $this->add_rapp_function(2, _("&Backup and Restore"),"admin/backups.php?", 'SA_BACKUP');
                        $this->add_rapp_function(2, _("Create/Update &Companies"),"admin/create_coy.php?", 'SA_CREATECOMPANY');
                        $this->add_rapp_function(2, _("Install/Update &Languages"),"admin/inst_lang.php?", 'SA_CREATELANGUAGE');
-                       $this->add_rapp_function(2, _("Install/Update &Modules"),"admin/inst_module.php?", 'SA_CREATEMODULES');
+                       $this->add_rapp_function(2, _("Install/Activate &Extensions"),"admin/inst_module.php?", 'SA_CREATEMODULES');
                        $this->add_rapp_function(2, _("Software &Upgrade"),"admin/inst_upgrade.php?", 'SA_SOFTWAREUPGRADE');
-                       if (count($installed_modules) > 0)
+                       if (count($installed_extensions) > 0)
                        {
-                               foreach ($installed_modules as $mod)
+                               foreach ($installed_extensions as $mod)
                                {
-                                       if ($mod["tab"] == "system")
-                                               $this->add_rapp_function(2, $mod["name"], "modules/".$mod["path"]."/".$mod["filename"]."?");
+                                       if (@$mod['active'] && $mod['type'] == 'plugin' && $mod["tab"] == "system")
+                                               $this->add_rapp_function(2, $mod["title"], "modules/".$mod["path"]."/".$mod["filename"]."?");
                                }
                        }
                }
index 345b3d10e95e8786bc4aed5e83108b11999e89c5..f7c529e5de173f714ec353d78f6629f752b6e6d1 100644 (file)
@@ -13,7 +13,7 @@
        {
                function suppliers_app() 
                {
-                       global $installed_modules;
+                       global $installed_extensions;
                        $this->application("AP",_("&Purchases"));
                        
                        $this->add_module(_("Transactions"));
                        
                        $this->add_module(_("Maintenance"));
                        $this->add_lapp_function(2, _("&Suppliers"),"purchasing/manage/suppliers.php?");
-                       if (count($installed_modules) > 0)
+                       if (count($installed_extensions) > 0)
                        {
-                               foreach ($installed_modules as $mod)
+                               foreach ($installed_extensions as $mod)
                                {
-                                       if ($mod["tab"] == "AP")
-                                               $this->add_rapp_function(2, $mod["name"], "modules/".$mod["path"]."/".$mod["filename"]."?");
+                                       if (@$mod['active'] && $mod['type'] == 'plugin' && $mod["tab"] == "AP")
+                                               $this->add_rapp_function(2, $mod["title"], "modules/".$mod["path"]."/".$mod["filename"]."?");
                                }
                        }       
                }
index 033c99283758f9f537cb096323221779ad7b69f2..267780b191b40593fbf4880aea4d5c480ccf5415 100644 (file)
@@ -24,12 +24,11 @@ if (!isset($path_to_root) || isset($_GET['path_to_root']) || isset($_POST['path_
        {
                foreach ($installed_extensions as $ext)
                {
-                       include_once($path_to_root."/".$ext['folder']."/".$ext['app_file']);
+                       if ($ext['type'] == 'module')
+                               @include_once($path_to_root."/".$ext['path']."/".$ext['filename']);
                }
        }       
 
-       include_once($path_to_root . '/modules/installed_modules.php');
-
        class front_accounting
                {
                var $user;
@@ -91,12 +90,15 @@ if (!isset($path_to_root) || isset($_GET['path_to_root']) || isset($_POST['path_
                        {
                                foreach ($installed_extensions as $ext)
                                {
-                                       $_SESSION['get_text']->add_domain($_SESSION['language']->code, 
-                                               $ext['folder']."/lang");
-                                       $class = $ext['name']."_app";
-                                       $this->add_application(new $class());
-                                       $_SESSION['get_text']->add_domain($_SESSION['language']->code, 
-                                               $path_to_root."/lang");
+                                       if (@($ext['active'] && $ext['type'] == 'module')) { // supressed warnings before 2.2 upgrade
+                                               $_SESSION['get_text']->add_domain($_SESSION['language']->code, 
+                                                       $ext['path']."/lang");
+                                               $class = $ext['tab']."_app";
+                                               if (class_exists($class))
+                                                       $this->add_application(new $class());
+                                               $_SESSION['get_text']->add_domain($_SESSION['language']->code, 
+                                                       $path_to_root."/lang");
+                                       }
                                }
                        }       
                        
index b4e4d7889324f2ff2d14611ba0d620941f766a17..3c60a0922a83a308498896ac2fc63b4cf2314ded 100644 (file)
@@ -249,13 +249,7 @@ function add_access_extensions()
        include($path_to_root.'/installed_extensions.php');
        foreach($installed_extensions as $ext) {
                if (isset($ext['acc_file']))
-                       include_once($path_to_root.'/'.$ext['folder'].'/'.$ext['acc_file']);
-       }
-       // Add modules private access levels
-       include($path_to_root.'/modules/installed_modules.php');
-       foreach($installed_modules as $mod) {
-               if (isset($mod['acc_file']) && $mod['acc_file'] != '')
-                       include($path_to_root.'/modules/'.$mod['path'].'/'.$mod['acc_file']);
+                       include_once($path_to_root.($ext['type'] == 'plugin' ? '/modules/':'/').$ext['path'].'/'.$ext['acc_file']);
        }
 }
 ?>
\ No newline at end of file
index 5430b1104c2eb1d59b1ae31df94f364a0901bf1b..94b7c2ffaa86f079c786071641004faf38a96b5c 100644 (file)
@@ -134,10 +134,11 @@ class current_user
 
                if ($page_level === 'SA_OPEN') 
                        return true;
-               $code = $security_areas[$page_level][0];
+               $code = @$security_areas[$page_level][0];
+
                // only first registered company has site admin privileges
                return $code && in_array($code, $this->role_set)
-                       && ($this->company == 0 || ($code&~0xff != SS_SADMIN));
+                       && ($this->company == 0 || (($code&~0xff) != SS_SADMIN));
        }
 
        function can_access_page($page_level)
index 1a2478e9f6a9580c54aa0d50d354f05be1d3981f..f52d88c6088a5d383ffa926f80dddab4c5d75484 100644 (file)
@@ -24,7 +24,6 @@ include_once($path_to_root . "/includes/db/audit_trail_db.inc");
 include_once($path_to_root . "/admin/db/users_db.inc");
 include_once($path_to_root . "/includes/ui/ui_view.inc");
 include_once($path_to_root . "/includes/ui/ui_controls.inc");
-include_once($path_to_root . "/installed_extensions.php");
        
 function page($title, $no_menu=false, $is_index=false, $onload="", $js="", $script_only=false)
 {
index b7880a91fbf6bba4572c8175907b04efa0a15645..19a0e4a66335a27edd064dd42ff969d7ba1d5c4f 100644 (file)
@@ -124,9 +124,9 @@ if (!isset($path_to_root))
 if (isset($_GET['path_to_root']) || isset($_POST['path_to_root']))
        die("Restricted access");
 
+include_once($path_to_root . "/includes/current_user.inc");
 include_once($path_to_root . "/frontaccounting.php");
 include_once($path_to_root . "/admin/db/security_db.inc");
-include_once($path_to_root . "/includes/current_user.inc");
 include_once($path_to_root . "/includes/lang/language.php");
 include_once($path_to_root . "/config_db.php");
 include_once($path_to_root . "/includes/ajax.inc");
@@ -229,6 +229,8 @@ if (strstr($_SERVER['PHP_SELF'], 'logout.php') == false){
                }
        }
 
+       include_once($path_to_root . '/company/'.user_company().'/installed_extensions.php');
+
        if (!isset($_SESSION["App"])) {
                $_SESSION["App"] = new front_accounting();
                $_SESSION["App"]->init();
index 9563cf08d5a49334868004e69d674b51226f1a2f..62a34df9b9c5612c2e4e62bbc5b3088b8defa243 100644 (file)
@@ -2126,5 +2126,23 @@ function tab_list_row($label, $name, $selected_id=null)
        echo "</td></tr>\n";
 }
 
+//---------------------------------------------------------------------------------------------
+//     List of sets of active extensions 
+//
+function extset_list($name, $value=null, $submit_on_change=false)
+{
+       global $db_connections;
+
+       $items = array();
+       foreach ($db_connections as $comp)
+               $items[] = sprintf(_("Activated for '%s'"), $comp['name']);
+       array_selector( $name, $value, $items,
+               array(
+                       'spec_option'=> _("Installed on system"),
+                       'spec_id' => -1,
+                       'select_submit'=> $submit_on_change,
+                       'async' => true
+               ));
+}
 
 ?>
\ No newline at end of file
index f18c1ff6563a7727d4f76f50152806c8bc1a75d0..b83e3cfb66645e973b1efb44032aee80ef03e122 100644 (file)
@@ -1,23 +1,19 @@
 <?php
 
-/* How to make new entries here
-
--- if adding extensions at the beginning of the list, make sure it's index is set to 0 (it has ' 0 => ')
--- 'app_file' is the application file name to be put into folder applications
--- 'name' is the name of the extension module. Will become the index of the application
--- 'title' is the Menu Title
--- 'folder' is the folder where the extension files exist
--- 'acc_file' is path inside extension folder to optional file with $security_areas/$security_sections extensions 
+/* List of installed additional modules and plugins. If adding extensions at the beginning 
+       of the list, make sure it's index is set to 0 (it has ' 0 => ');
+       
+       'name' - name for identification purposes;
+       'type' - type of extension: 'module' or 'plugin'
+       'path' - FA root based installation path
+       'filename' - name of module menu file, or plugin filename; related to path.
+       'tab' - index of the module tab (new for module, or one of standard module names for plugin);
+       'title' - is the menu text (for plugin) or new tab name
+       'active' - current status of extension
+       'acc_file' - (optional) file name with $security_areas/$security_sections extensions; 
+               related to 'path'.
 */
 
-$installed_extensions = array ();
-
-// example
-/*
 $installed_extensions = array (
-       0 => array ('app_file' => 'organizer.php', 'name' => 'organizer', 'title' => 'Organizer', 'folder' => 'organizer',
-       'acc_file'=>'')),
-       array ('app_file' => 'payroll.php', 'name' => 'payroll', 'title' => 'Payroll', 'folder' => 'payroll',
-               'acc_file'=>'includes/access_exts.inc'));
-*/     
+       );
 ?>
\ No newline at end of file
index 30219a7079c9cd0ebbbef04543198e09b80f070d..8d9e1449790e21fa05c86978edb32354aef9796f 100644 (file)
@@ -14,6 +14,12 @@ class fa2_2 {
        var $version = '2.2';   // version installed
        var $description = 'Version 2.2';
        var $sql = 'alter2.2.sql';
+       var $preconf = true;
+       
+       function fa2_2() {
+               $this->preconf = fix_extensions();
+       }
+       
        //
        //      Install procedure. All additional changes 
        //      not included in sql file should go here.
@@ -21,6 +27,10 @@ class fa2_2 {
        function install($pref, $force) 
        {
                global $db, $systypes_array;
+               
+               if (!$preconf)
+                       return false;
+               
                // set item category dflt accounts to values from company GL setup
                $prefs = get_company_prefs();
                $sql = "UPDATE {$pref}stock_category SET "
@@ -227,6 +237,52 @@ function import_security_role($pref, $name, $sections, $areas)
        db_query($sql, "could not add new security role");
 }
 
+/*
+       Changes in extensions system.
+       This function is executed once on first Upgrade System display.
+*/
+function fix_extensions() {
+       global $path_to_root, $db_connections;
+
+       if (!file_exists($path_to_root.'/modules/installed_modules.php'))
+               return true; // already converted
+       
+       if (!is_writable($path_to_root.'/modules/installed_modules.php')) {
+               display_error(_('Cannot upgrade extensions system: file /modules/installed_modules.php is no writeable'));
+               return false;
+       }
+       
+       $exts = array();
+       include($path_to_root.'/installed_extensions.php');
+       foreach($installed_extensions as $ext) {
+               $ext['filename'] = $ext['app_file']; unset($ext['app_file']);
+               $ext['tab'] = $ext['name'];
+               $ext['name'] = access_string($ext['title'], true); 
+               $ext['path'] = $ext['folder']; unset($ext['folder']);
+               $ext['type'] = 'module';
+               $ext['active'] = '1';
+               $exts[] = $ext;
+       }
+
+       include($path_to_root.'/modules/installed_modules.php');
+       foreach($installed_modules as $mod) {
+               $mod['title'] = $mod['name'];
+               $mod['name'] = access_string($mod['name'], true);
+               $mod['type'] = 'plugin';
+               $ext['active'] = '1';
+               $exts[] = $mod;
+       }
+       if (!write_extensions($exts))
+               return false;
+       
+       $cnt = count($db_connections);
+       for ($i = 0; $i < $cnt; $i++)
+               write_extensions($exts, $i);
+
+       unlink($path_to_root.'/modules/installed_modules.php');
+       return true;
+}
+
 $install = new fa2_2;
 
 ?>
\ No newline at end of file