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 break;
00157 case 'iCntNoticeListArticles':
00158 return $this->_iCntNoticeListArticles = $this->getNoticeListArtCnt();
00159 break;
00160 case 'iCntWishListArticles':
00161 return $this->_iCntWishListArticles = $this->getWishListArtCnt();
00162 break;
00163 case 'iCntRecommLists':
00164 return $this->_iCntRecommLists = $this->getRecommListsCount();
00165 break;
00166 case 'oAddresses':
00167 return $this->_oAddresses = $this->getUserAddresses();
00168 break;
00169 case 'oPayments':
00170 return $this->_oPayments = $this->getUserPayments();
00171 break;
00172 case 'oxuser__oxcountry':
00173 return $this->oxuser__oxcountry = $this->getUserCountry();
00174 break;
00175 case 'sDBOptin':
00176 return $this->sDBOptin = $this->getNewsSubscription()->getOptInStatus();
00177 break;
00178 case 'sEmailFailed':
00179 return $this->sEmailFailed = $this->getNewsSubscription()->getOptInEmailStatus();
00180 break;
00181 }
00182 }
00183
00189 public function getNewsSubscription()
00190 {
00191 if ( $this->_oNewsSubscription !== null ) {
00192 return $this->_oNewsSubscription;
00193 }
00194
00195 $this->_oNewsSubscription = oxNew( 'oxnewssubscribed' );
00196
00197
00198 if ( !$this->_oNewsSubscription->loadFromUserId( $this->getId() ) ) {
00199 if ( !$this->_oNewsSubscription->loadFromEmail( $this->oxuser__oxusername->value ) ) {
00200
00201
00202 $this->_oNewsSubscription->oxnewssubscribed__oxuserid = new oxField($this->getId(), oxField::T_RAW);
00203 $this->_oNewsSubscription->oxnewssubscribed__oxemail = new oxField($this->oxuser__oxusername->value, oxField::T_RAW);
00204 $this->_oNewsSubscription->oxnewssubscribed__oxsal = new oxField($this->oxuser__oxsal->value, oxField::T_RAW);
00205 $this->_oNewsSubscription->oxnewssubscribed__oxfname = new oxField($this->oxuser__oxfname->value, oxField::T_RAW);
00206 $this->_oNewsSubscription->oxnewssubscribed__oxlname = new oxField($this->oxuser__oxlname->value, oxField::T_RAW);
00207 }
00208 }
00209
00210 return $this->_oNewsSubscription;
00211 }
00212
00222 public function getUserCountry( $sCountryId = null, $iLang = null )
00223 {
00224
00225 if ( !$sCountryId ) {
00226 $sCountryId = $this->oxuser__oxcountryid->value;
00227 }
00228
00229 $sQ = 'select oxtitle'.oxLang::getInstance()->getLanguageTag( $iLang ).' from oxcountry where oxid = "'.$sCountryId.'" ';
00230 $this->oxuser__oxcountry = new oxField( oxDb::getDb()->getOne( $sQ ), oxField::T_RAW);
00231
00232 return $this->oxuser__oxcountry;
00233 }
00234
00242 public function getUserCountryId( $sCountry = null )
00243 {
00244 $sQ = 'select oxid from oxcountry where oxactive = "1" and oxisoalpha2 = "' . $sCountry . '"';
00245 $sCountryId = oxDb::getDb()->getOne( $sQ );
00246
00247 return $sCountryId;
00248 }
00249
00257 public function getUserGroups( $sOXID = null )
00258 {
00259
00260 if ( isset( $this->_oGroups ) ) {
00261 return $this->_oGroups;
00262 }
00263
00264 if ( !$sOXID ) {
00265 $sOXID = $this->getId();
00266 }
00267
00268 $this->_oGroups = oxNew( 'oxlist', 'oxgroups' );
00269
00270
00271 $sSelect = 'select oxgroups.* from oxgroups left join oxobject2group on oxobject2group.oxgroupsid = oxgroups.oxid ';
00272 $sSelect .= 'where oxobject2group.oxobjectid = "'.$sOXID.'" ';
00273 $this->_oGroups->selectString( $sSelect );
00274 return $this->_oGroups;
00275 }
00276
00284 public function getUserAddresses( $sUserId = null )
00285 {
00286
00287 if ( $this->_oAddresses == null ) {
00288
00289 $sSelect = "select * from oxaddress where oxaddress.oxuserid = '".( $sUserId ? $sUserId : $this->getId() )."'";
00290
00291
00292 $this->_oAddresses = oxNew( 'oxlist' );
00293 $this->_oAddresses->init( "oxbase", "oxaddress" );
00294 $this->_oAddresses->selectString( $sSelect );
00295
00296
00297 if ( $sAddressId = $this->getSelectedAddressId() ) {
00298 foreach ( $this->_oAddresses as $oAddress ) {
00299 $oAddress->selected = 0;
00300 if ( $oAddress->getId() == $sAddressId ) {
00301 $oAddress->selected = 1;
00302 break;
00303 }
00304 }
00305 }
00306 }
00307 return $this->_oAddresses;
00308 }
00309
00315 public function getSelectedAddressId()
00316 {
00317 if ( !( $sAddressId = oxConfig::getParameter( "oxaddressid") ) ) {
00318 $sAddressId = oxSession::getVar( "deladrid" );
00319 }
00320 return $sAddressId;
00321 }
00322
00331 public function getSelectedAddress( $sWishId = false )
00332 {
00333 $oAddresses = $this->getUserAddresses();
00334 if ( $oAddresses->count() ) {
00335 if ( $sAddressId = $this->getSelectedAddressId() ) {
00336 foreach ( $oAddresses as $oAddress ) {
00337 if ( $oAddress->selected == 1 ) {
00338 $sAddressId = $oAddress->getId();
00339 break;
00340 }
00341 }
00342 } elseif ( $sWishId ) {
00343 foreach ( $oAddresses as $oAddress ) {
00344 $oAddress->selected = 0;
00345 if ( $oAddress->oxaddress__oxaddressuserid->value == $sWishId ) {
00346 $oAddress->selected = 1;
00347 $sAddressId = $oAddress->getId();
00348 }
00349 }
00350 }
00351
00352
00353 if ( !$sAddressId ) {
00354 $oAddresses->rewind();
00355 $oAddress = $oAddresses->current();
00356 $oAddress->selected = 1;
00357 $sAddressId = $oAddress->getId();
00358 }
00359 }
00360
00361 return $sAddressId;
00362 }
00363
00371 public function getUserPayments( $sOXID = null )
00372 {
00373 if ( $this->_oPayments === null ) {
00374
00375 if ( !$sOXID ) {
00376 $sOXID = $this->getId();
00377 }
00378
00379 $sSelect = 'select * from oxuserpayments where oxuserid ="'. $sOXID .'"';
00380
00381 $this->_oPayments = oxNew( 'oxlist' );
00382 $this->_oPayments->init( 'oxUserPayment' );
00383 $this->_oPayments->selectString( $sSelect );
00384
00385 $myUtils = oxUtils::getInstance();
00386 foreach ( $this->_oPayments as $oPayment ) {
00387
00388 $oPayment = $myUtils->assignValuesFromText( $val->oxuserpayments__oxvalue->value );
00389 }
00390 }
00391
00392 return $this->_oPayments;
00393 }
00394
00400 public function save()
00401 {
00402
00403 $blAddRemark = false;
00404 if ( $this->oxuser__oxpassword->value && $this->oxuser__oxregister->value < 1 ) {
00405 $blAddRemark = true;
00406
00407 $this->oxuser__oxregister = new oxField(date( 'Y-m-d H:i:s' ), oxField::T_RAW);
00408 }
00409
00410
00411 $this->oxuser__oxrights = new oxField($this->_getUserRights(), oxField::T_RAW);
00412
00413
00414 if ( is_array( $this->oxuser__oxbirthdate->value ) ) {
00415 $this->oxuser__oxbirthdate = new oxField($this->convertBirthday( $this->oxuser__oxbirthdate->value ), oxField::T_RAW);
00416 }
00417
00418 $blRet = parent::save();
00419
00420
00421 if ( $blAddRemark && $blRet ) {
00422 $oRemark = oxNew( 'oxremark' );
00423 $oRemark->oxremark__oxtext = new oxField(oxLang::getInstance()->translateString( 'usrRegistered' ), oxField::T_RAW);
00424 $oRemark->oxremark__oxtype = new oxField('r', oxField::T_RAW);
00425 $oRemark->oxremark__oxparentid = new oxField($this->getId(), oxField::T_RAW);
00426 $oRemark->save();
00427 }
00428
00429 return $blRet;
00430 }
00431
00437 public function allowDerivedUpdate()
00438 {
00439 return true;
00440 }
00441
00449 public function inGroup( $sGroupID )
00450 {
00451 $blIn = false;
00452 if ( ( $oGroups = $this->getUserGroups() ) ) {
00453 $blIn = isset( $oGroups[ $sGroupID ] );
00454 }
00455
00456 return $blIn;
00457 }
00458
00467 public function delete( $sOXID = null )
00468 {
00469
00470 if ( !$sOXID ) {
00471 $sOXID = $this->getId();
00472 }
00473 if ( !$sOXID ) {
00474 return false;
00475 }
00476
00477 $blDeleted = parent::delete( $sOXID );
00478
00479 if ( $blDeleted ) {
00480 $oDB = oxDb::getDb();
00481
00482
00483 $rs = $oDB->execute( 'delete from oxaddress where oxaddress.oxuserid = "'.$sOXID.'" ' );
00484 $rs = $oDB->execute( 'delete from oxobject2group where oxobject2group.oxobjectid = "'.$sOXID.'" ');
00485
00486
00487 $rs = $oDB->execute( 'delete oxuserbasketitems.* from oxuserbasketitems, oxuserbaskets where oxuserbasketitems.oxbasketid = oxuserbaskets.oxid and oxuserid = "'.$sOXID.'" ' );
00488 $rs = $oDB->execute( 'delete from oxuserbaskets where oxuserid = "'.$sOXID.'" ' );
00489
00490
00491 $rs = $oDB->execute( 'delete from oxnewssubscribed where oxuserid = "'.$sOXID.'" ');
00492
00493
00494 $rs = $oDB->execute( 'delete from oxremark where oxparentid = "'.$sOXID.'" and oxtype !="o"' );
00495
00496 $blDeleted = $rs->EOF;
00497 }
00498
00499 return $blDeleted;
00500 }
00501
00509 public function load( $oxID )
00510 {
00511
00512 $blRet = parent::Load( $oxID );
00513
00514
00515 if ( isset( $this->oxuser__oxcreate->value ) ) {
00516 $this->oxuser__oxcreate->setValue(oxUtilsDate::getInstance()->formatDBDate( $this->oxuser__oxcreate->value ));
00517 }
00518
00519 return $blRet;
00520 }
00521
00529 public function exists( $sOXID = null )
00530 {
00531 if ( !$sOXID ) {
00532 $sOXID = $this->getId();
00533 }
00534
00535 $sSelect = 'SELECT oxid FROM '.$this->getViewName().'
00536 WHERE ( oxusername = "'.$this->oxuser__oxusername->value.'"';
00537
00538 if ( $sOXID ) {
00539 $sSelect.= " or oxid = '$sOXID' ) ";
00540 } else {
00541 $sSelect.= ' ) ';
00542 }
00543
00544 if ( !$this->_blMallUsers && $this->oxuser__oxrights->value != 'malladmin') {
00545 $sSelect .= ' AND oxshopid = "'.$this->getConfig()->getShopId().'" ';
00546 }
00547
00548 $blExists = false;
00549 if ( ( $sOxid = oxDb::getDb()->getOne( $sSelect ) ) ) {
00550
00551 $this->setId( $sOxid );
00552 $blExists = true;
00553 }
00554 return $blExists;
00555 }
00556
00562 public function getOrders()
00563 {
00564 $myConfig = $this->getConfig();
00565 $oOrders = oxNew( 'oxlist' );
00566 $oOrders->init( 'oxorder' );
00567
00568
00569
00570
00571
00572
00573
00574
00575 if ( $this->oxuser__oxregister->value > 1 ) {
00576 $sQ = 'select * from oxorder where oxuserid = "'.$this->getId().'" and oxorderdate >= "'.$this->oxuser__oxregister->value.'" ';
00577
00578
00579
00580 $sQ .= ' order by oxorderdate desc ';
00581 $oOrders->selectString( $sQ );
00582 }
00583
00584 return $oOrders;
00585 }
00586
00592 public function getOrderCount()
00593 {
00594 $iCnt = 0;
00595 if ( $this->getId() && $this->oxuser__oxregister->value > 1 ) {
00596 $sQ = 'select count(*) from oxorder where oxuserid = "'.$this->getId().'" AND oxorderdate >= "'.$this->oxuser__oxregister->value.'" and oxshopid = "'.$this->getConfig()->getShopId().'" ';
00597 $iCnt = (int) oxDb::getDb()->getOne( $sQ );
00598 }
00599
00600 return $iCnt;
00601 }
00602
00608 public function getNoticeListArtCnt()
00609 {
00610 if ( $this->_iCntNoticeListArticles === null ) {
00611 $this->_iCntNoticeListArticles = 0;
00612 if ( $this->getId() ) {
00613 $this->_iCntNoticeListArticles = $this->getBasket( 'noticelist' )->getItemCount();
00614 }
00615 }
00616 return $this->_iCntNoticeListArticles;
00617 }
00618
00624 public function getWishListArtCnt()
00625 {
00626 if ( $this->_iCntWishListArticles === null ) {
00627 $this->_iCntWishListArticles = false;
00628 if ( $this->getId() ) {
00629 $this->_iCntWishListArticles = $this->getBasket( 'wishlist' )->getItemCount();
00630 }
00631 }
00632 return $this->_iCntWishListArticles;
00633 }
00634
00641 public function getActiveCountry()
00642 {
00643 $sDeliveryCountry = '';
00644 if ( $soxAddressId = oxConfig::getParameter( 'deladrid' ) ) {
00645 $oDelAddress = oxNew( 'oxbase' );
00646 $oDelAddress->init( 'oxaddress' );
00647 $oDelAddress->load( $soxAddressId );
00648 $sDeliveryCountry = $oDelAddress->oxaddress__oxcountryid->value;
00649 } elseif ( $this->getId() ) {
00650 $sDeliveryCountry = $this->oxuser__oxcountryid->value;
00651 } else {
00652 $oUser = oxNew( 'oxuser' );
00653 if ( $oUser->loadActiveUser() ) {
00654 $sDeliveryCountry = $oUser->oxuser__oxcountryid->value;
00655 }
00656 }
00657
00658 return $sDeliveryCountry;
00659 }
00660
00668 public function createUser()
00669 {
00670 $oDB = oxDb::getDb();
00671 $sShopID = $this->getConfig()->getShopId();
00672
00673
00674 $sSelect = "select oxid from oxuser where oxusername = '{$this->oxuser__oxusername->value}' and oxpassword = '' ";
00675 if ( !$this->_blMallUsers ) {
00676 $sSelect .= " and oxshopid = '{$sShopID}' ";
00677 }
00678 $sOXID = $oDB->getOne( $sSelect );
00679
00680
00681 if ( isset( $sOXID ) && $sOXID ) {
00682
00683 $this->delete( $sOXID );
00684 } elseif ( $this->_blMallUsers ) {
00685 $sQ = "select oxid from oxuser where oxusername = '{$this->oxuser__oxusername->value}' and oxusername != '' ";
00686 if ( $oDB->getOne( $sQ ) ) {
00687 $oEx = oxNew( 'oxUserException' );
00688 $oLang = oxLang::getInstance();
00689 $oEx->setMessage( sprintf( $oLang->translateString( 'EXCEPTION_USER_USEREXISTS', $oLang->getTplLanguage() ), $this->oxuser__oxusername->value ) );
00690 throw $oEx;
00691 }
00692 }
00693
00694 $this->oxuser__oxshopid = new oxField( $sShopID, oxField::T_RAW );
00695 if ( ( $blOK = $this->save() ) ) {
00696
00697 $oDB->execute( "delete from oxaddress where oxaddress.oxuserid = '{$this->oxuser__oxid->value}' " );
00698 $oDB->execute( "update oxuserpayments set oxuserpayments.oxuserid = '{$this->oxuser__oxusername->value}' where oxuserpayments.oxuserid = '{$this->oxuser__oxid->value}' " );
00699 } else {
00700 $oEx = oxNew( 'oxUserException' );
00701 $oEx->setMessage( 'EXCEPTION_USER_USERCREATIONFAILED' );
00702 throw $oEx;
00703 }
00704
00705 return $blOK;
00706 }
00707
00715 public function addToGroup( $sGroupID )
00716 {
00717 if ( !$this->inGroup( $sGroupID ) ) {
00718 $oNewGroup = oxNew( 'oxobject2group' );
00719 $oNewGroup->oxobject2group__oxobjectid = new oxField($this->getId(), oxField::T_RAW);
00720 $oNewGroup->oxobject2group__oxgroupsid = new oxField($sGroupID, oxField::T_RAW);
00721 if ( $oNewGroup->save() ) {
00722 $this->_oGroups[$sGroupID] = $oNewGroup;
00723 return true;
00724 }
00725 }
00726 return false;
00727 }
00728
00736 public function removeFromGroup( $sGroupID = null )
00737 {
00738 if ( $sGroupID != null && $this->inGroup( $sGroupID ) ) {
00739 $oGroups = oxNew( 'oxlist' );
00740 $oGroups->init( 'oxobject2group' );
00741 $sSelect = 'select * from oxobject2group where oxobject2group.oxobjectid = "'.$this->getId().'" and oxobject2group.oxgroupsid = "'.$sGroupID.'" ';
00742 $oGroups->selectString( $sSelect );
00743 foreach ( $oGroups as $oRemgroup ) {
00744 if ( $oRemgroup->delete() ) {
00745 unset( $this->_oGroups[$oRemgroup->oxobject2group__oxgroupsid->value] );
00746 }
00747 }
00748 }
00749 }
00750
00759 public function onOrderExecute( $oBasket, $iSuccess )
00760 {
00761
00762 if ( is_numeric( $iSuccess ) && $iSuccess != 2 && $iSuccess <= 3 ) {
00763
00764 if ( !$this->oxuser__oxdisableautogrp->value ) {
00765
00766 $myConfig = $this->getConfig();
00767 $dMidlleCustPrice = (float) $myConfig->getConfigParam( 'sMidlleCustPrice' );
00768 $dLargeCustPrice = (float) $myConfig->getConfigParam( 'sLargeCustPrice' );
00769
00770 $this->addToGroup( 'oxidcustomer' );
00771 $dBasketPrice = $oBasket->getPrice()->getBruttoPrice();
00772 if ( $dBasketPrice < $dMidlleCustPrice ) {
00773 $this->addToGroup( 'oxidsmallcust' );
00774 }
00775 if ( $dBasketPrice >= $dMidlleCustPrice && $dBasketPrice < $dLargeCustPrice ) {
00776 $this->addToGroup( 'oxidmiddlecust' );
00777 }
00778 if ( $dBasketPrice >= $dLargeCustPrice ) {
00779 $this->addToGroup( 'oxidgoodcust' );
00780 }
00781 }
00782
00783 if ( $this->inGroup( 'oxidnotyetordered' ) ) {
00784 $this->removeFromGroup( 'oxidnotyetordered' );
00785 }
00786 }
00787 }
00788
00796 public function getBasket( $sName )
00797 {
00798 if ( !isset( $this->_aBaskets[$sName] ) ) {
00799 $oBasket = oxNew( 'oxuserbasket' );
00800 $aWhere = array( 'oxuserbaskets.oxuserid' => $this->getId(), 'oxuserbaskets.oxtitle' => $sName );
00801
00802
00803 if ( !$oBasket->assignRecord( $oBasket->buildSelectString( $aWhere ) ) ) {
00804 $oBasket->oxuserbaskets__oxtitle = new oxField($sName);
00805 $oBasket->oxuserbaskets__oxuserid = new oxField($this->getId());
00806
00807
00808 $oBasket->setIsNewBasket();
00809 }
00810
00811 $this->_aBaskets[$sName] = $oBasket;
00812 }
00813
00814 return $this->_aBaskets[$sName];
00815 }
00816
00825 public function convertBirthday( $aData )
00826 {
00827
00828
00829 $iYear = isset($aData['year'])?((int) $aData['year']):false;
00830 $iMonth = isset($aData['month'])?((int) $aData['month']):false;
00831 $iDay = isset($aData['day'])?((int) $aData['day']):false;
00832
00833
00834 if ( !$iYear && !$iMonth && !$iDay )
00835 return "";
00836
00837
00838 if ( !$iYear || $iYear < 1000 || $iYear > 9999)
00839 $iYear = date('Y');
00840
00841
00842 if ( !$iMonth || $iMonth < 1 || $iMonth > 12)
00843 $iMonth = 1;
00844
00845
00846 $iMaxDays = 31;
00847 switch( $iMonth) {
00848 case 2 :
00849 if ($iMaxDays > 28)
00850 $iMaxDays = ($iYear % 4 == 0 && ($iYear % 100 != 0 || $iYear % 400 == 0)) ? 29 : 28;
00851 break;
00852 case 4 :
00853 case 6 :
00854 case 9 :
00855 case 11 :
00856 $iMaxDays = min(30, $iMaxDays);
00857 break;
00858 }
00859
00860
00861 if ( !$iDay || $iDay < 1 || $iDay > $iMaxDays) {
00862 $iDay = 1;
00863 }
00864
00865
00866 return sprintf("%04d-%02d-%02d", $iYear, $iMonth, $iDay);
00867 }
00868
00875 public function getBoni()
00876 {
00877 return 1000;
00878 }
00879
00892 public function addDynGroup( $sDynGoup, $aDeniedDynGroups )
00893 {
00894
00895 $sDynGoup = strtolower( trim( $sDynGoup ) );
00896
00897
00898 $aDisabledDynGroups = array_merge( array( 'oxidadmin' ), (array) $aDeniedDynGroups );
00899
00900
00901 $blAdd = false;
00902
00903
00904 if ( $this->oxuser__oxdisableautogrp->value || !$sDynGoup ) {
00905 $blAdd = false;
00906 } elseif ( in_array( $sDynGoup, $aDisabledDynGroups ) ) {
00907
00908 $blAdd = false;
00909 } elseif ( $this->addToGroup( $sDynGoup ) ) {
00910 $blAdd = true;
00911 }
00912
00913
00914 oxSession::deleteVar( 'dgr' );
00915
00916 return $blAdd;
00917 }
00918
00934 public function checkValues( $sLogin, $sPassword, $sPassword2, $aInvAddress, $aDelAddress )
00935 {
00936
00937 $this->_checkLogin( $sLogin, $aInvAddress );
00938
00939
00940 $this->_checkEmail( $sLogin );
00941
00942
00943 $this->_checkPassword( $sPassword, $sPassword2, ((int) oxConfig::getParameter( 'option' ) == 3) );
00944
00945
00946 $this->_checkRequiredFields( $aInvAddress, $aDelAddress );
00947
00948
00949 $this->_checkCountries( $aInvAddress, $aDelAddress );
00950
00951
00952 $this->_checkVatId( $aInvAddress );
00953 }
00954
00963 public function setNewsSubscription( $blSubscribe, $blSendOptIn )
00964 {
00965
00966 $blSuccess = false;
00967 $myConfig = $this->getConfig();
00968
00969
00970 $oNewsSubscription = $this->getNewsSubscription();
00971 if ( $blSubscribe && $oNewsSubscription->getOptInStatus() != 1 ) {
00972 if ( !$blSendOptIn ) {
00973
00974
00975 $this->addToGroup( 'oxidnewsletter' );
00976
00977 $oNewsSubscription->setOptInStatus( 1 );
00978 $blSuccess = true;
00979 } else {
00980
00981
00982 $oNewsSubscription->setOptInStatus( 2 );
00983
00984
00985 $oEmail = oxNew( 'oxemail' );
00986 $blSuccess = $oEmail->sendNewsletterDBOptInMail( $this );
00987 }
00988 } elseif ( !$blSubscribe ) {
00989 $this->removeFromGroup( 'oxidnewsletter' );
00990 $oNewsSubscription->setOptInStatus( 0 );
00991 $blSuccess = true;
00992 }
00993
00994 return $blSuccess;
00995 }
00996
01014 public function changeUserData( $sUser, $sPassword, $sPassword2, $aInvAddress, $aDelAddress )
01015 {
01016
01017
01018 $this->checkValues( $sUser, $sPassword, $sPassword2, $aInvAddress, $aDelAddress );
01019
01020
01021 $this->assign( $aInvAddress );
01022
01023
01024
01025 $this->_assignAddress( $aDelAddress );
01026
01027
01028 if ( $this->save() ) {
01029
01030
01031 $sCountryId = isset( $aInvAddress['oxuser__oxcountryid'] )?$aInvAddress['oxuser__oxcountryid']:'';
01032 $this->_setAutoGroups( $sCountryId );
01033 }
01034 }
01035
01044 public function addUserAddress( $oUser )
01045 {
01046
01047 if ( $this->_hasUserAddress( $oUser->getId() ) ) {
01048 return false;
01049 }
01050
01051 $oAddress = oxNew( 'oxbase' );
01052 $oAddress->init( 'oxaddress' );
01053
01054 $oAddress->oxaddress__oxuserid = new oxField($this->getId(), oxField::T_RAW);
01055 $oAddress->oxaddress__oxaddressuserid = new oxField($oUser->getId(), oxField::T_RAW);
01056 $oAddress->oxaddress__oxfname = new oxField($oUser->oxuser__oxfname->value, oxField::T_RAW);
01057 $oAddress->oxaddress__oxlname = new oxField($oUser->oxuser__oxlname->value, oxField::T_RAW);
01058 $oAddress->oxaddress__oxstreet = new oxField($oUser->oxuser__oxstreet->value, oxField::T_RAW);
01059 $oAddress->oxaddress__oxstreetnr = new oxField($oUser->oxuser__oxstreetnr->value, oxField::T_RAW);
01060 $oAddress->oxaddress__oxcity = new oxField($oUser->oxuser__oxcity->value, oxField::T_RAW);
01061 $oAddress->oxaddress__oxzip = new oxField($oUser->oxuser__oxzip->value, oxField::T_RAW);
01062 $oAddress->oxaddress__oxcountry = new oxField($oUser->oxuser__oxcountry->value, oxField::T_RAW);
01063 $oAddress->oxaddress__oxcountryid = new oxField($oUser->oxuser__oxcountryid->value, oxField::T_RAW);
01064 $oAddress->oxaddress__oxcompany = new oxField($oUser->oxuser__oxcompany->value, oxField::T_RAW);
01065
01066
01067 if ( $oAddress->save() ) {
01068
01069 $this->_oAddresses = null;
01070 return $oAddress->getId();
01071 }
01072 }
01073
01081 protected function _assignAddress( $aDelAddress )
01082 {
01083 if ( ( isset( $aDelAddress['oxaddress__oxfname'] ) && $aDelAddress['oxaddress__oxfname'] ) ||
01084 ( isset( $aDelAddress['oxaddress__oxlname'] ) && $aDelAddress['oxaddress__oxlname'] ) ) {
01085
01086 $sAddressId = oxConfig::getParameter( 'oxaddressid' );
01087 $aDelAddress['oxaddress__oxid'] = ( $sAddressId === null || $sAddressId == -1 || $sAddressId == -2 ) ? null : $sAddressId;
01088
01089 $oAddress = oxNew( 'oxbase' );
01090 $oAddress->init( 'oxaddress' );
01091 $oAddress->assign( $aDelAddress );
01092 $oAddress->oxaddress__oxuserid = new oxField( $this->getId(), oxField::T_RAW );
01093 $oAddress->oxaddress__oxcountry = $this->getUserCountry( $oAddress->oxaddress__oxcountryid->value );
01094 $oAddress->save();
01095
01096
01097 $this->_oAddresses = null;
01098
01099
01100 oxSession::setVar( 'deladrid', $oAddress->getId() );
01101 } else {
01102
01103 oxSession::setVar( 'deladrid', null );
01104 }
01105 }
01106
01119 public function login( $sUser, $sPassword, $blCookie = false)
01120 {
01121 if ( $this->isAdmin() && !count( oxUtilsServer::getInstance()->getOxCookie() ) ) {
01122 $oEx = oxNew( 'oxCookieException' );
01123 $oEx->setMessage( 'EXCEPTION_COOKIE_NOCOOKIE' );
01124 throw $oEx;
01125 }
01126
01127 $myConfig = $this->getConfig();
01128 if ( $sPassword ) {
01129
01130 $sShopID = $myConfig->getShopId();
01131 $oDb = oxDb::getDb();
01132
01133 $sUserSelect = is_numeric( $sUser ) ? "oxuser.oxcustnr = {$sUser} " : "oxuser.oxusername = " . $oDb->quote( $sUser );
01134 $sPassSelect = " oxuser.oxpassword = MD5( CONCAT( ".$oDb->quote( $sPassword ).", UNHEX( oxuser.oxpasssalt ) ) ) ";
01135 $sShopSelect = "";
01136
01137
01138
01139 if ( $this->isAdmin() ) {
01140 $sShopSelect = " and ( oxrights != 'user' ) ";
01141 }
01142
01143 $sWhat = "oxid";
01144
01145 $sSelect = "select $sWhat from oxuser where oxuser.oxactive = 1 and {$sPassSelect} and {$sUserSelect} {$sShopSelect} ";
01146 if ( $myConfig->isDemoShop() && $this->isAdmin() ) {
01147 if ( $sPassword == "admin" && $sUser == "admin" ) {
01148 $sSelect = "select $sWhat from oxuser where oxrights = 'malladmin' {$sShopSelect} ";
01149 } else {
01150 $oEx = oxNew( 'oxUserException' );
01151 $oEx->setMessage( 'EXCEPTION_USER_NOVALIDLOGIN' );
01152 throw $oEx;
01153 }
01154 }
01155
01156
01157 $aData = $oDb->getAll( $sSelect );
01158 $sOXID = @$aData[0][0];
01159 if ( isset( $sOXID ) && $sOXID && !@$aData[0][1] ) {
01160
01161 if ( !$this->load( $sOXID ) ) {
01162 $oEx = oxNew( 'oxUserException' );
01163 $oEx->setMessage( 'EXCEPTION_USER_NOVALIDLOGIN' );
01164 throw $oEx;
01165 }
01166 }
01167 }
01168
01169
01170
01171 if ( $this->oxuser__oxid->value ) {
01172 if ( $this->isAdmin() ) {
01173 oxSession::setVar( 'auth', $this->oxuser__oxid->value );
01174 } else {
01175 oxSession::setVar( 'usr', $this->oxuser__oxid->value );
01176 }
01177
01178
01179 if ( $blCookie ) {
01180 oxUtilsServer::getInstance()->setUserCookie( $this->oxuser__oxusername->value, $this->oxuser__oxpassword->value, $myConfig->getShopId() );
01181 }
01182 return true;
01183 } else {
01184 $oEx = oxNew( 'oxUserException' );
01185 $oEx->setMessage( 'EXCEPTION_USER_NOVALIDLOGIN' );
01186 throw $oEx;
01187 }
01188 }
01189
01200 public function openIdLogin( $sUser )
01201 {
01202 $myConfig = $this->getConfig();
01203 $sShopID = $myConfig->getShopId();
01204 $oDb = oxDb::getDb();
01205
01206 $sUserSelect = "oxuser.oxusername = " . $oDb->quote( $sUser );
01207 $sShopSelect = "";
01208
01209
01210 $sSelect = "select oxid from oxuser where oxuser.oxactive = 1 and {$sUserSelect} {$sShopSelect} ";
01211
01212
01213 $aData = $oDb->getAll( $sSelect );
01214 $sOXID = @$aData[0][0];
01215 if ( isset( $sOXID ) && $sOXID ) {
01216
01217 if ( !$this->load( $sOXID ) ) {
01218 $oEx = oxNew( 'oxUserException' );
01219 $oEx->setMessage( 'EXCEPTION_USER_NOVALIDLOGIN' );
01220 throw $oEx;
01221 }
01222 }
01223
01224
01225 if ( $this->oxuser__oxid->value ) {
01226 oxSession::setVar( 'usr', $this->oxuser__oxid->value );
01227 return true;
01228 } else {
01229 $oEx = oxNew( 'oxUserException' );
01230 $oEx->setMessage( 'EXCEPTION_USER_NOVALIDLOGIN' );
01231 throw $oEx;
01232 }
01233 }
01234
01240 public function logout()
01241 {
01242
01243 oxSession::deleteVar( 'usr' );
01244 oxSession::deleteVar( 'auth' );
01245 oxSession::deleteVar( 'dgr' );
01246 oxSession::deleteVar( 'dynvalue' );
01247 oxSession::deleteVar( 'paymentid' );
01248
01249
01250
01251 oxUtilsServer::getInstance()->deleteUserCookie( $this->getConfig()->getShopID() );
01252
01253
01254 $this->setUser( null );
01255
01256 return true;
01257 }
01258
01265 public function loadAdminUser()
01266 {
01267 return $this->loadActiveUser( true );
01268 }
01269
01278 public function loadActiveUser( $blForceAdmin = false )
01279 {
01280 $myConfig = $this->getConfig();
01281
01282 $blAdmin = $myConfig->isAdmin() || $blForceAdmin;
01283 $oDB = oxDb::getDb();
01284
01285
01286 $sUserID = $blAdmin ? oxSession::getVar( 'auth' ) : oxSession::getVar( 'usr' );
01287 $blFoundInCookie = false;
01288
01289
01290 if ( !$sUserID && !$blAdmin ) {
01291 $sShopID = $myConfig->getShopId();
01292 if ( ( $sSet = oxUtilsServer::getInstance()->getUserCookie( $sShopID ) ) ) {
01293 $aData = explode( '@@@', $sSet );
01294 $sUser = $oDB->quote( $aData[0] );
01295 $sPWD = @$aData[1];
01296
01297 $sSelect = 'select oxid, oxpassword from oxuser where oxuser.oxpassword != "" and oxuser.oxactive = 1 and oxuser.oxusername = '.$sUser;
01298
01299
01300 $oDB = oxDb::getDb();
01301 $rs = $oDB->execute( $sSelect );
01302 if ( $rs != false && $rs->recordCount() > 0 ) {
01303 while (!$rs->EOF) {
01304 $sTest = crypt( $rs->fields[1], 'ox' );
01305 if ( $sTest == $sPWD ) {
01306
01307 $sUserID = $rs->fields[0];
01308 $blFoundInCookie = true;
01309 break;
01310 }
01311 $rs->moveNext();
01312 }
01313 }
01314 }
01315 }
01316
01317
01318 if ( $sUserID ) {
01319 if ( $this->load( $sUserID ) ) {
01320
01321 if ($blAdmin) {
01322 oxSession::setVar( 'auth', $sUserID );
01323 } else {
01324 oxSession::setVar( 'usr', $sUserID );
01325 }
01326
01327
01328 $this->_blLoadedFromCookie = $blFoundInCookie;
01329 return true;
01330 }
01331 } else {
01332
01333 oxSession::deleteVar( 'usr' );
01334 oxSession::deleteVar( 'auth' );
01335
01336 return false;
01337 }
01338 }
01339
01352 protected function _ldapLogin( $sUser, $sPassword, $sShopID, $sShopSelect)
01353 {
01354 include "oxldap.php";
01355 $myConfig = $this->getConfig();
01356 $oDb = oxDb::getDb();
01357
01358 $aLDAPParams = $myConfig->getConfigParam( 'aLDAPParams' );
01359 $oLDAP = new oxLDAP( $aLDAPParams['HOST'], $aLDAPParams['PORT'] );
01360
01361 $sLDAPKey = $oDb->getOne("select oxldapkey from oxuser where oxuser.oxactive = 1 and oxuser.oxusername = ".$oDb->quote($sUser)." $sShopSelect");
01362 if ( isset( $sLDAPKey) && $sLDAPKey) {
01363 $sUser = $sLDAPKey;
01364 }
01365
01366
01367 $oLDAP->login( $sUser, $sPassword, $aLDAPParams['USERQUERY'], $aLDAPParams['BASEDN'], $aLDAPParams['FILTER']);
01368
01369 $aData = $oLDAP->mapData($aLDAPParams['DATAMAP']);
01370 if ( isset( $aData['OXUSERNAME']) && $aData['OXUSERNAME']) {
01371
01372
01373 $sSelect = "select oxid from oxuser where oxuser.oxusername = ".$oDb->quote($aData['OXUSERNAME'])." $sShopSelect";
01374 $sOXID = $oDb->getOne( $sSelect);
01375
01376 if ( !isset( $sOXID) || !$sOXID) {
01377
01378 $this->setId();
01379
01380
01381 foreach ( $aData as $fldname => $value) {
01382 $sField = "oxuser__".strtolower( $fldname);
01383 $this->$sField->setValue($aData[$fldname]);
01384 }
01385
01386 $this->oxuser__oxactive->setValue(1);
01387 $this->oxuser__oxshopid->setValue($sShopID);
01388 $this->oxuser__oxldapkey->setValue($sUser);
01389 $this->oxuser__oxrights->setValue("user");
01390 $this->setPassword( "ldap user" );
01391
01392 $this->save();
01393 } else {
01394 $this->load( $sOXID);
01395 }
01396
01397 } else {
01398 $oEx = oxNew( 'oxUserException' );
01399 $oEx->setMessage('EXCEPTION_USER_NOVALUES');
01400 throw $oEx;
01401 }
01402 }
01403
01410 protected function _getUserRights()
01411 {
01412
01413 if ( !$this->oxuser__oxrights->value )
01414 return 'user';
01415
01416 $oDB = oxDb::getDb();
01417 $myConfig = $this->getConfig();
01418 $sAuthRights = null;
01419
01420
01421 $sAuthUserID = $this->isAdmin()?oxSession::getVar( 'auth' ):null;
01422 $sAuthUserID = $sAuthUserID?$sAuthUserID:oxSession::getVar( 'usr' );
01423 if ( $sAuthUserID ) {
01424 $sAuthUserID = $oDB->quote( $sAuthUserID );
01425 $sAuthRights = $oDB->getOne( 'select oxrights from '.$this->getViewName().' where oxid='.$sAuthUserID );
01426 }
01427
01428
01429 $aRights = array();
01430
01431
01432 if ( $sCurrRights = $oDB->getOne( 'select oxrights from '.$this->getViewName().' where oxid="'.$this->getId().'"' ) ) {
01433 $aRights[] = $sCurrRights;
01434 }
01435 $aRights[] = 'user';
01436
01437 if ( !$sAuthRights || !( $sAuthRights == 'malladmin' || $sAuthRights == $myConfig->getShopId() ) ) {
01438 return current( $aRights );
01439 } elseif ( $sAuthRights == $myConfig->getShopId() ) {
01440 $aRights[] = $sAuthRights;
01441 if ( !in_array( $this->oxuser__oxrights->value, $aRights ) ) {
01442 return current( $aRights );
01443 }
01444 }
01445
01446
01447 return $this->oxuser__oxrights->value;
01448 }
01449
01459 protected function _setRecordNumber( $sMaxField, $aWhere = null ,$iMaxTryCnt = 5 )
01460 {
01461
01462
01463
01464
01465
01466
01467 return parent::_setRecordNumber( $sMaxField, $aWhere, $iMaxTryCnt );
01468 }
01469
01475 protected function _insert()
01476 {
01477
01478
01479 $this->oxuser__oxcreate = new oxField(date( 'Y-m-d H:i:s' ), oxField::T_RAW);
01480
01481 if ( !isset( $this->oxuser__oxboni->value ) ) {
01482 $this->oxuser__oxboni = new oxField($this->getBoni(), oxField::T_RAW);
01483 }
01484
01485 if ( $blInsert = parent::_insert() ) {
01486
01487 if ( !$this->oxuser__oxcustnr->value || !$this->isAdmin() ) {
01488 $this->_setRecordNumber( 'oxcustnr' );
01489 }
01490 }
01491
01492 return $blInsert;
01493 }
01494
01500 protected function _update()
01501 {
01502
01503 if (!$this->oxuser__oxpassword->value && $this->oxuser__oxregister->value < 1) {
01504 $this->_aSkipSaveFields[] = 'oxboni';
01505 }
01506
01507
01508 $this->_aSkipSaveFields[] = 'oxcreate';
01509 if ( !$this->isAdmin() ) {
01510 $this->_aSkipSaveFields[] = 'oxcustnr';
01511 $this->_aSkipSaveFields[] = 'oxrights';
01512 }
01513
01514
01515 if ( ( $blUpdate = parent::_update() ) ) {
01516 $this->getNewsSubscription()->updateSubscription( $this );
01517 }
01518
01519 return $blUpdate;
01520 }
01521
01537 protected function _checkLogin( &$sLogin, $aInvAddress )
01538 {
01539 $myConfig = $this->getConfig();
01540
01541 $sLogin = ( isset( $aInvAddress['oxuser__oxusername'] ) )?$aInvAddress['oxuser__oxusername']:$sLogin;
01542
01543
01544
01545 if ( $this->oxuser__oxpassword->value && $sLogin != $this->oxuser__oxusername->value ) {
01546
01547
01548 $sNewPass = (isset( $aInvAddress['oxuser__oxpassword']) && $aInvAddress['oxuser__oxpassword'] )?$aInvAddress['oxuser__oxpassword']:oxConfig::getParameter( 'user_password' );
01549 if ( !$sNewPass ) {
01550
01551
01552 $oEx = oxNew( 'oxInputException' );
01553 $oEx->setMessage('EXCEPTION_INPUT_NOTALLFIELDS');
01554 throw $oEx;
01555 } else {
01556
01557
01558 if ( !$this->isSamePassword( $sNewPass ) ) {
01559 $oEx = oxNew( 'oxUserException' );
01560 $oEx->setMessage('EXCEPTION_USER_PWDDONTMATCH');
01561 throw $oEx;
01562 }
01563 }
01564 }
01565
01566 if ( $this->checkIfEmailExists( $sLogin ) ) {
01567
01568 $oEx = oxNew( 'oxUserException' );
01569 $oLang = oxLang::getInstance();
01570 $oEx->setMessage( sprintf( $oLang->translateString( 'EXCEPTION_USER_USEREXISTS', $oLang->getTplLanguage() ), $sLogin ) );
01571 throw $oEx;
01572 }
01573 }
01574
01582 public function checkIfEmailExists( $sEmail )
01583 {
01584 $myConfig = $this->getConfig();
01585 $oDB = oxDb::getDb();
01586 $iShopId = $myConfig->getShopId();
01587 $blExists = false;
01588
01589 $sQ = 'select oxshopid, oxrights, oxpassword from oxuser where oxusername = '. $oDB->quote( $sEmail );
01590 if ( ( $sOxid = $this->getId() ) ) {
01591 $sQ .= " and oxid <> '$sOxid' ";
01592 }
01593
01594 $oRs = $oDB->execute( $sQ );
01595 if ( $oRs != false && $oRs->recordCount() > 0 ) {
01596
01597 if ( $this->_blMallUsers ) {
01598
01599 $blExists = true;
01600 if ( $oRs->fields[1] == 'user' && !$oRs->fields[2] ) {
01601
01602
01603 $blExists = false;
01604 }
01605 } else {
01606
01607 $blExists = false;
01608 while ( !$oRs->EOF ) {
01609 if ( $oRs->fields[1] != 'user' ) {
01610
01611
01612 $blExists = true;
01613 break;
01614 } elseif ( $oRs->fields[0] == $iShopId && $oRs->fields[2] ) {
01615
01616
01617 $blExists = true;
01618 break;
01619 }
01620
01621 $oRs->moveNext();
01622 }
01623 }
01624 }
01625 return $blExists;
01626 }
01627
01635 public function getUserRecommLists( $sOXID = null )
01636 {
01637 if ( !$sOXID )
01638 $sOXID = $this->getId();
01639
01640
01641 $iActPage = (int) oxConfig::getParameter( 'pgNr' );
01642 $iActPage = ($iActPage < 0) ? 0 : $iActPage;
01643
01644
01645 $iNrofCatArticles = $this->getConfig()->getConfigParam( 'iNrofCatArticles' );
01646 $iNrofCatArticles = $iNrofCatArticles ? $iNrofCatArticles : 10;
01647
01648
01649 $oRecommList = oxNew( 'oxlist' );
01650 $oRecommList->init( 'oxrecommlist' );
01651 $oRecommList->setSqlLimit( $iNrofCatArticles * $iActPage, $iNrofCatArticles );
01652 $iShopId = $this->getConfig()->getShopId();
01653 $sSelect = 'select * from oxrecommlists where oxuserid ="'. $sOXID .'" and oxshopid ="'. $iShopId .'"';
01654 $oRecommList->selectString( $sSelect );
01655
01656 return $oRecommList;
01657 }
01658
01666 public function getRecommListsCount( $sOx = null )
01667 {
01668 if ( !$sOx ) {
01669 $sOXID = $this->getId();
01670 }
01671
01672 if ( $this->_iCntRecommLists === null || $sOx ) {
01673 $this->_iCntRecommLists = 0;
01674 $iShopId = $this->getConfig()->getShopId();
01675 $sSelect = 'select count(oxid) from oxrecommlists where oxuserid ="'. $sOXID .'" and oxshopid ="'. $iShopId .'"';
01676 $this->_iCntRecommLists = oxDb::getDb()->getOne( $sSelect );
01677 }
01678 return $this->_iCntRecommLists;
01679 }
01680
01689 protected function _checkEmail( $sEmail )
01690 {
01691
01692 if ( !$sEmail ) {
01693 $oEx = oxNew( 'oxInputException' );
01694 $oEx->setMessage('EXCEPTION_INPUT_NOTALLFIELDS');
01695 throw $oEx;
01696 }
01697
01698
01699 if ( !oxUtils::getInstance()->isValidEmail( $sEmail ) ) {
01700 $oEx = oxNew( 'oxInputException' );
01701 $oEx->setMessage( 'EXCEPTION_INPUT_NOVALIDEMAIL' );
01702 throw $oEx;
01703 }
01704 }
01705
01720 protected function _checkPassword( $sNewPass, $sConfPass, $blCheckLenght = false )
01721 {
01722 $this->checkPassword( $sNewPass, $sConfPass, $blCheckLenght );
01723 }
01724
01737 public function checkPassword( $sNewPass, $sConfPass, $blCheckLenght = false )
01738 {
01739
01740 if ( $blCheckLenght && getStr()->strlen( $sNewPass ) == 0 ) {
01741 $oEx = oxNew( 'oxInputException' );
01742 $oEx->setMessage('EXCEPTION_INPUT_EMPTYPASS');
01743 throw $oEx;
01744 }
01745
01746
01747 if ( $blCheckLenght && getStr()->strlen( $sNewPass ) < 6 ) {
01748 $oEx = oxNew( 'oxInputException' );
01749 $oEx->setMessage('EXCEPTION_INPUT_PASSTOOSHORT');
01750 throw $oEx;
01751 }
01752
01753
01754 if ( $sNewPass != $sConfPass ) {
01755 $oEx = oxNew( 'oxUserException' );
01756 $oEx->setMessage('EXCEPTION_USER_PWDDONTMATCH');
01757 throw $oEx;
01758 }
01759 }
01760
01769 protected function _checkCountries( $aInvAddress, $aDelAddress )
01770 {
01771 $sBillCtry = isset( $aInvAddress['oxuser__oxcountryid'] ) ? $aInvAddress['oxuser__oxcountryid'] : null;
01772 $sDelCtry = isset( $aDelAddress['oxaddress__oxcountryid'] ) ? $aDelAddress['oxaddress__oxcountryid'] : null;
01773
01774 if ( $sBillCtry || $sDelCtry ) {
01775 $oDb = oxDb::getDb();
01776
01777 if ( ( $sBillCtry == $sDelCtry ) || ( !$sBillCtry && $sDelCtry ) || ( $sBillCtry && !$sDelCtry ) ) {
01778 $sBillCtry = $sBillCtry ? $sBillCtry : $sDelCtry;
01779 $sQ = "select oxactive from oxcountry where oxid = ".$oDb->quote( $sBillCtry )." ";
01780 } else {
01781 $sQ = "select ( select oxactive from oxcountry where oxid = ".$oDb->quote( $sBillCtry )." ) and
01782 ( select oxactive from oxcountry where oxid = ".$oDb->quote( $sDelCtry )." ) ";
01783 }
01784
01785 if ( !$oDb->getOne( $sQ ) ) {
01786 $oEx = oxNew( 'oxUserException' );
01787 $oEx->setMessage('EXCEPTION_INPUT_NOTALLFIELDS' );
01788 throw $oEx;
01789 }
01790 }
01791 }
01792
01804 protected function _checkRequiredFields( $aInvAddress, $aDelAddress )
01805 {
01806
01807 $aMustFields = array( 'oxuser__oxfname',
01808 'oxuser__oxlname',
01809 'oxuser__oxstreetnr',
01810 'oxuser__oxstreet',
01811 'oxuser__oxzip',
01812 'oxuser__oxcity' );
01813
01814
01815 $aMustFillFields = $this->getConfig()->getConfigParam( 'aMustFillFields' );
01816 if ( is_array( $aMustFillFields ) ) {
01817 $aMustFields = $aMustFillFields;
01818 }
01819
01820
01821 $aInvAddress = is_array( $aInvAddress )?$aInvAddress:array();
01822 $aDelAddress = is_array( $aDelAddress )?$aDelAddress:array();
01823
01824
01825 $aFields = array_merge( $aInvAddress, $aDelAddress );
01826
01827
01828 $blCheckDel = false;
01829 if ( count( $aDelAddress ) ) {
01830 $blCheckDel = true;
01831 }
01832
01833
01834 foreach ( $aMustFields as $sMustField ) {
01835
01836
01837 if ( !$blCheckDel && strpos( $sMustField, 'oxaddress__' ) === 0 ) {
01838 continue;
01839 }
01840
01841 if ( isset( $aFields[$sMustField] ) && is_array( $aFields[$sMustField] ) ) {
01842 $this->_checkRequiredArrayFields( $sMustField, $aFields[$sMustField] );
01843 } elseif ( !isset( $aFields[$sMustField] ) || !trim( $aFields[$sMustField] ) ) {
01844 $oEx = oxNew( 'oxInputException' );
01845 $oEx->setMessage('EXCEPTION_INPUT_NOTALLFIELDS');
01846 throw $oEx;
01847 }
01848 }
01849 }
01850
01861 protected function _checkRequiredArrayFields( $sFieldName, $aFieldValues )
01862 {
01863 foreach ( $aFieldValues as $sValue ) {
01864 if ( !trim( $sValue ) ) {
01865 $oEx = oxNew( 'oxInputException' );
01866 $oEx->setMessage('EXCEPTION_INPUT_NOTALLFIELDS');
01867 throw $oEx;
01868 }
01869 }
01870 }
01871
01882 protected function _checkVatId( $aInvAddress )
01883 {
01884
01885 if ( $aInvAddress['oxuser__oxustid'] && $aInvAddress['oxuser__oxcompany'] ) {
01886
01887 if (!($sCountryId = $aInvAddress['oxuser__oxcountryid'])) {
01888
01889 return;
01890 }
01891 $oCountry = oxNew('oxcountry');
01892 if (!$oCountry->load($sCountryId)) {
01893 throw new oxObjectException();
01894 }
01895 if ($oCountry->isForeignCountry() && $oCountry->isInEU()) {
01896 if (strncmp($aInvAddress['oxuser__oxustid'], $oCountry->oxcountry__oxisoalpha2->value, 2)) {
01897 $oEx = oxNew( 'oxInputException' );
01898 $oEx->setMessage( 'VAT_MESSAGE_ID_NOT_VALID' );
01899 throw $oEx;
01900 }
01901 }
01902
01903 }
01904 }
01905
01914 protected function _setAutoGroups( $sCountryId )
01915 {
01916
01917 $blForeigner = true;
01918 $blForeignGroupExists = false;
01919 $blInlandGroupExists = false;
01920
01921 $aHomeCountry = $this->getConfig()->getConfigParam( 'aHomeCountry' );
01922
01923 if ( is_array($aHomeCountry)) {
01924 if (in_array($sCountryId, $aHomeCountry)) {
01925 $blForeigner = false;
01926 }
01927 } elseif ($sCountryId == $aHomeCountry) {
01928 $blForeigner = false;
01929 }
01930
01931 if ( $this->inGroup( 'oxidforeigncustomer' ) ) {
01932 $blForeignGroupExists = true;
01933 if ( !$blForeigner ) {
01934 $this->removeFromGroup( 'oxidforeigncustomer' );
01935 }
01936 }
01937
01938 if ( $this->inGroup( 'oxidnewcustomer' ) ) {
01939 $blInlandGroupExists = true;
01940 if ( $blForeigner ) {
01941 $this->removeFromGroup( 'oxidnewcustomer' );
01942 }
01943 }
01944
01945 if ( !$this->oxuser__oxdisableautogrp->value ) {
01946 if ( !$blForeignGroupExists && $blForeigner ) {
01947 $this->addToGroup( 'oxidforeigncustomer' );
01948 }
01949 if ( !$blInlandGroupExists && !$blForeigner ) {
01950 $this->addToGroup( 'oxidnewcustomer' );
01951 }
01952 }
01953 }
01954
01962 protected function _hasUserAddress( $sUserId )
01963 {
01964
01965 $oAddresses = $this->getUserAddresses();
01966 if ( $oAddresses && count($oAddresses)>0 ) {
01967 $oAddresses->rewind() ;
01968 foreach ($oAddresses as $key => $oAddress) {
01969 if ( $oAddress->oxaddress__oxaddressuserid->value == $sUserId ) {
01970 return true;
01971 }
01972 }
01973 }
01974 return false;
01975 }
01976
01989 protected function _setUserCookie( $sUser, $sPassword, $sShopId = null, $iTimeout = 31536000 )
01990 {
01991 oxUtilsServer::getInstance()->setUserCookie( $sUser, $sPassword, $sShopId, $iTimeout );
01992 }
01993
02003 protected function _deleteUserCookie( $sShopId = null )
02004 {
02005 oxUtilsServer::getInstance()->deleteUserCookie( $sShopId );
02006 }
02007
02017 protected static function _getUserCookie( $sShopId = null )
02018 {
02019 return oxUtilsServer::getInstance()->getUserCookie( $sShopId );
02020 }
02021
02022
02031 public function loadUserByUpdateId( $sUid )
02032 {
02033 $oDb = oxDb::getDb();
02034 $sQ = "select oxid from ".$this->getViewName()." where oxupdateexp >= ".time()." and MD5( CONCAT( oxid, oxshopid, oxupdatekey ) ) = ".$oDb->quote( $sUid );
02035 if ( $sUserId = $oDb->getOne( $sQ ) ) {
02036 return $this->load( $sUserId );
02037 }
02038 }
02039
02047 public function setUpdateKey( $blReset = false )
02048 {
02049 $sUpKey = $blReset ? '' : oxUtilsObject::getInstance()->generateUId();
02050 $iUpTime = $blReset ? 0 : oxUtilsDate::getInstance()->getTime() + $this->getUpdateLinkTerm();
02051
02052
02053 $this->oxuser__oxupdatekey = new oxField( $sUpKey, oxField::T_RAW );
02054
02055
02056 $this->oxuser__oxupdateexp = new oxField( $iUpTime, oxField::T_RAW );
02057
02058
02059 $this->save();
02060 }
02061
02067 public function getUpdateLinkTerm()
02068 {
02069 return 3600 * 6;
02070 }
02071
02079 public function isExpiredUpdateId( $sKey )
02080 {
02081 $oDb = oxDb::getDb();
02082 $sQ = "select 1 from ".$this->getViewName()." where oxupdateexp >= ".time()." and MD5( CONCAT( oxid, oxshopid, oxupdatekey ) ) = ".$oDb->quote( $sKey );
02083 return !( (bool) $oDb->getOne( $sQ ) );
02084 }
02085
02091 public function getUpdateId()
02092 {
02093 if ( $this->_sUpdateKey === null ) {
02094 $this->setUpdateKey();
02095 $this->_sUpdateKey = md5( $this->getId() . $this->oxuser__oxshopid->value . $this->oxuser__oxupdatekey->value );
02096 }
02097 return $this->_sUpdateKey;
02098 }
02099
02108 public function encodePassword( $sPassword, $sSalt )
02109 {
02110 $oDb = oxDb::getDb();
02111 return $oDb->getOne( "select MD5( CONCAT( ".$oDb->quote( $sPassword ).", UNHEX( '{$sSalt}' ) ) )" );
02112 }
02113
02121 public function prepareSalt( $sSalt )
02122 {
02123 return ( $sSalt ? oxDb::getDb()->getOne( "select HEX( '{$sSalt}' )" ) : '' );
02124 }
02125
02133 public function decodeSalt( $sSaltHex )
02134 {
02135 return ( $sSaltHex ? oxDb::getDb()->getOne( "select UNHEX( '{$sSaltHex}' )" ) : '' );
02136 }
02137
02145 public function setPassword( $sPassword = null )
02146 {
02147
02148 $sSalt = $sPassword ? $this->prepareSalt( oxUtilsObject::getInstance()->generateUID() ) : '';
02149
02150
02151 $sPassword = $sPassword ? $this->encodePassword( $sPassword, $sSalt ) : '';
02152
02153 $this->oxuser__oxpassword = new oxField( $sPassword, oxField::T_RAW );
02154 $this->oxuser__oxpasssalt = new oxField( $sSalt, oxField::T_RAW );
02155 }
02156
02164 public function isSamePassword( $sNewPass )
02165 {
02166 return $this->encodePassword( $sNewPass, $this->oxuser__oxpasssalt->value ) == $this->oxuser__oxpassword->value;
02167 }
02168
02174 public function isLoadedFromCookie()
02175 {
02176 return $this->_blLoadedFromCookie;
02177 }
02178
02185 public function getPasswordHash()
02186 {
02187 $sHash = null;
02188 if ( $this->oxuser__oxpassword->value ) {
02189 if ( strpos( $this->oxuser__oxpassword->value, 'ox_' ) === 0 ) {
02190
02191 $this->setPassword( oxUtils::getInstance()->strRem( $this->oxuser__oxpassword->value ) );
02192 } elseif ( ( strlen( $this->oxuser__oxpassword->value ) < 32 ) && ( strpos( $this->oxuser__oxpassword->value, 'openid_' ) !== 0 ) ) {
02193
02194 $this->setPassword( $this->oxuser__oxpassword->value );
02195 }
02196 $sHash = $this->oxuser__oxpassword->value;
02197 }
02198 return $sHash;
02199 }
02200
02209 public static function getAdminUser()
02210 {
02211 return self::getActiveUser( true );
02212 }
02213
02224 public static function getActiveUser( $blForceAdmin = false )
02225 {
02226 $oUser = oxNew( 'oxuser' );
02227 if ( $oUser->loadActiveUser( $blForceAdmin ) ) {
02228 return $oUser;
02229 } else {
02230 return false;
02231 }
02232 }
02233
02241 public function getOpenIdPassword( $iLength = 25 )
02242 {
02243 $sPassword= "openid_".substr( oxUtilsObject::getInstance()->generateUId(), 0, $iLength);
02244 return $sPassword;
02245 }
02246
02254 public function getReviewUserHash( $sUserId )
02255 {
02256 $sReviewUserHash = oxDb::getDb()->getOne('select md5(concat("oxid", oxpassword, oxusername )) from oxuser where oxid = "'.$sUserId.'"');
02257 return $sReviewUserHash;
02258 }
02259
02267 public function getReviewUserId( $sReviewUserHash )
02268 {
02269 $sUserId = oxDb::getDb()->getOne('select oxid from oxuser where md5(concat("oxid", oxpassword, oxusername )) = "'.$sReviewUserHash.'"');
02270 return $sUserId;
02271 }
02272
02273 }