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