3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.3 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2013 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
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. |
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. |
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 +--------------------------------------------------------------------+
32 * @copyright CiviCRM LLC (c) 2004-2013
38 * This class generates form components for scheduling reminders for Event
41 class CRM_Event_Form_ManageEvent_ScheduleReminders
extends CRM_Event_Form_ManageEvent
{
44 * Function to set variables up before form is built
49 function preProcess() {
52 $newReminder = CRM_Utils_Request
::retrieve('new', 'Boolean', $this, FALSE, FALSE);
53 if ($this->_action
& CRM_Core_Action
::UPDATE
&&
56 $field = 'civicrm_event';
57 if ($this->_isTemplate
) {
58 $field = 'event_template';
60 $reminderList = CRM_Core_BAO_ActionSchedule
::getList(FALSE, $field, $this->_id
);
61 if (is_array($reminderList)) {
62 // Add action links to each of the reminders
63 foreach ($reminderList as & $format) {
64 $action = CRM_Core_Action
::UPDATE + CRM_Core_Action
::DELETE
;
65 if ($format['is_active']) {
66 $action +
= CRM_Core_Action
::DISABLE
;
69 $action +
= CRM_Core_Action
::ENABLE
;
71 $links = CRM_Admin_Page_ScheduleReminders
::links();
72 $links[CRM_Core_Action
::DELETE
]['qs'] .= "&context=event&eventId={$this->_id}";
73 $links[CRM_Core_Action
::UPDATE
]['qs'] .= "&context=event&eventId={$this->_id}";
74 $format['action'] = CRM_Core_Action
::formLink(
77 array('id' => $format['id'])
80 $this->assign('rows', $reminderList);
86 * This function sets the default values for the form. For edit/view mode
87 * the default values are retrieved from the database
93 function setDefaultValues() {
95 $defaults['is_active'] = 1;
96 $defaults['record_activity'] = 1;
101 * Function to build the form
106 public function buildQuickForm() {
107 $field = 'civicrm_event';
108 if ($this->_isTemplate
) {
109 $field = 'event_template';
111 $this->_mappingID
= CRM_Core_DAO
::getFieldValue('CRM_Core_DAO_ActionMapping', $field, 'id', 'entity_value');
112 if (!$this->_mappingID
) {
113 CRM_Core_Error
::fatal('Could not find mapping for event scheduled reminders.');
116 parent
::buildQuickForm();
117 $this->add('text', 'title', ts('Reminder Name'),
119 'size' => 45, 'maxlength' => 128), TRUE
122 $selectionOptions = CRM_Core_BAO_ActionSchedule
::getSelection($this->_mappingID
);
123 extract($selectionOptions);
125 $entity = $this->add('select', 'entity', ts('Recipient(s)'), $sel3[$this->_mappingID
][0], TRUE);
126 $entity->setMultiple(TRUE);
128 //get the frequency units.
129 $this->_freqUnits
= array('hour' => 'hour') + CRM_Core_OptionGroup
::values('recur_frequency_units');
131 $numericOptions = CRM_Core_SelectValues
::getNumericOptions(0, 30);
134 $this->add('select', 'start_action_offset', ts('When'), $numericOptions);
136 foreach ($this->_freqUnits
as $val => $label) {
137 $freqUnitsDisplay[$val] = ts('%1(s)', array(1 => $label));
140 $this->addDate('absolute_date', ts('Start Date'), FALSE,
141 array('formatType' => 'mailing')
145 $this->add('select', 'start_action_unit', ts('Frequency'), $freqUnitsDisplay, TRUE);
147 $condition = array('before' => ts('before'),
148 'after' => ts('after'),
151 $this->add('select', 'start_action_condition', ts('Action Condition'), $condition);
153 $this->add('select', 'start_action_date', ts('Date Field'), $sel4, TRUE);
155 $this->addElement('checkbox', 'record_activity', ts('Record activity for automated email'));
157 $this->addElement('checkbox', 'is_repeat', ts('Repeat'),
158 NULL, array('onclick' => "return showHideByValue('is_repeat',true,'repeatFields','table-row','radio',false);")
161 $this->add('select', 'repetition_frequency_unit', ts('every'), $freqUnitsDisplay);
162 $this->add('select', 'repetition_frequency_interval', ts('every'), $numericOptions);
163 $this->add('select', 'end_frequency_unit', ts('until'), $freqUnitsDisplay);
164 $this->add('select', 'end_frequency_interval', ts('until'), $numericOptions);
165 $this->add('select', 'end_action', ts('Repetition Condition'), $condition, TRUE);
166 $this->add('select', 'end_date', ts('Date Field'), $sel4, TRUE);
168 $recipient = 'event_contacts';
169 $this->add('select', 'recipient', ts('Limit Recipients'), $sel5[$recipient],
170 FALSE, array('onClick' => "showHideByValue('recipient','manual','recipientManual','table-row','select',false); showHideByValue('recipient','group','recipientGroup','table-row','select',false);")
172 $recipientListing = $this->add('select', 'recipient_listing', ts('Recipient Listing'),
173 $sel3[$this->_mappingID
][0]
175 $recipientListing->setMultiple(TRUE);
178 $dataUrl = CRM_Utils_System
::url('civicrm/ajax/rest',
179 "className=CRM_Contact_Page_AJAX&fnName=getContactList&json=1&context=activity&reset=1",
183 $this->assign('dataUrl', $dataUrl);
185 $tokenUrl = CRM_Utils_System
::url('civicrm/ajax/checkemail',
189 $this->assign('tokenUrl', $tokenUrl);
190 $this->add('text', 'recipient_manual_id', ts('Manual Recipients'));
192 $this->addElement('select', 'group_id', ts('Group'),
193 CRM_Core_PseudoConstant
::staticGroup()
196 CRM_Mailing_BAO_Mailing
::commonCompose($this);
198 $this->add('text', 'subject', ts('Subject'),
199 CRM_Core_DAO
::getAttribute('CRM_Core_DAO_ActionSchedule', 'subject')
202 $this->add('checkbox', 'is_active', ts('Send email'));
204 $this->addFormRule(array('CRM_Event_Form_ManageEvent_ScheduleReminders', 'formRule'));
208 * global validation rules for the form
210 * @param array $fields posted values of the form
212 * @return array list of errors to be posted back to the form
216 static function formRule($fields) {
218 if (CRM_Utils_Array
::value('is_active', $fields) &&
219 CRM_Utils_System
::isNull($fields['subject'])
221 $errors['subject'] = ts('Subject is a required field.');
224 if (!CRM_Utils_System
::isNull($fields['absolute_date'])) {
225 if (CRM_Utils_Date
::format(CRM_Utils_Date
::processDate($fields['absolute_date'], NULL)) < CRM_Utils_Date
::format(date('YmdHi00'))) {
226 $errors['absolute_date'] = ts('Absolute date cannot be earlier than the current time.');
230 if (!empty($errors)) {
234 return empty($errors) ?
TRUE : $errors;
238 * Function to process the form
244 public function postProcess() {
245 if ($this->_action
& CRM_Core_Action
::DELETE
) {
247 CRM_Core_BAO_ActionSchedule
::del($this->_id
);
248 CRM_Core_Session
::setStatus(ts('Selected Reminder has been deleted.'), ts('Record Deleted'), 'success');
252 $values = $this->controller
->exportValues($this->getName());
260 foreach ($keys as $key) {
261 $params[$key] = CRM_Utils_Array
::value($key, $values);
265 'start_action_offset', 'start_action_unit',
266 'start_action_condition', 'start_action_date',
267 'repetition_frequency_unit',
268 'repetition_frequency_interval',
269 'end_frequency_unit',
270 'end_frequency_interval',
271 'end_action', 'end_date',
274 if ($absoluteDate = CRM_Utils_Array
::value('absolute_date', $params)) {
275 $params['absolute_date'] = CRM_Utils_Date
::processDate($absoluteDate);
276 foreach ($moreKeys as $mkey) {
277 $params[$mkey] = 'null';
281 $params['absolute_date'] = 'null';
282 foreach ($moreKeys as $mkey) {
283 $params[$mkey] = CRM_Utils_Array
::value($mkey, $values);
287 $params['body_text'] = CRM_Utils_Array
::value('text_message', $values);
288 $params['body_html'] = CRM_Utils_Array
::value('html_message', $values);
290 if (CRM_Utils_Array
::value('recipient', $values) == 'manual') {
291 $params['recipient_manual'] = CRM_Utils_Array
::value('recipient_manual_id', $values);
292 $params['group_id'] = $params['recipient'] = $params['recipient_listing'] = 'null';
294 elseif (CRM_Utils_Array
::value('recipient', $values) == 'group') {
295 $params['group_id'] = $values['group_id'];
296 $params['recipient_manual'] = $params['recipient'] = $params['recipient_listing'] = 'null';
298 elseif (!CRM_Utils_System
::isNull($values['recipient_listing'])) {
299 $params['recipient'] = CRM_Utils_Array
::value('recipient', $values);
300 $params['recipient_listing'] = implode(CRM_Core_DAO
::VALUE_SEPARATOR
,
301 CRM_Utils_Array
::value('recipient_listing', $values)
303 $params['group_id'] = $params['recipient_manual'] = 'null';
306 $params['recipient'] = CRM_Utils_Array
::value('recipient', $values);
307 $params['group_id'] = $params['recipient_manual'] = $params['recipient_listing'] = 'null';
310 $params['mapping_id'] = $this->_mappingID
;
312 $params['entity_value'] = $this->_id
;
313 $params['entity_status'] = implode(CRM_Core_DAO
::VALUE_SEPARATOR
, $values['entity']);
314 $params['is_active'] = CRM_Utils_Array
::value('is_active', $values, 0);
315 $params['is_repeat'] = CRM_Utils_Array
::value('is_repeat', $values, 0);
317 if (CRM_Utils_Array
::value('is_repeat', $values) == 0) {
318 $params['repetition_frequency_unit'] = 'null';
319 $params['repetition_frequency_interval'] = 'null';
320 $params['end_frequency_unit'] = 'null';
321 $params['end_frequency_interval'] = 'null';
322 $params['end_action'] = 'null';
323 $params['end_date'] = 'null';
325 $params['name'] = CRM_Utils_String
::munge($params['title'], '_', 64);
327 $composeFields = array(
328 'template', 'saveTemplate',
329 'updateTemplate', 'saveTemplateName',
332 //mail template is composed
333 $composeParams = array();
334 foreach ($composeFields as $key) {
335 if (CRM_Utils_Array
::value($key, $values)) {
336 $composeParams[$key] = $values[$key];
340 if (CRM_Utils_Array
::value('updateTemplate', $composeParams)) {
341 $templateParams = array(
342 'msg_text' => $params['body_text'],
343 'msg_html' => $params['body_html'],
344 'msg_subject' => $params['subject'],
348 $templateParams['id'] = $values['template'];
350 $msgTemplate = CRM_Core_BAO_MessageTemplates
::add($templateParams);
353 if (CRM_Utils_Array
::value('saveTemplate', $composeParams)) {
354 $templateParams = array(
355 'msg_text' => $params['body_text'],
356 'msg_html' => $params['body_html'],
357 'msg_subject' => $params['subject'],
361 $templateParams['msg_title'] = $composeParams['saveTemplateName'];
363 $msgTemplate = CRM_Core_BAO_MessageTemplates
::add($templateParams);
366 if (isset($msgTemplate->id
)) {
367 $params['msg_template_id'] = $msgTemplate->id
;
370 $params['msg_template_id'] = CRM_Utils_Array
::value('template', $values);
373 CRM_Core_BAO_ActionSchedule
::add($params, $ids);
375 $status = ts("Your new Reminder titled %1 has been saved.",
376 array(1 => "<strong>{$values['title']}</strong>")
379 CRM_Core_Session
::setStatus($status, ts('Saved'), 'success');
381 parent
::endPostProcess();
386 * Return a descriptive name for the page, used in wizard header
391 public function getTitle() {
392 return ts('Event Schedule Reminder');