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