00001 <?php
00002
00009 class oxUser extends oxBase
00010 {
00015 protected $_blDisableShopCheck = true;
00016
00021 protected $_oNewsSubscription = null;
00022
00027 protected $_sCoreTbl = 'oxuser';
00028
00033 protected $_sClassName = 'oxuser';
00034
00040 protected $_aBaskets = array();
00041
00047 protected $_oGroups;
00048
00054 protected $_oAddresses;
00055
00061 protected $_oPayments;
00062
00068 protected $_oRecommList;
00069
00075 protected $_blMallUsers = false;
00076
00082 protected static $_aUserCookie = array();
00083
00089 protected $_iCntNoticeListArticles = null;
00090
00096 protected $_iCntWishListArticles = null;
00097
00103 protected $_iCntRecommLists = null;
00104
00110 protected $_sUpdateKey = null;
00111
00117 protected $_blLoadedFromCookie = null;
00118
00124 public function __construct()
00125 {
00126 $this->setMallUsersStatus( $this->getConfig()->getConfigParam( 'blMallUsers' ) );
00127
00128 parent::__construct();
00129 $this->init( 'oxuser' );
00130 }
00131
00139 public function setMallUsersStatus( $blOn = false )
00140 {
00141 $this->_blMallUsers = $blOn;
00142 }
00143
00151 public function __get( $sParamName )
00152 {
00153
00154 switch ( $sParamName ) {
00155 case 'oGroups':
00156 return $this->_oGroups = $this->getUserGroups();
00157 case 'iCntNoticeListArticles':
00158 return $this->_iCntNoticeListArticles = $this->getNoticeListArtCnt();
00159 case 'iCntWishListArticles':
00160 return $this->_iCntWishListArticles = $this->getWishListArtCnt();
00161 case 'iCntRecommLists':
00162 return $this->_iCntRecommLists = $this->getRecommListsCount();
00163 case 'oAddresses':
00164 return $this->_oAddresses = $this->getUserAddresses();
00165 case 'oPayments':
00166 return $this->_oPayments = $this->getUserPayments();
00167 case 'oxuser__oxcountry':
00168 return $this->oxuser__oxcountry = $this->getUserCountry();
00169 case 'sDBOptin':
00170 return $this->sDBOptin = $this->getNewsSubscription()->getOptInStatus();
00171 case 'sEmailFailed':
00172 return $this->sEmailFailed = $this->getNewsSubscription()->getOptInEmailStatus();
00173 }
00174 }
00175
00181 public function getNewsSubscription()
00182 {
00183 if ( $this->_oNewsSubscription !== null ) {
00184 return $this->_oNewsSubscription;
00185 }
00186
00187 $this->_oNewsSubscription = oxNew( 'oxnewssubscribed' );
00188
00189
00190 if ( !$this->_oNewsSubscription->loadFromUserId( $this->getId() ) ) {
00191 if ( !$this->_oNewsSubscription->loadFromEmail( $this->oxuser__oxusername->value ) ) {
00192
00193
00194 $this->_oNewsSubscription->oxnewssubscribed__oxuserid = new oxField($this->getId(), oxField::T_RAW);
00195 $this->_oNewsSubscription->oxnewssubscribed__oxemail = new oxField($this->oxuser__oxusername->value, oxField::T_RAW);
00196 $this->_oNewsSubscription->oxnewssubscribed__oxsal = new oxField($this->oxuser__oxsal->value, oxField::T_RAW);
00197 $this->_oNewsSubscription->oxnewssubscribed__oxfname = new oxField($this->oxuser__oxfname->value, oxField::T_RAW);
00198 $this->_oNewsSubscription->oxnewssubscribed__oxlname = new oxField($this->oxuser__oxlname->value, oxField::T_RAW);
00199 }
00200 }
00201
00202 return $this->_oNewsSubscription;
00203 }
00204
00214 public function getUserCountry( $sCountryId = null, $iLang = null )
00215 {
00216
00217 if ( !$sCountryId ) {
00218 $sCountryId = $this->oxuser__oxcountryid->value;
00219 }
00220
00221 $sQ = 'select oxtitle'.oxLang::getInstance()->getLanguageTag( $iLang ).' from oxcountry where oxid = "'.$sCountryId.'" ';
00222 $this->oxuser__oxcountry = new oxField( oxDb::getDb()->GetOne( $sQ ), oxField::T_RAW);
00223
00224 return $this->oxuser__oxcountry;
00225 }
00226
00234 public function getUserGroups( $sOXID = null )
00235 {
00236
00237 if ( isset( $this->_oGroups ) ) {
00238 return $this->_oGroups;
00239 }
00240
00241 if ( !$sOXID ) {
00242 $sOXID = $this->getId();
00243 }
00244
00245 $this->_oGroups = oxNew( 'oxlist', 'oxgroups' );
00246
00247
00248 $sSelect = 'select oxgroups.* from oxgroups left join oxobject2group on oxobject2group.oxgroupsid = oxgroups.oxid ';
00249 $sSelect .= 'where oxobject2group.oxobjectid = "'.$sOXID.'" ';
00250 $this->_oGroups->selectString( $sSelect );
00251 return $this->_oGroups;
00252 }
00253
00261 public function getUserAddresses( $sOXID = null )
00262 {
00263
00264 if ( isset( $this->_oAddresses ) ) {
00265 return $this->_oAddresses;
00266 }
00267
00268 if ( !$sOXID ) {
00269 $sOXID = $this->getId();
00270 }
00271
00272
00273 $this->_oAddresses = oxNew( 'oxlist' );
00274 $this->_oAddresses->init( "oxbase", "oxaddress" );
00275 $sSelect = 'select * from oxaddress where oxaddress.oxuserid = "'.$sOXID.'" ';
00276 $this->_oAddresses->selectString( $sSelect );
00277 return $this->_oAddresses;
00278 }
00279
00288 public function getSelectedAddress( $sWishId = false )
00289 {
00290 $sAddressId = oxConfig::getParameter( "oxaddressid");
00291 if ( !$sAddressId ) {
00292 $sAddressId = oxSession::getVar( "deladrid" );
00293 }
00294
00295 if ( $sAddressId ) {
00296 $sWishId = null;
00297 }
00298
00299 $oAddresses = $this->getUserAddresses();
00300 if ( $sWishId && $oAddresses->count()) {
00301 foreach ( $oAddresses as $oAddress ) {
00302 $oAddress->selected = 0;
00303 if ( $oAddress->oxaddress__oxaddressuserid->value == $sWishId ) {
00304 $oAddress->selected = 1;
00305 return $oAddress->getId();
00306 }
00307 }
00308 }
00309
00310 if ( !$sAddressId && $oAddresses->count() ) {
00311 $oAddresses->rewind();
00312 if ( ( $oCurAdress = $oAddresses->current() ) ) {
00313 $sAddressId = $oCurAdress->getId();
00314 }
00315 }
00316
00317
00318 if ( $sAddressId ) {
00319 foreach ( $oAddresses as $oAddress ) {
00320 $oAddress->selected = 0;
00321 if ( $oAddress->getId() == $sAddressId ) {
00322 $oAddress->selected = 1;
00323 break;
00324 }
00325 }
00326 }
00327
00328 return $sAddressId;
00329 }
00330
00338 public function getUserPayments( $sOXID = null )
00339 {
00340 if ( $this->_oPayments === null ) {
00341
00342 if ( !$sOXID ) {
00343 $sOXID = $this->getId();
00344 }
00345
00346 $sSelect = 'select * from oxuserpayments where oxuserid ="'. $sOXID .'"';
00347
00348 $this->_oPayments = oxNew( 'oxlist' );
00349 $this->_oPayments->init( 'oxUserPayment' );
00350 $this->_oPayments->selectString( $sSelect );
00351
00352
00353 foreach ( $this->_oPayments as $oPayment ) {
00354
00355 $oPayment = oxUtils::getInstance()->assignValuesFromText( $val->oxuserpayments__oxvalue->value );
00356 }
00357 }
00358
00359 return $this->_oPayments;
00360 }
00361
00367 public function save()
00368 {
00369
00370 $blAddRemark = false;
00371 if ( $this->oxuser__oxpassword->value && $this->oxuser__oxregister->value < 1 ) {
00372 $blAddRemark = true;
00373
00374 $this->oxuser__oxregister = new oxField(date( 'Y-m-d H:i:s' ), oxField::T_RAW);
00375 }
00376
00377
00378 $this->oxuser__oxrights = new oxField($this->_getUserRights(), oxField::T_RAW);
00379
00380
00381 if ( is_array( $this->oxuser__oxbirthdate->value ) ) {
00382 $this->oxuser__oxbirthdate = new oxField($this->convertBirthday( $this->oxuser__oxbirthdate->value ), oxField::T_RAW);
00383 }
00384
00385
00386
00387 $blStore = $this->_blIsDerived;
00388 $this->_blIsDerived = false;
00389 $blRet = parent::save();
00390 $this->_blIsDerived = $blStore;
00391
00392
00393 if ( $blAddRemark && $blRet ) {
00394 $oRemark = oxNew( 'oxremark' );
00395 $oRemark->oxremark__oxtext = new oxField(oxLang::getInstance()->translateString( 'usrRegistered' ), oxField::T_RAW);
00396 $oRemark->oxremark__oxparentid = new oxField($this->getId(), oxField::T_RAW);
00397 $oRemark->save();
00398 }
00399
00400 return $blRet;
00401 }
00402
00410 public function inGroup( $sGroupID )
00411 {
00412 $blIn = false;
00413 if( ( $oGroups = $this->getUserGroups() ) ) {
00414 $blIn = isset( $oGroups[ $sGroupID ] );
00415 }
00416
00417 return $blIn;
00418 }
00419
00428 public function delete( $sOXID = null )
00429 {
00430
00431 if ( !$sOXID ) {
00432 $sOXID = $this->getId();
00433 }
00434 if ( !$sOXID ) {
00435 return false;
00436 }
00437
00438 $blDeleted = parent::delete( $sOXID );
00439
00440 if ( $blDeleted ) {
00441 $oDB = oxDb::getDb();
00442
00443
00444 $rs = $oDB->execute( 'delete from oxuserpayments where oxuserpayments.oxuserid = "'.$sOXID.'" ' );
00445 $rs = $oDB->execute( 'delete from oxaddress where oxaddress.oxuserid = "'.$sOXID.'" ' );
00446 $rs = $oDB->execute( 'delete from oxobject2group where oxobject2group.oxobjectid = "'.$sOXID.'" ');
00447 $rs = $oDB->execute( 'delete from oxremark where oxparentid = "'.$sOXID.'" ' );
00448
00449
00450 $rs = $oDB->execute( 'delete oxuserbasketitems.* from oxuserbasketitems, oxuserbaskets where oxuserbasketitems.oxbasketid = oxuserbaskets.oxid and oxuserid = "'.$sOXID.'" ' );
00451 $rs = $oDB->execute( 'delete from oxuserbaskets where oxuserid = "'.$sOXID.'" ' );
00452
00453
00454 $rs = $oDB->execute( 'delete from oxnewssubscribed where oxuserid = "'.$sOXID.'" ');
00455
00456 $blDeleted = $rs->EOF;
00457 }
00458
00459 return $blDeleted;
00460 }
00461
00469 public function load( $oxID )
00470 {
00471
00472 $blRet = parent::Load( $oxID );
00473
00474
00475 if ( isset( $this->oxuser__oxcreate->value ) ) {
00476 $this->oxuser__oxcreate->setValue(oxUtilsDate::getInstance()->formatDBDate( $this->oxuser__oxcreate->value ));
00477 }
00478
00479 return $blRet;
00480 }
00481
00489 public function exists( $sOXID = null )
00490 {
00491 if ( !$sOXID ) {
00492 $sOXID = $this->getId();
00493 }
00494
00495 $sSelect = 'SELECT oxid FROM '.$this->getViewName().'
00496 WHERE ( oxusername = "'.$this->oxuser__oxusername->value.'"';
00497
00498 if ( $sOXID ) {
00499 $sSelect.= " or oxid = '$sOXID' ) ";
00500 } else {
00501 $sSelect.= ' ) ';
00502 }
00503
00504 if ( !$this->_blMallUsers && $this->oxuser__oxrights->value != 'malladmin') {
00505 $sSelect .= ' AND oxshopid = "'.$this->getConfig()->getShopId().'" ';
00506 }
00507
00508 $blExists = false;
00509 if ( ( $sOxid = oxDb::getDb()->getOne( $sSelect ) ) ) {
00510
00511 $this->setId( $sOxid );
00512 $blExists = true;
00513 }
00514 return $blExists;
00515 }
00516
00522 public function getOrders()
00523 {
00524 $myConfig = $this->getConfig();
00525 $oOrders = oxNew( 'oxlist' );
00526 $oOrders->init( 'oxorder' );
00527
00528
00529
00530
00531
00532
00533
00534
00535 if ( $this->oxuser__oxregister->value > 1 ) {
00536 $sQ = 'select * from oxorder where oxuserid = "'.$this->getId().'" and oxorderdate >= "'.$this->oxuser__oxregister->value.'" ';
00537
00538
00539
00540 $sQ .= ' order by oxorderdate desc ';
00541 $oOrders->selectString( $sQ );
00542 }
00543
00544 return $oOrders;
00545 }
00546
00552 public function getOrderCount()
00553 {
00554 $iCnt = 0;
00555 if ( $this->getId() && $this->oxuser__oxregister->value > 1 ) {
00556 $sQ = 'select count(*) from oxorder where oxuserid = "'.$this->getId().'" AND oxorderdate >= "'.$this->oxuser__oxregister->value.'" and oxshopid = "'.$this->getConfig()->getShopId().'" ';
00557 $iCnt = (int) oxDb::getDb()->getOne( $sQ );
00558 }
00559
00560 return $iCnt;
00561 }
00562
00568 public function getNoticeListArtCnt()
00569 {
00570 if ( $this->_iCntNoticeListArticles === null ) {
00571 $this->_iCntNoticeListArticles = 0;
00572 if ( $this->getId() ) {
00573 $this->_iCntNoticeListArticles = $this->getBasket( 'noticelist' )->getItemCount();
00574 }
00575 }
00576 return $this->_iCntNoticeListArticles;
00577 }
00578
00584 public function getWishListArtCnt()
00585 {
00586 if ( $this->_iCntWishListArticles === null ) {
00587 $this->_iCntWishListArticles = false;
00588 if ( $this->getId() ) {
00589 $this->_iCntWishListArticles = $this->getBasket( 'wishlist' )->getItemCount();
00590 }
00591 }
00592 return $this->_iCntWishListArticles;
00593 }
00594
00601 public function getActiveCountry()
00602 {
00603 $sDeliveryCountry = '';
00604 if (!($soxAddressId = oxConfig::getParameter( 'deladrid' ))) {
00605 $soxAddressId = oxSession::getVar( 'deladrid' );
00606 }
00607 if ( $soxAddressId ) {
00608 $oDelAddress = oxNew( 'oxbase' );
00609 $oDelAddress->init( 'oxaddress' );
00610 $oDelAddress->load( $soxAddressId );
00611 $sDeliveryCountry = $oDelAddress->oxaddress__oxcountryid->value;
00612 } elseif ( $this->getId() ) {
00613 $sDeliveryCountry = $this->oxuser__oxcountryid->value;
00614 } else {
00615 $oUser = oxNew( 'oxuser' );
00616 if ( $oUser->loadActiveUser() ) {
00617 $sDeliveryCountry = $oUser->oxuser__oxcountryid->value;
00618 }
00619 }
00620
00621 return $sDeliveryCountry;
00622 }
00623
00631 public function createUser()
00632 {
00633 $oDB = oxDb::getDb();
00634 $sShopID = $this->getConfig()->getShopId();
00635
00636
00637 $sSelect = "select oxid from oxuser where oxusername = '{$this->oxuser__oxusername->value}' and oxpassword = '' ";
00638 if ( !$this->_blMallUsers ) {
00639 $sSelect .= " and oxshopid = '{$sShopID}' ";
00640 }
00641 $sOXID = $oDB->getOne( $sSelect );
00642
00643
00644 if ( isset( $sOXID ) && $sOXID ) {
00645
00646 $this->setId( $sOXID );
00647 } elseif ( $this->_blMallUsers ) {
00648 $sQ = "select oxid from oxuser where oxusername = '{$this->oxuser__oxusername->value}' and oxusername != '' ";
00649 if ( $oDB->getOne( $sQ ) ) {
00650 $oEx = oxNew( 'oxUserException' );
00651 $oEx->setMessage('EXCEPTION_USER_USEREXISTS');
00652 throw $oEx;
00653 }
00654 }
00655
00656 $this->oxuser__oxshopid = new oxField( $sShopID, oxField::T_RAW );
00657 if ( ( $blOK = $this->save() ) ) {
00658
00659 $oDB->execute( "delete from oxaddress where oxaddress.oxuserid = '{$this->oxuser__oxid->value}' " );
00660 $oDB->execute( "update oxuserpayments set oxuserpayments.oxuserid = '{$this->oxuser__oxusername->value}' where oxuserpayments.oxuserid = '{$this->oxuser__oxid->value}' " );
00661 } else {
00662 $oEx = oxNew( 'oxUserException' );
00663 $oEx->setMessage( 'EXCEPTION_USER_USERCREATIONFAILED' );
00664 throw $oEx;
00665 }
00666
00667 return $blOK;
00668 }
00669
00677 public function addToGroup( $sGroupID )
00678 {
00679 if ( !$this->inGroup( $sGroupID ) ) {
00680 $oNewGroup = oxNew( 'oxobject2group' );
00681 $oNewGroup->oxobject2group__oxobjectid = new oxField($this->getId(), oxField::T_RAW);
00682 $oNewGroup->oxobject2group__oxgroupsid = new oxField($sGroupID, oxField::T_RAW);
00683 if ( $oNewGroup->save() ) {
00684 $this->_oGroups[$sGroupID] = $oNewGroup;
00685 return true;
00686 }
00687 }
00688 return false;
00689 }
00690
00698 public function removeFromGroup( $sGroupID = null )
00699 {
00700 if ( $sGroupID != null && $this->inGroup( $sGroupID ) ) {
00701 $oGroups = oxNew( 'oxlist' );
00702 $oGroups->init( 'oxobject2group' );
00703 $sSelect = 'select * from oxobject2group where oxobject2group.oxobjectid = "'.$this->getId().'" and oxobject2group.oxgroupsid = "'.$sGroupID.'" ';
00704 $oGroups->selectString( $sSelect );
00705 foreach ( $oGroups as $oRemgroup ) {
00706 if ( $oRemgroup->delete() ) {
00707 unset( $this->_oGroups[$oRemgroup->oxobject2group__oxgroupsid->value] );
00708 }
00709 }
00710 }
00711 }
00712
00721 public function onOrderExecute( $oBasket, $iSuccess )
00722 {
00723
00724 if ( is_numeric( $iSuccess ) && $iSuccess != 2 && $iSuccess <= 3 ) {
00725
00726 if ( !$this->oxuser__oxdisableautogrp->value ) {
00727
00728 $myConfig = $this->getConfig();
00729 $dMidlleCustPrice = (float) $myConfig->getConfigParam( 'sMidlleCustPrice' );
00730 $dLargeCustPrice = (float) $myConfig->getConfigParam( 'sLargeCustPrice' );
00731
00732 $this->addToGroup( 'oxidcustomer' );
00733 $dBasketPrice = $oBasket->getPrice()->getBruttoPrice();
00734 if ( $dBasketPrice < $dMidlleCustPrice ) {
00735 $this->addToGroup( 'oxidsmallcust' );
00736 }
00737 if ( $dBasketPrice >= $dMidlleCustPrice && $dBasketPrice < $dLargeCustPrice ) {
00738 $this->addToGroup( 'oxidmiddlecust' );
00739 }
00740 if ( $dBasketPrice >= $dLargeCustPrice ) {
00741 $this->addToGroup( 'oxidgoodcust' );
00742 }
00743 }
00744
00745 if ( $this->inGroup( 'oxidnotyetordered' ) ) {
00746 $this->removeFromGroup( 'oxidnotyetordered' );
00747 }
00748 }
00749 }
00750
00758 public function getBasket( $sName )
00759 {
00760 if ( !isset( $this->_aBaskets[$sName] ) ) {
00761 $oBasket = oxNew( 'oxuserbasket' );
00762 $aWhere = array( 'oxuserbaskets.oxuserid' => $this->getId(), 'oxuserbaskets.oxtitle' => $sName );
00763
00764
00765 if ( !$oBasket->assignRecord( $oBasket->buildSelectString( $aWhere ) ) ) {
00766 $oBasket->oxuserbaskets__oxtitle = new oxField($sName);
00767 $oBasket->oxuserbaskets__oxuserid = new oxField($this->getId());
00768
00769
00770 $oBasket->setIsNewBasket();
00771 }
00772
00773 $this->_aBaskets[$sName] = $oBasket;
00774 }
00775
00776 return $this->_aBaskets[$sName];
00777 }
00778
00787 public function convertBirthday( $aData )
00788 {
00789
00790
00791 $iYear = isset($aData['year'])?((int) $aData['year']):false;
00792 $iMonth = isset($aData['month'])?((int) $aData['month']):false;
00793 $iDay = isset($aData['day'])?((int) $aData['day']):false;
00794
00795
00796 if ( !$iYear && !$iMonth && !$iDay )
00797 return "";
00798
00799
00800 if ( !$iYear || $iYear < 1000 || $iYear > 9999)
00801 $iYear = date('Y');
00802
00803
00804 if ( !$iMonth || $iMonth < 1 || $iMonth > 12)
00805 $iMonth = 1;
00806
00807
00808 $iMaxDays = 31;
00809 switch( $iMonth) {
00810 case 2 :
00811 if ($iMaxDays > 28)
00812 $iMaxDays = ($iYear % 4 == 0 && ($iYear % 100 != 0 || $iYear % 400 == 0)) ? 29 : 28;
00813 break;
00814 case 4 :
00815 case 6 :
00816 case 9 :
00817 case 11 :
00818 $iMaxDays = min(30, $iMaxDays);
00819 break;
00820 }
00821
00822
00823 if ( !$iDay || $iDay < 1 || $iDay > $iMaxDays) {
00824 $iDay = 1;
00825 }
00826
00827
00828 return sprintf("%04d-%02d-%02d", $iYear, $iMonth, $iDay);
00829 }
00830
00837 public function getBoni()
00838 {
00839 return 1000;
00840 }
00841
00854 public function addDynGroup( $sDynGoup, $aDeniedDynGroups )
00855 {
00856
00857 $sDynGoup = strtolower( trim( $sDynGoup ) );
00858
00859
00860 $aDisabledDynGroups = array_merge( array( 'oxidadmin' ), (array) $aDeniedDynGroups );
00861
00862
00863 $blAdd = false;
00864
00865
00866 if ( $this->oxuser__oxdisableautogrp->value || !$sDynGoup ) {
00867 $blAdd = false;
00868 } elseif ( in_array( $sDynGoup, $aDisabledDynGroups ) ) {
00869
00870 $blAdd = false;
00871 } elseif ( $this->addToGroup( $sDynGoup ) ) {
00872 $blAdd = true;
00873 }
00874
00875
00876 oxSession::deleteVar( 'dgr' );
00877
00878 return $blAdd;
00879 }
00880
00896 public function checkValues( $sLogin, $sPassword, $sPassword2, $aInvAddress, $aDelAddress )
00897 {
00898
00899 $this->_checkLogin( $sLogin, $aInvAddress );
00900
00901
00902 $this->_checkEmail( $sLogin );
00903
00904
00905 $this->_checkPassword( $sPassword, $sPassword2, ((int) oxConfig::getParameter( 'option' ) == 3) );
00906
00907
00908 $this->_checkRequiredFields( $aInvAddress, $aDelAddress );
00909
00910
00911 $this->_checkVatId( $aInvAddress );
00912 }
00913
00922 public function setNewsSubscription( $blSubscribe, $blSendOptIn )
00923 {
00924
00925 $blSuccess = false;
00926 $myConfig = $this->getConfig();
00927
00928
00929 $oNewsSubscription = $this->getNewsSubscription();
00930 if ( $blSubscribe && $oNewsSubscription->getOptInStatus() != 1 ) {
00931 if ( !$blSendOptIn ) {
00932
00933
00934 $this->addToGroup( 'oxidnewsletter' );
00935
00936 $oNewsSubscription->setOptInStatus( 1 );
00937 $blSuccess = true;
00938 } else {
00939
00940
00941 $oNewsSubscription->setOptInStatus( 2 );
00942
00943
00944 $oEmail = oxNew( 'oxemail' );
00945 $blSuccess = $oEmail->sendNewsletterDBOptInMail( $this );
00946 }
00947 } elseif ( !$blSubscribe ) {
00948 $this->removeFromGroup( 'oxidnewsletter' );
00949 $oNewsSubscription->setOptInStatus( 0 );
00950 $blSuccess = true;
00951 }
00952
00953 return $blSuccess;
00954 }
00955
00973 public function changeUserData( $sUser, $sPassword, $sPassword2, $aInvAddress, $aDelAddress )
00974 {
00975
00976
00977 $this->checkValues( $sUser, $sPassword, $sPassword2, $aInvAddress, $aDelAddress );
00978
00979
00980 $this->assign( $aInvAddress );
00981
00982
00983
00984 $this->_assignAddress( $aDelAddress );
00985
00986
00987 if ( $this->save() ) {
00988
00989
00990 $sCountryId = isset( $aInvAddress['oxuser__oxcountryid'] )?$aInvAddress['oxuser__oxcountryid']:'';
00991 $this->_setAutoGroups( $sCountryId );
00992 }
00993 }
00994
01003 public function addUserAddress( $oUser )
01004 {
01005
01006 if ( $this->_hasUserAddress( $oUser->getId() ) ) {
01007 return false;
01008 }
01009
01010 $oAddress = oxNew( 'oxbase' );
01011 $oAddress->init( 'oxaddress' );
01012
01013 $oAddress->oxaddress__oxuserid = new oxField($this->getId(), oxField::T_RAW);
01014 $oAddress->oxaddress__oxaddressuserid = new oxField($oUser->getId(), oxField::T_RAW);
01015 $oAddress->oxaddress__oxfname = new oxField($oUser->oxuser__oxfname->value, oxField::T_RAW);
01016 $oAddress->oxaddress__oxlname = new oxField($oUser->oxuser__oxlname->value, oxField::T_RAW);
01017 $oAddress->oxaddress__oxstreet = new oxField($oUser->oxuser__oxstreet->value, oxField::T_RAW);
01018 $oAddress->oxaddress__oxstreetnr = new oxField($oUser->oxuser__oxstreetnr->value, oxField::T_RAW);
01019 $oAddress->oxaddress__oxcity = new oxField($oUser->oxuser__oxcity->value, oxField::T_RAW);
01020 $oAddress->oxaddress__oxzip = new oxField($oUser->oxuser__oxzip->value, oxField::T_RAW);
01021 $oAddress->oxaddress__oxcountry = new oxField($oUser->oxuser__oxcountry->value, oxField::T_RAW);
01022 $oAddress->oxaddress__oxcountryid = new oxField($oUser->oxuser__oxcountryid->value, oxField::T_RAW);
01023 $oAddress->oxaddress__oxcompany = new oxField($oUser->oxuser__oxcompany->value, oxField::T_RAW);
01024
01025
01026 if ( $oAddress->save() ) {
01027
01028 $this->_oAddresses = null;
01029 return $oAddress->getId();
01030 }
01031 }
01032
01040 protected function _assignAddress( $aDelAddress )
01041 {
01042 if ( ( isset( $aDelAddress['oxaddress__oxfname'] ) && $aDelAddress['oxaddress__oxfname'] ) ||
01043 ( isset( $aDelAddress['oxaddress__oxlname'] ) && $aDelAddress['oxaddress__oxlname'] ) ) {
01044
01045 $sAddressId = oxConfig::getParameter( 'oxaddressid' );
01046 $aDelAddress['oxaddress__oxid'] = ( $sAddressId === null || $sAddressId == -1 || $sAddressId == -2 ) ? null : $sAddressId;
01047
01048 $oAddress = oxNew( 'oxbase' );
01049 $oAddress->init( 'oxaddress' );
01050 $oAddress->assign( $aDelAddress );
01051 $oAddress->oxaddress__oxuserid = new oxField( $this->getId(), oxField::T_RAW );
01052 $oAddress->oxaddress__oxcountry = $this->getUserCountry( $oAddress->oxaddress__oxcountryid->value );
01053 $oAddress->save();
01054
01055
01056 $this->_oAddresses = null;
01057
01058
01059 oxSession::setVar( 'deladrid', $oAddress->getId() );
01060 } else {
01061
01062 oxSession::setVar( 'deladrid', null );
01063 }
01064 }
01065
01078 public function login( $sUser, $sPassword, $blCookie = false)
01079 {
01080 if ( $this->isAdmin() && !count( oxUtilsServer::getInstance()->getOxCookie() ) ) {
01081 $oEx = oxNew( 'oxCookieException' );
01082 $oEx->setMessage( 'EXCEPTION_COOKIE_NOCOOKIE' );
01083 throw $oEx;
01084 }
01085
01086 $myConfig = $this->getConfig();
01087 if ( $sPassword ) {
01088
01089 $sShopID = $myConfig->getShopId();
01090 $oDb = oxDb::getDb();
01091
01092 $sUserSelect = is_numeric( $sUser ) ? "oxuser.oxcustnr = {$sUser} " : "oxuser.oxusername = " . $oDb->quote( $sUser );
01093 $sPassSelect = " oxuser.oxpassword = MD5( CONCAT( ".$oDb->quote( $sPassword ).", UNHEX( oxuser.oxpasssalt ) ) ) ";
01094 $sShopSelect = "";
01095
01096
01097
01098 if ( $this->isAdmin() ) {
01099 $sShopSelect = " and ( oxrights != 'user' ) ";
01100 }
01101
01102 $sWhat = "oxid";
01103
01104 $sSelect = "select $sWhat from oxuser where oxuser.oxactive = 1 and {$sPassSelect} and {$sUserSelect} {$sShopSelect} ";
01105 if ( $myConfig->isDemoShop() && $this->isAdmin() ) {
01106 if ( $sPassword == "admin" && $sUser == "admin" ) {
01107 $sSelect = "select $sWhat from oxuser where oxrights = 'malladmin' {$sShopSelect} ";
01108 } else {
01109 $oEx = oxNew( 'oxUserException' );
01110 $oEx->setMessage( 'EXCEPTION_USER_NOVALIDLOGIN' );
01111 throw $oEx;
01112 }
01113 }
01114
01115
01116 $aData = $oDb->getAll( $sSelect );
01117 $sOXID = @$aData[0][0];
01118 if ( isset( $sOXID ) && $sOXID && !@$aData[0][1] ) {
01119
01120 if ( !$this->load( $sOXID ) ) {
01121 $oEx = oxNew( 'oxUserException' );
01122 $oEx->setMessage( 'EXCEPTION_USER_NOVALIDLOGIN' );
01123 throw $oEx;
01124 }
01125 }
01126 }
01127
01128
01129
01130 if ( $this->oxuser__oxid->value ) {
01131 if ( $this->isAdmin() ) {
01132 oxSession::setVar( 'auth', $this->oxuser__oxid->value );
01133 } else {
01134 oxSession::setVar( 'usr', $this->oxuser__oxid->value );
01135 }
01136
01137
01138 if ( $blCookie ) {
01139 oxUtilsServer::getInstance()->setUserCookie( $this->oxuser__oxusername->value, $this->oxuser__oxpassword->value, $myConfig->getShopId() );
01140 }
01141 return true;
01142 } else {
01143 $oEx = oxNew( 'oxUserException' );
01144 $oEx->setMessage( 'EXCEPTION_USER_NOVALIDLOGIN' );
01145 throw $oEx;
01146 }
01147 }
01148
01154 public function logout()
01155 {
01156
01157 oxSession::deleteVar( 'usr' );
01158 oxSession::deleteVar( 'auth' );
01159 oxSession::deleteVar( 'dgr' );
01160 oxSession::deleteVar( 'dynvalue' );
01161 oxSession::deleteVar( 'paymentid' );
01162
01163
01164
01165 oxUtilsServer::getInstance()->deleteUserCookie( $this->getConfig()->getShopID() );
01166
01167
01168 $this->setUser( null );
01169
01170 return true;
01171 }
01172
01179 public function loadAdminUser()
01180 {
01181 return $this->loadActiveUser( true );
01182 }
01183
01192 public function loadActiveUser( $blForceAdmin = false )
01193 {
01194 $myConfig = oxConfig::getInstance();
01195
01196 $blAdmin = $myConfig->isAdmin() || $blForceAdmin;
01197 $oDB = oxDb::getDb();
01198
01199
01200 $sUserID = $blAdmin ? oxSession::getVar( 'auth' ) : oxSession::getVar( 'usr' );
01201 $blFoundInCookie = false;
01202
01203
01204 if ( !$sUserID && !$blAdmin ) {
01205 $sShopID = $myConfig->getShopId();
01206 if ( ( $sSet = oxUtilsServer::getInstance()->getUserCookie( $sShopID ) ) ) {
01207 $aData = explode( '@@@', $sSet );
01208 $sUser = $oDB->quote( $aData[0] );
01209 $sPWD = @$aData[1];
01210
01211 $sSelect = 'select oxid, oxpassword from oxuser where oxuser.oxactive = 1 and oxuser.oxusername = '.$sUser;
01212
01213
01214 $oDB = oxDb::getDb();
01215 $rs = $oDB->execute( $sSelect );
01216 if ( $rs != false && $rs->recordCount() > 0 ) {
01217 while (!$rs->EOF) {
01218 $sTest = crypt( $rs->fields[1], 'ox' );
01219 if ( $sTest == $sPWD ) {
01220
01221 $sUserID = $rs->fields[0];
01222 $blFoundInCookie = true;
01223 break;
01224 }
01225 $rs->moveNext();
01226 }
01227 }
01228 }
01229 }
01230
01231
01232 if ( $sUserID ) {
01233 if ( $this->load( $sUserID ) ) {
01234
01235 if ($blAdmin) {
01236 oxSession::setVar( 'auth', $sUserID );
01237 } else {
01238 oxSession::setVar( 'usr', $sUserID );
01239 }
01240
01241
01242 $this->_blLoadedFromCookie = $blFoundInCookie;
01243 return true;
01244 }
01245 } else {
01246
01247 oxSession::deleteVar( 'usr' );
01248 oxSession::deleteVar( 'auth' );
01249
01250 return false;
01251 }
01252 }
01253
01266 protected function _ldapLogin( $sUser, $sPassword, $sShopID, $sShopSelect)
01267 {
01268 include "oxldap.php";
01269 $myConfig = $this->getConfig();
01270
01271 $aLDAPParams = $myConfig->getConfigParam( 'aLDAPParams' );
01272 $oLDAP = new oxLDAP( $aLDAPParams['HOST'], $aLDAPParams['PORT'] );
01273
01274 $sLDAPKey = oxDb::getDb()->GetOne("select oxldapkey from oxuser where oxuser.oxactive = 1 and oxuser.oxusername = ".oxDb::getDb()->Quote($sUser)." $sShopSelect");
01275 if( isset( $sLDAPKey) && $sLDAPKey) {
01276 $sUser = $sLDAPKey;
01277 }
01278
01279
01280 $oLDAP->login( $sUser, $sPassword, $aLDAPParams['USERQUERY'], $aLDAPParams['BASEDN'], $aLDAPParams['FILTER']);
01281
01282 $aData = $oLDAP->mapData($aLDAPParams['DATAMAP']);
01283 if ( isset( $aData['OXUSERNAME']) && $aData['OXUSERNAME']) {
01284
01285
01286 $sSelect = "select oxid from oxuser where oxuser.oxusername = ".oxDb::getDb()->Quote($aData['OXUSERNAME'])." $sShopSelect";
01287 $sOXID = oxDb::getDb()->GetOne( $sSelect);
01288
01289 if ( !isset( $sOXID) || !$sOXID) {
01290
01291 $this->setId();
01292
01293
01294 foreach ( $aData as $fldname => $value) {
01295 $sField = "oxuser__".strtolower( $fldname);
01296 $this->$sField->setValue($aData[$fldname]);
01297 }
01298
01299 $this->oxuser__oxactive->setValue(1);
01300 $this->oxuser__oxshopid->setValue($sShopID);
01301 $this->oxuser__oxldapkey->setValue($sUser);
01302 $this->oxuser__oxrights->setValue("user");
01303 $this->setPassword( "ldap user" );
01304
01305 $this->save();
01306 } else {
01307 $this->load( $sOXID);
01308 }
01309
01310 } else {
01311 $oEx = oxNew( 'oxUserException' );
01312 $oEx->setMessage('EXCEPTION_USER_NOVALUES');
01313 throw $oEx;
01314 }
01315 }
01316
01323 protected function _getUserRights()
01324 {
01325
01326 if ( !$this->oxuser__oxrights->value )
01327 return 'user';
01328
01329 $oDB = oxDb::getDb();
01330 $myConfig = $this->getConfig();
01331 $sAuthRights = null;
01332
01333
01334 $sAuthUserID = $this->isAdmin()?oxSession::getVar( 'auth' ):null;
01335 $sAuthUserID = $sAuthUserID?$sAuthUserID:oxSession::getVar( 'usr' );
01336 if ( $sAuthUserID ) {
01337 $sAuthUserID = $oDB->quote( $sAuthUserID );
01338 $sAuthRights = $oDB->getOne( 'select oxrights from '.$this->getViewName().' where oxid='.$sAuthUserID );
01339 }
01340
01341
01342 $aRights = array();
01343
01344
01345 if ( $sCurrRights = $oDB->getOne( 'select oxrights from '.$this->getViewName().' where oxid="'.$this->getId().'"' ) ) {
01346 $aRights[] = $sCurrRights;
01347 }
01348 $aRights[] = 'user';
01349
01350 if ( !$sAuthRights || !( $sAuthRights == 'malladmin' || $sAuthRights == $myConfig->getShopId() ) ) {
01351 return current( $aRights );
01352 } elseif ( $sAuthRights == $myConfig->getShopId() ) {
01353 $aRights[] = $sAuthRights;
01354 if ( !in_array( $this->oxuser__oxrights->value, $aRights ) ) {
01355 return current( $aRights );
01356 }
01357 }
01358
01359
01360 return $this->oxuser__oxrights->value;
01361 }
01362
01372 protected function _setRecordNumber( $sMaxField, $aWhere = null ,$iMaxTryCnt = 5 )
01373 {
01374
01375
01376
01377
01378
01379
01380 return parent::_setRecordNumber( $sMaxField, $aWhere, $iMaxTryCnt );
01381 }
01382
01388 protected function _insert()
01389 {
01390
01391
01392 $this->oxuser__oxcreate = new oxField(date( 'Y-m-d H:i:s' ), oxField::T_RAW);
01393
01394 if ( !isset( $this->oxuser__oxboni->value ) ) {
01395 $this->oxuser__oxboni = new oxField($this->getBoni(), oxField::T_RAW);
01396 }
01397
01398 if ( $blInsert = parent::_insert() ) {
01399
01400 if ( !$this->oxuser__oxcustnr->value || !$this->isAdmin() ) {
01401 $this->_setRecordNumber( 'oxcustnr' );
01402 }
01403 }
01404
01405 return $blInsert;
01406 }
01407
01413 protected function _update()
01414 {
01415
01416 if (!$this->oxuser__oxpassword->value && $this->oxuser__oxregister->value < 1) {
01417 $this->_aSkipSaveFields[] = 'oxboni';
01418 }
01419
01420
01421 $this->_aSkipSaveFields[] = 'oxcreate';
01422 if ( !$this->isAdmin() ) {
01423 $this->_aSkipSaveFields[] = 'oxcustnr';
01424 $this->_aSkipSaveFields[] = 'oxrights';
01425 }
01426
01427
01428 if ( ( $blUpdate = parent::_update() ) ) {
01429 $this->getNewsSubscription()->updateSubscription( $this );
01430 }
01431
01432 return $blUpdate;
01433 }
01434
01450 protected function _checkLogin( &$sLogin, $aInvAddress )
01451 {
01452 $myConfig = $this->getConfig();
01453
01454 $sLogin = ( isset( $aInvAddress['oxuser__oxusername'] ) && $aInvAddress['oxuser__oxusername'] )?$aInvAddress['oxuser__oxusername']:$sLogin;
01455
01456
01457
01458 if ( $this->oxuser__oxpassword->value && $sLogin != $this->oxuser__oxusername->value ) {
01459
01460
01461 $sNewPass = isset( $aInvAddress['oxuser__oxpassword'] )?$aInvAddress['oxuser__oxpassword']:oxConfig::getParameter( 'user_password' );
01462 if ( !$sNewPass ) {
01463
01464
01465 $oEx = oxNew( 'oxInputException' );
01466 $oEx->setMessage('EXCEPTION_INPUT_NOTALLFIELDS');
01467 throw $oEx;
01468 } else {
01469
01470
01471 if ( !$this->isSamePassword( $sNewPass ) ) {
01472 $oEx = oxNew( 'oxUserException' );
01473 $oEx->setMessage('EXCEPTION_USER_PWDDONTMATCH');
01474 throw $oEx;
01475 }
01476 }
01477 }
01478
01479 if ( $this->checkIfEmailExists( $sLogin)) {
01480
01481 $oEx = oxNew( 'oxUserException' );
01482 $oEx->setMessage('EXCEPTION_USER_USEREXISTS');
01483 throw $oEx;
01484 }
01485 }
01486
01494 public function checkIfEmailExists( $sEmail )
01495 {
01496 $myConfig = $this->getConfig();
01497 $oDB = oxDb::getDb();
01498 $iShopId = $myConfig->getShopId();
01499 $blExists = false;
01500
01501 $sQ = 'select oxshopid, oxrights, oxpassword from oxuser where oxusername = '. $oDB->quote( $sEmail );
01502 if ( ( $sOxid = $this->getId() ) ) {
01503 $sQ .= " and oxid <> '$sOxid' ";
01504 }
01505
01506 $oRs = $oDB->execute( $sQ );
01507 if ( $oRs != false && $oRs->recordCount() > 0 ) {
01508
01509 if ( $this->_blMallUsers ) {
01510
01511 $blExists = true;
01512 if ( $oRs->fields[1] == 'user' && !$oRs->fields[2] ) {
01513
01514
01515 $blExists = false;
01516 }
01517 } else {
01518
01519 $blExists = false;
01520 while ( !$oRs->EOF ) {
01521 if ( $oRs->fields[1] != 'user' ) {
01522
01523
01524 $blExists = true;
01525 break;
01526 } elseif ( $oRs->fields[0] == $iShopId && $oRs->fields[2] ) {
01527
01528
01529 $blExists = true;
01530 break;
01531 }
01532
01533 $oRs->moveNext();
01534 }
01535 }
01536 }
01537 return $blExists;
01538 }
01539
01547 public function getUserRecommLists( $sOXID = null )
01548 {
01549 if ( !$sOXID )
01550 $sOXID = $this->getId();
01551
01552
01553 $iActPage = (int) oxConfig::getParameter( 'pgNr' );
01554 $iActPage = ($iActPage < 0) ? 0 : $iActPage;
01555
01556
01557 $iNrofCatArticles = $this->getConfig()->getConfigParam( 'iNrofCatArticles' );
01558 $iNrofCatArticles = $iNrofCatArticles ? $iNrofCatArticles : 10;
01559
01560
01561 $oRecommList = oxNew( 'oxlist' );
01562 $oRecommList->init( 'oxrecommlist' );
01563 $oRecommList->setSqlLimit( $iNrofCatArticles * $iActPage, $iNrofCatArticles );
01564 $iShopId = $this->getConfig()->getShopId();
01565 $sSelect = 'select * from oxrecommlists where oxuserid ="'. $sOXID .'" and oxshopid ="'. $iShopId .'"';
01566 $oRecommList->selectString( $sSelect );
01567
01568 return $oRecommList;
01569 }
01570
01578 public function getRecommListsCount( $sOx = null )
01579 {
01580 if ( !$sOx ) {
01581 $sOXID = $this->getId();
01582 }
01583
01584 if ( $this->_iCntRecommLists === null || $sOx ) {
01585 $this->_iCntRecommLists = 0;
01586 $iShopId = $this->getConfig()->getShopId();
01587 $sSelect = 'select count(oxid) from oxrecommlists where oxuserid ="'. $sOXID .'" and oxshopid ="'. $iShopId .'"';
01588 $this->_iCntRecommLists = oxDb::getDb()->getOne( $sSelect );
01589 }
01590 return $this->_iCntRecommLists;
01591 }
01592
01601 protected function _checkEmail( $sEmail )
01602 {
01603
01604 if ( !$sEmail ) {
01605 $oEx = oxNew( 'oxInputException' );
01606 $oEx->setMessage('EXCEPTION_INPUT_NOTALLFIELDS');
01607 throw $oEx;
01608 }
01609
01610
01611 if ( !oxUtils::getInstance()->isValidEmail( $sEmail ) ) {
01612 $oEx = oxNew( 'oxInputException' );
01613 $oEx->setMessage( 'EXCEPTION_INPUT_NOVALIDEMAIL' );
01614 throw $oEx;
01615 }
01616 }
01617
01630 protected function _checkPassword( $sNewPass, $sConfPass, $blCheckLenght = false )
01631 {
01632
01633
01634 if ( $blCheckLenght && strlen( $sNewPass ) < 6 ) {
01635 $oEx = oxNew( 'oxInputException' );
01636 $oEx->setMessage('EXCEPTION_INPUT_PASSTOOSHORT');
01637 throw $oEx;
01638 }
01639
01640
01641 if ( $sNewPass != $sConfPass ) {
01642 $oEx = oxNew( 'oxUserException' );
01643 $oEx->setMessage('EXCEPTION_USER_PWDDONTMATCH');
01644 throw $oEx;
01645 }
01646 }
01647
01659 protected function _checkRequiredFields( $aInvAddress, $aDelAddress )
01660 {
01661
01662 $aMustFields = array( 'oxuser__oxfname',
01663 'oxuser__oxlname',
01664 'oxuser__oxstreetnr',
01665 'oxuser__oxstreet',
01666 'oxuser__oxzip',
01667 'oxuser__oxcity' );
01668
01669
01670 $aMustFillFields = $this->getConfig()->getConfigParam( 'aMustFillFields' );
01671 if ( is_array( $aMustFillFields ) ) {
01672 $aMustFields = $aMustFillFields;
01673 }
01674
01675
01676 $aInvAddress = is_array( $aInvAddress )?$aInvAddress:array();
01677 $aDelAddress = is_array( $aDelAddress )?$aDelAddress:array();
01678
01679
01680 $aFields = array_merge( $aInvAddress, $aDelAddress );
01681
01682
01683 $blCheckDel = false;
01684 if ( count( $aDelAddress ) ) {
01685 $blCheckDel = true;
01686 }
01687
01688
01689 foreach ( $aMustFields as $sMustField ) {
01690
01691
01692 if ( !$blCheckDel && strpos( $sMustField, 'oxaddress__' ) === 0 ) {
01693 continue;
01694 }
01695
01696 if ( !isset( $aFields[$sMustField] ) || ! trim( $aFields[$sMustField] ) ) {
01697 $oEx = oxNew( 'oxInputException' );
01698 $oEx->setMessage('EXCEPTION_INPUT_NOTALLFIELDS');
01699 throw $oEx;
01700 }
01701 }
01702 }
01703
01714 protected function _checkVatId( $aInvAddress )
01715 {
01716
01717 if ( $aInvAddress['oxuser__oxustid'] && $aInvAddress['oxuser__oxcompany'] ) {
01718
01719 if (!($sCountryId = $aInvAddress['oxuser__oxcountryid'])) {
01720
01721 return;
01722 }
01723 $oCountry = oxNew('oxcountry');
01724 if (!$oCountry->load($sCountryId)) {
01725 throw new oxObjectException();
01726 }
01727 if ($oCountry->isForeignCountry() && $oCountry->isInEU()) {
01728 if (strncmp($aInvAddress['oxuser__oxustid'], $oCountry->oxcountry__oxisoalpha2->value, 2)) {
01729 $oEx = oxNew( 'oxInputException' );
01730 $oEx->setMessage( 'VAT_MESSAGE_ID_NOT_VALID' );
01731 throw $oEx;
01732 }
01733 }
01734
01735 }
01736 }
01737
01746 protected function _setAutoGroups( $sCountryId )
01747 {
01748
01749 $blForeigner = true;
01750 $blForeignGroupExists = false;
01751 $blInlandGroupExists = false;
01752
01753 $aHomeCountry = $this->getConfig()->getConfigParam( 'aHomeCountry' );
01754
01755 if ( is_array($aHomeCountry)) {
01756 if (in_array($sCountryId, $aHomeCountry)) {
01757 $blForeigner = false;
01758 }
01759 } elseif ($sCountryId == $aHomeCountry) {
01760 $blForeigner = false;
01761 }
01762
01763 if ( $this->inGroup( 'oxidforeigncustomer' ) ) {
01764 $blForeignGroupExists = true;
01765 if ( !$blForeigner ) {
01766 $this->removeFromGroup( 'oxidforeigncustomer' );
01767 }
01768 }
01769
01770 if ( $this->inGroup( 'oxidnewcustomer' ) ) {
01771 $blInlandGroupExists = true;
01772 if ( $blForeigner ) {
01773 $this->removeFromGroup( 'oxidnewcustomer' );
01774 }
01775 }
01776
01777 if ( !$this->oxuser__oxdisableautogrp->value ) {
01778 if ( !$blForeignGroupExists && $blForeigner ) {
01779 $this->addToGroup( 'oxidforeigncustomer' );
01780 }
01781 if ( !$blInlandGroupExists && !$blForeigner ) {
01782 $this->addToGroup( 'oxidnewcustomer' );
01783 }
01784 }
01785 }
01786
01794 protected function _hasUserAddress( $sUserId )
01795 {
01796
01797 $oAddresses = $this->getUserAddresses();
01798 if ( $oAddresses && count($oAddresses)>0 ) {
01799 $oAddresses->rewind() ;
01800 foreach ($oAddresses as $key => $oAddress) {
01801 if ( $oAddress->oxaddress__oxaddressuserid->value == $sUserId ) {
01802 return true;
01803 }
01804 }
01805 }
01806 return false;
01807 }
01808
01821 protected function _setUserCookie( $sUser, $sPassword, $sShopId = null, $iTimeout = 31536000 )
01822 {
01823 oxUtilsServer::getInstance()->setUserCookie( $sUser, $sPassword, $sShopId, $iTimeout );
01824 }
01825
01835 protected function _deleteUserCookie( $sShopId = null )
01836 {
01837 oxUtilsServer::getInstance()->deleteUserCookie( $sShopId );
01838 }
01839
01849 protected static function _getUserCookie( $sShopId = null )
01850 {
01851 return oxUtilsServer::getInstance()->getUserCookie( $sShopId );
01852 }
01853
01854
01863 public function loadUserByUpdateId( $sUid )
01864 {
01865 $oDb = oxDb::getDb();
01866 $sQ = "select oxid from ".$this->getViewName()." where oxupdateexp >= UNIX_TIMESTAMP() and MD5( CONCAT( oxid, oxshopid, oxupdatekey ) ) = ".$oDb->quote( $sUid );
01867 if ( $sUserId = $oDb->getOne( $sQ ) ) {
01868 return $this->load( $sUserId );
01869 }
01870 }
01871
01879 public function setUpdateKey( $blReset = false )
01880 {
01881 $sUpKey = $blReset ? '' : oxUtilsObject::getInstance()->generateUId();
01882 $iUpTime = $blReset ? 0 : oxUtilsDate::getInstance()->getTime() + $this->getUpdateLinkTerm();
01883
01884
01885 $this->oxuser__oxupdatekey = new oxField( $sUpKey, oxField::T_RAW );
01886
01887
01888 $this->oxuser__oxupdateexp = new oxField( $iUpTime, oxField::T_RAW );
01889
01890
01891 $this->save();
01892 }
01893
01899 public function getUpdateLinkTerm()
01900 {
01901 return 3600 * 6;
01902 }
01903
01911 public function isExpiredUpdateId( $sKey )
01912 {
01913 $oDb = oxDb::getDb();
01914 $sQ = "select 1 from ".$this->getViewName()." where oxupdateexp >= UNIX_TIMESTAMP() and MD5( CONCAT( oxid, oxshopid, oxupdatekey ) ) = ".$oDb->quote( $sKey );
01915 return !( (bool) $oDb->getOne( $sQ ) );
01916 }
01917
01923 public function getUpdateId()
01924 {
01925 if ( $this->_sUpdateKey === null ) {
01926 $this->setUpdateKey();
01927 $this->_sUpdateKey = md5( $this->getId() . $this->oxuser__oxshopid->value . $this->oxuser__oxupdatekey->value );
01928 }
01929 return $this->_sUpdateKey;
01930 }
01931
01939 public function encodePassword( $sPassword, $sSalt )
01940 {
01941 $oDb = oxDb::getDb();
01942 return $oDb->getOne( "select MD5( CONCAT( ".$oDb->quote( $sPassword ).", UNHEX( '{$sSalt}' ) ) )" );
01943 }
01944
01952 public function prepareSalt( $sSalt )
01953 {
01954 return ( $sSalt ? oxDb::getDb()->getOne( "select HEX( '{$sSalt}' )" ) : '' );
01955 }
01956
01964 public function decodeSalt( $sSaltHex )
01965 {
01966 return ( $sSaltHex ? oxDb::getDb()->getOne( "select UNHEX( '{$sSaltHex}' )" ) : '' );
01967 }
01968
01976 public function setPassword( $sPassword = null )
01977 {
01978
01979 $sSalt = $sPassword ? $this->prepareSalt( oxUtilsObject::getInstance()->generateUID() ) : '';
01980
01981
01982 $sPassword = $sPassword ? $this->encodePassword( $sPassword, $sSalt ) : '';
01983
01984 $this->oxuser__oxpassword = new oxField( $sPassword, oxField::T_RAW );
01985 $this->oxuser__oxpasssalt = new oxField( $sSalt, oxField::T_RAW );
01986 }
01987
01995 public function isSamePassword( $sNewPass )
01996 {
01997 return $this->encodePassword( $sNewPass, $this->oxuser__oxpasssalt->value ) == $this->oxuser__oxpassword->value;
01998 }
01999
02005 public function isLoadedFromCookie()
02006 {
02007 return $this->_blLoadedFromCookie;
02008 }
02009
02016 public function getPasswordHash()
02017 {
02018 $sHash = null;
02019 if ( $this->oxuser__oxpassword->value ) {
02020 if ( strpos( $this->oxuser__oxpassword->value, 'ox_' ) === 0 ) {
02021
02022 $this->setPassword( oxUtils::getInstance()->strRem( $this->oxuser__oxpassword->value ) );
02023 } elseif ( strlen( $this->oxuser__oxpassword->value ) < 32 ) {
02024
02025 $this->setPassword( $this->oxuser__oxpassword->value );
02026 }
02027 $sHash = $this->oxuser__oxpassword->value;
02028 }
02029 return $sHash;
02030 }
02031
02040 public static function getAdminUser()
02041 {
02042 return self::getActiveUser( true );
02043 }
02044
02054 public static function getActiveUser( $blForceAdmin = false )
02055 {
02056 $oUser = oxNew( 'oxuser' );
02057 if ( $oUser->loadActiveUser( $blForceAdmin ) ) {
02058 return $oUser;
02059 } else {
02060 return false;
02061 }
02062 }
02063 }