OXID eShop CE  4.8.12
 All Classes Files Functions Variables Pages
newsletter.php
Go to the documentation of this file.
1 <?php
2 
9 class Newsletter extends oxUBase
10 {
15  protected $_oActionArticles = null;
16 
21  protected $_oTopArticle = null;
22 
27  protected $_sHomeCountryId = null;
28 
33  protected $_iNewsletterStatus = null;
34 
39  protected $_aRegParams = null;
40 
45  protected $_sThisTemplate = 'page/info/newsletter.tpl';
46 
53 
62  public function fill()
63  {
64  // loads submited values
65  $this->_aRegParams = oxConfig::getParameter( "editval" );
66  }
67 
78  public function send()
79  {
80  $aParams = oxConfig::getParameter("editval");
81 
82  // loads submited values
83  $this->_aRegParams = $aParams;
84 
85  if ( !$aParams['oxuser__oxusername'] ) {
86  oxRegistry::get("oxUtilsView")->addErrorToDisplay('ERROR_MESSAGE_COMPLETE_FIELDS_CORRECTLY');
87  return;
88  } elseif ( !oxRegistry::getUtils()->isValidEmail( $aParams['oxuser__oxusername'] ) ) {
89  // #1052C - eMail validation added
90  oxRegistry::get("oxUtilsView")->addErrorToDisplay('MESSAGE_INVALID_EMAIL');
91  return;
92  }
93 
94  $blSubscribe = oxConfig::getParameter("subscribeStatus");
95 
96  $oUser = oxNew( 'oxuser' );
97  $oUser->oxuser__oxusername = new oxField($aParams['oxuser__oxusername'], oxField::T_RAW);
98 
99  $blUserLoaded = false;
100 
101  // if such user does not exist
102  if ( !$oUser->exists() ) {
103 
104  // and subscribe is off - error, on - create
105  if ( !$blSubscribe ) {
106 
107  oxRegistry::get("oxUtilsView")->addErrorToDisplay('NEWSLETTER_EMAIL_NOT_EXIST');
108  return;
109 
110  } else {
111  $oUser->oxuser__oxactive = new oxField(1, oxField::T_RAW);
112  $oUser->oxuser__oxrights = new oxField('user', oxField::T_RAW);
113  $oUser->oxuser__oxshopid = new oxField($this->getConfig()->getShopId(), oxField::T_RAW);
114  $oUser->oxuser__oxfname = new oxField($aParams['oxuser__oxfname'], oxField::T_RAW);
115  $oUser->oxuser__oxlname = new oxField($aParams['oxuser__oxlname'], oxField::T_RAW);
116  $oUser->oxuser__oxsal = new oxField($aParams['oxuser__oxsal'], oxField::T_RAW);
117  $oUser->oxuser__oxcountryid = new oxField($aParams['oxuser__oxcountryid'], oxField::T_RAW);
118  $blUserLoaded = $oUser->save();
119  }
120 
121  } else {
122  $blUserLoaded = $oUser->load( $oUser->getId() );
123  }
124 
125 
126 
127  // if user was added/loaded successfully and subscribe is on - subscribing to newsletter
128  if ( $blSubscribe && $blUserLoaded ) {
129  //removing user from subscribe list before adding
130  $oUser->setNewsSubscription( false, false );
131 
132  $blOrderOptInEmail = $this->getConfig()->getConfigParam( 'blOrderOptInEmail' );
133  if ( $oUser->setNewsSubscription( true, $blOrderOptInEmail ) ) {
134  // done, confirmation required?
135  if ( $blOrderOptInEmail ) {
136  $this->_iNewsletterStatus = 1;
137  } else {
138  $this->_iNewsletterStatus = 2;
139  }
140  } else {
141  oxRegistry::get("oxUtilsView")->addErrorToDisplay('MESSAGE_NOT_ABLE_TO_SEND_EMAIL');
142  }
143  } elseif ( !$blSubscribe && $blUserLoaded ) {
144  // unsubscribing user
145  $oUser->setNewsSubscription( false, false );
146  $this->_iNewsletterStatus = 3;
147  }
148  }
149 
158  public function addme()
159  {
160  // user exists ?
161  $oUser = oxNew( 'oxuser' );
162  if ( $oUser->load( oxRegistry::getConfig()->getRequestParameter( 'uid' ) ) ) {
163  $sConfirmCode = md5($oUser->oxuser__oxusername->value.$oUser->oxuser__oxpasssalt->value);
164  // is confirm code ok?
165  if ( oxRegistry::getConfig()->getRequestParameter( 'confirm' ) == $sConfirmCode ) {
166  $oUser->getNewsSubscription()->setOptInStatus( 1 );
167  $oUser->addToGroup( 'oxidnewsletter' );
168  $this->_iNewsletterStatus = 2;
169  }
170  }
171  }
172 
178  public function removeme()
179  {
180  // existing user ?
181  $oUser = oxNew( 'oxuser' );
182  if ( $oUser->load( oxConfig::getParameter( 'uid' ) ) ) {
183  $oUser->getNewsSubscription()->setOptInStatus( 0 );
184 
185  // removing from group ..
186  $oUser->removeFromGroup( 'oxidnewsletter' );
187 
188  $this->_iNewsletterStatus = 3;
189  }
190  }
191 
197  public function rmvm()
198  {
199  $this->removeme();
200  }
201 
207  public function getTopStartActionArticles()
208  {
209  if ( $this->_oActionArticles === null ) {
210  $this->_oActionArticles = false;
211  if ( $this->getConfig()->getConfigParam( 'bl_perfLoadAktion' ) ) {
212  $oArtList = oxNew( 'oxarticlelist' );
213  $oArtList->loadActionArticles( 'OXTOPSTART' );
214  if ( $oArtList->count() ) {
215  $this->_oTopArticle = $oArtList->current();
216  $this->_oActionArticles = $oArtList;
217  }
218  }
219  }
221  }
222 
228  public function getTopStartArticle()
229  {
230  if ( $this->_oTopArticle === null ) {
231  $this->_oTopArticle = false;
232  if ( $this->getTopStartActionArticles() ) {
233  return $this->_oTopArticle;
234  }
235  }
236  return $this->_oTopArticle;
237  }
238 
244  public function getHomeCountryId()
245  {
246  if ( $this->_sHomeCountryId === null ) {
247  $this->_sHomeCountryId = false;
248  $aHomeCountry = $this->getConfig()->getConfigParam( 'aHomeCountry' );
249  if ( is_array( $aHomeCountry ) ) {
250  $this->_sHomeCountryId = current( $aHomeCountry );
251  }
252  }
253  return $this->_sHomeCountryId;
254  }
255 
261  public function getNewsletterStatus()
262  {
264  }
265 
271  public function getRegParams()
272  {
273  return $this->_aRegParams;
274  }
275 
281  public function getBreadCrumb()
282  {
283  $aPaths = array();
284  $aPath = array();
285  $aPath['title'] = oxRegistry::getLang()->translateString( 'STAY_INFORMED', oxRegistry::getLang()->getBaseLanguage(), false );
286  $aPath['link'] = $this->getLink();
287 
288  $aPaths[] = $aPath;
289  return $aPaths;
290  }
291 }