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