function forena_report in Forena Reports 6
Same name and namespace in other branches
- 8 forena.module \forena_report()
- 6.2 forena.module \forena_report()
- 7.5 forena.module \forena_report()
- 7 forena.module \forena_report()
- 7.2 forena.module \forena_report()
- 7.3 forena.module \forena_report()
- 7.4 forena.module \forena_report()
Load and render a report based on a drupal path. In this function the arglist is used to get the full path to the report.
Return value
unknown
1 string reference to 'forena_report'
- forena_menu in ./
forena.module - Implementation of hook_menu.
File
- ./
forena.module, line 374
Code
function forena_report($name_in, $parms = array(), $print = TRUE) {
require_once 'forena.common.inc';
$desc = forena_report_desc($name_in);
$name = $desc['name'];
$format = $desc['format'];
$filename = $desc['filename'];
// Determine the data to get.
if (!$parms) {
$parms = $_GET;
}
else {
$parms = (array) $parms;
}
unset($parms['q']);
if ($name) {
$r = forena_get_report($name, $parms);
if ($r) {
//check for default parameters
$r_params = $r->parameters;
if ($r_params) {
//put default parameters in parms array
foreach ($r_params as $key => $parm) {
if (!$parms[$key] && $parm['value']) {
$parms[$key] = $parm['value'];
$reload_params = TRUE;
}
//do not show report if a required parameter does not have a value
//force the user to input a parameter
if (!$parms[$key] && strcmp($parm['require'], "1") == 0 && !$parm['value']) {
$missing_parms = TRUE;
}
}
}
//Reload report if parameters were missing
if ($reload_params) {
$r = forena_get_report($name, $parms);
}
// Get data from the report;
$r_parms = $r->parameters;
$form = $r->options['form'];
$rpt_xml = $r->rpt_xml;
// Default the form
if (!$form) {
$form = variable_get('forena_default_form', 'letter');
}
$q;
//put title on top of report
$title = $r->title;
if (!$missing_parms) {
$output .= $r
->render($format);
$css_files = forena_report_css($desc, $form, $format);
}
if ($format) {
//a format was requested
$header = '<h1>' . $title . '</h1>';
$output = $header . $output;
$css_text = '';
$r_text = '';
if ($css_files) {
foreach ($css_files as $css_file) {
$css_text .= file_get_contents($css_file);
}
}
$options = array(
'css' => $css_text,
'docname' => str_replace(' ', '_', $title),
'xml' => $r_text,
'title' => $title[0],
);
$output = forena_generate_doc($format, $output, $options, $print);
return $output;
}
else {
// We've got parameters so display the parameters form
if ($r_parms) {
$output = drupal_get_form('forena_parameters_form') . $output;
}
//set the title
$title = $r->title;
drupal_set_title($title);
//Creating links for downloadable documents.
//build querystring for document href
foreach ($parms as $key => $value) {
$q .= "&" . $key . '=' . $value;
}
$q = trim($q, '&');
//Building the document links
$rpt_xml = $r->rpt_xml;
$nodes = $rpt_xml
->xpath('//frx:docgen/frx:doc');
$div .= '<div class="doclinks">';
$default_doctypes = variable_get('forena_doc_defaults', array());
$base = base_path();
if (!$missing_parms) {
if (!$nodes) {
//show the default. All supported links
foreach ($default_doctypes as $value) {
if (is_object(forena_get_doctypes($value))) {
$div .= '<a class="doclinks" href="' . $base . 'report_doc/' . $name_in . '.' . $value . '?' . $q . '">' . strtoupper($value) . '</a>';
}
}
}
else {
//There were nodes. show the prefered doc types
$doctypes = forena_supported_doctypes();
foreach ($nodes as $value) {
$arr = $value
->attributes();
$type = (string) $arr['type'];
if ($doctypes[$type]) {
if (is_object(forena_get_doctypes($type))) {
$div .= '<a class="doclinks" href="' . $base . 'report_doc/' . $name_in . '.' . $type . '?' . $q . '">' . strtoupper($type) . '</a>';
}
}
}
}
$div .= '</div>';
$output = $div . '<div class="forena-report">' . $output . '</div>';
}
$path = drupal_get_path('module', 'forena');
drupal_add_css($path . '/forena.css', 'module');
if ($css_files) {
foreach ($css_files as $css_file) {
drupal_add_css($css_file, 'module');
}
}
$output = check_markup($output, variable_get('forena_input_format', FILTER_FORMAT_DEFAULT), FALSE);
return $output;
}
}
else {
// Didn't find it so assume we've got a stale cache entry and delete it.
require_once 'forena.admin.inc';
forena_delete_report($name, FALSE);
drupal_not_found();
}
}
else {
drupal_not_found();
}
}