suggest.php

Go to the documentation of this file.
00001 <?php
00002 
00008 class Suggest extends oxUBase
00009 {
00014     protected $_sThisTemplate = 'page/info/suggest.tpl';
00015 
00020     protected $_aReqFields = array( 'rec_name', 'rec_email', 'send_name', 'send_email', 'send_message', 'send_subject' );
00021 
00026     protected $_oCrossSelling = null;
00027 
00032     protected $_oSimilarProducts = null;
00033 
00038     protected $_oRecommList = null;
00039 
00044     protected $_aSuggestData = null;
00045 
00050     protected $_oCaptcha = null;
00051 
00061     public function send()
00062     {
00063         $aParams = oxConfig::getParameter( 'editval', true );
00064         if ( !is_array( $aParams ) ) {
00065             return;
00066         }
00067 
00068         // storing used written values
00069         $oParams = (object) $aParams;
00070         $this->setSuggestData( (object) oxConfig::getParameter( 'editval' ) );
00071 
00072         // spam spider prevension
00073         $sMac     = oxConfig::getParameter( 'c_mac' );
00074         $sMacHash = oxConfig::getParameter( 'c_mach' );
00075         $oCaptcha = $this->getCaptcha();
00076         $oUtilsView = oxUtilsView::getInstance();
00077 
00078         if ( !$oCaptcha->pass( $sMac, $sMacHash ) ) {
00079             // even if there is no exception, use this as a default display method
00080             $oUtilsView->addErrorToDisplay( 'EXCEPTION_INPUT_WRONGCAPTCHA' );
00081             return false;
00082         }
00083 
00084         // filled not all fields ?
00085         foreach ( $this->_aReqFields as $sFieldName ) {
00086             if ( !isset( $aParams[$sFieldName] ) || !$aParams[$sFieldName] ) {
00087                 $oUtilsView->addErrorToDisplay( 'SUGGEST_COMLETECORRECTLYFIELDS' );
00088                 return;
00089             }
00090         }
00091 
00092         $oUtils = oxUtils::getInstance();
00093         if ( !$oUtils->isValidEmail( $aParams["rec_email"] ) || !$oUtils->isValidEmail( $aParams["send_email"] ) ) {
00094             $oUtilsView->addErrorToDisplay( 'SUGGEST_INVALIDMAIL' );
00095             return;
00096         }
00097 
00098         $sReturn = "";
00099         // #1834M - specialchar search
00100         $sSearchParamForLink = rawurlencode( oxConfig::getParameter( 'searchparam', true ) );
00101         if ( $sSearchParamForLink ) {
00102             $sReturn .= "&searchparam=$sSearchParamForLink";
00103         }
00104 
00105         $sSearchCatId = oxConfig::getParameter( 'searchcnid' );
00106         if ( $sSearchCatId ) {
00107             $sReturn .= "&searchcnid=$sSearchCatId";
00108         }
00109 
00110         $sSearchVendor = oxConfig::getParameter( 'searchvendor' );
00111         if ( $sSearchVendor ) {
00112             $sReturn .= "&searchvendor=$sSearchVendor";
00113         }
00114 
00115         if ( ( $sSearchManufacturer = oxConfig::getParameter( 'searchmanufacturer' ) ) ) {
00116             $sReturn .= "&searchmanufacturer=$sSearchManufacturer";
00117         }
00118 
00119         $sListType = oxConfig::getParameter( 'listtype' );
00120         if ( $sListType ) {
00121             $sReturn .= "&listtype=$sListType";
00122         }
00123 
00124         // sending suggest email
00125         $oEmail = oxNew( 'oxemail' );
00126         $oProduct = $this->getProduct();
00127         if ( $oProduct && $oEmail->sendSuggestMail( $oParams, $oProduct ) ) {
00128             return 'details?anid='.$oProduct->getId().$sReturn;
00129         } else {
00130             $oUtilsView->addErrorToDisplay('SUGGEST_INVALIDMAIL');
00131         }
00132     }
00133 
00139     public function getProduct()
00140     {
00141         if ( $this->_oProduct === null ) {
00142             $this->_oProduct = false;
00143 
00144             if ( $sAnid = oxConfig::getParameter( 'anid' ) ) {
00145                 $this->_oProduct = oxNewArticle( $sAnid );
00146             }
00147         }
00148         return $this->_oProduct;
00149     }
00150 
00156     public function getCrossSelling()
00157     {
00158         if ( $this->_oCrossSelling === null ) {
00159             $this->_oCrossSelling = false;
00160             if ( $oProduct = $this->getProduct() ) {
00161                 $this->_oCrossSelling = $oProduct->getCrossSelling();
00162             }
00163         }
00164         return $this->_oCrossSelling;
00165     }
00166 
00172     public function getSimilarProducts()
00173     {
00174         if ( $this->_oSimilarProducts === null ) {
00175             $this->_oSimilarProducts = false;
00176             if ( $oProduct = $this->getProduct() ) {
00177                 $this->_oSimilarProducts = $oProduct->getSimilarProducts();
00178             }
00179         }
00180         return $this->_oSimilarProducts;
00181     }
00182 
00188     public function getRecommList()
00189     {
00190         if (!$this->getViewConfig()->getShowListmania()) {
00191             return false;
00192         }
00193 
00194         if ( $this->_oRecommList === null ) {
00195             $this->_oRecommList = false;
00196             if ( $oProduct = $this->getProduct() ) {
00197                 $oRecommList = oxNew('oxrecommlist');
00198                 $this->_oRecommList = $oRecommList->getRecommListsByIds( array( $oProduct->getId() ) );
00199             }
00200         }
00201         return $this->_oRecommList;
00202     }
00203 
00211     public function setSuggestData( $oData )
00212     {
00213         $this->_aSuggestData = $oData;
00214     }
00215 
00221     public function getSuggestData()
00222     {
00223         return $this->_aSuggestData;
00224     }
00225 
00233     public function getLink( $iLang = null )
00234     {
00235         $sLink = parent::getLink( $iLang );
00236 
00237         // active category
00238         if ( $sVal = oxConfig::getParameter( 'cnid' ) ) {
00239             $sLink .= ( ( strpos( $sLink, '?' ) === false ) ? '?' : '&amp;' ) . "cnid={$sVal}";
00240         }
00241 
00242         // active article
00243         if ( $sVal= oxConfig::getParameter( 'anid' ) ) {
00244             $sLink .= ( ( strpos( $sLink, '?' ) === false ) ? '?' : '&amp;' ) . "anid={$sVal}";
00245         }
00246 
00247         return $sLink;
00248     }
00249 
00255     public function getCaptcha()
00256     {
00257         if ( $this->_oCaptcha === null ) {
00258             $this->_oCaptcha = oxNew('oxCaptcha');
00259         }
00260         return $this->_oCaptcha;
00261     }
00262 
00268     public function getBreadCrumb()
00269     {
00270         $aPaths = array();
00271         $aPath  = array();
00272         $aPath['title'] = oxLang::getInstance()->translateString( 'PAGE_INFO_SUGGEST_TITLE', oxLang::getInstance()->getBaseLanguage(), false );
00273         $aPath['link']  = $this->getLink();
00274 
00275         $aPaths[] = $aPath;
00276 
00277         return $aPaths;
00278     }
00279 
00280 }