57c9c217 |
1 | <?php |
2 | /* |
3 | +--------------------------------------------------------------------+ |
4 | | CiviCRM version 4.6 | |
5 | +--------------------------------------------------------------------+ |
6 | | Copyright CiviCRM LLC (c) 2004-2015 | |
7 | +--------------------------------------------------------------------+ |
8 | | This file is a part of CiviCRM. | |
9 | | | |
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. | |
13 | | | |
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. | |
18 | | | |
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 | +--------------------------------------------------------------------+ |
26 | */ |
27 | |
28 | /** |
29 | * |
30 | * @package CRM |
31 | * @copyright CiviCRM LLC (c) 2004-2015 |
32 | * |
33 | */ |
34 | |
35 | /** |
36 | * This class contains the functions that are called using AJAX (jQuery) |
37 | */ |
38 | class CRM_Custom_Page_AJAX { |
39 | /** |
40 | * Get list of options. |
41 | * |
42 | */ |
43 | public static function getOptionList() { |
44 | $params = $_REQUEST; |
45 | |
46 | $sortMapper = array( |
47 | 0 => 'options.label', |
48 | 1 => 'options.value', |
49 | 2 => '', |
46227b8d |
50 | 3 => '', |
57c9c217 |
51 | 4 => '', |
57c9c217 |
52 | ); |
53 | |
54 | $sEcho = CRM_Utils_Type::escape($_REQUEST['sEcho'], 'Integer'); |
55 | $offset = isset($_REQUEST['iDisplayStart']) ? CRM_Utils_Type::escape($_REQUEST['iDisplayStart'], 'Integer') : 0; |
56 | $rowCount = isset($_REQUEST['iDisplayLength']) ? CRM_Utils_Type::escape($_REQUEST['iDisplayLength'], 'Integer') : 25; |
57 | $sort = isset($_REQUEST['iSortCol_0']) ? CRM_Utils_Array::value(CRM_Utils_Type::escape($_REQUEST['iSortCol_0'], 'Integer'), $sortMapper) : NULL; |
58 | $sortOrder = isset($_REQUEST['sSortDir_0']) ? CRM_Utils_Type::escape($_REQUEST['sSortDir_0'], 'String') : 'asc'; |
59 | |
60 | if ($sort && $sortOrder) { |
61 | $params['sortBy'] = $sort . ' ' . $sortOrder; |
62 | } |
63 | |
64 | $params['page'] = ($offset / $rowCount) + 1; |
65 | $params['rp'] = $rowCount; |
66 | |
67 | $options = CRM_Core_BAO_CustomOption::getOptionListSelector($params); |
68 | |
69 | $iFilteredTotal = $iTotal = $params['total']; |
70 | $selectorElements = array( |
71 | 'label', |
72 | 'value', |
73 | 'is_default', |
57c9c217 |
74 | 'is_active', |
75 | 'links', |
76 | 'class', |
77 | ); |
78 | |
79 | header('Content-Type: application/json'); |
80 | echo CRM_Utils_JSON::encodeDataTableSelector($options, $sEcho, $iTotal, $iFilteredTotal, $selectorElements); |
81 | CRM_Utils_System::civiExit(); |
82 | } |
83 | |
46227b8d |
84 | /** |
85 | * Fix Ordering of options |
86 | * |
87 | */ |
46227b8d |
88 | public static function fixOrdering() { |
89 | $params = $_REQUEST; |
90 | |
91 | $queryParams = array( |
92 | 1 => array($params['start'], 'Integer'), |
93 | 2 => array($params['end'], 'Integer'), |
94 | 3 => array($params['gid'], 'Integer'), |
95 | ); |
96 | $dao = "SELECT id FROM civicrm_option_value WHERE weight = %1 AND option_group_id = %3"; |
97 | $startid = CRM_Core_DAO::singleValueQuery($dao, $queryParams); |
98 | |
99 | $dao2 = "SELECT id FROM civicrm_option_value WHERE weight = %2 AND option_group_id = %3"; |
100 | $endid = CRM_Core_DAO::singleValueQuery($dao2, $queryParams); |
101 | |
102 | $query = "UPDATE civicrm_option_value SET weight = %2 WHERE id = $startid"; |
103 | CRM_Core_DAO::executeQuery($query, $queryParams); |
104 | |
105 | // increment or decrement the rest by one |
106 | if ($params['start'] < $params['end']) { |
107 | $updateRows = "UPDATE civicrm_option_value |
108 | SET weight = weight - 1 |
109 | WHERE weight > %1 AND weight < %2 AND option_group_id = %3 |
110 | OR id = $endid"; |
111 | } |
112 | else { |
113 | $updateRows = "UPDATE civicrm_option_value |
114 | SET weight = weight + 1 |
115 | WHERE weight < %1 AND weight > %2 AND option_group_id = %3 |
116 | OR id = $endid"; |
117 | } |
118 | CRM_Core_DAO::executeQuery($updateRows, $queryParams); |
119 | } |
120 | |
57c9c217 |
121 | } |