Added graphic edit/add icons in lists with $editkey.
authorJoe Hunt <joe.hunt.consulting@gmail.com>
Wed, 4 Jan 2012 10:19:40 +0000 (11:19 +0100)
committerJoe Hunt <joe.hunt.consulting@gmail.com>
Wed, 4 Jan 2012 10:19:40 +0000 (11:19 +0100)
includes/session.inc
includes/ui/ui_lists.inc
inventory/manage/items.php
purchasing/manage/suppliers.php
sales/manage/customer_branches.php
sales/manage/customers.php

index fd343ecb5114ce280a4cdf73599406a8233fd5a6..6407e6e0e0a7b69acdb3ab20f2490264388d0a6c 100644 (file)
@@ -162,7 +162,7 @@ function check_page_security($page_security)
        
        if ($msg){
                display_error($msg);
-               end_page();
+               end_page(@$_REQUEST['popup']);
                kill_login();
                exit;
        }
@@ -174,7 +174,7 @@ function check_page_security($page_security)
                echo _("The security settings on your account do not permit you to access this function");
                echo "</b>";
                echo "<br><br><br><br></center>";
-               end_page();
+               end_page(@$_REQUEST['popup']);
                exit;
        }
        if (!$_SESSION['SysPrefs']->db_ok 
index 592b49a0076afb40d534570ff2b3bed8e27b15b4..df6e4b17796f06cdf8ad66816a83e792868984bb 100644 (file)
@@ -417,6 +417,28 @@ function _format_add_curr($row)
                '' : ("&nbsp;-&nbsp;" . $row[2]));
 }
 
