PageRenderTime 38ms CodeModel.GetById 10ms RepoModel.GetById 0ms app.codeStats 0ms

/public_html/sites/all/modules/civicrm/CRM/Case/Page/AJAX.php

https://github.com/timstephenson/NatureBridge
PHP | 192 lines | 118 code | 37 blank | 37 comment | 7 complexity | f1bafa736bbe44915b3223a73419befb MD5 | raw file
  1. <?php
  2. /*
  3. +--------------------------------------------------------------------+
  4. | CiviCRM version 4.0 |
  5. +--------------------------------------------------------------------+
  6. | Copyright CiviCRM LLC (c) 2004-2011 |
  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. * @package CRM
  30. * @copyright CiviCRM LLC (c) 2004-2011
  31. *
  32. */
  33. require_once 'CRM/Utils/Type.php';
  34. /**
  35. * This class contains all case related functions that are called using AJAX (jQuery)
  36. */
  37. class CRM_Case_Page_AJAX
  38. {
  39. /**
  40. * Retrieve unclosed cases.
  41. */
  42. static function unclosedCases( )
  43. {
  44. $criteria = explode( '-', CRM_Utils_Type::escape( CRM_Utils_Array::value( 's', $_GET ), 'String' ) );
  45. $limit = null;
  46. if ( $limit = CRM_Utils_Array::value( 'limit', $_GET ) ) {
  47. $limit = CRM_Utils_Type::escape( $limit, 'Integer' );
  48. }
  49. $params = array( 'limit' => $limit,
  50. 'case_type' => trim( CRM_Utils_Array::value( 1, $criteria ) ),
  51. 'sort_name' => trim( CRM_Utils_Array::value( 0, $criteria ) ) );
  52. $excludeCaseIds = array( );
  53. if ( $caseIdStr = CRM_Utils_Array::value( 'excludeCaseIds', $_GET ) ) {
  54. $excludeIdStr = CRM_Utils_Type::escape( $caseIdStr, 'String' );
  55. $excludeCaseIds = explode( ',', $excludeIdStr );
  56. }
  57. require_once 'CRM/Case/BAO/Case.php';
  58. $unclosedCases = CRM_Case_BAO_Case::getUnclosedCases( $params, $excludeCaseIds );
  59. foreach ( $unclosedCases as $caseId => $details ) {
  60. echo $details['sort_name'].' - '.$details['case_type']."|$caseId|".$details['contact_id'].'|'.$details['case_type'].'|'.$details['sort_name']."\n";
  61. }
  62. CRM_Utils_System::civiExit( );
  63. }
  64. function processCaseTags( ) {
  65. require_once 'CRM/Core/BAO/EntityTag.php';
  66. $caseId = CRM_Utils_Type::escape($_POST['case_id'], 'Integer');
  67. $tags = CRM_Utils_Type::escape($_POST['tag'], 'String');
  68. if ( empty($caseId) ) {
  69. echo 'false';
  70. CRM_Utils_System::civiExit( );
  71. }
  72. $tagIds = array( );
  73. if ( $tags ) {
  74. $tagIds = explode( ',', $tags );
  75. }
  76. $params = array( 'entity_id' => $caseId,
  77. 'entity_table' => 'civicrm_case' );
  78. CRM_Core_BAO_EntityTag::del( $params );
  79. foreach( $tagIds as $tagid ) {
  80. if ( is_numeric( $tagid ) ) {
  81. $params['tag_id'] = $tagid;
  82. CRM_Core_BAO_EntityTag::add( $params );
  83. }
  84. }
  85. $session =& CRM_Core_Session::singleton( );
  86. require_once "CRM/Activity/BAO/Activity.php";
  87. require_once "CRM/Core/OptionGroup.php";
  88. $activityParams = array( );
  89. $activityParams['source_contact_id'] = $session->get( 'userID' );
  90. $activityParams['activity_type_id'] = CRM_Core_OptionGroup::getValue( 'activity_type', 'Change Case Tags', 'name' );
  91. $activityParams['activity_date_time'] = date('YmdHis');
  92. $activityParams['status_id'] = CRM_Core_OptionGroup::getValue( 'activity_status', 'Completed', 'name' );
  93. $activityParams['case_id'] = $caseId;
  94. $activityParams['is_auto'] = 0;
  95. $activityParams['subject'] = 'Change Case Tags';
  96. $activity = CRM_Activity_BAO_Activity::create( $activityParams );
  97. require_once "CRM/Case/BAO/Case.php";
  98. $caseParams = array( 'activity_id' => $activity->id,
  99. 'case_id' => $caseId );
  100. CRM_Case_BAO_Case::processCaseActivity( $caseParams );
  101. echo 'true';
  102. CRM_Utils_System::civiExit( );
  103. }
  104. function caseDetails( ) {
  105. $caseId = CRM_Utils_Type::escape( $_GET['caseId'], 'Integer' );
  106. $contactId = CRM_Utils_Type::escape( $_GET['contactId'], 'Integer' );
  107. require_once 'CRM/Case/BAO/Case.php';
  108. $sql = "SELECT * FROM civicrm_case where id = %1";
  109. $dao = CRM_Core_DAO::executeQuery( $sql , array( 1 => array( $caseId, 'Integer' ) ) );
  110. if ( $dao->fetch( ) ) {
  111. $caseType = CRM_Case_BAO_Case::getCaseType( ( str_replace( CRM_Core_DAO::VALUE_SEPARATOR,
  112. "",
  113. $dao->case_type_id) ) );
  114. $caseStatuses = CRM_Case_PseudoConstant::caseStatus();
  115. $cs = $caseStatuses[$dao->status_id];
  116. $caseDetails = "<table><tr><td>". ts('Case Subject') ."</td><td>{$dao->subject}</td></tr>
  117. <tr><td>". ts('Case Type') ."</td><td>{$caseType}</td></tr>
  118. <tr><td>". ts('Case Status') ."</td><td>{$cs}</td></tr>
  119. <tr><td>". ts('Case Start Date') ."</td><td>" . CRM_Utils_Date::customFormat($dao->start_date) ."</td></tr>
  120. <tr><td>". ts('Case End Date') ."</td><td></td></tr>". CRM_Utils_Date::customFormat($dao->end_date) ."</table>";
  121. echo $caseDetails;
  122. } else {
  123. echo ts('Could not find valid Case!');
  124. }
  125. CRM_Utils_System::civiExit( );
  126. }
  127. function addClient( ) {
  128. $caseId = CRM_Utils_Type::escape( $_POST['caseID'], 'Integer' );
  129. $contactId = CRM_Utils_Type::escape( $_POST['contactID'], 'Integer' );
  130. $params = array(
  131. 'case_id' => $caseId,
  132. 'contact_id' => $contactId
  133. );
  134. require_once 'CRM/Case/BAO/Case.php';
  135. $result = CRM_Case_BAO_Case::addCaseToContact( $params );
  136. $session =& CRM_Core_Session::singleton( );
  137. require_once "CRM/Activity/BAO/Activity.php";
  138. require_once "CRM/Core/OptionGroup.php";
  139. $activityParams = array( );
  140. $activityParams['source_contact_id'] = $session->get( 'userID' );
  141. $activityParams['activity_type_id'] = CRM_Core_OptionGroup::getValue( 'activity_type', 'Add Client To Case', 'name' );
  142. $activityParams['activity_date_time'] = date('YmdHis');
  143. $activityParams['status_id'] = CRM_Core_OptionGroup::getValue( 'activity_status', 'Completed', 'name' );
  144. $activityParams['case_id'] = $caseId;
  145. $activityParams['is_auto'] = 0;
  146. $activityParams['subject'] = 'Client Added To Case';
  147. $activity = CRM_Activity_BAO_Activity::create( $activityParams );
  148. require_once "CRM/Case/BAO/Case.php";
  149. $caseParams = array( 'activity_id' => $activity->id,
  150. 'case_id' => $caseId );
  151. CRM_Case_BAO_Case::processCaseActivity( $caseParams );
  152. echo json_encode( true );
  153. CRM_Utils_System::civiExit( );
  154. }
  155. }