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