3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.4 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2013 |
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-2013
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 if ($this->_action
== CRM_Core_Action
::DELETE
) {
51 if ($this->_id
&& $tag = CRM_Core_DAO
::getFieldValue('CRM_Core_DAO_Tag', $this->_id
, 'name', 'parent_id')) {
52 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');
53 $url = CRM_Utils_System
::url('civicrm/admin/tag', "reset=1");
54 CRM_Utils_System
::redirect($url);
58 $this->addButtons(array(
61 'name' => ts('Delete'),
66 'name' => ts('Cancel'),
73 $this->_isTagSet
= CRM_Utils_Request
::retrieve('tagset', 'Positive', $this);
75 if (!$this->_isTagSet
&&
77 CRM_Core_DAO
::getFieldValue('CRM_Core_DAO_Tag', $this->_id
, 'is_tagset')
79 $this->_isTagSet
= TRUE;
82 $allTag = array('' => '- ' . ts('select') . ' -') + CRM_Core_BAO_Tag
::getTagsNotInTagset();
85 unset($allTag[$this->_id
]);
88 if (!$this->_isTagSet
) {
89 $this->add('select', 'parent_id', ts('Parent Tag'), $allTag);
92 $this->assign('isTagSet', $this->_isTagSet
);
94 $this->applyFilter('__ALL__', 'trim');
96 $this->add('text', 'name', ts('Name'),
97 CRM_Core_DAO
::getAttribute('CRM_Core_DAO_Tag', 'name'), TRUE
99 $this->addRule('name', ts('Name already exists in Database.'), 'objectExists', array('CRM_Core_DAO_Tag', $this->_id
));
101 $this->add('text', 'description', ts('Description'),
102 CRM_Core_DAO
::getAttribute('CRM_Core_DAO_Tag', 'description')
105 //@lobo haven't a clue why the checkbox isn't displayed (it should be checked by default
106 $this->add('checkbox', 'is_selectable', ts("If it's a tag or a category"));
108 $isReserved = $this->add('checkbox', 'is_reserved', ts('Reserved?'));
110 $usedFor = $this->add('select', 'used_for', ts('Used For'),
111 CRM_Core_OptionGroup
::values('tag_used_for')
113 $usedFor->setMultiple(TRUE);
116 CRM_Core_DAO
::getFieldValue('CRM_Core_DAO_Tag', $this->_id
, 'parent_id')
122 if (!CRM_Core_Permission
::check('administer Tagsets')) {
123 $adminTagset = FALSE;
125 $this->assign('adminTagset', $adminTagset);
127 $adminReservedTags = TRUE;
128 if (!CRM_Core_Permission
::check('administer reserved tags')) {
129 $isReserved->freeze();
130 $adminReservedTags = FALSE;
132 $this->assign('adminReservedTags', $adminReservedTags);
134 parent
::buildQuickForm();
139 * Function to process the form
145 public function postProcess() {
146 $params = $ids = array();
148 // store the submitted values in an array
149 $params = $this->exportValues();
151 $ids['tag'] = $this->_id
;
152 if ($this->_action
== CRM_Core_Action
::ADD ||
153 $this->_action
== CRM_Core_Action
::UPDATE
155 $params['used_for'] = implode(",", $params['used_for']);
158 $params['is_tagset'] = 0;
159 if ($this->_isTagSet
) {
160 $params['is_tagset'] = 1;
163 if (!isset($params['is_reserved'])) {
164 $params['is_reserved'] = 0;
167 if ($this->_action
== CRM_Core_Action
::DELETE
) {
168 if ($this->_id
> 0) {
169 $tag = civicrm_api3('tag', 'getsingle', array('id' => $this->_id
));
170 CRM_Core_BAO_Tag
::del($this->_id
);
171 CRM_Core_Session
::setStatus(ts('The tag \'%1\' has been deleted.', array(1 => $tag['name'])), ts('Deleted'), 'success');
175 $tag = CRM_Core_BAO_Tag
::add($params, $ids);
176 CRM_Core_Session
::setStatus(ts('The tag \'%1\' has been saved.', array(1 => $tag->name
)), ts('Saved'), 'success');