Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
39de6fd5 | 4 | | CiviCRM version 4.6 | |
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 | * Main page for viewing activities | |
38 | * | |
39 | */ | |
40 | class CRM_Activity_Page_Tab extends CRM_Core_Page { | |
41 | ||
42 | /** | |
43 | * Browse all activities for a particular contact | |
44 | * | |
355ba699 | 45 | * @return void |
6a488035 | 46 | * |
6a488035 | 47 | */ |
00be9182 | 48 | public function browse() { |
6a488035 TO |
49 | $this->assign('admin', FALSE); |
50 | $this->assign('context', 'activity'); | |
51 | ||
52 | // also create the form element for the activity filter box | |
39c4fa3a DL |
53 | $controller = new CRM_Core_Controller_Simple( |
54 | 'CRM_Activity_Form_ActivityFilter', | |
55 | ts('Activity Filter'), | |
56 | NULL, | |
57 | FALSE, FALSE, TRUE | |
6a488035 TO |
58 | ); |
59 | $controller->set('contactId', $this->_contactId); | |
60 | $controller->setEmbedded(TRUE); | |
61 | $controller->run(); | |
4e8065a9 | 62 | $this->ajaxResponse['tabCount'] = CRM_Contact_BAO_Contact::getCountComponent('activity', $this->_contactId); |
6a488035 TO |
63 | } |
64 | ||
00be9182 | 65 | public function edit() { |
6a488035 TO |
66 | // used for ajax tabs |
67 | $context = CRM_Utils_Request::retrieve('context', 'String', $this); | |
68 | $this->assign('context', $context); | |
69 | ||
70 | $this->_id = CRM_Utils_Request::retrieve('id', 'Integer', $this); | |
71 | ||
72 | $this->_caseId = CRM_Utils_Request::retrieve('caseid', 'Integer', $this); | |
73 | ||
74 | $activityTypeId = CRM_Utils_Request::retrieve('atype', 'Positive', $this); | |
75 | ||
76 | // Email and Create Letter activities use a different form class | |
77 | $emailTypeValue = CRM_Core_OptionGroup::getValue('activity_type', | |
78 | 'Email', | |
79 | 'name' | |
80 | ); | |
81 | ||
82 | $letterTypeValue = CRM_Core_OptionGroup::getValue('activity_type', | |
83 | 'Print PDF Letter', | |
84 | 'name' | |
85 | ); | |
86 | ||
6a488035 TO |
87 | switch ($activityTypeId) { |
88 | case $emailTypeValue: | |
89 | $wrapper = new CRM_Utils_Wrapper(); | |
90 | $arguments = array('attachUpload' => 1); | |
91 | return $wrapper->run('CRM_Contact_Form_Task_Email', ts('Email a Contact'), $arguments); | |
92 | ||
93 | case $letterTypeValue: | |
94 | $wrapper = new CRM_Utils_Wrapper(); | |
95 | $arguments = array('attachUpload' => 1); | |
96 | return $wrapper->run('CRM_Contact_Form_Task_PDF', ts('Create PDF Letter'), $arguments); | |
97 | ||
98 | default: | |
99 | $controller = new CRM_Core_Controller_Simple('CRM_Activity_Form_Activity', | |
100 | ts('Contact Activities'), | |
101 | $this->_action, | |
102 | FALSE, FALSE, FALSE, TRUE | |
103 | ); | |
104 | } | |
105 | ||
106 | $controller->setEmbedded(TRUE); | |
107 | ||
108 | $controller->set('contactId', $this->_contactId); | |
109 | $controller->set('atype', $activityTypeId); | |
110 | $controller->set('id', $this->_id); | |
111 | $controller->set('pid', $this->get('pid')); | |
112 | $controller->set('action', $this->_action); | |
113 | $controller->set('context', $context); | |
114 | ||
115 | $controller->process(); | |
116 | $controller->run(); | |
117 | } | |
118 | ||
119 | /** | |
120 | * Heart of the viewing process. The runner gets all the meta data for | |
121 | * the contact and calls the appropriate type of page to view. | |
122 | * | |
123 | * @return void | |
6a488035 TO |
124 | * |
125 | */ | |
00be9182 | 126 | public function preProcess() { |
6a488035 TO |
127 | $this->_contactId = CRM_Utils_Request::retrieve('cid', 'Positive', $this, TRUE); |
128 | $this->assign('contactId', $this->_contactId); | |
129 | //FIX ME: need to fix this conflict | |
130 | $this->assign('contactID', $this->_contactId); | |
131 | ||
132 | // check logged in url permission | |
133 | CRM_Contact_Page_View::checkUserPermission($this); | |
134 | ||
6a488035 TO |
135 | $this->_action = CRM_Utils_Request::retrieve('action', 'String', $this, FALSE, 'browse'); |
136 | $this->assign('action', $this->_action); | |
137 | ||
138 | // also create the form element for the activity links box | |
39c4fa3a DL |
139 | $controller = new CRM_Core_Controller_Simple( |
140 | 'CRM_Activity_Form_ActivityLinks', | |
141 | ts('Activity Links'), | |
142 | NULL, | |
143 | FALSE, FALSE, TRUE | |
6a488035 TO |
144 | ); |
145 | $controller->setEmbedded(TRUE); | |
146 | $controller->run(); | |
147 | } | |
148 | ||
00be9182 | 149 | public function delete() { |
39c4fa3a DL |
150 | $controller = new CRM_Core_Controller_Simple( |
151 | 'CRM_Activity_Form_Activity', | |
6a488035 TO |
152 | ts('Activity Record'), |
153 | $this->_action | |
154 | ); | |
155 | $controller->set('id', $this->_id); | |
156 | $controller->setEmbedded(TRUE); | |
157 | $controller->process(); | |
158 | $controller->run(); | |
159 | } | |
160 | ||
161 | /** | |
100fef9d | 162 | * Perform actions and display for activities. |
6a488035 | 163 | * |
355ba699 | 164 | * @return void |
6a488035 | 165 | * |
6a488035 | 166 | */ |
00be9182 | 167 | public function run() { |
6a488035 TO |
168 | $context = CRM_Utils_Request::retrieve('context', 'String', $this); |
169 | $contactId = CRM_Utils_Request::retrieve('cid', 'Positive', $this); | |
170 | $action = CRM_Utils_Request::retrieve('action', 'String', $this); | |
171 | $this->_id = CRM_Utils_Request::retrieve('id', 'Positive', $this); | |
172 | ||
173 | //do check for view/edit operation. | |
174 | if ($this->_id && | |
175 | in_array($action, array(CRM_Core_Action::UPDATE, CRM_Core_Action::VIEW)) | |
176 | ) { | |
177 | if (!CRM_Activity_BAO_Activity::checkPermission($this->_id, $action)) { | |
178 | CRM_Core_Error::fatal(ts('You are not authorized to access this page.')); | |
179 | } | |
180 | } | |
181 | ||
182 | if ($context == 'standalone' || (!$contactId && ($action != CRM_Core_Action::DELETE) && !$this->_id)) { | |
183 | $this->_action = CRM_Core_Action::ADD; | |
184 | $this->assign('action', $this->_action); | |
185 | } | |
186 | else { | |
187 | // we should call contact view, preprocess only for activity in contact summary | |
188 | $this->preProcess(); | |
189 | } | |
190 | ||
191 | // route behaviour of contact/view/activity based on action defined | |
32864ccf | 192 | if ($this->_action & (CRM_Core_Action::UPDATE | CRM_Core_Action::ADD | CRM_Core_Action::VIEW) |
6a488035 TO |
193 | ) { |
194 | $this->edit(); | |
195 | $activityTypeId = CRM_Utils_Request::retrieve('atype', 'Positive', $this); | |
196 | ||
197 | // Email and Create Letter activities use a different form class | |
198 | $emailTypeValue = CRM_Core_OptionGroup::getValue('activity_type', | |
199 | 'Email', | |
200 | 'name' | |
201 | ); | |
202 | ||
203 | $letterTypeValue = CRM_Core_OptionGroup::getValue('activity_type', | |
204 | 'Print PDF Letter', | |
205 | 'name' | |
206 | ); | |
207 | ||
208 | if (in_array($activityTypeId, array( | |
209 | $emailTypeValue, $letterTypeValue))) { | |
210 | return; | |
211 | } | |
212 | } | |
213 | elseif ($this->_action & (CRM_Core_Action::DELETE | CRM_Core_Action::DETACH)) { | |
214 | $this->delete(); | |
215 | } | |
216 | else { | |
217 | $this->browse(); | |
218 | } | |
219 | ||
220 | return parent::run(); | |
221 | } | |
222 | } |