3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2017 |
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 +--------------------------------------------------------------------+
31 * @copyright CiviCRM LLC (c) 2004-2017
36 * This class contains the functions that are called using AJAX (jQuery)
38 class CRM_Custom_Page_AJAX
{
41 * This function uses the deprecated v1 datatable api and needs updating. See CRM-16353.
44 public static function getOptionList() {
47 $sEcho = CRM_Utils_Type
::escape($_REQUEST['sEcho'], 'Integer');
48 $offset = isset($_REQUEST['iDisplayStart']) ? CRM_Utils_Type
::escape($_REQUEST['iDisplayStart'], 'Integer') : 0;
49 $rowCount = isset($_REQUEST['iDisplayLength']) ? CRM_Utils_Type
::escape($_REQUEST['iDisplayLength'], 'Integer') : 25;
51 $params['page'] = ($offset / $rowCount) +
1;
52 $params['rp'] = $rowCount;
54 $options = CRM_Core_BAO_CustomOption
::getOptionListSelector($params);
56 $iFilteredTotal = $iTotal = $params['total'];
57 $selectorElements = array(
66 CRM_Utils_System
::setHttpHeader('Content-Type', 'application/json');
67 echo CRM_Utils_JSON
::encodeDataTableSelector($options, $sEcho, $iTotal, $iFilteredTotal, $selectorElements);
68 CRM_Utils_System
::civiExit();
72 * Fix Ordering of options
75 public static function fixOrdering() {
79 1 => array($params['start'], 'Integer'),
80 2 => array($params['end'], 'Integer'),
81 3 => array($params['gid'], 'Integer'),
83 $dao = "SELECT id FROM civicrm_option_value WHERE weight = %1 AND option_group_id = %3";
84 $startid = CRM_Core_DAO
::singleValueQuery($dao, $queryParams);
86 $dao2 = "SELECT id FROM civicrm_option_value WHERE weight = %2 AND option_group_id = %3";
87 $endid = CRM_Core_DAO
::singleValueQuery($dao2, $queryParams);
89 $query = "UPDATE civicrm_option_value SET weight = %2 WHERE id = $startid";
90 CRM_Core_DAO
::executeQuery($query, $queryParams);
92 // increment or decrement the rest by one
93 if ($params['start'] < $params['end']) {
94 $updateRows = "UPDATE civicrm_option_value
95 SET weight = weight - 1
96 WHERE weight > %1 AND weight < %2 AND option_group_id = %3
100 $updateRows = "UPDATE civicrm_option_value
101 SET weight = weight + 1
102 WHERE weight < %1 AND weight > %2 AND option_group_id = %3
105 CRM_Core_DAO
::executeQuery($updateRows, $queryParams);
106 CRM_Utils_JSON
::output(TRUE);
110 * Get list of Multi Record Fields.
113 public static function getMultiRecordFieldList() {
115 $params = CRM_Core_Page_AJAX
::defaultSortAndPagerParams(0, 10);
116 $params['cid'] = CRM_Utils_Type
::escape($_GET['cid'], 'Integer');
117 $params['cgid'] = CRM_Utils_Type
::escape($_GET['cgid'], 'Integer');
119 $contactType = CRM_Contact_BAO_Contact
::getContactType($params['cid']);
121 $obj = new CRM_Profile_Page_MultipleRecordFieldsListing();
122 $obj->_pageViewType
= 'customDataView';
123 $obj->_contactId
= $params['cid'];
124 $obj->_customGroupId
= $params['cgid'];
125 $obj->_contactType
= $contactType;
126 $obj->_DTparams
['offset'] = ($params['page'] - 1) * $params['rp'];
127 $obj->_DTparams
['rowCount'] = $params['rp'];
128 if (!empty($params['sortBy'])) {
129 $obj->_DTparams
['sort'] = $params['sortBy'];
132 list($fields, $attributes) = $obj->browse();
134 // format params and add class attributes
135 $fieldList = array();
136 foreach ($fields as $id => $value) {
138 foreach ($value as $fieldId => &$fieldName) {
139 if (!empty($attributes[$fieldId][$id]['class'])) {
140 $fieldName = array('data' => $fieldName, 'cellClass' => $attributes[$fieldId][$id]['class']);
142 if (is_numeric($fieldId)) {
143 $fName = CRM_Core_DAO
::getFieldValue('CRM_Core_DAO_CustomField', $fieldId, 'column_name');
144 CRM_Utils_Array
::crmReplaceKey($value, $fieldId, $fName);
148 array_push($fieldList, $field);
150 $totalRecords = !empty($obj->_total
) ?
$obj->_total
: 0;
152 $multiRecordFields = array();
153 $multiRecordFields['data'] = $fieldList;
154 $multiRecordFields['recordsTotal'] = $totalRecords;
155 $multiRecordFields['recordsFiltered'] = $totalRecords;
157 if (!empty($_GET['is_unit_test'])) {
158 return $multiRecordFields;
161 CRM_Utils_JSON
::output($multiRecordFields);