00001 <?php
00005 require oxRegistry::getConfig()->getConfigParam( 'sCoreDir' ) . "/phpmailer/class.phpmailer.php";
00006
00007
00013 class oxEmail extends PHPMailer
00014 {
00020 public $SMTP_PORT = 25;
00021
00027 protected $_sForgotPwdTemplate = "email/html/forgotpwd.tpl";
00028
00034 protected $_sForgotPwdTemplatePlain = "email/plain/forgotpwd.tpl";
00035
00041 protected $_sNewsletterOptInTemplate = "email/html/newsletteroptin.tpl";
00042
00048 protected $_sNewsletterOptInTemplatePlain = "email/plain/newsletteroptin.tpl";
00049
00055 protected $_sSuggestTemplate = "email/html/suggest.tpl";
00056
00062 protected $_sSuggestTemplatePlain = "email/plain/suggest.tpl";
00063
00069 protected $_sInviteTemplate = "email/html/invite.tpl";
00070
00076 protected $_sInviteTemplatePlain = "email/plain/invite.tpl";
00077
00083 protected $_sSenedNowTemplate = "email/html/sendednow.tpl";
00084
00090 protected $_sSenedNowTemplatePlain = "email/plain/sendednow.tpl";
00091
00097 protected $_sSendDownloadsTemplate = "email/html/senddownloadlinks.tpl";
00098
00104 protected $_sSendDownloadsTemplatePlain = "email/plain/senddownloadlinks.tpl";
00105
00111 protected $_sWishListTemplate = "email/html/wishlist.tpl";
00112
00118 protected $_sWishListTemplatePlain = "email/plain/wishlist.tpl";
00119
00125 protected $_sRegisterTemplate = "email/html/register.tpl";
00126
00132 protected $_sRegisterTemplatePlain = "email/plain/register.tpl";
00133
00139 protected $_sReminderMailTemplate = "email/html/owner_reminder.tpl";
00140
00146 protected $_sOrderUserTemplate = "email/html/order_cust.tpl";
00147
00153 protected $_sOrderUserPlainTemplate = "email/plain/order_cust.tpl";
00154
00160 protected $_sOrderOwnerTemplate = "email/html/order_owner.tpl";
00161
00167 protected $_sOrderOwnerPlainTemplate = "email/plain/order_owner.tpl";
00168
00169
00170
00176 protected $_sOrderUserSubjectTemplate = "email/html/order_cust_subj.tpl";
00177
00183 protected $_sOrderOwnerSubjectTemplate = "email/html/order_owner_subj.tpl";
00184
00190 protected $_sOwnerPricealarmTemplate = "email/html/pricealarm_owner.tpl";
00191
00197 protected $_sPricealamrCustomerTemplate = "email_pricealarm_customer.tpl";
00198
00204 protected $_aShops = array();
00205
00211 protected $_blInlineImgEmail = null;
00212
00218 protected $_aRecipients = array();
00219
00225 protected $_aReplies = array();
00226
00232 protected $_aAttachments = array();
00233
00239 protected $_oSmarty = null;
00240
00246 protected $_aViewData = array();
00247
00253 protected $_oShop = null;
00254
00260 protected $_sCharSet = null;
00261
00265 public function __construct()
00266 {
00267
00268 parent::__construct( true );
00269
00270 $myConfig = $this->getConfig();
00271
00272 $this->_setMailerPluginDir();
00273 $this->setSmtp();
00274
00275 $this->setUseInlineImages( $myConfig->getConfigParam('blInlineImgEmail') );
00276 $this->setMailWordWrap( 100 );
00277
00278 $this->isHtml( true );
00279 $this->setLanguage( "en", $myConfig->getConfigParam( 'sShopDir' )."/core/phpmailer/language/");
00280
00281 $this->_getSmarty();
00282 }
00283
00295 public function __call( $sMethod, $aArgs )
00296 {
00297 if ( defined( 'OXID_PHP_UNIT' ) ) {
00298 if ( substr( $sMethod, 0, 4) == "UNIT" ) {
00299 $sMethod = str_replace( "UNIT", "_", $sMethod );
00300 }
00301 if ( method_exists( $this, $sMethod)) {
00302 return call_user_func_array( array( & $this, $sMethod ), $aArgs );
00303 }
00304 }
00305
00306 throw new oxSystemComponentException( "Function '$sMethod' does not exist or is not accessible! (" . get_class($this) . ")".PHP_EOL);
00307 }
00308
00314 public function getConfig()
00315 {
00316 if ( $this->_oConfig == null ) {
00317 $this->_oConfig = oxRegistry::getConfig();
00318 }
00319
00320 return $this->_oConfig;
00321 }
00322
00330 public function setConfig( $oConfig )
00331 {
00332 $this->_oConfig = $oConfig;
00333 }
00334
00335
00341 protected function _getSmarty()
00342 {
00343 if ( $this->_oSmarty === null ) {
00344 $this->_oSmarty = oxRegistry::get("oxUtilsView")->getSmarty();
00345 }
00346
00347
00348 $this->_oSmarty->assign( "oEmailView", $this );
00349
00350 return $this->_oSmarty;
00351 }
00352
00360 public function send()
00361 {
00362
00363 if ( count( $this->getRecipient() ) < 1 ) {
00364 return false;
00365 }
00366
00367 $myConfig = $this->getConfig();
00368 $this->setCharSet();
00369
00370 if ( $this->_getUseInlineImages() ) {
00371 $this->_includeImages( $myConfig->getImageDir(), $myConfig->getImageUrl( false, false ), $myConfig->getPictureUrl(null, false),
00372 $myConfig->getImageDir(), $myConfig->getPictureDir(false));
00373 }
00374
00375 $this->_makeOutputProcessing();
00376
00377
00378 if ( $this->getMailer() == 'smtp' ) {
00379 $blRet = $this->_sendMail();
00380
00381
00382 if ( !$blRet ) {
00383
00384 $this->_sendMailErrorMsg();
00385
00386
00387 $this->setMailer( 'mail' );
00388 $blRet = $this->_sendMail();
00389 }
00390 } else {
00391
00392 $this->setMailer( 'mail' );
00393 $blRet = $this->_sendMail();
00394 }
00395
00396 if ( !$blRet ) {
00397
00398 $this->_sendMailErrorMsg();
00399 }
00400
00401 return $blRet;
00402 }
00403
00412 protected function _setSmtpProtocol($sUrl)
00413 {
00414 $sProtocol = '';
00415 $sSmtpHost = $sUrl;
00416 $aMatch = array();
00417 if ( getStr()->preg_match('@^([0-9a-z]+://)?(.*)$@i', $sUrl, $aMatch ) ) {
00418 if ($aMatch[1]) {
00419 if (($aMatch[1] == 'ssl://') || ($aMatch[1] == 'tls://')) {
00420 $this->set( "SMTPSecure", substr($aMatch[1], 0, 3) );
00421 } else {
00422 $sProtocol = $aMatch[1];
00423 }
00424 }
00425 $sSmtpHost = $aMatch[2];
00426 }
00427
00428 return $sProtocol.$sSmtpHost;
00429 }
00430
00438 public function setSmtp( $oShop = null )
00439 {
00440 $myConfig = $this->getConfig();
00441 $oShop = ( $oShop ) ? $oShop : $this->_getShop();
00442
00443 $sSmtpUrl = $this->_setSmtpProtocol($oShop->oxshops__oxsmtp->value);
00444
00445 if ( !$this->_isValidSmtpHost( $sSmtpUrl ) ) {
00446 $this->setMailer( "mail" );
00447 return;
00448 }
00449
00450 $this->setHost( $sSmtpUrl );
00451 $this->setMailer( "smtp" );
00452
00453 if ( $oShop->oxshops__oxsmtpuser->value ) {
00454 $this->_setSmtpAuthInfo( $oShop->oxshops__oxsmtpuser->value, $oShop->oxshops__oxsmtppwd->value );
00455 }
00456
00457 if ( $myConfig->getConfigParam( 'iDebug' ) == 6 ) {
00458 $this->_setSmtpDebug( true );
00459 }
00460 }
00461
00469 protected function _isValidSmtpHost( $sSmtpHost )
00470 {
00471 $blIsSmtp = false;
00472 if ( $sSmtpHost ) {
00473 $sSmtpPort = $this->SMTP_PORT;
00474 $aMatch = array();
00475 if ( getStr()->preg_match('@^(.*?)(:([0-9]+))?$@i', $sSmtpHost, $aMatch)) {
00476 $sSmtpHost = $aMatch[1];
00477 $sSmtpPort = (int)$aMatch[3];
00478 if (!$sSmtpPort) {
00479 $sSmtpPort = $this->SMTP_PORT;
00480 }
00481 }
00482 if ( $blIsSmtp = (bool) ( $rHandle = @fsockopen( $sSmtpHost, $sSmtpPort, $iErrNo, $sErrStr, 30 )) ) {
00483
00484 fclose( $rHandle );
00485 }
00486 }
00487
00488 return $blIsSmtp;
00489 }
00490
00500 public function sendOrderEmailToUser( $oOrder, $sSubject = null )
00501 {
00502 $myConfig = $this->getConfig();
00503
00504
00505 $oOrder = $this->_addUserInfoOrderEMail( $oOrder );
00506
00507 $oShop = $this->_getShop();
00508 $this->_setMailParams( $oShop );
00509
00510 $oUser = $oOrder->getOrderUser();
00511 $this->setUser( $oUser );
00512
00513
00514 $oSmarty = $this->_getSmarty();
00515 $this->setViewData( "order", $oOrder);
00516
00517 if ( $myConfig->getConfigParam( "bl_perfLoadReviews" ) ) {
00518 $this->setViewData( "blShowReviewLink", true );
00519 }
00520
00521
00522 $this->_processViewArray();
00523
00524 $this->setBody( $oSmarty->fetch( $this->_sOrderUserTemplate ) );
00525 $this->setAltBody( $oSmarty->fetch( $this->_sOrderUserPlainTemplate ) );
00526
00527
00528 if ( $sSubject === null ) {
00529 if ( $oSmarty->template_exists( $this->_sOrderUserSubjectTemplate) ) {
00530 $sSubject = $oSmarty->fetch( $this->_sOrderUserSubjectTemplate );
00531 } else {
00532 $sSubject = $oShop->oxshops__oxordersubject->getRawValue()." (#".$oOrder->oxorder__oxordernr->value.")";
00533 }
00534 }
00535
00536 $this->setSubject( $sSubject );
00537
00538 $sFullName = $oUser->oxuser__oxfname->getRawValue() . " " . $oUser->oxuser__oxlname->getRawValue();
00539
00540 $this->setRecipient( $oUser->oxuser__oxusername->value, $sFullName );
00541 $this->setReplyTo( $oShop->oxshops__oxorderemail->value, $oShop->oxshops__oxname->getRawValue() );
00542
00543 $blSuccess = $this->send();
00544
00545 return $blSuccess;
00546 }
00547
00557 public function sendOrderEmailToOwner( $oOrder, $sSubject = null )
00558 {
00559 $myConfig = $this->getConfig();
00560
00561 $oShop = $this->_getShop();
00562
00563
00564 $this->_clearMailer();
00565
00566
00567 $oOrder = $this->_addUserInfoOrderEMail( $oOrder );
00568
00569 $oUser = $oOrder->getOrderUser();
00570 $this->setUser( $oUser );
00571
00572
00573
00574 $this->setFrom( $oShop->oxshops__oxowneremail->value );
00575
00576 $oLang = oxRegistry::getLang();
00577 $iOrderLang = $oLang->getObjectTplLanguage();
00578
00579
00580
00581 if ( $oShop->getLanguage() != $iOrderLang ) {
00582 $oShop = $this->_getShop( $iOrderLang );
00583 }
00584
00585 $this->setSmtp( $oShop );
00586
00587
00588 $oSmarty = $this->_getSmarty();
00589 $this->setViewData( "order", $oOrder );
00590
00591
00592 $this->_processViewArray();
00593
00594 $this->setBody( $oSmarty->fetch( $myConfig->getTemplatePath( $this->_sOrderOwnerTemplate, false ) ) );
00595 $this->setAltBody( $oSmarty->fetch( $myConfig->getTemplatePath( $this->_sOrderOwnerPlainTemplate, false ) ) );
00596
00597
00598
00599 if ( $sSubject === null ) {
00600 if ( $oSmarty->template_exists( $this->_sOrderOwnerSubjectTemplate) ) {
00601 $sSubject = $oSmarty->fetch( $this->_sOrderOwnerSubjectTemplate );
00602 } else {
00603 $sSubject = $oShop->oxshops__oxordersubject->getRawValue()." (#".$oOrder->oxorder__oxordernr->value.")";
00604 }
00605 }
00606
00607 $this->setSubject( $sSubject );
00608 $this->setRecipient( $oShop->oxshops__oxowneremail->value, $oLang->translateString("order") );
00609
00610 if ( $oUser->oxuser__oxusername->value != "admin" )
00611 $sFullName = $oUser->oxuser__oxfname->getRawValue() . " " . $oUser->oxuser__oxlname->getRawValue();
00612 $this->setReplyTo( $oUser->oxuser__oxusername->value, $sFullName );
00613
00614 $blSuccess = $this->send();
00615
00616
00617 $oRemark = oxNew( "oxremark" );
00618 $oRemark->oxremark__oxtext = new oxField($this->getAltBody(), oxField::T_RAW);
00619 $oRemark->oxremark__oxparentid = new oxField($oUser->getId(), oxField::T_RAW);
00620 $oRemark->oxremark__oxtype = new oxField("o", oxField::T_RAW);
00621 $oRemark->save();
00622
00623
00624 if ( $myConfig->getConfigParam( 'iDebug' ) == 6) {
00625 oxRegistry::getUtils()->showMessageAndExit( "" );
00626 }
00627
00628 return $blSuccess;
00629 }
00630
00640 public function sendRegisterConfirmEmail( $oUser, $sSubject = null )
00641 {
00642
00643
00644 $this->setViewData( "contentident", "oxregisteraltemail" );
00645 $this->setViewData( "contentplainident", "oxregisterplainaltemail" );
00646
00647
00648 return $this->sendRegisterEmail( $oUser, $sSubject );
00649 }
00650
00660 public function sendRegisterEmail( $oUser, $sSubject = null )
00661 {
00662
00663 $oUser = $this->_addUserRegisterEmail( $oUser );
00664
00665
00666 $oShop = $this->_getShop();
00667
00668
00669 $this->_setMailParams( $oShop );
00670
00671
00672 $oSmarty = $this->_getSmarty();
00673 $this->setUser( $oUser );
00674
00675
00676 $this->_processViewArray();
00677
00678 $this->setBody( $oSmarty->fetch( $this->_sRegisterTemplate ) );
00679 $this->setAltBody( $oSmarty->fetch( $this->_sRegisterTemplatePlain ) );
00680
00681 $this->setSubject( ( $sSubject !== null ) ? $sSubject : $oShop->oxshops__oxregistersubject->getRawValue() );
00682
00683 $sFullName = $oUser->oxuser__oxfname->getRawValue() . " " . $oUser->oxuser__oxlname->getRawValue();
00684
00685 $this->setRecipient( $oUser->oxuser__oxusername->value, $sFullName );
00686 $this->setReplyTo( $oShop->oxshops__oxorderemail->value, $oShop->oxshops__oxname->getRawValue() );
00687
00688 return $this->send();
00689 }
00690
00700 public function sendForgotPwdEmail( $sEmailAddress, $sSubject = null )
00701 {
00702 $myConfig = $this->getConfig();
00703 $oDb = oxDb::getDb();
00704
00705
00706 $oShop = $this->_getShop();
00707
00708
00709 $oShop = $this->_addForgotPwdEmail( $oShop );
00710
00711
00712 $this->_setMailParams( $oShop );
00713
00714
00715 $sWhere = "oxuser.oxactive = 1 and oxuser.oxusername = ".$oDb->quote( $sEmailAddress )." and oxuser.oxpassword != ''";
00716 $sOrder = "";
00717 if ( $myConfig->getConfigParam( 'blMallUsers' )) {
00718 $sOrder = "order by oxshopid = '".$oShop->getId()."' desc";
00719 } else {
00720 $sWhere .= " and oxshopid = '".$oShop->getId()."'";
00721 }
00722
00723 $sSelect = "select oxid from oxuser where $sWhere $sOrder";
00724 if ( ( $sOxId = $oDb->getOne( $sSelect ) ) ) {
00725
00726 $oUser = oxNew( 'oxuser' );
00727 if ( $oUser->load($sOxId) ) {
00728
00729 $oSmarty = $this->_getSmarty();
00730 $this->setUser( $oUser );
00731
00732
00733 $this->_processViewArray();
00734
00735 $this->setBody( $oSmarty->fetch( $this->_sForgotPwdTemplate ) );
00736
00737 $this->setAltBody( $oSmarty->fetch( $this->_sForgotPwdTemplatePlain ) );
00738
00739
00740 $this->setSubject( ( $sSubject !== null ) ? $sSubject : $oShop->oxshops__oxforgotpwdsubject->getRawValue() );
00741
00742 $sFullName = $oUser->oxuser__oxfname->getRawValue() . " " . $oUser->oxuser__oxlname->getRawValue();
00743
00744 $this->setRecipient( $sEmailAddress, $sFullName );
00745 $this->setReplyTo( $oShop->oxshops__oxorderemail->value, $oShop->oxshops__oxname->getRawValue() );
00746
00747 return $this->send();
00748 }
00749 }
00750
00751 return false;
00752 }
00753
00764 public function sendContactMail( $sEmailAddress = null, $sSubject = null, $sMessage = null )
00765 {
00766
00767
00768 $oShop = $this->_getShop();
00769
00770
00771 $this->_setMailParams( $oShop );
00772
00773 $this->setBody( $sMessage );
00774 $this->setSubject( $sSubject );
00775
00776 $this->setRecipient( $oShop->oxshops__oxinfoemail->value, "" );
00777 $this->setFrom( $sEmailAddress, "" );
00778 $this->setReplyTo( $sEmailAddress, "" );
00779
00780 return $this->send();
00781 }
00782
00792 public function sendNewsletterDbOptInMail( $oUser, $sSubject = null )
00793 {
00794 $oLang = oxRegistry::getLang();
00795
00796
00797 $oUser = $this->_addNewsletterDbOptInMail( $oUser );
00798
00799
00800 $oShop = $this->_getShop();
00801
00802
00803 $this->_setMailParams( $oShop );
00804
00805
00806 $oSmarty = $this->_getSmarty();
00807 $this->setViewData( "subscribeLink", $this->_getNewsSubsLink($oUser->oxuser__oxid->value) );
00808 $this->setUser( $oUser );
00809
00810
00811 $this->_processViewArray();
00812
00813 $this->setBody( $oSmarty->fetch( $this->_sNewsletterOptInTemplate ) );
00814 $this->setAltBody( $oSmarty->fetch( $this->_sNewsletterOptInTemplatePlain ) );
00815 $this->setSubject( ( $sSubject !== null ) ? $sSubject : oxRegistry::getLang()->translateString("EMAIL_NEWSLETTERDBOPTINMAIL_SUBJECT") . " " . $oShop->oxshops__oxname->getRawValue() );
00816
00817 $sFullName = $oUser->oxuser__oxfname->getRawValue() . " " . $oUser->oxuser__oxlname->getRawValue();
00818
00819 $this->setRecipient( $oUser->oxuser__oxusername->value, $sFullName );
00820 $this->setFrom( $oShop->oxshops__oxinfoemail->value, $oShop->oxshops__oxname->getRawValue() );
00821 $this->setReplyTo( $oShop->oxshops__oxinfoemail->value, $oShop->oxshops__oxname->getRawValue() );
00822
00823 return $this->send();
00824 }
00825
00833 protected function _getNewsSubsLink( $sId )
00834 {
00835 $myConfig = $this->getConfig();
00836 $iActShopLang = $myConfig->getActiveShop()->getLanguage();
00837
00838 $sUrl = $myConfig->getShopHomeURL().'cl=newsletter&fnc=addme&uid='.$sId;
00839 $sUrl.= ( $iActShopLang ) ? '&lang='.$iActShopLang : "";
00840 return $sUrl;
00841 }
00842
00853 public function sendNewsletterMail( $oNewsLetter, $oUser, $sSubject = null )
00854 {
00855
00856 $oShop = $this->_getShop();
00857
00858
00859 $this->_setMailParams( $oShop );
00860
00861 $sBody = $oNewsLetter->getHtmlText();
00862
00863 if ( !empty($sBody) ) {
00864 $this->setBody( $sBody );
00865 $this->setAltBody( $oNewsLetter->getPlainText() );
00866 } else {
00867 $this->isHtml( false );
00868 $this->setBody( $oNewsLetter->getPlainText() );
00869 }
00870
00871 $this->setSubject( ( $sSubject !== null ) ? $sSubject : $oNewsLetter->oxnewsletter__oxtitle->getRawValue() );
00872
00873 $sFullName = $oUser->oxuser__oxfname->getRawValue() . " " . $oUser->oxuser__oxlname->getRawValue();
00874 $this->setRecipient( $oUser->oxuser__oxusername->value, $sFullName );
00875 $this->setReplyTo( $oShop->oxshops__oxorderemail->value, $oShop->oxshops__oxname->getRawValue() );
00876
00877 return $this->send();
00878 }
00879
00889 public function sendSuggestMail( $oParams, $oProduct )
00890 {
00891 $myConfig = $this->getConfig();
00892
00893
00894 $iCurrLang = $myConfig->getActiveShop()->getLanguage();
00895
00896
00897 $oShop = $this->_getShop( $iCurrLang );
00898
00899
00900 if ( $oProduct->getLanguage() != $iCurrLang ) {
00901 $oProduct->setLanguage( $iCurrLang );
00902 $oProduct->load( $oProduct->getId() );
00903 }
00904
00905
00906
00907 $this->setFrom( $oShop->oxshops__oxinfoemail->value );
00908 $this->setSMTP();
00909
00910
00911 $oSmarty = $this->_getSmarty();
00912 $this->setViewData( "product", $oProduct );
00913 $this->setUser( $oParams );
00914
00915 $sArticleUrl = $oProduct->getLink();
00916
00917
00918 if ( $myConfig->getActiveView()->isActive('Invitations') && $oActiveUser = $oShop->getUser() ) {
00919 $sArticleUrl = oxRegistry::get("oxUtilsUrl")->appendParamSeparator( $sArticleUrl );
00920 $sArticleUrl .= "su=" . $oActiveUser->getId();
00921 }
00922
00923 $this->setViewData( "sArticleUrl", $sArticleUrl );
00924
00925
00926 $this->_processViewArray();
00927
00928 $this->setBody( $oSmarty->fetch( $this->_sSuggestTemplate ) );
00929 $this->setAltBody( $oSmarty->fetch( $this->_sSuggestTemplatePlain ) );
00930 $this->setSubject( $oParams->send_subject );
00931
00932 $this->setRecipient( $oParams->rec_email, $oParams->rec_name );
00933 $this->setReplyTo( $oParams->send_email, $oParams->send_name );
00934
00935 return $this->send();
00936 }
00937
00946 public function sendInviteMail( $oParams )
00947 {
00948 $myConfig = $this->getConfig();
00949
00950
00951 $iCurrLang = $myConfig->getActiveShop()->getLanguage();
00952
00953
00954 $oShop = $this->_getShop( $iCurrLang );
00955
00956
00957 $this->setFrom( $oParams->send_email, $oParams->send_name );
00958 $this->setSMTP();
00959
00960
00961 $oSmarty = oxRegistry::get("oxUtilsView")->getSmarty();
00962 $this->setUser( $oParams );
00963
00964 $sHomeUrl = $this->getViewConfig()->getHomeLink();
00965
00966
00967 if ( $myConfig->getActiveView()->isActive('Invitations') && $oActiveUser = $oShop->getUser() ) {
00968 $sHomeUrl = oxRegistry::get("oxUtilsUrl")->appendParamSeparator( $sHomeUrl );
00969 $sHomeUrl .= "su=" . $oActiveUser->getId();
00970 }
00971
00972 if ( is_array($oParams->rec_email) && count($oParams->rec_email) > 0 ) {
00973 foreach ( $oParams->rec_email as $sEmail ) {
00974 if ( !empty( $sEmail ) ) {
00975 $sRegisterUrl = oxRegistry::get("oxUtilsUrl")->appendParamSeparator( $sHomeUrl );
00976
00977 $sRegisterUrl .= "re=" . md5($sEmail);
00978 $this->setViewData( "sHomeUrl", $sRegisterUrl );
00979
00980
00981 $this->_processViewArray();
00982
00983 $this->setBody( $oSmarty->fetch( $this->_sInviteTemplate ) );
00984
00985 $this->setAltBody( $oSmarty->fetch( $this->_sInviteTemplatePlain ) );
00986 $this->setSubject( $oParams->send_subject );
00987
00988 $this->setRecipient( $sEmail );
00989 $this->setReplyTo( $oParams->send_email, $oParams->send_name );
00990 $this->send();
00991 $this->clearAllRecipients();
00992 }
00993 }
00994 return true;
00995 }
00996
00997 return false;
00998 }
00999
01009 public function sendSendedNowMail( $oOrder, $sSubject = null )
01010 {
01011 $myConfig = $this->getConfig();
01012
01013 $iOrderLang = (int) ( isset( $oOrder->oxorder__oxlang->value ) ? $oOrder->oxorder__oxlang->value : 0 );
01014
01015
01016 $oShop = $this->_getShop( $iOrderLang );
01017
01018
01019 $this->_setMailParams( $oShop );
01020
01021
01022 $oLang = oxRegistry::getLang();
01023 $oSmarty = $this->_getSmarty();
01024 $this->setViewData( "order", $oOrder );
01025 $this->setViewData( "shopTemplateDir", $myConfig->getTemplateDir(false) );
01026
01027 if ( $myConfig->getConfigParam( "bl_perfLoadReviews" ) ) {
01028 $this->setViewData( "blShowReviewLink", true );
01029 $oUser = oxNew( 'oxuser' );
01030 $this->setViewData( "reviewuserhash", $oUser->getReviewUserHash($oOrder->oxorder__oxuserid->value) );
01031 }
01032
01033
01034 $this->_processViewArray();
01035
01036
01037 $aStore['INCLUDE_ANY'] = $oSmarty->security_settings['INCLUDE_ANY'];
01038
01039 $iOldTplLang = $oLang->getTplLanguage();
01040 $iOldBaseLang = $oLang->getTplLanguage();
01041 $oLang->setTplLanguage( $iOrderLang );
01042 $oLang->setBaseLanguage( $iOrderLang );
01043
01044 $oSmarty->security_settings['INCLUDE_ANY'] = true;
01045
01046 $myConfig->setAdminMode( false );
01047 $this->setBody( $oSmarty->fetch( $this->_sSenedNowTemplate ) );
01048 $this->setAltBody( $oSmarty->fetch( $this->_sSenedNowTemplatePlain ) );
01049 $myConfig->setAdminMode( true );
01050 $oLang->setTplLanguage( $iOldTplLang );
01051 $oLang->setBaseLanguage( $iOldBaseLang );
01052
01053 $oSmarty->security_settings['INCLUDE_ANY'] = $aStore['INCLUDE_ANY'] ;
01054
01055
01056 $this->setSubject( ( $sSubject !== null ) ? $sSubject : $oShop->oxshops__oxsendednowsubject->getRawValue() );
01057
01058 $sFullName = $oOrder->oxorder__oxbillfname->getRawValue() . " " . $oOrder->oxorder__oxbilllname->getRawValue();
01059
01060 $this->setRecipient( $oOrder->oxorder__oxbillemail->value, $sFullName );
01061 $this->setReplyTo( $oShop->oxshops__oxorderemail->value, $oShop->oxshops__oxname->getRawValue() );
01062
01063 return $this->send();
01064 }
01065
01075 public function sendDownloadLinksMail( $oOrder, $sSubject = null )
01076 {
01077 $myConfig = $this->getConfig();
01078
01079 $iOrderLang = (int) ( isset( $oOrder->oxorder__oxlang->value ) ? $oOrder->oxorder__oxlang->value : 0 );
01080
01081
01082 $oShop = $this->_getShop( $iOrderLang );
01083
01084
01085 $this->_setMailParams( $oShop );
01086
01087
01088 $oLang = oxRegistry::getLang();
01089 $oSmarty = $this->_getSmarty();
01090 $this->setViewData( "order", $oOrder );
01091 $this->setViewData( "shopTemplateDir", $myConfig->getTemplateDir(false) );
01092
01093 $oUser = oxNew( 'oxuser' );
01094 $this->setViewData( "reviewuserhash", $oUser->getReviewUserHash($oOrder->oxorder__oxuserid->value) );
01095
01096
01097 $this->_processViewArray();
01098
01099
01100 $aStore['INCLUDE_ANY'] = $oSmarty->security_settings['INCLUDE_ANY'];
01101
01102 $iOldTplLang = $oLang->getTplLanguage();
01103 $iOldBaseLang = $oLang->getTplLanguage();
01104 $oLang->setTplLanguage( $iOrderLang );
01105 $oLang->setBaseLanguage( $iOrderLang );
01106
01107 $oSmarty->security_settings['INCLUDE_ANY'] = true;
01108
01109 $myConfig->setAdminMode( false );
01110 $this->setBody( $oSmarty->fetch( $this->_sSendDownloadsTemplate ) );
01111 $this->setAltBody( $oSmarty->fetch( $this->_sSendDownloadsTemplatePlain ) );
01112 $myConfig->setAdminMode( true );
01113 $oLang->setTplLanguage( $iOldTplLang );
01114 $oLang->setBaseLanguage( $iOldBaseLang );
01115
01116 $oSmarty->security_settings['INCLUDE_ANY'] = $aStore['INCLUDE_ANY'] ;
01117
01118
01119 $this->setSubject( ( $sSubject !== null ) ? $sSubject : $oLang->translateString("EMAIL_SENDDOWNLOADS_SUBJECT") );
01120
01121 $sFullName = $oOrder->oxorder__oxbillfname->getRawValue() . " " . $oOrder->oxorder__oxbilllname->getRawValue();
01122
01123 $this->setRecipient( $oOrder->oxorder__oxbillemail->value, $sFullName );
01124 $this->setReplyTo( $oShop->oxshops__oxorderemail->value, $oShop->oxshops__oxname->getRawValue() );
01125
01126 return $this->send();
01127 }
01128
01143 public function sendBackupMail( $aAttFiles, $sAttPath, $sEmailAddress, $sSubject, $sMessage, &$aStatus, &$aError )
01144 {
01145
01146 $oShop = $this->_getShop();
01147
01148
01149 $this->_setMailParams( $oShop );
01150
01151 $this->setBody( $sMessage );
01152 $this->setSubject( $sSubject );
01153
01154 $this->setRecipient( $oShop->oxshops__oxinfoemail->value, "" );
01155 $sEmailAddress = $sEmailAddress ? $sEmailAddress : $oShop->oxshops__oxowneremail->value;
01156
01157 $this->setFrom( $sEmailAddress, "" );
01158 $this->setReplyTo( $sEmailAddress, "" );
01159
01160
01161 $blAttashSucc = true;
01162 $sAttPath = oxRegistry::get("oxUtilsFile")->normalizeDir($sAttPath);
01163 foreach ( $aAttFiles as $iNum => $sAttFile ) {
01164 $sFullPath = $sAttPath . $sAttFile;
01165 if ( @is_readable( $sFullPath ) && @is_file( $sFullPath ) ) {
01166 $blAttashSucc = $this->addAttachment( $sFullPath, $sAttFile );
01167 } else {
01168 $blAttashSucc = false;
01169 $aError[] = array( 5, $sAttFile );
01170 }
01171 }
01172
01173 if ( !$blAttashSucc ) {
01174 $aError[] = array( 4, "" );
01175 $this->clearAttachments();
01176 return false;
01177 }
01178
01179 $aStatus[] = 3;
01180 $blSend = $this->send();
01181 $this->clearAttachments();
01182
01183 return $blSend;
01184 }
01185
01196 public function sendEmail( $sTo, $sSubject, $sBody )
01197 {
01198
01199 $this->_setMailParams();
01200
01201 if ( is_array($sTo) ) {
01202 foreach ($sTo as $sAddress) {
01203 $this->setRecipient( $sAddress, "" );
01204 $this->setReplyTo( $sAddress, "" );
01205 }
01206 } else {
01207 $this->setRecipient( $sTo, "" );
01208 $this->setReplyTo( $sTo, "" );
01209 }
01210
01211
01212 $this->isHtml( false );
01213
01214 $this->setSubject( $sSubject );
01215 $this->setBody( $sBody );
01216
01217 return $this->send();
01218 }
01219
01228 public function sendStockReminder( $aBasketContents, $sSubject = null )
01229 {
01230 $blSend = false;
01231
01232 $oArticleList = oxNew( "oxarticlelist" );
01233 $oArticleList->loadStockRemindProducts( $aBasketContents );
01234
01235
01236 if ( $oArticleList->count() ) {
01237 $oShop = $this->_getShop();
01238
01239
01240 $this->_setMailParams( $oShop );
01241 $oLang = oxRegistry::getLang();
01242
01243 $oSmarty = $this->_getSmarty();
01244 $this->setViewData( "articles", $oArticleList );
01245
01246
01247 $this->_processViewArray();
01248
01249 $this->setRecipient( $oShop->oxshops__oxowneremail->value, $oShop->oxshops__oxname->getRawValue() );
01250 $this->setFrom( $oShop->oxshops__oxowneremail->value, $oShop->oxshops__oxname->getRawValue() );
01251 $this->setBody( $oSmarty->fetch( $this->getConfig()->getTemplatePath( $this->_sReminderMailTemplate, false ) ) );
01252 $this->setAltBody( "" );
01253 $this->setSubject( ( $sSubject !== null ) ? $sSubject : $oLang->translateString( 'EMAIL_STOCKREMINDER_SUBJECT' ) );
01254
01255 $blSend = $this->send();
01256 }
01257
01258 return $blSend;
01259 }
01260
01269 public function sendWishlistMail( $oParams )
01270 {
01271 $myConfig = $this->getConfig();
01272
01273 $this->_clearMailer();
01274
01275
01276 $oShop = $this->_getShop();
01277
01278
01279 $this->setFrom( $oParams->send_email, $oParams->send_name );
01280 $this->setSMTP();
01281
01282
01283 $oSmarty = $this->_getSmarty();
01284 $this->setUser( $oParams );
01285
01286
01287 $this->_processViewArray();
01288
01289 $this->setBody( $oSmarty->fetch( $this->_sWishListTemplate ) );
01290 $this->setAltBody( $oSmarty->fetch( $this->_sWishListTemplatePlain ) );
01291 $this->setSubject( $oParams->send_subject );
01292
01293 $this->setRecipient( $oParams->rec_email, $oParams->rec_name );
01294 $this->setReplyTo( $oParams->send_email, $oParams->send_name );
01295
01296 return $this->send();
01297 }
01298
01309 public function sendPriceAlarmNotification( $aParams, $oAlarm, $sSubject = null )
01310 {
01311 $this->_clearMailer();
01312 $oShop = $this->_getShop();
01313
01314
01315 $this->_setMailParams( $oShop );
01316
01317 $iAlarmLang = $oAlarm->oxpricealarm__oxlang->value;
01318
01319 $oArticle = oxNew( "oxarticle" );
01320
01321 $oArticle->loadInLang( $iAlarmLang, $aParams['aid'] );
01322 $oLang = oxRegistry::getLang();
01323
01324
01325 $oSmarty = $this->_getSmarty();
01326 $this->setViewData( "product", $oArticle );
01327 $this->setViewData( "email", $aParams['email']);
01328 $this->setViewData( "bidprice", $oLang->formatCurrency( $oAlarm->oxpricealarm__oxprice->value, $oCur ) );
01329
01330
01331 $this->_processViewArray();
01332
01333 $this->setRecipient( $oShop->oxshops__oxorderemail->value, $oShop->oxshops__oxname->getRawValue() );
01334 $this->setSubject( ( $sSubject !== null ) ? $sSubject : $oLang->translateString( 'EMAIL_PRICEALARM_OWNER_SUBJECT', $iAlarmLang ) . " " . $oArticle->oxarticles__oxtitle->getRawValue() );
01335 $this->setBody( $oSmarty->fetch( $this->_sOwnerPricealarmTemplate ) );
01336 $this->setFrom( $aParams['email'], "" );
01337 $this->setReplyTo( $aParams['email'], "" );
01338
01339 return $this->send();
01340 }
01341
01353 public function sendPricealarmToCustomer( $sRecipient, $oAlarm, $sBody = null, $sReturnMailBody = null )
01354 {
01355 $this->_clearMailer();
01356
01357 $oShop = $this->_getShop();
01358
01359 if ( $oShop->getId() != $oAlarm->oxpricealarm__oxshopid->value) {
01360 $oShop = oxNew( "oxshop" );
01361 $oShop->load( $oAlarm->oxpricealarm__oxshopid->value);
01362 $this->setShop( $oShop );
01363 }
01364
01365
01366 $this->_setMailParams( $oShop );
01367
01368
01369 $oSmarty = $this->_getSmarty();
01370
01371 $this->setViewData( "product", $oAlarm->getArticle() );
01372 $this->setViewData( "oPriceAlarm", $oAlarm );
01373 $this->setViewData( "bidprice", $oAlarm->getFProposedPrice() );
01374 $this->setViewData( "currency", $oAlarm->getPriceAlarmCurrency() );
01375
01376
01377 $this->_processViewArray();
01378
01379 $this->setRecipient( $sRecipient, $sRecipient );
01380 $this->setSubject( $oShop->oxshops__oxname->value );
01381
01382 if ( $sBody === null ) {
01383 $sBody = $oSmarty->fetch( $this->_sPricealamrCustomerTemplate );
01384 }
01385
01386 $this->setBody( $sBody );
01387
01388 $this->addAddress( $sRecipient, $sRecipient );
01389 $this->setReplyTo( $oShop->oxshops__oxorderemail->value, $oShop->oxshops__oxname->getRawValue() );
01390
01391 if ( $sReturnMailBody ) {
01392 return $this->getBody();
01393 } else {
01394 return $this->send();
01395 }
01396 }
01397
01409 protected function _includeImages($sImageDir = null, $sImageDirNoSSL = null, $sDynImageDir = null, $sAbsImageDir = null, $sAbsDynImageDir = null)
01410 {
01411 $sBody = $this->getBody();
01412 if (preg_match_all('/<\s*img\s+[^>]*?src[\s]*=[\s]*[\'"]?([^[\'">]]+|.*?)?[\'">]/i', $sBody, $matches, PREG_SET_ORDER)) {
01413
01414 $oFileUtils = oxRegistry::get("oxUtilsFile");
01415 $blReSetBody = false;
01416
01417
01418 $sDynImageDir = $oFileUtils->normalizeDir( $sDynImageDir );
01419 $sImageDir = $oFileUtils->normalizeDir( $sImageDir );
01420 $sImageDirNoSSL = $oFileUtils->normalizeDir( $sImageDirNoSSL );
01421
01422 if (is_array($matches) && count($matches)) {
01423 $aImageCache = array();
01424 $myUtils = oxRegistry::getUtils();
01425 $myUtilsObject = oxUtilsObject::getInstance();
01426 $oImgGenerator = oxNew( "oxDynImgGenerator" );
01427
01428 foreach ($matches as $aImage) {
01429
01430 $image = $aImage[1];
01431 $sFileName = '';
01432 if ( strpos( $image, $sDynImageDir ) === 0 ) {
01433 $sFileName = $oFileUtils->normalizeDir( $sAbsDynImageDir ) . str_replace( $sDynImageDir, '', $image );
01434 } elseif ( strpos( $image, $sImageDir ) === 0 ) {
01435 $sFileName = $oFileUtils->normalizeDir( $sAbsImageDir ) . str_replace( $sImageDir, '', $image );
01436 } elseif ( strpos( $image, $sImageDirNoSSL ) === 0 ) {
01437 $sFileName = $oFileUtils->normalizeDir( $sAbsImageDir ) . str_replace( $sImageDirNoSSL, '', $image );
01438 }
01439
01440 if ( $sFileName && !@is_readable( $sFileName ) ) {
01441 $sFileName = $oImgGenerator->getImagePath( $sFileName );
01442 }
01443
01444 if ( $sFileName ) {
01445 $sCId = '';
01446 if ( isset( $aImageCache[$sFileName] ) && $aImageCache[$sFileName] ) {
01447 $sCId = $aImageCache[$sFileName];
01448 } else {
01449 $sCId = $myUtilsObject->generateUID();
01450 $sMIME = $myUtils->oxMimeContentType($sFileName);
01451 if ($sMIME == 'image/jpeg' || $sMIME == 'image/gif' || $sMIME == 'image/png') {
01452 if ( $this->addEmbeddedImage( $sFileName, $sCId, "image", "base64", $sMIME ) ) {
01453 $aImageCache[$sFileName] = $sCId;
01454 } else {
01455 $sCId = '';
01456 }
01457 }
01458 }
01459 if ( $sCId && $sCId == $aImageCache[$sFileName] ) {
01460 if ( $sReplTag = str_replace( $image, 'cid:'.$sCId, $aImage[0] ) ) {
01461 $sBody = str_replace($aImage[0], $sReplTag, $sBody );
01462 $blReSetBody = true;
01463 }
01464 }
01465 }
01466 }
01467 }
01468
01469 if ( $blReSetBody ) {
01470 $this->setBody( $sBody );
01471 }
01472 }
01473 }
01474
01482 public function setSubject( $sSubject = null )
01483 {
01484
01485 $sSubject = str_replace(array('&', '"', ''', '<', '>'), array('&', '"', "'", '<', '>' ), $sSubject);
01486
01487 $this->set( "Subject", $sSubject );
01488 }
01489
01495 public function getSubject()
01496 {
01497 return $this->Subject;
01498 }
01499
01509 public function setBody( $sBody = null, $blClearSid = true )
01510 {
01511 if ( $blClearSid ) {
01512 $sBody = getStr()->preg_replace('/((\?|&(amp;)?)(force_)?(admin_)?)sid=[A-Z0-9\.]+/i', '\1sid=x&shp=' . $this->getConfig()->getShopId(), $sBody);
01513 }
01514
01515 $this->set( "Body", $sBody );
01516 }
01517
01523 public function getBody()
01524 {
01525 return $this->Body;
01526 }
01527
01537 public function setAltBody( $sAltBody = null, $blClearSid = true )
01538 {
01539 if ( $blClearSid ) {
01540 $sAltBody = getStr()->preg_replace('/((\?|&(amp;)?)(force_)?(admin_)?)sid=[A-Z0-9\.]+/i', '\1sid=x&shp=' . $this->getConfig()->getShopId(), $sAltBody);
01541 }
01542
01543
01544 $sAltBody = str_replace(array('&', '"', ''', '<', '>'), array('&', '"', "'", '<', '>' ), $sAltBody);
01545
01546 $this->set( "AltBody", $sAltBody );
01547 }
01548
01554 public function getAltBody()
01555 {
01556 return $this->AltBody;
01557 }
01558
01567 public function setRecipient( $sAddress = null, $sName = null )
01568 {
01569 try {
01570 parent::AddAddress( $sAddress, $sName );
01571
01572
01573 $this->_aRecipients[] = array( $sAddress, $sName );
01574 } catch( Exception $oEx ) {
01575 }
01576 }
01577
01585 public function getRecipient()
01586 {
01587 return $this->_aRecipients;
01588 }
01589
01596 public function clearAllRecipients()
01597 {
01598 $this->_aRecipients = array();
01599 parent::clearAllRecipients();
01600 }
01601
01613 public function setReplyTo( $sEmail = null, $sName = null )
01614 {
01615 if ( !oxRegistry::getUtils()->isValidEmail( $sEmail ) ) {
01616 $sEmail = $this->_getShop()->oxshops__oxorderemail->value;
01617 }
01618
01619 $this->_aReplies[] = array( $sEmail, $sName );
01620
01621 try {
01622 parent::addReplyTo( $sEmail, $sName );
01623 } catch( Exception $oEx ) {
01624 }
01625 }
01626
01632 public function getReplyTo()
01633 {
01634 return $this->_aReplies;
01635 }
01636
01642 public function clearReplyTos()
01643 {
01644 $this->_aReplies = array();
01645 parent::clearReplyTos();
01646 }
01647
01656 public function setFrom( $sFromAdress, $sFromName = null )
01657 {
01658
01659
01660
01661 $sFromAdress = substr($sFromAdress, 0, 150);
01662 $sFromName = substr($sFromName, 0, 150);
01663
01664 try {
01665 parent::setFrom( $sFromAdress, $sFromName );
01666 } catch( Exception $oEx ) {
01667 }
01668 }
01669
01675 public function getFrom()
01676 {
01677 return $this->From;
01678 }
01679
01685 public function getFromName()
01686 {
01687 return $this->FromName;
01688 }
01689
01698 public function setCharSet( $sCharSet = null )
01699 {
01700 if ( $sCharSet ) {
01701 $this->_sCharSet = $sCharSet;
01702 } else {
01703 $this->_sCharSet = oxRegistry::getLang()->translateString( "charset" );
01704 }
01705 $this->set( "CharSet", $this->_sCharSet );
01706 }
01707
01715 public function setMailer( $sMailer = null )
01716 {
01717 $this->set( "Mailer", $sMailer );
01718 }
01719
01725 public function getMailer()
01726 {
01727 return $this->Mailer;
01728 }
01729
01737 public function setHost( $sHost = null )
01738 {
01739 $this->set( "Host", $sHost );
01740 }
01741
01747 public function getErrorInfo()
01748 {
01749 return $this->ErrorInfo;
01750 }
01751
01760 public function setMailWordWrap( $iWordWrap = null )
01761 {
01762 $this->set( "WordWrap", $iWordWrap );
01763 }
01764
01772 public function setUseInlineImages( $blUseImages = null )
01773 {
01774 $this->_blInlineImgEmail = $blUseImages;
01775 }
01776
01787 public function addAttachment( $sAttPath, $sAttFile = '', $sEncoding = 'base64', $sType = 'application/octet-stream' )
01788 {
01789 $this->_aAttachments[] = array( $sAttPath, $sAttFile, $sEncoding, $sType );
01790 $blResult = false;
01791
01792 try {
01793 $blResult = parent::addAttachment( $sAttPath, $sAttFile, $sEncoding, $sType );
01794 } catch( Exception $oEx ) {
01795 }
01796
01797 return $blResult;
01798 }
01799
01811 public function addEmbeddedImage( $sFullPath, $sCid, $sAttFile = '', $sEncoding = 'base64', $sType = 'application/octet-stream' )
01812 {
01813 $this->_aAttachments[] = array( $sFullPath, basename($sFullPath), $sAttFile, $sEncoding, $sType, false, 'inline', $sCid );
01814 return parent::addEmbeddedImage( $sFullPath, $sCid, $sAttFile, $sEncoding, $sType );
01815 }
01816
01822 public function getAttachments()
01823 {
01824 return $this->_aAttachments;
01825 }
01826
01832 public function clearAttachments()
01833 {
01834 $this->_aAttachments = array();
01835 return parent::clearAttachments();
01836 }
01837
01847 public function headerLine($sName, $sValue)
01848 {
01849 if (stripos($sName, 'X-') !== false) {
01850 return;
01851 }
01852 return parent::headerLine($sName, $sValue);
01853 }
01854
01860 protected function _getUseInlineImages()
01861 {
01862 return $this->_blInlineImgEmail;
01863 }
01864
01870 protected function _sendMailErrorMsg()
01871 {
01872
01873 $sToAdress = "";
01874 $sToName = "";
01875
01876 $aRecipients = $this->getRecipient();
01877
01878 $sOwnerMessage = "Error sending eMail(". $this->getSubject().") to: \n\n";
01879
01880 foreach ( $aRecipients as $aEMail ) {
01881 $sOwnerMessage .= $aEMail[0];
01882 $sOwnerMessage .= ( !empty($aEMail[1]) ) ? ' (' . $aEMail[1] . ')' : '';
01883 $sOwnerMessage .= " \n ";
01884 }
01885 $sOwnerMessage .= "\n\nError : " . $this->getErrorInfo();
01886
01887
01888 $oShop = $this->_getShop();
01889
01890 $blRet = @mail( $oShop->oxshops__oxorderemail->value, "eMail problem in shop!", $sOwnerMessage);
01891
01892 return $blRet;
01893 }
01894
01904 protected function _addUserInfoOrderEMail( $oOrder )
01905 {
01906 return $oOrder;
01907 }
01908
01918 protected function _addUserRegisterEmail( $oUser )
01919 {
01920 return $oUser;
01921 }
01922
01932 protected function _addForgotPwdEmail( $oShop )
01933 {
01934 return $oShop;
01935 }
01936
01946 protected function _addNewsletterDbOptInMail( $oUser )
01947 {
01948 return $oUser;
01949 }
01950
01956 protected function _clearMailer()
01957 {
01958 $this->clearAllRecipients();
01959 $this->clearReplyTos();
01960 $this->clearAttachments();
01961
01962
01963 $this->error_count = 0;
01964 $this->ErrorInfo = '';
01965 }
01966
01974 protected function _setMailParams( $oShop = null )
01975 {
01976 $this->_clearMailer();
01977
01978 if ( !$oShop ) {
01979 $oShop = $this->_getShop();
01980 }
01981
01982 $this->setFrom( $oShop->oxshops__oxorderemail->value, $oShop->oxshops__oxname->getRawValue() );
01983 $this->setSmtp( $oShop );
01984 }
01985
01995 protected function _getShop( $iLangId = null, $iShopId = null )
01996 {
01997 if ( $iLangId === null && $iShopId === null ) {
01998 if ( isset( $this->_oShop ) ) {
01999 return $this->_oShop;
02000 } else {
02001 return $this->_oShop = $this->getConfig()->getActiveShop();
02002 }
02003 }
02004
02005 $myConfig = $this->getConfig();
02006
02007 $oShop = oxNew( 'oxshop' );
02008 if ( $iShopId !== null ) {
02009 $oShop->setShopId($iShopId);
02010 }
02011 if ( $iLangId !== null ) {
02012 $oShop->setLanguage($iLangId);
02013 }
02014 $oShop->load($myConfig->getShopId());
02015
02016 return $oShop;
02017 }
02018
02027 protected function _setSmtpAuthInfo( $sUserName = null, $sUserPassword = null )
02028 {
02029 $this->set( "SMTPAuth", true );
02030 $this->set( "Username", $sUserName );
02031 $this->set( "Password", $sUserPassword );
02032 }
02033
02041 protected function _setSmtpDebug( $blDebug = null )
02042 {
02043 $this->set( "SMTPDebug", $blDebug );
02044 }
02045
02051 protected function _setMailerPluginDir()
02052 {
02053 $this->set( "PluginDir", getShopBasePath() . "core/phpmailer/" );
02054 }
02055
02062 protected function _makeOutputProcessing()
02063 {
02064 $oOutput = oxNew( "oxoutput" );
02065 $this->setBody( $oOutput->process($this->getBody(), "oxemail") );
02066 $this->setAltBody( $oOutput->process($this->getAltBody(), "oxemail") );
02067 $oOutput->processEmail( $this );
02068 }
02069
02075 protected function _sendMail()
02076 {
02077 $blResult = false;
02078 try {
02079 $blResult = parent::send();
02080 } catch( Exception $oException ) {
02081 $oEx = oxNew( "oxException" );
02082 $oEx->setMessage($oException->getMessage());
02083 $oEx->debugOut();
02084 if ( $this->getConfig()->getConfigParam( 'iDebug' ) != 0 ) {
02085 throw $oEx;
02086 }
02087 }
02088 return $blResult;
02089 }
02090
02091
02097 protected function _processViewArray()
02098 {
02099 $oSmarty = $this->_getSmarty();
02100 $oOutputProcessor = oxNew( "oxoutput" );
02101
02102
02103 foreach ( $this->_aViewData as $sKey => $sValue ) {
02104 $oSmarty->assign( $sKey, $sValue );
02105 }
02106
02107
02108 $aNewSmartyArray = $oOutputProcessor->processViewArray( $oSmarty->get_template_vars(), "oxemail" );
02109
02110 foreach ( $aNewSmartyArray as $key => $val ) {
02111 $oSmarty->assign( $key, $val );
02112 }
02113 }
02114
02120 public function getCharset()
02121 {
02122 if ( !$this->_sCharSet ) {
02123 return oxRegistry::getLang()->translateString("charset");
02124 } else {
02125 return $this->CharSet;
02126 }
02127 }
02128
02134 public function getShop()
02135 {
02136 return $this->_getShop();
02137 }
02138
02146 public function setShop( $oShop )
02147 {
02148 $this->_oShop = $oShop;
02149 }
02150
02156 public function getViewConfig()
02157 {
02158 return $this->getConfig()->getActiveView()->getViewConfig();
02159 }
02160
02166 public function getView()
02167 {
02168 return $this->getConfig()->getActiveView();
02169 }
02170
02176 public function getCurrency()
02177 {
02178 $oConfig = oxRegistry::getConfig();
02179
02180 return $oConfig->getActShopCurrencyObject();
02181 }
02182
02191 public function setViewData( $sKey, $sValue )
02192 {
02193 $this->_aViewData[$sKey] = $sValue;
02194 }
02195
02201 public function getViewData()
02202 {
02203 return $this->_aViewData;
02204 }
02205
02213 public function getViewDataItem( $sKey )
02214 {
02215 if ( isset($this->_aViewData[$sKey]) ) {
02216 return $this->_aViewData;
02217 }
02218 }
02219
02227 public function setUser( $oUser)
02228 {
02229 $this->_aViewData["oUser"] = $oUser;
02230 }
02231
02237 public function getUser()
02238 {
02239 return $this->_aViewData["oUser"];
02240 }
02241
02249 public function getOrderFileList( $sOrderId )
02250 {
02251 $oOrderList = oxNew('oxOrderFileList');
02252 $oOrderList->loadOrderFiles( $sOrderId );
02253
02254 if ( count($oOrderList) > 0 ) {
02255 return $oOrderList;
02256 }
02257
02258 return false;
02259 }
02260
02261 }