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 * This file is for civimember search
43 class CRM_Member_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 = "member_";
134 * processing needed for buildForm and later
139 function preProcess() {
140 $this->set('searchFormName', 'Search');
143 * set the button names
145 $this->_searchButtonName
= $this->getButtonName('refresh');
146 $this->_printButtonName
= $this->getButtonName('next', 'print');
147 $this->_actionButtonName
= $this->getButtonName('next', 'action');
149 $this->_done
= FALSE;
151 $this->defaults
= array();
154 * we allow the controller to set force/reset externally, useful when we are being
155 * driven by the wizard framework
158 $this->_reset
= CRM_Utils_Request
::retrieve('reset', 'Boolean', CRM_Core_DAO
::$_nullObject);
159 $this->_force
= CRM_Utils_Request
::retrieve('force', 'Boolean', $this, FALSE);
160 $this->_limit
= CRM_Utils_Request
::retrieve('limit', 'Positive', $this);
161 $this->_context
= CRM_Utils_Request
::retrieve('context', 'String', $this, FALSE, 'search');
163 $this->assign("context", $this->_context
);
165 // get user submitted values
166 // get it from controller only if form has been submitted, else preProcess has set this
167 if (!empty($_POST)) {
168 $this->_formValues
= $this->controller
->exportValues($this->_name
);
171 $this->_formValues
= $this->get('formValues');
175 $this->postProcess();
176 $this->set('force', 0);
180 if ($this->get(CRM_Utils_Sort
::SORT_ID
)) {
181 $sortID = CRM_Utils_Sort
::sortIDValue($this->get(CRM_Utils_Sort
::SORT_ID
),
182 $this->get(CRM_Utils_Sort
::SORT_DIRECTION
)
186 $this->_queryParams
= CRM_Contact_BAO_Query
::convertFormValues($this->_formValues
);
187 $selector = new CRM_Member_Selector_Search($this->_queryParams
,
195 if ($this->_context
== 'basic') {
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
,
211 $controller->setEmbedded(TRUE);
212 $controller->moveFromSessionToTemplate();
214 $this->assign('summary', $this->get('summary'));
224 function buildQuickForm() {
225 $this->addElement('text', 'sort_name', ts('Member Name or Email'), CRM_Core_DAO
::getAttribute('CRM_Contact_DAO_Contact', 'sort_name'));
227 CRM_Member_BAO_Query
::buildSearchForm($this);
230 * add form checkboxes for each row. This is needed out here to conform to QF protocol
231 * of all elements being declared in builQuickForm
234 $rows = $this->get('rows');
235 if (is_array($rows)) {
236 if (!$this->_single
) {
237 $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_Member_Task
::permissionedTaskTitles($permission);
251 $this->add('select', 'task', ts('Actions:') . ' ', $tasks);
252 $this->add('submit', $this->_actionButtonName
, ts('Go'),
254 'class' => 'form-submit',
256 'onclick' => "return checkPerformAction('mark_x', '" . $this->getName() . "', 0);",
260 $this->add('submit', $this->_printButtonName
, ts('Print'),
262 'class' => 'form-submit',
263 '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 );"));
275 $this->addButtons(array(
278 'name' => ts('Search'),
285 * The post processing of the form gets done here.
287 * Key things done during post processing are
288 * - check for reset or next request. if present, skip post procesing.
289 * - now check if user requested running a saved search, if so, then
290 * the form values associated with the saved search are used for searching.
291 * - if user has done a submit with new values the regular post submissing is
293 * The processing consists of using a Selector / Controller framework for getting the
301 function postProcess() {
308 $this->_formValues
= $this->controller
->exportValues($this->_name
);
310 $this->fixFormValues();
312 // We don't show test records in summaries or dashboards
313 if (empty($this->_formValues
['member_test']) && $this->_force
) {
314 $this->_formValues
["member_test"] = 0;
317 CRM_Core_BAO_CustomValue
::fixFieldValueOfTypeMemo($this->_formValues
);
319 $this->_queryParams
= CRM_Contact_BAO_Query
::convertFormValues($this->_formValues
);
321 $this->set('formValues', $this->_formValues
);
322 $this->set('queryParams', $this->_queryParams
);
324 $buttonName = $this->controller
->getButtonName();
325 if ($buttonName == $this->_actionButtonName ||
$buttonName == $this->_printButtonName
) {
326 // check actionName and if next, then do not repeat a search, since we are going to the next page
328 // hack, make sure we reset the task values
329 $stateMachine = &$this->controller
->getStateMachine();
330 $formName = $stateMachine->getTaskFormName();
331 $this->controller
->resetPage($formName);
336 if ($this->get(CRM_Utils_Sort
::SORT_ID
)) {
337 $sortID = CRM_Utils_Sort
::sortIDValue($this->get(CRM_Utils_Sort
::SORT_ID
),
338 $this->get(CRM_Utils_Sort
::SORT_DIRECTION
)
342 $this->_queryParams
= CRM_Contact_BAO_Query
::convertFormValues($this->_formValues
);
344 $selector = new CRM_Member_Selector_Search($this->_queryParams
,
351 $selector->setKey($this->controller
->_key
);
354 if ($this->_context
== 'basic') {
355 $prefix = $this->_prefix
;
358 $controller = new CRM_Core_Selector_Controller($selector,
359 $this->get(CRM_Utils_Pager
::PAGE_ID
),
361 CRM_Core_Action
::VIEW
,
363 CRM_Core_Selector_Controller
::SESSION
,
366 $controller->setEmbedded(TRUE);
368 $query = &$selector->getQuery();
372 function setDefaultValues() {
373 return $this->_defaults
;
376 function fixFormValues() {
377 // if this search has been forced
378 // then see if there are any get values, and if so over-ride the post values
379 // note that this means that GET over-rides POST :)
381 if (!$this->_force
) {
385 $status = CRM_Utils_Request
::retrieve('status', 'String',
386 CRM_Core_DAO
::$_nullObject
389 $status = explode(',', $status);
390 $tempStatus = array();
391 foreach ($status as $value) {
392 $tempStatus[$value] = 1;
394 $this->_formValues
['member_status_id'] = $tempStatus;
395 $this->_defaults
['member_status_id'] = $tempStatus;
398 $membershipType = CRM_Utils_Request
::retrieve('type', 'String',
399 CRM_Core_DAO
::$_nullObject
402 if ($membershipType) {
403 $this->_formValues
['member_membership_type_id'] = array($membershipType => 1);
404 $this->_defaults
['member_membership_type_id'] = array($membershipType => 1);
408 $cid = CRM_Utils_Request
::retrieve('cid', 'Positive',
409 CRM_Core_DAO
::$_nullObject
413 $cid = CRM_Utils_Type
::escape($cid, 'Integer');
415 $this->_formValues
['contact_id'] = $cid;
416 list($display, $image) = CRM_Contact_BAO_Contact
::getDisplayAndImage($cid);
417 $this->_defaults
['sort_name'] = CRM_Core_DAO
::getFieldValue('CRM_Contact_DAO_Contact', $cid,
420 // also assign individual mode to the template
421 $this->_single
= TRUE;
425 $fromDate = CRM_Utils_Request
::retrieve('start', 'Date',
426 CRM_Core_DAO
::$_nullObject
429 list($date) = CRM_Utils_Date
::setDateDefaults($fromDate);
430 $this->_formValues
['member_start_date_low'] = $this->_defaults
['member_start_date_low'] = $date;
433 $toDate = CRM_Utils_Request
::retrieve('end', 'Date',
434 CRM_Core_DAO
::$_nullObject
437 list($date) = CRM_Utils_Date
::setDateDefaults($toDate);
438 $this->_formValues
['member_start_date_high'] = $this->_defaults
['member_start_date_high'] = $date;
440 $joinDate = CRM_Utils_Request
::retrieve('join', 'Date',
441 CRM_Core_DAO
::$_nullObject
444 list($date) = CRM_Utils_Date
::setDateDefaults($joinDate);
445 $this->_formValues
['member_join_date_low'] = $this->_defaults
['member_join_date_low'] = $date;
448 $joinEndDate = CRM_Utils_Request
::retrieve('joinEnd', 'Date',
449 CRM_Core_DAO
::$_nullObject
452 list($date) = CRM_Utils_Date
::setDateDefaults($joinEndDate);
453 $this->_formValues
['member_join_date_high'] = $this->_defaults
['member_join_date_high'] = $date;
456 $this->_limit
= CRM_Utils_Request
::retrieve('limit', 'Positive',
460 //LCD also allow restrictions to membership owner via GET
461 $owner = CRM_Utils_Request
::retrieve('owner', 'String', CRM_Core_DAO
::$_nullObject);
463 $this->_formValues
['member_is_primary'] = $this->_defaults
['member_is_primary'] = 2;
468 * Return a descriptive name for the page, used in wizard header
473 public function getTitle() {
474 return ts('Find Memberships');