9d9c78130212b7c6c88c84174185aae861523839
[civicrm-core.git] / CRM / Report / Page / Instance.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 5 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2019 |
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-2019
32 */
33
34 /**
35 * Page for invoking report instances
36 */
37 class CRM_Report_Page_Instance extends CRM_Core_Page {
38
39 /**
40 * Run this page (figure out the action needed and perform it).
41 */
42 public function run() {
43 $instanceId = CRM_Report_Utils_Report::getInstanceID();
44 if (!$instanceId) {
45 $instanceId = CRM_Report_Utils_Report::getInstanceIDForPath();
46 }
47
48 $action = CRM_Utils_Request::retrieve('action', 'String', $this);
49 $reportUrl = CRM_Utils_System::url('civicrm/report/list', "reset=1");
50
51 if ($action & CRM_Core_Action::DELETE) {
52 CRM_Report_BAO_ReportInstance::doFormDelete($instanceId, $reportUrl);
53 return CRM_Utils_System::redirect($reportUrl);
54 }
55
56 if (is_numeric($instanceId)) {
57 $instanceURL = CRM_Utils_System::url("civicrm/report/instance/{$instanceId}", 'reset=1');
58 CRM_Core_Session::singleton()->replaceUserContext($instanceURL);
59 }
60 $optionVal = CRM_Report_Utils_Report::getValueFromUrl($instanceId);
61 $templateInfo = CRM_Core_OptionGroup::getRowValues('report_template', "{$optionVal}", 'value');
62 if (empty($templateInfo)) {
63 CRM_Core_Error::statusBounce('You have tried to access a report that does not exist.');
64 }
65
66 $extKey = strpos($templateInfo['name'], '.');
67
68 $reportClass = NULL;
69
70 if ($extKey !== FALSE) {
71 $ext = CRM_Extension_System::singleton()->getMapper();
72 $reportClass = $ext->keyToClass($templateInfo['name'], 'report');
73 $templateInfo['name'] = $reportClass;
74 }
75
76 if (strstr($templateInfo['name'], '_Form') || !is_null($reportClass)) {
77 $instanceInfo = [];
78 CRM_Report_BAO_ReportInstance::retrieve(['id' => $instanceId], $instanceInfo);
79
80 if (!empty($instanceInfo['title'])) {
81 CRM_Utils_System::setTitle($instanceInfo['title']);
82 $this->assign('reportTitle', $instanceInfo['title']);
83 }
84 else {
85 CRM_Utils_System::setTitle($templateInfo['label']);
86 $this->assign('reportTitle', $templateInfo['label']);
87 }
88
89 $wrapper = new CRM_Utils_Wrapper();
90 return $wrapper->run($templateInfo['name'], NULL, NULL);
91 }
92
93 CRM_Core_Session::setStatus(ts('Could not find template for the instance.'), ts('Template Not Found'), 'error');
94
95 return CRM_Utils_System::redirect($reportUrl);
96 }
97
98 }