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 = 'newsletter.tpl';
00046
00052 protected $_iViewIndexState = VIEW_INDEXSTATE_NOINDEXNOFOLLOW;
00053
00064 public function render()
00065 {
00066 $myConfig = $this->getConfig();
00067
00068 parent::render();
00069
00070
00071 $this->_aViewData['toparticle'] = $this->getTopStartArticle();
00072 $this->_aViewData['toparticlelist'] = $this->getTopStartActionArticles();
00073
00074 $this->_aViewData['homecountryid'] = $this->getHomeCountryId();
00075
00076 $this->_aViewData['success'] = $this->getNewsletterStatus();
00077
00078 $this->_aViewData['aRegParams'] = $this->getRegParams();
00079
00080 return $this->_sThisTemplate;
00081 }
00082
00091 public function fill()
00092 {
00093
00094 $this->_aRegParams = oxConfig::getParameter( "editval" );
00095 }
00096
00107 public function send()
00108 {
00109 $aParams = oxConfig::getParameter("editval");
00110
00111
00112 $this->_aRegParams = $aParams;
00113
00114 if ( !$aParams['oxuser__oxusername'] ) {
00115 oxUtilsView::getInstance()->addErrorToDisplay('NEWSLETTER_COMPLETEALLFIELEDS');
00116 return;
00117 } elseif ( !oxUtils::getInstance()->isValidEmail( $aParams['oxuser__oxusername'] ) ) {
00118
00119 oxUtilsView::getInstance()->addErrorToDisplay('NEWSLETTER_INVALIDEMAIL');
00120 return;
00121 }
00122
00123 $blSubscribe = oxConfig::getParameter("subscribeStatus");
00124
00125 $oUser = oxNew( 'oxuser' );
00126 $oUser->oxuser__oxusername = new oxField($aParams['oxuser__oxusername'], oxField::T_RAW);
00127
00128 $blUserLoaded = false;
00129
00130
00131 if ( !$oUser->exists() && $blSubscribe ) {
00132 $oUser->oxuser__oxactive = new oxField(1, oxField::T_RAW);
00133 $oUser->oxuser__oxrights = new oxField('user', oxField::T_RAW);
00134 $oUser->oxuser__oxshopid = new oxField($this->getConfig()->getShopId(), oxField::T_RAW);
00135 $oUser->oxuser__oxfname = new oxField($aParams['oxuser__oxfname'], oxField::T_RAW);
00136 $oUser->oxuser__oxlname = new oxField($aParams['oxuser__oxlname'], oxField::T_RAW);
00137 $oUser->oxuser__oxsal = new oxField($aParams['oxuser__oxsal'], oxField::T_RAW);
00138 $oUser->oxuser__oxcountryid = new oxField($aParams['oxuser__oxcountryid'], oxField::T_RAW);
00139 $blUserLoaded = $oUser->save();
00140 } else {
00141 $blUserLoaded = $oUser->load( $oUser->getId() );
00142 }
00143
00144
00145 if ( $blSubscribe && $blUserLoaded ) {
00146
00147 $oUser->setNewsSubscription( false, false );
00148
00149 $blOrderOptInEmail = $this->getConfig()->getConfigParam( 'blOrderOptInEmail' );
00150 if ( $oUser->setNewsSubscription( true, $blOrderOptInEmail ) ) {
00151
00152 if ( $blOrderOptInEmail ) {
00153 $this->_iNewsletterStatus = 1;
00154 } else {
00155 $this->_iNewsletterStatus = 2;
00156 }
00157 } else {
00158 oxUtilsView::getInstance()->addErrorToDisplay('NEWSLETTER_NOTABLETOSENDEMAIL');
00159 }
00160 } elseif ( !$blSubscribe && $blUserLoaded ) {
00161
00162 $oUser->setNewsSubscription( false, false );
00163 $this->_iNewsletterStatus = 3;
00164 }
00165 }
00166
00175 public function addme()
00176 {
00177
00178 $oUser = oxNew( 'oxuser' );
00179 if ( $oUser->load( oxConfig::getParameter( 'uid' ) ) ) {
00180 $oUser->getNewsSubscription()->setOptInStatus( 1 );
00181 $oUser->addToGroup( 'oxidnewsletter' );
00182 $this->_iNewsletterStatus = 2;
00183 }
00184 }
00185
00194 public function removeme()
00195 {
00196
00197 $oUser = oxNew( 'oxuser' );
00198 if ( $oUser->load( oxConfig::getParameter( 'uid' ) ) ) {
00199 $oUser->getNewsSubscription()->setOptInStatus( 0 );
00200
00201
00202 if ( !$this->getConfig()->getConfigParam( 'blOrderOptInEmail' ) ) {
00203 $oUser->removeFromGroup( 'oxidnewsletter' );
00204 }
00205
00206 $this->_iNewsletterStatus = 3;
00207 }
00208 }
00209
00215 public function getTopStartActionArticles()
00216 {
00217 if ( $this->_oActionArticles === null ) {
00218 $this->_oActionArticles = false;
00219 if ( $this->getConfig()->getConfigParam( 'bl_perfLoadAktion' ) ) {
00220 $oArtList = oxNew( 'oxarticlelist' );
00221 $oArtList->loadAktionArticles( 'OXTOPSTART' );
00222 if ( $oArtList->count() ) {
00223 $this->_oTopArticle = $oArtList->current();
00224 $this->_oActionArticles = $oArtList;
00225 }
00226 }
00227 }
00228 return $this->_oActionArticles;
00229 }
00230
00236 public function getTopStartArticle()
00237 {
00238 if ( $this->_oTopArticle === null ) {
00239 $this->_oTopArticle = false;
00240 if ( $this->getTopStartActionArticles() ) {
00241 return $this->_oTopArticle;
00242 }
00243 }
00244 return $this->_oTopArticle;
00245 }
00246
00252 public function getHomeCountryId()
00253 {
00254 if ( $this->_sHomeCountryId === null ) {
00255 $this->_sHomeCountryId = false;
00256 $aHomeCountry = $this->getConfig()->getConfigParam( 'aHomeCountry' );
00257 if ( is_array( $aHomeCountry ) ) {
00258 $this->_sHomeCountryId = current( $aHomeCountry );
00259 }
00260 }
00261 return $this->_sHomeCountryId;
00262 }
00263
00269 public function getNewsletterStatus()
00270 {
00271 return $this->_iNewsletterStatus;
00272 }
00273
00279 public function getRegParams()
00280 {
00281 return $this->_aRegParams;
00282 }
00283 }