Merge pull request #11660 from JMAConsulting/CRM-21754
[civicrm-core.git] / CRM / Report / Page / Report.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 5 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2018 |
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-2018
32 */
33
34 /**
35 * Page for invoking report templates.
36 */
37 class CRM_Report_Page_Report extends CRM_Core_Page {
38
39 /**
40 * Run this page (figure out the action needed and perform it).
41 */
42 public function run() {
43 if (!CRM_Core_Permission::check('administer Reports')) {
44 return CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/report/list', 'reset=1'));
45 }
46
47 $optionVal = CRM_Report_Utils_Report::getValueFromUrl();
48
49 $templateInfo = CRM_Core_OptionGroup::getRowValues('report_template', "{$optionVal}", 'value',
50 'String', FALSE, TRUE
51 );
52
53 $extKey = strpos(CRM_Utils_Array::value('name', $templateInfo), '.');
54
55 $reportClass = NULL;
56
57 if ($extKey !== FALSE) {
58 $ext = CRM_Extension_System::singleton()->getMapper();
59 $reportClass = $ext->keyToClass($templateInfo['name'], 'report');
60 $templateInfo['name'] = $reportClass;
61 }
62
63 if (strstr(CRM_Utils_Array::value('name', $templateInfo), '_Form') || !is_null($reportClass)) {
64 CRM_Utils_System::setTitle(ts('%1 - Template', array(1 => $templateInfo['label'])));
65 $this->assign('reportTitle', $templateInfo['label']);
66
67 $session = CRM_Core_Session::singleton();
68 $session->set('reportDescription', $templateInfo['description']);
69
70 $wrapper = new CRM_Utils_Wrapper();
71
72 return $wrapper->run($templateInfo['name'], NULL, NULL);
73 }
74
75 if ($optionVal) {
76 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');
77 }
78 return CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/report/list', 'reset=1'));
79 }
80
81 }