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