Merge remote-tracking branch 'upstream/4.5' into 4.5-master-2015-03-09-21-44-34
authorkurund <kurund@civicrm.org>
Mon, 9 Mar 2015 16:27:45 +0000 (21:57 +0530)
committerkurund <kurund@civicrm.org>
Mon, 9 Mar 2015 16:27:45 +0000 (21:57 +0530)
Conflicts:
CRM/Contact/Page/AJAX.php
CRM/Core/Form.php
CRM/Core/Page/AJAX.php
sql/civicrm_generated.mysql
xml/version.xml

19 files changed:
CRM/Activity/Page/AJAX.php
CRM/Batch/Page/AJAX.php
CRM/Campaign/Page/AJAX.php
CRM/Contact/Page/AJAX.php
CRM/Core/Form.php
CRM/Core/Page/AJAX.php
CRM/Core/xml/Menu/Contact.xml
CRM/Financial/Page/AJAX.php
CRM/Group/Page/AJAX.php
CRM/Mailing/BAO/Component.php
CRM/Mailing/BAO/Mailing.php
CRM/Mailing/Form/Component.php
CRM/Mailing/Page/AJAX.php
CRM/Pledge/Page/AJAX.php
CRM/Upgrade/Incremental/sql/4.5.8.mysql.tpl [new file with mode: 0644]
CRM/Upgrade/Incremental/sql/4.5.9.mysql.tpl [new file with mode: 0644]
api/v3/MailingComponent.php
api/v3/MessageTemplate.php
templates/CRM/Contact/Page/View/Summary.js

index dc6b5323ba1e0d57a6fc2c2d565c3e0636e98f8c..5e11dc87b1ecb1a336e924cbb1bd2b906baf0f00 100644 (file)
@@ -80,6 +80,7 @@ class CRM_Activity_Page_AJAX {
       'class',
     );
 
+    header('Content-Type: application/json');
     echo CRM_Utils_JSON::encodeDataTableSelector($activities, $sEcho, $iTotal, $iFilteredTotal, $selectorElements);
     CRM_Utils_System::civiExit();
   }
@@ -115,6 +116,7 @@ class CRM_Activity_Page_AJAX {
     $iFilteredTotal = $iTotal = $relGlobalTotalCount;
     $selectorElements = array('sort_name', 'phone', 'email');
 
+    header('Content-Type: application/json');
     echo CRM_Utils_JSON::encodeDataTableSelector($relGlobal, $sEcho, $iTotal, $iFilteredTotal, $selectorElements);
     CRM_Utils_System::civiExit();
   }
@@ -178,6 +180,7 @@ class CRM_Activity_Page_AJAX {
     $iFilteredTotal = $iTotal = $params['total'] = count($allClientRelationships);
     $selectorElements = array('relation', 'name', 'phone', 'email');
 
+    header('Content-Type: application/json');
     echo CRM_Utils_JSON::encodeDataTableSelector($clientRelationships, $sEcho, $iTotal, $iFilteredTotal, $selectorElements);
     CRM_Utils_System::civiExit();
   }
@@ -315,6 +318,7 @@ class CRM_Activity_Page_AJAX {
     $iFilteredTotal = $iTotal = $params['total'] = count($allCaseRelationships);
     $selectorElements = array('relation', 'name', 'phone', 'email', 'actions');
 
+    header('Content-Type: application/json');
     echo CRM_Utils_JSON::encodeDataTableSelector($caseRelationships, $sEcho, $iTotal, $iFilteredTotal, $selectorElements);
     CRM_Utils_System::civiExit();
   }
@@ -543,6 +547,7 @@ class CRM_Activity_Page_AJAX {
       'class',
     );
 
+    header('Content-Type: application/json');
     echo CRM_Utils_JSON::encodeDataTableSelector($activities, $sEcho, $iTotal, $iFilteredTotal, $selectorElements);
     CRM_Utils_System::civiExit();
   }
index 6c66b66bd2e940f561e6f03ecd0965b8596a9356..0bea0dcb5296468715c01bc77e60d2823577fdb1 100644 (file)
@@ -114,6 +114,7 @@ class CRM_Batch_Page_AJAX {
         'links',
       );
     }
+    header('Content-Type: application/json');
     echo CRM_Utils_JSON::encodeDataTableSelector($batches, $sEcho, $iTotal, $iFilteredTotal, $selectorElements);
     CRM_Utils_System::civiExit();
   }
index 0d7b5e2f8897c92318d25e50d0c232bb89ea1353..79a47cc4defcf75f1e62156f0c081da450934c0a 100644 (file)
@@ -360,6 +360,7 @@ class CRM_Campaign_Page_AJAX {
 
     $iFilteredTotal = $iTotal;
 
+    header('Content-Type: application/json');
     echo CRM_Utils_JSON::encodeDataTableSelector($searchRows, $sEcho, $iTotal, $iFilteredTotal, $selectorElements);
     CRM_Utils_System::civiExit();
   }
