00001 <?php 00002 00010 class Contact extends oxUBase 00011 { 00016 protected $_aUserData = null; 00017 00022 protected $_sContactSubject = null; 00023 00028 protected $_sContactMessage = null; 00029 00034 protected $_oCaptcha = null; 00035 00040 protected $_blContactSendStatus = null; 00041 00046 protected $_sThisTemplate = 'contact.tpl'; 00047 00053 protected $_iViewIndexState = VIEW_INDEXSTATE_NOINDEXNOFOLLOW; 00054 00065 public function render() 00066 { 00067 parent::render(); 00068 00069 $this->_aViewData['editval'] = $this->getUserData(); 00070 $this->_aViewData['c_subject'] = $this->getContactSubject(); 00071 $this->_aViewData['c_message'] = $this->getContactMessage(); 00072 00073 //captcha 00074 $this->_aViewData['oCaptcha'] = $this->getCaptcha(); 00075 $this->_aViewData['success'] = $this->getContactSendStatus(); 00076 00077 return $this->_sThisTemplate; 00078 } 00079 00089 public function send() 00090 { 00091 // spam spider prevension 00092 $sMac = oxConfig::getParameter( 'c_mac' ); 00093 $sMacHash = oxConfig::getParameter( 'c_mach' ); 00094 $oCaptcha = oxNew('oxCaptcha'); 00095 if (!$oCaptcha->pass($sMac, $sMacHash)) 00096 { 00097 // even if there is no exception, use this as a default display method 00098 oxUtilsView::getInstance()->addErrorToDisplay( 'EXCEPTION_INPUT_NOTALLFIELDS' ); 00099 return false; 00100 } 00101 00102 $aParams = oxConfig::getParameter( 'editval' ); 00103 $sSubject = oxConfig::getParameter( 'c_subject' ); 00104 $sBody = oxConfig::getParameter( 'c_message' ); 00105 if ( !$aParams['oxuser__oxfname'] || !$aParams['oxuser__oxlname'] || !$aParams['oxuser__oxusername'] || !$sSubject ) { 00106 // even if there is no exception, use this as a default display method 00107 oxUtilsView::getInstance()->addErrorToDisplay( 'EXCEPTION_INPUT_NOTALLFIELDS' ); 00108 return false; 00109 } 00110 00111 $sMessage = oxLang::getInstance()->translateString( 'CONTACT_FROM' )." ".$aParams['oxuser__oxsal']." ".$aParams['oxuser__oxfname']." ".$aParams['oxuser__oxlname']."(".$aParams['oxuser__oxusername'].")\n\n"; 00112 $sMessage .= nl2br( $sBody ); 00113 00114 $oEmail = oxNew( 'oxemail' ); 00115 if ( $oEmail->sendContactMail( $aParams['oxuser__oxusername'], $sSubject, $sMessage ) ) { 00116 $this->_blContactSendStatus = 1; 00117 } 00118 } 00119 00125 public function getUserData() 00126 { 00127 if ( $this->_oUserData === null ) { 00128 $this->_oUserData = oxConfig::getParameter( 'editval' ); 00129 } 00130 return $this->_oUserData; 00131 } 00132 00138 public function getContactSubject() 00139 { 00140 if ( $this->_sContactSubject === null ) { 00141 $this->_sContactSubject = oxConfig::getParameter( 'c_subject' ); 00142 } 00143 return $this->_sContactSubject; 00144 } 00145 00151 public function getContactMessage() 00152 { 00153 if ( $this->_sContactMessage === null ) { 00154 $this->_sContactMessage = oxConfig::getParameter( 'c_message' ); 00155 } 00156 return $this->_sContactMessage; 00157 } 00158 00164 public function getCaptcha() 00165 { 00166 if ( $this->_oCaptcha === null ) { 00167 $this->_oCaptcha = oxNew('oxCaptcha'); 00168 } 00169 return $this->_oCaptcha; 00170 } 00171 00177 public function getContactSendStatus() 00178 { 00179 return $this->_blContactSendStatus; 00180 } 00181 }