3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.4 |
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 action button
67 protected $_actionButtonName;
70 * form values that we will be using
75 protected $_formValues;
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 = "member_";
126 * processing needed for buildForm and later
131 function preProcess() {
132 $this->set('searchFormName', 'Search');
135 * set the button names
137 $this->_searchButtonName
= $this->getButtonName('refresh');
138 $this->_actionButtonName
= $this->getButtonName('next', 'action');
140 $this->_done
= FALSE;
142 $this->defaults
= array();
145 * we allow the controller to set force/reset externally, useful when we are being
146 * driven by the wizard framework
149 $this->_reset
= CRM_Utils_Request
::retrieve('reset', 'Boolean', CRM_Core_DAO
::$_nullObject);
150 $this->_force
= CRM_Utils_Request
::retrieve('force', 'Boolean', $this, FALSE);
151 $this->_limit
= CRM_Utils_Request
::retrieve('limit', 'Positive', $this);
152 $this->_context
= CRM_Utils_Request
::retrieve('context', 'String', $this, FALSE, 'search');
154 $this->assign("context", $this->_context
);
156 // get user submitted values
157 // get it from controller only if form has been submitted, else preProcess has set this
158 if (!empty($_POST)) {
159 $this->_formValues
= $this->controller
->exportValues($this->_name
);
162 $this->_formValues
= $this->get('formValues');
166 $this->postProcess();
167 $this->set('force', 0);
171 if ($this->get(CRM_Utils_Sort
::SORT_ID
)) {
172 $sortID = CRM_Utils_Sort
::sortIDValue($this->get(CRM_Utils_Sort
::SORT_ID
),
173 $this->get(CRM_Utils_Sort
::SORT_DIRECTION
)
177 $this->_queryParams
= CRM_Contact_BAO_Query
::convertFormValues($this->_formValues
);
178 $selector = new CRM_Member_Selector_Search($this->_queryParams
,
186 if ($this->_context
== 'basic') {
187 $prefix = $this->_prefix
;
190 $this->assign("{$prefix}limit", $this->_limit
);
191 $this->assign("{$prefix}single", $this->_single
);
193 $controller = new CRM_Core_Selector_Controller($selector,
194 $this->get(CRM_Utils_Pager
::PAGE_ID
),
196 CRM_Core_Action
::VIEW
,
198 CRM_Core_Selector_Controller
::TRANSFER
,
202 $controller->setEmbedded(TRUE);
203 $controller->moveFromSessionToTemplate();
205 $this->assign('summary', $this->get('summary'));
215 function buildQuickForm() {
216 $this->addElement('text', 'sort_name', ts('Member Name or Email'), CRM_Core_DAO
::getAttribute('CRM_Contact_DAO_Contact', 'sort_name'));
218 CRM_Member_BAO_Query
::buildSearchForm($this);
221 * add form checkboxes for each row. This is needed out here to conform to QF protocol
222 * of all elements being declared in builQuickForm
225 $rows = $this->get('rows');
226 if (is_array($rows)) {
227 CRM_Core_Resources
::singleton()->addScriptFile('civicrm', 'js/crm.searchForm.js');
228 if (!$this->_single
) {
229 $this->addElement('checkbox', 'toggleSelect', NULL, NULL, array('onclick' => "toggleTaskAction( true ); return toggleCheckboxVals('mark_x_',this);"));
230 foreach ($rows as $row) {
231 $this->addElement('checkbox', $row['checkbox'],
233 array('onclick' => "toggleTaskAction( true ); return checkSelectedBox('" . $row['checkbox'] . "');")
238 $total = $cancel = 0;
240 $permission = CRM_Core_Permission
::getPermission();
242 $tasks = array('' => ts('- actions -')) + CRM_Member_Task
::permissionedTaskTitles($permission);
243 $this->add('select', 'task', ts('Actions:') . ' ', $tasks);
244 $this->add('submit', $this->_actionButtonName
, ts('Go'),
246 'class' => 'form-submit',
248 'onclick' => "return checkPerformAction('mark_x', '" . $this->getName() . "', 0);",
252 // need to perform tasks on all or selected items ? using radio_ts(task selection) for it
253 $this->addElement('radio', 'radio_ts', NULL, '', 'ts_sel', array('checked' => 'checked'));
254 $this->addElement('radio', 'radio_ts', NULL, '', 'ts_all', array('onclick' => $this->getName() . ".toggleSelect.checked = false; toggleCheckboxVals('mark_x_',this); toggleTaskAction( true );"));
259 $this->addButtons(array(
262 'name' => ts('Search'),
269 * The post processing of the form gets done here.
271 * Key things done during post processing are
272 * - check for reset or next request. if present, skip post procesing.
273 * - now check if user requested running a saved search, if so, then
274 * the form values associated with the saved search are used for searching.
275 * - if user has done a submit with new values the regular post submissing is
277 * The processing consists of using a Selector / Controller framework for getting the
285 function postProcess() {
292 $this->_formValues
= $this->controller
->exportValues($this->_name
);
294 $this->fixFormValues();
296 // We don't show test records in summaries or dashboards
297 if (empty($this->_formValues
['member_test']) && $this->_force
) {
298 $this->_formValues
["member_test"] = 0;
301 CRM_Core_BAO_CustomValue
::fixFieldValueOfTypeMemo($this->_formValues
);
303 $this->_queryParams
= CRM_Contact_BAO_Query
::convertFormValues($this->_formValues
);
305 $this->set('formValues', $this->_formValues
);
306 $this->set('queryParams', $this->_queryParams
);
308 $buttonName = $this->controller
->getButtonName();
309 if ($buttonName == $this->_actionButtonName
) {
310 // check actionName and if next, then do not repeat a search, since we are going to the next page
312 // hack, make sure we reset the task values
313 $stateMachine = $this->controller
->getStateMachine();
314 $formName = $stateMachine->getTaskFormName();
315 $this->controller
->resetPage($formName);
320 if ($this->get(CRM_Utils_Sort
::SORT_ID
)) {
321 $sortID = CRM_Utils_Sort
::sortIDValue($this->get(CRM_Utils_Sort
::SORT_ID
),
322 $this->get(CRM_Utils_Sort
::SORT_DIRECTION
)
326 $this->_queryParams
= CRM_Contact_BAO_Query
::convertFormValues($this->_formValues
);
328 $selector = new CRM_Member_Selector_Search($this->_queryParams
,
335 $selector->setKey($this->controller
->_key
);
338 if ($this->_context
== 'basic') {
339 $prefix = $this->_prefix
;
342 $controller = new CRM_Core_Selector_Controller($selector,
343 $this->get(CRM_Utils_Pager
::PAGE_ID
),
345 CRM_Core_Action
::VIEW
,
347 CRM_Core_Selector_Controller
::SESSION
,
350 $controller->setEmbedded(TRUE);
352 $query = &$selector->getQuery();
356 function setDefaultValues() {
357 return $this->_defaults
;
360 function fixFormValues() {
361 // if this search has been forced
362 // then see if there are any get values, and if so over-ride the post values
363 // note that this means that GET over-rides POST :)
365 if (!$this->_force
) {
369 $status = CRM_Utils_Request
::retrieve('status', 'String',
370 CRM_Core_DAO
::$_nullObject
373 $status = explode(',', $status);
374 $tempStatus = array();
375 foreach ($status as $value) {
376 $tempStatus[$value] = 1;
378 $this->_formValues
['member_status_id'] = $tempStatus;
379 $this->_defaults
['member_status_id'] = $tempStatus;
382 $membershipType = CRM_Utils_Request
::retrieve('type', 'String',
383 CRM_Core_DAO
::$_nullObject
386 if ($membershipType) {
387 $this->_formValues
['member_membership_type_id'] = array($membershipType => 1);
388 $this->_defaults
['member_membership_type_id'] = array($membershipType => 1);
392 $cid = CRM_Utils_Request
::retrieve('cid', 'Positive',
393 CRM_Core_DAO
::$_nullObject
397 $cid = CRM_Utils_Type
::escape($cid, 'Integer');
399 $this->_formValues
['contact_id'] = $cid;
400 list($display, $image) = CRM_Contact_BAO_Contact
::getDisplayAndImage($cid);
401 $this->_defaults
['sort_name'] = CRM_Core_DAO
::getFieldValue('CRM_Contact_DAO_Contact', $cid,
404 // also assign individual mode to the template
405 $this->_single
= TRUE;
409 $fromDate = CRM_Utils_Request
::retrieve('start', 'Date',
410 CRM_Core_DAO
::$_nullObject
413 list($date) = CRM_Utils_Date
::setDateDefaults($fromDate);
414 $this->_formValues
['member_start_date_low'] = $this->_defaults
['member_start_date_low'] = $date;
417 $toDate = CRM_Utils_Request
::retrieve('end', 'Date',
418 CRM_Core_DAO
::$_nullObject
421 list($date) = CRM_Utils_Date
::setDateDefaults($toDate);
422 $this->_formValues
['member_start_date_high'] = $this->_defaults
['member_start_date_high'] = $date;
424 $joinDate = CRM_Utils_Request
::retrieve('join', 'Date',
425 CRM_Core_DAO
::$_nullObject
428 list($date) = CRM_Utils_Date
::setDateDefaults($joinDate);
429 $this->_formValues
['member_join_date_low'] = $this->_defaults
['member_join_date_low'] = $date;
432 $joinEndDate = CRM_Utils_Request
::retrieve('joinEnd', 'Date',
433 CRM_Core_DAO
::$_nullObject
436 list($date) = CRM_Utils_Date
::setDateDefaults($joinEndDate);
437 $this->_formValues
['member_join_date_high'] = $this->_defaults
['member_join_date_high'] = $date;
440 $this->_limit
= CRM_Utils_Request
::retrieve('limit', 'Positive',
444 //LCD also allow restrictions to membership owner via GET
445 $owner = CRM_Utils_Request
::retrieve('owner', 'String', CRM_Core_DAO
::$_nullObject);
447 $this->_formValues
['member_is_primary'] = $this->_defaults
['member_is_primary'] = 2;
452 * Return a descriptive name for the page, used in wizard header
457 public function getTitle() {
458 return ts('Find Memberships');