Commit b1a5fc1e authored by metzlerd's avatar metzlerd
Browse files

Working altering of changed block format.

New Quick reports method of creating a report. 
parent 1a3f016a
......@@ -167,6 +167,7 @@ class Frx {
return $instances;
}
/**
* Returns an object of the template class
* that has a method named templates.
......
......@@ -222,4 +222,19 @@ class FrxBlockEditor {
return $tokens;
}
/**
* Get persisted parateters from a block from a session.
*/
public function getParms() {
return $_SESSION['forena_data_block_parms'][$this->block_name];
}
/**
* Persist paramaters for a block into a session
*/
public function saveParms() {
$parms = Frx::Data()->getContext('parm');
$_SESSION['forena_data_block_parms'][$this->block_name] = $parms;
}
}
\ No newline at end of file
<?php
require_once 'FrxReport.inc';
/**
* @file FrxEditor.inc
* Wrapper XML class for working with DOM object.
......@@ -16,6 +17,7 @@ class FrxEditor {
public $frx_attributes;
public $cache;
public $frxReport;
public $desc;
public $doc_prefix = '<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE root [
<!ENTITY nbsp "&#160;">
......@@ -76,9 +78,10 @@ class FrxEditor {
* @return string
*/
public function load($report_name) {
$this->desc = Frx::Menu()->parseURL($report_name);
$r_text='';
$dom = $this->dom;
$this->report_name = $report_name;
$this->report_name = $report_name = $this->desc['name'];
// Load the latest copy of the report editor
if ($report_name) {
if (isset($_SESSION['forena_report_editor'][$report_name])) {
......@@ -637,6 +640,44 @@ class FrxEditor {
return $this;
}
/**
* Scrape Data block configuration
* This tries to introspect the frx:block configuration based
* on the child nodes in the report by calling the
* getConfig method on the block.
*/
public function scrapeBlockConfig($id, &$config) {
$path = "//*[@id='$id']";
$nodes = $this->simplexml->xpath($path);
if ($nodes) ( $node = dom_import_simplexml($nodes[0]));
if (!$node) {
drupal_set_message(t('Could not find %s in report', array('%s' => $id)), 'error');
return '';
}
$block_name = $node->getAttributeNS($this->xmlns, 'block');
$class = $node->getAttribute("class");
$templates = $this->templateOptions();
foreach ($templates as $tclass => $desc) {
if (strpos($class, $tclass)!==FALSE) {
$template_class = $tclass;
break;
}
}
if ($template_class) {
$c = Frx::Template($template_class);
if ($c && method_exists($c, 'getConfig')) {
$c->initReportNode($node, $$this->frxReport);
$config = array_merge($config,$c->getConfig());
}
return $template_class;
}
else {
return 'FrxTable';
}
}
/**
* Apply a template based on the block id.
......@@ -680,6 +721,7 @@ class FrxEditor {
* @return FrxEditor
*/
public function addBlock($block_name, $template_class='FrxTable', $config=array(), $id='') {
$block_name = str_replace('.', '/', $block_name);
if ($id) {
$node = $this->dom->getElementById($id);
}
......@@ -705,6 +747,7 @@ class FrxEditor {
public function preview() {
$r = $this->frxReport;
if(strpos($this->report_name, '__') !== 0) $r->preview_mode = TRUE;
//check for default parameters
$r->processParameters();
Frx::Skin()->load($r->skin);
......@@ -712,4 +755,47 @@ class FrxEditor {
return $r->render('web');
}
public function editLinks($frx, $id='') {
$o = '';
if ($frx['block']) {
$block_name = (string)$frx['block'];
$block_link = str_replace('/', '.', $block_name);
$report_name = str_replace('/', '.' , $this->report_name);
//$b=Frx::BlockEditor($block_name)->block;
$o = '<div class="forena-edit-links">' . l($block_name, "reports/$report_name/edit/data/$block_link/$id" ) . "</div>";
}
return $o;
}
/**
* Generate the configuration form for the template for a class.
* @param unknown $class
* @param unknown $config
*/
public function templateConfigForm($class, $config) {
$form = array();
$c = Frx::Template($class);
if ($c && method_exists($c, 'configForm')) {
$form = $c->configForm($config);
}
return $form;
}
/**
* Generate the list of possible templates.
*/
public function templateOptions() {
$controls = Frx::Controls();
$templates = array();
foreach ($controls as $control) {
if (method_exists($control, 'generate') && isset($control->templateName)) {
$templates[get_class($control)] = $control->templateName;
}
}
return $templates;
}
}
\ No newline at end of file
......@@ -36,6 +36,7 @@ class FrxReport {
public $dom;
public $format;
public $link_mode = '';
public $preview_mode = FALSE; // This will make the report renderer put in editing controls when TRUE
public function __construct($xhtml='', $data=array()) {
......
......@@ -680,146 +680,6 @@ function forena_edit_delete_submit($form, &$form_state) {
}
function forena_add_report_form($formid, $form_state, $report_name='') {
$name = '';
$filename = '';
$format = '';
if ($report_name) {
$desc = Frx::Menu()->parseURL($report_name);
$name = $desc['name'];
$filename = $desc['filename'];
$format = @$desc['format'];
}
$form = array();
global $language;
//determine if this is an add new report request
$r = Frx::Editor($name);
$title = (string)$r->title;
if (module_exists('locale')) {
@list($tlang, $tsave_name) = explode('/', $name, 2);
// FInd out if the starting name of the report is an installed language.
if (array_key_exists($tlang, language_list() )) {
$lang = $tlang;
$save_name = $tsave_name;
}
else {
$lang = 'en';
}
}
// Need to get all option attributes
$frx_options = $r->getOptions();
$hidden = @$frx_options['hidden']=='1' ? 1 : 0;
$report_form = @$frx_options['form'];
$attributes = $r->get_attributes_by_id();
$category = $r->getCategory();
$body = $r->simplexml->body->asXML();
//array of xml attributes that are required to have a value
$required = array('id' => TRUE, 'label' => TRUE);
//list of supported document formats
$doclist = variable_get('forena_doc_formats', array());
$form['save_report_name'] = array(
'#type' => 'textfield',
'#title' => t('Report Name'),
'#description' => t('Enter only letters, numbers, and special characters: - _ /
<br/>White space is not permitted.
Create a directory using the format: (directory name) / (report name). Save multiple reports to the same directory
by referencing the same name.'),
'#required' => TRUE,
);
$form['title'] = array(
'#type' => 'textfield',
'#title' => t('Title'),
'#default_value' => $title,
'#required' => TRUE,
);
$form['category'] = array(
'#type' => 'textfield',
'#title' => t('Category'),
'#default_value' => $category,
'#autocomplete_path' => 'forena/categories/autocomplete',
'#description' => t('The heading your report will be grouped under on the report list.'),
);
$form['hidden'] = array(
'#type' => 'checkbox',
'#title' => t('Hidden'),
'#default_value' => $hidden,
'#description' => t('Hide your report from showing up on the report list.'),
);
$form['report_name'] = array(
'#title' => t('Create from report'),
'#type' => 'textfield',
'#autocomplete_path' => 'forena/reports/autocomplete',
'#default_value' => $name,
);
$form['save'] = array(
'#type' => 'submit',
'#value' => 'Create',
);
return $form;
}
function forena_add_report_form_validate($form, &$form_state) {
$values = $form_state['values'];
$pattern = "@^[A-Za-z0-9\/\_]$@";
$save_report_name = $values['save_report_name'];
if (preg_match($pattern, $save_report_name)) {
form_set_error('save_report_name', t('Invalid characters in report name') );
}
//comparing the report names to see if they have changed.
//If they have, making sure the new name does not already exist.
$filename = $save_report_name . '.frx';
if (Frx::File()->exists($filename, FALSE)) {
form_set_error('save_report_name', t('The report ' . $save_report_name . ' already exists. Please enter another name.'));
}
}
function forena_add_report_form_submit($form, &$form_state) {
$values = $form_state['values'];
$report_name = $values['save_report_name'];
$desc = Frx::Menu()->parseURL($report_name);
$report_name = $desc['name'];
if ($values['report_name']) {
$r = Frx::Editor($values['report_name']);
$r->report_name = $values['save_report_name'];
}
else {
$r = Frx::Editor($values['save_report_name']);
}
// Title and category
$r->setTitle($values['title']);
$r->setCategory($values['category']);
// Form options
$options = array(
'hidden' => $values['hidden'],
);
$r->setOptions($options);
//determine redirection.
$filename = $desc['filename'];
$r->update();
//if this is a new report then redirect to data blocks
if ($values['report_name']) {
$edit = '/edit';
}
else {
$edit = '/edit/data/add';
}
$form_state['redirect']= $desc['i_link'] . $edit;
}
function forena_create_trans_form($formid, $form_state, $report_name) {
$name = '';
$filename = '';
......@@ -1335,9 +1195,6 @@ function forena_access_info_callback($form, $form_state) {
return $form['access_details'];
}
function forena_save_submit($form, &$form_state) {
Frx::Editor()->save();
}
function forena_save_cancel($form, &$form_state) {
Frx::Editor()->cancel();
......@@ -1712,20 +1569,6 @@ function forena_add_cancel($form, &$form_state) {
$form_state['redirect'] = $form_state['values']['return'];
}
function forena_data_preview() {
$args = func_get_args();
$block_name = implode('/', $args);
$block_name = str_replace('.', '/', $block_name);
$r = Frx::Editor('__block_preview__');
$r->cancel();
$r->addBlock($block_name);
$output = 'hello';
$output .= $r->preview();
return $output;
}
/**
* submit handler for forena_data_block_form.
* This adds the datablock to an existing report.
......@@ -1849,144 +1692,6 @@ function forena_add_data_block_form_submit($form, &$form_state) {
}
/**
* A form to preview and add data blocks to an existing report
* @param $formid String representation fo form
* @param $form_state Array of block type
* @return unknown_type
*/
function forena_data_block_form($formid, &$form_state, $report_name) {
$desc = Frx::Menu()->parseURL($report_name);
$name = $desc['name'];
$filename = $desc['filename'];
$format = isset($desc['format']) ? $desc['format'] : '';
$r = Frx::Editor($name);
drupal_set_title($r->title);
$form = array();
$title = (string)$r->title;
$template_array = FrxReportGenerator::instance()->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,
);
$links = array();
$links[] = array('href' => $desc['link'] . '/edit/data/add', 'title' => 'Add Data' );
$form['add_link'] = array(
'#type' => 'markup',
'#markup' => theme('links',
array(
'links' => $links,
'attributes' => array('class' => 'action-links'),
)
)
);
//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]';
$form['blocks'] = array(
'#tree' => TRUE,
'#type' => 'vertical_tabs',
);
if ($body) foreach ($body->xpath($path) as $node) {
$attrs = $node->attributes(FRX_NS);
$id = (string)$node['id'];
$block = (string)$attrs['block'];
$parameters = (string)$attrs['parameters'];
$block_info = Frx::RepoMan()->loadBlock($block);
$access = @$block_info['access'];
$data_block_array[$id] = $block . ": <i>" . ' security "' . $access . '"</i>';
$ctl = array(
'#type' => 'fieldset',
'#title' => $id,
'#group' => 'additional_settings'
);
$ctl['id'] = array(
'#type' => 'value',
'#value' => $id,
);
$ctl['block'] = array(
'#type' => 'textfield',
'#autocomplete_path' => 'forena/data_block/autocomplete',
'#title' => 'Data Block',
'#default_value' => $block,
'#required' => TRUE,
'#description' => t('The data block to be used as the source for the data in the report.'),
);
$ctl['access'] = array(
'#type' => 'item',
'#markup' => $access,
'#title' => t('Security'),
);
$ctl['parameters'] = array(
'#type' => 'textfield',
'#title' => t('Parameters'),
'#default_value' => $parameters,
'#description' => t('Leave blank to use the current data context as parameters. In a simple report this will be the parameters of the report.
In master detail reports, this will be the report of the containing data block. Parameters should be specified in the form of a url string.')
);
$ctl['delete'] = array(
'#type' => 'checkbox',
'#title' => 'Confirm delete',
'#description' => t('Check this box to remove this data from the report.'),
);
$ctl['delete_submit'] = array(
'#type' => 'submit',
'#value' => 'Delete',
'#submit' => array('forena_data_block_delete'),
);
$form['blocks'][] = $ctl;
}
$form['update'] = array(
'#type' => 'update',
'#value' => 'Update',
);
$form['save'] = array(
'#type' => 'submit',
'#value' => 'Save',
'#submit' => array('forena_data_block_form_submit', 'forena_save_submit'),
);
$form['cancel'] = array(
'#type' => 'submit',
'#value' => 'Cancel',
'#submit' => array('forena_save_cancel'),
);
return $form;
}
......
<?php
/**
* @file forena.data.inc
* Common files for diplaying and previewing data blocks.
*/
function forena_display_blocks() {
$header = array(t('Block'), t('Access'), t('Keywords'), t('Actions'));
$blocks = Frx::BlockEditor()->revertDBBLocks();
$blocks = Frx::DataFile()->userBlocks();
$links[] = array('href' => 'admin/structure/forena/data/add', 'title' => 'Create New SQL Query)' );
$content['add']['#markup'] = theme('links',
array(
'links' => $links,
'attributes' => array('class' => 'action-links'),
)
);
$data=array();
foreach ($blocks as $block_name => $block) {
$blck = str_replace('/', '.', $block_name);
$actions = '';
if ($block->cache['type'] == 'sql' && module_exists('forena_query')){
if ($block->include) {
$actions = l(t('Override'), 'admin/structure/forena/data/' . $blck . '/edit');
}
else {
$actions = l(t('Edit'), 'admin/structure/forena/data/' . $blck . '/edit');
}
$clone = l(t('Clone'), 'admin/structure/forena/data/clone/' . $blck);
// Determine the nature of the report delete link.
if ($block->override && !$block->include) {
$actions .= ' ' .l(t('Revert'), 'admin/structure/forena/data/' . $blck . '/delete', array('query' => array('destination' => 'admin/structure/forena/data')));
}
else if (!$block->include) {
$actions .= ' ' . l(t('Delete'), 'admin/structure/forena/data/' . $blck . '/delete', array('query' => array('destination' => 'admin/structure/forena/data')));
}
}
// Build the table.
$data[] = array(
l($block_name, "forena/data/$blck"),
@$block->cache['access'],
@$block->cache['keywords'],
$actions,
);
}
// Theme the table
$content['data_blocks'] = array('#markup' => theme('forena_data_table', array('header' => $header, 'rows' => $data)));
return $content;
}
function forena_data_preview() {
$args = func_get_args();
$block_name = implode('/', $args);
$block_name = str_replace('.', '/', $block_name);
$r = Frx::Editor('__block_preview__');
$r->cancel();
$r->addBlock($block_name);
$content ['preview']['#markup'] = $r->preview();
$content ['add_report'] = drupal_get_form('forena_data_quick_report_form', $block_name);
return $content;
}
/**
* Create a report quickly from a data block
* @param unknown $form
* @param unknown $form_state
* @param unknown $block_name
*/
function forena_data_quick_report_form($form, &$form_state, $block_name) {
require_once 'forena.report.inc';
//@TODO: Make sure report name is unique.
// Get the add form.
$form['add'] = array('#type' => 'fieldset', '#title' => t('Quick Report'), '#collapsible' => TRUE, '#collapsed' => TRUE);
$form['add'] = array_merge($form['add'], forena_add_report_form($form, $form_state));
$form['block_name'] = array(
'#type' => 'value',
'#value' => $block_name,
);
$form['add']['save']['#submit'][] = 'forena_data_quick_report_form_submit';
return $form;
}
function forena_data_quick_report_form_submit($form, &$form_state) {
Frx::BlockEditor($form_state['values']['block_name'])->saveParms();
$report_name = str_replace('/', '.', $form_state['values']['report_name']);
$block_name = str_replace('/', '.', $form_state['values']['block_name']);
$form_state['redirect'] = "reports/$report_name/edit/add-data/$block_name";
}
\ No newline at end of file
......@@ -83,6 +83,22 @@ function forena_menu() {
'file' => 'forena.admin.inc',
);
$items['admin/structure/forena/data'] = array(
'type' => MENU_LOCAL_TASK,
'title' => 'Data',
'access arguments' => array('design any report'),
'page callback' => 'forena_display_blocks',
'file' => 'forena.data.inc',
);
$items['forena/data'] = array(
'page callback' => 'forena_data_preview',
'access arguments' => array('design any report'),
'file' => 'forena.data.inc',
'type' => MENU_CALLBACK,
);
$items['reports/%'] = array(
'page callback' => 'forena_report',
'page arguments' => array(1),
......@@ -111,12 +127,12 @@ function forena_menu() {
$items['reports/%/edit'] = array(
'title' => 'Edit',
'page callback' => 'drupal_get_form',
'page arguments' => array( 'forena_general_form',1),
'page callback' => 'forena_report_preview',
'page arguments' => array(1),
'access arguments' => array('design any report'),
'description' => 'Edit the layout of your report',
'type' => MENU_LOCAL_TASK,
'file' => 'forena.admin.inc',
'file' => 'forena.report.inc',
);
if (module_exists('locale')) {
......@@ -153,7 +169,7 @@ function forena_menu() {