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