Commit | Line | Data |
---|---|---|
8ffdec17 ARW |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
4 | | CiviCRM version 4.5 | | |
5 | +--------------------------------------------------------------------+ | |
6 | | Copyright CiviCRM LLC (c) 2004-2014 | | |
7 | +--------------------------------------------------------------------+ | |
8 | | This file is a part of CiviCRM. | | |
9 | | | | |
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. | | |
13 | | | | |
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. | | |
18 | | | | |
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 | +--------------------------------------------------------------------+ | |
26 | */ | |
27 | ||
28 | /** | |
29 | * | |
30 | * @package CRM | |
31 | * @copyright CiviCRM LLC (c) 2004-2014 | |
32 | * $Id$ | |
33 | * | |
34 | */ | |
35 | ||
36 | /** | |
37 | * This class generates form components for Case Type | |
38 | * | |
39 | */ | |
40 | class CRM_Admin_Form_CaseType extends CRM_Admin_Form { | |
41 | ||
42 | /** | |
43 | * Function to build the form | |
44 | * | |
45 | * @return void | |
46 | * @access public | |
47 | */ | |
48 | public function buildQuickForm() { | |
49 | parent::buildQuickForm(); | |
50 | if ($this->_action & CRM_Core_Action::DELETE) { | |
51 | return; | |
52 | } | |
53 | $this->applyFilter('__ALL__', 'trim'); | |
54 | $this->add('text', 'title', ts('Name'), | |
55 | CRM_Core_DAO::getAttribute('CRM_Case_DAO_CaseType', 'title'), | |
56 | TRUE | |
57 | ); | |
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') | |
61 | ); | |
62 | ||
63 | $this->assign('cid', $this->_id); | |
64 | $this->addFormRule(array('CRM_Admin_Form_CaseType', 'formRule'), $this); | |
65 | } | |
66 | ||
67 | /** | |
68 | * global form rule | |
69 | * | |
77b97be7 EM |
70 | * @param array $fields the input form values |
71 | * | |
72 | * @param $files | |
73 | * @param $self | |
8ffdec17 ARW |
74 | * |
75 | * @return true if no errors, else array of errors | |
76 | * @access public | |
77 | * @static | |
78 | */ | |
79 | static function formRule($fields, $files, $self) { | |
80 | ||
81 | $errors = array(); | |
82 | ||
83 | if ($self->_id) { | |
84 | $caseName = CRM_Core_DAO::getFieldValue('CRM_Case_DAO_CaseType', $self->_id, 'name'); | |
85 | } | |
86 | else { | |
87 | $caseName = ucfirst(CRM_Utils_String::munge($fields['title'])); | |
88 | } | |
89 | ||
90 | if (!CRM_Core_DAO::objectExists($caseName, 'CRM_Case_DAO_CaseType', $self->_id)) { | |
91 | $errors['title'] = ts('This case type name already exists in database. Case type names must be unique.'); | |
92 | } | |
93 | ||
94 | $reservedKeyWords = CRM_Core_SelectValues::customGroupExtends(); | |
95 | //restrict "name" from being a reserved keyword when a new contact subtype is created | |
96 | if (!$self->_id && in_array($caseName, array_keys($reservedKeyWords))) { | |
97 | $errors['title'] = ts('Case Type names should not use reserved keywords.'); | |
98 | } | |
99 | return empty($errors) ? TRUE : $errors; | |
100 | } | |
101 | ||
102 | /** | |
103 | * Function to process the form | |
104 | * | |
105 | * @access public | |
106 | * | |
107 | * @return void | |
108 | */ | |
109 | public function postProcess() { | |
110 | CRM_Utils_System::flushCache(); | |
111 | ||
112 | if ($this->_action & CRM_Core_Action::DELETE) { | |
113 | $isDelete = CRM_Case_BAO_CaseType::del($this->_id); | |
114 | if ($isDelete) { | |
115 | CRM_Core_Session::setStatus(ts('Selected case type has been deleted.'), ts('Record Deleted'), 'success'); | |
116 | } | |
117 | else { | |
118 | CRM_Core_Session::setStatus(ts("Selected case type can not be deleted."), ts('Sorry'), 'error'); | |
119 | } | |
120 | return; | |
121 | } | |
122 | // store the submitted values in an array | |
123 | $params = $this->exportValues(); | |
124 | ||
125 | if ($this->_action & CRM_Core_Action::ADD) { | |
126 | $params['name'] = ucfirst(CRM_Utils_String::munge($params['title'])); | |
127 | } else { | |
128 | $params['id'] = $this->_id; | |
129 | $params['name'] = CRM_Core_DAO::getFieldValue('CRM_Case_DAO_CaseType', $this->_id, 'name'); | |
130 | } | |
131 | $caseType = CRM_Case_BAO_CaseType::add($params); | |
132 | CRM_Core_Session::setStatus(ts("The Case Type '%1' has been saved.", | |
133 | array(1 => $caseType->title) | |
134 | ), ts('Saved'), 'success'); | |
135 | } | |
136 | } | |
137 |