Merge pull request #23157 from eileenmcnaughton/anet
[civicrm-core.git] / CRM / Report / Page / Instance.php
CommitLineData
6a488035 1<?php
6a488035
TO
2/*
3 +--------------------------------------------------------------------+
bc77d7c0 4 | Copyright CiviCRM LLC. All rights reserved. |
6a488035 5 | |
bc77d7c0
TO
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
6a488035 9 +--------------------------------------------------------------------+
d25dd0ee 10 */
6a488035
TO
11
12/**
13 *
14 * @package CRM
ca5cec67 15 * @copyright CiviCRM LLC https://civicrm.org/licensing
6a488035
TO
16 */
17
18/**
19 * Page for invoking report instances
20 */
21class CRM_Report_Page_Instance extends CRM_Core_Page {
c86d4e7c 22
6a488035 23 /**
100fef9d 24 * Run this page (figure out the action needed and perform it).
6a488035 25 */
00be9182 26 public function run() {
6a488035
TO
27 $instanceId = CRM_Report_Utils_Report::getInstanceID();
28 if (!$instanceId) {
29 $instanceId = CRM_Report_Utils_Report::getInstanceIDForPath();
30 }
e3c612db 31
32 $action = CRM_Utils_Request::retrieve('action', 'String', $this);
33 $reportUrl = CRM_Utils_System::url('civicrm/report/list', "reset=1");
34
35 if ($action & CRM_Core_Action::DELETE) {
add1919d 36 CRM_Report_BAO_ReportInstance::doFormDelete($instanceId, $reportUrl);
e3c612db 37 return CRM_Utils_System::redirect($reportUrl);
38 }
39
182f5081 40 if (is_numeric($instanceId)) {
41 $instanceURL = CRM_Utils_System::url("civicrm/report/instance/{$instanceId}", 'reset=1');
42 CRM_Core_Session::singleton()->replaceUserContext($instanceURL);
43 }
6a488035 44 $optionVal = CRM_Report_Utils_Report::getValueFromUrl($instanceId);
e3c612db 45 $templateInfo = CRM_Core_OptionGroup::getRowValues('report_template', "{$optionVal}", 'value');
46 if (empty($templateInfo)) {
507bc932 47 CRM_Core_Error::statusBounce(ts('You have tried to access a report that does not exist.'));
e3c612db 48 }
6a488035 49
e3c612db 50 $extKey = strpos($templateInfo['name'], '.');
6a488035 51
e3c612db 52 $reportClass = NULL;
6a488035 53
e3c612db 54 if ($extKey !== FALSE) {
55 $ext = CRM_Extension_System::singleton()->getMapper();
56 $reportClass = $ext->keyToClass($templateInfo['name'], 'report');
57 $templateInfo['name'] = $reportClass;
6a488035 58 }
6a488035 59
e3c612db 60 if (strstr($templateInfo['name'], '_Form') || !is_null($reportClass)) {
be2fb01f
CW
61 $instanceInfo = [];
62 CRM_Report_BAO_ReportInstance::retrieve(['id' => $instanceId], $instanceInfo);
6a488035 63
e3c612db 64 if (!empty($instanceInfo['title'])) {
65 CRM_Utils_System::setTitle($instanceInfo['title']);
66 $this->assign('reportTitle', $instanceInfo['title']);
6a488035 67 }
e3c612db 68 else {
69 CRM_Utils_System::setTitle($templateInfo['label']);
70 $this->assign('reportTitle', $templateInfo['label']);
6a488035
TO
71 }
72
e3c612db 73 $wrapper = new CRM_Utils_Wrapper();
74 return $wrapper->run($templateInfo['name'], NULL, NULL);
6a488035 75 }
e3c612db 76
77 CRM_Core_Session::setStatus(ts('Could not find template for the instance.'), ts('Template Not Found'), 'error');
78
6a488035
TO
79 return CRM_Utils_System::redirect($reportUrl);
80 }
96025800 81
6a488035 82}