3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.3 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2013 |
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-2013
41 * advanced search, extends basic search
43 class CRM_Contribute_Form_Search
extends CRM_Core_Form
{
46 * Are we forced to run a search
54 * name of search button
59 protected $_searchButtonName;
62 * name of print button
67 protected $_printButtonName;
70 * name of action button
75 protected $_actionButtonName;
78 * form values that we will be using
83 protected $_formValues;
86 * the params that are sent to the query
91 protected $_queryParams;
94 * have we already done this search
102 * are we restricting ourselves to a single contact
107 protected $_single = FALSE;
110 * are we restricting ourselves to a single contact
115 protected $_limit = NULL;
118 * what context are we being invoked from
123 protected $_context = NULL;
125 protected $_defaults;
128 * prefix for the controller
131 protected $_prefix = "contribute_";
134 * processing needed for buildForm and later
138 */ function preProcess() {
139 $this->set('searchFormName', 'Search');
142 * set the button names
144 $this->_searchButtonName
= $this->getButtonName('refresh');
145 $this->_printButtonName
= $this->getButtonName('next', 'print');
146 $this->_actionButtonName
= $this->getButtonName('next', 'action');
148 $this->_done
= FALSE;
149 $this->defaults
= array();
152 * we allow the controller to set force/reset externally, useful when we are being
153 * driven by the wizard framework
156 $this->_reset
= CRM_Utils_Request
::retrieve('reset', 'Boolean', CRM_Core_DAO
::$_nullObject);
157 $this->_force
= CRM_Utils_Request
::retrieve('force', 'Boolean', $this, FALSE);
158 $this->_limit
= CRM_Utils_Request
::retrieve('limit', 'Positive', $this);
159 $this->_context
= CRM_Utils_Request
::retrieve('context', 'String', $this, FALSE, 'search');
161 $this->assign("context", $this->_context
);
163 // get user submitted values
164 // get it from controller only if form has been submitted, else preProcess has set this
165 if (!empty($_POST)) {
166 $this->_formValues
= $this->controller
->exportValues($this->_name
);
169 $this->_formValues
= $this->get('formValues');
173 $memberShipId = CRM_Utils_Request
::retrieve('memberId', 'Positive', $this);
174 if (isset($memberShipId)) {
175 $this->_formValues
['contribution_membership_id'] = $memberShipId;
177 $participantId = CRM_Utils_Request
::retrieve('participantId', 'Positive', $this);
178 if (isset($participantId)) {
179 $this->_formValues
['contribution_participant_id'] = $participantId;
183 $this->postProcess();
184 $this->set('force', 0);
188 if ($this->get(CRM_Utils_Sort
::SORT_ID
)) {
189 $sortID = CRM_Utils_Sort
::sortIDValue($this->get(CRM_Utils_Sort
::SORT_ID
),
190 $this->get(CRM_Utils_Sort
::SORT_DIRECTION
)
194 $this->_queryParams
= CRM_Contact_BAO_Query
::convertFormValues($this->_formValues
);
195 $selector = new CRM_Contribute_Selector_Search($this->_queryParams
,
203 if ($this->_context
== 'user') {
204 $prefix = $this->_prefix
;
207 $this->assign("{$prefix}limit", $this->_limit
);
208 $this->assign("{$prefix}single", $this->_single
);
210 $controller = new CRM_Core_Selector_Controller($selector,
211 $this->get(CRM_Utils_Pager
::PAGE_ID
),
213 CRM_Core_Action
::VIEW
,
215 CRM_Core_Selector_Controller
::TRANSFER
,
219 $controller->setEmbedded(TRUE);
220 $controller->moveFromSessionToTemplate();
222 $this->assign('contributionSummary', $this->get('summary'));
225 function setDefaultValues() {
226 if (!CRM_Utils_Array
::value('contribution_status',
229 $this->_defaults
['contribution_status'][1] = 1;
231 return $this->_defaults
;
241 function buildQuickForm() {
242 // text for sort_name
243 $this->addElement('text',
245 ts('Contributor Name or Email'),
246 CRM_Core_DAO
::getAttribute('CRM_Contact_DAO_Contact',
251 $this->_group
= CRM_Core_PseudoConstant
::group();
253 // multiselect for groups
255 $this->add('select', 'group', ts('Groups'), $this->_group
, FALSE,
256 array('id' => 'group', 'multiple' => 'multiple', 'title' => ts('- select -'))
260 // multiselect for tags
261 require_once 'CRM/Core/BAO/Tag.php';
262 $contactTags = CRM_Core_BAO_Tag
::getTags();
265 $this->add('select', 'contact_tags', ts('Tags'), $contactTags, FALSE,
266 array('id' => 'contact_tags', 'multiple' => 'multiple', 'title' => ts('- select -'))
270 CRM_Contribute_BAO_Query
::buildSearchForm($this);
273 * add form checkboxes for each row. This is needed out here to conform to QF protocol
274 * of all elements being declared in builQuickForm
277 $rows = $this->get('rows');
278 if (is_array($rows)) {
279 if (!$this->_single
) {
280 $this->addElement('checkbox',
284 array('onclick' => "toggleTaskAction( true ); return toggleCheckboxVals('mark_x_',this);")
286 foreach ($rows as $row) {
287 $this->addElement('checkbox', $row['checkbox'],
289 array('onclick' => "toggleTaskAction( true ); return checkSelectedBox('" . $row['checkbox'] . "');")
294 $total = $cancel = 0;
296 $permission = CRM_Core_Permission
::getPermission();
298 $tasks = array('' => ts('- actions -')) + CRM_Contribute_Task
::permissionedTaskTitles($permission);
299 $this->add('select', 'task', ts('Actions:') . ' ', $tasks);
300 $this->add('submit', $this->_actionButtonName
, ts('Go'),
302 'class' => 'form-submit',
304 'onclick' => "return checkPerformAction('mark_x', '" . $this->getName() . "', 0);",
308 $this->add('submit', $this->_printButtonName
, ts('Print'),
310 'class' => 'form-submit',
311 'onclick' => "return checkPerformAction('mark_x', '" . $this->getName() . "', 1);",
315 // need to perform tasks on all or selected items ? using radio_ts(task selection) for it
316 $this->addElement('radio', 'radio_ts', NULL, '', 'ts_sel', array('checked' => 'checked'));
317 $this->addElement('radio', 'radio_ts', NULL, '', 'ts_all', array('onclick' => $this->getName() . ".toggleSelect.checked = false; toggleCheckboxVals('mark_x_',this); toggleTaskAction( true );"));
321 $this->addButtons(array(
324 'name' => ts('Search'),
332 * The post processing of the form gets done here.
334 * Key things done during post processing are
335 * - check for reset or next request. if present, skip post procesing.
336 * - now check if user requested running a saved search, if so, then
337 * the form values associated with the saved search are used for searching.
338 * - if user has done a submit with new values the regular post submissing is
340 * The processing consists of using a Selector / Controller framework for getting the
348 function postProcess() {
355 if (!empty($_POST)) {
356 $this->_formValues
= $this->controller
->exportValues($this->_name
);
359 $this->fixFormValues();
361 // we don't show test contributions in Contact Summary / User Dashboard
362 // in Search mode by default we hide test contributions
363 if (!CRM_Utils_Array
::value('contribution_test',
366 $this->_formValues
["contribution_test"] = 0;
370 'contribution_amount_low', 'contribution_amount_high') as $f) {
371 if (isset($this->_formValues
[$f])) {
372 $this->_formValues
[$f] = CRM_Utils_Rule
::cleanMoney($this->_formValues
[$f]);
376 $config = CRM_Core_Config
::singleton();
377 $tags = CRM_Utils_Array
::value('contact_tags', $this->_formValues
);
378 if ($tags && !is_array($tags)) {
379 unset($this->_formValues
['contact_tags']);
380 $this->_formValues
['contact_tags'][$tags] = 1;
383 if ($tags && is_array($tags)) {
384 unset($this->_formValues
['contact_tags']);
385 foreach($tags as $notImportant => $tagID) {
386 $this->_formValues
['contact_tags'][$tagID] = 1;
391 if (!$config->groupTree
) {
392 $group = CRM_Utils_Array
::value('group', $this->_formValues
);
393 if ($group && !is_array($group)) {
394 unset($this->_formValues
['group']);
395 $this->_formValues
['group'][$group] = 1;
398 if ($group && is_array($group)) {
399 unset($this->_formValues
['group']);
400 foreach($group as $notImportant => $groupID) {
401 $this->_formValues
['group'][$groupID] = 1;
407 CRM_Core_BAO_CustomValue
::fixFieldValueOfTypeMemo($this->_formValues
);
409 $this->_queryParams
= CRM_Contact_BAO_Query
::convertFormValues($this->_formValues
);
411 $this->set('formValues', $this->_formValues
);
412 $this->set('queryParams', $this->_queryParams
);
414 $buttonName = $this->controller
->getButtonName();
415 if ($buttonName == $this->_actionButtonName ||
$buttonName == $this->_printButtonName
) {
416 // check actionName and if next, then do not repeat a search, since we are going to the next page
418 // hack, make sure we reset the task values
419 $stateMachine = $this->controller
->getStateMachine();
420 $formName = $stateMachine->getTaskFormName();
421 $this->controller
->resetPage($formName);
427 if ($this->get(CRM_Utils_Sort
::SORT_ID
)) {
428 $sortID = CRM_Utils_Sort
::sortIDValue($this->get(CRM_Utils_Sort
::SORT_ID
),
429 $this->get(CRM_Utils_Sort
::SORT_DIRECTION
)
433 $this->_queryParams
= CRM_Contact_BAO_Query
::convertFormValues($this->_formValues
);
434 $selector = new CRM_Contribute_Selector_Search($this->_queryParams
,
441 $selector->setKey($this->controller
->_key
);
444 if ($this->_context
== 'basic' ||
$this->_context
== 'user') {
445 $prefix = $this->_prefix
;
448 $controller = new CRM_Core_Selector_Controller($selector,
449 $this->get(CRM_Utils_Pager
::PAGE_ID
),
451 CRM_Core_Action
::VIEW
,
453 CRM_Core_Selector_Controller
::SESSION
,
456 $controller->setEmbedded(TRUE);
458 $query = &$selector->getQuery();
459 if ($this->_context
== 'user') {
460 $query->setSkipPermission(TRUE);
462 $summary = &$query->summaryContribution($this->_context
);
463 $this->set('summary', $summary);
464 $this->assign('contributionSummary', $summary);
468 function fixFormValues() {
469 // if this search has been forced
470 // then see if there are any get values, and if so over-ride the post values
471 // note that this means that GET over-rides POST :)
473 if (!$this->_force
) {
477 $status = CRM_Utils_Request
::retrieve('status', 'String',
478 CRM_Core_DAO
::$_nullObject
481 $this->_formValues
['contribution_status_id'] = array($status => 1);
482 $this->_defaults
['contribution_status_id'] = array($status => 1);
485 $cid = CRM_Utils_Request
::retrieve('cid', 'Positive', $this);
488 $cid = CRM_Utils_Type
::escape($cid, 'Integer');
490 $this->_formValues
['contact_id'] = $cid;
491 list($display, $image) = CRM_Contact_BAO_Contact
::getDisplayAndImage($cid);
492 $this->_defaults
['sort_name'] = CRM_Core_DAO
::getFieldValue('CRM_Contact_DAO_Contact', $cid,
495 // also assign individual mode to the template
496 $this->_single
= TRUE;
500 $lowDate = CRM_Utils_Request
::retrieve('start', 'Timestamp',
501 CRM_Core_DAO
::$_nullObject
504 $lowDate = CRM_Utils_Type
::escape($lowDate, 'Timestamp');
505 $date = CRM_Utils_Date
::setDateDefaults($lowDate);
506 $this->_formValues
['contribution_date_low'] = $this->_defaults
['contribution_date_low'] = $date[0];
509 $highDate = CRM_Utils_Request
::retrieve('end', 'Timestamp',
510 CRM_Core_DAO
::$_nullObject
513 $highDate = CRM_Utils_Type
::escape($highDate, 'Timestamp');
514 $date = CRM_Utils_Date
::setDateDefaults($highDate);
515 $this->_formValues
['contribution_date_high'] = $this->_defaults
['contribution_date_high'] = $date[0];
518 if ($highDate ||
$lowDate) {
519 //set the Choose Date Range value
520 $this->_formValues
['contribution_date_relative'] = 0;
523 $this->_limit
= CRM_Utils_Request
::retrieve('limit', 'Positive',
527 $test = CRM_Utils_Request
::retrieve('test', 'Boolean',
528 CRM_Core_DAO
::$_nullObject
531 $test = CRM_Utils_Type
::escape($test, 'Boolean');
532 $this->_formValues
['contribution_test'] = $test;
535 $recur = CRM_Utils_Request
::retrieve('recur', 'Positive', $this, FALSE);
537 $this->_formValues
['contribution_recur_id'] = $recur;
538 $this->_formValues
['contribution_recurring'] = 1;
541 //check for contribution page id.
542 $contribPageId = CRM_Utils_Request
::retrieve('pid', 'Positive', $this);
543 if ($contribPageId) {
544 $this->_formValues
['contribution_page_id'] = $contribPageId;
547 //give values to default.
548 $this->_defaults
= $this->_formValues
;
552 * Return a descriptive name for the page, used in wizard header
557 public function getTitle() {
558 return ts('Find Contributions');