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
    • 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:      */
 40:     protected function _processStoredData() {
 41: 
 42:         // array to collect errors
 43:         $errors = array();
 44: 
 45:         // client mail
 46:         try {
 47:             $mailOptions = $this->_getMailOptions(self::MAIL_MODE_CLIENT);
 48: 
 49:             // send mail
 50:             if ($mailOptions !== false) {
 51:                 $this->getForm()->toMailRecipient($mailOptions);
 52:             }
 53:         } catch (PifaMailException $e) {
 54:             $errors[] = mi18n("PIFA_CLIENT_MAIL") . ": " . $e->getMessage();
 55:         }
 56: 
 57:         // system mail
 58:         try {
 59:             $mailOptions = $this->_getMailOptions(self::MAIL_MODE_SYSTEM);
 60: 
 61:             // send mail
 62:             if ($mailOptions !== false) {
 63:                 $this->getForm()->toMailRecipient($mailOptions);
 64:             }
 65:         } catch (PifaMailException $e) {
 66:             $errors[] = mi18n("PIFA_SYSTEM_MAIL") . ": " . $e->getMessage();
 67:         }
 68: 
 69:         // throw errors
 70:         if (0 < count($errors)) {
 71:             throw new PifaMailException(implode('<br>', $errors));
 72:         }
 73:     }
 74: 
 75:     /**
 76:      * Sends a mail to the client or configured system address when mail template was selected.
 77:      *
 78:      * @param string $mode mail mode, must be "client" or "system"
 79:      * @return boolean|array
 80:      */
 81:     protected function _getMailOptions($mode) {
 82:         if ($mode != self::MAIL_MODE_CLIENT && $mode != self::MAIL_MODE_SYSTEM) {
 83:             return false;
 84:         }
 85: 
 86:         $bodyTemplate = $this->getModule()->getSetting('pifaform_mail_' . $mode . '_template');
 87:         if ($bodyTemplate == '') {
 88:             return false;
 89:         }
 90: 
 91:         // get values
 92:         $values = $this->getForm()->getValues();
 93: 
 94:         // get subject from template
 95:         $tpl = cSmartyFrontend::getInstance(true);
 96:         $tpl->assign('values', $values);
 97:         $subject = $tpl->fetch('eval:' . $this->getModule()->getSetting('pifaform_mail_' . $mode . '_subject'));
 98: 
 99:         // get body from template
100:         $tpl = cSmartyFrontend::getInstance(true);
101:         $tpl->assign('values', $values);
102:         $body = $tpl->fetchGeneral($bodyTemplate);
103: 
104:         if ($mode == self::MAIL_MODE_CLIENT) {
105:             $mailTo = $values['email'];
106:         } else {
107:             $mailTo = $this->getModule()->getSetting('pifaform_mail_system_recipient_email');
108:         }
109: 
110:         if (cRegistry::getLanguageId() != 0) {
111:             $language = cRegistry::getLanguage();
112:             $encoding = $language->getField('encoding');
113:             if ($encoding == '') {
114:                 $encoding = 'UTF-8';
115:             }
116:         }
117: 
118:         $mailOptions = array(
119:             'from' => $this->getModule()->getSetting('pifaform_mail_' . $mode . '_from_email'),
120:             'fromName' => $this->getModule()->getSetting('pifaform_mail_' . $mode . '_from_name'),
121:             'to' => $mailTo,
122:             'subject' => $subject,
123:             'body' => $body,
124:             'charSet' => $encoding
125:         );
126: 
127:         // !!
128: 
129:         if ($mode == self::MAIL_MODE_SYSTEM) {
130:             $mailOptions['attachmentNames'] = $this->_getAttachmentNames();
131:             $mailOptions['attachmentStrings'] = $this->_getAttachmentStrings();
132:         }
133: 
134:         return $mailOptions;
135:     }
136: 
137:     /**
138:      * Return all files that were uploaded by the form as names of attachments
139:      * to be added to the system mail.
140:      *
141:      * @return array
142:      */
143:     protected function _getAttachmentNames() {
144: 
145:         // determine attachment names
146:         // these are already stored in the FS
147:         $attachmentNames = array();
148:         if (0 < count($this->getForm()->getFiles())) {
149:             $tableName = $this->getForm()->get('data_table');
150:             $lastInsertedId = $this->getForm()->getLastInsertedId();
151:             $cfg = cRegistry::getConfig();
152:             $destPath = $cfg['path']['contenido_cache'] . 'form_assistant/';
153:             foreach ($this->getForm()->getFiles() as $column => $file) {
154:                 if (!is_array($file)) {
155:                     continue;
156:                 }
157:                 $destName = $tableName . '_' . $lastInsertedId . '_' . $column;
158:                 $destName = preg_replace('/[^a-z0-9_]+/i', '_', $destName);
159:                 $attachmentNames[$column] = $destPath . $destName;
160:             }
161:         }
162: 
163:         return $attachmentNames;
164:     }
165: 
166:     /**
167:      * Returns an empty array cause there are no attachments that will be
168:      * created on the fly.
169:      *
170:      * @return array
171:      */
172:     protected function _getAttachmentStrings() {
173:         return array();
174:     }
175: }
176: 
177: ?>
CMS CONTENIDO 4.10.0 API documentation generated by ApiGen 2.8.0