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 $_aAddresses = array();
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->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 $sUserId = isset( $sUserId ) ? $sUserId : $this->getId();
00288 if ( !isset( $this->_aAddresses[$sUserId] ) ) {
00289 $sSelect = "select * from oxaddress where oxaddress.oxuserid = " . oxDb::getDb()->quote( $sUserId ) . "";
00290
00291
00292 $this->_aAddresses[$sUserId] = oxNew( 'oxlist' );
00293 $this->_aAddresses[$sUserId]->init( "oxaddress" );
00294 $this->_aAddresses[$sUserId]->selectString( $sSelect );
00295
00296
00297 if ( $sAddressId = $this->getSelectedAddressId() ) {
00298 foreach ( $this->_aAddresses[$sUserId] as $oAddress ) {
00299 $oAddress->selected = 0;
00300 if ( $oAddress->getId() === $sAddressId ) {
00301 $oAddress->selected = 1;
00302 break;
00303 }
00304 }
00305 }
00306 }
00307 return $this->_aAddresses[$sUserId];
00308 }
00309
00317 public function setSelectedAddressId( $sAddressId )
00318 {
00319 $this->_sSelAddressId = $sAddressId;
00320 }
00321
00327 public function getSelectedAddressId()
00328 {
00329 if ( $this->_sSelAddressId !== null ) {
00330 return $this->_sSelAddressId;
00331 }
00332
00333 $sAddressId = oxConfig::getParameter( "oxaddressid");
00334 if ( !$sAddressId && !oxConfig::getParameter( 'reloadaddress' ) ) {
00335 $sAddressId = oxSession::getVar( "deladrid" );
00336 }
00337 return $sAddressId;
00338 }
00339
00348 public function getSelectedAddress( $sWishId = false )
00349 {
00350 $oAddresses = $this->getUserAddresses();
00351 if ( $oAddresses->count() ) {
00352 if ( $sAddressId = $this->getSelectedAddressId() ) {
00353 foreach ( $oAddresses as $oAddress ) {
00354 if ( $oAddress->selected == 1 ) {
00355 $sAddressId = $oAddress->getId();
00356 break;
00357 }
00358 }
00359 } elseif ( $sWishId ) {
00360 foreach ( $oAddresses as $oAddress ) {
00361 $oAddress->selected = 0;
00362 if ( $oAddress->oxaddress__oxaddressuserid->value == $sWishId ) {
00363 $oAddress->selected = 1;
00364 $sAddressId = $oAddress->getId();
00365 }
00366 }
00367 }
00368
00369
00370 if ( !$sAddressId ) {
00371 $oAddresses->rewind();
00372 $oAddress = $oAddresses->current();
00373 $oAddress->selected = 1;
00374 $sAddressId = $oAddress->getId();
00375 }
00376 }
00377
00378 return $sAddressId;
00379 }
00380
00388 public function getUserPayments( $sOXID = null )
00389 {
00390 if ( $this->_oPayments === null ) {
00391
00392 if ( !$sOXID ) {
00393 $sOXID = $this->getId();
00394 }
00395
00396 $sSelect = 'select * from oxuserpayments where oxuserid = ' . oxDb::getDb()->quote( $sOXID ) . ' ';
00397
00398 $this->_oPayments = oxNew( 'oxlist' );
00399 $this->_oPayments->init( 'oxUserPayment' );
00400 $this->_oPayments->selectString( $sSelect );
00401
00402 $myUtils = oxUtils::getInstance();
00403 foreach ( $this->_oPayments as $oPayment ) {
00404
00405 $oPayment = $myUtils->assignValuesFromText( $val->oxuserpayments__oxvalue->value );
00406 }
00407 }
00408
00409 return $this->_oPayments;
00410 }
00411
00417 public function save()
00418 {
00419 $myConfig = oxConfig::getInstance();
00420
00421 $blAddRemark = false;
00422 if ( $this->oxuser__oxpassword->value && $this->oxuser__oxregister->value < 1 ) {
00423 $blAddRemark = true;
00424
00425 $this->oxuser__oxregister = new oxField(date( 'Y-m-d H:i:s' ), oxField::T_RAW);
00426 }
00427
00428
00429 $this->oxuser__oxrights = new oxField($this->_getUserRights(), oxField::T_RAW);
00430
00431
00432 if ( is_array( $this->oxuser__oxbirthdate->value ) ) {
00433 $this->oxuser__oxbirthdate = new oxField($this->convertBirthday( $this->oxuser__oxbirthdate->value ), oxField::T_RAW);
00434 }
00435
00436
00437 if ( $myConfig->getConfigParam( "bl_showFbConnect" ) ) {
00438 $oFb = oxFb::getInstance();
00439 if ( $oFb->isConnected() && $oFb->getUser() ) {
00440 $this->oxuser__oxfbid = new oxField( $oFb->getUser() );
00441 }
00442 }
00443
00444 $blRet = parent::save();
00445
00446
00447 if ( $blAddRemark && $blRet ) {
00448 $oRemark = oxNew( 'oxremark' );
00449 $oRemark->oxremark__oxtext = new oxField(oxLang::getInstance()->translateString( 'usrRegistered' ), oxField::T_RAW);
00450 $oRemark->oxremark__oxtype = new oxField('r', oxField::T_RAW);
00451 $oRemark->oxremark__oxparentid = new oxField($this->getId(), oxField::T_RAW);
00452 $oRemark->save();
00453 }
00454
00455 return $blRet;
00456 }
00457
00463 public function allowDerivedUpdate()
00464 {
00465 return true;
00466 }
00467
00475 public function inGroup( $sGroupID )
00476 {
00477 $blIn = false;
00478 if ( ( $oGroups = $this->getUserGroups() ) ) {
00479 $blIn = isset( $oGroups[ $sGroupID ] );
00480 }
00481
00482 return $blIn;
00483 }
00484
00493 public function delete( $sOXID = null )
00494 {
00495
00496 if ( !$sOXID ) {
00497 $sOXID = $this->getId();
00498 }
00499 if ( !$sOXID ) {
00500 return false;
00501 }
00502
00503 $blDeleted = parent::delete( $sOXID );
00504
00505 if ( $blDeleted ) {
00506 $oDB = oxDb::getDb();
00507 $sOXIDQuoted = $oDB->quote($sOXID);
00508
00509
00510 $rs = $oDB->execute( "delete from oxaddress where oxaddress.oxuserid = {$sOXIDQuoted}" );
00511 $rs = $oDB->execute( "delete from oxobject2group where oxobject2group.oxobjectid = {$sOXIDQuoted}" );
00512
00513
00514 $rs = $oDB->execute( "delete oxuserbasketitems.* from oxuserbasketitems, oxuserbaskets where oxuserbasketitems.oxbasketid = oxuserbaskets.oxid and oxuserid = {$sOXIDQuoted}" );
00515 $rs = $oDB->execute( "delete from oxuserbaskets where oxuserid = {$sOXIDQuoted}" );
00516
00517
00518 $rs = $oDB->execute( "delete from oxnewssubscribed where oxuserid = {$sOXIDQuoted}" );
00519
00520
00521 $rs = $oDB->execute( "delete from oxobject2delivery where oxobjectid = {$sOXIDQuoted}");
00522
00523
00524 $rs = $oDB->execute( "delete from oxobject2discount where oxobjectid = {$sOXIDQuoted}");
00525
00526
00527
00528 $rs = $oDB->execute( "delete from oxremark where oxparentid = {$sOXIDQuoted} and oxtype !='o'" );
00529
00530 $blDeleted = $rs->EOF;
00531 }
00532
00533 return $blDeleted;
00534 }
00535
00543 public function load( $oxID )
00544 {
00545
00546 $blRet = parent::Load( $oxID );
00547
00548
00549 if ( isset( $this->oxuser__oxcreate->value ) ) {
00550 $this->oxuser__oxcreate->setValue(oxUtilsDate::getInstance()->formatDBDate( $this->oxuser__oxcreate->value ));
00551 }
00552
00553 return $blRet;
00554 }
00555
00563 public function exists( $sOXID = null )
00564 {
00565 $oDb = oxDb::getDb();
00566 if ( !$sOXID ) {
00567 $sOXID = $this->getId();
00568 }
00569
00570 $sSelect = 'SELECT oxid FROM '.$this->getViewName().'
00571 WHERE ( oxusername = '.$oDb->quote( $this->oxuser__oxusername->value).'';
00572
00573 if ( $sOXID ) {
00574 $sSelect.= " or oxid = ".$oDb->quote( $sOXID ) . " ) ";
00575 } else {
00576 $sSelect.= ' ) ';
00577 }
00578
00579 if ( !$this->_blMallUsers && $this->oxuser__oxrights->value != 'malladmin') {
00580 $sSelect .= ' AND oxshopid = "'.$this->getConfig()->getShopId().'" ';
00581 }
00582
00583 $blExists = false;
00584 if ( ( $sOxid = oxDb::getDb()->getOne( $sSelect ) ) ) {
00585
00586 $this->setId( $sOxid );
00587 $blExists = true;
00588 }
00589 return $blExists;
00590 }
00591
00600 public function getOrders( $iLimit = false, $iPage = 0 )
00601 {
00602 $myConfig = $this->getConfig();
00603 $oOrders = oxNew( 'oxlist' );
00604 $oOrders->init( 'oxorder' );
00605
00606 if ( $iLimit !== false ) {
00607 $oOrders->setSqlLimit( $iLimit * $iPage, $iLimit );
00608 }
00609
00610
00611
00612
00613
00614
00615
00616
00617 if ( $this->oxuser__oxregister->value > 1 ) {
00618 $sQ = 'select * from oxorder where oxuserid = "'.$this->getId().'" and oxorderdate >= ' . oxDb::getDb()->quote( $this->oxuser__oxregister->value ) . ' ';
00619
00620
00621
00622 $sQ .= ' order by oxorderdate desc ';
00623 $oOrders->selectString( $sQ );
00624 }
00625
00626 return $oOrders;
00627 }
00628
00634 public function getOrderCount()
00635 {
00636 $iCnt = 0;
00637 if ( $this->getId() && $this->oxuser__oxregister->value > 1 ) {
00638 $oDb = oxDb::getDb();
00639 $sQ = 'select count(*) from oxorder where oxuserid = "'.$this->getId().'" AND oxorderdate >= ' . $oDb->quote( $this->oxuser__oxregister->value) . ' and oxshopid = "'.$this->getConfig()->getShopId().'" ';
00640 $iCnt = (int) $oDb->getOne( $sQ );
00641 }
00642
00643 return $iCnt;
00644 }
00645
00651 public function getNoticeListArtCnt()
00652 {
00653 if ( $this->_iCntNoticeListArticles === null ) {
00654 $this->_iCntNoticeListArticles = 0;
00655 if ( $this->getId() ) {
00656 $this->_iCntNoticeListArticles = $this->getBasket( 'noticelist' )->getItemCount();
00657 }
00658 }
00659 return $this->_iCntNoticeListArticles;
00660 }
00661
00667 public function getWishListArtCnt()
00668 {
00669 if ( $this->_iCntWishListArticles === null ) {
00670 $this->_iCntWishListArticles = false;
00671 if ( $this->getId() ) {
00672 $this->_iCntWishListArticles = $this->getBasket( 'wishlist' )->getItemCount();
00673 }
00674 }
00675 return $this->_iCntWishListArticles;
00676 }
00677
00684 public function getActiveCountry()
00685 {
00686 $sDeliveryCountry = '';
00687 if ( $soxAddressId = oxConfig::getParameter( 'deladrid' ) ) {
00688 $oDelAddress = oxNew( 'oxaddress' );
00689 $oDelAddress->load( $soxAddressId );
00690 $sDeliveryCountry = $oDelAddress->oxaddress__oxcountryid->value;
00691 } elseif ( $this->getId() ) {
00692 $sDeliveryCountry = $this->oxuser__oxcountryid->value;
00693 } else {
00694 $oUser = oxNew( 'oxuser' );
00695 if ( $oUser->loadActiveUser() ) {
00696 $sDeliveryCountry = $oUser->oxuser__oxcountryid->value;
00697 }
00698 }
00699
00700 return $sDeliveryCountry;
00701 }
00702
00710 public function createUser()
00711 {
00712 $oDB = oxDb::getDb();
00713 $sShopID = $this->getConfig()->getShopId();
00714
00715
00716 $sSelect = "select oxid from oxuser where oxusername = " . $oDB->quote( $this->oxuser__oxusername->value ) . " and oxpassword = '' ";
00717 if ( !$this->_blMallUsers ) {
00718 $sSelect .= " and oxshopid = '{$sShopID}' ";
00719 }
00720 $sOXID = $oDB->getOne( $sSelect );
00721
00722
00723 if ( isset( $sOXID ) && $sOXID ) {
00724
00725 $this->delete( $sOXID );
00726 } elseif ( $this->_blMallUsers ) {
00727
00728 $sQ = "select oxid from oxuser where oxusername = " . $oDB->quote( $this->oxuser__oxusername->value ) . " and oxusername != '' ";
00729 if ( $oDB->getOne( $sQ ) ) {
00730 $oEx = oxNew( 'oxUserException' );
00731 $oLang = oxLang::getInstance();
00732 $oEx->setMessage( sprintf( $oLang->translateString( 'EXCEPTION_USER_USEREXISTS', $oLang->getTplLanguage() ), $this->oxuser__oxusername->value ) );
00733 throw $oEx;
00734 }
00735 }
00736
00737 $this->oxuser__oxshopid = new oxField( $sShopID, oxField::T_RAW );
00738 if ( ( $blOK = $this->save() ) ) {
00739
00740 $oDB->execute( "delete from oxaddress where oxaddress.oxuserid = " . $oDB->quote( $this->oxuser__oxid->value ) . " " );
00741 $oDB->execute( "update oxuserpayments set oxuserpayments.oxuserid = " . $oDB->quote( $this->oxuser__oxusername->value ) . " where oxuserpayments.oxuserid = " . $oDB->quote( $this->oxuser__oxid->value ) . " " );
00742 } else {
00743 $oEx = oxNew( 'oxUserException' );
00744 $oEx->setMessage( 'EXCEPTION_USER_USERCREATIONFAILED' );
00745 throw $oEx;
00746 }
00747
00748 return $blOK;
00749 }
00750
00758 public function addToGroup( $sGroupID )
00759 {
00760 if ( !$this->inGroup( $sGroupID ) ) {
00761 $oNewGroup = oxNew( 'oxobject2group' );
00762 $oNewGroup->oxobject2group__oxobjectid = new oxField($this->getId(), oxField::T_RAW);
00763 $oNewGroup->oxobject2group__oxgroupsid = new oxField($sGroupID, oxField::T_RAW);
00764 if ( $oNewGroup->save() ) {
00765 $this->_oGroups[$sGroupID] = $oNewGroup;
00766 return true;
00767 }
00768 }
00769 return false;
00770 }
00771
00779 public function removeFromGroup( $sGroupID = null )
00780 {
00781 if ( $sGroupID != null && $this->inGroup( $sGroupID ) ) {
00782 $oGroups = oxNew( 'oxlist' );
00783 $oGroups->init( 'oxobject2group' );
00784 $sSelect = 'select * from oxobject2group where oxobject2group.oxobjectid = "'.$this->getId().'" and oxobject2group.oxgroupsid = "'.$sGroupID.'" ';
00785 $oGroups->selectString( $sSelect );
00786 foreach ( $oGroups as $oRemgroup ) {
00787 if ( $oRemgroup->delete() ) {
00788 unset( $this->_oGroups[$oRemgroup->oxobject2group__oxgroupsid->value] );
00789 }
00790 }
00791 }
00792 }
00793
00802 public function onOrderExecute( $oBasket, $iSuccess )
00803 {
00804
00805 if ( is_numeric( $iSuccess ) && $iSuccess != 2 && $iSuccess <= 3 ) {
00806
00807 if ( !$this->oxuser__oxdisableautogrp->value ) {
00808
00809 $myConfig = $this->getConfig();
00810 $dMidlleCustPrice = (float) $myConfig->getConfigParam( 'sMidlleCustPrice' );
00811 $dLargeCustPrice = (float) $myConfig->getConfigParam( 'sLargeCustPrice' );
00812
00813 $this->addToGroup( 'oxidcustomer' );
00814 $dBasketPrice = $oBasket->getPrice()->getBruttoPrice();
00815 if ( $dBasketPrice < $dMidlleCustPrice ) {
00816 $this->addToGroup( 'oxidsmallcust' );
00817 }
00818 if ( $dBasketPrice >= $dMidlleCustPrice && $dBasketPrice < $dLargeCustPrice ) {
00819 $this->addToGroup( 'oxidmiddlecust' );
00820 }
00821 if ( $dBasketPrice >= $dLargeCustPrice ) {
00822 $this->addToGroup( 'oxidgoodcust' );
00823 }
00824 }
00825
00826 if ( $this->inGroup( 'oxidnotyetordered' ) ) {
00827 $this->removeFromGroup( 'oxidnotyetordered' );
00828 }
00829 }
00830 }
00831
00839 public function getBasket( $sName )
00840 {
00841 if ( !isset( $this->_aBaskets[$sName] ) ) {
00842 $oBasket = oxNew( 'oxuserbasket' );
00843 $aWhere = array( 'oxuserbaskets.oxuserid' => $this->getId(), 'oxuserbaskets.oxtitle' => $sName );
00844
00845
00846 if ( !$oBasket->assignRecord( $oBasket->buildSelectString( $aWhere ) ) ) {
00847 $oBasket->oxuserbaskets__oxtitle = new oxField($sName);
00848 $oBasket->oxuserbaskets__oxuserid = new oxField($this->getId());
00849
00850
00851 $oBasket->setIsNewBasket();
00852 }
00853
00854 $this->_aBaskets[$sName] = $oBasket;
00855 }
00856
00857 return $this->_aBaskets[$sName];
00858 }
00859
00868 public function convertBirthday( $aData )
00869 {
00870
00871
00872 $iYear = isset($aData['year'])?((int) $aData['year']):false;
00873 $iMonth = isset($aData['month'])?((int) $aData['month']):false;
00874 $iDay = isset($aData['day'])?((int) $aData['day']):false;
00875
00876
00877 if ( !$iYear && !$iMonth && !$iDay )
00878 return "";
00879
00880
00881 if ( !$iYear || $iYear < 1000 || $iYear > 9999)
00882 $iYear = date('Y');
00883
00884
00885 if ( !$iMonth || $iMonth < 1 || $iMonth > 12)
00886 $iMonth = 1;
00887
00888
00889 $iMaxDays = 31;
00890 switch( $iMonth) {
00891 case 2 :
00892 if ($iMaxDays > 28)
00893 $iMaxDays = ($iYear % 4 == 0 && ($iYear % 100 != 0 || $iYear % 400 == 0)) ? 29 : 28;
00894 break;
00895 case 4 :
00896 case 6 :
00897 case 9 :
00898 case 11 :
00899 $iMaxDays = min(30, $iMaxDays);
00900 break;
00901 }
00902
00903
00904 if ( !$iDay || $iDay < 1 || $iDay > $iMaxDays) {
00905 $iDay = 1;
00906 }
00907
00908
00909 return sprintf("%04d-%02d-%02d", $iYear, $iMonth, $iDay);
00910 }
00911
00918 public function getBoni()
00919 {
00920 return 1000;
00921 }
00922
00935 public function addDynGroup( $sDynGoup, $aDeniedDynGroups )
00936 {
00937
00938 $sDynGoup = strtolower( trim( $sDynGoup ) );
00939
00940
00941 $aDisabledDynGroups = array_merge( array( 'oxidadmin' ), (array) $aDeniedDynGroups );
00942
00943
00944 $blAdd = false;
00945
00946
00947 if ( $this->oxuser__oxdisableautogrp->value || !$sDynGoup ) {
00948 $blAdd = false;
00949 } elseif ( in_array( $sDynGoup, $aDisabledDynGroups ) ) {
00950
00951 $blAdd = false;
00952 } elseif ( $this->addToGroup( $sDynGoup ) ) {
00953 $blAdd = true;
00954 }
00955
00956
00957 oxSession::deleteVar( 'dgr' );
00958
00959 return $blAdd;
00960 }
00961
00977 public function checkValues( $sLogin, $sPassword, $sPassword2, $aInvAddress, $aDelAddress )
00978 {
00979
00980 $sLogin = $this->_checkLogin( $sLogin, $aInvAddress );
00981
00982
00983 $this->_checkEmail( $sLogin );
00984
00985
00986 $this->_checkPassword( $sPassword, $sPassword2, ((int) oxConfig::getParameter( 'option' ) == 3) );
00987
00988
00989 $this->_checkRequiredFields( $aInvAddress, $aDelAddress );
00990
00991
00992 $this->_checkCountries( $aInvAddress, $aDelAddress );
00993
00994
00995 $this->_checkVatId( $aInvAddress );
00996 }
00997
01006 public function setNewsSubscription( $blSubscribe, $blSendOptIn )
01007 {
01008
01009 $blSuccess = false;
01010 $myConfig = $this->getConfig();
01011 $mySession = $this->getSession();
01012
01013
01014 $oNewsSubscription = $this->getNewsSubscription();
01015 if ( $blSubscribe && $oNewsSubscription->getOptInStatus() != 1 ) {
01016 if ( !$blSendOptIn ) {
01017
01018
01019 $this->addToGroup( 'oxidnewsletter' );
01020
01021 $oNewsSubscription->setOptInStatus( 1 );
01022 $blSuccess = true;
01023 } else {
01024
01025 $oNewsSubscription->setOptInStatus( 2 );
01026
01027
01028 if ( !$mySession->getVar( "blDBOptInMailAlreadyDone" ) ) {
01029
01030
01031 $oEmail = oxNew( 'oxemail' );
01032 $blSuccess = $oEmail->sendNewsletterDBOptInMail( $this );
01033
01034 if ( $blSuccess ) {
01035
01036 $mySession->setVar( "blDBOptInMailAlreadyDone", true );
01037 }
01038 } else {
01039
01040 $blSuccess = true;
01041 }
01042 }
01043 } elseif ( !$blSubscribe ) {
01044
01045 $this->removeFromGroup( 'oxidnewsletter' );
01046 $oNewsSubscription->setOptInStatus( 0 );
01047 $blSuccess = true;
01048 }
01049
01050 return $blSuccess;
01051 }
01052
01070 public function changeUserData( $sUser, $sPassword, $sPassword2, $aInvAddress, $aDelAddress )
01071 {
01072
01073
01074 $this->checkValues( $sUser, $sPassword, $sPassword2, $aInvAddress, $aDelAddress );
01075
01076
01077 $this->assign( $aInvAddress );
01078
01079
01080
01081 $this->_assignAddress( $aDelAddress );
01082
01083
01084 if ( $this->save() ) {
01085
01086
01087 $sCountryId = isset( $aInvAddress['oxuser__oxcountryid'] )?$aInvAddress['oxuser__oxcountryid']:'';
01088 $this->_setAutoGroups( $sCountryId );
01089 }
01090 }
01091
01100 public function addUserAddress( $oUser )
01101 {
01102 if ( $this->_hasUserAddress( $oUser->getId() ) ) {
01103 return false;
01104 }
01105
01106 $oAddress = oxNew( 'oxaddress' );
01107 $oAddress->oxaddress__oxuserid = new oxField($this->getId(), oxField::T_RAW);
01108 $oAddress->oxaddress__oxaddressuserid = new oxField($oUser->getId(), oxField::T_RAW);
01109 $oAddress->oxaddress__oxfname = new oxField($oUser->oxuser__oxfname->value, oxField::T_RAW);
01110 $oAddress->oxaddress__oxlname = new oxField($oUser->oxuser__oxlname->value, oxField::T_RAW);
01111 $oAddress->oxaddress__oxstreet = new oxField($oUser->oxuser__oxstreet->value, oxField::T_RAW);
01112 $oAddress->oxaddress__oxstreetnr = new oxField($oUser->oxuser__oxstreetnr->value, oxField::T_RAW);
01113 $oAddress->oxaddress__oxcity = new oxField($oUser->oxuser__oxcity->value, oxField::T_RAW);
01114 $oAddress->oxaddress__oxzip = new oxField($oUser->oxuser__oxzip->value, oxField::T_RAW);
01115 $oAddress->oxaddress__oxcountry = new oxField($oUser->oxuser__oxcountry->value, oxField::T_RAW);
01116 $oAddress->oxaddress__oxcountryid = new oxField($oUser->oxuser__oxcountryid->value, oxField::T_RAW);
01117 $oAddress->oxaddress__oxcompany = new oxField($oUser->oxuser__oxcompany->value, oxField::T_RAW);
01118
01119
01120 if ( $oAddress->save() ) {
01121
01122 $this->_aAddresses = null;
01123 return $oAddress->getId();
01124 }
01125 }
01126
01134 protected function _assignAddress( $aDelAddress )
01135 {
01136 if (isset($aDelAddress) && count($aDelAddress)) {
01137 $sAddressId = oxConfig::getParameter( 'oxaddressid' );
01138 $sMyAddressId = ( $sAddressId === null || $sAddressId == -1 || $sAddressId == -2 ) ? null : $sAddressId;
01139 $aDelAddress['oxaddress__oxid'] = $sMyAddressId;
01140 $oAddress = oxNew( 'oxaddress' );
01141 $oAddress->assign( $aDelAddress );
01142 $oAddress->oxaddress__oxuserid = new oxField( $this->getId(), oxField::T_RAW );
01143 $oAddress->oxaddress__oxcountry = $this->getUserCountry( $oAddress->oxaddress__oxcountryid->value );
01144 $oAddress->save();
01145
01146
01147 $this->_aAddresses = null;
01148
01149
01150 oxSession::setVar( 'deladrid', $oAddress->getId() );
01151 } else {
01152
01153 oxSession::setVar( 'deladrid', null );
01154 }
01155 }
01156
01169 public function login( $sUser, $sPassword, $blCookie = false)
01170 {
01171 if ( $this->isAdmin() && !count( oxUtilsServer::getInstance()->getOxCookie() ) ) {
01172 $oEx = oxNew( 'oxCookieException' );
01173 $oEx->setMessage( 'EXCEPTION_COOKIE_NOCOOKIE' );
01174 throw $oEx;
01175 }
01176
01177 $myConfig = $this->getConfig();
01178 if ( $sPassword ) {
01179
01180 $sShopID = $myConfig->getShopId();
01181 $oDb = oxDb::getDb();
01182
01183 $sUserSelect = is_numeric( $sUser ) ? "oxuser.oxcustnr = {$sUser} " : "oxuser.oxusername = " . $oDb->quote( $sUser );
01184 $sPassSelect = " oxuser.oxpassword = MD5( CONCAT( ".$oDb->quote( $sPassword ).", UNHEX( oxuser.oxpasssalt ) ) ) ";
01185 $sShopSelect = "";
01186
01187
01188
01189 if ( $this->isAdmin() ) {
01190 $sShopSelect = " and ( oxrights != 'user' ) ";
01191 }
01192
01193 $sWhat = "oxid";
01194
01195 $sSelect = "select $sWhat from oxuser where oxuser.oxactive = 1 and {$sPassSelect} and {$sUserSelect} {$sShopSelect} ";
01196 if ( $myConfig->isDemoShop() && $this->isAdmin() ) {
01197 if ( $sPassword == "admin" && $sUser == "admin" ) {
01198 $sSelect = "select $sWhat from oxuser where oxrights = 'malladmin' {$sShopSelect} ";
01199 } else {
01200 $oEx = oxNew( 'oxUserException' );
01201 $oEx->setMessage( 'EXCEPTION_USER_NOVALIDLOGIN' );
01202 throw $oEx;
01203 }
01204 }
01205
01206
01207 $aData = $oDb->getAll( $sSelect );
01208 $sOXID = @$aData[0][0];
01209 if ( isset( $sOXID ) && $sOXID && !@$aData[0][1] ) {
01210
01211 if ( !$this->load( $sOXID ) ) {
01212 $oEx = oxNew( 'oxUserException' );
01213 $oEx->setMessage( 'EXCEPTION_USER_NOVALIDLOGIN' );
01214 throw $oEx;
01215 }
01216 }
01217 }
01218
01219
01220
01221 if ( $this->oxuser__oxid->value ) {
01222
01223 if ( $this->isAdmin() ) {
01224 oxSession::setVar( 'auth', $this->oxuser__oxid->value );
01225 } else {
01226 oxSession::setVar( 'usr', $this->oxuser__oxid->value );
01227 }
01228
01229
01230 if ( $blCookie ) {
01231 oxUtilsServer::getInstance()->setUserCookie( $this->oxuser__oxusername->value, $this->oxuser__oxpassword->value, $myConfig->getShopId() );
01232 }
01233 return true;
01234 } else {
01235 $oEx = oxNew( 'oxUserException' );
01236 $oEx->setMessage( 'EXCEPTION_USER_NOVALIDLOGIN' );
01237 throw $oEx;
01238 }
01239 }
01240
01251 public function openIdLogin( $sUser )
01252 {
01253 $myConfig = $this->getConfig();
01254 $sShopID = $myConfig->getShopId();
01255 $oDb = oxDb::getDb();
01256
01257 $sUserSelect = "oxuser.oxusername = " . $oDb->quote( $sUser );
01258 $sShopSelect = "";
01259
01260
01261 $sSelect = "select oxid from oxuser where oxuser.oxactive = 1 and {$sUserSelect} {$sShopSelect} ";
01262
01263
01264 $aData = $oDb->getAll( $sSelect );
01265 $sOXID = @$aData[0][0];
01266 if ( isset( $sOXID ) && $sOXID ) {
01267
01268 if ( !$this->load( $sOXID ) ) {
01269 $oEx = oxNew( 'oxUserException' );
01270 $oEx->setMessage( 'EXCEPTION_USER_NOVALIDLOGIN' );
01271 throw $oEx;
01272 }
01273 }
01274
01275
01276 if ( $this->oxuser__oxid->value ) {
01277
01278 oxSession::setVar( 'usr', $this->oxuser__oxid->value );
01279 return true;
01280 } else {
01281 $oEx = oxNew( 'oxUserException' );
01282 $oEx->setMessage( 'EXCEPTION_USER_NOVALIDLOGIN' );
01283 throw $oEx;
01284 }
01285 }
01286
01292 public function logout()
01293 {
01294
01295 oxSession::deleteVar( 'usr' );
01296 oxSession::deleteVar( 'auth' );
01297 oxSession::deleteVar( 'dgr' );
01298 oxSession::deleteVar( 'dynvalue' );
01299 oxSession::deleteVar( 'paymentid' );
01300
01301
01302
01303 oxUtilsServer::getInstance()->deleteUserCookie( $this->getConfig()->getShopID() );
01304
01305
01306 $this->setUser( null );
01307
01308 return true;
01309 }
01310
01317 public function loadAdminUser()
01318 {
01319 return $this->loadActiveUser( true );
01320 }
01321
01330 public function loadActiveUser( $blForceAdmin = false )
01331 {
01332 $myConfig = $this->getConfig();
01333
01334 $blAdmin = $myConfig->isAdmin() || $blForceAdmin;
01335 $oDB = oxDb::getDb();
01336
01337
01338 $sUserID = $blAdmin ? oxSession::getVar( 'auth' ) : oxSession::getVar( 'usr' );
01339 $blFoundInCookie = false;
01340
01341
01342 if ( !$sUserID && !$blAdmin ) {
01343 $sShopID = $myConfig->getShopId();
01344 if ( ( $sSet = oxUtilsServer::getInstance()->getUserCookie( $sShopID ) ) ) {
01345 $aData = explode( '@@@', $sSet );
01346 $sUser = $aData[0];
01347 $sPWD = @$aData[1];
01348
01349 $sSelect = 'select oxid, oxpassword from oxuser where oxuser.oxpassword != "" and oxuser.oxactive = 1 and oxuser.oxusername = '.$oDB->quote($sUser);
01350
01351
01352 $oDB = oxDb::getDb();
01353 $rs = $oDB->execute( $sSelect );
01354 if ( $rs != false && $rs->recordCount() > 0 ) {
01355 while (!$rs->EOF) {
01356 $sTest = crypt( $rs->fields[1], 'ox' );
01357 if ( $sTest == $sPWD ) {
01358
01359 $sUserID = $rs->fields[0];
01360 $blFoundInCookie = true;
01361 break;
01362 }
01363 $rs->moveNext();
01364 }
01365 }
01366 }
01367 }
01368
01369
01370
01371 if ( $myConfig->getConfigParam( "bl_showFbConnect") && !$sUserID && !$blAdmin ) {
01372 $oFb = oxFb::getInstance();
01373 if ( $oFb->isConnected() && $oFb->getUser() ) {
01374 $sUserSelect = "oxuser.oxfbid = " . $oDB->quote( $oFb->getUser() );
01375 $sShopSelect = "";
01376
01377
01378 $sSelect = "select oxid from oxuser where oxuser.oxactive = 1 and {$sUserSelect} {$sShopSelect} ";
01379 $sUserID = $oDB->getOne( $sSelect );
01380 }
01381 }
01382
01383
01384 if ( $sUserID ) {
01385 if ( $this->load( $sUserID ) ) {
01386
01387 if ($blAdmin) {
01388 oxSession::setVar( 'auth', $sUserID );
01389 } else {
01390 oxSession::setVar( 'usr', $sUserID );
01391 }
01392
01393
01394 $this->_blLoadedFromCookie = $blFoundInCookie;
01395 return true;
01396 }
01397 } else {
01398
01399 oxSession::deleteVar( 'usr' );
01400 oxSession::deleteVar( 'auth' );
01401
01402 return false;
01403 }
01404 }
01405
01418 protected function _ldapLogin( $sUser, $sPassword, $sShopID, $sShopSelect)
01419 {
01420 include "oxldap.php";
01421 $myConfig = $this->getConfig();
01422 $oDb = oxDb::getDb();
01423
01424 $aLDAPParams = $myConfig->getConfigParam( 'aLDAPParams' );
01425 $oLDAP = new oxLDAP( $aLDAPParams['HOST'], $aLDAPParams['PORT'] );
01426
01427 $sLDAPKey = $oDb->getOne("select oxldapkey from oxuser where oxuser.oxactive = 1 and oxuser.oxusername = ".$oDb->quote($sUser)." $sShopSelect");
01428 if ( isset( $sLDAPKey) && $sLDAPKey) {
01429 $sUser = $sLDAPKey;
01430 }
01431
01432
01433 $oLDAP->login( $sUser, $sPassword, $aLDAPParams['USERQUERY'], $aLDAPParams['BASEDN'], $aLDAPParams['FILTER']);
01434
01435 $aData = $oLDAP->mapData($aLDAPParams['DATAMAP']);
01436 if ( isset( $aData['OXUSERNAME']) && $aData['OXUSERNAME']) {
01437
01438
01439
01440 $sSelect = "select oxid from oxuser where oxuser.oxusername = ".$oDb->quote($aData['OXUSERNAME'])." $sShopSelect";
01441 $sOXID = $oDb->getOne( $sSelect);
01442
01443 if ( !isset( $sOXID) || !$sOXID) {
01444
01445
01446 $this->setId();
01447
01448
01449 foreach ( $aData as $fldname => $value) {
01450 $sField = "oxuser__".strtolower( $fldname);
01451 $this->$sField->setValue($aData[$fldname]);
01452 }
01453
01454 $this->oxuser__oxactive->setValue(1);
01455 $this->oxuser__oxshopid->setValue($sShopID);
01456 $this->oxuser__oxldapkey->setValue($sUser);
01457 $this->oxuser__oxrights->setValue("user");
01458 $this->setPassword( "ldap user" );
01459
01460 $this->save();
01461 } else {
01462
01463 $this->load( $sOXID);
01464 }
01465
01466 } else {
01467 $oEx = oxNew( 'oxUserException' );
01468 $oEx->setMessage('EXCEPTION_USER_NOVALUES');
01469 throw $oEx;
01470 }
01471 }
01472
01479 protected function _getUserRights()
01480 {
01481
01482 if ( !$this->oxuser__oxrights->value )
01483 return 'user';
01484
01485 $oDB = oxDb::getDb();
01486 $myConfig = $this->getConfig();
01487 $sAuthRights = null;
01488
01489
01490 $sAuthUserID = $this->isAdmin()?oxSession::getVar( 'auth' ):null;
01491 $sAuthUserID = $sAuthUserID?$sAuthUserID:oxSession::getVar( 'usr' );
01492 if ( $sAuthUserID ) {
01493 $sAuthRights = $oDB->getOne( 'select oxrights from '.$this->getViewName().' where oxid='.$oDB->quote( $sAuthUserID ) );
01494 }
01495
01496
01497 $aRights = array();
01498
01499
01500 if ( $sCurrRights = $oDB->getOne( 'select oxrights from '.$this->getViewName().' where oxid="'.$this->getId().'"' ) ) {
01501 $aRights[] = $sCurrRights;
01502 }
01503 $aRights[] = 'user';
01504
01505 if ( !$sAuthRights || !( $sAuthRights == 'malladmin' || $sAuthRights == $myConfig->getShopId() ) ) {
01506 return current( $aRights );
01507 } elseif ( $sAuthRights == $myConfig->getShopId() ) {
01508 $aRights[] = $sAuthRights;
01509 if ( !in_array( $this->oxuser__oxrights->value, $aRights ) ) {
01510 return current( $aRights );
01511 }
01512 }
01513
01514
01515 return $this->oxuser__oxrights->value;
01516 }
01517
01527 protected function _setRecordNumber( $sMaxField, $aWhere = null ,$iMaxTryCnt = 5 )
01528 {
01529
01530
01531
01532
01533
01534
01535 return parent::_setRecordNumber( $sMaxField, $aWhere, $iMaxTryCnt );
01536 }
01537
01543 protected function _insert()
01544 {
01545
01546
01547 $this->oxuser__oxcreate = new oxField(date( 'Y-m-d H:i:s' ), oxField::T_RAW);
01548
01549 if ( !isset( $this->oxuser__oxboni->value ) ) {
01550 $this->oxuser__oxboni = new oxField($this->getBoni(), oxField::T_RAW);
01551 }
01552
01553 return parent::_insert();
01554 }
01555
01561 protected function _update()
01562 {
01563
01564 if (!$this->oxuser__oxpassword->value && $this->oxuser__oxregister->value < 1) {
01565 $this->_aSkipSaveFields[] = 'oxboni';
01566 }
01567
01568
01569 $this->_aSkipSaveFields[] = 'oxcreate';
01570 if ( !$this->isAdmin() ) {
01571 $this->_aSkipSaveFields[] = 'oxcustnr';
01572 $this->_aSkipSaveFields[] = 'oxrights';
01573 }
01574
01575
01576 if ( ( $blUpdate = parent::_update() ) ) {
01577 $this->getNewsSubscription()->updateSubscription( $this );
01578 }
01579
01580 return $blUpdate;
01581 }
01582
01598 protected function _checkLogin( $sLogin, $aInvAddress )
01599 {
01600 $myConfig = $this->getConfig();
01601
01602 $sLogin = ( isset( $aInvAddress['oxuser__oxusername'] ) )?$aInvAddress['oxuser__oxusername']:$sLogin;
01603
01604
01605
01606 if ( $this->oxuser__oxpassword->value && $sLogin != $this->oxuser__oxusername->value ) {
01607
01608
01609 $sNewPass = (isset( $aInvAddress['oxuser__oxpassword']) && $aInvAddress['oxuser__oxpassword'] )?$aInvAddress['oxuser__oxpassword']:oxConfig::getParameter( 'user_password' );
01610 if ( !$sNewPass ) {
01611
01612
01613 $oEx = oxNew( 'oxInputException' );
01614 $oEx->setMessage('EXCEPTION_INPUT_NOTALLFIELDS');
01615 throw $oEx;
01616 } else {
01617
01618
01619 if ( !$this->isSamePassword( $sNewPass ) ) {
01620 $oEx = oxNew( 'oxUserException' );
01621 $oEx->setMessage('EXCEPTION_USER_PWDDONTMATCH');
01622 throw $oEx;
01623 }
01624 }
01625 }
01626
01627 if ( $this->checkIfEmailExists( $sLogin ) ) {
01628
01629 $oEx = oxNew( 'oxUserException' );
01630 $oLang = oxLang::getInstance();
01631 $oEx->setMessage( sprintf( $oLang->translateString( 'EXCEPTION_USER_USEREXISTS', $oLang->getTplLanguage() ), $sLogin ) );
01632 throw $oEx;
01633 }
01634
01635 return $sLogin;
01636 }
01637
01645 public function checkIfEmailExists( $sEmail )
01646 {
01647 $myConfig = $this->getConfig();
01648 $oDB = oxDb::getDb();
01649 $iShopId = $myConfig->getShopId();
01650 $blExists = false;
01651
01652 $sQ = 'select oxshopid, oxrights, oxpassword from oxuser where oxusername = '. $oDB->quote( $sEmail );
01653 if ( ( $sOxid = $this->getId() ) ) {
01654 $sQ .= " and oxid <> '$sOxid' ";
01655 }
01656
01657 $oRs = $oDB->execute( $sQ );
01658 if ( $oRs != false && $oRs->recordCount() > 0 ) {
01659
01660 if ( $this->_blMallUsers ) {
01661
01662 $blExists = true;
01663 if ( $oRs->fields[1] == 'user' && !$oRs->fields[2] ) {
01664
01665
01666 $blExists = false;
01667 }
01668 } else {
01669
01670 $blExists = false;
01671 while ( !$oRs->EOF ) {
01672 if ( $oRs->fields[1] != 'user' ) {
01673
01674
01675 $blExists = true;
01676 break;
01677 } elseif ( $oRs->fields[0] == $iShopId && $oRs->fields[2] ) {
01678
01679
01680 $blExists = true;
01681 break;
01682 }
01683
01684 $oRs->moveNext();
01685 }
01686 }
01687 }
01688 return $blExists;
01689 }
01690
01698 public function getUserRecommLists( $sOXID = null )
01699 {
01700 if ( !$sOXID )
01701 $sOXID = $this->getId();
01702
01703
01704 $iActPage = (int) oxConfig::getParameter( 'pgNr' );
01705 $iActPage = ($iActPage < 0) ? 0 : $iActPage;
01706
01707
01708 $iNrofCatArticles = $this->getConfig()->getConfigParam( 'iNrofCatArticles' );
01709 $iNrofCatArticles = $iNrofCatArticles ? $iNrofCatArticles : 10;
01710
01711
01712 $oRecommList = oxNew( 'oxlist' );
01713 $oRecommList->init( 'oxrecommlist' );
01714 $oRecommList->setSqlLimit( $iNrofCatArticles * $iActPage, $iNrofCatArticles );
01715 $iShopId = $this->getConfig()->getShopId();
01716 $sSelect = 'select * from oxrecommlists where oxuserid ='. oxDb::getDb()->quote( $sOXID ) . ' and oxshopid ="'. $iShopId .'"';
01717 $oRecommList->selectString( $sSelect );
01718
01719 return $oRecommList;
01720 }
01721
01729 public function getRecommListsCount( $sOx = null )
01730 {
01731 if ( !$sOx ) {
01732 $sOx = $this->getId();
01733 }
01734
01735 if ( $this->_iCntRecommLists === null || $sOx ) {
01736 $oDb = oxDb::getDb();
01737 $this->_iCntRecommLists = 0;
01738 $iShopId = $this->getConfig()->getShopId();
01739 $sSelect = 'select count(oxid) from oxrecommlists where oxuserid = ' . $oDb->quote( $sOx ) . ' and oxshopid ="'. $iShopId .'"';
01740 $this->_iCntRecommLists = $oDb->getOne( $sSelect );
01741 }
01742 return $this->_iCntRecommLists;
01743 }
01744
01753 protected function _checkEmail( $sEmail )
01754 {
01755
01756 if ( !$sEmail ) {
01757 $oEx = oxNew( 'oxInputException' );
01758 $oEx->setMessage('EXCEPTION_INPUT_NOTALLFIELDS');
01759 throw $oEx;
01760 }
01761
01762
01763 if ( !oxUtils::getInstance()->isValidEmail( $sEmail ) ) {
01764 $oEx = oxNew( 'oxInputException' );
01765 $oEx->setMessage( 'EXCEPTION_INPUT_NOVALIDEMAIL' );
01766 throw $oEx;
01767 }
01768 }
01769
01784 protected function _checkPassword( $sNewPass, $sConfPass, $blCheckLenght = false )
01785 {
01786 $this->checkPassword( $sNewPass, $sConfPass, $blCheckLenght );
01787 }
01788
01801 public function checkPassword( $sNewPass, $sConfPass, $blCheckLenght = false )
01802 {
01803
01804 if ( $blCheckLenght && getStr()->strlen( $sNewPass ) == 0 ) {
01805 $oEx = oxNew( 'oxInputException' );
01806 $oEx->setMessage('EXCEPTION_INPUT_EMPTYPASS');
01807 throw $oEx;
01808 }
01809
01810
01811 if ( $blCheckLenght && getStr()->strlen( $sNewPass ) < 6 ) {
01812 $oEx = oxNew( 'oxInputException' );
01813 $oEx->setMessage('EXCEPTION_INPUT_PASSTOOSHORT');
01814 throw $oEx;
01815 }
01816
01817
01818 if ( $sNewPass != $sConfPass ) {
01819 $oEx = oxNew( 'oxUserException' );
01820 $oEx->setMessage('EXCEPTION_USER_PWDDONTMATCH');
01821 throw $oEx;
01822 }
01823 }
01824
01835 protected function _checkCountries( $aInvAddress, $aDelAddress )
01836 {
01837 $sBillCtry = isset( $aInvAddress['oxuser__oxcountryid'] ) ? $aInvAddress['oxuser__oxcountryid'] : null;
01838 $sDelCtry = isset( $aDelAddress['oxaddress__oxcountryid'] ) ? $aDelAddress['oxaddress__oxcountryid'] : null;
01839
01840 if ( $sBillCtry || $sDelCtry ) {
01841 $oDb = oxDb::getDb();
01842
01843 if ( ( $sBillCtry == $sDelCtry ) || ( !$sBillCtry && $sDelCtry ) || ( $sBillCtry && !$sDelCtry ) ) {
01844 $sBillCtry = $sBillCtry ? $sBillCtry : $sDelCtry;
01845 $sQ = "select oxactive from oxcountry where oxid = ".$oDb->quote( $sBillCtry )." ";
01846 } else {
01847 $sQ = "select ( select oxactive from oxcountry where oxid = ".$oDb->quote( $sBillCtry )." ) and
01848 ( select oxactive from oxcountry where oxid = ".$oDb->quote( $sDelCtry )." ) ";
01849 }
01850
01851 if ( !$oDb->getOne( $sQ ) ) {
01852 $oEx = oxNew( 'oxUserException' );
01853 $oEx->setMessage('EXCEPTION_INPUT_NOTALLFIELDS' );
01854 throw $oEx;
01855 }
01856 }
01857 }
01858
01870 protected function _checkRequiredFields( $aInvAddress, $aDelAddress )
01871 {
01872
01873 $aMustFields = array( 'oxuser__oxfname',
01874 'oxuser__oxlname',
01875 'oxuser__oxstreetnr',
01876 'oxuser__oxstreet',
01877 'oxuser__oxzip',
01878 'oxuser__oxcity' );
01879
01880
01881 $aMustFillFields = $this->getConfig()->getConfigParam( 'aMustFillFields' );
01882 if ( is_array( $aMustFillFields ) ) {
01883 $aMustFields = $aMustFillFields;
01884 }
01885
01886
01887 $aInvAddress = is_array( $aInvAddress )?$aInvAddress:array();
01888 $aDelAddress = is_array( $aDelAddress )?$aDelAddress:array();
01889
01890
01891 $aFields = array_merge( $aInvAddress, $aDelAddress );
01892
01893
01894
01895 $blCheckDel = false;
01896 if ( count( $aDelAddress ) ) {
01897 $blCheckDel = true;
01898 }
01899
01900
01901 foreach ( $aMustFields as $sMustField ) {
01902
01903
01904 if ( !$blCheckDel && strpos( $sMustField, 'oxaddress__' ) === 0 ) {
01905 continue;
01906 }
01907
01908 if ( isset( $aFields[$sMustField] ) && is_array( $aFields[$sMustField] ) ) {
01909 $this->_checkRequiredArrayFields( $sMustField, $aFields[$sMustField] );
01910 } elseif ( !isset( $aFields[$sMustField] ) || !trim( $aFields[$sMustField] ) ) {
01911 $oEx = oxNew( 'oxInputException' );
01912 $oEx->setMessage('EXCEPTION_INPUT_NOTALLFIELDS');
01913 throw $oEx;
01914 }
01915 }
01916 }
01917
01928 protected function _checkRequiredArrayFields( $sFieldName, $aFieldValues )
01929 {
01930 foreach ( $aFieldValues as $sValue ) {
01931 if ( !trim( $sValue ) ) {
01932 $oEx = oxNew( 'oxInputException' );
01933 $oEx->setMessage('EXCEPTION_INPUT_NOTALLFIELDS');
01934 throw $oEx;
01935 }
01936 }
01937 }
01938
01949 protected function _checkVatId( $aInvAddress )
01950 {
01951 if ( $aInvAddress['oxuser__oxustid'] ) {
01952
01953 if (!($sCountryId = $aInvAddress['oxuser__oxcountryid'])) {
01954
01955 return;
01956 }
01957 $oCountry = oxNew('oxcountry');
01958 if (!$oCountry->load($sCountryId)) {
01959 throw new oxObjectException();
01960 }
01961 if ($oCountry->isForeignCountry() && $oCountry->isInEU()) {
01962 if (strncmp($aInvAddress['oxuser__oxustid'], $oCountry->oxcountry__oxisoalpha2->value, 2)) {
01963 $oEx = oxNew( 'oxInputException' );
01964 $oEx->setMessage( 'VAT_MESSAGE_ID_NOT_VALID' );
01965 throw $oEx;
01966 }
01967 }
01968 }
01969 }
01970
01979 protected function _setAutoGroups( $sCountryId )
01980 {
01981
01982 $blForeigner = true;
01983 $blForeignGroupExists = false;
01984 $blInlandGroupExists = false;
01985
01986 $aHomeCountry = $this->getConfig()->getConfigParam( 'aHomeCountry' );
01987
01988 if ( is_array($aHomeCountry)) {
01989 if (in_array($sCountryId, $aHomeCountry)) {
01990 $blForeigner = false;
01991 }
01992 } elseif ($sCountryId == $aHomeCountry) {
01993 $blForeigner = false;
01994 }
01995
01996 if ( $this->inGroup( 'oxidforeigncustomer' ) ) {
01997 $blForeignGroupExists = true;
01998 if ( !$blForeigner ) {
01999 $this->removeFromGroup( 'oxidforeigncustomer' );
02000 }
02001 }
02002
02003 if ( $this->inGroup( 'oxidnewcustomer' ) ) {
02004 $blInlandGroupExists = true;
02005 if ( $blForeigner ) {
02006 $this->removeFromGroup( 'oxidnewcustomer' );
02007 }
02008 }
02009
02010 if ( !$this->oxuser__oxdisableautogrp->value ) {
02011 if ( !$blForeignGroupExists && $blForeigner ) {
02012 $this->addToGroup( 'oxidforeigncustomer' );
02013 }
02014 if ( !$blInlandGroupExists && !$blForeigner ) {
02015 $this->addToGroup( 'oxidnewcustomer' );
02016 }
02017 }
02018 }
02019
02027 protected function _hasUserAddress( $sUserId )
02028 {
02029 $oAddresses = $this->getUserAddresses();
02030 if ( $oAddresses && count($oAddresses)>0 ) {
02031 $oAddresses->rewind() ;
02032 foreach ($oAddresses as $key => $oAddress) {
02033 if ( $oAddress->oxaddress__oxaddressuserid->value == $sUserId ) {
02034 return true;
02035 }
02036 }
02037 }
02038 return false;
02039 }
02040
02053 protected function _setUserCookie( $sUser, $sPassword, $sShopId = null, $iTimeout = 31536000 )
02054 {
02055 oxUtilsServer::getInstance()->setUserCookie( $sUser, $sPassword, $sShopId, $iTimeout );
02056 }
02057
02067 protected function _deleteUserCookie( $sShopId = null )
02068 {
02069 oxUtilsServer::getInstance()->deleteUserCookie( $sShopId );
02070 }
02071
02081 protected static function _getUserCookie( $sShopId = null )
02082 {
02083 return oxUtilsServer::getInstance()->getUserCookie( $sShopId );
02084 }
02085
02086
02095 public function loadUserByUpdateId( $sUid )
02096 {
02097 $oDb = oxDb::getDb();
02098 $sQ = "select oxid from ".$this->getViewName()." where oxupdateexp >= ".time()." and MD5( CONCAT( oxid, oxshopid, oxupdatekey ) ) = ".$oDb->quote( $sUid );
02099 if ( $sUserId = $oDb->getOne( $sQ ) ) {
02100 return $this->load( $sUserId );
02101 }
02102 }
02103
02111 public function setUpdateKey( $blReset = false )
02112 {
02113 $sUpKey = $blReset ? '' : oxUtilsObject::getInstance()->generateUId();
02114 $iUpTime = $blReset ? 0 : oxUtilsDate::getInstance()->getTime() + $this->getUpdateLinkTerm();
02115
02116
02117 $this->oxuser__oxupdatekey = new oxField( $sUpKey, oxField::T_RAW );
02118
02119
02120 $this->oxuser__oxupdateexp = new oxField( $iUpTime, oxField::T_RAW );
02121
02122
02123 $this->save();
02124 }
02125
02131 public function getUpdateLinkTerm()
02132 {
02133 return 3600 * 6;
02134 }
02135
02143 public function isExpiredUpdateId( $sKey )
02144 {
02145 $oDb = oxDb::getDb();
02146 $sQ = "select 1 from ".$this->getViewName()." where oxupdateexp >= ".time()." and MD5( CONCAT( oxid, oxshopid, oxupdatekey ) ) = ".$oDb->quote( $sKey );
02147 return !( (bool) $oDb->getOne( $sQ ) );
02148 }
02149
02155 public function getUpdateId()
02156 {
02157 if ( $this->_sUpdateKey === null ) {
02158 $this->setUpdateKey();
02159 $this->_sUpdateKey = md5( $this->getId() . $this->oxuser__oxshopid->value . $this->oxuser__oxupdatekey->value );
02160 }
02161 return $this->_sUpdateKey;
02162 }
02163
02172 public function encodePassword( $sPassword, $sSalt )
02173 {
02174 $oDb = oxDb::getDb();
02175 return $oDb->getOne( "select MD5( CONCAT( ".$oDb->quote( $sPassword ).", UNHEX( '{$sSalt}' ) ) )" );
02176 }
02177
02185 public function prepareSalt( $sSalt )
02186 {
02187 return ( $sSalt ? oxDb::getDb()->getOne( "select HEX( '{$sSalt}' )" ) : '' );
02188 }
02189
02197 public function decodeSalt( $sSaltHex )
02198 {
02199 return ( $sSaltHex ? oxDb::getDb()->getOne( "select UNHEX( '{$sSaltHex}' )" ) : '' );
02200 }
02201
02209 public function setPassword( $sPassword = null )
02210 {
02211
02212 $sSalt = $sPassword ? $this->prepareSalt( oxUtilsObject::getInstance()->generateUID() ) : '';
02213
02214
02215 $sPassword = $sPassword ? $this->encodePassword( $sPassword, $sSalt ) : '';
02216
02217 $this->oxuser__oxpassword = new oxField( $sPassword, oxField::T_RAW );
02218 $this->oxuser__oxpasssalt = new oxField( $sSalt, oxField::T_RAW );
02219 }
02220
02228 public function isSamePassword( $sNewPass )
02229 {
02230 return $this->encodePassword( $sNewPass, $this->oxuser__oxpasssalt->value ) == $this->oxuser__oxpassword->value;
02231 }
02232
02238 public function isLoadedFromCookie()
02239 {
02240 return $this->_blLoadedFromCookie;
02241 }
02242
02249 public function getPasswordHash()
02250 {
02251 $sHash = null;
02252 if ( $this->oxuser__oxpassword->value ) {
02253 if ( strpos( $this->oxuser__oxpassword->value, 'ox_' ) === 0 ) {
02254
02255 $this->setPassword( oxUtils::getInstance()->strRem( $this->oxuser__oxpassword->value ) );
02256 } elseif ( ( strlen( $this->oxuser__oxpassword->value ) < 32 ) && ( strpos( $this->oxuser__oxpassword->value, 'openid_' ) !== 0 ) ) {
02257
02258 $this->setPassword( $this->oxuser__oxpassword->value );
02259 }
02260 $sHash = $this->oxuser__oxpassword->value;
02261 }
02262 return $sHash;
02263 }
02264
02273 public static function getAdminUser()
02274 {
02275 return self::getActiveUser( true );
02276 }
02277
02288 public static function getActiveUser( $blForceAdmin = false )
02289 {
02290 $oUser = oxNew( 'oxuser' );
02291 if ( $oUser->loadActiveUser( $blForceAdmin ) ) {
02292 return $oUser;
02293 } else {
02294 return false;
02295 }
02296 }
02297
02305 public function getOpenIdPassword( $iLength = 25 )
02306 {
02307 $sPassword= "openid_".substr( oxUtilsObject::getInstance()->generateUId(), 0, $iLength);
02308 return $sPassword;
02309 }
02310
02318 public function getReviewUserHash( $sUserId )
02319 {
02320 $oDb = oxDb::getDb();
02321 $sReviewUserHash = $oDb->getOne('select md5(concat("oxid", oxpassword, oxusername )) from oxuser where oxid = ' . $oDb->quote( $sUserId ) .'');
02322 return $sReviewUserHash;
02323 }
02324
02332 public function getReviewUserId( $sReviewUserHash )
02333 {
02334 $oDb = oxDb::getDb();
02335 $sUserId = $oDb->getOne('select oxid from oxuser where md5(concat("oxid", oxpassword, oxusername )) = ' . $oDb->quote( $sReviewUserHash ) .'');
02336 return $sUserId;
02337 }
02338
02344 public function getState()
02345 {
02346 return $this->oxuser__oxstateid->value;
02347 }
02348
02354 public function isTermsAccepted()
02355 {
02356 $sShopId = $this->getConfig()->getShopId();
02357 $sUserId = $this->getId();
02358 return (bool) oxDb::getDb()->getOne( "select 1 from oxacceptedterms where oxuserid='{$sUserId}' and oxshopid='{$sShopId}'" );
02359 }
02360
02366 public function acceptTerms()
02367 {
02368 $sUserId = $this->getId();
02369 $sShopId = $this->getConfig()->getShopId();
02370 $sVersion = oxNew( "oxcontent" )->getTermsVersion();
02371
02372 oxDb::getDb()->execute( "replace oxacceptedterms set oxuserid='{$sUserId}', oxshopid='{$sShopId}', oxtermversion='{$sVersion}'" );
02373 }
02374
02383 public function setCreditPointsForRegistrant( $sUserId )
02384 {
02385 $blSet = false;
02386 $iPoints = $this->getConfig()->getConfigParam( 'dPointsForRegistration' );
02387 if ( $iPoints ) {
02388 $this->oxuser__oxpoints = new oxField( $iPoints, oxField::T_RAW );
02389 if ( $blSet = $this->save() ) {
02390 $oDb = oxDb::getDb();
02391
02392
02393 $oDb->execute( "UPDATE oxinvitations SET oxpending = '0', oxaccepted = '1' where oxuserid = ". $oDb->quote( $sUserId ) );
02394
02395 $oInvUser = oxNew( "oxuser" );
02396 if ( $oInvUser->load( $sUserId ) ) {
02397 $blSet = $oInvUser->setCreditPointsForInviter();
02398 }
02399 }
02400
02401 oxSession::deleteVar( 'su' );
02402 }
02403
02404 return $blSet;
02405 }
02406
02412 public function setCreditPointsForInviter()
02413 {
02414 $blSet = false;
02415 $iPoints = $this->getConfig()->getConfigParam( 'dPointsForInvitation' );
02416 if ( $iPoints ) {
02417 $iNewPoints = $this->oxuser__oxpoints->value + $iPoints;
02418 $this->oxuser__oxpoints = new oxField( $iNewPoints, oxField::T_RAW );
02419 $blSet = $this->save();
02420 }
02421
02422 return $blSet;
02423 }
02424
02430 public function updateFbId()
02431 {
02432 $oFb = oxFb::getInstance();
02433 $blRet = false;
02434
02435 if ( $oFb->isConnected() && $oFb->getUser() ) {
02436 $this->oxuser__oxfbid = new oxField( $oFb->getUser() );
02437 $blRet = $this->save();
02438 }
02439
02440 return $blRet;
02441 }
02442 }