|
From: <dai...@us...> - 2014-09-20 02:33:17
|
Revision: 6896
http://sourceforge.net/p/web-erp/reponame/6896
Author: daintree
Date: 2014-09-20 02:33:13 +0000 (Sat, 20 Sep 2014)
Log Message:
-----------
Phil: Move the DB Maintenance/GetConfig/Exchange rates update/audit trail purge inside UserLogin.php to ensure they do no add unecessary overhead to every page
Modified Paths:
--------------
trunk/doc/Change.log
trunk/includes/UserLogin.php
trunk/includes/session.inc
trunk/sql/mysql/upgrade4.11-4.12.sql
Modified: trunk/doc/Change.log
===================================================================
--- trunk/doc/Change.log 2014-09-19 20:25:01 UTC (rev 6895)
+++ trunk/doc/Change.log 2014-09-20 02:33:13 UTC (rev 6896)
@@ -1,5 +1,6 @@
webERP Change Log
+20/9/14 Phil: Move the DB Maintenance/GetConfig/Exchange rates update/audit trail purge inside UserLogin.php to ensure they do no add unecessary overhead to every page
20/9/14 Bob Thomas: StockStatus incorrectly displaying quantity on order extended by conversion units
11/09/14 RChacon: Add ascending class to PaymentMethods.php to have sortable columns.
17/9/14 Phil: Moved the audit log purge to occur if DB_Maintenance is set to run
Modified: trunk/includes/UserLogin.php
===================================================================
--- trunk/includes/UserLogin.php 2014-09-19 20:25:01 UTC (rev 6895)
+++ trunk/includes/UserLogin.php 2014-09-20 02:33:13 UTC (rev 6896)
@@ -144,14 +144,93 @@
$i++;
}
}
- // check if only maintenance users can access webERP
- $sql = "SELECT confvalue FROM config WHERE confname = 'DB_Maintenance'";
- $Maintenance_Result = DB_query($sql, $db);
- if (DB_num_rows($Maintenance_Result)==0){
+
+
+ /*User is logged in so get configuration parameters - save in session*/
+ include($PathPrefix . 'includes/GetConfig.php');
+
+
+ /*If the Code $Version - held in ConnectDB.inc is > than the Database VersionNumber held in config table then do upgrades */
+ if (strcmp($Version,$_SESSION['VersionNumber'])>0 AND (basename($_SERVER['SCRIPT_NAME'])!='UpgradeDatabase.php')) {
+ header('Location: UpgradeDatabase.php');
+ }
+
+ if(isset($_SESSION['DB_Maintenance'])){
+ if ($_SESSION['DB_Maintenance']>0) { //run the DB maintenance script
+ 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);
+ $_SESSION['DB_Maintenance_LastRun'] = Date('Y-m-d');
+
+ /* Audit trail purge only runs if DB_Maintenance is enabled */
+ 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);
+ }
+ }
+ }
+ }
+
+ /*Check to see if currency rates need to be updated */
+ if (isset($_SESSION['UpdateCurrencyRatesDaily'])){
+ if ($_SESSION['UpdateCurrencyRatesDaily']!=0) {
+ /* Only run the update to currency rates if today is after the last update i.e. only runs once a day */
+ if (DateDiff(Date($_SESSION['DefaultDateFormat']),
+ ConvertSQLDate($_SESSION['UpdateCurrencyRatesDaily']),'d')> 0){
+
+ if ($_SESSION['ExchangeRateFeed']=='ECB') {
+ $CurrencyRates = GetECBCurrencyRates(); // gets rates from ECB see includes/MiscFunctions.php
+ /*Loop around the defined currencies and get the rate from ECB */
+ if ($CurrencyRates!=false) {
+ $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);
+ }
+ }
+ }
+ } else {
+ $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='" . google_currency_rate($CurrencyRow[0]) . "'
+ 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);
+ }
+ }
+ }
+
+
+ /* Set the logo if not yet set.
+ * will be done only once per session and each time
+ * we are not in session (i.e. before login)
+ */
+ if (empty($_SESSION['LogoFile'])) {
+ /* find a logo in companies/CompanyDir */
+ if (file_exists($PathPrefix . 'companies/' . $_SESSION['DatabaseName'] . '/logo.png')) {
+ $_SESSION['LogoFile'] = 'companies/' . $_SESSION['DatabaseName'] . '/logo.png';
+ } elseif (file_exists($PathPrefix . 'companies/' . $_SESSION['DatabaseName'] . '/logo.jpg')) {
+ $_SESSION['LogoFile'] = 'companies/' . $_SESSION['DatabaseName'] . '/logo.jpg';
+ }
+ }
+
+
+ if(!isset($_SESSION['DB_Maintenance'])){
return UL_CONFIGERR;
} else {
- $myMaintenanceRow = DB_fetch_row($Maintenance_Result);
- if (($myMaintenanceRow[0] == -1) AND ($UserIsSysAdmin == FALSE)){
+
+ if ($_SESSION['DB_Maintenance']==-1 AND !in_array(15, $_SESSION['AllowedPageSecurityTokens'])){
// the configuration setting has been set to -1 ==> Allow SysAdmin Access Only
// the user is NOT a SysAdmin
return UL_MAINTENANCE;
Modified: trunk/includes/session.inc
===================================================================
--- trunk/includes/session.inc 2014-09-19 20:25:01 UTC (rev 6895)
+++ trunk/includes/session.inc 2014-09-20 02:33:13 UTC (rev 6896)
@@ -132,71 +132,7 @@
}
-/*User is logged in so get configuration parameters - save in session*/
-include($PathPrefix . 'includes/GetConfig.php');
-
-/*If the Code $Version - held in ConnectDB.inc is > than the Database VersionNumber held in config table then do upgrades */
-if (strcmp($Version,$_SESSION['VersionNumber'])>0 AND (basename($_SERVER['SCRIPT_NAME'])!='UpgradeDatabase.php')) {
- header('Location: UpgradeDatabase.php');
-}
-
-if(isset($_SESSION['DB_Maintenance'])){
- if ($_SESSION['DB_Maintenance']>0) { //run the DB maintenance script
- 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);
- $_SESSION['DB_Maintenance_LastRun'] = Date('Y-m-d');
-
- /* Audit trail purge only runs if DB_Maintenance is enabled */
- 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);
- }
- }
- }
-}
-
-/*Check to see if currency rates need to be updated */
-if (isset($_SESSION['UpdateCurrencyRatesDaily'])){
- if ($_SESSION['UpdateCurrencyRatesDaily']!=0) {
- /* Only run the update to currency rates if today is after the last update i.e. only runs once a day */
- if (DateDiff(Date($_SESSION['DefaultDateFormat']),
- ConvertSQLDate($_SESSION['UpdateCurrencyRatesDaily']),'d')> 0){
-
- if ($_SESSION['ExchangeRateFeed']=='ECB') {
- $CurrencyRates = GetECBCurrencyRates(); // gets rates from ECB see includes/MiscFunctions.php
- /*Loop around the defined currencies and get the rate from ECB */
- if ($CurrencyRates!=false) {
- $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);
- }
- }
- }
- } else {
- $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='" . google_currency_rate($CurrencyRow[0]) . "'
- 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);
- }
- }
-}
-
If (isset($_POST['Theme']) AND ($_SESSION['UsersRealName'] == $_POST['RealName'])) {
$_SESSION['Theme'] = $_POST['Theme'];
$Theme = $_POST['Theme'];
@@ -204,34 +140,7 @@
$Theme = $_SESSION['Theme'];
}
-/* Set the logo if not yet set.
- * will be done only once per session and each time
- * we are not in session (i.e. before login)
- */
-if (empty($_SESSION['LogoFile'])) {
- /* find a logo in companies/$CompanyDir
- * (nice side effect of function:
- * variables are local, so we will never
- * cause name clashes)
- */
- function findLogoFile($CompanyDir, $PathPrefix) {
- $result = null;
- $dir = $PathPrefix . 'companies/' . $CompanyDir;
- if (file_exists($dir . '/logo.png')) {
- $result = 'companies/' . $CompanyDir . '/logo.png';
- } elseif (file_exists($dir . '/logo.jpg')) {
- $result = 'companies/' . $CompanyDir . '/logo.jpg';
- }
- return $result;
- }
-
- /* Find a logo in companies/<company of this session> */
- if (!empty($_SESSION['DatabaseName'])) {
- $_SESSION['LogoFile'] = findLogoFile($_SESSION['DatabaseName'], $PathPrefix);
- }
-}
-
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/sql/mysql/upgrade4.11-4.12.sql
===================================================================
--- trunk/sql/mysql/upgrade4.11-4.12.sql 2014-09-19 20:25:01 UTC (rev 6895)
+++ trunk/sql/mysql/upgrade4.11-4.12.sql 2014-09-20 02:33:13 UTC (rev 6896)
@@ -82,6 +82,7 @@
ALTER TABLE `locations` ADD `usedforwo` TINYINT( 4 ) NOT NULL DEFAULT '1' AFTER `internalrequest`;
ALTER TABLE `bankaccounts` ADD `importformat` VARCHAR( 10 ) NOT NULL DEFAULT '';
+ALTER TABLE `audittrail` ADD INDEX ( `transactiondate` );
UPDATE config SET confvalue='4.12' WHERE confname='VersionNumber';
|