Commit 5e4ff972 authored by metzlerd's avatar metzlerd
Browse files

Basic working copy with list of reports, but no categories.

parent 0890a55d
......@@ -16,31 +16,33 @@ class FrxReport {
public $access;
public function __construct($xhtml, $data=array()) {
$this->teng = new FrxSyntaxEngine(FRX_TOKEN_EXP, '{}', $this);
if (!is_object($xhtml)) {
$this->rpt_xml = new SimpleXMLElement($xhtml);
}
else {
$this->rpt_xml = $xhtml;
}
$this->cur_data = $data;
// Load header data
$rpt_xml = $this->rpt_xml;
if ($rpt_xml->head) {
$this->title = (string)$rpt_xml->head->title;
foreach ($rpt_xml->head->children('urn:FrxReports') as $name => $node) {
switch ($name) {
case 'fields':
$this->fields = $node;
break;
case 'category':
$this->categories[] = (string)$node;
break;
case 'access':
$this->access[] = (string)$node;
break;
$this->teng = new FrxSyntaxEngine(FRX_TOKEN_EXP, '{}', $this);
if ($xhtml) {
if (!is_object($xhtml)) {
$this->rpt_xml = new SimpleXMLElement($xhtml);
}
else {
$this->rpt_xml = $xhtml;
}
$this->cur_data = $data;
// Load header data
$rpt_xml = $this->rpt_xml;
if ($rpt_xml->head) {
$this->title = (string)$rpt_xml->head->title;
foreach ($rpt_xml->head->children('urn:FrxReports') as $name => $node) {
switch ($name) {
case 'fields':
$this->fields = $node;
break;
case 'category':
$this->categories[] = (string)$node;
break;
case 'access':
$this->access[] = (string)$node;
break;
}
}
}
}
......@@ -73,7 +75,7 @@ class FrxReport {
* Walks the nodes renering the report.
*/
public function render_section(SimpleXMLElement $node) {
$cur_data = $this->cur_data;
$elements = count($node->xpath('*'));
$frx = $node->attributes('urn:FrxReports');
// Test to see if we have any nodes that are contains data url
......@@ -97,7 +99,7 @@ class FrxReport {
if ($nodes) foreach ($nodes as $x) {
$this->cur_data = $x;
$o .= $this->teng->replace('<'. $tag . $attr_text .'>', $this->cur_data);
$o .= $this->teng->replace('<'. $tag . $attr_text .'>', $cur_data);
foreach ($node->children() as $child) {
$o .= $this->render_section($child);
}
......@@ -121,6 +123,7 @@ class FrxReport {
$text = $node->asXML();
$o .= $this->teng->replace($text, $this->cur_data);
}
$this->cur_data = $cur_data;
return $o;
}
......@@ -186,4 +189,18 @@ class FrxReport {
}
return $value;
}
/**
* Return the xml data for the report.
*
* @return unknown
*/
public function asXML() {
if ($this->rpt_xml) {
return $this->rpt_xml->asXML();
}
else {
return '';
}
}
}
\ No newline at end of file
......@@ -11,22 +11,85 @@ require_once('forena.common.inc');
* @param string $name File name to save report to
* @param unknown_type $data
*/
function forena_save_report($name, $data) {
function forena_save_report($data, $report, $save_file = FALSE) {
static $save_count=0;
$report_path = forena_report_path();
//@TODO: Clean up filename to make sure
$filepath = $report_path .'/'. $name .'frx';
if (is_object($data)) {
$data = $data->asXML();
$name = $data['name'];
$filepath = $report_path .'/'. $data['name'] .'.frx';
$data['enabled'] = $data['enabled'] ? 1 : 0;
// If we need to save this to the file system
if ($save_file) {
// Serialize the report for saving
if (is_object($data)) {
$data = $data->asXML();
}
try {
file_put_contents($filepath, $data);
} catch (Exception $e) {
fornea_error('Error Saving Report', $e->getMessage());
}
}
try {
file_put_contents($filepath, $data);
} catch (Exception $e) {
fornea_error('Error Saving Report', $e->getMessage());
// Save to the Database
if (file_exists($filepath)) {
$result = db_query("SELECT report_name FROM {forena_reports} WHERE report_name='%s'", $name);
if ($rpt = db_fetch_object($result)) {
db_query("UPDATE {forena_reports} SET title='%s' WHERE report_name='%s'", array($data['title'], $name));
}
else {
db_query("INSERT INTO {forena_reports} (report_name,title) VALUES ('%s','%s')", array($name, $data['title']));
}
$save_count++;
}
return $save_count;
}
/**
* Syncronize the data
*
*/
function forena_db_sync($subdir='') {
static $prefix = '';
if (!$subdir) {
$prefix = '';
}
$path = forena_report_path() .'/'. $subdir;
$d = dir($path);
if ($d) while (false !== ($rpt_file = $d->read())) {
$src_file = $d->path .'/'. $rpt_file;
$dest_file = $path .'/'. $rpt_file;
if (is_file($src_file)) {
list($report_name, $ext) = explode('.', $rpt_file, 2);
if ($ext == 'frx') {
$report_name = trim($prefix .'/'. $report_name, '/');
$r_xml = file_get_contents($src_file);
// Load the report
$r = new FrxReport($r_xml);
$data['title'] = $r->title;
$data['name'] = $report_name;
$save_count = forena_save_report($data, $r_xml);
}
}
elseif (is_dir($src_file)) {
if (substr($rpt_file, 0, 1)!='.') {
$save_prefix = $prefix;
$prefix .= trim('/'. $rpt_file, '/');
forena_db_sync($prefix);
$prefix = $save_prefix;
}
}
}
if ($d) $d->close();
return $save_count;
}
/**
* Forena admin settings form
*
......@@ -84,11 +147,11 @@ function forena_settings_submit($form, &$form_state) {
mkdir($path);
} catch (Exception $e) {
forena_error('Unable to create report directory', $e->getMessage());
forena_error(t('Unable to create report directory'), $e->getMessage());
}
}
elseif ($path != $src_dir) {
if (file_exists($path) && $path != $src_dir) {
// Copy the reports from the
$d = dir($src_dir);
$dest_dir = $d->path;
......@@ -104,7 +167,9 @@ function forena_settings_submit($form, &$form_state) {
}
$d->close();
drupal_set_message($i .' delivered reports copied from '. $src_dir .' to '. $path);
drupal_set_message($i .' delivered reports copied from '. $src_dir .' to '. $path);
}
$save_count = forena_db_sync();
drupal_set_message('Imported '. $save_count .' forms into the database');
menu_cache_clear();
}
<?php
// $Id$
/**
* @file
* Installation api for module
*/
/**
* Implementation of hook_schema
*
* @return unknown
*/
function forena_schema() {
$schema['forena_reports'] = array(
'fields' => array(
'report_name' => array('type' => 'varchar', 'length' => 255, 'NOT NULL' => TRUE),
'title' => array('type' => 'varchar', 'length' => 63, 'NOT NULL' => TRUE),
'file_name' => array('type' => 'varchar', 'length' => 255, 'NOT NULL' => TRUE),
'category' => array('type' => 'varchar', 'length' => 255, 'NOT NULL' => FALSE),
'repository' => array('type' => 'varchar', 'length' => 255, 'NOT NULL' => FALSE),
'access' => array('type' => 'varchar', 'length' => 255, 'NOT NULL' => FALSE),
'hidden' => array('type' => 'int', 'NOT NULL' => FALSE, ),
),
'primary key' => array('report_name'),
'indexes' => array(
'category' => array('category'),
),
);
return $schema;
}
/**
* Basic install and uninstall
*
*/
function forena_install() {
drupal_install_schema('forena');
}
function forena_uninstall() {
drupal_uninstall_schema('forena');
}
\ No newline at end of file
......@@ -28,7 +28,7 @@ function forena_menu() {
$items[$path] = array(
'page callback' => 'forena_report',
'page arguments' => array(),
'title' => t('Forena Reports'),
'title' => t('Reports'),
'access arguments' => array('access content'),
'type' => MENU_NORMAL_ITEM,
);
......@@ -62,8 +62,17 @@ function forena_test() {
return $output;
}
function forena_report($report_name='') {
function forena_report() {
$arg_list = func_get_args();
require_once('forena.common.inc');
// Concat argument to function to get a path
$f_path = variable_get('forena_path', 'reports');
foreach ($arg_list as $arg) {
$report_name .= '/'. $arg;
}
$report_name = trim($report_name, '/');
$report_path = forena_report_path();
list($name, $format) = explode('.', $report_name, 2);
if ($name) {
......@@ -85,7 +94,12 @@ function forena_report($report_name='') {
}
else {
// @TODO: List reports
$output = 'Need to specify a report name';
$result = db_query('SELECT * FROM {forena_reports} ORDER BY title asc');
$output .= '<ul>';
while ($row = db_fetch_object($result)) {
$output .= '<li>'. l($row->title, variable_get('forena_path', 'reports') .'/'. $row->report_name) .'</li>';
}
$output .= '</ul>';
}
return $output;
}
......@@ -110,9 +124,9 @@ function forena_render_report($report, $format='', $data='') {
*
*/
function forena_forena_plugins() {
$plugins[] = array('file' => 'plugins/FrxDBEngine.inc',
$plugins[] = array('file' => 'plugins/FrxPDO.inc',
'type' => 'data',
'class' => 'FrxDbEngine',
'class' => 'FrxPDO',
);
$plugins[] = array('file' => 'plugins/FrxOracle.inc',
'type' => 'data',
......@@ -122,9 +136,9 @@ function forena_forena_plugins() {
'type' => 'data',
'class' => 'FrxDrupal',
);
$plugins[] = array('file' => 'plugins/FrxFileEngine.inc',
$plugins[] = array('file' => 'plugins/FrxFiles.inc',
'type' => 'data',
'class' => 'FrxFileEngine',
'class' => 'FrxFiles',
);
return $plugins;
}
......
......@@ -50,7 +50,8 @@ class frxDrupal extends FrxDataEngine {
$row_node = $xml->addChild('row');
foreach ($data as $key => $value) {
$row_node->addChild($key, $value);
$row_node->addChild($key, htmlspecialchars($value));
//$row_node->$key = $value;
}
}
......
......@@ -65,7 +65,7 @@ class FrxOracle extends FrxDataEngine {
while ($row = oci_fetch_array($stmt, OCI_ASSOC+OCI_RETURN_NULLS)) {
$row_node = $xml->addChild('row');
foreach ($row as $key => $value) {
$row_node->addChild(strtolower($key), $value);
$row_node->addChild(strtolower($key), htmlspecialchars($value));
}
}
oci_free_statement($stmt);
......
......@@ -6,7 +6,7 @@
*
*/
class FrxDBEngine extends FrxDataEngine {
class FrxPDO extends FrxDataEngine {
private $te;
private $db;
......@@ -69,7 +69,7 @@ class FrxDBEngine extends FrxDataEngine {
foreach ($data as $row) {
$row_node = $xml->addChild('row');
foreach ($row as $key => $value) {
$row_node->addChild($key, $value);
$row_node->addChild($key, htmlspecialchars($value));
}
}
......
......@@ -15,7 +15,7 @@ $conf['access callback'] = 'user_access';
*
*/
$conf['data_engine'] = 'FrxDrupal';
$conf['data_engine'] = 'FrxDrupal';
/*
* URI:
......
--ACCESS=access content
SELECT u.uid, u.name, timestamp, type, severity, wid from watchdog w JOIN users u on u.uid=w.uid
WHERE u.name=:name
\ No newline at end of file
--ACCESS=access administration pages
SELECT u.uid, u.name, timestamp, location, type, severity, wid from watchdog w JOIN users u on u.uid=w.uid
WHERE u.name=:name ORDER BY timestamp desc
\ No newline at end of file
--ACCESS=access content
SELECT u.uid, u.name, timestamp, type, severity, wid from watchdog w JOIN users u on u.uid=w.uid
WHERE u.name=:name
\ No newline at end of file
--ACCESS=access administration pages
SELECT u.name, count(1) as total from watchdog w JOIN users u on u.uid=w.uid
GROUP BY u.name ORDER BY name asc
\ No newline at end of file
......@@ -27,11 +27,12 @@
<h4>Log Entries for {name}</h4>
<table frx:block="drupal/user_logs">
<thead>
<tr><th width="200px">Type</th><th>Timestamp</th></tr>
<tr><th width="200px">Type</th><th width="200">Location</th><th>Timestamp</th></tr>
</thead>
<tbody>
<tr frx:foreach="*">
<td>{type}</td>
<td>{location}</td>
<td>{timestamp}</td>
<td>{details}</td>
<td></td>
......
......@@ -15,7 +15,7 @@ $conf['access callback'] = 'user_access';
*
*/
$conf['data_engine'] = 'FrxFileEngine';
$conf['data_engine'] = 'FrxFiles';
/*
* URI:
......
<?xml version="1.0" encoding="UTF-8"?>
<root>
<row>
<last_name>Metzler</last_name>
<first_name>Dave</first_name>
</row>
<row>
<last_name>Bailey</last_name>
<first_name>Scott</first_name>
</row>
</root>
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