00001 <?php
00002
00009 class oxUser extends oxBase
00010 {
00015 protected $_blDisableShopCheck = true;
00016
00021 protected $_oNewsSubscription = null;
00022
00027 protected $_sClassName = 'oxuser';
00028
00034 protected $_aBaskets = array();
00035
00041 protected $_oGroups;
00042
00048 protected $_aAddresses = array();
00049
00055 protected $_oPayments;
00056
00062 protected $_oRecommList;
00063
00069 protected $_blMallUsers = false;
00070
00076 protected static $_aUserCookie = array();
00077
00083 protected $_iCntNoticeListArticles = null;
00084
00090 protected $_iCntWishListArticles = null;
00091
00097 protected $_iCntRecommLists = null;
00098
00104 protected $_sUpdateKey = null;
00105
00111 protected $_blLoadedFromCookie = null;
00112
00118 protected $_sSelAddressId = null;
00119
00125 protected $_oSelAddress = null;
00126
00132 protected $_sWishId = null;
00133
00139 protected $_oUserCountryTitle = null;
00140
00146 public function __construct()
00147 {
00148 $this->setMallUsersStatus( $this->getConfig()->getConfigParam( 'blMallUsers' ) );
00149
00150 parent::__construct();
00151 $this->init( 'oxuser' );
00152 }
00153
00161 public function setMallUsersStatus( $blOn = false )
00162 {
00163 $this->_blMallUsers = $blOn;
00164 }
00165
00173 public function __get( $sParamName )
00174 {
00175
00176 switch ( $sParamName ) {
00177 case 'oGroups':
00178 return $this->_oGroups = $this->getUserGroups();
00179 break;
00180 case 'iCntNoticeListArticles':
00181 return $this->_iCntNoticeListArticles = $this->getNoticeListArtCnt();
00182 break;
00183 case 'iCntWishListArticles':
00184 return $this->_iCntWishListArticles = $this->getWishListArtCnt();
00185 break;
00186 case 'iCntRecommLists':
00187 return $this->_iCntRecommLists = $this->getRecommListsCount();
00188 break;
00189 case 'oAddresses':
00190 return $this->getUserAddresses();
00191 break;
00192 case 'oPayments':
00193 return $this->_oPayments = $this->getUserPayments();
00194 break;
00195 case 'oxuser__oxcountry':
00196 return $this->oxuser__oxcountry = $this->getUserCountry();
00197 break;
00198 case 'sDBOptin':
00199 return $this->sDBOptin = $this->getNewsSubscription()->getOptInStatus();
00200 break;
00201 case 'sEmailFailed':
00202 return $this->sEmailFailed = $this->getNewsSubscription()->getOptInEmailStatus();
00203 break;
00204 }
00205 }
00206
00212 public function getNewsSubscription()
00213 {
00214 if ( $this->_oNewsSubscription !== null ) {
00215 return $this->_oNewsSubscription;
00216 }
00217
00218 $this->_oNewsSubscription = oxNew( 'oxnewssubscribed' );
00219
00220
00221 if ( !$this->_oNewsSubscription->loadFromUserId( $this->getId() ) ) {
00222 if ( !$this->_oNewsSubscription->loadFromEmail( $this->oxuser__oxusername->value ) ) {
00223
00224
00225 $this->_oNewsSubscription->oxnewssubscribed__oxuserid = new oxField($this->getId(), oxField::T_RAW);
00226 $this->_oNewsSubscription->oxnewssubscribed__oxemail = new oxField($this->oxuser__oxusername->value, oxField::T_RAW);
00227 $this->_oNewsSubscription->oxnewssubscribed__oxsal = new oxField($this->oxuser__oxsal->value, oxField::T_RAW);
00228 $this->_oNewsSubscription->oxnewssubscribed__oxfname = new oxField($this->oxuser__oxfname->value, oxField::T_RAW);
00229 $this->_oNewsSubscription->oxnewssubscribed__oxlname = new oxField($this->oxuser__oxlname->value, oxField::T_RAW);
00230 }
00231 }
00232
00233 return $this->_oNewsSubscription;
00234 }
00235
00245 public function getUserCountry( $sCountryId = null, $iLang = null )
00246 {
00247 if ( $this->_oUserCountryTitle == null || $sCountryId ) {
00248 $sId = $sCountryId ? $sCountryId : $this->oxuser__oxcountryid->value;
00249 $oDb = oxDb::getDb();
00250 $sViewName = getViewName( 'oxcountry', $iLang );
00251 $sQ = "select oxtitle from {$sViewName} where oxid = " . $oDb->quote( $sId ) . " ";
00252 $oCountry = new oxField( $oDb->getOne( $sQ ), oxField::T_RAW);
00253 if ( !$sCountryId ) {
00254 $this->_oUserCountryTitle = $oCountry;
00255 }
00256 } else {
00257 return $this->_oUserCountryTitle;
00258 }
00259
00260 return $oCountry;
00261 }
00262
00270 public function getUserCountryId( $sCountry = null )
00271 {
00272 $oDb = oxDb::getDb();
00273 $sQ = "select oxid from ".getviewName( "oxcountry" )." where oxactive = '1' and oxisoalpha2 = " . $oDb->quote( $sCountry ) . " ";
00274 $sCountryId = $oDb->getOne( $sQ );
00275
00276 return $sCountryId;
00277 }
00278
00286 public function getUserGroups( $sOXID = null )
00287 {
00288
00289 if ( isset( $this->_oGroups ) ) {
00290 return $this->_oGroups;
00291 }
00292
00293 if ( !$sOXID ) {
00294 $sOXID = $this->getId();
00295 }
00296
00297 $sViewName = getViewName( "oxgroups" );
00298 $this->_oGroups = oxNew( 'oxlist', 'oxgroups' );
00299 $sSelect = "select {$sViewName}.* from {$sViewName} left join oxobject2group on oxobject2group.oxgroupsid = {$sViewName}.oxid
00300 where oxobject2group.oxobjectid = " . oxDb::getDb()->quote( $sOXID );
00301 $this->_oGroups->selectString( $sSelect );
00302 return $this->_oGroups;
00303 }
00304
00312 public function getUserAddresses( $sUserId = null )
00313 {
00314 $sUserId = isset( $sUserId ) ? $sUserId : $this->getId();
00315 if ( !isset( $this->_aAddresses[$sUserId] ) ) {
00316 $sSelect = "select * from oxaddress where oxaddress.oxuserid = " . oxDb::getDb()->quote( $sUserId );
00317
00318
00319 $this->_aAddresses[$sUserId] = oxNew( "oxlist" );
00320 $this->_aAddresses[$sUserId]->init( "oxaddress" );
00321 $this->_aAddresses[$sUserId]->selectString( $sSelect );
00322
00323
00324 if ( $sAddressId = $this->getSelectedAddressId() ) {
00325 foreach ( $this->_aAddresses[$sUserId] as $oAddress ) {
00326 if ( $oAddress->getId() === $sAddressId ) {
00327 $oAddress->setSelected();
00328 break;
00329 }
00330 }
00331 }
00332 }
00333 return $this->_aAddresses[$sUserId];
00334 }
00335
00343 public function setSelectedAddressId( $sAddressId )
00344 {
00345 $this->_sSelAddressId = $sAddressId;
00346 }
00347
00353 public function getSelectedAddressId()
00354 {
00355 if ( $this->_sSelAddressId !== null ) {
00356 return $this->_sSelAddressId;
00357 }
00358
00359 $sAddressId = oxConfig::getParameter( "oxaddressid");
00360 if ( !$sAddressId && !oxConfig::getParameter( 'reloadaddress' ) ) {
00361 $sAddressId = oxSession::getVar( "deladrid" );
00362 }
00363 return $sAddressId;
00364 }
00365
00371 protected function _getWishListId()
00372 {
00373 $this->_sWishId = null;
00374
00375 $oBasket = $this->getSession()->getBasket();
00376 foreach ( $oBasket->getContents() as $oBasketItem ) {
00377 if ( $this->_sWishId = $oBasketItem->getWishId() ) {
00378
00379 break;
00380 }
00381 }
00382 return $this->_sWishId;
00383 }
00384
00393 public function getSelectedAddress( $sWishId = false )
00394 {
00395 if ( $this->_oSelAddress !== null ) {
00396 return $this->_oSelAddress;
00397 }
00398
00399 $oSelectedAddress = null;
00400 $oAddresses = $this->getUserAddresses();
00401 if ( $oAddresses->count() ) {
00402 if ( $sAddressId = $this->getSelectedAddressId() ) {
00403 foreach ( $oAddresses as $oAddress ) {
00404 if ( $oAddress->getId() == $sAddressId ) {
00405 $oAddress->selected = 1;
00406 $oAddress->setSelected();
00407 $oSelectedAddress = $oAddress;
00408 break;
00409 }
00410 }
00411 }
00412
00413
00414 if ( !$oSelectedAddress ) {
00415 if ( !$sAddressId || $sAddressId >= 0 ) {
00416 $oAddresses->rewind();
00417 $oAddress = $oAddresses->current();
00418 } else {
00419 $aAddresses = $oAddresses->getArray();
00420 $oAddress = array_pop( $aAddresses );
00421 }
00422 $oAddress->selected = 1;
00423 $oAddress->setSelected();
00424 $oSelectedAddress = $oAddress;
00425 }
00426 }
00427 $this->_oSelAddress = $oSelectedAddress;
00428 return $oSelectedAddress;
00429 }
00430
00438 public function getUserPayments( $sOXID = null )
00439 {
00440 if ( $this->_oPayments === null ) {
00441
00442 if ( !$sOXID ) {
00443 $sOXID = $this->getId();
00444 }
00445
00446 $sSelect = 'select * from oxuserpayments where oxuserid = ' . oxDb::getDb()->quote( $sOXID ) . ' ';
00447
00448 $this->_oPayments = oxNew( 'oxlist' );
00449 $this->_oPayments->init( 'oxUserPayment' );
00450 $this->_oPayments->selectString( $sSelect );
00451
00452 $myUtils = oxRegistry::getUtils();
00453 foreach ( $this->_oPayments as $oPayment ) {
00454
00455 $oPayment = $myUtils->assignValuesFromText( $val->oxuserpayments__oxvalue->value );
00456 }
00457 }
00458
00459 return $this->_oPayments;
00460 }
00461
00467 public function save()
00468 {
00469 $myConfig = oxRegistry::getConfig();
00470
00471 $blAddRemark = false;
00472 if ( $this->oxuser__oxpassword->value && $this->oxuser__oxregister->value < 1 ) {
00473 $blAddRemark = true;
00474
00475 $this->oxuser__oxregister = new oxField(date( 'Y-m-d H:i:s' ), oxField::T_RAW);
00476 }
00477
00478
00479 $this->oxuser__oxrights = new oxField($this->_getUserRights(), oxField::T_RAW);
00480
00481
00482 if ( is_array( $this->oxuser__oxbirthdate->value ) ) {
00483 $this->oxuser__oxbirthdate = new oxField($this->convertBirthday( $this->oxuser__oxbirthdate->value ), oxField::T_RAW);
00484 }
00485
00486
00487 if ( $myConfig->getConfigParam( "bl_showFbConnect" ) ) {
00488 $oFb = oxRegistry::get("oxFb");
00489 if ( $oFb->isConnected() && $oFb->getUser() ) {
00490 $this->oxuser__oxfbid = new oxField( $oFb->getUser() );
00491 }
00492 }
00493
00494 $blRet = parent::save();
00495
00496
00497 if ( $blAddRemark && $blRet ) {
00498 $oRemark = oxNew( 'oxremark' );
00499 $oRemark->oxremark__oxtext = new oxField(oxRegistry::getLang()->translateString( 'usrRegistered', null, true ), oxField::T_RAW);
00500 $oRemark->oxremark__oxtype = new oxField('r', oxField::T_RAW);
00501 $oRemark->oxremark__oxparentid = new oxField($this->getId(), oxField::T_RAW);
00502 $oRemark->save();
00503 }
00504
00505 return $blRet;
00506 }
00507
00513 public function allowDerivedUpdate()
00514 {
00515 return true;
00516 }
00517
00525 public function inGroup( $sGroupID )
00526 {
00527 $blIn = false;
00528 if ( ( $oGroups = $this->getUserGroups() ) ) {
00529 $blIn = isset( $oGroups[ $sGroupID ] );
00530 }
00531
00532 return $blIn;
00533 }
00534
00543 public function delete( $sOXID = null )
00544 {
00545
00546 if ( !$sOXID ) {
00547 $sOXID = $this->getId();
00548 }
00549 if ( !$sOXID ) {
00550 return false;
00551 }
00552
00553 $blDeleted = parent::delete( $sOXID );
00554
00555 if ( $blDeleted ) {
00556 $oDb = oxDb::getDb();
00557 $sOXIDQuoted = $oDb->quote($sOXID);
00558
00559
00560 $rs = $oDb->execute( "delete from oxaddress where oxaddress.oxuserid = {$sOXIDQuoted}" );
00561 $rs = $oDb->execute( "delete from oxobject2group where oxobject2group.oxobjectid = {$sOXIDQuoted}" );
00562
00563
00564 $rs = $oDb->execute( "delete oxuserbasketitems.* from oxuserbasketitems, oxuserbaskets where oxuserbasketitems.oxbasketid = oxuserbaskets.oxid and oxuserid = {$sOXIDQuoted}" );
00565 $rs = $oDb->execute( "delete from oxuserbaskets where oxuserid = {$sOXIDQuoted}" );
00566
00567
00568 $rs = $oDb->execute( "delete from oxnewssubscribed where oxuserid = {$sOXIDQuoted}" );
00569
00570
00571 $rs = $oDb->execute( "delete from oxobject2delivery where oxobjectid = {$sOXIDQuoted}");
00572
00573
00574 $rs = $oDb->execute( "delete from oxobject2discount where oxobjectid = {$sOXIDQuoted}");
00575
00576
00577
00578 $rs = $oDb->execute( "delete from oxremark where oxparentid = {$sOXIDQuoted} and oxtype !='o'" );
00579
00580 $blDeleted = $rs->EOF;
00581 }
00582
00583 return $blDeleted;
00584 }
00585
00593 public function load( $oxID )
00594 {
00595
00596 $blRet = parent::load( $oxID );
00597
00598
00599 if ( isset( $this->oxuser__oxcreate->value ) ) {
00600 $this->oxuser__oxcreate->setValue(oxRegistry::get("oxUtilsDate")->formatDBDate( $this->oxuser__oxcreate->value ));
00601 }
00602
00603
00604 if ( isset($this->_oNewsSubscription) ) {
00605 $this->_oNewsSubscription->oxnewssubscribed__oxuserid = new oxField( $oxID, oxField::T_RAW);
00606 }
00607
00608 return $blRet;
00609 }
00610
00618 public function exists( $sOXID = null )
00619 {
00620 $oDb = oxDb::getDb();
00621 if ( !$sOXID ) {
00622 $sOXID = $this->getId();
00623 }
00624
00625 $sShopSelect = '';
00626 if ( !$this->_blMallUsers && $this->oxuser__oxrights->value != 'malladmin') {
00627 $sShopSelect = ' AND oxshopid = "'.$this->getConfig()->getShopId().'" ';
00628 }
00629
00630
00631 if ( $sOXID ) {
00632 $sSelect = 'SELECT oxid FROM '.$this->getViewName().'
00633 WHERE ( oxid = '.$oDb->quote( $sOXID ).' ) ';
00634 $sSelect .= $sShopSelect;
00635
00636 if ( ( $sOxid = $oDb->getOne( $sSelect, false, false ) ) ) {
00637
00638 $this->setId( $sOxid );
00639 return true;
00640 }
00641 }
00642
00643 $sSelect = 'SELECT oxid FROM '.$this->getViewName().'
00644 WHERE ( oxusername = '.$oDb->quote( $this->oxuser__oxusername->value).' ) ';
00645 $sSelect .= $sShopSelect;
00646
00647 if ( ( $sOxid = $oDb->getOne( $sSelect, false, false ) ) ) {
00648
00649 $this->setId( $sOxid );
00650 return true;
00651 }
00652 return false;
00653 }
00654
00663 public function getOrders( $iLimit = false, $iPage = 0 )
00664 {
00665 $myConfig = $this->getConfig();
00666 $oOrders = oxNew( 'oxlist' );
00667 $oOrders->init( 'oxorder' );
00668
00669 if ( $iLimit !== false ) {
00670 $oOrders->setSqlLimit( $iLimit * $iPage, $iLimit );
00671 }
00672
00673
00674
00675
00676
00677
00678
00679
00680 if ( $this->oxuser__oxregister->value > 1 ) {
00681 $oDb = oxDb::getDb();
00682 $sQ = 'select * from oxorder where oxuserid = '.$oDb->quote( $this->getId() ).' and oxorderdate >= ' . $oDb->quote( $this->oxuser__oxregister->value ) . ' ';
00683
00684
00685
00686 $sQ .= ' order by oxorderdate desc ';
00687 $oOrders->selectString( $sQ );
00688 }
00689
00690 return $oOrders;
00691 }
00692
00698 public function getOrderCount()
00699 {
00700 $iCnt = 0;
00701 if ( $this->getId() && $this->oxuser__oxregister->value > 1 ) {
00702 $oDb = oxDb::getDb();
00703 $sQ = 'select count(*) from oxorder where oxuserid = '.$oDb->quote( $this->getId() ).' AND oxorderdate >= ' . $oDb->quote( $this->oxuser__oxregister->value) . ' and oxshopid = "'.$this->getConfig()->getShopId().'" ';
00704 $iCnt = (int) $oDb->getOne( $sQ );
00705 }
00706
00707 return $iCnt;
00708 }
00709
00715 public function getNoticeListArtCnt()
00716 {
00717 if ( $this->_iCntNoticeListArticles === null ) {
00718 $this->_iCntNoticeListArticles = 0;
00719 if ( $this->getId() ) {
00720 $this->_iCntNoticeListArticles = $this->getBasket( 'noticelist' )->getItemCount();
00721 }
00722 }
00723 return $this->_iCntNoticeListArticles;
00724 }
00725
00731 public function getWishListArtCnt()
00732 {
00733 if ( $this->_iCntWishListArticles === null ) {
00734 $this->_iCntWishListArticles = false;
00735 if ( $this->getId() ) {
00736 $this->_iCntWishListArticles = $this->getBasket( 'wishlist' )->getItemCount();
00737 }
00738 }
00739 return $this->_iCntWishListArticles;
00740 }
00741
00747 public function getEncodedDeliveryAddress()
00748 {
00749 return md5($this->_getMergedAddressFields());
00750 }
00751
00758 public function getActiveCountry()
00759 {
00760 $sDeliveryCountry = '';
00761 $soxAddressId = oxSession::getVar( 'deladrid' );
00762 if ( $soxAddressId ) {
00763 $oDelAddress = oxNew( 'oxaddress' );
00764 $oDelAddress->load( $soxAddressId );
00765 $sDeliveryCountry = $oDelAddress->oxaddress__oxcountryid->value;
00766 } elseif ( $this->getId() ) {
00767 $sDeliveryCountry = $this->oxuser__oxcountryid->value;
00768 } else {
00769 $oUser = oxNew( 'oxuser' );
00770 if ( $oUser->loadActiveUser() ) {
00771 $sDeliveryCountry = $oUser->oxuser__oxcountryid->value;
00772 }
00773 }
00774
00775 return $sDeliveryCountry;
00776 }
00777
00785 public function createUser()
00786 {
00787 $oDb = oxDb::getDb();
00788 $sShopID = $this->getConfig()->getShopId();
00789
00790
00791 $sSelect = "select oxid from oxuser where oxusername = " . $oDb->quote( $this->oxuser__oxusername->value ) . " and oxpassword = '' ";
00792 if ( !$this->_blMallUsers ) {
00793 $sSelect .= " and oxshopid = '{$sShopID}' ";
00794 }
00795 $sOXID = $oDb->getOne( $sSelect, false, false );
00796
00797
00798 if ( isset( $sOXID ) && $sOXID ) {
00799
00800 $this->delete( $sOXID );
00801 } elseif ( $this->_blMallUsers ) {
00802
00803 $sQ = "select oxid from oxuser where oxusername = " . $oDb->quote( $this->oxuser__oxusername->value ) . " and oxusername != '' ";
00804 if ( $oDb->getOne( $sQ, false, false ) ) {
00805 $oEx = oxNew( 'oxUserException' );
00806 $oLang = oxRegistry::getLang();
00807 $oEx->setMessage( sprintf( $oLang->translateString( 'ERROR_MESSAGE_USER_USEREXISTS', $oLang->getTplLanguage() ), $this->oxuser__oxusername->value ) );
00808 throw $oEx;
00809 }
00810 }
00811
00812 $this->oxuser__oxshopid = new oxField( $sShopID, oxField::T_RAW );
00813 if ( ( $blOK = $this->save() ) ) {
00814
00815 $oDb->execute( "delete from oxaddress where oxaddress.oxuserid = " . $oDb->quote( $this->oxuser__oxid->value ) . " " );
00816 $oDb->execute( "update oxuserpayments set oxuserpayments.oxuserid = " . $oDb->quote( $this->oxuser__oxusername->value ) . " where oxuserpayments.oxuserid = " . $oDb->quote( $this->oxuser__oxid->value ) . " " );
00817 } else {
00818 $oEx = oxNew( 'oxUserException' );
00819 $oEx->setMessage( 'EXCEPTION_USER_USERCREATIONFAILED' );
00820 throw $oEx;
00821 }
00822
00823 return $blOK;
00824 }
00825
00833 public function addToGroup( $sGroupID )
00834 {
00835 if ( !$this->inGroup( $sGroupID ) ) {
00836
00837 $oGroup = oxNew('oxGroups');
00838 if ( $oGroup->load($sGroupID) ) {
00839 $oNewGroup = oxNew( 'oxobject2group' );
00840 $oNewGroup->oxobject2group__oxobjectid = new oxField( $this->getId(), oxField::T_RAW );
00841 $oNewGroup->oxobject2group__oxgroupsid = new oxField( $sGroupID, oxField::T_RAW );
00842 if ( $oNewGroup->save() ) {
00843 $this->_oGroups[$sGroupID] = $oGroup;
00844 return true;
00845 }
00846 }
00847 }
00848 return false;
00849 }
00850
00858 public function removeFromGroup( $sGroupID = null )
00859 {
00860 if ( $sGroupID != null && $this->inGroup( $sGroupID ) ) {
00861 $oGroups = oxNew( 'oxlist' );
00862 $oGroups->init( 'oxobject2group' );
00863 $sSelect = 'select * from oxobject2group where oxobject2group.oxobjectid = "'.$this->getId().'" and oxobject2group.oxgroupsid = "'.$sGroupID.'" ';
00864 $oGroups->selectString( $sSelect );
00865 foreach ( $oGroups as $oRemgroup ) {
00866 if ( $oRemgroup->delete() ) {
00867 unset( $this->_oGroups[$oRemgroup->oxobject2group__oxgroupsid->value] );
00868 }
00869 }
00870 }
00871 }
00872
00881 public function onOrderExecute( $oBasket, $iSuccess )
00882 {
00883
00884 if ( is_numeric( $iSuccess ) && $iSuccess != 2 && $iSuccess <= 3 ) {
00885
00886 if ( !$this->oxuser__oxdisableautogrp->value ) {
00887
00888 $myConfig = $this->getConfig();
00889 $dMidlleCustPrice = (float) $myConfig->getConfigParam( 'sMidlleCustPrice' );
00890 $dLargeCustPrice = (float) $myConfig->getConfigParam( 'sLargeCustPrice' );
00891
00892 $this->addToGroup( 'oxidcustomer' );
00893 $dBasketPrice = $oBasket->getPrice()->getBruttoPrice();
00894 if ( $dBasketPrice < $dMidlleCustPrice ) {
00895 $this->addToGroup( 'oxidsmallcust' );
00896 }
00897 if ( $dBasketPrice >= $dMidlleCustPrice && $dBasketPrice < $dLargeCustPrice ) {
00898 $this->addToGroup( 'oxidmiddlecust' );
00899 }
00900 if ( $dBasketPrice >= $dLargeCustPrice ) {
00901 $this->addToGroup( 'oxidgoodcust' );
00902 }
00903 }
00904
00905 if ( $this->inGroup( 'oxidnotyetordered' ) ) {
00906 $this->removeFromGroup( 'oxidnotyetordered' );
00907 }
00908 }
00909 }
00910
00918 public function getBasket( $sName )
00919 {
00920 if ( !isset( $this->_aBaskets[$sName] ) ) {
00921 $oBasket = oxNew( 'oxuserbasket' );
00922 $aWhere = array( 'oxuserbaskets.oxuserid' => $this->getId(), 'oxuserbaskets.oxtitle' => $sName );
00923
00924
00925 if ( !$oBasket->assignRecord( $oBasket->buildSelectString( $aWhere ) ) ) {
00926 $oBasket->oxuserbaskets__oxtitle = new oxField($sName);
00927 $oBasket->oxuserbaskets__oxuserid = new oxField($this->getId());
00928
00929
00930 $oBasket->setIsNewBasket();
00931 }
00932
00933 $this->_aBaskets[$sName] = $oBasket;
00934 }
00935
00936 return $this->_aBaskets[$sName];
00937 }
00938
00947 public function convertBirthday( $aData )
00948 {
00949
00950
00951 $iYear = isset($aData['year'])?((int) $aData['year']):false;
00952 $iMonth = isset($aData['month'])?((int) $aData['month']):false;
00953 $iDay = isset($aData['day'])?((int) $aData['day']):false;
00954
00955
00956 if ( !$iYear && !$iMonth && !$iDay )
00957 return "";
00958
00959
00960 if ( !$iYear || $iYear < 1000 || $iYear > 9999)
00961 $iYear = date('Y');
00962
00963
00964 if ( !$iMonth || $iMonth < 1 || $iMonth > 12)
00965 $iMonth = 1;
00966
00967
00968 $iMaxDays = 31;
00969 switch( $iMonth) {
00970 case 2 :
00971 if ($iMaxDays > 28)
00972 $iMaxDays = ($iYear % 4 == 0 && ($iYear % 100 != 0 || $iYear % 400 == 0)) ? 29 : 28;
00973 break;
00974 case 4 :
00975 case 6 :
00976 case 9 :
00977 case 11 :
00978 $iMaxDays = min(30, $iMaxDays);
00979 break;
00980 }
00981
00982
00983 if ( !$iDay || $iDay < 1 || $iDay > $iMaxDays) {
00984 $iDay = 1;
00985 }
00986
00987
00988 return sprintf("%04d-%02d-%02d", $iYear, $iMonth, $iDay);
00989 }
00990
00996 public function getBoni()
00997 {
00998 if ( ! $iBoni = $this->getConfig()->getConfigParam( 'iCreditRating' ) ) {
00999 $iBoni = 1000;
01000 }
01001
01002 return $iBoni;
01003 }
01004
01017 public function addDynGroup( $sDynGoup, $aDeniedDynGroups )
01018 {
01019
01020 $sDynGoup = strtolower( trim( $sDynGoup ) );
01021
01022
01023 $aDisabledDynGroups = array_merge( array( 'oxidadmin' ), (array) $aDeniedDynGroups );
01024
01025
01026 $blAdd = false;
01027
01028
01029 if ( $this->oxuser__oxdisableautogrp->value || !$sDynGoup ) {
01030 $blAdd = false;
01031 } elseif ( in_array( $sDynGoup, $aDisabledDynGroups ) ) {
01032
01033 $blAdd = false;
01034 } elseif ( $this->addToGroup( $sDynGoup ) ) {
01035 $blAdd = true;
01036 }
01037
01038
01039 oxSession::deleteVar( 'dgr' );
01040
01041 return $blAdd;
01042 }
01043
01062 public function checkValues( $sLogin, $sPassword, $sPassword2, $aInvAddress, $aDelAddress )
01063 {
01064
01065 $sLogin = $this->_checkLogin( $sLogin, $aInvAddress );
01066
01067
01068 $this->_checkEmail( $sLogin );
01069
01070
01071 $this->checkPassword( $sPassword, $sPassword2, ((int) oxConfig::getParameter( 'option' ) == 3) );
01072
01073
01074 $this->_checkRequiredFields( $aInvAddress, $aDelAddress );
01075
01076
01077 $this->_checkCountries( $aInvAddress, $aDelAddress );
01078
01079
01080 $this->_checkVatId( $aInvAddress );
01081
01082
01083
01084 if ( $oError = oxRegistry::get("oxInputValidator")->getFirstValidationError() ) {
01085 throw $oError;
01086 }
01087 }
01088
01098 public function setNewsSubscription( $blSubscribe, $blSendOptIn, $blForceCheckOptIn = false )
01099 {
01100
01101 $blSuccess = false;
01102 $myConfig = $this->getConfig();
01103 $mySession = $this->getSession();
01104
01105
01106 $oNewsSubscription = $this->getNewsSubscription();
01107 if ( $oNewsSubscription ) {
01108 if ( $blSubscribe && ($blForceCheckOptIn || ( $iOptInStatus = $oNewsSubscription->getOptInStatus() ) != 1) ) {
01109 if ( !$blSendOptIn ) {
01110
01111
01112 $this->addToGroup( 'oxidnewsletter' );
01113
01114 $oNewsSubscription->setOptInStatus( 1 );
01115 $blSuccess = true;
01116 } else {
01117
01118
01119 if ( $iOptInStatus != 2 ) {
01120
01121 $oEmail = oxNew( 'oxemail' );
01122 $blSuccess = $oEmail->sendNewsletterDBOptInMail( $this );
01123 } else {
01124
01125 $blSuccess = true;
01126 }
01127
01128 $oNewsSubscription->setOptInStatus( 2 );
01129 }
01130 } elseif ( !$blSubscribe ) {
01131
01132 $this->removeFromGroup( 'oxidnewsletter' );
01133 $oNewsSubscription->setOptInStatus( 0 );
01134 $blSuccess = true;
01135 }
01136 }
01137
01138 return $blSuccess;
01139 }
01140
01158 public function changeUserData( $sUser, $sPassword, $sPassword2, $aInvAddress, $aDelAddress )
01159 {
01160
01161
01162 $this->checkValues( $sUser, $sPassword, $sPassword2, $aInvAddress, $aDelAddress );
01163
01164
01165
01166
01167 $this->assign( $aInvAddress );
01168
01169
01170
01171
01172
01173
01174 $this->_assignAddress( $aDelAddress );
01175
01176
01177
01178
01179
01180 if ( $this->save() ) {
01181
01182
01183 $sCountryId = isset( $aInvAddress['oxuser__oxcountryid'] )?$aInvAddress['oxuser__oxcountryid']:'';
01184 $this->_setAutoGroups( $sCountryId );
01185 }
01186 }
01187
01193 protected function _getMergedAddressFields()
01194 {
01195 $sDelAddress = '';
01196 $sDelAddress .= $this->oxuser__oxcompany;
01197 $sDelAddress .= $this->oxuser__oxusername;
01198 $sDelAddress .= $this->oxuser__oxfname;
01199 $sDelAddress .= $this->oxuser__oxlname;
01200 $sDelAddress .= $this->oxuser__oxstreet;
01201 $sDelAddress .= $this->oxuser__oxstreetnr;
01202 $sDelAddress .= $this->oxuser__oxaddinfo;
01203 $sDelAddress .= $this->oxuser__oxustid;
01204 $sDelAddress .= $this->oxuser__oxcity;
01205 $sDelAddress .= $this->oxuser__oxcountryid;
01206 $sDelAddress .= $this->oxuser__oxstateid;
01207 $sDelAddress .= $this->oxuser__oxzip;
01208 $sDelAddress .= $this->oxuser__oxfon;
01209 $sDelAddress .= $this->oxuser__oxfax;
01210 $sDelAddress .= $this->oxuser__oxsal;
01211
01212 return $sDelAddress;
01213 }
01214
01222 protected function _assignAddress( $aDelAddress )
01223 {
01224 if ( is_array( $aDelAddress ) && count( $aDelAddress ) ) {
01225
01226 $sAddressId = $this->getConfig()->getRequestParameter( 'oxaddressid' );
01227 $sAddressId = ( $sAddressId === null || $sAddressId == -1 || $sAddressId == -2 ) ? null : $sAddressId;
01228
01229 $oAddress = oxNew( 'oxaddress' );
01230 $oAddress->setId( $sAddressId );
01231 $oAddress->load( $sAddressId );
01232 $oAddress->assign( $aDelAddress );
01233 $oAddress->oxaddress__oxuserid = new oxField( $this->getId(), oxField::T_RAW );
01234 $oAddress->oxaddress__oxcountry = $this->getUserCountry( $oAddress->oxaddress__oxcountryid->value );
01235 $oAddress->save();
01236
01237
01238 $this->_aAddresses = null;
01239
01240
01241 oxSession::setVar( 'deladrid', $oAddress->getId() );
01242 } else {
01243
01244 oxSession::setVar( 'deladrid', null );
01245 }
01246 }
01247
01258 protected function _getLoginQuery( $sUser, $sPassword, $sShopID, $blAdmin )
01259 {
01260 $myConfig = $this->getConfig();
01261 $oDb = oxDb::getDb();
01262
01263 $sUserSelect = is_numeric( $sUser ) ? "oxuser.oxcustnr = {$sUser} " : "oxuser.oxusername = " . $oDb->quote( $sUser );
01264 $sPassSelect = " oxuser.oxpassword = MD5( CONCAT( ".$oDb->quote( $sPassword ).", UNHEX( oxuser.oxpasssalt ) ) ) ";
01265 $sShopSelect = "";
01266
01267
01268
01269 if ( $blAdmin ) {
01270 $sShopSelect = " and ( oxrights != 'user' ) ";
01271 }
01272
01273 $blStagingMode = false;
01274 $blDemoMode = false;
01275 $sWhat = "oxid";
01276 if ($myConfig->isDemoShop()) {
01277 $blDemoMode = true;
01278 }
01279
01280 $sSelect = "select $sWhat from oxuser where oxuser.oxactive = 1 and {$sPassSelect} and {$sUserSelect} {$sShopSelect} ";
01281 if ( ( $blDemoMode || $blStagingMode ) && $blAdmin ) {
01282 if ( $sPassword == "admin" && $sUser == "admin" ) {
01283 $sSelect = "select $sWhat from oxuser where oxrights = 'malladmin' ";
01284 } elseif ( $blDemoMode ) {
01285 $oEx = oxNew( 'oxUserException' );
01286 $oEx->setMessage( 'ERROR_MESSAGE_USER_NOVALIDLOGIN' );
01287 throw $oEx;
01288 }
01289 }
01290
01291 return $sSelect;
01292 }
01293
01303 protected function _getShopSelect( $myConfig, $sShopID, $blAdmin )
01304 {
01305 $sShopSelect = "";
01306
01307 if ( $blAdmin ) {
01308 $sShopSelect = " and ( oxrights != 'user' ) ";
01309 }
01310
01311 return $sShopSelect;
01312 }
01320 protected function _loadSavedUserBasketAfterLogin()
01321 {
01322 if ( !$this->isAdmin() && !$this->getConfig()->getConfigParam( 'blPerfNoBasketSaving' )) {
01323
01324 try {
01325 if ( $oBasket = $this->getSession()->getBasket() ) {
01326 $oBasket->load();
01327 }
01328 } catch ( Exception $oE ) {
01329
01330 }
01331 }
01332 }
01333
01334
01347 public function login( $sUser, $sPassword, $blCookie = false)
01348 {
01349 if ( $this->isAdmin() && !count( oxRegistry::get("oxUtilsServer")->getOxCookie() ) ) {
01350 $oEx = oxNew( 'oxCookieException' );
01351 $oEx->setMessage( 'ERROR_MESSAGE_COOKIE_NOCOOKIE' );
01352 throw $oEx;
01353 }
01354
01355 $myConfig = $this->getConfig();
01356 if ( $sPassword ) {
01357
01358 $sShopID = $myConfig->getShopId();
01359 $sSelect = $this->_getLoginQuery( $sUser, $sPassword, $sShopID, $this->isAdmin() );
01360
01361
01362 $aData = oxDb::getDb()->getAll( $sSelect );
01363 $sOXID = @$aData[0][0];
01364 if ( isset( $sOXID ) && $sOXID && !@$aData[0][1] ) {
01365
01366 if ( !$this->load( $sOXID ) ) {
01367 $oEx = oxNew( 'oxUserException' );
01368 $oEx->setMessage( 'ERROR_MESSAGE_USER_NOVALIDLOGIN' );
01369 throw $oEx;
01370 }
01371 }
01372 }
01373
01374
01375
01376 if ( $this->oxuser__oxid->value ) {
01377
01378
01379
01380 $this->setUser( null );
01381
01382 if ( $this->isAdmin() ) {
01383 oxSession::setVar( 'auth', $this->oxuser__oxid->value );
01384 } else {
01385 oxSession::setVar( 'usr', $this->oxuser__oxid->value );
01386 }
01387
01388
01389 if ( $blCookie && $myConfig->getConfigParam( 'blShowRememberMe' ) ) {
01390 oxRegistry::get("oxUtilsServer")->setUserCookie( $this->oxuser__oxusername->value, $this->oxuser__oxpassword->value, $myConfig->getShopId(), 31536000, $this->oxuser__oxpasssalt->value );
01391 }
01392
01393 return true;
01394 } else {
01395 $oEx = oxNew( 'oxUserException' );
01396 $oEx->setMessage( 'ERROR_MESSAGE_USER_NOVALIDLOGIN' );
01397 throw $oEx;
01398 }
01399 }
01400
01406 public function logout()
01407 {
01408
01409 oxSession::deleteVar( 'usr' );
01410 oxSession::deleteVar( 'auth' );
01411 oxSession::deleteVar( 'dgr' );
01412 oxSession::deleteVar( 'dynvalue' );
01413 oxSession::deleteVar( 'paymentid' );
01414
01415
01416
01417 oxRegistry::get("oxUtilsServer")->deleteUserCookie( $this->getConfig()->getShopID() );
01418
01419
01420 $this->setUser( null );
01421
01422 return true;
01423 }
01424
01431 public function loadAdminUser()
01432 {
01433 return $this->loadActiveUser( true );
01434 }
01435
01444 public function loadActiveUser( $blForceAdmin = false )
01445 {
01446 $oConfig = $this->getConfig();
01447
01448 $blAdmin = $this->isAdmin() || $blForceAdmin;
01449
01450
01451 $sUserID = $blAdmin ? oxRegistry::getSession()->getVariable( 'auth' ) : oxRegistry::getSession()->getVariable( 'usr' );
01452
01453
01454 $blFoundInCookie = false;
01455 if ( !$sUserID && !$blAdmin && $oConfig->getConfigParam('blShowRememberMe') ) {
01456 $sUserID = $this->_getCookieUserId();
01457 $blFoundInCookie = $sUserID? true : false;
01458 }
01459
01460
01461 if ( !$sUserID && !$blAdmin && $oConfig->getConfigParam( "bl_showFbConnect") ) {
01462 $sUserID = $this->_getFacebookUserId();
01463 }
01464
01465
01466 if ( $sUserID ) {
01467 if ( $this->load( $sUserID ) ) {
01468
01469 if ($blAdmin) {
01470 oxRegistry::getSession()->setVariable( 'auth', $sUserID );
01471 } else {
01472 oxRegistry::getSession()->setVariable( 'usr', $sUserID );
01473 }
01474
01475
01476 $this->_blLoadedFromCookie = $blFoundInCookie;
01477 return true;
01478 }
01479 } else {
01480
01481 if ($blAdmin) {
01482 oxRegistry::getSession()->deleteVariable( 'auth' );
01483 } else {
01484 oxRegistry::getSession()->deleteVariable( 'usr' );
01485 }
01486
01487 return false;
01488 }
01489 }
01490
01496 protected function _getFacebookUserId()
01497 {
01498 $oDb = oxDb::getDb();
01499 $oFb = oxRegistry::get("oxFb");
01500 $oConfig = $this->getConfig();
01501 if ( $oFb->isConnected() && $oFb->getUser() ) {
01502 $sUserSelect = "oxuser.oxfbid = " . $oDb->quote( $oFb->getUser() );
01503 $sShopSelect = "";
01504
01505
01506 $sSelect = "select oxid from oxuser where oxuser.oxactive = 1 and {$sUserSelect} {$sShopSelect} ";
01507 $sUserID = $oDb->getOne( $sSelect );
01508 }
01509 return $sUserID;
01510 }
01511
01517 protected function _getCookieUserId()
01518 {
01519 $sUserID = null;
01520 $oConfig = $this->getConfig();
01521 $sShopID = $oConfig->getShopId();
01522 if ( ( $sSet = oxRegistry::get("oxUtilsServer")->getUserCookie( $sShopID ) ) ) {
01523 $oDb = oxDb::getDb();
01524 $aData = explode( '@@@', $sSet );
01525 $sUser = $aData[0];
01526 $sPWD = @$aData[1];
01527
01528 $sSelect = 'select oxid, oxpassword, oxpasssalt from oxuser where oxuser.oxpassword != "" and oxuser.oxactive = 1 and oxuser.oxusername = '.$oDb->quote($sUser);
01529
01530 $rs = $oDb->select( $sSelect );
01531 if ( $rs != false && $rs->recordCount() > 0 ) {
01532 while (!$rs->EOF) {
01533 $sTest = crypt( $rs->fields[1], $rs->fields[2] );
01534 if ( $sTest == $sPWD ) {
01535
01536 $sUserID = $rs->fields[0];
01537 break;
01538 }
01539 $rs->moveNext();
01540 }
01541 }
01542
01543 if ( !$sUserID ) {
01544 oxRegistry::get('oxUtilsServer')->deleteUserCookie( $sShopID );
01545 }
01546 }
01547 return $sUserID;
01548 }
01549
01562 protected function _ldapLogin( $sUser, $sPassword, $sShopID, $sShopSelect)
01563 {
01564 $aLDAPParams = $this->getConfig()->getConfigParam( 'aLDAPParams' );
01565 $oLDAP = oxNew( "oxLDAP", $aLDAPParams['HOST'], $aLDAPParams['PORT'] );
01566
01567
01568 $oDb = oxDb::getDb();
01569 $sLDAPKey = $oDb->getOne( "select oxldapkey from oxuser where oxuser.oxactive = 1 and oxuser.oxusername = ".$oDb->quote( $sUser )." $sShopSelect");
01570 if ( isset( $sLDAPKey) && $sLDAPKey) {
01571 $sUser = $sLDAPKey;
01572 }
01573
01574
01575 $oLDAP->login( $sUser, $sPassword, $aLDAPParams['USERQUERY'], $aLDAPParams['BASEDN'], $aLDAPParams['FILTER'] );
01576
01577 $aData = $oLDAP->mapData($aLDAPParams['DATAMAP']);
01578 if ( isset( $aData['OXUSERNAME']) && $aData['OXUSERNAME']) {
01579
01580
01581
01582 $sSelect = "select oxid from oxuser where oxuser.oxusername = ".$oDb->quote( $aData['OXUSERNAME'] )." $sShopSelect";
01583 $sOXID = $oDb->getOne( $sSelect );
01584
01585 if ( !isset( $sOXID ) || !$sOXID ) {
01586
01587
01588 $this->setId();
01589
01590
01591 foreach ( $aData as $fldname => $value) {
01592 $sField = "oxuser__".strtolower( $fldname);
01593 $this->$sField = new oxField( $aData[$fldname] );
01594 }
01595
01596 $this->oxuser__oxactive = new oxField( 1 );
01597 $this->oxuser__oxshopid = new oxField( $sShopID );
01598 $this->oxuser__oxldapkey = new oxField( $sUser );
01599 $this->oxuser__oxrights = new oxField( "user" );
01600 $this->setPassword( "ldap user" );
01601
01602 $this->save();
01603 } else {
01604
01605 $this->load( $sOXID);
01606 }
01607
01608 } else {
01609 $oEx = oxNew( 'oxUserException' );
01610 $oEx->setMessage('EXCEPTION_USER_NOVALUES');
01611 throw $oEx;
01612 }
01613 }
01614
01621 protected function _getUserRights()
01622 {
01623
01624 if ( !$this->oxuser__oxrights->value )
01625 return 'user';
01626
01627 $oDb = oxDb::getDb();
01628 $myConfig = $this->getConfig();
01629 $sAuthRights = null;
01630
01631
01632 $sAuthUserID = $this->isAdmin()?oxSession::getVar( 'auth' ):null;
01633 $sAuthUserID = $sAuthUserID?$sAuthUserID:oxSession::getVar( 'usr' );
01634 if ( $sAuthUserID ) {
01635 $sAuthRights = $oDb->getOne( 'select oxrights from '.$this->getViewName().' where oxid='.$oDb->quote( $sAuthUserID ) );
01636 }
01637
01638
01639 $aRights = array();
01640
01641
01642 if ( $sCurrRights = $oDb->getOne( 'select oxrights from '.$this->getViewName().' where oxid='.$oDb->quote( $this->getId() ) ) ) {
01643 $aRights[] = $sCurrRights;
01644 }
01645 $aRights[] = 'user';
01646
01647 if ( !$sAuthRights || !( $sAuthRights == 'malladmin' || $sAuthRights == $myConfig->getShopId() ) ) {
01648 return current( $aRights );
01649 } elseif ( $sAuthRights == $myConfig->getShopId() ) {
01650 $aRights[] = $sAuthRights;
01651 if ( !in_array( $this->oxuser__oxrights->value, $aRights ) ) {
01652 return current( $aRights );
01653 }
01654 }
01655
01656
01657 return $this->oxuser__oxrights->value;
01658 }
01659
01665 protected function _insert()
01666 {
01667
01668
01669 $this->oxuser__oxcreate = new oxField(date( 'Y-m-d H:i:s' ), oxField::T_RAW);
01670
01671 if ( !isset( $this->oxuser__oxboni->value ) ) {
01672 $this->oxuser__oxboni = new oxField($this->getBoni(), oxField::T_RAW);
01673 }
01674
01675 return parent::_insert();
01676 }
01677
01683 protected function _update()
01684 {
01685
01686 if (!$this->oxuser__oxpassword->value && $this->oxuser__oxregister->value < 1) {
01687 $this->_aSkipSaveFields[] = 'oxboni';
01688 }
01689
01690
01691 $this->_aSkipSaveFields[] = 'oxcreate';
01692 if ( !$this->isAdmin() ) {
01693 $this->_aSkipSaveFields[] = 'oxcustnr';
01694 $this->_aSkipSaveFields[] = 'oxrights';
01695 }
01696
01697
01698 if ( ( $blUpdate = parent::_update() ) ) {
01699 $this->getNewsSubscription()->updateSubscription( $this );
01700 }
01701
01702 return $blUpdate;
01703 }
01704
01720 protected function _checkLogin( $sLogin, $aInvAddress )
01721 {
01722 $sLogin = ( isset( $aInvAddress['oxuser__oxusername'] ) )?$aInvAddress['oxuser__oxusername'] : $sLogin;
01723 oxRegistry::get("oxInputValidator")->checkLogin( $this, $sLogin, $aInvAddress );
01724 return $sLogin;
01725 }
01726
01734 public function checkIfEmailExists( $sEmail )
01735 {
01736 $myConfig = $this->getConfig();
01737 $oDb = oxDb::getDb();
01738 $iShopId = $myConfig->getShopId();
01739 $blExists = false;
01740
01741 $sQ = 'select oxshopid, oxrights, oxpassword from oxuser where oxusername = '. $oDb->quote( $sEmail );
01742 if ( ( $sOxid = $this->getId() ) ) {
01743 $sQ .= " and oxid <> ".$oDb->quote( $sOxid );
01744 }
01745 $oRs = $oDb->select( $sQ, false, false );
01746 if ( $oRs != false && $oRs->recordCount() > 0 ) {
01747
01748 if ( $this->_blMallUsers ) {
01749
01750 $blExists = true;
01751 if ( $oRs->fields[1] == 'user' && !$oRs->fields[2] ) {
01752
01753
01754 $blExists = false;
01755 }
01756 } else {
01757
01758 $blExists = false;
01759 while ( !$oRs->EOF ) {
01760 if ( $oRs->fields[1] != 'user' ) {
01761
01762
01763 $blExists = true;
01764 break;
01765 } elseif ( $oRs->fields[0] == $iShopId && $oRs->fields[2] ) {
01766
01767
01768 $blExists = true;
01769 break;
01770 }
01771
01772 $oRs->moveNext();
01773 }
01774 }
01775 }
01776 return $blExists;
01777 }
01778
01786 public function getUserRecommLists( $sOXID = null )
01787 {
01788 if ( !$sOXID )
01789 $sOXID = $this->getId();
01790
01791
01792 $iActPage = (int) oxConfig::getParameter( 'pgNr' );
01793 $iActPage = ($iActPage < 0) ? 0 : $iActPage;
01794
01795
01796 $iNrofCatArticles = $this->getConfig()->getConfigParam( 'iNrofCatArticles' );
01797 $iNrofCatArticles = $iNrofCatArticles ? $iNrofCatArticles : 10;
01798
01799
01800 $oRecommList = oxNew( 'oxlist' );
01801 $oRecommList->init( 'oxrecommlist' );
01802 $oRecommList->setSqlLimit( $iNrofCatArticles * $iActPage, $iNrofCatArticles );
01803 $iShopId = $this->getConfig()->getShopId();
01804 $sSelect = 'select * from oxrecommlists where oxuserid ='. oxDb::getDb()->quote( $sOXID ) . ' and oxshopid ="'. $iShopId .'"';
01805 $oRecommList->selectString( $sSelect );
01806
01807 return $oRecommList;
01808 }
01809
01817 public function getRecommListsCount( $sOx = null )
01818 {
01819 if ( !$sOx ) {
01820 $sOx = $this->getId();
01821 }
01822
01823 if ( $this->_iCntRecommLists === null || $sOx ) {
01824 $oDb = oxDb::getDb();
01825 $this->_iCntRecommLists = 0;
01826 $iShopId = $this->getConfig()->getShopId();
01827 $sSelect = 'select count(oxid) from oxrecommlists where oxuserid = ' . $oDb->quote( $sOx ) . ' and oxshopid ="'. $iShopId .'"';
01828 $this->_iCntRecommLists = $oDb->getOne( $sSelect );
01829 }
01830 return $this->_iCntRecommLists;
01831 }
01832
01843 protected function _checkEmail( $sEmail )
01844 {
01845 oxRegistry::get("oxInputValidator")->checkEmail( $this, $sEmail );
01846 }
01847
01860 public function checkPassword( $sNewPass, $sConfPass, $blCheckLenght = false )
01861 {
01862 return oxRegistry::get("oxInputValidator")->checkPassword( $this, $sNewPass, $sConfPass, $blCheckLenght );
01863 }
01864
01875 protected function _checkCountries( $aInvAddress, $aDelAddress )
01876 {
01877 oxRegistry::get("oxInputValidator")->checkCountries( $this, $aInvAddress, $aDelAddress );
01878 }
01879
01891 protected function _checkRequiredFields( $aInvAddress, $aDelAddress )
01892 {
01893 oxRegistry::get("oxInputValidator")->checkRequiredFields( $this, $aInvAddress, $aDelAddress );
01894 }
01895
01906 protected function _checkRequiredArrayFields( $sFieldName, $aFieldValues )
01907 {
01908 oxRegistry::get("oxInputValidator")->checkRequiredArrayFields( $this, $sFieldName, $aFieldValues );
01909 }
01910
01921 protected function _checkVatId( $aInvAddress )
01922 {
01923 oxRegistry::get("oxInputValidator")->checkVatId( $this, $aInvAddress );
01924 }
01925
01934 protected function _setAutoGroups( $sCountryId )
01935 {
01936
01937 $blForeigner = true;
01938 $blForeignGroupExists = false;
01939 $blInlandGroupExists = false;
01940
01941 $aHomeCountry = $this->getConfig()->getConfigParam( 'aHomeCountry' );
01942
01943 if ( is_array($aHomeCountry)) {
01944 if (in_array($sCountryId, $aHomeCountry)) {
01945 $blForeigner = false;
01946 }
01947 } elseif ($sCountryId == $aHomeCountry) {
01948 $blForeigner = false;
01949 }
01950
01951 if ( $this->inGroup( 'oxidforeigncustomer' ) ) {
01952 $blForeignGroupExists = true;
01953 if ( !$blForeigner ) {
01954 $this->removeFromGroup( 'oxidforeigncustomer' );
01955 }
01956 }
01957
01958 if ( $this->inGroup( 'oxidnewcustomer' ) ) {
01959 $blInlandGroupExists = true;
01960 if ( $blForeigner ) {
01961 $this->removeFromGroup( 'oxidnewcustomer' );
01962 }
01963 }
01964
01965 if ( !$this->oxuser__oxdisableautogrp->value ) {
01966 if ( !$blForeignGroupExists && $blForeigner ) {
01967 $this->addToGroup( 'oxidforeigncustomer' );
01968 }
01969 if ( !$blInlandGroupExists && !$blForeigner ) {
01970 $this->addToGroup( 'oxidnewcustomer' );
01971 }
01972 }
01973 }
01974
01975
01984 public function loadUserByUpdateId( $sUid )
01985 {
01986 $oDb = oxDb::getDb();
01987 $sQ = "select oxid from ".$this->getViewName()." where oxupdateexp >= ".time()." and MD5( CONCAT( oxid, oxshopid, oxupdatekey ) ) = ".$oDb->quote( $sUid );
01988 if ( $sUserId = $oDb->getOne( $sQ ) ) {
01989 return $this->load( $sUserId );
01990 }
01991 }
01992
02000 public function setUpdateKey( $blReset = false )
02001 {
02002 $sUpKey = $blReset ? '' : oxUtilsObject::getInstance()->generateUId();
02003 $iUpTime = $blReset ? 0 : oxRegistry::get("oxUtilsDate")->getTime() + $this->getUpdateLinkTerm();
02004
02005
02006 $this->oxuser__oxupdatekey = new oxField( $sUpKey, oxField::T_RAW );
02007
02008
02009 $this->oxuser__oxupdateexp = new oxField( $iUpTime, oxField::T_RAW );
02010
02011
02012 $this->save();
02013 }
02014
02020 public function getUpdateLinkTerm()
02021 {
02022 return 3600 * 6;
02023 }
02024
02032 public function isExpiredUpdateId( $sKey )
02033 {
02034 $oDb = oxDb::getDb();
02035 $sQ = "select 1 from ".$this->getViewName()." where oxupdateexp >= ".time()." and MD5( CONCAT( oxid, oxshopid, oxupdatekey ) ) = ".$oDb->quote( $sKey );
02036 return !( (bool) $oDb->getOne( $sQ ) );
02037 }
02038
02044 public function getUpdateId()
02045 {
02046 if ( $this->_sUpdateKey === null ) {
02047 $this->setUpdateKey();
02048 $this->_sUpdateKey = md5( $this->getId() . $this->oxuser__oxshopid->value . $this->oxuser__oxupdatekey->value );
02049 }
02050 return $this->_sUpdateKey;
02051 }
02052
02061 public function encodePassword( $sPassword, $sSalt )
02062 {
02063 $oDb = oxDb::getDb();
02064 return $oDb->getOne( "select MD5( CONCAT( ".$oDb->quote( $sPassword ).", UNHEX( '{$sSalt}' ) ) )" );
02065 }
02066
02074 public function prepareSalt( $sSalt )
02075 {
02076 return ( $sSalt ? oxDb::getDb()->getOne( "select HEX( '{$sSalt}' )" ) : '' );
02077 }
02078
02086 public function decodeSalt( $sSaltHex )
02087 {
02088 return ( $sSaltHex ? oxDb::getDb()->getOne( "select UNHEX( '{$sSaltHex}' )" ) : '' );
02089 }
02090
02098 public function setPassword( $sPassword = null )
02099 {
02100
02101 $sSalt = $sPassword ? $this->prepareSalt( oxUtilsObject::getInstance()->generateUID() ) : '';
02102
02103
02104 $sPassword = $sPassword ? $this->encodePassword( $sPassword, $sSalt ) : '';
02105
02106 $this->oxuser__oxpassword = new oxField( $sPassword, oxField::T_RAW );
02107 $this->oxuser__oxpasssalt = new oxField( $sSalt, oxField::T_RAW );
02108 }
02109
02117 public function isSamePassword( $sNewPass )
02118 {
02119 return $this->encodePassword( $sNewPass, $this->oxuser__oxpasssalt->value ) == $this->oxuser__oxpassword->value;
02120 }
02121
02127 public function isLoadedFromCookie()
02128 {
02129 return $this->_blLoadedFromCookie;
02130 }
02131
02138 public function getPasswordHash()
02139 {
02140 $sHash = null;
02141 if ( $this->oxuser__oxpassword->value ) {
02142 if ( strpos( $this->oxuser__oxpassword->value, 'ox_' ) === 0 ) {
02143
02144 $this->setPassword( oxRegistry::getUtils()->strRem( $this->oxuser__oxpassword->value ) );
02145 } elseif ( strlen( $this->oxuser__oxpassword->value ) < 32 ) {
02146
02147 $this->setPassword( $this->oxuser__oxpassword->value );
02148 }
02149 $sHash = $this->oxuser__oxpassword->value;
02150 }
02151 return $sHash;
02152 }
02153
02161 public function getReviewUserHash( $sUserId )
02162 {
02163 $oDb = oxDb::getDb();
02164 $sReviewUserHash = $oDb->getOne('select md5(concat("oxid", oxpassword, oxusername )) from oxuser where oxid = ' . $oDb->quote( $sUserId ) .'');
02165 return $sReviewUserHash;
02166 }
02167
02175 public function getReviewUserId( $sReviewUserHash )
02176 {
02177 $oDb = oxDb::getDb();
02178 $sUserId = $oDb->getOne('select oxid from oxuser where md5(concat("oxid", oxpassword, oxusername )) = ' . $oDb->quote( $sReviewUserHash ) .'');
02179 return $sUserId;
02180 }
02181
02187 public function getState()
02188 {
02189 return $this->oxuser__oxstateid->value;
02190 }
02191
02197 public function isTermsAccepted()
02198 {
02199 $oDb = oxDb::getDb();
02200 $sShopId = $this->getConfig()->getShopId();
02201 $sUserId = $oDb->quote( $this->getId() );
02202 return (bool) $oDb->getOne( "select 1 from oxacceptedterms where oxuserid={$sUserId} and oxshopid='{$sShopId}'" );
02203 }
02204
02210 public function acceptTerms()
02211 {
02212 $oDb = oxDb::getDb();
02213 $sUserId = $oDb->quote( $this->getId() );
02214 $sShopId = $this->getConfig()->getShopId();
02215 $sVersion = oxNew( "oxcontent" )->getTermsVersion();
02216
02217 $oDb->execute( "replace oxacceptedterms set oxuserid={$sUserId}, oxshopid='{$sShopId}', oxtermversion='{$sVersion}'" );
02218 }
02219
02229 public function setCreditPointsForRegistrant( $sUserId, $sRecEmail )
02230 {
02231 $blSet = false;
02232 $oDb = oxDb::getDb();
02233 $iPoints = $this->getConfig()->getConfigParam( 'dPointsForRegistration' );
02234
02235 $iPending = $oDb->getOne( "select count(oxuserid) from oxinvitations where oxuserid = ".$oDb->quote( $sUserId )." and md5(oxemail) = ".$oDb->quote( $sRecEmail )." and oxpending = 1 and oxaccepted = 0", false, false);
02236 if ( $iPoints && $iPending ) {
02237 $this->oxuser__oxpoints = new oxField( $iPoints, oxField::T_RAW );
02238 if ( $blSet = $this->save() ) {
02239
02240 $oDb->execute( "UPDATE oxinvitations SET oxpending = '0', oxaccepted = '1' where oxuserid = ".$oDb->quote( $sUserId )." and md5(oxemail) = ".$oDb->quote( $sRecEmail ) );
02241 $oInvUser = oxNew( "oxuser" );
02242 if ( $oInvUser->load( $sUserId ) ) {
02243 $blSet = $oInvUser->setCreditPointsForInviter();
02244 }
02245 }
02246 }
02247 oxSession::deleteVar( 'su' );
02248 oxSession::deleteVar( 're' );
02249
02250 return $blSet;
02251 }
02252
02258 public function setCreditPointsForInviter()
02259 {
02260 $blSet = false;
02261 $iPoints = $this->getConfig()->getConfigParam( 'dPointsForInvitation' );
02262 if ( $iPoints ) {
02263 $iNewPoints = $this->oxuser__oxpoints->value + $iPoints;
02264 $this->oxuser__oxpoints = new oxField( $iNewPoints, oxField::T_RAW );
02265 $blSet = $this->save();
02266 }
02267
02268 return $blSet;
02269 }
02270
02276 public function updateFbId()
02277 {
02278 $oFb = oxRegistry::get("oxFb");
02279 $blRet = false;
02280
02281 if ( $oFb->isConnected() && $oFb->getUser() ) {
02282 $this->oxuser__oxfbid = new oxField( $oFb->getUser() );
02283 $blRet = $this->save();
02284 }
02285
02286 return $blRet;
02287 }
02288
02296 public function updateInvitationStatistics( $aRecEmail )
02297 {
02298 $oDb = oxDb::getDb();
02299 $sUserId = $this->getId();
02300
02301 if ( $sUserId && is_array( $aRecEmail ) && count( $aRecEmail ) > 0 ) {
02302
02303 $sDate = oxRegistry::get("oxUtilsDate")->formatDBDate( date("Y-m-d"), true );
02304 $aRecEmail = oxDb::getInstance()->quoteArray( $aRecEmail );
02305 foreach ( $aRecEmail as $sRecEmail ) {
02306 $sSql = "INSERT INTO oxinvitations SET oxuserid = ".$oDb->quote( $sUserId ).", oxemail = $sRecEmail, oxdate='$sDate', oxpending = '1', oxaccepted = '0', oxtype = '1' ";
02307 $oDb->execute( $sSql );
02308 }
02309 }
02310 }
02311
02319 public function getIdByUserName( $sUserName )
02320 {
02321 $oDb = oxDb::getDb();
02322 $sQ = "SELECT `oxid` FROM `oxuser` WHERE `oxusername` = ". $oDb->quote( $sUserName );
02323 if ( !$this->getConfig()->getConfigParam( 'blMallUsers' ) ) {
02324 $sQ .= " AND `oxshopid` = ". $oDb->quote( $this->getConfig()->getShopId() );
02325 }
02326
02327 return $oDb->getOne( $sQ );
02328
02329 }
02330
02336 public function hasAccount()
02337 {
02338
02339 return (bool) $this->oxuser__oxpassword->value;
02340
02341 }
02342
02348 public function isPriceViewModeNetto()
02349 {
02350 return (bool) $this->getConfig()->getConfigParam('blShowNetPrice');
02351 }
02352
02353 }