@@ -659,6 +660,7 @@ class CRM_Campaign_Page_AJAX {
 
     $iFilteredTotal = $iTotal;
 
+    header('Content-Type: application/json');
     echo CRM_Utils_JSON::encodeDataTableSelector($searchRows, $sEcho, $iTotal, $iFilteredTotal, $selectorElements);
     CRM_Utils_System::civiExit();
   }
@@ -762,6 +764,7 @@ class CRM_Campaign_Page_AJAX {
 
     $iFilteredTotal = $iTotal;
 
+    header('Content-Type: application/json');
     echo CRM_Utils_JSON::encodeDataTableSelector($searchRows, $sEcho, $iTotal, $iFilteredTotal, $selectorElements);
     CRM_Utils_System::civiExit();
   }
@@ -860,6 +863,7 @@ class CRM_Campaign_Page_AJAX {
 
     $iFilteredTotal = $iTotal;
 
+    header('Content-Type: application/json');
     echo CRM_Utils_JSON::encodeDataTableSelector($searchRows, $sEcho, $iTotal, $iFilteredTotal, $selectorElements);
     CRM_Utils_System::civiExit();
   }
index 26c4fc749874b7aba067d75e7582cd6bd182e077..0da9dd3698176d151dc5572bf41880b3e15d1e9e 100644 (file)
@@ -46,64 +46,7 @@ class CRM_Contact_Page_AJAX {
   const AUTOCOMPLETE_TTL = 21600; // 6hr; 6*60*60
 
   /**
-   * @deprecated
-   */
-  public static function getContactList() {
-    // if context is 'customfield'
-    if (CRM_Utils_Array::value('context', $_GET) == 'customfield') {
-      return self::contactReference();
-    }
-
-    $params = array('version' => 3, 'check_permissions' => TRUE);
-
-    // String params
-    // FIXME: param keys don't match input keys, using this array to translate
-    $whitelist = array(
-      's' => 'name',
-      'fieldName' => 'field_name',
-      'tableName' => 'table_name',
-      'context' => 'context',
-      'rel' => 'rel',
-      'contact_sub_type' => 'contact_sub_type',
-      'contact_type' => 'contact_type',
-    );
-    foreach ($whitelist as $key => $param) {
-      if (!empty($_GET[$key])) {
-        $params[$param] = $_GET[$key];
-      }
-    }
-
-    //CRM-10687: Allow quicksearch by multiple fields
-    if (!empty($params['field_name'])) {
-      if ($params['field_name'] == 'phone_numeric') {
-        $params['name'] = preg_replace('/[^\d]/', '', $params['name']);
-      }
-      if (!$params['name']) {
-        CRM_Utils_System::civiExit();
-      }
-    }
-
-    // Numeric params
-    $whitelist = array(
-      'limit',
-      'org',
-      'employee_id',
-      'cid',
-      'id',
-      'cmsuser',
-    );
-    foreach ($whitelist as $key) {
-      if (!empty($_GET[$key]) && is_numeric($_GET[$key])) {
-        $params[$key] = $_GET[$key];
-      }
-    }
-
-    $result = civicrm_api('Contact', 'getquick', $params);
-    CRM_Core_Page_AJAX::autocompleteResults(CRM_Utils_Array::value('values', $result), 'data');
-  }
-
-  /**
-   * Ajax callback for custom fields of type ContactReference.
+   * Ajax callback for custom fields of type ContactReference
    *
    * Todo: Migrate contact reference fields to use EntityRef
    */
@@ -206,7 +149,7 @@ class CRM_Contact_Page_AJAX {
       $contactList[] = array('id' => $value['id'], 'text' => implode(' :: ', $view));
     }
 
-    CRM_Utils_System::civiExit(json_encode($contactList));
+    CRM_Utils_JSON::output($contactList);
   }
 
   /**
@@ -344,198 +287,17 @@ class CRM_Contact_Page_AJAX {
   }
 
   public static function groupTree() {
+    header('Content-Type: application/json');
     $gids = CRM_Utils_Type::escape($_GET['gids'], 'String');
     echo CRM_Contact_BAO_GroupNestingCache::json($gids);
     CRM_Utils_System::civiExit();
   }
 
-  /**
-   * @deprecated
-   * Old quicksearch function. No longer used in core.
-   * @todo: Remove this function and associated menu entry in CiviCRM 5
-   */
-  public static function search() {
-    $json = TRUE;
-    $name = CRM_Utils_Array::value('name', $_GET, '');
-    if (!array_key_exists('name', $_GET)) {
-      $name = CRM_Utils_Array::value('s', $_GET) . '%';
-      $json = FALSE;
-    }
-    $name = CRM_Utils_Type::escape($name, 'String');
-    $whereIdClause = '';
-    if (!empty($_GET['id'])) {
-      $json = TRUE;
-      if (is_numeric($_GET['id'])) {
-        $id = CRM_Utils_Type::escape($_GET['id'], 'Integer');
-        $whereIdClause = " AND civicrm_contact.id = {$id}";
-      }
-      else {
-        $name = $_GET['id'];
-      }
-    }
-
-    $elements = array();
-    if ($name || isset($id)) {
-      $name = $name . '%';
-
-      //contact's based of relationhip type
-      $relType = NULL;
-      if (isset($_GET['rel'])) {
-        $relation = explode('_', $_GET['rel']);
-        $relType = CRM_Utils_Type::escape($relation[0], 'Integer');
-        $rel = CRM_Utils_Type::escape($relation[2], 'String');
-      }
-
-      //shared household info
-      $shared = NULL;
-      if (isset($_GET['sh'])) {
-        $shared = CRM_Utils_Type::escape($_GET['sh'], 'Integer');
-        if ($shared == 1) {
-          $contactType = 'Household';
-          $cName = 'household_name';
-        }
-        else {
-          $contactType = 'Organization';
-          $cName = 'organization_name';
-        }
-      }
-
-      // contacts of type household
-      $hh = $addStreet = $addCity = NULL;
-      if (isset($_GET['hh'])) {
-        $hh = CRM_Utils_Type::escape($_GET['hh'], 'Integer');
-      }
-
-      //organization info
-      $organization = $street = $city = NULL;
-      if (isset($_GET['org'])) {
-        $organization = CRM_Utils_Type::escape($_GET['org'], 'Integer');
-      }
-
-      if (isset($_GET['org']) || isset($_GET['hh'])) {
-        $json = FALSE;
-        $splitName = explode(' :: ', $name);
-        if ($splitName) {
-          $contactName = trim(CRM_Utils_Array::value('0', $splitName));
-          $street = trim(CRM_Utils_Array::value('1', $splitName));
-          $city = trim(CRM_Utils_Array::value('2', $splitName));
-        }
-        else {
-          $contactName = $name;
-        }
-
-        if ($street) {
-          $addStreet = "AND civicrm_address.street_address LIKE '$street%'";
-        }
-        if ($city) {
-          $addCity = "AND civicrm_address.city LIKE '$city%'";
-        }
-      }
-
-      if ($organization) {
-
-        $query = "
-SELECT CONCAT_WS(' :: ',sort_name,LEFT(street_address,25),city) 'sort_name',
-civicrm_contact.id 'id'
-FROM civicrm_contact
-LEFT JOIN civicrm_address ON ( civicrm_contact.id = civicrm_address.contact_id
-                                AND civicrm_address.is_primary=1
-                             )
-WHERE civicrm_contact.contact_type='Organization' AND organization_name LIKE '%$contactName%'
-{$addStreet} {$addCity} {$whereIdClause}
-ORDER BY organization_name ";
-      }
-      elseif ($shared) {
-        $query = "
-SELECT CONCAT_WS(':::' , sort_name, supplemental_address_1, sp.abbreviation, postal_code, cc.name )'sort_name' , civicrm_contact.id 'id' , civicrm_contact.display_name 'disp' FROM civicrm_contact LEFT JOIN civicrm_address ON (civicrm_contact.id =civicrm_address.contact_id AND civicrm_address.is_primary =1 )LEFT JOIN civicrm_state_province sp ON (civicrm_address.state_province_id =sp.id )LEFT JOIN civicrm_country cc ON (civicrm_address.country_id =cc.id )WHERE civicrm_contact.contact_type ='{$contactType}' AND {$cName} LIKE '%$name%' {$whereIdClause} ORDER BY {$cName} ";
-      }
-      elseif ($hh) {
-        $query = "
-SELECT CONCAT_WS(' :: ' , sort_name, LEFT(street_address,25),city) 'sort_name' , location_type_id 'location_type_id', is_primary 'is_primary', is_billing 'is_billing', civicrm_contact.id 'id'
-FROM civicrm_contact
-LEFT JOIN civicrm_address ON (civicrm_contact.id =civicrm_address.contact_id AND civicrm_address.is_primary =1 )
-WHERE civicrm_contact.contact_type ='Household'
-AND household_name LIKE '%$contactName%' {$addStreet} {$addCity} {$whereIdClause} ORDER BY household_name ";
-      }
-      elseif ($relType) {
-        if (!empty($_GET['case'])) {
-          $query = "
-SELECT distinct(c.id), c.sort_name
-FROM civicrm_contact c
-LEFT JOIN civicrm_relationship ON civicrm_relationship.contact_id_{$rel} = c.id
-WHERE c.sort_name LIKE '%$name%'
-AND civicrm_relationship.relationship_type_id = $relType
-GROUP BY sort_name
-";
-        }
-      }
-      else {
-
-        $query = "
-SELECT sort_name, id
-FROM civicrm_contact
-WHERE sort_name LIKE '%$name'
-{$whereIdClause}
-ORDER BY sort_name ";
-      }
-
-      $limit = 10;
-      if (isset($_GET['limit'])) {
-        $limit = CRM_Utils_Type::escape($_GET['limit'], 'Positive');
-      }
-
-      $query .= " LIMIT 0,{$limit}";
-
-      $dao = CRM_Core_DAO::executeQuery($query);
-
-      if ($shared) {
-        while ($dao->fetch()) {
-          echo $dao->sort_name;
-          CRM_Utils_System::civiExit();
-        }
-      }
-      else {
-        while ($dao->fetch()) {
-          if ($json) {
-            $elements[] = array(
-              'name' => addslashes($dao->sort_name),
-              'id' => $dao->id,
-            );
-          }
-          else {
-            echo $elements = "$dao->sort_name|$dao->id|$dao->location_type_id|$dao->is_primary|$dao->is_billing\n";
-          }
-        }
-        //for adding new household address / organization
-        if (empty($elements) && !$json && ($hh || $organization)) {
-          echo CRM_Utils_Array::value('s', $_GET);
-        }
-      }
-    }
-
-    if (isset($_GET['sh'])) {
-      echo "";
-      CRM_Utils_System::civiExit();
-    }
-
-    if (empty($elements)) {
-      $name = str_replace('%', '', $name);
-      $elements[] = array(
-        'name' => $name,
-        'id' => $name,
-      );
-    }
-
-    if ($json) {
-      echo json_encode($elements);
-    }
-    CRM_Utils_System::civiExit();
-  }
-
   /**
    * Delete custom value.
    */
   public static function deleteCustomValue() {
+    header('Content-Type: text/plain');
     $customValueID = CRM_Utils_Type::escape($_REQUEST['valueID'], 'Positive');
     $customGroupID = CRM_Utils_Type::escape($_REQUEST['groupID'], 'Positive');
 
@@ -561,8 +323,7 @@ ORDER BY sort_name ";
       || !$signer->validate($_REQUEST['sig'], $_REQUEST)
     ) {
       $user = array('name' => 'error');
-      echo json_encode($user);
-      CRM_Utils_System::civiExit();
+      CRM_Utils_JSON::output($user);
     }
 
     $config = CRM_Core_Config::singleton();
