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 | ||
60 | function __construct() { | |
6a488035 TO |
61 | parent::__construct(); |
62 | ||
63 | $check = CRM_Core_Permission::check('access Contact Dashboard'); | |
64 | ||
65 | if (!$check) { | |
66 | CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/dashboard', 'reset=1')); | |
67 | break; | |
68 | } | |
69 | ||
70 | $this->_contactId = CRM_Utils_Request::retrieve('id', 'Positive', $this); | |
71 | ||
72 | $session = CRM_Core_Session::singleton(); | |
73 | $userID = $session->get('userID'); | |
74 | ||
75 | if (!$this->_contactId) { | |
76 | $this->_contactId = $userID; | |
77 | } | |
78 | elseif ($this->_contactId != $userID) { | |
79 | if (!CRM_Contact_BAO_Contact_Permission::allow($this->_contactId, CRM_Core_Permission::VIEW)) { | |
80 | CRM_Core_Error::fatal(ts('You do not have permission to view this contact')); | |
81 | } | |
82 | if (!CRM_Contact_BAO_Contact_Permission::allow($this->_contactId, CRM_Core_Permission::EDIT)) { | |
83 | $this->_edit = FALSE; | |
84 | } | |
85 | } | |
86 | } | |
87 | ||
88 | /* | |
89 | * Heart of the viewing process. The runner gets all the meta data for | |
90 | * the contact and calls the appropriate type of page to view. | |
91 | * | |
92 | * @return void | |
93 | * @access public | |
94 | * | |
95 | */ | |
96 | function preProcess() { | |
97 | if (!$this->_contactId) { | |
98 | CRM_Core_Error::fatal(ts('You must be logged in to view this page.')); | |
99 | } | |
100 | ||
101 | list($displayName, $contactImage) = CRM_Contact_BAO_Contact::getDisplayAndImage($this->_contactId); | |
102 | ||
103 | $this->set('displayName', $displayName); | |
104 | $this->set('contactImage', $contactImage); | |
105 | ||
106 | CRM_Utils_System::setTitle(ts('Dashboard - %1', array(1 => $displayName))); | |
107 | ||
108 | $this->assign('recentlyViewed', FALSE); | |
109 | } | |
110 | ||
111 | /** | |
112 | * Function to build user dashboard | |
113 | * | |
355ba699 | 114 | * @return void |
6a488035 TO |
115 | * @access public |
116 | */ | |
117 | function buildUserDashBoard() { | |
118 | //build component selectors | |
119 | $dashboardElements = array(); | |
120 | $config = CRM_Core_Config::singleton(); | |
121 | ||
122 | $this->_userOptions = CRM_Core_BAO_Setting::valueOptions(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, | |
123 | 'user_dashboard_options' | |
124 | ); | |
125 | ||
126 | $components = CRM_Core_Component::getEnabledComponents(); | |
127 | $this->assign('contactId', $this->_contactId); | |
128 | foreach ($components as $name => $component) { | |
129 | $elem = $component->getUserDashboardElement(); | |
130 | if (!$elem) { | |
131 | continue; | |
132 | } | |
133 | ||
a7488080 | 134 | if (!empty($this->_userOptions[$name]) && |
6a488035 TO |
135 | (CRM_Core_Permission::access($component->name) || |
136 | CRM_Core_Permission::check($elem['perm'][0]) | |
137 | ) | |
138 | ) { | |
139 | ||
140 | $userDashboard = $component->getUserDashboardObject(); | |
e81ccbf6 FG |
141 | $dashboardElements[] = array( |
142 | 'class' => 'crm-dashboard-' . strtolower($component->name), | |
6a488035 | 143 | 'sectionTitle' => $elem['title'], |
e81ccbf6 | 144 | 'templatePath' => $userDashboard->getTemplateFileName(), |
6a488035 TO |
145 | 'weight' => $elem['weight'], |
146 | ); | |
147 | $userDashboard->run(); | |
148 | } | |
149 | } | |
150 | ||
a7488080 | 151 | if (!empty($this->_userOptions['Permissioned Orgs'])) { |
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 | ||
a7488080 | 173 | if (!empty($this->_userOptions['Assigned Activities'])) { |
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 | ); | |
181 | $userDashboard = new CRM_Activity_Page_UserDashboard; | |
182 | $userDashboard->run(); | |
183 | } | |
184 | ||
185 | usort($dashboardElements, array('CRM_Utils_Sort', 'cmpFunc')); | |
186 | $this->assign('dashboardElements', $dashboardElements); | |
187 | ||
a7488080 | 188 | if (!empty($this->_userOptions['Groups'])) { |
6a488035 TO |
189 | $this->assign('showGroup', TRUE); |
190 | //build group selector | |
191 | $gContact = new CRM_Contact_Page_View_UserDashBoard_GroupContact(); | |
192 | $gContact->run(); | |
193 | } | |
194 | else { | |
195 | $this->assign('showGroup', FALSE); | |
196 | } | |
197 | } | |
198 | ||
199 | /** | |
200 | * perform actions and display for user dashboard | |
201 | * | |
355ba699 | 202 | * @return void |
6a488035 TO |
203 | * |
204 | * @access public | |
205 | */ | |
206 | function run() { | |
207 | $this->preProcess(); | |
208 | $this->buildUserDashBoard(); | |
209 | return parent::run(); | |
210 | } | |
211 | ||
212 | /** | |
213 | * Get action links | |
214 | * | |
215 | * @return array (reference) of action links | |
216 | * @static | |
217 | */ | |
218 | static | |
219 | function &links() { | |
220 | if (!(self::$_links)) { | |
221 | $disableExtra = ts('Are you sure you want to disable this relationship?'); | |
222 | ||
223 | self::$_links = array( | |
224 | CRM_Core_Action::UPDATE => array( | |
225 | 'name' => ts('Edit Contact Information'), | |
226 | 'url' => 'civicrm/contact/relatedcontact', | |
227 | 'qs' => 'action=update&reset=1&cid=%%cbid%%&rcid=%%cid%%', | |
228 | 'title' => ts('Edit Relationship'), | |
229 | ), | |
230 | CRM_Core_Action::VIEW => array( | |
231 | 'name' => ts('Dashboard'), | |
232 | 'url' => 'civicrm/user', | |
233 | 'qs' => 'reset=1&id=%%cbid%%', | |
234 | 'title' => ts('View Relationship'), | |
235 | ), | |
236 | ); | |
237 | ||
238 | ||
239 | if (CRM_Core_Permission::check('access CiviCRM')) { | |
240 | self::$_links = array_merge(self::$_links, array( | |
241 | CRM_Core_Action::DISABLE => array( | |
242 | 'name' => ts('Disable'), | |
243 | 'url' => 'civicrm/contact/view/rel', | |
a9b15f31 | 244 | 'qs' => 'action=disable&reset=1&cid=%%cid%%&id=%%id%%&rtype=%%rtype%%&selectedChild=rel&context=dashboard', |
6a488035 TO |
245 | 'extra' => 'onclick = "return confirm(\'' . $disableExtra . '\');"', |
246 | 'title' => ts('Disable Relationship'), | |
247 | ), | |
248 | )); | |
249 | } | |
250 | } | |
251 | ||
252 | // call the hook so we can modify it | |
253 | CRM_Utils_Hook::links('view.contact.userDashBoard', | |
254 | 'Contact', | |
255 | CRM_Core_DAO::$_nullObject, | |
256 | self::$_links, | |
a9b15f31 | 257 | CRM_Core_DAO::$_nullObject, |
6a488035 TO |
258 | CRM_Core_DAO::$_nullObject |
259 | ); | |
260 | return self::$_links; | |
261 | } | |
262 | } |