View source
<?php
require_once 'forena.data.inc';
require_once 'Frx.inc';
function forena_menu() {
$items = array();
Frx::Menu()
->addMenuItems($items);
$items['admin/structure/forena'] = array(
'type' => MENU_NORMAL_ITEM,
'title' => 'Forena Reports',
'description' => 'Build reports based on data in your sites databases.',
'page callback' => 'forena_admin_reports',
'access arguments' => array(
'design any report',
),
'file' => 'forena.admin.inc',
);
$items['admin/structure/forena/reports'] = array(
'type' => MENU_DEFAULT_LOCAL_TASK,
'title' => 'Reports',
'description' => 'Build reports based on data in your sites databases.',
'page callback' => 'forena_admin_reports',
'access arguments' => array(
'design any report',
),
'file' => 'forena.admin.inc',
);
$items['admin/config/content/forena'] = array(
'page callback' => 'drupal_get_form',
'page arguments' => array(
'forena_settings',
),
'title' => 'Forena Reports',
'description' => 'Tell Forena where to store report files and how users should access them.',
'access arguments' => array(
'administer forena reports',
),
'type' => MENU_NORMAL_ITEM,
'file' => 'forena.admin.inc',
);
$items['admin/config/content/forena/general'] = array(
'title' => 'General',
'type' => MENU_DEFAULT_LOCAL_TASK,
'file' => 'forena.admin.inc',
'weight' => -10,
);
$items['admin/config/content/forena/data/configure'] = array(
'title' => 'Configure data source',
'page callback' => 'drupal_get_form',
'page arguments' => array(
'forena_data_settings_edit',
),
'type' => MENU_CALLBACK,
'file' => 'forena.admin.inc',
'access arguments' => array(
'administer forena reports',
),
);
$items['admin/config/content/forena/data/add'] = array(
'title' => 'Add data source',
'type' => MENU_CALLBACK,
'page callback' => 'drupal_get_form',
'page arguments' => array(
'forena_data_settings_edit',
),
'file' => 'forena.admin.inc',
'access arguments' => array(
'administer forena reports',
),
);
$items['admin/config/content/forena/data'] = array(
'title' => 'Data',
'page callback' => 'forena_data_settings',
'type' => MENU_LOCAL_TASK,
'file' => 'forena.admin.inc',
'access arguments' => array(
'administer forena reports',
),
);
$items['admin/config/content/forena/formats'] = array(
'page callback' => 'drupal_get_form',
'page arguments' => array(
'forena_doc_formats_settings',
),
'title' => 'Document Types',
'access arguments' => array(
'administer forena reports',
),
'type' => MENU_LOCAL_TASK,
'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,
),
'title' => 'Reports',
'access arguments' => array(
'access content',
),
'type' => MENU_CALLBACK,
'file' => 'forena.common.inc',
);
$items['reports/%/nojs'] = array(
'page callback' => 'forena_report',
'page arguments' => array(
1,
),
'title' => 'Reports',
'access arguments' => array(
'access content',
),
'type' => MENU_CALLBACK,
'file' => 'forena.common.inc',
);
$items['reports/%/ajax'] = array(
'page callback' => 'forena_report_ajax_callback',
'page arguments' => array(
1,
),
'title' => 'Reports',
'access arguments' => array(
'access content',
),
'type' => MENU_CALLBACK,
'file' => 'forena.common.inc',
);
$items['report_doc/%'] = array(
'page callback' => 'forena_report',
'page arguments' => array(
1,
),
'access arguments' => array(
'access content',
),
'type' => MENU_CALLBACK,
'file' => 'forena.common.inc',
);
$items['reports/%/edit'] = array(
'title' => 'Edit',
'page callback' => 'forena_report_preview',
'page arguments' => array(
1,
),
'access arguments' => array(
'design any report',
),
'description' => 'Edit the layout of your report',
'type' => MENU_CALLBACK,
'file' => 'forena.report.inc',
);
if (module_exists('locale')) {
$items['reports/%/translations'] = array(
'page callback' => 'forena_report_translations',
'page arguments' => array(
1,
),
'title' => 'Translate',
'file' => 'forena.report.inc',
'access arguments' => array(
'design any report',
),
'type' => MENU_CALLBACK,
);
}
$items['reports/%/edit/parameters'] = array(
'page callback' => 'drupal_get_form',
'page arguments' => array(
'forena_report_parameters_form',
1,
),
'title' => 'Parameters',
'file' => 'forena.report.inc',
'access arguments' => array(
'design any report',
),
'type' => MENU_LOCAL_TASK,
);
$items['reports/%/edit/edit-parameter'] = array(
'page callback' => 'drupal_get_form',
'page arguments' => array(
'forena_report_parameter_config_form',
1,
),
'title' => 'Edit Parameter',
'file' => 'forena.report.inc',
'access arguments' => array(
'design any report',
),
'type' => MENU_CALLBACK,
);
$items['reports/%/edit/add-parameter'] = array(
'page callback' => 'drupal_get_form',
'page arguments' => array(
'forena_report_add_parameter_form',
1,
),
'file' => 'forena.report.inc',
'title' => 'Parameters',
'access arguments' => array(
'design any report',
),
'type' => MENU_CALLBACK,
);
$items['reports/%/edit/general'] = array(
'title' => 'General',
'page callback' => 'drupal_get_form',
'page arguments' => array(
'forena_report_general_form',
1,
),
'access arguments' => array(
'design any report',
),
'description' => 'General Report Properties',
'type' => MENU_LOCAL_TASK,
'weight' => -1,
'file' => 'forena.report.inc',
);
$items['reports/%/edit/layout'] = array(
'title' => 'Layout',
'page callback' => 'drupal_get_form',
'page arguments' => array(
'forena_report_layout_form',
1,
),
'access arguments' => array(
'design any report',
),
'description' => 'Edit the layout of your report',
'type' => MENU_LOCAL_TASK,
'file' => 'forena.report.inc',
);
$items['reports/%/edit/edit-data/%/%'] = array(
'title' => 'Edit Block',
'file' => 'forena.report.inc',
'page callback' => 'drupal_get_form',
'page arguments' => array(
'forena_report_data_block_form',
1,
3,
4,
5,
'edit-data',
),
'access arguments' => array(
'design any report',
),
'description' => 'Add a data block to your report',
'type' => MENU_CALLBACK,
);
$items['reports/%/edit/edit-field/%'] = array(
'title' => 'Edit Block',
'file' => 'forena.report.inc',
'page callback' => 'drupal_get_form',
'page arguments' => array(
'forena_report_field_form',
1,
4,
),
'access arguments' => array(
'design any report',
),
'description' => 'Add a data block to your report',
'type' => MENU_CALLBACK,
);
$items['reports/%/edit/select-data/%'] = array(
'title' => 'Select Data Block',
'file' => 'forena.report.inc',
'page callback' => 'forena_select_block_list',
'page arguments' => array(
1,
4,
),
'access arguments' => array(
'design any report',
),
'description' => 'Select the data blcok to add',
'type' => MENU_CALLBACK,
);
$items['reports/%/edit/select-data/%/%'] = array(
'title' => 'Select Data Block',
'file' => 'forena.report.inc',
'page callback' => 'forena_select_block_list',
'page arguments' => array(
1,
4,
5,
),
'access arguments' => array(
'design any report',
),
'description' => 'Select the data blcok to add',
'type' => MENU_CALLBACK,
);
$items['reports/%/edit/preview-data/%/%'] = array(
'title' => 'Preview Data Block',
'file' => 'forena.report.inc',
'page callback' => 'forena_report_block_preview',
'page arguments' => array(
1,
4,
5,
),
'access arguments' => array(
'design any report',
),
'description' => 'Select the data block to add',
'type' => MENU_CALLBACK,
);
$items['reports/%/edit/preview-data/%/%/%'] = array(
'title' => 'Preview Data Block',
'file' => 'forena.report.inc',
'page callback' => 'forena_report_block_preview',
'page arguments' => array(
1,
4,
5,
6,
),
'access arguments' => array(
'design any report',
),
'description' => 'Select the data block to add',
'type' => MENU_CALLBACK,
);
$items['reports/%/edit/add-data/%'] = array(
'title' => 'Data',
'file' => 'forena.report.inc',
'page callback' => 'drupal_get_form',
'page arguments' => array(
'forena_report_data_block_form',
1,
3,
4,
),
'access arguments' => array(
'design any report',
),
'description' => 'Edit a data block on the report. ',
'type' => MENU_CALLBACK,
);
$items['reports/%/edit/add-data/%/%'] = array(
'title' => 'Add Data',
'file' => 'forena.report.inc',
'page callback' => 'drupal_get_form',
'page arguments' => array(
'forena_report_data_block_form',
1,
3,
4,
5,
),
'access arguments' => array(
'design any report',
),
'description' => 'Edit a data block on the report. ',
'type' => MENU_CALLBACK,
);
$items['reports/%/edit/prepend-data/%/%'] = array(
'title' => 'Add Data',
'file' => 'forena.report.inc',
'page callback' => 'drupal_get_form',
'page arguments' => array(
'forena_report_data_block_form',
1,
3,
4,
5,
),
'access arguments' => array(
'design any report',
),
'description' => 'Edit a data block on the report. ',
'type' => MENU_CALLBACK,
);
$items['reports/%/edit/delete-data/%'] = array(
'title' => 'Delete Data',
'file' => 'forena.report.inc',
'page callback' => 'drupal_get_form',
'page arguments' => array(
'forena_report_delete_confirm',
1,
4,
),
'access arguments' => array(
'design any report',
),
'description' => 'Delete this form',
'type' => MENU_CALLBACK,
);
$items['reports/%/edit/format'] = array(
'title' => 'Document Types',
'page callback' => 'drupal_get_form',
'page arguments' => array(
'forena_report_format_form',
1,
),
'access arguments' => array(
'design any report',
),
'file' => 'forena.report.inc',
'description' => 'Document Options',
'type' => MENU_LOCAL_TASK,
);
$items['reports/%/delete'] = array(
'title' => 'Remove Custom Report',
'page callback' => 'drupal_get_form',
'page arguments' => array(
'forena_report_delete_form',
1,
),
'access arguments' => array(
'delete report',
),
'type' => MENU_CALLBACK,
'file' => 'forena.report.inc',
);
$items['reports/add'] = array(
'title' => 'Create Report',
'page callback' => 'drupal_get_form',
'page arguments' => array(
'forena_add_report_form',
),
'access arguments' => array(
'create any report',
),
'description' => 'Create a new report',
'file' => 'forena.report.inc',
'type' => MENU_SUGGESTED_ITEM,
);
$items['reports/%/add'] = array(
'title' => 'Create Report',
'page callback' => 'drupal_get_form',
'page arguments' => array(
'forena_add_report_form',
1,
),
'access arguments' => array(
'create any report',
),
'description' => 'Create a new report from a template',
'file' => 'forena.admin.inc',
'type' => MENU_CALLBACK,
);
$items['reports/%/translate'] = array(
'title' => 'Translate Report',
'page callback' => 'drupal_get_form',
'page arguments' => array(
'forena_create_trans_form',
1,
),
'access arguments' => array(
'create any report',
),
'description' => 'Create a new report translation',
'file' => 'forena.admin.inc',
'type' => MENU_CALLBACK,
);
$items['forena'] = array(
'page callback' => 'forena_user_reports',
'page arguments' => array(),
'title' => 'My Reports',
'access arguments' => array(
'list reports',
),
'type' => MENU_CALLBACK,
);
$items['reports'] = array(
'page callback' => 'forena_user_reports',
'page arguments' => array(),
'title' => 'My Reports',
'access arguments' => array(
'list reports',
),
'type' => MENU_NORMAL_ITEM,
);
$items['forena/xml/%'] = array(
'page callback' => 'forena_block_xml',
'page arguments' => array(
2,
),
'access arguments' => array(
'access forena block xml',
),
'type' => MENU_CALLBACK,
);
$items['forena/json/%'] = array(
'page callback' => 'forena_json',
'page arguments' => array(
2,
),
'access arguments' => array(
'access forena block xml',
),
'type' => MENU_CALLBACK,
);
$items['forena/fields/format/autocomplete'] = array(
'page callback' => 'forena_fields_format_autocomplete',
'access callback' => TRUE,
'type' => MENU_CALLBACK,
);
$items['forena/data_block/autocomplete'] = array(
'page callback' => 'forena_data_block_autocomplete',
'access callback' => TRUE,
'type' => MENU_CALLBACK,
);
$items['forena/reports/autocomplete'] = array(
'page callback' => 'forena_reports_autocomplete',
'access callback' => TRUE,
'type' => MENU_CALLBACK,
);
$items['forena/categories/autocomplete'] = array(
'page callback' => 'forena_categories_autocomplete',
'access callback' => TRUE,
'type' => MENU_CALLBACK,
);
return $items;
}
function forena_admin_paths_alter(&$paths) {
$paths['reports/*/*'] = TRUE;
$paths['reports/*/nojs'] = FALSE;
$paths['reports/*/ajax'] = FALSE;
$paths['reports/*/view'] = FALSE;
$paths['reports/*/edit'] = FALSE;
$paths['reports/add'] = TRUE;
}
function forena_library_file($library) {
$libraries = array(
'dataTables' => 'dataTables/media/js/jquery.dataTables.min.js',
'mpdf' => 'mpdf/mpdf.php',
'SVGGraph' => 'SVGGraph/SVGGraph.php',
'prince' => 'prince/prince.php',
);
$path = isset($libraries[$library]) && file_exists('sites/all/libraries/' . $libraries[$library]) ? 'sites/all/libraries/' . $libraries[$library] : '';
return $path;
}
function forena_block_info() {
$blocks['forena_reports'] = array(
'info' => t('My reports'),
'status' => 1,
'region' => 'sidebar_first',
'visibility' => 1,
'pages' => 'forena',
);
return $blocks;
}
function forena_block_view($delta = 0) {
require_once 'forena.common.inc';
switch ($delta) {
case 'forena_reports':
$block = array(
'subject' => 'My Reports',
'content' => forena_my_reports_block(),
);
break;
}
return $block;
}
function forena_categories_autocomplete($string = '') {
require_once 'forena.admin.inc';
$categories = @forena_get_categories($string);
print drupal_json_output($categories);
}
function forena_data_block_autocomplete() {
require_once 'forena.admin.inc';
$args = func_get_args();
$search = implode('/', $args);
if (strlen($search) < 2) {
$search .= '*';
}
else {
$search = "*{$search}*";
}
$data_blocks = Frx::DataFile()
->userBlocks($search);
if ($data_blocks) {
$temp = array_keys($data_blocks);
$data_blocks = array_combine($temp, $temp);
}
else {
$data_blocks = array();
}
print drupal_json_output($data_blocks);
}
function forena_reports_autocomplete($string = '', $string2 = '') {
global $language;
$reports = '';
$link = '';
if ($string2) {
$mode = $string;
$string = $string2;
}
$string = '*' . $string . '*';
$result = Frx::File()
->allReports();
foreach ($result as $name => $row) {
if (drupal_match_path($name, $string)) {
$reports[$name] = $name . ' - ' . $row->cache['title'];
}
}
return drupal_json_output($reports);
}
function forena_xml($block_name, $parms = array()) {
include_once 'forena.common.inc';
drupal_alter('forena_parameters', $block_name, $parms);
Frx::Data()
->push($parms, 'parm');
return Frx::DataManager()
->data($block_name);
}
function forena_data($block_name, $parms = array(), $raw_mode = TRUE) {
include_once 'forena.common.inc';
drupal_alter('forena_parameters', $block_name, $parms);
Frx::Data()
->push($parms, 'parm');
$data = Frx::DataManager()
->data($block_name, $raw_mode);
Frx::Data()
->pop();
return $data;
}
function forena_json($block_name, $parms = NULL) {
$block_name = str_replace('.', '/', $block_name);
if ($parms === NULL) {
$parms = array_merge($_GET, $_POST);
unset($parms['q']);
}
$data = forena_data($block_name, $parms);
$ret = array();
if ($data) {
foreach ($data as $row) {
$ret[] = $row;
}
}
drupal_json_output($ret);
}
function forena_block_xml($block_name = '', $parms = NULL) {
$block_name = str_replace('.', '/', $block_name);
if ($parms === NULL) {
$parms = array_merge($_GET, $_POST);
unset($parms['q']);
}
$data = forena_data($block_name, $parms, FALSE);
if (is_object($data) && method_exists($data, 'asXML')) {
header('Content-Type: text/xml');
print $data
->asXML();
}
}
function forena_fields_format_autocomplete($string = '') {
require_once 'forena.common.inc';
$matches = array();
$formats = @Frx::supportedFormats();
if ($string == "*") {
$matches = $formats;
print drupal_json_output($matches);
return;
}
if ($formats && $string) {
foreach ($formats as $name => $value) {
if (strpos(strtolower($name), strtolower($string)) !== FALSE || strpos(strtolower($value), strtolower($string)) !== FALSE) {
$matches[$name] = $value;
}
}
}
print drupal_json_output($matches);
}
function forena_parameters_report() {
require_once 'forena.admin.inc';
$m = Frx::Menu();
$name = $m->name;
$filename = $m->filename;
$format = $m->format;
$report = forena_get_report($name);
if ($report) {
$r = forena_report_object();
$o = drupal_get_form('forena_parameters_form');
return $o;
}
else {
drupal_not_found();
}
}
function forena_parameter_form($formid, &$form_state, $parameters, $attributes = array()) {
$parms = $_GET;
$menu_parms = array();
$desc = array();
if (!isset($form_state['storage'])) {
$desc = Frx::Data()
->getContext('report');
$form_state['storage']['desc'] = $desc;
$desc = $form_state['storage']['desc'];
$menu_parms = Frx::Data()
->getContext('menu-parms');
if ($menu_parms) {
$form_state['storage']['menu-parms'] = $menu_parms;
}
}
else {
extract($form_state['storage']);
}
$report_name = @$desc['name'];
$collapse = isset($attributes['collapsed']) ? $attributes['collapsed'] : FALSE;
if (isset($form_state['values'])) {
$collapse = FALSE;
$parms = array_merge($parms, $form_state['values']['params']);
if (isset($form_state['storage']['menu-parms'])) {
$menu_parms = $form_state['storage']['menu-parms'];
$parms = array_merge($menu_parms, $parms);
}
drupal_alter('forena_parameters', $report_name, $parms);
Frx::Data()
->push($parms, 'parm');
}
$template = @$attributes['template'];
$collapsible = isset($attributes['collapsible']) ? $attributes['collapsible'] : TRUE;
$title = isset($attributes['title']) ? $attributes['title'] : t('Parameters');
$submit_value = isset($attributes['submit']) ? $attributes['submit'] : t('Submit');
unset($parms['q']);
$form = array();
if ($parameters) {
if ($parameters) {
$form['params'] = array(
'#tree' => TRUE,
'#title' => $title,
'#type' => 'fieldset',
'#collapsible' => $collapsible,
'#collapsed' => $collapse,
'#prefix' => '<div id="parameters-wrapper">',
'#suffix' => '</div>',
);
foreach ($parameters as $node) {
$add_null = FALSE;
$list = array();
$disabled = FALSE;
$label = @(string) $node['label'];
$id = @(string) $node['id'];
$data_source = @(string) $node['data_source'];
$data_field = @(string) $node['data_field'];
$class = @(string) $node['class'];
$type = @(string) $node['type'];
$option_str = @(string) $node['options'];
$options = array();
if ($option_str) {
parse_str($option_str, $options);
}
if (isset($parms[$id])) {
$value = $parms[$id];
$multi_value = (array) $parms[$id];
}
else {
$value = @(string) $node['default'];
$multi_value = array();
if (strpos($value, '|') !== FALSE) {
$multi_value = explode('|', $value);
}
}
$desc = @(string) $node['desc'];
$label_field = @(string) $node['label_field'];
@(strcmp((string) $node['require'], "1") == 0) ? $required = TRUE : ($required = FALSE);
$ctl_attrs = array();
if ($data_source) {
$list = Frx::DataManager()
->dataBlockParams($data_source, $data_field, $label_field);
if (!$required && $add_null) {
$list = array(
'' => '',
) + $list;
}
}
$multiselect = FALSE;
$ajax = FALSE;
$add_null = FALSE;
switch ($type) {
case 'multiselect':
$type = 'select';
$multiselect = TRUE;
$value = $multi_value;
break;
case 'multiselectajax':
$type = 'select';
$multiselect = TRUE;
$value = $multi_value;
$ajax = TRUE;
break;
case 'checkboxes':
$value = $multi_value;
break;
case 'selectajax':
$ajax = TRUE;
$type = 'select';
$add_null = TRUE;
break;
case 'select':
$add_null = TRUE;
break;
case 'date_text':
case 'date_select':
case 'date_popup':
$options['date_format'] = @$options['date_format'] ? $options['date_format'] : 'Y-m-d';
$ctl_attrs['#date_format'] = $options['date_format'];
if ($value) {
$datetime = @strtotime($value);
if ($datetime) {
$value = date('Y-m-d h:i', $datetime);
}
}
$ctl_attrs['#forena_date_format'] = @$options['date_parm_format'] ? $options['date_parm_format'] : 'Y-m-d';
if (@$options['date_year_range']) {
$ctl_attrs['#date_year_range'] = $options['date_year_range'];
}
if (@$options['date_label_position']) {
$ctl_attrs['#date_label_position'] = $options['date_label_position'];
}
$list = array();
break;
case 'checkbox':
if (@$option_str['return_value']) {
$ctl_attrs['#return_value'] = $options['return_value'];
}
$list = array();
break;
case 'radios':
break;
case 'hidden':
$list = array();
break;
default:
$type = 'textfield';
$list = array();
}
if (isset($menu_parms[$id]) && $type != 'hidden') {
$disabled = TRUE;
}
$form['params'][$id] = array(
'#type' => $type,
'#title' => $label ? t($label) : t($id),
'#default_value' => $value,
'#disabled' => $disabled,
'#required' => $required,
'#description' => t($desc),
);
if (isset($option['size'])) {
$forms['params'][$id]['#size'] = @$options['size'];
}
$form['params'][$id] = array_merge($form['params'][$id], $ctl_attrs);
if ($type == 'item') {
$form['params'][$id]['#markup'] = $value;
}
if ($type == 'hidden') {
$form['params'][$id]['#value'] = $value;
}
if ($class) {
$form['params'][$id]['#attributes'] = array(
'class' => @explode(' ', $class),
);
}
if ($list || $type == 'select' || $type == 'radios') {
if ($add_null) {
$prompt = @$options['prompt'];
if (!$prompt) {
$prompt = $required ? '-' . t('select') . '-' : '-' . t('none') . '-';
}
$form['params'][$id]['#empty_option'] = $prompt;
}
$form['params'][$id]['#options'] = $list;
$form['params'][$id]['#multiple'] = $multiselect;
}
if ($ajax) {
$form['params'][$id]['#ajax'] = array(
'callback' => 'forena_parameters_callback',
'wrapper' => 'parameters-wrapper',
);
}
}
if ($template) {
$form['params']['#forena-template'] = $template;
$form['params']['#theme'] = 'forena_fieldset_template';
_forena_set_inline_theme($form['params']);
}
$form['params']['submit'] = array(
'#type' => 'submit',
'#value' => $submit_value,
);
}
return $form;
}
}
function forena_parameter_form_submit($form, &$form_state) {
$values = $form_state['values'];
unset($values['params']['submit']);
if (isset($values['params'])) {
foreach ($values['params'] as $key => $value) {
$ctl = $form['params'][$key];
switch ($ctl['#type']) {
case 'date_popup':
case 'date_select':
case 'date_text':
$datetime = @strtotime($value);
if ($datetime) {
$value = $values['params'][$key] = date($ctl['#forena_date_format'], $datetime);
}
break;
}
if (is_array($value)) {
$values['params'][$key] = array();
foreach ($value as $k => $val) {
if ($val) {
$values['params'][$key][] = $val;
}
}
}
else {
if (strpos($value, '|') !== FALSE) {
$values['params'][$key] = explode('|', $value);
}
elseif ($value === '' || $value === NULL) {
unset($values['params'][$key]);
}
}
}
}
$desc = $form_state['storage']['desc'];
if ($desc['always_redirect']) {
$path = $desc['link'];
}
else {
$path = isset($desc['q']) ? $desc['q'] : '';
}
if (!$path) {
$path = $_GET['q'];
}
if ($path) {
$form_state['redirect'] = array(
$path,
array(
'query' => @$values['params'],
),
);
}
}
function forena_parameters_callback($form, &$form_state) {
return $form['params'];
}
function forena_permission() {
$perms = array(
'administer forena reports' => array(
'title' => t('Administer Forena Reports'),
),
'list reports' => array(
'title' => t('List reports'),
),
'create any report' => array(
'title' => t('Create a report'),
),
'design any report' => array(
'title' => t('Design reports'),
),
'delete report' => array(
'title' => t('Delete reports'),
),
'perform email merge' => array(
'title' => t('Peform email merge'),
),
'access forena block xml' => array(
'title' => t('Access data from data blocks directly'),
'description' => t('Useful for ajax calls to data blocks'),
),
);
foreach (Frx::DataManager()->repositories as $repos => $conf) {
$name = !empty($conf['title']) ? $conf['title'] : $repos;
$perms['access ' . $repos . ' data'] = array(
'title' => 'Access ' . $name . ' Data',
);
}
return $perms;
}
function forena_user_reports($category = '') {
require_once 'forena.common.inc';
$output = '';
$reports = forena_get_user_reports($category);
if (!$reports) {
$output = 'No Reports Found';
}
$links = '';
foreach ($reports as $category => $reports) {
$links .= '<li><a href="#' . urlencode($category) . '">' . $category . '</a></li> ';
$output .= '<h3 id="' . urlencode($category) . '">' . $category . '</h3>';
$output .= '<ul>';
foreach ($reports as $r) {
$output .= '<li>' . l($r['title'], 'reports/' . str_replace('/', '.', $r['report_name'])) . '</li>';
}
$output .= '</ul>';
}
return $output;
}
function forena_include_data_tables() {
static $init = FALSE;
if (!$init) {
$init = TRUE;
$lib = 'sites/all/libraries/dataTables/media/js/jquery.dataTables.min.js';
if (file_exists($lib)) {
drupal_add_js($lib);
}
$lib = 'sites/all/libraries/FixedColumns/media/js/FixedColumns.min.js';
if (file_exists($lib)) {
drupal_add_js($lib);
}
$lib = 'sites/all/libraries/FixedHeader/js/FixedHeader.min.js';
if (file_exists($lib)) {
drupal_add_js($lib);
}
}
}
function forena_report_ajax_callback($report_name) {
$content = forena_report("{$report_name}");
$title = Frx::Editor()->frxReport->title;
if (is_callable('ctools_include')) {
ctools_include('modal');
ctools_modal_render($title, $content['content']['#markup']);
}
else {
drupal_set_title($title);
return $content;
}
}
function forena_report($name_in, $parms = NULL, $print = TRUE, $filename = '') {
$in_block = FALSE;
if ($print === 'block') {
$in_block = TRUE;
}
require_once 'forena.common.inc';
$desc = Frx::Menu()
->parseURL($name_in);
$time = @new DateTime();
$desc['time'] = date_format($time, 'Y-m-d H:i:s');
$desc['basepath'] = base_path();
$desc['path'] = $desc['basepath'] . Frx::File()
->directory(Frx::File()
->path($desc['filename'], TRUE));
$path_info = Frx::File()
->pathinfo($desc['filename']);
$desc['dir'] = base_path() . $path_info['dirname'];
$desc['theme'] = $desc['basepath'] . drupal_get_path('theme', $GLOBALS['theme']);
$desc['print'] = $print;
$desc['q'] = $_GET['q'];
$desc['always_redirect'] = $in_block;
if (!$desc['exists']) {
watchdog('error', 'Report %s not found', array(
'%s' => $name_in,
), WATCHDOG_ERROR);
if ($print) {
drupal_not_found();
exit;
}
return '';
}
Frx::Data()
->setContext('cookie', $_COOKIE);
Frx::Data()
->setContext('report', $desc);
$report_name = $desc['name'];
$o = Frx::Editor($name_in, FALSE);
$o->alwaysRedirect = $in_block;
$content = $o
->report($parms, $print, FALSE, $filename);
$m_path = drupal_get_path('module', 'forena');
if ($content) {
if ($print) {
drupal_add_js($m_path . '/forena.js');
}
$forena_js = array();
$forena_js['form'] = preg_replace('/[^\\w\\-]+/u', '_', Frx::Skin()->name);
$forena_js['report'] = preg_replace('/[^\\w\\-]+/u', '_', $name_in);
if ($print) {
drupal_add_js(array(
'forena' => $forena_js,
), 'setting');
}
}
if (!$print && is_array($content)) {
return drupal_render($content['content']);
}
return $content;
}
function forena_report_include($report_name, $parms = array()) {
require_once 'forena.common.inc';
$desc = Frx::Menu()
->parseURL($report_name);
$name = $desc['name'];
$r = Frx::Editor()
->loadReport($name, $parms);
if (!$r || !$r->rpt_xml) {
return '';
}
$r
->processParameters();
$format = $desc['format'];
$r
->render($format, FALSE);
return $r->html;
}
function forena_report_menu_callback() {
$args = func_get_args();
$path = array_shift($args);
$report_name = array_shift($args);
$parms = $_GET;
unset($parms['q']);
$menu_parms = array();
$tokens = Frx::Menu()
->tokens($path);
if ($args && $tokens) {
foreach ($args as $i => $value) {
@($menu_parms[$tokens[$i]] = $value);
}
}
Frx::Data()
->setContext('menu-parms', $menu_parms);
$parms = array_merge($parms, $menu_parms);
$output = forena_report($report_name, $parms);
if ($output) {
return $output;
}
}
function forena_check_all_access($checks) {
$access = FALSE;
if ($checks) {
foreach ($checks as $provider => $callbacks) {
if (user_access('access ' . $provider . ' data')) {
foreach ($callbacks as $callback => $args) {
if ($callback) {
foreach ($args as $arg) {
if (function_exists($callback) && $arg) {
$a = $callback($arg);
if ($a) {
$access = TRUE;
}
}
else {
$access = TRUE;
}
}
}
else {
$access = TRUE;
}
}
}
}
}
return $access;
}
function forena_report_title_callback($report_name, $use_menu_title = TRUE) {
$title = '';
$info = Frx::File()
->getReportCacheInfo($report_name);
if ($info) {
$title = $use_menu_title && $info && isset($info->cache['menu']['title']) ? $info->cache['menu']['title'] : $info->cache['title'];
}
return $title;
}
function forena_forena_plugins() {
$plugins['FrxPDO'] = array(
'parent' => 'FrxDataSource',
'class' => '\\Drupal\\forena\\Driver\\FrxPDO',
);
$plugins['FrxOracle'] = array(
'parent' => 'FrxDataSource',
'class' => '\\Drupal\\forena\\Driver\\FrxOracle',
);
$plugins['FrxDrupal'] = array(
'parent' => 'FrxDataSource',
'class' => '\\Drupal\\forena\\Driver\\FrxDrupal',
);
$plugins['FrxFiles'] = array(
'parent' => 'FrxDataSource',
'class' => '\\Drupal\\forena\\Driver\\FrxFiles',
);
$plugins['FrxPostgres'] = array(
'class' => '\\Drupal\\forena\\Driver\\FrxPostgres',
'parent' => 'FrxDataSource',
);
$plugins['FrxMSSQL'] = array(
'parent' => 'FrxDataSource',
'class' => '\\Drupal\\forena\\Driver\\FrxMSSQL',
);
$plugins['Report'] = array(
'parent' => 'FrxContext',
'class' => '\\Drupal\\forena\\Context\\FrxReportContext',
);
return $plugins;
}
function forena_forena_document_types() {
$items['web'] = array(
'class' => '\\Drupal\\forena\\DocumentFormats\\DrupalPage',
'title' => t('Themed Drupal Page'),
);
$items['csv'] = array(
'class' => '\\Drupal\\forena\\DocumentFormats\\CSVDocument',
'title' => t('Comma separated values'),
);
$items['email'] = array(
'class' => '\\Drupal\\forena\\DocumentFormats\\EmailMerge',
'title' => t('Email Merge Document'),
);
$items['html'] = array(
'class' => '\\Drupal\\forena\\DocumentFormats\\HtmlDocument',
'title' => t('Unthemed HTML'),
);
$items['svg'] = array(
'class' => '\\Drupal\\forena\\DocumentFormats\\SVGDocument',
'title' => t('SVG Document'),
);
$items['doc'] = array(
'class' => '\\Drupal\\forena\\DocumentFormats\\WordDocument',
'title' => t('MS Word Document format'),
);
$items['xls'] = array(
'class' => '\\Drupal\\forena\\DocumentFormats\\ExcelDocument',
'title' => t('Excel Document'),
);
$items['xml'] = array(
'class' => '\\Drupal\\forena\\DocumentFormats\\XMLDocument',
'title' => t('XML Document'),
);
return $items;
}
function forena_forena_controls() {
$controls['RendererBase'] = array(
'class' => '\\Drupal\\forena\\Renderer\\RendererBase',
);
$controls['ForenaFormatter'] = array(
'class' => 'Drupal\\forena\\Format\\ForenaFormatter',
);
$controls['FrxSection'] = array(
'class' => '\\Drupal\\forena\\Renderer\\FrxSection',
);
$controls['FrxCrosstab'] = array(
'class' => '\\Drupal\\forena\\Renderer\\FrxCrosstab',
);
$controls['FrxEmailMerge'] = array(
'class' => '\\Drupal\\forena\\Renderer\\FrxEmailMerge',
);
$controls['FrxFieldTable'] = array(
'class' => '\\Drupal\\forena\\RendererFrxFieldTable',
);
$controls['FrxTable'] = array(
'class' => '\\Drupal\\forena\\Renderer\\FrxTable',
);
$controls['FrxMergeDocument'] = array(
'class' => '\\Drupal\\forena\\Renderer\\FrxMergeDocument',
);
$controls['FrxSource'] = array(
'class' => '\\Drupal\\forena\\Renderer\\FrxSource',
);
$controls['FrxXML'] = array(
'class' => '\\Drupal\\forena\\Renderer\\FrxXML',
);
$controls['FrxInclude'] = array(
'class' => '\\Drupal\\forena\\Renderer\\FrxInclude',
);
$controls['FrxMyReports'] = array(
'class' => '\\Drupal\\forena\\Renderer\\FrxMyReports',
);
$controls['FrxParameterForm'] = array(
'class' => '\\Drupal\\forena\\Renderer\\FrxParameterForm',
);
$controls['FrxTitle'] = array(
'class' => '\\Drupal\\forena\\Renderer\\FrxTitle',
);
if (forena_library_file('SVGGraph')) {
$controls['FrxSVGGraph'] = array(
'class' => '\\Drupal\\forena\\Renderer\\FrxSVGGraph',
);
}
return $controls;
}
function forena_forena_report_directory() {
return drupal_get_path('module', 'forena') . '/reports';
}
function forena_report_path() {
return Frx::File()->dir;
}
function forena_current_user_uid() {
return forena_current_user_id();
}
function forena_current_user_id() {
global $user;
return $user->uid;
}
function forena_current_user_name() {
global $user;
if (isset($user->name)) {
return $user->name;
}
}
function forena_current_user_email() {
global $user;
if (isset($user->name)) {
return $user->mail;
}
}
function forena_filter_info() {
$filters['forena_report'] = array(
'title' => t('Embed Forena Reports'),
'description' => t('Allows you to embed a report in a text'),
'process callback' => '_forena_filter_process',
'cache' => FALSE,
);
return $filters;
}
function _forena_filter_process($text = '') {
require_once 'forena.admin.inc';
global $language;
$in_parms = Frx::Data()
->getContext('parm');
if (!$in_parms) {
$parms = $_GET;
}
if (preg_match_all("/\\[report?:?([^\\]]+)\\]/i", $text, $match)) {
foreach ($match[1] as $idx => $value) {
$parms = $in_parms;
@(list($report_name, $parmsStr) = explode(':', $value));
$pairs = explode(',', $parmsStr);
if ($pairs) {
foreach ($pairs as $pair) {
@(list($key, $value) = explode('=', $pair));
if ($key) {
$parms[$key] = $value;
}
}
}
$output = forena_report($report_name, $parms, FALSE);
$find[] = $match[0][$idx];
$replace[] = $output;
}
return str_replace($find, $replace, $text);
}
return $text;
}
function forena_mail($key, &$message, $parms) {
switch ($key) {
case 'mailmerge':
$message['subject'] = $parms['subject'];
$body = $parms['body'];
$message['body'][] = $body;
if (isset($parms['headers'])) {
$message['headers'] += $parms['headers'];
}
$htmlmail = FALSE;
break;
}
}
function _forena_verify_directory($fullpath, $recursive = FALSE) {
static $path = '';
$success = TRUE;
if (!$recursive) {
$path = forena_report_path();
if (!is_writable($path)) {
drupal_set_message(t('Report directory %s is not modifiable', array(
'%s' => $path,
)), 'error', FALSE);
return FALSE;
}
}
@(list($dir, $file) = explode('/', $fullpath, 2));
$path .= '/' . $dir;
if (!file_exists($path) && $file) {
@mkdir($path);
if (!@is_writable($path)) {
drupal_set_message(t('Error creating directory %path', array(
'%path' => $path,
)), 'error');
return FALSE;
}
}
if ($file && strpos($file, '/')) {
_forena_verify_directory($file, TRUE);
}
return TRUE;
}
function _forena_revert_reports($subdir = '') {
static $cnt = 0;
$cnt++;
if ($cnt > 100) {
return 0;
}
$i = 0;
$src_dir = rtrim(Frx::File()->dir, '/');
if ($subdir) {
$src_dir .= '/' . $subdir;
}
$d = dir($src_dir);
while ($d && false !== ($rpt_file = $d
->read())) {
$src_file = $d->path . '/' . $rpt_file;
if (strpos($rpt_file, '.') !== 0 && is_file($src_file)) {
$filename = $subdir ? "{$subdir}/{$rpt_file}" : $rpt_file;
$i += Frx::File()
->revert($filename);
}
else {
if (strpos($rpt_file, '.') !== 0) {
$dir = $subdir ? $subdir . '/' . $rpt_file : $rpt_file;
$i += _forena_revert_reports($dir);
}
}
}
if ($d) {
$d
->close();
}
return $i;
}
function forena_sync_reports($copy_reports = FALSE) {
if ($copy_reports) {
$i = _forena_revert_reports();
if ($i > 0) {
drupal_set_message($i . ' reports reverted');
}
}
}
function forena_theme() {
return array(
'forena_web_report' => array(
'variables' => array(
'doc_types' => NULL,
'parameters' => NULL,
'content' => NULL,
),
),
'forena_inline_form_element' => array(
'render element' => 'element',
'file' => 'forena.common.inc',
),
'forena_inline_field' => array(
'render element' => 'field',
'file' => 'forena.common.inc',
),
'forena_fieldset_template' => array(
'render element' => 'fieldset',
'file' => 'forena.common.inc',
),
'forena_data_table' => array(
'file' => 'forena.common.inc',
'variables' => array(
'header' => NULL,
'data' => NULL,
),
),
'forena_report_parameters_form' => array(
'file' => 'forena.report.inc',
'render element' => 'form',
),
'forena_element_draggable' => array(
'file' => 'forena.report.inc',
'render element' => 'element',
),
);
}
function theme_forena_web_report($variables) {
$output = '';
if (@$variables['parameters']) {
$output .= '<div id="forena-parameters">' . $variables['parameters'] . '</div>';
}
if (@$variables['doc_links']) {
$output .= "<div id='forena-doc-links'>" . $variables['doc_links'] . '</div>';
}
$output .= '<div class="forena-report">' . $variables['content'] . '</div>';
return $output;
}
function forena_views_api() {
return array(
'api' => 3,
'path' => drupal_get_path('module', 'forena'),
'template path' => drupal_get_path('module', 'forena'),
);
}
function forena_feeds_plugins() {
module_load_include('inc', 'forena', 'feeds/forena_feeds');
return _forena_feeds_plugins();
}
function forena_bean_types_api_info() {
return array(
'api' => 4,
);
}
function forena_bean_types() {
$plugins = array();
$plugin_path = drupal_get_path('module', 'forena') . '/bean';
$plugins['forena'] = array(
'label' => t('Forena report'),
'description' => t('Display a report.'),
'handler' => array(
'class' => 'FrxBean',
'parent' => 'bean',
'path' => $plugin_path,
'file' => 'FrxBean.inc',
),
'path' => $plugin_path,
'file' => 'FrxBean.inc',
);
return $plugins;
}
function forena_form_reflector($formid, &$form_state, $form) {
return $form;
}
function forena_requirements($phase) {
$requirements = array();
switch ($phase) {
case 'runtime':
$writeable = is_writable(Frx::File()->dir);
$direxists = file_exists(Frx::File()->dir);
$RptDirConfig = t('which is set in the <a href="@report-dir-config">report repository configuration</a>', array(
'@report-dir-config' => url('admin/config/content/forena'),
));
if (!$direxists) {
$reqsDesciption = t('The mandatory report directory, ') . $RptDirConfig . t(', has not been created yet.');
$requirements['forena_direxists'] = array(
'title' => 'Forena Report Directory',
'value' => Frx::File()->dir,
'severity' => REQUIREMENT_ERROR,
'description' => $reqsDesciption,
);
}
else {
$writeable = is_writable(Frx::File()->dir);
if (!$writeable) {
$reqsDesciption = t('The directory, ') . $RptDirConfig . t(', must be writable by the web user in order to create custom reports.');
$requirements['forena_writable'] = array(
'title' => 'Forena Report Directory',
'value' => Frx::File()->dir,
'severity' => REQUIREMENT_ERROR,
'description' => $reqsDesciption,
);
}
else {
$requirements['forena_writable'] = array(
'title' => 'Forena Report Directory',
'value' => Frx::File()->dir,
'severity' => REQUIREMENT_OK,
);
}
}
$req = array(
'severity' => REQUIREMENT_INFO,
'requirement',
);
$libraries = array(
'dataTables',
'mpdf',
'prince',
'SVGGraph',
);
foreach ($libraries as $lib) {
$requirements['forena_' . $lib] = $req;
$requirements['forena_' . $lib]['title'] = "Forena {$lib} support";
$usinglib = t('sites/all/libraries/') . $lib . t(' (Enabled)');
$missinglib = $lib . t(' library missing in sites/all/libraries/') . t(' (Not Enabled)');
$requirements['forena_' . $lib]['value'] = forena_library_file($lib) ? $usinglib : $missinglib;
$requirements['forena_' . $lib]['severity'] = forena_library_file($lib) ? REQUIREMENT_OK : REQUIREMENT_INFO;
}
if (!module_exists('forena_pdf')) {
unset($requirements['forena_prince']);
unset($requirements['forena_mpdf']);
}
break;
}
return $requirements;
}
function forena_machine_name_validate($element, &$form_state) {
if (preg_match('@^' . $element['#machine_name']['replace'] . '+$@', $element['#value'])) {
form_error($element, t('The machine-readable name must contain unique characters.'));
}
if (preg_match('@' . $element['#machine_name']['replace_pattern'] . '@', $element['#value'])) {
if (!isset($element['#machine_name']['error'])) {
if ($element['#machine_name']['replace'] == '-') {
form_error($element, t('The machine-readable name must contain only letters, numbers, and hyphens.'));
}
else {
form_error($element, t('The machine-readable name must contain only letters, numbers, and underscores.'));
}
}
else {
form_error($element, $element['#machine_name']['error']);
}
}
}
function forena_process_machine_name($element, &$form_state) {
$element['#machine_name']['replace_pattern'] = '[^A-Za-z0-9_\\.\\/]+';
return $element;
}
function forena_element_info() {
$types['forena_machine_name'] = array(
'#input' => TRUE,
'#element_validate' => array(
'forena_machine_name_validate',
),
'#default_value' => NULL,
'#size' => 60,
'#maxlength' => 64,
'#required' => TRUE,
'#autocomplete_path' => FALSE,
'#process' => array(
'form_process_machine_name',
'forena_process_machine_name',
'ajax_process_form',
),
'#theme_wrappers' => array(
'form_element',
),
'#theme' => 'textfield',
);
return $types;
}