00001 <?php
00002
00008 class oxUser extends oxBase
00009 {
00014 protected $_blDisableShopCheck = true;
00015
00020 protected $_oNewsSubscription = null;
00021
00026 protected $_sCoreTbl = 'oxuser';
00027
00032 protected $_sClassName = 'oxuser';
00033
00039 protected $_aBaskets = array();
00040
00046 protected $_oGroups;
00047
00053 protected $_oAddresses;
00054
00060 protected $_oPayments;
00061
00067 protected $_oRecommList;
00068
00074 protected $_blMallUsers = false;
00075
00081 protected static $_aUserCookie = array();
00082
00088 protected $_iCntNoticeListArticles = null;
00089
00095 protected $_iCntWishListArticles = null;
00096
00102 protected $_iCntRecommLists = null;
00103
00109 protected $_sUpdateKey = null;
00110
00116 protected $_blLoadedFromCookie = null;
00117
00123 public function __construct()
00124 {
00125 $this->setMallUsersStatus( $this->getConfig()->getConfigParam( 'blMallUsers' ) );
00126
00127 parent::__construct();
00128 $this->init( 'oxuser' );
00129 }
00130
00138 public function setMallUsersStatus( $blOn = false )
00139 {
00140 $this->_blMallUsers = $blOn;
00141 }
00142
00150 public function __get( $sParamName )
00151 {
00152
00153 switch ( $sParamName ) {
00154 case 'oGroups':
00155 return $this->_oGroups = $this->getUserGroups();
00156 case 'iCntNoticeListArticles':
00157 return $this->_iCntNoticeListArticles = $this->getNoticeListArtCnt();
00158 case 'iCntWishListArticles':
00159 return $this->_iCntWishListArticles = $this->getWishListArtCnt();
00160 case 'iCntRecommLists':
00161 return $this->_iCntRecommLists = $this->getRecommListsCount();
00162 case 'oAddresses':
00163 return $this->_oAddresses = $this->getUserAddresses();
00164 case 'oPayments':
00165 return $this->_oPayments = $this->getUserPayments();
00166 case 'oxuser__oxcountry':
00167 return $this->oxuser__oxcountry = $this->getUserCountry();
00168 case 'sDBOptin':
00169 return $this->sDBOptin = $this->getNewsSubscription()->getOptInStatus();
00170 case 'sEmailFailed':
00171 return $this->sEmailFailed = $this->getNewsSubscription()->getOptInEmailStatus();
00172 }
00173 }
00174
00180 public function getNewsSubscription()
00181 {
00182 if ( $this->_oNewsSubscription !== null ) {
00183 return $this->_oNewsSubscription;
00184 }
00185
00186 $this->_oNewsSubscription = oxNew( 'oxnewssubscribed' );
00187
00188
00189 if ( !$this->_oNewsSubscription->loadFromUserId( $this->getId() ) ) {
00190 if ( !$this->_oNewsSubscription->loadFromEmail( $this->oxuser__oxusername->value ) ) {
00191
00192
00193 $this->_oNewsSubscription->oxnewssubscribed__oxuserid = new oxField($this->getId(), oxField::T_RAW);
00194 $this->_oNewsSubscription->oxnewssubscribed__oxemail = new oxField($this->oxuser__oxusername->value, oxField::T_RAW);
00195 $this->_oNewsSubscription->oxnewssubscribed__oxsal = new oxField($this->oxuser__oxsal->value, oxField::T_RAW);
00196 $this->_oNewsSubscription->oxnewssubscribed__oxfname = new oxField($this->oxuser__oxfname->value, oxField::T_RAW);
00197 $this->_oNewsSubscription->oxnewssubscribed__oxlname = new oxField($this->oxuser__oxlname->value, oxField::T_RAW);
00198 }
00199 }
00200
00201 return $this->_oNewsSubscription;
00202 }
00203
00213 public function getUserCountry( $sCountryId = null, $iLang = null )
00214 {
00215
00216 if ( !$sCountryId ) {
00217 $sCountryId = $this->oxuser__oxcountryid->value;
00218 }
00219
00220 $sQ = 'select oxtitle'.oxLang::getInstance()->getLanguageTag( $iLang ).' from oxcountry where oxid = "'.$sCountryId.'" ';
00221 $this->oxuser__oxcountry = new oxField( oxDb::getDb()->getOne( $sQ ), oxField::T_RAW);
00222
00223 return $this->oxuser__oxcountry;
00224 }
00225
00233 public function getUserCountryId( $sCountry = null )
00234 {
00235 $sQ = 'select oxid from oxcountry where oxactive = "1" and oxisoalpha2 = "' . $sCountry . '"';
00236 $sCountryId = oxDb::getDb()->getOne( $sQ );
00237
00238 return $sCountryId;
00239 }
00240
00248 public function getUserGroups( $sOXID = null )
00249 {
00250
00251 if ( isset( $this->_oGroups ) ) {
00252 return $this->_oGroups;
00253 }
00254
00255 if ( !$sOXID ) {
00256 $sOXID = $this->getId();
00257 }
00258
00259 $this->_oGroups = oxNew( 'oxlist', 'oxgroups' );
00260
00261
00262 $sSelect = 'select oxgroups.* from oxgroups left join oxobject2group on oxobject2group.oxgroupsid = oxgroups.oxid ';
00263 $sSelect .= 'where oxobject2group.oxobjectid = "'.$sOXID.'" ';
00264 $this->_oGroups->selectString( $sSelect );
00265 return $this->_oGroups;
00266 }
00267
00275 public function getUserAddresses( $sOXID = null )
00276 {
00277
00278 if ( isset( $this->_oAddresses ) ) {
00279 return $this->_oAddresses;
00280 }
00281
00282 if ( !$sOXID ) {
00283 $sOXID = $this->getId();
00284 }
00285
00286
00287 $this->_oAddresses = oxNew( 'oxlist' );
00288 $this->_oAddresses->init( "oxbase", "oxaddress" );
00289 $sSelect = 'select * from oxaddress where oxaddress.oxuserid = "'.$sOXID.'" ';
00290 $this->_oAddresses->selectString( $sSelect );
00291 return $this->_oAddresses;
00292 }
00293
00302 public function getSelectedAddress( $sWishId = false )
00303 {
00304 $sAddressId = oxConfig::getParameter( "oxaddressid");
00305 if ( !$sAddressId ) {
00306 $sAddressId = oxSession::getVar( "deladrid" );
00307 }
00308
00309 if ( $sAddressId ) {
00310 $sWishId = null;
00311 }
00312
00313 $oAddresses = $this->getUserAddresses();
00314 if ( $sWishId && $oAddresses->count()) {
00315 foreach ( $oAddresses as $oAddress ) {
00316 $oAddress->selected = 0;
00317 if ( $oAddress->oxaddress__oxaddressuserid->value == $sWishId ) {
00318 $oAddress->selected = 1;
00319 return $oAddress->getId();
00320 }
00321 }
00322 }
00323
00324 if ( !$sAddressId && $oAddresses->count() ) {
00325 $oAddresses->rewind();
00326 if ( ( $oCurAdress = $oAddresses->current() ) ) {
00327 $sAddressId = $oCurAdress->getId();
00328 }
00329 }
00330
00331
00332 if ( $sAddressId ) {
00333 foreach ( $oAddresses as $oAddress ) {
00334 $oAddress->selected = 0;
00335 if ( $oAddress->getId() == $sAddressId ) {
00336 $oAddress->selected = 1;
00337 break;
00338 }
00339 }
00340 }
00341
00342 return $sAddressId;
00343 }
00344
00352 public function getUserPayments( $sOXID = null )
00353 {
00354 if ( $this->_oPayments === null ) {
00355
00356 if ( !$sOXID ) {
00357 $sOXID = $this->getId();
00358 }
00359
00360 $sSelect = 'select * from oxuserpayments where oxuserid ="'. $sOXID .'"';
00361
00362 $this->_oPayments = oxNew( 'oxlist' );
00363 $this->_oPayments->init( 'oxUserPayment' );
00364 $this->_oPayments->selectString( $sSelect );
00365
00366 $myUtils = oxUtils::getInstance();
00367 foreach ( $this->_oPayments as $oPayment ) {
00368
00369 $oPayment = $myUtils->assignValuesFromText( $val->oxuserpayments__oxvalue->value );
00370 }
00371 }
00372
00373 return $this->_oPayments;
00374 }
00375
00381 public function save()
00382 {
00383
00384 $blAddRemark = false;
00385 if ( $this->oxuser__oxpassword->value && $this->oxuser__oxregister->value < 1 ) {
00386 $blAddRemark = true;
00387
00388 $this->oxuser__oxregister = new oxField(date( 'Y-m-d H:i:s' ), oxField::T_RAW);
00389 }
00390
00391
00392 $this->oxuser__oxrights = new oxField($this->_getUserRights(), oxField::T_RAW);
00393
00394
00395 if ( is_array( $this->oxuser__oxbirthdate->value ) ) {
00396 $this->oxuser__oxbirthdate = new oxField($this->convertBirthday( $this->oxuser__oxbirthdate->value ), oxField::T_RAW);
00397 }
00398
00399 $blRet = parent::save();
00400
00401
00402 if ( $blAddRemark && $blRet ) {
00403 $oRemark = oxNew( 'oxremark' );
00404 $oRemark->oxremark__oxtext = new oxField(oxLang::getInstance()->translateString( 'usrRegistered' ), oxField::T_RAW);
00405 $oRemark->oxremark__oxparentid = new oxField($this->getId(), oxField::T_RAW);
00406 $oRemark->save();
00407 }
00408
00409 return $blRet;
00410 }
00411
00417 public function allowDerivedUpdate()
00418 {
00419 return true;
00420 }
00421
00429 public function inGroup( $sGroupID )
00430 {
00431 $blIn = false;
00432 if ( ( $oGroups = $this->getUserGroups() ) ) {
00433 $blIn = isset( $oGroups[ $sGroupID ] );
00434 }
00435
00436 return $blIn;
00437 }
00438
00447 public function delete( $sOXID = null )
00448 {
00449
00450 if ( !$sOXID ) {
00451 $sOXID = $this->getId();
00452 }
00453 if ( !$sOXID ) {
00454 return false;
00455 }
00456
00457 $blDeleted = parent::delete( $sOXID );
00458
00459 if ( $blDeleted ) {
00460 $oDB = oxDb::getDb();
00461
00462
00463 $rs = $oDB->execute( 'delete from oxuserpayments where oxuserpayments.oxuserid = "'.$sOXID.'" ' );
00464 $rs = $oDB->execute( 'delete from oxaddress where oxaddress.oxuserid = "'.$sOXID.'" ' );
00465 $rs = $oDB->execute( 'delete from oxobject2group where oxobject2group.oxobjectid = "'.$sOXID.'" ');
00466 $rs = $oDB->execute( 'delete from oxremark where oxparentid = "'.$sOXID.'" ' );
00467
00468
00469 $rs = $oDB->execute( 'delete oxuserbasketitems.* from oxuserbasketitems, oxuserbaskets where oxuserbasketitems.oxbasketid = oxuserbaskets.oxid and oxuserid = "'.$sOXID.'" ' );
00470 $rs = $oDB->execute( 'delete from oxuserbaskets where oxuserid = "'.$sOXID.'" ' );
00471
00472
00473 $rs = $oDB->execute( 'delete from oxnewssubscribed where oxuserid = "'.$sOXID.'" ');
00474
00475 $blDeleted = $rs->EOF;
00476 }
00477
00478 return $blDeleted;
00479 }
00480
00488 public function load( $oxID )
00489 {
00490
00491 $blRet = parent::Load( $oxID );
00492
00493
00494 if ( isset( $this->oxuser__oxcreate->value ) ) {
00495 $this->oxuser__oxcreate->setValue(oxUtilsDate::getInstance()->formatDBDate( $this->oxuser__oxcreate->value ));
00496 }
00497
00498 return $blRet;
00499 }
00500
00508 public function exists( $sOXID = null )
00509 {
00510 if ( !$sOXID ) {
00511 $sOXID = $this->getId();
00512 }
00513
00514 $sSelect = 'SELECT oxid FROM '.$this->getViewName().'
00515 WHERE ( oxusername = "'.$this->oxuser__oxusername->value.'"';
00516
00517 if ( $sOXID ) {
00518 $sSelect.= " or oxid = '$sOXID' ) ";
00519 } else {
00520 $sSelect.= ' ) ';
00521 }
00522
00523 if ( !$this->_blMallUsers && $this->oxuser__oxrights->value != 'malladmin') {
00524 $sSelect .= ' AND oxshopid = "'.$this->getConfig()->getShopId().'" ';
00525 }
00526
00527 $blExists = false;
00528 if ( ( $sOxid = oxDb::getDb()->getOne( $sSelect ) ) ) {
00529
00530 $this->setId( $sOxid );
00531 $blExists = true;
00532 }
00533 return $blExists;
00534 }
00535
00541 public function getOrders()
00542 {
00543 $myConfig = $this->getConfig();
00544 $oOrders = oxNew( 'oxlist' );
00545 $oOrders->init( 'oxorder' );
00546
00547
00548
00549
00550
00551
00552
00553
00554 if ( $this->oxuser__oxregister->value > 1 ) {
00555 $sQ = 'select * from oxorder where oxuserid = "'.$this->getId().'" and oxorderdate >= "'.$this->oxuser__oxregister->value.'" ';
00556
00557
00558
00559 $sQ .= ' order by oxorderdate desc ';
00560 $oOrders->selectString( $sQ );
00561 }
00562
00563 return $oOrders;
00564 }
00565
00571 public function getOrderCount()
00572 {
00573 $iCnt = 0;
00574 if ( $this->getId() && $this->oxuser__oxregister->value > 1 ) {
00575 $sQ = 'select count(*) from oxorder where oxuserid = "'.$this->getId().'" AND oxorderdate >= "'.$this->oxuser__oxregister->value.'" and oxshopid = "'.$this->getConfig()->getShopId().'" ';
00576 $iCnt = (int) oxDb::getDb()->getOne( $sQ );
00577 }
00578
00579 return $iCnt;
00580 }
00581
00587 public function getNoticeListArtCnt()
00588 {
00589 if ( $this->_iCntNoticeListArticles === null ) {
00590 $this->_iCntNoticeListArticles = 0;
00591 if ( $this->getId() ) {
00592 $this->_iCntNoticeListArticles = $this->getBasket( 'noticelist' )->getItemCount();
00593 }
00594 }
00595 return $this->_iCntNoticeListArticles;
00596 }
00597
00603 public function getWishListArtCnt()
00604 {
00605 if ( $this->_iCntWishListArticles === null ) {
00606 $this->_iCntWishListArticles = false;
00607 if ( $this->getId() ) {
00608 $this->_iCntWishListArticles = $this->getBasket( 'wishlist' )->getItemCount();
00609 }
00610 }
00611 return $this->_iCntWishListArticles;
00612 }
00613
00620 public function getActiveCountry()
00621 {
00622 $sDeliveryCountry = '';
00623 if (!($soxAddressId = oxConfig::getParameter( 'deladrid' ))) {
00624 $soxAddressId = oxSession::getVar( 'deladrid' );
00625 }
00626 if ( $soxAddressId ) {
00627 $oDelAddress = oxNew( 'oxbase' );
00628 $oDelAddress->init( 'oxaddress' );
00629 $oDelAddress->load( $soxAddressId );
00630 $sDeliveryCountry = $oDelAddress->oxaddress__oxcountryid->value;
00631 } elseif ( $this->getId() ) {
00632 $sDeliveryCountry = $this->oxuser__oxcountryid->value;
00633 } else {
00634 $oUser = oxNew( 'oxuser' );
00635 if ( $oUser->loadActiveUser() ) {
00636 $sDeliveryCountry = $oUser->oxuser__oxcountryid->value;
00637 }
00638 }
00639
00640 return $sDeliveryCountry;
00641 }
00642
00650 public function createUser()
00651 {
00652 $oDB = oxDb::getDb();
00653 $sShopID = $this->getConfig()->getShopId();
00654
00655
00656 $sSelect = "select oxid from oxuser where oxusername = '{$this->oxuser__oxusername->value}' and oxpassword = '' ";
00657 if ( !$this->_blMallUsers ) {
00658 $sSelect .= " and oxshopid = '{$sShopID}' ";
00659 }
00660 $sOXID = $oDB->getOne( $sSelect );
00661
00662
00663 if ( isset( $sOXID ) && $sOXID ) {
00664
00665 $this->setId( $sOXID );
00666 } elseif ( $this->_blMallUsers ) {
00667 $sQ = "select oxid from oxuser where oxusername = '{$this->oxuser__oxusername->value}' and oxusername != '' ";
00668 if ( $oDB->getOne( $sQ ) ) {
00669 $oEx = oxNew( 'oxUserException' );
00670 $oLang = oxLang::getInstance();
00671 $oEx->setMessage( sprintf( $oLang->translateString( 'EXCEPTION_USER_USEREXISTS', $oLang->getTplLanguage() ), $this->oxuser__oxusername->value ) );
00672 throw $oEx;
00673 }
00674 }
00675
00676 $this->oxuser__oxshopid = new oxField( $sShopID, oxField::T_RAW );
00677 if ( ( $blOK = $this->save() ) ) {
00678
00679 $oDB->execute( "delete from oxaddress where oxaddress.oxuserid = '{$this->oxuser__oxid->value}' " );
00680 $oDB->execute( "update oxuserpayments set oxuserpayments.oxuserid = '{$this->oxuser__oxusername->value}' where oxuserpayments.oxuserid = '{$this->oxuser__oxid->value}' " );
00681 } else {
00682 $oEx = oxNew( 'oxUserException' );
00683 $oEx->setMessage( 'EXCEPTION_USER_USERCREATIONFAILED' );
00684 throw $oEx;
00685 }
00686
00687 return $blOK;
00688 }
00689
00697 public function addToGroup( $sGroupID )
00698 {
00699 if ( !$this->inGroup( $sGroupID ) ) {
00700 $oNewGroup = oxNew( 'oxobject2group' );
00701 $oNewGroup->oxobject2group__oxobjectid = new oxField($this->getId(), oxField::T_RAW);
00702 $oNewGroup->oxobject2group__oxgroupsid = new oxField($sGroupID, oxField::T_RAW);
00703 if ( $oNewGroup->save() ) {
00704 $this->_oGroups[$sGroupID] = $oNewGroup;
00705 return true;
00706 }
00707 }
00708 return false;
00709 }
00710
00718 public function removeFromGroup( $sGroupID = null )
00719 {
00720 if ( $sGroupID != null && $this->inGroup( $sGroupID ) ) {
00721 $oGroups = oxNew( 'oxlist' );
00722 $oGroups->init( 'oxobject2group' );
00723 $sSelect = 'select * from oxobject2group where oxobject2group.oxobjectid = "'.$this->getId().'" and oxobject2group.oxgroupsid = "'.$sGroupID.'" ';
00724 $oGroups->selectString( $sSelect );
00725 foreach ( $oGroups as $oRemgroup ) {
00726 if ( $oRemgroup->delete() ) {
00727 unset( $this->_oGroups[$oRemgroup->oxobject2group__oxgroupsid->value] );
00728 }
00729 }
00730 }
00731 }
00732
00741 public function onOrderExecute( $oBasket, $iSuccess )
00742 {
00743
00744 if ( is_numeric( $iSuccess ) && $iSuccess != 2 && $iSuccess <= 3 ) {
00745
00746 if ( !$this->oxuser__oxdisableautogrp->value ) {
00747
00748 $myConfig = $this->getConfig();
00749 $dMidlleCustPrice = (float) $myConfig->getConfigParam( 'sMidlleCustPrice' );
00750 $dLargeCustPrice = (float) $myConfig->getConfigParam( 'sLargeCustPrice' );
00751
00752 $this->addToGroup( 'oxidcustomer' );
00753 $dBasketPrice = $oBasket->getPrice()->getBruttoPrice();
00754 if ( $dBasketPrice < $dMidlleCustPrice ) {
00755 $this->addToGroup( 'oxidsmallcust' );
00756 }
00757 if ( $dBasketPrice >= $dMidlleCustPrice && $dBasketPrice < $dLargeCustPrice ) {
00758 $this->addToGroup( 'oxidmiddlecust' );
00759 }
00760 if ( $dBasketPrice >= $dLargeCustPrice ) {
00761 $this->addToGroup( 'oxidgoodcust' );
00762 }
00763 }
00764
00765 if ( $this->inGroup( 'oxidnotyetordered' ) ) {
00766 $this->removeFromGroup( 'oxidnotyetordered' );
00767 }
00768 }
00769 }
00770
00778 public function getBasket( $sName )
00779 {
00780 if ( !isset( $this->_aBaskets[$sName] ) ) {
00781 $oBasket = oxNew( 'oxuserbasket' );
00782 $aWhere = array( 'oxuserbaskets.oxuserid' => $this->getId(), 'oxuserbaskets.oxtitle' => $sName );
00783
00784
00785 if ( !$oBasket->assignRecord( $oBasket->buildSelectString( $aWhere ) ) ) {
00786 $oBasket->oxuserbaskets__oxtitle = new oxField($sName);
00787 $oBasket->oxuserbaskets__oxuserid = new oxField($this->getId());
00788
00789
00790 $oBasket->setIsNewBasket();
00791 }
00792
00793 $this->_aBaskets[$sName] = $oBasket;
00794 }
00795
00796 return $this->_aBaskets[$sName];
00797 }
00798
00807 public function convertBirthday( $aData )
00808 {
00809
00810
00811 $iYear = isset($aData['year'])?((int) $aData['year']):false;
00812 $iMonth = isset($aData['month'])?((int) $aData['month']):false;
00813 $iDay = isset($aData['day'])?((int) $aData['day']):false;
00814
00815
00816 if ( !$iYear && !$iMonth && !$iDay )
00817 return "";
00818
00819
00820 if ( !$iYear || $iYear < 1000 || $iYear > 9999)
00821 $iYear = date('Y');
00822
00823
00824 if ( !$iMonth || $iMonth < 1 || $iMonth > 12)
00825 $iMonth = 1;
00826
00827
00828 $iMaxDays = 31;
00829 switch( $iMonth) {
00830 case 2 :
00831 if ($iMaxDays > 28)
00832 $iMaxDays = ($iYear % 4 == 0 && ($iYear % 100 != 0 || $iYear % 400 == 0)) ? 29 : 28;
00833 break;
00834 case 4 :
00835 case 6 :
00836 case 9 :
00837 case 11 :
00838 $iMaxDays = min(30, $iMaxDays);
00839 break;
00840 }
00841
00842
00843 if ( !$iDay || $iDay < 1 || $iDay > $iMaxDays) {
00844 $iDay = 1;
00845 }
00846
00847
00848 return sprintf("%04d-%02d-%02d", $iYear, $iMonth, $iDay);
00849 }
00850
00857 public function getBoni()
00858 {
00859 return 1000;
00860 }
00861
00874 public function addDynGroup( $sDynGoup, $aDeniedDynGroups )
00875 {
00876
00877 $sDynGoup = strtolower( trim( $sDynGoup ) );
00878
00879
00880 $aDisabledDynGroups = array_merge( array( 'oxidadmin' ), (array) $aDeniedDynGroups );
00881
00882
00883 $blAdd = false;
00884
00885
00886 if ( $this->oxuser__oxdisableautogrp->value || !$sDynGoup ) {
00887 $blAdd = false;
00888 } elseif ( in_array( $sDynGoup, $aDisabledDynGroups ) ) {
00889
00890 $blAdd = false;
00891 } elseif ( $this->addToGroup( $sDynGoup ) ) {
00892 $blAdd = true;
00893 }
00894
00895
00896 oxSession::deleteVar( 'dgr' );
00897
00898 return $blAdd;
00899 }
00900
00916 public function checkValues( $sLogin, $sPassword, $sPassword2, $aInvAddress, $aDelAddress )
00917 {
00918
00919 $this->_checkLogin( $sLogin, $aInvAddress );
00920
00921
00922 $this->_checkEmail( $sLogin );
00923
00924
00925 $this->_checkPassword( $sPassword, $sPassword2, ((int) oxConfig::getParameter( 'option' ) == 3) );
00926
00927
00928 $this->_checkRequiredFields( $aInvAddress, $aDelAddress );
00929
00930
00931 $this->_checkVatId( $aInvAddress );
00932 }
00933
00942 public function setNewsSubscription( $blSubscribe, $blSendOptIn )
00943 {
00944
00945 $blSuccess = false;
00946 $myConfig = $this->getConfig();
00947
00948
00949 $oNewsSubscription = $this->getNewsSubscription();
00950 if ( $blSubscribe && $oNewsSubscription->getOptInStatus() != 1 ) {
00951 if ( !$blSendOptIn ) {
00952
00953
00954 $this->addToGroup( 'oxidnewsletter' );
00955
00956 $oNewsSubscription->setOptInStatus( 1 );
00957 $blSuccess = true;
00958 } else {
00959
00960
00961 $oNewsSubscription->setOptInStatus( 2 );
00962
00963
00964 $oEmail = oxNew( 'oxemail' );
00965 $blSuccess = $oEmail->sendNewsletterDBOptInMail( $this );
00966 }
00967 } elseif ( !$blSubscribe ) {
00968 $this->removeFromGroup( 'oxidnewsletter' );
00969 $oNewsSubscription->setOptInStatus( 0 );
00970 $blSuccess = true;
00971 }
00972
00973 return $blSuccess;
00974 }
00975
00993 public function changeUserData( $sUser, $sPassword, $sPassword2, $aInvAddress, $aDelAddress )
00994 {
00995
00996
00997 $this->checkValues( $sUser, $sPassword, $sPassword2, $aInvAddress, $aDelAddress );
00998
00999
01000 $this->assign( $aInvAddress );
01001
01002
01003
01004 $this->_assignAddress( $aDelAddress );
01005
01006
01007 if ( $this->save() ) {
01008
01009
01010 $sCountryId = isset( $aInvAddress['oxuser__oxcountryid'] )?$aInvAddress['oxuser__oxcountryid']:'';
01011 $this->_setAutoGroups( $sCountryId );
01012 }
01013 }
01014
01023 public function addUserAddress( $oUser )
01024 {
01025
01026 if ( $this->_hasUserAddress( $oUser->getId() ) ) {
01027 return false;
01028 }
01029
01030 $oAddress = oxNew( 'oxbase' );
01031 $oAddress->init( 'oxaddress' );
01032
01033 $oAddress->oxaddress__oxuserid = new oxField($this->getId(), oxField::T_RAW);
01034 $oAddress->oxaddress__oxaddressuserid = new oxField($oUser->getId(), oxField::T_RAW);
01035 $oAddress->oxaddress__oxfname = new oxField($oUser->oxuser__oxfname->value, oxField::T_RAW);
01036 $oAddress->oxaddress__oxlname = new oxField($oUser->oxuser__oxlname->value, oxField::T_RAW);
01037 $oAddress->oxaddress__oxstreet = new oxField($oUser->oxuser__oxstreet->value, oxField::T_RAW);
01038 $oAddress->oxaddress__oxstreetnr = new oxField($oUser->oxuser__oxstreetnr->value, oxField::T_RAW);
01039 $oAddress->oxaddress__oxcity = new oxField($oUser->oxuser__oxcity->value, oxField::T_RAW);
01040 $oAddress->oxaddress__oxzip = new oxField($oUser->oxuser__oxzip->value, oxField::T_RAW);
01041 $oAddress->oxaddress__oxcountry = new oxField($oUser->oxuser__oxcountry->value, oxField::T_RAW);
01042 $oAddress->oxaddress__oxcountryid = new oxField($oUser->oxuser__oxcountryid->value, oxField::T_RAW);
01043 $oAddress->oxaddress__oxcompany = new oxField($oUser->oxuser__oxcompany->value, oxField::T_RAW);
01044
01045
01046 if ( $oAddress->save() ) {
01047
01048 $this->_oAddresses = null;
01049 return $oAddress->getId();
01050 }
01051 }
01052
01060 protected function _assignAddress( $aDelAddress )
01061 {
01062 if ( ( isset( $aDelAddress['oxaddress__oxfname'] ) && $aDelAddress['oxaddress__oxfname'] ) ||
01063 ( isset( $aDelAddress['oxaddress__oxlname'] ) && $aDelAddress['oxaddress__oxlname'] ) ) {
01064
01065 $sAddressId = oxConfig::getParameter( 'oxaddressid' );
01066 $aDelAddress['oxaddress__oxid'] = ( $sAddressId === null || $sAddressId == -1 || $sAddressId == -2 ) ? null : $sAddressId;
01067
01068 $oAddress = oxNew( 'oxbase' );
01069 $oAddress->init( 'oxaddress' );
01070 $oAddress->assign( $aDelAddress );
01071 $oAddress->oxaddress__oxuserid = new oxField( $this->getId(), oxField::T_RAW );
01072 $oAddress->oxaddress__oxcountry = $this->getUserCountry( $oAddress->oxaddress__oxcountryid->value );
01073 $oAddress->save();
01074
01075
01076 $this->_oAddresses = null;
01077
01078
01079 oxSession::setVar( 'deladrid', $oAddress->getId() );
01080 } else {
01081
01082 oxSession::setVar( 'deladrid', null );
01083 }
01084 }
01085
01098 public function login( $sUser, $sPassword, $blCookie = false)
01099 {
01100 if ( $this->isAdmin() && !count( oxUtilsServer::getInstance()->getOxCookie() ) ) {
01101 $oEx = oxNew( 'oxCookieException' );
01102 $oEx->setMessage( 'EXCEPTION_COOKIE_NOCOOKIE' );
01103 throw $oEx;
01104 }
01105
01106 $myConfig = $this->getConfig();
01107 if ( $sPassword ) {
01108
01109 $sShopID = $myConfig->getShopId();
01110 $oDb = oxDb::getDb();
01111
01112 $sUserSelect = is_numeric( $sUser ) ? "oxuser.oxcustnr = {$sUser} " : "oxuser.oxusername = " . $oDb->quote( $sUser );
01113 $sPassSelect = " oxuser.oxpassword = MD5( CONCAT( ".$oDb->quote( $sPassword ).", UNHEX( oxuser.oxpasssalt ) ) ) ";
01114 $sShopSelect = "";
01115
01116
01117
01118 if ( $this->isAdmin() ) {
01119 $sShopSelect = " and ( oxrights != 'user' ) ";
01120 }
01121
01122 $sWhat = "oxid";
01123
01124 $sSelect = "select $sWhat from oxuser where oxuser.oxactive = 1 and {$sPassSelect} and {$sUserSelect} {$sShopSelect} ";
01125 if ( $myConfig->isDemoShop() && $this->isAdmin() ) {
01126 if ( $sPassword == "admin" && $sUser == "admin" ) {
01127 $sSelect = "select $sWhat from oxuser where oxrights = 'malladmin' {$sShopSelect} ";
01128 } else {
01129 $oEx = oxNew( 'oxUserException' );
01130 $oEx->setMessage( 'EXCEPTION_USER_NOVALIDLOGIN' );
01131 throw $oEx;
01132 }
01133 }
01134
01135
01136 $aData = $oDb->getAll( $sSelect );
01137 $sOXID = @$aData[0][0];
01138 if ( isset( $sOXID ) && $sOXID && !@$aData[0][1] ) {
01139
01140 if ( !$this->load( $sOXID ) ) {
01141 $oEx = oxNew( 'oxUserException' );
01142 $oEx->setMessage( 'EXCEPTION_USER_NOVALIDLOGIN' );
01143 throw $oEx;
01144 }
01145 }
01146 }
01147
01148
01149
01150 if ( $this->oxuser__oxid->value ) {
01151 if ( $this->isAdmin() ) {
01152 oxSession::setVar( 'auth', $this->oxuser__oxid->value );
01153 } else {
01154 oxSession::setVar( 'usr', $this->oxuser__oxid->value );
01155 }
01156
01157
01158 if ( $blCookie ) {
01159 oxUtilsServer::getInstance()->setUserCookie( $this->oxuser__oxusername->value, $this->oxuser__oxpassword->value, $myConfig->getShopId() );
01160 }
01161 return true;
01162 } else {
01163 $oEx = oxNew( 'oxUserException' );
01164 $oEx->setMessage( 'EXCEPTION_USER_NOVALIDLOGIN' );
01165 throw $oEx;
01166 }
01167 }
01168
01179 public function openIdLogin( $sUser )
01180 {
01181 $myConfig = $this->getConfig();
01182 $sShopID = $myConfig->getShopId();
01183 $oDb = oxDb::getDb();
01184
01185 $sUserSelect = "oxuser.oxusername = " . $oDb->quote( $sUser );
01186 $sShopSelect = "";
01187
01188
01189 $sSelect = "select oxid from oxuser where oxuser.oxactive = 1 and {$sUserSelect} {$sShopSelect} ";
01190
01191
01192 $aData = $oDb->getAll( $sSelect );
01193 $sOXID = @$aData[0][0];
01194 if ( isset( $sOXID ) && $sOXID && !@$aData[0][1] ) {
01195
01196 if ( !$this->load( $sOXID ) ) {
01197 $oEx = oxNew( 'oxUserException' );
01198 $oEx->setMessage( 'EXCEPTION_USER_NOVALIDLOGIN' );
01199 throw $oEx;
01200 }
01201 }
01202
01203
01204 if ( $this->oxuser__oxid->value ) {
01205 oxSession::setVar( 'usr', $this->oxuser__oxid->value );
01206 return true;
01207 } else {
01208 $oEx = oxNew( 'oxUserException' );
01209 $oEx->setMessage( 'EXCEPTION_USER_NOVALIDLOGIN' );
01210 throw $oEx;
01211 }
01212 }
01213
01219 public function logout()
01220 {
01221
01222 oxSession::deleteVar( 'usr' );
01223 oxSession::deleteVar( 'auth' );
01224 oxSession::deleteVar( 'dgr' );
01225 oxSession::deleteVar( 'dynvalue' );
01226 oxSession::deleteVar( 'paymentid' );
01227
01228
01229
01230 oxUtilsServer::getInstance()->deleteUserCookie( $this->getConfig()->getShopID() );
01231
01232
01233 $this->setUser( null );
01234
01235 return true;
01236 }
01237
01244 public function loadAdminUser()
01245 {
01246 return $this->loadActiveUser( true );
01247 }
01248
01257 public function loadActiveUser( $blForceAdmin = false )
01258 {
01259 $myConfig = $this->getConfig();
01260
01261 $blAdmin = $myConfig->isAdmin() || $blForceAdmin;
01262 $oDB = oxDb::getDb();
01263
01264
01265 $sUserID = $blAdmin ? oxSession::getVar( 'auth' ) : oxSession::getVar( 'usr' );
01266 $blFoundInCookie = false;
01267
01268
01269 if ( !$sUserID && !$blAdmin ) {
01270 $sShopID = $myConfig->getShopId();
01271 if ( ( $sSet = oxUtilsServer::getInstance()->getUserCookie( $sShopID ) ) ) {
01272 $aData = explode( '@@@', $sSet );
01273 $sUser = $oDB->quote( $aData[0] );
01274 $sPWD = @$aData[1];
01275
01276 $sSelect = 'select oxid, oxpassword from oxuser where oxuser.oxpassword != "" and oxuser.oxactive = 1 and oxuser.oxusername = '.$sUser;
01277
01278
01279 $oDB = oxDb::getDb();
01280 $rs = $oDB->execute( $sSelect );
01281 if ( $rs != false && $rs->recordCount() > 0 ) {
01282 while (!$rs->EOF) {
01283 $sTest = crypt( $rs->fields[1], 'ox' );
01284 if ( $sTest == $sPWD ) {
01285
01286 $sUserID = $rs->fields[0];
01287 $blFoundInCookie = true;
01288 break;
01289 }
01290 $rs->moveNext();
01291 }
01292 }
01293 }
01294 }
01295
01296
01297 if ( $sUserID ) {
01298 if ( $this->load( $sUserID ) ) {
01299
01300 if ($blAdmin) {
01301 oxSession::setVar( 'auth', $sUserID );
01302 } else {
01303 oxSession::setVar( 'usr', $sUserID );
01304 }
01305
01306
01307 $this->_blLoadedFromCookie = $blFoundInCookie;
01308 return true;
01309 }
01310 } else {
01311
01312 oxSession::deleteVar( 'usr' );
01313 oxSession::deleteVar( 'auth' );
01314
01315 return false;
01316 }
01317 }
01318
01331 protected function _ldapLogin( $sUser, $sPassword, $sShopID, $sShopSelect)
01332 {
01333 include "oxldap.php";
01334 $myConfig = $this->getConfig();
01335 $oDb = oxDb::getDb();
01336
01337 $aLDAPParams = $myConfig->getConfigParam( 'aLDAPParams' );
01338 $oLDAP = new oxLDAP( $aLDAPParams['HOST'], $aLDAPParams['PORT'] );
01339
01340 $sLDAPKey = $oDb->getOne("select oxldapkey from oxuser where oxuser.oxactive = 1 and oxuser.oxusername = ".$oDb->quote($sUser)." $sShopSelect");
01341 if ( isset( $sLDAPKey) && $sLDAPKey) {
01342 $sUser = $sLDAPKey;
01343 }
01344
01345
01346 $oLDAP->login( $sUser, $sPassword, $aLDAPParams['USERQUERY'], $aLDAPParams['BASEDN'], $aLDAPParams['FILTER']);
01347
01348 $aData = $oLDAP->mapData($aLDAPParams['DATAMAP']);
01349 if ( isset( $aData['OXUSERNAME']) && $aData['OXUSERNAME']) {
01350
01351
01352 $sSelect = "select oxid from oxuser where oxuser.oxusername = ".$oDb->quote($aData['OXUSERNAME'])." $sShopSelect";
01353 $sOXID = $oDb->getOne( $sSelect);
01354
01355 if ( !isset( $sOXID) || !$sOXID) {
01356
01357 $this->setId();
01358
01359
01360 foreach ( $aData as $fldname => $value) {
01361 $sField = "oxuser__".strtolower( $fldname);
01362 $this->$sField->setValue($aData[$fldname]);
01363 }
01364
01365 $this->oxuser__oxactive->setValue(1);
01366 $this->oxuser__oxshopid->setValue($sShopID);
01367 $this->oxuser__oxldapkey->setValue($sUser);
01368 $this->oxuser__oxrights->setValue("user");
01369 $this->setPassword( "ldap user" );
01370
01371 $this->save();
01372 } else {
01373 $this->load( $sOXID);
01374 }
01375
01376 } else {
01377 $oEx = oxNew( 'oxUserException' );
01378 $oEx->setMessage('EXCEPTION_USER_NOVALUES');
01379 throw $oEx;
01380 }
01381 }
01382
01389 protected function _getUserRights()
01390 {
01391
01392 if ( !$this->oxuser__oxrights->value )
01393 return 'user';
01394
01395 $oDB = oxDb::getDb();
01396 $myConfig = $this->getConfig();
01397 $sAuthRights = null;
01398
01399
01400 $sAuthUserID = $this->isAdmin()?oxSession::getVar( 'auth' ):null;
01401 $sAuthUserID = $sAuthUserID?$sAuthUserID:oxSession::getVar( 'usr' );
01402 if ( $sAuthUserID ) {
01403 $sAuthUserID = $oDB->quote( $sAuthUserID );
01404 $sAuthRights = $oDB->getOne( 'select oxrights from '.$this->getViewName().' where oxid='.$sAuthUserID );
01405 }
01406
01407
01408 $aRights = array();
01409
01410
01411 if ( $sCurrRights = $oDB->getOne( 'select oxrights from '.$this->getViewName().' where oxid="'.$this->getId().'"' ) ) {
01412 $aRights[] = $sCurrRights;
01413 }
01414 $aRights[] = 'user';
01415
01416 if ( !$sAuthRights || !( $sAuthRights == 'malladmin' || $sAuthRights == $myConfig->getShopId() ) ) {
01417 return current( $aRights );
01418 } elseif ( $sAuthRights == $myConfig->getShopId() ) {
01419 $aRights[] = $sAuthRights;
01420 if ( !in_array( $this->oxuser__oxrights->value, $aRights ) ) {
01421 return current( $aRights );
01422 }
01423 }
01424
01425
01426 return $this->oxuser__oxrights->value;
01427 }
01428
01438 protected function _setRecordNumber( $sMaxField, $aWhere = null ,$iMaxTryCnt = 5 )
01439 {
01440
01441
01442
01443
01444
01445
01446 return parent::_setRecordNumber( $sMaxField, $aWhere, $iMaxTryCnt );
01447 }
01448
01454 protected function _insert()
01455 {
01456
01457
01458 $this->oxuser__oxcreate = new oxField(date( 'Y-m-d H:i:s' ), oxField::T_RAW);
01459
01460 if ( !isset( $this->oxuser__oxboni->value ) ) {
01461 $this->oxuser__oxboni = new oxField($this->getBoni(), oxField::T_RAW);
01462 }
01463
01464 if ( $blInsert = parent::_insert() ) {
01465
01466 if ( !$this->oxuser__oxcustnr->value || !$this->isAdmin() ) {
01467 $this->_setRecordNumber( 'oxcustnr' );
01468 }
01469 }
01470
01471 return $blInsert;
01472 }
01473
01479 protected function _update()
01480 {
01481
01482 if (!$this->oxuser__oxpassword->value && $this->oxuser__oxregister->value < 1) {
01483 $this->_aSkipSaveFields[] = 'oxboni';
01484 }
01485
01486
01487 $this->_aSkipSaveFields[] = 'oxcreate';
01488 if ( !$this->isAdmin() ) {
01489 $this->_aSkipSaveFields[] = 'oxcustnr';
01490 $this->_aSkipSaveFields[] = 'oxrights';
01491 }
01492
01493
01494 if ( ( $blUpdate = parent::_update() ) ) {
01495 $this->getNewsSubscription()->updateSubscription( $this );
01496 }
01497
01498 return $blUpdate;
01499 }
01500
01516 protected function _checkLogin( &$sLogin, $aInvAddress )
01517 {
01518 $myConfig = $this->getConfig();
01519
01520 $sLogin = ( isset( $aInvAddress['oxuser__oxusername'] ) )?$aInvAddress['oxuser__oxusername']:$sLogin;
01521
01522
01523
01524 if ( $this->oxuser__oxpassword->value && $sLogin != $this->oxuser__oxusername->value ) {
01525
01526
01527 $sNewPass = (isset( $aInvAddress['oxuser__oxpassword']) && $aInvAddress['oxuser__oxpassword'] )?$aInvAddress['oxuser__oxpassword']:oxConfig::getParameter( 'user_password' );
01528 if ( !$sNewPass ) {
01529
01530
01531 $oEx = oxNew( 'oxInputException' );
01532 $oEx->setMessage('EXCEPTION_INPUT_NOTALLFIELDS');
01533 throw $oEx;
01534 } else {
01535
01536
01537 if ( !$this->isSamePassword( $sNewPass ) ) {
01538 $oEx = oxNew( 'oxUserException' );
01539 $oEx->setMessage('EXCEPTION_USER_PWDDONTMATCH');
01540 throw $oEx;
01541 }
01542 }
01543 }
01544
01545 if ( $this->checkIfEmailExists( $sLogin ) ) {
01546
01547 $oEx = oxNew( 'oxUserException' );
01548 $oLang = oxLang::getInstance();
01549 $oEx->setMessage( sprintf( $oLang->translateString( 'EXCEPTION_USER_USEREXISTS', $oLang->getTplLanguage() ), $sLogin ) );
01550 throw $oEx;
01551 }
01552 }
01553
01561 public function checkIfEmailExists( $sEmail )
01562 {
01563 $myConfig = $this->getConfig();
01564 $oDB = oxDb::getDb();
01565 $iShopId = $myConfig->getShopId();
01566 $blExists = false;
01567
01568 $sQ = 'select oxshopid, oxrights, oxpassword from oxuser where oxusername = '. $oDB->quote( $sEmail );
01569 if ( ( $sOxid = $this->getId() ) ) {
01570 $sQ .= " and oxid <> '$sOxid' ";
01571 }
01572
01573 $oRs = $oDB->execute( $sQ );
01574 if ( $oRs != false && $oRs->recordCount() > 0 ) {
01575
01576 if ( $this->_blMallUsers ) {
01577
01578 $blExists = true;
01579 if ( $oRs->fields[1] == 'user' && !$oRs->fields[2] ) {
01580
01581
01582 $blExists = false;
01583 }
01584 } else {
01585
01586 $blExists = false;
01587 while ( !$oRs->EOF ) {
01588 if ( $oRs->fields[1] != 'user' ) {
01589
01590
01591 $blExists = true;
01592 break;
01593 } elseif ( $oRs->fields[0] == $iShopId && $oRs->fields[2] ) {
01594
01595
01596 $blExists = true;
01597 break;
01598 }
01599
01600 $oRs->moveNext();
01601 }
01602 }
01603 }
01604 return $blExists;
01605 }
01606
01614 public function getUserRecommLists( $sOXID = null )
01615 {
01616 if ( !$sOXID )
01617 $sOXID = $this->getId();
01618
01619
01620 $iActPage = (int) oxConfig::getParameter( 'pgNr' );
01621 $iActPage = ($iActPage < 0) ? 0 : $iActPage;
01622
01623
01624 $iNrofCatArticles = $this->getConfig()->getConfigParam( 'iNrofCatArticles' );
01625 $iNrofCatArticles = $iNrofCatArticles ? $iNrofCatArticles : 10;
01626
01627
01628 $oRecommList = oxNew( 'oxlist' );
01629 $oRecommList->init( 'oxrecommlist' );
01630 $oRecommList->setSqlLimit( $iNrofCatArticles * $iActPage, $iNrofCatArticles );
01631 $iShopId = $this->getConfig()->getShopId();
01632 $sSelect = 'select * from oxrecommlists where oxuserid ="'. $sOXID .'" and oxshopid ="'. $iShopId .'"';
01633 $oRecommList->selectString( $sSelect );
01634
01635 return $oRecommList;
01636 }
01637
01645 public function getRecommListsCount( $sOx = null )
01646 {
01647 if ( !$sOx ) {
01648 $sOXID = $this->getId();
01649 }
01650
01651 if ( $this->_iCntRecommLists === null || $sOx ) {
01652 $this->_iCntRecommLists = 0;
01653 $iShopId = $this->getConfig()->getShopId();
01654 $sSelect = 'select count(oxid) from oxrecommlists where oxuserid ="'. $sOXID .'" and oxshopid ="'. $iShopId .'"';
01655 $this->_iCntRecommLists = oxDb::getDb()->getOne( $sSelect );
01656 }
01657 return $this->_iCntRecommLists;
01658 }
01659
01668 protected function _checkEmail( $sEmail )
01669 {
01670
01671 if ( !$sEmail ) {
01672 $oEx = oxNew( 'oxInputException' );
01673 $oEx->setMessage('EXCEPTION_INPUT_NOTALLFIELDS');
01674 throw $oEx;
01675 }
01676
01677
01678 if ( !oxUtils::getInstance()->isValidEmail( $sEmail ) ) {
01679 $oEx = oxNew( 'oxInputException' );
01680 $oEx->setMessage( 'EXCEPTION_INPUT_NOVALIDEMAIL' );
01681 throw $oEx;
01682 }
01683 }
01684
01699 protected function _checkPassword( $sNewPass, $sConfPass, $blCheckLenght = false )
01700 {
01701 $this->checkPassword( $sNewPass, $sConfPass, $blCheckLenght );
01702 }
01703
01716 public function checkPassword( $sNewPass, $sConfPass, $blCheckLenght = false )
01717 {
01718
01719 if ( $blCheckLenght && getStr()->strlen( $sNewPass ) == 0 ) {
01720 $oEx = oxNew( 'oxInputException' );
01721 $oEx->setMessage('EXCEPTION_INPUT_EMPTYPASS');
01722 throw $oEx;
01723 }
01724
01725
01726 if ( $blCheckLenght && getStr()->strlen( $sNewPass ) < 6 ) {
01727 $oEx = oxNew( 'oxInputException' );
01728 $oEx->setMessage('EXCEPTION_INPUT_PASSTOOSHORT');
01729 throw $oEx;
01730 }
01731
01732
01733 if ( $sNewPass != $sConfPass ) {
01734 $oEx = oxNew( 'oxUserException' );
01735 $oEx->setMessage('EXCEPTION_USER_PWDDONTMATCH');
01736 throw $oEx;
01737 }
01738 }
01739
01751 protected function _checkRequiredFields( $aInvAddress, $aDelAddress )
01752 {
01753
01754 $aMustFields = array( 'oxuser__oxfname',
01755 'oxuser__oxlname',
01756 'oxuser__oxstreetnr',
01757 'oxuser__oxstreet',
01758 'oxuser__oxzip',
01759 'oxuser__oxcity' );
01760
01761
01762 $aMustFillFields = $this->getConfig()->getConfigParam( 'aMustFillFields' );
01763 if ( is_array( $aMustFillFields ) ) {
01764 $aMustFields = $aMustFillFields;
01765 }
01766
01767
01768 $aInvAddress = is_array( $aInvAddress )?$aInvAddress:array();
01769 $aDelAddress = is_array( $aDelAddress )?$aDelAddress:array();
01770
01771
01772 $aFields = array_merge( $aInvAddress, $aDelAddress );
01773
01774
01775 $blCheckDel = false;
01776 if ( count( $aDelAddress ) ) {
01777 $blCheckDel = true;
01778 }
01779
01780
01781 foreach ( $aMustFields as $sMustField ) {
01782
01783
01784 if ( !$blCheckDel && strpos( $sMustField, 'oxaddress__' ) === 0 ) {
01785 continue;
01786 }
01787
01788 if ( isset( $aFields[$sMustField] ) && is_array( $aFields[$sMustField] ) ) {
01789 $this->_checkRequiredArrayFields( $sMustField, $aFields[$sMustField] );
01790 } elseif ( !isset( $aFields[$sMustField] ) || !trim( $aFields[$sMustField] ) ) {
01791 $oEx = oxNew( 'oxInputException' );
01792 $oEx->setMessage('EXCEPTION_INPUT_NOTALLFIELDS');
01793 throw $oEx;
01794 }
01795 }
01796 }
01797
01808 protected function _checkRequiredArrayFields( $sFieldName, $aFieldValues )
01809 {
01810 foreach ( $aFieldValues as $sValue ) {
01811 if ( !trim( $sValue ) ) {
01812 $oEx = oxNew( 'oxInputException' );
01813 $oEx->setMessage('EXCEPTION_INPUT_NOTALLFIELDS');
01814 throw $oEx;
01815 }
01816 }
01817 }
01818
01829 protected function _checkVatId( $aInvAddress )
01830 {
01831
01832 if ( $aInvAddress['oxuser__oxustid'] && $aInvAddress['oxuser__oxcompany'] ) {
01833
01834 if (!($sCountryId = $aInvAddress['oxuser__oxcountryid'])) {
01835
01836 return;
01837 }
01838 $oCountry = oxNew('oxcountry');
01839 if (!$oCountry->load($sCountryId)) {
01840 throw new oxObjectException();
01841 }
01842 if ($oCountry->isForeignCountry() && $oCountry->isInEU()) {
01843 if (strncmp($aInvAddress['oxuser__oxustid'], $oCountry->oxcountry__oxisoalpha2->value, 2)) {
01844 $oEx = oxNew( 'oxInputException' );
01845 $oEx->setMessage( 'VAT_MESSAGE_ID_NOT_VALID' );
01846 throw $oEx;
01847 }
01848 }
01849
01850 }
01851 }
01852
01861 protected function _setAutoGroups( $sCountryId )
01862 {
01863
01864 $blForeigner = true;
01865 $blForeignGroupExists = false;
01866 $blInlandGroupExists = false;
01867
01868 $aHomeCountry = $this->getConfig()->getConfigParam( 'aHomeCountry' );
01869
01870 if ( is_array($aHomeCountry)) {
01871 if (in_array($sCountryId, $aHomeCountry)) {
01872 $blForeigner = false;
01873 }
01874 } elseif ($sCountryId == $aHomeCountry) {
01875 $blForeigner = false;
01876 }
01877
01878 if ( $this->inGroup( 'oxidforeigncustomer' ) ) {
01879 $blForeignGroupExists = true;
01880 if ( !$blForeigner ) {
01881 $this->removeFromGroup( 'oxidforeigncustomer' );
01882 }
01883 }
01884
01885 if ( $this->inGroup( 'oxidnewcustomer' ) ) {
01886 $blInlandGroupExists = true;
01887 if ( $blForeigner ) {
01888 $this->removeFromGroup( 'oxidnewcustomer' );
01889 }
01890 }
01891
01892 if ( !$this->oxuser__oxdisableautogrp->value ) {
01893 if ( !$blForeignGroupExists && $blForeigner ) {
01894 $this->addToGroup( 'oxidforeigncustomer' );
01895 }
01896 if ( !$blInlandGroupExists && !$blForeigner ) {
01897 $this->addToGroup( 'oxidnewcustomer' );
01898 }
01899 }
01900 }
01901
01909 protected function _hasUserAddress( $sUserId )
01910 {
01911
01912 $oAddresses = $this->getUserAddresses();
01913 if ( $oAddresses && count($oAddresses)>0 ) {
01914 $oAddresses->rewind() ;
01915 foreach ($oAddresses as $key => $oAddress) {
01916 if ( $oAddress->oxaddress__oxaddressuserid->value == $sUserId ) {
01917 return true;
01918 }
01919 }
01920 }
01921 return false;
01922 }
01923
01936 protected function _setUserCookie( $sUser, $sPassword, $sShopId = null, $iTimeout = 31536000 )
01937 {
01938 oxUtilsServer::getInstance()->setUserCookie( $sUser, $sPassword, $sShopId, $iTimeout );
01939 }
01940
01950 protected function _deleteUserCookie( $sShopId = null )
01951 {
01952 oxUtilsServer::getInstance()->deleteUserCookie( $sShopId );
01953 }
01954
01964 protected static function _getUserCookie( $sShopId = null )
01965 {
01966 return oxUtilsServer::getInstance()->getUserCookie( $sShopId );
01967 }
01968
01969
01978 public function loadUserByUpdateId( $sUid )
01979 {
01980 $oDb = oxDb::getDb();
01981 $sQ = "select oxid from ".$this->getViewName()." where oxupdateexp >= ".time()." and MD5( CONCAT( oxid, oxshopid, oxupdatekey ) ) = ".$oDb->quote( $sUid );
01982 if ( $sUserId = $oDb->getOne( $sQ ) ) {
01983 return $this->load( $sUserId );
01984 }
01985 }
01986
01994 public function setUpdateKey( $blReset = false )
01995 {
01996 $sUpKey = $blReset ? '' : oxUtilsObject::getInstance()->generateUId();
01997 $iUpTime = $blReset ? 0 : oxUtilsDate::getInstance()->getTime() + $this->getUpdateLinkTerm();
01998
01999
02000 $this->oxuser__oxupdatekey = new oxField( $sUpKey, oxField::T_RAW );
02001
02002
02003 $this->oxuser__oxupdateexp = new oxField( $iUpTime, oxField::T_RAW );
02004
02005
02006 $this->save();
02007 }
02008
02014 public function getUpdateLinkTerm()
02015 {
02016 return 3600 * 6;
02017 }
02018
02026 public function isExpiredUpdateId( $sKey )
02027 {
02028 $oDb = oxDb::getDb();
02029 $sQ = "select 1 from ".$this->getViewName()." where oxupdateexp >= ".time()." and MD5( CONCAT( oxid, oxshopid, oxupdatekey ) ) = ".$oDb->quote( $sKey );
02030 return !( (bool) $oDb->getOne( $sQ ) );
02031 }
02032
02038 public function getUpdateId()
02039 {
02040 if ( $this->_sUpdateKey === null ) {
02041 $this->setUpdateKey();
02042 $this->_sUpdateKey = md5( $this->getId() . $this->oxuser__oxshopid->value . $this->oxuser__oxupdatekey->value );
02043 }
02044 return $this->_sUpdateKey;
02045 }
02046
02055 public function encodePassword( $sPassword, $sSalt )
02056 {
02057 $oDb = oxDb::getDb();
02058 return $oDb->getOne( "select MD5( CONCAT( ".$oDb->quote( $sPassword ).", UNHEX( '{$sSalt}' ) ) )" );
02059 }
02060
02068 public function prepareSalt( $sSalt )
02069 {
02070 return ( $sSalt ? oxDb::getDb()->getOne( "select HEX( '{$sSalt}' )" ) : '' );
02071 }
02072
02080 public function decodeSalt( $sSaltHex )
02081 {
02082 return ( $sSaltHex ? oxDb::getDb()->getOne( "select UNHEX( '{$sSaltHex}' )" ) : '' );
02083 }
02084
02092 public function setPassword( $sPassword = null )
02093 {
02094
02095 $sSalt = $sPassword ? $this->prepareSalt( oxUtilsObject::getInstance()->generateUID() ) : '';
02096
02097
02098 $sPassword = $sPassword ? $this->encodePassword( $sPassword, $sSalt ) : '';
02099
02100 $this->oxuser__oxpassword = new oxField( $sPassword, oxField::T_RAW );
02101 $this->oxuser__oxpasssalt = new oxField( $sSalt, oxField::T_RAW );
02102 }
02103
02111 public function isSamePassword( $sNewPass )
02112 {
02113 return $this->encodePassword( $sNewPass, $this->oxuser__oxpasssalt->value ) == $this->oxuser__oxpassword->value;
02114 }
02115
02121 public function isLoadedFromCookie()
02122 {
02123 return $this->_blLoadedFromCookie;
02124 }
02125
02132 public function getPasswordHash()
02133 {
02134 $sHash = null;
02135 if ( $this->oxuser__oxpassword->value ) {
02136 if ( strpos( $this->oxuser__oxpassword->value, 'ox_' ) === 0 ) {
02137
02138 $this->setPassword( oxUtils::getInstance()->strRem( $this->oxuser__oxpassword->value ) );
02139 } elseif ( ( strlen( $this->oxuser__oxpassword->value ) < 32 ) && ( strpos( $this->oxuser__oxpassword->value, 'openid_' ) !== 0 ) ) {
02140
02141 $this->setPassword( $this->oxuser__oxpassword->value );
02142 }
02143 $sHash = $this->oxuser__oxpassword->value;
02144 }
02145 return $sHash;
02146 }
02147
02156 public static function getAdminUser()
02157 {
02158 return self::getActiveUser( true );
02159 }
02160
02171 public static function getActiveUser( $blForceAdmin = false )
02172 {
02173 $oUser = oxNew( 'oxuser' );
02174 if ( $oUser->loadActiveUser( $blForceAdmin ) ) {
02175 return $oUser;
02176 } else {
02177 return false;
02178 }
02179 }
02180
02188 public function getOpenIdPassword( $iLength = 25 )
02189 {
02190 $sPassword= "openid_".substr( oxUtilsObject::getInstance()->generateUId(), 0, $iLength);
02191 return $sPassword;
02192 }
02193
02201 public function getReviewUserHash( $sUserId )
02202 {
02203 $sReviewUserHash = oxDb::getDb()->getOne('select md5(concat("oxid", oxpassword, oxusername )) from oxuser where oxid = "'.$sUserId.'"');
02204 return $sReviewUserHash;
02205 }
02206
02214 public function getReviewUserId( $sReviewUserHash )
02215 {
02216 $sUserId = oxDb::getDb()->getOne('select oxid from oxuser where md5(concat("oxid", oxpassword, oxusername )) = "'.$sReviewUserHash.'"');
02217 return $sUserId;
02218 }
02219 }