3 +--------------------------------------------------------------------+
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2018 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
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. |
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. |
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 +--------------------------------------------------------------------+
31 * @copyright CiviCRM LLC (c) 2004-2018
35 * This class is used to build User Dashboard
37 class CRM_Contact_Page_View_UserDashBoard
extends CRM_Core_Page
{
38 public $_contactId = NULL;
41 * Always show public groups.
44 public $_onlyPublicGroups = TRUE;
49 * The action links that we need to display for the browse screen.
53 static $_links = NULL;
58 public function __construct() {
59 parent
::__construct();
61 $check = CRM_Core_Permission
::check('access Contact Dashboard');
64 CRM_Utils_System
::redirect(CRM_Utils_System
::url('civicrm/dashboard', 'reset=1'));
67 $this->_contactId
= CRM_Utils_Request
::retrieve('id', 'Positive', $this);
69 $session = CRM_Core_Session
::singleton();
70 $userID = $session->get('userID');
72 $userChecksum = CRM_Utils_Request
::retrieve('cs', 'String', $this);
74 if (empty($userID) && $this->_contactId
&& $userChecksum) {
75 $this->assign('userChecksum', $userChecksum);
76 $validUser = CRM_Contact_BAO_Contact_Utils
::validChecksum($this->_contactId
, $userChecksum);
77 $this->_isChecksumUser
= $validUser;
80 if (!$this->_contactId
) {
81 $this->_contactId
= $userID;
83 elseif ($this->_contactId
!= $userID && !$validUser) {
84 if (!CRM_Contact_BAO_Contact_Permission
::allow($this->_contactId
, CRM_Core_Permission
::VIEW
)) {
85 CRM_Core_Error
::fatal(ts('You do not have permission to access this contact.'));
87 if (!CRM_Contact_BAO_Contact_Permission
::allow($this->_contactId
, CRM_Core_Permission
::EDIT
)) {
94 * Heart of the viewing process.
96 * The runner gets all the meta data for the contact and calls the appropriate type of page to view.
98 public function preProcess() {
99 if (!$this->_contactId
) {
100 CRM_Core_Error
::fatal(ts('You must be logged in to view this page.'));
103 list($displayName, $contactImage) = CRM_Contact_BAO_Contact
::getDisplayAndImage($this->_contactId
);
105 $this->set('displayName', $displayName);
106 $this->set('contactImage', $contactImage);
108 CRM_Utils_System
::setTitle(ts('Dashboard - %1', array(1 => $displayName)));
110 $this->assign('recentlyViewed', FALSE);
114 * Build user dashboard.
116 public function buildUserDashBoard() {
117 //build component selectors
118 $dashboardElements = array();
119 $config = CRM_Core_Config
::singleton();
121 $this->_userOptions
= CRM_Core_BAO_Setting
::valueOptions(CRM_Core_BAO_Setting
::SYSTEM_PREFERENCES_NAME
,
122 'user_dashboard_options'
125 $components = CRM_Core_Component
::getEnabledComponents();
126 $this->assign('contactId', $this->_contactId
);
127 foreach ($components as $name => $component) {
128 $elem = $component->getUserDashboardElement();
133 if (!empty($this->_userOptions
[$name]) &&
134 (CRM_Core_Permission
::access($component->name
) ||
135 CRM_Core_Permission
::check($elem['perm'][0])
139 $userDashboard = $component->getUserDashboardObject();
140 $dashboardElements[] = array(
141 'class' => 'crm-dashboard-' . strtolower($component->name
),
142 'sectionTitle' => $elem['title'],
143 'templatePath' => $userDashboard->getTemplateFileName(),
144 'weight' => $elem['weight'],
146 $userDashboard->run();
150 // CRM-16512 - Hide related contact table if user lacks permission to view self
151 if (!empty($this->_userOptions
['Permissioned Orgs']) && CRM_Core_Permission
::check('view my contact')) {
152 $dashboardElements[] = array(
153 'class' => 'crm-dashboard-permissionedOrgs',
154 'templatePath' => 'CRM/Contact/Page/View/RelationshipSelector.tpl',
155 'sectionTitle' => ts('Your Contacts / Organizations'),
161 if (!empty($this->_userOptions
['PCP'])) {
162 $dashboardElements[] = array(
163 'class' => 'crm-dashboard-pcp',
164 'templatePath' => 'CRM/Contribute/Page/PcpUserDashboard.tpl',
165 'sectionTitle' => ts('Personal Campaign Pages'),
168 list($pcpBlock, $pcpInfo) = CRM_PCP_BAO_PCP
::getPcpDashboardInfo($this->_contactId
);
169 $this->assign('pcpBlock', $pcpBlock);
170 $this->assign('pcpInfo', $pcpInfo);
173 if (!empty($this->_userOptions
['Assigned Activities']) && empty($this->_isChecksumUser
)) {
174 // Assigned Activities section
175 $dashboardElements[] = array(
176 'class' => 'crm-dashboard-assignedActivities',
177 'templatePath' => 'CRM/Activity/Page/UserDashboard.tpl',
178 'sectionTitle' => ts('Your Assigned Activities'),
181 $userDashboard = new CRM_Activity_Page_UserDashboard();
182 $userDashboard->run();
185 usort($dashboardElements, array('CRM_Utils_Sort', 'cmpFunc'));
186 $this->assign('dashboardElements', $dashboardElements);
188 // return true when 'Invoices / Credit Notes' checkbox is checked
189 $this->assign('invoices', $this->_userOptions
['Invoices / Credit Notes']);
191 if (!empty($this->_userOptions
['Groups'])) {
192 $this->assign('showGroup', TRUE);
193 //build group selector
194 $gContact = new CRM_Contact_Page_View_UserDashBoard_GroupContact();
198 $this->assign('showGroup', FALSE);
203 * Perform actions and display for user dashboard.
205 public function run() {
207 $this->buildUserDashBoard();
208 return parent
::run();
215 * (reference) of action links
217 public static function &links() {
218 if (!(self
::$_links)) {
219 $disableExtra = ts('Are you sure you want to disable this relationship?');
221 self
::$_links = array(
222 CRM_Core_Action
::UPDATE
=> array(
223 'name' => ts('Edit Contact Information'),
224 'url' => 'civicrm/contact/relatedcontact',
225 'qs' => 'action=update&reset=1&cid=%%cbid%%&rcid=%%cid%%',
226 'title' => ts('Edit Relationship'),
228 CRM_Core_Action
::VIEW
=> array(
229 'name' => ts('Dashboard'),
230 'url' => 'civicrm/user',
231 'class' => 'no-popup',
232 'qs' => 'reset=1&id=%%cbid%%',
233 'title' => ts('View Relationship'),
237 if (CRM_Core_Permission
::check('access CiviCRM')) {
238 self
::$_links = array_merge(self
::$_links, array(
239 CRM_Core_Action
::DISABLE
=> array(
240 'name' => ts('Disable'),
241 'url' => 'civicrm/contact/view/rel',
242 'qs' => 'action=disable&reset=1&cid=%%cid%%&id=%%id%%&rtype=%%rtype%%&selectedChild=rel&context=dashboard',
243 'extra' => 'onclick = "return confirm(\'' . $disableExtra . '\');"',
244 'title' => ts('Disable Relationship'),
250 // call the hook so we can modify it
251 CRM_Utils_Hook
::links('view.contact.userDashBoard',
253 CRM_Core_DAO
::$_nullObject,
256 return self
::$_links;