You are here

public function FrxEditor::load in Forena Reports 7.4

Load report from file system

Parameters

unknown_type $report_name:

Return value

string

1 call to FrxEditor::load()
FrxEditor::__construct in ./FrxEditor.inc
Construct the editor Enter description here ...

File

./FrxEditor.inc, line 86
FrxEditor.inc Wrapper XML class for working with DOM object. It provides helper Enter description here ... @author metzlerd

Class

FrxEditor
@file FrxEditor.inc Wrapper XML class for working with DOM object. It provides helper Enter description here ... @author metzlerd

Code

public function load($report_name, $edit = TRUE) {
  $this->desc = Frx::Menu()
    ->parseURL($report_name);
  $r_text = '';
  $dom = $this->dom;
  $this->report_name = $report_name = $this->desc['name'];
  $this->report_link = 'reports/' . str_replace('/', '.', $this->desc['base_name']);

  // Load the latest copy of the report editor
  if ($report_name) {
    if (isset($_SESSION['forena_report_editor'][$report_name]) && $edit) {
      $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');
  }
  libxml_use_internal_errors();
  try {
    @$dom
      ->loadXML($r_text);
    $this->xpq = new DOMXPath($dom);
  } catch (Exception $e) {
    Frx::error('Invalid or malformed report document', '<pre>' . $e
      ->getMessage() . $e
      ->getTraceAsString() . '</pre>');
  }
  if (!$this->dom->documentElement) {
    Frx::error(t('Invalid or malformed report document'));
    return;
  }
  $this
    ->verifyHeaderElements();
  $tnodes = $dom
    ->getElementsByTagName('title');
  if ($tnodes->length) {
    $this->title = $tnodes
      ->item(0)->textContent;
  }
  $this->document_root = $dom->documentElement;
  $this->simplexml = simplexml_import_dom($dom);
  $dom->formatOutput = TRUE;

  // Try to make sure garbage collection happens.
  unset($this->xpq);
  $this->xpq = new DOMXPath($dom);
  $this->xpq
    ->registerNamespace('frx', $this->xmlns);

  // Make sure document header is reparsed.
  $this->frxReport
    ->setReport($this->dom, $this->xpq, $this->edit);
  $cache = forena_load_cache($this->frxReport->rpt_xml);
  if (isset($cache['access'])) {
    $this->access = forena_check_all_access($cache['access']);
  }
  if (!$edit) {
    $this->cache = Frx::File()
      ->getCacheEntry($report_name . '.frx');
  }
  return $r_text;
}