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