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 
00077         if ( !$oCaptcha->pass( $sMac, $sMacHash ) ) {
00078             // even if there is no exception, use this as a default display method
00079             oxUtilsView::getInstance()->addErrorToDisplay( 'EXCEPTION_INPUT_WRONGCAPTCHA' );
00080             return false;
00081         }
00082 
00083         $oUtilsView = oxUtilsView::getInstance();
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         $sReturn = "";
00093         // #1834M - specialchar search
00094         $sSearchParamForLink = rawurlencode( oxConfig::getParameter( 'searchparam', true ) );
00095         if ( $sSearchParamForLink ) {
00096             $sReturn .= "&searchparam=$sSearchParamForLink";
00097         }
00098 
00099         $sSearchCatId = oxConfig::getParameter( 'searchcnid' );
00100         if ( $sSearchCatId ) {
00101             $sReturn .= "&searchcnid=$sSearchCatId";
00102         }
00103 
00104         $sSearchVendor = oxConfig::getParameter( 'searchvendor' );
00105         if ( $sSearchVendor ) {
00106             $sReturn .= "&searchvendor=$sSearchVendor";
00107         }
00108 
00109         if ( ( $sSearchManufacturer = oxConfig::getParameter( 'searchmanufacturer' ) ) ) {
00110             $sReturn .= "&searchmanufacturer=$sSearchManufacturer";
00111         }
00112 
00113         $sListType = oxConfig::getParameter( 'listtype' );
00114         if ( $sListType ) {
00115             $sReturn .= "&listtype=$sListType";
00116         }
00117 
00118         // sending suggest email
00119         $oEmail = oxNew( 'oxemail' );
00120         $oProduct = $this->getProduct();
00121         if ( $oProduct && $oEmail->sendSuggestMail( $oParams, $oProduct ) ) {
00122             return 'details?anid='.$oProduct->getId().$sReturn;
00123         } else {
00124             oxUtilsView::getInstance()->addErrorToDisplay('SUGGEST_INVALIDMAIL');
00125         }
00126     }
00127 
00133     public function getProduct()
00134     {
00135         if ( $this->_oProduct === null ) {
00136             $this->_oProduct = false;
00137 
00138             if ( $sAnid = oxConfig::getParameter( 'anid' ) ) {
00139                 $this->_oProduct = oxNewArticle( $sAnid );
00140             }
00141         }
00142         return $this->_oProduct;
00143     }
00144 
00150     public function getCrossSelling()
00151     {
00152         if ( $this->_oCrossSelling === null ) {
00153             $this->_oCrossSelling = false;
00154             if ( $oProduct = $this->getProduct() ) {
00155                 $this->_oCrossSelling = $oProduct->getCrossSelling();
00156             }
00157         }
00158         return $this->_oCrossSelling;
00159     }
00160 
00166     public function getSimilarProducts()
00167     {
00168         if ( $this->_oSimilarProducts === null ) {
00169             $this->_oSimilarProducts = false;
00170             if ( $oProduct = $this->getProduct() ) {
00171                 $this->_oSimilarProducts = $oProduct->getSimilarProducts();
00172             }
00173         }
00174         return $this->_oSimilarProducts;
00175     }
00176 
00182     public function getRecommList()
00183     {
00184         if (!$this->getViewConfig()->getShowListmania()) {
00185             return false;
00186         }
00187 
00188         if ( $this->_oRecommList === null ) {
00189             $this->_oRecommList = false;
00190             if ( $oProduct = $this->getProduct() ) {
00191                 $oRecommList = oxNew('oxrecommlist');
00192                 $this->_oRecommList = $oRecommList->getRecommListsByIds( array( $oProduct->getId() ) );
00193             }
00194         }
00195         return $this->_oRecommList;
00196     }
00197 
00205     public function setSuggestData( $oData )
00206     {
00207         $this->_aSuggestData = $oData;
00208     }
00209 
00215     public function getSuggestData()
00216     {
00217         return $this->_aSuggestData;
00218     }
00219 
00227     public function getLink( $iLang = null )
00228     {
00229         $sLink = parent::getLink( $iLang );
00230 
00231         // active category
00232         if ( $sVal = oxConfig::getParameter( 'cnid' ) ) {
00233             $sLink .= ( ( strpos( $sLink, '?' ) === false ) ? '?' : '&amp;' ) . "cnid={$sVal}";
00234         }
00235 
00236         // active article
00237         if ( $sVal= oxConfig::getParameter( 'anid' ) ) {
00238             $sLink .= ( ( strpos( $sLink, '?' ) === false ) ? '?' : '&amp;' ) . "anid={$sVal}";
00239         }
00240 
00241         return $sLink;
00242     }
00243 
00249     public function getCaptcha()
00250     {
00251         if ( $this->_oCaptcha === null ) {
00252             $this->_oCaptcha = oxNew('oxCaptcha');
00253         }
00254         return $this->_oCaptcha;
00255     }
00256 
00262     public function getBreadCrumb()
00263     {
00264         $aPaths = array();
00265         $aPath  = array();
00266         $aPath['title'] = oxLang::getInstance()->translateString( 'PAGE_INFO_SUGGEST_TITLE', oxLang::getInstance()->getBaseLanguage(), false );
00267         $aPath['link']  = $this->getLink();
00268 
00269         $aPaths[] = $aPath;
00270 
00271         return $aPaths;
00272     }
00273 
00274 }