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