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
    • ContentSitemapHtml
    • ContentSitemapXml
    • ContentUserForum
    • NavigationTop
    • ScriptCookieDirective
  • mpAutoloaderClassMap
  • None
  • PHP
  • Plugin
    • ContentAllocation
    • CronjobOverview
    • FormAssistant
    • FrontendLogic
    • FrontendUsers
    • Linkchecker
    • ModRewrite
    • Newsletter
    • Repository
      • FrontendNavigation
      • KeywordDensity
    • SIWECOS
    • SmartyWrapper
    • UrlShortener
    • UserForum
    • Workflow
  • PluginManager
  • Setup
    • Form
    • GUI
    • Helper
      • Environment
      • Filesystem
      • MySQL
      • PHP
    • UpgradeJob

Classes

  • cContentTypePifaForm
  • DefaultFormModule
  • DefaultFormProcessor
  • ExampleOptionsDatasource
  • MailedFormProcessor
  • Pifa
  • PifaAbstractFormModule
  • PifaAbstractFormProcessor
  • PifaAjaxHandler
  • PifaExporter
  • PifaExternalOptionsDatasourceInterface
  • PifaField
  • PifaFieldCollection
  • PifaForm
  • PifaFormCollection
  • PifaImporter
  • PifaLeftBottomPage
  • PifaRightBottomFormDataPage
  • PifaRightBottomFormExportPage
  • PifaRightBottomFormFieldsPage
  • PifaRightBottomFormImportPage
  • PifaRightBottomFormPage

Exceptions

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