3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.5 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
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. |
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. |
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 +--------------------------------------------------------------------+
31 * @copyright CiviCRM LLC (c) 2004-2014
37 * This class generates form components for Tag
40 class CRM_Admin_Form_Tag
extends CRM_Admin_Form
{
44 * Function to build the form
49 public function buildQuickForm() {
50 $this->setPageTitle($this->_isTagSet ?
ts('Tag Set') : ts('Tag'));
52 if ($this->_action
== CRM_Core_Action
::DELETE
) {
53 if ($this->_id
&& $tag = CRM_Core_DAO
::getFieldValue('CRM_Core_DAO_Tag', $this->_id
, 'name', 'parent_id')) {
54 $url = CRM_Utils_System
::url('civicrm/admin/tag', "reset=1");
55 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);
57 if ($this->_values
['is_reserved'] == 1 && !CRM_Core_Permission
::check('administer reserved tags')) {
58 CRM_Core_Error
::statusBounce(ts("You do not have sufficient permission to delete this reserved tag."));
62 $this->_isTagSet
= CRM_Utils_Request
::retrieve('tagset', 'Positive', $this);
64 if (!$this->_isTagSet
&&
66 CRM_Core_DAO
::getFieldValue('CRM_Core_DAO_Tag', $this->_id
, 'is_tagset')
68 $this->_isTagSet
= TRUE;
71 $allTag = array('' => ts('- select -')) + CRM_Core_BAO_Tag
::getTagsNotInTagset();
74 unset($allTag[$this->_id
]);
77 if (!$this->_isTagSet
) {
78 $this->add('select', 'parent_id', ts('Parent Tag'), $allTag, FALSE, array('class' => 'crm-select2'));
81 $this->assign('isTagSet', $this->_isTagSet
);
83 $this->applyFilter('__ALL__', 'trim');
85 $this->add('text', 'name', ts('Name'),
86 CRM_Core_DAO
::getAttribute('CRM_Core_DAO_Tag', 'name'), TRUE
88 $this->addRule('name', ts('Name already exists in Database.'), 'objectExists', array('CRM_Core_DAO_Tag', $this->_id
));
90 $this->add('text', 'description', ts('Description'),
91 CRM_Core_DAO
::getAttribute('CRM_Core_DAO_Tag', 'description')
94 //@lobo haven't a clue why the checkbox isn't displayed (it should be checked by default
95 $this->add('checkbox', 'is_selectable');
97 $isReserved = $this->add('checkbox', 'is_reserved', ts('Reserved?'));
99 $usedFor = $this->addSelect('used_for', array('multiple' => TRUE, 'option_url' => NULL));
102 CRM_Core_DAO
::getFieldValue('CRM_Core_DAO_Tag', $this->_id
, 'parent_id')
108 if (!CRM_Core_Permission
::check('administer Tagsets')) {
109 $adminTagset = FALSE;
111 $this->assign('adminTagset', $adminTagset);
113 $adminReservedTags = TRUE;
114 if (!CRM_Core_Permission
::check('administer reserved tags')) {
115 $isReserved->freeze();
116 $adminReservedTags = FALSE;
118 $this->assign('adminReservedTags', $adminReservedTags);
121 parent
::buildQuickForm();
125 * Function to process the form
131 public function postProcess() {
132 $params = $ids = array();
134 // store the submitted values in an array
135 $params = $this->exportValues();
137 $ids['tag'] = $this->_id
;
138 if ($this->_action
== CRM_Core_Action
::ADD ||
139 $this->_action
== CRM_Core_Action
::UPDATE
141 $params['used_for'] = implode(",", $params['used_for']);
144 $params['is_tagset'] = 0;
145 if ($this->_isTagSet
) {
146 $params['is_tagset'] = 1;
149 if (!isset($params['is_reserved'])) {
150 $params['is_reserved'] = 0;
153 if ($this->_action
== CRM_Core_Action
::DELETE
) {
154 if ($this->_id
> 0) {
155 $tag = civicrm_api3('tag', 'getsingle', array('id' => $this->_id
));
156 CRM_Core_BAO_Tag
::del($this->_id
);
157 CRM_Core_Session
::setStatus(ts('The tag \'%1\' has been deleted.', array(1 => $tag['name'])), ts('Deleted'), 'success');
161 $tag = CRM_Core_BAO_Tag
::add($params, $ids);
162 CRM_Core_Session
::setStatus(ts('The tag \'%1\' has been saved.', array(1 => $tag->name
)), ts('Saved'), 'success');