Merge branch '4.4' into master
[civicrm-core.git] / CRM / Admin / Form / ScheduleReminders.php
index ccda529b21e6565c911b62418d1c8e90a6e5d097..1c5cbb67d2247762aeae279466d594ff59fb4bce 100644 (file)
@@ -1,7 +1,7 @@
 <?php
 /*
  +--------------------------------------------------------------------+
- | CiviCRM version 4.4                                                |
+ | CiviCRM version 4.5                                                |
  +--------------------------------------------------------------------+
  | Copyright (C) 2011 Marty Wright                                    |
  | Licensed to CiviCRM under the Academic Free License version 3.0.   |
@@ -29,7 +29,7 @@
 /**
  *
  * @package CRM
- * @copyright CiviCRM LLC (c) 2004-2013
+ * @copyright CiviCRM LLC (c) 2004-2014
  * $Id$
  *
  */
@@ -77,7 +77,7 @@ class CRM_Admin_Form_ScheduleReminders extends CRM_Admin_Form {
       }
     }
 
-    if (!empty($_POST) && CRM_Utils_Array::value('entity', $_POST)) {
+    if (!empty($_POST) && !empty($_POST['entity'])) {
       $mappingID = $_POST['entity'][0];
     }
     elseif ($this->_mappingID) {
@@ -126,7 +126,7 @@ class CRM_Admin_Form_ScheduleReminders extends CRM_Admin_Form {
     }
 
     //get the frequency units.
-    $this->_freqUnits = array('hour' => 'hour') + CRM_Core_OptionGroup::values('recur_frequency_units');
+    $this->_freqUnits = CRM_Core_SelectValues::getScheduleReminderFrequencyUnits();
 
     //pass the mapping ID in UPDATE mode
     $mappings = CRM_Core_BAO_ActionSchedule::getMapping($mappingID);
@@ -202,30 +202,17 @@ class CRM_Admin_Form_ScheduleReminders extends CRM_Admin_Form {
       FALSE, array('onClick' => "showHideByValue('recipient','manual','recipientManual','table-row','select',false); showHideByValue('recipient','group','recipientGroup','table-row','select',false);")
     );
 
-    if (CRM_Utils_Array::value('is_recipient_listing', $_POST)) {
+    if (!empty($_POST['is_recipient_listing'])) {
       $recipientListingOptions = CRM_Core_BAO_ActionSchedule::getRecipientListing($_POST['entity'][0], $_POST['recipient']);
     }
-    elseif (CRM_Utils_Array::value('recipient_listing', $this->_values)) {
+    elseif (!empty($this->_values['recipient_listing'])) {
       $recipientListingOptions = CRM_Core_BAO_ActionSchedule::getRecipientListing($this->_values['mapping_id'], $this->_values['recipient']);
     }
     $recipientListing = $this->add('select', 'recipient_listing', ts('Recipient Listing'), $recipientListingOptions);
     $recipientListing->setMultiple(TRUE);
     $this->add('hidden', 'is_recipient_listing', empty($recipientListingOptions) ? FALSE : TRUE, array('id' => 'is_recipient_listing'));
 
-    //auto-complete url
-    $dataUrl = CRM_Utils_System::url('civicrm/ajax/rest',
-      'className=CRM_Contact_Page_AJAX&fnName=getContactList&json=1&context=activity&reset=1',
-      FALSE, NULL, FALSE
-    );
-
-    $this->assign('dataUrl', $dataUrl);
-    //token input url
-    $tokenUrl = CRM_Utils_System::url('civicrm/ajax/checkemail',
-      'noemail=1',
-      FALSE, NULL, FALSE
-    );
-    $this->assign('tokenUrl', $tokenUrl);
-    $this->add('text', 'recipient_manual_id', ts('Manual Recipients'));
+    $this->addEntityRef('recipient_manual_id', ts('Manual Recipients'), array('multiple' => TRUE, 'create' => TRUE));
 
     $this->addElement(
       'select',
@@ -262,7 +249,7 @@ class CRM_Admin_Form_ScheduleReminders extends CRM_Admin_Form {
       $errors['entity'] = ts('Please select appropriate value');
     }
 
-    if (CRM_Utils_Array::value('is_active', $fields) &&
+    if (!empty($fields['is_active']) &&
       CRM_Utils_System::isNull($fields['subject'])
     ) {
       $errors['subject'] = ts('Subject is a required field.');
@@ -273,7 +260,7 @@ class CRM_Admin_Form_ScheduleReminders extends CRM_Admin_Form {
     }
 
     if (!CRM_Utils_System::isNull($fields['absolute_date'])) {
-      if (CRM_Utils_Date::format(CRM_Utils_Date::processDate($fields['absolute_date'], NULL)) < CRM_Utils_Date::format(date('YmdHi00'))) {
+      if (CRM_Utils_Date::format(CRM_Utils_Date::processDate($fields['absolute_date'], NULL)) < CRM_Utils_Date::format(date('Ymd'))) {
         $errors['absolute_date'] = ts('Absolute date cannot be earlier than the current time.');
       }
     }
@@ -315,19 +302,12 @@ class CRM_Admin_Form_ScheduleReminders extends CRM_Admin_Form {
       $defaults['text_message'] = CRM_Utils_Array::value('body_text', $defaults);
       $defaults['html_message'] = CRM_Utils_Array::value('body_html', $defaults);
       $defaults['template'] = CRM_Utils_Array::value('msg_template_id', $defaults);
-      if (CRM_Utils_Array::value('group_id', $defaults)) {
+      if (!empty($defaults['group_id'])) {
         $defaults['recipient'] = 'group';
       }
-      elseif (CRM_Utils_Array::value('recipient_manual', $defaults)) {
+      elseif (!empty($defaults['recipient_manual'])) {
         $defaults['recipient'] = 'manual';
-        $recipients = array();
-        foreach (explode(',', $defaults['recipient_manual']) as $cid) {
-          $recipients[$cid] = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact',
-            $cid,
-            'sort_name'
-          );
-        }
-        $this->assign('recipients', $recipients);
+        $defaults['recipient_manual_id'] = $defaults['recipient_manual'];
       }
     }
 
@@ -458,12 +438,12 @@ class CRM_Admin_Form_ScheduleReminders extends CRM_Admin_Form {
 
     $composeParams = array();
     foreach ($composeFields as $key) {
-      if (CRM_Utils_Array::value($key, $values)) {
+      if (!empty($values[$key])) {
         $composeParams[$key] = $values[$key];
       }
     }
 
-    if (CRM_Utils_Array::value('updateTemplate', $composeParams)) {
+    if (!empty($composeParams['updateTemplate'])) {
       $templateParams = array(
         'msg_text' => $params['body_text'],
         'msg_html' => $params['body_html'],
@@ -476,7 +456,7 @@ class CRM_Admin_Form_ScheduleReminders extends CRM_Admin_Form {
       $msgTemplate = CRM_Core_BAO_MessageTemplate::add($templateParams);
     }
 
-    if (CRM_Utils_Array::value('saveTemplate', $composeParams)) {
+    if (!empty($composeParams['saveTemplate'])) {
       $templateParams = array(
         'msg_text' => $params['body_text'],
         'msg_html' => $params['body_html'],