Commit | Line | Data |
---|---|---|
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 | */ |
37 | class 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) { | |
e8401861 | 75 | $this->assign('userChecksum', $userChecksum); |
2b329653 | 76 | $validUser = CRM_Contact_BAO_Contact_Utils::validChecksum($this->_contactId, $userChecksum); |
4ded03d2 | 77 | $this->_isChecksumUser = $validUser; |
2b329653 JP |
78 | } |
79 | ||
6a488035 TO |
80 | if (!$this->_contactId) { |
81 | $this->_contactId = $userID; | |
82 | } | |
2b329653 | 83 | elseif ($this->_contactId != $userID && !$validUser) { |
6a488035 | 84 | if (!CRM_Contact_BAO_Contact_Permission::allow($this->_contactId, CRM_Core_Permission::VIEW)) { |
994b9e9f | 85 | CRM_Core_Error::fatal(ts('You do not have permission to access this contact.')); |
6a488035 TO |
86 | } |
87 | if (!CRM_Contact_BAO_Contact_Permission::allow($this->_contactId, CRM_Core_Permission::EDIT)) { | |
88 | $this->_edit = FALSE; | |
89 | } | |
90 | } | |
91 | } | |
92 | ||
c490a46a | 93 | /** |
95cdcc0f | 94 | * Heart of the viewing process. |
c490a46a | 95 | * |
95cdcc0f | 96 | * The runner gets all the meta data for the contact and calls the appropriate type of page to view. |
c490a46a | 97 | */ |
00be9182 | 98 | public function preProcess() { |
6a488035 TO |
99 | if (!$this->_contactId) { |
100 | CRM_Core_Error::fatal(ts('You must be logged in to view this page.')); | |
101 | } | |
102 | ||
103 | list($displayName, $contactImage) = CRM_Contact_BAO_Contact::getDisplayAndImage($this->_contactId); | |
104 | ||
105 | $this->set('displayName', $displayName); | |
106 | $this->set('contactImage', $contactImage); | |
107 | ||
108 | CRM_Utils_System::setTitle(ts('Dashboard - %1', array(1 => $displayName))); | |
109 | ||
110 | $this->assign('recentlyViewed', FALSE); | |
111 | } | |
112 | ||
113 | /** | |
fe482240 | 114 | * Build user dashboard. |
6a488035 | 115 | */ |
00be9182 | 116 | public function buildUserDashBoard() { |
6a488035 TO |
117 | //build component selectors |
118 | $dashboardElements = array(); | |
119 | $config = CRM_Core_Config::singleton(); | |
120 | ||
121 | $this->_userOptions = CRM_Core_BAO_Setting::valueOptions(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, | |
122 | 'user_dashboard_options' | |
123 | ); | |
124 | ||
125 | $components = CRM_Core_Component::getEnabledComponents(); | |
126 | $this->assign('contactId', $this->_contactId); | |
127 | foreach ($components as $name => $component) { | |
128 | $elem = $component->getUserDashboardElement(); | |
129 | if (!$elem) { | |
130 | continue; | |
131 | } | |
132 | ||
a7488080 | 133 | if (!empty($this->_userOptions[$name]) && |
6a488035 TO |
134 | (CRM_Core_Permission::access($component->name) || |
135 | CRM_Core_Permission::check($elem['perm'][0]) | |
136 | ) | |
137 | ) { | |
138 | ||
139 | $userDashboard = $component->getUserDashboardObject(); | |
e81ccbf6 FG |
140 | $dashboardElements[] = array( |
141 | 'class' => 'crm-dashboard-' . strtolower($component->name), | |
6a488035 | 142 | 'sectionTitle' => $elem['title'], |
e81ccbf6 | 143 | 'templatePath' => $userDashboard->getTemplateFileName(), |
6a488035 TO |
144 | 'weight' => $elem['weight'], |
145 | ); | |
146 | $userDashboard->run(); | |
147 | } | |
148 | } | |
149 | ||
bb36d17a CW |
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')) { | |
6a488035 | 152 | $dashboardElements[] = array( |
e81ccbf6 | 153 | 'class' => 'crm-dashboard-permissionedOrgs', |
d0592c3d | 154 | 'templatePath' => 'CRM/Contact/Page/View/RelationshipSelector.tpl', |
6a488035 TO |
155 | 'sectionTitle' => ts('Your Contacts / Organizations'), |
156 | 'weight' => 40, | |
157 | ); | |
158 | ||
6a488035 TO |
159 | } |
160 | ||
a7488080 | 161 | if (!empty($this->_userOptions['PCP'])) { |
6a488035 | 162 | $dashboardElements[] = array( |
e81ccbf6 | 163 | 'class' => 'crm-dashboard-pcp', |
6a488035 TO |
164 | 'templatePath' => 'CRM/Contribute/Page/PcpUserDashboard.tpl', |
165 | 'sectionTitle' => ts('Personal Campaign Pages'), | |
166 | 'weight' => 40, | |
167 | ); | |
168 | list($pcpBlock, $pcpInfo) = CRM_PCP_BAO_PCP::getPcpDashboardInfo($this->_contactId); | |
169 | $this->assign('pcpBlock', $pcpBlock); | |
170 | $this->assign('pcpInfo', $pcpInfo); | |
171 | } | |
172 | ||
4ded03d2 | 173 | if (!empty($this->_userOptions['Assigned Activities']) && empty($this->_isChecksumUser)) { |
6a488035 TO |
174 | // Assigned Activities section |
175 | $dashboardElements[] = array( | |
e81ccbf6 | 176 | 'class' => 'crm-dashboard-assignedActivities', |
6a488035 TO |
177 | 'templatePath' => 'CRM/Activity/Page/UserDashboard.tpl', |
178 | 'sectionTitle' => ts('Your Assigned Activities'), | |
179 | 'weight' => 5, | |
180 | ); | |
acb1052e | 181 | $userDashboard = new CRM_Activity_Page_UserDashboard(); |
6a488035 TO |
182 | $userDashboard->run(); |
183 | } | |
184 | ||
185 | usort($dashboardElements, array('CRM_Utils_Sort', 'cmpFunc')); | |
186 | $this->assign('dashboardElements', $dashboardElements); | |
187 | ||
56ed0b01 PB |
188 | // return true when 'Invoices / Credit Notes' checkbox is checked |
189 | $this->assign('invoices', $this->_userOptions['Invoices / Credit Notes']); | |
190 | ||
a7488080 | 191 | if (!empty($this->_userOptions['Groups'])) { |
6a488035 TO |
192 | $this->assign('showGroup', TRUE); |
193 | //build group selector | |
194 | $gContact = new CRM_Contact_Page_View_UserDashBoard_GroupContact(); | |
195 | $gContact->run(); | |
196 | } | |
197 | else { | |
198 | $this->assign('showGroup', FALSE); | |
199 | } | |
200 | } | |
201 | ||
202 | /** | |
fe482240 | 203 | * Perform actions and display for user dashboard. |
6a488035 | 204 | */ |
00be9182 | 205 | public function run() { |
6a488035 TO |
206 | $this->preProcess(); |
207 | $this->buildUserDashBoard(); | |
208 | return parent::run(); | |
209 | } | |
210 | ||
211 | /** | |
fe482240 | 212 | * Get action links. |
6a488035 | 213 | * |
a6c01b45 CW |
214 | * @return array |
215 | * (reference) of action links | |
6a488035 | 216 | */ |
74607358 | 217 | public static function &links() { |
6a488035 TO |
218 | if (!(self::$_links)) { |
219 | $disableExtra = ts('Are you sure you want to disable this relationship?'); | |
220 | ||
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'), | |
227 | ), | |
228 | CRM_Core_Action::VIEW => array( | |
229 | 'name' => ts('Dashboard'), | |
230 | 'url' => 'civicrm/user', | |
5940abe4 | 231 | 'class' => 'no-popup', |
6a488035 TO |
232 | 'qs' => 'reset=1&id=%%cbid%%', |
233 | 'title' => ts('View Relationship'), | |
234 | ), | |
235 | ); | |
236 | ||
6a488035 TO |
237 | if (CRM_Core_Permission::check('access CiviCRM')) { |
238 | self::$_links = array_merge(self::$_links, array( | |
239 | CRM_Core_Action::DISABLE => array( | |
353ffa53 TO |
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'), | |
245 | ), | |
246 | )); | |
6a488035 TO |
247 | } |
248 | } | |
249 | ||
250 | // call the hook so we can modify it | |
251 | CRM_Utils_Hook::links('view.contact.userDashBoard', | |
252 | 'Contact', | |
253 | CRM_Core_DAO::$_nullObject, | |
1273d77c | 254 | self::$_links |
6a488035 TO |
255 | ); |
256 | return self::$_links; | |
257 | } | |
96025800 | 258 | |
6a488035 | 259 | } |