newsletter.php

Go to the documentation of this file.
00001 <?php
00002 
00009 class Newsletter extends oxUBase
00010 {
00011 
00017     protected $_oActionArticles = null;
00018 
00024     protected $_oTopArticle = null;
00025 
00031     protected $_sHomeCountryId = null;
00032 
00038     protected $_iNewsletterStatus = null;
00039 
00045     protected $_aRegParams = null;
00046 
00052     protected $_sThisTemplate = 'page/info/newsletter.tpl';
00053 
00059     protected $_iViewIndexState = VIEW_INDEXSTATE_NOINDEXNOFOLLOW;
00060 
00067     public function fill()
00068     {
00069         // loads submited values
00070         $this->_aRegParams = oxRegistry::getConfig()->getRequestParameter("editval");
00071     }
00072 
00083     public function send()
00084     {
00085         $aParams = oxRegistry::getConfig()->getRequestParameter("editval");
00086 
00087         // loads submited values
00088         $this->_aRegParams = $aParams;
00089 
00090         if (!$aParams['oxuser__oxusername']) {
00091             oxRegistry::get("oxUtilsView")->addErrorToDisplay('ERROR_MESSAGE_COMPLETE_FIELDS_CORRECTLY');
00092 
00093             return;
00094         } elseif (!oxRegistry::getUtils()->isValidEmail($aParams['oxuser__oxusername'])) {
00095             // #1052C - eMail validation added
00096             oxRegistry::get("oxUtilsView")->addErrorToDisplay('MESSAGE_INVALID_EMAIL');
00097 
00098             return;
00099         }
00100 
00101         $blSubscribe = oxRegistry::getConfig()->getRequestParameter("subscribeStatus");
00102 
00103         $oUser = oxNew('oxuser');
00104         $oUser->oxuser__oxusername = new oxField($aParams['oxuser__oxusername'], oxField::T_RAW);
00105 
00106         $blUserLoaded = false;
00107 
00108         // if such user does not exist
00109         if (!$oUser->exists()) {
00110 
00111             // and subscribe is off - error, on - create
00112             if (!$blSubscribe) {
00113 
00114                 oxRegistry::get("oxUtilsView")->addErrorToDisplay('NEWSLETTER_EMAIL_NOT_EXIST');
00115 
00116                 return;
00117 
00118             } else {
00119                 $oUser->oxuser__oxactive = new oxField(1, oxField::T_RAW);
00120                 $oUser->oxuser__oxrights = new oxField('user', oxField::T_RAW);
00121                 $oUser->oxuser__oxshopid = new oxField($this->getConfig()->getShopId(), oxField::T_RAW);
00122                 $oUser->oxuser__oxfname = new oxField($aParams['oxuser__oxfname'], oxField::T_RAW);
00123                 $oUser->oxuser__oxlname = new oxField($aParams['oxuser__oxlname'], oxField::T_RAW);
00124                 $oUser->oxuser__oxsal = new oxField($aParams['oxuser__oxsal'], oxField::T_RAW);
00125                 $oUser->oxuser__oxcountryid = new oxField($aParams['oxuser__oxcountryid'], oxField::T_RAW);
00126                 $blUserLoaded = $oUser->save();
00127             }
00128 
00129         } else {
00130             $blUserLoaded = $oUser->load($oUser->getId());
00131         }
00132 
00133 
00134         // if user was added/loaded successfully and subscribe is on - subscribing to newsletter
00135         if ($blSubscribe && $blUserLoaded) {
00136             //removing user from subscribe list before adding
00137             $oUser->setNewsSubscription(false, false);
00138 
00139             $blOrderOptInEmail = $this->getConfig()->getConfigParam('blOrderOptInEmail');
00140             if ($oUser->setNewsSubscription(true, $blOrderOptInEmail)) {
00141                 // done, confirmation required?
00142                 if ($blOrderOptInEmail) {
00143                     $this->_iNewsletterStatus = 1;
00144                 } else {
00145                     $this->_iNewsletterStatus = 2;
00146                 }
00147             } else {
00148                 oxRegistry::get("oxUtilsView")->addErrorToDisplay('MESSAGE_NOT_ABLE_TO_SEND_EMAIL');
00149             }
00150         } elseif (!$blSubscribe && $blUserLoaded) {
00151             // unsubscribing user
00152             $oUser->setNewsSubscription(false, false);
00153             $this->_iNewsletterStatus = 3;
00154         }
00155     }
00156 
00163     public function addme()
00164     {
00165         // user exists ?
00166         $oUser = oxNew('oxuser');
00167         if ($oUser->load(oxRegistry::getConfig()->getRequestParameter('uid'))) {
00168             $sConfirmCode = md5($oUser->oxuser__oxusername->value . $oUser->oxuser__oxpasssalt->value);
00169             // is confirm code ok?
00170             if (oxRegistry::getConfig()->getRequestParameter('confirm') == $sConfirmCode) {
00171                 $oUser->getNewsSubscription()->setOptInStatus(1);
00172                 $oUser->addToGroup('oxidnewsletter');
00173                 $this->_iNewsletterStatus = 2;
00174             }
00175         }
00176     }
00177 
00181     public function removeme()
00182     {
00183         // existing user ?
00184         $oUser = oxNew('oxuser');
00185         if ($oUser->load(oxRegistry::getConfig()->getRequestParameter('uid'))) {
00186             $oUser->getNewsSubscription()->setOptInStatus(0);
00187 
00188             // removing from group ..
00189             $oUser->removeFromGroup('oxidnewsletter');
00190 
00191             $this->_iNewsletterStatus = 3;
00192         }
00193     }
00194 
00198     public function rmvm()
00199     {
00200         $this->removeme();
00201     }
00202 
00208     public function getTopStartActionArticles()
00209     {
00210         if ($this->_oActionArticles === null) {
00211             $this->_oActionArticles = false;
00212             if ($this->getConfig()->getConfigParam('bl_perfLoadAktion')) {
00213                 $oArtList = oxNew('oxarticlelist');
00214                 $oArtList->loadActionArticles('OXTOPSTART');
00215                 if ($oArtList->count()) {
00216                     $this->_oTopArticle = $oArtList->current();
00217                     $this->_oActionArticles = $oArtList;
00218                 }
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 
00239         return $this->_oTopArticle;
00240     }
00241 
00247     public function getHomeCountryId()
00248     {
00249         if ($this->_sHomeCountryId === null) {
00250             $this->_sHomeCountryId = false;
00251             $aHomeCountry = $this->getConfig()->getConfigParam('aHomeCountry');
00252             if (is_array($aHomeCountry)) {
00253                 $this->_sHomeCountryId = current($aHomeCountry);
00254             }
00255         }
00256 
00257         return $this->_sHomeCountryId;
00258     }
00259 
00265     public function getNewsletterStatus()
00266     {
00267         return $this->_iNewsletterStatus;
00268     }
00269 
00275     public function getRegParams()
00276     {
00277         return $this->_aRegParams;
00278     }
00279 
00285     public function getBreadCrumb()
00286     {
00287         $aPaths = array();
00288         $aPath = array();
00289         $iBaseLanguage = oxRegistry::getLang()->getBaseLanguage();
00290         $aPath['title'] = oxRegistry::getLang()->translateString('STAY_INFORMED', $iBaseLanguage, false);
00291         $aPath['link'] = $this->getLink();
00292 
00293         $aPaths[] = $aPath;
00294 
00295         return $aPaths;
00296     }
00297 
00303     public function getTitle()
00304     {
00305         if ($this->getNewsletterStatus() == 4 || !$this->getNewsletterStatus()) {
00306             $sConstant = 'STAY_INFORMED';
00307         } elseif ($this->getNewsletterStatus() == 1) {
00308             $sConstant = 'MESSAGE_THANKYOU_FOR_SUBSCRIBING_NEWSLETTERS';
00309         } elseif ($this->getNewsletterStatus() == 2) {
00310             $sConstant = 'MESSAGE_NEWSLETTER_CONGRATULATIONS';
00311         } elseif ($this->getNewsletterStatus() == 3) {
00312             $sConstant = 'SUCCESS';
00313         }
00314 
00315         return oxRegistry::getLang()->translateString($sConstant, oxRegistry::getLang()->getBaseLanguage(), false);
00316     }
00317 }