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