guestbookentry.php

Go to the documentation of this file.
00001 <?php
00002 
00007 class GuestbookEntry extends GuestBook
00008 {
00009 
00015     protected $_sThisTemplate = 'page/guestbook/guestbookentry.tpl';
00016 
00022     protected $_sGbFormId = null;
00023 
00031     public function saveEntry()
00032     {
00033         if (!oxRegistry::getSession()->checkSessionChallenge()) {
00034             return;
00035         }
00036 
00037         $sReviewText = trim(( string ) oxRegistry::getConfig()->getRequestParameter('rvw_txt', true));
00038         $sShopId = $this->getConfig()->getShopId();
00039         $sUserId = oxRegistry::getSession()->getVariable('usr');
00040 
00041         // guest book`s entry is validated
00042         if (!$sUserId) {
00043             $sErrorMessage = 'ERROR_MESSAGE_GUESTBOOK_ENTRY_ERR_LOGIN_TO_WRITE_ENTRY';
00044             oxRegistry::get("oxUtilsView")->addErrorToDisplay($sErrorMessage);
00045 
00046             //return to same page
00047             return;
00048         }
00049 
00050         if (!$sShopId) {
00051             $sErrorMessage = 'ERROR_MESSAGE_GUESTBOOK_ENTRY_ERR_UNDEFINED_SHOP';
00052             oxRegistry::get("oxUtilsView")->addErrorToDisplay($sErrorMessage);
00053 
00054             return 'guestbookentry';
00055         }
00056 
00057         // empty entries validation
00058         if ('' == $sReviewText) {
00059             $sErrorMessage = 'ERROR_MESSAGE_GUESTBOOK_ENTRY_ERR_REVIEW_CONTAINS_NO_TEXT';
00060             oxRegistry::get("oxUtilsView")->addErrorToDisplay($sErrorMessage);
00061 
00062             return 'guestbookentry';
00063         }
00064 
00065         // flood protection
00066         $oEntrie = oxNew('oxgbentry');
00067         if ($oEntrie->floodProtection($sShopId, $sUserId)) {
00068             $sErrorMessage = 'ERROR_MESSAGE_GUESTBOOK_ENTRY_ERR_MAXIMUM_NUMBER_EXCEEDED';
00069             oxRegistry::get("oxUtilsView")->addErrorToDisplay($sErrorMessage);
00070 
00071             return 'guestbookentry';
00072         }
00073 
00074         // double click protection
00075         if ($this->canAcceptFormData()) {
00076             // here the guest book entry is saved
00077             $oEntry = oxNew('oxgbentry');
00078             $oEntry->oxgbentries__oxshopid = new oxField($sShopId);
00079             $oEntry->oxgbentries__oxuserid = new oxField($sUserId);
00080             $oEntry->oxgbentries__oxcontent = new oxField($sReviewText);
00081             $oEntry->save();
00082         }
00083 
00084         return 'guestbook';
00085     }
00086 }