Xataface HTML Reports Module 0.2
HTML Reports Module for Xataface
|
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 */ 00022 00056 class actions_htmlreports_preview_report { 00057 00058 function handle($params){ 00059 try { 00060 $app = Dataface_Application::getInstance(); 00061 $query = $app->getQuery(); 00062 $mod = Dataface_ModuleTool::getInstance()->loadModule('modules_htmlreports'); 00063 00064 $templateContent = @$query['--template']; 00065 if ( !$templateContent ){ 00066 throw new Exception("No template provided"); 00067 } 00068 00069 $css = ''; 00070 if ( @$query['--css'] ){ 00071 $css = $query['--css']; 00072 } 00073 00074 00075 $table = Dataface_Table::loadTable($query['-table']); 00076 $perms =& $table->getPermissions(); 00077 if ( !@$perms['preview report'] ){ 00078 throw new Exception("You don't have permission to preview reports on this table. Previewing reports requires the 'preview report' permission."); 00079 00080 } 00081 00082 00083 $records = df_get_selected_records($query); 00084 if ( !$records ){ 00085 $records = df_get_records_array($query['-table'], $query, 0, 10, false); 00086 } 00087 00088 00089 00090 00091 require_once(dirname(__FILE__).DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'classes'.DIRECTORY_SEPARATOR.'XfHtmlReportBuilder.class.php'); 00092 if ( @$query['--view'] == 'table' ){ 00093 $results = XfHtmlReportBuilder::fillReportTable($records, $templateContent); 00094 } else { 00095 $results = XfHtmlReportBuilder::fillReportMultiple($records, $templateContent); 00096 } 00097 header('Content-type: text/html; charset="'.$app->_conf['oe'].'"'); 00098 df_register_skin('htmlreports', dirname(__FILE__).DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'templates'); 00099 00100 $context = array( 00101 'html'=>$results, 00102 'css' => $css 00103 ); 00104 00105 df_display($context, 'xataface/modules/htmlreports/preview_report.html'); 00106 } catch (Exception $ex){ 00107 //if ( $ex->getCode() == 2000 ){ 00108 // print($ex->getTraceAsString()); 00109 // exit; 00110 //} 00111 return Dataface_Error::permissionDenied($ex->getMessage()); 00112 } 00113 } 00114 }