Merge pull request #12549 from civicrm/5.4
[civicrm-core.git] / CRM / Contact / Form / Edit / Email.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 5 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2018 |
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-2018
32 */
33
34 /**
35 * Form helper class for an Email object.
36 */
37 class CRM_Contact_Form_Edit_Email {
38
39 /**
40 * Build the form object elements for an email object.
41 *
42 * @param CRM_Core_Form $form
43 * Reference to the form object.
44 * @param int $blockCount
45 * Block number to build.
46 * @param bool $blockEdit
47 * Is it block edit.
48 */
49 public static function buildQuickForm(&$form, $blockCount = NULL, $blockEdit = FALSE) {
50 // passing this via the session is AWFUL. we need to fix this
51 if (!$blockCount) {
52 $blockId = ($form->get('Email_Block_Count')) ? $form->get('Email_Block_Count') : 1;
53 }
54 else {
55 $blockId = $blockCount;
56 }
57
58 $form->applyFilter('__ALL__', 'trim');
59
60 //Email box
61 $form->addField("email[$blockId][email]", array('entity' => 'email', 'aria-label' => ts('Email %1', [1 => $blockId])));
62 $form->addRule("email[$blockId][email]", ts('Email is not valid.'), 'email');
63 if (isset($form->_contactType) || $blockEdit) {
64 //Block type
65 $form->addField("email[$blockId][location_type_id]", array('entity' => 'email', 'placeholder' => NULL, 'class' => 'eight', 'option_url' => NULL));
66
67 //TODO: Refactor on_hold field to select.
68 $multipleBulk = CRM_Core_BAO_Email::isMultipleBulkMail();
69
70 //On-hold select
71 if ($multipleBulk) {
72 $holdOptions = array(
73 0 => ts('- select -'),
74 1 => ts('On Hold Bounce'),
75 2 => ts('On Hold Opt Out'),
76 );
77 $form->addElement('select', "email[$blockId][on_hold]", '', $holdOptions);
78 }
79 else {
80 $form->addField("email[$blockId][on_hold]", array('entity' => 'email', 'type' => 'advcheckbox', 'aria-label' => ts('On Hold for Email %1?', [1 => $blockId])));
81 }
82
83 //Bulkmail checkbox
84 $form->assign('multipleBulk', $multipleBulk);
85 $js = array('id' => "Email_" . $blockId . "_IsBulkmail" , 'aria-label' => ts('Bulk Mailing for Email %1?', [1 => $blockId]));
86 if ($multipleBulk) {
87 $form->addElement('advcheckbox', "email[$blockId][is_bulkmail]", NULL, '', $js);
88 }
89 else {
90 if (!$blockEdit) {
91 $js['onClick'] = 'singleSelect( this.id );';
92 }
93 $form->addElement('radio', "email[$blockId][is_bulkmail]", '', '', '1', $js);
94 }
95
96 //is_Primary radio
97 $js = array('id' => "Email_" . $blockId . "_IsPrimary", 'aria-label' => ts('Email %1 is primary?', [1 => $blockId]));
98 if (!$blockEdit) {
99 $js['onClick'] = 'singleSelect( this.id );';
100 }
101
102 $form->addElement('radio', "email[$blockId][is_primary]", '', '', '1', $js);
103
104 if (CRM_Utils_System::getClassName($form) == 'CRM_Contact_Form_Contact') {
105
106 $form->add('textarea', "email[$blockId][signature_text]", ts('Signature (Text)'),
107 array('rows' => 2, 'cols' => 40)
108 );
109
110 $form->add('wysiwyg', "email[$blockId][signature_html]", ts('Signature (HTML)'),
111 array('rows' => 2, 'cols' => 40)
112 );
113 }
114 }
115 }
116
117 }