oxcmp_user.php

Go to the documentation of this file.
00001 <?php
00002 
00008 class oxcmp_user extends oxView
00009 {
00014     protected $_blIsNewUser    = false;
00015 
00020     protected $_blIsComponent = true;
00021 
00026     protected $_blNewsSubscriptionStatus = null;
00027 
00037     public function init()
00038     {
00039         // load session user
00040         $this->_loadSessionUser();
00041 
00042         parent::init();
00043     }
00044 
00057     public function render()
00058     {
00059         parent::render();
00060 
00061         // dyn_group feature: if you specify a groupid in URL the user
00062         // will automatically be added to this group later
00063         if ( $sDynGoup = oxConfig::getParameter( 'dgr' ) ) {
00064             oxSession::setVar( 'dgr', $sDynGoup );
00065         }
00066 
00067         if ( $blNewsReg = oxConfig::getParameter( 'blnewssubscribed' )) {
00068             $this->_oParent->setNewsSubscribed( $blNewsReg );
00069             // Passing to view. Left for compatibility reasons for a while. Will be removed in future
00070             $this->_oParent->addTplParam( 'blnewssubscribed', $this->_oParent->isNewsSubscribed() );
00071         }
00072 
00073         if ( $aInvAdress = oxConfig::getParameter( 'invadr') ) {
00074             $this->_oParent->addTplParam( 'invadr', $aInvAdress );
00075         }
00076 
00077         if ( $aDelAdress = oxConfig::getParameter( 'deladr') ) {
00078             $this->_oParent->addTplParam( 'deladr', $aDelAdress );
00079         }
00080 
00081         if ( $sUser = oxConfig::getParameter( 'lgn_usr' ) ) {
00082             $this->_oParent->addTplParam( 'lgn_usr', $sUser );
00083         }
00084 
00085         if ( $aDelAdressID = oxConfig::getParameter( 'deladrid' ) ) {
00086             $oAddress = oxNew( 'oxbase' );
00087             $oAddress->init( 'oxaddress' );
00088             $oAddress->load( $aDelAdressID );
00089             $this->_oParent->setDelAddress( $oAddress );
00090             $this->_oParent->addTplParam( 'delivadr', $this->_oParent->getDelAddress() );
00091         }
00092 
00093         // clicked on show address ?
00094         if ( $blShowAddress = oxSession::getVar( 'blshowshipaddress' ) ) {
00095             $this->_oParent->setShowShipAddress( 1 );
00096             // Passing to view. Left for compatibility reasons for a while. Will be removed in future
00097             $this->_oParent->addTplParam( 'blshowshipaddress', 1 );
00098         }
00099 
00100         return $this->getUser();
00101     }
00102 
00108     public function _loadSessionUser()
00109     {
00110         $myConfig = $this->getConfig();
00111         $oUser = $this->getUser();
00112 
00113         // no session user
00114         if ( !$oUser ) {
00115             return;
00116         }
00117 
00118         // this user is blocked, deny him
00119         if ( $oUser->inGroup( 'oxidblocked' ) ) {
00120             oxUtils::getInstance()->redirect( $myConfig->getShopHomeURL() . 'cl=info&tpl=user_blocked.tpl' );
00121         }
00122 
00123         // TODO: we need todo something with this !!!
00124         if ( $oUser->isLoadedFromCookie() ) {
00125 
00126                 // #1678 R
00127                 if ( !$myConfig->getConfigParam( 'blPerfNoBasketSaving' ) ) {
00128                     $myConfig->setGlobalParameter( 'blUserChanged', 1 );
00129                 }
00130 
00131             if ( $oBasket = $this->getSession()->getBasket() ) {
00132                 $oBasket->onUpdate();
00133             }
00134         }
00135     }
00136 
00150     public function login()
00151     {
00152         $sUser     = oxConfig::getParameter( 'lgn_usr' );
00153         $sPassword = oxConfig::getParameter( 'lgn_pwd' );
00154         $sCookie   = oxConfig::getParameter( 'lgn_cook' );
00155 
00156         // trying to login user
00157         try {
00158             $oUser = oxNew( 'oxuser' );
00159             $oUser->login( $sUser, $sPassword, $sCookie );
00160         } catch ( oxUserException $oEx ) {
00161             // for login component send excpetion text to a custom component (if defined)
00162             oxUtilsView::getInstance()->addErrorToDisplay( $oEx, false, true );
00163             return 'user';
00164         } catch( oxCookieException $oEx ){
00165             oxUtilsView::getInstance()->addErrorToDisplay( $oEx );
00166             return 'user';
00167         } catch( oxConnectionException $oEx ){
00168             //connection to external resource broken, change message and pass to the view
00169             $oEx->setMessage( 'EXCEPTION_ACTIONNOTPOSSIBLEATTHEMOMENT' );
00170             oxUtilsView::getInstance()->addErrorToDisplay( $oEx, false, true );
00171             return 'user';
00172         }
00173 
00174         // finalizing ..
00175         $this->_afterLogin( $oUser );
00176     }
00177 
00195     protected function _afterLogin( $oUser )
00196     {
00197         $myConfig = $this->getConfig();
00198 
00199         // this user is blocked, deny him
00200         if ( $oUser->inGroup( 'oxidblocked' ) ) {
00201             oxUtils::getInstance()->redirect( $myConfig->getShopHomeURL().'cl=info&tpl=user_blocked.tpl' );
00202         }
00203 
00204         // adding to dyn group
00205         $oUser->addDynGroup(oxSession::getVar( 'dgr' ), $myConfig->getConfigParam( 'aDeniedDynGroups' ));
00206 
00207         // recalc basket
00208         if ( $oBasket = $this->getSession()->getBasket() ) {
00209             $oBasket->onUpdate();
00210         }
00211 
00212             // #1678 R
00213             if ( !$myConfig->getConfigParam( 'blPerfNoBasketSaving' ) ) {
00214                 $myConfig->setGlobalParameter( 'blUserChanged', 1);
00215             }
00216 
00217 
00218         return 'payment';
00219     }
00220 
00227     public function login_noredirect()
00228     {
00229         $this->login();
00230     }
00231 
00240     protected function _afterLogout()
00241     {
00242         oxSession::deleteVar( 'paymentid' );
00243         oxSession::deleteVar( 'sShipSet' );
00244         oxSession::deleteVar( 'deladrid' );
00245         oxSession::deleteVar( 'dynvalue' );
00246 
00247         // resetting & recalc basket
00248         if ( ( $oBasket = $this->getSession()->getBasket() ) ) {
00249             $oBasket->resetUserInfo();
00250             $oBasket->onUpdate();
00251         }
00252     }
00253 
00262     public function logout()
00263     {
00264         $myConfig  = $this->getConfig();
00265         $oUser = oxNew( 'oxuser' );
00266 
00267         if ( $oUser->logout() ) {
00268 
00269             // finalizing ..
00270             $this->_afterLogout();
00271 
00272 
00273             // redirecting if user logs out in SSL mode
00274             if ( oxConfig::getParameter('redirect') && $myConfig->getConfigParam( 'sSSLShopURL' ) ) {
00275                 $sLogoutLink = $myConfig->getShopSecureHomeURL();
00276                 if ( $myConfig->isSsl() ) {
00277                     $sLogoutLink = $myConfig->getShopHomeURL();
00278                 }
00279                 oxUtils::getInstance()->redirect( $sLogoutLink.'cl='.oxConfig::getParameter('cl').'&amp;cnid='.oxConfig::getParameter('cnid').'&amp;fnc=logout&amp;tpl='.oxConfig::getParameter('tpl') );
00280             }
00281         }
00282     }
00283 
00293     public function changeUser( )
00294     {
00295         // checking if "open address area" button was clicked
00296         if ( $blSetup = $this->_setupDelAddress() ) {
00297             return;
00298         }
00299 
00300         $blUserRegistered = $this->_changeUser_noRedirect( );
00301 
00302         if ( $blUserRegistered === true ) {
00303             return 'payment';
00304         } else {
00305             return $blUserRegistered;
00306         }
00307     }
00308 
00314     public function changeuser_testvalues()
00315     {
00316         $this->_changeUser_noRedirect();
00317     }
00318 
00340     public function createUser()
00341     {
00342         // checking if "open address area" button was clicked
00343         if ( $blSetup = $this->_setupDelAddress() ) {
00344             return;
00345         }
00346 
00347         $myConfig = $this->getConfig();
00348         $myUtils  = oxUtils::getInstance();
00349 
00350         // collecting values to check
00351         $sUser = oxConfig::getParameter( 'lgn_usr' );
00352 
00353         // first pass
00354         $sPassword = oxConfig::getParameter( 'lgn_pwd' );
00355 
00356         // second pass
00357         $sPassword2 = oxConfig::getParameter( 'lgn_pwd2' );
00358 
00359         $aRawVal = array('oxuser__oxcompany', 'oxuser__oxaddinfo', 'oxuser__oxfname', 'oxuser__oxlname');
00360         $aInvAdress = oxConfig::getParameter( 'invadr', $aRawVal );
00361         $aDelAdress = $this->_getDelAddressData();
00362 
00363         $oUser = oxNew( 'oxuser' );
00364 
00365         try {
00366 
00367             $oUser->checkValues( $sUser, $sPassword, $sPassword2, $aInvAdress, $aDelAdress );
00368 
00369             // setting values
00370             $oUser->oxuser__oxusername = new oxField($sUser, oxField::T_RAW);
00371             $oUser->setPassword( $sPassword );
00372             $oUser->oxuser__oxactive   = new oxField(1, oxField::T_RAW);
00373 
00374             $oUser->createUser();
00375             $oUser->load( $oUser->getId() );
00376             $oUser->changeUserData( $oUser->oxuser__oxusername->value, $sPassword, $sPassword, $aInvAdress, $aDelAdress );
00377 
00378             // assigning to newsletter
00379             $blOptin = oxConfig::getParameter( 'blnewssubscribed' );
00380             $this->_blNewsSubscriptionStatus = $oUser->setNewsSubscription( $blOptin, true );
00381 
00382             $oUser->logout();
00383 
00384         } catch ( oxUserException $oEx ) {
00385             oxUtilsView::getInstance()->addErrorToDisplay( $oEx, false, true );
00386             return false;
00387         } catch( oxInputException $oEx ){
00388             oxUtilsView::getInstance()->addErrorToDisplay( $oEx, false, true );
00389             return false;
00390         } catch( oxConnectionException $oEx ){
00391             oxUtilsView::getInstance()->addErrorToDisplay( $oEx, false, true );
00392             return false;
00393         }
00394 
00395         if ( !$sPassword ) {
00396             oxSession::setVar( 'usr', $oUser->getId() );
00397             $this->_afterLogin( $oUser );
00398         } elseif ( $this->login() == 'user' ) {
00399             return false;
00400         }
00401 
00402         // order remark
00403         //V #427: order remark for new users 
00404         $sOrd_Remark = oxConfig::getParameter( 'order_remark' );
00405         if ( $sOrd_Remark ) {
00406             oxSession::setVar( 'ordrem', $sOrd_Remark );
00407         }
00408 
00409         // send register eMail
00410         //TODO: move into user
00411         if ( (int) oxConfig::getParameter( 'option' ) == 3 ) {
00412             $oxEMail = oxNew( 'oxemail' );
00413             $oxEMail->sendRegisterEmail( $oUser );
00414         }
00415 
00416         // new registered
00417         $this->_blIsNewUser = true;
00418 
00419         return 'payment';
00420     }
00421 
00427     public function registerUser()
00428     {
00429         // checking if "open address area" button was clicked
00430         if ( $blSetup = $this->_setupDelAddress() ) {
00431             return;
00432         }
00433 
00434         // registered new user ?
00435         if ( $this->createuser()!= false && $this->_blIsNewUser ) {
00436                 // #1672 R
00437                 $this->getUser()->addToGroup( 'oxidnotyetordered' );
00438 
00439             if ( $this->_blNewsSubscriptionStatus === null || $this->_blNewsSubscriptionStatus ) {
00440                 return 'register?success=1';
00441             } else {
00442                 return 'register?success=1&newslettererror=4';
00443             }
00444         } else { // problems with registration ...
00445             $this->logout();
00446         }
00447     }
00448 
00462     protected function _changeUser_noRedirect( )
00463     {
00464         // no user ?
00465         $oUser = $this->getUser();
00466         if ( !$oUser ) {
00467             return;
00468         }
00469 
00470         // collecting values to check
00471         $aDelAdress = $this->_getDelAddressData();
00472         // if user company name, user name and additional info has special chars
00473         $aRawVal = array('oxuser__oxcompany', 'oxuser__oxaddinfo', 'oxuser__oxfname', 'oxuser__oxlname');
00474         $aInvAdress = oxConfig::getParameter( 'invadr', $aRawVal );
00475 
00476         $sUserName  = $oUser->oxuser__oxusername->value;
00477         $sPassword  = $sPassword2 = $oUser->oxuser__oxpassword->value;
00478 
00479         try { // testing user input
00480             $oUser->changeUserData( $sUserName, $sPassword, $sPassword2, $aInvAdress, $aDelAdress );
00481             // assigning to newsletter
00482             if (($blOptin = oxConfig::getParameter( 'blnewssubscribed' )) === null) {
00483                 $blOptin = $oUser->getNewsSubscription()->getOptInStatus();
00484             }
00485             $this->_blNewsSubscriptionStatus = $oUser->setNewsSubscription( $blOptin, oxConfig::getInstance()->getConfigParam( 'blOrderOptInEmail' ) );
00486 
00487         } catch ( oxUserException $oEx ) { // errors in input
00488             // marking error code
00489             //TODO
00490             oxUtilsView::getInstance()->addErrorToDisplay($oEx, false, true);
00491             return;
00492         } catch(oxInputException $oEx) {
00493             oxUtilsView::getInstance()->addErrorToDisplay($oEx, false, true);
00494             return;
00495         } catch(oxConnectionException $oEx){
00496              //connection to external resource broken, change message and pass to the view
00497             oxUtilsView::getInstance()->addErrorToDisplay($oEx, false, true);
00498             return;
00499         }
00500 
00501 
00502         // order remark
00503         $sOrd_Remark = oxConfig::getParameter( 'order_remark' );
00504         if ( $sOrd_Remark ) {
00505             oxSession::setVar( 'ordrem', $sOrd_Remark );
00506         }
00507 
00508         if ( $oBasket = $this->getSession()->getBasket() ) {
00509             $oBasket->onUpdate();
00510         }
00511         return true;
00512     }
00513 
00520     protected function _getDelAddressData()
00521     {
00522         // if user company name, user name and additional info has special chars
00523         $aRawVal = array('oxaddress__oxcompany', 'oxaddress__oxaddinfo', 'oxuser__oxfname', 'oxuser__oxlname');
00524         $aDelAdress = $aDeladr = oxConfig::getParameter( 'deladr', $aRawVal );
00525 
00526         if ( is_array( $aDeladr ) ) {
00527             // checking if data is filled
00528             if ( isset( $aDeladr['oxaddress__oxsal'] ) ) {
00529                 unset( $aDeladr['oxaddress__oxsal'] );
00530             }
00531             if ( !count( $aDeladr ) || implode( '', $aDeladr ) == '' ) {
00532                 // resetting to avoid empty records
00533                 $aDelAdress = array();
00534             }
00535         }
00536         return $aDelAdress;
00537     }
00538 
00548     protected function _setupDelAddress()
00549     {
00550         $blSetup = false;
00551         $blShowShipAddress = $blSessShowAddress = (int) oxSession::getVar( 'blshowshipaddress' );
00552 
00553         // user clicked on button to hide
00554         if ( $blHideAddress = oxConfig::getParameter( 'blhideshipaddress' ) ) {
00555             $blShowShipAddress = 0;
00556             $blSetup = true;
00557 
00558             // unsetting delivery address
00559             oxSession::deleteVar( 'deladdrid' );
00560         } else {
00561 
00562             $blShowAddress = oxConfig::getParameter( 'blshowshipaddress' )? 1 : 0;
00563             // user clicked on button to show
00564             if ( $blShowAddress != $blSessShowAddress ) {
00565                 $blShowShipAddress = 1;
00566                 $blSetup = true;
00567             }
00568         }
00569 
00570         oxSession::setVar( 'blshowshipaddress', $blShowShipAddress );
00571         $this->_oParent->_aViewData['blshowshipaddress'] = $blShowShipAddress;
00572 
00573         return $blSetup;
00574     }
00575 }

Generated on Fri Dec 19 14:20:29 2008 for OXID eShop CE by  doxygen 1.5.5