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 action button
66 protected $_actionButtonName;
69 * form values that we will be using
77 * the params that are sent to the query
82 protected $_queryParams;
85 * have we already done this search
93 * are we restricting ourselves to a single contact
98 protected $_single = FALSE;
101 * are we restricting ourselves to a single contact
106 protected $_limit = NULL;
109 * what context are we being invoked from
114 protected $_context = NULL;
117 * prefix for the controller
120 protected $_prefix = "activity_";
122 protected $_defaults;
125 * the saved search ID retrieved from the GET vars
133 * processing needed for buildForm and later
138 function preProcess() {
139 $this->set('searchFormName', 'Search');
142 * set the button names
144 $this->_searchButtonName
= $this->getButtonName('refresh');
145 $this->_actionButtonName
= $this->getButtonName('next', 'action');
147 $this->_done
= FALSE;
148 $this->defaults
= array();
151 * we allow the controller to set force/reset externally, useful when we are being
152 * driven by the wizard framework
154 $this->_reset
= CRM_Utils_Request
::retrieve('reset', 'Boolean', CRM_Core_DAO
::$_nullObject);
155 $this->_force
= CRM_Utils_Request
::retrieve('force', 'Boolean', $this, FALSE);
156 $this->_limit
= CRM_Utils_Request
::retrieve('limit', 'Positive', $this);
157 $this->_context
= CRM_Utils_Request
::retrieve('context', 'String', $this, FALSE, 'search');
159 $this->assign("context", $this->_context
);
161 // get user submitted values
162 // get it from controller only if form has been submitted, else preProcess has set this
163 if (!empty($_POST) && !$this->controller
->isModal()) {
164 $this->_formValues
= $this->controller
->exportValues($this->_name
);
167 $this->_formValues
= $this->get('formValues');
170 if (empty($this->_formValues
)) {
171 if (isset($this->_ssID
)) {
172 $this->_formValues
= CRM_Contact_BAO_SavedSearch
::getFormValues($this->_ssID
);
177 $this->postProcess();
178 $this->set('force', 0);
182 if ($this->get(CRM_Utils_Sort
::SORT_ID
)) {
183 $sortID = CRM_Utils_Sort
::sortIDValue($this->get(CRM_Utils_Sort
::SORT_ID
),
184 $this->get(CRM_Utils_Sort
::SORT_DIRECTION
)
188 $this->_queryParams
= CRM_Contact_BAO_Query
::convertFormValues($this->_formValues
);
189 $selector = new CRM_Activity_Selector_Search($this->_queryParams
,
197 if ($this->_context
== 'user') {
198 $prefix = $this->_prefix
;
201 $this->assign("{$prefix}limit", $this->_limit
);
202 $this->assign("{$prefix}single", $this->_single
);
204 $controller = new CRM_Core_Selector_Controller($selector,
205 $this->get(CRM_Utils_Pager
::PAGE_ID
),
207 CRM_Core_Action
::VIEW
,
209 CRM_Core_Selector_Controller
::TRANSFER
,
212 $controller->setEmbedded(TRUE);
213 $controller->moveFromSessionToTemplate();
215 $this->assign('summary', $this->get('summary'));
225 function buildQuickForm() {
226 $this->addElement('text', 'sort_name', ts('Name or Email'), CRM_Core_DAO
::getAttribute('CRM_Contact_DAO_Contact', 'sort_name'));
228 CRM_Activity_BAO_Query
::buildSearchForm($this);
231 * add form checkboxes for each row. This is needed out here to conform to QF protocol
232 * of all elements being declared in builQuickForm
235 $rows = $this->get('rows');
236 if (is_array($rows)) {
237 CRM_Core_Resources
::singleton()->addScriptFile('civicrm', 'js/crm.searchForm.js');
238 if (!$this->_single
) {
239 $this->addElement('checkbox', 'toggleSelect', NULL, NULL,
240 array('onclick' => "toggleTaskAction( true );", 'class' => 'select-rows')
242 foreach ($rows as $row) {
243 $this->addElement('checkbox', $row['checkbox'],
245 array('onclick' => "toggleTaskAction( true );", 'class' => 'select-row')
250 $permission = CRM_Core_Permission
::getPermission();
252 $tasks = array('' => ts('- actions -')) + CRM_Activity_Task
::permissionedTaskTitles($permission);
254 $this->add('select', 'task', ts('Actions:') . ' ', $tasks);
255 $this->add('submit', $this->_actionButtonName
, ts('Go'),
257 'class' => 'form-submit',
259 'onclick' => "return checkPerformAction('mark_x', '" . $this->getName() . "', 0);",
263 // need to perform tasks on all or selected items ? using radio_ts(task selection) for it
264 $this->addElement('radio', 'radio_ts', NULL, '', 'ts_sel', array('checked' => 'checked'));
265 $this->addElement('radio', 'radio_ts', NULL, '', 'ts_all',
266 array('class' => 'select-rows', 'onchange' => $this->getName() . ".toggleSelect.checked = false; toggleTaskAction( true );")
271 $this->addButtons(array(
274 'name' => ts('Search'),
281 * The post processing of the form gets done here.
283 * Key things done during post processing are
284 * - check for reset or next request. if present, skip post procesing.
285 * - now check if user requested running a saved search, if so, then
286 * the form values associated with the saved search are used for searching.
287 * - if user has done a submit with new values the regular post submissing is
289 * The processing consists of using a Selector / Controller framework for getting the
297 function postProcess() {
304 if (!empty($_POST)) {
305 $this->_formValues
= $this->controller
->exportValues($this->_name
);
308 $this->fixFormValues();
310 if (isset($this->_ssID
) && empty($_POST)) {
311 // if we are editing / running a saved search and the form has not been posted
312 $this->_formValues
= CRM_Contact_BAO_SavedSearch
::getFormValues($this->_ssID
);
315 // We don't show test records in summaries or dashboards
316 if (empty($this->_formValues
['activity_test']) && $this->_force
) {
317 $this->_formValues
["activity_test"] = 0;
320 CRM_Core_BAO_CustomValue
::fixFieldValueOfTypeMemo($this->_formValues
);
322 $this->_queryParams
= CRM_Contact_BAO_Query
::convertFormValues($this->_formValues
);
324 $this->set('formValues', $this->_formValues
);
325 $this->set('queryParams', $this->_queryParams
);
327 $buttonName = $this->controller
->getButtonName();
328 if ($buttonName == $this->_actionButtonName
) {
329 // check actionName and if next, then do not repeat a search, since we are going to the next page
330 // hack, make sure we reset the task values
331 $stateMachine = $this->controller
->getStateMachine();
332 $formName = $stateMachine->getTaskFormName();
333 $this->controller
->resetPage($formName);
338 if ($this->get(CRM_Utils_Sort
::SORT_ID
)) {
339 $sortID = CRM_Utils_Sort
::sortIDValue($this->get(CRM_Utils_Sort
::SORT_ID
),
340 $this->get(CRM_Utils_Sort
::SORT_DIRECTION
)
344 $this->_queryParams
= CRM_Contact_BAO_Query
::convertFormValues($this->_formValues
);
346 $selector = new CRM_Activity_Selector_Search($this->_queryParams
,
353 $selector->setKey($this->controller
->_key
);
356 if ($this->_context
== 'basic' ||
$this->_context
== 'user') {
357 $prefix = $this->_prefix
;
360 $controller = new CRM_Core_Selector_Controller($selector,
361 $this->get(CRM_Utils_Pager
::PAGE_ID
),
363 CRM_Core_Action
::VIEW
,
365 CRM_Core_Selector_Controller
::SESSION
,
368 $controller->setEmbedded(TRUE);
369 $query = &$selector->getQuery();
371 if ($this->_context
== 'user') {
372 $query->setSkipPermission(TRUE);
377 function fixFormValues() {
378 if (!$this->_force
) {
382 $status = CRM_Utils_Request
::retrieve('status', 'String', $this);
384 $this->_formValues
['activity_status'] = $status;
385 $this->_defaults
['activity_status'] = $status;
388 $survey = CRM_Utils_Request
::retrieve('survey', 'Positive', CRM_Core_DAO
::$_nullObject);
391 $this->_formValues
['activity_survey_id'] = $this->_defaults
['activity_survey_id'] = $survey;
392 $sid = CRM_Utils_Array
::value('activity_survey_id', $this->_formValues
);
393 $activity_type_id = CRM_Core_DAO
::getFieldValue('CRM_Campaign_DAO_Survey', $sid, 'activity_type_id');
395 $this->_formValues
['activity_type_id'][$activity_type_id] = 1;
396 $this->_defaults
['activity_type_id'][$activity_type_id] = 1;
398 $cid = CRM_Utils_Request
::retrieve('cid', 'Positive', $this);
401 $cid = CRM_Utils_Type
::escape($cid, 'Integer');
403 $this->_formValues
['contact_id'] = $cid;
405 $activity_role = CRM_Utils_Request
::retrieve('activity_role', 'Positive', $this);
407 if ($activity_role) {
408 $this->_formValues
['activity_role'] = $activity_role;
411 $this->_defaults
['sort_name'] = CRM_Core_DAO
::getFieldValue('CRM_Contact_DAO_Contact', $cid, 'sort_name');
413 // also assign individual mode to the template
414 $this->_single
= TRUE;
418 // Added for membership search
420 $signupType = CRM_Utils_Request
::retrieve('signupType', 'Positive',
421 CRM_Core_DAO
::$_nullObject
425 //$this->_formValues['activity_type_id'] = array();
426 $this->_formValues
['activity_role'] = 1;
427 $this->_defaults
['activity_role'] = 1;
428 $activityTypes = CRM_Core_PseudoConstant
::activityType(TRUE, FALSE, FALSE, 'name');
430 $renew = CRM_Utils_Array
::key('Membership Renewal', $activityTypes);
431 $signup = CRM_Utils_Array
::key('Membership Signup', $activityTypes);
433 switch ($signupType) {
434 case 3: // signups and renewals
435 $this->_formValues
['activity_type_id'][$renew] = 1;
436 $this->_defaults
['activity_type_id'][$renew] = 1;
437 case 1: // signups only
438 $this->_formValues
['activity_type_id'][$signup] = 1;
439 $this->_defaults
['activity_type_id'][$signup] = 1;
442 case 2: // renewals only
443 $this->_formValues
['activity_type_id'][$renew] = 1;
444 $this->_defaults
['activity_type_id'][$renew] = 1;
449 $dateLow = CRM_Utils_Request
::retrieve('dateLow', 'String',
450 CRM_Core_DAO
::$_nullObject
454 $dateLow = date('m/d/Y', strtotime($dateLow));
455 $this->_formValues
['activity_date_relative'] = 0;
456 $this->_defaults
['activity_date_relative'] = 0;
457 $this->_formValues
['activity_date_low'] = $dateLow;
458 $this->_defaults
['activity_date_low'] = $dateLow;
461 $dateHigh = CRM_Utils_Request
::retrieve('dateHigh', 'String',
462 CRM_Core_DAO
::$_nullObject
466 // Activity date time assumes midnight at the beginning of the date
467 // This sets it to almost midnight at the end of the date
468 /* if ($dateHigh <= 99999999) {
469 $dateHigh = 1000000 * $dateHigh + 235959;
471 $dateHigh = date('m/d/Y', strtotime($dateHigh));
472 $this->_formValues
['activity_date_relative'] = 0;
473 $this->_defaults
['activity_date_relative'] = 0;
474 $this->_formValues
['activity_date_high'] = $dateHigh;
475 $this->_defaults
['activity_date_high'] = $dateHigh;
478 if (!empty($this->_defaults
)) {
479 $this->setDefaults($this->_defaults
);
483 function getFormValues() {
488 * Return a descriptive name for the page, used in wizard header
493 public function getTitle() {
494 return ts('Find Activities');