Merge pull request #2327 from colemanw/4.4
[civicrm-core.git] / CRM / Admin / Page / Options.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.4 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2013 |
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 and the CiviCRM Licensing Exception. |
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 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 +--------------------------------------------------------------------+
26 */
27
28 /**
29 *
30 * @package CRM
31 * @copyright CiviCRM LLC (c) 2004-2013
32 * $Id$
33 *
34 */
35
36 /**
37 * Page for displaying list of Gender
38 */
39 class CRM_Admin_Page_Options extends CRM_Core_Page_Basic {
40
41 /**
42 * The action links that we need to display for the browse screen
43 *
44 * @var array
45 * @static
46 */
47 static $_links = NULL;
48
49 /**
50 * The option group name
51 *
52 * @var array
53 * @static
54 */
55 static $_gName = NULL;
56
57 /**
58 * The option group name in display format (capitalized, without underscores...etc)
59 *
60 * @var array
61 * @static
62 */
63 static $_GName = NULL;
64
65 /**
66 * The option group id
67 *
68 * @var array
69 * @static
70 */
71 static $_gId = NULL;
72
73 /**
74 * Obtains the group name from url and sets the title.
75 *
76 * @return void
77 * @access public
78 *
79 */
80 function preProcess() {
81 if (!self::$_gName) {
82 self::$_gName = CRM_Utils_Request::retrieve('group', 'String', CRM_Core_DAO::$_nullObject, FALSE, NULL, 'GET');
83 }
84 if (self::$_gName) {
85 $this->set('gName', self::$_gName);
86 }
87 else {
88 self::$_gName = $this->get('gName');
89 }
90 if (self::$_gName) {
91 self::$_gId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionGroup', self::$_gName, 'id', 'name');
92 }
93 else {
94 CRM_Core_Error::fatal();
95 }
96
97 self::$_GName = ucwords(str_replace('_', ' ', self::$_gName));
98
99 $this->assign('gName', self::$_gName);
100 $this->assign('GName', self::$_GName);
101
102 if (self::$_gName == 'acl_role') {
103 CRM_Utils_System::setTitle(ts('Manage ACL Roles'));
104 // set breadcrumb to append to admin/access
105 $breadCrumb = array(array('title' => ts('Access Control'),
106 'url' => CRM_Utils_System::url('civicrm/admin/access',
107 'reset=1'
108 ),
109 ));
110 CRM_Utils_System::appendBreadCrumb($breadCrumb);
111 }
112 else {
113 CRM_Utils_System::setTitle(ts("%1 Options", array(1 => self::$_GName)));
114 }
115 if (in_array(self::$_gName,
116 array(
117 'from_email_address', 'email_greeting',
118 'postal_greeting', 'addressee',
119 'case_status', 'encounter_medium',
120 'case_type', 'payment_instrument'
121 )
122 )) {
123 $this->assign('showIsDefault', TRUE);
124 }
125 if (self::$_gName == 'participant_status') {
126 $this->assign('showCounted', TRUE);
127 $this->assign('showVisibility', TRUE);
128 }
129
130 if (self::$_gName == 'participant_role') {
131 $this->assign('showCounted', TRUE);
132 }
133 $config = CRM_Core_Config::singleton();
134 if (self::$_gName == 'activity_type') {
135 $this->assign('showComponent', TRUE);
136 }
137 }
138
139 /**
140 * Get BAO Name
141 *
142 * @return string Classname of BAO.
143 */
144 function getBAOName() {
145 return 'CRM_Core_BAO_OptionValue';
146 }
147
148 /**
149 * Get action Links
150 *
151 * @return array (reference) of action links
152 */
153 function &links() {
154 if (!(self::$_links)) {
155 self::$_links = array(
156 CRM_Core_Action::UPDATE => array(
157 'name' => ts('Edit'),
158 'url' => 'civicrm/admin/options/' . self::$_gName,
159 'qs' => 'group=' . self::$_gName . '&action=update&id=%%id%%&reset=1',
160 'title' => ts('Edit %1', array(1 => self::$_gName)),
161 ),
162 CRM_Core_Action::DISABLE => array(
163 'name' => ts('Disable'),
164 'extra' => 'onclick = "enableDisable( %%id%%,\'' . 'CRM_Core_BAO_OptionValue' . '\',\'' . 'enable-disable' . '\' );"',
165 'ref' => 'disable-action',
166 'title' => ts('Disable %1', array(1 => self::$_gName)),
167 ),
168 CRM_Core_Action::ENABLE => array(
169 'name' => ts('Enable'),
170 'extra' => 'onclick = "enableDisable( %%id%%,\'' . 'CRM_Core_BAO_OptionValue' . '\',\'' . 'disable-enable' . '\' );"',
171 'ref' => 'enable-action',
172 'title' => ts('Enable %1', array(1 => self::$_gName)),
173 ),
174 CRM_Core_Action::DELETE => array(
175 'name' => ts('Delete'),
176 'url' => 'civicrm/admin/options/' . self::$_gName,
177 'qs' => 'group=' . self::$_gName . '&action=delete&id=%%id%%',
178 'title' => ts('Delete %1 Type', array(1 => self::$_gName)),
179 ),
180 );
181
182 if (self::$_gName == 'custom_search') {
183 $runLink = array(
184 CRM_Core_Action::FOLLOWUP => array(
185 'name' => ts('Run'),
186 'url' => 'civicrm/contact/search/custom',
187 'qs' => 'reset=1&csid=%%value%%',
188 'title' => ts('Run %1', array(1 => self::$_gName)),
189 ));
190 self::$_links = $runLink + self::$_links;
191 }
192 }
193 return self::$_links;
194 }
195
196 /**
197 * Run the basic page (run essentially starts execution for that page).
198 *
199 * @return void
200 */
201 function run() {
202 $this->preProcess();
203 return parent::run();
204 }
205
206 /**
207 * Browse all options
208 *
209 *
210 * @return void
211 * @access public
212 * @static
213 */
214 function browse() {
215
216 $groupParams = array('name' => self::$_gName);
217 $optionValue = CRM_Core_OptionValue::getRows($groupParams, $this->links(), 'component_id,weight');
218 $gName = self::$_gName;
219 $returnURL = CRM_Utils_System::url("civicrm/admin/options/$gName",
220 "reset=1&group=$gName"
221 );
222 $filter = "option_group_id = " . self::$_gId;
223 CRM_Utils_Weight::addOrder($optionValue, 'CRM_Core_DAO_OptionValue',
224 'id', $returnURL, $filter
225 );
226
227 // retrieve financial account name for the payment instrument page
228 if ($gName = "payment_instrument") {
229 foreach ($optionValue as $key => $option) {
230 $optionValue[$key]['financial_account'] = CRM_Financial_BAO_FinancialTypeAccount::getFinancialAccount($key, 'civicrm_option_value'); }
231 }
232
233 $this->assign('rows', $optionValue);
234 }
235
236 /**
237 * Get name of edit form
238 *
239 * @return string Classname of edit form.
240 */
241 function editForm() {
242 return 'CRM_Admin_Form_Options';
243 }
244
245 /**
246 * Get edit form name
247 *
248 * @return string name of this page.
249 */
250 function editName() {
251 return self::$_GName;
252 }
253
254 /**
255 * Get user context.
256 *
257 * @return string user context.
258 */
259 function userContext($mode = NULL) {
260 return 'civicrm/admin/options/' . self::$_gName;
261 }
262
263 /**
264 * function to get userContext params
265 *
266 * @param int $mode mode that we are in
267 *
268 * @return string
269 * @access public
270 */
271 function userContextParams($mode = NULL) {
272 return 'group=' . self::$_gName . '&reset=1&action=browse';
273 }
274 }
275