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
37 * This file is for Pledge search
39 class CRM_Pledge_Form_Search
extends CRM_Core_Form
{
42 * Are we forced to run a search
50 * name of search button
55 protected $_searchButtonName;
58 * name of print button
63 protected $_printButtonName;
66 * name of action button
71 protected $_actionButtonName;
74 * form values that we will be using
79 protected $_formValues;
82 * the params that are sent to the query
87 protected $_queryParams;
90 * have we already done this search
98 * are we restricting ourselves to a single contact
103 protected $_single = FALSE;
106 * are we restricting ourselves to a single contact
111 protected $_limit = NULL;
114 * what context are we being invoked from
119 protected $_context = NULL;
122 * prefix for the controller
125 protected $_prefix = "pledge_";
127 protected $_defaults;
130 * processing needed for buildForm and later
135 function preProcess() {
138 * set the button names
140 $this->_searchButtonName
= $this->getButtonName('refresh');
141 $this->_printButtonName
= $this->getButtonName('next', 'print');
142 $this->_actionButtonName
= $this->getButtonName('next', 'action');
144 $this->_done
= FALSE;
145 $this->defaults
= array();
148 * we allow the controller to set force/reset externally, useful when we are being
149 * driven by the wizard framework
151 $this->_reset
= CRM_Utils_Request
::retrieve('reset', 'Boolean', CRM_Core_DAO
::$_nullObject);
152 $this->_force
= CRM_Utils_Request
::retrieve('force', 'Boolean', $this, FALSE);
153 $this->_limit
= CRM_Utils_Request
::retrieve('limit', 'Positive', $this);
154 $this->_context
= CRM_Utils_Request
::retrieve('context', 'String', $this, FALSE, 'search');
156 $this->assign("context", $this->_context
);
158 // get user submitted values
159 // get it from controller only if form has been submitted, else preProcess has set this
160 if (!empty($_POST) && !$this->controller
->isModal()) {
161 $this->_formValues
= $this->controller
->exportValues($this->_name
);
164 $this->_formValues
= $this->get('formValues');
167 if (empty($this->_formValues
)) {
168 if (isset($this->_ssID
)) {
169 $this->_formValues
= CRM_Contact_BAO_SavedSearch
::getFormValues($this->_ssID
);
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
)
186 $this->_queryParams
= CRM_Contact_BAO_Query
::convertFormValues($this->_formValues
);
187 $selector = new CRM_Pledge_Selector_Search($this->_queryParams
,
195 if ($this->_context
== 'user') {
196 $prefix = $this->_prefix
;
199 $this->assign("{$prefix}limit", $this->_limit
);
200 $this->assign("{$prefix}single", $this->_single
);
202 $controller = new CRM_Core_Selector_Controller($selector,
203 $this->get(CRM_Utils_Pager
::PAGE_ID
),
205 CRM_Core_Action
::VIEW
,
207 CRM_Core_Selector_Controller
::TRANSFER
,
210 $controller->setEmbedded(TRUE);
211 $controller->moveFromSessionToTemplate();
213 $this->assign('summary', $this->get('summary'));
223 function buildQuickForm() {
224 $this->addElement('text', 'sort_name', ts('Pledger Name or Email'), CRM_Core_DAO
::getAttribute('CRM_Contact_DAO_Contact', 'sort_name'));
226 CRM_Pledge_BAO_Query
::buildSearchForm($this);
229 * add form checkboxes for each row. This is needed out here to conform to QF protocol
230 * of all elements being declared in builQuickForm
232 $rows = $this->get('rows');
233 if (is_array($rows)) {
235 if (!$this->_single
) {
236 $this->addElement('checkbox', 'toggleSelect', NULL, NULL, array('onclick' => "toggleTaskAction( true ); return toggleCheckboxVals('mark_x_',this);"));
238 foreach ($rows as $row) {
239 $this->addElement('checkbox', $row['checkbox'],
241 array('onclick' => "toggleTaskAction( true ); return checkSelectedBox('" . $row['checkbox'] . "');")
246 $total = $cancel = 0;
248 $permission = CRM_Core_Permission
::getPermission();
250 $tasks = array('' => ts('- actions -')) + CRM_Pledge_Task
::permissionedTaskTitles($permission);
252 $this->add('select', 'task', ts('Actions:') . ' ', $tasks);
253 $this->add('submit', $this->_actionButtonName
, ts('Go'),
255 'class' => 'form-submit',
257 'onclick' => "return checkPerformAction('mark_x', '" . $this->getName() . "', 0);",
261 $this->add('submit', $this->_printButtonName
, ts('Print'),
263 'class' => 'form-submit',
264 'onclick' => "return checkPerformAction('mark_x', '" . $this->getName() . "', 1);",
268 // need to perform tasks on all or selected items ? using radio_ts(task selection) for it
269 $this->addElement('radio', 'radio_ts', NULL, '', 'ts_sel', array('checked' => 'checked'));
270 $this->addElement('radio', 'radio_ts', NULL, '', 'ts_all', array('onclick' => $this->getName() . ".toggleSelect.checked = false; toggleCheckboxVals('mark_x_',this); toggleTaskAction( true );"));
274 $this->addButtons(array(
277 'name' => ts('Search'),
284 * The post processing of the form gets done here.
286 * Key things done during post processing are
287 * - check for reset or next request. if present, skip post procesing.
288 * - now check if user requested running a saved search, if so, then
289 * the form values associated with the saved search are used for searching.
290 * - if user has done a submit with new values the regular post submissing is
292 * The processing consists of using a Selector / Controller framework for getting the
300 function postProcess() {
307 $this->_formValues
= $this->controller
->exportValues($this->_name
);
309 $this->fixFormValues();
311 // We don't show test records in summaries or dashboards
312 if (empty($this->_formValues
['pledge_test']) && $this->_force
) {
313 $this->_formValues
["pledge_test"] = 0;
316 foreach (array('pledge_amount_low', 'pledge_amount_high') as $f) {
317 if (isset($this->_formValues
[$f])) {
318 $this->_formValues
[$f] = CRM_Utils_Rule
::cleanMoney($this->_formValues
[$f]);
322 if (isset($this->_ssID
) && empty($_POST)) {
323 // if we are editing / running a saved search and the form has not been posted
324 $this->_formValues
= CRM_Contact_BAO_SavedSearch
::getFormValues($this->_ssID
);
327 CRM_Core_BAO_CustomValue
::fixFieldValueOfTypeMemo($this->_formValues
);
329 $this->_queryParams
= CRM_Contact_BAO_Query
::convertFormValues($this->_formValues
);
331 $this->set('formValues', $this->_formValues
);
332 $this->set('queryParams', $this->_queryParams
);
334 $buttonName = $this->controller
->getButtonName();
335 if ($buttonName == $this->_actionButtonName ||
$buttonName == $this->_printButtonName
) {
336 // check actionName and if next, then do not repeat a search, since we are going to the next page
338 // hack, make sure we reset the task values
339 $stateMachine = $this->controller
->getStateMachine();
340 $formName = $stateMachine->getTaskFormName();
341 $this->controller
->resetPage($formName);
346 if ($this->get(CRM_Utils_Sort
::SORT_ID
)) {
347 $sortID = CRM_Utils_Sort
::sortIDValue($this->get(CRM_Utils_Sort
::SORT_ID
),
348 $this->get(CRM_Utils_Sort
::SORT_DIRECTION
)
352 $this->_queryParams
= CRM_Contact_BAO_Query
::convertFormValues($this->_formValues
);
354 $selector = new CRM_Pledge_Selector_Search($this->_queryParams
,
361 $selector->setKey($this->controller
->_key
);
364 if ($this->_context
== 'user') {
365 $prefix = $this->_prefix
;
368 $this->assign("{$prefix}limit", $this->_limit
);
369 $this->assign("{$prefix}single", $this->_single
);
371 $controller = new CRM_Core_Selector_Controller($selector,
372 $this->get(CRM_Utils_Pager
::PAGE_ID
),
374 CRM_Core_Action
::VIEW
,
376 CRM_Core_Selector_Controller
::SESSION
,
379 $controller->setEmbedded(TRUE);
381 $query = &$selector->getQuery();
382 if ($this->_context
== 'user') {
383 $query->setSkipPermission(TRUE);
389 * This function is used to add the rules (mainly global rules) for form.
390 * All local rules are added near the element
396 function addRules() {
397 $this->addFormRule(array('CRM_Pledge_Form_Search', 'formRule'));
401 * global validation rules for the form
403 * @param array $fields posted values of the form
404 * @param array $errors list of errors to be posted back to the form
410 static function formRule($fields) {
413 if (!empty($errors)) {
421 * Set the default form values
425 * @return array the default array reference
427 function setDefaultValues() {
429 $defaults = $this->_formValues
;
433 function fixFormValues() {
434 if (!$this->_force
) {
438 // set pledge payment related fields
439 $status = CRM_Utils_Request
::retrieve('status', 'String',
440 CRM_Core_DAO
::$_nullObject
443 $this->_formValues
['pledge_payment_status_id'] = array($status => 1);
444 $this->_defaults
['pledge_payment_status_id'] = array($status => 1);
447 $fromDate = CRM_Utils_Request
::retrieve('start', 'Date',
448 CRM_Core_DAO
::$_nullObject
451 list($date) = CRM_Utils_Date
::setDateDefaults($fromDate);
452 $this->_formValues
['pledge_payment_date_low'] = $date;
453 $this->_defaults
['pledge_payment_date_low'] = $date;
456 $toDate = CRM_Utils_Request
::retrieve('end', 'Date',
457 CRM_Core_DAO
::$_nullObject
460 list($date) = CRM_Utils_Date
::setDateDefaults($toDate);
461 $this->_formValues
['pledge_payment_date_high'] = $date;
462 $this->_defaults
['pledge_payment_date_high'] = $date;
465 // set pledge related fields
466 $pledgeStatus = CRM_Utils_Request
::retrieve('pstatus', 'String',
467 CRM_Core_DAO
::$_nullObject
470 $statusValues = CRM_Contribute_PseudoConstant
::contributionStatus();
472 // Remove status values that are only used for recurring contributions for now (Failed).
473 unset($statusValues['4']);
475 // we need set all statuses except Cancelled
476 unset($statusValues[$pledgeStatus]);
479 foreach ($statusValues as $statusId => $value) {
480 $statuses[$statusId] = 1;
483 $this->_formValues
['pledge_status_id'] = $statuses;
484 $this->_defaults
['pledge_status_id'] = $statuses;
487 $pledgeFromDate = CRM_Utils_Request
::retrieve('pstart', 'Date',
488 CRM_Core_DAO
::$_nullObject
490 if ($pledgeFromDate) {
491 list($date) = CRM_Utils_Date
::setDateDefaults($pledgeFromDate);
492 $this->_formValues
['pledge_create_date_low'] = $this->_defaults
['pledge_create_date_low'] = $date;
495 $pledgeToDate = CRM_Utils_Request
::retrieve('pend', 'Date',
496 CRM_Core_DAO
::$_nullObject
499 list($date) = CRM_Utils_Date
::setDateDefaults($pledgeToDate);
500 $this->_formValues
['pledge_create_date_high'] = $this->_defaults
['pledge_create_date_high'] = $date;
503 $cid = CRM_Utils_Request
::retrieve('cid', 'Positive', $this);
505 $cid = CRM_Utils_Type
::escape($cid, 'Integer');
507 $this->_formValues
['contact_id'] = $cid;
508 list($display, $image) = CRM_Contact_BAO_Contact
::getDisplayAndImage($cid);
509 $this->_defaults
['sort_name'] = CRM_Core_DAO
::getFieldValue('CRM_Contact_DAO_Contact', $cid,
512 // also assign individual mode to the template
513 $this->_single
= TRUE;
518 function getFormValues() {
523 * Return a descriptive name for the page, used in wizard header
528 public function getTitle() {
529 return ts('Find Pledges');