Overview

Packages

  • Horde
    • Block
  • None
  • Ulaform

Classes

  • Ulaform
  • Ulaform_Action
  • Ulaform_Action_Mailto
  • Ulaform_Action_Sql
  • Ulaform_Api
  • Ulaform_Driver
  • Ulaform_Driver_Sql
  • Ulaform_Exception
  • Ulaform_Factory_Action
  • Ulaform_Factory_Driver
  • Overview
  • Package
  • Class
  • Tree
  1: <?php
  2: /**
  3:  * Ulaform_Action_Mailto Class provides a Ulaform action driver to mail the
  4:  * results of a form to one or more recipients.
  5:  *
  6:  * Copyright 2003-2012 Horde LLC (http://www.horde.org/)
  7:  *
  8:  * See the enclosed file COPYING for license information (GPL). If you
  9:  * did not receive this file, see http://www.horde.org/licenses/gpl.
 10:  *
 11:  * @author  Marko Djukic <marko@oblo.com>
 12:  * @package Ulaform
 13:  */
 14: class Ulaform_Action_Mailto extends Ulaform_Action {
 15: 
 16:     /**
 17:      * Actually carry out the action.
 18:      */
 19:     public function doAction($form_params, $form_data, $fields)
 20:     {
 21:         global $conf;
 22: 
 23:         $mail = new Horde_Mime_Mail();
 24:         $mail->addHeader('From', $form_params['from']);
 25:         $mail->addHeader('Subject', $form_params['subject']);
 26:         $mail->addHeader('To', $form_params['to']);
 27:         if (!empty($form_params['cc'])) {
 28:             $mail->addHeader('Cc', $form_params['cc']);
 29:         }
 30:         if (!empty($form_params['bcc'])) {
 31:             $mail->addHeader('Bcc', $form_params['bcc']);
 32:         }
 33: 
 34:         $body = '';
 35:         foreach ($fields as $field) {
 36:             $value = array_shift($form_data);
 37:             switch ($field['field_type']) {
 38:             case 'file':
 39:             case 'image':
 40:                 if (!empty($value['file'])) {
 41:                     $mail->addAttachment($value['file'], $value['name'], $value['type']);
 42:                 }
 43:                 break;
 44: 
 45:             default:
 46:                 $body .= $field['field_label'] . ': ' .
 47:                          $this->_formatFormData($value) . "\n";
 48:                 break;
 49:             }
 50:         }
 51: 
 52:         $mail->setBody($body);
 53:         return $mail->send($GLOBALS['injector']->getInstance('Horde_Mail'));
 54:     }
 55: 
 56:     /**
 57:      * Identifies this action driver and returns a brief description, used by
 58:      * admin when configuring an action for a form and set up using Horde_Form.
 59:      *
 60:      * @return array  Array of required parameters.
 61:      */
 62:     static public function getInfo()
 63:     {
 64:         $info['name'] = _("Mailto");
 65:         $info['desc'] = _("This driver allows the sending of form results via email to one or more recipients.");
 66: 
 67:         return $info;
 68:     }
 69: 
 70:     /**
 71:      * Returns the required parameters for this action driver, used by admin
 72:      * when configuring an action for a form and set up using Horde_Form.
 73:      *
 74:      * @return array  Array of required parameters.
 75:      */
 76:     static public function getParams()
 77:     {
 78:         $params = array();
 79:         $params['subject'] = array('label' => _("Subject"), 'type' => 'text');
 80:         $params['from']    = array('label' => _("From"), 'type' => 'email');
 81:         $params['to']      = array('label' => _("To"),
 82:                                    'type' => 'email',
 83:                                    'params' => array(true));
 84:         $params['cc']      = array('label' => _("Cc"),
 85:                                    'type' => 'email',
 86:                                    'required' => false,
 87:                                    'params' => array(true));
 88:         $params['bcc']     = array('label' => _("Bcc"),
 89:                                    'type' => 'email',
 90:                                    'required' => false,
 91:                                    'params' => array(true));
 92: 
 93:         return $params;
 94:     }
 95: 
 96:     /**
 97:      * Returns an email-friendly string containing the field data supplied.
 98:      * Mainly to deal with form data supplied in an array structure.
 99:      *
100:      * @return string
101:      */
102:     protected function _formatFormData($field_data)
103:     {
104:         $body = '';
105:         if (!is_array($field_data)) {
106:             $body = $field_data;
107:         } else {
108:             foreach ($field_data as $data) {
109:                 $body .= empty($body) ? $this->_formatFormData($data)
110:                             : ', ' . $this->_formatFormData($data);
111:             }
112:         }
113:         return $body;
114:     }
115: 
116: }
117: 
API documentation generated by ApiGen