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
36 * This class contains all case related functions that are called using AJAX (jQuery)
38 class CRM_Case_Page_AJAX
{
41 * Retrieve unclosed cases.
43 static function unclosedCases() {
44 $criteria = explode('-', CRM_Utils_Type
::escape(CRM_Utils_Array
::value('s', $_GET), 'String'));
46 $limit = CRM_Utils_Array
::value('limit', $_GET);
48 $limit = CRM_Utils_Type
::escape($limit, 'Integer');
53 'case_type' => trim(CRM_Utils_Array
::value(1, $criteria)),
54 'sort_name' => trim(CRM_Utils_Array
::value(0, $criteria)),
57 $excludeCaseIds = array();
58 if ($caseIdStr = CRM_Utils_Array
::value('excludeCaseIds', $_GET)) {
59 $excludeIdStr = CRM_Utils_Type
::escape($caseIdStr, 'String');
60 $excludeCaseIds = explode(',', $excludeIdStr);
62 $unclosedCases = CRM_Case_BAO_Case
::getUnclosedCases($params, $excludeCaseIds);
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";
68 CRM_Utils_System
::civiExit();
71 function processCaseTags() {
73 $caseId = CRM_Utils_Type
::escape($_POST['case_id'], 'Integer');
74 $tags = CRM_Utils_Type
::escape($_POST['tag'], 'String');
75 $tagList = $_POST['taglist'];
79 CRM_Utils_System
::civiExit();
84 $tagIds = explode(',', $tags);
87 if (!empty($tagIds)) {
89 'entity_id' => $caseId,
90 'entity_table' => 'civicrm_case',
93 CRM_Core_BAO_EntityTag
::del($params);
95 foreach ($tagIds as $tagid) {
96 if (is_numeric($tagid)) {
97 $params['tag_id'] = $tagid;
98 CRM_Core_BAO_EntityTag
::add($params);
103 if (!empty($tagList)) {
104 CRM_Core_Form_Tag
::postProcess($tagList, $caseId, 'civicrm_case', CRM_Core_DAO
::$_nullObject);
107 $session = CRM_Core_Session
::singleton();
109 $activityParams = array();
110 $activityParams['source_contact_id'] = $session->get('userID');
111 $activityParams['activity_type_id'] = CRM_Core_OptionGroup
::getValue('activity_type', 'Change Case Tags', 'name');
112 $activityParams['activity_date_time'] = date('YmdHis');
113 $activityParams['status_id'] = CRM_Core_OptionGroup
::getValue('activity_status', 'Completed', 'name');
114 $activityParams['case_id'] = $caseId;
115 $activityParams['is_auto'] = 0;
116 $activityParams['subject'] = 'Change Case Tags';
118 $activity = CRM_Activity_BAO_Activity
::create($activityParams);
121 'activity_id' => $activity->id
,
122 'case_id' => $caseId,
125 CRM_Case_BAO_Case
::processCaseActivity($caseParams);
128 CRM_Utils_System
::civiExit();
131 function caseDetails() {
132 $caseId = CRM_Utils_Type
::escape($_GET['caseId'], 'Integer');
133 $sql = "SELECT * FROM civicrm_case where id = %1";
134 $dao = CRM_Core_DAO
::executeQuery($sql, array(1 => array($caseId, 'Integer')));
137 $caseType = CRM_Case_BAO_Case
::getCaseType((str_replace(CRM_Core_DAO
::VALUE_SEPARATOR
,
141 $caseStatuses = CRM_Case_PseudoConstant
::caseStatus();
142 $cs = $caseStatuses[$dao->status_id
];
143 $caseDetails = "<table><tr><td>" . ts('Case Subject') . "</td><td>{$dao->subject}</td></tr>
144 <tr><td>" . ts('Case Type') . "</td><td>{$caseType}</td></tr>
145 <tr><td>" . ts('Case Status') . "</td><td>{$cs}</td></tr>
146 <tr><td>" . ts('Case Start Date') . "</td><td>" . CRM_Utils_Date
::customFormat($dao->start_date
) . "</td></tr>
147 <tr><td>" . ts('Case End Date') . "</td><td></td></tr>" . CRM_Utils_Date
::customFormat($dao->end_date
) . "</table>";
151 echo ts('Could not find valid Case!');
153 CRM_Utils_System
::civiExit();
156 function addClient() {
157 $caseId = CRM_Utils_Type
::escape($_POST['caseID'], 'Integer');
158 $contactId = CRM_Utils_Type
::escape($_POST['contactID'], 'Integer');
161 'case_id' => $caseId,
162 'contact_id' => $contactId,
165 CRM_Case_BAO_Case
::addCaseToContact($params);
167 // add case relationships
168 CRM_Case_BAO_Case
::addCaseRelationships($caseId, $contactId);
170 $session = CRM_Core_Session
::singleton();
172 $activityParams = array();
173 $activityParams['source_contact_id'] = $session->get('userID');
174 $activityParams['activity_type_id'] = CRM_Core_OptionGroup
::getValue('activity_type', 'Add Client To Case', 'name');
175 $activityParams['activity_date_time'] = date('YmdHis');
176 $activityParams['status_id'] = CRM_Core_OptionGroup
::getValue('activity_status', 'Completed', 'name');
177 $activityParams['case_id'] = $caseId;
178 $activityParams['is_auto'] = 0;
179 $activityParams['subject'] = 'Client Added To Case';
181 $activity = CRM_Activity_BAO_Activity
::create($activityParams);
184 'activity_id' => $activity->id
,
185 'case_id' => $caseId,
188 CRM_Case_BAO_Case
::processCaseActivity($caseParams);
189 echo json_encode(TRUE);
190 CRM_Utils_System
::civiExit();
194 * Function to delete relationships specific to case and relationship type
196 static function deleteCaseRoles() {
197 $caseId = CRM_Utils_Type
::escape($_POST['case_id'], 'Integer');
198 $relType = CRM_Utils_Type
::escape($_POST['rel_type'], 'Integer');
200 $sql = "DELETE FROM civicrm_relationship WHERE case_id={$caseId} AND relationship_type_id={$relType}";
201 CRM_Core_DAO
::executeQuery($sql);
203 CRM_Utils_System
::civiExit();