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 $oDb = oxDb::getDb();
00225 if ( !$sCountryId ) {
00226 $sCountryId = $this->oxuser__oxcountryid->value;
00227 }
00228
00229 $sQ = "select oxtitle".oxLang::getInstance()->getLanguageTag( $iLang )." from oxcountry where oxid = " . $oDb->quote( $sCountryId ) . " ";
00230 $this->oxuser__oxcountry = new oxField( $oDb->getOne( $sQ ), oxField::T_RAW);
00231
00232 return $this->oxuser__oxcountry;
00233 }
00234
00242 public function getUserCountryId( $sCountry = null )
00243 {
00244 $oDb = oxDb::getDb();
00245 $sQ = "select oxid from oxcountry where oxactive = '1' and oxisoalpha2 = " . $oDb->quote( $sCountry ) . " ";
00246 $sCountryId = $oDb->getOne( $sQ );
00247
00248 return $sCountryId;
00249 }
00250
00258 public function getUserGroups( $sOXID = null )
00259 {
00260
00261 if ( isset( $this->_oGroups ) ) {
00262 return $this->_oGroups;
00263 }
00264
00265 if ( !$sOXID ) {
00266 $sOXID = $this->getId();
00267 }
00268
00269 $this->_oGroups = oxNew( 'oxlist', 'oxgroups' );
00270
00271
00272 $sSelect = 'select oxgroups.* from oxgroups left join oxobject2group on oxobject2group.oxgroupsid = oxgroups.oxid ';
00273 $sSelect .= 'where oxobject2group.oxobjectid = ' . oxDb::getDb()->quote( $sOXID ) . ' ';
00274 $this->_oGroups->selectString( $sSelect );
00275 return $this->_oGroups;
00276 }
00277
00285 public function getUserAddresses( $sUserId = null )
00286 {
00287
00288 if ( $this->_oAddresses == null ) {
00289
00290 $sUserId = ( $sUserId ) ? $sUserId : $this->getId();
00291 $sSelect = "select * from oxaddress where oxaddress.oxuserid = " . oxDb::getDb()->quote( $sUserId ) . "";
00292
00293
00294 $this->_oAddresses = oxNew( 'oxlist' );
00295 $this->_oAddresses->init( "oxaddress" );
00296 $this->_oAddresses->selectString( $sSelect );
00297
00298
00299 if ( $sAddressId = $this->getSelectedAddressId() ) {
00300 foreach ( $this->_oAddresses as $oAddress ) {
00301 $oAddress->selected = 0;
00302 if ( $oAddress->getId() == $sAddressId ) {
00303 $oAddress->selected = 1;
00304 break;
00305 }
00306 }
00307 }
00308 }
00309 return $this->_oAddresses;
00310 }
00311
00317 public function getSelectedAddressId()
00318 {
00319 if ( !( $sAddressId = oxConfig::getParameter( "oxaddressid") ) ) {
00320 $sAddressId = oxSession::getVar( "deladrid" );
00321 }
00322 return $sAddressId;
00323 }
00324
00333 public function getSelectedAddress( $sWishId = false )
00334 {
00335 $oAddresses = $this->getUserAddresses();
00336 if ( $oAddresses->count() ) {
00337 if ( $sAddressId = $this->getSelectedAddressId() ) {
00338 foreach ( $oAddresses as $oAddress ) {
00339 if ( $oAddress->selected == 1 ) {
00340 $sAddressId = $oAddress->getId();
00341 break;
00342 }
00343 }
00344 } elseif ( $sWishId ) {
00345 foreach ( $oAddresses as $oAddress ) {
00346 $oAddress->selected = 0;
00347 if ( $oAddress->oxaddress__oxaddressuserid->value == $sWishId ) {
00348 $oAddress->selected = 1;
00349 $sAddressId = $oAddress->getId();
00350 }
00351 }
00352 }
00353
00354
00355 if ( !$sAddressId ) {
00356 $oAddresses->rewind();
00357 $oAddress = $oAddresses->current();
00358 $oAddress->selected = 1;
00359 $sAddressId = $oAddress->getId();
00360 }
00361 }
00362
00363 return $sAddressId;
00364 }
00365
00373 public function getUserPayments( $sOXID = null )
00374 {
00375 if ( $this->_oPayments === null ) {
00376
00377 if ( !$sOXID ) {
00378 $sOXID = $this->getId();
00379 }
00380
00381 $sSelect = 'select * from oxuserpayments where oxuserid = ' . oxDb::getDb()->quote( $sOXID ) . ' ';
00382
00383 $this->_oPayments = oxNew( 'oxlist' );
00384 $this->_oPayments->init( 'oxUserPayment' );
00385 $this->_oPayments->selectString( $sSelect );
00386
00387 $myUtils = oxUtils::getInstance();
00388 foreach ( $this->_oPayments as $oPayment ) {
00389
00390 $oPayment = $myUtils->assignValuesFromText( $val->oxuserpayments__oxvalue->value );
00391 }
00392 }
00393
00394 return $this->_oPayments;
00395 }
00396
00402 public function save()
00403 {
00404
00405 $blAddRemark = false;
00406 if ( $this->oxuser__oxpassword->value && $this->oxuser__oxregister->value < 1 ) {
00407 $blAddRemark = true;
00408
00409 $this->oxuser__oxregister = new oxField(date( 'Y-m-d H:i:s' ), oxField::T_RAW);
00410 }
00411
00412
00413 $this->oxuser__oxrights = new oxField($this->_getUserRights(), oxField::T_RAW);
00414
00415
00416 if ( is_array( $this->oxuser__oxbirthdate->value ) ) {
00417 $this->oxuser__oxbirthdate = new oxField($this->convertBirthday( $this->oxuser__oxbirthdate->value ), oxField::T_RAW);
00418 }
00419
00420 $blRet = parent::save();
00421
00422
00423 if ( $blAddRemark && $blRet ) {
00424 $oRemark = oxNew( 'oxremark' );
00425 $oRemark->oxremark__oxtext = new oxField(oxLang::getInstance()->translateString( 'usrRegistered' ), oxField::T_RAW);
00426 $oRemark->oxremark__oxtype = new oxField('r', oxField::T_RAW);
00427 $oRemark->oxremark__oxparentid = new oxField($this->getId(), oxField::T_RAW);
00428 $oRemark->save();
00429 }
00430
00431 return $blRet;
00432 }
00433
00439 public function allowDerivedUpdate()
00440 {
00441 return true;
00442 }
00443
00451 public function inGroup( $sGroupID )
00452 {
00453 $blIn = false;
00454 if ( ( $oGroups = $this->getUserGroups() ) ) {
00455 $blIn = isset( $oGroups[ $sGroupID ] );
00456 }
00457
00458 return $blIn;
00459 }
00460
00469 public function delete( $sOXID = null )
00470 {
00471
00472 if ( !$sOXID ) {
00473 $sOXID = $this->getId();
00474 }
00475 if ( !$sOXID ) {
00476 return false;
00477 }
00478
00479 $blDeleted = parent::delete( $sOXID );
00480
00481 if ( $blDeleted ) {
00482 $oDB = oxDb::getDb();
00483 $sOXIDQuoted = $oDB->quote($sOXID);
00484
00485
00486 $rs = $oDB->execute( "delete from oxaddress where oxaddress.oxuserid = {$sOXIDQuoted}" );
00487 $rs = $oDB->execute( "delete from oxobject2group where oxobject2group.oxobjectid = {$sOXIDQuoted}" );
00488
00489
00490 $rs = $oDB->execute( "delete oxuserbasketitems.* from oxuserbasketitems, oxuserbaskets where oxuserbasketitems.oxbasketid = oxuserbaskets.oxid and oxuserid = {$sOXIDQuoted}" );
00491 $rs = $oDB->execute( "delete from oxuserbaskets where oxuserid = {$sOXIDQuoted}" );
00492
00493
00494 $rs = $oDB->execute( "delete from oxnewssubscribed where oxuserid = {$sOXIDQuoted}" );
00495
00496
00497 $rs = $oDB->execute( "delete from oxobject2delivery where oxobjectid = {$sOXIDQuoted}");
00498
00499
00500 $rs = $oDB->execute( "delete from oxobject2discount where oxobjectid = {$sOXIDQuoted}");
00501
00502
00503
00504 $rs = $oDB->execute( "delete from oxremark where oxparentid = {$sOXIDQuoted} and oxtype !='o'" );
00505
00506 $blDeleted = $rs->EOF;
00507 }
00508
00509 return $blDeleted;
00510 }
00511
00519 public function load( $oxID )
00520 {
00521
00522 $blRet = parent::Load( $oxID );
00523
00524
00525 if ( isset( $this->oxuser__oxcreate->value ) ) {
00526 $this->oxuser__oxcreate->setValue(oxUtilsDate::getInstance()->formatDBDate( $this->oxuser__oxcreate->value ));
00527 }
00528
00529 return $blRet;
00530 }
00531
00539 public function exists( $sOXID = null )
00540 {
00541 $oDb = oxDb::getDb();
00542 if ( !$sOXID ) {
00543 $sOXID = $this->getId();
00544 }
00545
00546 $sSelect = 'SELECT oxid FROM '.$this->getViewName().'
00547 WHERE ( oxusername = '.$oDb->quote( $this->oxuser__oxusername->value).'';
00548
00549 if ( $sOXID ) {
00550 $sSelect.= " or oxid = ".$oDb->quote( $sOXID ) . " ) ";
00551 } else {
00552 $sSelect.= ' ) ';
00553 }
00554
00555 if ( !$this->_blMallUsers && $this->oxuser__oxrights->value != 'malladmin') {
00556 $sSelect .= ' AND oxshopid = "'.$this->getConfig()->getShopId().'" ';
00557 }
00558
00559 $blExists = false;
00560 if ( ( $sOxid = oxDb::getDb()->getOne( $sSelect ) ) ) {
00561
00562 $this->setId( $sOxid );
00563 $blExists = true;
00564 }
00565 return $blExists;
00566 }
00567
00573 public function getOrders()
00574 {
00575 $myConfig = $this->getConfig();
00576 $oOrders = oxNew( 'oxlist' );
00577 $oOrders->init( 'oxorder' );
00578
00579
00580
00581
00582
00583
00584
00585
00586 if ( $this->oxuser__oxregister->value > 1 ) {
00587 $sQ = 'select * from oxorder where oxuserid = "'.$this->getId().'" and oxorderdate >= ' . oxDb::getDb()->quote( $this->oxuser__oxregister->value ) . ' ';
00588
00589
00590
00591 $sQ .= ' order by oxorderdate desc ';
00592 $oOrders->selectString( $sQ );
00593 }
00594
00595 return $oOrders;
00596 }
00597
00603 public function getOrderCount()
00604 {
00605 $iCnt = 0;
00606 if ( $this->getId() && $this->oxuser__oxregister->value > 1 ) {
00607 $oDb = oxDb::getDb();
00608 $sQ = 'select count(*) from oxorder where oxuserid = "'.$this->getId().'" AND oxorderdate >= ' . $oDb->quote( $this->oxuser__oxregister->value) . ' and oxshopid = "'.$this->getConfig()->getShopId().'" ';
00609 $iCnt = (int) $oDb->getOne( $sQ );
00610 }
00611
00612 return $iCnt;
00613 }
00614
00620 public function getNoticeListArtCnt()
00621 {
00622 if ( $this->_iCntNoticeListArticles === null ) {
00623 $this->_iCntNoticeListArticles = 0;
00624 if ( $this->getId() ) {
00625 $this->_iCntNoticeListArticles = $this->getBasket( 'noticelist' )->getItemCount();
00626 }
00627 }
00628 return $this->_iCntNoticeListArticles;
00629 }
00630
00636 public function getWishListArtCnt()
00637 {
00638 if ( $this->_iCntWishListArticles === null ) {
00639 $this->_iCntWishListArticles = false;
00640 if ( $this->getId() ) {
00641 $this->_iCntWishListArticles = $this->getBasket( 'wishlist' )->getItemCount();
00642 }
00643 }
00644 return $this->_iCntWishListArticles;
00645 }
00646
00653 public function getActiveCountry()
00654 {
00655 $sDeliveryCountry = '';
00656 if ( $soxAddressId = oxConfig::getParameter( 'deladrid' ) ) {
00657 $oDelAddress = oxNew( 'oxaddress' );
00658 $oDelAddress->load( $soxAddressId );
00659 $sDeliveryCountry = $oDelAddress->oxaddress__oxcountryid->value;
00660 } elseif ( $this->getId() ) {
00661 $sDeliveryCountry = $this->oxuser__oxcountryid->value;
00662 } else {
00663 $oUser = oxNew( 'oxuser' );
00664 if ( $oUser->loadActiveUser() ) {
00665 $sDeliveryCountry = $oUser->oxuser__oxcountryid->value;
00666 }
00667 }
00668
00669 return $sDeliveryCountry;
00670 }
00671
00679 public function createUser()
00680 {
00681 $oDB = oxDb::getDb();
00682 $sShopID = $this->getConfig()->getShopId();
00683
00684
00685 $sSelect = "select oxid from oxuser where oxusername = " . $oDB->quote( $this->oxuser__oxusername->value ) . " and oxpassword = '' ";
00686 if ( !$this->_blMallUsers ) {
00687 $sSelect .= " and oxshopid = '{$sShopID}' ";
00688 }
00689 $sOXID = $oDB->getOne( $sSelect );
00690
00691
00692 if ( isset( $sOXID ) && $sOXID ) {
00693
00694 $this->delete( $sOXID );
00695 } elseif ( $this->_blMallUsers ) {
00696 $sQ = "select oxid from oxuser where oxusername = " . $oDB->quote( $this->oxuser__oxusername->value ) . " and oxusername != '' ";
00697 if ( $oDB->getOne( $sQ ) ) {
00698 $oEx = oxNew( 'oxUserException' );
00699 $oLang = oxLang::getInstance();
00700 $oEx->setMessage( sprintf( $oLang->translateString( 'EXCEPTION_USER_USEREXISTS', $oLang->getTplLanguage() ), $this->oxuser__oxusername->value ) );
00701 throw $oEx;
00702 }
00703 }
00704
00705 $this->oxuser__oxshopid = new oxField( $sShopID, oxField::T_RAW );
00706 if ( ( $blOK = $this->save() ) ) {
00707
00708 $oDB->execute( "delete from oxaddress where oxaddress.oxuserid = " . $oDB->quote( $this->oxuser__oxid->value ) . " " );
00709 $oDB->execute( "update oxuserpayments set oxuserpayments.oxuserid = " . $oDB->quote( $this->oxuser__oxusername->value ) . " where oxuserpayments.oxuserid = " . $oDB->quote( $this->oxuser__oxid->value ) . " " );
00710 } else {
00711 $oEx = oxNew( 'oxUserException' );
00712 $oEx->setMessage( 'EXCEPTION_USER_USERCREATIONFAILED' );
00713 throw $oEx;
00714 }
00715
00716 return $blOK;
00717 }
00718
00726 public function addToGroup( $sGroupID )
00727 {
00728 if ( !$this->inGroup( $sGroupID ) ) {
00729 $oNewGroup = oxNew( 'oxobject2group' );
00730 $oNewGroup->oxobject2group__oxobjectid = new oxField($this->getId(), oxField::T_RAW);
00731 $oNewGroup->oxobject2group__oxgroupsid = new oxField($sGroupID, oxField::T_RAW);
00732 if ( $oNewGroup->save() ) {
00733 $this->_oGroups[$sGroupID] = $oNewGroup;
00734 return true;
00735 }
00736 }
00737 return false;
00738 }
00739
00747 public function removeFromGroup( $sGroupID = null )
00748 {
00749 if ( $sGroupID != null && $this->inGroup( $sGroupID ) ) {
00750 $oGroups = oxNew( 'oxlist' );
00751 $oGroups->init( 'oxobject2group' );
00752 $sSelect = 'select * from oxobject2group where oxobject2group.oxobjectid = "'.$this->getId().'" and oxobject2group.oxgroupsid = "'.$sGroupID.'" ';
00753 $oGroups->selectString( $sSelect );
00754 foreach ( $oGroups as $oRemgroup ) {
00755 if ( $oRemgroup->delete() ) {
00756 unset( $this->_oGroups[$oRemgroup->oxobject2group__oxgroupsid->value] );
00757 }
00758 }
00759 }
00760 }
00761
00770 public function onOrderExecute( $oBasket, $iSuccess )
00771 {
00772
00773 if ( is_numeric( $iSuccess ) && $iSuccess != 2 && $iSuccess <= 3 ) {
00774
00775 if ( !$this->oxuser__oxdisableautogrp->value ) {
00776
00777 $myConfig = $this->getConfig();
00778 $dMidlleCustPrice = (float) $myConfig->getConfigParam( 'sMidlleCustPrice' );
00779 $dLargeCustPrice = (float) $myConfig->getConfigParam( 'sLargeCustPrice' );
00780
00781 $this->addToGroup( 'oxidcustomer' );
00782 $dBasketPrice = $oBasket->getPrice()->getBruttoPrice();
00783 if ( $dBasketPrice < $dMidlleCustPrice ) {
00784 $this->addToGroup( 'oxidsmallcust' );
00785 }
00786 if ( $dBasketPrice >= $dMidlleCustPrice && $dBasketPrice < $dLargeCustPrice ) {
00787 $this->addToGroup( 'oxidmiddlecust' );
00788 }
00789 if ( $dBasketPrice >= $dLargeCustPrice ) {
00790 $this->addToGroup( 'oxidgoodcust' );
00791 }
00792 }
00793
00794 if ( $this->inGroup( 'oxidnotyetordered' ) ) {
00795 $this->removeFromGroup( 'oxidnotyetordered' );
00796 }
00797 }
00798 }
00799
00807 public function getBasket( $sName )
00808 {
00809 if ( !isset( $this->_aBaskets[$sName] ) ) {
00810 $oBasket = oxNew( 'oxuserbasket' );
00811 $aWhere = array( 'oxuserbaskets.oxuserid' => $this->getId(), 'oxuserbaskets.oxtitle' => $sName );
00812
00813
00814 if ( !$oBasket->assignRecord( $oBasket->buildSelectString( $aWhere ) ) ) {
00815 $oBasket->oxuserbaskets__oxtitle = new oxField($sName);
00816 $oBasket->oxuserbaskets__oxuserid = new oxField($this->getId());
00817
00818
00819 $oBasket->setIsNewBasket();
00820 }
00821
00822 $this->_aBaskets[$sName] = $oBasket;
00823 }
00824
00825 return $this->_aBaskets[$sName];
00826 }
00827
00836 public function convertBirthday( $aData )
00837 {
00838
00839
00840 $iYear = isset($aData['year'])?((int) $aData['year']):false;
00841 $iMonth = isset($aData['month'])?((int) $aData['month']):false;
00842 $iDay = isset($aData['day'])?((int) $aData['day']):false;
00843
00844
00845 if ( !$iYear && !$iMonth && !$iDay )
00846 return "";
00847
00848
00849 if ( !$iYear || $iYear < 1000 || $iYear > 9999)
00850 $iYear = date('Y');
00851
00852
00853 if ( !$iMonth || $iMonth < 1 || $iMonth > 12)
00854 $iMonth = 1;
00855
00856
00857 $iMaxDays = 31;
00858 switch( $iMonth) {
00859 case 2 :
00860 if ($iMaxDays > 28)
00861 $iMaxDays = ($iYear % 4 == 0 && ($iYear % 100 != 0 || $iYear % 400 == 0)) ? 29 : 28;
00862 break;
00863 case 4 :
00864 case 6 :
00865 case 9 :
00866 case 11 :
00867 $iMaxDays = min(30, $iMaxDays);
00868 break;
00869 }
00870
00871
00872 if ( !$iDay || $iDay < 1 || $iDay > $iMaxDays) {
00873 $iDay = 1;
00874 }
00875
00876
00877 return sprintf("%04d-%02d-%02d", $iYear, $iMonth, $iDay);
00878 }
00879
00886 public function getBoni()
00887 {
00888 return 1000;
00889 }
00890
00903 public function addDynGroup( $sDynGoup, $aDeniedDynGroups )
00904 {
00905
00906 $sDynGoup = strtolower( trim( $sDynGoup ) );
00907
00908
00909 $aDisabledDynGroups = array_merge( array( 'oxidadmin' ), (array) $aDeniedDynGroups );
00910
00911
00912 $blAdd = false;
00913
00914
00915 if ( $this->oxuser__oxdisableautogrp->value || !$sDynGoup ) {
00916 $blAdd = false;
00917 } elseif ( in_array( $sDynGoup, $aDisabledDynGroups ) ) {
00918
00919 $blAdd = false;
00920 } elseif ( $this->addToGroup( $sDynGoup ) ) {
00921 $blAdd = true;
00922 }
00923
00924
00925 oxSession::deleteVar( 'dgr' );
00926
00927 return $blAdd;
00928 }
00929
00945 public function checkValues( $sLogin, $sPassword, $sPassword2, $aInvAddress, $aDelAddress )
00946 {
00947
00948 $this->_checkLogin( $sLogin, $aInvAddress );
00949
00950
00951 $this->_checkEmail( $sLogin );
00952
00953
00954 $this->_checkPassword( $sPassword, $sPassword2, ((int) oxConfig::getParameter( 'option' ) == 3) );
00955
00956
00957 $this->_checkRequiredFields( $aInvAddress, $aDelAddress );
00958
00959
00960 $this->_checkCountries( $aInvAddress, $aDelAddress );
00961
00962
00963 $this->_checkVatId( $aInvAddress );
00964 }
00965
00974 public function setNewsSubscription( $blSubscribe, $blSendOptIn )
00975 {
00976
00977 $blSuccess = false;
00978 $myConfig = $this->getConfig();
00979
00980
00981 $oNewsSubscription = $this->getNewsSubscription();
00982 if ( $blSubscribe && $oNewsSubscription->getOptInStatus() != 1 ) {
00983 if ( !$blSendOptIn ) {
00984
00985
00986 $this->addToGroup( 'oxidnewsletter' );
00987
00988 $oNewsSubscription->setOptInStatus( 1 );
00989 $blSuccess = true;
00990 } else {
00991
00992
00993 $oNewsSubscription->setOptInStatus( 2 );
00994
00995
00996 $oEmail = oxNew( 'oxemail' );
00997 $blSuccess = $oEmail->sendNewsletterDBOptInMail( $this );
00998 }
00999 } elseif ( !$blSubscribe ) {
01000 $this->removeFromGroup( 'oxidnewsletter' );
01001 $oNewsSubscription->setOptInStatus( 0 );
01002 $blSuccess = true;
01003 }
01004
01005 return $blSuccess;
01006 }
01007
01025 public function changeUserData( $sUser, $sPassword, $sPassword2, $aInvAddress, $aDelAddress )
01026 {
01027
01028
01029 $this->checkValues( $sUser, $sPassword, $sPassword2, $aInvAddress, $aDelAddress );
01030
01031
01032 $this->assign( $aInvAddress );
01033
01034
01035
01036 $this->_assignAddress( $aDelAddress );
01037
01038
01039 if ( $this->save() ) {
01040
01041
01042 $sCountryId = isset( $aInvAddress['oxuser__oxcountryid'] )?$aInvAddress['oxuser__oxcountryid']:'';
01043 $this->_setAutoGroups( $sCountryId );
01044 }
01045 }
01046
01055 public function addUserAddress( $oUser )
01056 {
01057
01058 if ( $this->_hasUserAddress( $oUser->getId() ) ) {
01059 return false;
01060 }
01061
01062 $oAddress = oxNew( 'oxaddress' );
01063
01064 $oAddress->oxaddress__oxuserid = new oxField($this->getId(), oxField::T_RAW);
01065 $oAddress->oxaddress__oxaddressuserid = new oxField($oUser->getId(), oxField::T_RAW);
01066 $oAddress->oxaddress__oxfname = new oxField($oUser->oxuser__oxfname->value, oxField::T_RAW);
01067 $oAddress->oxaddress__oxlname = new oxField($oUser->oxuser__oxlname->value, oxField::T_RAW);
01068 $oAddress->oxaddress__oxstreet = new oxField($oUser->oxuser__oxstreet->value, oxField::T_RAW);
01069 $oAddress->oxaddress__oxstreetnr = new oxField($oUser->oxuser__oxstreetnr->value, oxField::T_RAW);
01070 $oAddress->oxaddress__oxcity = new oxField($oUser->oxuser__oxcity->value, oxField::T_RAW);
01071 $oAddress->oxaddress__oxzip = new oxField($oUser->oxuser__oxzip->value, oxField::T_RAW);
01072 $oAddress->oxaddress__oxcountry = new oxField($oUser->oxuser__oxcountry->value, oxField::T_RAW);
01073 $oAddress->oxaddress__oxcountryid = new oxField($oUser->oxuser__oxcountryid->value, oxField::T_RAW);
01074 $oAddress->oxaddress__oxcompany = new oxField($oUser->oxuser__oxcompany->value, oxField::T_RAW);
01075
01076
01077 if ( $oAddress->save() ) {
01078
01079 $this->_oAddresses = null;
01080 return $oAddress->getId();
01081 }
01082 }
01083
01091 protected function _assignAddress( $aDelAddress )
01092 {
01093 if (isset($aDelAddress) && count($aDelAddress)) {
01094 $sAddressId = oxConfig::getParameter( 'oxaddressid' );
01095 $sMyAddressId = ( $sAddressId === null || $sAddressId == -1 || $sAddressId == -2 ) ? null : $sAddressId;
01096 $aDelAddress['oxaddress__oxid'] = $sMyAddressId;
01097 $oAddress = oxNew( 'oxaddress' );
01098 $oAddress->assign( $aDelAddress );
01099 $oAddress->oxaddress__oxuserid = new oxField( $this->getId(), oxField::T_RAW );
01100 $oAddress->oxaddress__oxcountry = $this->getUserCountry( $oAddress->oxaddress__oxcountryid->value );
01101 $oAddress->save();
01102
01103
01104 $this->_oAddresses = null;
01105
01106
01107 oxSession::setVar( 'deladrid', $oAddress->getId() );
01108 } else {
01109
01110 oxSession::setVar( 'deladrid', null );
01111 }
01112
01113 }
01114
01127 public function login( $sUser, $sPassword, $blCookie = false)
01128 {
01129 if ( $this->isAdmin() && !count( oxUtilsServer::getInstance()->getOxCookie() ) ) {
01130 $oEx = oxNew( 'oxCookieException' );
01131 $oEx->setMessage( 'EXCEPTION_COOKIE_NOCOOKIE' );
01132 throw $oEx;
01133 }
01134
01135 $myConfig = $this->getConfig();
01136 if ( $sPassword ) {
01137
01138 $sShopID = $myConfig->getShopId();
01139 $oDb = oxDb::getDb();
01140
01141 $sUserSelect = is_numeric( $sUser ) ? "oxuser.oxcustnr = {$sUser} " : "oxuser.oxusername = " . $oDb->quote( $sUser );
01142 $sPassSelect = " oxuser.oxpassword = MD5( CONCAT( ".$oDb->quote( $sPassword ).", UNHEX( oxuser.oxpasssalt ) ) ) ";
01143 $sShopSelect = "";
01144
01145
01146
01147 if ( $this->isAdmin() ) {
01148 $sShopSelect = " and ( oxrights != 'user' ) ";
01149 }
01150
01151 $sWhat = "oxid";
01152
01153 $sSelect = "select $sWhat from oxuser where oxuser.oxactive = 1 and {$sPassSelect} and {$sUserSelect} {$sShopSelect} ";
01154 if ( $myConfig->isDemoShop() && $this->isAdmin() ) {
01155 if ( $sPassword == "admin" && $sUser == "admin" ) {
01156 $sSelect = "select $sWhat from oxuser where oxrights = 'malladmin' {$sShopSelect} ";
01157 } else {
01158 $oEx = oxNew( 'oxUserException' );
01159 $oEx->setMessage( 'EXCEPTION_USER_NOVALIDLOGIN' );
01160 throw $oEx;
01161 }
01162 }
01163
01164
01165 $aData = $oDb->getAll( $sSelect );
01166 $sOXID = @$aData[0][0];
01167 if ( isset( $sOXID ) && $sOXID && !@$aData[0][1] ) {
01168
01169 if ( !$this->load( $sOXID ) ) {
01170 $oEx = oxNew( 'oxUserException' );
01171 $oEx->setMessage( 'EXCEPTION_USER_NOVALIDLOGIN' );
01172 throw $oEx;
01173 }
01174 }
01175 }
01176
01177
01178
01179 if ( $this->oxuser__oxid->value ) {
01180 if ( $this->isAdmin() ) {
01181 oxSession::setVar( 'auth', $this->oxuser__oxid->value );
01182 } else {
01183 oxSession::setVar( 'usr', $this->oxuser__oxid->value );
01184 }
01185
01186
01187 if ( $blCookie ) {
01188 oxUtilsServer::getInstance()->setUserCookie( $this->oxuser__oxusername->value, $this->oxuser__oxpassword->value, $myConfig->getShopId() );
01189 }
01190 return true;
01191 } else {
01192 $oEx = oxNew( 'oxUserException' );
01193 $oEx->setMessage( 'EXCEPTION_USER_NOVALIDLOGIN' );
01194 throw $oEx;
01195 }
01196 }
01197
01208 public function openIdLogin( $sUser )
01209 {
01210 $myConfig = $this->getConfig();
01211 $sShopID = $myConfig->getShopId();
01212 $oDb = oxDb::getDb();
01213
01214 $sUserSelect = "oxuser.oxusername = " . $oDb->quote( $sUser );
01215 $sShopSelect = "";
01216
01217
01218 $sSelect = "select oxid from oxuser where oxuser.oxactive = 1 and {$sUserSelect} {$sShopSelect} ";
01219
01220
01221 $aData = $oDb->getAll( $sSelect );
01222 $sOXID = @$aData[0][0];
01223 if ( isset( $sOXID ) && $sOXID ) {
01224
01225 if ( !$this->load( $sOXID ) ) {
01226 $oEx = oxNew( 'oxUserException' );
01227 $oEx->setMessage( 'EXCEPTION_USER_NOVALIDLOGIN' );
01228 throw $oEx;
01229 }
01230 }
01231
01232
01233 if ( $this->oxuser__oxid->value ) {
01234 oxSession::setVar( 'usr', $this->oxuser__oxid->value );
01235 return true;
01236 } else {
01237 $oEx = oxNew( 'oxUserException' );
01238 $oEx->setMessage( 'EXCEPTION_USER_NOVALIDLOGIN' );
01239 throw $oEx;
01240 }
01241 }
01242
01248 public function logout()
01249 {
01250
01251 oxSession::deleteVar( 'usr' );
01252 oxSession::deleteVar( 'auth' );
01253 oxSession::deleteVar( 'dgr' );
01254 oxSession::deleteVar( 'dynvalue' );
01255 oxSession::deleteVar( 'paymentid' );
01256
01257
01258
01259 oxUtilsServer::getInstance()->deleteUserCookie( $this->getConfig()->getShopID() );
01260
01261
01262 $this->setUser( null );
01263
01264 return true;
01265 }
01266
01273 public function loadAdminUser()
01274 {
01275 return $this->loadActiveUser( true );
01276 }
01277
01286 public function loadActiveUser( $blForceAdmin = false )
01287 {
01288 $myConfig = $this->getConfig();
01289
01290 $blAdmin = $myConfig->isAdmin() || $blForceAdmin;
01291 $oDB = oxDb::getDb();
01292
01293
01294 $sUserID = $blAdmin ? oxSession::getVar( 'auth' ) : oxSession::getVar( 'usr' );
01295 $blFoundInCookie = false;
01296
01297
01298 if ( !$sUserID && !$blAdmin ) {
01299 $sShopID = $myConfig->getShopId();
01300 if ( ( $sSet = oxUtilsServer::getInstance()->getUserCookie( $sShopID ) ) ) {
01301 $aData = explode( '@@@', $sSet );
01302 $sUser = $aData[0];
01303 $sPWD = @$aData[1];
01304
01305 $sSelect = 'select oxid, oxpassword from oxuser where oxuser.oxpassword != "" and oxuser.oxactive = 1 and oxuser.oxusername = '.$oDB->quote($sUser);
01306
01307
01308 $oDB = oxDb::getDb();
01309 $rs = $oDB->execute( $sSelect );
01310 if ( $rs != false && $rs->recordCount() > 0 ) {
01311 while (!$rs->EOF) {
01312 $sTest = crypt( $rs->fields[1], 'ox' );
01313 if ( $sTest == $sPWD ) {
01314
01315 $sUserID = $rs->fields[0];
01316 $blFoundInCookie = true;
01317 break;
01318 }
01319 $rs->moveNext();
01320 }
01321 }
01322 }
01323 }
01324
01325
01326 if ( $sUserID ) {
01327 if ( $this->load( $sUserID ) ) {
01328
01329 if ($blAdmin) {
01330 oxSession::setVar( 'auth', $sUserID );
01331 } else {
01332 oxSession::setVar( 'usr', $sUserID );
01333 }
01334
01335
01336 $this->_blLoadedFromCookie = $blFoundInCookie;
01337 return true;
01338 }
01339 } else {
01340
01341 oxSession::deleteVar( 'usr' );
01342 oxSession::deleteVar( 'auth' );
01343
01344 return false;
01345 }
01346 }
01347
01360 protected function _ldapLogin( $sUser, $sPassword, $sShopID, $sShopSelect)
01361 {
01362 include "oxldap.php";
01363 $myConfig = $this->getConfig();
01364 $oDb = oxDb::getDb();
01365
01366 $aLDAPParams = $myConfig->getConfigParam( 'aLDAPParams' );
01367 $oLDAP = new oxLDAP( $aLDAPParams['HOST'], $aLDAPParams['PORT'] );
01368
01369 $sLDAPKey = $oDb->getOne("select oxldapkey from oxuser where oxuser.oxactive = 1 and oxuser.oxusername = ".$oDb->quote($sUser)." $sShopSelect");
01370 if ( isset( $sLDAPKey) && $sLDAPKey) {
01371 $sUser = $sLDAPKey;
01372 }
01373
01374
01375 $oLDAP->login( $sUser, $sPassword, $aLDAPParams['USERQUERY'], $aLDAPParams['BASEDN'], $aLDAPParams['FILTER']);
01376
01377 $aData = $oLDAP->mapData($aLDAPParams['DATAMAP']);
01378 if ( isset( $aData['OXUSERNAME']) && $aData['OXUSERNAME']) {
01379
01380
01381 $sSelect = "select oxid from oxuser where oxuser.oxusername = ".$oDb->quote($aData['OXUSERNAME'])." $sShopSelect";
01382 $sOXID = $oDb->getOne( $sSelect);
01383
01384 if ( !isset( $sOXID) || !$sOXID) {
01385
01386 $this->setId();
01387
01388
01389 foreach ( $aData as $fldname => $value) {
01390 $sField = "oxuser__".strtolower( $fldname);
01391 $this->$sField->setValue($aData[$fldname]);
01392 }
01393
01394 $this->oxuser__oxactive->setValue(1);
01395 $this->oxuser__oxshopid->setValue($sShopID);
01396 $this->oxuser__oxldapkey->setValue($sUser);
01397 $this->oxuser__oxrights->setValue("user");
01398 $this->setPassword( "ldap user" );
01399
01400 $this->save();
01401 } else {
01402 $this->load( $sOXID);
01403 }
01404
01405 } else {
01406 $oEx = oxNew( 'oxUserException' );
01407 $oEx->setMessage('EXCEPTION_USER_NOVALUES');
01408 throw $oEx;
01409 }
01410 }
01411
01418 protected function _getUserRights()
01419 {
01420
01421 if ( !$this->oxuser__oxrights->value )
01422 return 'user';
01423
01424 $oDB = oxDb::getDb();
01425 $myConfig = $this->getConfig();
01426 $sAuthRights = null;
01427
01428
01429 $sAuthUserID = $this->isAdmin()?oxSession::getVar( 'auth' ):null;
01430 $sAuthUserID = $sAuthUserID?$sAuthUserID:oxSession::getVar( 'usr' );
01431 if ( $sAuthUserID ) {
01432 $sAuthRights = $oDB->getOne( 'select oxrights from '.$this->getViewName().' where oxid='.$oDB->quote( $sAuthUserID ) );
01433 }
01434
01435
01436 $aRights = array();
01437
01438
01439 if ( $sCurrRights = $oDB->getOne( 'select oxrights from '.$this->getViewName().' where oxid="'.$this->getId().'"' ) ) {
01440 $aRights[] = $sCurrRights;
01441 }
01442 $aRights[] = 'user';
01443
01444 if ( !$sAuthRights || !( $sAuthRights == 'malladmin' || $sAuthRights == $myConfig->getShopId() ) ) {
01445 return current( $aRights );
01446 } elseif ( $sAuthRights == $myConfig->getShopId() ) {
01447 $aRights[] = $sAuthRights;
01448 if ( !in_array( $this->oxuser__oxrights->value, $aRights ) ) {
01449 return current( $aRights );
01450 }
01451 }
01452
01453
01454 return $this->oxuser__oxrights->value;
01455 }
01456
01466 protected function _setRecordNumber( $sMaxField, $aWhere = null ,$iMaxTryCnt = 5 )
01467 {
01468
01469
01470
01471
01472
01473
01474 return parent::_setRecordNumber( $sMaxField, $aWhere, $iMaxTryCnt );
01475 }
01476
01482 protected function _insert()
01483 {
01484
01485
01486 $this->oxuser__oxcreate = new oxField(date( 'Y-m-d H:i:s' ), oxField::T_RAW);
01487
01488 if ( !isset( $this->oxuser__oxboni->value ) ) {
01489 $this->oxuser__oxboni = new oxField($this->getBoni(), oxField::T_RAW);
01490 }
01491
01492 if ( $blInsert = parent::_insert() ) {
01493
01494 if ( !$this->oxuser__oxcustnr->value || !$this->isAdmin() ) {
01495 $this->_setRecordNumber( 'oxcustnr' );
01496 }
01497 }
01498
01499 return $blInsert;
01500 }
01501
01507 protected function _update()
01508 {
01509
01510 if (!$this->oxuser__oxpassword->value && $this->oxuser__oxregister->value < 1) {
01511 $this->_aSkipSaveFields[] = 'oxboni';
01512 }
01513
01514
01515 $this->_aSkipSaveFields[] = 'oxcreate';
01516 if ( !$this->isAdmin() ) {
01517 $this->_aSkipSaveFields[] = 'oxcustnr';
01518 $this->_aSkipSaveFields[] = 'oxrights';
01519 }
01520
01521
01522 if ( ( $blUpdate = parent::_update() ) ) {
01523 $this->getNewsSubscription()->updateSubscription( $this );
01524 }
01525
01526 return $blUpdate;
01527 }
01528
01544 protected function _checkLogin( &$sLogin, $aInvAddress )
01545 {
01546 $myConfig = $this->getConfig();
01547
01548 $sLogin = ( isset( $aInvAddress['oxuser__oxusername'] ) )?$aInvAddress['oxuser__oxusername']:$sLogin;
01549
01550
01551
01552 if ( $this->oxuser__oxpassword->value && $sLogin != $this->oxuser__oxusername->value ) {
01553
01554
01555 $sNewPass = (isset( $aInvAddress['oxuser__oxpassword']) && $aInvAddress['oxuser__oxpassword'] )?$aInvAddress['oxuser__oxpassword']:oxConfig::getParameter( 'user_password' );
01556 if ( !$sNewPass ) {
01557
01558
01559 $oEx = oxNew( 'oxInputException' );
01560 $oEx->setMessage('EXCEPTION_INPUT_NOTALLFIELDS');
01561 throw $oEx;
01562 } else {
01563
01564
01565 if ( !$this->isSamePassword( $sNewPass ) ) {
01566 $oEx = oxNew( 'oxUserException' );
01567 $oEx->setMessage('EXCEPTION_USER_PWDDONTMATCH');
01568 throw $oEx;
01569 }
01570 }
01571 }
01572
01573 if ( $this->checkIfEmailExists( $sLogin ) ) {
01574
01575 $oEx = oxNew( 'oxUserException' );
01576 $oLang = oxLang::getInstance();
01577 $oEx->setMessage( sprintf( $oLang->translateString( 'EXCEPTION_USER_USEREXISTS', $oLang->getTplLanguage() ), $sLogin ) );
01578 throw $oEx;
01579 }
01580 }
01581
01589 public function checkIfEmailExists( $sEmail )
01590 {
01591 $myConfig = $this->getConfig();
01592 $oDB = oxDb::getDb();
01593 $iShopId = $myConfig->getShopId();
01594 $blExists = false;
01595
01596 $sQ = 'select oxshopid, oxrights, oxpassword from oxuser where oxusername = '. $oDB->quote( $sEmail );
01597 if ( ( $sOxid = $this->getId() ) ) {
01598 $sQ .= " and oxid <> '$sOxid' ";
01599 }
01600
01601 $oRs = $oDB->execute( $sQ );
01602 if ( $oRs != false && $oRs->recordCount() > 0 ) {
01603
01604 if ( $this->_blMallUsers ) {
01605
01606 $blExists = true;
01607 if ( $oRs->fields[1] == 'user' && !$oRs->fields[2] ) {
01608
01609
01610 $blExists = false;
01611 }
01612 } else {
01613
01614 $blExists = false;
01615 while ( !$oRs->EOF ) {
01616 if ( $oRs->fields[1] != 'user' ) {
01617
01618
01619 $blExists = true;
01620 break;
01621 } elseif ( $oRs->fields[0] == $iShopId && $oRs->fields[2] ) {
01622
01623
01624 $blExists = true;
01625 break;
01626 }
01627
01628 $oRs->moveNext();
01629 }
01630 }
01631 }
01632 return $blExists;
01633 }
01634
01642 public function getUserRecommLists( $sOXID = null )
01643 {
01644 if ( !$sOXID )
01645 $sOXID = $this->getId();
01646
01647
01648 $iActPage = (int) oxConfig::getParameter( 'pgNr' );
01649 $iActPage = ($iActPage < 0) ? 0 : $iActPage;
01650
01651
01652 $iNrofCatArticles = $this->getConfig()->getConfigParam( 'iNrofCatArticles' );
01653 $iNrofCatArticles = $iNrofCatArticles ? $iNrofCatArticles : 10;
01654
01655
01656 $oRecommList = oxNew( 'oxlist' );
01657 $oRecommList->init( 'oxrecommlist' );
01658 $oRecommList->setSqlLimit( $iNrofCatArticles * $iActPage, $iNrofCatArticles );
01659 $iShopId = $this->getConfig()->getShopId();
01660 $sSelect = 'select * from oxrecommlists where oxuserid ='. oxDb::getDb()->quote( $sOXID ) . ' and oxshopid ="'. $iShopId .'"';
01661 $oRecommList->selectString( $sSelect );
01662
01663 return $oRecommList;
01664 }
01665
01673 public function getRecommListsCount( $sOx = null )
01674 {
01675 if ( !$sOx ) {
01676 $sOx = $this->getId();
01677 }
01678
01679 if ( $this->_iCntRecommLists === null || $sOx ) {
01680 $oDb = oxDb::getDb();
01681 $this->_iCntRecommLists = 0;
01682 $iShopId = $this->getConfig()->getShopId();
01683 $sSelect = 'select count(oxid) from oxrecommlists where oxuserid = ' . $oDb->quote( $sOx ) . ' and oxshopid ="'. $iShopId .'"';
01684 $this->_iCntRecommLists = $oDb->getOne( $sSelect );
01685 }
01686 return $this->_iCntRecommLists;
01687 }
01688
01697 protected function _checkEmail( $sEmail )
01698 {
01699
01700 if ( !$sEmail ) {
01701 $oEx = oxNew( 'oxInputException' );
01702 $oEx->setMessage('EXCEPTION_INPUT_NOTALLFIELDS');
01703 throw $oEx;
01704 }
01705
01706
01707 if ( !oxUtils::getInstance()->isValidEmail( $sEmail ) ) {
01708 $oEx = oxNew( 'oxInputException' );
01709 $oEx->setMessage( 'EXCEPTION_INPUT_NOVALIDEMAIL' );
01710 throw $oEx;
01711 }
01712 }
01713
01728 protected function _checkPassword( $sNewPass, $sConfPass, $blCheckLenght = false )
01729 {
01730 $this->checkPassword( $sNewPass, $sConfPass, $blCheckLenght );
01731 }
01732
01745 public function checkPassword( $sNewPass, $sConfPass, $blCheckLenght = false )
01746 {
01747
01748 if ( $blCheckLenght && getStr()->strlen( $sNewPass ) == 0 ) {
01749 $oEx = oxNew( 'oxInputException' );
01750 $oEx->setMessage('EXCEPTION_INPUT_EMPTYPASS');
01751 throw $oEx;
01752 }
01753
01754
01755 if ( $blCheckLenght && getStr()->strlen( $sNewPass ) < 6 ) {
01756 $oEx = oxNew( 'oxInputException' );
01757 $oEx->setMessage('EXCEPTION_INPUT_PASSTOOSHORT');
01758 throw $oEx;
01759 }
01760
01761
01762 if ( $sNewPass != $sConfPass ) {
01763 $oEx = oxNew( 'oxUserException' );
01764 $oEx->setMessage('EXCEPTION_USER_PWDDONTMATCH');
01765 throw $oEx;
01766 }
01767 }
01768
01777 protected function _checkCountries( $aInvAddress, $aDelAddress )
01778 {
01779 $sBillCtry = isset( $aInvAddress['oxuser__oxcountryid'] ) ? $aInvAddress['oxuser__oxcountryid'] : null;
01780 $sDelCtry = isset( $aDelAddress['oxaddress__oxcountryid'] ) ? $aDelAddress['oxaddress__oxcountryid'] : null;
01781
01782 if ( $sBillCtry || $sDelCtry ) {
01783 $oDb = oxDb::getDb();
01784
01785 if ( ( $sBillCtry == $sDelCtry ) || ( !$sBillCtry && $sDelCtry ) || ( $sBillCtry && !$sDelCtry ) ) {
01786 $sBillCtry = $sBillCtry ? $sBillCtry : $sDelCtry;
01787 $sQ = "select oxactive from oxcountry where oxid = ".$oDb->quote( $sBillCtry )." ";
01788 } else {
01789 $sQ = "select ( select oxactive from oxcountry where oxid = ".$oDb->quote( $sBillCtry )." ) and
01790 ( select oxactive from oxcountry where oxid = ".$oDb->quote( $sDelCtry )." ) ";
01791 }
01792
01793 if ( !$oDb->getOne( $sQ ) ) {
01794 $oEx = oxNew( 'oxUserException' );
01795 $oEx->setMessage('EXCEPTION_INPUT_NOTALLFIELDS' );
01796 throw $oEx;
01797 }
01798 }
01799 }
01800
01812 protected function _checkRequiredFields( $aInvAddress, $aDelAddress )
01813 {
01814
01815 $aMustFields = array( 'oxuser__oxfname',
01816 'oxuser__oxlname',
01817 'oxuser__oxstreetnr',
01818 'oxuser__oxstreet',
01819 'oxuser__oxzip',
01820 'oxuser__oxcity' );
01821
01822
01823 $aMustFillFields = $this->getConfig()->getConfigParam( 'aMustFillFields' );
01824 if ( is_array( $aMustFillFields ) ) {
01825 $aMustFields = $aMustFillFields;
01826 }
01827
01828
01829 $aInvAddress = is_array( $aInvAddress )?$aInvAddress:array();
01830 $aDelAddress = is_array( $aDelAddress )?$aDelAddress:array();
01831
01832
01833 $aFields = array_merge( $aInvAddress, $aDelAddress );
01834
01835
01836
01837 $blCheckDel = false;
01838 if ( count( $aDelAddress ) ) {
01839 $blCheckDel = true;
01840 }
01841
01842
01843 foreach ( $aMustFields as $sMustField ) {
01844
01845
01846 if ( !$blCheckDel && strpos( $sMustField, 'oxaddress__' ) === 0 ) {
01847 continue;
01848 }
01849
01850 if ( isset( $aFields[$sMustField] ) && is_array( $aFields[$sMustField] ) ) {
01851 $this->_checkRequiredArrayFields( $sMustField, $aFields[$sMustField] );
01852 } elseif ( !isset( $aFields[$sMustField] ) || !trim( $aFields[$sMustField] ) ) {
01853 $oEx = oxNew( 'oxInputException' );
01854 $oEx->setMessage('EXCEPTION_INPUT_NOTALLFIELDS');
01855 throw $oEx;
01856 }
01857 }
01858 }
01859
01870 protected function _checkRequiredArrayFields( $sFieldName, $aFieldValues )
01871 {
01872 foreach ( $aFieldValues as $sValue ) {
01873 if ( !trim( $sValue ) ) {
01874 $oEx = oxNew( 'oxInputException' );
01875 $oEx->setMessage('EXCEPTION_INPUT_NOTALLFIELDS');
01876 throw $oEx;
01877 }
01878 }
01879 }
01880
01891 protected function _checkVatId( $aInvAddress )
01892 {
01893
01894 if ( $aInvAddress['oxuser__oxustid'] && $aInvAddress['oxuser__oxcompany'] ) {
01895
01896 if (!($sCountryId = $aInvAddress['oxuser__oxcountryid'])) {
01897
01898 return;
01899 }
01900 $oCountry = oxNew('oxcountry');
01901 if (!$oCountry->load($sCountryId)) {
01902 throw new oxObjectException();
01903 }
01904 if ($oCountry->isForeignCountry() && $oCountry->isInEU()) {
01905 if (strncmp($aInvAddress['oxuser__oxustid'], $oCountry->oxcountry__oxisoalpha2->value, 2)) {
01906 $oEx = oxNew( 'oxInputException' );
01907 $oEx->setMessage( 'VAT_MESSAGE_ID_NOT_VALID' );
01908 throw $oEx;
01909 }
01910 }
01911
01912 }
01913 }
01914
01923 protected function _setAutoGroups( $sCountryId )
01924 {
01925
01926 $blForeigner = true;
01927 $blForeignGroupExists = false;
01928 $blInlandGroupExists = false;
01929
01930 $aHomeCountry = $this->getConfig()->getConfigParam( 'aHomeCountry' );
01931
01932 if ( is_array($aHomeCountry)) {
01933 if (in_array($sCountryId, $aHomeCountry)) {
01934 $blForeigner = false;
01935 }
01936 } elseif ($sCountryId == $aHomeCountry) {
01937 $blForeigner = false;
01938 }
01939
01940 if ( $this->inGroup( 'oxidforeigncustomer' ) ) {
01941 $blForeignGroupExists = true;
01942 if ( !$blForeigner ) {
01943 $this->removeFromGroup( 'oxidforeigncustomer' );
01944 }
01945 }
01946
01947 if ( $this->inGroup( 'oxidnewcustomer' ) ) {
01948 $blInlandGroupExists = true;
01949 if ( $blForeigner ) {
01950 $this->removeFromGroup( 'oxidnewcustomer' );
01951 }
01952 }
01953
01954 if ( !$this->oxuser__oxdisableautogrp->value ) {
01955 if ( !$blForeignGroupExists && $blForeigner ) {
01956 $this->addToGroup( 'oxidforeigncustomer' );
01957 }
01958 if ( !$blInlandGroupExists && !$blForeigner ) {
01959 $this->addToGroup( 'oxidnewcustomer' );
01960 }
01961 }
01962 }
01963
01971 protected function _hasUserAddress( $sUserId )
01972 {
01973 $oAddresses = $this->getUserAddresses();
01974 if ( $oAddresses && count($oAddresses)>0 ) {
01975 $oAddresses->rewind() ;
01976 foreach ($oAddresses as $key => $oAddress) {
01977 if ( $oAddress->oxaddress__oxaddressuserid->value == $sUserId ) {
01978 return true;
01979 }
01980 }
01981 }
01982 return false;
01983 }
01984
01997 protected function _setUserCookie( $sUser, $sPassword, $sShopId = null, $iTimeout = 31536000 )
01998 {
01999 oxUtilsServer::getInstance()->setUserCookie( $sUser, $sPassword, $sShopId, $iTimeout );
02000 }
02001
02011 protected function _deleteUserCookie( $sShopId = null )
02012 {
02013 oxUtilsServer::getInstance()->deleteUserCookie( $sShopId );
02014 }
02015
02025 protected static function _getUserCookie( $sShopId = null )
02026 {
02027 return oxUtilsServer::getInstance()->getUserCookie( $sShopId );
02028 }
02029
02030
02039 public function loadUserByUpdateId( $sUid )
02040 {
02041 $oDb = oxDb::getDb();
02042 $sQ = "select oxid from ".$this->getViewName()." where oxupdateexp >= ".time()." and MD5( CONCAT( oxid, oxshopid, oxupdatekey ) ) = ".$oDb->quote( $sUid );
02043 if ( $sUserId = $oDb->getOne( $sQ ) ) {
02044 return $this->load( $sUserId );
02045 }
02046 }
02047
02055 public function setUpdateKey( $blReset = false )
02056 {
02057 $sUpKey = $blReset ? '' : oxUtilsObject::getInstance()->generateUId();
02058 $iUpTime = $blReset ? 0 : oxUtilsDate::getInstance()->getTime() + $this->getUpdateLinkTerm();
02059
02060
02061 $this->oxuser__oxupdatekey = new oxField( $sUpKey, oxField::T_RAW );
02062
02063
02064 $this->oxuser__oxupdateexp = new oxField( $iUpTime, oxField::T_RAW );
02065
02066
02067 $this->save();
02068 }
02069
02075 public function getUpdateLinkTerm()
02076 {
02077 return 3600 * 6;
02078 }
02079
02087 public function isExpiredUpdateId( $sKey )
02088 {
02089 $oDb = oxDb::getDb();
02090 $sQ = "select 1 from ".$this->getViewName()." where oxupdateexp >= ".time()." and MD5( CONCAT( oxid, oxshopid, oxupdatekey ) ) = ".$oDb->quote( $sKey );
02091 return !( (bool) $oDb->getOne( $sQ ) );
02092 }
02093
02099 public function getUpdateId()
02100 {
02101 if ( $this->_sUpdateKey === null ) {
02102 $this->setUpdateKey();
02103 $this->_sUpdateKey = md5( $this->getId() . $this->oxuser__oxshopid->value . $this->oxuser__oxupdatekey->value );
02104 }
02105 return $this->_sUpdateKey;
02106 }
02107
02116 public function encodePassword( $sPassword, $sSalt )
02117 {
02118 $oDb = oxDb::getDb();
02119 return $oDb->getOne( "select MD5( CONCAT( ".$oDb->quote( $sPassword ).", UNHEX( '{$sSalt}' ) ) )" );
02120 }
02121
02129 public function prepareSalt( $sSalt )
02130 {
02131 return ( $sSalt ? oxDb::getDb()->getOne( "select HEX( '{$sSalt}' )" ) : '' );
02132 }
02133
02141 public function decodeSalt( $sSaltHex )
02142 {
02143 return ( $sSaltHex ? oxDb::getDb()->getOne( "select UNHEX( '{$sSaltHex}' )" ) : '' );
02144 }
02145
02153 public function setPassword( $sPassword = null )
02154 {
02155
02156 $sSalt = $sPassword ? $this->prepareSalt( oxUtilsObject::getInstance()->generateUID() ) : '';
02157
02158
02159 $sPassword = $sPassword ? $this->encodePassword( $sPassword, $sSalt ) : '';
02160
02161 $this->oxuser__oxpassword = new oxField( $sPassword, oxField::T_RAW );
02162 $this->oxuser__oxpasssalt = new oxField( $sSalt, oxField::T_RAW );
02163 }
02164
02172 public function isSamePassword( $sNewPass )
02173 {
02174 return $this->encodePassword( $sNewPass, $this->oxuser__oxpasssalt->value ) == $this->oxuser__oxpassword->value;
02175 }
02176
02182 public function isLoadedFromCookie()
02183 {
02184 return $this->_blLoadedFromCookie;
02185 }
02186
02193 public function getPasswordHash()
02194 {
02195 $sHash = null;
02196 if ( $this->oxuser__oxpassword->value ) {
02197 if ( strpos( $this->oxuser__oxpassword->value, 'ox_' ) === 0 ) {
02198
02199 $this->setPassword( oxUtils::getInstance()->strRem( $this->oxuser__oxpassword->value ) );
02200 } elseif ( ( strlen( $this->oxuser__oxpassword->value ) < 32 ) && ( strpos( $this->oxuser__oxpassword->value, 'openid_' ) !== 0 ) ) {
02201
02202 $this->setPassword( $this->oxuser__oxpassword->value );
02203 }
02204 $sHash = $this->oxuser__oxpassword->value;
02205 }
02206 return $sHash;
02207 }
02208
02217 public static function getAdminUser()
02218 {
02219 return self::getActiveUser( true );
02220 }
02221
02232 public static function getActiveUser( $blForceAdmin = false )
02233 {
02234 $oUser = oxNew( 'oxuser' );
02235 if ( $oUser->loadActiveUser( $blForceAdmin ) ) {
02236 return $oUser;
02237 } else {
02238 return false;
02239 }
02240 }
02241
02249 public function getOpenIdPassword( $iLength = 25 )
02250 {
02251 $sPassword= "openid_".substr( oxUtilsObject::getInstance()->generateUId(), 0, $iLength);
02252 return $sPassword;
02253 }
02254
02262 public function getReviewUserHash( $sUserId )
02263 {
02264 $oDb = oxDb::getDb();
02265 $sReviewUserHash = $oDb->getOne('select md5(concat("oxid", oxpassword, oxusername )) from oxuser where oxid = ' . $oDb->quote( $sUserId ) .'');
02266 return $sReviewUserHash;
02267 }
02268
02276 public function getReviewUserId( $sReviewUserHash )
02277 {
02278 $oDb = oxDb::getDb();
02279 $sUserId = $oDb->getOne('select oxid from oxuser where md5(concat("oxid", oxpassword, oxusername )) = ' . $oDb->quote( $sReviewUserHash ) .'');
02280 return $sUserId;
02281 }
02282
02283 }