suggest.php

Go to the documentation of this file.
00001 <?php
00002 
00008 class Suggest extends oxUBase
00009 {
00010 
00016     protected $_sThisTemplate = 'page/info/suggest.tpl';
00017 
00023     protected $_aReqFields = array('rec_name', 'rec_email', 'send_name', 'send_email', 'send_message', 'send_subject');
00024 
00030     protected $_oCrossSelling = null;
00031 
00037     protected $_oSimilarProducts = null;
00038 
00044     protected $_oRecommList = null;
00045 
00051     protected $_aSuggestData = null;
00052 
00058     protected $_oCaptcha = null;
00059 
00069     public function send()
00070     {
00071         $aParams = oxRegistry::getConfig()->getRequestParameter('editval', true);
00072         if (!is_array($aParams)) {
00073             return;
00074         }
00075 
00076         // storing used written values
00077         $oParams = (object) $aParams;
00078         $this->setSuggestData((object) oxRegistry::getConfig()->getRequestParameter('editval'));
00079 
00080         // spam spider prevension
00081         $sMac = oxRegistry::getConfig()->getRequestParameter('c_mac');
00082         $sMacHash = oxRegistry::getConfig()->getRequestParameter('c_mach');
00083         $oCaptcha = $this->getCaptcha();
00084         $oUtilsView = oxRegistry::get("oxUtilsView");
00085 
00086         if (!$oCaptcha->pass($sMac, $sMacHash)) {
00087             // even if there is no exception, use this as a default display method
00088             $oUtilsView->addErrorToDisplay('MESSAGE_WRONG_VERIFICATION_CODE');
00089 
00090             return false;
00091         }
00092 
00093         // filled not all fields ?
00094         foreach ($this->_aReqFields as $sFieldName) {
00095             if (!isset($aParams[$sFieldName]) || !$aParams[$sFieldName]) {
00096                 $oUtilsView->addErrorToDisplay('SUGGEST_COMLETECORRECTLYFIELDS');
00097 
00098                 return;
00099             }
00100         }
00101 
00102         $oUtils = oxRegistry::getUtils();
00103         if (!$oUtils->isValidEmail($aParams["rec_email"]) || !$oUtils->isValidEmail($aParams["send_email"])) {
00104             $oUtilsView->addErrorToDisplay('SUGGEST_INVALIDMAIL');
00105 
00106             return;
00107         }
00108 
00109         $sReturn = "";
00110         // #1834M - specialchar search
00111         $sSearchParamForLink = rawurlencode(oxRegistry::getConfig()->getRequestParameter('searchparam', true));
00112         if ($sSearchParamForLink) {
00113             $sReturn .= "&searchparam=$sSearchParamForLink";
00114         }
00115 
00116         $sSearchCatId = oxRegistry::getConfig()->getRequestParameter('searchcnid');
00117         if ($sSearchCatId) {
00118             $sReturn .= "&searchcnid=$sSearchCatId";
00119         }
00120 
00121         $sSearchVendor = oxRegistry::getConfig()->getRequestParameter('searchvendor');
00122         if ($sSearchVendor) {
00123             $sReturn .= "&searchvendor=$sSearchVendor";
00124         }
00125 
00126         if (($sSearchManufacturer = oxRegistry::getConfig()->getRequestParameter('searchmanufacturer'))) {
00127             $sReturn .= "&searchmanufacturer=$sSearchManufacturer";
00128         }
00129 
00130         $sListType = oxRegistry::getConfig()->getRequestParameter('listtype');
00131         if ($sListType) {
00132             $sReturn .= "&listtype=$sListType";
00133         }
00134 
00135         // sending suggest email
00136         $oEmail = oxNew('oxemail');
00137         $oProduct = $this->getProduct();
00138         if ($oProduct && $oEmail->sendSuggestMail($oParams, $oProduct)) {
00139             return 'details?anid=' . $oProduct->getId() . $sReturn;
00140         } else {
00141             $oUtilsView->addErrorToDisplay('SUGGEST_INVALIDMAIL');
00142         }
00143     }
00144 
00150     public function getProduct()
00151     {
00152         if ($this->_oProduct === null) {
00153             $this->_oProduct = false;
00154 
00155             if ($sProductId = $this->getConfig()->getRequestParameter('anid')) {
00156                 $oProduct = oxNew('oxArticle');
00157                 $oProduct->load($sProductId);
00158                 $this->_oProduct = $oProduct;
00159             }
00160         }
00161 
00162         return $this->_oProduct;
00163     }
00164 
00170     public function getCrossSelling()
00171     {
00172         if ($this->_oCrossSelling === null) {
00173             $this->_oCrossSelling = false;
00174             if ($oProduct = $this->getProduct()) {
00175                 $this->_oCrossSelling = $oProduct->getCrossSelling();
00176             }
00177         }
00178 
00179         return $this->_oCrossSelling;
00180     }
00181 
00187     public function getSimilarProducts()
00188     {
00189         if ($this->_oSimilarProducts === null) {
00190             $this->_oSimilarProducts = false;
00191             if ($oProduct = $this->getProduct()) {
00192                 $this->_oSimilarProducts = $oProduct->getSimilarProducts();
00193             }
00194         }
00195 
00196         return $this->_oSimilarProducts;
00197     }
00198 
00204     public function getRecommList()
00205     {
00206         if (!$this->getViewConfig()->getShowListmania()) {
00207             return false;
00208         }
00209 
00210         if ($this->_oRecommList === null) {
00211             $this->_oRecommList = false;
00212             if ($oProduct = $this->getProduct()) {
00213                 $oRecommList = oxNew('oxrecommlist');
00214                 $this->_oRecommList = $oRecommList->getRecommListsByIds(array($oProduct->getId()));
00215             }
00216         }
00217 
00218         return $this->_oRecommList;
00219     }
00220 
00226     public function setSuggestData($oData)
00227     {
00228         $this->_aSuggestData = $oData;
00229     }
00230 
00236     public function getSuggestData()
00237     {
00238         return $this->_aSuggestData;
00239     }
00240 
00248     public function getLink($iLang = null)
00249     {
00250         $sLink = parent::getLink($iLang);
00251 
00252         // active category
00253         if ($sVal = oxRegistry::getConfig()->getRequestParameter('cnid')) {
00254             $sLink .= ((strpos($sLink, '?') === false) ? '?' : '&amp;') . "cnid={$sVal}";
00255         }
00256 
00257         // active article
00258         if ($sVal = oxRegistry::getConfig()->getRequestParameter('anid')) {
00259             $sLink .= ((strpos($sLink, '?') === false) ? '?' : '&amp;') . "anid={$sVal}";
00260         }
00261 
00262         return $sLink;
00263     }
00264 
00270     public function getCaptcha()
00271     {
00272         if ($this->_oCaptcha === null) {
00273             $this->_oCaptcha = oxNew('oxCaptcha');
00274         }
00275 
00276         return $this->_oCaptcha;
00277     }
00278 
00284     public function getBreadCrumb()
00285     {
00286         $aPaths = array();
00287         $aPath = array();
00288         $iBaseLanguage = oxRegistry::getLang()->getBaseLanguage();
00289         $aPath['title'] = oxRegistry::getLang()->translateString('RECOMMEND_PRODUCT', $iBaseLanguage, false);
00290         $aPath['link'] = $this->getLink();
00291 
00292         $aPaths[] = $aPath;
00293 
00294         return $aPaths;
00295     }
00296 }