function forena_data_block_add in Forena Reports 6
Same name and namespace in other branches
- 6.2 forena.admin.inc \forena_data_block_add()
- 7 forena.admin.inc \forena_data_block_add()
- 7.2 forena.admin.inc \forena_data_block_add()
- 7.3 forena.admin.inc \forena_data_block_add()
submit handler for forena_data_block_form. This adds the datablock to an existing report.
1 string reference to 'forena_data_block_add'
- forena_data_block_form in ./
forena.admin.inc - A form to preview and add data blocks to an existing report
File
- ./
forena.admin.inc, line 1022
Code
function forena_data_block_add($form, &$form_state) {
$values = $form_state['values'];
$report_name = $values['report_name'];
$data_block = $values['data_block'];
$template = $values['templates'];
$where_clause = $values['where_clause'];
$r = forena_get_report_editor($report_name);
$head = $r->simplexml->head;
//Get the xml body of the added data block
$added_report = $form_state['storage']['template_body'];
//Get the data block parameters
$block_info = forena_load_block($data_block, $where_clause);
$data_block_parms = $block_info['tokens'];
//Build the parameters
$xml = "";
$path_parent = '//frx:parameters';
$parent_node = $head
->xpath($path_parent);
$path_child = '//frx:parm';
$child_nodes = $head
->xpath($path_child);
$parm_name = 'parm';
//loop through the data block parameters
foreach ($data_block_parms as $index => $id) {
//check if rpt_params exist
if ($child_nodes) {
$path_id = '//frx:parm[@id="' . $id . '"]';
$found_rpt_param = $child_nodes[0]
->xpath($path_id);
}
//add block params if none are found in report
if (!$found_rpt_param) {
if ($parent_node) {
$parm = $parent_node[0]
->addChild($parm_name);
$parm
->addAttribute('id', $id);
}
}
}
$main_report = forena_inner_xml($r->simplexml, 'body');
$added_report = forena_clean_xhtml($added_report);
$r
->setBody($main_report . "\n" . $added_report);
if (forena_save_report($report_name, $r
->asXML(), TRUE) == 1) {
drupal_set_message('Your report has been saved');
}
}