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
00040 $this->_loadSessionUser();
00041
00042 parent::init();
00043 }
00044
00057 public function render()
00058 {
00059 parent::render();
00060
00061
00062
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
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
00094 if ( $blShowAddress = oxSession::getVar( 'blshowshipaddress' ) ) {
00095 $this->_oParent->setShowShipAddress( 1 );
00096
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
00114 if ( !$oUser ) {
00115 return;
00116 }
00117
00118
00119 if ( $oUser->inGroup( 'oxidblocked' ) ) {
00120 oxUtils::getInstance()->redirect( $myConfig->getShopHomeURL() . 'cl=info&tpl=user_blocked.tpl' );
00121 }
00122
00123
00124 if ( $oUser->blLoadedFromCookie ) {
00125
00126
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
00157 try {
00158 $oUser = oxNew( 'oxuser' );
00159 $oUser->login( $sUser, $sPassword, $sCookie );
00160 } catch ( oxUserException $oEx ) {
00161
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
00169 $oEx->setMessage( 'EXCEPTION_ACTIONNOTPOSSIBLEATTHEMOMENT' );
00170 oxUtilsView::getInstance()->addErrorToDisplay( $oEx, false, true );
00171 return 'user';
00172 }
00173
00174
00175 $this->_afterLogin( $oUser );
00176 }
00177
00195 protected function _afterLogin( $oUser )
00196 {
00197 $myConfig = $this->getConfig();
00198
00199
00200 if ( $oUser->inGroup( 'oxidblocked' ) ) {
00201 oxUtils::getInstance()->redirect( $myConfig->getShopHomeURL().'cl=info&tpl=user_blocked.tpl' );
00202 }
00203
00204
00205 $oUser->addDynGroup(oxSession::getVar( 'dgr' ), $myConfig->getConfigParam( 'aDeniedDynGroups' ));
00206
00207
00208 if ( $oBasket = $this->getSession()->getBasket() ) {
00209 $oBasket->onUpdate();
00210 }
00211
00212
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
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
00270 $this->_afterLogout();
00271
00272
00273
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').'&cnid='.oxConfig::getParameter('cnid').'&fnc=logout&tpl='.oxConfig::getParameter('tpl') );
00280 }
00281 }
00282 }
00283
00293 public function changeUser( )
00294 {
00295
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
00343 if ( $blSetup = $this->_setupDelAddress() ) {
00344 return;
00345 }
00346
00347 $myConfig = $this->getConfig();
00348 $myUtils = oxUtils::getInstance();
00349
00350
00351 $sUser = oxConfig::getParameter( 'lgn_usr' );
00352
00353
00354 $sPassword = oxConfig::getParameter( 'lgn_pwd' );
00355
00356
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
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
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
00403
00404 if ( (int) oxConfig::getParameter( 'option' ) == 3 ) {
00405 $oxEMail = oxNew( 'oxemail' );
00406 $oxEMail->sendRegisterEmail( $oUser );
00407 }
00408
00409
00410 $this->_blIsNewUser = true;
00411
00412 return 'payment';
00413 }
00414
00420 public function registerUser()
00421 {
00422
00423 if ( $blSetup = $this->_setupDelAddress() ) {
00424 return;
00425 }
00426
00427
00428 if ( $this->createuser()!= false && $this->_blIsNewUser ) {
00429
00430 $this->getUser()->addToGroup( 'oxidnotyetordered' );
00431
00432 if ( $this->_blNewsSubscriptionStatus === null || $this->_blNewsSubscriptionStatus ) {
00433 return 'register?success=1';
00434 } else {
00435 return 'register?success=1&newslettererror=4';
00436 }
00437 } else {
00438 $this->logout();
00439 }
00440 }
00441
00455 protected function _changeUser_noRedirect( )
00456 {
00457
00458 $oUser = $this->getUser();
00459 if ( !$oUser ) {
00460 return;
00461 }
00462
00463
00464 $aDelAdress = $this->_getDelAddressData();
00465
00466 $aRawVal = array('oxuser__oxcompany', 'oxuser__oxaddinfo', 'oxuser__oxfname', 'oxuser__oxlname');
00467 $aInvAdress = oxConfig::getParameter( 'invadr', $aRawVal );
00468
00469 $sUserName = $oUser->oxuser__oxusername->value;
00470 $sPassword = $sPassword2 = $oUser->oxuser__oxpassword->value;
00471
00472 try {
00473 $oUser->changeUserData( $sUserName, $sPassword, $sPassword2, $aInvAdress, $aDelAdress );
00474
00475 if (($blOptin = oxConfig::getParameter( 'blnewssubscribed' )) === null) {
00476 $blOptin = $oUser->getNewsSubscription()->getOptInStatus();
00477 }
00478 $this->_blNewsSubscriptionStatus = $oUser->setNewsSubscription( $blOptin, oxConfig::getInstance()->getConfigParam( 'blOrderOptInEmail' ) );
00479
00480 } catch ( oxUserException $oEx ) {
00481
00482
00483 oxUtilsView::getInstance()->addErrorToDisplay($oEx, false, true);
00484 return;
00485 } catch(oxInputException $oEx) {
00486 oxUtilsView::getInstance()->addErrorToDisplay($oEx, false, true);
00487 return;
00488 } catch(oxConnectionException $oEx){
00489
00490 oxUtilsView::getInstance()->addErrorToDisplay($oEx, false, true);
00491 return;
00492 }
00493
00494
00495
00496 $sOrd_Remark = oxConfig::getParameter( 'order_remark' );
00497 if ( $sOrd_Remark ) {
00498 oxSession::setVar( 'ordrem', $sOrd_Remark );
00499 }
00500
00501 if ( $oBasket = $this->getSession()->getBasket() ) {
00502 $oBasket->onUpdate();
00503 }
00504 return true;
00505 }
00506
00513 protected function _getDelAddressData()
00514 {
00515
00516 $aRawVal = array('oxaddress__oxcompany', 'oxaddress__oxaddinfo', 'oxuser__oxfname', 'oxuser__oxlname');
00517 $aDelAdress = $aDeladr = oxConfig::getParameter( 'deladr', $aRawVal );
00518
00519 if ( is_array( $aDeladr ) ) {
00520
00521 if ( isset( $aDeladr['oxaddress__oxsal'] ) ) {
00522 unset( $aDeladr['oxaddress__oxsal'] );
00523 }
00524 if ( !count( $aDeladr ) || implode( '', $aDeladr ) == '' ) {
00525
00526 $aDelAdress = array();
00527 }
00528 }
00529 return $aDelAdress;
00530 }
00531
00541 protected function _setupDelAddress()
00542 {
00543 $blSetup = false;
00544 $blShowShipAddress = $blSessShowAddress = (int) oxSession::getVar( 'blshowshipaddress' );
00545
00546
00547 if ( $blHideAddress = oxConfig::getParameter( 'blhideshipaddress' ) ) {
00548 $blShowShipAddress = 0;
00549 $blSetup = true;
00550
00551
00552 oxSession::deleteVar( 'deladdrid' );
00553 } else {
00554
00555 $blShowAddress = oxConfig::getParameter( 'blshowshipaddress' )? 1 : 0;
00556
00557 if ( $blShowAddress != $blSessShowAddress ) {
00558 $blShowShipAddress = 1;
00559 $blSetup = true;
00560 }
00561 }
00562
00563 oxSession::setVar( 'blshowshipaddress', $blShowShipAddress );
00564 $this->_oParent->_aViewData['blshowshipaddress'] = $blShowShipAddress;
00565
00566 return $blSetup;
00567 }
00568 }