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