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
00236 public function getUserCountryId( $sCountry = null )
00237 {
00238 $sQ = 'select oxid from oxcountry where oxactive = "1" and oxisoalpha2 = "' . $sCountry . '"';
00239 $sCountryId = oxDb::getDb()->GetOne( $sQ );
00240
00241 return $sCountryId;
00242 }
00243
00251 public function getUserGroups( $sOXID = null )
00252 {
00253
00254 if ( isset( $this->_oGroups ) ) {
00255 return $this->_oGroups;
00256 }
00257
00258 if ( !$sOXID ) {
00259 $sOXID = $this->getId();
00260 }
00261
00262 $this->_oGroups = oxNew( 'oxlist', 'oxgroups' );
00263
00264
00265 $sSelect = 'select oxgroups.* from oxgroups left join oxobject2group on oxobject2group.oxgroupsid = oxgroups.oxid ';
00266 $sSelect .= 'where oxobject2group.oxobjectid = "'.$sOXID.'" ';
00267 $this->_oGroups->selectString( $sSelect );
00268 return $this->_oGroups;
00269 }
00270
00278 public function getUserAddresses( $sOXID = null )
00279 {
00280
00281 if ( isset( $this->_oAddresses ) ) {
00282 return $this->_oAddresses;
00283 }
00284
00285 if ( !$sOXID ) {
00286 $sOXID = $this->getId();
00287 }
00288
00289
00290 $this->_oAddresses = oxNew( 'oxlist' );
00291 $this->_oAddresses->init( "oxbase", "oxaddress" );
00292 $sSelect = 'select * from oxaddress where oxaddress.oxuserid = "'.$sOXID.'" ';
00293 $this->_oAddresses->selectString( $sSelect );
00294 return $this->_oAddresses;
00295 }
00296
00305 public function getSelectedAddress( $sWishId = false )
00306 {
00307 $sAddressId = oxConfig::getParameter( "oxaddressid");
00308 if ( !$sAddressId ) {
00309 $sAddressId = oxSession::getVar( "deladrid" );
00310 }
00311
00312 if ( $sAddressId ) {
00313 $sWishId = null;
00314 }
00315
00316 $oAddresses = $this->getUserAddresses();
00317 if ( $sWishId && $oAddresses->count()) {
00318 foreach ( $oAddresses as $oAddress ) {
00319 $oAddress->selected = 0;
00320 if ( $oAddress->oxaddress__oxaddressuserid->value == $sWishId ) {
00321 $oAddress->selected = 1;
00322 return $oAddress->getId();
00323 }
00324 }
00325 }
00326
00327 if ( !$sAddressId && $oAddresses->count() ) {
00328 $oAddresses->rewind();
00329 if ( ( $oCurAdress = $oAddresses->current() ) ) {
00330 $sAddressId = $oCurAdress->getId();
00331 }
00332 }
00333
00334
00335 if ( $sAddressId ) {
00336 foreach ( $oAddresses as $oAddress ) {
00337 $oAddress->selected = 0;
00338 if ( $oAddress->getId() == $sAddressId ) {
00339 $oAddress->selected = 1;
00340 break;
00341 }
00342 }
00343 }
00344
00345 return $sAddressId;
00346 }
00347
00355 public function getUserPayments( $sOXID = null )
00356 {
00357 if ( $this->_oPayments === null ) {
00358
00359 if ( !$sOXID ) {
00360 $sOXID = $this->getId();
00361 }
00362
00363 $sSelect = 'select * from oxuserpayments where oxuserid ="'. $sOXID .'"';
00364
00365 $this->_oPayments = oxNew( 'oxlist' );
00366 $this->_oPayments->init( 'oxUserPayment' );
00367 $this->_oPayments->selectString( $sSelect );
00368
00369
00370 foreach ( $this->_oPayments as $oPayment ) {
00371
00372 $oPayment = oxUtils::getInstance()->assignValuesFromText( $val->oxuserpayments__oxvalue->value );
00373 }
00374 }
00375
00376 return $this->_oPayments;
00377 }
00378
00384 public function save()
00385 {
00386
00387 $blAddRemark = false;
00388 if ( $this->oxuser__oxpassword->value && $this->oxuser__oxregister->value < 1 ) {
00389 $blAddRemark = true;
00390
00391 $this->oxuser__oxregister = new oxField(date( 'Y-m-d H:i:s' ), oxField::T_RAW);
00392 }
00393
00394
00395 $this->oxuser__oxrights = new oxField($this->_getUserRights(), oxField::T_RAW);
00396
00397
00398 if ( is_array( $this->oxuser__oxbirthdate->value ) ) {
00399 $this->oxuser__oxbirthdate = new oxField($this->convertBirthday( $this->oxuser__oxbirthdate->value ), oxField::T_RAW);
00400 }
00401
00402
00403
00404 $blStore = $this->_blIsDerived;
00405 $this->_blIsDerived = false;
00406 $blRet = parent::save();
00407 $this->_blIsDerived = $blStore;
00408
00409
00410 if ( $blAddRemark && $blRet ) {
00411 $oRemark = oxNew( 'oxremark' );
00412 $oRemark->oxremark__oxtext = new oxField(oxLang::getInstance()->translateString( 'usrRegistered' ), oxField::T_RAW);
00413 $oRemark->oxremark__oxparentid = new oxField($this->getId(), oxField::T_RAW);
00414 $oRemark->save();
00415 }
00416
00417 return $blRet;
00418 }
00419
00427 public function inGroup( $sGroupID )
00428 {
00429 $blIn = false;
00430 if( ( $oGroups = $this->getUserGroups() ) ) {
00431 $blIn = isset( $oGroups[ $sGroupID ] );
00432 }
00433
00434 return $blIn;
00435 }
00436
00445 public function delete( $sOXID = null )
00446 {
00447
00448 if ( !$sOXID ) {
00449 $sOXID = $this->getId();
00450 }
00451 if ( !$sOXID ) {
00452 return false;
00453 }
00454
00455 $blDeleted = parent::delete( $sOXID );
00456
00457 if ( $blDeleted ) {
00458 $oDB = oxDb::getDb();
00459
00460
00461 $rs = $oDB->execute( 'delete from oxuserpayments where oxuserpayments.oxuserid = "'.$sOXID.'" ' );
00462 $rs = $oDB->execute( 'delete from oxaddress where oxaddress.oxuserid = "'.$sOXID.'" ' );
00463 $rs = $oDB->execute( 'delete from oxobject2group where oxobject2group.oxobjectid = "'.$sOXID.'" ');
00464 $rs = $oDB->execute( 'delete from oxremark where oxparentid = "'.$sOXID.'" ' );
00465
00466
00467 $rs = $oDB->execute( 'delete oxuserbasketitems.* from oxuserbasketitems, oxuserbaskets where oxuserbasketitems.oxbasketid = oxuserbaskets.oxid and oxuserid = "'.$sOXID.'" ' );
00468 $rs = $oDB->execute( 'delete from oxuserbaskets where oxuserid = "'.$sOXID.'" ' );
00469
00470
00471 $rs = $oDB->execute( 'delete from oxnewssubscribed where oxuserid = "'.$sOXID.'" ');
00472
00473 $blDeleted = $rs->EOF;
00474 }
00475
00476 return $blDeleted;
00477 }
00478
00486 public function load( $oxID )
00487 {
00488
00489 $blRet = parent::Load( $oxID );
00490
00491
00492 if ( isset( $this->oxuser__oxcreate->value ) ) {
00493 $this->oxuser__oxcreate->setValue(oxUtilsDate::getInstance()->formatDBDate( $this->oxuser__oxcreate->value ));
00494 }
00495
00496 return $blRet;
00497 }
00498
00506 public function exists( $sOXID = null )
00507 {
00508 if ( !$sOXID ) {
00509 $sOXID = $this->getId();
00510 }
00511
00512 $sSelect = 'SELECT oxid FROM '.$this->getViewName().'
00513 WHERE ( oxusername = "'.$this->oxuser__oxusername->value.'"';
00514
00515 if ( $sOXID ) {
00516 $sSelect.= " or oxid = '$sOXID' ) ";
00517 } else {
00518 $sSelect.= ' ) ';
00519 }
00520
00521 if ( !$this->_blMallUsers && $this->oxuser__oxrights->value != 'malladmin') {
00522 $sSelect .= ' AND oxshopid = "'.$this->getConfig()->getShopId().'" ';
00523 }
00524
00525 $blExists = false;
00526 if ( ( $sOxid = oxDb::getDb()->getOne( $sSelect ) ) ) {
00527
00528 $this->setId( $sOxid );
00529 $blExists = true;
00530 }
00531 return $blExists;
00532 }
00533
00539 public function getOrders()
00540 {
00541 $myConfig = $this->getConfig();
00542 $oOrders = oxNew( 'oxlist' );
00543 $oOrders->init( 'oxorder' );
00544
00545
00546
00547
00548
00549
00550
00551
00552 if ( $this->oxuser__oxregister->value > 1 ) {
00553 $sQ = 'select * from oxorder where oxuserid = "'.$this->getId().'" and oxorderdate >= "'.$this->oxuser__oxregister->value.'" ';
00554
00555
00556
00557 $sQ .= ' order by oxorderdate desc ';
00558 $oOrders->selectString( $sQ );
00559 }
00560
00561 return $oOrders;
00562 }
00563
00569 public function getOrderCount()
00570 {
00571 $iCnt = 0;
00572 if ( $this->getId() && $this->oxuser__oxregister->value > 1 ) {
00573 $sQ = 'select count(*) from oxorder where oxuserid = "'.$this->getId().'" AND oxorderdate >= "'.$this->oxuser__oxregister->value.'" and oxshopid = "'.$this->getConfig()->getShopId().'" ';
00574 $iCnt = (int) oxDb::getDb()->getOne( $sQ );
00575 }
00576
00577 return $iCnt;
00578 }
00579
00585 public function getNoticeListArtCnt()
00586 {
00587 if ( $this->_iCntNoticeListArticles === null ) {
00588 $this->_iCntNoticeListArticles = 0;
00589 if ( $this->getId() ) {
00590 $this->_iCntNoticeListArticles = $this->getBasket( 'noticelist' )->getItemCount();
00591 }
00592 }
00593 return $this->_iCntNoticeListArticles;
00594 }
00595
00601 public function getWishListArtCnt()
00602 {
00603 if ( $this->_iCntWishListArticles === null ) {
00604 $this->_iCntWishListArticles = false;
00605 if ( $this->getId() ) {
00606 $this->_iCntWishListArticles = $this->getBasket( 'wishlist' )->getItemCount();
00607 }
00608 }
00609 return $this->_iCntWishListArticles;
00610 }
00611
00618 public function getActiveCountry()
00619 {
00620 $sDeliveryCountry = '';
00621 if (!($soxAddressId = oxConfig::getParameter( 'deladrid' ))) {
00622 $soxAddressId = oxSession::getVar( 'deladrid' );
00623 }
00624 if ( $soxAddressId ) {
00625 $oDelAddress = oxNew( 'oxbase' );
00626 $oDelAddress->init( 'oxaddress' );
00627 $oDelAddress->load( $soxAddressId );
00628 $sDeliveryCountry = $oDelAddress->oxaddress__oxcountryid->value;
00629 } elseif ( $this->getId() ) {
00630 $sDeliveryCountry = $this->oxuser__oxcountryid->value;
00631 } else {
00632 $oUser = oxNew( 'oxuser' );
00633 if ( $oUser->loadActiveUser() ) {
00634 $sDeliveryCountry = $oUser->oxuser__oxcountryid->value;
00635 }
00636 }
00637
00638 return $sDeliveryCountry;
00639 }
00640
00648 public function createUser()
00649 {
00650 $oDB = oxDb::getDb();
00651 $sShopID = $this->getConfig()->getShopId();
00652
00653
00654 $sSelect = "select oxid from oxuser where oxusername = '{$this->oxuser__oxusername->value}' and oxpassword = '' ";
00655 if ( !$this->_blMallUsers ) {
00656 $sSelect .= " and oxshopid = '{$sShopID}' ";
00657 }
00658 $sOXID = $oDB->getOne( $sSelect );
00659
00660
00661 if ( isset( $sOXID ) && $sOXID ) {
00662
00663 $this->setId( $sOXID );
00664 } elseif ( $this->_blMallUsers ) {
00665 $sQ = "select oxid from oxuser where oxusername = '{$this->oxuser__oxusername->value}' and oxusername != '' ";
00666 if ( $oDB->getOne( $sQ ) ) {
00667 $oEx = oxNew( 'oxUserException' );
00668 $oLang = oxLang::getInstance();
00669 $oEx->setMessage( sprintf( $oLang->translateString( 'EXCEPTION_USER_USEREXISTS', $oLang->getTplLanguage() ), $this->oxuser__oxusername->value ) );
00670 throw $oEx;
00671 }
00672 }
00673
00674 $this->oxuser__oxshopid = new oxField( $sShopID, oxField::T_RAW );
00675 if ( ( $blOK = $this->save() ) ) {
00676
00677 $oDB->execute( "delete from oxaddress where oxaddress.oxuserid = '{$this->oxuser__oxid->value}' " );
00678 $oDB->execute( "update oxuserpayments set oxuserpayments.oxuserid = '{$this->oxuser__oxusername->value}' where oxuserpayments.oxuserid = '{$this->oxuser__oxid->value}' " );
00679 } else {
00680 $oEx = oxNew( 'oxUserException' );
00681 $oEx->setMessage( 'EXCEPTION_USER_USERCREATIONFAILED' );
00682 throw $oEx;
00683 }
00684
00685 return $blOK;
00686 }
00687
00695 public function addToGroup( $sGroupID )
00696 {
00697 if ( !$this->inGroup( $sGroupID ) ) {
00698 $oNewGroup = oxNew( 'oxobject2group' );
00699 $oNewGroup->oxobject2group__oxobjectid = new oxField($this->getId(), oxField::T_RAW);
00700 $oNewGroup->oxobject2group__oxgroupsid = new oxField($sGroupID, oxField::T_RAW);
00701 if ( $oNewGroup->save() ) {
00702 $this->_oGroups[$sGroupID] = $oNewGroup;
00703 return true;
00704 }
00705 }
00706 return false;
00707 }
00708
00716 public function removeFromGroup( $sGroupID = null )
00717 {
00718 if ( $sGroupID != null && $this->inGroup( $sGroupID ) ) {
00719 $oGroups = oxNew( 'oxlist' );
00720 $oGroups->init( 'oxobject2group' );
00721 $sSelect = 'select * from oxobject2group where oxobject2group.oxobjectid = "'.$this->getId().'" and oxobject2group.oxgroupsid = "'.$sGroupID.'" ';
00722 $oGroups->selectString( $sSelect );
00723 foreach ( $oGroups as $oRemgroup ) {
00724 if ( $oRemgroup->delete() ) {
00725 unset( $this->_oGroups[$oRemgroup->oxobject2group__oxgroupsid->value] );
00726 }
00727 }
00728 }
00729 }
00730
00739 public function onOrderExecute( $oBasket, $iSuccess )
00740 {
00741
00742 if ( is_numeric( $iSuccess ) && $iSuccess != 2 && $iSuccess <= 3 ) {
00743
00744 if ( !$this->oxuser__oxdisableautogrp->value ) {
00745
00746 $myConfig = $this->getConfig();
00747 $dMidlleCustPrice = (float) $myConfig->getConfigParam( 'sMidlleCustPrice' );
00748 $dLargeCustPrice = (float) $myConfig->getConfigParam( 'sLargeCustPrice' );
00749
00750 $this->addToGroup( 'oxidcustomer' );
00751 $dBasketPrice = $oBasket->getPrice()->getBruttoPrice();
00752 if ( $dBasketPrice < $dMidlleCustPrice ) {
00753 $this->addToGroup( 'oxidsmallcust' );
00754 }
00755 if ( $dBasketPrice >= $dMidlleCustPrice && $dBasketPrice < $dLargeCustPrice ) {
00756 $this->addToGroup( 'oxidmiddlecust' );
00757 }
00758 if ( $dBasketPrice >= $dLargeCustPrice ) {
00759 $this->addToGroup( 'oxidgoodcust' );
00760 }
00761 }
00762
00763 if ( $this->inGroup( 'oxidnotyetordered' ) ) {
00764 $this->removeFromGroup( 'oxidnotyetordered' );
00765 }
00766 }
00767 }
00768
00776 public function getBasket( $sName )
00777 {
00778 if ( !isset( $this->_aBaskets[$sName] ) ) {
00779 $oBasket = oxNew( 'oxuserbasket' );
00780 $aWhere = array( 'oxuserbaskets.oxuserid' => $this->getId(), 'oxuserbaskets.oxtitle' => $sName );
00781
00782
00783 if ( !$oBasket->assignRecord( $oBasket->buildSelectString( $aWhere ) ) ) {
00784 $oBasket->oxuserbaskets__oxtitle = new oxField($sName);
00785 $oBasket->oxuserbaskets__oxuserid = new oxField($this->getId());
00786
00787
00788 $oBasket->setIsNewBasket();
00789 }
00790
00791 $this->_aBaskets[$sName] = $oBasket;
00792 }
00793
00794 return $this->_aBaskets[$sName];
00795 }
00796
00805 public function convertBirthday( $aData )
00806 {
00807
00808
00809 $iYear = isset($aData['year'])?((int) $aData['year']):false;
00810 $iMonth = isset($aData['month'])?((int) $aData['month']):false;
00811 $iDay = isset($aData['day'])?((int) $aData['day']):false;
00812
00813
00814 if ( !$iYear && !$iMonth && !$iDay )
00815 return "";
00816
00817
00818 if ( !$iYear || $iYear < 1000 || $iYear > 9999)
00819 $iYear = date('Y');
00820
00821
00822 if ( !$iMonth || $iMonth < 1 || $iMonth > 12)
00823 $iMonth = 1;
00824
00825
00826 $iMaxDays = 31;
00827 switch( $iMonth) {
00828 case 2 :
00829 if ($iMaxDays > 28)
00830 $iMaxDays = ($iYear % 4 == 0 && ($iYear % 100 != 0 || $iYear % 400 == 0)) ? 29 : 28;
00831 break;
00832 case 4 :
00833 case 6 :
00834 case 9 :
00835 case 11 :
00836 $iMaxDays = min(30, $iMaxDays);
00837 break;
00838 }
00839
00840
00841 if ( !$iDay || $iDay < 1 || $iDay > $iMaxDays) {
00842 $iDay = 1;
00843 }
00844
00845
00846 return sprintf("%04d-%02d-%02d", $iYear, $iMonth, $iDay);
00847 }
00848
00855 public function getBoni()
00856 {
00857 return 1000;
00858 }
00859
00872 public function addDynGroup( $sDynGoup, $aDeniedDynGroups )
00873 {
00874
00875 $sDynGoup = strtolower( trim( $sDynGoup ) );
00876
00877
00878 $aDisabledDynGroups = array_merge( array( 'oxidadmin' ), (array) $aDeniedDynGroups );
00879
00880
00881 $blAdd = false;
00882
00883
00884 if ( $this->oxuser__oxdisableautogrp->value || !$sDynGoup ) {
00885 $blAdd = false;
00886 } elseif ( in_array( $sDynGoup, $aDisabledDynGroups ) ) {
00887
00888 $blAdd = false;
00889 } elseif ( $this->addToGroup( $sDynGoup ) ) {
00890 $blAdd = true;
00891 }
00892
00893
00894 oxSession::deleteVar( 'dgr' );
00895
00896 return $blAdd;
00897 }
00898
00914 public function checkValues( $sLogin, $sPassword, $sPassword2, $aInvAddress, $aDelAddress )
00915 {
00916
00917 $this->_checkLogin( $sLogin, $aInvAddress );
00918
00919
00920 $this->_checkEmail( $sLogin );
00921
00922
00923 $this->_checkPassword( $sPassword, $sPassword2, ((int) oxConfig::getParameter( 'option' ) == 3) );
00924
00925
00926 $this->_checkRequiredFields( $aInvAddress, $aDelAddress );
00927
00928
00929 $this->_checkVatId( $aInvAddress );
00930 }
00931
00940 public function setNewsSubscription( $blSubscribe, $blSendOptIn )
00941 {
00942
00943 $blSuccess = false;
00944 $myConfig = $this->getConfig();
00945
00946
00947 $oNewsSubscription = $this->getNewsSubscription();
00948 if ( $blSubscribe && $oNewsSubscription->getOptInStatus() != 1 ) {
00949 if ( !$blSendOptIn ) {
00950
00951
00952 $this->addToGroup( 'oxidnewsletter' );
00953
00954 $oNewsSubscription->setOptInStatus( 1 );
00955 $blSuccess = true;
00956 } else {
00957
00958
00959 $oNewsSubscription->setOptInStatus( 2 );
00960
00961
00962 $oEmail = oxNew( 'oxemail' );
00963 $blSuccess = $oEmail->sendNewsletterDBOptInMail( $this );
00964 }
00965 } elseif ( !$blSubscribe ) {
00966 $this->removeFromGroup( 'oxidnewsletter' );
00967 $oNewsSubscription->setOptInStatus( 0 );
00968 $blSuccess = true;
00969 }
00970
00971 return $blSuccess;
00972 }
00973
00991 public function changeUserData( $sUser, $sPassword, $sPassword2, $aInvAddress, $aDelAddress )
00992 {
00993
00994
00995 $this->checkValues( $sUser, $sPassword, $sPassword2, $aInvAddress, $aDelAddress );
00996
00997
00998 $this->assign( $aInvAddress );
00999
01000
01001
01002 $this->_assignAddress( $aDelAddress );
01003
01004
01005 if ( $this->save() ) {
01006
01007
01008 $sCountryId = isset( $aInvAddress['oxuser__oxcountryid'] )?$aInvAddress['oxuser__oxcountryid']:'';
01009 $this->_setAutoGroups( $sCountryId );
01010 }
01011 }
01012
01021 public function addUserAddress( $oUser )
01022 {
01023
01024 if ( $this->_hasUserAddress( $oUser->getId() ) ) {
01025 return false;
01026 }
01027
01028 $oAddress = oxNew( 'oxbase' );
01029 $oAddress->init( 'oxaddress' );
01030
01031 $oAddress->oxaddress__oxuserid = new oxField($this->getId(), oxField::T_RAW);
01032 $oAddress->oxaddress__oxaddressuserid = new oxField($oUser->getId(), oxField::T_RAW);
01033 $oAddress->oxaddress__oxfname = new oxField($oUser->oxuser__oxfname->value, oxField::T_RAW);
01034 $oAddress->oxaddress__oxlname = new oxField($oUser->oxuser__oxlname->value, oxField::T_RAW);
01035 $oAddress->oxaddress__oxstreet = new oxField($oUser->oxuser__oxstreet->value, oxField::T_RAW);
01036 $oAddress->oxaddress__oxstreetnr = new oxField($oUser->oxuser__oxstreetnr->value, oxField::T_RAW);
01037 $oAddress->oxaddress__oxcity = new oxField($oUser->oxuser__oxcity->value, oxField::T_RAW);
01038 $oAddress->oxaddress__oxzip = new oxField($oUser->oxuser__oxzip->value, oxField::T_RAW);
01039 $oAddress->oxaddress__oxcountry = new oxField($oUser->oxuser__oxcountry->value, oxField::T_RAW);
01040 $oAddress->oxaddress__oxcountryid = new oxField($oUser->oxuser__oxcountryid->value, oxField::T_RAW);
01041 $oAddress->oxaddress__oxcompany = new oxField($oUser->oxuser__oxcompany->value, oxField::T_RAW);
01042
01043
01044 if ( $oAddress->save() ) {
01045
01046 $this->_oAddresses = null;
01047 return $oAddress->getId();
01048 }
01049 }
01050
01058 protected function _assignAddress( $aDelAddress )
01059 {
01060 if ( ( isset( $aDelAddress['oxaddress__oxfname'] ) && $aDelAddress['oxaddress__oxfname'] ) ||
01061 ( isset( $aDelAddress['oxaddress__oxlname'] ) && $aDelAddress['oxaddress__oxlname'] ) ) {
01062
01063 $sAddressId = oxConfig::getParameter( 'oxaddressid' );
01064 $aDelAddress['oxaddress__oxid'] = ( $sAddressId === null || $sAddressId == -1 || $sAddressId == -2 ) ? null : $sAddressId;
01065
01066 $oAddress = oxNew( 'oxbase' );
01067 $oAddress->init( 'oxaddress' );
01068 $oAddress->assign( $aDelAddress );
01069 $oAddress->oxaddress__oxuserid = new oxField( $this->getId(), oxField::T_RAW );
01070 $oAddress->oxaddress__oxcountry = $this->getUserCountry( $oAddress->oxaddress__oxcountryid->value );
01071 $oAddress->save();
01072
01073
01074 $this->_oAddresses = null;
01075
01076
01077 oxSession::setVar( 'deladrid', $oAddress->getId() );
01078 } else {
01079
01080 oxSession::setVar( 'deladrid', null );
01081 }
01082 }
01083
01096 public function login( $sUser, $sPassword, $blCookie = false)
01097 {
01098 if ( $this->isAdmin() && !count( oxUtilsServer::getInstance()->getOxCookie() ) ) {
01099 $oEx = oxNew( 'oxCookieException' );
01100 $oEx->setMessage( 'EXCEPTION_COOKIE_NOCOOKIE' );
01101 throw $oEx;
01102 }
01103
01104 $myConfig = $this->getConfig();
01105 if ( $sPassword ) {
01106
01107 $sShopID = $myConfig->getShopId();
01108 $oDb = oxDb::getDb();
01109
01110 $sUserSelect = is_numeric( $sUser ) ? "oxuser.oxcustnr = {$sUser} " : "oxuser.oxusername = " . $oDb->quote( $sUser );
01111 $sPassSelect = " oxuser.oxpassword = MD5( CONCAT( ".$oDb->quote( $sPassword ).", UNHEX( oxuser.oxpasssalt ) ) ) ";
01112 $sShopSelect = "";
01113
01114
01115
01116 if ( $this->isAdmin() ) {
01117 $sShopSelect = " and ( oxrights != 'user' ) ";
01118 }
01119
01120 $sWhat = "oxid";
01121
01122 $sSelect = "select $sWhat from oxuser where oxuser.oxactive = 1 and {$sPassSelect} and {$sUserSelect} {$sShopSelect} ";
01123 if ( $myConfig->isDemoShop() && $this->isAdmin() ) {
01124 if ( $sPassword == "admin" && $sUser == "admin" ) {
01125 $sSelect = "select $sWhat from oxuser where oxrights = 'malladmin' {$sShopSelect} ";
01126 } else {
01127 $oEx = oxNew( 'oxUserException' );
01128 $oEx->setMessage( 'EXCEPTION_USER_NOVALIDLOGIN' );
01129 throw $oEx;
01130 }
01131 }
01132
01133
01134 $aData = $oDb->getAll( $sSelect );
01135 $sOXID = @$aData[0][0];
01136 if ( isset( $sOXID ) && $sOXID && !@$aData[0][1] ) {
01137
01138 if ( !$this->load( $sOXID ) ) {
01139 $oEx = oxNew( 'oxUserException' );
01140 $oEx->setMessage( 'EXCEPTION_USER_NOVALIDLOGIN' );
01141 throw $oEx;
01142 }
01143 }
01144 }
01145
01146
01147
01148 if ( $this->oxuser__oxid->value ) {
01149 if ( $this->isAdmin() ) {
01150 oxSession::setVar( 'auth', $this->oxuser__oxid->value );
01151 } else {
01152 oxSession::setVar( 'usr', $this->oxuser__oxid->value );
01153 }
01154
01155
01156 if ( $blCookie ) {
01157 oxUtilsServer::getInstance()->setUserCookie( $this->oxuser__oxusername->value, $this->oxuser__oxpassword->value, $myConfig->getShopId() );
01158 }
01159 return true;
01160 } else {
01161 $oEx = oxNew( 'oxUserException' );
01162 $oEx->setMessage( 'EXCEPTION_USER_NOVALIDLOGIN' );
01163 throw $oEx;
01164 }
01165 }
01166
01177 public function openIdLogin( $sUser )
01178 {
01179 $myConfig = $this->getConfig();
01180 $sShopID = $myConfig->getShopId();
01181 $oDb = oxDb::getDb();
01182
01183 $sUserSelect = "oxuser.oxusername = " . $oDb->quote( $sUser );
01184 $sShopSelect = "";
01185
01186
01187 $sSelect = "select oxid from oxuser where oxuser.oxactive = 1 and {$sUserSelect} {$sShopSelect} ";
01188
01189
01190 $aData = $oDb->getAll( $sSelect );
01191 $sOXID = @$aData[0][0];
01192 if ( isset( $sOXID ) && $sOXID && !@$aData[0][1] ) {
01193
01194 if ( !$this->load( $sOXID ) ) {
01195 $oEx = oxNew( 'oxUserException' );
01196 $oEx->setMessage( 'EXCEPTION_USER_NOVALIDLOGIN' );
01197 throw $oEx;
01198 }
01199 }
01200
01201
01202 if ( $this->oxuser__oxid->value ) {
01203 oxSession::setVar( 'usr', $this->oxuser__oxid->value );
01204 return true;
01205 } else {
01206 $oEx = oxNew( 'oxUserException' );
01207 $oEx->setMessage( 'EXCEPTION_USER_NOVALIDLOGIN' );
01208 throw $oEx;
01209 }
01210 }
01211
01217 public function logout()
01218 {
01219
01220 oxSession::deleteVar( 'usr' );
01221 oxSession::deleteVar( 'auth' );
01222 oxSession::deleteVar( 'dgr' );
01223 oxSession::deleteVar( 'dynvalue' );
01224 oxSession::deleteVar( 'paymentid' );
01225
01226
01227
01228 oxUtilsServer::getInstance()->deleteUserCookie( $this->getConfig()->getShopID() );
01229
01230
01231 $this->setUser( null );
01232
01233 return true;
01234 }
01235
01242 public function loadAdminUser()
01243 {
01244 return $this->loadActiveUser( true );
01245 }
01246
01255 public function loadActiveUser( $blForceAdmin = false )
01256 {
01257 $myConfig = oxConfig::getInstance();
01258
01259 $blAdmin = $myConfig->isAdmin() || $blForceAdmin;
01260 $oDB = oxDb::getDb();
01261
01262
01263 $sUserID = $blAdmin ? oxSession::getVar( 'auth' ) : oxSession::getVar( 'usr' );
01264 $blFoundInCookie = false;
01265
01266
01267 if ( !$sUserID && !$blAdmin ) {
01268 $sShopID = $myConfig->getShopId();
01269 if ( ( $sSet = oxUtilsServer::getInstance()->getUserCookie( $sShopID ) ) ) {
01270 $aData = explode( '@@@', $sSet );
01271 $sUser = $oDB->quote( $aData[0] );
01272 $sPWD = @$aData[1];
01273
01274 $sSelect = 'select oxid, oxpassword from oxuser where oxuser.oxactive = 1 and oxuser.oxusername = '.$sUser;
01275
01276
01277 $oDB = oxDb::getDb();
01278 $rs = $oDB->execute( $sSelect );
01279 if ( $rs != false && $rs->recordCount() > 0 ) {
01280 while (!$rs->EOF) {
01281 $sTest = crypt( $rs->fields[1], 'ox' );
01282 if ( $sTest == $sPWD ) {
01283
01284 $sUserID = $rs->fields[0];
01285 $blFoundInCookie = true;
01286 break;
01287 }
01288 $rs->moveNext();
01289 }
01290 }
01291 }
01292 }
01293
01294
01295 if ( $sUserID ) {
01296 if ( $this->load( $sUserID ) ) {
01297
01298 if ($blAdmin) {
01299 oxSession::setVar( 'auth', $sUserID );
01300 } else {
01301 oxSession::setVar( 'usr', $sUserID );
01302 }
01303
01304
01305 $this->_blLoadedFromCookie = $blFoundInCookie;
01306 return true;
01307 }
01308 } else {
01309
01310 oxSession::deleteVar( 'usr' );
01311 oxSession::deleteVar( 'auth' );
01312
01313 return false;
01314 }
01315 }
01316
01329 protected function _ldapLogin( $sUser, $sPassword, $sShopID, $sShopSelect)
01330 {
01331 include "oxldap.php";
01332 $myConfig = $this->getConfig();
01333
01334 $aLDAPParams = $myConfig->getConfigParam( 'aLDAPParams' );
01335 $oLDAP = new oxLDAP( $aLDAPParams['HOST'], $aLDAPParams['PORT'] );
01336
01337 $sLDAPKey = oxDb::getDb()->GetOne("select oxldapkey from oxuser where oxuser.oxactive = 1 and oxuser.oxusername = ".oxDb::getDb()->Quote($sUser)." $sShopSelect");
01338 if( isset( $sLDAPKey) && $sLDAPKey) {
01339 $sUser = $sLDAPKey;
01340 }
01341
01342
01343 $oLDAP->login( $sUser, $sPassword, $aLDAPParams['USERQUERY'], $aLDAPParams['BASEDN'], $aLDAPParams['FILTER']);
01344
01345 $aData = $oLDAP->mapData($aLDAPParams['DATAMAP']);
01346 if ( isset( $aData['OXUSERNAME']) && $aData['OXUSERNAME']) {
01347
01348
01349 $sSelect = "select oxid from oxuser where oxuser.oxusername = ".oxDb::getDb()->Quote($aData['OXUSERNAME'])." $sShopSelect";
01350 $sOXID = oxDb::getDb()->GetOne( $sSelect);
01351
01352 if ( !isset( $sOXID) || !$sOXID) {
01353
01354 $this->setId();
01355
01356
01357 foreach ( $aData as $fldname => $value) {
01358 $sField = "oxuser__".strtolower( $fldname);
01359 $this->$sField->setValue($aData[$fldname]);
01360 }
01361
01362 $this->oxuser__oxactive->setValue(1);
01363 $this->oxuser__oxshopid->setValue($sShopID);
01364 $this->oxuser__oxldapkey->setValue($sUser);
01365 $this->oxuser__oxrights->setValue("user");
01366 $this->setPassword( "ldap user" );
01367
01368 $this->save();
01369 } else {
01370 $this->load( $sOXID);
01371 }
01372
01373 } else {
01374 $oEx = oxNew( 'oxUserException' );
01375 $oEx->setMessage('EXCEPTION_USER_NOVALUES');
01376 throw $oEx;
01377 }
01378 }
01379
01386 protected function _getUserRights()
01387 {
01388
01389 if ( !$this->oxuser__oxrights->value )
01390 return 'user';
01391
01392 $oDB = oxDb::getDb();
01393 $myConfig = $this->getConfig();
01394 $sAuthRights = null;
01395
01396
01397 $sAuthUserID = $this->isAdmin()?oxSession::getVar( 'auth' ):null;
01398 $sAuthUserID = $sAuthUserID?$sAuthUserID:oxSession::getVar( 'usr' );
01399 if ( $sAuthUserID ) {
01400 $sAuthUserID = $oDB->quote( $sAuthUserID );
01401 $sAuthRights = $oDB->getOne( 'select oxrights from '.$this->getViewName().' where oxid='.$sAuthUserID );
01402 }
01403
01404
01405 $aRights = array();
01406
01407
01408 if ( $sCurrRights = $oDB->getOne( 'select oxrights from '.$this->getViewName().' where oxid="'.$this->getId().'"' ) ) {
01409 $aRights[] = $sCurrRights;
01410 }
01411 $aRights[] = 'user';
01412
01413 if ( !$sAuthRights || !( $sAuthRights == 'malladmin' || $sAuthRights == $myConfig->getShopId() ) ) {
01414 return current( $aRights );
01415 } elseif ( $sAuthRights == $myConfig->getShopId() ) {
01416 $aRights[] = $sAuthRights;
01417 if ( !in_array( $this->oxuser__oxrights->value, $aRights ) ) {
01418 return current( $aRights );
01419 }
01420 }
01421
01422
01423 return $this->oxuser__oxrights->value;
01424 }
01425
01435 protected function _setRecordNumber( $sMaxField, $aWhere = null ,$iMaxTryCnt = 5 )
01436 {
01437
01438
01439
01440
01441
01442
01443 return parent::_setRecordNumber( $sMaxField, $aWhere, $iMaxTryCnt );
01444 }
01445
01451 protected function _insert()
01452 {
01453
01454
01455 $this->oxuser__oxcreate = new oxField(date( 'Y-m-d H:i:s' ), oxField::T_RAW);
01456
01457 if ( !isset( $this->oxuser__oxboni->value ) ) {
01458 $this->oxuser__oxboni = new oxField($this->getBoni(), oxField::T_RAW);
01459 }
01460
01461 if ( $blInsert = parent::_insert() ) {
01462
01463 if ( !$this->oxuser__oxcustnr->value || !$this->isAdmin() ) {
01464 $this->_setRecordNumber( 'oxcustnr' );
01465 }
01466 }
01467
01468 return $blInsert;
01469 }
01470
01476 protected function _update()
01477 {
01478
01479 if (!$this->oxuser__oxpassword->value && $this->oxuser__oxregister->value < 1) {
01480 $this->_aSkipSaveFields[] = 'oxboni';
01481 }
01482
01483
01484 $this->_aSkipSaveFields[] = 'oxcreate';
01485 if ( !$this->isAdmin() ) {
01486 $this->_aSkipSaveFields[] = 'oxcustnr';
01487 $this->_aSkipSaveFields[] = 'oxrights';
01488 }
01489
01490
01491 if ( ( $blUpdate = parent::_update() ) ) {
01492 $this->getNewsSubscription()->updateSubscription( $this );
01493 }
01494
01495 return $blUpdate;
01496 }
01497
01513 protected function _checkLogin( &$sLogin, $aInvAddress )
01514 {
01515 $myConfig = $this->getConfig();
01516
01517 $sLogin = ( isset( $aInvAddress['oxuser__oxusername'] ) && $aInvAddress['oxuser__oxusername'] )?$aInvAddress['oxuser__oxusername']:$sLogin;
01518
01519
01520
01521 if ( $this->oxuser__oxpassword->value && $sLogin != $this->oxuser__oxusername->value ) {
01522
01523
01524 $sNewPass = isset( $aInvAddress['oxuser__oxpassword'] )?$aInvAddress['oxuser__oxpassword']:oxConfig::getParameter( 'user_password' );
01525 if ( !$sNewPass ) {
01526
01527
01528 $oEx = oxNew( 'oxInputException' );
01529 $oEx->setMessage('EXCEPTION_INPUT_NOTALLFIELDS');
01530 throw $oEx;
01531 } else {
01532
01533
01534 if ( !$this->isSamePassword( $sNewPass ) ) {
01535 $oEx = oxNew( 'oxUserException' );
01536 $oEx->setMessage('EXCEPTION_USER_PWDDONTMATCH');
01537 throw $oEx;
01538 }
01539 }
01540 }
01541
01542 if ( $this->checkIfEmailExists( $sLogin ) ) {
01543
01544 $oEx = oxNew( 'oxUserException' );
01545 $oLang = oxLang::getInstance();
01546 $oEx->setMessage( sprintf( $oLang->translateString( 'EXCEPTION_USER_USEREXISTS', $oLang->getTplLanguage() ), $sLogin ) );
01547 throw $oEx;
01548 }
01549 }
01550
01558 public function checkIfEmailExists( $sEmail )
01559 {
01560 $myConfig = $this->getConfig();
01561 $oDB = oxDb::getDb();
01562 $iShopId = $myConfig->getShopId();
01563 $blExists = false;
01564
01565 $sQ = 'select oxshopid, oxrights, oxpassword from oxuser where oxusername = '. $oDB->quote( $sEmail );
01566 if ( ( $sOxid = $this->getId() ) ) {
01567 $sQ .= " and oxid <> '$sOxid' ";
01568 }
01569
01570 $oRs = $oDB->execute( $sQ );
01571 if ( $oRs != false && $oRs->recordCount() > 0 ) {
01572
01573 if ( $this->_blMallUsers ) {
01574
01575 $blExists = true;
01576 if ( $oRs->fields[1] == 'user' && !$oRs->fields[2] ) {
01577
01578
01579 $blExists = false;
01580 }
01581 } else {
01582
01583 $blExists = false;
01584 while ( !$oRs->EOF ) {
01585 if ( $oRs->fields[1] != 'user' ) {
01586
01587
01588 $blExists = true;
01589 break;
01590 } elseif ( $oRs->fields[0] == $iShopId && $oRs->fields[2] ) {
01591
01592
01593 $blExists = true;
01594 break;
01595 }
01596
01597 $oRs->moveNext();
01598 }
01599 }
01600 }
01601 return $blExists;
01602 }
01603
01611 public function getUserRecommLists( $sOXID = null )
01612 {
01613 if ( !$sOXID )
01614 $sOXID = $this->getId();
01615
01616
01617 $iActPage = (int) oxConfig::getParameter( 'pgNr' );
01618 $iActPage = ($iActPage < 0) ? 0 : $iActPage;
01619
01620
01621 $iNrofCatArticles = $this->getConfig()->getConfigParam( 'iNrofCatArticles' );
01622 $iNrofCatArticles = $iNrofCatArticles ? $iNrofCatArticles : 10;
01623
01624
01625 $oRecommList = oxNew( 'oxlist' );
01626 $oRecommList->init( 'oxrecommlist' );
01627 $oRecommList->setSqlLimit( $iNrofCatArticles * $iActPage, $iNrofCatArticles );
01628 $iShopId = $this->getConfig()->getShopId();
01629 $sSelect = 'select * from oxrecommlists where oxuserid ="'. $sOXID .'" and oxshopid ="'. $iShopId .'"';
01630 $oRecommList->selectString( $sSelect );
01631
01632 return $oRecommList;
01633 }
01634
01642 public function getRecommListsCount( $sOx = null )
01643 {
01644 if ( !$sOx ) {
01645 $sOXID = $this->getId();
01646 }
01647
01648 if ( $this->_iCntRecommLists === null || $sOx ) {
01649 $this->_iCntRecommLists = 0;
01650 $iShopId = $this->getConfig()->getShopId();
01651 $sSelect = 'select count(oxid) from oxrecommlists where oxuserid ="'. $sOXID .'" and oxshopid ="'. $iShopId .'"';
01652 $this->_iCntRecommLists = oxDb::getDb()->getOne( $sSelect );
01653 }
01654 return $this->_iCntRecommLists;
01655 }
01656
01665 protected function _checkEmail( $sEmail )
01666 {
01667
01668 if ( !$sEmail ) {
01669 $oEx = oxNew( 'oxInputException' );
01670 $oEx->setMessage('EXCEPTION_INPUT_NOTALLFIELDS');
01671 throw $oEx;
01672 }
01673
01674
01675 if ( !oxUtils::getInstance()->isValidEmail( $sEmail ) ) {
01676 $oEx = oxNew( 'oxInputException' );
01677 $oEx->setMessage( 'EXCEPTION_INPUT_NOVALIDEMAIL' );
01678 throw $oEx;
01679 }
01680 }
01681
01694 protected function _checkPassword( $sNewPass, $sConfPass, $blCheckLenght = false )
01695 {
01696
01697
01698 if ( $blCheckLenght && strlen( $sNewPass ) == 0 ) {
01699 $oEx = oxNew( 'oxInputException' );
01700 $oEx->setMessage('EXCEPTION_INPUT_EMPTYPASS');
01701 throw $oEx;
01702 }
01703
01704
01705 if ( $blCheckLenght && strlen( $sNewPass ) < 6 ) {
01706 $oEx = oxNew( 'oxInputException' );
01707 $oEx->setMessage('EXCEPTION_INPUT_PASSTOOSHORT');
01708 throw $oEx;
01709 }
01710
01711
01712 if ( $sNewPass != $sConfPass ) {
01713 $oEx = oxNew( 'oxUserException' );
01714 $oEx->setMessage('EXCEPTION_USER_PWDDONTMATCH');
01715 throw $oEx;
01716 }
01717 }
01718
01730 protected function _checkRequiredFields( $aInvAddress, $aDelAddress )
01731 {
01732
01733 $aMustFields = array( 'oxuser__oxfname',
01734 'oxuser__oxlname',
01735 'oxuser__oxstreetnr',
01736 'oxuser__oxstreet',
01737 'oxuser__oxzip',
01738 'oxuser__oxcity' );
01739
01740
01741 $aMustFillFields = $this->getConfig()->getConfigParam( 'aMustFillFields' );
01742 if ( is_array( $aMustFillFields ) ) {
01743 $aMustFields = $aMustFillFields;
01744 }
01745
01746
01747 $aInvAddress = is_array( $aInvAddress )?$aInvAddress:array();
01748 $aDelAddress = is_array( $aDelAddress )?$aDelAddress:array();
01749
01750
01751 $aFields = array_merge( $aInvAddress, $aDelAddress );
01752
01753
01754 $blCheckDel = false;
01755 if ( count( $aDelAddress ) ) {
01756 $blCheckDel = true;
01757 }
01758
01759
01760 foreach ( $aMustFields as $sMustField ) {
01761
01762
01763 if ( !$blCheckDel && strpos( $sMustField, 'oxaddress__' ) === 0 ) {
01764 continue;
01765 }
01766
01767 if ( isset( $aFields[$sMustField] ) && is_array( $aFields[$sMustField] ) ) {
01768 $this->_checkRequiredArrayFields( $sMustField, $aFields[$sMustField] );
01769 } elseif ( !isset( $aFields[$sMustField] ) || !trim( $aFields[$sMustField] ) ) {
01770 $oEx = oxNew( 'oxInputException' );
01771 $oEx->setMessage('EXCEPTION_INPUT_NOTALLFIELDS');
01772 throw $oEx;
01773 }
01774 }
01775 }
01776
01787 protected function _checkRequiredArrayFields( $sFieldName, $aFieldValues )
01788 {
01789 foreach ( $aFieldValues as $sValue ) {
01790 if ( !trim( $sValue ) ) {
01791 $oEx = oxNew( 'oxInputException' );
01792 $oEx->setMessage('EXCEPTION_INPUT_NOTALLFIELDS');
01793 throw $oEx;
01794 }
01795 }
01796 }
01797
01808 protected function _checkVatId( $aInvAddress )
01809 {
01810
01811 if ( $aInvAddress['oxuser__oxustid'] && $aInvAddress['oxuser__oxcompany'] ) {
01812
01813 if (!($sCountryId = $aInvAddress['oxuser__oxcountryid'])) {
01814
01815 return;
01816 }
01817 $oCountry = oxNew('oxcountry');
01818 if (!$oCountry->load($sCountryId)) {
01819 throw new oxObjectException();
01820 }
01821 if ($oCountry->isForeignCountry() && $oCountry->isInEU()) {
01822 if (strncmp($aInvAddress['oxuser__oxustid'], $oCountry->oxcountry__oxisoalpha2->value, 2)) {
01823 $oEx = oxNew( 'oxInputException' );
01824 $oEx->setMessage( 'VAT_MESSAGE_ID_NOT_VALID' );
01825 throw $oEx;
01826 }
01827 }
01828
01829 }
01830 }
01831
01840 protected function _setAutoGroups( $sCountryId )
01841 {
01842
01843 $blForeigner = true;
01844 $blForeignGroupExists = false;
01845 $blInlandGroupExists = false;
01846
01847 $aHomeCountry = $this->getConfig()->getConfigParam( 'aHomeCountry' );
01848
01849 if ( is_array($aHomeCountry)) {
01850 if (in_array($sCountryId, $aHomeCountry)) {
01851 $blForeigner = false;
01852 }
01853 } elseif ($sCountryId == $aHomeCountry) {
01854 $blForeigner = false;
01855 }
01856
01857 if ( $this->inGroup( 'oxidforeigncustomer' ) ) {
01858 $blForeignGroupExists = true;
01859 if ( !$blForeigner ) {
01860 $this->removeFromGroup( 'oxidforeigncustomer' );
01861 }
01862 }
01863
01864 if ( $this->inGroup( 'oxidnewcustomer' ) ) {
01865 $blInlandGroupExists = true;
01866 if ( $blForeigner ) {
01867 $this->removeFromGroup( 'oxidnewcustomer' );
01868 }
01869 }
01870
01871 if ( !$this->oxuser__oxdisableautogrp->value ) {
01872 if ( !$blForeignGroupExists && $blForeigner ) {
01873 $this->addToGroup( 'oxidforeigncustomer' );
01874 }
01875 if ( !$blInlandGroupExists && !$blForeigner ) {
01876 $this->addToGroup( 'oxidnewcustomer' );
01877 }
01878 }
01879 }
01880
01888 protected function _hasUserAddress( $sUserId )
01889 {
01890
01891 $oAddresses = $this->getUserAddresses();
01892 if ( $oAddresses && count($oAddresses)>0 ) {
01893 $oAddresses->rewind() ;
01894 foreach ($oAddresses as $key => $oAddress) {
01895 if ( $oAddress->oxaddress__oxaddressuserid->value == $sUserId ) {
01896 return true;
01897 }
01898 }
01899 }
01900 return false;
01901 }
01902
01915 protected function _setUserCookie( $sUser, $sPassword, $sShopId = null, $iTimeout = 31536000 )
01916 {
01917 oxUtilsServer::getInstance()->setUserCookie( $sUser, $sPassword, $sShopId, $iTimeout );
01918 }
01919
01929 protected function _deleteUserCookie( $sShopId = null )
01930 {
01931 oxUtilsServer::getInstance()->deleteUserCookie( $sShopId );
01932 }
01933
01943 protected static function _getUserCookie( $sShopId = null )
01944 {
01945 return oxUtilsServer::getInstance()->getUserCookie( $sShopId );
01946 }
01947
01948
01957 public function loadUserByUpdateId( $sUid )
01958 {
01959 $oDb = oxDb::getDb();
01960 $sQ = "select oxid from ".$this->getViewName()." where oxupdateexp >= ".time()." and MD5( CONCAT( oxid, oxshopid, oxupdatekey ) ) = ".$oDb->quote( $sUid );
01961 if ( $sUserId = $oDb->getOne( $sQ ) ) {
01962 return $this->load( $sUserId );
01963 }
01964 }
01965
01973 public function setUpdateKey( $blReset = false )
01974 {
01975 $sUpKey = $blReset ? '' : oxUtilsObject::getInstance()->generateUId();
01976 $iUpTime = $blReset ? 0 : oxUtilsDate::getInstance()->getTime() + $this->getUpdateLinkTerm();
01977
01978
01979 $this->oxuser__oxupdatekey = new oxField( $sUpKey, oxField::T_RAW );
01980
01981
01982 $this->oxuser__oxupdateexp = new oxField( $iUpTime, oxField::T_RAW );
01983
01984
01985 $this->save();
01986 }
01987
01993 public function getUpdateLinkTerm()
01994 {
01995 return 3600 * 6;
01996 }
01997
02005 public function isExpiredUpdateId( $sKey )
02006 {
02007 $oDb = oxDb::getDb();
02008 $sQ = "select 1 from ".$this->getViewName()." where oxupdateexp >= ".time()." and MD5( CONCAT( oxid, oxshopid, oxupdatekey ) ) = ".$oDb->quote( $sKey );
02009 return !( (bool) $oDb->getOne( $sQ ) );
02010 }
02011
02017 public function getUpdateId()
02018 {
02019 if ( $this->_sUpdateKey === null ) {
02020 $this->setUpdateKey();
02021 $this->_sUpdateKey = md5( $this->getId() . $this->oxuser__oxshopid->value . $this->oxuser__oxupdatekey->value );
02022 }
02023 return $this->_sUpdateKey;
02024 }
02025
02033 public function encodePassword( $sPassword, $sSalt )
02034 {
02035 $oDb = oxDb::getDb();
02036 return $oDb->getOne( "select MD5( CONCAT( ".$oDb->quote( $sPassword ).", UNHEX( '{$sSalt}' ) ) )" );
02037 }
02038
02046 public function prepareSalt( $sSalt )
02047 {
02048 return ( $sSalt ? oxDb::getDb()->getOne( "select HEX( '{$sSalt}' )" ) : '' );
02049 }
02050
02058 public function decodeSalt( $sSaltHex )
02059 {
02060 return ( $sSaltHex ? oxDb::getDb()->getOne( "select UNHEX( '{$sSaltHex}' )" ) : '' );
02061 }
02062
02070 public function setPassword( $sPassword = null )
02071 {
02072
02073 $sSalt = $sPassword ? $this->prepareSalt( oxUtilsObject::getInstance()->generateUID() ) : '';
02074
02075
02076 $sPassword = $sPassword ? $this->encodePassword( $sPassword, $sSalt ) : '';
02077
02078 $this->oxuser__oxpassword = new oxField( $sPassword, oxField::T_RAW );
02079 $this->oxuser__oxpasssalt = new oxField( $sSalt, oxField::T_RAW );
02080 }
02081
02089 public function isSamePassword( $sNewPass )
02090 {
02091 return $this->encodePassword( $sNewPass, $this->oxuser__oxpasssalt->value ) == $this->oxuser__oxpassword->value;
02092 }
02093
02099 public function isLoadedFromCookie()
02100 {
02101 return $this->_blLoadedFromCookie;
02102 }
02103
02110 public function getPasswordHash()
02111 {
02112 $sHash = null;
02113 if ( $this->oxuser__oxpassword->value ) {
02114 if ( strpos( $this->oxuser__oxpassword->value, 'ox_' ) === 0 ) {
02115
02116 $this->setPassword( oxUtils::getInstance()->strRem( $this->oxuser__oxpassword->value ) );
02117 } elseif ( ( strlen( $this->oxuser__oxpassword->value ) < 32 ) && ( strpos( $this->oxuser__oxpassword->value, 'openid_' ) !== 0 ) ) {
02118
02119 $this->setPassword( $this->oxuser__oxpassword->value );
02120 }
02121 $sHash = $this->oxuser__oxpassword->value;
02122 }
02123 return $sHash;
02124 }
02125
02134 public static function getAdminUser()
02135 {
02136 return self::getActiveUser( true );
02137 }
02138
02148 public static function getActiveUser( $blForceAdmin = false )
02149 {
02150 $oUser = oxNew( 'oxuser' );
02151 if ( $oUser->loadActiveUser( $blForceAdmin ) ) {
02152 return $oUser;
02153 } else {
02154 return false;
02155 }
02156 }
02157
02165 public function getOpenIdPassword( $iLength = 25 )
02166 {
02167 $sPassword= "openid_".substr( oxUtilsObject::getInstance()->generateUId(), 0, $iLength);
02168 return $sPassword;
02169 }
02170 }