newsletter.php

Go to the documentation of this file.
00001 <?php
00002 
00009 class Newsletter extends oxUBase
00010 {
00015     protected $_oActionArticles = null;
00016 
00021     protected $_oTopArticle = null;
00022 
00027     protected $_sHomeCountryId = null;
00028 
00033     protected $_iNewsletterStatus = null;
00034 
00039     protected $_aRegParams = null;
00040 
00045     protected $_sThisTemplate = 'page/info/newsletter.tpl';
00046 
00052     protected $_iViewIndexState = VIEW_INDEXSTATE_NOINDEXNOFOLLOW;
00053 
00062     public function fill()
00063     {
00064         // loads submited values
00065         $this->_aRegParams = oxConfig::getParameter( "editval" );
00066     }
00067 
00078     public function send()
00079     {
00080         $aParams  = oxConfig::getParameter("editval");
00081 
00082         // loads submited values
00083         $this->_aRegParams = $aParams;
00084 
00085         if ( !$aParams['oxuser__oxusername'] ) {
00086             oxRegistry::get("oxUtilsView")->addErrorToDisplay('ERROR_MESSAGE_COMPLETE_FIELDS_CORRECTLY');
00087             return;
00088         } elseif ( !oxRegistry::getUtils()->isValidEmail( $aParams['oxuser__oxusername'] ) ) {
00089             // #1052C - eMail validation added
00090             oxRegistry::get("oxUtilsView")->addErrorToDisplay('MESSAGE_INVALID_EMAIL');
00091             return;
00092         }
00093 
00094         $blSubscribe = oxConfig::getParameter("subscribeStatus");
00095 
00096         $oUser = oxNew( 'oxuser' );
00097         $oUser->oxuser__oxusername = new oxField($aParams['oxuser__oxusername'], oxField::T_RAW);
00098 
00099         $blUserLoaded = false;
00100 
00101         // if such user does not exist
00102         if ( !$oUser->exists() ) {
00103 
00104             // and subscribe is off - error, on - create
00105             if ( !$blSubscribe ) {
00106 
00107                 oxRegistry::get("oxUtilsView")->addErrorToDisplay('NEWSLETTER_EMAIL_NOT_EXIST');
00108                 return;
00109 
00110             } else {
00111                 $oUser->oxuser__oxactive    = new oxField(1, oxField::T_RAW);
00112                 $oUser->oxuser__oxrights    = new oxField('user', oxField::T_RAW);
00113                 $oUser->oxuser__oxshopid    = new oxField($this->getConfig()->getShopId(), oxField::T_RAW);
00114                 $oUser->oxuser__oxfname     = new oxField($aParams['oxuser__oxfname'], oxField::T_RAW);
00115                 $oUser->oxuser__oxlname     = new oxField($aParams['oxuser__oxlname'], oxField::T_RAW);
00116                 $oUser->oxuser__oxsal       = new oxField($aParams['oxuser__oxsal'], oxField::T_RAW);
00117                 $oUser->oxuser__oxcountryid = new oxField($aParams['oxuser__oxcountryid'], oxField::T_RAW);
00118                 $blUserLoaded = $oUser->save();
00119             }
00120 
00121         } else {
00122             $blUserLoaded = $oUser->load( $oUser->getId() );
00123         }
00124 
00125 
00126 
00127         // if user was added/loaded successfully and subscribe is on - subscribing to newsletter
00128         if ( $blSubscribe && $blUserLoaded ) {
00129             //removing user from subscribe list before adding
00130             $oUser->setNewsSubscription( false, false );
00131 
00132             $blOrderOptInEmail = $this->getConfig()->getConfigParam( 'blOrderOptInEmail' );
00133             if ( $oUser->setNewsSubscription( true, $blOrderOptInEmail ) ) {
00134                 // done, confirmation required?
00135                 if ( $blOrderOptInEmail ) {
00136                     $this->_iNewsletterStatus = 1;
00137                 } else {
00138                     $this->_iNewsletterStatus = 2;
00139                 }
00140             } else {
00141                 oxRegistry::get("oxUtilsView")->addErrorToDisplay('MESSAGE_NOT_ABLE_TO_SEND_EMAIL');
00142             }
00143         } elseif ( !$blSubscribe && $blUserLoaded ) {
00144             // unsubscribing user
00145             $oUser->setNewsSubscription( false, false );
00146             $this->_iNewsletterStatus = 3;
00147         }
00148     }
00149 
00158     public function addme()
00159     {
00160         // user exists ?
00161         $oUser = oxNew( 'oxuser' );
00162         if ( $oUser->load( oxRegistry::getConfig()->getRequestParameter( 'uid' ) ) ) {
00163             $sConfirmCode = md5($oUser->oxuser__oxusername->value.$oUser->oxuser__oxpasssalt->value);
00164             // is confirm code ok?
00165             if ( oxRegistry::getConfig()->getRequestParameter( 'confirm' ) == $sConfirmCode ) {
00166                 $oUser->getNewsSubscription()->setOptInStatus( 1 );
00167                 $oUser->addToGroup( 'oxidnewsletter' );
00168                 $this->_iNewsletterStatus = 2;
00169             }
00170         }
00171     }
00172 
00178     public function removeme()
00179     {
00180         // existing user ?
00181         $oUser = oxNew( 'oxuser' );
00182         if ( $oUser->load( oxConfig::getParameter( 'uid' ) ) ) {
00183             $oUser->getNewsSubscription()->setOptInStatus( 0 );
00184 
00185             // removing from group ..
00186             if ( !$this->getConfig()->getConfigParam( 'blOrderOptInEmail' ) ) {
00187                 $oUser->removeFromGroup( 'oxidnewsletter' );
00188             }
00189 
00190             $this->_iNewsletterStatus = 3;
00191         }
00192     }
00193 
00199     public function rmvm()
00200     {
00201         $this->removeme();
00202     }
00203 
00209     public function getTopStartActionArticles()
00210     {
00211         if ( $this->_oActionArticles === null ) {
00212             $this->_oActionArticles = false;
00213             if ( $this->getConfig()->getConfigParam( 'bl_perfLoadAktion' ) ) {
00214                 $oArtList = oxNew( 'oxarticlelist' );
00215                 $oArtList->loadActionArticles( 'OXTOPSTART' );
00216                 if ( $oArtList->count() ) {
00217                     $this->_oTopArticle     = $oArtList->current();
00218                     $this->_oActionArticles = $oArtList;
00219                 }
00220             }
00221         }
00222         return $this->_oActionArticles;
00223     }
00224 
00230     public function getTopStartArticle()
00231     {
00232         if ( $this->_oTopArticle === null ) {
00233             $this->_oTopArticle = false;
00234             if ( $this->getTopStartActionArticles() ) {
00235                 return $this->_oTopArticle;
00236             }
00237         }
00238         return $this->_oTopArticle;
00239     }
00240 
00246     public function getHomeCountryId()
00247     {
00248         if ( $this->_sHomeCountryId === null ) {
00249             $this->_sHomeCountryId = false;
00250             $aHomeCountry = $this->getConfig()->getConfigParam( 'aHomeCountry' );
00251             if ( is_array( $aHomeCountry ) ) {
00252                 $this->_sHomeCountryId = current( $aHomeCountry );
00253             }
00254         }
00255         return $this->_sHomeCountryId;
00256     }
00257 
00263     public function getNewsletterStatus()
00264     {
00265         return $this->_iNewsletterStatus;
00266     }
00267 
00273     public function getRegParams()
00274     {
00275         return $this->_aRegParams;
00276     }
00277 
00283     public function getBreadCrumb()
00284     {
00285         $aPaths = array();
00286         $aPath  = array();
00287         $aPath['title'] = oxRegistry::getLang()->translateString( 'STAY_INFORMED', oxRegistry::getLang()->getBaseLanguage(), false );
00288         $aPath['link']  = $this->getLink();
00289 
00290         $aPaths[] = $aPath;
00291         return $aPaths;
00292     }
00293 }