OXID eShop CE  4.10.7
 All Classes Namespaces 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 
53  protected $_oRecommList = null;
54 
60  protected $_aInviteData = null;
61 
69  protected $_oCaptcha = null;
70 
76  protected $_iMailStatus = null;
77 
83  public function render()
84  {
85  $oConfig = $this->getConfig();
86 
87  if (!$oConfig->getConfigParam("blInvitationsEnabled")) {
88  oxRegistry::getUtils()->redirect($oConfig->getShopHomeURL());
89 
90  return;
91  }
92 
94 
95  return $this->getUser() ? $this->_sThisTemplate : $this->_sThisLoginTemplate;
96  }
97 
104  public function send()
105  {
106  $oConfig = $this->getConfig();
107 
108  if (!$oConfig->getConfigParam("blInvitationsEnabled")) {
109  oxRegistry::getUtils()->redirect($oConfig->getShopHomeURL());
110  }
111 
112  $aParams = oxRegistry::getConfig()->getRequestParameter('editval', true);
113  $oUser = $this->getUser();
114  if (!is_array($aParams) || !$oUser) {
115  return;
116  }
117 
118  // storing used written values
119  $oParams = (object) $aParams;
120  $this->setInviteData((object) oxRegistry::getConfig()->getRequestParameter('editval'));
121 
122  // spam spider prevension
123  $sMac = oxRegistry::getConfig()->getRequestParameter('c_mac');
124  $sMacHash = oxRegistry::getConfig()->getRequestParameter('c_mach');
125  $oCaptcha = $this->getCaptcha();
126 
127  if (!$oCaptcha->pass($sMac, $sMacHash)) {
128  // even if there is no exception, use this as a default display method
129  oxRegistry::get("oxUtilsView")->addErrorToDisplay('MESSAGE_WRONG_VERIFICATION_CODE');
130 
131  return;
132  }
133 
134  $oUtilsView = oxRegistry::get("oxUtilsView");
135 
136  // filled not all fields ?
137  foreach ($this->_aReqFields as $sFieldName) {
138  //checking if any email was entered
139  if ($sFieldName == "rec_email") {
140  foreach ($aParams[$sFieldName] as $sKey => $sEmail) {
141  //removing empty emails fields from eMails array
142  if (empty($sEmail)) {
143  unset($aParams[$sFieldName][$sKey]);
144  }
145  }
146 
147  //counting entered eMails
148  if (count($aParams[$sFieldName]) < 1) {
149  $oUtilsView->addErrorToDisplay('ERROR_MESSAGE_COMPLETE_FIELDS_CORRECTLY');
150 
151  return;
152  }
153 
154  //updating values object
155  $oParams->rec_email = $aParams[$sFieldName];
156  }
157 
158  if (!isset($aParams[$sFieldName]) || !$aParams[$sFieldName]) {
159  $oUtilsView->addErrorToDisplay('ERROR_MESSAGE_COMPLETE_FIELDS_CORRECTLY');
160 
161  return;
162  }
163  }
164 
165  $oUtils = oxRegistry::getUtils();
166 
167  //validating entered emails
168  foreach ($aParams["rec_email"] as $sRecipientEmail) {
169  if (!$oUtils->isValidEmail($sRecipientEmail)) {
170  $oUtilsView->addErrorToDisplay('ERROR_MESSAGE_INVITE_INCORRECTEMAILADDRESS');
171 
172  return;
173  }
174  }
175 
176  if (!$oUtils->isValidEmail($aParams["send_email"])) {
177  $oUtilsView->addErrorToDisplay('ERROR_MESSAGE_INVITE_INCORRECTEMAILADDRESS');
178 
179  return;
180  }
181 
182  // sending invite email
183  $oEmail = oxNew('oxemail');
184 
185  if ($oEmail->sendInviteMail($oParams)) {
186  $this->_iMailStatus = 1;
187 
188  //getting active user
189  $oUser = $this->getUser();
190 
191  //saving statistics for sent emails
192  $oUser->updateInvitationStatistics($aParams["rec_email"]);
193  } else {
194  oxRegistry::get("oxUtilsView")->addErrorToDisplay('ERROR_MESSAGE_CHECK_EMAIL');
195  }
196  }
197 
203  public function getInviteSendStatus()
204  {
205  //checking if email was sent
206  if ($this->_iMailStatus == 1) {
207  return true;
208  }
209 
210  return false;
211  }
212 
218  public function setInviteData($oData)
219  {
220  $this->_aInviteData = $oData;
221  }
222 
228  public function getInviteData()
229  {
230  return $this->_aInviteData;
231  }
232 
240  public function getCaptcha()
241  {
242  if ($this->_oCaptcha === null) {
243  $this->_oCaptcha = oxNew('oxCaptcha');
244  }
245 
246  return $this->_oCaptcha;
247  }
248 
254  public function getBreadCrumb()
255  {
256  $aPaths = array();
257  $aPath = array();
258 
259  $iLang = oxRegistry::getLang()->getBaseLanguage();
260  $aPath['title'] = oxRegistry::getLang()->translateString('INVITE_YOUR_FRIENDS', $iLang, false);
261  $aPath['link'] = $this->getLink();
262  $aPaths[] = $aPath;
263 
264  return $aPaths;
265  }
266 }