4 +--------------------------------------------------------------------+
5 | CiviCRM version 4.4 |
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 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';
102 $report .= " AND v.component_id = {$this->compID} ";
103 $cmpName = CRM_Core_DAO
::getFieldValue('CRM_Core_DAO_Component', $this->compID
,
106 $this->_compName
= substr($cmpName, 4);
107 if ($this->_compName
== 'Contribute') {
108 $this->_compName
= 'Contribution';
112 elseif ($this->grouping
) {
113 $report .= " AND v.grouping = '{$this->grouping}' ";
117 SELECT inst.id, inst.title, inst.report_id, inst.description, v.label, v.grouping,
119 WHEN comp.name IS NOT NULL THEN SUBSTRING(comp.name, 5)
120 WHEN v.grouping IS NOT NULL THEN v.grouping
123 FROM civicrm_option_group g
124 LEFT JOIN civicrm_option_value v
125 ON v.option_group_id = g.id AND
126 g.name = 'report_template'
127 LEFT JOIN civicrm_report_instance inst
128 ON v.value = inst.report_id
129 LEFT JOIN civicrm_component comp
130 ON v.component_id = comp.id
132 WHERE v.is_active = 1 {$report}
133 AND inst.domain_id = %1
136 $dao = CRM_Core_DAO
::executeQuery($sql, array(
137 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');
180 * run this page (figure out the action needed and perform it).
185 //Filters by source report template or by component
186 $this->ovID
= CRM_Utils_Request
::retrieve('ovid', 'Positive', $this);
187 $this->compID
= CRM_Utils_Request
::retrieve('compid', 'Positive', $this);
188 $this->grouping
= CRM_Utils_Request
::retrieve('grp', 'String', $this);
190 $rows = $this->info();
192 $this->assign('list', $rows);
193 if ($this->ovID
OR $this->compID
) {
194 // link to view all reports
195 $reportUrl = CRM_Utils_System
::url('civicrm/report/list', "reset=1");
196 $this->assign('reportUrl', $reportUrl);
198 $this->assign('title', $this->title
);
200 CRM_Utils_System
::setTitle(ts('%1 Reports', array(1 => $this->_compName
)));
203 // assign link to template list for users with appropriate permissions
204 if (CRM_Core_Permission
::check('administer Reports')) {
206 $newButton = ts('New %1 Report', array(1 => $this->_compName
));
207 $templateUrl = CRM_Utils_System
::url('civicrm/report/template/list', "reset=1&compid={$this->compID}");
209 $newButton = ts('New Report');
210 $templateUrl = CRM_Utils_System
::url('civicrm/report/template/list', "reset=1");
212 $this->assign('newButton', $newButton);
213 $this->assign('templateUrl', $templateUrl);
214 $this->assign('compName', $this->_compName
);
216 return parent
::run();