function forena_save_report in Forena Reports 6
Same name and namespace in other branches
- 8 forena.common.inc \forena_save_report()
- 6.2 forena.admin.inc \forena_save_report()
- 7.5 forena.common.inc \forena_save_report()
- 7 forena.admin.inc \forena_save_report()
- 7.2 forena.admin.inc \forena_save_report()
- 7.3 forena.common.inc \forena_save_report()
- 7.4 forena.common.inc \forena_save_report()
Save the report file to disk
Parameters
string $name File name to save report to:
unknown_type $data:
7 calls to forena_save_report()
- forena_admin_params_form_submit in ./
forena.admin.inc - forena_data_block_add in ./
forena.admin.inc - submit handler for forena_data_block_form. This adds the datablock to an existing report.
- forena_data_block_delete in ./
forena.admin.inc - Delete submit handler to delete report blocks
- forena_db_sync in ./
forena.admin.inc - Syncronize the data
- forena_fields_form_submit in ./
forena.admin.inc
File
- ./
forena.admin.inc, line 78
Code
function forena_save_report($report_name, $report, $save_file = FALSE) {
static $save_count = 0;
if ($report && !is_object($report)) {
try {
$report = new SimpleXMLElement($report);
} catch (Exception $e) {
forena_error(t('Could not save %s because XML was malformed', htmlspecialchars($report_name)), "<p>Invalid XML</p><pre>XML:" . htmlspecialchars($report) . "\n" . $e
->getMessage() . "</pre>");
return;
}
}
_forena_verify_directory($report_name);
$report_path = forena_report_path();
$r = new FrxReport($report);
$data['title'] = $r->title;
$data['category'] = $r->category;
$data['options'] = $r->options;
$data['name'] = $report_name;
//@TODO: Clean up filename to make sure
$name = $data['name'];
$filepath = $report_path . '/' . $report_name . '.frx';
// If we need to save this to the file system
if ($save_file) {
// Serialize the report for saving
if (is_object($report)) {
$r_xml = $report
->asXML();
}
try {
file_put_contents($filepath, $r_xml);
} catch (Exception $e) {
fornea_error('Error Saving Report', $e
->getMessage());
}
}
// Get the security caches from the reports
if ($report) {
$cache = forena_load_cache($report);
}
else {
$cache = '';
}
if ($cache) {
$rpt_cache = serialize($cache);
}
// Set default interpretations of data
$data['enabled'] = $data['enabled'] ? 1 : 0;
if ((string) $data['options']['hidden']) {
$data['hidden'] = $data['options']['hidden'] && $data['options']['hidden'] != 'N' && $data['options']['hidden'] != '0' ? 1 : 0;
if (!$data['category']) {
$data['category'] = 'All';
}
}
else {
// Set hidden based on category
$data['hidden'] = $data['category'] ? 0 : 1;
}
// Save to the Database
if (file_exists($filepath)) {
$modified = filemtime($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', category='%s'" . ", hidden='%s', cache='%s', modified=%d WHERE report_name='%s'", array(
$data['title'],
$data['category'],
$data['hidden'],
$rpt_cache,
$modified,
$name,
));
}
else {
db_query("INSERT INTO {forena_reports} (report_name, title, category, hidden, cache, modified) " . "VALUES ('%s', '%s', '%s', %d, '%s', %d)", array(
$name,
$data['title'],
$data['category'],
$data['hidden'],
$rpt_cache,
$modified,
));
}
$save_count++;
}
$r = null;
$result = null;
$r_xml = null;
$report = NULL;
$data = NULL;
$rpt = null;
$cache = null;
$rpt_cache = null;
return $save_count;
}