Xataface HTML Reports Module 0.2
HTML Reports Module for Xataface
actions/htmlreports_view_report.php
Go to the documentation of this file.
00001 <?php
00002 /*
00003  * Xataface HTML Reports Module
00004  * Copyright (C) 2011  Steve Hannah <steve@weblite.ca>
00005  * 
00006  * This library is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU Library General Public
00008  * License as published by the Free Software Foundation; either
00009  * version 2 of the License, or (at your option) any later version.
00010  * 
00011  * This library is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014  * Library General Public License for more details.
00015  * 
00016  * You should have received a copy of the GNU Library General Public
00017  * License along with this library; if not, write to the
00018  * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
00019  * Boston, MA  02110-1301, USA.
00020  *
00021  */
00076 class actions_htmlreports_view_report {
00077 
00078         function handle($params){
00079                 try {
00080                         $app = Dataface_Application::getInstance();
00081                         $query = $app->getQuery();
00082                         $mod = Dataface_ModuleTool::getInstance()->loadModule('modules_htmlreports');
00083                         
00084                         $reportid = @$query['--report-id'];
00085                         if ( !$reportid ){
00086                                 throw new Exception("No report id specified");
00087                         }
00088                         
00089                         $report = $mod->getReportById($reportid);
00090                         if ( !$report ){
00091                                 throw new Exception("No report found with that id");
00092                         }
00093                         
00094                         if ( $query['-table'] != $report->val('tablename') ){
00095                                 throw new Exception("The specified report is not designed to work on this table.");
00096                         }
00097                         
00098                         $table = Dataface_Table::loadTable($query['-table']);
00099                         $perms = $table->getPermissions();
00100                         
00101                         
00102                         if ( $report->val('actiontool_permission') and !@$perms[$report->val('actiontool_permission')] ){
00103                                 throw new Exception(sprintf(
00104                                         "You don't have permission to view this report.  '%s' is required.",
00105                                         $report->val('actiontool_permission')
00106                                 ));
00107                                 
00108                         }
00109                         
00110                         
00111                         
00112                         
00113                         if ( !@$query['--view'] and $report->val('default_view') ){
00114                                 $query['--view'] = $report->val('default_view');
00115                         }
00116                         
00117                         require_once(dirname(__FILE__).DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'classes'.DIRECTORY_SEPARATOR.'XfHtmlReportBuilder.class.php');
00118                         if ( @$query['--view'] == 'table' ){
00119                                 $records = df_get_selected_records($query);
00120                                 if ( !$records ){
00121                                         $records = df_get_records_array($query['-table'], $query, 0, 999, false);
00122                                 }
00123                                 $results = XfHtmlReportBuilder::fillReportTable($records, $report->val('template_html'));
00124                         } else if ( @$query['--view'] == 'details' ){
00125                                 
00126                                 $results = XfHtmlReportBuilder::fillReportSingle($app->getRecord(), $report->val('template_html'));
00127                         } else {
00128                                 $records = df_get_selected_records($query);
00129                                 if ( !$records ){
00130                                         $records = df_get_records_array($query['-table'], $query, 0, 999, false);
00131                                 }
00132                                 $results = XfHtmlReportBuilder::fillReportMultiple($records, $report->val('template_html'));
00133                         }
00134                         header('Content-type: text/html; charset="'.$app->_conf['oe'].'"');
00135                         df_register_skin('htmlreports', dirname(__FILE__).DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'templates');
00136                         
00137                         $context = array(
00138                                 'html'=>$results,
00139                                 'report'=>$report
00140                         );
00141                         
00142                         df_display($context, 'xataface/modules/htmlreports/view_report.html');
00143                         //echo $results;
00144                 } catch (Exception $ex){
00145                         if ( $ex->getCode() == 2000 ){
00146                                 print($ex->getTraceAsString());
00147                                 exit;
00148                         }
00149                         return Dataface_Error::permissionDenied($ex->getMessage());
00150                 }
00151         }
00152 }
 All Data Structures Files Functions Variables Enumerations