Overview

Packages

  • CONTENIDO
  • Core
    • Authentication
    • Backend
    • Cache
    • CEC
    • Chain
    • ContentType
    • Database
    • Debug
    • Exception
    • Frontend
      • Search
      • URI
      • Util
    • GenericDB
      • Model
    • GUI
      • HTML
    • I18N
    • LayoutHandler
    • Log
    • Security
    • Session
    • Util
    • Validation
    • Versioning
    • XML
  • Module
    • ContentRssCreator
    • ContentSitemapHtml
    • ContentSitemapXml
    • ContentUserForum
    • NavigationTop
    • ScriptCookieDirective
  • mpAutoloaderClassMap
  • None
  • Plugin
    • ContentAllocation
    • CronjobOverview
    • FormAssistant
    • FrontendLogic
    • FrontendUsers
    • Linkchecker
    • ModRewrite
    • Newsletter
    • Repository
      • FrontendNavigation
      • KeywordDensity
    • SearchSolr
    • SmartyWrapper
    • UrlShortener
    • UserForum
    • Workflow
  • PluginManager
  • Setup
    • Form
    • GUI
    • Helper
      • Environment
      • Filesystem
      • MySQL
      • PHP
    • UpgradeJob
  • Smarty
    • Cacher
    • Compiler
    • Config
    • Debug
    • PluginsBlock
    • PluginsFilter
    • PluginsFunction
    • PluginsInternal
    • PluginsModifier
    • PluginsModifierCompiler
    • PluginsShared
    • Security
    • Template
    • TemplateResources
  • Swift
    • ByteStream
    • CharacterStream
    • Encoder
    • Events
    • KeyCache
    • Mailer
    • Mime
    • Plugins
    • Transport

Classes

  • Swift_FailoverTransport
  • Swift_LoadBalancedTransport
  • Swift_MailTransport
  • Swift_Plugins_Loggers_ArrayLogger
  • Swift_Plugins_Loggers_EchoLogger
  • Swift_SendmailTransport
  • Swift_SmtpTransport
  • Swift_Transport_AbstractSmtpTransport
  • Swift_Transport_Esmtp_Auth_CramMd5Authenticator
  • Swift_Transport_Esmtp_Auth_LoginAuthenticator
  • Swift_Transport_Esmtp_Auth_PlainAuthenticator
  • Swift_Transport_Esmtp_AuthHandler
  • Swift_Transport_EsmtpTransport
  • Swift_Transport_FailoverTransport
  • Swift_Transport_LoadBalancedTransport
  • Swift_Transport_MailTransport
  • Swift_Transport_SendmailTransport
  • Swift_Transport_SimpleMailInvoker
  • Swift_Transport_StreamBuffer

