Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
232624b1 | 4 | | CiviCRM version 4.4 | |
6a488035 TO |
5 | +--------------------------------------------------------------------+ |
6 | | Copyright CiviCRM LLC (c) 2004-2013 | | |
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-2013 | |
32 | * | |
33 | */ | |
34 | ||
35 | /** | |
36 | * This class contains all case related functions that are called using AJAX (jQuery) | |
37 | */ | |
38 | class CRM_Case_Page_AJAX { | |
39 | ||
40 | /** | |
41 | * Retrieve unclosed cases. | |
42 | */ | |
43 | static function unclosedCases() { | |
44 | $criteria = explode('-', CRM_Utils_Type::escape(CRM_Utils_Array::value('s', $_GET), 'String')); | |
45 | ||
46 | $limit = NULL; | |
47 | if ($limit = CRM_Utils_Array::value('limit', $_GET)) { | |
48 | $limit = CRM_Utils_Type::escape($limit, 'Integer'); | |
49 | } | |
50 | ||
51 | $params = array( | |
52 | 'limit' => $limit, | |
53 | 'case_type' => trim(CRM_Utils_Array::value(1, $criteria)), | |
54 | 'sort_name' => trim(CRM_Utils_Array::value(0, $criteria)), | |
55 | ); | |
56 | ||
57 | $excludeCaseIds = array(); | |
58 | if ($caseIdStr = CRM_Utils_Array::value('excludeCaseIds', $_GET)) { | |
59 | $excludeIdStr = CRM_Utils_Type::escape($caseIdStr, 'String'); | |
60 | $excludeCaseIds = explode(',', $excludeIdStr); | |
61 | } | |
62 | $unclosedCases = CRM_Case_BAO_Case::getUnclosedCases($params, $excludeCaseIds); | |
63 | ||
64 | foreach ($unclosedCases as $caseId => $details) { | |
65 | echo $details['sort_name'] . ' (' . $details['case_type'] . ': ' . $details['case_subject'] . ') ' . "|$caseId|" . $details['contact_id'] . '|' . $details['case_type'] . '|' . $details['sort_name'] . "\n"; | |
66 | } | |
67 | ||
68 | CRM_Utils_System::civiExit(); | |
69 | } | |
70 | ||
71 | function processCaseTags() { | |
72 | ||
73 | $caseId = CRM_Utils_Type::escape($_POST['case_id'], 'Integer'); | |
74 | $tags = CRM_Utils_Type::escape($_POST['tag'], 'String'); | |
75 | ||
76 | if (empty($caseId)) { | |
77 | echo 'false'; | |
78 | CRM_Utils_System::civiExit(); | |
79 | } | |
80 | ||
81 | $tagIds = array(); | |
82 | if ($tags) { | |
83 | $tagIds = explode(',', $tags); | |
84 | } | |
85 | ||
86 | $params = array( | |
87 | 'entity_id' => $caseId, | |
88 | 'entity_table' => 'civicrm_case', | |
89 | ); | |
90 | ||
91 | CRM_Core_BAO_EntityTag::del($params); | |
92 | ||
93 | foreach ($tagIds as $tagid) { | |
94 | if (is_numeric($tagid)) { | |
95 | $params['tag_id'] = $tagid; | |
96 | CRM_Core_BAO_EntityTag::add($params); | |
97 | } | |
98 | } | |
99 | ||
100 | $session = CRM_Core_Session::singleton(); | |
101 | ||
102 | $activityParams = array(); | |
103 | $activityParams['source_contact_id'] = $session->get('userID'); | |
104 | $activityParams['activity_type_id'] = CRM_Core_OptionGroup::getValue('activity_type', 'Change Case Tags', 'name'); | |
105 | $activityParams['activity_date_time'] = date('YmdHis'); | |
106 | $activityParams['status_id'] = CRM_Core_OptionGroup::getValue('activity_status', 'Completed', 'name'); | |
107 | $activityParams['case_id'] = $caseId; | |
108 | $activityParams['is_auto'] = 0; | |
109 | $activityParams['subject'] = 'Change Case Tags'; | |
110 | ||
111 | $activity = CRM_Activity_BAO_Activity::create($activityParams); | |
112 | ||
113 | $caseParams = array( | |
114 | 'activity_id' => $activity->id, | |
115 | 'case_id' => $caseId, | |
116 | ); | |
117 | ||
118 | CRM_Case_BAO_Case::processCaseActivity($caseParams); | |
119 | ||
120 | echo 'true'; | |
121 | CRM_Utils_System::civiExit(); | |
122 | } | |
123 | ||
124 | function caseDetails() { | |
125 | $caseId = CRM_Utils_Type::escape($_GET['caseId'], 'Integer'); | |
126 | $sql = "SELECT * FROM civicrm_case where id = %1"; | |
127 | $dao = CRM_Core_DAO::executeQuery($sql, array(1 => array($caseId, 'Integer'))); | |
128 | ||
129 | if ($dao->fetch()) { | |
130 | $caseType = CRM_Case_BAO_Case::getCaseType((str_replace(CRM_Core_DAO::VALUE_SEPARATOR, | |
131 | "", | |
132 | $dao->case_type_id | |
133 | ))); | |
134 | $caseStatuses = CRM_Case_PseudoConstant::caseStatus(); | |
135 | $cs = $caseStatuses[$dao->status_id]; | |
136 | $caseDetails = "<table><tr><td>" . ts('Case Subject') . "</td><td>{$dao->subject}</td></tr> | |
8ef12e64 | 137 | <tr><td>" . ts('Case Type') . "</td><td>{$caseType}</td></tr> |
6a488035 TO |
138 | <tr><td>" . ts('Case Status') . "</td><td>{$cs}</td></tr> |
139 | <tr><td>" . ts('Case Start Date') . "</td><td>" . CRM_Utils_Date::customFormat($dao->start_date) . "</td></tr> | |
140 | <tr><td>" . ts('Case End Date') . "</td><td></td></tr>" . CRM_Utils_Date::customFormat($dao->end_date) . "</table>"; | |
141 | echo $caseDetails; | |
142 | } | |
143 | else { | |
144 | echo ts('Could not find valid Case!'); | |
145 | } | |
146 | CRM_Utils_System::civiExit(); | |
147 | } | |
148 | ||
149 | function addClient() { | |
150 | $caseId = CRM_Utils_Type::escape($_POST['caseID'], 'Integer'); | |
151 | $contactId = CRM_Utils_Type::escape($_POST['contactID'], 'Integer'); | |
152 | ||
153 | $params = array( | |
154 | 'case_id' => $caseId, | |
155 | 'contact_id' => $contactId, | |
156 | ); | |
157 | ||
158 | CRM_Case_BAO_Case::addCaseToContact($params); | |
159 | ||
44466d80 KJ |
160 | // add case relationships |
161 | CRM_Case_BAO_Case::addCaseRelationships($caseId, $contactId); | |
162 | ||
6a488035 TO |
163 | $session = CRM_Core_Session::singleton(); |
164 | ||
165 | $activityParams = array(); | |
166 | $activityParams['source_contact_id'] = $session->get('userID'); | |
167 | $activityParams['activity_type_id'] = CRM_Core_OptionGroup::getValue('activity_type', 'Add Client To Case', 'name'); | |
168 | $activityParams['activity_date_time'] = date('YmdHis'); | |
169 | $activityParams['status_id'] = CRM_Core_OptionGroup::getValue('activity_status', 'Completed', 'name'); | |
170 | $activityParams['case_id'] = $caseId; | |
171 | $activityParams['is_auto'] = 0; | |
172 | $activityParams['subject'] = 'Client Added To Case'; | |
173 | ||
174 | $activity = CRM_Activity_BAO_Activity::create($activityParams); | |
175 | ||
176 | $caseParams = array( | |
177 | 'activity_id' => $activity->id, | |
178 | 'case_id' => $caseId, | |
179 | ); | |
180 | ||
181 | CRM_Case_BAO_Case::processCaseActivity($caseParams); | |
182 | echo json_encode(TRUE); | |
183 | CRM_Utils_System::civiExit(); | |
184 | } | |
4cd35744 KJ |
185 | |
186 | /** | |
187 | * Function to delete relationships specific to case and relationship type | |
188 | */ | |
189 | static function deleteCaseRoles() { | |
190 | $caseId = CRM_Utils_Type::escape($_POST['case_id'], 'Integer'); | |
191 | $relType = CRM_Utils_Type::escape($_POST['rel_type'], 'Integer'); | |
192 | ||
193 | $sql = "DELETE FROM civicrm_relationship WHERE case_id={$caseId} AND relationship_type_id={$relType}"; | |
194 | CRM_Core_DAO::executeQuery($sql); | |
195 | ||
196 | CRM_Utils_System::civiExit(); | |
197 | } | |
6a488035 TO |
198 | } |
199 |