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