4 +--------------------------------------------------------------------+
5 | CiviCRM version 4.3 |
6 +--------------------------------------------------------------------+
7 | Copyright CiviCRM LLC (c) 2004-2013 |
8 +--------------------------------------------------------------------+
9 | This file is a part of CiviCRM. |
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. |
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. |
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 +--------------------------------------------------------------------+
32 * @copyright CiviCRM LLC (c) 2004-2013
38 * Page for invoking report instances
40 class CRM_Report_Page_InstanceList
extends CRM_Core_Page
{
42 static $_links = NULL;
44 static $_exceptions = array( 'logging/contact/detail' );
47 * Name of component if report list is filtered
51 protected $_compName = NULL;
54 * ID of component if report list is filtered
58 protected $_compID = NULL;
61 * ID of parent report template if list is filtered by template
65 protected $_ovID = NULL;
69 * Title of parent report template if list is filtered by template
73 protected $_title = NULL;
76 * Retrieves report instances, optionally filtered by parent report template ($ovID)
77 * or by component ($compID)
83 public function &info() {
87 $report .= " AND v.id = {$this->ovID} ";
91 if ($this->compID
== 99) {
92 $report .= " AND v.component_id IS NULL ";
93 $this->_compName
= 'Contact';
95 $report .= " AND v.component_id = {$this->compID} ";
96 $cmpName = CRM_Core_DAO
::getFieldValue('CRM_Core_DAO_Component', $this->compID
,
99 $this->_compName
= substr($cmpName, 4);
100 if ($this->_compName
== 'Contribute') {
101 $this->_compName
= 'Contribution';
107 SELECT inst.id, inst.title, inst.report_id, inst.description, v.label,
108 ifnull( SUBSTRING(comp.name, 5), 'Contact' ) as compName
109 FROM civicrm_option_group g
110 LEFT JOIN civicrm_option_value v
111 ON v.option_group_id = g.id AND
112 g.name = 'report_template'
113 LEFT JOIN civicrm_report_instance inst
114 ON v.value = inst.report_id
115 LEFT JOIN civicrm_component comp
116 ON v.component_id = comp.id
118 WHERE v.is_active = 1 {$report}
119 AND inst.domain_id = %1
122 $dao = CRM_Core_DAO
::executeQuery($sql, array(
123 1 => array(CRM_Core_Config
::domainID(), 'Integer'),
127 $config = CRM_Core_Config
::singleton();
129 $url = 'civicrm/report/instance';
130 while ($dao->fetch()) {
131 if (in_array($dao->report_id
, self
::$_exceptions)) {
135 $enabled = in_array("Civi{$dao->compName}", $config->enableComponents
);
136 if ($dao->compName
== 'Contact') {
139 //filter report listings by permissions
140 if (!($enabled && CRM_Report_Utils_Report
::isInstancePermissioned($dao->id
))) {
143 //filter report listing by group/role
144 if (!($enabled && CRM_Report_Utils_Report
::isInstanceGroupRoleAllowed($dao->id
))) {
148 if (trim($dao->title
)) {
150 $this->title
= ts("Report(s) created from the template: %1", array(1 => $dao->label
));
152 $rows[$dao->compName
][$dao->id
]['title'] = $dao->title
;
153 $rows[$dao->compName
][$dao->id
]['label'] = $dao->label
;
154 $rows[$dao->compName
][$dao->id
]['description'] = $dao->description
;
155 $rows[$dao->compName
][$dao->id
]['url'] = CRM_Utils_System
::url("{$url}/{$dao->id}", "reset=1");
156 if (CRM_Core_Permission
::check('administer Reports')) {
157 $rows[$dao->compName
][$dao->id
]['deleteUrl'] = CRM_Utils_System
::url("{$url}/{$dao->id}", 'action=delete&reset=1');
166 * run this page (figure out the action needed and perform it).
171 //Filters by source report template or by component
172 $this->ovID
= CRM_Utils_Request
::retrieve('ovid', 'Positive', $this);
173 $this->compID
= CRM_Utils_Request
::retrieve('compid', 'Positive', $this);
174 $rows = $this->info();
176 $this->assign('list', $rows);
177 if ($this->ovID
OR $this->compID
) {
178 // link to view all reports
179 $reportUrl = CRM_Utils_System
::url('civicrm/report/list', "reset=1");
180 $this->assign('reportUrl', $reportUrl);
182 $this->assign('title', $this->title
);
185 // assign link to template list for users with appropriate permissions
186 if (CRM_Core_Permission
::check('administer Reports')) {
188 $newButton = ts('New %1 Report', array(1 => $this->_compName
));
189 $templateUrl = CRM_Utils_System
::url('civicrm/report/template/list', "reset=1&compid={$this->compID}");
191 $newButton = ts('New Report');
192 $templateUrl = CRM_Utils_System
::url('civicrm/report/template/list', "reset=1");
194 $this->assign('newButton', $newButton);
195 $this->assign('templateUrl', $templateUrl);
196 $this->assign('compName', $this->_compName
);
198 return parent
::run();