OXID eShop CE  4.8.12
 All Classes Files Functions Variables Pages
invite.php
Go to the documentation of this file.
1 <?php
2 
8 class Invite extends oxUBase
9 {
14  protected $_sThisTemplate = 'page/privatesales/invite.tpl';
15 
20  protected $_sThisLoginTemplate = 'page/account/login.tpl';
21 
26  protected $_aReqFields = array( 'rec_email', 'send_name', 'send_email', 'send_message', 'send_subject' );
27 
32  protected $_oCrossSelling = null;
33 
38  protected $_oSimilarProducts = null;
39 
44  protected $_oRecommList = null;
45 
50  protected $_aInviteData = null;
51 
56  protected $_oCaptcha = null;
57 
62  protected $_iMailStatus = null;
63 
69  public function render()
70  {
71  $oConfig = $this->getConfig();
72 
73  if ( !$oConfig->getConfigParam( "blInvitationsEnabled" ) ) {
74  oxRegistry::getUtils()->redirect( $oConfig->getShopHomeURL() );
75  return;
76  }
77 
79 
80  return $this->getUser() ? $this->_sThisTemplate : $this->_sThisLoginTemplate;
81  }
82 
89  public function send()
90  {
91  $oConfig = $this->getConfig();
92 
93  if ( !$oConfig->getConfigParam( "blInvitationsEnabled" ) ) {
94  oxRegistry::getUtils()->redirect( $oConfig->getShopHomeURL() );
95  }
96 
97  $aParams = oxConfig::getParameter( 'editval', true );
98  $oUser = $this->getUser();
99  if ( !is_array( $aParams ) || !$oUser ) {
100  return;
101  }
102 
103  // storing used written values
104  $oParams = (object) $aParams;
105  $this->setInviteData( (object) oxConfig::getParameter( 'editval' ) );
106 
107  // spam spider prevension
108  $sMac = oxConfig::getParameter( 'c_mac' );
109  $sMacHash = oxConfig::getParameter( 'c_mach' );
110  $oCaptcha = $this->getCaptcha();
111 
112  if ( !$oCaptcha->pass( $sMac, $sMacHash ) ) {
113  // even if there is no exception, use this as a default display method
114  oxRegistry::get("oxUtilsView")->addErrorToDisplay( 'MESSAGE_WRONG_VERIFICATION_CODE' );
115  return;
116  }
117 
118  $oUtilsView = oxRegistry::get("oxUtilsView");
119 
120  // filled not all fields ?
121  foreach ( $this->_aReqFields as $sFieldName ) {
122  //checking if any email was entered
123  if ( $sFieldName == "rec_email" ) {
124  foreach ( $aParams[$sFieldName] as $sKey => $sEmail ) {
125  //removing empty emails fields from eMails array
126  if ( empty( $sEmail ) ) {
127  unset( $aParams[$sFieldName][$sKey] );
128  }
129  }
130 
131  //counting entered eMails
132  if ( count( $aParams[$sFieldName] ) < 1 ) {
133  $oUtilsView->addErrorToDisplay('ERROR_MESSAGE_COMPLETE_FIELDS_CORRECTLY');
134  return;
135  }
136 
137  //updating values object
138  $oParams->rec_email = $aParams[$sFieldName];
139  }
140 
141  if ( !isset( $aParams[$sFieldName] ) || !$aParams[$sFieldName] ) {
142  $oUtilsView->addErrorToDisplay('ERROR_MESSAGE_COMPLETE_FIELDS_CORRECTLY');
143  return;
144  }
145  }
146 
147  $oUtils = oxRegistry::getUtils();
148 
149  //validating entered emails
150  foreach ( $aParams["rec_email"] as $sRecipientEmail ) {
151  if ( !$oUtils->isValidEmail( $sRecipientEmail ) ) {
152  $oUtilsView->addErrorToDisplay('ERROR_MESSAGE_INVITE_INCORRECTEMAILADDRESS');
153  return;
154  }
155  }
156 
157  if ( !$oUtils->isValidEmail( $aParams["send_email"] ) ) {
158  $oUtilsView->addErrorToDisplay('ERROR_MESSAGE_INVITE_INCORRECTEMAILADDRESS');
159  return;
160  }
161 
162  // sending invite email
163  $oEmail = oxNew( 'oxemail' );
164 
165  if ( $oEmail->sendInviteMail( $oParams ) ) {
166  $this->_iMailStatus = 1;
167 
168  //getting active user
169  $oUser = $this->getUser();
170 
171  //saving statistics for sent emails
172  $oUser->updateInvitationStatistics( $aParams["rec_email"] );
173  } else {
174  oxRegistry::get("oxUtilsView")->addErrorToDisplay('ERROR_MESSAGE_CHECK_EMAIL');
175  }
176  }
177 
183  public function getInviteSendStatus()
184  {
185  //checking if email was sent
186  if ( $this->_iMailStatus == 1 ) {
187  return true;
188  }
189  return false;
190  }
191 
199  public function setInviteData( $oData )
200  {
201  $this->_aInviteData = $oData;
202  }
203 
209  public function getInviteData()
210  {
211  return $this->_aInviteData;
212  }
213 
219  public function getCaptcha()
220  {
221  if ( $this->_oCaptcha === null ) {
222  $this->_oCaptcha = oxNew('oxCaptcha');
223  }
224  return $this->_oCaptcha;
225  }
226 
232  public function getBreadCrumb()
233  {
234  $aPaths = array();
235  $aPath = array();
236 
237  $aPath['title'] = oxRegistry::getLang()->translateString( 'INVITE_YOUR_FRIENDS', oxRegistry::getLang()->getBaseLanguage(), false );
238  $aPath['link'] = $this->getLink();
239  $aPaths[] = $aPath;
240 
241  return $aPaths;
242  }
243 
244 
245 }