+function add_edit_combo($combo_name,$url,$key_param='',$restrict_pages='')
+{
+       global $path_to_root, $page_security;
+
+       // Derive theme path
+       $theme_path = $path_to_root . '/themes/' . user_theme();
+
+       // Check if $url already has other parameters
+       if ($key_param) {
+               $key_param = ((strpos($url,'?')) ? '&' : '?') . $key_param;
+       }
+
+       $return_url = ($key_param) ?  "<a target = '_blank' href='$url${key_param}=' onclick=\"javascript:var combo_id=document.forms[0].$combo_name;openWindow(this.href+combo_id.options[combo_id.selectedIndex].value,this.target); return false;\" tabindex='-1'><img width='16' height='16' border='0' alt='Add/Edit' title='Add/Edit' src='$theme_path/images/".ICON_EDIT."'></a>" : "<a target = '_blank' href='$url${key_param}' onclick=\"javascript:openWindow(this.href,this.target); return false;\" tabindex='-1'><img width='16' height='16' border='0' alt='Add/Edit' title='Add/Edit' src='$theme_path/images/".ICON_EDIT."'></a>";
+
+       // Don't pass edit button code If restrict_pages contains instructions but fails security check
+       if ($restrict_pages && strpos($restrict_pages, $page_security) === false) {
+               return '';
+       }
+
+       return $return_url;
+}
+
 function supplier_list($name, $selected_id=null, $spec_option=false, $submit_on_change=false,
        $all=false, $editkey = false)
 {
@@ -429,7 +451,7 @@ function supplier_list($name, $selected_id=null, $spec_option=false, $submit_on_
        if ($editkey)
                set_editor('supplier', $name, $editkey);
                
-       return combo_input($name, $selected_id, $sql, 'supplier_id', 'supp_name',
+       $ret = combo_input($name, $selected_id, $sql, 'supplier_id', 'supp_name',
        array(
                'format' => '_format_add_curr',
            'order' => array('supp_ref'),
@@ -443,6 +465,12 @@ function supplier_list($name, $selected_id=null, $spec_option=false, $submit_on_
                _('Select supplier'),
                'show_inactive'=>$all
                ));
+       if ($editkey)
+       {
+               global $path_to_root;
+               $ret .= add_edit_combo('supplier_id',"$path_to_root/purchasing/manage/suppliers.php?popup=1",'supplier_id');            
+       }
+       return $ret;
 }
 
 function supplier_list_cells($label, $name, $selected_id=null, $all_option=false, 
@@ -477,7 +505,7 @@ function customer_list($name, $selected_id=null, $spec_option=false, $submit_on_
        if ($editkey)
                set_editor('customer', $name, $editkey);
 
-       return combo_input($name, $selected_id, $sql, 'debtor_no', 'debtor_ref',
+       $ret = combo_input($name, $selected_id, $sql, 'debtor_no', 'debtor_ref',
        array(
            'format' => '_format_add_curr',
            'order' => array('debtor_ref'),
@@ -492,6 +520,12 @@ function customer_list($name, $selected_id=null, $spec_option=false, $submit_on_
                _('Select customer'),
                'show_inactive' => $show_inactive
        ) );
+       if ($editkey)
+       {
+               global $path_to_root;
+               $ret .= add_edit_combo('customer_id',"$path_to_root/sales/manage/customers.php?popup=1", "debtor_no");
+       }       
+       return $ret;
 }
 
 function customer_list_cells($label, $name, $selected_id=null, $all_option=false, 
@@ -508,6 +542,8 @@ function customer_list_cells($label, $name, $selected_id=null, $all_option=false
 function customer_list_row($label, $name, $selected_id=null, $all_option = false, 
        $submit_on_change=false, $show_inactive=false, $editkey = false)
 {
+       global $path_to_root;
+
        echo "<tr><td class='label'>$label</td><td nowrap>";
        echo customer_list($name, $selected_id, $all_option, $submit_on_change,
                $show_inactive, $editkey);
@@ -528,7 +564,7 @@ function customer_branches_list($customer_id, $name, $selected_id=null,
                set_editor('branch', $name, $editkey);
 
        $where = $enabled ? array("disable_trans = 0") : array();
-       return  combo_input($name, $selected_id, $sql, 'branch_code', 'branch_ref',
+       $ret = combo_input($name, $selected_id, $sql, 'branch_code', 'branch_ref',
        array(
                'where' => $where,
                'order' => array('branch_ref'),
@@ -537,6 +573,12 @@ function customer_branches_list($customer_id, $name, $selected_id=null,
                'select_submit'=> $submit_on_change,
                'sel_hint' => _('Select customer branch')
        ) );
+       if ($editkey)
+       {
+               global $path_to_root;
+               $ret .= add_edit_combo('branch_id',"$path_to_root/sales/manage/customer_branches.php?popup=1",'SelectedBranch');
+       }       
+       return $ret;
 }
 //------------------------------------------------------------------------------------------------
 
@@ -718,7 +760,7 @@ function stock_items_list($name, $selected_id=null, $all_option=false,
        if ($editkey)
                set_editor('item', $name, $editkey);
 
-       return combo_input($name, $selected_id, $sql, 'stock_id', 's.description',
+       $ret = combo_input($name, $selected_id, $sql, 'stock_id', 's.description',
        array_merge(
          array(
                'format' => '_format_stock_items',
@@ -732,6 +774,13 @@ function stock_items_list($name, $selected_id=null, $all_option=false,
                'category' => 2,
                'order' => array('c.description','stock_id')
          ), $opts) );
+       if ($editkey)
+       {
+               global $path_to_root;
+               $ret .= add_edit_combo('stock_id',"$path_to_root/inventory/manage/items.php?popup=1",'stock_id');               
+       }
+       return $ret;
+         
 }
 
 function _format_stock_items($row)
index 43495e0fd136d1eb947056e24fb78414323e416e..666486f08b94ddd1295210e20c122d80e8547feb 100644 (file)
@@ -483,5 +483,5 @@ end_form();
 
 //------------------------------------------------------------------------------------
 
-end_page();
+end_page(@$_REQUEST['popup']);
 ?>
index b545115e9c7d8a60ce91c506ae58d45cd386c7d8..edfad13a6d9d3021e8f5d3c29a33b5b30a9e87f7 100644 (file)
@@ -334,6 +334,6 @@ tabbed_content_end();
 hidden('popup', @$_REQUEST['popup']);
 end_form();
 
-end_page();
+end_page(@$_REQUEST['popup']);
 
 ?>
index 5ab27166df15c9213085aa2b1e7653602e6d2edd..e3b1565fba697ddbb21f6c6feab7bcfcc67adfed 100644 (file)
@@ -343,6 +343,6 @@ tabbed_content_end();
 
 end_form();
 
-end_page();
+end_page(@$_REQUEST['popup']);
 
 ?>
index 006d4b90f22f33b0063ee0a35ec94f00ebb574ee..41c642ac760ae5e964c9c0e00157c7491c258ad9 100644 (file)
@@ -370,6 +370,6 @@ tabbed_content_end();
 
 hidden('popup', @$_REQUEST['popup']);
 end_form();
-end_page();
+end_page(@$_REQUEST['popup']);
 
 ?>