| 1 | <?php |
| 2 | /* |
| 3 | +--------------------------------------------------------------------+ |
| 4 | | CiviCRM version 5 | |
| 5 | +--------------------------------------------------------------------+ |
| 6 | | Copyright CiviCRM LLC (c) 2004-2018 | |
| 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-2018 |
| 32 | */ |
| 33 | |
| 34 | /** |
| 35 | * Page for displaying list of Gender. |
| 36 | */ |
| 37 | class CRM_Admin_Page_Options extends CRM_Core_Page_Basic { |
| 38 | |
| 39 | public $useLivePageJS = TRUE; |
| 40 | |
| 41 | /** |
| 42 | * The action links that we need to display for the browse screen. |
| 43 | * |
| 44 | * @var array |
| 45 | */ |
| 46 | static $_links = NULL; |
| 47 | |
| 48 | /** |
| 49 | * The option group name. |
| 50 | * |
| 51 | * @var array |
| 52 | */ |
| 53 | static $_gName = NULL; |
| 54 | |
| 55 | /** |
| 56 | * The option group name in display format (capitalized, without underscores...etc) |
| 57 | * |
| 58 | * @var array |
| 59 | */ |
| 60 | static $_gLabel = NULL; |
| 61 | |
| 62 | /** |
| 63 | * The option group id. |
| 64 | * |
| 65 | * @var array |
| 66 | */ |
| 67 | static $_gId = NULL; |
| 68 | |
| 69 | /** |
| 70 | * A boolean determining if you can add options to this group in the GUI. |
| 71 | * |
| 72 | * @var boolean |
| 73 | */ |
| 74 | static $_isLocked = FALSE; |
| 75 | |
| 76 | /** |
| 77 | * Obtains the group name from url string or id from $_GET['gid']. |
| 78 | * |
| 79 | * Sets the title. |
| 80 | */ |
| 81 | public function preProcess() { |
| 82 | if (!self::$_gName && !empty($this->urlPath[3])) { |
| 83 | self::$_gName = $this->urlPath[3]; |
| 84 | self::$_isLocked = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionGroup', self::$_gName, 'is_locked', 'name'); |
| 85 | } |
| 86 | // If an id arg is passed instead of a group name in the path |
| 87 | elseif (!self::$_gName && !empty($_GET['gid'])) { |
| 88 | self::$_gId = $_GET['gid']; |
| 89 | self::$_gName = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionGroup', self::$_gId, 'name'); |
| 90 | self::$_isLocked = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionGroup', self::$_gId, 'is_locked'); |
| 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( |
| 121 | array( |
| 122 | 'title' => ts('Access Control'), |
| 123 | 'url' => CRM_Utils_System::url('civicrm/admin/access', |
| 124 | 'reset=1' |
| 125 | ), |
| 126 | ), |
| 127 | ); |
| 128 | CRM_Utils_System::appendBreadCrumb($breadCrumb); |
| 129 | } |
| 130 | else { |
| 131 | CRM_Utils_System::setTitle(ts("%1 Options", array(1 => self::$_gLabel))); |
| 132 | } |
| 133 | if (in_array(self::$_gName, |
| 134 | array( |
| 135 | 'from_email_address', |
| 136 | 'email_greeting', |
| 137 | 'postal_greeting', |
| 138 | 'addressee', |
| 139 | 'communication_style', |
| 140 | 'case_status', |
| 141 | 'encounter_medium', |
| 142 | 'case_type', |
| 143 | 'payment_instrument', |
| 144 | 'soft_credit_type', |
| 145 | '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 | $this->assign('allowLoggedIn', Civi::settings()->get('allow_mail_from_logged_in_contact')); |
| 156 | $config = CRM_Core_Config::singleton(); |
| 157 | if (self::$_gName == 'activity_type') { |
| 158 | $this->assign('showComponent', TRUE); |
| 159 | } |
| 160 | } |
| 161 | |
| 162 | /** |
| 163 | * Get BAO Name. |
| 164 | * |
| 165 | * @return string |
| 166 | * Classname of BAO. |
| 167 | */ |
| 168 | public function getBAOName() { |
| 169 | return self::$_gName ? 'CRM_Core_BAO_OptionValue' : 'CRM_Core_BAO_OptionGroup'; |
| 170 | } |
| 171 | |
| 172 | /** |
| 173 | * Get action Links. |
| 174 | * |
| 175 | * @return array |
| 176 | * (reference) of action links |
| 177 | */ |
| 178 | public function &links() { |
| 179 | if (!(self::$_links)) { |
| 180 | self::$_links = array( |
| 181 | CRM_Core_Action::UPDATE => array( |
| 182 | 'name' => ts('Edit'), |
| 183 | 'url' => 'civicrm/admin/options/' . self::$_gName, |
| 184 | 'qs' => 'action=update&id=%%id%%&reset=1', |
| 185 | 'title' => ts('Edit %1', array(1 => self::$_gName)), |
| 186 | ), |
| 187 | CRM_Core_Action::DISABLE => array( |
| 188 | 'name' => ts('Disable'), |
| 189 | 'ref' => 'crm-enable-disable', |
| 190 | 'title' => ts('Disable %1', array(1 => self::$_gName)), |
| 191 | ), |
| 192 | CRM_Core_Action::ENABLE => array( |
| 193 | 'name' => ts('Enable'), |
| 194 | 'ref' => 'crm-enable-disable', |
| 195 | 'title' => ts('Enable %1', array(1 => self::$_gName)), |
| 196 | ), |
| 197 | CRM_Core_Action::DELETE => array( |
| 198 | 'name' => ts('Delete'), |
| 199 | 'url' => 'civicrm/admin/options/' . self::$_gName, |
| 200 | 'qs' => 'action=delete&id=%%id%%', |
| 201 | 'title' => ts('Delete %1 Type', array(1 => self::$_gName)), |
| 202 | ), |
| 203 | ); |
| 204 | |
| 205 | if (self::$_gName == 'custom_search') { |
| 206 | $runLink = array( |
| 207 | CRM_Core_Action::FOLLOWUP => array( |
| 208 | 'name' => ts('Run'), |
| 209 | 'url' => 'civicrm/contact/search/custom', |
| 210 | 'qs' => 'reset=1&csid=%%value%%', |
| 211 | 'title' => ts('Run %1', array(1 => self::$_gName)), |
| 212 | 'class' => 'no-popup', |
| 213 | ), |
| 214 | ); |
| 215 | self::$_links = $runLink + self::$_links; |
| 216 | } |
| 217 | } |
| 218 | return self::$_links; |
| 219 | } |
| 220 | |
| 221 | /** |
| 222 | * Run the basic page (run essentially starts execution for that page). |
| 223 | */ |
| 224 | public function run() { |
| 225 | $this->preProcess(); |
| 226 | return parent::run(); |
| 227 | } |
| 228 | |
| 229 | /** |
| 230 | * Browse all options. |
| 231 | */ |
| 232 | public function browse() { |
| 233 | if (!self::$_gName) { |
| 234 | return parent::browse(); |
| 235 | } |
| 236 | $groupParams = array('name' => self::$_gName); |
| 237 | $optionValue = CRM_Core_OptionValue::getRows($groupParams, $this->links(), 'component_id,weight'); |
| 238 | $gName = self::$_gName; |
| 239 | $returnURL = CRM_Utils_System::url("civicrm/admin/options/$gName", |
| 240 | "reset=1&group=$gName" |
| 241 | ); |
| 242 | $filter = "option_group_id = " . self::$_gId; |
| 243 | CRM_Utils_Weight::addOrder($optionValue, 'CRM_Core_DAO_OptionValue', |
| 244 | 'id', $returnURL, $filter |
| 245 | ); |
| 246 | |
| 247 | // retrieve financial account name for the payment method page |
| 248 | if ($gName = "payment_instrument") { |
| 249 | foreach ($optionValue as $key => $option) { |
| 250 | $optionValue[$key]['financial_account'] = CRM_Contribute_PseudoConstant::getRelationalFinancialAccount($key, NULL, 'civicrm_option_value', 'financial_account_id.name'); |
| 251 | } |
| 252 | } |
| 253 | $this->assign('rows', $optionValue); |
| 254 | } |
| 255 | |
| 256 | /** |
| 257 | * Get name of edit form. |
| 258 | * |
| 259 | * @return string |
| 260 | * Classname of edit form. |
| 261 | */ |
| 262 | public function editForm() { |
| 263 | return self::$_gName ? 'CRM_Admin_Form_Options' : 'CRM_Admin_Form_OptionGroup'; |
| 264 | } |
| 265 | |
| 266 | /** |
| 267 | * Get edit form name. |
| 268 | * |
| 269 | * @return string |
| 270 | * name of this page. |
| 271 | */ |
| 272 | public function editName() { |
| 273 | return self::$_gLabel; |
| 274 | } |
| 275 | |
| 276 | /** |
| 277 | * Get user context. |
| 278 | * |
| 279 | * @param null $mode |
| 280 | * |
| 281 | * @return string |
| 282 | * user context. |
| 283 | */ |
| 284 | public function userContext($mode = NULL) { |
| 285 | return 'civicrm/admin/options' . (self::$_gName ? '/' . self::$_gName : ''); |
| 286 | } |
| 287 | |
| 288 | } |