Commit 19711143 authored by metzlerd's avatar metzlerd
Browse files

Somewhat working refactored include logic. Will continue to flesh

this out. 
parent 943b7b4f
......@@ -6,6 +6,7 @@
*/
class FrxDocument {
public $format;
public $content_type='';
public function loadCSSFIles($format) {
......@@ -58,4 +59,19 @@ class FrxDocument {
}
}
public function output($output) {
if ($this->content_type) {
header('Content-Type: '. $this->content_type);
header('Cache-Control:');
header('Pragma:');
header('Cache-Control: must-revalidate');
print $output;
return TRUE;
}
else {
return FALSE;
}
}
}
\ No newline at end of file
......@@ -17,6 +17,12 @@ class FrxReportGenerator {
public $title;
public $content;
/**
* Factory
*
* @return FrxReportGenerator
*
**/
static public function instance() {
global $forena_application_class;
if (!self::$instance) {
......@@ -84,7 +90,7 @@ class FrxReportGenerator {
/**
* Accepts the name of a file
*
* Returns a xml object of the file.
* @return FrxReport
*
*/
function get_report($report_name, $data=array()) {
......@@ -258,11 +264,13 @@ function report($name_in, $parms = array(), $print=TRUE) {
Frx::Skin()->loadSkinFiles($name);
$r->render($format);
$o = Frx::Document($format);
if ($o) $output .= $o->render($r, $format, array());
return $output;
}
else {
$this->app->not_found();
if ($o) {
$output .= $o->render($r, $format, array());
$printed = $o->output($output);
if (!$printed) {
return $output;
}
}
}
}
......
<?php
class FrxCSVDoc extends FrxDocument {
public function __construct() {
$this->content_type = 'application/csv';
}
/**
* Fill columns with rowspan tags.
* @param unknown_type $colspan
......@@ -55,13 +59,6 @@ class FrxCSVDoc extends FrxDocument {
}
$output .= "\n";
}
if ($output) {
header('Content-Type: application/csv');
header('Cache-Control:');
header('Pragma:');
header("Cache-Control: must-revalidate");
header("Content-Disposition: attachment; filename=report.csv");
print $output;
}
return $output;
}
}
\ No newline at end of file
<?php
class FrxHtmlDoc extends FrxDocument {
public function render($r, $format, $options = array()) {
$css = $this->loadCSSFiles($format);
$output = '<html><head>';
......@@ -13,6 +11,10 @@ class FrxHtmlDoc extends FrxDocument {
$output .= '</style>';
}
$output .= '<title>' . $r->title . '</title></head><body class="forena-report"><h1>' . $r->title . '</h1>' . $r->html . '</body></html>';
print $output;
return $output;
}
public function output($output) {
print $output;
}
}
\ No newline at end of file
<?php
class FrxPrincePDF extends FrxDocument {
public function render($r, $format, $options = array()) {
private $p;
public function __construct() {
include_once('sites/all/libraries/prince.php');
$prince_path = variable_get('forena_pdf_prince_path', '/usr/local/bin/prince');
$this->content_type='application/pdf';
$prince_path = variable_get('forena_pdf_prince_path', '/usr/local/bin/prince');
if (class_exists('Prince') && file_exists($prince_path)) {
$this->p = new Prince($prince_path);
}
}
public function render($r, $format, $options = array()) {
$disable_links = variable_get('forena_pdf_disable_links', TRUE);
$link_class = $disable_links ? 'prince-disable-links': '';
$output = '<html><head>';
......@@ -16,8 +28,8 @@ class FrxPrincePDF extends FrxDocument {
$output .= '<title>' . $r->title . "</title></head><body class='forena-report $link_class'><h1>" . $r->title . '</h1>' . $r->html . '</body></html>';
$prince_css = drupal_get_path('module', 'forena_pdf') . '/forena_pdf_prince.css';
// Generate the document
if (class_exists('Prince') && file_exists($prince_path)) {
$p = new Prince($prince_path);
if ($this->p) {
$p = $this->p;
$p->addStyleSheet($prince_css);
foreach (Frx::Skin()->stylesheets as $type=>$sheets) {
foreach ($sheets as $sheet) {
......@@ -31,15 +43,19 @@ class FrxPrincePDF extends FrxDocument {
}
}
}
header('Content-Type: application/pdf');
header('Cache-Control:');
header('Pragma:');
header("Cache-Control: must-revalidate");
$p->convert_string_to_passthru($output);
return $output;
} else {
drupal_set_message(t('Prince XML Not Properly Installed'), 'error');
return ('');
}
}
}
\ No newline at end of file
public function output($output) {
header('Content-Type: '. $this->content_type);
header('Cache-Control:');
header('Pragma:');
header('Cache-Control: must-revalidate');
$this->p->convert_string_to_passthru($output);
return TRUE;
}
}
<?php
class FrxSVGDoc extends FrxDocument {
public function __construct() {
$this->content_type = 'image/svg+xml';
}
public function render($r, $format, $options = array()) {
$output = '';
$doc = new DomDocument();
......@@ -12,15 +17,11 @@ class FrxSVGDoc extends FrxDocument {
$xml->registerXPathNamespace('__empty_ns', 'http://www.w3.org/2000/svg');
if ($xml) $svg = $xml->xpath('//__empty_ns:svg');
if ($svg) {
$output = '<?xml version="1.0" encoding="UTF-8" standalone="no" ?>';
$output .= $svg[0]->asXML();
} else {
$output = '<svg/>';
}
header('Content-Type: image/svg+xml');
header('Cache-Control:');
header('Pragma:');
header('Cache-Control: must-revalidate');
print $output;
return $output;
}
}
\ No newline at end of file
<?php
class FrxWordDoc extends FrxDocument {
public function __construct() {
$this->content_type = 'application/msword';
}
public function render($r, $format, $options = array()) {
$css = $this->loadCSSFiles($format);
$output = '<html><head>';
......@@ -10,10 +14,6 @@ class FrxWordDoc extends FrxDocument {
$output .= '</style>';
}
$output .= '<title>' . $r->title . '</title></head><body class="forena-report">' . $r->html . '</body></html>';
header('Content-Type: application/msword');
header('Cache-Control:');
header('Pragma:');
header("Cache-Control: must-revalidate");
print $output;
return $output;
}
}
\ No newline at end of file
<?php
class FrxXLSDoc extends FrxDocument {
public function __construct() {
$this->content_type = 'application/msexcel';
}
public function render($r, $format, $options = array()) {
......@@ -66,11 +69,6 @@ class FrxXLSDoc extends FrxDocument {
$output .= '</Worksheet>' . "\n";
}
$output .= '</Workbook>';
header('Content-Type: application/msexcel');
header('Cache-Control:');
header('Pragma:');
header("Cache-Control: must-revalidate");
header("Content-Disposition: attachment; filename=report.xls");
print $output;
return $output;
}
}
\ No newline at end of file
......@@ -32,30 +32,21 @@ class FrxDrupal extends FrxDataSource {
* @param Array $parm_data
* @param Query $subQuery
*/
public function sqlData($block_name) {
public function sqlData($sql) {
// Load the block from the file
$block = $this->loadBlock($block_name);
$xml ='';
if (trim($block['source']) && $this->access($block['access'])) {
$sql = $block['source'];
if ($clause) {
$sql = 'SELECT * FROM (' . trim($sql, ' ;') . ') forena_table ' . $clause;
}
$sql = $this->te->replace($sql);
$rs = db_query($sql);
$xml = new SimpleXMLElement('<table/>');
foreach ($rs as $data) {
$row_node = $xml->addChild('row');
foreach ($data as $key => $value) {
$row_node->addChild($key, htmlspecialchars($value));
//$row_node->$key = $value;
}
}
$sql = $this->te->replace($sql);
$rs = db_query($sql);
}
$xml = new SimpleXMLElement('<table/>');
foreach ($rs as $data) {
$row_node = $xml->addChild('row');
foreach ($data as $key => $value) {
$row_node->addChild($key, htmlspecialchars($value));
//$row_node->$key = $value;
}
}
return $xml;
}
......
......@@ -9,6 +9,7 @@ class FrxInclude extends FrxRenderer {
$include = @$attributes['src'];
$include = $this->teng->replace($include);
@list($url, $query_str)=@explode('?', $include);
$report_url = $url;
$parts = @explode('/', $url);
$file = @$parts[count($parts) - 1];
$parts = explode('.', $file);
......@@ -18,15 +19,33 @@ class FrxInclude extends FrxRenderer {
parse_str($query_str, $query );
$options = array('query' => $query);
$url = FrxReportGenerator::instance()->url($url, $options);
$doc_types = FrxReportGenerator::instance()->configuration('doc_formats');
if (@$doc_types[$ext]) {
if ($this->format=='web') {
$output = $this->render_reference($url, $ext, $attributes);
}
else {
$output = $this->teng->replace($this->reportDocNode->asXML());
$output = $this->renderInclude(str_replace('reports/','',$report_url), $query);
}
return $output;
}
public function renderInclude($name, $parms) {
$desc= Frx::Menu()->parseURL($name);
$name = $desc['name'];
Frx::Data()->push($parms, 'parms');
print_r($parms);
$r = @FrxReportGenerator::instance()->get_report($name, $parms);
if (!$r || !$r->rpt_xml) {
return '';
}
Frx::Data()->pop();
//check for default parameters
//$r->processParameters();
$output = $r->render($desc['format']);
return $output;
}
function render_reference($url, $ext, $attributes) {
$ext = strtolower($ext);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment