Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
fee14197 | 4 | | CiviCRM version 5 | |
6a488035 | 5 | +--------------------------------------------------------------------+ |
6b83d5bd | 6 | | Copyright CiviCRM LLC (c) 2004-2019 | |
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 | +--------------------------------------------------------------------+ | |
d25dd0ee | 26 | */ |
6a488035 TO |
27 | |
28 | /** | |
29 | * | |
30 | * @package CRM | |
6b83d5bd | 31 | * @copyright CiviCRM LLC (c) 2004-2019 |
6a488035 TO |
32 | */ |
33 | ||
34 | /** | |
b6c94f42 | 35 | * This class handle activity view mode. |
6a488035 TO |
36 | */ |
37 | class CRM_Activity_Form_ActivityView extends CRM_Core_Form { | |
38 | ||
39 | /** | |
fe482240 | 40 | * Set variables up before form is built. |
6a488035 TO |
41 | */ |
42 | public function preProcess() { | |
7808aae6 | 43 | // Get the activity values. |
6a488035 | 44 | $activityId = CRM_Utils_Request::retrieve('id', 'Positive', $this); |
edc80cda | 45 | $context = CRM_Utils_Request::retrieve('context', 'Alphanumeric', $this); |
353ffa53 | 46 | $cid = CRM_Utils_Request::retrieve('cid', 'Positive', $this); |
6a488035 | 47 | |
7808aae6 | 48 | // Check for required permissions, CRM-6264. |
6a488035 TO |
49 | if ($activityId && |
50 | !CRM_Activity_BAO_Activity::checkPermission($activityId, CRM_Core_Action::VIEW) | |
51 | ) { | |
52 | CRM_Core_Error::fatal(ts('You do not have permission to access this page.')); | |
53 | } | |
54 | ||
55 | $session = CRM_Core_Session::singleton(); | |
be2fb01f | 56 | if (!in_array($context, [ |
353ffa53 TO |
57 | 'home', |
58 | 'dashlet', | |
408b79bf | 59 | 'dashletFullscreen', |
be2fb01f | 60 | ]) |
353ffa53 | 61 | ) { |
6a488035 TO |
62 | $url = CRM_Utils_System::url('civicrm/contact/view', "reset=1&cid={$cid}&selectedChild=activity"); |
63 | } | |
64 | else { | |
65 | $url = CRM_Utils_System::url('civicrm/dashboard', 'reset=1'); | |
66 | } | |
67 | ||
68 | $session->pushUserContext($url); | |
be2fb01f CW |
69 | $defaults = []; |
70 | $params = ['id' => $activityId]; | |
6a488035 TO |
71 | CRM_Activity_BAO_Activity::retrieve($params, $defaults); |
72 | ||
7808aae6 | 73 | // Set activity type name and description to template. |
6a488035 TO |
74 | list($activityTypeName, $activityTypeDescription) = CRM_Core_BAO_OptionValue::getActivityTypeDetails($defaults['activity_type_id']); |
75 | ||
498638d9 D |
76 | // activityTypeName - dev/core#1116-unknown-if-ok |
77 | // It seems like activityTypeName is no longer used? Description is still used though. See PR notes for more details. | |
6a488035 TO |
78 | $this->assign('activityTypeName', $activityTypeName); |
79 | $this->assign('activityTypeDescription', $activityTypeDescription); | |
80 | ||
a7488080 | 81 | if (!empty($defaults['mailingId'])) { |
6a488035 TO |
82 | $this->_mailing_id = CRM_Utils_Array::value('source_record_id', $defaults); |
83 | $mailingReport = CRM_Mailing_BAO_Mailing::report($this->_mailing_id, TRUE); | |
84 | CRM_Mailing_BAO_Mailing::getMailingContent($mailingReport, $this); | |
85 | $this->assign('mailingReport', $mailingReport); | |
86 | ||
87 | $full_open_report = CRM_Mailing_Event_BAO_Opened::getRows( | |
88 | $this->_mailing_id, NULL, FALSE, NULL, NULL, NULL, $cid); | |
32864ccf | 89 | $this->assign('openreport', $full_open_report); |
6a488035 | 90 | |
481a74f4 | 91 | $click_thru_report = CRM_Mailing_Event_BAO_TrackableURLOpen::getRows($this->_mailing_id, NULL, FALSE, NULL, NULL, NULL, NULL, $cid); |
32864ccf | 92 | $this->assign('clickreport', $click_thru_report); |
6a488035 TO |
93 | } |
94 | ||
95 | foreach ($defaults as $key => $value) { | |
96 | if (substr($key, -3) != '_id') { | |
97 | $values[$key] = $value; | |
98 | } | |
99 | } | |
100 | ||
7808aae6 | 101 | // Get the campaign. |
6a488035 TO |
102 | if ($campaignId = CRM_Utils_Array::value('campaign_id', $defaults)) { |
103 | $campaigns = CRM_Campaign_BAO_Campaign::getCampaigns($campaignId); | |
104 | $values['campaign'] = $campaigns[$campaignId]; | |
105 | } | |
106 | if ($engagementLevel = CRM_Utils_Array::value('engagement_level', $defaults)) { | |
107 | $engagementLevels = CRM_Campaign_PseudoConstant::engagementLevel(); | |
108 | $values['engagement_level'] = CRM_Utils_Array::value($engagementLevel, $engagementLevels, $engagementLevel); | |
109 | } | |
110 | ||
111 | $values['attachment'] = CRM_Core_BAO_File::attachmentInfo('civicrm_activity', $activityId); | |
112 | $this->assign('values', $values); | |
234fa48a NH |
113 | |
114 | $url = CRM_Utils_System::url(implode("/", $this->urlPath), "reset=1&id={$activityId}&action=view&cid={$values['source_contact_id']}"); | |
115 | CRM_Utils_Recent::add($this->_values['subject'], | |
116 | $url, | |
117 | $values['id'], | |
118 | 'Activity', | |
119 | $values['source_contact_id'], | |
120 | $values['source_contact'] | |
121 | ); | |
6a488035 TO |
122 | } |
123 | ||
124 | /** | |
fe482240 | 125 | * Build the form object. |
6a488035 TO |
126 | */ |
127 | public function buildQuickForm() { | |
be2fb01f CW |
128 | $this->addButtons([ |
129 | [ | |
a10432db | 130 | 'type' => 'cancel', |
6a488035 TO |
131 | 'name' => ts('Done'), |
132 | 'spacing' => ' ', | |
133 | 'isDefault' => TRUE, | |
be2fb01f | 134 | ], |
0d48f1cc | 135 | ] |
6a488035 TO |
136 | ); |
137 | } | |
96025800 | 138 | |
6a488035 | 139 | } |