Code cleanup.
authorJanusz Dobrowolski <janusz@frontaccounting.eu>
Mon, 15 Dec 2008 19:28:25 +0000 (19:28 +0000)
committerJanusz Dobrowolski <janusz@frontaccounting.eu>
Mon, 15 Dec 2008 19:28:25 +0000 (19:28 +0000)
purchasing/view/view_po.php
sales/includes/cart_class.inc
sales/includes/sales_ui.inc
sales/includes/ui/sales_credit_ui.inc
sales/includes/ui/sales_order_ui.inc

index 144192df7f1021a43d5a9f40d0308352648c300b..c572cf59809205b66edb20ddc745c3c3fa6c69d8 100644 (file)
@@ -21,11 +21,6 @@ if (!isset($_GET['trans_no']))
 
 display_heading(_("Purchase Order") . " #" . $_GET['trans_no']);
 
-if (isset($_SESSION['Items']))
-{
-       unset ($_SESSION['Items']);
-}
-
 $purchase_order = new purch_order;
 
 read_po($_GET['trans_no'], $purchase_order);
index 96faeb1ca0e765287f20aa95ebae52b0db616d43..eafcd102e45fdea06cac7272f56387edeaebbd5d 100644 (file)
@@ -17,7 +17,7 @@ class cart
        var $trans_type; // invoice, order, delivery note ...
        var $trans_no = array();// array (num1=>ver1,..) or 0 for new
        var $so_type = 0;               // for sales order: simple=0 template=1
-
+       var $cart_id;           // used to detect multi-tab edition conflits
        var $line_items;  //array of objects of class line_details
 
        var $src_docs = array();        // array of arrays(num1=>ver1,...) or 0 for no src
@@ -77,6 +77,7 @@ class cart
                $this->dimension_id = 0;
                $this->dimension2_id = 0;
                $this->read($type, $trans_no, $view );
+               $this->cart_id = uniqid('');
        }
 
        //-------------------------------------------------------------------------
index 64045bb155e78faddc5b1d1c2604bc30a5549cf7..56e4746e60f56caae919492fec9418a4f0000de2 100644 (file)
@@ -27,5 +27,19 @@ function processing_active()
 {
     return (isset($_SESSION['Processing']) && $_SESSION['Processing']==$_SERVER['PHP_SELF']);
 }
+/*
+       Check if the cart was not destroyed during opening the edition page in
+       another browser tab.
+*/
+function check_edit_conflicts($cartname='Items')
+{
+       global $Ajax;
+       
+       if (isset($_POST['cart_id']) && $_POST['cart_id'] != $_SESSION[$cartname]->cart_id) {
+               display_error(_('This edit session has been abandoned by opening sales document in another browser tab. You cannot edit more than one sales document at once.'));
+               $Ajax->activate('_page_body');
+               display_footer_exit();
+       }
+}
 
 ?>
\ No newline at end of file
index 303a7e0fab7a90409ac25c39a9b33f7b6d78a9a8..24f3beb49a7554294da513cffadbfcbe6809675f 100644 (file)
@@ -81,7 +81,7 @@ function display_credit_header(&$order)
 
        if (!isset($_POST['ref']))
                $_POST['ref'] = references::get_next(11);
-       if ($_SESSION['Items']->trans_no==0)
+       if ($order->trans_no==0)
            ref_row(_("Reference").':', 'ref');
        else
            label_row(_("Reference").':', $_POST['ref'] );
@@ -225,7 +225,7 @@ function display_credit_items($title, &$order)
 
     $taxes = $order->get_taxes($_POST['ChargeFreightCost']);
 
-    $tax_total = display_edit_tax_items($taxes, 6, $_SESSION['Items']->tax_included);
+    $tax_total = display_edit_tax_items($taxes, 6, $order->tax_included);
 
     $display_total = price_format(($subtotal + $_POST['ChargeFreightCost'] + $tax_total));
 
@@ -305,7 +305,7 @@ function credit_edit_item_controls(&$order, $rowcounter, $line_no=-1)
 
 //---------------------------------------------------------------------------------
 
-function credit_options_controls()
+function credit_options_controls($credit)
 {
        global $table_style2, $Ajax;
        echo "<br>";
@@ -323,7 +323,7 @@ if (isset($_POST['_CreditType_update']))
 
                /*if the credit note is a return of goods then need to know which location to receive them into */
                if (!isset($_POST['Location']))
-                       $_POST['Location'] = $_SESSION['Items']->Location;
+                       $_POST['Location'] = $credit->Location;
                locations_list_row(_("Items Returned to Location"), 'Location', $_POST['Location']);
        }
        else
index a1122708b8f16c05c1e63f572c600c9253cf83e7..ab81e5f462688d7864db8ba01a2ebb8c2f815ebf 100644 (file)
@@ -307,7 +307,7 @@ function display_order_header(&$order, $editable, $date_text, $display_tax_group
                } // changed branch
        }
 
-       if ($_SESSION['Items']->trans_type!=30) {
+       if ($order->trans_type != 30) {
                ref_cells(_("Reference").':', 'ref', _('Reference number unique for this document type'), null, '');
        }
 
@@ -403,7 +403,7 @@ function display_order_header(&$order, $editable, $date_text, $display_tax_group
        if ($display_tax_group)
        {
            label_row(_("Tax Group:"), $order->tax_group_name);
-           hidden('tax_group_id', $_SESSION['Items']->tax_group_id);
+           hidden('tax_group_id', $order->tax_group_id);
        }
 
        end_outer_table(1); // outer table