3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2017 |
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-2017
36 * This class contains all case related functions that are called using AJAX
38 class CRM_Case_Page_AJAX
{
41 * @throws \CRM_Core_Exception
43 public function processCaseTags() {
45 $caseId = CRM_Utils_Type
::escape($_POST['case_id'], 'Positive');
46 $tags = CRM_Utils_Type
::escape($_POST['tag'], 'String');
47 $tagList = $_POST['taglist'];
49 if (!CRM_Case_BAO_Case
::accessCase($caseId)) {
50 CRM_Utils_System
::permissionDenied();
55 $tagIds = explode(',', $tags);
59 'entity_id' => $caseId,
60 'entity_table' => 'civicrm_case',
63 CRM_Core_BAO_EntityTag
::del($params);
65 foreach ($tagIds as $tagid) {
66 if (is_numeric($tagid)) {
67 $params['tag_id'] = $tagid;
68 CRM_Core_BAO_EntityTag
::add($params);
72 if (!empty($tagList)) {
73 CRM_Core_Form_Tag
::postProcess($tagList, $caseId, 'civicrm_case');
76 $session = CRM_Core_Session
::singleton();
78 $activityParams = array();
79 $activityParams['source_contact_id'] = $session->get('userID');
80 $activityParams['activity_type_id'] = CRM_Core_OptionGroup
::getValue('activity_type', 'Change Case Tags', 'name');
81 $activityParams['activity_date_time'] = date('YmdHis');
82 $activityParams['status_id'] = CRM_Core_OptionGroup
::getValue('activity_status', 'Completed', 'name');
83 $activityParams['case_id'] = $caseId;
84 $activityParams['is_auto'] = 0;
85 $activityParams['subject'] = 'Change Case Tags';
87 $activity = CRM_Activity_BAO_Activity
::create($activityParams);
90 'activity_id' => $activity->id
,
94 CRM_Case_BAO_Case
::processCaseActivity($caseParams);
97 CRM_Utils_System
::civiExit();
101 * @throws \CiviCRM_API3_Exception
103 public function caseDetails() {
104 $caseId = CRM_Utils_Type
::escape($_GET['caseId'], 'Positive');
106 $case = civicrm_api3('Case', 'getsingle', array(
108 'check_permissions' => TRUE,
109 'return' => array('subject', 'case_type_id', 'status_id', 'start_date', 'end_date'))
112 $caseStatuses = CRM_Case_PseudoConstant
::caseStatus();
113 $caseTypes = CRM_Case_PseudoConstant
::caseType('title', FALSE);
114 $caseDetails = "<table><tr><td>" . ts('Case Subject') . "</td><td>{$case['subject']}</td></tr>
115 <tr><td>" . ts('Case Type') . "</td><td>{$caseTypes[$case['case_type_id']]}</td></tr>
116 <tr><td>" . ts('Case Status') . "</td><td>{$caseStatuses[$case['status_id']]}</td></tr>
117 <tr><td>" . ts('Case Start Date') . "</td><td>" . CRM_Utils_Date
::customFormat($case['start_date']) . "</td></tr>
118 <tr><td>" . ts('Case End Date') . "</td><td></td></tr>" . CRM_Utils_Date
::customFormat($case['end_date']) . "</table>";
120 if (CRM_Utils_Array
::value('snippet', $_GET) == 'json') {
121 CRM_Core_Page_AJAX
::returnJsonResponse($caseDetails);
125 CRM_Utils_System
::civiExit();
129 * @throws \CRM_Core_Exception
131 public function addClient() {
132 $caseId = CRM_Utils_Type
::escape($_POST['caseID'], 'Positive');
133 $contactId = CRM_Utils_Type
::escape($_POST['contactID'], 'Positive');
135 if (!$contactId ||
!CRM_Case_BAO_Case
::accessCase($caseId)) {
136 CRM_Utils_System
::permissionDenied();
140 'case_id' => $caseId,
141 'contact_id' => $contactId,
144 CRM_Case_BAO_CaseContact
::create($params);
146 // add case relationships
147 CRM_Case_BAO_Case
::addCaseRelationships($caseId, $contactId);
149 $session = CRM_Core_Session
::singleton();
151 $activityParams = array();
152 $activityParams['source_contact_id'] = $session->get('userID');
153 $activityParams['activity_type_id'] = CRM_Core_OptionGroup
::getValue('activity_type', 'Add Client To Case', 'name');
154 $activityParams['activity_date_time'] = date('YmdHis');
155 $activityParams['status_id'] = CRM_Core_OptionGroup
::getValue('activity_status', 'Completed', 'name');
156 $activityParams['case_id'] = $caseId;
157 $activityParams['is_auto'] = 0;
158 $activityParams['subject'] = 'Client Added To Case';
160 $activity = CRM_Activity_BAO_Activity
::create($activityParams);
163 'activity_id' => $activity->id
,
164 'case_id' => $caseId,
167 CRM_Case_BAO_Case
::processCaseActivity($caseParams);
168 CRM_Utils_JSON
::output(TRUE);
172 * Delete relationships specific to case and relationship type.
174 public static function deleteCaseRoles() {
175 $caseId = CRM_Utils_Type
::escape($_POST['case_id'], 'Positive');
176 $cid = CRM_Utils_Type
::escape($_POST['cid'], 'Positive');
177 $relType = CRM_Utils_Request
::retrieve('rel_type', 'String', CRM_Core_DAO
::$_nullObject, TRUE);
179 if (!$cid ||
!CRM_Case_BAO_Case
::accessCase($caseId)) {
180 CRM_Utils_System
::permissionDenied();
183 list($relTypeId, $a, $b) = explode('_', $relType);
185 CRM_Case_BAO_Case
::endCaseRole($caseId, $b, $cid, $relTypeId);
186 CRM_Utils_System
::civiExit();