Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
39de6fd5 | 4 | | CiviCRM version 4.6 | |
6a488035 | 5 | +--------------------------------------------------------------------+ |
06b69b18 | 6 | | Copyright CiviCRM LLC (c) 2004-2014 | |
6a488035 TO |
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 | |
06b69b18 | 31 | * @copyright CiviCRM LLC (c) 2004-2014 |
6a488035 TO |
32 | * |
33 | */ | |
34 | ||
35 | /** | |
36 | * This class contains all campaign related functions that are called using AJAX (jQuery) | |
37 | */ | |
38 | class CRM_Campaign_Page_AJAX { | |
39 | ||
40 | static function registerInterview() { | |
41 | $fields = array( | |
42 | 'result', | |
43 | 'voter_id', | |
44 | 'survey_id', | |
45 | 'activity_id', | |
46 | 'surveyTitle', | |
47 | 'interviewer_id', | |
48 | 'activity_type_id', | |
49 | ); | |
50 | ||
51 | $params = array(); | |
52 | foreach ($fields as $fld) { | |
53 | $params[$fld] = CRM_Utils_Array::value($fld, $_POST); | |
54 | } | |
55 | $params['details'] = CRM_Utils_Array::value('note', $_POST); | |
56 | $voterId = $params['voter_id']; | |
57 | $activityId = $params['activity_id']; | |
58 | ||
59 | $customKey = "field_{$voterId}_custom"; | |
60 | foreach ($_POST as $key => $value) { | |
61 | if (strpos($key, $customKey) !== FALSE) { | |
62 | $customFieldKey = str_replace(str_replace(substr($customKey, -6), '', $customKey), '', $key); | |
63 | $params[$customFieldKey] = $value; | |
64 | } | |
65 | } | |
66 | ||
8cc574cf | 67 | if (isset($_POST['field']) && !empty($_POST['field'][$voterId]) && |
6a488035 TO |
68 | is_array($_POST['field'][$voterId]) |
69 | ) { | |
70 | foreach ($_POST['field'][$voterId] as $fieldKey => $value) { | |
71 | $params[$fieldKey] = $value; | |
72 | } | |
73 | } | |
74 | ||
75 | //lets pickup contat related fields. | |
76 | foreach ($_POST as $key => $value) { | |
77 | if (strpos($key, "field_{$voterId}_") !== FALSE && | |
78 | strpos($key, "field_{$voterId}_custom") === FALSE | |
79 | ) { | |
80 | $key = substr($key, strlen("field_{$voterId}_")); | |
81 | $params[$key] = $value; | |
82 | } | |
83 | } | |
84 | ||
85 | $result = array( | |
86 | 'status' => 'fail', | |
87 | 'voter_id' => $voterId, | |
88 | 'activity_id' => $params['interviewer_id'], | |
89 | ); | |
90 | ||
91 | //time to validate custom data. | |
92 | $errors = CRM_Core_BAO_CustomField::validateCustomData($params); | |
93 | if (is_array($errors) && !empty($errors)) { | |
94 | $result['errors'] = $errors; | |
ecdef330 | 95 | CRM_Utils_JSON::output($result); |
6a488035 TO |
96 | } |
97 | ||
98 | //process the response/interview data. | |
99 | $activityId = CRM_Campaign_Form_Task_Interview::registerInterview($params); | |
100 | if ($activityId) { | |
101 | $result['status'] = 'success'; | |
102 | } | |
103 | ||
ecdef330 | 104 | CRM_Utils_JSON::output($result); |
6a488035 TO |
105 | } |
106 | ||
107 | static function loadOptionGroupDetails() { | |
108 | ||
109 | $id = CRM_Utils_Array::value('option_group_id', $_POST); | |
110 | $status = 'fail'; | |
111 | $opValues = array(); | |
112 | ||
113 | if ($id) { | |
114 | $groupParams['id'] = $id; | |
115 | CRM_Core_OptionValue::getValues($groupParams, $opValues); | |
116 | } | |
117 | ||
118 | $surveyId = CRM_Utils_Array::value('survey_id', $_POST); | |
119 | if ($surveyId) { | |
120 | $survey = new CRM_Campaign_DAO_Survey(); | |
121 | $survey->id = $surveyId; | |
122 | $survey->result_id = $id; | |
123 | if ($survey->find(TRUE)) { | |
124 | if ($survey->recontact_interval) { | |
125 | $recontactInterval = unserialize($survey->recontact_interval); | |
126 | foreach ($opValues as $opValId => $opVal) { | |
127 | if (is_numeric($recontactInterval[$opVal['label']])) { | |
128 | $opValues[$opValId]['interval'] = $recontactInterval[$opVal['label']]; | |
129 | } | |
130 | } | |
131 | } | |
132 | } | |
133 | } | |
134 | ||
135 | if (!empty($opValues)) { | |
136 | $status = 'success'; | |
137 | } | |
138 | ||
139 | $result = array( | |
140 | 'status' => $status, | |
141 | 'result' => $opValues, | |
142 | ); | |
143 | ||
ecdef330 | 144 | CRM_Utils_JSON::output($result); |
6a488035 TO |
145 | } |
146 | ||
147 | function voterList() { | |
148 | //get the search criteria params. | |
149 | $searchParams = explode(',', CRM_Utils_Array::value('searchCriteria', $_POST)); | |
150 | ||
151 | $params = $searchRows = array(); | |
152 | foreach ($searchParams as $param) { | |
a7488080 | 153 | if (!empty($_POST[$param])) { |
6a488035 TO |
154 | $params[$param] = $_POST[$param]; |
155 | } | |
156 | } | |
157 | ||
158 | //format multi-select group and contact types. | |
159 | foreach (array( | |
160 | 'group', 'contact_type') as $param) { | |
161 | $paramValue = CRM_Utils_Array::value($param, $params); | |
162 | if ($paramValue) { | |
163 | unset($params[$param]); | |
164 | $paramValue = explode(',', $paramValue); | |
165 | foreach ($paramValue as $key => $value) { | |
166 | $params[$param][$value] = 1; | |
167 | } | |
168 | } | |
169 | } | |
170 | ||
171 | $voterClauseParams = array(); | |
172 | foreach (array( | |
173 | 'campaign_survey_id', 'survey_interviewer_id', 'campaign_search_voter_for') as $fld) { | |
174 | $voterClauseParams[$fld] = CRM_Utils_Array::value($fld, $params); | |
175 | } | |
176 | ||
177 | $interviewerId = $surveyTypeId = $surveyId = NULL; | |
178 | $searchVoterFor = $params['campaign_search_voter_for']; | |
179 | if ($searchVoterFor == 'reserve') { | |
a7488080 | 180 | if (!empty($params['campaign_survey_id'])) { |
6a488035 TO |
181 | $survey = new CRM_Campaign_DAO_Survey(); |
182 | $survey->id = $surveyId = $params['campaign_survey_id']; | |
183 | $survey->selectAdd('campaign_id, activity_type_id'); | |
184 | $survey->find(TRUE); | |
185 | $campaignId = $survey->campaign_id; | |
186 | $surveyTypeId = $survey->activity_type_id; | |
187 | ||
188 | //allow voter search in sub-part of given constituents, | |
189 | //but make sure in case user does not select any group. | |
190 | //get all associated campaign groups in where filter, CRM-7406 | |
191 | $groups = CRM_Utils_Array::value('group', $params); | |
192 | if ($campaignId && CRM_Utils_System::isNull($groups)) { | |
193 | $campaignGroups = CRM_Campaign_BAO_Campaign::getCampaignGroups($campaignId); | |
194 | foreach ($campaignGroups as $id => $group) $params['group'][$id] = 1; | |
195 | } | |
196 | ||
197 | //apply filter of survey contact type for search. | |
198 | $contactType = CRM_Campaign_BAO_Survey::getSurveyContactType($surveyId); | |
199 | if ($contactType) { | |
200 | $params['contact_type'][$contactType] = 1; | |
201 | } | |
202 | ||
203 | unset($params['campaign_survey_id']); | |
204 | } | |
205 | unset($params['survey_interviewer_id']); | |
206 | } | |
207 | else { | |
208 | //get the survey status in where clause. | |
209 | $scheduledStatusId = array_search('Scheduled', CRM_Core_PseudoConstant::activityStatus('name')); | |
210 | if ($scheduledStatusId) { | |
211 | $params['survey_status_id'] = $scheduledStatusId; | |
212 | } | |
213 | //BAO/Query knows reserve/release/interview processes. | |
214 | if ($params['campaign_search_voter_for'] == 'gotv') { | |
215 | $params['campaign_search_voter_for'] = 'release'; | |
216 | } | |
217 | } | |
218 | ||
219 | $selectorCols = array( | |
220 | 'sort_name', | |
221 | 'street_address', | |
222 | 'street_name', | |
223 | 'street_number', | |
224 | 'street_unit', | |
225 | ); | |
226 | ||
227 | // get the data table params. | |
228 | $dataTableParams = array( | |
229 | 'sEcho' => array('name' => 'sEcho', | |
230 | 'type' => 'Integer', | |
231 | 'default' => 0, | |
232 | ), | |
233 | 'offset' => array( | |
234 | 'name' => 'iDisplayStart', | |
235 | 'type' => 'Integer', | |
236 | 'default' => 0, | |
237 | ), | |
238 | 'rowCount' => array( | |
239 | 'name' => 'iDisplayLength', | |
240 | 'type' => 'Integer', | |
241 | 'default' => 25, | |
242 | ), | |
243 | 'sort' => array( | |
244 | 'name' => 'iSortCol_0', | |
245 | 'type' => 'Integer', | |
246 | 'default' => 'sort_name', | |
247 | ), | |
248 | 'sortOrder' => array( | |
249 | 'name' => 'sSortDir_0', | |
250 | 'type' => 'String', | |
251 | 'default' => 'asc', | |
252 | ), | |
253 | ); | |
254 | foreach ($dataTableParams as $pName => $pValues) { | |
255 | $$pName = $pValues['default']; | |
a7488080 | 256 | if (!empty($_POST[$pValues['name']])) { |
6a488035 TO |
257 | $$pName = CRM_Utils_Type::escape($_POST[$pValues['name']], $pValues['type']); |
258 | if ($pName == 'sort')$$pName = $selectorCols[$$pName]; | |
259 | } | |
260 | } | |
261 | ||
262 | $queryParams = CRM_Contact_BAO_Query::convertFormValues($params); | |
263 | $query = new CRM_Contact_BAO_Query($queryParams, | |
264 | NULL, NULL, FALSE, FALSE, | |
265 | CRM_Contact_BAO_Query::MODE_CAMPAIGN, | |
266 | TRUE | |
267 | ); | |
268 | ||
269 | //get the voter clause to restrict and validate search. | |
270 | $voterClause = CRM_Campaign_BAO_Query::voterClause($voterClauseParams); | |
271 | ||
272 | $searchCount = $query->searchQuery(0, 0, NULL, | |
273 | TRUE, FALSE, | |
274 | FALSE, FALSE, | |
275 | FALSE, | |
276 | CRM_Utils_Array::value('whereClause', $voterClause), | |
277 | NULL, | |
278 | CRM_Utils_Array::value('fromClause', $voterClause) | |
279 | ); | |
280 | ||
281 | $iTotal = $searchCount; | |
282 | ||
283 | $selectorCols = array( | |
284 | 'contact_type', 'sort_name', 'street_address', | |
285 | 'street_name', 'street_number', 'street_unit', | |
286 | ); | |
287 | ||
288 | $extraVoterColName = 'is_interview_conducted'; | |
0aec9935 | 289 | if ($params['campaign_search_voter_for'] == 'reserve') { |
6a488035 TO |
290 | $extraVoterColName = 'reserve_voter'; |
291 | } | |
292 | ||
293 | if ($searchCount > 0) { | |
294 | if ($searchCount < $offset) { | |
295 | $offset = 0; | |
296 | } | |
297 | ||
298 | $config = CRM_Core_Config::singleton(); | |
299 | ||
300 | // get the result of the search | |
301 | $result = $query->searchQuery($offset, $rowCount, $sort, | |
302 | FALSE, FALSE, | |
303 | FALSE, FALSE, | |
304 | FALSE, | |
305 | CRM_Utils_Array::value('whereClause', $voterClause), | |
306 | $sortOrder, | |
307 | CRM_Utils_Array::value('fromClause', $voterClause) | |
308 | ); | |
309 | while ($result->fetch()) { | |
310 | $contactID = $result->contact_id; | |
311 | $typeImage = CRM_Contact_BAO_Contact_Utils::getImage($result->contact_sub_type ? | |
312 | $result->contact_sub_type : $result->contact_type, | |
313 | FALSE, | |
314 | $result->contact_id | |
315 | ); | |
316 | ||
317 | $searchRows[$contactID] = array('id' => $contactID); | |
318 | foreach ($selectorCols as $col) { | |
319 | $val = $result->$col; | |
320 | if ($col == 'contact_type') { | |
321 | $val = $typeImage; | |
322 | } | |
323 | $searchRows[$contactID][$col] = $val; | |
324 | } | |
325 | if ($searchVoterFor == 'reserve') { | |
326 | $voterExtraColHtml = '<input type="checkbox" id="survey_activity[' . $contactID . ']" name="survey_activity[' . $contactID . ']" value=' . $contactID . ' onClick="processVoterData( this, \'reserve\' );" />'; | |
327 | $msg = ts('Respondent Reserved.'); | |
328 | $voterExtraColHtml .= " <span id='success_msg_{$contactID}' class='ok' style='display:none;'>$msg</span>"; | |
329 | } | |
330 | elseif ($searchVoterFor == 'gotv') { | |
331 | $surveyActId = $result->survey_activity_id; | |
332 | $voterExtraColHtml = '<input type="checkbox" id="survey_activity[' . $surveyActId . ']" name="survey_activity[' . $surveyActId . ']" value=' . $surveyActId . ' onClick="processVoterData( this, \'gotv\' );" />'; | |
805dd6a2 | 333 | $msg = ts('Vote Recorded.'); |
6a488035 TO |
334 | $voterExtraColHtml .= " <span id='success_msg_{$surveyActId}' class='ok' style='display:none;'>$msg</span>"; |
335 | } | |
336 | else { | |
337 | $surveyActId = $result->survey_activity_id; | |
338 | $voterExtraColHtml = '<input type="checkbox" id="survey_activity[' . $surveyActId . ']" name="survey_activity[' . $surveyActId . ']" value=' . $surveyActId . ' onClick="processVoterData( this, \'release\' );" />'; | |
805dd6a2 | 339 | $msg = ts('Vote Recorded.'); |
6a488035 TO |
340 | $voterExtraColHtml .= " <span id='success_msg_{$surveyActId}' class='ok' style='display:none;'>$msg</span>"; |
341 | } | |
342 | $searchRows[$contactID][$extraVoterColName] = $voterExtraColHtml; | |
343 | } | |
344 | } | |
345 | ||
346 | $selectorElements = array_merge($selectorCols, array($extraVoterColName)); | |
347 | ||
348 | $iFilteredTotal = $iTotal; | |
349 | ||
350 | echo CRM_Utils_JSON::encodeDataTableSelector($searchRows, $sEcho, $iTotal, $iFilteredTotal, $selectorElements); | |
351 | CRM_Utils_System::civiExit(); | |
352 | } | |
353 | ||
354 | function processVoterData() { | |
355 | $status = NULL; | |
356 | $operation = CRM_Utils_Type::escape($_POST['operation'], 'String'); | |
357 | if ($operation == 'release') { | |
358 | $activityId = CRM_Utils_Type::escape($_POST['activity_id'], 'Integer'); | |
359 | $isDelete = CRM_Utils_String::strtoboolstr(CRM_Utils_Type::escape($_POST['isDelete'], 'String')); | |
360 | if ($activityId && | |
361 | CRM_Core_DAO::setFieldValue('CRM_Activity_DAO_Activity', | |
362 | $activityId, | |
363 | 'is_deleted', | |
364 | $isDelete | |
365 | ) | |
366 | ) { | |
367 | $status = 'success'; | |
368 | } | |
369 | } | |
370 | elseif ($operation == 'reserve') { | |
371 | $activityId = NULL; | |
372 | $createActivity = TRUE; | |
a7488080 | 373 | if (!empty($_POST['activity_id'])) { |
6a488035 TO |
374 | $activityId = CRM_Utils_Type::escape($_POST['activity_id'], 'Integer'); |
375 | if ($activityId) { | |
376 | $createActivity = FALSE; | |
377 | $activityUpdated = CRM_Core_DAO::setFieldValue('CRM_Activity_DAO_Activity', | |
378 | $activityId, | |
379 | 'is_deleted', | |
380 | 0 | |
381 | ); | |
382 | if ($activityUpdated) { | |
383 | $status = 'success'; | |
384 | } | |
385 | } | |
386 | } | |
387 | if ($createActivity) { | |
388 | $ids = array( | |
389 | 'source_record_id', | |
390 | 'source_contact_id', | |
391 | 'target_contact_id', | |
392 | 'assignee_contact_id', | |
393 | ); | |
394 | $activityParams = array(); | |
395 | foreach ($ids as $id) { | |
396 | $val = CRM_Utils_Array::value($id, $_POST); | |
397 | if (!$val) { | |
398 | $createActivity = FALSE; | |
399 | break; | |
400 | } | |
401 | $activityParams[$id] = CRM_Utils_Type::escape($val, 'Integer'); | |
402 | } | |
403 | } | |
404 | if ($createActivity) { | |
405 | $isReserved = CRM_Utils_String::strtoboolstr(CRM_Utils_Type::escape($_POST['isReserved'], 'String')); | |
406 | $activityStatus = CRM_Core_PseudoConstant::activityStatus('name'); | |
407 | $scheduledStatusId = array_search('Scheduled', $activityStatus); | |
408 | if ($isReserved) { | |
409 | $surveyValues = array(); | |
410 | $surveyParams = array('id' => $activityParams['source_record_id']); | |
411 | CRM_Core_DAO::commonRetrieve('CRM_Campaign_DAO_Survey', | |
412 | $surveyParams, | |
413 | $surveyValues, | |
414 | array('title', 'activity_type_id', 'campaign_id') | |
415 | ); | |
416 | ||
417 | $activityTypeId = $surveyValues['activity_type_id']; | |
418 | ||
419 | $surveytitle = CRM_Utils_Array::value('surveyTitle', $_POST); | |
420 | if (!$surveytitle) { | |
421 | $surveytitle = $surveyValues['title']; | |
422 | } | |
423 | ||
424 | $subject = ts('%1', array(1 => $surveytitle)) . ' - ' . ts('Respondent Reservation'); | |
425 | $activityParams['subject'] = $subject; | |
426 | $activityParams['status_id'] = $scheduledStatusId; | |
427 | $activityParams['skipRecentView'] = 1; | |
428 | $activityParams['activity_date_time'] = date('YmdHis'); | |
429 | $activityParams['activity_type_id'] = $activityTypeId; | |
bef6ccc5 | 430 | $activityParams['campaign_id'] = isset($surveyValues['campaign_id']) ? $surveyValues['campaign_id'] : NULL; |
6a488035 TO |
431 | |
432 | $activity = CRM_Activity_BAO_Activity::create($activityParams); | |
433 | if ($activity->id) { | |
434 | $status = 'success'; | |
435 | } | |
436 | } | |
437 | else { | |
438 | //delete reserved activity for given voter. | |
439 | $voterIds = array($activityParams['target_contact_id']); | |
440 | $activities = CRM_Campaign_BAO_Survey::voterActivityDetails($activityParams['source_record_id'], | |
441 | $voterIds, | |
442 | $activityParams['source_contact_id'], | |
443 | array($scheduledStatusId) | |
444 | ); | |
445 | foreach ($activities as $voterId => $values) { | |
446 | $activityId = CRM_Utils_Array::value('activity_id', $values); | |
447 | if ($activityId && ($values['status_id'] == $scheduledStatusId)) { | |
448 | CRM_Core_DAO::setFieldValue('CRM_Activity_DAO_Activity', | |
449 | $activityId, | |
450 | 'is_deleted', | |
451 | TRUE | |
452 | ); | |
453 | $status = 'success'; | |
454 | break; | |
455 | } | |
456 | } | |
457 | } | |
458 | } | |
459 | } | |
460 | elseif ($operation == 'gotv') { | |
461 | $activityId = CRM_Utils_Type::escape($_POST['activity_id'], 'Integer'); | |
462 | $hasVoted = CRM_Utils_String::strtoboolstr(CRM_Utils_Type::escape($_POST['hasVoted'], 'String')); | |
463 | if ($activityId) { | |
464 | if ($hasVoted) { | |
465 | $statusValue = 2; | |
466 | } | |
467 | else { | |
468 | $statusValue = 1; | |
469 | } | |
470 | CRM_Core_DAO::setFieldValue('CRM_Activity_DAO_Activity', | |
471 | $activityId, | |
472 | 'status_id', | |
473 | $statusValue | |
474 | ); | |
475 | $status = 'success'; | |
476 | } | |
477 | } | |
478 | ||
ecdef330 | 479 | CRM_Utils_JSON::output(array('status' => $status)); |
6a488035 TO |
480 | } |
481 | ||
482 | function allActiveCampaigns() { | |
483 | $currentCampaigns = CRM_Campaign_BAO_Campaign::getCampaigns(); | |
484 | $campaigns = CRM_Campaign_BAO_Campaign::getCampaigns(NULL, NULL, TRUE, FALSE, TRUE); | |
485 | $options = array( | |
486 | array('value' => '', | |
487 | 'title' => ts('- select -'), | |
488 | )); | |
489 | foreach ($campaigns as $value => $title) { | |
490 | $class = NULL; | |
491 | if (!array_key_exists($value, $currentCampaigns)) { | |
492 | $class = 'status-past'; | |
493 | } | |
494 | $options[] = array( | |
495 | 'value' => $value, | |
496 | 'title' => $title, | |
497 | 'class' => $class, | |
498 | ); | |
499 | } | |
500 | $status = 'fail'; | |
501 | if (count($options) > 1) { | |
502 | $status = 'success'; | |
503 | } | |
504 | ||
505 | $results = array( | |
506 | 'status' => $status, | |
507 | 'campaigns' => $options, | |
508 | ); | |
509 | ||
ecdef330 | 510 | CRM_Utils_JSON::output($results); |
6a488035 TO |
511 | } |
512 | ||
513 | function campaignGroups() { | |
514 | $surveyId = CRM_Utils_Request::retrieve('survey_id', 'Positive', | |
515 | CRM_Core_DAO::$_nullObject, FALSE, NULL, 'POST' | |
516 | ); | |
517 | $campGroups = array(); | |
518 | if ($surveyId) { | |
519 | $campaignId = CRM_Core_DAO::getFieldValue('CRM_Campaign_DAO_Survey', $surveyId, 'campaign_id'); | |
520 | if ($campaignId) { | |
521 | $campGroups = CRM_Campaign_BAO_Campaign::getCampaignGroups($campaignId); | |
522 | } | |
523 | } | |
524 | ||
525 | //CRM-7406 --If there is no campaign or no group associated with | |
526 | //campaign of given survey, lets allow to search across all groups. | |
527 | if (empty($campGroups)) { | |
528 | $campGroups = CRM_Core_PseudoConstant::group(); | |
529 | } | |
530 | $groups = array( | |
531 | array('value' => '', | |
532 | 'title' => ts('- select -'), | |
533 | )); | |
534 | foreach ($campGroups as $grpId => $title) { | |
535 | $groups[] = array( | |
536 | 'value' => $grpId, | |
537 | 'title' => $title, | |
538 | ); | |
539 | } | |
540 | $results = array( | |
541 | 'status' => 'success', | |
542 | 'groups' => $groups, | |
543 | ); | |
544 | ||
ecdef330 | 545 | CRM_Utils_JSON::output($results); |
6a488035 TO |
546 | } |
547 | ||
548 | /** | |
549 | * Retrieve campaigns as for campaign dashboard. | |
550 | * | |
551 | **/ | |
552 | function campaignList() { | |
553 | //get the search criteria params. | |
554 | $searchParams = explode(',', CRM_Utils_Array::value('searchCriteria', $_POST)); | |
555 | ||
556 | $params = $searchRows = array(); | |
557 | foreach ($searchParams as $param) { | |
a7488080 | 558 | if (!empty($_POST[$param])) { |
6a488035 TO |
559 | $params[$param] = $_POST[$param]; |
560 | } | |
561 | } | |
562 | ||
563 | //this is sequence columns on datatable. | |
564 | $selectorCols = array( | |
565 | 'id', | |
566 | 'name', | |
567 | 'title', | |
568 | 'description', | |
569 | 'start_date', | |
570 | 'end_date', | |
571 | 'campaign_type_id', | |
572 | 'campaign_type', | |
573 | 'status_id', | |
574 | 'status', | |
575 | 'is_active', | |
576 | 'isActive', | |
577 | 'action', | |
578 | ); | |
579 | ||
580 | // get the data table params. | |
581 | $dataTableParams = array( | |
582 | 'sEcho' => array('name' => 'sEcho', | |
583 | 'type' => 'Integer', | |
584 | 'default' => 0, | |
585 | ), | |
586 | 'offset' => array( | |
587 | 'name' => 'iDisplayStart', | |
588 | 'type' => 'Integer', | |
589 | 'default' => 0, | |
590 | ), | |
591 | 'rowCount' => array( | |
592 | 'name' => 'iDisplayLength', | |
593 | 'type' => 'Integer', | |
594 | 'default' => 25, | |
595 | ), | |
596 | 'sort' => array( | |
597 | 'name' => 'iSortCol_0', | |
598 | 'type' => 'Integer', | |
599 | 'default' => 'start_date', | |
600 | ), | |
601 | 'sortOrder' => array( | |
602 | 'name' => 'sSortDir_0', | |
603 | 'type' => 'String', | |
604 | 'default' => 'desc', | |
605 | ), | |
606 | ); | |
607 | foreach ($dataTableParams as $pName => $pValues) { | |
608 | $$pName = $pValues['default']; | |
a7488080 | 609 | if (!empty($_POST[$pValues['name']])) { |
6a488035 TO |
610 | $$pName = CRM_Utils_Type::escape($_POST[$pValues['name']], $pValues['type']); |
611 | if ($pName == 'sort') { | |
612 | $$pName = $selectorCols[$$pName]; | |
613 | } | |
614 | } | |
615 | } | |
616 | foreach (array( | |
617 | 'sort', 'offset', 'rowCount', 'sortOrder') as $sortParam) { | |
618 | $params[$sortParam] = $$sortParam; | |
619 | } | |
620 | ||
621 | $searchCount = CRM_Campaign_BAO_Campaign::getCampaignSummary($params, TRUE); | |
622 | $campaigns = CRM_Campaign_Page_DashBoard::getCampaignSummary($params); | |
623 | $iTotal = $searchCount; | |
624 | ||
625 | if ($searchCount > 0) { | |
626 | if ($searchCount < $offset) { | |
627 | $offset = 0; | |
628 | } | |
629 | foreach ($campaigns as $campaignID => $values) { | |
630 | foreach ($selectorCols as $col) { | |
631 | $searchRows[$campaignID][$col] = CRM_Utils_Array::value($col, $values); | |
632 | } | |
633 | } | |
634 | } | |
635 | ||
636 | $selectorElements = $selectorCols; | |
637 | ||
638 | $iFilteredTotal = $iTotal; | |
639 | ||
640 | echo CRM_Utils_JSON::encodeDataTableSelector($searchRows, $sEcho, $iTotal, $iFilteredTotal, $selectorElements); | |
641 | CRM_Utils_System::civiExit(); | |
642 | } | |
643 | ||
644 | /** | |
645 | * Retrieve survey for survey dashboard. | |
646 | * | |
647 | **/ | |
648 | function surveyList() { | |
649 | //get the search criteria params. | |
650 | $searchParams = explode(',', CRM_Utils_Array::value('searchCriteria', $_POST)); | |
651 | ||
652 | $params = $searchRows = array(); | |
653 | foreach ($searchParams as $param) { | |
a7488080 | 654 | if (!empty($_POST[$param])) { |
6a488035 TO |
655 | $params[$param] = $_POST[$param]; |
656 | } | |
657 | } | |
658 | ||
659 | //this is sequence columns on datatable. | |
660 | $selectorCols = array( | |
661 | 'id', | |
662 | 'title', | |
663 | 'campaign_id', | |
664 | 'campaign', | |
665 | 'activity_type_id', | |
666 | 'activity_type', | |
667 | 'release_frequency', | |
668 | 'default_number_of_contacts', | |
669 | 'max_number_of_contacts', | |
670 | 'is_default', | |
671 | 'is_active', | |
672 | 'isActive', | |
673 | 'result_id', | |
674 | 'action', | |
675 | 'voterLinks', | |
676 | ); | |
677 | ||
678 | // get the data table params. | |
679 | $dataTableParams = array( | |
680 | 'sEcho' => array('name' => 'sEcho', | |
681 | 'type' => 'Integer', | |
682 | 'default' => 0, | |
683 | ), | |
684 | 'offset' => array( | |
685 | 'name' => 'iDisplayStart', | |
686 | 'type' => 'Integer', | |
687 | 'default' => 0, | |
688 | ), | |
689 | 'rowCount' => array( | |
690 | 'name' => 'iDisplayLength', | |
691 | 'type' => 'Integer', | |
692 | 'default' => 25, | |
693 | ), | |
694 | 'sort' => array( | |
695 | 'name' => 'iSortCol_0', | |
696 | 'type' => 'Integer', | |
697 | 'default' => 'created_date', | |
698 | ), | |
699 | 'sortOrder' => array( | |
700 | 'name' => 'sSortDir_0', | |
701 | 'type' => 'String', | |
702 | 'default' => 'desc', | |
703 | ), | |
704 | ); | |
705 | foreach ($dataTableParams as $pName => $pValues) { | |
706 | $$pName = $pValues['default']; | |
a7488080 | 707 | if (!empty($_POST[$pValues['name']])) { |
6a488035 TO |
708 | $$pName = CRM_Utils_Type::escape($_POST[$pValues['name']], $pValues['type']); |
709 | if ($pName == 'sort') { | |
710 | $$pName = $selectorCols[$$pName]; | |
711 | } | |
712 | } | |
713 | } | |
714 | foreach (array( | |
715 | 'sort', 'offset', 'rowCount', 'sortOrder') as $sortParam) { | |
716 | $params[$sortParam] = $$sortParam; | |
717 | } | |
718 | ||
719 | $surveys = CRM_Campaign_Page_DashBoard::getSurveySummary($params); | |
720 | $searchCount = CRM_Campaign_BAO_Survey::getSurveySummary($params, TRUE); | |
721 | $iTotal = $searchCount; | |
722 | ||
723 | if ($searchCount > 0) { | |
724 | if ($searchCount < $offset) { | |
725 | $offset = 0; | |
726 | } | |
727 | foreach ($surveys as $surveyID => $values) { | |
728 | foreach ($selectorCols as $col) { | |
729 | $searchRows[$surveyID][$col] = CRM_Utils_Array::value($col, $values); | |
730 | } | |
731 | } | |
732 | } | |
733 | ||
734 | $selectorElements = $selectorCols; | |
735 | ||
736 | $iFilteredTotal = $iTotal; | |
737 | ||
738 | echo CRM_Utils_JSON::encodeDataTableSelector($searchRows, $sEcho, $iTotal, $iFilteredTotal, $selectorElements); | |
739 | CRM_Utils_System::civiExit(); | |
740 | } | |
741 | ||
742 | /** | |
743 | * Retrieve petitions for petition dashboard. | |
744 | * | |
745 | **/ | |
746 | function petitionList() { | |
747 | //get the search criteria params. | |
748 | $searchParams = explode(',', CRM_Utils_Array::value('searchCriteria', $_POST)); | |
749 | ||
750 | $params = $searchRows = array(); | |
751 | foreach ($searchParams as $param) { | |
a7488080 | 752 | if (!empty($_POST[$param])) { |
6a488035 TO |
753 | $params[$param] = $_POST[$param]; |
754 | } | |
755 | } | |
756 | ||
757 | //this is sequence columns on datatable. | |
758 | $selectorCols = array( | |
759 | 'id', | |
760 | 'title', | |
761 | 'campaign_id', | |
762 | 'campaign', | |
763 | 'activity_type_id', | |
764 | 'activity_type', | |
765 | 'is_default', | |
766 | 'is_active', | |
767 | 'isActive', | |
768 | 'action', | |
769 | ); | |
770 | ||
771 | // get the data table params. | |
772 | $dataTableParams = array( | |
773 | 'sEcho' => array('name' => 'sEcho', | |
774 | 'type' => 'Integer', | |
775 | 'default' => 0, | |
776 | ), | |
777 | 'offset' => array( | |
778 | 'name' => 'iDisplayStart', | |
779 | 'type' => 'Integer', | |
780 | 'default' => 0, | |
781 | ), | |
782 | 'rowCount' => array( | |
783 | 'name' => 'iDisplayLength', | |
784 | 'type' => 'Integer', | |
785 | 'default' => 25, | |
786 | ), | |
787 | 'sort' => array( | |
788 | 'name' => 'iSortCol_0', | |
789 | 'type' => 'Integer', | |
790 | 'default' => 'created_date', | |
791 | ), | |
792 | 'sortOrder' => array( | |
793 | 'name' => 'sSortDir_0', | |
794 | 'type' => 'String', | |
795 | 'default' => 'desc', | |
796 | ), | |
797 | ); | |
798 | foreach ($dataTableParams as $pName => $pValues) { | |
799 | $$pName = $pValues['default']; | |
a7488080 | 800 | if (!empty($_POST[$pValues['name']])) { |
6a488035 TO |
801 | $$pName = CRM_Utils_Type::escape($_POST[$pValues['name']], $pValues['type']); |
802 | if ($pName == 'sort') { | |
803 | $$pName = $selectorCols[$$pName]; | |
804 | } | |
805 | } | |
806 | } | |
807 | foreach (array( | |
808 | 'sort', 'offset', 'rowCount', 'sortOrder') as $sortParam) { | |
809 | $params[$sortParam] = $$sortParam; | |
810 | } | |
811 | ||
812 | $petitions = CRM_Campaign_Page_DashBoard::getPetitionSummary($params); | |
813 | $searchCount = CRM_Campaign_BAO_Petition::getPetitionSummary($params, TRUE); | |
814 | $iTotal = $searchCount; | |
815 | ||
816 | if ($searchCount > 0) { | |
817 | if ($searchCount < $offset) { | |
818 | $offset = 0; | |
819 | } | |
820 | foreach ($petitions as $petitionID => $values) { | |
821 | foreach ($selectorCols as $col) { | |
822 | $searchRows[$petitionID][$col] = CRM_Utils_Array::value($col, $values); | |
823 | } | |
824 | } | |
825 | } | |
826 | ||
827 | $selectorElements = $selectorCols; | |
828 | ||
829 | $iFilteredTotal = $iTotal; | |
830 | ||
831 | echo CRM_Utils_JSON::encodeDataTableSelector($searchRows, $sEcho, $iTotal, $iFilteredTotal, $selectorElements); | |
832 | CRM_Utils_System::civiExit(); | |
833 | } | |
834 | } | |
835 |