Merge remote-tracking branch 'upstream/4.4' into 4.4-master-2014-04-21-08-12-12
[civicrm-core.git] / CRM / Case / Page / DashBoard.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.5 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
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-2014
32 * $Id$
33 *
34 */
35
36 /**
37 * This page is for Case Dashboard
38 */
39 class CRM_Case_Page_DashBoard extends CRM_Core_Page {
40
41 public $useLivePageJS = TRUE;
42
43 /**
44 * Heart of the viewing process. The runner gets all the meta data for
45 * the contact and calls the appropriate type of page to view.
46 *
47 * @return void
48 * @access public
49 *
50 */
51 function preProcess() {
52 //check for civicase access.
53 if (!CRM_Case_BAO_Case::accessCiviCase()) {
54 CRM_Core_Error::fatal(ts('You are not authorized to access this page.'));
55 }
56
57 //validate case configuration.
58 $configured = CRM_Case_BAO_Case::isCaseConfigured();
59 $this->assign('notConfigured', !$configured['configured']);
60 $this->assign('allowToAddNewCase', $configured['allowToAddNewCase']);
61 if (!$configured['configured']) {
62 return;
63 }
64
65 $session = CRM_Core_Session::singleton();
66 $allCases = CRM_Utils_Request::retrieve('all', 'Positive', $session);
67
68 CRM_Utils_System::setTitle(ts('CiviCase Dashboard'));
69
70 $userID = $session->get('userID');
71
72 //validate access for all cases.
73 if ($allCases && !CRM_Core_Permission::check('access all cases and activities')) {
74 $allCases = FALSE;
75 CRM_Core_Session::setStatus(ts('You are not authorized to access all cases and activities.'), ts('Sorry'), 'error');
76 }
77 if (!$allCases) {
78 $this->assign('myCases', TRUE);
79 }
80 else {
81 $this->assign('myCases', FALSE);
82 }
83
84 $this->assign('newClient', FALSE);
85 if (CRM_Core_Permission::check('add contacts') &&
86 CRM_Core_Permission::check('access all cases and activities')
87 ) {
88 $this->assign('newClient', TRUE);
89 }
90 $summary = CRM_Case_BAO_Case::getCasesSummary($allCases, $userID);
91 $upcoming = CRM_Case_BAO_Case::getCases($allCases, $userID, 'upcoming');
92 $recent = CRM_Case_BAO_Case::getCases($allCases, $userID, 'recent');
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 * This function is 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 * @access public
109 */
110 function run() {
111 $this->preProcess();
112
113 return parent::run();
114 }
115 }
116