Ian province abbreviation patch - issue 724
[civicrm-core.git] / CRM / Activity / Form / ActivityView.php
CommitLineData
6a488035
TO
1<?php
2/*
3 +--------------------------------------------------------------------+
7e9e8871 4 | CiviCRM version 4.7 |
6a488035 5 +--------------------------------------------------------------------+
e7112fa7 6 | Copyright CiviCRM LLC (c) 2004-2015 |
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
e7112fa7 31 * @copyright CiviCRM LLC (c) 2004-2015
6a488035
TO
32 */
33
34/**
b6c94f42 35 * This class handle activity view mode.
6a488035
TO
36 */
37class 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() {
43 //get the activity values
44 $activityId = CRM_Utils_Request::retrieve('id', 'Positive', $this);
353ffa53
TO
45 $context = CRM_Utils_Request::retrieve('context', 'String', $this);
46 $cid = CRM_Utils_Request::retrieve('cid', 'Positive', $this);
6a488035
TO
47
48 //check for required permissions, CRM-6264
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();
56 if (!in_array($context, array(
353ffa53
TO
57 'home',
58 'dashlet',
408b79bf 59 'dashletFullscreen',
353ffa53
TO
60 ))
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);
69 $defaults = array();
70 $params = array('id' => $activityId);
71 CRM_Activity_BAO_Activity::retrieve($params, $defaults);
72
73 //set activity type name and description to template
74 list($activityTypeName, $activityTypeDescription) = CRM_Core_BAO_OptionValue::getActivityTypeDetails($defaults['activity_type_id']);
75
76 $this->assign('activityTypeName', $activityTypeName);
77 $this->assign('activityTypeDescription', $activityTypeDescription);
78
a7488080 79 if (!empty($defaults['mailingId'])) {
6a488035
TO
80 $this->_mailing_id = CRM_Utils_Array::value('source_record_id', $defaults);
81 $mailingReport = CRM_Mailing_BAO_Mailing::report($this->_mailing_id, TRUE);
82 CRM_Mailing_BAO_Mailing::getMailingContent($mailingReport, $this);
83 $this->assign('mailingReport', $mailingReport);
84
85 $full_open_report = CRM_Mailing_Event_BAO_Opened::getRows(
86 $this->_mailing_id, NULL, FALSE, NULL, NULL, NULL, $cid);
32864ccf 87 $this->assign('openreport', $full_open_report);
6a488035 88
481a74f4 89 $click_thru_report = CRM_Mailing_Event_BAO_TrackableURLOpen::getRows($this->_mailing_id, NULL, FALSE, NULL, NULL, NULL, NULL, $cid);
32864ccf 90 $this->assign('clickreport', $click_thru_report);
6a488035
TO
91 }
92
93 foreach ($defaults as $key => $value) {
94 if (substr($key, -3) != '_id') {
95 $values[$key] = $value;
96 }
97 }
98
99 //get the campaign
100 if ($campaignId = CRM_Utils_Array::value('campaign_id', $defaults)) {
101 $campaigns = CRM_Campaign_BAO_Campaign::getCampaigns($campaignId);
102 $values['campaign'] = $campaigns[$campaignId];
103 }
104 if ($engagementLevel = CRM_Utils_Array::value('engagement_level', $defaults)) {
105 $engagementLevels = CRM_Campaign_PseudoConstant::engagementLevel();
106 $values['engagement_level'] = CRM_Utils_Array::value($engagementLevel, $engagementLevels, $engagementLevel);
107 }
108
109 $values['attachment'] = CRM_Core_BAO_File::attachmentInfo('civicrm_activity', $activityId);
110 $this->assign('values', $values);
111 }
112
113 /**
fe482240 114 * Build the form object.
6a488035
TO
115 */
116 public function buildQuickForm() {
117 $this->addButtons(array(
118 array(
a10432db 119 'type' => 'cancel',
6a488035
TO
120 'name' => ts('Done'),
121 'spacing' => '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;',
122 'isDefault' => TRUE,
123 ),
124 )
125 );
126 }
96025800 127
6a488035 128}