3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.4 |
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 'event.reminder.list',
85 $this->assign('rows', $reminderList);
91 * This function sets the default values for the form. For edit/view mode
92 * the default values are retrieved from the database
98 function setDefaultValues() {
100 $defaults['is_active'] = 1;
101 $defaults['record_activity'] = 1;
106 * Function to build the form
111 public function buildQuickForm() {
112 $field = 'civicrm_event';
113 if ($this->_isTemplate
) {
114 $field = 'event_template';
116 $this->_mappingID
= CRM_Core_DAO
::getFieldValue('CRM_Core_DAO_ActionMapping', $field, 'id', 'entity_value');
117 if (!$this->_mappingID
) {
118 CRM_Core_Error
::fatal('Could not find mapping for event scheduled reminders.');
121 parent
::buildQuickForm();
122 $this->add('text', 'title', ts('Reminder Name'),
129 $selectionOptions = CRM_Core_BAO_ActionSchedule
::getSelection($this->_mappingID
);
130 extract($selectionOptions);
132 $this->assign('recipientMapping', json_encode($recipientMapping));
134 $entity = $this->add('select', 'entity', ts('Recipient(s)'), $sel3[$this->_mappingID
][0], TRUE);
135 $entity->setMultiple(TRUE);
137 //get the frequency units.
138 $this->_freqUnits
= array('hour' => 'hour') + CRM_Core_OptionGroup
::values('recur_frequency_units');
140 $numericOptions = CRM_Core_SelectValues
::getNumericOptions(0, 30);
143 $this->add('select', 'start_action_offset', ts('When'), $numericOptions);
145 foreach ($this->_freqUnits
as $val => $label) {
146 $freqUnitsDisplay[$val] = ts('%1(s)', array(1 => $label));
149 $this->addDate('absolute_date', ts('Start Date'), FALSE,
150 array('formatType' => 'mailing')
154 $this->add('select', 'start_action_unit', ts('Frequency'), $freqUnitsDisplay, TRUE);
156 $condition = array('before' => ts('before'),
157 'after' => ts('after'),
160 $this->add('select', 'start_action_condition', ts('Action Condition'), $condition);
162 $this->add('select', 'start_action_date', ts('Date Field'), $sel4, TRUE);
164 $this->addElement('checkbox', 'record_activity', ts('Record activity for automated email'));
166 $this->addElement('checkbox', 'is_repeat', ts('Repeat'),
167 NULL, array('onclick' => "return showHideByValue('is_repeat',true,'repeatFields','table-row','radio',false);")
170 $this->add('select', 'repetition_frequency_unit', ts('every'), $freqUnitsDisplay);
171 $this->add('select', 'repetition_frequency_interval', ts('every'), $numericOptions);
172 $this->add('select', 'end_frequency_unit', ts('until'), $freqUnitsDisplay);
173 $this->add('select', 'end_frequency_interval', ts('until'), $numericOptions);
174 $this->add('select', 'end_action', ts('Repetition Condition'), $condition, TRUE);
175 $this->add('select', 'end_date', ts('Date Field'), $sel4, TRUE);
177 $recipient = 'event_contacts';
178 $limitOptions = array(1 => ts('Limit to'), 0 => ts('Addition to'));
179 $this->add('select', 'limit_to', ts('Limit Options'), $limitOptions);
181 $this->add('select', 'recipient', ts('Recipients'), $sel5[$recipient],
182 FALSE, array('onClick' => "showHideByValue('recipient','manual','recipientManual','table-row','select',false); showHideByValue('recipient','group','recipientGroup','table-row','select',false);")
184 $recipientListing = $this->add('select', 'recipient_listing', ts('Recipient Listing'),
185 $sel3[$this->_mappingID
][0]
187 $recipientListing->setMultiple(TRUE);
190 $dataUrl = CRM_Utils_System
::url('civicrm/ajax/rest',
191 "className=CRM_Contact_Page_AJAX&fnName=getContactList&json=1&context=activity&reset=1",
195 $this->assign('dataUrl', $dataUrl);
197 $tokenUrl = CRM_Utils_System
::url('civicrm/ajax/checkemail',
201 $this->assign('tokenUrl', $tokenUrl);
202 $this->add('text', 'recipient_manual_id', ts('Manual Recipients'));
204 $this->addElement('select', 'group_id', ts('Group'),
205 CRM_Core_PseudoConstant
::staticGroup()
208 CRM_Mailing_BAO_Mailing
::commonCompose($this);
210 $this->add('text', 'subject', ts('Subject'),
211 CRM_Core_DAO
::getAttribute('CRM_Core_DAO_ActionSchedule', 'subject')
214 $this->add('checkbox', 'is_active', ts('Send email'));
216 $this->addFormRule(array('CRM_Event_Form_ManageEvent_ScheduleReminders', 'formRule'));
220 * global validation rules for the form
222 * @param array $fields posted values of the form
224 * @return array list of errors to be posted back to the form
228 static function formRule($fields) {
230 if (CRM_Utils_Array
::value('is_active', $fields) &&
231 CRM_Utils_System
::isNull($fields['subject'])
233 $errors['subject'] = ts('Subject is a required field.');
236 if (!CRM_Utils_System
::isNull($fields['absolute_date'])) {
237 if (CRM_Utils_Date
::format(CRM_Utils_Date
::processDate($fields['absolute_date'], NULL)) < CRM_Utils_Date
::format(date('YmdHi00'))) {
238 $errors['absolute_date'] = ts('Absolute date cannot be earlier than the current time.');
242 if (!empty($errors)) {
246 return empty($errors) ?
TRUE : $errors;
250 * Function to process the form
256 public function postProcess() {
257 if ($this->_action
& CRM_Core_Action
::DELETE
) {
259 CRM_Core_BAO_ActionSchedule
::del($this->_id
);
260 CRM_Core_Session
::setStatus(ts('Selected Reminder has been deleted.'), ts('Record Deleted'), 'success');
264 $values = $this->controller
->exportValues($this->getName());
273 foreach ($keys as $key) {
274 $params[$key] = CRM_Utils_Array
::value($key, $values);
278 'start_action_offset',
280 'start_action_condition',
282 'repetition_frequency_unit',
283 'repetition_frequency_interval',
284 'end_frequency_unit',
285 'end_frequency_interval',
290 if ($absoluteDate = CRM_Utils_Array
::value('absolute_date', $params)) {
291 $params['absolute_date'] = CRM_Utils_Date
::processDate($absoluteDate);
292 foreach ($moreKeys as $mkey) {
293 $params[$mkey] = 'null';
297 $params['absolute_date'] = 'null';
298 foreach ($moreKeys as $mkey) {
299 $params[$mkey] = CRM_Utils_Array
::value($mkey, $values);
303 $params['body_text'] = CRM_Utils_Array
::value('text_message', $values);
304 $params['body_html'] = CRM_Utils_Array
::value('html_message', $values);
306 if (CRM_Utils_Array
::value('recipient', $values) == 'manual') {
307 $params['recipient_manual'] = CRM_Utils_Array
::value('recipient_manual_id', $values);
308 $params['group_id'] = $params['recipient'] = $params['recipient_listing'] = 'null';
310 elseif (CRM_Utils_Array
::value('recipient', $values) == 'group') {
311 $params['group_id'] = $values['group_id'];
312 $params['recipient_manual'] = $params['recipient'] = $params['recipient_listing'] = 'null';
314 elseif (!CRM_Utils_System
::isNull($values['recipient_listing'])) {
315 $params['recipient'] = CRM_Utils_Array
::value('recipient', $values);
316 $params['recipient_listing'] = implode(CRM_Core_DAO
::VALUE_SEPARATOR
,
317 CRM_Utils_Array
::value('recipient_listing', $values)
319 $params['group_id'] = $params['recipient_manual'] = 'null';
322 $params['recipient'] = CRM_Utils_Array
::value('recipient', $values);
323 $params['group_id'] = $params['recipient_manual'] = $params['recipient_listing'] = 'null';
326 $params['mapping_id'] = $this->_mappingID
;
328 $params['entity_value'] = $this->_id
;
329 $params['entity_status'] = implode(CRM_Core_DAO
::VALUE_SEPARATOR
, $values['entity']);
330 $params['is_active'] = CRM_Utils_Array
::value('is_active', $values, 0);
331 $params['is_repeat'] = CRM_Utils_Array
::value('is_repeat', $values, 0);
333 if (CRM_Utils_Array
::value('is_repeat', $values) == 0) {
334 $params['repetition_frequency_unit'] = 'null';
335 $params['repetition_frequency_interval'] = 'null';
336 $params['end_frequency_unit'] = 'null';
337 $params['end_frequency_interval'] = 'null';
338 $params['end_action'] = 'null';
339 $params['end_date'] = 'null';
341 $params['name'] = CRM_Utils_String
::munge($params['title'], '_', 64);
343 $composeFields = array(
344 'template', 'saveTemplate',
345 'updateTemplate', 'saveTemplateName',
348 //mail template is composed
349 $composeParams = array();
350 foreach ($composeFields as $key) {
351 if (CRM_Utils_Array
::value($key, $values)) {
352 $composeParams[$key] = $values[$key];
356 if (CRM_Utils_Array
::value('updateTemplate', $composeParams)) {
357 $templateParams = array(
358 'msg_text' => $params['body_text'],
359 'msg_html' => $params['body_html'],
360 'msg_subject' => $params['subject'],
364 $templateParams['id'] = $values['template'];
366 $msgTemplate = CRM_Core_BAO_MessageTemplate
::add($templateParams);
369 if (CRM_Utils_Array
::value('saveTemplate', $composeParams)) {
370 $templateParams = array(
371 'msg_text' => $params['body_text'],
372 'msg_html' => $params['body_html'],
373 'msg_subject' => $params['subject'],
377 $templateParams['msg_title'] = $composeParams['saveTemplateName'];
379 $msgTemplate = CRM_Core_BAO_MessageTemplate
::add($templateParams);
382 if (isset($msgTemplate->id
)) {
383 $params['msg_template_id'] = $msgTemplate->id
;
386 $params['msg_template_id'] = CRM_Utils_Array
::value('template', $values);
389 CRM_Core_BAO_ActionSchedule
::add($params, $ids);
391 $status = ts("Your new Reminder titled %1 has been saved.",
392 array(1 => "<strong>{$values['title']}</strong>")
395 CRM_Core_Session
::setStatus($status, ts('Saved'), 'success');
397 parent
::endPostProcess();
402 * Return a descriptive name for the page, used in wizard header
407 public function getTitle() {
408 return ts('Event Schedule Reminder');