oxdb.php

Go to the documentation of this file.
00001 <?php
00002 
00003 
00004 // Including main ADODB include
00005 require_once getShopBasePath() . 'core/adodblite/adodb.inc.php';
00006 
00010 class oxDb extends oxSuperCfg
00011 {
00016     const FETCH_MODE_NUM = ADODB_FETCH_NUM;
00017 
00022     const FETCH_MODE_ASSOC = ADODB_FETCH_ASSOC;
00023 
00029     protected static $_instance = null;
00030 
00036     protected static $_oDB = null;
00037 
00038 
00044     protected static $_aTblDescCache = array();
00045 
00051     public static function getInstance()
00052     {
00053         // disable caching for test modules
00054         if ( defined( 'OXID_PHP_UNIT' ) ) {
00055             self::$_instance = modInstances::getMod( __CLASS__ );
00056         }
00057 
00058         if ( !self::$_instance instanceof oxDb ) {
00059 
00060             //do not use simple oxNew here as it goes to eternal cycle
00061             self::$_instance = oxNew( 'oxdb' );
00062 
00063             if ( defined( 'OXID_PHP_UNIT' ) ) {
00064                 modInstances::addMod( __CLASS__, self::$_instance);
00065             }
00066         }
00067         return self::$_instance;
00068     }
00069 
00075     protected function _getModules()
00076     {
00077         //adding exception handler for SQL errors
00078         $myConfig = $this->getConfig();
00079         $iDebug = $myConfig->getConfigParam( 'iDebug' );
00080 
00081         global $ADODB_EXCEPTION;
00082         $ADODB_EXCEPTION = 'oxAdoDbException';
00083         include_once getShopBasePath() . 'core/adodblite/adodb-exceptions.inc.php';
00084 
00085         $sModules = '';
00086         if (  $iDebug == 2 || $iDebug == 3 || $iDebug == 4 || $iDebug == 7  ) {
00087             $sModules = 'perfmon';
00088         }
00089 
00090         // log admin changes ?
00091         if ( $myConfig->isAdmin() && $myConfig->getConfigParam( 'blLogChangesInAdmin' ) ) {
00092             $sModules .= ( $sModules ? ':' : '' ) . 'oxadminlog';
00093         }
00094 
00095         return $sModules;
00096     }
00097 
00105     protected function _setUp( $oDb )
00106     {
00107         $myConfig = $this->getConfig();
00108         $iDebug = $myConfig->getConfigParam( 'iDebug' );
00109         if ( $iDebug == 2 || $iDebug == 3 || $iDebug == 4  || $iDebug == 7 ) {
00110             try {
00111                 $oDb->execute( 'truncate table adodb_logsql' );
00112             } catch ( ADODB_Exception $e ) {
00113                 // nothing
00114             }
00115             if ( method_exists( $oDb, "logSQL" ) ) {
00116                 $oDb->logSQL( true );
00117             }
00118         }
00119 
00120         $oDb->cacheSecs = 60 * 10; // 10 minute caching
00121         $oDb->execute( 'SET @@session.sql_mode = ""' );
00122 
00123         if ( $myConfig->isUtf() ) {
00124             $oDb->execute( 'SET NAMES "utf8"' );
00125             $oDb->execute( 'SET CHARACTER SET utf8' );
00126             $oDb->execute( 'SET CHARACTER_SET_CONNECTION = utf8' );
00127             $oDb->execute( 'SET CHARACTER_SET_DATABASE = utf8' );
00128             $oDb->execute( 'SET character_set_results = utf8' );
00129             $oDb->execute( 'SET character_set_server = utf8' );
00130         } elseif ( ( $sConn = $myConfig->getConfigParam('sDefaultDatabaseConnection') ) != '' ) {
00131             $oDb->execute( 'SET NAMES "' . $sConn . '"' );
00132         }
00133     }
00134 
00144     protected function _sendMail( $sEmail, $sSubject, $sBody )
00145     {
00146         include_once getShopBasePath() . 'core/phpmailer/class.phpmailer.php';
00147         $oMailer = new phpmailer();
00148         $oMailer->isMail();
00149 
00150         $oMailer->From = $sEmail;
00151         $oMailer->AddAddress( $sEmail );
00152         $oMailer->Subject = $sSubject;
00153         $oMailer->Body = $sBody;
00154         return $oMailer->send();
00155     }
00156 
00164     protected function _notifyConnectionErrors( $oDb )
00165     {
00166         $myConfig = $this->getConfig();
00167         // notifying shop owner about connection problems
00168         if ( ( $sAdminEmail = $myConfig->getConfigParam( 'sAdminEmail' ) ) ) {
00169             $sFailedShop = isset( $_REQUEST['shp'] ) ? addslashes( $_REQUEST['shp'] ) : 'Base shop';
00170 
00171             $sDate = date( 'l dS of F Y h:i:s A');
00172             $sScript  = $_SERVER['SCRIPT_NAME'] . '?' . $_SERVER['QUERY_STRING'];
00173             $sReferer = $_SERVER['HTTP_REFERER'];
00174 
00175             //sending a message to admin
00176             $sWarningSubject = 'Offline warning!';
00177             $sWarningBody = "
00178                 Database error in OXID eShop:
00179                 Date: {$sDate}
00180                 Shop: {$sFailedShop}
00181 
00182                 mysql error: " . $oDb->errorMsg()."
00183                 mysql error no: " . $oDb->errorNo()."
00184 
00185                 Script: {$sScript}
00186                 Referer: {$sReferer}";
00187 
00188             $this->_sendMail( $sAdminEmail, $sWarningSubject, $sWarningBody );
00189         }
00190 
00191         //only exception to default construction method
00192         $oEx = new oxConnectionException();
00193         $oEx->setMessage( 'EXCEPTION_CONNECTION_NODB' );
00194         $oEx->setConnectionError( $myConfig->getConfigParam( 'dbUser' ) . 's' . getShopBasePath() . $oDb->errorMsg() );
00195         throw $oEx;
00196     }
00197 
00206     protected function _onConnectionError( $oDb )
00207     {
00208         $sVerPrefix = '';
00209             $sVerPrefix = '_ce';
00210 
00211         $sConfig = join( '', file( getShopBasePath().'config.inc.php' ) );
00212         if ( strpos( $sConfig, '<dbHost'.$sVerPrefix.'>' ) !== false &&
00213              strpos( $sConfig, '<dbName'.$sVerPrefix.'>' ) !== false ) {
00214             // pop to setup as there is something wrong
00215             oxUtils::getInstance()->redirect( "setup/index.php", true, 302 );
00216         } else {
00217             // notifying about connection problems
00218             $this->_notifyConnectionErrors( $oDb );
00219         }
00220     }
00221 
00222 
00230     protected function _getDbInstance( $iInstType = false )
00231     {
00232         $oConfig = $this->getConfig();
00233 
00234         $sHost = $oConfig->getConfigParam( "dbHost" );
00235         $sUser = $oConfig->getConfigParam( "dbUser" );
00236         $sPwd  = $oConfig->getConfigParam( "dbPwd" );
00237         $sName = $oConfig->getConfigParam( "dbName" );
00238         $sType = $oConfig->getConfigParam( "dbType" );
00239 
00240         $oDb = ADONewConnection( $sType, $this->_getModules() );
00241 
00242 
00243             if ( !$oDb->connect( $sHost, $sUser, $sPwd, $sName ) ) {
00244                 $this->_onConnectionError( $oDb );
00245             }
00246 
00247         $this->_setUp( $oDb );
00248 
00249         return $oDb;
00250     }
00251 
00252 
00262     public static function getDb( $iFetchMode = oxDb::FETCH_MODE_NUM )
00263     {
00264         //Added for 0003480 bug; needed as backward compatibility; @deprecated in 4.6 since 2012-01-15; must be removed;
00265         if ( $iFetchMode === true ) {
00266             $iFetchMode = oxDb::FETCH_MODE_ASSOC;
00267         } elseif ( $iFetchMode === false ) {
00268             $iFetchMode = oxDb::FETCH_MODE_NUM;
00269         }
00270 
00271         if ( defined( 'OXID_PHP_UNIT' ) ) {
00272             if ( isset( modDB::$unitMOD ) && is_object( modDB::$unitMOD ) ) {
00273                 return modDB::$unitMOD;
00274             }
00275         }
00276 
00277         if ( self::$_oDB === null ) {
00278 
00279             $oInst = self::getInstance();
00280             $myConfig = $oInst->getConfig();
00281 
00282              global  $ADODB_SESSION_TBL,
00283                     $ADODB_SESSION_CONNECT,
00284                     $ADODB_SESSION_DRIVER,
00285                     $ADODB_SESSION_USER,
00286                     $ADODB_SESSION_PWD,
00287                     $ADODB_SESSION_DB,
00288                     $ADODB_SESS_LIFE,
00289                     $ADODB_SESS_DEBUG;
00290 
00291              // session related parameters. don't change.
00292 
00293             //Tomas
00294             //the default setting is 3000 * 60, but actually changing this will give no effect as now redefinition of this constant
00295             //appears after OXID custom settings are loaded and $ADODB_SESS_LIFE depends on user settings.
00296             //You can find the redefinition of ADODB_SESS_LIFE @ oxconfig.php:: line ~ 390.
00297             $ADODB_SESS_LIFE       = 3000 * 60;
00298             $ADODB_SESSION_TBL     = "oxsessions";
00299             $ADODB_SESSION_DRIVER  = $myConfig->getConfigParam( 'dbType' );
00300             $ADODB_SESSION_USER    = $myConfig->getConfigParam( 'dbUser' );
00301             $ADODB_SESSION_PWD     = $myConfig->getConfigParam( 'dbPwd' );
00302             $ADODB_SESSION_DB      = $myConfig->getConfigParam( 'dbName' );
00303             $ADODB_SESSION_CONNECT = $myConfig->getConfigParam( 'dbHost' );
00304             $ADODB_SESS_DEBUG      = false;
00305 
00306             $oDb = oxNew( 'oxLegacyDb' );
00307             $oDb->setConnection( $oInst->_getDbInstance() );
00308 
00309             self::$_oDB = $oDb;
00310         }
00311 
00312         self::$_oDB->setFetchMode( $iFetchMode );
00313 
00314         return self::$_oDB;
00315     }
00316 
00326     public function getMultiLangFieldName( $sField )
00327     {
00328         return $sField . oxLang::getInstance()->getLanguageTag();
00329     }
00330 
00341     public function isQuoteNeeded( $sFieldtype)
00342     {
00343         $aTypesWoQuotes = array('int', 'decimal', 'float', 'tinyint', 'smallint', 'mediumint', 'bigint', 'double');
00344         return !in_array( $sFieldtype, $aTypesWoQuotes);
00345     }
00346 
00354     public function quoteArray( $aStrArray )
00355     {
00356         $oDb = self::getDb();
00357 
00358         foreach ( $aStrArray as $sKey => $sString ) {
00359             $aStrArray[$sKey] = $oDb->quote( $sString );
00360         }
00361         return $aStrArray;
00362     }
00363 
00369     public function resetTblDescCache()
00370     {
00371         self::$_aTblDescCache = array();
00372     }
00373 
00381     public function getTableDescription( $sTableName )
00382     {
00383         // simple cache
00384         if ( isset( self::$_aTblDescCache[$sTableName] ) ) {
00385             return self::$_aTblDescCache[$sTableName];
00386         }
00387 
00388             $aFields = self::getDb()->MetaColumns( $sTableName );
00389 
00390         self::$_aTblDescCache[$sTableName] = $aFields;
00391 
00392         return $aFields;
00393     }
00394 
00404     public function convertDBDateTime( $oObject, $blToTimeStamp = false, $blOnlyDate = false )
00405     {
00406         $sDate = $oObject->value;
00407 
00408         // defining time format
00409         $sLocalDateFormat = $this->_defineAndCheckDefaultDateValues( $blToTimeStamp );
00410         $sLocalTimeFormat = $this->_defineAndCheckDefaultTimeValues( $blToTimeStamp );
00411 
00412         // default date/time patterns
00413         $aDefDatePatterns = $this->_defaultDatePattern();
00414 
00415         // regexps to validate input
00416         $aDatePatterns = $this->_regexp2ValidateDateInput();
00417         $aTimePatterns = $this->_regexp2ValidateTimeInput();
00418 
00419         // date/time formatting rules
00420         $aDFormats  = $this->_defineDateFormattingRules();
00421         $aTFormats  = $this->_defineTimeFormattingRules();
00422 
00423         // empty date field value ? setting default value
00424         if ( !$sDate) {
00425             $this->_setDefaultDateTimeValue($oObject, $sLocalDateFormat, $sLocalTimeFormat, $blOnlyDate);
00426             return $oObject->value;
00427         }
00428 
00429         $blDefDateFound = false;
00430         $oStr = getStr();
00431 
00432         // looking for default values that are formatted by MySQL
00433         foreach ( array_keys( $aDefDatePatterns ) as $sDefDatePattern ) {
00434             if ( $oStr->preg_match( $sDefDatePattern, $sDate)) {
00435                 $blDefDateFound = true;
00436                 break;
00437             }
00438         }
00439 
00440         // default value is set ?
00441         if ( $blDefDateFound) {
00442             $this->_setDefaultFormatedValue($oObject, $sDate, $sLocalDateFormat, $sLocalTimeFormat, $blOnlyDate);
00443             return $oObject->value;
00444         }
00445 
00446         $blDateFound = false;
00447         $blTimeFound = false;
00448         $aDateMatches = array();
00449         $aTimeMatches = array();
00450 
00451         // looking for date field
00452         foreach ( $aDatePatterns as $sPattern => $sType) {
00453             if ( $oStr->preg_match( $sPattern, $sDate, $aDateMatches)) {
00454                 $blDateFound = true;
00455 
00456                 // now we know the type of passed date
00457                 $sDateFormat = $aDFormats[$sLocalDateFormat][0];
00458                 $aDFields    = $aDFormats[$sType][1];
00459                 break;
00460             }
00461         }
00462 
00463         // no such date field available ?
00464         if ( !$blDateFound) {
00465             return $sDate;
00466         }
00467 
00468         if ( $blOnlyDate) {
00469             $this->_setDate($oObject, $sDateFormat, $aDFields, $aDateMatches);
00470             return $oObject->value;
00471         }
00472 
00473         // looking for time field
00474         foreach ( $aTimePatterns as $sPattern => $sType) {
00475             if ( $oStr->preg_match( $sPattern, $sDate, $aTimeMatches)) {
00476                 $blTimeFound = true;
00477 
00478                 // now we know the type of passed time
00479                 $sTimeFormat = $aTFormats[$sLocalTimeFormat][0];
00480                 $aTFields    = $aTFormats[$sType][1];
00481 
00482                 //
00483                 if ( $sType == "USA" && isset($aTimeMatches[4])) {
00484                     $iIntVal = (int) $aTimeMatches[1];
00485                     if ( $aTimeMatches[4] == "PM") {
00486                         if ( $iIntVal < 13) {
00487                             $iIntVal += 12;
00488                         }
00489                     } elseif ( $aTimeMatches[4] == "AM" && $aTimeMatches[1] == "12") {
00490                         $iIntVal = 0;
00491                     }
00492 
00493                     $aTimeMatches[1] = sprintf("%02d", $iIntVal);
00494                 }
00495 
00496                 break;
00497             }
00498         }
00499 
00500         if ( !$blTimeFound) {
00501             //return $sDate;
00502             // #871A. trying to keep date as possible correct
00503             $this->_setDate($oObject, $sDateFormat, $aDFields, $aDateMatches);
00504             return $oObject->value;
00505         }
00506 
00507         $this->_formatCorrectTimeValue($oObject, $sDateFormat, $sTimeFormat, $aDateMatches, $aTimeMatches, $aTFields, $aDFields);
00508 
00509         // on some cases we get empty value
00510         if ( !$oObject->fldmax_length) {
00511             return $this->convertDBDateTime( $oObject, $blToTimeStamp, $blOnlyDate);
00512         }
00513         return $oObject->value;
00514     }
00515 
00524     public function convertDBTimestamp( $oObject, $blToTimeStamp = false )
00525     {
00526          // on this case usually means that we gonna save value, and value is formatted, not plain
00527         $sSQLTimeStampPattern = "/^([0-9]{4})([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})$/";
00528         $sISOTimeStampPattern = "/^([0-9]{4})-([0-9]{2})-([0-9]{2}) ([0-9]{2}):([0-9]{2}):([0-9]{2})$/";
00529         $aMatches = array();
00530         $oStr = getStr();
00531 
00532         // preparing value to save
00533         if ( $blToTimeStamp) {
00534             // reformatting value to ISO
00535             $this->convertDBDateTime( $oObject, $blToTimeStamp );
00536 
00537             if ( $oStr->preg_match( $sISOTimeStampPattern, $oObject->value, $aMatches)) {
00538                 // changing layout
00539                 $oObject->setValue($aMatches[1].$aMatches[2].$aMatches[3].$aMatches[4].$aMatches[5].$aMatches[6]);
00540                 $oObject->fldmax_length = strlen( $oObject->value);
00541                 return $oObject->value;
00542             }
00543         } else {
00544             // loading and formatting value
00545             // checking and parsing SQL timestamp value
00546             //$sSQLTimeStampPattern = "/^([0-9]{4})([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})$/";
00547             if ( $oStr->preg_match( $sSQLTimeStampPattern, $oObject->value, $aMatches ) ) {
00548                 $iTimestamp = mktime( $aMatches[4], //h
00549                                         $aMatches[5], //m
00550                                         $aMatches[6], //s
00551                                         $aMatches[2], //M
00552                                         $aMatches[3], //d
00553                                         $aMatches[1]); //y
00554                 if ( !$iTimestamp ) {
00555                     $iTimestamp = "0";
00556                 }
00557 
00558                 $oObject->setValue(trim( date( "Y-m-d H:i:s", $iTimestamp)));
00559                 $oObject->fldmax_length = strlen( $oObject->value);
00560                 $this->convertDBDateTime( $oObject, $blToTimeStamp );
00561                 return $oObject->value;
00562             }
00563         }
00564     }
00565 
00574     public function convertDBDate( $oObject, $blToTimeStamp = false )
00575     {
00576         return $this->convertDBDateTime( $oObject, $blToTimeStamp, true );
00577     }
00578 
00588     public function createSQLList( $aArray )
00589     {
00590         $sRet = "";
00591 
00592         $blSep = false;
00593         foreach ( $aArray as $aToken) {
00594             if ( !$aToken[0]) {
00595                 continue;
00596             }
00597             if ( $blSep) {
00598                 $sRet .= ",";
00599             }
00600             $sRet .= "'".$aToken[0]."'";
00601             $blSep = true;
00602         }
00603         return $sRet;
00604     }
00605 
00613     static public function startTransaction()
00614     {
00615         return self::getDb()->execute( 'START TRANSACTION' );
00616     }
00617 
00625     static public function commitTransaction()
00626     {
00627         return self::getDb()->execute( 'COMMIT' );
00628     }
00629 
00637     static public function rollbackTransaction()
00638     {
00639         return self::getDb()->execute( 'ROLLBACK' );
00640     }
00641 
00652     static public function setTransactionIsolationLevel( $sLevel = null )
00653     {
00654         $aLevels = array( 'READ UNCOMMITTED', 'READ COMMITTED', 'REPEATABLE READ', 'SERIALIZABLE' );
00655         if ( in_array( strtoupper( $sLevel ), $aLevels ) ) {
00656             return self::getDb()->execute( 'SET TRANSACTION ISOLATION LEVEL ' . $sLevel );
00657         }
00658     }
00659 
00660 
00669     public function isValidFieldName( $sField )
00670     {
00671         return ( boolean ) getStr()->preg_match( "#^[\w\d\._]*$#", $sField );
00672     }
00673 
00685     protected function _setDefaultFormatedValue( $oObject, $sDate, $sLocalDateFormat, $sLocalTimeFormat, $blOnlyDate )
00686     {
00687         $aDefTimePatterns = $this->_defaultTimePattern();
00688         $aDFormats  = $this->_defineDateFormattingRules();
00689         $aTFormats  = $this->_defineTimeFormattingRules();
00690         $oStr = getStr();
00691 
00692         foreach ( array_keys( $aDefTimePatterns ) as $sDefTimePattern ) {
00693             if ( $oStr->preg_match( $sDefTimePattern, $sDate ) ) {
00694                 $blDefTimeFound = true;
00695                 break;
00696             }
00697         }
00698 
00699         // setting and returning default formatted value
00700         if ( $blOnlyDate) {
00701             $oObject->setValue(trim( $aDFormats[$sLocalDateFormat][2] ));// . " " . @$aTFormats[$sLocalTimeFormat][2]);
00702             // increasing(decreasing) field lenght
00703             $oObject->fldmax_length = strlen( $oObject->value );
00704             return ;
00705         } elseif ( $blDefTimeFound ) {
00706             // setting value
00707             $oObject->setValue(trim( $aDFormats[$sLocalDateFormat][2] . " " . $aTFormats[$sLocalTimeFormat][2] ));
00708             // increasing(decreasing) field lenght
00709             $oObject->fldmax_length = strlen( $oObject->value );
00710             return ;
00711         }
00712     }
00713 
00721     protected function _defineAndCheckDefaultTimeValues( $blToTimeStamp )
00722     {
00723         // defining time format
00724         // checking for default values
00725         $sLocalTimeFormat = $this->getConfig()->getConfigParam( 'sLocalTimeFormat' );
00726         if ( !$sLocalTimeFormat || $blToTimeStamp) {
00727             $sLocalTimeFormat = "ISO";
00728         }
00729         return $sLocalTimeFormat;
00730     }
00731 
00739     protected function _defineAndCheckDefaultDateValues( $blToTimeStamp )
00740     {
00741         // defining time format
00742         // checking for default values
00743         $sLocalDateFormat = $this->getConfig()->getConfigParam( 'sLocalDateFormat' );
00744         if ( !$sLocalDateFormat || $blToTimeStamp) {
00745             $sLocalDateFormat = "ISO";
00746         }
00747         return $sLocalDateFormat;
00748     }
00749 
00755     protected function _defaultDatePattern()
00756     {
00757         // default date patterns
00758         $aDefDatePatterns = array("/^0000-00-00/"   => "ISO",
00759                                   "/^00\.00\.0000/" => "EUR",
00760                                   "/^00\/00\/0000/" => "USA"
00761                                  );
00762         return $aDefDatePatterns;
00763     }
00764 
00770     protected function _defaultTimePattern()
00771     {
00772         // default time patterns
00773         $aDefTimePatterns = array("/00:00:00$/"    => "ISO",
00774                                   "/00\.00\.00$/"  => "EUR",
00775                                   "/00:00:00 AM$/" => "USA"
00776                                  );
00777         return $aDefTimePatterns;
00778     }
00779 
00785     protected function _regexp2ValidateDateInput()
00786     {
00787         // regexps to validate input
00788         $aDatePatterns = array("/^([0-9]{4})-([0-9]{2})-([0-9]{2})/"   => "ISO",
00789                                "/^([0-9]{2})\.([0-9]{2})\.([0-9]{4})/" => "EUR",
00790                                "/^([0-9]{2})\/([0-9]{2})\/([0-9]{4})/" => "USA"
00791                               );
00792         return $aDatePatterns;
00793     }
00794 
00800     protected function _regexp2ValidateTimeInput()
00801     {
00802         // regexps to validate input
00803         $aTimePatterns = array("/([0-9]{2}):([0-9]{2}):([0-9]{2})$/"   => "ISO",
00804                                "/([0-9]{2})\.([0-9]{2})\.([0-9]{2})$/" => "EUR",
00805                                "/([0-9]{2}):([0-9]{2}):([0-9]{2}) ([AP]{1}[M]{1})$/" => "USA"
00806                               );
00807         return $aTimePatterns;
00808     }
00809 
00815     protected function _defineDateFormattingRules()
00816     {
00817         // date formatting rules
00818         $aDFormats  = array("ISO" => array("Y-m-d", array(2, 3, 1), "0000-00-00"),
00819                             "EUR" => array("d.m.Y", array(2, 1, 3), "00.00.0000"),
00820                             "USA" => array("m/d/Y", array(1, 2, 3), "00/00/0000")
00821                            );
00822         return $aDFormats;
00823     }
00824 
00830     protected function _defineTimeFormattingRules()
00831     {
00832         // time formatting rules
00833         $aTFormats  = array("ISO" => array("H:i:s",   array(1, 2, 3 ), "00:00:00"),
00834                             "EUR" => array("H.i.s",   array(1, 2, 3 ), "00.00.00"),
00835                             "USA" => array("h:i:s A", array(1, 2, 3 ), "00:00:00 AM")
00836                            );
00837         return $aTFormats;
00838     }
00839 
00850     protected function _setDefaultDateTimeValue( $oObject, $sLocalDateFormat, $sLocalTimeFormat, $blOnlyDate )
00851     {
00852         $aDFormats  = $this->_defineDateFormattingRules();
00853         $aTFormats  = $this->_defineTimeFormattingRules();
00854 
00855         $sReturn = $aDFormats[$sLocalDateFormat][2];
00856         if ( !$blOnlyDate) {
00857             $sReturn .= " ".$aTFormats[$sLocalTimeFormat][2];
00858         }
00859 
00860         if ($oObject instanceof oxField) {
00861             $oObject->setValue(trim($sReturn));
00862         } else {
00863             $oObject->value = trim($sReturn);
00864         }
00865         // increasing(decreasing) field lenght
00866         $oObject->fldmax_length = strlen( $oObject->value);
00867     }
00868 
00879     protected function _setDate( $oObject, $sDateFormat, $aDFields, $aDateMatches )
00880     {
00881         // formatting correct time value
00882         $iTimestamp = mktime( 0, 0, 0, $aDateMatches[$aDFields[0]],
00883                               $aDateMatches[$aDFields[1]],
00884                               $aDateMatches[$aDFields[2]]);
00885 
00886         if ($oObject instanceof oxField) {
00887             $oObject->setValue(@date( $sDateFormat, $iTimestamp ));
00888         } else {
00889             $oObject->value = @date( $sDateFormat, $iTimestamp );
00890         }
00891         // we should increase (decrease) field lenght
00892         $oObject->fldmax_length = strlen( $oObject->value );
00893     }
00894 
00908     protected function _formatCorrectTimeValue( $oObject, $sDateFormat, $sTimeFormat, $aDateMatches, $aTimeMatches, $aTFields, $aDFields )
00909     {
00910         // formatting correct time value
00911         $iTimestamp = @mktime( (int) $aTimeMatches[$aTFields[0]],
00912                                (int) $aTimeMatches[$aTFields[1]],
00913                                (int) $aTimeMatches[$aTFields[2]],
00914                                (int) $aDateMatches[$aDFields[0]],
00915                                (int) $aDateMatches[$aDFields[1]],
00916                                (int) $aDateMatches[$aDFields[2]] );
00917 
00918         if ($oObject instanceof oxField) {
00919             $oObject->setValue(trim( @date( $sDateFormat." ".$sTimeFormat, $iTimestamp ) ));
00920         } else {
00921             $oObject->value = trim( @date( $sDateFormat." ".$sTimeFormat, $iTimestamp ) );
00922         }
00923 
00924         // we should increase (decrease) field lenght
00925         $oObject->fldmax_length = strlen( $oObject->value );
00926     }
00927 
00933     protected function _getConnectionId()
00934     {
00935         return self::getDb()->getDb()->connectionId;
00936     }
00937 
00945     public function escapeString( $sString )
00946     {
00947         $myConfig  = $this->getConfig();
00948         if ( 'mysql' == $myConfig->getConfigParam( "dbType" )) {
00949             return mysql_real_escape_string( $sString, $this->_getConnectionId() );
00950         } elseif ( 'mysqli' == $myConfig->getConfigParam( "dbType" )) {
00951             return mysqli_real_escape_string( $this->_getConnectionId(), $sString );
00952         } else {
00953             return mysql_real_escape_string( $sString, $this->_getConnectionId() );
00954         }
00955     }
00956 
00964     public function updateViews( $aTables = null )
00965     {
00966         set_time_limit(0);
00967 
00968         $myConfig  = $this->getConfig();
00969         $oShopList = oxNew("oxshoplist" );
00970         $oShopList->selectString( "select * from oxshops"); // Shop view may not exist at this point
00971 
00972         $aTables = $aTables ? $aTables : $myConfig->getConfigParam( 'aMultiShopTables' );
00973         foreach ( $oShopList as $key => $oShop ) {
00974             $oShop->setMultiShopTables( $aTables );
00975             $blMultishopInherit = $myConfig->getShopConfVar( 'blMultishopInherit_oxcategories', $oShop->sOXID );
00976             $aMallInherit = array();
00977             foreach ( $aTables as $sTable ) {
00978                 $aMallInherit[$sTable] = $myConfig->getShopConfVar( 'blMallInherit_' . $sTable, $oShop->sOXID );
00979             }
00980             $oShop->generateViews( $blMultishopInherit, $aMallInherit );
00981         }
00982     }
00983 }