Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
fee14197 | 4 | | CiviCRM version 5 | |
6a488035 | 5 | +--------------------------------------------------------------------+ |
6b83d5bd | 6 | | Copyright CiviCRM LLC (c) 2004-2019 | |
6a488035 TO |
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 | +--------------------------------------------------------------------+ | |
d25dd0ee | 26 | */ |
6a488035 TO |
27 | |
28 | /** | |
29 | * | |
30 | * @package CRM | |
6b83d5bd | 31 | * @copyright CiviCRM LLC (c) 2004-2019 |
6a488035 TO |
32 | */ |
33 | ||
34 | /** | |
35 | * This class provides the functionality to email a group of contacts | |
36 | */ | |
37 | class CRM_Activity_Form_Task_FileOnCase extends CRM_Activity_Form_Task { | |
38 | ||
39 | /** | |
fe482240 | 40 | * The title of the group. |
6a488035 TO |
41 | * |
42 | * @var string | |
43 | */ | |
44 | protected $_title; | |
45 | ||
46 | /** | |
fe482240 | 47 | * Variable to store redirect path. |
6a488035 TO |
48 | */ |
49 | protected $_userContext; | |
50 | ||
51 | /** | |
fe482240 | 52 | * Variable to store contact Ids. |
6a488035 TO |
53 | */ |
54 | public $_contacts; | |
55 | ||
56 | /** | |
fe482240 | 57 | * Build all the data structures needed to build the form. |
f72119d9 | 58 | */ |
00be9182 | 59 | public function preProcess() { |
6a488035 TO |
60 | parent::preProcess(); |
61 | $session = CRM_Core_Session::singleton(); | |
62 | $this->_userContext = $session->readUserContext(); | |
63 | ||
64 | CRM_Utils_System::setTitle(ts('File on Case')); | |
6a488035 TO |
65 | } |
66 | ||
67 | /** | |
fe482240 | 68 | * Build the form object. |
6a488035 | 69 | */ |
00be9182 | 70 | public function buildQuickForm() { |
abd06efc | 71 | $this->addEntityRef('unclosed_case_id', ts('Select Case'), array('entity' => 'Case'), TRUE); |
f212d37d | 72 | $this->addDefaultButtons(ts('Save')); |
6a488035 TO |
73 | } |
74 | ||
6a488035 | 75 | /** |
fe482240 | 76 | * Process the form after the input has been submitted and validated. |
6a488035 | 77 | */ |
6a488035 | 78 | public function postProcess() { |
353ffa53 TO |
79 | $formparams = $this->exportValues(); |
80 | $caseId = $formparams['unclosed_case_id']; | |
6a488035 TO |
81 | $filedActivities = 0; |
82 | foreach ($this->_activityHolderIds as $key => $id) { | |
83 | $targetContactValues = $defaults = array(); | |
84 | $params = array('id' => $id); | |
85 | CRM_Activity_BAO_Activity::retrieve($params, $defaults); | |
86 | if (CRM_Case_BAO_Case::checkPermission($id, 'File On Case', $defaults['activity_type_id'])) { | |
87 | ||
88 | if (!CRM_Utils_Array::crmIsEmptyArray($defaults['target_contact'])) { | |
89 | $targetContactValues = array_combine(array_unique($defaults['target_contact']), | |
90 | explode(';', trim($defaults['target_contact_value'])) | |
91 | ); | |
92 | $targetContactValues = implode(',', array_keys($targetContactValues)); | |
93 | } | |
94 | ||
95 | $params = array( | |
96 | 'caseID' => $caseId, | |
97 | 'activityID' => $id, | |
98 | 'newSubject' => empty($defaults['subject']) ? '' : $defaults['subject'], | |
99 | 'targetContactIds' => $targetContactValues, | |
100 | 'mode' => 'file', | |
101 | ); | |
102 | ||
103 | $error_msg = CRM_Activity_Page_AJAX::_convertToCaseActivity($params); | |
104 | if (empty($error_msg['error_msg'])) { | |
105 | $filedActivities++; | |
106 | } | |
107 | else { | |
108 | CRM_Core_Session::setStatus($error_msg['error_msg'], ts("Error"), "error"); | |
109 | } | |
110 | } | |
111 | else { | |
112 | CRM_Core_Session::setStatus(ts('Not permitted to file activity %1 %2.', array( | |
353ffa53 | 113 | 1 => empty($defaults['subject']) ? '' : $defaults['subject'], |
389bcebf | 114 | 2 => $defaults['activity_date_time'], |
353ffa53 | 115 | )), |
6a488035 TO |
116 | ts("Error"), "error"); |
117 | } | |
118 | } | |
119 | ||
120 | CRM_Core_Session::setStatus($filedActivities, ts("Filed Activities"), "success"); | |
121 | CRM_Core_Session::setStatus("", ts('Total Selected Activities: %1', array(1 => count($this->_activityHolderIds))), "info"); | |
122 | } | |
96025800 | 123 | |
6a488035 | 124 | } |