Optional additional security roles inscludable from modules/extensions.
authorJanusz Dobrowolski <janusz@frontaccounting.eu>
Sun, 20 Sep 2009 16:34:48 +0000 (16:34 +0000)
committerJanusz Dobrowolski <janusz@frontaccounting.eu>
Sun, 20 Sep 2009 16:34:48 +0000 (16:34 +0000)
admin/inst_module.php
admin/security_roles.php
includes/access_levels.inc
installed_extensions.php

index 00ab1adc90f5a08b4bc378b5c6e69c4125ffda8b..92ea632470648b26a0eab379946e953c9b3d7a8a 100644 (file)
@@ -36,10 +36,20 @@ else
 
 //---------------------------------------------------------------------------------------------
 
-function check_data()
+function check_data($id)
 {
-       if ($_POST['name'] == "" || $_POST['path'] == "")
+       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;
 }
 
@@ -113,7 +123,8 @@ function write_modules()
                $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 .= "'filename' => '" . $installed_modules[$i]['filename'] . "',";
+               $msg .= "'acc_file' => '" . $installed_modules[$i]['acc_file'] . "'";
                $msg .= "),\n";
        }
        $msg .= "\t);\n?>";
@@ -151,9 +162,9 @@ function write_modules()
 
 function handle_submit()
 {
-       global $path_to_root, $installed_modules, $db_connections;
+       global $path_to_root, $installed_modules, $db_connections, $selected_id;
 
-       if (!check_data())
+       if (!check_data($selected_id))
                return false;
 
        $id = $_GET['id'];
@@ -176,7 +187,7 @@ function handle_submit()
                move_uploaded_file($file1, $file2);
        }
        else
-               $installed_modules[$id]['filename'] = $_POST['filename'];
+               $installed_modules[$id]['filename'] = get_post('filename');
        if (is_uploaded_file($_FILES['uploadfile2']['tmp_name']))
        {
                $file1 = $_FILES['uploadfile2']['tmp_name'];
@@ -187,6 +198,19 @@ function handle_submit()
                $db_name = $_SESSION["wa_current_user"]->company;
                db_import($file2, $db_connections[$db_name]);
        }
+       
+       if (is_uploaded_file($_FILES['uploadfile3']['tmp_name']))
+       {
+               $installed_modules[$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);
+       }
+       else
+               $installed_modules[$id]['acc_file'] = get_post('acc_file');
+       
        if (!write_modules())
                return false;
        return true;
@@ -237,7 +261,7 @@ function display_modules()
                }
                </script>";
        start_table($table_style);
-       $th = array(_("Tab"), _("Name"), _("Folder"), _("Filename"), "", "");
+       $th = array(_("Tab"), _("Name"), _("Folder"), _("Filename"), _("Access extensions"),"", "");
        table_header($th);
 
        $k = 0;
@@ -251,6 +275,7 @@ function display_modules()
                label_cell($mods[$i]['name']);
                label_cell($mods[$i]['path']);
                label_cell($mods[$i]['filename']);
+               label_cell(@$mods[$i]['acc_file']);
                $edit = _("Edit");
                $delete = _("Delete");
                if (user_graphic_links())
@@ -296,14 +321,17 @@ function display_module_edit($selected_id)
                $_POST['name'] = $mod['name'];
                $_POST['path'] = $mod['path'];
                $_POST['filename'] = $mod['filename'];
+               $_POST['acc_file'] = @$mod['acc_file'];
                hidden('selected_id', $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);
 
        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);
@@ -314,7 +342,6 @@ function display_module_edit($selected_id)
        end_form();
 }
 
-
 //---------------------------------------------------------------------------------------------
 
 if (isset($_GET['c']))
@@ -328,7 +355,10 @@ if (isset($_GET['c']))
        {
                if (handle_submit())
                {
-                       //meta_forward($_SERVER['PHP_SELF']);
+                       if ($selected_id != -1)
+                               display_notification(_("Module data has been updated."));
+                       else
+                               display_notification(_("Module has been installed."));
                }
        }
 }
index c961e76cd521dd6f57aa92142a74e3caae7c7c93..a6792f863da9417508b390388a1879c5bc5a19c7 100644 (file)
@@ -13,6 +13,8 @@ $page_security = 'SA_SECROLES';
 $path_to_root = "..";
 include_once($path_to_root . "/includes/session.inc");
 
+add_access_extensions();
+
 page(_("Access setup"));
 
 include_once($path_to_root . "/includes/ui.inc");
index d884e741d76bbd363b65f53250559639230e9a8b..b4e4d7889324f2ff2d14611ba0d620941f766a17 100644 (file)
@@ -235,4 +235,27 @@ $security_areas =array(
        'SA_BANKREP' => array(SS_GL_A|3, _("Bank reports and inquiries")),
        'SA_GLREP' => array(SS_GL_A|4, _("GL reports and inquiries")),
 );
+/*
+       This function should be called whenever we want to extend core access level system
+       with new security areas and/or sections i.e.: 
+       . on any page with non-standard security areas
+       . in security roles editor
+*/
+function add_access_extensions()
+{
+       global $path_to_root, $security_areas, $security_sections;
+       
+       // Add extension private access levels
+       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']);
+       }
+}
 ?>
\ No newline at end of file
index 002256124b0b1a4c7a5b1afbbb5b70fc054d0235..f18c1ff6563a7727d4f76f50152806c8bc1a75d0 100644 (file)
@@ -7,7 +7,7 @@
 -- '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 
 */
 
 $installed_extensions = array ();
@@ -15,8 +15,9 @@ $installed_extensions = array ();
 // example
 /*
 $installed_extensions = array (
-       0 => array ('app_file' => 'organizer.php', 'name' => 'organizer', 'title' => 'Organizer', 'folder' => 'organizer'),
-       array ('app_file' => 'payroll.php', 'name' => 'payroll', 'title' => 'Payroll', 'folder' => 'payroll')
-       );
+       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