Merge pull request #4979 from xurizaemon/codingstandards-12
[civicrm-core.git] / CRM / Report / Page / Instance.php
CommitLineData
6a488035 1<?php
6a488035
TO
2/*
3 +--------------------------------------------------------------------+
39de6fd5 4 | CiviCRM version 4.6 |
6a488035 5 +--------------------------------------------------------------------+
06b69b18 6 | Copyright CiviCRM LLC (c) 2004-2014 |
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 +--------------------------------------------------------------------+
26*/
27
28/**
29 *
30 * @package CRM
06b69b18 31 * @copyright CiviCRM LLC (c) 2004-2014
6a488035
TO
32 * $Id$
33 *
34 */
35
36/**
37 * Page for invoking report instances
38 */
39class CRM_Report_Page_Instance extends CRM_Core_Page {
40 /**
100fef9d 41 * Run this page (figure out the action needed and perform it).
6a488035
TO
42 *
43 * @return void
44 */
00be9182 45 public function run() {
6a488035
TO
46 $instanceId = CRM_Report_Utils_Report::getInstanceID();
47 if (!$instanceId) {
48 $instanceId = CRM_Report_Utils_Report::getInstanceIDForPath();
49 }
353ffa53 50 $action = CRM_Utils_Request::retrieve('action', 'String', $this);
6a488035
TO
51 $optionVal = CRM_Report_Utils_Report::getValueFromUrl($instanceId);
52 $reportUrl = CRM_Utils_System::url('civicrm/report/list', "reset=1");
53
54 if ($action & CRM_Core_Action::DELETE) {
55 if (!CRM_Core_Permission::check('administer Reports')) {
56 $statusMessage = ts('You do not have permission to Delete Report.');
57 CRM_Core_Error::statusBounce($statusMessage, $reportUrl);
58 }
59
0b25329b
DS
60 $navId = CRM_Core_DAO::getFieldValue('CRM_Report_DAO_ReportInstance', $instanceId, 'navigation_id', 'id');
61 CRM_Report_BAO_ReportInstance::del($instanceId);
6a488035
TO
62
63 //delete navigation if exists
64 if ($navId) {
65 CRM_Core_BAO_Navigation::processDelete($navId);
66 CRM_Core_BAO_Navigation::resetNavigation();
67 }
68
69 CRM_Core_Session::setStatus(ts('Selected report has been deleted.'), ts('Deleted'), 'success');
70 }
71 else {
72 $templateInfo = CRM_Core_OptionGroup::getRowValues('report_template', "{$optionVal}", 'value');
73 if (empty($templateInfo)) {
6c68db9f 74 CRM_Core_Session::setStatus(ts('Could not find template for the instance.'), ts('Template Not Found'), 'error');
6a488035
TO
75 return;
76 }
77
78 $extKey = strpos($templateInfo['name'], '.');
79
80 $reportClass = NULL;
81
82 if ($extKey !== FALSE) {
83 $ext = CRM_Extension_System::singleton()->getMapper();
84 $reportClass = $ext->keyToClass($templateInfo['name'], 'report');
85 $templateInfo['name'] = $reportClass;
86 }
87
88 if (strstr($templateInfo['name'], '_Form') || !is_null($reportClass)) {
89 $instanceInfo = array();
0b25329b 90 CRM_Report_BAO_ReportInstance::retrieve(array('id' => $instanceId), $instanceInfo);
6a488035
TO
91
92 if (!empty($instanceInfo['title'])) {
93 CRM_Utils_System::setTitle($instanceInfo['title']);
94 $this->assign('reportTitle', $instanceInfo['title']);
95 }
96 else {
97 CRM_Utils_System::setTitle($templateInfo['label']);
98 $this->assign('reportTitle', $templateInfo['label']);
99 }
100
101 $wrapper = new CRM_Utils_Wrapper();
102 return $wrapper->run($templateInfo['name'], NULL, NULL);
103 }
104
105 CRM_Core_Session::setStatus(ts('Could not find template for the instance.'), ts('Template Not Found'), 'error');
106 }
107 return CRM_Utils_System::redirect($reportUrl);
108 }
109}