commiting uncommited changes on live site
[weblabels.fsf.org.git] / crm.fsf.org / 20131203 / files / sites / all / modules-new / civicrm / CRM / Activity / Form / Task / FileOnCase.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.6 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2015 |
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
31 * @copyright CiviCRM LLC (c) 2004-2015
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 protected $_userContext;
52
53 /**
54 * Variable to store contact Ids.
55 */
56 public $_contacts;
57
58 /**
59 * Build all the data structures needed to build the form.
60 *
61 * @return void
62 */
63 public function preProcess() {
64 parent::preProcess();
65 $session = CRM_Core_Session::singleton();
66 $this->_userContext = $session->readUserContext();
67
68 CRM_Utils_System::setTitle(ts('File on Case'));
69 }
70
71 /**
72 * Build the form object.
73 *
74 *
75 * @return void
76 */
77 public function buildQuickForm() {
78 $this->add('text', 'unclosed_case_id', ts('Select Case'), array('class' => 'huge'), TRUE);
79 $this->addDefaultButtons(ts('Save'));
80 }
81
82 /**
83 * Add local and global form rules.
84 *
85 *
86 * @return void
87 */
88 public function addRules() {
89 }
90
91 /**
92 * Process the form after the input has been submitted and validated.
93 *
94 *
95 * @return void
96 */
97 public function postProcess() {
98 $formparams = $this->exportValues();
99 $caseId = $formparams['unclosed_case_id'];
100 $filedActivities = 0;
101 foreach ($this->_activityHolderIds as $key => $id) {
102 $targetContactValues = $defaults = array();
103 $params = array('id' => $id);
104 CRM_Activity_BAO_Activity::retrieve($params, $defaults);
105 if (CRM_Case_BAO_Case::checkPermission($id, 'File On Case', $defaults['activity_type_id'])) {
106
107 if (!CRM_Utils_Array::crmIsEmptyArray($defaults['target_contact'])) {
108 $targetContactValues = array_combine(array_unique($defaults['target_contact']),
109 explode(';', trim($defaults['target_contact_value']))
110 );
111 $targetContactValues = implode(',', array_keys($targetContactValues));
112 }
113
114 $params = array(
115 'caseID' => $caseId,
116 'activityID' => $id,
117 'newSubject' => empty($defaults['subject']) ? '' : $defaults['subject'],
118 'targetContactIds' => $targetContactValues,
119 'mode' => 'file',
120 );
121
122 $error_msg = CRM_Activity_Page_AJAX::_convertToCaseActivity($params);
123 if (empty($error_msg['error_msg'])) {
124 $filedActivities++;
125 }
126 else {
127 CRM_Core_Session::setStatus($error_msg['error_msg'], ts("Error"), "error");
128 }
129 }
130 else {
131 CRM_Core_Session::setStatus(ts('Not permitted to file activity %1 %2.', array(
132 1 => empty($defaults['subject']) ? '' : $defaults['subject'],
133 2 => $defaults['activity_date_time'],
134 )),
135 ts("Error"), "error");
136 }
137 }
138
139 CRM_Core_Session::setStatus($filedActivities, ts("Filed Activities"), "success");
140 CRM_Core_Session::setStatus("", ts('Total Selected Activities: %1', array(1 => count($this->_activityHolderIds))), "info");
141 }
142
143 }