Fix for CRM-15729
[civicrm-core.git] / CRM / Contact / Form / Edit / Email.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.6 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
9 | |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
13 | |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
18 | |
19 | You should have received a copy of the GNU Affero General Public |
20 | License and the CiviCRM Licensing Exception along |
21 | with this program; if not, contact CiviCRM LLC |
22 | at info[AT]civicrm[DOT]org. If you have questions about the |
23 | GNU Affero General Public License or the licensing of CiviCRM, |
24 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
25 +--------------------------------------------------------------------+
26 */
27
28 /**
29 *
30 * @package CRM
31 * @copyright CiviCRM LLC (c) 2004-2014
32 * $Id$
33 *
34 */
35
36 /**
37 * form helper class for an Email object
38 */
39 class CRM_Contact_Form_Edit_Email {
40
41 /**
42 * Build the form object elements for an email object.
43 *
44 * @param CRM_Core_Form $form
45 * Reference to the form object.
46 * @param int $blockCount
47 * Block number to build.
48 * @param bool $blockEdit
49 * Is it block edit.
50 *
51 * @return void
52 */
53 public static function buildQuickForm(&$form, $blockCount = NULL, $blockEdit = FALSE) {
54 // passing this via the session is AWFUL. we need to fix this
55 if (!$blockCount) {
56 $blockId = ($form->get('Email_Block_Count')) ? $form->get('Email_Block_Count') : 1;
57 }
58 else {
59 $blockId = $blockCount;
60 }
61
62 $form->applyFilter('__ALL__', 'trim');
63
64 //Email box
65 $form->addElement('text', "email[$blockId][email]", ts('Email'), CRM_Core_DAO::getAttribute('CRM_Core_DAO_Email', 'email'));
66 $form->addRule("email[$blockId][email]", ts('Email is not valid.'), 'email');
67 if (isset($form->_contactType) || $blockEdit) {
68 //Block type
69 $form->addSelect("email[$blockId][location_type_id]", array(
70 'entity' => 'email',
71 'class' => 'eight',
72 'placeholder' => NULL,
73 ));
74
75 $multipleBulk = CRM_Core_BAO_Email::isMultipleBulkMail();
76
77 //On-hold select
78 if ($multipleBulk) {
79 $holdOptions = array(
80 0 => ts('- select -'),
81 1 => ts('On Hold Bounce'),
82 2 => ts('On Hold Opt Out'),
83 );
84 $form->addElement('select', "email[$blockId][on_hold]", '', $holdOptions);
85 }
86 else {
87 $form->addElement('advcheckbox', "email[$blockId][on_hold]", NULL);
88 }
89
90 //Bulkmail checkbox
91 $form->assign('multipleBulk', $multipleBulk);
92 if ($multipleBulk) {
93 $js = array('id' => "Email_" . $blockId . "_IsBulkmail");
94 $form->addElement('advcheckbox', "email[$blockId][is_bulkmail]", NULL, '', $js);
95 }
96 else {
97 $js = array('id' => "Email_" . $blockId . "_IsBulkmail");
98 if (!$blockEdit) {
99 $js['onClick'] = 'singleSelect( this.id );';
100 }
101 $form->addElement('radio', "email[$blockId][is_bulkmail]", '', '', '1', $js);
102 }
103
104 //is_Primary radio
105 $js = array('id' => "Email_" . $blockId . "_IsPrimary");
106 if (!$blockEdit) {
107 $js['onClick'] = 'singleSelect( this.id );';
108 }
109
110 $form->addElement('radio', "email[$blockId][is_primary]", '', '', '1', $js);
111
112 if (CRM_Utils_System::getClassName($form) == 'CRM_Contact_Form_Contact') {
113
114 $form->add('textarea', "email[$blockId][signature_text]", ts('Signature (Text)'),
115 array('rows' => 2, 'cols' => 40)
116 );
117
118 $form->addWysiwyg("email[$blockId][signature_html]", ts('Signature (HTML)'),
119 array('rows' => 2, 'cols' => 40)
120 );
121 }
122 }
123 }
124
125 }