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 CRM_Core_Resources
::singleton()->addScriptFile('civicrm', 'js/crm.livePage.js');
247 if (!$this->_single
) {
248 $this->addElement('checkbox', 'toggleSelect', NULL, NULL,
249 array('onclick' => "toggleTaskAction( true ); return toggleCheckboxVals('mark_x_',this);")
251 foreach ($rows as $row) {
252 $this->addElement('checkbox', $row['checkbox'],
254 array('onclick' => "toggleTaskAction( true ); return checkSelectedBox('" . $row['checkbox'] . "');")
259 $permission = CRM_Core_Permission
::getPermission();
261 $tasks = array('' => ts('- actions -')) + CRM_Activity_Task
::permissionedTaskTitles($permission);
263 $this->add('select', 'task', ts('Actions:') . ' ', $tasks);
264 $this->add('submit', $this->_actionButtonName
, ts('Go'),
266 'class' => 'form-submit',
268 'onclick' => "return checkPerformAction('mark_x', '" . $this->getName() . "', 0);",
272 $this->add('submit', $this->_printButtonName
, ts('Print'),
274 'class' => 'form-submit',
275 'onclick' => "return checkPerformAction('mark_x', '" . $this->getName() . "', 1);",
279 // need to perform tasks on all or selected items ? using radio_ts(task selection) for it
280 $this->addElement('radio', 'radio_ts', NULL, '', 'ts_sel', array('checked' => 'checked'));
281 $this->addElement('radio', 'radio_ts', NULL, '', 'ts_all',
282 array('onchange' => $this->getName() . ".toggleSelect.checked = false; toggleCheckboxVals('mark_x_',this); toggleTaskAction( true );")
287 $this->addButtons(array(
290 'name' => ts('Search'),
297 * The post processing of the form gets done here.
299 * Key things done during post processing are
300 * - check for reset or next request. if present, skip post procesing.
301 * - now check if user requested running a saved search, if so, then
302 * the form values associated with the saved search are used for searching.
303 * - if user has done a submit with new values the regular post submissing is
305 * The processing consists of using a Selector / Controller framework for getting the
313 function postProcess() {
320 if (!empty($_POST)) {
321 $this->_formValues
= $this->controller
->exportValues($this->_name
);
324 $this->fixFormValues();
326 if (isset($this->_ssID
) && empty($_POST)) {
327 // if we are editing / running a saved search and the form has not been posted
328 $this->_formValues
= CRM_Contact_BAO_SavedSearch
::getFormValues($this->_ssID
);
331 // We don't show test records in summaries or dashboards
332 if (empty($this->_formValues
['activity_test']) && $this->_force
) {
333 $this->_formValues
["activity_test"] = 0;
336 CRM_Core_BAO_CustomValue
::fixFieldValueOfTypeMemo($this->_formValues
);
338 $this->_queryParams
= CRM_Contact_BAO_Query
::convertFormValues($this->_formValues
);
340 $this->set('formValues', $this->_formValues
);
341 $this->set('queryParams', $this->_queryParams
);
343 $buttonName = $this->controller
->getButtonName();
344 if ($buttonName == $this->_actionButtonName ||
$buttonName == $this->_printButtonName
) {
345 // check actionName and if next, then do not repeat a search, since we are going to the next page
346 // hack, make sure we reset the task values
347 $stateMachine = $this->controller
->getStateMachine();
348 $formName = $stateMachine->getTaskFormName();
349 $this->controller
->resetPage($formName);
354 if ($this->get(CRM_Utils_Sort
::SORT_ID
)) {
355 $sortID = CRM_Utils_Sort
::sortIDValue($this->get(CRM_Utils_Sort
::SORT_ID
),
356 $this->get(CRM_Utils_Sort
::SORT_DIRECTION
)
360 $this->_queryParams
= CRM_Contact_BAO_Query
::convertFormValues($this->_formValues
);
362 $selector = new CRM_Activity_Selector_Search($this->_queryParams
,
369 $selector->setKey($this->controller
->_key
);
372 if ($this->_context
== 'basic' ||
$this->_context
== 'user') {
373 $prefix = $this->_prefix
;
376 $controller = new CRM_Core_Selector_Controller($selector,
377 $this->get(CRM_Utils_Pager
::PAGE_ID
),
379 CRM_Core_Action
::VIEW
,
381 CRM_Core_Selector_Controller
::SESSION
,
384 $controller->setEmbedded(TRUE);
385 $query = &$selector->getQuery();
387 if ($this->_context
== 'user') {
388 $query->setSkipPermission(TRUE);
393 function fixFormValues() {
394 if (!$this->_force
) {
398 $status = CRM_Utils_Request
::retrieve('status', 'String', $this);
400 $this->_formValues
['activity_status'] = $status;
401 $this->_defaults
['activity_status'] = $status;
404 $survey = CRM_Utils_Request
::retrieve('survey', 'Positive', CRM_Core_DAO
::$_nullObject);
407 $this->_formValues
['activity_survey_id'] = $this->_defaults
['activity_survey_id'] = $survey;
408 $sid = CRM_Utils_Array
::value('activity_survey_id', $this->_formValues
);
409 $activity_type_id = CRM_Core_DAO
::getFieldValue('CRM_Campaign_DAO_Survey', $sid, 'activity_type_id');
411 $this->_formValues
['activity_type_id'][$activity_type_id] = 1;
412 $this->_defaults
['activity_type_id'][$activity_type_id] = 1;
414 $cid = CRM_Utils_Request
::retrieve('cid', 'Positive', $this);
417 $cid = CRM_Utils_Type
::escape($cid, 'Integer');
419 $this->_formValues
['contact_id'] = $cid;
421 $activity_role = CRM_Utils_Request
::retrieve('activity_role', 'Positive', $this);
423 if ($activity_role) {
424 $this->_formValues
['activity_role'] = $activity_role;
427 $this->_defaults
['sort_name'] = CRM_Core_DAO
::getFieldValue('CRM_Contact_DAO_Contact', $cid, 'sort_name');
429 // also assign individual mode to the template
430 $this->_single
= TRUE;
434 // Added for membership search
436 $signupType = CRM_Utils_Request
::retrieve('signupType', 'Positive',
437 CRM_Core_DAO
::$_nullObject
441 //$this->_formValues['activity_type_id'] = array();
442 $this->_formValues
['activity_role'] = 1;
443 $this->_defaults
['activity_role'] = 1;
444 $activityTypes = CRM_Core_PseudoConstant
::activityType(TRUE, FALSE, FALSE, 'name');
446 $renew = CRM_Utils_Array
::key('Membership Renewal', $activityTypes);
447 $signup = CRM_Utils_Array
::key('Membership Signup', $activityTypes);
449 switch ($signupType) {
450 case 3: // signups and renewals
451 $this->_formValues
['activity_type_id'][$renew] = 1;
452 $this->_defaults
['activity_type_id'][$renew] = 1;
453 case 1: // signups only
454 $this->_formValues
['activity_type_id'][$signup] = 1;
455 $this->_defaults
['activity_type_id'][$signup] = 1;
458 case 2: // renewals only
459 $this->_formValues
['activity_type_id'][$renew] = 1;
460 $this->_defaults
['activity_type_id'][$renew] = 1;
465 $dateLow = CRM_Utils_Request
::retrieve('dateLow', 'String',
466 CRM_Core_DAO
::$_nullObject
470 $dateLow = date('m/d/Y', strtotime($dateLow));
471 $this->_formValues
['activity_date_relative'] = 0;
472 $this->_defaults
['activity_date_relative'] = 0;
473 $this->_formValues
['activity_date_low'] = $dateLow;
474 $this->_defaults
['activity_date_low'] = $dateLow;
477 $dateHigh = CRM_Utils_Request
::retrieve('dateHigh', 'String',
478 CRM_Core_DAO
::$_nullObject
482 // Activity date time assumes midnight at the beginning of the date
483 // This sets it to almost midnight at the end of the date
484 /* if ($dateHigh <= 99999999) {
485 $dateHigh = 1000000 * $dateHigh + 235959;
487 $dateHigh = date('m/d/Y', strtotime($dateHigh));
488 $this->_formValues
['activity_date_relative'] = 0;
489 $this->_defaults
['activity_date_relative'] = 0;
490 $this->_formValues
['activity_date_high'] = $dateHigh;
491 $this->_defaults
['activity_date_high'] = $dateHigh;
494 if (!empty($this->_defaults
)) {
495 $this->setDefaults($this->_defaults
);
499 function getFormValues() {
504 * Return a descriptive name for the page, used in wizard header
509 public function getTitle() {
510 return ts('Find Activities');