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