3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.5 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
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-2014
41 * advanced search, extends basic search
43 class CRM_Contribute_Form_Search
extends CRM_Core_Form_Search
{
46 * Are we forced to run a search
54 * name of search button
59 protected $_searchButtonName;
62 * name of action button
67 protected $_actionButtonName;
70 * form values that we will be using
78 * the params that are sent to the query
83 protected $_queryParams;
86 * have we already done this search
94 * are we restricting ourselves to a single contact
99 protected $_single = FALSE;
102 * are we restricting ourselves to a single contact
107 protected $_limit = NULL;
110 * what context are we being invoked from
115 protected $_context = NULL;
117 protected $_defaults;
120 * prefix for the controller
123 protected $_prefix = "contribute_";
126 * processing needed for buildForm and later
130 */ function preProcess() {
131 $this->set('searchFormName', 'Search');
134 * set the button names
136 $this->_searchButtonName
= $this->getButtonName('refresh');
137 $this->_actionButtonName
= $this->getButtonName('next', 'action');
139 $this->_done
= FALSE;
140 $this->defaults
= array();
143 * we allow the controller to set force/reset externally, useful when we are being
144 * driven by the wizard framework
147 $this->_reset
= CRM_Utils_Request
::retrieve('reset', 'Boolean', CRM_Core_DAO
::$_nullObject);
148 $this->_force
= CRM_Utils_Request
::retrieve('force', 'Boolean', $this, FALSE);
149 $this->_limit
= CRM_Utils_Request
::retrieve('limit', 'Positive', $this);
150 $this->_context
= CRM_Utils_Request
::retrieve('context', 'String', $this, FALSE, 'search');
152 $this->assign("context", $this->_context
);
154 // get user submitted values
155 // get it from controller only if form has been submitted, else preProcess has set this
156 if (!empty($_POST)) {
157 $this->_formValues
= $this->controller
->exportValues($this->_name
);
160 $this->_formValues
= $this->get('formValues');
164 $memberShipId = CRM_Utils_Request
::retrieve('memberId', 'Positive', $this);
165 if (isset($memberShipId)) {
166 $this->_formValues
['contribution_membership_id'] = $memberShipId;
168 $participantId = CRM_Utils_Request
::retrieve('participantId', 'Positive', $this);
169 if (isset($participantId)) {
170 $this->_formValues
['contribution_participant_id'] = $participantId;
174 $this->postProcess();
175 $this->set('force', 0);
179 if ($this->get(CRM_Utils_Sort
::SORT_ID
)) {
180 $sortID = CRM_Utils_Sort
::sortIDValue($this->get(CRM_Utils_Sort
::SORT_ID
),
181 $this->get(CRM_Utils_Sort
::SORT_DIRECTION
)
185 $this->_queryParams
= CRM_Contact_BAO_Query
::convertFormValues($this->_formValues
);
186 $selector = new CRM_Contribute_Selector_Search($this->_queryParams
,
194 if ($this->_context
== 'user') {
195 $prefix = $this->_prefix
;
198 $this->assign("{$prefix}limit", $this->_limit
);
199 $this->assign("{$prefix}single", $this->_single
);
201 $controller = new CRM_Core_Selector_Controller($selector,
202 $this->get(CRM_Utils_Pager
::PAGE_ID
),
204 CRM_Core_Action
::VIEW
,
206 CRM_Core_Selector_Controller
::TRANSFER
,
210 $controller->setEmbedded(TRUE);
211 $controller->moveFromSessionToTemplate();
213 $this->assign('contributionSummary', $this->get('summary'));
216 function setDefaultValues() {
217 if (empty($this->_defaults
218 ['contribution_status'])) {
219 $this->_defaults
['contribution_status'][1] = 1;
221 return $this->_defaults
;
231 function buildQuickForm() {
232 parent
::buildQuickForm();
233 // text for sort_name
234 $this->addElement('text',
236 ts('Contributor Name or Email'),
237 CRM_Core_DAO
::getAttribute('CRM_Contact_DAO_Contact',
242 $this->_group
= CRM_Core_PseudoConstant
::group();
244 // multiselect for groups
246 $this->add('select', 'group', ts('Groups'), $this->_group
, FALSE,
247 array('id' => 'group', 'multiple' => 'multiple', 'class' => 'crm-select2')
251 // multiselect for tags
252 $contactTags = CRM_Core_BAO_Tag
::getTags();
255 $this->add('select', 'contact_tags', ts('Tags'), $contactTags, FALSE,
256 array('id' => 'contact_tags', 'multiple' => 'multiple', 'class' => 'crm-select2')
260 CRM_Contribute_BAO_Query
::buildSearchForm($this);
263 * add form checkboxes for each row. This is needed out here to conform to QF protocol
264 * of all elements being declared in builQuickForm
267 $rows = $this->get('rows');
268 if (is_array($rows)) {
269 if (!$this->_single
) {
270 $this->addElement('checkbox',
274 array('onclick' => "toggleTaskAction( true );", 'class' => 'select-rows')
276 foreach ($rows as $row) {
277 $this->addElement('checkbox', $row['checkbox'],
279 array('onclick' => "toggleTaskAction( true );", 'class' => 'select-row')
284 $total = $cancel = 0;
286 $permission = CRM_Core_Permission
::getPermission();
288 $queryParams = $this->get('queryParams');
289 $softCreditFiltering = FALSE;
290 if (!empty($queryParams)) {
291 $softCreditFiltering = CRM_Contribute_BAO_Query
::isSoftCreditOptionEnabled($queryParams);
293 $tasks = array('' => ts('- actions -')) + CRM_Contribute_Task
::permissionedTaskTitles($permission, $softCreditFiltering);
294 $this->add('select', 'task', ts('Actions:') . ' ', $tasks);
295 $this->add('submit', $this->_actionButtonName
, ts('Go'),
297 'class' => 'form-submit',
299 'onclick' => "return checkPerformAction('mark_x', '" . $this->getName() . "', 0);",
303 // need to perform tasks on all or selected items ? using radio_ts(task selection) for it
304 $this->addElement('radio', 'radio_ts', NULL, '', 'ts_sel', array('checked' => 'checked'));
305 $this->addElement('radio', 'radio_ts', NULL, '', 'ts_all', array('class' => 'select-rows', 'onclick' => $this->getName() . ".toggleSelect.checked = false; toggleTaskAction( true );"));
311 * The post processing of the form gets done here.
313 * Key things done during post processing are
314 * - check for reset or next request. if present, skip post procesing.
315 * - now check if user requested running a saved search, if so, then
316 * the form values associated with the saved search are used for searching.
317 * - if user has done a submit with new values the regular post submissing is
319 * The processing consists of using a Selector / Controller framework for getting the
327 function postProcess() {
334 if (!empty($_POST)) {
335 $this->_formValues
= $this->controller
->exportValues($this->_name
);
338 $this->fixFormValues();
340 // We don't show test records in summaries or dashboards
341 if (empty($this->_formValues
['contribution_test']) && $this->_force
) {
342 $this->_formValues
["contribution_test"] = 0;
346 'contribution_amount_low', 'contribution_amount_high') as $f) {
347 if (isset($this->_formValues
[$f])) {
348 $this->_formValues
[$f] = CRM_Utils_Rule
::cleanMoney($this->_formValues
[$f]);
352 $config = CRM_Core_Config
::singleton();
353 if (!empty($_POST)) {
355 $financialType = CRM_Utils_Array
::value('financial_type_id', $this->_formValues
);
356 if ($financialType && is_array($financialType)) {
357 unset($this->_formValues
['financial_type_id']);
358 foreach($financialType as $notImportant => $typeID) {
359 $this->_formValues
['financial_type_id'][$typeID] = 1;
363 $tags = CRM_Utils_Array
::value('contact_tags', $this->_formValues
);
364 if ($tags && !is_array($tags)) {
365 unset($this->_formValues
['contact_tags']);
366 $this->_formValues
['contact_tags'][$tags] = 1;
369 if ($tags && is_array($tags)) {
370 unset($this->_formValues
['contact_tags']);
371 foreach($tags as $notImportant => $tagID) {
372 $this->_formValues
['contact_tags'][$tagID] = 1;
377 if (!$config->groupTree
) {
378 $group = CRM_Utils_Array
::value('group', $this->_formValues
);
379 if ($group && !is_array($group)) {
380 unset($this->_formValues
['group']);
381 $this->_formValues
['group'][$group] = 1;
384 if ($group && is_array($group)) {
385 unset($this->_formValues
['group']);
386 foreach($group as $notImportant => $groupID) {
387 $this->_formValues
['group'][$groupID] = 1;
393 CRM_Core_BAO_CustomValue
::fixFieldValueOfTypeMemo($this->_formValues
);
395 $this->_queryParams
= CRM_Contact_BAO_Query
::convertFormValues($this->_formValues
);
397 $this->set('formValues', $this->_formValues
);
398 $this->set('queryParams', $this->_queryParams
);
400 $buttonName = $this->controller
->getButtonName();
401 if ($buttonName == $this->_actionButtonName
) {
402 // check actionName and if next, then do not repeat a search, since we are going to the next page
404 // hack, make sure we reset the task values
405 $stateMachine = $this->controller
->getStateMachine();
406 $formName = $stateMachine->getTaskFormName();
407 $this->controller
->resetPage($formName);
413 if ($this->get(CRM_Utils_Sort
::SORT_ID
)) {
414 $sortID = CRM_Utils_Sort
::sortIDValue($this->get(CRM_Utils_Sort
::SORT_ID
),
415 $this->get(CRM_Utils_Sort
::SORT_DIRECTION
)
419 $this->_queryParams
= CRM_Contact_BAO_Query
::convertFormValues($this->_formValues
);
420 $selector = new CRM_Contribute_Selector_Search($this->_queryParams
,
427 $selector->setKey($this->controller
->_key
);
430 if ($this->_context
== 'basic' ||
$this->_context
== 'user') {
431 $prefix = $this->_prefix
;
434 $controller = new CRM_Core_Selector_Controller($selector,
435 $this->get(CRM_Utils_Pager
::PAGE_ID
),
437 CRM_Core_Action
::VIEW
,
439 CRM_Core_Selector_Controller
::SESSION
,
442 $controller->setEmbedded(TRUE);
444 $query = &$selector->getQuery();
445 if ($this->_context
== 'user') {
446 $query->setSkipPermission(TRUE);
448 $summary = &$query->summaryContribution($this->_context
);
449 $this->set('summary', $summary);
450 $this->assign('contributionSummary', $summary);
454 function fixFormValues() {
455 // if this search has been forced
456 // then see if there are any get values, and if so over-ride the post values
457 // note that this means that GET over-rides POST :)
458 if (!$this->_force
) {
462 $status = CRM_Utils_Request
::retrieve('status', 'String',
463 CRM_Core_DAO
::$_nullObject
466 $this->_formValues
['contribution_status_id'] = array($status => 1);
467 $this->_defaults
['contribution_status_id'] = array($status => 1);
470 $cid = CRM_Utils_Request
::retrieve('cid', 'Positive', $this);
473 $cid = CRM_Utils_Type
::escape($cid, 'Integer');
475 $this->_formValues
['contact_id'] = $cid;
476 list($display, $image) = CRM_Contact_BAO_Contact
::getDisplayAndImage($cid);
477 $this->_defaults
['sort_name'] = CRM_Core_DAO
::getFieldValue('CRM_Contact_DAO_Contact', $cid,
480 // also assign individual mode to the template
481 $this->_single
= TRUE;
485 $lowDate = CRM_Utils_Request
::retrieve('start', 'Timestamp',
486 CRM_Core_DAO
::$_nullObject
489 $lowDate = CRM_Utils_Type
::escape($lowDate, 'Timestamp');
490 $date = CRM_Utils_Date
::setDateDefaults($lowDate);
491 $this->_formValues
['contribution_date_low'] = $this->_defaults
['contribution_date_low'] = $date[0];
494 $highDate = CRM_Utils_Request
::retrieve('end', 'Timestamp',
495 CRM_Core_DAO
::$_nullObject
498 $highDate = CRM_Utils_Type
::escape($highDate, 'Timestamp');
499 $date = CRM_Utils_Date
::setDateDefaults($highDate);
500 $this->_formValues
['contribution_date_high'] = $this->_defaults
['contribution_date_high'] = $date[0];
503 if ($highDate ||
$lowDate) {
504 //set the Choose Date Range value
505 $this->_formValues
['contribution_date_relative'] = 0;
508 $this->_limit
= CRM_Utils_Request
::retrieve('limit', 'Positive',
512 $test = CRM_Utils_Request
::retrieve('test', 'Boolean',
513 CRM_Core_DAO
::$_nullObject
516 $test = CRM_Utils_Type
::escape($test, 'Boolean');
517 $this->_formValues
['contribution_test'] = $test;
520 $recur = CRM_Utils_Request
::retrieve('recur', 'Positive', $this, FALSE);
522 $this->_formValues
['contribution_recur_id'] = $recur;
523 $this->_formValues
['contribution_recurring'] = 1;
526 //check for contribution page id.
527 $contribPageId = CRM_Utils_Request
::retrieve('pid', 'Positive', $this);
528 if ($contribPageId) {
529 $this->_formValues
['contribution_page_id'] = $contribPageId;
532 //give values to default.
533 $this->_defaults
= $this->_formValues
;
537 * Return a descriptive name for the page, used in wizard header
542 public function getTitle() {
543 return ts('Find Contributions');