Merge pull request #12732 from eileenmcnaughton/setting_form1
[civicrm-core.git] / CRM / Contact / Page / View / UserDashBoard.php
CommitLineData
6a488035
TO
1<?php
2/*
3 +--------------------------------------------------------------------+
fee14197 4 | CiviCRM version 5 |
6a488035 5 +--------------------------------------------------------------------+
8c9251b3 6 | Copyright CiviCRM LLC (c) 2004-2018 |
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
8c9251b3 31 * @copyright CiviCRM LLC (c) 2004-2018
6a488035
TO
32 */
33
34/**
6a488035 35 * This class is used to build User Dashboard
6a488035
TO
36 */
37class CRM_Contact_Page_View_UserDashBoard extends CRM_Core_Page {
38 public $_contactId = NULL;
39
c490a46a 40 /**
fe482240 41 * Always show public groups.
c490a46a
CW
42 * @var bool
43 */
6a488035
TO
44 public $_onlyPublicGroups = TRUE;
45
46 public $_edit = TRUE;
47
48 /**
fe482240 49 * The action links that we need to display for the browse screen.
6a488035
TO
50 *
51 * @var array
6a488035 52 */
430ae6dd
TO
53 static $_links = NULL;
54
4319322b
EM
55 /**
56 * @throws Exception
57 */
00be9182 58 public function __construct() {
6a488035
TO
59 parent::__construct();
60
61 $check = CRM_Core_Permission::check('access Contact Dashboard');
62
63 if (!$check) {
64 CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/dashboard', 'reset=1'));
6a488035
TO
65 }
66
67 $this->_contactId = CRM_Utils_Request::retrieve('id', 'Positive', $this);
68
69 $session = CRM_Core_Session::singleton();
70 $userID = $session->get('userID');
71
2b329653
JP
72 $userChecksum = CRM_Utils_Request::retrieve('cs', 'String', $this);
73 $validUser = FALSE;
74 if (empty($userID) && $this->_contactId && $userChecksum) {
75 $validUser = CRM_Contact_BAO_Contact_Utils::validChecksum($this->_contactId, $userChecksum);
76 }
77
6a488035
TO
78 if (!$this->_contactId) {
79 $this->_contactId = $userID;
80 }
2b329653 81 elseif ($this->_contactId != $userID && !$validUser) {
6a488035 82 if (!CRM_Contact_BAO_Contact_Permission::allow($this->_contactId, CRM_Core_Permission::VIEW)) {
994b9e9f 83 CRM_Core_Error::fatal(ts('You do not have permission to access this contact.'));
6a488035
TO
84 }
85 if (!CRM_Contact_BAO_Contact_Permission::allow($this->_contactId, CRM_Core_Permission::EDIT)) {
86 $this->_edit = FALSE;
87 }
88 }
89 }
90
c490a46a 91 /**
95cdcc0f 92 * Heart of the viewing process.
c490a46a 93 *
95cdcc0f 94 * The runner gets all the meta data for the contact and calls the appropriate type of page to view.
c490a46a 95 */
00be9182 96 public function preProcess() {
6a488035
TO
97 if (!$this->_contactId) {
98 CRM_Core_Error::fatal(ts('You must be logged in to view this page.'));
99 }
100
101 list($displayName, $contactImage) = CRM_Contact_BAO_Contact::getDisplayAndImage($this->_contactId);
102
103 $this->set('displayName', $displayName);
104 $this->set('contactImage', $contactImage);
105
106 CRM_Utils_System::setTitle(ts('Dashboard - %1', array(1 => $displayName)));
107
108 $this->assign('recentlyViewed', FALSE);
109 }
110
111 /**
fe482240 112 * Build user dashboard.
6a488035 113 */
00be9182 114 public function buildUserDashBoard() {
6a488035
TO
115 //build component selectors
116 $dashboardElements = array();
117 $config = CRM_Core_Config::singleton();
118
119 $this->_userOptions = CRM_Core_BAO_Setting::valueOptions(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME,
120 'user_dashboard_options'
121 );
122
123 $components = CRM_Core_Component::getEnabledComponents();
124 $this->assign('contactId', $this->_contactId);
125 foreach ($components as $name => $component) {
126 $elem = $component->getUserDashboardElement();
127 if (!$elem) {
128 continue;
129 }
130
a7488080 131 if (!empty($this->_userOptions[$name]) &&
6a488035
TO
132 (CRM_Core_Permission::access($component->name) ||
133 CRM_Core_Permission::check($elem['perm'][0])
134 )
135 ) {
136
137 $userDashboard = $component->getUserDashboardObject();
e81ccbf6
FG
138 $dashboardElements[] = array(
139 'class' => 'crm-dashboard-' . strtolower($component->name),
6a488035 140 'sectionTitle' => $elem['title'],
e81ccbf6 141 'templatePath' => $userDashboard->getTemplateFileName(),
6a488035
TO
142 'weight' => $elem['weight'],
143 );
144 $userDashboard->run();
145 }
146 }
147
bb36d17a
CW
148 // CRM-16512 - Hide related contact table if user lacks permission to view self
149 if (!empty($this->_userOptions['Permissioned Orgs']) && CRM_Core_Permission::check('view my contact')) {
6a488035 150 $dashboardElements[] = array(
e81ccbf6 151 'class' => 'crm-dashboard-permissionedOrgs',
d0592c3d 152 'templatePath' => 'CRM/Contact/Page/View/RelationshipSelector.tpl',
6a488035
TO
153 'sectionTitle' => ts('Your Contacts / Organizations'),
154 'weight' => 40,
155 );
156
6a488035
TO
157 }
158
a7488080 159 if (!empty($this->_userOptions['PCP'])) {
6a488035 160 $dashboardElements[] = array(
e81ccbf6 161 'class' => 'crm-dashboard-pcp',
6a488035
TO
162 'templatePath' => 'CRM/Contribute/Page/PcpUserDashboard.tpl',
163 'sectionTitle' => ts('Personal Campaign Pages'),
164 'weight' => 40,
165 );
166 list($pcpBlock, $pcpInfo) = CRM_PCP_BAO_PCP::getPcpDashboardInfo($this->_contactId);
167 $this->assign('pcpBlock', $pcpBlock);
168 $this->assign('pcpInfo', $pcpInfo);
169 }
170
a7488080 171 if (!empty($this->_userOptions['Assigned Activities'])) {
6a488035
TO
172 // Assigned Activities section
173 $dashboardElements[] = array(
e81ccbf6 174 'class' => 'crm-dashboard-assignedActivities',
6a488035
TO
175 'templatePath' => 'CRM/Activity/Page/UserDashboard.tpl',
176 'sectionTitle' => ts('Your Assigned Activities'),
177 'weight' => 5,
178 );
acb1052e 179 $userDashboard = new CRM_Activity_Page_UserDashboard();
6a488035
TO
180 $userDashboard->run();
181 }
182
183 usort($dashboardElements, array('CRM_Utils_Sort', 'cmpFunc'));
184 $this->assign('dashboardElements', $dashboardElements);
185
56ed0b01
PB
186 // return true when 'Invoices / Credit Notes' checkbox is checked
187 $this->assign('invoices', $this->_userOptions['Invoices / Credit Notes']);
188
a7488080 189 if (!empty($this->_userOptions['Groups'])) {
6a488035
TO
190 $this->assign('showGroup', TRUE);
191 //build group selector
192 $gContact = new CRM_Contact_Page_View_UserDashBoard_GroupContact();
193 $gContact->run();
194 }
195 else {
196 $this->assign('showGroup', FALSE);
197 }
198 }
199
200 /**
fe482240 201 * Perform actions and display for user dashboard.
6a488035 202 */
00be9182 203 public function run() {
6a488035
TO
204 $this->preProcess();
205 $this->buildUserDashBoard();
206 return parent::run();
207 }
208
209 /**
fe482240 210 * Get action links.
6a488035 211 *
a6c01b45
CW
212 * @return array
213 * (reference) of action links
6a488035 214 */
74607358 215 public static function &links() {
6a488035
TO
216 if (!(self::$_links)) {
217 $disableExtra = ts('Are you sure you want to disable this relationship?');
218
219 self::$_links = array(
220 CRM_Core_Action::UPDATE => array(
221 'name' => ts('Edit Contact Information'),
222 'url' => 'civicrm/contact/relatedcontact',
223 'qs' => 'action=update&reset=1&cid=%%cbid%%&rcid=%%cid%%',
224 'title' => ts('Edit Relationship'),
225 ),
226 CRM_Core_Action::VIEW => array(
227 'name' => ts('Dashboard'),
228 'url' => 'civicrm/user',
5940abe4 229 'class' => 'no-popup',
6a488035
TO
230 'qs' => 'reset=1&id=%%cbid%%',
231 'title' => ts('View Relationship'),
232 ),
233 );
234
6a488035
TO
235 if (CRM_Core_Permission::check('access CiviCRM')) {
236 self::$_links = array_merge(self::$_links, array(
237 CRM_Core_Action::DISABLE => array(
353ffa53
TO
238 'name' => ts('Disable'),
239 'url' => 'civicrm/contact/view/rel',
240 'qs' => 'action=disable&reset=1&cid=%%cid%%&id=%%id%%&rtype=%%rtype%%&selectedChild=rel&context=dashboard',
241 'extra' => 'onclick = "return confirm(\'' . $disableExtra . '\');"',
242 'title' => ts('Disable Relationship'),
243 ),
244 ));
6a488035
TO
245 }
246 }
247
248 // call the hook so we can modify it
249 CRM_Utils_Hook::links('view.contact.userDashBoard',
250 'Contact',
251 CRM_Core_DAO::$_nullObject,
1273d77c 252 self::$_links
6a488035
TO
253 );
254 return self::$_links;
255 }
96025800 256
6a488035 257}