Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
06b69b18 | 4 | | CiviCRM version 4.5 | |
6a488035 | 5 | +--------------------------------------------------------------------+ |
06b69b18 | 6 | | Copyright CiviCRM LLC (c) 2004-2014 | |
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 | +--------------------------------------------------------------------+ | |
26 | */ | |
27 | ||
28 | /** | |
29 | * | |
30 | * @package CRM | |
06b69b18 | 31 | * @copyright CiviCRM LLC (c) 2004-2014 |
6a488035 TO |
32 | * $Id$ |
33 | * | |
34 | */ | |
35 | ||
36 | /** | |
37 | * This class provides the functionality to email a group of contacts | |
38 | */ | |
39 | class CRM_Activity_Form_Task_FileOnCase extends CRM_Activity_Form_Task { | |
40 | ||
41 | /** | |
42 | * the title of the group | |
43 | * | |
44 | * @var string | |
45 | */ | |
46 | protected $_title; | |
47 | ||
48 | /** | |
49 | * variable to store redirect path | |
50 | * | |
51 | */ | |
52 | protected $_userContext; | |
53 | ||
54 | /** | |
55 | * variable to store contact Ids | |
56 | * | |
57 | */ | |
58 | public $_contacts; | |
59 | ||
60 | /** | |
61 | * build all the data structures needed to build the form | |
62 | * | |
63 | * @return void | |
64 | * @access public | |
f72119d9 CW |
65 | */ |
66 | function preProcess() { | |
6a488035 TO |
67 | parent::preProcess(); |
68 | $session = CRM_Core_Session::singleton(); | |
69 | $this->_userContext = $session->readUserContext(); | |
70 | ||
71 | CRM_Utils_System::setTitle(ts('File on Case')); | |
6a488035 TO |
72 | } |
73 | ||
74 | /** | |
c490a46a | 75 | * Build the form object |
6a488035 TO |
76 | * |
77 | * @access public | |
78 | * | |
79 | * @return void | |
80 | */ | |
81 | function buildQuickForm() { | |
f72119d9 | 82 | $this->add('text', 'unclosed_case_id', ts('Select Case'), array('class' => 'huge'), TRUE); |
6a488035 TO |
83 | $this->addDefaultButtons(ts('Continue >>')); |
84 | } | |
85 | ||
86 | /** | |
87 | * Add local and global form rules | |
88 | * | |
89 | * @access protected | |
90 | * | |
91 | * @return void | |
92 | */ | |
f72119d9 | 93 | function addRules() {} |
6a488035 TO |
94 | |
95 | /** | |
96 | * process the form after the input has been submitted and validated | |
97 | * | |
98 | * @access public | |
99 | * | |
355ba699 | 100 | * @return void |
6a488035 TO |
101 | */ |
102 | ||
103 | public function postProcess() { | |
104 | $formparams = $this->exportValues(); | |
105 | $caseId = $formparams['unclosed_case_id']; | |
106 | $filedActivities = 0; | |
107 | foreach ($this->_activityHolderIds as $key => $id) { | |
108 | $targetContactValues = $defaults = array(); | |
109 | $params = array('id' => $id); | |
110 | CRM_Activity_BAO_Activity::retrieve($params, $defaults); | |
111 | if (CRM_Case_BAO_Case::checkPermission($id, 'File On Case', $defaults['activity_type_id'])) { | |
112 | ||
113 | if (!CRM_Utils_Array::crmIsEmptyArray($defaults['target_contact'])) { | |
114 | $targetContactValues = array_combine(array_unique($defaults['target_contact']), | |
115 | explode(';', trim($defaults['target_contact_value'])) | |
116 | ); | |
117 | $targetContactValues = implode(',', array_keys($targetContactValues)); | |
118 | } | |
119 | ||
120 | $params = array( | |
121 | 'caseID' => $caseId, | |
122 | 'activityID' => $id, | |
123 | 'newSubject' => empty($defaults['subject']) ? '' : $defaults['subject'], | |
124 | 'targetContactIds' => $targetContactValues, | |
125 | 'mode' => 'file', | |
126 | ); | |
127 | ||
128 | $error_msg = CRM_Activity_Page_AJAX::_convertToCaseActivity($params); | |
129 | if (empty($error_msg['error_msg'])) { | |
130 | $filedActivities++; | |
131 | } | |
132 | else { | |
133 | CRM_Core_Session::setStatus($error_msg['error_msg'], ts("Error"), "error"); | |
134 | } | |
135 | } | |
136 | else { | |
137 | CRM_Core_Session::setStatus(ts('Not permitted to file activity %1 %2.', array( | |
138 | 1 => empty($defaults['subject']) ? '' : $defaults['subject'], | |
f813f78e | 139 | 2 => $defaults['activity_date_time'])), |
6a488035 TO |
140 | ts("Error"), "error"); |
141 | } | |
142 | } | |
143 | ||
144 | CRM_Core_Session::setStatus($filedActivities, ts("Filed Activities"), "success"); | |
145 | CRM_Core_Session::setStatus("", ts('Total Selected Activities: %1', array(1 => count($this->_activityHolderIds))), "info"); | |
146 | } | |
147 | } | |
148 |