Merge pull request #3972 from colemanw/CRM-15193
[civicrm-core.git] / CRM / Admin / Form / Tag.php
index f768d82a02413be997b713ac6ed6ad001c4af9d7..ccf752700c8f69010f6262be591aaef0f58ca6e8 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$
  *
  */
@@ -47,26 +47,15 @@ class CRM_Admin_Form_Tag extends CRM_Admin_Form {
    * @access public
    */
   public function buildQuickForm() {
+    $this->setPageTitle($this->_isTagSet ? ts('Tag Set') : ts('Tag'));
+
     if ($this->_action == CRM_Core_Action::DELETE) {
       if ($this->_id && $tag = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_Tag', $this->_id, 'name', 'parent_id')) {
-        CRM_Core_Session::setStatus(ts("This tag cannot be deleted. You must delete all its child tags ('%1', etc) prior to deleting this tag.", array(1 => $tag)), ts('Sorry'), 'error');
         $url = CRM_Utils_System::url('civicrm/admin/tag', "reset=1");
-        CRM_Utils_System::redirect($url);
-        return TRUE;
+        CRM_Core_Error::statusBounce(ts("This tag cannot be deleted. You must delete all its child tags ('%1', etc) prior to deleting this tag.", array(1 => $tag)), $url);
       }
-      else {
-        $this->addButtons(array(
-            array(
-              'type' => 'next',
-              'name' => ts('Delete'),
-              'isDefault' => TRUE,
-            ),
-            array(
-              'type' => 'cancel',
-              'name' => ts('Cancel'),
-            ),
-          )
-        );
+      if ($this->_values['is_reserved'] == 1 && !CRM_Core_Permission::check('administer reserved tags')) {
+        CRM_Core_Error::statusBounce(ts("You do not have sufficient permission to delete this reserved tag."));
       }
     }
     else {
@@ -79,14 +68,14 @@ class CRM_Admin_Form_Tag extends CRM_Admin_Form {
         $this->_isTagSet = TRUE;
       }
 
-      $allTag = array('' => '- ' . ts('select') . ' -') + CRM_Core_BAO_Tag::getTagsNotInTagset();
+      $allTag = array('' => ts('- select -')) + CRM_Core_BAO_Tag::getTagsNotInTagset();
 
       if ($this->_id) {
         unset($allTag[$this->_id]);
       }
 
       if (!$this->_isTagSet) {
-        $this->add('select', 'parent_id', ts('Parent Tag'), $allTag);
+        $this->add('select', 'parent_id', ts('Parent Tag'), $allTag, FALSE, array('class' => 'crm-select2'));
       }
 
       $this->assign('isTagSet', $this->_isTagSet);
@@ -103,14 +92,11 @@ class CRM_Admin_Form_Tag extends CRM_Admin_Form {
       );
 
       //@lobo haven't a clue why the checkbox isn't displayed (it should be checked by default
-      $this->add('checkbox', 'is_selectable', ts("If it's a tag or a category"));
+      $this->add('checkbox', 'is_selectable');
 
       $isReserved = $this->add('checkbox', 'is_reserved', ts('Reserved?'));
 
-      $usedFor = $this->add('select', 'used_for', ts('Used For'),
-        CRM_Core_OptionGroup::values('tag_used_for')
-      );
-      $usedFor->setMultiple(TRUE);
+      $usedFor = $this->addSelect('used_for', array('multiple' => TRUE, 'option_url' => NULL));
 
       if ($this->_id &&
         CRM_Core_DAO::getFieldValue('CRM_Core_DAO_Tag', $this->_id, 'parent_id')
@@ -131,8 +117,8 @@ class CRM_Admin_Form_Tag extends CRM_Admin_Form {
       }
       $this->assign('adminReservedTags', $adminReservedTags);
 
-      parent::buildQuickForm();
     }
+    parent::buildQuickForm();
   }
 
   /**
@@ -176,6 +162,6 @@ class CRM_Admin_Form_Tag extends CRM_Admin_Form {
       CRM_Core_Session::setStatus(ts('The tag \'%1\' has been saved.', array(1 => $tag->name)), ts('Saved'), 'success');
     }
   }
-  //end of function
+
 }