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 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 action button
67 protected $_actionButtonName;
70 * form values that we will be using
75 protected $_formValues;
78 * the params that are sent to the query
83 protected $_queryParams;
86 * have we already done this search
94 * are we restricting ourselves to a single contact
99 protected $_single = FALSE;
102 * are we restricting ourselves to a single contact
107 protected $_limit = NULL;
110 * what context are we being invoked from
115 protected $_context = NULL;
118 * prefix for the controller
121 protected $_prefix = "grant_";
123 protected $_defaults;
126 * processing needed for buildForm and later
130 */ function preProcess() {
133 * set the button names
136 $this->_searchButtonName
= $this->getButtonName('refresh');
137 $this->_actionButtonName
= $this->getButtonName('next', 'action');
139 $this->_done
= FALSE;
140 $this->defaults
= array();
143 * we allow the controller to set force/reset externally, useful when we are being
144 * driven by the wizard framework
147 $this->_reset
= CRM_Utils_Request
::retrieve('reset', 'Boolean', CRM_Core_DAO
::$_nullObject);
148 $this->_force
= CRM_Utils_Request
::retrieve('force', 'Boolean', $this, FALSE);
149 $this->_limit
= CRM_Utils_Request
::retrieve('limit', 'Positive', $this);
150 $this->_context
= CRM_Utils_Request
::retrieve('context', 'String', $this, FALSE, 'search');
152 $this->assign("context", $this->_context
);
154 // get user submitted values
155 // get it from controller only if form has been submitted, else preProcess has set this
156 if (!empty($_POST)) {
157 $this->_formValues
= $this->controller
->exportValues($this->_name
);
160 $this->_formValues
= $this->get('formValues');
163 if (empty($this->_formValues
)) {
164 if (isset($this->_ssID
)) {
165 $this->_formValues
= CRM_Contact_BAO_SavedSearch
::getFormValues($this->_ssID
);
170 $this->postProcess();
171 $this->set('force', 0);
175 if ($this->get(CRM_Utils_Sort
::SORT_ID
)) {
176 $sortID = CRM_Utils_Sort
::sortIDValue($this->get(CRM_Utils_Sort
::SORT_ID
),
177 $this->get(CRM_Utils_Sort
::SORT_DIRECTION
)
181 $this->_queryParams
= CRM_Contact_BAO_Query
::convertFormValues($this->_formValues
);
182 $selector = new CRM_Grant_Selector_Search($this->_queryParams
,
190 if ($this->_context
== 'user') {
191 $prefix = $this->_prefix
;
194 $this->assign("{$prefix}limit", $this->_limit
);
195 $this->assign("{$prefix}single", $this->_single
);
197 $controller = new CRM_Core_Selector_Controller($selector,
198 $this->get(CRM_Utils_Pager
::PAGE_ID
),
200 CRM_Core_Action
::VIEW
,
202 CRM_Core_Selector_Controller
::TRANSFER
,
205 $controller->setEmbedded(TRUE);
206 $controller->moveFromSessionToTemplate();
208 $this->assign('summary', $this->get('summary'));
218 function buildQuickForm() {
219 $this->addElement('text', 'sort_name', ts('Name or Email'), CRM_Core_DAO
::getAttribute('CRM_Contact_DAO_Contact', 'sort_name'));
221 CRM_Grant_BAO_Query
::buildSearchForm($this);
224 * add form checkboxes for each row. This is needed out here to conform to QF protocol
225 * of all elements being declared in builQuickForm
229 $rows = $this->get('rows');
230 if (is_array($rows)) {
231 CRM_Core_Resources
::singleton()->addScriptFile('civicrm', 'js/crm.livePage.js');
232 CRM_Core_Resources
::singleton()->addScriptFile('civicrm', 'js/crm.searchForm.js');
233 if (!$this->_single
) {
234 $this->addElement('checkbox', 'toggleSelect', NULL, NULL, array('onchange' => "toggleTaskAction( true );", 'class' => 'select-rows'));
235 foreach ($rows as $row) {
236 $this->addElement('checkbox', CRM_Utils_Array
::value('checkbox', $row),
238 array('onclick' => " toggleTaskAction( true );", 'class' => 'select-row')
240 $grant_id = $row['grant_id'];
244 $total = $cancel = 0;
246 $permission = CRM_Core_Permission
::getPermission();
248 $tasks = array('' => ts('- actions -'));
249 $permissionedTask = CRM_Grant_Task
::permissionedTaskTitles($permission);
250 if (is_array($permissionedTask) && !CRM_Utils_System
::isNull($permissionedTask)) {
251 $tasks +
= $permissionedTask;
254 $this->add('select', 'task', ts('Actions:') . ' ', $tasks);
255 $this->add('submit', $this->_actionButtonName
, ts('Go'),
257 'class' => 'form-submit',
258 'onclick' => "return checkPerformAction('mark_x', '" . $this->getName() . "', 0);",
262 // need to perform tasks on all or selected items ? using radio_ts(task selection) for it
263 $this->addElement('radio', 'radio_ts', NULL, '', 'ts_sel', array('checked' => 'checked'));
264 $this->addElement('radio', 'radio_ts', NULL, '', 'ts_all', array('class' => 'select-rows', 'onchange' => $this->getName() . ".toggleSelect.checked = false; toggleTaskAction( true );"));
268 $this->addButtons(array(
271 'name' => ts('Search'),
278 * The post processing of the form gets done here.
280 * Key things done during post processing are
281 * - check for reset or next request. if present, skip post procesing.
282 * - now check if user requested running a saved search, if so, then
283 * the form values associated with the saved search are used for searching.
284 * - if user has done a submit with new values the regular post submissing is
286 * The processing consists of using a Selector / Controller framework for getting the
294 function postProcess() {
301 $this->_formValues
= $this->controller
->exportValues($this->_name
);
302 $this->fixFormValues();
304 if (isset($this->_ssID
) && empty($_POST)) {
305 // if we are editing / running a saved search and the form has not been posted
306 $this->_formValues
= CRM_Contact_BAO_SavedSearch
::getFormValues($this->_ssID
);
309 $this->_queryParams
= CRM_Contact_BAO_Query
::convertFormValues($this->_formValues
);
311 $this->set('formValues', $this->_formValues
);
312 $this->set('queryParams', $this->_queryParams
);
314 $buttonName = $this->controller
->getButtonName();
315 if ($buttonName == $this->_actionButtonName
) {
316 // check actionName and if next, then do not repeat a search, since we are going to the next page
318 // hack, make sure we reset the task values
319 $stateMachine = $this->controller
->getStateMachine();
320 $formName = $stateMachine->getTaskFormName();
321 $this->controller
->resetPage($formName);
326 if ($this->get(CRM_Utils_Sort
::SORT_ID
)) {
327 $sortID = CRM_Utils_Sort
::sortIDValue($this->get(CRM_Utils_Sort
::SORT_ID
),
328 $this->get(CRM_Utils_Sort
::SORT_DIRECTION
)
333 $selector = new CRM_Grant_Selector_Search($this->_queryParams
,
340 $selector->setKey($this->controller
->_key
);
343 if ($this->_context
== 'basic' ||
$this->_context
== 'user') {
344 $prefix = $this->_prefix
;
347 $controller = new CRM_Core_Selector_Controller($selector,
348 $this->get(CRM_Utils_Pager
::PAGE_ID
),
350 CRM_Core_Action
::VIEW
,
352 CRM_Core_Selector_Controller
::SESSION
,
355 $controller->setEmbedded(TRUE);
357 $query = &$selector->getQuery();
358 if ($this->_context
== 'user') {
359 $query->setSkipPermission(TRUE);
365 * Set the default form values
369 * @return array the default array reference
371 function &setDefaultValues() {
372 return $this->_formValues
;
375 function fixFormValues() {
376 // if this search has been forced
377 // then see if there are any get values, and if so over-ride the post values
378 // note that this means that GET over-rides POST :)
380 if (!$this->_force
) {
384 $status = CRM_Utils_Request
::retrieve('status', 'String',
385 CRM_Core_DAO
::$_nullObject
388 $this->_formValues
['grant_status_id'] = $status;
389 $this->_defaults
['grant_status_id'] = $status;
392 $cid = CRM_Utils_Request
::retrieve('cid', 'Positive', $this);
395 $cid = CRM_Utils_Type
::escape($cid, 'Integer');
397 $this->_formValues
['contact_id'] = $cid;
399 // also assign individual mode to the template
400 $this->_single
= TRUE;
405 function getFormValues() {
410 * Return a descriptive name for the page, used in wizard header
415 public function getTitle() {
416 return ts('Find Grants');