3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.6 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
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. |
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. |
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 +--------------------------------------------------------------------+
31 * @copyright CiviCRM LLC (c) 2004-2014
37 * Page for invoking report instances
39 class CRM_Report_Page_InstanceList
extends CRM_Core_Page
{
41 static $_links = NULL;
43 static $_exceptions = array('logging/contact/detail');
46 * Name of component if report list is filtered
50 protected $_compName = NULL;
53 * ID of component if report list is filtered
57 protected $_compID = NULL;
60 * ID of grouping if report list is filtered
64 protected $_grouping = NULL;
67 * ID of parent report template if list is filtered by template
71 protected $_ovID = NULL;
75 * Title of parent report template if list is filtered by template
79 protected $_title = NULL;
82 * Retrieves report instances, optionally filtered by parent report template ($ovID)
83 * or by component ($compID)
87 public function &info() {
91 $report .= " AND v.id = {$this->ovID} ";
95 if ($this->compID
== 99) {
96 $report .= " AND v.component_id IS NULL ";
97 $this->_compName
= 'Contact';
100 $report .= " AND v.component_id = {$this->compID} ";
101 $cmpName = CRM_Core_DAO
::getFieldValue('CRM_Core_DAO_Component', $this->compID
,
104 $this->_compName
= substr($cmpName, 4);
105 if ($this->_compName
== 'Contribute') {
106 $this->_compName
= 'Contribution';
110 elseif ($this->grouping
) {
111 $report .= " AND v.grouping = '{$this->grouping}' ";
115 SELECT inst.id, inst.title, inst.report_id, inst.description, v.label, v.grouping,
117 WHEN comp.name IS NOT NULL THEN SUBSTRING(comp.name, 5)
118 WHEN v.grouping IS NOT NULL THEN v.grouping
121 FROM civicrm_option_group g
122 LEFT JOIN civicrm_option_value v
123 ON v.option_group_id = g.id AND
124 g.name = 'report_template'
125 LEFT JOIN civicrm_report_instance inst
126 ON v.value = inst.report_id
127 LEFT JOIN civicrm_component comp
128 ON v.component_id = comp.id
130 WHERE v.is_active = 1 {$report}
131 AND inst.domain_id = %1
134 $dao = CRM_Core_DAO
::executeQuery($sql, array(
135 1 => array(CRM_Core_Config
::domainID(), 'Integer'),
138 $config = CRM_Core_Config
::singleton();
140 $url = 'civicrm/report/instance';
141 while ($dao->fetch()) {
142 if (in_array($dao->report_id
, self
::$_exceptions)) {
146 $enabled = in_array("Civi{$dao->compName}", $config->enableComponents
);
147 if ($dao->compName
== 'Contact' ||
$dao->compName
== $dao->grouping
) {
150 //filter report listings by permissions
151 if (!($enabled && CRM_Report_Utils_Report
::isInstancePermissioned($dao->id
))) {
154 //filter report listing by group/role
155 if (!($enabled && CRM_Report_Utils_Report
::isInstanceGroupRoleAllowed($dao->id
))) {
159 if (trim($dao->title
)) {
161 $this->title
= ts("Report(s) created from the template: %1", array(1 => $dao->label
));
163 $rows[$dao->compName
][$dao->id
]['title'] = $dao->title
;
164 $rows[$dao->compName
][$dao->id
]['label'] = $dao->label
;
165 $rows[$dao->compName
][$dao->id
]['description'] = $dao->description
;
166 $rows[$dao->compName
][$dao->id
]['url'] = CRM_Utils_System
::url("{$url}/{$dao->id}", "reset=1");
167 if (CRM_Core_Permission
::check('administer Reports')) {
168 $rows[$dao->compName
][$dao->id
]['deleteUrl'] = CRM_Utils_System
::url("{$url}/{$dao->id}", 'action=delete&reset=1');
176 * Run this page (figure out the action needed and perform it).
180 public function run() {
181 //Filters by source report template or by component
182 $this->ovID
= CRM_Utils_Request
::retrieve('ovid', 'Positive', $this);
183 $this->compID
= CRM_Utils_Request
::retrieve('compid', 'Positive', $this);
184 $this->grouping
= CRM_Utils_Request
::retrieve('grp', 'String', $this);
186 $rows = $this->info();
188 $this->assign('list', $rows);
189 if ($this->ovID
OR $this->compID
) {
190 // link to view all reports
191 $reportUrl = CRM_Utils_System
::url('civicrm/report/list', "reset=1");
192 $this->assign('reportUrl', $reportUrl);
194 $this->assign('title', $this->title
);
197 CRM_Utils_System
::setTitle(ts('%1 Reports', array(1 => $this->_compName
)));
200 // assign link to template list for users with appropriate permissions
201 if (CRM_Core_Permission
::check('administer Reports')) {
203 $newButton = ts('New %1 Report', array(1 => $this->_compName
));
204 $templateUrl = CRM_Utils_System
::url('civicrm/report/template/list', "reset=1&compid={$this->compID}");
207 $newButton = ts('New Report');
208 $templateUrl = CRM_Utils_System
::url('civicrm/report/template/list', "reset=1");
210 $this->assign('newButton', $newButton);
211 $this->assign('templateUrl', $templateUrl);
212 $this->assign('compName', $this->_compName
);
214 return parent
::run();