@@ -576,13 +337,15 @@ ORDER BY sort_name ";
     if (isset($errors['cms_name']) || isset($errors['name'])) {
       //user name is not availble
       $user = array('name' => 'no');
-      echo json_encode($user);
+      CRM_Utils_JSON::output($user);
     }
     else {
       //user name is available
       $user = array('name' => 'yes');
-      echo json_encode($user);
+      CRM_Utils_JSON::output($user);
     }
+
+    // Not reachable: JSON::output() above exits.
     CRM_Utils_System::civiExit();
   }
 
@@ -598,6 +361,8 @@ ORDER BY sort_name ";
       list($displayName,
         $userEmail
         ) = CRM_Contact_BAO_Contact_Location::getEmailDetails($contactID);
+
+      header('Content-Type: text/plain');
       if ($userEmail) {
         echo $userEmail;
       }
@@ -691,7 +456,7 @@ LIMIT {$offset}, {$rowCount}
           }
         }
         if ($result) {
-          echo json_encode($result);
+          CRM_Utils_JSON::output($result);
         }
       }
     }
@@ -762,7 +527,7 @@ LIMIT {$offset}, {$rowCount}
     }
 
     if ($result) {
-      echo json_encode($result);
+      CRM_Utils_JSON::output($result);
     }
     CRM_Utils_System::civiExit();
   }
