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 * This file is for civimember search
43 class CRM_Member_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
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 parent
::buildQuickForm();
217 $this->addElement('text', 'sort_name', ts('Member Name or Email'), CRM_Core_DAO
::getAttribute('CRM_Contact_DAO_Contact', 'sort_name'));
219 CRM_Member_BAO_Query
::buildSearchForm($this);
222 * add form checkboxes for each row. This is needed out here to conform to QF protocol
223 * of all elements being declared in builQuickForm
226 $rows = $this->get('rows');
227 if (is_array($rows)) {
228 if (!$this->_single
) {
229 $this->addElement('checkbox', 'toggleSelect', NULL, NULL, array('onclick' => "toggleTaskAction( true );", 'class' => 'select-rows'));
230 foreach ($rows as $row) {
231 $this->addElement('checkbox', $row['checkbox'],
233 array('onclick' => "toggleTaskAction( true );", 'class' => 'select-row')
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('class' => 'select-rows', 'onclick' => $this->getName() . ".toggleSelect.checked = false; toggleTaskAction( true );"));
260 * The post processing of the form gets done here.
262 * Key things done during post processing are
263 * - check for reset or next request. if present, skip post procesing.
264 * - now check if user requested running a saved search, if so, then
265 * the form values associated with the saved search are used for searching.
266 * - if user has done a submit with new values the regular post submissing is
268 * The processing consists of using a Selector / Controller framework for getting the
276 function postProcess() {
283 $this->_formValues
= $this->controller
->exportValues($this->_name
);
285 $this->fixFormValues();
287 // We don't show test records in summaries or dashboards
288 if (empty($this->_formValues
['member_test']) && $this->_force
) {
289 $this->_formValues
["member_test"] = 0;
292 CRM_Core_BAO_CustomValue
::fixFieldValueOfTypeMemo($this->_formValues
);
294 $this->_queryParams
= CRM_Contact_BAO_Query
::convertFormValues($this->_formValues
);
296 $this->set('formValues', $this->_formValues
);
297 $this->set('queryParams', $this->_queryParams
);
299 $buttonName = $this->controller
->getButtonName();
300 if ($buttonName == $this->_actionButtonName
) {
301 // check actionName and if next, then do not repeat a search, since we are going to the next page
303 // hack, make sure we reset the task values
304 $stateMachine = $this->controller
->getStateMachine();
305 $formName = $stateMachine->getTaskFormName();
306 $this->controller
->resetPage($formName);
311 if ($this->get(CRM_Utils_Sort
::SORT_ID
)) {
312 $sortID = CRM_Utils_Sort
::sortIDValue($this->get(CRM_Utils_Sort
::SORT_ID
),
313 $this->get(CRM_Utils_Sort
::SORT_DIRECTION
)
317 $this->_queryParams
= CRM_Contact_BAO_Query
::convertFormValues($this->_formValues
);
319 $selector = new CRM_Member_Selector_Search($this->_queryParams
,
326 $selector->setKey($this->controller
->_key
);
329 if ($this->_context
== 'basic') {
330 $prefix = $this->_prefix
;
333 $controller = new CRM_Core_Selector_Controller($selector,
334 $this->get(CRM_Utils_Pager
::PAGE_ID
),
336 CRM_Core_Action
::VIEW
,
338 CRM_Core_Selector_Controller
::SESSION
,
341 $controller->setEmbedded(TRUE);
343 $query = &$selector->getQuery();
347 function setDefaultValues() {
348 return $this->_defaults
;
351 function fixFormValues() {
352 // if this search has been forced
353 // then see if there are any get values, and if so over-ride the post values
354 // note that this means that GET over-rides POST :)
356 if (!$this->_force
) {
360 $status = CRM_Utils_Request
::retrieve('status', 'String',
361 CRM_Core_DAO
::$_nullObject
364 $status = explode(',', $status);
365 $tempStatus = array();
366 foreach ($status as $value) {
367 $tempStatus[$value] = 1;
369 $this->_formValues
['member_status_id'] = $tempStatus;
370 $this->_defaults
['member_status_id'] = $tempStatus;
373 $membershipType = CRM_Utils_Request
::retrieve('type', 'String',
374 CRM_Core_DAO
::$_nullObject
377 if ($membershipType) {
378 $this->_formValues
['member_membership_type_id'] = array($membershipType => 1);
379 $this->_defaults
['member_membership_type_id'] = array($membershipType => 1);
383 $cid = CRM_Utils_Request
::retrieve('cid', 'Positive',
384 CRM_Core_DAO
::$_nullObject
388 $cid = CRM_Utils_Type
::escape($cid, 'Integer');
390 $this->_formValues
['contact_id'] = $cid;
391 list($display, $image) = CRM_Contact_BAO_Contact
::getDisplayAndImage($cid);
392 $this->_defaults
['sort_name'] = CRM_Core_DAO
::getFieldValue('CRM_Contact_DAO_Contact', $cid,
395 // also assign individual mode to the template
396 $this->_single
= TRUE;
400 $fromDate = CRM_Utils_Request
::retrieve('start', 'Date',
401 CRM_Core_DAO
::$_nullObject
404 list($date) = CRM_Utils_Date
::setDateDefaults($fromDate);
405 $this->_formValues
['member_start_date_low'] = $this->_defaults
['member_start_date_low'] = $date;
408 $toDate = CRM_Utils_Request
::retrieve('end', 'Date',
409 CRM_Core_DAO
::$_nullObject
412 list($date) = CRM_Utils_Date
::setDateDefaults($toDate);
413 $this->_formValues
['member_start_date_high'] = $this->_defaults
['member_start_date_high'] = $date;
415 $joinDate = CRM_Utils_Request
::retrieve('join', 'Date',
416 CRM_Core_DAO
::$_nullObject
419 list($date) = CRM_Utils_Date
::setDateDefaults($joinDate);
420 $this->_formValues
['member_join_date_low'] = $this->_defaults
['member_join_date_low'] = $date;
423 $joinEndDate = CRM_Utils_Request
::retrieve('joinEnd', 'Date',
424 CRM_Core_DAO
::$_nullObject
427 list($date) = CRM_Utils_Date
::setDateDefaults($joinEndDate);
428 $this->_formValues
['member_join_date_high'] = $this->_defaults
['member_join_date_high'] = $date;
431 $this->_limit
= CRM_Utils_Request
::retrieve('limit', 'Positive',
435 //LCD also allow restrictions to membership owner via GET
436 $owner = CRM_Utils_Request
::retrieve('owner', 'String', CRM_Core_DAO
::$_nullObject);
438 $this->_formValues
['member_is_primary'] = $this->_defaults
['member_is_primary'] = 2;
443 * Return a descriptive name for the page, used in wizard header
448 public function getTitle() {
449 return ts('Find Memberships');