Interfaces

  • Swift_Plugins_Logger
  • Swift_Plugins_Pop_Pop3Exception
  • Swift_Transport
  • Swift_Transport_Esmtp_Authenticator
  • Swift_Transport_EsmtpHandler
  • Swift_Transport_IoBuffer
  • Swift_Transport_MailInvoker
  • Swift_Transport_SmtpAgent
  • Swift_TransportException
  • Overview
  • Package
  • Function
  • Todo
  • Download
  1: <?php
  2: 
  3: /**
  4:  *
  5:  * @package Plugin
  6:  * @subpackage FormAssistant
  7:  * @version SVN Revision $Rev:$
  8:  * @author marcus.gnass
  9:  * @copyright four for business AG
 10:  * @link http://www.4fb.de
 11:  */
 12: 
 13: // assert CONTENIDO framework
 14: defined('CON_FRAMEWORK') || die('Illegal call: Missing framework initialization - request aborted.');
 15: 
 16: plugin_include(Pifa::getName(), 'extensions/class.pifa.default_form_processor.php');
 17: 
 18: /**
 19:  * The given data should be send via email to the systems mail address and a
 20:  * confirmation mail to the user itself.
 21:  * This feature can be accomplished by extending the class
 22:  * PifaFormAbstractProcessor and implementing its method _processStoredData().
 23:  *
 24:  * Any uploads of the given form will be added as attachments to the system
 25:  * mail.
 26:  *
 27:  * @author marcus.gnass
 28:  */
 29: class MailedFormProcessor extends DefaultFormProcessor {
 30:     const MAIL_MODE_CLIENT = 'client';
 31:     const MAIL_MODE_SYSTEM = 'system';
 32: 
 33:     /**
 34:      * Sends client & system mail independantly.
 35:      * If an error occurs on sending the first mail the second mail is sent
 36:      * nonetheless.
 37:      *
 38:      * @see DefaultFormProcessor::_processStoredData()
 39:      * @throws PifaMailException if any mail could not be sent
 40:      */
 41:     protected function _processStoredData() {
 42: 
 43:         // array to collect errors
 44:         $errors = array();
 45: 
 46:         // client mail
 47:         try {
 48:             $mailOptions = $this->_getMailOptions(self::MAIL_MODE_CLIENT);
 49: 
 50:             // send mail
 51:             if ($mailOptions !== false) {
 52:                 $this->getForm()->toMailRecipient($mailOptions);
 53:             }
 54:         } catch (PifaMailException $e) {
 55:             $errors[] = mi18n("PIFA_CLIENT_MAIL") . ": " . $e->getMessage();
 56:         }
 57: 
 58:         // system mail
 59:         try {
 60:             $mailOptions = $this->_getMailOptions(self::MAIL_MODE_SYSTEM);
 61: 
 62:             // send mail
 63:             if ($mailOptions !== false) {
 64:                 $this->getForm()->toMailRecipient($mailOptions);
 65:             }
 66:         } catch (PifaMailException $e) {
 67:             $errors[] = mi18n("PIFA_SYSTEM_MAIL") . ": " . $e->getMessage();
 68:         }
 69: 
 70:         // throw errors
 71:         if (0 < count($errors)) {
 72:             throw new PifaMailException(implode('<br>', $errors));
 73:         }
 74:     }
 75: 
 76:     /**
 77:      * Sends a mail to the client or configured system address when mail template was selected.
 78:      *
 79:      * @param string $mode mail mode, must be "client" or "system"
 80:      * @return boolean|array
 81:      */
 82:     protected function _getMailOptions($mode) {
 83:         if ($mode != self::MAIL_MODE_CLIENT && $mode != self::MAIL_MODE_SYSTEM) {
 84:             return false;
 85:         }
 86: 
 87:         $bodyTemplate = $this->getModule()->getSetting('pifaform_mail_' . $mode . '_template');
 88:         if ($bodyTemplate == '') {
 89:             return false;
 90:         }
 91: 
 92:         // get values
 93:         $values = $this->getForm()->getValues();
 94: 
 95:         // get subject from template
 96:         $tpl = cSmartyFrontend::getInstance(true);
 97:         $tpl->assign('values', $values);
 98:         $subject = $tpl->fetch('eval:' . $this->getModule()->getSetting('pifaform_mail_' . $mode . '_subject'));
 99: 
100:         // get body from template
101:         $tpl = cSmartyFrontend::getInstance(true);
102:         $tpl->assign('values', $values);
103:         $body = $tpl->fetchGeneral($bodyTemplate);
104: 
105:         if ($mode == self::MAIL_MODE_CLIENT) {
106:             $mailTo = $values['email'];
107:         } else {
108:             $mailTo = $this->getModule()->getSetting('pifaform_mail_system_recipient_email');
109:         }
110: 
111:         if (cRegistry::getLanguageId() != 0) {
112:             $language = cRegistry::getLanguage();
113:             $encoding = $language->getField('encoding');
114:             if ($encoding == '') {
115:                 $encoding = 'UTF-8';
116:             }
117:         }
118: 
119:         $mailOptions = array(
120:             'from' => $this->getModule()->getSetting('pifaform_mail_' . $mode . '_from_email'),
121:             'fromName' => $this->getModule()->getSetting('pifaform_mail_' . $mode . '_from_name'),
122:             'to' => $mailTo,
123:             'subject' => $subject,
124:             'body' => $body,
125:             'charSet' => $encoding
126:         );
127: 
128:         // !!
129: 
130:         if ($mode == self::MAIL_MODE_SYSTEM) {
131:             $mailOptions['attachmentNames'] = $this->_getAttachmentNames();
132:             $mailOptions['attachmentStrings'] = $this->_getAttachmentStrings();
133:         }
134: 
135:         return $mailOptions;
136:     }
137: 
138:     /**
139:      * Return all files that were uploaded by the form as names of attachments
140:      * to be added to the system mail.
141:      *
142:      * @return array
143:      */
144:     protected function _getAttachmentNames() {
145: 
146:         // determine attachment names
147:         // these are already stored in the FS
148:         $attachmentNames = array();
149:         if (0 < count($this->getForm()->getFiles())) {
150:             $tableName = $this->getForm()->get('data_table');
151:             $lastInsertedId = $this->getForm()->getLastInsertedId();
152:             $cfg = cRegistry::getConfig();
153:             $destPath = $cfg['path']['contenido_cache'] . 'form_assistant/';
154:             foreach ($this->getForm()->getFiles() as $column => $file) {
155:                 if (!is_array($file)) {
156:                     continue;
157:                 }
158:                 $destName = $tableName . '_' . $lastInsertedId . '_' . $column;
159:                 $destName = preg_replace('/[^a-z0-9_]+/i', '_', $destName);
160:                 $attachmentNames[$column] = $destPath . $destName;
161:             }
162:         }
163: 
164:         return $attachmentNames;
165:     }
166: 
167:     /**
168:      * Returns an empty array cause there are no attachments that will be
169:      * created on the fly.
170:      *
171:      * @return array
172:      */
173:     protected function _getAttachmentStrings() {
174:         return array();
175:     }
176: }
177: 
178: ?>
CMS CONTENIDO 4.9.7 API documentation generated by ApiGen