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() {
45 'limit' => CRM_Core_BAO_Setting
::getItem(CRM_Core_BAO_Setting
::SYSTEM_PREFERENCES_NAME
, 'search_autocomplete_count', NULL, 10),
46 'sort_name' => CRM_Utils_Type
::escape(CRM_Utils_Array
::value('term', $_GET, ''), 'String'),
49 $excludeCaseIds = array();
50 if (!empty($_GET['excludeCaseIds'])) {
51 $excludeCaseIds = explode(',', CRM_Utils_Type
::escape($_GET['excludeCaseIds'], 'String'));
53 $unclosedCases = CRM_Case_BAO_Case
::getUnclosedCases($params, $excludeCaseIds);
55 foreach ($unclosedCases as $caseId => $details) {
58 'text' => $details['sort_name'] . ' (' . $details['case_type'] . ': ' . $details['case_subject'] . ')',
62 print json_encode($results);
63 CRM_Utils_System
::civiExit();
66 function processCaseTags() {
68 $caseId = CRM_Utils_Type
::escape($_POST['case_id'], 'Integer');
69 $tags = CRM_Utils_Type
::escape($_POST['tag'], 'String');
70 $tagList = $_POST['taglist'];
74 CRM_Utils_System
::civiExit();
79 $tagIds = explode(',', $tags);
82 if (!empty($tagIds)) {
84 'entity_id' => $caseId,
85 'entity_table' => 'civicrm_case',
88 CRM_Core_BAO_EntityTag
::del($params);
90 foreach ($tagIds as $tagid) {
91 if (is_numeric($tagid)) {
92 $params['tag_id'] = $tagid;
93 CRM_Core_BAO_EntityTag
::add($params);
98 if (!empty($tagList)) {
99 CRM_Core_Form_Tag
::postProcess($tagList, $caseId, 'civicrm_case', CRM_Core_DAO
::$_nullObject);
102 $session = CRM_Core_Session
::singleton();
104 $activityParams = array();
105 $activityParams['source_contact_id'] = $session->get('userID');
106 $activityParams['activity_type_id'] = CRM_Core_OptionGroup
::getValue('activity_type', 'Change Case Tags', 'name');
107 $activityParams['activity_date_time'] = date('YmdHis');
108 $activityParams['status_id'] = CRM_Core_OptionGroup
::getValue('activity_status', 'Completed', 'name');
109 $activityParams['case_id'] = $caseId;
110 $activityParams['is_auto'] = 0;
111 $activityParams['subject'] = 'Change Case Tags';
113 $activity = CRM_Activity_BAO_Activity
::create($activityParams);
116 'activity_id' => $activity->id
,
117 'case_id' => $caseId,
120 CRM_Case_BAO_Case
::processCaseActivity($caseParams);
123 CRM_Utils_System
::civiExit();
126 function caseDetails() {
127 $caseId = CRM_Utils_Type
::escape($_GET['caseId'], 'Integer');
128 $sql = "SELECT * FROM civicrm_case where id = %1";
129 $dao = CRM_Core_DAO
::executeQuery($sql, array(1 => array($caseId, 'Integer')));
132 $caseType = CRM_Case_BAO_Case
::getCaseType((str_replace(CRM_Core_DAO
::VALUE_SEPARATOR
,
136 $caseStatuses = CRM_Case_PseudoConstant
::caseStatus();
137 $cs = $caseStatuses[$dao->status_id
];
138 $caseDetails = "<table><tr><td>" . ts('Case Subject') . "</td><td>{$dao->subject}</td></tr>
139 <tr><td>" . ts('Case Type') . "</td><td>{$caseType}</td></tr>
140 <tr><td>" . ts('Case Status') . "</td><td>{$cs}</td></tr>
141 <tr><td>" . ts('Case Start Date') . "</td><td>" . CRM_Utils_Date
::customFormat($dao->start_date
) . "</td></tr>
142 <tr><td>" . ts('Case End Date') . "</td><td></td></tr>" . CRM_Utils_Date
::customFormat($dao->end_date
) . "</table>";
146 echo ts('Could not find valid Case!');
148 CRM_Utils_System
::civiExit();
151 function addClient() {
152 $caseId = CRM_Utils_Type
::escape($_POST['caseID'], 'Integer');
153 $contactId = CRM_Utils_Type
::escape($_POST['contactID'], 'Integer');
156 'case_id' => $caseId,
157 'contact_id' => $contactId,
160 CRM_Case_BAO_Case
::addCaseToContact($params);
162 // add case relationships
163 CRM_Case_BAO_Case
::addCaseRelationships($caseId, $contactId);
165 $session = CRM_Core_Session
::singleton();
167 $activityParams = array();
168 $activityParams['source_contact_id'] = $session->get('userID');
169 $activityParams['activity_type_id'] = CRM_Core_OptionGroup
::getValue('activity_type', 'Add Client To Case', 'name');
170 $activityParams['activity_date_time'] = date('YmdHis');
171 $activityParams['status_id'] = CRM_Core_OptionGroup
::getValue('activity_status', 'Completed', 'name');
172 $activityParams['case_id'] = $caseId;
173 $activityParams['is_auto'] = 0;
174 $activityParams['subject'] = 'Client Added To Case';
176 $activity = CRM_Activity_BAO_Activity
::create($activityParams);
179 'activity_id' => $activity->id
,
180 'case_id' => $caseId,
183 CRM_Case_BAO_Case
::processCaseActivity($caseParams);
184 echo json_encode(TRUE);
185 CRM_Utils_System
::civiExit();
189 * Function to delete relationships specific to case and relationship type
191 static function deleteCaseRoles() {
192 $caseId = CRM_Utils_Type
::escape($_POST['case_id'], 'Integer');
193 $relType = CRM_Utils_Type
::escape($_POST['rel_type'], 'Integer');
195 $sql = "DELETE FROM civicrm_relationship WHERE case_id={$caseId} AND relationship_type_id={$relType}";
196 CRM_Core_DAO
::executeQuery($sql);
198 CRM_Utils_System
::civiExit();