Merge pull request #23157 from eileenmcnaughton/anet
[civicrm-core.git] / CRM / Report / Page / Instance.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
5 | |
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 |
9 +--------------------------------------------------------------------+
10 */
11
12 /**
13 *
14 * @package CRM
15 * @copyright CiviCRM LLC https://civicrm.org/licensing
16 */
17
18 /**
19 * Page for invoking report instances
20 */
21 class CRM_Report_Page_Instance extends CRM_Core_Page {
22
23 /**
24 * Run this page (figure out the action needed and perform it).
25 */
26 public function run() {
27 $instanceId = CRM_Report_Utils_Report::getInstanceID();
28 if (!$instanceId) {
29 $instanceId = CRM_Report_Utils_Report::getInstanceIDForPath();
30 }
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) {
36 CRM_Report_BAO_ReportInstance::doFormDelete($instanceId, $reportUrl);
37 return CRM_Utils_System::redirect($reportUrl);
38 }
39
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 }
44 $optionVal = CRM_Report_Utils_Report::getValueFromUrl($instanceId);
45 $templateInfo = CRM_Core_OptionGroup::getRowValues('report_template', "{$optionVal}", 'value');
46 if (empty($templateInfo)) {
47 CRM_Core_Error::statusBounce(ts('You have tried to access a report that does not exist.'));
48 }
49
50 $extKey = strpos($templateInfo['name'], '.');
51
52 $reportClass = NULL;
53
54 if ($extKey !== FALSE) {
55 $ext = CRM_Extension_System::singleton()->getMapper();
56 $reportClass = $ext->keyToClass($templateInfo['name'], 'report');
57 $templateInfo['name'] = $reportClass;
58 }
59
60 if (strstr($templateInfo['name'], '_Form') || !is_null($reportClass)) {
61 $instanceInfo = [];
62 CRM_Report_BAO_ReportInstance::retrieve(['id' => $instanceId], $instanceInfo);
63
64 if (!empty($instanceInfo['title'])) {
65 CRM_Utils_System::setTitle($instanceInfo['title']);
66 $this->assign('reportTitle', $instanceInfo['title']);
67 }
68 else {
69 CRM_Utils_System::setTitle($templateInfo['label']);
70 $this->assign('reportTitle', $templateInfo['label']);
71 }
72
73 $wrapper = new CRM_Utils_Wrapper();
74 return $wrapper->run($templateInfo['name'], NULL, NULL);
75 }
76
77 CRM_Core_Session::setStatus(ts('Could not find template for the instance.'), ts('Template Not Found'), 'error');
78
79 return CRM_Utils_System::redirect($reportUrl);
80 }
81
82 }