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 Case Type
40 class CRM_Admin_Form_CaseType
extends CRM_Admin_Form
{
43 * Function to build the form
48 public function buildQuickForm() {
49 parent
::buildQuickForm();
50 if ($this->_action
& CRM_Core_Action
::DELETE
) {
53 $this->applyFilter('__ALL__', 'trim');
54 $this->add('text', 'title', ts('Name'),
55 CRM_Core_DAO
::getAttribute('CRM_Case_DAO_CaseType', 'title'),
58 $enabled = $this->add('checkbox', 'is_active', ts('Enabled?'));
59 $this->add('text', 'description', ts('Description'),
60 CRM_Core_DAO
::getAttribute('CRM_Case_DAO_CaseType', 'description')
63 $this->assign('cid', $this->_id
);
64 $this->addFormRule(array('CRM_Admin_Form_CaseType', 'formRule'), $this);
70 * @param array $fields the input form values
72 * @return true if no errors, else array of errors
76 static function formRule($fields, $files, $self) {
81 $caseName = CRM_Core_DAO
::getFieldValue('CRM_Case_DAO_CaseType', $self->_id
, 'name');
84 $caseName = ucfirst(CRM_Utils_String
::munge($fields['title']));
87 if (!CRM_Core_DAO
::objectExists($caseName, 'CRM_Case_DAO_CaseType', $self->_id
)) {
88 $errors['title'] = ts('This case type name already exists in database. Case type names must be unique.');
91 $reservedKeyWords = CRM_Core_SelectValues
::customGroupExtends();
92 //restrict "name" from being a reserved keyword when a new contact subtype is created
93 if (!$self->_id
&& in_array($caseName, array_keys($reservedKeyWords))) {
94 $errors['title'] = ts('Case Type names should not use reserved keywords.');
96 return empty($errors) ?
TRUE : $errors;
100 * Function to process the form
106 public function postProcess() {
107 CRM_Utils_System
::flushCache();
109 if ($this->_action
& CRM_Core_Action
::DELETE
) {
110 $isDelete = CRM_Case_BAO_CaseType
::del($this->_id
);
112 CRM_Core_Session
::setStatus(ts('Selected case type has been deleted.'), ts('Record Deleted'), 'success');
115 CRM_Core_Session
::setStatus(ts("Selected case type can not be deleted."), ts('Sorry'), 'error');
119 // store the submitted values in an array
120 $params = $this->exportValues();
122 if ($this->_action
& CRM_Core_Action
::ADD
) {
123 $params['name'] = ucfirst(CRM_Utils_String
::munge($params['title']));
125 $params['id'] = $this->_id
;
126 $params['name'] = CRM_Core_DAO
::getFieldValue('CRM_Case_DAO_CaseType', $this->_id
, 'name');
128 $caseType = CRM_Case_BAO_CaseType
::add($params);
129 CRM_Core_Session
::setStatus(ts("The Case Type '%1' has been saved.",
130 array(1 => $caseType->title
)
131 ), ts('Saved'), 'success');