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. |
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-2014
40 * This file is for activity search
42 class CRM_Activity_Form_Search
extends CRM_Core_Form_Search
{
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 parent
::buildQuickForm();
227 $this->addElement('text', 'sort_name', ts('Name or Email'), CRM_Core_DAO
::getAttribute('CRM_Contact_DAO_Contact', 'sort_name'));
229 CRM_Activity_BAO_Query
::buildSearchForm($this);
232 * add form checkboxes for each row. This is needed out here to conform to QF protocol
233 * of all elements being declared in builQuickForm
236 $rows = $this->get('rows');
237 if (is_array($rows)) {
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 );")
273 * The post processing of the form gets done here.
275 * Key things done during post processing are
276 * - check for reset or next request. if present, skip post procesing.
277 * - now check if user requested running a saved search, if so, then
278 * the form values associated with the saved search are used for searching.
279 * - if user has done a submit with new values the regular post submissing is
281 * The processing consists of using a Selector / Controller framework for getting the
289 function postProcess() {
296 if (!empty($_POST)) {
297 $this->_formValues
= $this->controller
->exportValues($this->_name
);
300 $this->fixFormValues();
302 if (isset($this->_ssID
) && empty($_POST)) {
303 // if we are editing / running a saved search and the form has not been posted
304 $this->_formValues
= CRM_Contact_BAO_SavedSearch
::getFormValues($this->_ssID
);
307 // We don't show test records in summaries or dashboards
308 if (empty($this->_formValues
['activity_test']) && $this->_force
) {
309 $this->_formValues
["activity_test"] = 0;
312 CRM_Core_BAO_CustomValue
::fixFieldValueOfTypeMemo($this->_formValues
);
314 $this->_queryParams
= CRM_Contact_BAO_Query
::convertFormValues($this->_formValues
);
316 $this->set('formValues', $this->_formValues
);
317 $this->set('queryParams', $this->_queryParams
);
319 $buttonName = $this->controller
->getButtonName();
320 if ($buttonName == $this->_actionButtonName
) {
321 // check actionName and if next, then do not repeat a search, since we are going to the next page
322 // hack, make sure we reset the task values
323 $stateMachine = $this->controller
->getStateMachine();
324 $formName = $stateMachine->getTaskFormName();
325 $this->controller
->resetPage($formName);
330 if ($this->get(CRM_Utils_Sort
::SORT_ID
)) {
331 $sortID = CRM_Utils_Sort
::sortIDValue($this->get(CRM_Utils_Sort
::SORT_ID
),
332 $this->get(CRM_Utils_Sort
::SORT_DIRECTION
)
336 $this->_queryParams
= CRM_Contact_BAO_Query
::convertFormValues($this->_formValues
);
338 $selector = new CRM_Activity_Selector_Search($this->_queryParams
,
345 $selector->setKey($this->controller
->_key
);
348 if ($this->_context
== 'basic' ||
$this->_context
== 'user') {
349 $prefix = $this->_prefix
;
352 $controller = new CRM_Core_Selector_Controller($selector,
353 $this->get(CRM_Utils_Pager
::PAGE_ID
),
355 CRM_Core_Action
::VIEW
,
357 CRM_Core_Selector_Controller
::SESSION
,
360 $controller->setEmbedded(TRUE);
361 $query = &$selector->getQuery();
363 if ($this->_context
== 'user') {
364 $query->setSkipPermission(TRUE);
369 function fixFormValues() {
370 if (!$this->_force
) {
374 $status = CRM_Utils_Request
::retrieve('status', 'String', $this);
376 $this->_formValues
['activity_status'] = $status;
377 $this->_defaults
['activity_status'] = $status;
380 $survey = CRM_Utils_Request
::retrieve('survey', 'Positive', CRM_Core_DAO
::$_nullObject);
383 $this->_formValues
['activity_survey_id'] = $this->_defaults
['activity_survey_id'] = $survey;
384 $sid = CRM_Utils_Array
::value('activity_survey_id', $this->_formValues
);
385 $activity_type_id = CRM_Core_DAO
::getFieldValue('CRM_Campaign_DAO_Survey', $sid, 'activity_type_id');
387 $this->_formValues
['activity_type_id'][$activity_type_id] = 1;
388 $this->_defaults
['activity_type_id'][$activity_type_id] = 1;
390 $cid = CRM_Utils_Request
::retrieve('cid', 'Positive', $this);
393 $cid = CRM_Utils_Type
::escape($cid, 'Integer');
395 $this->_formValues
['contact_id'] = $cid;
397 $activity_role = CRM_Utils_Request
::retrieve('activity_role', 'Positive', $this);
399 if ($activity_role) {
400 $this->_formValues
['activity_role'] = $activity_role;
403 $this->_defaults
['sort_name'] = CRM_Core_DAO
::getFieldValue('CRM_Contact_DAO_Contact', $cid, 'sort_name');
405 // also assign individual mode to the template
406 $this->_single
= TRUE;
410 // Added for membership search
412 $signupType = CRM_Utils_Request
::retrieve('signupType', 'Positive',
413 CRM_Core_DAO
::$_nullObject
417 //$this->_formValues['activity_type_id'] = array();
418 $this->_formValues
['activity_role'] = 1;
419 $this->_defaults
['activity_role'] = 1;
420 $activityTypes = CRM_Core_PseudoConstant
::activityType(TRUE, FALSE, FALSE, 'name');
422 $renew = CRM_Utils_Array
::key('Membership Renewal', $activityTypes);
423 $signup = CRM_Utils_Array
::key('Membership Signup', $activityTypes);
425 switch ($signupType) {
426 case 3: // signups and renewals
427 $this->_formValues
['activity_type_id'][$renew] = 1;
428 $this->_defaults
['activity_type_id'][$renew] = 1;
429 case 1: // signups only
430 $this->_formValues
['activity_type_id'][$signup] = 1;
431 $this->_defaults
['activity_type_id'][$signup] = 1;
434 case 2: // renewals only
435 $this->_formValues
['activity_type_id'][$renew] = 1;
436 $this->_defaults
['activity_type_id'][$renew] = 1;
441 $dateLow = CRM_Utils_Request
::retrieve('dateLow', 'String',
442 CRM_Core_DAO
::$_nullObject
446 $dateLow = date('m/d/Y', strtotime($dateLow));
447 $this->_formValues
['activity_date_relative'] = 0;
448 $this->_defaults
['activity_date_relative'] = 0;
449 $this->_formValues
['activity_date_low'] = $dateLow;
450 $this->_defaults
['activity_date_low'] = $dateLow;
453 $dateHigh = CRM_Utils_Request
::retrieve('dateHigh', 'String',
454 CRM_Core_DAO
::$_nullObject
458 // Activity date time assumes midnight at the beginning of the date
459 // This sets it to almost midnight at the end of the date
460 /* if ($dateHigh <= 99999999) {
461 $dateHigh = 1000000 * $dateHigh + 235959;
463 $dateHigh = date('m/d/Y', strtotime($dateHigh));
464 $this->_formValues
['activity_date_relative'] = 0;
465 $this->_defaults
['activity_date_relative'] = 0;
466 $this->_formValues
['activity_date_high'] = $dateHigh;
467 $this->_defaults
['activity_date_high'] = $dateHigh;
470 if (!empty($this->_defaults
)) {
471 $this->setDefaults($this->_defaults
);
478 function getFormValues() {
483 * Return a descriptive name for the page, used in wizard header
488 public function getTitle() {
489 return ts('Find Activities');