Commit 325987e2 authored by metzlerd's avatar metzlerd
Browse files

Started refactor. Still needs to have report editing based on

attributes. 
parent 29ce9f5b
......@@ -316,9 +316,21 @@ class Frx {
}
}
}
return $ret_plugins;
}
static public function Editor($report_name = '') {
static $o='';
require_once('FrxEditor.inc');
if (!$o) {
$o = new FrxEditor($report_name);
}
else {
if ($report_name) $o->load($report_name) ;
}
return $o;
}
}
\ No newline at end of file
......@@ -12,6 +12,7 @@ class FrxEditor {
public $document_root;
public $simplexml;
public $title;
public $report_name;
public $doc_prefix = '<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE root [
<!ENTITY nbsp "&#160;">
......@@ -19,31 +20,23 @@ class FrxEditor {
public $xmlns = 'urn:FrxReports';
private $xpq;
/**
* Create initial FRX report
* Enter description here ...
* @param unknown_type $xml_string
*/
public function __construct($xml_string = '') {
public function __construct($report_name) {
$this->dom = new DOMDocument('1.0', 'UTF-8');
$dom = $this->dom;
// Load a new one or build the empty XML Document
if ($xml_string) {
// Eliminate the xml headers that don't have encoding info
$xml_string = str_ireplace('<?xml version="1.0"?>', '', $xml_string);
// If the <?xml code is missing assume UTF-8
if (strpos($xml_string, '<?xml')===FALSE) {
$xml_string = $this->doc_prefix . "\n" . $xml_string;
}
}
else {
$xml_string = $this->doc_prefix .
'<html xmlns:frx="urn:FrxReports"><head/><body/></html>';
}
$rpt_text = $this->load($report_name);
libxml_use_internal_errors();
try {
$dom->loadXML($xml_string);
$dom->loadXML($rpt_text);
}
catch (Exception $e) {
forena_error('Invalid or malformed report document', '<pre>' .
......@@ -70,6 +63,56 @@ class FrxEditor {
return $dom->saveXML();
}
/**
* Save data away in the session state.
*/
public function update() {
dpm($this->report_name,'update');
$_SESSION['forena_report_editor'][$this->report_name] = $this->asXML();
}
public function cancel() {
unset($_SESSION['forena_report_editor'][$this->report_name]);
drupal_get_messages('warning');
}
/**
* Load report from file system
* @param unknown_type $report_name
* @return string
*/
public function load($report_name) {
$r_text='';
$this->report_name = $report_name;
// Load the latest copy of the report editor
if ($report_name) {
dpm($_SESSION['forena_report_editor'], $report_name);
if (isset($_SESSION['forena_report_editor'][$report_name])) {
$r_text = $_SESSION['forena_report_editor'][$report_name];
drupal_set_message(t('All changes are stored temporarily. Click Save to make your changes permanent. Click Cancel to discard your changes.'), 'warning', FALSE);
}
else {
$filename = $report_name . '.frx';
$r_text = Frx::File()->contents($filename);
}
}
if (!$r_text) {
$m_path = drupal_get_path('module', 'forena');
$r_text = file_get_contents($m_path . '/default.frx');
}
return $r_text;
}
/**
* Save report
*/
public function save() {
unset($_SESSION['forena_report_editor'][$this->report_name]);
forena_save_report($this->report_name, $this->asXML());
drupal_set_message(t('Your report, %s has been saved.', array('%s' => $this->report_name)));
drupal_get_messages('warning');
}
/**
* Set the value of an element within the report
* @param String $xpath Xpath to element being saved
......
<?xml version="1.0"?>
<html xmlns:frx="urn:FrxReports">
<head>
<title></title>
<frx:category></frx:category>
<frx:options form=""></frx:options>
<frx:parameters>
</frx:parameters>
<frx:docgen>
</frx:docgen>
</head>
<body>
</body>
</html>
This diff is collapsed.
Markdown is supported
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