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