function forena_data_block_form in Forena Reports 6
Same name and namespace in other branches
- 6.2 forena.admin.inc \forena_data_block_form()
- 7 forena.admin.inc \forena_data_block_form()
- 7.2 forena.admin.inc \forena_data_block_form()
- 7.3 forena.admin.inc \forena_data_block_form()
A form to preview and add data blocks to an existing report
Parameters
unknown_type $form_state:
Return value
unknown_type
1 string reference to 'forena_data_block_form'
- forena_data_block in ./
forena.module - Add, preview, or delete data blocks from your report
File
- ./
forena.admin.inc, line 787
Code
function forena_data_block_form($form_state) {
$desc = forena_report_desc();
$name = $desc['name'];
$filename = $desc['filename'];
$format = $desc['format'];
if ($desc['exists']) {
$r = forena_get_report_editor($name);
drupal_set_title($r->title);
$form = array();
$title = (string) $r->title;
$template_array = forena_supported_templates();
$default_template = $form_state['storage']['template'];
$params = $form_state['storage']['parameters'];
$param_values = $form_state['storage']['param_values'];
$form = array();
$form['report_name'] = array(
'#type' => 'value',
'#value' => $name,
);
//The default submit handler
//If someone presses enter, this handler will execute
$form['default_submit'] = array(
'#type' => 'submit',
'#submit' => array(
'forena_data_block_form_submit',
),
'#prefix' => '<div style="visibility:hidden;float:right">',
'#suffix' => '</div>',
);
//find the datablocks in the existing report
$data_block_array = array();
if ($r) {
$r
->get_attributes_by_id();
}
$body = $r->simplexml->body;
$path = '//*[@frx:block]';
if ($body) {
foreach ($body
->xpath($path) as $node) {
$attrs = $node
->attributes(FRX_NS);
$id = (string) $node['id'];
$block = (string) $attrs['block'];
if ($attrs['clause']) {
$clause = "(" . (string) $attrs['clause'] . ")";
}
$block_info = forena_load_block($block, $clause);
$access = $block_info['access'];
$data_block_array[$id] = $block . ": <i>" . $clause . ' security "' . $access . '"</i>';
}
}
$form['delete_blocks'] = array(
'#type' => 'checkboxes',
'#title' => t('Data Blocks In Report'),
'#options' => $data_block_array,
'#description' => $data_block_array ? t('Check the data block to be deleted from your report.') : '',
);
if ($data_block_array) {
$form['delete'] = array(
'#type' => 'submit',
'#value' => 'Delete',
'#submit' => array(
'forena_data_block_delete',
),
);
}
$form['data_block'] = array(
'#type' => 'textfield',
'#title' => t('Data Block'),
'#default_value' => $form_state['storage']['data_block'],
'#autocomplete_path' => 'forena/data_block/autocomplete',
'#description' => t('Enter a data block, a preview will appear below'),
);
$form['where_clause'] = array(
'#type' => 'textfield',
'#title' => t('Where Clause'),
'#default_value' => $form_state['storage']['where_clause'],
'#description' => t('Enter a where clause to filter your report.'),
);
$form['templates'] = array(
'#type' => 'radios',
'#title' => t('Templates'),
'#default_value' => $default_template ? $default_template : $template_array['table'],
'#options' => $template_array,
'#required' => TRUE,
'#description' => t('Select a template to preview the data block in.'),
);
//If there are parameters in the data block allow the user to input data
//Check if there is already a parameter of the same name in the existing report. If there is, use the report value.
if ($params) {
$rpt_params = array();
//returns a 2 dimensional array of report parameters from the report
if ($r) {
$rpt_params = $r->parameters;
}
$form['params'] = array(
'#tree' => TRUE,
'#title' => 'Parameters',
'#type' => 'fieldset',
'#collapsible' => TRUE,
'#collapsed' => $form_state['storage']['output'] ? TRUE : FALSE,
);
foreach ($params as $param) {
$form['params'][$param] = array(
'#type' => 'textfield',
'#title' => t($param),
'#default_value' => $param_values[$param] ? $param_values[$param] : $rpt_params[$param]['value'],
);
}
}
$form['output'] = array(
'#type' => 'markup',
'#value' => '</p>' . $form_state['storage']['output'] . '</p>',
);
$form['preview'] = array(
'#type' => 'submit',
'#value' => 'Preview',
);
if ($form_state['storage']['output'] != '') {
$form['add'] = array(
'#type' => 'submit',
'#value' => 'Add',
'#submit' => array(
'forena_data_block_add',
),
);
}
return $form;
}
else {
drupal_not_found();
}
}