Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
39de6fd5 | 4 | | CiviCRM version 4.6 | |
6a488035 | 5 | +--------------------------------------------------------------------+ |
06b69b18 | 6 | | Copyright CiviCRM LLC (c) 2004-2014 | |
6a488035 TO |
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 | +--------------------------------------------------------------------+ | |
d25dd0ee | 26 | */ |
6a488035 TO |
27 | |
28 | /** | |
29 | * | |
30 | * @package CRM | |
06b69b18 | 31 | * @copyright CiviCRM LLC (c) 2004-2014 |
6a488035 TO |
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 | ||
96f50de2 CW |
41 | public $useLivePageJS = TRUE; |
42 | ||
6a488035 TO |
43 | /** |
44 | * The action links that we need to display for the browse screen | |
45 | * | |
46 | * @var array | |
6a488035 TO |
47 | */ |
48 | static $_links = NULL; | |
49 | ||
50 | /** | |
51 | * The option group name | |
52 | * | |
53 | * @var array | |
6a488035 TO |
54 | */ |
55 | static $_gName = NULL; | |
56 | ||
57 | /** | |
58 | * The option group name in display format (capitalized, without underscores...etc) | |
59 | * | |
60 | * @var array | |
6a488035 | 61 | */ |
6c2473d5 | 62 | static $_gLabel = NULL; |
6a488035 TO |
63 | |
64 | /** | |
65 | * The option group id | |
66 | * | |
67 | * @var array | |
6a488035 TO |
68 | */ |
69 | static $_gId = NULL; | |
70 | ||
cede6590 DG |
71 | /** |
72 | * A boolean determining if you can add options to this group in the GUI | |
73 | * | |
74 | * @var boolean | |
cede6590 DG |
75 | */ |
76 | static $_isLocked = FALSE; | |
77 | ||
6a488035 | 78 | /** |
6c2473d5 CW |
79 | * Obtains the group name from url string or id from $_GET['gid']. |
80 | * Sets the title. | |
6a488035 TO |
81 | * |
82 | * @return void | |
6a488035 | 83 | */ |
00be9182 | 84 | public function preProcess() { |
6c2473d5 CW |
85 | if (!self::$_gName && !empty($this->urlPath[3])) { |
86 | self::$_gName = $this->urlPath[3]; | |
6a488035 | 87 | } |
6c2473d5 CW |
88 | // If an id arg is passed instead of a group name in the path |
89 | elseif (!self::$_gName && !empty($_GET['gid'])) { | |
90 | self::$_gId = $_GET['gid']; | |
91 | self::$_gName = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionGroup', self::$_gId, 'name'); | |
cede6590 | 92 | self::$_isLocked = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionGroup', self::$_gId, 'is_locked'); |
6c2473d5 CW |
93 | $breadCrumb = array( |
94 | 'title' => ts('Option Groups'), | |
95 | 'url' => CRM_Utils_System::url('civicrm/admin/options', 'reset=1'), | |
96 | ); | |
97 | CRM_Utils_System::appendBreadCrumb(array($breadCrumb)); | |
6a488035 | 98 | } |
6c2473d5 | 99 | if (!self::$_gName) { |
6a488035 TO |
100 | self::$_gName = $this->get('gName'); |
101 | } | |
6c2473d5 CW |
102 | // If we don't have a group we will browse all groups |
103 | if (!self::$_gName) { | |
104 | return; | |
6a488035 | 105 | } |
6c2473d5 CW |
106 | $this->set('gName', self::$_gName); |
107 | if (!self::$_gId) { | |
108 | self::$_gId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionGroup', self::$_gName, 'id', 'name'); | |
6a488035 TO |
109 | } |
110 | ||
6c2473d5 CW |
111 | self::$_gLabel = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionGroup', self::$_gId, 'title'); |
112 | if (!self::$_gLabel) { | |
113 | self::$_gLabel = ts('Option'); | |
114 | } | |
6a488035 TO |
115 | |
116 | $this->assign('gName', self::$_gName); | |
6c2473d5 | 117 | $this->assign('gLabel', self::$_gLabel); |
6a488035 TO |
118 | |
119 | if (self::$_gName == 'acl_role') { | |
120 | CRM_Utils_System::setTitle(ts('Manage ACL Roles')); | |
121 | // set breadcrumb to append to admin/access | |
353ffa53 TO |
122 | $breadCrumb = array( |
123 | array( | |
124 | 'title' => ts('Access Control'), | |
6a488035 TO |
125 | 'url' => CRM_Utils_System::url('civicrm/admin/access', |
126 | 'reset=1' | |
127 | ), | |
389bcebf | 128 | ), |
353ffa53 | 129 | ); |
6a488035 TO |
130 | CRM_Utils_System::appendBreadCrumb($breadCrumb); |
131 | } | |
132 | else { | |
6c2473d5 | 133 | CRM_Utils_System::setTitle(ts("%1 Options", array(1 => self::$_gLabel))); |
6a488035 TO |
134 | } |
135 | if (in_array(self::$_gName, | |
353ffa53 TO |
136 | array( |
137 | 'from_email_address', | |
138 | 'email_greeting', | |
139 | 'postal_greeting', | |
140 | 'addressee', | |
141 | 'communication_style', | |
142 | 'case_status', | |
143 | 'encounter_medium', | |
144 | 'case_type', | |
145 | 'payment_instrument', | |
146 | 'soft_credit_type', | |
147 | 'website_type', | |
148 | ) | |
149 | )) { | |
6a488035 TO |
150 | $this->assign('showIsDefault', TRUE); |
151 | } | |
6a488035 TO |
152 | |
153 | if (self::$_gName == 'participant_role') { | |
154 | $this->assign('showCounted', TRUE); | |
155 | } | |
cede6590 | 156 | $this->assign('isLocked', self::$_isLocked); |
6a488035 TO |
157 | $config = CRM_Core_Config::singleton(); |
158 | if (self::$_gName == 'activity_type') { | |
159 | $this->assign('showComponent', TRUE); | |
160 | } | |
161 | } | |
162 | ||
163 | /** | |
164 | * Get BAO Name | |
165 | * | |
a6c01b45 CW |
166 | * @return string |
167 | * Classname of BAO. | |
6a488035 | 168 | */ |
00be9182 | 169 | public function getBAOName() { |
6c2473d5 | 170 | return self::$_gName ? 'CRM_Core_BAO_OptionValue' : 'CRM_Core_BAO_OptionGroup'; |
6a488035 TO |
171 | } |
172 | ||
173 | /** | |
174 | * Get action Links | |
175 | * | |
a6c01b45 CW |
176 | * @return array |
177 | * (reference) of action links | |
6a488035 | 178 | */ |
00be9182 | 179 | public function &links() { |
6a488035 TO |
180 | if (!(self::$_links)) { |
181 | self::$_links = array( | |
182 | CRM_Core_Action::UPDATE => array( | |
183 | 'name' => ts('Edit'), | |
5c3522e8 | 184 | 'url' => 'civicrm/admin/options/' . self::$_gName, |
118e964e | 185 | 'qs' => 'action=update&id=%%id%%&reset=1', |
6a488035 TO |
186 | 'title' => ts('Edit %1', array(1 => self::$_gName)), |
187 | ), | |
188 | CRM_Core_Action::DISABLE => array( | |
189 | 'name' => ts('Disable'), | |
5e7dd082 | 190 | 'ref' => 'crm-enable-disable', |
6a488035 TO |
191 | 'title' => ts('Disable %1', array(1 => self::$_gName)), |
192 | ), | |
193 | CRM_Core_Action::ENABLE => array( | |
194 | 'name' => ts('Enable'), | |
5e7dd082 | 195 | 'ref' => 'crm-enable-disable', |
6a488035 TO |
196 | 'title' => ts('Enable %1', array(1 => self::$_gName)), |
197 | ), | |
198 | CRM_Core_Action::DELETE => array( | |
199 | 'name' => ts('Delete'), | |
5c3522e8 | 200 | 'url' => 'civicrm/admin/options/' . self::$_gName, |
118e964e | 201 | 'qs' => 'action=delete&id=%%id%%', |
6a488035 TO |
202 | 'title' => ts('Delete %1 Type', array(1 => self::$_gName)), |
203 | ), | |
204 | ); | |
205 | ||
206 | if (self::$_gName == 'custom_search') { | |
207 | $runLink = array( | |
208 | CRM_Core_Action::FOLLOWUP => array( | |
209 | 'name' => ts('Run'), | |
210 | 'url' => 'civicrm/contact/search/custom', | |
211 | 'qs' => 'reset=1&csid=%%value%%', | |
212 | 'title' => ts('Run %1', array(1 => self::$_gName)), | |
389bcebf | 213 | ), |
353ffa53 | 214 | ); |
6a488035 TO |
215 | self::$_links = $runLink + self::$_links; |
216 | } | |
217 | } | |
218 | return self::$_links; | |
219 | } | |
220 | ||
221 | /** | |
222 | * Run the basic page (run essentially starts execution for that page). | |
223 | * | |
224 | * @return void | |
225 | */ | |
00be9182 | 226 | public function run() { |
6a488035 TO |
227 | $this->preProcess(); |
228 | return parent::run(); | |
229 | } | |
230 | ||
231 | /** | |
232 | * Browse all options | |
233 | * | |
234 | * | |
235 | * @return void | |
6a488035 | 236 | */ |
00be9182 | 237 | public function browse() { |
6c2473d5 CW |
238 | if (!self::$_gName) { |
239 | return parent::browse(); | |
240 | } | |
6a488035 TO |
241 | $groupParams = array('name' => self::$_gName); |
242 | $optionValue = CRM_Core_OptionValue::getRows($groupParams, $this->links(), 'component_id,weight'); | |
353ffa53 TO |
243 | $gName = self::$_gName; |
244 | $returnURL = CRM_Utils_System::url("civicrm/admin/options/$gName", | |
6a488035 TO |
245 | "reset=1&group=$gName" |
246 | ); | |
247 | $filter = "option_group_id = " . self::$_gId; | |
248 | CRM_Utils_Weight::addOrder($optionValue, 'CRM_Core_DAO_OptionValue', | |
249 | 'id', $returnURL, $filter | |
250 | ); | |
251 | ||
252 | // retrieve financial account name for the payment instrument page | |
253 | if ($gName = "payment_instrument") { | |
02fc859b | 254 | foreach ($optionValue as $key => $option) { |
6eafcb19 CW |
255 | $optionValue[$key]['financial_account'] = CRM_Financial_BAO_FinancialTypeAccount::getFinancialAccount($key, 'civicrm_option_value'); |
256 | } | |
6a488035 | 257 | } |
6a488035 TO |
258 | $this->assign('rows', $optionValue); |
259 | } | |
260 | ||
261 | /** | |
262 | * Get name of edit form | |
263 | * | |
a6c01b45 CW |
264 | * @return string |
265 | * Classname of edit form. | |
6a488035 | 266 | */ |
00be9182 | 267 | public function editForm() { |
6c2473d5 | 268 | return self::$_gName ? 'CRM_Admin_Form_Options' : 'CRM_Admin_Form_OptionGroup'; |
6a488035 TO |
269 | } |
270 | ||
271 | /** | |
272 | * Get edit form name | |
273 | * | |
a6c01b45 CW |
274 | * @return string |
275 | * name of this page. | |
6a488035 | 276 | */ |
00be9182 | 277 | public function editName() { |
6c2473d5 | 278 | return self::$_gLabel; |
6a488035 TO |
279 | } |
280 | ||
281 | /** | |
282 | * Get user context. | |
283 | * | |
dd244018 EM |
284 | * @param null $mode |
285 | * | |
a6c01b45 CW |
286 | * @return string |
287 | * user context. | |
6a488035 | 288 | */ |
00be9182 | 289 | public function userContext($mode = NULL) { |
6c2473d5 | 290 | return 'civicrm/admin/options' . (self::$_gName ? '/' . self::$_gName : ''); |
6a488035 | 291 | } |
96025800 | 292 | |
6a488035 | 293 | } |