Merge remote-tracking branch 'upstream/4.5' into 4.5-master-2015-02-02-18-36-16
[civicrm-core.git] / CRM / Core / Form / Search.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.6 |
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 */
37 protected $_force;
38
39 /**
40 * Name of search button
41 *
42 * @var string
43 */
44 protected $_searchButtonName;
45
46 /**
47 * Name of action button
48 *
49 * @var string
50 */
51 protected $_actionButtonName;
52
53 /**
54 * Form values that we will be using
55 *
56 * @var array
57 */
58 public $_formValues;
59
60 /**
61 * Have we already done this search
62 *
63 * @var boolean
64 */
65 protected $_done;
66
67 /**
68 * What context are we being invoked from
69 *
70 * @var string
71 */
72 protected $_context = NULL;
73
74 /**
75 * Common buildform tasks required by all searches
76 */
77 public function buildQuickform() {
78 $resources = CRM_Core_Resources::singleton();
79
80 if ($resources->ajaxPopupsEnabled) {
81 // Script needed by some popups
82 $this->assign('includeWysiwygEditor', TRUE);
83 }
84
85 $resources->addScriptFile('civicrm', 'js/crm.searchForm.js', 1, 'html-header');
86
87 $this->addButtons(array(
88 array(
89 'type' => 'refresh',
90 'name' => ts('Search'),
91 'isDefault' => TRUE,
92 ),
93 ));
94
95 $this->addClass('crm-search-form');
96 }
97
98 /**
99 * Add checkboxes for each row plus a master checkbox
100 */
101 public function addRowSelectors($rows) {
102 $this->addElement('checkbox', 'toggleSelect', NULL, NULL, array('class' => 'select-rows'));
103 foreach ($rows as $row) {
104 $this->addElement('checkbox', $row['checkbox'], NULL, NULL, array('class' => 'select-row'));
105 }
106 }
107
108 /**
109 * Add actions menu to search results form
110 * @param $tasks
111 */
112 public function addTaskMenu($tasks) {
113 if (is_array($tasks) && !empty($tasks)) {
114 $tasks = array('' => ts('Actions')) + $tasks;
115 $this->add('select', 'task', NULL, $tasks, FALSE, array('class' => 'crm-select2 crm-action-menu huge crm-search-result-actions'));
116 $this->add('submit', $this->_actionButtonName, ts('Go'), array('class' => 'hiddenElement crm-search-go-button'));
117
118 // Radio to choose "All items" or "Selected items only"
119 $selectedRowsRadio = $this->addElement('radio', 'radio_ts', NULL, '', 'ts_sel', array('checked' => 'checked'));
120 $allRowsRadio = $this->addElement('radio', 'radio_ts', NULL, '', 'ts_all');
121 $this->assign('ts_sel_id', $selectedRowsRadio->_attributes['id']);
122 $this->assign('ts_all_id', $allRowsRadio->_attributes['id']);
123 }
124 }
125
126 }