Commit | Line | Data |
---|---|---|
6a488035 | 1 | <?php |
6a488035 TO |
2 | |
3 | /* | |
4 | +--------------------------------------------------------------------+ | |
5 | | CiviCRM version 4.3 | | |
6 | +--------------------------------------------------------------------+ | |
7 | | Copyright CiviCRM LLC (c) 2004-2013 | | |
8 | +--------------------------------------------------------------------+ | |
9 | | This file is a part of CiviCRM. | | |
10 | | | | |
11 | | CiviCRM is free software; you can copy, modify, and distribute it | | |
12 | | under the terms of the GNU Affero General Public License | | |
13 | | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. | | |
14 | | | | |
15 | | CiviCRM is distributed in the hope that it will be useful, but | | |
16 | | WITHOUT ANY WARRANTY; without even the implied warranty of | | |
17 | | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | | |
18 | | See the GNU Affero General Public License for more details. | | |
19 | | | | |
20 | | You should have received a copy of the GNU Affero General Public | | |
21 | | License and the CiviCRM Licensing Exception along | | |
22 | | with this program; if not, contact CiviCRM LLC | | |
23 | | at info[AT]civicrm[DOT]org. If you have questions about the | | |
24 | | GNU Affero General Public License or the licensing of CiviCRM, | | |
25 | | see the CiviCRM license FAQ at http://civicrm.org/licensing | | |
26 | +--------------------------------------------------------------------+ | |
27 | */ | |
28 | ||
29 | /** | |
30 | * | |
31 | * @package CRM | |
32 | * @copyright CiviCRM LLC (c) 2004-2013 | |
33 | * $Id$ | |
34 | * | |
35 | */ | |
36 | ||
37 | /** | |
38 | * Page for invoking report instances | |
39 | */ | |
40 | class CRM_Report_Page_Instance extends CRM_Core_Page { | |
41 | /** | |
42 | * run this page (figure out the action needed and perform it). | |
43 | * | |
44 | * @return void | |
45 | */ | |
46 | function run() { | |
47 | $instanceId = CRM_Report_Utils_Report::getInstanceID(); | |
48 | if (!$instanceId) { | |
49 | $instanceId = CRM_Report_Utils_Report::getInstanceIDForPath(); | |
50 | } | |
51 | $action = CRM_Utils_Request::retrieve('action', 'String', $this); | |
52 | $optionVal = CRM_Report_Utils_Report::getValueFromUrl($instanceId); | |
53 | $reportUrl = CRM_Utils_System::url('civicrm/report/list', "reset=1"); | |
54 | ||
55 | if ($action & CRM_Core_Action::DELETE) { | |
56 | if (!CRM_Core_Permission::check('administer Reports')) { | |
57 | $statusMessage = ts('You do not have permission to Delete Report.'); | |
58 | CRM_Core_Error::statusBounce($statusMessage, $reportUrl); | |
59 | } | |
60 | ||
0b25329b DS |
61 | $navId = CRM_Core_DAO::getFieldValue('CRM_Report_DAO_ReportInstance', $instanceId, 'navigation_id', 'id'); |
62 | CRM_Report_BAO_ReportInstance::del($instanceId); | |
6a488035 TO |
63 | |
64 | //delete navigation if exists | |
65 | if ($navId) { | |
66 | CRM_Core_BAO_Navigation::processDelete($navId); | |
67 | CRM_Core_BAO_Navigation::resetNavigation(); | |
68 | } | |
69 | ||
70 | CRM_Core_Session::setStatus(ts('Selected report has been deleted.'), ts('Deleted'), 'success'); | |
71 | } | |
72 | else { | |
73 | $templateInfo = CRM_Core_OptionGroup::getRowValues('report_template', "{$optionVal}", 'value'); | |
74 | if (empty($templateInfo)) { | |
75 | CRM_Core_Session::setStatus(ts('Could not find template for this report instance.'), ts('Template Not Found'), 'error'); | |
76 | return; | |
77 | } | |
78 | ||
79 | $extKey = strpos($templateInfo['name'], '.'); | |
80 | ||
81 | $reportClass = NULL; | |
82 | ||
83 | if ($extKey !== FALSE) { | |
84 | $ext = CRM_Extension_System::singleton()->getMapper(); | |
85 | $reportClass = $ext->keyToClass($templateInfo['name'], 'report'); | |
86 | $templateInfo['name'] = $reportClass; | |
87 | } | |
88 | ||
89 | if (strstr($templateInfo['name'], '_Form') || !is_null($reportClass)) { | |
90 | $instanceInfo = array(); | |
0b25329b | 91 | CRM_Report_BAO_ReportInstance::retrieve(array('id' => $instanceId), $instanceInfo); |
6a488035 TO |
92 | |
93 | if (!empty($instanceInfo['title'])) { | |
94 | CRM_Utils_System::setTitle($instanceInfo['title']); | |
95 | $this->assign('reportTitle', $instanceInfo['title']); | |
96 | } | |
97 | else { | |
98 | CRM_Utils_System::setTitle($templateInfo['label']); | |
99 | $this->assign('reportTitle', $templateInfo['label']); | |
100 | } | |
101 | ||
102 | $wrapper = new CRM_Utils_Wrapper(); | |
103 | return $wrapper->run($templateInfo['name'], NULL, NULL); | |
104 | } | |
105 | ||
106 | CRM_Core_Session::setStatus(ts('Could not find template for the instance.'), ts('Template Not Found'), 'error'); | |
107 | } | |
108 | return CRM_Utils_System::redirect($reportUrl); | |
109 | } | |
110 | } | |
111 |