4 +--------------------------------------------------------------------+
5 | CiviCRM version 4.5 |
6 +--------------------------------------------------------------------+
7 | Copyright CiviCRM LLC (c) 2004-2014 |
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-2014
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 grouping if report list is filtered
65 protected $_grouping = NULL;
68 * ID of parent report template if list is filtered by template
72 protected $_ovID = NULL;
76 * Title of parent report template if list is filtered by template
80 protected $_title = NULL;
83 * Retrieves report instances, optionally filtered by parent report template ($ovID)
84 * or by component ($compID)
90 public function &info() {
94 $report .= " AND v.id = {$this->ovID} ";
98 if ($this->compID
== 99) {
99 $report .= " AND v.component_id IS NULL ";
100 $this->_compName
= 'Contact';
103 $report .= " AND v.component_id = {$this->compID} ";
104 $cmpName = CRM_Core_DAO
::getFieldValue('CRM_Core_DAO_Component', $this->compID
,
107 $this->_compName
= substr($cmpName, 4);
108 if ($this->_compName
== 'Contribute') {
109 $this->_compName
= 'Contribution';
113 elseif ($this->grouping
) {
114 $report .= " AND v.grouping = '{$this->grouping}' ";
118 SELECT inst.id, inst.title, inst.report_id, inst.description, v.label, v.grouping,
120 WHEN comp.name IS NOT NULL THEN SUBSTRING(comp.name, 5)
121 WHEN v.grouping IS NOT NULL THEN v.grouping
124 FROM civicrm_option_group g
125 LEFT JOIN civicrm_option_value v
126 ON v.option_group_id = g.id AND
127 g.name = 'report_template'
128 LEFT JOIN civicrm_report_instance inst
129 ON v.value = inst.report_id
130 LEFT JOIN civicrm_component comp
131 ON v.component_id = comp.id
133 WHERE v.is_active = 1 {$report}
134 AND inst.domain_id = %1
137 $dao = CRM_Core_DAO
::executeQuery($sql, array(
138 1 => array(CRM_Core_Config
::domainID(), 'Integer'),
141 $config = CRM_Core_Config
::singleton();
143 $url = 'civicrm/report/instance';
144 while ($dao->fetch()) {
145 if (in_array($dao->report_id
, self
::$_exceptions)) {
149 $enabled = in_array("Civi{$dao->compName}", $config->enableComponents
);
150 if ($dao->compName
== 'Contact' ||
$dao->compName
== $dao->grouping
) {
153 //filter report listings by permissions
154 if (!($enabled && CRM_Report_Utils_Report
::isInstancePermissioned($dao->id
))) {
157 //filter report listing by group/role
158 if (!($enabled && CRM_Report_Utils_Report
::isInstanceGroupRoleAllowed($dao->id
))) {
162 if (trim($dao->title
)) {
164 $this->title
= ts("Report(s) created from the template: %1", array(1 => $dao->label
));
166 $rows[$dao->compName
][$dao->id
]['title'] = $dao->title
;
167 $rows[$dao->compName
][$dao->id
]['label'] = $dao->label
;
168 $rows[$dao->compName
][$dao->id
]['description'] = $dao->description
;
169 $rows[$dao->compName
][$dao->id
]['url'] = CRM_Utils_System
::url("{$url}/{$dao->id}", "reset=1");
170 if (CRM_Core_Permission
::check('administer Reports')) {
171 $rows[$dao->compName
][$dao->id
]['deleteUrl'] = CRM_Utils_System
::url("{$url}/{$dao->id}", 'action=delete&reset=1');
179 * Run this page (figure out the action needed and perform it).
184 //Filters by source report template or by component
185 $this->ovID
= CRM_Utils_Request
::retrieve('ovid', 'Positive', $this);
186 $this->compID
= CRM_Utils_Request
::retrieve('compid', 'Positive', $this);
187 $this->grouping
= CRM_Utils_Request
::retrieve('grp', 'String', $this);
189 $rows = $this->info();
191 $this->assign('list', $rows);
192 if ($this->ovID
OR $this->compID
) {
193 // link to view all reports
194 $reportUrl = CRM_Utils_System
::url('civicrm/report/list', "reset=1");
195 $this->assign('reportUrl', $reportUrl);
197 $this->assign('title', $this->title
);
199 CRM_Utils_System
::setTitle(ts('%1 Reports', array(1 => $this->_compName
)));
202 // assign link to template list for users with appropriate permissions
203 if (CRM_Core_Permission
::check('administer Reports')) {
205 $newButton = ts('New %1 Report', array(1 => $this->_compName
));
206 $templateUrl = CRM_Utils_System
::url('civicrm/report/template/list', "reset=1&compid={$this->compID}");
208 $newButton = ts('New Report');
209 $templateUrl = CRM_Utils_System
::url('civicrm/report/template/list', "reset=1");
211 $this->assign('newButton', $newButton);
212 $this->assign('templateUrl', $templateUrl);
213 $this->assign('compName', $this->_compName
);
215 return parent
::run();