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