From: <lin...@us...> - 2010-02-19 09:46:24
|
Revision: 3352 http://web-erp.svn.sourceforge.net/web-erp/?rev=3352&view=rev Author: lindsayh Date: 2010-02-19 09:46:15 +0000 (Fri, 19 Feb 2010) Log Message: ----------- Added severl 'global $db' entries to included files as the API doesn't necessarily include them in the global context. As a result, sales order entry via the API works for both original and new API styles. Including putting the correct date into the records! Modified Paths: -------------- trunk/api/api_login.php trunk/api/api_session.inc trunk/api/api_xml-rpc.php trunk/doc/Change.log.html trunk/includes/ConnectDB_mysql.inc trunk/includes/ConnectDB_mysqli.inc trunk/includes/ConnectDB_postgres.inc trunk/includes/GetConfig.php trunk/includes/MiscFunctions.php Modified: trunk/api/api_login.php =================================================================== --- trunk/api/api_login.php 2010-02-18 06:09:20 UTC (rev 3351) +++ trunk/api/api_login.php 2010-02-19 09:46:15 UTC (rev 3352) @@ -29,6 +29,7 @@ switch ($rc) { case UL_OK: $RetCode[0] = 0; // All is well + DoSetup(); // Additional setting up break; case UL_NOTVALID: case UL_BLOCKED: @@ -92,4 +93,61 @@ return $retmsg; } + + +/* + * Some initialisation cannot be done until the user is logged in. This + * function should be called when a successful login occurs. + */ + +function DoSetup() +{ + global $PathPrefix; + if (isset($_SESSION['db']) AND $_SESSION['db'] != '' ) + include($PathPrefix . 'includes/GetConfig.php'); + + $db = $_SESSION['db']; // Used a bit in the following. + if(isset($_SESSION['DB_Maintenance'])){ + if ($_SESSION['DB_Maintenance']!=0) { + if (DateDiff(Date($_SESSION['DefaultDateFormat']), + ConvertSQLDate($_SESSION['DB_Maintenance_LastRun']) + ,'d') > $_SESSION['DB_Maintenance']){ + + /*Do the DB maintenance routing for the DB_type selected */ + DB_Maintenance($db); + //purge the audit trail if necessary + if (isset($_SESSION['MonthsAuditTrail'])){ + $sql = "DELETE FROM audittrail + WHERE transactiondate <= '" . Date('Y-m-d', mktime(0,0,0, Date('m')-$_SESSION['MonthsAuditTrail'])) . "'"; + $ErrMsg = _('There was a problem deleting expired audit-trail history'); + $result = DB_query($sql,$db); + } + $_SESSION['DB_Maintenance_LastRun'] = Date('Y-m-d'); + } + } + } + + /*Check to see if currency rates need to be updated */ + if (isset($_SESSION['UpdateCurrencyRatesDaily'])){ + if ($_SESSION['UpdateCurrencyRatesDaily']!=0) { + if (DateDiff(Date($_SESSION['DefaultDateFormat']), + ConvertSQLDate($_SESSION['UpdateCurrencyRatesDaily']) + ,'d')> 0){ + + $CurrencyRates = GetECBCurrencyRates(); // gets rates from ECB see includes/MiscFunctions.php + /*Loop around the defined currencies and get the rate from ECB */ + $CurrenciesResult = DB_query('SELECT currabrev FROM currencies',$db); + while ($CurrencyRow = DB_fetch_row($CurrenciesResult)){ + if ($CurrencyRow[0]!=$_SESSION['CompanyRecord']['currencydefault']){ + $UpdateCurrRateResult = DB_query('UPDATE currencies SET + rate=' . GetCurrencyRate ($CurrencyRow[0],$CurrencyRates) . " + WHERE currabrev='" . $CurrencyRow[0] . "'",$db); + } + } + $_SESSION['UpdateCurrencyRatesDaily'] = Date('Y-m-d'); + $UpdateConfigResult = DB_query("UPDATE config SET confvalue = '" . Date('Y-m-d') . "' WHERE confname='UpdateCurrencyRatesDaily'",$db); + } + } + } +} ?> \ No newline at end of file Modified: trunk/api/api_session.inc =================================================================== --- trunk/api/api_session.inc 2010-02-18 06:09:20 UTC (rev 3351) +++ trunk/api/api_session.inc 2010-02-19 09:46:15 UTC (rev 3352) @@ -40,54 +40,6 @@ $_SESSION['AttemptsCounter'] = 0; } -/*User is logged in so get configuration parameters - save in session*/ -if (isset($_SESSION['db']) AND $_SESSION['db'] != '' ) { - include($PathPrefix . 'includes/GetConfig.php'); -} - -if(isset($_SESSION['DB_Maintenance'])){ - if ($_SESSION['DB_Maintenance']!=0) { - if (DateDiff(Date($_SESSION['DefaultDateFormat']), - ConvertSQLDate($_SESSION['DB_Maintenance_LastRun']) - ,'d') > $_SESSION['DB_Maintenance']){ - - /*Do the DB maintenance routing for the DB_type selected */ - DB_Maintenance($db); - //purge the audit trail if necessary - if (isset($_SESSION['MonthsAuditTrail'])){ - $sql = "DELETE FROM audittrail - WHERE transactiondate <= '" . Date('Y-m-d', mktime(0,0,0, Date('m')-$_SESSION['MonthsAuditTrail'])) . "'"; - $ErrMsg = _('There was a problem deleting expired audit-trail history'); - $result = DB_query($sql,$db); - } - $_SESSION['DB_Maintenance_LastRun'] = Date('Y-m-d'); - } - } -} - -/*Check to see if currency rates need to be updated */ -if (isset($_SESSION['UpdateCurrencyRatesDaily'])){ - if ($_SESSION['UpdateCurrencyRatesDaily']!=0) { - if (DateDiff(Date($_SESSION['DefaultDateFormat']), - ConvertSQLDate($_SESSION['UpdateCurrencyRatesDaily']) - ,'d')> 0){ - - $CurrencyRates = GetECBCurrencyRates(); // gets rates from ECB see includes/MiscFunctions.php - /*Loop around the defined currencies and get the rate from ECB */ - $CurrenciesResult = DB_query('SELECT currabrev FROM currencies',$db); - while ($CurrencyRow = DB_fetch_row($CurrenciesResult)){ - if ($CurrencyRow[0]!=$_SESSION['CompanyRecord']['currencydefault']){ - $UpdateCurrRateResult = DB_query('UPDATE currencies SET - rate=' . GetCurrencyRate ($CurrencyRow[0],$CurrencyRates) . " - WHERE currabrev='" . $CurrencyRow[0] . "'",$db); - } - } - $_SESSION['UpdateCurrencyRatesDaily'] = Date('Y-m-d'); - $UpdateConfigResult = DB_query("UPDATE config SET confvalue = '" . Date('Y-m-d') . "' WHERE confname='UpdateCurrencyRatesDaily'",$db); - } - } -} -// include('../includes/GetConfig.php'); if ($_SESSION['HTTPS_Only']==1){ if ($_SERVER['HTTPS']!='on'){ prnMsg(_('webERP is configured to allow only secure socket connections. Pages must be called with https://') . ' .....','error'); Modified: trunk/api/api_xml-rpc.php =================================================================== --- trunk/api/api_xml-rpc.php 2010-02-18 06:09:20 UTC (rev 3351) +++ trunk/api/api_xml-rpc.php 2010-02-19 09:46:15 UTC (rev 3352) @@ -222,7 +222,7 @@ function xmlrpc_GetCustomerBranchCodes($xmlrpcmsg){ ob_start('ob_file_callback'); -/*x*/ if ($xmlrpcmsg->getNumParams() == 4) +/*x*/ if ($xmlrpcmsg->getNumParams() == 3) /*x*/ { /*x*/ $rtn = new xmlrpcresp( php_xmlrpc_encode(GetCustomerBranchCodes($xmlrpcmsg->getParam( 0 )->scalarval( ), /*x*/ $xmlrpcmsg->getParam( 1 )->scalarval( ), Modified: trunk/doc/Change.log.html =================================================================== --- trunk/doc/Change.log.html 2010-02-18 06:09:20 UTC (rev 3351) +++ trunk/doc/Change.log.html 2010-02-19 09:46:15 UTC (rev 3352) @@ -1,5 +1,6 @@ <p><font SIZE=4 COLOR=BLUE><b>webERP Change Log</b></font></p> <p></p> +<p>19/02/10 Lindsay: Bug fixing to make SalesOrder entry work for old and new API.</p> <p>18/02/10 Lindsay: API: date formatting in api_salesorders.php; added FormatDateWithTimeForSQL function to includes/DateFunctions.inc <p>16/02/10 Pak Ricard: New Petty cash module</p> <p>16/02/10 Lindsay: Added GetCustomerBranchCodes() to API, and aoi_DB_query function to record DB error message and SQL causing it.</p> Modified: trunk/includes/ConnectDB_mysql.inc =================================================================== --- trunk/includes/ConnectDB_mysql.inc 2010-02-18 06:09:20 UTC (rev 3351) +++ trunk/includes/ConnectDB_mysql.inc 2010-02-19 09:46:15 UTC (rev 3352) @@ -4,6 +4,7 @@ define ('LIKE','LIKE'); +global $db; // Make sure it IS global, regardless of our context $db = mysql_connect($host.':'.$mysqlport , $dbuser, $dbpassword); if ( !$db ) { Modified: trunk/includes/ConnectDB_mysqli.inc =================================================================== --- trunk/includes/ConnectDB_mysqli.inc 2010-02-18 06:09:20 UTC (rev 3351) +++ trunk/includes/ConnectDB_mysqli.inc 2010-02-19 09:46:15 UTC (rev 3352) @@ -9,6 +9,7 @@ define ('LIKE','LIKE'); +global $db; // Make sure it IS global, regardless of our context $db = mysqli_connect($host , $dbuser, $dbpassword,$_SESSION['DatabaseName'], $mysqlport); /* check connection */ Modified: trunk/includes/ConnectDB_postgres.inc =================================================================== --- trunk/includes/ConnectDB_postgres.inc 2010-02-18 06:09:20 UTC (rev 3351) +++ trunk/includes/ConnectDB_postgres.inc 2010-02-19 09:46:15 UTC (rev 3352) @@ -18,6 +18,7 @@ } } +global $db; // Make sure it IS global, regardless of our context $db = pg_connect( $PgConnStr ); if ( !$db ) { Modified: trunk/includes/GetConfig.php =================================================================== --- trunk/includes/GetConfig.php 2010-02-18 06:09:20 UTC (rev 3351) +++ trunk/includes/GetConfig.php 2010-02-19 09:46:15 UTC (rev 3352) @@ -4,6 +4,7 @@ /* $Id$*/ if(isset($ForceConfigReload) and $ForceConfigReload==TRUE OR !isset($_SESSION['CompanyDefaultsLoaded'])) { + global $db; // It is global, we may not be. $sql = 'SELECT confname, confvalue FROM config'; // dont care about the order by $ConfigResult = DB_query($sql,$db); while( $myrow = DB_fetch_row($ConfigResult) ) { Modified: trunk/includes/MiscFunctions.php =================================================================== --- trunk/includes/MiscFunctions.php 2010-02-18 06:09:20 UTC (rev 3351) +++ trunk/includes/MiscFunctions.php 2010-02-19 09:46:15 UTC (rev 3352) @@ -202,4 +202,70 @@ return $myrow['decimalplaces']; } + +// Lindsay debug stuff +function LogBackTrace( $dest = 0 ) { + error_log( "***BEGIN STACK BACKTRACE***", $dest ); + + $stack = debug_backtrace(); + // Leave out our frame and the topmost - huge for xmlrpc! + for( $ii = 1; $ii < count( $stack ) - 3; $ii++ ) + { + $frame = $stack[$ii]; + $msg = "FRAME " . $ii . ": "; + if( isset( $frame['file'] ) ) + $msg .= "; file=" . $frame['file']; + if( isset( $frame['line'] ) ) + $msg .= "; line=" . $frame['line']; + if( isset( $frame['function'] ) ) + $msg .= "; function=" . $frame['function']; + if( isset( $frame['args'] ) ) + { + // Either function args, or included file name(s) + $msg .= ' ('; + foreach( $frame['args'] as $val ) + { + $typ = gettype( $val ); + switch( $typ ) + { + case 'array': + $msg .= '[ '; + foreach( $val as $v2 ) + { + if( gettype( $v2 ) == 'array' ) + { + $msg .= '[ '; + foreach( $v2 as $v3 ) + $msg .= $v3; + $msg .= ' ]'; + } + else + $msg .= $v2 . ', '; + } + + $msg .= ' ]'; + break; + + case 'string': + $msg .= $val . ', '; + break; + + case 'integer': + $msg .= sprintf( "%d, ", $val ); + break; + + default: + $msg .= '<' . gettype( $val ) . '>, '; + break; + } + } + $msg .= ' )'; + } + error_log( $msg, $dest ); + } + + error_log( '++++END STACK BACKTRACE++++', $dest ); + + return; +} ?> \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |