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 = oxRegistry::get("oxUtilsView");
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 = oxRegistry::getUtils();
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 ( $sProductId = $this->getConfig()->getRequestParameter( 'anid' ) ) {
00145                 $oProduct = oxNew( 'oxArticle' );
00146                 $oProduct->load( $sProductId );
00147                 $this->_oProduct = $oProduct;
00148             }
00149         }
00150         return $this->_oProduct;
00151     }
00152 
00158     public function getCrossSelling()
00159     {
00160         if ( $this->_oCrossSelling === null ) {
00161             $this->_oCrossSelling = false;
00162             if ( $oProduct = $this->getProduct() ) {
00163                 $this->_oCrossSelling = $oProduct->getCrossSelling();
00164             }
00165         }
00166         return $this->_oCrossSelling;
00167     }
00168 
00174     public function getSimilarProducts()
00175     {
00176         if ( $this->_oSimilarProducts === null ) {
00177             $this->_oSimilarProducts = false;
00178             if ( $oProduct = $this->getProduct() ) {
00179                 $this->_oSimilarProducts = $oProduct->getSimilarProducts();
00180             }
00181         }
00182         return $this->_oSimilarProducts;
00183     }
00184 
00190     public function getRecommList()
00191     {
00192         if (!$this->getViewConfig()->getShowListmania()) {
00193             return false;
00194         }
00195 
00196         if ( $this->_oRecommList === null ) {
00197             $this->_oRecommList = false;
00198             if ( $oProduct = $this->getProduct() ) {
00199                 $oRecommList = oxNew('oxrecommlist');
00200                 $this->_oRecommList = $oRecommList->getRecommListsByIds( array( $oProduct->getId() ) );
00201             }
00202         }
00203         return $this->_oRecommList;
00204     }
00205 
00213     public function setSuggestData( $oData )
00214     {
00215         $this->_aSuggestData = $oData;
00216     }
00217 
00223     public function getSuggestData()
00224     {
00225         return $this->_aSuggestData;
00226     }
00227 
00235     public function getLink( $iLang = null )
00236     {
00237         $sLink = parent::getLink( $iLang );
00238 
00239         // active category
00240         if ( $sVal = oxConfig::getParameter( 'cnid' ) ) {
00241             $sLink .= ( ( strpos( $sLink, '?' ) === false ) ? '?' : '&amp;' ) . "cnid={$sVal}";
00242         }
00243 
00244         // active article
00245         if ( $sVal= oxConfig::getParameter( 'anid' ) ) {
00246             $sLink .= ( ( strpos( $sLink, '?' ) === false ) ? '?' : '&amp;' ) . "anid={$sVal}";
00247         }
00248 
00249         return $sLink;
00250     }
00251 
00257     public function getCaptcha()
00258     {
00259         if ( $this->_oCaptcha === null ) {
00260             $this->_oCaptcha = oxNew('oxCaptcha');
00261         }
00262         return $this->_oCaptcha;
00263     }
00264 
00270     public function getBreadCrumb()
00271     {
00272         $aPaths = array();
00273         $aPath  = array();
00274         $aPath['title'] = oxRegistry::getLang()->translateString( 'PAGE_INFO_SUGGEST_TITLE', oxRegistry::getLang()->getBaseLanguage(), false );
00275         $aPath['link']  = $this->getLink();
00276 
00277         $aPaths[] = $aPath;
00278 
00279         return $aPaths;
00280     }
00281 
00282 }