3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.3 |
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 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-2013
41 * This file is for civigrant search
43 class CRM_Grant_Form_Search
extends CRM_Core_Form
{
46 * Are we forced to run a search
54 * name of search button
59 protected $_searchButtonName;
62 * name of print button
67 protected $_printButtonName;
70 * name of action button
75 protected $_actionButtonName;
78 * form values that we will be using
83 protected $_formValues;
86 * the params that are sent to the query
91 protected $_queryParams;
94 * have we already done this search
102 * are we restricting ourselves to a single contact
107 protected $_single = FALSE;
110 * are we restricting ourselves to a single contact
115 protected $_limit = NULL;
118 * what context are we being invoked from
123 protected $_context = NULL;
126 * prefix for the controller
129 protected $_prefix = "grant_";
131 protected $_defaults;
134 * processing needed for buildForm and later
138 */ function preProcess() {
141 * set the button names
144 $this->_searchButtonName
= $this->getButtonName('refresh');
145 $this->_printButtonName
= $this->getButtonName('next', 'print');
146 $this->_actionButtonName
= $this->getButtonName('next', 'action');
148 $this->_done
= FALSE;
149 $this->defaults
= array();
152 * we allow the controller to set force/reset externally, useful when we are being
153 * driven by the wizard framework
156 $this->_reset
= CRM_Utils_Request
::retrieve('reset', 'Boolean', CRM_Core_DAO
::$_nullObject);
157 $this->_force
= CRM_Utils_Request
::retrieve('force', 'Boolean', $this, FALSE);
158 $this->_limit
= CRM_Utils_Request
::retrieve('limit', 'Positive', $this);
159 $this->_context
= CRM_Utils_Request
::retrieve('context', 'String', $this, FALSE, 'search');
161 $this->assign("context", $this->_context
);
163 // get user submitted values
164 // get it from controller only if form has been submitted, else preProcess has set this
165 if (!empty($_POST)) {
166 $this->_formValues
= $this->controller
->exportValues($this->_name
);
169 $this->_formValues
= $this->get('formValues');
172 if (empty($this->_formValues
)) {
173 if (isset($this->_ssID
)) {
174 $this->_formValues
= CRM_Contact_BAO_SavedSearch
::getFormValues($this->_ssID
);
179 $this->postProcess();
180 $this->set('force', 0);
184 if ($this->get(CRM_Utils_Sort
::SORT_ID
)) {
185 $sortID = CRM_Utils_Sort
::sortIDValue($this->get(CRM_Utils_Sort
::SORT_ID
),
186 $this->get(CRM_Utils_Sort
::SORT_DIRECTION
)
190 $this->_queryParams
= CRM_Contact_BAO_Query
::convertFormValues($this->_formValues
);
191 $selector = new CRM_Grant_Selector_Search($this->_queryParams
,
199 if ($this->_context
== 'user') {
200 $prefix = $this->_prefix
;
203 $this->assign("{$prefix}limit", $this->_limit
);
204 $this->assign("{$prefix}single", $this->_single
);
206 $controller = new CRM_Core_Selector_Controller($selector,
207 $this->get(CRM_Utils_Pager
::PAGE_ID
),
209 CRM_Core_Action
::VIEW
,
211 CRM_Core_Selector_Controller
::TRANSFER
,
214 $controller->setEmbedded(TRUE);
215 $controller->moveFromSessionToTemplate();
217 $this->assign('summary', $this->get('summary'));
227 function buildQuickForm() {
228 $this->addElement('text', 'sort_name', ts('Name or Email'), CRM_Core_DAO
::getAttribute('CRM_Contact_DAO_Contact', 'sort_name'));
230 CRM_Grant_BAO_Query
::buildSearchForm($this);
233 * add form checkboxes for each row. This is needed out here to conform to QF protocol
234 * of all elements being declared in builQuickForm
238 $rows = $this->get('rows');
239 if (is_array($rows)) {
240 if (!$this->_single
) {
241 $this->addElement('checkbox', 'toggleSelect', NULL, NULL, array('onchange' => "toggleTaskAction( true ); return toggleCheckboxVals('mark_x_',this);"));
242 foreach ($rows as $row) {
243 $this->addElement('checkbox', CRM_Utils_Array
::value('checkbox', $row),
245 array('onclick' => " toggleTaskAction( true ); return checkSelectedBox('" . CRM_Utils_Array
::value('checkbox', $row) . "');")
247 $grant_id = $row['grant_id'];
251 $total = $cancel = 0;
253 $permission = CRM_Core_Permission
::getPermission();
255 $tasks = array('' => ts('- actions -'));
256 $permissionedTask = CRM_Grant_Task
::permissionedTaskTitles($permission);
257 if (is_array($permissionedTask) && !CRM_Utils_System
::isNull($permissionedTask)) {
258 $tasks +
= $permissionedTask;
261 $this->add('select', 'task', ts('Actions:') . ' ', $tasks);
262 $this->add('submit', $this->_actionButtonName
, ts('Go'),
264 'class' => 'form-submit',
265 'onclick' => "return checkPerformAction('mark_x', '" . $this->getName() . "', 0);",
269 $this->add('submit', $this->_printButtonName
, ts('Print'),
271 'class' => 'form-submit',
272 'onclick' => "return checkPerformAction('mark_x', '" . $this->getName() . "', 1);",
276 // need to perform tasks on all or selected items ? using radio_ts(task selection) for it
277 $this->addElement('radio', 'radio_ts', NULL, '', 'ts_sel', array('checked' => 'checked'));
278 $this->addElement('radio', 'radio_ts', NULL, '', 'ts_all', array('onchange' => $this->getName() . ".toggleSelect.checked = false; toggleCheckboxVals('mark_x_',this); toggleTaskAction( true );"));
282 $this->addButtons(array(
285 'name' => ts('Search'),
292 * The post processing of the form gets done here.
294 * Key things done during post processing are
295 * - check for reset or next request. if present, skip post procesing.
296 * - now check if user requested running a saved search, if so, then
297 * the form values associated with the saved search are used for searching.
298 * - if user has done a submit with new values the regular post submissing is
300 * The processing consists of using a Selector / Controller framework for getting the
308 function postProcess() {
315 $this->_formValues
= $this->controller
->exportValues($this->_name
);
316 $this->fixFormValues();
318 if (isset($this->_ssID
) && empty($_POST)) {
319 // if we are editing / running a saved search and the form has not been posted
320 $this->_formValues
= CRM_Contact_BAO_SavedSearch
::getFormValues($this->_ssID
);
323 $this->_queryParams
= CRM_Contact_BAO_Query
::convertFormValues($this->_formValues
);
325 $this->set('formValues', $this->_formValues
);
326 $this->set('queryParams', $this->_queryParams
);
328 $buttonName = $this->controller
->getButtonName();
329 if ($buttonName == $this->_actionButtonName ||
$buttonName == $this->_printButtonName
) {
330 // check actionName and if next, then do not repeat a search, since we are going to the next page
332 // hack, make sure we reset the task values
333 $stateMachine = &$this->controller
->getStateMachine();
334 $formName = $stateMachine->getTaskFormName();
335 $this->controller
->resetPage($formName);
340 if ($this->get(CRM_Utils_Sort
::SORT_ID
)) {
341 $sortID = CRM_Utils_Sort
::sortIDValue($this->get(CRM_Utils_Sort
::SORT_ID
),
342 $this->get(CRM_Utils_Sort
::SORT_DIRECTION
)
347 $selector = new CRM_Grant_Selector_Search($this->_queryParams
,
354 $selector->setKey($this->controller
->_key
);
357 if ($this->_context
== 'basic' ||
$this->_context
== 'user') {
358 $prefix = $this->_prefix
;
361 $controller = new CRM_Core_Selector_Controller($selector,
362 $this->get(CRM_Utils_Pager
::PAGE_ID
),
364 CRM_Core_Action
::VIEW
,
366 CRM_Core_Selector_Controller
::SESSION
,
369 $controller->setEmbedded(TRUE);
371 $query = &$selector->getQuery();
372 if ($this->_context
== 'user') {
373 $query->setSkipPermission(TRUE);
379 * Set the default form values
383 * @return array the default array reference
385 function &setDefaultValues() {
386 return $this->_formValues
;
389 function fixFormValues() {
390 // if this search has been forced
391 // then see if there are any get values, and if so over-ride the post values
392 // note that this means that GET over-rides POST :)
394 if (!$this->_force
) {
398 $status = CRM_Utils_Request
::retrieve('status', 'String',
399 CRM_Core_DAO
::$_nullObject
402 $this->_formValues
['grant_status_id'] = $status;
403 $this->_defaults
['grant_status_id'] = $status;
406 $cid = CRM_Utils_Request
::retrieve('cid', 'Positive', $this);
409 $cid = CRM_Utils_Type
::escape($cid, 'Integer');
411 $this->_formValues
['contact_id'] = $cid;
413 // also assign individual mode to the template
414 $this->_single
= TRUE;
419 function getFormValues() {
424 * Return a descriptive name for the page, used in wizard header
429 public function getTitle() {
430 return ts('Find Grants');