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. |
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 along with this program; if not, contact CiviCRM LLC |
21 | at info[AT]civicrm[DOT]org. If you have questions about the |
22 | GNU Affero General Public License or the licensing of CiviCRM, |
23 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
24 +--------------------------------------------------------------------+
30 * @copyright CiviCRM LLC (c) 2004-2013
40 * This file is for activity search
42 class CRM_Activity_Form_Search
extends CRM_Core_Form
{
45 * Are we forced to run a search
53 * name of search button
58 protected $_searchButtonName;
61 * name of print button
66 protected $_printButtonName;
69 * name of action button
74 protected $_actionButtonName;
77 * form values that we will be using
85 * the params that are sent to the query
90 protected $_queryParams;
93 * have we already done this search
101 * are we restricting ourselves to a single contact
106 protected $_single = FALSE;
109 * are we restricting ourselves to a single contact
114 protected $_limit = NULL;
117 * what context are we being invoked from
122 protected $_context = NULL;
125 * prefix for the controller
128 protected $_prefix = "activity_";
130 protected $_defaults;
133 * the saved search ID retrieved from the GET vars
141 * processing needed for buildForm and later
146 function preProcess() {
147 $this->set('searchFormName', 'Search');
150 * set the button names
152 $this->_searchButtonName
= $this->getButtonName('refresh');
153 $this->_printButtonName
= $this->getButtonName('next', 'print');
154 $this->_actionButtonName
= $this->getButtonName('next', 'action');
156 $this->_done
= FALSE;
157 $this->defaults
= array();
160 * we allow the controller to set force/reset externally, useful when we are being
161 * driven by the wizard framework
163 $this->_reset
= CRM_Utils_Request
::retrieve('reset', 'Boolean', CRM_Core_DAO
::$_nullObject);
164 $this->_force
= CRM_Utils_Request
::retrieve('force', 'Boolean', $this, FALSE);
165 $this->_limit
= CRM_Utils_Request
::retrieve('limit', 'Positive', $this);
166 $this->_context
= CRM_Utils_Request
::retrieve('context', 'String', $this, FALSE, 'search');
168 $this->assign("context", $this->_context
);
170 // get user submitted values
171 // get it from controller only if form has been submitted, else preProcess has set this
172 if (!empty($_POST) && !$this->controller
->isModal()) {
173 $this->_formValues
= $this->controller
->exportValues($this->_name
);
176 $this->_formValues
= $this->get('formValues');
179 if (empty($this->_formValues
)) {
180 if (isset($this->_ssID
)) {
181 $this->_formValues
= CRM_Contact_BAO_SavedSearch
::getFormValues($this->_ssID
);
186 $this->postProcess();
187 $this->set('force', 0);
191 if ($this->get(CRM_Utils_Sort
::SORT_ID
)) {
192 $sortID = CRM_Utils_Sort
::sortIDValue($this->get(CRM_Utils_Sort
::SORT_ID
),
193 $this->get(CRM_Utils_Sort
::SORT_DIRECTION
)
197 $this->_queryParams
= CRM_Contact_BAO_Query
::convertFormValues($this->_formValues
);
198 $selector = new CRM_Activity_Selector_Search($this->_queryParams
,
206 if ($this->_context
== 'user') {
207 $prefix = $this->_prefix
;
210 $this->assign("{$prefix}limit", $this->_limit
);
211 $this->assign("{$prefix}single", $this->_single
);
213 $controller = new CRM_Core_Selector_Controller($selector,
214 $this->get(CRM_Utils_Pager
::PAGE_ID
),
216 CRM_Core_Action
::VIEW
,
218 CRM_Core_Selector_Controller
::TRANSFER
,
221 $controller->setEmbedded(TRUE);
222 $controller->moveFromSessionToTemplate();
224 $this->assign('summary', $this->get('summary'));
234 function buildQuickForm() {
235 $this->addElement('text', 'sort_name', ts('Name or Email'), CRM_Core_DAO
::getAttribute('CRM_Contact_DAO_Contact', 'sort_name'));
237 CRM_Activity_BAO_Query
::buildSearchForm($this);
240 * add form checkboxes for each row. This is needed out here to conform to QF protocol
241 * of all elements being declared in builQuickForm
244 $rows = $this->get('rows');
245 if (is_array($rows)) {
246 if (!$this->_single
) {
247 $this->addElement('checkbox', 'toggleSelect', NULL, NULL,
248 array('onclick' => "toggleTaskAction( true ); return toggleCheckboxVals('mark_x_',this);")
250 foreach ($rows as $row) {
251 $this->addElement('checkbox', $row['checkbox'],
253 array('onclick' => "toggleTaskAction( true ); return checkSelectedBox('" . $row['checkbox'] . "');")
258 $permission = CRM_Core_Permission
::getPermission();
260 $tasks = array('' => ts('- actions -')) + CRM_Activity_Task
::permissionedTaskTitles($permission);
262 $this->add('select', 'task', ts('Actions:') . ' ', $tasks);
263 $this->add('submit', $this->_actionButtonName
, ts('Go'),
265 'class' => 'form-submit',
267 'onclick' => "return checkPerformAction('mark_x', '" . $this->getName() . "', 0);",
271 $this->add('submit', $this->_printButtonName
, ts('Print'),
273 'class' => 'form-submit',
274 'onclick' => "return checkPerformAction('mark_x', '" . $this->getName() . "', 1);",
278 // need to perform tasks on all or selected items ? using radio_ts(task selection) for it
279 $this->addElement('radio', 'radio_ts', NULL, '', 'ts_sel', array('checked' => 'checked'));
280 $this->addElement('radio', 'radio_ts', NULL, '', 'ts_all',
281 array('onchange' => $this->getName() . ".toggleSelect.checked = false; toggleCheckboxVals('mark_x_',this); toggleTaskAction( true );")
286 $this->addButtons(array(
289 'name' => ts('Search'),
296 * The post processing of the form gets done here.
298 * Key things done during post processing are
299 * - check for reset or next request. if present, skip post procesing.
300 * - now check if user requested running a saved search, if so, then
301 * the form values associated with the saved search are used for searching.
302 * - if user has done a submit with new values the regular post submissing is
304 * The processing consists of using a Selector / Controller framework for getting the
312 function postProcess() {
319 if (!empty($_POST)) {
320 $this->_formValues
= $this->controller
->exportValues($this->_name
);
323 $this->fixFormValues();
325 if (isset($this->_ssID
) && empty($_POST)) {
326 // if we are editing / running a saved search and the form has not been posted
327 $this->_formValues
= CRM_Contact_BAO_SavedSearch
::getFormValues($this->_ssID
);
330 // We don't show test records in summaries or dashboards
331 if (empty($this->_formValues
['activity_test']) && $this->_force
) {
332 $this->_formValues
["activity_test"] = 0;
335 CRM_Core_BAO_CustomValue
::fixFieldValueOfTypeMemo($this->_formValues
);
337 $this->_queryParams
= CRM_Contact_BAO_Query
::convertFormValues($this->_formValues
);
339 $this->set('formValues', $this->_formValues
);
340 $this->set('queryParams', $this->_queryParams
);
342 $buttonName = $this->controller
->getButtonName();
343 if ($buttonName == $this->_actionButtonName ||
$buttonName == $this->_printButtonName
) {
344 // check actionName and if next, then do not repeat a search, since we are going to the next page
345 // hack, make sure we reset the task values
346 $stateMachine = $this->controller
->getStateMachine();
347 $formName = $stateMachine->getTaskFormName();
348 $this->controller
->resetPage($formName);
353 if ($this->get(CRM_Utils_Sort
::SORT_ID
)) {
354 $sortID = CRM_Utils_Sort
::sortIDValue($this->get(CRM_Utils_Sort
::SORT_ID
),
355 $this->get(CRM_Utils_Sort
::SORT_DIRECTION
)
359 $this->_queryParams
= CRM_Contact_BAO_Query
::convertFormValues($this->_formValues
);
361 $selector = new CRM_Activity_Selector_Search($this->_queryParams
,
368 $selector->setKey($this->controller
->_key
);
371 if ($this->_context
== 'basic' ||
$this->_context
== 'user') {
372 $prefix = $this->_prefix
;
375 $controller = new CRM_Core_Selector_Controller($selector,
376 $this->get(CRM_Utils_Pager
::PAGE_ID
),
378 CRM_Core_Action
::VIEW
,
380 CRM_Core_Selector_Controller
::SESSION
,
383 $controller->setEmbedded(TRUE);
384 $query = &$selector->getQuery();
386 if ($this->_context
== 'user') {
387 $query->setSkipPermission(TRUE);
392 function fixFormValues() {
393 if (!$this->_force
) {
397 $status = CRM_Utils_Request
::retrieve('status', 'String', $this);
399 $this->_formValues
['activity_status'] = $status;
400 $this->_defaults
['activity_status'] = $status;
403 $survey = CRM_Utils_Request
::retrieve('survey', 'Positive', CRM_Core_DAO
::$_nullObject);
406 $this->_formValues
['activity_survey_id'] = $this->_defaults
['activity_survey_id'] = $survey;
407 $sid = CRM_Utils_Array
::value('activity_survey_id', $this->_formValues
);
408 $activity_type_id = CRM_Core_DAO
::getFieldValue('CRM_Campaign_DAO_Survey', $sid, 'activity_type_id');
410 $this->_formValues
['activity_type_id'][$activity_type_id] = 1;
411 $this->_defaults
['activity_type_id'][$activity_type_id] = 1;
413 $cid = CRM_Utils_Request
::retrieve('cid', 'Positive', $this);
416 $cid = CRM_Utils_Type
::escape($cid, 'Integer');
418 $this->_formValues
['contact_id'] = $cid;
420 $activity_role = CRM_Utils_Request
::retrieve('activity_role', 'Positive', $this);
422 if ($activity_role) {
423 $this->_formValues
['activity_role'] = $activity_role;
426 $this->_defaults
['sort_name'] = CRM_Core_DAO
::getFieldValue('CRM_Contact_DAO_Contact', $cid, 'sort_name');
428 // also assign individual mode to the template
429 $this->_single
= TRUE;
433 // Added for membership search
435 $signupType = CRM_Utils_Request
::retrieve('signupType', 'Positive',
436 CRM_Core_DAO
::$_nullObject
440 //$this->_formValues['activity_type_id'] = array();
441 $this->_formValues
['activity_role'] = 1;
442 $this->_defaults
['activity_role'] = 1;
443 $activityTypes = CRM_Core_PseudoConstant
::activityType(TRUE, FALSE, FALSE, 'name');
445 $renew = CRM_Utils_Array
::key('Membership Renewal', $activityTypes);
446 $signup = CRM_Utils_Array
::key('Membership Signup', $activityTypes);
448 switch ($signupType) {
449 case 3: // signups and renewals
450 $this->_formValues
['activity_type_id'][$renew] = 1;
451 $this->_defaults
['activity_type_id'][$renew] = 1;
452 case 1: // signups only
453 $this->_formValues
['activity_type_id'][$signup] = 1;
454 $this->_defaults
['activity_type_id'][$signup] = 1;
457 case 2: // renewals only
458 $this->_formValues
['activity_type_id'][$renew] = 1;
459 $this->_defaults
['activity_type_id'][$renew] = 1;
464 $dateLow = CRM_Utils_Request
::retrieve('dateLow', 'String',
465 CRM_Core_DAO
::$_nullObject
469 $dateLow = date('m/d/Y', strtotime($dateLow));
470 $this->_formValues
['activity_date_relative'] = 0;
471 $this->_defaults
['activity_date_relative'] = 0;
472 $this->_formValues
['activity_date_low'] = $dateLow;
473 $this->_defaults
['activity_date_low'] = $dateLow;
476 $dateHigh = CRM_Utils_Request
::retrieve('dateHigh', 'String',
477 CRM_Core_DAO
::$_nullObject
481 // Activity date time assumes midnight at the beginning of the date
482 // This sets it to almost midnight at the end of the date
483 /* if ($dateHigh <= 99999999) {
484 $dateHigh = 1000000 * $dateHigh + 235959;
486 $dateHigh = date('m/d/Y', strtotime($dateHigh));
487 $this->_formValues
['activity_date_relative'] = 0;
488 $this->_defaults
['activity_date_relative'] = 0;
489 $this->_formValues
['activity_date_high'] = $dateHigh;
490 $this->_defaults
['activity_date_high'] = $dateHigh;
493 if (!empty($this->_defaults
)) {
494 $this->setDefaults($this->_defaults
);
498 function getFormValues() {
503 * Return a descriptive name for the page, used in wizard header
508 public function getTitle() {
509 return ts('Find Activities');