CRM-16425 Added CiviCRM Licensing Exception in header
[civicrm-core.git] / CRM / Core / Form / Search.php
CommitLineData
3efb5b86
CW
1<?php
2/*
3 +--------------------------------------------------------------------+
39de6fd5 4 | CiviCRM version 4.6 |
3efb5b86 5 +--------------------------------------------------------------------+
e7112fa7 6 | Copyright CiviCRM LLC (c) 2004-2015 |
3efb5b86
CW
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
9 | |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
c73475ea 12 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
3efb5b86
CW
13 | |
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. |
18 | |
19 | You should have received a copy of the GNU Affero General Public |
c73475ea
WA
20 | License and the CiviCRM Licensing Exception along |
21 | with this program; if not, contact CiviCRM LLC |
3efb5b86
CW
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 +--------------------------------------------------------------------+
d25dd0ee 26 */
3efb5b86
CW
27
28/**
29 * Base class for most search forms
30 */
31class CRM_Core_Form_Search extends CRM_Core_Form {
32
48473171
CW
33 /**
34 * Are we forced to run a search
35 *
36 * @var int
48473171
CW
37 */
38 protected $_force;
39
40 /**
100fef9d 41 * Name of search button
48473171
CW
42 *
43 * @var string
48473171
CW
44 */
45 protected $_searchButtonName;
46
47 /**
100fef9d 48 * Name of action button
48473171
CW
49 *
50 * @var string
48473171
CW
51 */
52 protected $_actionButtonName;
53
54 /**
100fef9d 55 * Form values that we will be using
48473171
CW
56 *
57 * @var array
48473171
CW
58 */
59 public $_formValues;
60
61 /**
100fef9d 62 * Have we already done this search
48473171 63 *
48473171
CW
64 * @var boolean
65 */
66 protected $_done;
67
68 /**
100fef9d 69 * What context are we being invoked from
48473171 70 *
48473171
CW
71 * @var string
72 */
73 protected $_context = NULL;
74
7a3978aa
FG
75 /**
76 * The list of tasks or actions that a searcher can perform on a result set.
77 *
78 * @var array
79 */
80 protected $_taskList = array();
81
82 /**
83 * Builds the list of tasks or actions that a searcher can perform on a result set.
84 *
85 * To modify the task list, child classes should alter $this->_taskList,
86 * preferably by extending this method.
87 *
88 * @return array
89 */
90 protected function buildTaskList() {
91 return $this->_taskList;
92 }
93
34197a55
CW
94 /**
95 * Common buildform tasks required by all searches
96 */
00be9182 97 public function buildQuickform() {
3efb5b86
CW
98 $resources = CRM_Core_Resources::singleton();
99
100 if ($resources->ajaxPopupsEnabled) {
3efb5b86
CW
101 // Script needed by some popups
102 $this->assign('includeWysiwygEditor', TRUE);
103 }
104
562fda4b
CW
105 $resources
106 ->addScriptFile('civicrm', 'js/crm.searchForm.js', 1, 'html-header')
107 ->addStyleFile('civicrm', 'css/searchForm.css', 1, 'html-header');
3efb5b86
CW
108
109 $this->addButtons(array(
110 array(
111 'type' => 'refresh',
112 'name' => ts('Search'),
113 'isDefault' => TRUE,
114 ),
115 ));
8d36b801 116
023e90c3 117 $this->addClass('crm-search-form');
7a3978aa
FG
118
119 // for backwards compatibility we pass an argument to addTaskMenu even though
120 // it could just as well access $this->_taskList internally
121 $tasks = $this->buildTaskList();
122 $this->addTaskMenu($tasks);
8d36b801
CW
123 }
124
125 /**
126 * Add checkboxes for each row plus a master checkbox
127 */
00be9182 128 public function addRowSelectors($rows) {
8d36b801
CW
129 $this->addElement('checkbox', 'toggleSelect', NULL, NULL, array('class' => 'select-rows'));
130 foreach ($rows as $row) {
131 $this->addElement('checkbox', $row['checkbox'], NULL, NULL, array('class' => 'select-row'));
132 }
3efb5b86 133 }
34197a55
CW
134
135 /**
136 * Add actions menu to search results form
137 * @param $tasks
138 */
00be9182 139 public function addTaskMenu($tasks) {
34197a55
CW
140 if (is_array($tasks) && !empty($tasks)) {
141 $tasks = array('' => ts('Actions')) + $tasks;
142 $this->add('select', 'task', NULL, $tasks, FALSE, array('class' => 'crm-select2 crm-action-menu huge crm-search-result-actions'));
143 $this->add('submit', $this->_actionButtonName, ts('Go'), array('class' => 'hiddenElement crm-search-go-button'));
8d36b801
CW
144
145 // Radio to choose "All items" or "Selected items only"
146 $selectedRowsRadio = $this->addElement('radio', 'radio_ts', NULL, '', 'ts_sel', array('checked' => 'checked'));
147 $allRowsRadio = $this->addElement('radio', 'radio_ts', NULL, '', 'ts_all');
148 $this->assign('ts_sel_id', $selectedRowsRadio->_attributes['id']);
149 $this->assign('ts_all_id', $allRowsRadio->_attributes['id']);
34197a55
CW
150 }
151 }
96025800 152
3efb5b86 153}