Merge pull request #8548 from fuzionnz/CRM-18811
[civicrm-core.git] / CRM / Case / Page / DashBoard.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2017 |
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-2017
32 */
33
34 /**
35 * This page is for Case Dashboard.
36 */
37 class CRM_Case_Page_DashBoard extends CRM_Core_Page {
38
39 public $useLivePageJS = TRUE;
40
41 /**
42 * Heart of the viewing process.
43 *
44 * The runner gets all the meta data for the contact and calls the appropriate type of page to view.
45 */
46 public function preProcess() {
47 //check for civicase access.
48 if (!CRM_Case_BAO_Case::accessCiviCase()) {
49 CRM_Core_Error::fatal(ts('You are not authorized to access this page.'));
50 }
51
52 //validate case configuration.
53 $configured = CRM_Case_BAO_Case::isCaseConfigured();
54 $this->assign('notConfigured', !$configured['configured']);
55 $this->assign('allowToAddNewCase', $configured['allowToAddNewCase']);
56 if (!$configured['configured']) {
57 return;
58 }
59
60 $session = CRM_Core_Session::singleton();
61 $allCases = CRM_Utils_Request::retrieve('all', 'Positive', $session);
62
63 CRM_Utils_System::setTitle(ts('CiviCase Dashboard'));
64
65 $userID = $session->get('userID');
66
67 //validate access for all cases.
68 if ($allCases && !CRM_Core_Permission::check('access all cases and activities')) {
69 $allCases = FALSE;
70 CRM_Core_Session::setStatus(ts('You are not authorized to access all cases and activities.'), ts('Sorry'), 'error');
71 }
72 if (!$allCases) {
73 $this->assign('myCases', TRUE);
74 }
75 else {
76 $this->assign('myCases', FALSE);
77 }
78
79 $this->assign('newClient', FALSE);
80 if (CRM_Core_Permission::check('add contacts') &&
81 CRM_Core_Permission::check('access all cases and activities')
82 ) {
83 $this->assign('newClient', TRUE);
84 }
85 $summary = CRM_Case_BAO_Case::getCasesSummary($allCases, $userID);
86 $upcoming = CRM_Case_BAO_Case::getCases($allCases, $userID, 'upcoming');
87 $recent = CRM_Case_BAO_Case::getCases($allCases, $userID, 'recent');
88
89 foreach ($upcoming as $key => $value) {
90 if (strtotime($value['case_scheduled_activity_date']) < time()) {
91 $upcoming[$key]['activity_status'] = 'status-overdue';
92 }
93 }
94 $this->assign('casesSummary', $summary);
95 if (!empty($upcoming)) {
96 $this->assign('upcomingCases', $upcoming);
97 }
98 if (!empty($recent)) {
99 $this->assign('recentCases', $recent);
100 }
101 }
102
103 /**
104 * the main function that is called when the page loads,
105 * it decides the which action has to be taken for the page.
106 *
107 * @return null
108 */
109 public function run() {
110 $this->preProcess();
111
112 return parent::run();
113 }
114
115 }