Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
bc77d7c0 | 4 | | Copyright CiviCRM LLC. All rights reserved. | |
6a488035 | 5 | | | |
bc77d7c0 TO |
6 | | This work is published under the GNU AGPLv3 license with some | |
7 | | permitted exceptions and without any warranty. For full license | | |
8 | | and copyright information, see https://civicrm.org/licensing | | |
6a488035 | 9 | +--------------------------------------------------------------------+ |
d25dd0ee | 10 | */ |
6a488035 TO |
11 | |
12 | /** | |
13 | * | |
14 | * @package CRM | |
ca5cec67 | 15 | * @copyright CiviCRM LLC https://civicrm.org/licensing |
6a488035 TO |
16 | */ |
17 | ||
18 | /** | |
b6c94f42 | 19 | * This class handle activity view mode. |
6a488035 TO |
20 | */ |
21 | class CRM_Activity_Form_ActivityView extends CRM_Core_Form { | |
22 | ||
23 | /** | |
fe482240 | 24 | * Set variables up before form is built. |
6a488035 TO |
25 | */ |
26 | public function preProcess() { | |
7808aae6 | 27 | // Get the activity values. |
6a488035 | 28 | $activityId = CRM_Utils_Request::retrieve('id', 'Positive', $this); |
edc80cda | 29 | $context = CRM_Utils_Request::retrieve('context', 'Alphanumeric', $this); |
353ffa53 | 30 | $cid = CRM_Utils_Request::retrieve('cid', 'Positive', $this); |
6a488035 | 31 | |
7808aae6 | 32 | // Check for required permissions, CRM-6264. |
6a488035 TO |
33 | if ($activityId && |
34 | !CRM_Activity_BAO_Activity::checkPermission($activityId, CRM_Core_Action::VIEW) | |
35 | ) { | |
beb414cc | 36 | CRM_Core_Error::statusBounce(ts('You do not have permission to access this page.')); |
6a488035 TO |
37 | } |
38 | ||
39 | $session = CRM_Core_Session::singleton(); | |
be2fb01f | 40 | if (!in_array($context, [ |
353ffa53 TO |
41 | 'home', |
42 | 'dashlet', | |
408b79bf | 43 | 'dashletFullscreen', |
be2fb01f | 44 | ]) |
353ffa53 | 45 | ) { |
6a488035 TO |
46 | $url = CRM_Utils_System::url('civicrm/contact/view', "reset=1&cid={$cid}&selectedChild=activity"); |
47 | } | |
48 | else { | |
49 | $url = CRM_Utils_System::url('civicrm/dashboard', 'reset=1'); | |
50 | } | |
51 | ||
52 | $session->pushUserContext($url); | |
be2fb01f CW |
53 | $defaults = []; |
54 | $params = ['id' => $activityId]; | |
6a488035 TO |
55 | CRM_Activity_BAO_Activity::retrieve($params, $defaults); |
56 | ||
86effd58 | 57 | // Send activity type description to template. |
58 | list(, $activityTypeDescription) = CRM_Core_BAO_OptionValue::getActivityTypeDetails($defaults['activity_type_id']); | |
6a488035 TO |
59 | $this->assign('activityTypeDescription', $activityTypeDescription); |
60 | ||
a7488080 | 61 | if (!empty($defaults['mailingId'])) { |
9c1bc317 | 62 | $this->_mailing_id = $defaults['source_record_id'] ?? NULL; |
6a488035 TO |
63 | $mailingReport = CRM_Mailing_BAO_Mailing::report($this->_mailing_id, TRUE); |
64 | CRM_Mailing_BAO_Mailing::getMailingContent($mailingReport, $this); | |
65 | $this->assign('mailingReport', $mailingReport); | |
66 | ||
67 | $full_open_report = CRM_Mailing_Event_BAO_Opened::getRows( | |
68 | $this->_mailing_id, NULL, FALSE, NULL, NULL, NULL, $cid); | |
32864ccf | 69 | $this->assign('openreport', $full_open_report); |
6a488035 | 70 | |
481a74f4 | 71 | $click_thru_report = CRM_Mailing_Event_BAO_TrackableURLOpen::getRows($this->_mailing_id, NULL, FALSE, NULL, NULL, NULL, NULL, $cid); |
32864ccf | 72 | $this->assign('clickreport', $click_thru_report); |
6a488035 TO |
73 | } |
74 | ||
75 | foreach ($defaults as $key => $value) { | |
76 | if (substr($key, -3) != '_id') { | |
77 | $values[$key] = $value; | |
78 | } | |
79 | } | |
80 | ||
7808aae6 | 81 | // Get the campaign. |
6a488035 TO |
82 | if ($campaignId = CRM_Utils_Array::value('campaign_id', $defaults)) { |
83 | $campaigns = CRM_Campaign_BAO_Campaign::getCampaigns($campaignId); | |
84 | $values['campaign'] = $campaigns[$campaignId]; | |
85 | } | |
86 | if ($engagementLevel = CRM_Utils_Array::value('engagement_level', $defaults)) { | |
87 | $engagementLevels = CRM_Campaign_PseudoConstant::engagementLevel(); | |
88 | $values['engagement_level'] = CRM_Utils_Array::value($engagementLevel, $engagementLevels, $engagementLevel); | |
89 | } | |
90 | ||
91 | $values['attachment'] = CRM_Core_BAO_File::attachmentInfo('civicrm_activity', $activityId); | |
92 | $this->assign('values', $values); | |
234fa48a | 93 | |
9827fb70 | 94 | $url = CRM_Utils_System::url(implode("/", $this->urlPath), "reset=1&id={$activityId}&action=view&cid={$defaults['source_contact_id']}"); |
95 | CRM_Utils_Recent::add($defaults['subject'], | |
234fa48a | 96 | $url, |
9827fb70 | 97 | $activityId, |
234fa48a | 98 | 'Activity', |
9827fb70 | 99 | $defaults['source_contact_id'], |
100 | $defaults['source_contact'] | |
234fa48a | 101 | ); |
6a488035 TO |
102 | } |
103 | ||
104 | /** | |
fe482240 | 105 | * Build the form object. |
6a488035 TO |
106 | */ |
107 | public function buildQuickForm() { | |
be2fb01f CW |
108 | $this->addButtons([ |
109 | [ | |
a10432db | 110 | 'type' => 'cancel', |
6a488035 TO |
111 | 'name' => ts('Done'), |
112 | 'spacing' => ' ', | |
113 | 'isDefault' => TRUE, | |
be2fb01f | 114 | ], |
0d48f1cc | 115 | ] |
6a488035 TO |
116 | ); |
117 | } | |
96025800 | 118 | |
6a488035 | 119 | } |