Merge remote-tracking branch 'upstream/4.4' into 4.4-master-2013-12-09-17-00-10
[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 'communication_style',
120 'case_status', 'encounter_medium',
121 'case_type', 'payment_instrument'
122 )
123 )) {
124 $this->assign('showIsDefault', TRUE);
125 }
126 if (self::$_gName == 'participant_status') {
127 $this->assign('showCounted', TRUE);
128 $this->assign('showVisibility', TRUE);
129 }
130
131 if (self::$_gName == 'participant_role') {
132 $this->assign('showCounted', TRUE);
133 }
134 $config = CRM_Core_Config::singleton();
135 if (self::$_gName == 'activity_type') {
136 $this->assign('showComponent', TRUE);
137 }
138 }
139
140 /**
141 * Get BAO Name
142 *
143 * @return string Classname of BAO.
144 */
145 function getBAOName() {
146 return 'CRM_Core_BAO_OptionValue';
147 }
148
149 /**
150 * Get action Links
151 *
152 * @return array (reference) of action links
153 */
154 function &links() {
155 if (!(self::$_links)) {
156 self::$_links = array(
157 CRM_Core_Action::UPDATE => array(
158 'name' => ts('Edit'),
159 'url' => 'civicrm/admin/options/' . self::$_gName,
160 'qs' => 'group=' . self::$_gName . '&action=update&id=%%id%%&reset=1',
161 'title' => ts('Edit %1', array(1 => self::$_gName)),
162 ),
163 CRM_Core_Action::DISABLE => array(
164 'name' => ts('Disable'),
165 'extra' => 'onclick = "enableDisable( %%id%%,\'' . 'CRM_Core_BAO_OptionValue' . '\',\'' . 'enable-disable' . '\' );"',
166 'ref' => 'disable-action',
167 'title' => ts('Disable %1', array(1 => self::$_gName)),
168 ),
169 CRM_Core_Action::ENABLE => array(
170 'name' => ts('Enable'),
171 'extra' => 'onclick = "enableDisable( %%id%%,\'' . 'CRM_Core_BAO_OptionValue' . '\',\'' . 'disable-enable' . '\' );"',
172 'ref' => 'enable-action',
173 'title' => ts('Enable %1', array(1 => self::$_gName)),
174 ),
175 CRM_Core_Action::DELETE => array(
176 'name' => ts('Delete'),
177 'url' => 'civicrm/admin/options/' . self::$_gName,
178 'qs' => 'group=' . self::$_gName . '&action=delete&id=%%id%%',
179 'title' => ts('Delete %1 Type', array(1 => self::$_gName)),
180 ),
181 );
182
183 if (self::$_gName == 'custom_search') {
184 $runLink = array(
185 CRM_Core_Action::FOLLOWUP => array(
186 'name' => ts('Run'),
187 'url' => 'civicrm/contact/search/custom',
188 'qs' => 'reset=1&csid=%%value%%',
189 'title' => ts('Run %1', array(1 => self::$_gName)),
190 ));
191 self::$_links = $runLink + self::$_links;
192 }
193 }
194 return self::$_links;
195 }
196
197 /**
198 * Run the basic page (run essentially starts execution for that page).
199 *
200 * @return void
201 */
202 function run() {
203 $this->preProcess();
204 return parent::run();
205 }
206
207 /**
208 * Browse all options
209 *
210 *
211 * @return void
212 * @access public
213 * @static
214 */
215 function browse() {
216
217 $groupParams = array('name' => self::$_gName);
218 $optionValue = CRM_Core_OptionValue::getRows($groupParams, $this->links(), 'component_id,weight');
219 $gName = self::$_gName;
220 $returnURL = CRM_Utils_System::url("civicrm/admin/options/$gName",
221 "reset=1&group=$gName"
222 );
223 $filter = "option_group_id = " . self::$_gId;
224 CRM_Utils_Weight::addOrder($optionValue, 'CRM_Core_DAO_OptionValue',
225 'id', $returnURL, $filter
226 );
227
228 // retrieve financial account name for the payment instrument page
229 if ($gName = "payment_instrument") {
230 foreach ($optionValue as $key => $option) {
231 $optionValue[$key]['financial_account'] = CRM_Financial_BAO_FinancialTypeAccount::getFinancialAccount($key, 'civicrm_option_value'); }
232 }
233
234 $this->assign('rows', $optionValue);
235 }
236
237 /**
238 * Get name of edit form
239 *
240 * @return string Classname of edit form.
241 */
242 function editForm() {
243 return 'CRM_Admin_Form_Options';
244 }
245
246 /**
247 * Get edit form name
248 *
249 * @return string name of this page.
250 */
251 function editName() {
252 return self::$_GName;
253 }
254
255 /**
256 * Get user context.
257 *
258 * @return string user context.
259 */
260 function userContext($mode = NULL) {
261 return 'civicrm/admin/options/' . self::$_gName;
262 }
263
264 /**
265 * function to get userContext params
266 *
267 * @param int $mode mode that we are in
268 *
269 * @return string
270 * @access public
271 */
272 function userContextParams($mode = NULL) {
273 return 'group=' . self::$_gName . '&reset=1&action=browse';
274 }
275 }
276