Commit 455c3fc5 authored by metzlerd's avatar metzlerd
Browse files

Bug fixes.

Parameter changes.
parent 5645634b
......@@ -48,15 +48,26 @@ class FrxDataProvider{
* @param unknown_type $block_name
* @return unknown
*/
public function load_block($block_name) {
public function load_block($block_name, $clause='') {
$filename = $this->block_path .'/'. $block_name .'.'. $this->block_ext;
$block = forena_load_block_file($filename, $this->comment_prefix, $this->comment_suffix);
// If we have a regular expression token parser, then get the tokens out of the block.
if ($this->te) {
$tokens = $this->te->tokens($block['source']);
$tokens = $this->te->tokens($block['source']);
//check tokens in the where clause
if ($clause) {
$clause_tokens = $this->te->tokens($clause);
$temp = array_combine($tokens, $tokens);
//check for duplicates in block tokens
if ($clause_tokens) foreach ($clause_tokens as $ct) {
if (!$temp[$ct]) {
array_push($tokens,$ct);
}
}
}
$block['tokens'] = $tokens;
}
return $block;
}
......@@ -86,9 +97,7 @@ class FrxDataProvider{
if (is_dir($dir_name)) {
$block_list += $this->list_blocks($search, $dir_name);
}
}
}
return $block_list;
}
......
......@@ -66,7 +66,7 @@ class FrxReport {
$parm[$akey] = (string)$attr;
}
$id = $parm['id'];
$parm['value']= (string)$node;
$parm['value']= ((string)$node) ? (string)$node : $parm['value'];
$this->parameters[$id] = $parm;
}
break;
......
......@@ -52,7 +52,6 @@ class FrxSyntaxEngine {
if ($retvar) {
// Find the end of the first tag.
//print $root_tag;
$p = strpos($retvar, '>');
$retvar = substr_replace($retvar, ' ', 0, $p+1);
$p = strrpos($retvar, '<', -1);
......
......@@ -376,54 +376,7 @@ function forena_layout_form($form_state, $new_report='') {
'#description' => t('Hide your report from showing up on the report list.'),
);
if ($r) $nodes = $r->rpt_xml->head->xpath('frx:parameters/frx:parm');
if ($nodes) {
$form['params'] = array('#tree' => TRUE,
'#type' => 'fieldset',
'#title' => 'Params',
'#collapsible' => TRUE,
'#collapsed' => TRUE,
'#description' => 'Report parameters are used to filter reports for specific information.
"id" and "Default Value" are the field => value pairs to be filtered against. "label"
is a descriptive name for form display and "require" forces a prompt for a Default Value
before the report can be displayed.');
foreach ($nodes as $node) {
//make a subtree of params
$form['params'][(string)$node['id']] = array('#tree' => TRUE, '#type' => 'fieldset', '#title' => (string)$node['label'], '#collapsible' => TRUE, '#collapsed' => TRUE );
//now walk the attributes of each node
//and make a subtree for each node
$w_count = 0; // increments the weight, so form elements show in order
foreach ($node->attributes() as $key => $value) {
if (strcmp($key, 'require') == 0) {
$form['params'][(string)$node['id']][(string)$key] = array(
'#type' => 'radios',
'#title' => $key,
'#default_value' => $value,
'#options' => array("1" => t('Yes'), "0" => t('No')),
);
}
else{
$form['params'][(string)$node['id']][(string)$key] = array(
'#type' => 'textfield',
'#title' => $key,
'#default_value' => $value,
'#required' => $required[$key],
'#weight' => ($required[$key]) ? -20 + $w_count : 0,
);
}
$w_count ++;
}
//add the default value
$form['params'][(string)$node['id']]['default'] = array(
'#type' => 'textfield',
'#title' => 'Default Value',
'#default_value' => (string)$node,
'#required' => FALSE,
);
}
}
//begin checking doc generation options
if ($r) $nodes = $r->rpt_xml->head->xpath('frx:docgen/frx:doc');
......@@ -510,6 +463,8 @@ function forena_layout_form_validate($form, &$form_state) {
*/
function forena_layout_form_submit($form, &$form_state) {
$values = $form_state['values'];
$report_name = $values['report_name'];
$h = $values['head'];
//$xml = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">'. "\n";
$xml = '<html xmlns:frx="urn:FrxReports">'. "\n";
......@@ -524,22 +479,11 @@ function forena_layout_form_submit($form, &$form_state) {
$xml .= 'form="'. $values['form'] .'"';
$xml .= '/>'. "\n";
$xml .= ' <frx:parameters>'. "\n";
$default_value;
if ($values['params']) foreach ($values['params'] as $key => $value) {
$name = $key;
$xml .= ' <frx:parm ';
foreach ($values['params'][$key] as $n => $v) {
//capture default value, concatenate it outside of tag.
if (! (strcmp($n, 'default') == 0)) {
$xml .= htmlspecialchars($n) . '="' . htmlspecialchars($v) . '" ';
}
else{
$default_value = htmlspecialchars($v);
}
}
$xml .= '>' . $default_value . '</frx:parm>' . "\n";
}
$xml .= ' <frx:parameters>'. "\n";
if ($h) $parms = $h->xpath('//frx:parm');
if ($parms) foreach ($parms as $parm) {
$xml .= ' '. $parm[0]->asXML() . "\n";
}
$xml .= ' </frx:parameters>' . "\n";
//check if docgen is avaialable for report
......@@ -579,12 +523,25 @@ function forena_layout_form_submit($form, &$form_state) {
$o->save_attributes_by_id($values['attributes']);
}
//determine redirection.
$report_path = forena_report_path();
$filename = $report_path .'/'. $report_name .'.frx';
if (!file_exists($filename)) {
$new_rpt = TRUE;
}
if (forena_save_report($file, $o->rpt_xml, TRUE) == 1) {
drupal_set_message('Your report, "' . $file . '" has been saved.');
$form_state['redirect']= 'reports/' . str_replace('/', '.', $file) .'/layout';
drupal_set_message('Your report, "' . $file . '" has been saved.');
//if this is a new report then redirect to data blocks
if ($new_rpt) {
$form_state['redirect']= 'reports/' . str_replace('/', '.', $file) .'/data';
}
else{
$form_state['redirect']= 'reports/' . str_replace('/', '.', $file) .'/layout';
}
}
}
/*
......@@ -820,11 +777,11 @@ function forena_data_block_form($form_state) {
//find the datablocks in the existing report
$data_block_array = array();
$r->get_attributes_by_id();
if ($r) $r->get_attributes_by_id();
$body = $r->body;
$path = '//*[@frx:block]';
foreach ($body->xpath($path) as $node) {
if ($body) foreach ($body->xpath($path) as $node) {
$attrs = $node->attributes(FRX_NS);
$id = (string)$node['id'];
if ($attrs['clause']) $clause = "(". (string)$attrs['clause'] .")";
......@@ -963,9 +920,9 @@ function forena_data_block_form_submit($form, &$form_state) {
if ($data_block) {
//get xml from data block
//check for and store parameters
$block_info = forena_load_block($data_block);
if ($block_info) {
//check for and store parameters
$block_info = forena_load_block($data_block, $where_clause);
if ($block_info) {
//if there were not any parameters passed. Use the report parameters
if(!$params) {
$rpt_params = $r->parameters;
......@@ -973,12 +930,11 @@ function forena_data_block_form_submit($form, &$form_state) {
$params[$id] = $rpt_params[$id]['value'];
}
}
//now invoke the data provider with the correct params
$xml = forena_invoke_data_provider($data_block, $params, $where_clause);
//drupal_set_message("report: ". htmlspecialchars($xml->asXML()));
$xml = forena_invoke_data_provider($data_block, $params, $where_clause);
}
}
//drupal_set_message("params: ". print_r($params, 1));
if ($xml) {
//create an array of columns
$rows = $xml->xpath('//row');
......@@ -1020,10 +976,8 @@ function forena_data_block_add($form, &$form_state) {
$report_name = $values['report_name'];
$data_block = $values['data_block'];
$template = $values['templates'];
$form_params = $values['params'];
$form_params = $values['params'];
$where_clause = $values['where_clause'];
$r = forena_get_report($report_name);
$head = $r->rpt_xml->head;
......@@ -1032,7 +986,7 @@ function forena_data_block_add($form, &$form_state) {
$added_report = $form_state['storage']['template_body'];
//Get the data block parameters
$block_info = forena_load_block($data_block);
$block_info = forena_load_block($data_block, $where_clause);
$data_block_parms = $block_info['tokens'];
//Build the parameters
......@@ -1054,17 +1008,12 @@ function forena_data_block_add($form, &$form_state) {
//add block params if none are found in report
if(!$found_rpt_param) {
if ($parent_node) {
if($form_params[$id]) { //if a value was passed from the form
$parm = $parent_node[0]->addChild($parm_name, $form_params[$id]);
$parm->addAttribute('id', $id);
}
else {
$parm = $parent_node[0]->addChild($parm_name);
$parm->addAttribute('id', $id);
}
$parm = $parent_node[0]->addChild($parm_name);
$parm->addAttribute('id', $id);
}
}
}
}
$main_report = forena_inner_xml($r->rpt_xml, 'body');
......@@ -1143,7 +1092,7 @@ function forena_user_data_blocks($search) {
// Make really sure the data provider objects have been instantiated
$provider = $r;
if (!$provider['data']) {
$provider = forena_repository($name);
$provider = forena_repository($name);
}
$repos[$name] = $provider;
// Invoke the list block function to find out all of the block names
......@@ -1151,7 +1100,7 @@ function forena_user_data_blocks($search) {
if (method_exists($o, 'list_blocks')) {
$blocks = $o->list_blocks($search);
foreach ($blocks as $block) {
$block_info = $o->load_block($block);
$block_info = $o->load_block($block);
if (method_exists($o, 'access')) {
$allow = $o->access($block_info['access']);
if ($allow) $user_blocks[] = $name . '/' . $block;
......@@ -1161,3 +1110,118 @@ function forena_user_data_blocks($search) {
}
return $user_blocks;
}
function forena_admin_params_form($form_state) {
$desc = forena_report_desc();
$name = $desc['name'];
$filename = $desc['filename'];
$format = $desc['format'];
if ($desc['exists'] && $name) {
$r = forena_get_report($name);
drupal_set_title($r->title);
$form = array();
$form['rpt_name'] = array (
'#type' => 'value',
'#value' => $name,
);
if ($r) $nodes = $r->rpt_xml->head->xpath('frx:parameters/frx:parm');
if ($nodes) {
$form['params'] = array('#tree' => TRUE, );
foreach ($nodes as $node) {
$attrs = $node->attributes();
$id = (string)$attrs['id'];
$label = (string)$attrs['label'];
$value = (string)$attrs['value'];
$require = $attrs['require'];
$desc = (string)$attrs['desc'];
//make a subtree of params
$form['params'][$id] = array(
'#tree' => TRUE,
'#type' => 'fieldset',
'#title' => ($label) ? $label : $id,
'#collapsible' => TRUE,
'#collapsed' => TRUE
);
$form['params'][$id]['id'] = array(
'#type' => 'textfield',
'#title' => t('id'),
'#default_value' => $id,
'#required' => TRUE,
'#description' => t('The name of the parameter to be filtered against.')
);
$form['params'][$id]['label'] = array(
'#type' => 'textfield',
'#title' => t('label'),
'#default_value' => $label,
'#required' => FALSE,
'#description' => t('A descriptive name of the parameter to be displayed on a form.')
);
$form['params'][$id]['require'] = array(
'#type' => 'radios',
'#title' => t('require'),
'#default_value' => ($require) ? $require : "0",
'#options' => array("1" => t('Yes'), "0" => t('No')),
'#description' => t('Requires a value for this parameter to display the report. If there is not a default value, the user will be prompted to enter a value.')
);
$form['params'][(string)$node['id']]['value'] = array(
'#type' => 'textfield',
'#title' => 'default value',
'#default_value' => $value,
'#description' => t('The value of the parameter for the initial view of the report.')
);
$form['params'][$id]['desc'] = array(
'#type' => 'textfield',
'#title' => t('description'),
'#default_value' => $desc,
'#description' => t('Enter a helpful description about this parameter. This will display on the form when the user is prompted to enter a parameter.'),
);
}
$form['submit'] = array(
'#type' => 'submit',
'#value' => 'Save',
);
return $form;
}
}
else {
drupal_not_found();
}
}
function forena_admin_params_form_submit($form, &$form_state) {
$values = $form_state['values'];
$name = $values['rpt_name'];
$params = $values['params'];
$r = forena_get_report($name);
if ($r) $head = $r->rpt_xml->head;
if ($r) $body = $r->body;
//delete the previous parms
unset($head->parameters->parm);
if($r) $parent = $head->xpath('frx:parameters');
//add the new parms
foreach ($params as $parm) {
$p = $parent[0]->addChild('parm');
foreach ($parm as $n => $v) {
$p->addAttribute($n, $v);
}
}
$new_report = '<html xmlns:frx="urn:FrxReports">'. $head->asXML() .'<body>'. $body->asXML() .'</body></html>';
if (forena_save_report($name, $new_report, TRUE) == 1) {
drupal_set_message('Your report has been saved');
}
}
......@@ -55,10 +55,11 @@ function forena_report_css($desc, $form, $format = '') {
$css_files = array();
// First check for the form file
$path = forena_report_path();
if ($format && file_exists($path .'/'. $form .'-'. $format .'.css')) {
$css_files[] = $path . '/'. $form . '-' . $format .'.css';
}
else {
else {
if (file_exists($path . '/' . $form . '.css')) {
$css_files[] = $path . '/' . $form . '.css';
}
......@@ -71,8 +72,9 @@ function forena_report_css($desc, $form, $format = '') {
}
elseif (file_exists($base_file .'.css')) {
$css_files[] = $base_file .'.css';
}
}
//drupal_set_message("desc: <pre>". print_r($desc, 1) ."</pre>");
//drupal_set_message("css files: <pre>". print_r($css_files, 1) ."</pre>");
return $css_files;
}
......@@ -90,35 +92,41 @@ function forena_report($name_in, $parms = array()) {
$filename = $desc['filename'];
// Determine the data to get.
if (!$parms) $parms = $_GET; else $parms = (array)$parms;
unset($parms['q']);
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->form;
$rpt_xml = $r->rpt_xml;
$rpt_xml = $r->rpt_xml;
// Default the form
if (!$form) $form = variable_get('forena_default_form', 'letter');
$q;
$bool = FALSE;
if ($r_parms) {
//put default parmeters in the query string
foreach ($r_parms as $key => $parm) {
if (!$parms[$key] && $r_parm['value']) {
$parms[$key] = $r_parm['value'];
}
}
if ((!$parms[$key]) && strcmp ($node['require'], '1') == 0) {
$missing_parms = TRUE;
}
}
$q;
//put title on top of report
$title = $r->title;
if (!$missing_parms) {
......@@ -137,6 +145,7 @@ function forena_report($name_in, $parms = array()) {
'xml' => $r_text,
'title' => $title[0],
);
forena_generate_doc($format, $output, $options);
}
else {
......@@ -349,7 +358,6 @@ function forena_invoke_data_provider($data_block, $parameters=array(), $clause='
$xml = $provider->data($block, $parameters, $clause);
}
//drupal_set_message("xml invoked: ". htmlspecialchars($xml->asXML()));
return $xml;
}
}
......@@ -364,7 +372,8 @@ function forena_invoke_data_provider($data_block, $parameters=array(), $clause='
* @param $data_block
* @return unknown_type
*/
function forena_load_block($data_block) {
function forena_load_block($data_block, $clause='') {
list($provider, $block) = explode('/', $data_block, 2);
// Get the data
......@@ -373,7 +382,7 @@ function forena_load_block($data_block) {
if ($repos['data']) {
$provider = $repos['data'];
if (method_exists($provider, 'load_block')) {
$block_info = $provider->load_block($block);
$block_info = $provider->load_block($block, $clause);
}
return $block_info;
......@@ -540,7 +549,7 @@ function forena_load_block_file($filepath, $comment='--', $trim) {
* @param string $short_message Message that will be displayed to the users
* @param string $log Message that will be recorded in the logs.
*/
function forena_error($short_message, $log) {
function forena_error($short_message='', $log='') {
if ($short_message) {
drupal_set_message($short_message, 'error');
}
......@@ -648,7 +657,9 @@ function forena_define_controls( $class='') {
* Form to edit parameters
*/
function forena_parameters_form($form_state) {
$parms = $_GET;
unset($parms['q']);
$r = forena_report_object();
if ($r) {
drupal_set_title($r->title);
......@@ -657,13 +668,28 @@ function forena_parameters_form($form_state) {
$form = array();
$form['params'] = array('#tree' => TRUE, '#title' => 'Parameters', '#type' => 'fieldset', '#collapsible' => TRUE, '#collapsed' => $r->blocks_loaded);
$nodes = $head->xpath('frx:parameters/frx:parm');
foreach ($nodes as $node) {
foreach ($nodes as $node) {
$label = (string)$node['label'];
$id = (string)$node['id'];
//check querystring for parameters
if ($parms[$id]) {
$value = $parms[$id];
}
else {
$value = (string)$node['value'];
}
(strcmp((string)$node['require'], "1") == 0) ? $bool = TRUE : $bool = FALSE;
$form['params'][(string)$node['id']] = array(
'#type' => 'textfield',
'#title' => t((string)$node['label']),
'#default_value' => $node,
'#title' => ($label) ? t($label) : t($id),
'#default_value' => ($value) ? $value : $node,
'#required' => $bool,
'#description' => $node['desc'],
);
}
$form['params']['submit'] = array(
......@@ -819,7 +845,8 @@ function forena_generate_doc($format, $output, $options = array()) {
header("Cache-Control: must-revalidate");
header("Content-Length: $flen");
header("Content-Disposition: attachment; filename=report.pdf");
break;
break;
case 'xls':
header('Content-Type: application/msexcel');
header('Cache-Control:');
......
......@@ -16,6 +16,7 @@ function forena_menu() {
'type' => MENU_NORMAL_ITEM,
'file' => 'forena.admin.inc',
);
$items['admin/settings/forena/general'] = array(
'title' => 'General',
'type' => MENU_DEFAULT_LOCAL_TASK,
......@@ -40,6 +41,7 @@ function forena_menu() {
'type' => MENU_CALLBACK,
'file' => 'forena.common.inc',
);
$items['reports/%/view'] = array(
'title' => t('View'),
......@@ -49,6 +51,14 @@ function forena_menu() {
'access arguments' => array('design any report'),
);
$items['reports/%/params'] = array(
'page callback' => 'forena_admin_params',
'page arguments' => array(1),
'title' => t('Params'),
'access arguments' => array('design any report'),
'type' => MENU_LOCAL_TASK,
);
$items['reports/%/layout'] = array(
'title' => 'Layout',
'page callback' => 'forena_layout_report',
......@@ -85,7 +95,7 @@ function forena_menu() {
'description' => t('Create a new report'),
'type' => MENU_NORMAL_ITEM,
);
$items['forena'] = array(
'page callback' => 'forena_user_reports',
'page arguments' => array(),
......@@ -94,7 +104,7 @@ function forena_menu() {
'type' => MENU_NORMAL_ITEM,
'file' => 'forena.common.inc',
);
$items['forena/fields/format/autocomplete'] = array(