function forena_data_block_add in Forena Reports 7.2
Same name and namespace in other branches
- 6.2 forena.admin.inc \forena_data_block_add()
- 6 forena.admin.inc \forena_data_block_add()
- 7 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'
File
- ./
forena.admin.inc, line 1818
Code
function forena_data_block_add($form, &$form_state) {
//$form_state['rebuild'] = TRUE;
$values = $form_state['values'];
$report_name = $values['report_name'];
$data_block = $form_state['storage']['data_block'];
$where_clause = $form_state['storage']['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 = FrxReportGenerator::instance()
->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);
$found_rpt_param = FALSE;
$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(t('Your report has been saved'));
$form_state['redirect'] = $values['return'];
}
}