Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
7e9e8871 | 4 | | CiviCRM version 4.7 | |
6a488035 | 5 | +--------------------------------------------------------------------+ |
8c9251b3 | 6 | | Copyright CiviCRM LLC (c) 2004-2018 | |
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 | +--------------------------------------------------------------------+ | |
d25dd0ee | 26 | */ |
6a488035 TO |
27 | |
28 | /** | |
29 | * | |
30 | * @package CRM | |
8c9251b3 | 31 | * @copyright CiviCRM LLC (c) 2004-2018 |
6a488035 TO |
32 | */ |
33 | ||
34 | /** | |
ce064e4f | 35 | * Page for displaying list of Gender. |
6a488035 TO |
36 | */ |
37 | class CRM_Admin_Page_Options extends CRM_Core_Page_Basic { | |
38 | ||
96f50de2 CW |
39 | public $useLivePageJS = TRUE; |
40 | ||
6a488035 | 41 | /** |
eceb18cc | 42 | * The action links that we need to display for the browse screen. |
6a488035 TO |
43 | * |
44 | * @var array | |
6a488035 TO |
45 | */ |
46 | static $_links = NULL; | |
47 | ||
48 | /** | |
eceb18cc | 49 | * The option group name. |
6a488035 TO |
50 | * |
51 | * @var array | |
6a488035 TO |
52 | */ |
53 | static $_gName = NULL; | |
54 | ||
55 | /** | |
56 | * The option group name in display format (capitalized, without underscores...etc) | |
57 | * | |
58 | * @var array | |
6a488035 | 59 | */ |
6c2473d5 | 60 | static $_gLabel = NULL; |
6a488035 TO |
61 | |
62 | /** | |
eceb18cc | 63 | * The option group id. |
6a488035 TO |
64 | * |
65 | * @var array | |
6a488035 TO |
66 | */ |
67 | static $_gId = NULL; | |
68 | ||
cede6590 | 69 | /** |
eceb18cc | 70 | * A boolean determining if you can add options to this group in the GUI. |
cede6590 DG |
71 | * |
72 | * @var boolean | |
cede6590 DG |
73 | */ |
74 | static $_isLocked = FALSE; | |
75 | ||
6a488035 | 76 | /** |
6c2473d5 | 77 | * Obtains the group name from url string or id from $_GET['gid']. |
6a488035 | 78 | * |
ce064e4f | 79 | * Sets the title. |
6a488035 | 80 | */ |
00be9182 | 81 | public 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'); | |
cede6590 | 89 | self::$_isLocked = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionGroup', self::$_gId, 'is_locked'); |
6c2473d5 CW |
90 | $breadCrumb = array( |
91 | 'title' => ts('Option Groups'), | |
92 | 'url' => CRM_Utils_System::url('civicrm/admin/options', 'reset=1'), | |
93 | ); | |
94 | CRM_Utils_System::appendBreadCrumb(array($breadCrumb)); | |
6a488035 | 95 | } |
6c2473d5 | 96 | if (!self::$_gName) { |
6a488035 TO |
97 | self::$_gName = $this->get('gName'); |
98 | } | |
6c2473d5 CW |
99 | // If we don't have a group we will browse all groups |
100 | if (!self::$_gName) { | |
101 | return; | |
6a488035 | 102 | } |
6c2473d5 CW |
103 | $this->set('gName', self::$_gName); |
104 | if (!self::$_gId) { | |
105 | self::$_gId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionGroup', self::$_gName, 'id', 'name'); | |
6a488035 TO |
106 | } |
107 | ||
6c2473d5 CW |
108 | self::$_gLabel = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionGroup', self::$_gId, 'title'); |
109 | if (!self::$_gLabel) { | |
110 | self::$_gLabel = ts('Option'); | |
111 | } | |
6a488035 TO |
112 | |
113 | $this->assign('gName', self::$_gName); | |
6c2473d5 | 114 | $this->assign('gLabel', self::$_gLabel); |
6a488035 TO |
115 | |
116 | if (self::$_gName == 'acl_role') { | |
117 | CRM_Utils_System::setTitle(ts('Manage ACL Roles')); | |
118 | // set breadcrumb to append to admin/access | |
353ffa53 TO |
119 | $breadCrumb = array( |
120 | array( | |
121 | 'title' => ts('Access Control'), | |
6a488035 TO |
122 | 'url' => CRM_Utils_System::url('civicrm/admin/access', |
123 | 'reset=1' | |
124 | ), | |
389bcebf | 125 | ), |
353ffa53 | 126 | ); |
6a488035 TO |
127 | CRM_Utils_System::appendBreadCrumb($breadCrumb); |
128 | } | |
129 | else { | |
6c2473d5 | 130 | CRM_Utils_System::setTitle(ts("%1 Options", array(1 => self::$_gLabel))); |
6a488035 TO |
131 | } |
132 | if (in_array(self::$_gName, | |
353ffa53 TO |
133 | array( |
134 | 'from_email_address', | |
135 | 'email_greeting', | |
136 | 'postal_greeting', | |
137 | 'addressee', | |
138 | 'communication_style', | |
139 | 'case_status', | |
140 | 'encounter_medium', | |
141 | 'case_type', | |
142 | 'payment_instrument', | |
143 | 'soft_credit_type', | |
144 | 'website_type', | |
145 | ) | |
146 | )) { | |
6a488035 TO |
147 | $this->assign('showIsDefault', TRUE); |
148 | } | |
6a488035 TO |
149 | |
150 | if (self::$_gName == 'participant_role') { | |
151 | $this->assign('showCounted', TRUE); | |
152 | } | |
cede6590 | 153 | $this->assign('isLocked', self::$_isLocked); |
6a488035 TO |
154 | $config = CRM_Core_Config::singleton(); |
155 | if (self::$_gName == 'activity_type') { | |
156 | $this->assign('showComponent', TRUE); | |
157 | } | |
158 | } | |
159 | ||
160 | /** | |
eceb18cc | 161 | * Get BAO Name. |
6a488035 | 162 | * |
a6c01b45 CW |
163 | * @return string |
164 | * Classname of BAO. | |
6a488035 | 165 | */ |
00be9182 | 166 | public function getBAOName() { |
6c2473d5 | 167 | return self::$_gName ? 'CRM_Core_BAO_OptionValue' : 'CRM_Core_BAO_OptionGroup'; |
6a488035 TO |
168 | } |
169 | ||
170 | /** | |
eceb18cc | 171 | * Get action Links. |
6a488035 | 172 | * |
a6c01b45 CW |
173 | * @return array |
174 | * (reference) of action links | |
6a488035 | 175 | */ |
00be9182 | 176 | public function &links() { |
6a488035 TO |
177 | if (!(self::$_links)) { |
178 | self::$_links = array( | |
179 | CRM_Core_Action::UPDATE => array( | |
180 | 'name' => ts('Edit'), | |
5c3522e8 | 181 | 'url' => 'civicrm/admin/options/' . self::$_gName, |
118e964e | 182 | 'qs' => 'action=update&id=%%id%%&reset=1', |
6a488035 TO |
183 | 'title' => ts('Edit %1', array(1 => self::$_gName)), |
184 | ), | |
185 | CRM_Core_Action::DISABLE => array( | |
186 | 'name' => ts('Disable'), | |
5e7dd082 | 187 | 'ref' => 'crm-enable-disable', |
6a488035 TO |
188 | 'title' => ts('Disable %1', array(1 => self::$_gName)), |
189 | ), | |
190 | CRM_Core_Action::ENABLE => array( | |
191 | 'name' => ts('Enable'), | |
5e7dd082 | 192 | 'ref' => 'crm-enable-disable', |
6a488035 TO |
193 | 'title' => ts('Enable %1', array(1 => self::$_gName)), |
194 | ), | |
195 | CRM_Core_Action::DELETE => array( | |
196 | 'name' => ts('Delete'), | |
5c3522e8 | 197 | 'url' => 'civicrm/admin/options/' . self::$_gName, |
118e964e | 198 | 'qs' => 'action=delete&id=%%id%%', |
6a488035 TO |
199 | 'title' => ts('Delete %1 Type', array(1 => self::$_gName)), |
200 | ), | |
201 | ); | |
202 | ||
203 | if (self::$_gName == 'custom_search') { | |
204 | $runLink = array( | |
205 | CRM_Core_Action::FOLLOWUP => array( | |
206 | 'name' => ts('Run'), | |
207 | 'url' => 'civicrm/contact/search/custom', | |
208 | 'qs' => 'reset=1&csid=%%value%%', | |
209 | 'title' => ts('Run %1', array(1 => self::$_gName)), | |
a9f247da | 210 | 'class' => 'no-popup', |
389bcebf | 211 | ), |
353ffa53 | 212 | ); |
6a488035 TO |
213 | self::$_links = $runLink + self::$_links; |
214 | } | |
215 | } | |
216 | return self::$_links; | |
217 | } | |
218 | ||
219 | /** | |
220 | * Run the basic page (run essentially starts execution for that page). | |
6a488035 | 221 | */ |
00be9182 | 222 | public function run() { |
6a488035 TO |
223 | $this->preProcess(); |
224 | return parent::run(); | |
225 | } | |
226 | ||
227 | /** | |
eceb18cc | 228 | * Browse all options. |
6a488035 | 229 | */ |
00be9182 | 230 | public function browse() { |
6c2473d5 CW |
231 | if (!self::$_gName) { |
232 | return parent::browse(); | |
233 | } | |
6a488035 TO |
234 | $groupParams = array('name' => self::$_gName); |
235 | $optionValue = CRM_Core_OptionValue::getRows($groupParams, $this->links(), 'component_id,weight'); | |
353ffa53 TO |
236 | $gName = self::$_gName; |
237 | $returnURL = CRM_Utils_System::url("civicrm/admin/options/$gName", | |
6a488035 TO |
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 | ||
536f0e02 | 245 | // retrieve financial account name for the payment method page |
6a488035 | 246 | if ($gName = "payment_instrument") { |
02fc859b | 247 | foreach ($optionValue as $key => $option) { |
74afdc40 | 248 | $optionValue[$key]['financial_account'] = CRM_Contribute_PseudoConstant::getRelationalFinancialAccount($key, NULL, 'civicrm_option_value', 'financial_account_id.name'); |
6eafcb19 | 249 | } |
6a488035 | 250 | } |
6a488035 TO |
251 | $this->assign('rows', $optionValue); |
252 | } | |
253 | ||
254 | /** | |
eceb18cc | 255 | * Get name of edit form. |
6a488035 | 256 | * |
a6c01b45 CW |
257 | * @return string |
258 | * Classname of edit form. | |
6a488035 | 259 | */ |
00be9182 | 260 | public function editForm() { |
6c2473d5 | 261 | return self::$_gName ? 'CRM_Admin_Form_Options' : 'CRM_Admin_Form_OptionGroup'; |
6a488035 TO |
262 | } |
263 | ||
264 | /** | |
eceb18cc | 265 | * Get edit form name. |
6a488035 | 266 | * |
a6c01b45 CW |
267 | * @return string |
268 | * name of this page. | |
6a488035 | 269 | */ |
00be9182 | 270 | public function editName() { |
6c2473d5 | 271 | return self::$_gLabel; |
6a488035 TO |
272 | } |
273 | ||
274 | /** | |
275 | * Get user context. | |
276 | * | |
dd244018 EM |
277 | * @param null $mode |
278 | * | |
a6c01b45 CW |
279 | * @return string |
280 | * user context. | |
6a488035 | 281 | */ |
00be9182 | 282 | public function userContext($mode = NULL) { |
6c2473d5 | 283 | return 'civicrm/admin/options' . (self::$_gName ? '/' . self::$_gName : ''); |
6a488035 | 284 | } |
96025800 | 285 | |
6a488035 | 286 | } |