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             $oUser->removeFromGroup( 'oxidnewsletter' );
00187 
00188             $this->_iNewsletterStatus = 3;
00189         }
00190     }
00191 
00197     public function rmvm()
00198     {
00199         $this->removeme();
00200     }
00201 
00207     public function getTopStartActionArticles()
00208     {
00209         if ( $this->_oActionArticles === null ) {
00210             $this->_oActionArticles = false;
00211             if ( $this->getConfig()->getConfigParam( 'bl_perfLoadAktion' ) ) {
00212                 $oArtList = oxNew( 'oxarticlelist' );
00213                 $oArtList->loadActionArticles( 'OXTOPSTART' );
00214                 if ( $oArtList->count() ) {
00215                     $this->_oTopArticle     = $oArtList->current();
00216                     $this->_oActionArticles = $oArtList;
00217                 }
00218             }
00219         }
00220         return $this->_oActionArticles;
00221     }
00222 
00228     public function getTopStartArticle()
00229     {
00230         if ( $this->_oTopArticle === null ) {
00231             $this->_oTopArticle = false;
00232             if ( $this->getTopStartActionArticles() ) {
00233                 return $this->_oTopArticle;
00234             }
00235         }
00236         return $this->_oTopArticle;
00237     }
00238 
00244     public function getHomeCountryId()
00245     {
00246         if ( $this->_sHomeCountryId === null ) {
00247             $this->_sHomeCountryId = false;
00248             $aHomeCountry = $this->getConfig()->getConfigParam( 'aHomeCountry' );
00249             if ( is_array( $aHomeCountry ) ) {
00250                 $this->_sHomeCountryId = current( $aHomeCountry );
00251             }
00252         }
00253         return $this->_sHomeCountryId;
00254     }
00255 
00261     public function getNewsletterStatus()
00262     {
00263         return $this->_iNewsletterStatus;
00264     }
00265 
00271     public function getRegParams()
00272     {
00273         return $this->_aRegParams;
00274     }
00275 
00281     public function getBreadCrumb()
00282     {
00283         $aPaths = array();
00284         $aPath  = array();
00285         $aPath['title'] = oxRegistry::getLang()->translateString( 'STAY_INFORMED', oxRegistry::getLang()->getBaseLanguage(), false );
00286         $aPath['link']  = $this->getLink();
00287 
00288         $aPaths[] = $aPath;
00289         return $aPaths;
00290     }
00291 }