Merge pull request #3906 from colemanw/CRM-15141
[civicrm-core.git] / CRM / Admin / Form / Options.php
index a23d9a1329abb42f6261f7056de202d1d1b3a817..8282796976e620bf665b06fb1ce225ba558192c9 100644 (file)
@@ -1,9 +1,9 @@
 <?php
 /*
  +--------------------------------------------------------------------+
- | CiviCRM version 4.4                                                |
+ | CiviCRM version 4.5                                                |
  +--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2013                                |
+ | Copyright CiviCRM LLC (c) 2004-2014                                |
  +--------------------------------------------------------------------+
  | This file is a part of CiviCRM.                                    |
  |                                                                    |
@@ -28,7 +28,7 @@
 /**
  *
  * @package CRM
- * @copyright CiviCRM LLC (c) 2004-2013
+ * @copyright CiviCRM LLC (c) 2004-2014
  * $Id$
  *
  */
@@ -53,7 +53,7 @@ class CRM_Admin_Form_Options extends CRM_Admin_Form {
    * @var array
    * @static
    */
-  protected $_GName;
+  protected $_gLabel;
 
   /**
    * Function to pre-process
@@ -64,13 +64,11 @@ class CRM_Admin_Form_Options extends CRM_Admin_Form {
   public function preProcess() {
     parent::preProcess();
     $session = CRM_Core_Session::singleton();
-    if (!$this->_gName) {
-      $this->_gName = CRM_Utils_Request::retrieve('group', 'String', $this, FALSE, 0);
-      $this->_gid = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionGroup',
-        $this->_gName,
-        'id',
-        'name'
-      );
+    if (!$this->_gName && !empty($this->urlPath[3])) {
+      $this->_gName = $this->urlPath[3];
+    }
+    if (!$this->_gName && !empty($_GET['gid'])) {
+      $this->_gName = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionGroup', (int) $_GET['gid'], 'name');
     }
     if ($this->_gName) {
       $this->set('gName', $this->_gName);
@@ -78,9 +76,14 @@ class CRM_Admin_Form_Options extends CRM_Admin_Form {
     else {
       $this->_gName = $this->get('gName');
     }
-    $this->_GName = ucwords(str_replace('_', ' ', $this->_gName));
+    $this->_gid = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionGroup',
+      $this->_gName,
+      'id',
+      'name'
+    );
+    $this->_gLabel = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionGroup', $this->_gid, 'title');
     $url          = "civicrm/admin/options/{$this->_gName}";
-    $params       = "group={$this->_gName}&reset=1";
+    $params       = "reset=1";
 
     if (($this->_action & CRM_Core_Action::DELETE) &&
       in_array($this->_gName, array('email_greeting', 'postal_greeting', 'addressee'))
@@ -93,7 +96,7 @@ class CRM_Admin_Form_Options extends CRM_Admin_Form {
       $isInUse    = CRM_Core_DAO::singleValueQuery($sql, $queryParam);
       if ($isInUse) {
         $scriptURL = "<a href='" . CRM_Utils_System::docURL2('Update Greetings and Address Data for Contacts', TRUE, NULL, NULL, NULL, "wiki") . "'>" . ts('Learn more about a script that can automatically update contact addressee and greeting options.') . "</a>";
-        CRM_Core_Session::setStatus(ts('The selected %1 option has <strong>not been deleted</strong> because it is currently in use. Please update these contacts to use a different format before deleting this option. %2', array(1 => $this->_GName, 2 => $scriptURL)), ts('Sorry'), 'error');
+        CRM_Core_Session::setStatus(ts('The selected %1 option has <strong>not been deleted</strong> because it is currently in use. Please update these contacts to use a different format before deleting this option. %2', array(1 => $this->_gLabel, 2 => $scriptURL)), ts('Sorry'), 'error');
         $redirect = CRM_Utils_System::url($url, $params);
         CRM_Utils_System::redirect($redirect);
       }
@@ -147,6 +150,8 @@ class CRM_Admin_Form_Options extends CRM_Admin_Form {
    */
   public function buildQuickForm() {
     parent::buildQuickForm();
+    $this->setPageTitle(ts('%1 Option', array(1 => $this->_gLabel)));
+
     if ($this->_action & CRM_Core_Action::DELETE) {
       return;
     }
@@ -194,7 +199,8 @@ class CRM_Admin_Form_Options extends CRM_Admin_Form {
       $financialAccount = CRM_Contribute_PseudoConstant::financialAccount(NULL, key($accountType));
 
       $this->add('select', 'financial_account_id', ts('Financial Account'),
-        array('' => ts('- select -')) + $financialAccount
+        array('' => ts('- select -')) + $financialAccount,
+        TRUE
       );
     }
 
@@ -280,6 +286,8 @@ class CRM_Admin_Form_Options extends CRM_Admin_Form {
       'case_type',
       'payment_instrument',
       'communication_style',
+      'soft_credit_type',
+      'website_type',
     );
 
     if (in_array($this->_gName, $showIsDefaultGroups)) {
@@ -325,13 +333,11 @@ class CRM_Admin_Form_Options extends CRM_Admin_Form {
    */
   static function formRule($fields, $files, $self) {
     $errors = array();
-    if ($self->_gName == 'case_status' && !CRM_Utils_Array::value('grouping', $fields)) {
+    if ($self->_gName == 'case_status' && empty($fields['grouping'])) {
       $errors['grouping'] = ts('Status class is a required field');
     }
 
-    if (in_array($self->_gName, array('email_greeting', 'postal_greeting', 'addressee'))
-      && !CRM_Utils_Array::value('is_reserved', $self->_defaultValues)
-    ) {
+    if (in_array($self->_gName, array('email_greeting', 'postal_greeting', 'addressee')) && empty($self->_defaultValues['is_reserved'])) {
       $label               = $fields['label'];
       $condition           = " AND v.label = '{$label}' ";
       $values              = CRM_Core_OptionGroup::values($self->_gName, FALSE, FALSE, FALSE, $condition, 'filter');
@@ -378,10 +384,10 @@ class CRM_Admin_Form_Options extends CRM_Admin_Form {
           CRM_Core_BAO_Phone::setOptionToNull(CRM_Utils_Array::value('value', $this->_defaultValues));
         }
 
-        CRM_Core_Session::setStatus(ts('Selected %1 type has been deleted.', array(1 => $this->_GName)), ts('Record Deleted'), 'success');
+        CRM_Core_Session::setStatus(ts('Selected %1 type has been deleted.', array(1 => $this->_gLabel)), ts('Record Deleted'), 'success');
       }
       else {
-        CRM_Core_Session::setStatus(ts('Selected %1 type has not been deleted.', array(1 => $this->_GName)), ts('Sorry'), 'error');
+        CRM_Core_Session::setStatus(ts('Selected %1 type has not been deleted.', array(1 => $this->_gLabel)), ts('Sorry'), 'error');
         CRM_Utils_Weight::correctDuplicateWeights('CRM_Core_DAO_OptionValue', $fieldValues);
       }
     }
@@ -430,7 +436,8 @@ class CRM_Admin_Form_Options extends CRM_Admin_Form {
         CRM_Financial_BAO_FinancialTypeAccount::add($params);
       }
 
-      CRM_Core_Session::setStatus(ts('The %1 \'%2\' has been saved.', array(1 => $this->_GName, 2 => $optionValue->label)), ts('Saved'), 'success');
+      CRM_Core_Session::setStatus(ts('The %1 \'%2\' has been saved.', array(1 => $this->_gLabel, 2 => $optionValue->label)), ts('Saved'), 'success');
     }
   }
+
 }