OXID eShop CE  4.9.8
 All Classes Files Functions Variables Pages
newsletter.php
Go to the documentation of this file.
1 <?php
2 
9 class Newsletter extends oxUBase
10 {
11 
17  protected $_oActionArticles = null;
18 
24  protected $_oTopArticle = null;
25 
31  protected $_sHomeCountryId = null;
32 
38  protected $_iNewsletterStatus = null;
39 
45  protected $_aRegParams = null;
46 
52  protected $_sThisTemplate = 'page/info/newsletter.tpl';
53 
60 
67  public function fill()
68  {
69  // loads submited values
70  $this->_aRegParams = oxRegistry::getConfig()->getRequestParameter("editval");
71  }
72 
83  public function send()
84  {
85  $aParams = oxRegistry::getConfig()->getRequestParameter("editval");
86 
87  // loads submited values
88  $this->_aRegParams = $aParams;
89 
90  if (!$aParams['oxuser__oxusername']) {
91  oxRegistry::get("oxUtilsView")->addErrorToDisplay('ERROR_MESSAGE_COMPLETE_FIELDS_CORRECTLY');
92 
93  return;
94  } elseif (!oxRegistry::getUtils()->isValidEmail($aParams['oxuser__oxusername'])) {
95  // #1052C - eMail validation added
96  oxRegistry::get("oxUtilsView")->addErrorToDisplay('MESSAGE_INVALID_EMAIL');
97 
98  return;
99  }
100 
101  $blSubscribe = oxRegistry::getConfig()->getRequestParameter("subscribeStatus");
102 
103  $oUser = oxNew('oxuser');
104  $oUser->oxuser__oxusername = new oxField($aParams['oxuser__oxusername'], oxField::T_RAW);
105 
106  $blUserLoaded = false;
107 
108  // if such user does not exist
109  if (!$oUser->exists()) {
110 
111  // and subscribe is off - error, on - create
112  if (!$blSubscribe) {
113 
114  oxRegistry::get("oxUtilsView")->addErrorToDisplay('NEWSLETTER_EMAIL_NOT_EXIST');
115 
116  return;
117 
118  } else {
119  $oUser->oxuser__oxactive = new oxField(1, oxField::T_RAW);
120  $oUser->oxuser__oxrights = new oxField('user', oxField::T_RAW);
121  $oUser->oxuser__oxshopid = new oxField($this->getConfig()->getShopId(), oxField::T_RAW);
122  $oUser->oxuser__oxfname = new oxField($aParams['oxuser__oxfname'], oxField::T_RAW);
123  $oUser->oxuser__oxlname = new oxField($aParams['oxuser__oxlname'], oxField::T_RAW);
124  $oUser->oxuser__oxsal = new oxField($aParams['oxuser__oxsal'], oxField::T_RAW);
125  $oUser->oxuser__oxcountryid = new oxField($aParams['oxuser__oxcountryid'], oxField::T_RAW);
126  $blUserLoaded = $oUser->save();
127  }
128 
129  } else {
130  $blUserLoaded = $oUser->load($oUser->getId());
131  }
132 
133 
134  // if user was added/loaded successfully and subscribe is on - subscribing to newsletter
135  if ($blSubscribe && $blUserLoaded) {
136  //removing user from subscribe list before adding
137  $oUser->setNewsSubscription(false, false);
138 
139  $blOrderOptInEmail = $this->getConfig()->getConfigParam('blOrderOptInEmail');
140  if ($oUser->setNewsSubscription(true, $blOrderOptInEmail)) {
141  // done, confirmation required?
142  if ($blOrderOptInEmail) {
143  $this->_iNewsletterStatus = 1;
144  } else {
145  $this->_iNewsletterStatus = 2;
146  }
147  } else {
148  oxRegistry::get("oxUtilsView")->addErrorToDisplay('MESSAGE_NOT_ABLE_TO_SEND_EMAIL');
149  }
150  } elseif (!$blSubscribe && $blUserLoaded) {
151  // unsubscribing user
152  $oUser->setNewsSubscription(false, false);
153  $this->_iNewsletterStatus = 3;
154  }
155  }
156 
163  public function addme()
164  {
165  // user exists ?
166  $oUser = oxNew('oxuser');
167  if ($oUser->load(oxRegistry::getConfig()->getRequestParameter('uid'))) {
168  $sConfirmCode = md5($oUser->oxuser__oxusername->value . $oUser->oxuser__oxpasssalt->value);
169  // is confirm code ok?
170  if (oxRegistry::getConfig()->getRequestParameter('confirm') == $sConfirmCode) {
171  $oUser->getNewsSubscription()->setOptInStatus(1);
172  $oUser->addToGroup('oxidnewsletter');
173  $this->_iNewsletterStatus = 2;
174  }
175  }
176  }
177 
181  public function removeme()
182  {
183  // existing user ?
184  $oUser = oxNew('oxuser');
185  if ($oUser->load(oxRegistry::getConfig()->getRequestParameter('uid'))) {
186  $oUser->getNewsSubscription()->setOptInStatus(0);
187 
188  // removing from group ..
189  $oUser->removeFromGroup('oxidnewsletter');
190 
191  $this->_iNewsletterStatus = 3;
192  }
193  }
194 
198  public function rmvm()
199  {
200  $this->removeme();
201  }
202 
208  public function getTopStartActionArticles()
209  {
210  if ($this->_oActionArticles === null) {
211  $this->_oActionArticles = false;
212  if ($this->getConfig()->getConfigParam('bl_perfLoadAktion')) {
213  $oArtList = oxNew('oxarticlelist');
214  $oArtList->loadActionArticles('OXTOPSTART');
215  if ($oArtList->count()) {
216  $this->_oTopArticle = $oArtList->current();
217  $this->_oActionArticles = $oArtList;
218  }
219  }
220  }
221 
223  }
224 
230  public function getTopStartArticle()
231  {
232  if ($this->_oTopArticle === null) {
233  $this->_oTopArticle = false;
234  if ($this->getTopStartActionArticles()) {
235  return $this->_oTopArticle;
236  }
237  }
238 
239  return $this->_oTopArticle;
240  }
241 
247  public function getHomeCountryId()
248  {
249  if ($this->_sHomeCountryId === null) {
250  $this->_sHomeCountryId = false;
251  $aHomeCountry = $this->getConfig()->getConfigParam('aHomeCountry');
252  if (is_array($aHomeCountry)) {
253  $this->_sHomeCountryId = current($aHomeCountry);
254  }
255  }
256 
257  return $this->_sHomeCountryId;
258  }
259 
265  public function getNewsletterStatus()
266  {
268  }
269 
275  public function getRegParams()
276  {
277  return $this->_aRegParams;
278  }
279 
285  public function getBreadCrumb()
286  {
287  $aPaths = array();
288  $aPath = array();
289  $iBaseLanguage = oxRegistry::getLang()->getBaseLanguage();
290  $aPath['title'] = oxRegistry::getLang()->translateString('STAY_INFORMED', $iBaseLanguage, false);
291  $aPath['link'] = $this->getLink();
292 
293  $aPaths[] = $aPath;
294 
295  return $aPaths;
296  }
297 
303  public function getTitle()
304  {
305  if ($this->getNewsletterStatus() == 4 || !$this->getNewsletterStatus()) {
306  $sConstant = 'STAY_INFORMED';
307  } elseif ($this->getNewsletterStatus() == 1) {
308  $sConstant = 'MESSAGE_THANKYOU_FOR_SUBSCRIBING_NEWSLETTERS';
309  } elseif ($this->getNewsletterStatus() == 2) {
310  $sConstant = 'MESSAGE_NEWSLETTER_CONGRATULATIONS';
311  } elseif ($this->getNewsletterStatus() == 3) {
312  $sConstant = 'SUCCESS';
313  }
314 
315  return oxRegistry::getLang()->translateString($sConstant, oxRegistry::getLang()->getBaseLanguage(), false);
316  }
317 }