@@ -940,6 +705,7 @@ LIMIT {$offset}, {$rowCount}
       }
     }
 
+    header('Content-Type: application/json');
     echo CRM_Utils_JSON::encodeDataTableSelector($searchRows, $sEcho, $iTotal, $iFilteredTotal, $selectorElements);
 
     CRM_Utils_System::civiExit();
@@ -1096,6 +862,7 @@ LIMIT {$offset}, {$rowCount}
       'is_active',
     );
 
+    header('Content-Type: application/json');
     echo CRM_Utils_JSON::encodeDataTableSelector($relationships, $sEcho, $iTotal, $iFilteredTotal, $selectorElements);
     CRM_Utils_System::civiExit();
   }
index 1bf6a2f24d6c2159027b5f6b877f46ebc75cbb62..3b70af47c69f4118805d96baaf0d3abfc1d9a022 100644 (file)
@@ -1824,43 +1824,46 @@ class CRM_Core_Form extends HTML_QuickForm_Page {
    */
   private function preProcessChainSelectFields() {
     foreach ($this->_chainSelectFields as $control => $target) {
-      $targetField = $this->getElement($target);
-      $targetType = $targetField->getAttribute('data-callback') == 'civicrm/ajax/jqCounty' ? 'county' : 'stateProvince';
-      $options = array();
-      // If the control field is on the form, setup chain-select and dynamically populate options
-      if ($this->elementExists($control)) {
-        $controlField = $this->getElement($control);
-        $controlType = $targetType == 'county' ? 'stateProvince' : 'country';
-
-        $targetField->setAttribute('class', $targetField->getAttribute('class') . ' crm-chain-select-target');
-
-        $css = (string) $controlField->getAttribute('class');
-        $controlField->updateAttributes(array(
-          'class' => ($css ? "$css " : 'crm-select2 ') . 'crm-chain-select-control',
-          'data-target' => $target,
-        ));
-        $controlValue = $controlField->getValue();
-        if ($controlValue) {
-          $options = CRM_Core_BAO_Location::getChainSelectValues($controlValue, $controlType, TRUE);
-          if (!$options) {
-            $targetField->setAttribute('placeholder', $targetField->getAttribute('data-none-prompt'));
+      // The 'target' might get missing if extensions do removeElement() in a form hook.
+      if ($this->elementExists($target)) {
+        $targetField = $this->getElement($target);
+        $targetType = $targetField->getAttribute('data-callback') == 'civicrm/ajax/jqCounty' ? 'county' : 'stateProvince';
+        $options = array();
+        // If the control field is on the form, setup chain-select and dynamically populate options
+        if ($this->elementExists($control)) {
+          $controlField = $this->getElement($control);
+          $controlType = $targetType == 'county' ? 'stateProvince' : 'country';
+
+          $targetField->setAttribute('class', $targetField->getAttribute('class') . ' crm-chain-select-target');
+
+          $css = (string) $controlField->getAttribute('class');
+          $controlField->updateAttributes(array(
+            'class' => ($css ? "$css " : 'crm-select2 ') . 'crm-chain-select-control',
+            'data-target' => $target,
+          ));
+          $controlValue = $controlField->getValue();
+          if ($controlValue) {
+            $options = CRM_Core_BAO_Location::getChainSelectValues($controlValue, $controlType, TRUE);
+            if (!$options) {
+              $targetField->setAttribute('placeholder', $targetField->getAttribute('data-none-prompt'));
+            }
+          } 
+          else {
+            $targetField->setAttribute('placeholder', $targetField->getAttribute('data-empty-prompt'));
+            $targetField->setAttribute('disabled', 'disabled');
           }
         }
+        // Control field not present - fall back to loading default options
         else {
-          $targetField->setAttribute('placeholder', $targetField->getAttribute('data-empty-prompt'));
-          $targetField->setAttribute('disabled', 'disabled');
+          $options = CRM_Core_PseudoConstant::$targetType();
         }
+        if (!$targetField->getAttribute('multiple')) {
+          $options = array('' => $targetField->getAttribute('placeholder')) + $options;
+          $targetField->removeAttribute('placeholder');
+        }
+        $targetField->_options = array();
+        $targetField->loadArray($options);
       }
-      // Control field not present - fall back to loading default options
-      else {
-        $options = CRM_Core_PseudoConstant::$targetType();
-      }
-      if (!$targetField->getAttribute('multiple')) {
-        $options = array('' => $targetField->getAttribute('placeholder')) + $options;
-        $targetField->removeAttribute('placeholder');
-      }
-      $targetField->_options = array();
-      $targetField->loadArray($options);
     }
   }
 
@@ -1869,7 +1872,7 @@ class CRM_Core_Form extends HTML_QuickForm_Page {
    */
   private function validateChainSelectFields() {
     foreach ($this->_chainSelectFields as $control => $target) {
-      if ($this->elementExists($control)) {
+      if ($this->elementExists($control) && $this->elementExists($target)) {
         $controlValue = (array) $this->getElementValue($control);
         $targetField = $this->getElement($target);
         $controlType = $targetField->getAttribute('data-callback') == 'civicrm/ajax/jqCounty' ? 'stateProvince' : 'country';
index 21adef2cefd486c6d9b94c2a2ae1196b9744d8f6..69ae14537d2d2556023502e63f0203315a8b7423 100644 (file)
@@ -214,29 +214,4 @@ class CRM_Core_Page_AJAX {
     header("Cache-Control: max-age=$ttl, public");
   }
 
-  /**
-   * Send autocomplete results to the client. Input can be a simple or nested array.
-   * @param array $results
-   *   If nested array, also provide:.
-   * @param string $val
-   *   Array key to use as the value.
-   * @param string $key
-   *   Array key to use as the key.
-   * @deprecated
-   */
-  public static function autocompleteResults($results, $val = 'label', $key = 'id') {
-    $output = array();
-    if (is_array($results)) {
-      foreach ($results as $k => $v) {
-        if (is_array($v)) {
-          echo $v[$val] . '|' . $v[$key] . "\n";
-        }
-        else {
-          echo "$v|$k\n";
-        }
-      }
-    }
-    CRM_Utils_System::civiExit();
-  }
-
 }
index 1dab01874ec708ac04fa7d371b0391a30264ec19..729452ed1ace019f2ac4336dbd1dc861c2b34cbb 100644 (file)
      <title>CiviCRM Blog</title>
      <page_callback>CRM_Dashlet_Page_Blog</page_callback>
   </item>
-  <item>
-    <path>civicrm/ajax/search</path>
-    <page_callback>CRM_Contact_Page_AJAX::search</page_callback>
-    <access_arguments>access CiviCRM</access_arguments>
-</item>
 <item>
      <path>civicrm/ajax/relation</path>
      <page_callback>CRM_Contact_Page_AJAX::relationship</page_callback>
index f5698efeb691f36d7fad0f9ee81c52eda2e7842a..f9e194520b2b14fc111e7762a28927ae329daa9a 100644 (file)
@@ -460,6 +460,7 @@ class CRM_Financial_Page_AJAX {
       'action',
     );
 
+    header('Content-Type: application/json');
     echo CRM_Utils_JSON::encodeDataTableSelector($financialitems, $sEcho, $iTotal, $iFilteredTotal, $selectorElements);
     CRM_Utils_System::civiExit();
   }
index 2a346f8eac9c2a9065ec764e8cb599a6526c1b89..ce150a1422aa140ef1f41c01ed147134165ba779 100644 (file)
@@ -112,6 +112,7 @@ class CRM_Group_Page_AJAX {
       if (!empty($params['is_unit_test'])) {
         return array($groups, $iFilteredTotal);
       }
+      header('Content-Type: application/json');
       echo CRM_Utils_JSON::encodeDataTableSelector($groups, $sEcho, $iTotal, $iFilteredTotal, $selectorElements);
       CRM_Utils_System::civiExit();
     }
index 7a632418a3b67a246a42d7b281bbadac26837a5b..05d87cee7dd55a23739fac1fa183dea383bdf9a6 100644 (file)
@@ -90,14 +90,31 @@ class CRM_Mailing_BAO_Component extends CRM_Mailing_DAO_Component {
   public static function add(&$params, $ids = array()) {
     $id = CRM_Utils_Array::value('id', $params, CRM_Utils_Array::value('id', $ids));
     $component = new CRM_Mailing_DAO_Component();
-    $component->id = $id;
+    if ($id) {
+      $component->id = $id;
+      $component->find(TRUE);
+    }
+
     $component->copyValues($params);
     if (empty($id) && empty($params['body_text'])) {
       $component->body_text = CRM_Utils_String::htmlToText(CRM_Utils_Array::value('body_html', $params));
     }
 
-    if ($component->is_default && !empty($id)) {
-      CRM_Core_DAO::executeQuery("UPDATE civicrm_mailing_component SET is_default = 0 WHERE component_type ='{$component->component_type}' AND id <> $id");
+    if ($component->is_default) {
+      if (!empty($id)) {
+        $sql = 'UPDATE civicrm_mailing_component SET is_default = 0 WHERE component_type = %1 AND id <> %2';
+        $sqlParams = array(
+          1 => array($component->component_type, 'String'),
+          2 => array($id, 'Positive'),
+        );
+      }
+      else {
+        $sql = 'UPDATE civicrm_mailing_component SET is_default = 0 WHERE component_type = %1';
+        $sqlParams = array(
+          1 => array($component->component_type, 'String'),
+        );
+      }
+      CRM_Core_DAO::executeQuery($sql, $sqlParams);
     }
 
     $component->save();
index 19e43393c733091fc566ab9f46578b1d291ed083..94e7f7f40a09f0009d11d25e383d70608a695f5e 100644 (file)
@@ -1330,6 +1330,9 @@ ORDER BY   civicrm_email.is_bulkmail DESC
     );
     $mailParams['toEmail'] = $email;
 
+    // Add job ID to mailParams for external email delivery service to utilise
+    $mailParams['job_id'] = $job_id;
+
     CRM_Utils_Hook::alterMailParams($mailParams, 'civimail');
 
     // CRM-10699 support custom email headers
index ae7596a96c49c1c514e88597f0d22ff9a7220f93..3963329d6d4f5d6fb1fb98c0b62ded0114c1ee91 100644 (file)
@@ -88,8 +88,8 @@ class CRM_Mailing_Form_Component extends CRM_Core_Form {
       CRM_Core_DAO::getAttribute('CRM_Mailing_DAO_Component', 'body_html')
     );
 
-    $this->add('checkbox', 'is_default', ts('Default?'));
-    $this->add('checkbox', 'is_active', ts('Enabled?'));
+    $this->addYesNo('is_default', ts('Default?'));
+    $this->addYesNo('is_active', ts('Enabled?'));
 
     $this->addFormRule(array('CRM_Mailing_Form_Component', 'dataRule'));
 
@@ -122,7 +122,9 @@ class CRM_Mailing_Form_Component extends CRM_Core_Form {
       $baoName = $this->_BAOName;
       $baoName::retrieve($params, $defaults);
     }
-    $defaults['is_active'] = 1;
+    else {
+      $defaults['is_active'] = 1;
+    }
 
     return $defaults;
   }
index 60e7d43e193c1a2b89190bb3c3b4aeb339c4c873..5a0fef0788c1378a0f8053f682f4477cc5a3ec8e 100644 (file)
@@ -104,6 +104,7 @@ class CRM_Mailing_Page_AJAX {
       'links',
     );
 
+    header('Content-Type: application/json');
     echo CRM_Utils_JSON::encodeDataTableSelector($mailings, $sEcho, $iTotal, $iFilteredTotal, $selectorElements);
     CRM_Utils_System::civiExit();
   }
index 186ef74f822413bafb805d18e0141223fc252ec0..33cec34871433739303ee0d8ac6f2978a4e97117 100755 (executable)
@@ -84,6 +84,7 @@ WHERE {$whereClause}
       );
     }
 
+    header('Content-Type: application/json');
     echo CRM_Utils_JSON::encode($elements, 'value');
     CRM_Utils_System::civiExit();
   }
diff --git a/CRM/Upgrade/Incremental/sql/4.5.8.mysql.tpl b/CRM/Upgrade/Incremental/sql/4.5.8.mysql.tpl
new file mode 100644 (file)
index 0000000..3c2f7c6
--- /dev/null
@@ -0,0 +1 @@
+{* file to handle db changes in 4.5.8 during upgrade *}
diff --git a/CRM/Upgrade/Incremental/sql/4.5.9.mysql.tpl b/CRM/Upgrade/Incremental/sql/4.5.9.mysql.tpl
new file mode 100644 (file)
index 0000000..7b1e227
--- /dev/null
@@ -0,0 +1 @@
+{* file to handle db changes in 4.5.9 during upgrade *}
index a44f6fd36efc9ec8278109b2788494831d918d91..626232974f9a55eb8aa7988e344c04b61b0d25e6 100644 (file)
@@ -44,6 +44,19 @@ function civicrm_api3_mailing_component_create($params) {
   return _civicrm_api3_basic_create(_civicrm_api3_get_BAO(__FUNCTION__), $params);
 }
 
+
+/**
+ * Adjust Metadata for Create action.
+ *
+ * The metadata is used for setting defaults, documentation & validation.
+ *
+ * @param array $spec
+ *   Array of parameters determined by getfields.
+ */
+function _civicrm_api3_mailing_component_create_spec(&$spec) {
+  $spec['is_active']['api.default'] = 1;
+}
+
 /**
  * Get a MailingComponent.
  *
index 370cb833a057f8e1af8c361d8cef03759f572f5f..a58219306ed28fc71fd4198ff860f2bcce528308 100644 (file)
@@ -100,7 +100,27 @@ function civicrm_api3_message_template_get($params) {
  * @param array $params
  */
 function civicrm_api3_message_template_send($params) {
-  CRM_Core_BAO_MessageTemplates::sendTemplate($params);
+  // Change external param names to internal ones
+  $fieldSpec = array();
+  _civicrm_api3_message_template_send_spec($fieldSpec);
+
+  foreach ($fieldSpec as $field => $spec) {
+    if (isset($spec['api.aliases']) && array_key_exists($field, $params)) {
+      $params[CRM_Utils_Array::first($spec['api.aliases'])] = $params[$field];
+      unset($params[$field]);
+    }
+  }
+  if (empty($params['messageTemplateID'])) {
+    if (empty($params['groupName']) || empty($params['valueName'])) {
+      // Can't use civicrm_api3_verify_mandatory for this because it would give the wrong field names
+      throw new API_Exception(
+        "Mandatory key(s) missing from params array: requires id or option_group_name + option_value_name",
+        "mandatory_missing",
+        array("fields" => array('id', 'option_group_name', 'option_value_name'))
+      );
+    }
+  }
+  CRM_Core_BAO_MessageTemplate::sendTemplate($params);
 }
 
 /**
@@ -113,12 +133,55 @@ function civicrm_api3_message_template_send($params) {
  *   Array of parameters determined by getfields.
  */
 function _civicrm_api3_message_template_send_spec(&$params) {
-  $params['messageTemplateID']['api.required'] = 1;
-  $params['messageTemplateID']['title'] = 'Message Template ID';
-  $params['contactId']['api.required'] = 1;
-  $params['contactId']['title'] = 'Contact ID';
-  $params['toEmail']['api.required'] = 1;
-  $params['toEmail']['title'] = 'To Email';
-  $params['toName']['api.required'] = 1;
-  $params['toName']['title'] = 'To Name';
+  $params['id']['description'] = 'ID of the template';
+  $params['id']['title'] = 'Message Template ID';
+  $params['id']['api.aliases'] = array('messageTemplateID', 'message_template_id');
+
+  $params['option_group_name']['description'] = 'option group name of the template (required if no id supplied)';
+  $params['option_group_name']['title'] = 'Option Group Name';
+  $params['option_group_name']['api.aliases'] = array('groupName');
+
+  $params['option_value_name']['description'] = 'option value name of the template (required if no id supplied)';
+  $params['option_value_name']['title'] = 'Option Value Name';
+  $params['option_value_name']['api.aliases'] = array('valueName');
+
+  $params['contact_id']['description'] = 'contact id if contact tokens are to be replaced';
+  $params['contact_id']['title'] = 'Contact ID';
+  $params['contact_id']['api.aliases'] = array('contactId');
+
+  $params['template_params']['description'] = 'additional template params (other than the ones already set in the template singleton)';
+  $params['template_params']['title'] = 'Template Params';
+  $params['template_params']['api.aliases'] = array('tplParams');
+
+  $params['from']['description'] = 'the From: header';
+  $params['from']['title'] = 'From';
+
+  $params['to_name']['description'] = 'the recipient’s name';
+  $params['to_name']['title'] = 'Recipient Name';
+  $params['to_name']['api.aliases'] = array('toName');
+
+  $params['to_email']['description'] = 'the recipient’s email - mail is sent only if set';
+  $params['to_email']['title'] = 'Recipient Email';
+  $params['to_email']['api.aliases'] = array('toEmail');
+
+  $params['cc']['description'] = 'the Cc: header';
+  $params['cc']['title'] = 'CC';
+
+  $params['bcc']['description'] = 'the Bcc: header';
+  $params['bcc']['title'] = 'BCC';
+
+  $params['reply_to']['description'] = 'the Reply-To: header';
+  $params['reply_to']['title'] = 'Reply To';
+  $params['reply_to']['api.aliases'] = array('replyTo');
+
+  $params['attachments']['description'] = 'email attachments';
+  $params['attachments']['title'] = 'Attachments';
+
+  $params['is_test']['description'] = 'whether this is a test email (and hence should include the test banner)';
+  $params['is_test']['title'] = 'Is Test';
+  $params['is_test']['api.aliases'] = array('isTest');
+
+  $params['pdf_filename']['description'] = 'filename of optional PDF version to add as attachment (do not include path)';
+  $params['pdf_filename']['title'] = 'PDF Filename';
+  $params['pdf_filename']['api.aliases'] = array('PDFFilename');
 }
index 7fa6837a4ac9c1cdc7343dad559ce5ddccf99278..f38bf305b5a49f3c76da70fdb7c1f7d76f6e1824 100644 (file)
@@ -1,11 +1,25 @@
 // http://civicrm.org/licensing
 (function($, _) {
+  // FIXME: Much of this code is redundant with CRM.loadForm
 
   var ajaxFormParams = {
     dataType:'json',
     beforeSubmit: function(arr, $form, options) {
       $form.block();
     },
+    beforeSerialize: function(form, options) {
+      // Copied from crm.ajax.js
+      if (window.CKEDITOR && window.CKEDITOR.instances) {
+        $.each(CKEDITOR.instances, function() {
+          this.updateElement && this.updateElement();
+        });
+      }
+      if (window.tinyMCE && tinyMCE.editors) {
+        $.each(tinyMCE.editors, function() {
+          this.save();
+        });
+      }
+    },
     success: requestHandler,
     error: errorHandler
   };