invite.php

Go to the documentation of this file.
00001 <?php
00002 
00008 class Invite extends oxUBase
00009 {
00014     protected $_sThisTemplate = 'page/privatesales/invite.tpl';
00015 
00020     protected $_aReqFields = array( '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 $_aInviteData = null;
00045 
00050     protected $_oCaptcha = null;
00051 
00056     protected $_iMailStatus = null;
00057 
00064     public function send()
00065     {
00066         $aParams = oxConfig::getParameter( 'editval', true );
00067         if ( !is_array( $aParams ) ) {
00068             return;
00069         }
00070 
00071         // storing used written values
00072         $oParams = (object) $aParams;
00073         $this->setInviteData( (object) oxConfig::getParameter( 'editval' ) );
00074 
00075         // spam spider prevension
00076         $sMac     = oxConfig::getParameter( 'c_mac' );
00077         $sMacHash = oxConfig::getParameter( 'c_mach' );
00078         $oCaptcha = $this->getCaptcha();
00079 
00080         if ( !$oCaptcha->pass( $sMac, $sMacHash ) ) {
00081             // even if there is no exception, use this as a default display method
00082             oxUtilsView::getInstance()->addErrorToDisplay( 'EXCEPTION_INPUT_WRONGCAPTCHA' );
00083             return;
00084         }
00085 
00086         $oUtilsView = oxUtilsView::getInstance();
00087 
00088         // filled not all fields ?
00089         foreach ( $this->_aReqFields as $sFieldName ) {
00090             //checking if any email was entered
00091             if ( $sFieldName == "rec_email" ) {
00092                 foreach ( $aParams[$sFieldName] as $sKey => $sEmail ) {
00093                     //removing empty emails fields from eMails array
00094                     if ( empty( $sEmail ) ) {
00095                         unset( $aParams[$sFieldName][$sKey] );
00096                     }
00097                 }
00098 
00099                 //counting entered eMails
00100                 if ( count( $aParams[$sFieldName] ) < 1 ) {
00101                     $oUtilsView->addErrorToDisplay('EXCEPTION_INVITE_COMLETECORRECTLYFIELDS');
00102                     return;
00103                 }
00104 
00105                 //updating values object
00106                 $oParams->rec_email = $aParams[$sFieldName];
00107             }
00108 
00109             if ( !isset( $aParams[$sFieldName] ) || !$aParams[$sFieldName] ) {
00110                 $oUtilsView->addErrorToDisplay('EXCEPTION_INVITE_COMLETECORRECTLYFIELDS');
00111                 return;
00112             }
00113         }
00114 
00115         $oUtils = oxUtils::getInstance();
00116 
00117         //validating entered emails
00118         foreach ( $aParams["rec_email"] as $sRecipientEmail ) {
00119             if ( !$oUtils->isValidEmail( $sRecipientEmail ) ) {
00120                 $oUtilsView->addErrorToDisplay('EXCEPTION_INVITE_INCORRECTEMAILADDRESS');
00121                 return;
00122             }
00123         }
00124 
00125         if ( !$oUtils->isValidEmail( $aParams["send_email"] ) ) {
00126             $oUtilsView->addErrorToDisplay('EXCEPTION_INVITE_INCORRECTEMAILADDRESS');
00127             return;
00128         }
00129 
00130         // sending invite email
00131         $oEmail = oxNew( 'oxemail' );
00132 
00133         if ( $oEmail->sendInviteMail( $oParams ) ) {
00134             $this->_iMailStatus = 1;
00135 
00136             //getting active user
00137             $oUser = $this->getUser();
00138 
00139             //saving statitics for sended emails
00140             if ( $oUser ) {
00141                 $oUser->updateInvitationStatistics( $aParams["rec_email"] );
00142             }
00143 
00144         } else {
00145             oxUtilsView::getInstance()->addErrorToDisplay('EXCEPTION_INVITE_ERRORWHILESENDINGMAIL');
00146         }
00147     }
00148 
00154     public function getInviteSendStatus()
00155     {
00156         //checking if email was sent
00157         if ( $this->_iMailStatus == 1 ) {
00158             return true;
00159         }
00160         return false;
00161     }
00162 
00170     public function setInviteData( $oData )
00171     {
00172         $this->_aInviteData = $oData;
00173     }
00174 
00180     public function getInviteData()
00181     {
00182         return $this->_aInviteData;
00183     }
00184 
00190     public function getCaptcha()
00191     {
00192         if ( $this->_oCaptcha === null ) {
00193             $this->_oCaptcha = oxNew('oxCaptcha');
00194         }
00195         return $this->_oCaptcha;
00196     }
00197 
00203     public function getBreadCrumb()
00204     {
00205         $aPaths = array();
00206         $aPath = array();
00207 
00208         $aPath['title'] = oxLang::getInstance()->translateString( 'PAGE_PRIVATESALES_INVITE_TITLE', oxLang::getInstance()->getBaseLanguage(), false );
00209         $aPath['link']  = $this->getLink();
00210         $aPaths[] = $aPath;
00211 
00212         return $aPaths;
00213     }
00214 
00215 
00216 }