OXID eShop CE  4.9.10
 All Classes Files Functions Variables Pages
invite.php
Go to the documentation of this file.
1 <?php
2 
8 class Invite extends oxUBase
9 {
10 
16  protected $_sThisTemplate = 'page/privatesales/invite.tpl';
17 
23  protected $_sThisLoginTemplate = 'page/account/login.tpl';
24 
30  protected $_aReqFields = array('rec_email', 'send_name', 'send_email', 'send_message', 'send_subject');
31 
37  protected $_oCrossSelling = null;
38 
44  protected $_oSimilarProducts = null;
45 
51  protected $_oRecommList = null;
52 
58  protected $_aInviteData = null;
59 
65  protected $_oCaptcha = null;
66 
72  protected $_iMailStatus = null;
73 
79  public function render()
80  {
81  $oConfig = $this->getConfig();
82 
83  if (!$oConfig->getConfigParam("blInvitationsEnabled")) {
84  oxRegistry::getUtils()->redirect($oConfig->getShopHomeURL());
85 
86  return;
87  }
88 
90 
91  return $this->getUser() ? $this->_sThisTemplate : $this->_sThisLoginTemplate;
92  }
93 
100  public function send()
101  {
102  $oConfig = $this->getConfig();
103 
104  if (!$oConfig->getConfigParam("blInvitationsEnabled")) {
105  oxRegistry::getUtils()->redirect($oConfig->getShopHomeURL());
106  }
107 
108  $aParams = oxRegistry::getConfig()->getRequestParameter('editval', true);
109  $oUser = $this->getUser();
110  if (!is_array($aParams) || !$oUser) {
111  return;
112  }
113 
114  // storing used written values
115  $oParams = (object) $aParams;
116  $this->setInviteData((object) oxRegistry::getConfig()->getRequestParameter('editval'));
117 
118  // spam spider prevension
119  $sMac = oxRegistry::getConfig()->getRequestParameter('c_mac');
120  $sMacHash = oxRegistry::getConfig()->getRequestParameter('c_mach');
121  $oCaptcha = $this->getCaptcha();
122 
123  if (!$oCaptcha->pass($sMac, $sMacHash)) {
124  // even if there is no exception, use this as a default display method
125  oxRegistry::get("oxUtilsView")->addErrorToDisplay('MESSAGE_WRONG_VERIFICATION_CODE');
126 
127  return;
128  }
129 
130  $oUtilsView = oxRegistry::get("oxUtilsView");
131 
132  // filled not all fields ?
133  foreach ($this->_aReqFields as $sFieldName) {
134  //checking if any email was entered
135  if ($sFieldName == "rec_email") {
136  foreach ($aParams[$sFieldName] as $sKey => $sEmail) {
137  //removing empty emails fields from eMails array
138  if (empty($sEmail)) {
139  unset($aParams[$sFieldName][$sKey]);
140  }
141  }
142 
143  //counting entered eMails
144  if (count($aParams[$sFieldName]) < 1) {
145  $oUtilsView->addErrorToDisplay('ERROR_MESSAGE_COMPLETE_FIELDS_CORRECTLY');
146 
147  return;
148  }
149 
150  //updating values object
151  $oParams->rec_email = $aParams[$sFieldName];
152  }
153 
154  if (!isset($aParams[$sFieldName]) || !$aParams[$sFieldName]) {
155  $oUtilsView->addErrorToDisplay('ERROR_MESSAGE_COMPLETE_FIELDS_CORRECTLY');
156 
157  return;
158  }
159  }
160 
161  $oUtils = oxRegistry::getUtils();
162 
163  //validating entered emails
164  foreach ($aParams["rec_email"] as $sRecipientEmail) {
165  if (!$oUtils->isValidEmail($sRecipientEmail)) {
166  $oUtilsView->addErrorToDisplay('ERROR_MESSAGE_INVITE_INCORRECTEMAILADDRESS');
167 
168  return;
169  }
170  }
171 
172  if (!$oUtils->isValidEmail($aParams["send_email"])) {
173  $oUtilsView->addErrorToDisplay('ERROR_MESSAGE_INVITE_INCORRECTEMAILADDRESS');
174 
175  return;
176  }
177 
178  // sending invite email
179  $oEmail = oxNew('oxemail');
180 
181  if ($oEmail->sendInviteMail($oParams)) {
182  $this->_iMailStatus = 1;
183 
184  //getting active user
185  $oUser = $this->getUser();
186 
187  //saving statistics for sent emails
188  $oUser->updateInvitationStatistics($aParams["rec_email"]);
189  } else {
190  oxRegistry::get("oxUtilsView")->addErrorToDisplay('ERROR_MESSAGE_CHECK_EMAIL');
191  }
192  }
193 
199  public function getInviteSendStatus()
200  {
201  //checking if email was sent
202  if ($this->_iMailStatus == 1) {
203  return true;
204  }
205 
206  return false;
207  }
208 
214  public function setInviteData($oData)
215  {
216  $this->_aInviteData = $oData;
217  }
218 
224  public function getInviteData()
225  {
226  return $this->_aInviteData;
227  }
228 
234  public function getCaptcha()
235  {
236  if ($this->_oCaptcha === null) {
237  $this->_oCaptcha = oxNew('oxCaptcha');
238  }
239 
240  return $this->_oCaptcha;
241  }
242 
248  public function getBreadCrumb()
249  {
250  $aPaths = array();
251  $aPath = array();
252 
253  $iLang = oxRegistry::getLang()->getBaseLanguage();
254  $aPath['title'] = oxRegistry::getLang()->translateString('INVITE_YOUR_FRIENDS', $iLang, false);
255  $aPath['link'] = $this->getLink();
256  $aPaths[] = $aPath;
257 
258  return $aPaths;
259  }
260 }