From 7f3464c4092c4fa9982fe98be6698050583a7497 Mon Sep 17 00:00:00 2001 From: Paul Thursby Date: Mon, 26 Feb 2018 17:41:20 +0000 Subject: [PATCH] Remove unused $db and $conn parameters from DB_Last_Insert_ID() and (where present) from DB_show_tables(), and DB_show_fields(). Also, remove any unused 'global $db' references across the code base. --- AuditTrail.php | 2 +- BOMs.php | 1 - BOMs_SingleLevel.php | 1 - ConfirmDispatch_Invoice.php | 4 +-- ContractCosting.php | 2 +- CounterReturns.php | 6 ++-- CounterSales.php | 6 ++-- Credit_Invoice.php | 8 ++--- FixedAssetItems.php | 2 +- GLProfit_Loss.php | 2 +- GoodsReceived.php | 2 +- InternalStockRequestFulfill.php | 2 +- InternalStockRequestInquiry.php | 20 ++--------- MailingGroupMaintenance.php | 8 ----- PcClaimExpensesFromTab.php | 2 +- RecurringSalesOrders.php | 2 +- RecurringSalesOrdersProcess.php | 4 +-- ReverseGRN.php | 2 +- SelectCreditItems.php | 6 ++-- SelectOrderItems.php | 1 - SelectQASamples.php | 2 +- StockAdjustments.php | 2 +- StockLocTransferReceive.php | 4 +-- StockTransfers.php | 4 +-- SupplierCredit.php | 2 +- SupplierInvoice.php | 2 +- TaxAuthorities.php | 2 +- TaxCategories.php | 2 +- TaxProvinces.php | 2 +- WorkOrderIssue.php | 2 +- WorkOrderReceive.php | 2 +- Z_AutoCustomerAllocations.php | 1 - Z_ChangeSupplierCode.php | 2 -- Z_ImportFixedAssets.php | 2 +- Z_ImportGLTransactions.php | 2 -- api/api_debtortransactions.php | 4 +-- api/api_salesorders.php | 4 +-- doc/Change.log | 1 + includes/ConnectDB_mysql.inc | 43 ++++++++++-------------- includes/ConnectDB_mysqli.inc | 22 +++++------- includes/ConnectDB_postgres.inc | 16 ++++----- includes/DefineCartClass.php | 12 ------- includes/DefineContractClass.php | 2 -- includes/DefineOfferClass.php | 1 - includes/DefineReceiptClass.php | 1 - includes/DefineSerialItems.php | 4 --- includes/DefineSuppTransClass.php | 6 ---- includes/GetPrice.inc | 1 - includes/PDFPaymentRun_PymtFooter.php | 2 +- includes/SQL_CommonFunctions.inc | 8 +---- index.php | 2 +- reportwriter/FormMaker.php | 6 ++-- reportwriter/ReportMaker.php | 15 ++------- reportwriter/WriteForm.inc | 1 - reportwriter/WriteReport.inc | 2 +- reportwriter/admin/RCFunctions.inc | 36 +++++++------------- reportwriter/admin/ReportCreator.php | 4 +-- reportwriter/install/ReportListForm.php | 2 +- reportwriter/install/ReportListLinks.php | 2 +- 59 files changed, 108 insertions(+), 205 deletions(-) diff --git a/AuditTrail.php b/AuditTrail.php index e416807a4..c3d5613d4 100644 --- a/AuditTrail.php +++ b/AuditTrail.php @@ -29,7 +29,7 @@ } // Get list of tables -$TableResult = DB_show_tables($db); +$TableResult = DB_show_tables(); // Get list of users $UserResult = DB_query("SELECT userid FROM www_users ORDER BY userid"); diff --git a/BOMs.php b/BOMs.php index 7ee5352ba..dc85a1e8b 100644 --- a/BOMs.php +++ b/BOMs.php @@ -11,7 +11,6 @@ function display_children($Parent, $Level, &$BOMTree) { - global $db; global $i; // retrive all children of parent diff --git a/BOMs_SingleLevel.php b/BOMs_SingleLevel.php index e86c1daa7..0e815fd26 100644 --- a/BOMs_SingleLevel.php +++ b/BOMs_SingleLevel.php @@ -11,7 +11,6 @@ function display_children($Parent, $Level, &$BOMTree) { - global $db; global $i; // retrive all children of parent diff --git a/ConfirmDispatch_Invoice.php b/ConfirmDispatch_Invoice.php index 77cd94a65..843537d21 100644 --- a/ConfirmDispatch_Invoice.php +++ b/ConfirmDispatch_Invoice.php @@ -890,7 +890,7 @@ $DbgMsg = _('The following SQL to insert the debtor transaction record was used'); $Result = DB_query($SQL,$ErrMsg,$DbgMsg,true); - $DebtorTransID = DB_Last_Insert_ID($db,'debtortrans','id'); + $DebtorTransID = DB_Last_Insert_ID('debtortrans','id'); /* Insert the tax totals for each tax authority where tax was charged on the invoice */ foreach ($TaxTotals AS $TaxAuthID => $TaxAmount) { @@ -1251,7 +1251,7 @@ $Result = DB_query($SQL,$ErrMsg,$DbgMsg,true); /*Get the ID of the StockMove... */ - $StkMoveNo = DB_Last_Insert_ID($db,'stockmoves','stkmoveno'); + $StkMoveNo = DB_Last_Insert_ID('stockmoves','stkmoveno'); /*Insert the taxes that applied to this line */ foreach ($OrderLine->Taxes as $Tax) { diff --git a/ContractCosting.php b/ContractCosting.php index 26d80dffa..5a6c26213 100644 --- a/ContractCosting.php +++ b/ContractCosting.php @@ -370,7 +370,7 @@ $Result = DB_query($SQL, $ErrMsg, $DbgMsg, true); /*Get the ID of the StockMove... */ - $StkMoveNo = DB_Last_Insert_ID($db,'stockmoves','stkmoveno'); + $StkMoveNo = DB_Last_Insert_ID('stockmoves','stkmoveno'); /* If GLLink_Stock then insert GLTrans to debit the GL Code and credit GRN Suspense account at standard cost*/ if ($_SESSION['CompanyRecord']['gllink_stock']==1 AND ($OtherReqtsBudget+$ContractBOMBudget)!=0){ diff --git a/CounterReturns.php b/CounterReturns.php index ac5e58c17..62e8b22af 100644 --- a/CounterReturns.php +++ b/CounterReturns.php @@ -948,7 +948,7 @@ $DbgMsg = _('The following SQL to insert the debtor transaction record was used'); $Result = DB_query($SQL,$ErrMsg,$DbgMsg,true); - $DebtorTransID = DB_Last_Insert_ID($db,'debtortrans','id'); + $DebtorTransID = DB_Last_Insert_ID('debtortrans','id'); /* Insert the tax totals for each tax authority where tax was charged on the invoice */ foreach ($_SESSION['Items' . $identifier]->TaxTotals AS $TaxAuthID => $TaxAmount) { @@ -1172,7 +1172,7 @@ $Result = DB_query($SQL,$ErrMsg,$DbgMsg,true); /*Get the ID of the StockMove... */ - $StkMoveNo = DB_Last_Insert_ID($db,'stockmoves','stkmoveno'); + $StkMoveNo = DB_Last_Insert_ID('stockmoves','stkmoveno'); /*Insert the taxes that applied to this line */ foreach ($ReturnItemLine->Taxes as $Tax) { @@ -1569,7 +1569,7 @@ functionalexrate, $ErrMsg = _('Cannot insert a receipt transaction against the customer because') ; $result = DB_query($SQL,$ErrMsg,$DbgMsg,true); - $ReceiptDebtorTransID = DB_Last_Insert_ID($db,'debtortrans','id'); + $ReceiptDebtorTransID = DB_Last_Insert_ID('debtortrans','id'); //and finally add the allocation record between receipt and invoice diff --git a/CounterSales.php b/CounterSales.php index 8ff0eac94..d640fc937 100644 --- a/CounterSales.php +++ b/CounterSales.php @@ -1359,7 +1359,7 @@ $DbgMsg = _('The following SQL to insert the debtor transaction record was used'); $Result = DB_query($SQL,$ErrMsg,$DbgMsg,true); - $DebtorTransID = DB_Last_Insert_ID($db,'debtortrans','id'); + $DebtorTransID = DB_Last_Insert_ID('debtortrans','id'); /* Insert the tax totals for each tax authority where tax was charged on the invoice */ foreach ($_SESSION['Items'.$identifier]->TaxTotals AS $TaxAuthID => $TaxAmount) { @@ -1584,7 +1584,7 @@ $Result = DB_query($SQL,$ErrMsg,$DbgMsg,true); /*Get the ID of the StockMove... */ - $StkMoveNo = DB_Last_Insert_ID($db,'stockmoves','stkmoveno'); + $StkMoveNo = DB_Last_Insert_ID('stockmoves','stkmoveno'); /*Insert the taxes that applied to this line */ foreach ($OrderLine->Taxes as $Tax) { @@ -2021,7 +2021,7 @@ functionalexrate, $ErrMsg = _('Cannot insert a receipt transaction against the customer because') ; $result = DB_query($SQL,$ErrMsg,$DbgMsg,true); - $ReceiptDebtorTransID = DB_Last_Insert_ID($db,'debtortrans','id'); + $ReceiptDebtorTransID = DB_Last_Insert_ID('debtortrans','id'); $SQL = "UPDATE debtorsmaster SET lastpaiddate = '" . $DefaultDispatchDate . "', lastpaid='" . filter_number_format($_POST['AmountPaid']) . "' diff --git a/Credit_Invoice.php b/Credit_Invoice.php index 12bfb1b77..729de5742 100644 --- a/Credit_Invoice.php +++ b/Credit_Invoice.php @@ -658,7 +658,7 @@ $DbgMsg = _('The following SQL to insert the customer credit note was used'); $Result = DB_query($SQL,$ErrMsg, $DbgMsg, true); - $CreditTransID = DB_Last_Insert_ID($db,'debtortrans','id'); + $CreditTransID = DB_Last_Insert_ID('debtortrans','id'); /* Insert the tax totals for each tax authority where tax was charged on the invoice */ foreach($TaxTotals AS $TaxAuthID => $TaxAmount) { @@ -958,7 +958,7 @@ $DbgMsg = _('The following SQL to insert the stock movement records was used'); $Result = DB_query($SQL,$ErrMsg,$DbgMsg,true); - $StkMoveNo = DB_Last_Insert_ID($db,'stockmoves','stkmoveno'); + $StkMoveNo = DB_Last_Insert_ID('stockmoves','stkmoveno'); /*Insert the StockSerialMovements and update the StockSerialItems for controlled items*/ //echo "
"; var_dump($CreditLine); echo "
"; if($CreditLine->Controlled ==1) { @@ -1060,7 +1060,7 @@ $DbgMsg = _('The following SQL to insert the stock movement records was used'); $Result = DB_query($SQL,$ErrMsg, $DbgMsg, true); /*Get the ID of the StockMove... */ - $StkMoveNo = DB_Last_Insert_ID($db,'stockmoves','stkmoveno'); + $StkMoveNo = DB_Last_Insert_ID('stockmoves','stkmoveno'); $SQL = "INSERT INTO stockmoves(stockid, type, @@ -1145,7 +1145,7 @@ $Result = DB_query($SQL,$ErrMsg, $DbgMsg, true); /*Get the ID of the StockMove... */ - $StkMoveNo = DB_Last_Insert_ID($db,'stockmoves','stkmoveno'); + $StkMoveNo = DB_Last_Insert_ID('stockmoves','stkmoveno'); } /*Insert the taxes that applied to this line */ diff --git a/FixedAssetItems.php b/FixedAssetItems.php index fb4012293..d35b48191 100644 --- a/FixedAssetItems.php +++ b/FixedAssetItems.php @@ -277,7 +277,7 @@ $result = DB_query($sql, $ErrMsg, $DbgMsg); if (DB_error_no() ==0) { - $NewAssetID = DB_Last_Insert_ID($db,'fixedassets', 'assetid'); + $NewAssetID = DB_Last_Insert_ID('fixedassets', 'assetid'); prnMsg( _('The new asset has been added to the database with an asset code of:') . ' ' . $NewAssetID,'success'); unset($_POST['LongDescription']); unset($_POST['Description']); diff --git a/GLProfit_Loss.php b/GLProfit_Loss.php index 0b61d1ec2..3c83bf6d7 100644 --- a/GLProfit_Loss.php +++ b/GLProfit_Loss.php @@ -93,7 +93,7 @@ $RetResult = DB_data_seek($Periods,0); - while ($myrow=DB_fetch_array($Periods,$db)){ + while ($myrow=DB_fetch_array($Periods)){ if($myrow['periodno']==$DefaultToPeriod){ echo ''; diff --git a/GoodsReceived.php b/GoodsReceived.php index 40193d00d..f1b36f342 100644 --- a/GoodsReceived.php +++ b/GoodsReceived.php @@ -591,7 +591,7 @@ $Result = DB_query($SQL, $ErrMsg, $DbgMsg, true); /*Get the ID of the StockMove... */ - $StkMoveNo = DB_Last_Insert_ID($db,'stockmoves','stkmoveno'); + $StkMoveNo = DB_Last_Insert_ID('stockmoves','stkmoveno'); /* Do the Controlled Item INSERTS HERE */ if ($OrderLine->Controlled ==1){ diff --git a/InternalStockRequestFulfill.php b/InternalStockRequestFulfill.php index f8ad01b40..6cd59f044 100644 --- a/InternalStockRequestFulfill.php +++ b/InternalStockRequestFulfill.php @@ -91,7 +91,7 @@ /*Get the ID of the StockMove... */ - $StkMoveNo = DB_Last_Insert_ID($db,'stockmoves','stkmoveno'); + $StkMoveNo = DB_Last_Insert_ID('stockmoves','stkmoveno'); $SQL="UPDATE stockrequestitems SET qtydelivered=qtydelivered+" . $Quantity . " diff --git a/InternalStockRequestInquiry.php b/InternalStockRequestInquiry.php index 47486e4e7..8935ac23e 100644 --- a/InternalStockRequestInquiry.php +++ b/InternalStockRequestInquiry.php @@ -164,9 +164,7 @@ ' . _('Date To') . ' - - - '; + '; if (!isset($_POST['ShowDetails'])) { $_POST['ShowDetails'] = 1; } @@ -324,8 +322,7 @@ FROM stockrequest INNER JOIN stockrequestitems ON stockrequest.dispatchid=stockrequestitems.dispatchid INNER JOIN departments ON stockrequest.departmentid=departments.departmentid INNER JOIN locations ON locations.loccode=stockrequest.loccode - INNER JOIN stockmaster ON stockrequestitems.stockid=stockmaster.stockid - "; + INNER JOIN stockmaster ON stockrequestitems.stockid=stockmaster.stockid"; } else { $SQL = "SELECT stockrequest.dispatchid, stockrequest.loccode, @@ -338,7 +335,7 @@ narrative, initiator FROM stockrequest INNER JOIN departments ON stockrequest.departmentid=departments.departmentid - INNER JOIN locations ON locations.loccode=stockrequest.loccode "; + INNER JOIN locations ON locations.loccode=stockrequest.loccode"; } //lets add the condition selected by users if (isset($_POST['RequestNo']) AND $_POST['RequestNo'] !== '') { @@ -489,23 +486,12 @@ } else { prnMsg(_('There are no stock request available'),'warn'); } - - - - - - - - - - } include('includes/footer.php'); exit; function GetSearchItems ($SQLConstraint='') { - global $db; if ($_POST['Keywords'] AND $_POST['StockCode']) { echo _('Stock description keywords have been used in preference to the Stock code extract entered'); } diff --git a/MailingGroupMaintenance.php b/MailingGroupMaintenance.php index 3d93f8f35..17eaf5a40 100644 --- a/MailingGroupMaintenance.php +++ b/MailingGroupMaintenance.php @@ -153,15 +153,8 @@ ?> - - - - - - $Value) { if (substr($Index, 0, 5) == 'index') { $Index = $Value; diff --git a/RecurringSalesOrders.php b/RecurringSalesOrders.php index 6ca159d37..20d8a2716 100644 --- a/RecurringSalesOrders.php +++ b/RecurringSalesOrders.php @@ -267,7 +267,7 @@ $DbgMsg = _('The SQL that failed was'); $InsertQryResult = DB_query($HeaderSQL,$ErrMsg,$DbgMsg,true); - $RecurrOrderNo = DB_Last_Insert_ID($db,'recurringsalesorders','recurrorderno'); + $RecurrOrderNo = DB_Last_Insert_ID('recurringsalesorders','recurrorderno'); echo 'xxx'.$RecurrOrderNo; $StartOf_LineItemsSQL = "INSERT INTO recurrsalesorderdetails (recurrorderno, stkcode, diff --git a/RecurringSalesOrdersProcess.php b/RecurringSalesOrdersProcess.php index 3e80bf2ce..20fd69403 100644 --- a/RecurringSalesOrdersProcess.php +++ b/RecurringSalesOrdersProcess.php @@ -367,7 +367,7 @@ $Result = DB_query($SQL,$ErrMsg,$DbgMsg,true); /*Get the ID of the StockMove... */ - $StkMoveNo = DB_Last_Insert_ID($db,'stockmoves','stkmoveno'); + $StkMoveNo = DB_Last_Insert_ID('stockmoves','stkmoveno'); /*Insert the taxes that applied to this line */ foreach ($LineTaxes[$LineCounter] as $Tax) { @@ -683,7 +683,7 @@ $DbgMsg = _('The following SQL to insert the debtor transaction record was used'); $Result = DB_query($SQL,$ErrMsg,$DbgMsg,true); - $DebtorTransID = DB_Last_Insert_ID($db,'debtortrans','id'); + $DebtorTransID = DB_Last_Insert_ID('debtortrans','id'); $SQL = "INSERT INTO debtortranstaxes (debtortransid, diff --git a/ReverseGRN.php b/ReverseGRN.php index c152192c4..88d783f32 100644 --- a/ReverseGRN.php +++ b/ReverseGRN.php @@ -257,7 +257,7 @@ $DbgMsg = _('The following SQL to insert the stock movement records was used'); $Result=DB_query($SQL,$ErrMsg,$DbgMsg,true); - $StkMoveNo = DB_Last_Insert_ID($db,'stockmoves','stkmoveno'); + $StkMoveNo = DB_Last_Insert_ID('stockmoves','stkmoveno'); if ($Controlled==true){ while ($SerialStockMoves = DB_fetch_array($GetStockMoveResult)){ diff --git a/SelectCreditItems.php b/SelectCreditItems.php index 0450ad178..22b6d26a5 100644 --- a/SelectCreditItems.php +++ b/SelectCreditItems.php @@ -1171,7 +1171,7 @@ $Result = DB_query($SQL,$ErrMsg,$DbgMsg,true); - $CreditTransID = DB_Last_Insert_ID($db,'debtortrans','id'); + $CreditTransID = DB_Last_Insert_ID('debtortrans','id'); /* Insert the tax totals for each tax authority where tax was charged on the invoice */ foreach ($TaxTotals AS $TaxAuthID => $TaxAmount) { @@ -1332,7 +1332,7 @@ $Result = DB_query($SQL, $ErrMsg, $DbgMsg, true); /*Get the stockmoveno from above - need to ref StockMoveTaxes and possibly SerialStockMoves */ - $StkMoveNo = DB_Last_Insert_ID($db,'stockmoves','stkmoveno'); + $StkMoveNo = DB_Last_Insert_ID('stockmoves','stkmoveno'); /*Insert the taxes that applied to this line */ foreach ($CreditLine->Taxes as $Tax) { @@ -1613,7 +1613,7 @@ /*Its a write off too still so need to process the serial items written off */ - $StkMoveNo = DB_Last_Insert_ID($db,'stockmoves','stkmoveno'); + $StkMoveNo = DB_Last_Insert_ID('stockmoves','stkmoveno'); foreach($CreditLine->SerialItems as $Item){ /*no need to check StockSerialItems record exists diff --git a/SelectOrderItems.php b/SelectOrderItems.php index 390e678eb..752d28211 100644 --- a/SelectOrderItems.php +++ b/SelectOrderItems.php @@ -1888,7 +1888,6 @@ include('includes/footer.php'); function GetCustBranchDetails($identifier) { - global $db; $sql = "SELECT custbranch.brname, custbranch.branchcode, custbranch.braddress1, diff --git a/SelectQASamples.php b/SelectQASamples.php index 13973462f..6d3fa2da1 100644 --- a/SelectQASamples.php +++ b/SelectQASamples.php @@ -106,7 +106,7 @@ } else { CreateQASample($_POST['ProdSpecKey'],$_POST['LotKey'], $_POST['Identifier'], $_POST['Comments'], $_POST['Cert'], $_POST['DuplicateOK'],$db); - $SelectedSampleID=DB_Last_Insert_ID($db,'qasamples','sampleid'); + $SelectedSampleID=DB_Last_Insert_ID('qasamples','sampleid'); if ($SelectedSampleID > '') { $msg = _('Created New Sample'); prnMsg($msg , 'success'); diff --git a/StockAdjustments.php b/StockAdjustments.php index 87538f975..ffd889c6b 100644 --- a/StockAdjustments.php +++ b/StockAdjustments.php @@ -240,7 +240,7 @@ $Result = DB_query($SQL, $ErrMsg, $DbgMsg, true); /*Get the ID of the StockMove... */ - $StkMoveNo = DB_Last_Insert_ID($db,'stockmoves','stkmoveno'); + $StkMoveNo = DB_Last_Insert_ID('stockmoves','stkmoveno'); /*Insert the StockSerialMovements and update the StockSerialItems for controlled items*/ diff --git a/StockLocTransferReceive.php b/StockLocTransferReceive.php index ef518c6ac..3326d569f 100644 --- a/StockLocTransferReceive.php +++ b/StockLocTransferReceive.php @@ -113,7 +113,7 @@ $Result = DB_query($SQL,$ErrMsg, $DbgMsg, true); /*Get the ID of the StockMove... */ - $StkMoveNo = DB_Last_Insert_ID($db,'stockmoves','stkmoveno'); + $StkMoveNo = DB_Last_Insert_ID('stockmoves','stkmoveno'); /*Insert the StockSerialMovements and update the StockSerialItems for controlled items*/ @@ -267,7 +267,7 @@ /*Get the ID of the StockMove... */ - $StkMoveNo = DB_Last_Insert_ID($db,'stockmoves','stkmoveno'); + $StkMoveNo = DB_Last_Insert_ID('stockmoves','stkmoveno'); /*Insert the StockSerialMovements and update the StockSerialItems for controlled items*/ if($TrfLine->Controlled ==1) { diff --git a/StockTransfers.php b/StockTransfers.php index 57be11177..46198dd89 100644 --- a/StockTransfers.php +++ b/StockTransfers.php @@ -283,7 +283,7 @@ $Result = DB_query($SQL,$ErrMsg,$DbgMsg,true); /*Get the ID of the StockMove... */ - $StkMoveNo = DB_Last_Insert_ID($db,'stockmoves','stkmoveno'); + $StkMoveNo = DB_Last_Insert_ID('stockmoves','stkmoveno'); /*Insert the StockSerialMovements and update the StockSerialItems for controlled items*/ @@ -437,7 +437,7 @@ $Result = DB_query($SQL,$ErrMsg,$DbgMsg,true); /*Get the ID of the StockMove... */ - $StkMoveNo = DB_Last_Insert_ID($db,'stockmoves','stkmoveno'); + $StkMoveNo = DB_Last_Insert_ID('stockmoves','stkmoveno'); /*Insert the StockSerialMovements and update the StockSerialItems for controlled items*/ diff --git a/SupplierCredit.php b/SupplierCredit.php index d4affb981..860857fe8 100644 --- a/SupplierCredit.php +++ b/SupplierCredit.php @@ -1145,7 +1145,7 @@ $DbgMsg = _('The following SQL to insert the supplier credit note was used'); $Result = DB_query($SQL, $ErrMsg, $DbgMsg, True); - $SuppTransID = DB_Last_Insert_ID($db,'supptrans','id'); + $SuppTransID = DB_Last_Insert_ID('supptrans','id'); /* Insert the tax totals for each tax authority where tax was charged on the invoice */ foreach ($_SESSION['SuppTrans']->Taxes AS $TaxTotals) { diff --git a/SupplierInvoice.php b/SupplierInvoice.php index fb1ca6846..487c906bd 100644 --- a/SupplierInvoice.php +++ b/SupplierInvoice.php @@ -1518,7 +1518,7 @@ $ErrMsg = _('CRITICAL ERROR') . '! ' . _('NOTE DOWN THIS ERROR AND SEEK ASSISTANCE') . ': ' . _('The supplier invoice transaction could not be added to the database because'); $DbgMsg = _('The following SQL to insert the supplier invoice was used'); $Result = DB_query($SQL, $ErrMsg, $DbgMsg, True); - $SuppTransID = DB_Last_Insert_ID($db,'supptrans','id'); + $SuppTransID = DB_Last_Insert_ID('supptrans','id'); /* Insert the tax totals for each tax authority where tax was charged on the invoice */ foreach ($_SESSION['SuppTrans']->Taxes AS $TaxTotals) { diff --git a/TaxAuthorities.php b/TaxAuthorities.php index 3d6311046..3c60f4926 100644 --- a/TaxAuthorities.php +++ b/TaxAuthorities.php @@ -74,7 +74,7 @@ $msg = _('The new tax authority record has been added to the database'); - $NewTaxID = DB_Last_Insert_ID($db,'taxauthorities','taxid'); + $NewTaxID = DB_Last_Insert_ID('taxauthorities','taxid'); $sql = "INSERT INTO taxauthrates ( taxauthority, diff --git a/TaxCategories.php b/TaxCategories.php index 88bbecc83..c0d6efb88 100644 --- a/TaxCategories.php +++ b/TaxCategories.php @@ -88,7 +88,7 @@ $ErrMsg = _('The new tax category could not be added'); $result = DB_query($sql,$ErrMsg,true); - $LastTaxCatID = DB_Last_Insert_ID($db, 'taxcategories','taxcatid'); + $LastTaxCatID = DB_Last_Insert_ID('taxcategories','taxcatid'); $sql = "INSERT INTO taxauthrates (taxauthority, dispatchtaxprovince, diff --git a/TaxProvinces.php b/TaxProvinces.php index f4397d79a..bae658fdd 100644 --- a/TaxProvinces.php +++ b/TaxProvinces.php @@ -90,7 +90,7 @@ $ErrMsg = _('Could not add tax province'); $result = DB_query($sql, $ErrMsg); - $TaxProvinceID = DB_Last_Insert_ID($db, 'taxprovinces', 'taxprovinceid'); + $TaxProvinceID = DB_Last_Insert_ID('taxprovinces', 'taxprovinceid'); $sql = "INSERT INTO taxauthrates (taxauthority, dispatchtaxprovince, taxcatid) SELECT taxauthorities.taxid, '" . $TaxProvinceID . "', taxcategories.taxcatid FROM taxauthorities CROSS JOIN taxcategories"; diff --git a/WorkOrderIssue.php b/WorkOrderIssue.php index 722fef6fa..e074fe991 100644 --- a/WorkOrderIssue.php +++ b/WorkOrderIssue.php @@ -233,7 +233,7 @@ $Result = DB_query($SQL, $ErrMsg, $DbgMsg, true); /*Get the ID of the StockMove... */ - $StkMoveNo = DB_Last_Insert_ID($db,'stockmoves','stkmoveno'); + $StkMoveNo = DB_Last_Insert_ID('stockmoves','stkmoveno'); /* Do the Controlled Item INSERTS HERE */ if ($IssueItemRow['controlled'] ==1){ diff --git a/WorkOrderReceive.php b/WorkOrderReceive.php index 7ea35d3b7..e6daea39c 100644 --- a/WorkOrderReceive.php +++ b/WorkOrderReceive.php @@ -492,7 +492,7 @@ $Result = DB_query($SQL, $ErrMsg, $DbgMsg, true); /*Get the ID of the StockMove... */ - $StkMoveNo = DB_Last_Insert_ID($db,'stockmoves','stkmoveno'); + $StkMoveNo = DB_Last_Insert_ID('stockmoves','stkmoveno'); /* Do the Controlled Item INSERTS HERE */ if ($WORow['controlled'] ==1){ diff --git a/Z_AutoCustomerAllocations.php b/Z_AutoCustomerAllocations.php index 0e3a1f698..6bbca9d32 100755 --- a/Z_AutoCustomerAllocations.php +++ b/Z_AutoCustomerAllocations.php @@ -116,7 +116,6 @@ include('includes/footer.php'); function ProcessAllocation() { - global $db; if ($InputError==0) { // //========[ START TRANSACTION ]=========== diff --git a/Z_ChangeSupplierCode.php b/Z_ChangeSupplierCode.php index 4754406f9..e978ad341 100644 --- a/Z_ChangeSupplierCode.php +++ b/Z_ChangeSupplierCode.php @@ -37,7 +37,6 @@ function ProcessSupplier($oldCode, $newCode) { - global $db; $table_key= array ( 'grns' => 'supplierid', 'offers'=>'supplierid', @@ -106,7 +105,6 @@ function ProcessSupplier($oldCode, $newCode) { } function checkSupplierExist($codeSupplier) { - global $db; $result=DB_query("SELECT supplierid FROM suppliers WHERE supplierid='" . $codeSupplier . "'"); if (DB_num_rows($result)==0) return false; return true; diff --git a/Z_ImportFixedAssets.php b/Z_ImportFixedAssets.php index 15879103a..53cb49512 100644 --- a/Z_ImportFixedAssets.php +++ b/Z_ImportFixedAssets.php @@ -219,7 +219,7 @@ if (DB_error_no() ==0) { //the insert of the new code worked so bang in the fixedassettrans records too - $AssetID = DB_Last_Insert_ID($db, 'fixedassets','assetid'); + $AssetID = DB_Last_Insert_ID('fixedassets','assetid'); $sql = "INSERT INTO fixedassettrans ( assetid, transtype, transno, diff --git a/Z_ImportGLTransactions.php b/Z_ImportGLTransactions.php index b9edab0ce..bdc5e1f5a 100644 --- a/Z_ImportGLTransactions.php +++ b/Z_ImportGLTransactions.php @@ -266,8 +266,6 @@ functionalexrate, include('includes/footer.php'); function IsBankAccount($Account) { - global $db; - $sql ="SELECT accountcode FROM bankaccounts WHERE accountcode='" . $Account . "'"; $result = DB_query($sql); if (DB_num_rows($result)==0) { diff --git a/api/api_debtortransactions.php b/api/api_debtortransactions.php index ccb0c2aaa..b51c630f0 100644 --- a/api/api_debtortransactions.php +++ b/api/api_debtortransactions.php @@ -803,7 +803,7 @@ function CreateCreditNote($Header,$LineDetails, $User, $Password) { $Result = api_DB_query($SQL,'','',true); } /*Get the ID of the StockMove... */ - $StkMoveNo = DB_Last_Insert_ID($db,'stockmoves','stkmoveno'); + $StkMoveNo = DB_Last_Insert_ID('stockmoves','stkmoveno'); /*Insert the taxes that applied to this line */ foreach ($LineTaxes[$LineCounter] as $Tax) { @@ -1088,7 +1088,7 @@ function CreateCreditNote($Header,$LineDetails, $User, $Password) { $Result = api_DB_query($SQL,'','',true); - $DebtorTransID = DB_Last_Insert_ID($db,'debtortrans','id'); + $DebtorTransID = DB_Last_Insert_ID('debtortrans','id'); /*for each Tax - need to insert into debtortranstaxes */ foreach ($TaxTotals AS $TaxAuthID => $Tax) { diff --git a/api/api_salesorders.php b/api/api_salesorders.php index 8a169a37e..f95da95d9 100644 --- a/api/api_salesorders.php +++ b/api/api_salesorders.php @@ -970,7 +970,7 @@ function InvoiceSalesOrder($OrderNo, $User, $Password) { $Result = api_DB_query($SQL,'','',true); } /*Get the ID of the StockMove... */ - $StkMoveNo = DB_Last_Insert_ID($db,'stockmoves','stkmoveno'); + $StkMoveNo = DB_Last_Insert_ID('stockmoves','stkmoveno'); /*Insert the taxes that applied to this line */ foreach ($LineTaxes[$LineCounter] as $Tax) { @@ -1263,7 +1263,7 @@ function InvoiceSalesOrder($OrderNo, $User, $Password) { $Result = api_DB_query($SQL,'','',true); - $DebtorTransID = DB_Last_Insert_ID($db,'debtortrans','id'); + $DebtorTransID = DB_Last_Insert_ID('debtortrans','id'); /*for each Tax - need to insert into debtortranstaxes */ foreach ($TaxTotals AS $TaxAuthID => $Tax) { diff --git a/doc/Change.log b/doc/Change.log index b14018115..52749451e 100644 --- a/doc/Change.log +++ b/doc/Change.log @@ -1,5 +1,6 @@ webERP Change Log +2/4/18 PaulT: Remove unused $db and $conn parameters from DB_Last_Insert_ID() and (where present) from DB_show_tables(), and DB_show_fields(). Also, remove any unused 'global $db' references across the code base. 2/4/18 Paul Becker (PaulT commit): MRPPlannedPurchaseOrders.php: Add capability to review planned purchase orders and add a new link to convert to a new PO. (Reported in forums: http://www.weberp.org/forum/showthread.php?tid=8061) 2/4/18 Paul Becker (PaulT commit): PrintCustOrder.php, PrintCustOrder_generic.php, PDFOrderPageHeader_generic.inc: Add units, volume, and weight info, date/signature lines, sales order details narrative, plus other minor PDF formatting. (Reported in forums: http://www.weberp.org/forum/showthread.php?tid=8048) 2/4/18 PaulT: Remove unused $db parameter from DB_fetch_array() and DB_Query() functions. Also, rename several DB_Query names to match function definition name: DB_query. diff --git a/includes/ConnectDB_mysql.inc b/includes/ConnectDB_mysql.inc index 0d833ab39..31b77c3d0 100644 --- a/includes/ConnectDB_mysql.inc +++ b/includes/ConnectDB_mysql.inc @@ -4,20 +4,17 @@ define('LIKE', 'LIKE'); -global $db;// Make sure it IS global, regardless of our context if(!isset($mysqlport)) { $mysqlport = 3306; } +global $db;// Make sure it IS global, regardless of our context + $db = mysql_connect($host . ':' . $mysqlport, $DBUser, $DBPassword); //this statement sets the charset to be used for sending data to and from the db server //if not set, both mysql server and mysql client/library may assume otherwise mysql_set_charset('utf8', $db); -//$varabc = mysql_client_encoding($db); -//printf("client encoding is %s\n", $varabc); - - if(!$db) { echo '
' . _('The configuration in the file config.php for the database user name and password do not provide the information required to connect to the database server'); session_unset(); @@ -29,7 +26,6 @@ if(!$db) { /* Update to allow RecurringSalesOrdersProcess.php to run via cron */ if(isset($DatabaseName)) { - if(! mysql_select_db($_SESSION['DatabaseName'],$db)) { echo '
' . _('The company name entered does not correspond to a database on the database server specified in the config.php configuration file. Try logging in with a different company name'); echo '
' . _('Back to login page') . ''; @@ -45,8 +41,6 @@ if(isset($DatabaseName)) { } } -require_once($PathPrefix . 'includes/MiscFunctions.php'); - //DB wrapper functions to change only once for whole application function DB_query($SQL, $ErrorMessage='', $DebugMessage= '', $Transaction=false, $TrapErrors=true) { @@ -74,7 +68,7 @@ function DB_query($SQL, $ErrorMessage='', $DebugMessage= '', $Transaction=false, $SQL = 'rollback'; $Result = DB_query($SQL); if(DB_error_no() != 0) { - prnMsg(_('Error Rolling Back Transaction'), '', _('Database Rollback Error') ); + prnMsg(_('Error Rolling Back Transaction'), 'error', _('Database Rollback Error') ); } } if($TrapErrors) { @@ -103,7 +97,6 @@ function DB_query($SQL, $ErrorMessage='', $DebugMessage= '', $Transaction=false, } return $result; - } function DB_fetch_row($ResultIndex) { @@ -147,7 +140,7 @@ function DB_error_msg() { return mysql_error($db); } -function DB_Last_Insert_ID(&$Conn='',$table, $fieldname) { +function DB_Last_Insert_ID($table, $fieldname) { // return mysql_insert_id($db); if (isset($_SESSION['LastInsertId'])) { $Last_Insert_ID = $_SESSION['LastInsertId']; @@ -162,58 +155,58 @@ function DB_escape_string($String) { return mysql_real_escape_string($String); } -function DB_show_tables(&$Conn='') { +function DB_show_tables() { $Result = DB_query('SHOW TABLES'); return $Result; } -function DB_show_fields($TableName, &$Conn='') { +function DB_show_fields($TableName) { $Result = DB_query("DESCRIBE $TableName"); return $Result; } function interval( $val, $Inter ) { - global $DBType; - return "\n".'interval ' . $val . ' '. $Inter."\n"; + return "\n".'interval ' . $val . ' ' . $Inter . "\n"; } function DB_Maintenance() { prnMsg(_('The system has just run the regular database administration and optimisation routine.'),'info'); - $TablesResult = DB_query('SHOW TABLES'); + + $TablesResult = DB_show_tables(); while ($myrow = DB_fetch_row($TablesResult)) { $Result = DB_query('OPTIMIZE TABLE ' . $myrow[0]); } $Result = DB_query("UPDATE config - SET confvalue='" . Date('Y-m-d') . "' - WHERE confname='DB_Maintenance_LastRun'"); + SET confvalue = CURRENT_DATE + WHERE confname = 'DB_Maintenance_LastRun'"); } function DB_Txn_Begin() { global $db; - mysql_query("SET autocommit=0",$db); - mysql_query("START TRANSACTION",$db); + mysql_query('SET autocommit=0',$db); + mysql_query('START TRANSACTION',$db); } function DB_Txn_Commit() { global $db; - mysql_query("COMMIT",$db); - mysql_query("SET autocommit=1",$db); + mysql_query('COMMIT',$db); + mysql_query('SET autocommit=1',$db); } function DB_Txn_Rollback() { global $db; - mysql_query("ROLLBACK",$db); + mysql_query('ROLLBACK',$db); } function DB_IgnoreForeignKeys() { global $db; - mysql_query("SET FOREIGN_KEY_CHECKS=0",$db); + mysql_query('SET FOREIGN_KEY_CHECKS=0',$db); } function DB_ReinstateForeignKeys() { global $db; - mysql_query("SET FOREIGN_KEY_CHECKS=1",$db); + mysql_query('SET FOREIGN_KEY_CHECKS=1',$db); } ?> diff --git a/includes/ConnectDB_mysqli.inc b/includes/ConnectDB_mysqli.inc index eb5949cc6..2d26b4f6f 100644 --- a/includes/ConnectDB_mysqli.inc +++ b/includes/ConnectDB_mysqli.inc @@ -15,8 +15,6 @@ if(!isset($mysqlport)) { global $db; // Make sure it IS global, regardless of our context $db = mysqli_connect($host , $DBUser, $DBPassword,$_SESSION['DatabaseName'], $mysqlport); -//$result=DB_query('SET sql_mode = ANSI'); - //this statement sets the charset to be used for sending data to and from the db server //if not set, both mysqli server and mysqli client/library may assume otherwise @@ -48,7 +46,6 @@ if(isset($DatabaseName)) { if(!mysqli_select_db($db,$_SESSION['DatabaseName'])) { echo '
' . _('The company name entered does not correspond to a database on the database server specified in the config.php configuration file. Try logging in with a different company name'); echo '
' . _('Back to login page') . ''; - unset ($_SESSION['DatabaseName']); exit; } @@ -63,7 +60,6 @@ function DB_query($SQL, $ErrorMessage='', $DebugMessage= '', $Transaction=false, global $db; $result = mysqli_query($db, $SQL); - $_SESSION['LastInsertId'] = mysqli_insert_id($db); if($DebugMessage == '') { @@ -111,6 +107,7 @@ function DB_query($SQL, $ErrorMessage='', $DebugMessage= '', $Transaction=false, } } } + return $result; } @@ -146,7 +143,6 @@ function DB_num_rows($ResultIndex) { function DB_affected_rows($ResultIndex) { global $db; return mysqli_affected_rows($db); - } function DB_error_no() { @@ -159,7 +155,7 @@ function DB_error_msg() { return mysqli_error($db); } -function DB_Last_Insert_ID($Conn='', $Table, $FieldName) { +function DB_Last_Insert_ID($Table, $FieldName) { // return mysqli_insert_id($Conn); if(isset($_SESSION['LastInsertId'])) { $Last_Insert_ID = $_SESSION['LastInsertId']; @@ -175,33 +171,31 @@ function DB_escape_string($String) { return mysqli_real_escape_string($db, $String); } -function DB_show_tables($Conn='') { - global $db; +function DB_show_tables() { $Result = DB_query('SHOW TABLES'); return $Result; } -function DB_show_fields($TableName, $Conn='') { +function DB_show_fields($TableName) { $Result = DB_query("DESCRIBE $TableName"); return $Result; } -function interval($val, $Inter) { - global $dbtype; +function interval( $val, $Inter ) { return "\n".'interval ' . $val . ' ' . $Inter . "\n"; } function DB_Maintenance() { prnMsg(_('The system has just run the regular database administration and optimisation routine.'),'info'); - $TablesResult = DB_query("SHOW TABLES"); + $TablesResult = DB_show_tables(); while ($myrow = DB_fetch_row($TablesResult)) { $Result = DB_query('OPTIMIZE TABLE ' . $myrow[0]); } $Result = DB_query("UPDATE config - SET confvalue='" . Date('Y-m-d') . "' - WHERE confname='DB_Maintenance_LastRun'"); + SET confvalue = CURRENT_DATE + WHERE confname = 'DB_Maintenance_LastRun'"); } function DB_Txn_Begin() { diff --git a/includes/ConnectDB_postgres.inc b/includes/ConnectDB_postgres.inc index 0c1c979b1..2e0795390 100644 --- a/includes/ConnectDB_postgres.inc +++ b/includes/ConnectDB_postgres.inc @@ -48,7 +48,7 @@ function DB_query ($SQL, if($DebugMessage == '') { $DebugMessage = _('The SQL that failed was:'); } - //if(DB_error_no($Conn) != 0) { + if( !$result AND $TrapErrors) { if($TrapErrors) { require_once($PathPrefix . 'includes/header.php'); @@ -60,7 +60,7 @@ function DB_query ($SQL, if($Transaction) { $SQL = 'rollback'; $Result = DB_query($SQL); - if(DB_error_no($Conn) !=0) { + if(DB_error_no() !=0) { prnMsg('
' . _('Error Rolling Back Transaction!!'), '', _('DB DEBUG:') ); } } @@ -109,10 +109,11 @@ function DB_error_no() { } function DB_error_msg() { + global $db; return pg_last_error($db); } -function DB_Last_Insert_ID(&$Conn, $table, $fieldname) { +function DB_Last_Insert_ID($table, $fieldname) { $tempres = DB_query ("SELECT currval('".$table."_".$fieldname."_seq') FROM ".$table); $Res = pg_fetch_result( $tempres, 0, 0 ); DB_free_result($tempres); @@ -124,14 +125,13 @@ function DB_escape_string($String) { } function INTERVAL( $val, $Inter ) { - global $dbtype; return "\n(CAST( (" . $val . ") as text ) || ' ". $Inter ."')::interval\n"; } -function DB_show_tables(&$Conn) { +function DB_show_tables() { $Result =DB_query("SELECT table_name FROM information_schema.tables WHERE table_schema = 'public'"); return $Result; } -function DB_show_fields($TableName,&$Conn) { +function DB_show_fields($TableName) { $Result = DB_query("SELECT table_name FROM information_schema.tables WHERE table_schema='public' AND table_name='" . $TableName . "'"); if(DB_num_rows($Result)==1) { $Result = DB_query("SELECT column_name FROM information_schema.columns WHERE table_name ='$TableName'"); @@ -145,8 +145,8 @@ function DB_Maintenance() { $Result = DB_query('VACUUM ANALYZE'); $Result = DB_query("UPDATE config - SET confvalue='" . Date('Y-m-d') . "' - WHERE confname='DB_Maintenance_LastRun'"); + SET confvalue = CURRENT_DATE + WHERE confname = 'DB_Maintenance_LastRun'"); } ?> diff --git a/includes/DefineCartClass.php b/includes/DefineCartClass.php index 971be8eb2..f4c3e8924 100644 --- a/includes/DefineCartClass.php +++ b/includes/DefineCartClass.php @@ -155,7 +155,6 @@ function add_to_cart($StockID, being retrieved from the DB - dont want to add them again - would return errors anyway */ - global $db; $sql = "INSERT INTO salesorderdetails (orderlineno, orderno, stkcode, @@ -203,7 +202,6 @@ function update_cart_item( $UpdateLineNumber, $this->LineItems[$UpdateLineNumber]->POLine = $POLine; $this->LineItems[$UpdateLineNumber]->GPPercent = $GPPercent; if ($UpdateDB=='Yes'){ - global $db; $result = DB_query("UPDATE salesorderdetails SET quantity=" . $Qty . ", unitprice=" . $Price . ", discountpercent=" . $Disc . ", @@ -223,7 +221,6 @@ function remove_from_cart($LineNumber, $UpdateDB='No', $identifier=0){ return; } if ($UpdateDB=='Yes'){ - global $db; if ($this->Some_Already_Delivered($LineNumber)==0){ /* nothing has been delivered, delete it. */ $result = DB_query("DELETE FROM salesorderdetails @@ -295,9 +292,6 @@ function AllDummyLineItems(){ } function GetExistingTaxes($LineNumber, $stkmoveno){ - - global $db; - /*Gets the Taxes and rates applicable to this line from the TaxGroup of the branch and TaxCategory of the item and the taxprovince of the dispatch location */ @@ -328,9 +322,6 @@ function GetExistingTaxes($LineNumber, $stkmoveno){ } //end method GetExistingTaxes function GetTaxes($LineNumber){ - - global $db; - /*Gets the Taxes and rates applicable to this line from the TaxGroup of the branch and TaxCategory of the item and the taxprovince of the dispatch location */ @@ -369,9 +360,6 @@ function GetTaxes($LineNumber){ } //end method GetTaxes function GetFreightTaxes () { - - global $db; - /*Gets the Taxes and rates applicable to the freight based on the tax group of the branch combined with the tax category for this particular freight and SESSION['FreightTaxCategory'] the taxprovince of the dispatch location */ diff --git a/includes/DefineContractClass.php b/includes/DefineContractClass.php index b13e6fffa..f6ba1a7df 100644 --- a/includes/DefineContractClass.php +++ b/includes/DefineContractClass.php @@ -65,7 +65,6 @@ function Add_To_ContractBOM($StockID, } function Remove_ContractComponent($ContractComponent_ID){ - global $db; $result = DB_query("DELETE FROM contractbom WHERE contractref='" . $this->ContractRef . "' AND stockid='" . $this->ContractBOM[$ContractComponent_ID]->StockID . "'"); @@ -89,7 +88,6 @@ function Add_To_ContractRequirements($Requirement, } function Remove_ContractRequirement($ContractRequirementID){ - global $db; $result = DB_query("DELETE FROM contractreqts WHERE contractreqid='" . $this->ContractReqts[$ContractRequirementID]->ContractReqID . "'"); unset($this->ContractReqts[$ContractRequirementID]); } diff --git a/includes/DefineOfferClass.php b/includes/DefineOfferClass.php index 233ddbad2..91cb45692 100644 --- a/includes/DefineOfferClass.php +++ b/includes/DefineOfferClass.php @@ -19,7 +19,6 @@ function __construct($Supplier){ /*Constructor function initialises a new purchase offer object */ - global $db; $this->LineItems = array(); $this->total=0; $this->LinesOnOffer=0; diff --git a/includes/DefineReceiptClass.php b/includes/DefineReceiptClass.php index b5aa2e26d..0010cd25f 100644 --- a/includes/DefineReceiptClass.php +++ b/includes/DefineReceiptClass.php @@ -63,7 +63,6 @@ function remove_receipt_item($RcptID){ var $TagName; function __construct ($Amt, $Cust, $Disc, $Narr, $id, $GLCode, $PayeeBankDetail, $CustomerName, $Tag){ - global $db; /* Constructor function to add a new Receipt object with passed params */ $this->Amount =$Amt; $this->Customer = $Cust; diff --git a/includes/DefineSerialItems.php b/includes/DefineSerialItems.php index f1c9f4320..0a73eec87 100644 --- a/includes/DefineSerialItems.php +++ b/includes/DefineSerialItems.php @@ -2,8 +2,6 @@ /* $Id$*/ function ValidBundleRef ($StockID, $LocCode, $BundleRef){ - global $db; - $SQL = "SELECT quantity FROM stockserialitems WHERE stockid='" . $StockID . "' @@ -18,8 +16,6 @@ function ValidBundleRef ($StockID, $LocCode, $BundleRef){ } } function GetExpiryDate ($StockID, $LocCode, $BundleRef){ - global $db; - $SQL = "SELECT expirationdate FROM stockserialitems WHERE stockid = '" . $StockID . "' diff --git a/includes/DefineSuppTransClass.php b/includes/DefineSuppTransClass.php index b0fe49a07..748775a94 100644 --- a/includes/DefineSuppTransClass.php +++ b/includes/DefineSuppTransClass.php @@ -53,9 +53,6 @@ function SuppTrans() { } function GetTaxes () { - - global $db; - /*Gets the Taxes and rates applicable to the tax group of the supplier and SESSION['DefaultTaxCategory'] and the taxprovince of the location that the user is setup to use*/ @@ -471,8 +468,6 @@ function Modify ($PODetailItem, Var $TagName; function __construct($Counter, $GLCode, $GLActName, $Amount, $Narrative, $Tag=0, $TagName=''){ - - global $db; /* Constructor function to add a new GLCodes object with passed params */ $this->Counter = $Counter; $this->GLCode = $GLCode; @@ -523,7 +518,6 @@ function Shipment ($Counter, $ShiptRef, $Amount){ Var $Amount; function __construct($Counter, $AssetID, $Amount){ - global $db; $this->Counter = $Counter; $this->AssetID = $AssetID; $this->Amount = $Amount; diff --git a/includes/GetPrice.inc b/includes/GetPrice.inc index f2807bb81..e9bd1b13b 100644 --- a/includes/GetPrice.inc +++ b/includes/GetPrice.inc @@ -1,7 +1,6 @@ '.$FieldListings['displaydesc'].''; // add the description // retrieve the dropdown based on the params field (dropdown type) diff --git a/reportwriter/ReportMaker.php b/reportwriter/ReportMaker.php index c6a90bd3f..3bb32ca9d 100644 --- a/reportwriter/ReportMaker.php +++ b/reportwriter/ReportMaker.php @@ -176,8 +176,6 @@ // Begin functions function GetReports($Default) { - - global $db; $DropDownString = ''; if ($Default) { $Def=1; @@ -219,7 +217,6 @@ function build_dropdown_list($arraylist) { } function FetchReportDetails($ReportID) { - global $db; $sql= "SELECT * FROM ".DBReports." WHERE id = '".$ReportID."'"; $Result=DB_query($sql,'','',false,true); $myrow=DB_fetch_assoc($Result); @@ -239,7 +236,6 @@ function FetchReportDetails($ReportID) { } function RetrieveFields($ReportID, $EntryType) { - global $db; $FieldListings = array(); $sql= "SELECT * FROM ".DBRptFields." WHERE reportid = '".$ReportID."' AND entrytype = '".$EntryType."' @@ -255,7 +251,6 @@ function ChangeSequence($ReportID, $SeqNum, $EntryType, $UpDown) { - global $db; // find the id of the row to move $sql = "SELECT id FROM ".DBRptFields." WHERE reportid = '".$ReportID."' @@ -282,7 +277,7 @@ function ChangeSequence($ReportID, } function BuildCriteria($FieldListings) { - global $db, $CritChoices; + global $CritChoices; $SeqNum = $FieldListings['seqnum']; $CriteriaString = ''.$FieldListings['displaydesc'].''; // add the description // retrieve the dropdown based on the params field (dropdown type) @@ -336,7 +331,6 @@ function BuildFieldList($FieldListings) { } function ReadPostData($ReportID, $Prefs) { - global $db; // check for page setup form entry to look at check boxes and save as new defaults, return if (isset($_POST['PageForm'])) { $success = SavePrefs($ReportID); @@ -407,7 +401,6 @@ function ReadPostData($ReportID, $Prefs) { } function SaveFilters($ReportID, $EntryType, $Params) { - global $db; $sql = "UPDATE ".DBRptFields." SET params='".$Params."' WHERE reportid ='".$ReportID."' AND entrytype='".$EntryType."'"; $Result=DB_query($sql,'','',false,true); return true; @@ -415,7 +408,6 @@ function SaveFilters($ReportID, $EntryType, $Params) { function SaveDefSettings($ReportID, $EntryType, $SeqNum) { // This function sets all the params for a given entrytype to 0 and sets just the new default seqnum to 1 - global $db; $sql = "UPDATE ".DBRptFields." SET params='0' WHERE reportid='".$ReportID."' AND entrytype='".$EntryType."';"; $Result=DB_query($sql,'','',false,true); $sql = "UPDATE ".DBRptFields." SET params='1' @@ -425,7 +417,6 @@ function SaveDefSettings($ReportID, $EntryType, $SeqNum) { } function SavePrefs($ReportID) { - global $db; // the checkboxes to false if not checked if (!isset($_POST['CoyNameShow'])) $_POST['CoyNameShow'] = '0'; if (!isset($_POST['Title1Show'])) $_POST['Title1Show'] = '0'; @@ -492,7 +483,7 @@ function SavePrefs($ReportID) { } function SaveNewReport($ReportID, $AllowOverwrite) { - global $db, $Prefs; + global $Prefs; // input error check reportname, blank duplicate, bad characters, etc. // Delete any special characters from ReportName if ($_POST['ReportName']=='') { // no report name was entered, error and reload form @@ -538,7 +529,7 @@ function SaveNewReport($ReportID, $AllowOverwrite) { $sql = "INSERT INTO ".DBReports." SELECT * FROM ".DBReports." WHERE id=0;"; $Result=DB_query($sql,'','',false,true); // Fetch the id entered - $ReportID = DB_Last_Insert_ID($db,'reports','id'); + $ReportID = DB_Last_Insert_ID('reports','id'); // Restore original report ID from 0 $sql = "UPDATE ".DBReports." SET id='".$OrigID."' WHERE id=0;"; $Result=DB_query($sql,'','',false,true); diff --git a/reportwriter/WriteForm.inc b/reportwriter/WriteForm.inc index 6b126269c..ba9ed04ee 100644 --- a/reportwriter/WriteForm.inc +++ b/reportwriter/WriteForm.inc @@ -299,7 +299,6 @@ class PDF extends PDF_Language { } // end class function BuildPDF($ReportID, $Prefs) { - global $db; global $FieldListings, $FieldValues; // first fetch all the fields we need to display $FieldListings = ''; diff --git a/reportwriter/WriteReport.inc b/reportwriter/WriteReport.inc index 39ab46424..5f733fdfa 100644 --- a/reportwriter/WriteReport.inc +++ b/reportwriter/WriteReport.inc @@ -460,7 +460,7 @@ function BuildSQL($Prefs) { } function BuildDataArray($ReportID, $sql, $Prefs) { - global $db, $Heading, $Seq; + global $Heading, $Seq; // first see if we have data $Result=DB_query($sql,'','',false,true); if (DB_num_rows($Result)==0) return false; // No data so bail now diff --git a/reportwriter/admin/RCFunctions.inc b/reportwriter/admin/RCFunctions.inc index e2aca3ef0..a6e997cd6 100644 --- a/reportwriter/admin/RCFunctions.inc +++ b/reportwriter/admin/RCFunctions.inc @@ -52,7 +52,7 @@ function PrepStep($StepNum) { } function RetrieveReports() { - global $db, $ReportGroups, $FormGroups; + global $ReportGroups, $FormGroups; $OutputString = ''; foreach ($ReportGroups as $key=>$GName) { @@ -95,7 +95,7 @@ function RetrieveReports() { } function RetrieveFields($EntryType) { - global $db, $ReportID; + global $ReportID; $FieldListings['fields'] = ''; $sql= "SELECT * FROM ".DBRptFields." WHERE reportid = ".$ReportID." AND entrytype = '".$EntryType."' @@ -118,7 +118,7 @@ function RetrieveFields($EntryType) { } function UpdatePageFields($ReportID) { - global $db, $Type; + global $Type; // For both reports and forms start sql string $sql = "UPDATE ".DBReports." SET papersize = '".$_POST['PaperSize']."', @@ -188,7 +188,7 @@ function UpdatePageFields($ReportID) { } function UpdateCritFields($ReportID, $DateString) { - global $db, $Type; + global $Type; $sql = "UPDATE ".DBRptFields." SET reportid = '".$ReportID."', entrytype = 'dateselect', @@ -222,7 +222,6 @@ function UpdateCritFields($ReportID, $DateString) { } function UpdateDBFields($ReportID) { - global $db; // Test inputs to see if they are valid $strTable = DB_escape_string($_POST['Table1']); if ($_POST['Table2']) $strTable .= ' INNER JOIN '.DB_escape_string($_POST['Table2']).' ON '.DB_escape_string($_POST['Table2Criteria']); @@ -258,7 +257,7 @@ function UpdateDBFields($ReportID) { } function UpdateSequence($EntryType) { - global $db, $ReportID, $Type; + global $ReportID, $Type; if (!isset($_POST['Visible'])) $_POST['Visible'] = '0'; if (!isset($_POST['ColumnBreak'])) $_POST['ColumnBreak'] = '0'; if (!isset($_POST['Params'])) $Params = '0'; else $Params = $_POST['Params']; @@ -275,7 +274,7 @@ function UpdateSequence($EntryType) { } function ChangeSequence($SeqNum, $EntryType, $UpDown) { - global $db, $ReportID; + global $ReportID; // find the id of the row to move $sql = "SELECT id FROM ".DBRptFields." WHERE reportid = ".$ReportID." AND entrytype = '".$EntryType."' AND seqnum = ".$SeqNum.";"; @@ -294,7 +293,7 @@ function ChangeSequence($SeqNum, $EntryType, $UpDown) { function InsertSequence($SeqNum, $EntryType) { // This function creates a hole in the sequencing to allow inserting new data - global $db, $ReportID, $Type; + global $ReportID, $Type; if (!$SeqNum) $SeqNum = 999; // set sequence to max if not entered // read the sequence numbers for the given EntryType $sql = "SELECT id FROM ".DBRptFields." @@ -330,7 +329,7 @@ function InsertSequence($SeqNum, $EntryType) { function DeleteSequence($SeqNum, $EntryType) { // This function removes a sequence field and fills the sequence hole left behind - global $db, $ReportID; + global $ReportID; // delete the sequence number from the list $sql = "DELETE FROM ".DBRptFields." WHERE reportid = ".$ReportID." AND entrytype = '".$EntryType."' AND seqnum = ".$SeqNum.";"; @@ -424,7 +423,7 @@ function ModFormTblEntry(&$Params) { } function ValidateField($ReportID, $FieldName, $Description) { - global $db, $Type; + global $Type; // This function checks the fieldname and field reference and validates that it is good. // first check if a form (fieldname is not provided unless it's the form page break field) if ($Type=='frm' AND $Description<>'TestField') { // then check for non-zero description unless a fieldname is present @@ -514,7 +513,6 @@ function ReadImages($Default) { } function ImportImage() { - global $db; if ($_POST['ImgChoice']=='Select') { // then a locally stored image was chosen, return with image name $Rtn['result'] = 'success'; $Rtn['message'] = $_POST['ImgFileName'].RPT_IMP_ERMSG9; @@ -550,7 +548,6 @@ function ImportImage() { } function ExportReport($ReportID) { - global $db; $crlf = chr(10); $CSVOutput = '/* Report Builder Export Tool */'.$crlf; $CSVOutput .= 'version:1.0'.$crlf; @@ -612,7 +609,6 @@ function ExportReport($ReportID) { } function ImportReport($RptName) { - global $db; if ($_POST['RptFileName']<>'') { // then a locally stored report was chosen $arrSQL = file(DefRptPath.$_POST['RptFileName']); } else { // check for an uploaded file @@ -669,7 +665,7 @@ function ImportReport($RptName) { return $Rtn; } // fetch the id of the row inserted - $ReportID = DB_Last_Insert_ID($db,DBReports,'id'); + $ReportID = DB_Last_Insert_ID(DBReports,'id'); // update the translated report name and title fields into the newly imported report $sql = "UPDATE ".DBReports." SET reportname = '".$RptName."', @@ -690,7 +686,7 @@ function ImportReport($RptName) { $FldIndex = mb_substr($sql,9,mb_strpos($sql,':')-9); $sql="INSERT INTO ".DBRptFields." SET ".mb_substr($sql,mb_strpos($sql,':')+1); $Result=DB_query($sql,'','',false,true); - $FieldID = DB_Last_Insert_ID($db,DBRptFields, 'id'); + $FieldID = DB_Last_Insert_ID(DBRptFields, 'id'); if ($FieldID<>0) { // A field was successfully written update the report id if (isset($Language[$FldIndex])) $DispSQL = "displaydesc='".$Language[$FldIndex]."', "; else $DispSQL = ''; @@ -706,14 +702,13 @@ function ImportReport($RptName) { } function CreateTableList($ReportID,$Table) { - global $db; $sql = "SELECT table".$Table." FROM ".DBReports." WHERE id='".$ReportID."'"; $Result=DB_query($sql,'','',false,true); $myrow = DB_fetch_row($Result); $TableList = ''; - $Result=DB_show_tables($db); + $Result=DB_show_tables(); while ($mytable=DB_fetch_row($Result)) { $tablename = strtolower($mytable[0]); @@ -724,7 +719,6 @@ function CreateTableList($ReportID,$Table) { } // CreateTableList function CreateLinkList($ReportID,$Table) { - global $db; $sql = "SELECT table1, table2, table3, table4, table5, table6 FROM ".DBReports." WHERE id='".$ReportID."'"; $Result=DB_query($sql,'','',false,true); @@ -733,7 +727,6 @@ function CreateLinkList($ReportID,$Table) { /* Get list of link tables from foreign keys */ for ($i = 0; $i < $Table; $i++) { - $comments = ''; $sql = "SELECT table1, table2 FROM reportlinks WHERE table1 = '" . $myrow[$i] . "'"; $Result=DB_query($sql,'','',false,true); while($mytable=DB_fetch_row($Result)) { @@ -760,7 +753,6 @@ function CreateLinkList($ReportID,$Table) { } function CreateLinkEqList($ReportID,$Table) { - global $db; $sql = "SELECT table1, table2, table2criteria, table3, table3criteria, @@ -774,7 +766,6 @@ function CreateLinkEqList($ReportID,$Table) { /* Get list of foreign key constraints */ for ($i = 0; $i < $Table; $i++) { - $comments = ''; $sql = "SELECT table1, table2, equation FROM reportlinks WHERE table1 = '" . $myrow[$i] . "'"; $Result=DB_query($sql,'','',false,true); while($mytable=DB_fetch_row($Result)) { @@ -801,7 +792,6 @@ function CreateLinkEqList($ReportID,$Table) { } // CreateLinkEqList function CreateFieldList($ReportID,$FName,$Type) { - global $db; if ($Type=='Company') { // then pull from the company information table $myrow[]=CompanyDataBase; } else { // pull from user selected tables for this report @@ -814,7 +804,7 @@ function CreateFieldList($ReportID,$FName,$Type) { for ($i = 0; $i < 6; $i++) { if ($myrow[$i]) { - $Result = DB_show_fields($myrow[$i],$db); + $Result = DB_show_fields($myrow[$i]); while ($mytable=DB_fetch_row($Result)) { $fieldname = strtolower($myrow[$i]) . "." . strtolower($mytable[0]); if ($FName == $fieldname){ diff --git a/reportwriter/admin/ReportCreator.php b/reportwriter/admin/ReportCreator.php index faaac7c0a..06bdb712e 100644 --- a/reportwriter/admin/ReportCreator.php +++ b/reportwriter/admin/ReportCreator.php @@ -146,7 +146,7 @@ $sql = "INSERT INTO ".DBReports." (reportname, reporttype, groupname, defaultreport) VALUES ('".addslashes($_POST['ReportName'])."', '".$Type."', '".$GroupName."', '1')"; $Result=DB_query($sql,'','',false,true); - $ReportID = DB_Last_Insert_ID($db,DBReports,'id'); + $ReportID = DB_Last_Insert_ID(DBReports,'id'); // Set some default report information: date display default choices to 'ALL' if ($Type<>'frm') { // set the truncate long descriptions default $sql = "INSERT INTO ".DBRptFields." (reportid, entrytype, params, displaydesc) @@ -168,7 +168,7 @@ $sql = "INSERT INTO ".DBReports." SELECT * FROM ".DBReports." WHERE id = 0;"; $Result=DB_query($sql,'','',false,true); // Fetch the id entered - $ReportID = DB_Last_Insert_ID($db,DBReports,'id'); + $ReportID = DB_Last_Insert_ID(DBReports,'id'); // Restore original report ID from 0 $sql = "UPDATE ".DBReports." SET id=".$OrigID." WHERE id=0;"; $Result=DB_query($sql,'','',false,true); diff --git a/reportwriter/install/ReportListForm.php b/reportwriter/install/ReportListForm.php index cc6c8c7e6..329f1e9bf 100644 --- a/reportwriter/install/ReportListForm.php +++ b/reportwriter/install/ReportListForm.php @@ -10,7 +10,7 @@ Revision 1.0 - 2005-11-03 - By D. Premo - Initial Release */ function GetReports($GroupID) { - global $db, $RootPath; + global $RootPath; $Title= array(_('Custom Reports'), _('Default Reports')); $RptForm = '
'; echo ''; diff --git a/reportwriter/install/ReportListLinks.php b/reportwriter/install/ReportListLinks.php index b78e03b58..aaf9e45b0 100644 --- a/reportwriter/install/ReportListLinks.php +++ b/reportwriter/install/ReportListLinks.php @@ -10,7 +10,7 @@ Revision 1.0 - 2005-11-03 - By D. Premo - Initial Release */ function GetRptLinks($GroupID) { - global $db, $RootPath; + global $RootPath; $Title= array(_('Custom Reports'), _('Standard Reports')); $RptLinks = ''; for ($Def=1; $Def>=0; $Def--) {