OXID eShop CE  4.9.8
 All Classes Files Functions Variables Pages
guestbookentry.php
Go to the documentation of this file.
1 <?php
2 
7 class GuestbookEntry extends GuestBook
8 {
9 
15  protected $_sThisTemplate = 'page/guestbook/guestbookentry.tpl';
16 
22  protected $_sGbFormId = null;
23 
31  public function saveEntry()
32  {
33  if (!oxRegistry::getSession()->checkSessionChallenge()) {
34  return;
35  }
36 
37  $sReviewText = trim(( string ) oxRegistry::getConfig()->getRequestParameter('rvw_txt', true));
38  $sShopId = $this->getConfig()->getShopId();
39  $sUserId = oxRegistry::getSession()->getVariable('usr');
40 
41  // guest book`s entry is validated
42  if (!$sUserId) {
43  $sErrorMessage = 'ERROR_MESSAGE_GUESTBOOK_ENTRY_ERR_LOGIN_TO_WRITE_ENTRY';
44  oxRegistry::get("oxUtilsView")->addErrorToDisplay($sErrorMessage);
45 
46  //return to same page
47  return;
48  }
49 
50  if (!$sShopId) {
51  $sErrorMessage = 'ERROR_MESSAGE_GUESTBOOK_ENTRY_ERR_UNDEFINED_SHOP';
52  oxRegistry::get("oxUtilsView")->addErrorToDisplay($sErrorMessage);
53 
54  return 'guestbookentry';
55  }
56 
57  // empty entries validation
58  if ('' == $sReviewText) {
59  $sErrorMessage = 'ERROR_MESSAGE_GUESTBOOK_ENTRY_ERR_REVIEW_CONTAINS_NO_TEXT';
60  oxRegistry::get("oxUtilsView")->addErrorToDisplay($sErrorMessage);
61 
62  return 'guestbookentry';
63  }
64 
65  // flood protection
66  $oEntrie = oxNew('oxgbentry');
67  if ($oEntrie->floodProtection($sShopId, $sUserId)) {
68  $sErrorMessage = 'ERROR_MESSAGE_GUESTBOOK_ENTRY_ERR_MAXIMUM_NUMBER_EXCEEDED';
69  oxRegistry::get("oxUtilsView")->addErrorToDisplay($sErrorMessage);
70 
71  return 'guestbookentry';
72  }
73 
74  // double click protection
75  if ($this->canAcceptFormData()) {
76  // here the guest book entry is saved
77  $oEntry = oxNew('oxgbentry');
78  $oEntry->oxgbentries__oxshopid = new oxField($sShopId);
79  $oEntry->oxgbentries__oxuserid = new oxField($sUserId);
80  $oEntry->oxgbentries__oxcontent = new oxField($sReviewText);
81  $oEntry->save();
82  }
83 
84  return 'guestbook';
85  }
86 }