Merge pull request #19421 from eileenmcnaughton/act2
[civicrm-core.git] / CRM / Report / Page / Report.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 templates.
20 */
21 class CRM_Report_Page_Report extends CRM_Core_Page {
22
23 /**
24 * Run this page (figure out the action needed and perform it).
25 */
26 public function run() {
27 if (!CRM_Core_Permission::check('administer Reports')) {
28 return CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/report/list', 'reset=1'));
29 }
30
31 $optionVal = CRM_Report_Utils_Report::getValueFromUrl();
32
33 $templateInfo = CRM_Core_OptionGroup::getRowValues('report_template', "{$optionVal}", 'value',
34 'String', FALSE, TRUE
35 );
36
37 $extKey = strpos(CRM_Utils_Array::value('name', $templateInfo), '.');
38
39 $reportClass = NULL;
40
41 if ($extKey !== FALSE) {
42 $ext = CRM_Extension_System::singleton()->getMapper();
43 $reportClass = $ext->keyToClass($templateInfo['name'], 'report');
44 $templateInfo['name'] = $reportClass;
45 }
46
47 if (strstr(CRM_Utils_Array::value('name', $templateInfo), '_Form') || !is_null($reportClass)) {
48 CRM_Utils_System::setTitle(ts('%1 - Template', [1 => $templateInfo['label']]));
49 $this->assign('reportTitle', $templateInfo['label']);
50
51 $session = CRM_Core_Session::singleton();
52 $session->set('reportDescription', $templateInfo['description']);
53
54 $wrapper = new CRM_Utils_Wrapper();
55
56 return $wrapper->run($templateInfo['name'], NULL, NULL);
57 }
58
59 if ($optionVal) {
60 CRM_Core_Session::setStatus(ts('Could not find the report template. Make sure the report template is registered and / or url is correct.'), ts('Template Not Found'), 'error');
61 }
62 return CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/report/list', 'reset=1'));
63 }
64
65 }