You are here

function FrxDrupalApplication::load_report in Forena Reports 7.3

Same name and namespace in other branches
  1. 6.2 FrxDrupalApplication.inc \FrxDrupalApplication::load_report()
  2. 7.2 FrxDrupalApplication.inc \FrxDrupalApplication::load_report()
  3. 7.4 FrxDrupalApplication.inc \FrxDrupalApplication::load_report()

Accepts the name of a file

Returns a xml object of the file.

File

./FrxDrupalApplication.inc, line 108
HostApp.inc Defines all the interface points between the host application and Forena. Each of these methods must be specified in order for Forena to function properly. The base class here is drupal, so those

Class

FrxDrupalApplication

Code

function load_report($report_name) {
  $r = NULL;
  global $language;
  $r_text = '';
  if ($report_name) {
    $i_report_name = $report_name;
    $report_path = Frx::File()
      ->path('');
    $int_filename = $language->language . '/' . $report_name . '.frx';
    $filename = $report_name . '.frx';
    if (Frx::File()
      ->exists($int_filename) && @$_GET['language'] != 'en') {
      $i_report_name = $language->language . '/' . $report_name;
      $r_text = file_get_contents($int_filename);
      $modified = filemtime($int_filename);
      $filename = $int_filename;
    }
    elseif (Frx::File()
      ->exists($filename)) {
      $r_text = Frx::File()
        ->contents($filename);
      $modified = filemtime(Frx::File()
        ->path($filename));
    }
    $result = db_query("SELECT * FROM {forena_reports} WHERE report_name=:report_name AND language=:language", array(
      ':report_name' => $report_name,
      ':language' => $language->language,
    ));
    $save = FALSE;
    if ($rpt = $result
      ->fetchObject()) {

      // If the file modification time has changed then save.
      if ($modified && $rpt->modified != $modified) {
        $save = TRUE;
      }

      // If the report has been altered by a user then use that.
      if ($rpt->altered == -1) {
        if ($rpt->src) {
          $r_text = $rpt->src;
        }
      }
    }
    elseif ($r_text) {
      $save = TRUE;
    }
    if ($save) {
      require_once 'forena.admin.inc';
      forena_save_report($i_report_name, $r_text, FALSE);
    }
    return $r_text;
  }
}