guestbookentry.php

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