You are here

forena.module in Forena Reports 7.4

File

forena.module
View source
<?php

require_once 'forena.data.inc';
require_once 'Frx.inc';

/**
 * Implementation of hook_menu.
 *
 * @return array
 */
function forena_menu() {
  $items = array();

  // First build menu items.
  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/%/%'] = array(
    'page callback' => 'forena_report_page_callback',
    'page arguments' => array(
      1,
      2,
    ),
    '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;
}

/**
 * Implements hook_admin_paths_alter().
 */
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;
}

/**
 * Implements hook_library().
 */
function forena_library() {
  $m_path = drupal_get_path('module', 'forena');
  $libraries['ajax'] = array(
    'title' => 'Forena Ajax API',
    'version' => '7.x-4.x',
    'js' => array(
      $m_path . '/js/forena-ajax.js' => array(
        'weight' => 15,
      ),
    ),
    'dependencies' => array(
      array(
        'system',
        'drupal.ajax',
      ),
    ),
  );
  return $libraries;
}
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;
}

/**
 * Implementation of hook_block_info
 */
function forena_block_info() {
  $blocks['forena_reports'] = array(
    'info' => t('My reports'),
    'status' => 1,
    'region' => 'sidebar_first',
    'visibility' => 1,
    'pages' => 'forena',
  );
  return $blocks;
}

/**
 * Implementation of hook_block_view
 */
function forena_block_view($delta = 0) {

  // Inlcude the base library
  require_once 'forena.common.inc';
  switch ($delta) {
    case 'forena_reports':
      $block = array(
        'subject' => 'My Reports',
        'content' => forena_my_reports_block(),
      );
      break;
  }
  return $block;
}

/**
 * Auto complete for categories
 *
 */
function forena_categories_autocomplete($string = '') {
  require_once 'forena.admin.inc';
  $categories = @forena_get_categories($string);
  print drupal_json_output($categories);
}

/**
 * Auto complete for data blocks
 * @param $string
 * @return unknown_type
 */
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 we have two parameters.
  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);

  //now invoke the data provider with the correct params
  Frx::Data()
    ->push($parms, 'parm');
  return Frx::RepoMan()
    ->data($block_name);
}

/**
 * Get the raw data from a block if supported.
 * Note that this may return a simplexml object or a recordset or an
 * array depending on the support provided by the product.
 * @param unknown $block_name
 * @param unknown $parms
 * @return Ambigous <unknown, string, NULL>
 */
function forena_data($block_name, $parms = array(), $raw_mode = TRUE) {
  include_once 'forena.common.inc';
  drupal_alter('forena_parameters', $block_name, $parms);

  //now invoke the data provider with the correct params
  Frx::Data()
    ->push($parms, 'parm');
  $data = Frx::RepoMan()
    ->data($block_name, $raw_mode);
  Frx::Data()
    ->pop();
  return $data;
}

/**
 * Output forena data as JSON objects.
 * @param unknown $block_name
 * @param string $parms
 */
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);
}

/**
 * Send report block XML
 * Enter description here ...
 * @param unknown_type $block_name
 */
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();
  }
}

/**
 * Auto complete for formats
 * @param $string
 * @return unknown_type
 */
function forena_fields_format_autocomplete($string = '') {
  require_once 'forena.common.inc';
  $matches = array();
  $formats = @FrxReportGenerator::instance()
    ->supported_formats();
  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);
}

/**
 *  Calls forena_parameter_form
 *  in forena.common.inc
 */
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'])) {

    // Set Descriptors
    $desc = FrxData::instance()
      ->getContext('report');
    $form_state['storage']['desc'] = $desc;
    $desc = $form_state['storage']['desc'];

    // Set menu parms
    $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']);

    // In the case of ahah, we need to restore menu parameters from the form state.
    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) {

    //drupal_alter('forena_parameters', $report_name,  $parms);
    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'];
          if (strpos($value, '|') !== FALSE) {
            $multi_value = explode('|', $value);
          }
          elseif ($value) {
            $multi_value = (array) $value;
          }
          else {
            $multi_value = array();
          }
        }
        $desc = @(string) $node['desc'];
        $label_field = @(string) $node['label_field'];
        @(strcmp((string) $node['require'], "1") == 0) ? $required = TRUE : ($required = FALSE);
        $ctl_attrs = array();

        //returned values filtered against data_field attr.
        if ($data_source) {
          $list = Frx::RepoMan()
            ->dataBlockParams($data_source, $data_field, $label_field);
          if (!$required && $add_null) {
            $list = array(
              '' => '',
            ) + $list;
          }
        }

        //Determine the form element type to be displayed

        //If select or radios is chosen then begin a $list array for display values.
        $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;
        }

        //If a data_source attr was found then create an array of
        $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;
        }

        // Add class to parmeter form.
        if ($class) {
          $form['params'][$id]['#attributes'] = array(
            'class' => @explode(' ', $class),
          );
        }

        //if $list is not empty then push options

        //onto the array. options will cause an error for

        //textfield elements.
        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;
  }
}

/**
 *
 * gets the values from the params form
 * redirects to the report page with the values in
 * the querystring.
 */
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'],
      ),
    );
  }
}

/**
 * Ajax form callback function
 * Enter description here ...
 * @param unknown_type $form
 * @param unknown_type $form_state
 */
function forena_parameters_callback($form, &$form_state) {
  return $form['params'];
}

/**
 * Implementation of hook_perm
 *
 * @return unknown
 */
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::RepoMan()->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);
  $report_repos = variable_get('forena_path', 'reports');
  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'], $report_repos . '/' . str_replace('/', '.', $r['report_name'])) . '</li>';
    }
    $output .= '</ul>';
  }
  return $output;
}

/**
 * Tries to load data tables libary and other libraries that help.
 */
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);
    }
  }
}

/**
 * @param string $report_name
 * @param string $com
 */
function forena_report_page_callback($report_name, $js_mode, $id = '', $command = '') {
  $commands = array();
  if ($js_mode != 'ajax') {
    return forena_report($report_name);
  }
  else {
    $content = forena_report($report_name);
    $report =& $content['content']['#markup'];
    if (!empty($content['content']['#ajax_commands']['pre'])) {
      $commands = array_merge($commands, $content['content']['#ajax_commands']['pre']);
    }
    if (!$command) {
      $command = 'modal';
    }
    switch ($command) {
      case 'after':
        $commands[] = ajax_command_after("#{$id}", $report);
        break;
      case 'append':
        $commands[] = ajax_command_append("#{$id}", $report);
        break;
      case 'before':
        $commands[] = ajax_command_before("#{$id}", $report);
        break;
      case 'modal':
        $title = Frx::Editor()->frxReport->title;
        if (is_callable('ctools_include')) {
          ctools_include('modal');
          ctools_modal_render($title, $report);
          return NULL;
        }
        else {
          drupal_set_title($title);
          return $content;
        }
        break;
      case 'html':
        $commands[] = ajax_command_html("#{$id}", $report);
        break;
      case 'replace':
        $commands[] = ajax_command_replace("#{$id}", $report);
        break;
    }
    if (!empty($content['content']['#ajax_commands']['post'])) {
      $commands = array_merge($commands, $content['content']['#ajax_commands']['post']);
    }
    ajax_deliver(array(
      '#type' => 'ajax',
      '#commands' => $commands,
    ));
  }
}

/**
 * Load and render a report based on a drupal path.
 * In this function the arglist is used to get the full path to the report.
 *
 * @return string|array
 *   Render array or 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 '';
  }
  FrxData::instance()
    ->setContext('cookie', $_COOKIE);
  FrxData::instance()
    ->setContext('report', $desc);
  $report_name = $desc['name'];

  // Load dataTable plugin if possible.

  //forena_include_data_tables();
  $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) {

    // This has been deprecated, but we'll eave it in for now.
    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;
}

/**
 * Render report as an inlcude.  Don't perform the output fuctnions for the document
 * @param $report_name String
 * @param $parms array of parameters to include
 */
function forena_report_include($report_name, $parms = array()) {
  $output = '';
  require_once 'forena.common.inc';
  $desc = Frx::Menu()
    ->parseURL($report_name);
  $name = $desc['name'];
  $r = @FrxReportGenerator::instance()
    ->get_report($name, $parms);
  if (!$r || !$r->rpt_xml) {
    return '';
  }

  //check for default parameters
  $r
    ->processParameters();
  $format = $desc['format'];
  $r
    ->render($format, FALSE, NULL, TRUE);
  return $r->html;
}

/**
 * Menu callback for rendering the forena report.
 */
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;
  }
}

/**
 * Used in hook_menu to test access to menu items.
 * @param $checks array key value of callbacks and args to check.
 */
function forena_check_all_access($checks) {

  // Check each callback function to see if we have an error.
  $access = FALSE;

  // Check each callback function to see if we have an error.
  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;
}

/**
 * Callback for setting international titles
 * @param $report_name string name of report
 * @param $use_menu_title boolean indicate wether to use menu title attribute.
 */
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;
}

/**
 * Render report with some data
 *
 * @param string $report
 * @param string $format
 * @param mixed $data
 * @return unknown
 */
function forena_render_report($report, $format = '', $data = '', $options = array(), $print = TRUE) {
  require_once 'forena.common.inc';
  $o = forena_report_object($report, $data);
  $output = $o
    ->render($format, $print);

  //If a format was requested render a custom non-drupal document
  if ($format && $format != 'web') {
    $output = FrxReportGenerator::instance()
      ->generate_doc($format, $output, $options, $print);
  }
  return $output;
}

/**
 * Self register plugins with forena.
 *
 */
function forena_forena_plugins() {
  $path = drupal_get_path('module', 'forena');
  $plugins['FrxPDO'] = array(
    'file' => 'plugins/FrxPDO.inc',
    'parent' => 'FrxDataSource',
    'class' => 'FrxPDO',
    'path' => $path,
  );
  $plugins['FrxOracle'] = array(
    'file' => 'plugins/FrxOracle.inc',
    'parent' => 'FrxDataSource',
    'class' => 'FrxOracle',
    'path' => $path,
  );
  $plugins['FrxDrupal'] = array(
    'file' => 'plugins/FrxDrupal.inc',
    'parent' => 'FrxDataSource',
    'class' => 'FrxDrupal',
    'path' => $path,
  );
  $plugins['FrxFiles'] = array(
    'file' => 'plugins/FrxFiles.inc',
    'parent' => 'FrxDataSource',
    'class' => 'FrxFiles',
  );
  $plugins['FrxPostgres'] = array(
    'file' => 'plugins/FrxPostgres.inc',
    'class' => 'FrxPostgres',
    'parent' => 'FrxDataSource',
  );
  $plugins['FrxMSSQL'] = array(
    'file' => 'plugins/FrxMSSQL.inc',
    'parent' => 'FrxDataSource',
    'class' => 'FrxMSSQL',
    'path' => $path,
  );
  return $plugins;
}

/**
 * Self register document formats with Forena
 *
 */
function forena_forena_document_types() {
  require_once 'docformats/FrxWebDoc.inc';
  require_once 'docformats/FrxCSVDoc.inc';
  require_once 'docformats/FrxHtmlDoc.inc';
  require_once 'docformats/FrxSVGDoc.inc';
  require_once 'docformats/FrxWordDoc.inc';
  require_once 'docformats/FrxXLSDoc.inc';
  require_once 'docformats/FrxXMLDoc.inc';
  require_once 'docformats/FrxEmailMergeDoc.inc';
  $items['web'] = array(
    'class' => 'FrxWebDoc',
    'title' => t('Themed Drupal Page'),
  );
  $items['csv'] = array(
    'class' => 'FrxCSVDoc',
    'title' => t('Comma separated values'),
  );
  $items['email'] = array(
    'class' => 'FrxEmailMergeDoc',
    'title' => t('Email Merge Document'),
  );
  $items['html'] = array(
    'class' => 'FrxHtmlDoc',
    'title' => t('Unthemed HTML'),
  );
  $items['svg'] = array(
    'class' => 'FrxSVGDoc',
    'title' => t('SVG Document'),
  );
  $items['doc'] = array(
    'class' => 'FrxWordDoc',
    'title' => t('MS Word Document format'),
  );
  $items['xls'] = array(
    'class' => 'FrxXLSDoc',
    'title' => t('Excel Document'),
  );
  $items['xml'] = array(
    'class' => 'FrxXMLDoc',
    'title' => t('XML Document'),
  );
  return $items;
}

/**
 * Self register controls with forena.
 *
 */
function forena_forena_controls() {
  $controls[] = array(
    'file' => 'plugins/FrxControls.inc',
    'class' => 'FrxControls',
  );
  $controls[] = array(
    'file' => 'plugins/FrxDrupalControls.inc',
    'class' => 'FrxDrupalControls',
  );
  $controls[] = array(
    'file' => 'renderers/FrxAjax.inc',
    'class' => 'FrxAjax',
  );
  $controls[] = array(
    'file' => 'renderers/FrxSection.inc',
    'class' => 'FrxSection',
  );
  $controls[] = array(
    'file' => 'renderers/FrxCrosstab.inc',
    'class' => 'FrxCrosstab',
  );
  $controls[] = array(
    'file' => 'renderers/FrxEmailMerge.inc',
    'class' => 'FrxEmailMerge',
  );
  $controls[] = array(
    'file' => 'renderers/FrxFieldTable.inc',
    'class' => 'FrxFieldTable',
  );
  $controls[] = array(
    'file' => 'renderers/FrxRenderer.inc',
    'class' => 'FrxRenderer',
  );
  $controls[] = array(
    'file' => 'renderers/FrxTable.inc',
    'class' => 'FrxTable',
  );
  $controls[] = array(
    'file' => 'renderers/FrxMergeDocument.inc',
    'class' => 'FrxMergeDocument',
  );
  $controls[] = array(
    'file' => 'renderers/FrxSource.inc',
    'class' => 'FrxSource',
  );
  $controls[] = array(
    'file' => 'renderers/FrxXML.inc',
    'class' => 'FrxXML',
  );
  $controls[] = array(
    'file' => 'renderers/FrxInclude.inc',
    'class' => 'FrxInclude',
  );
  $controls[] = array(
    'file' => 'renderers/FrxMyReports.inc',
    'class' => 'FrxMyReports',
  );
  $controls[] = array(
    'file' => 'renderers/FrxParameterForm.inc',
    'class' => 'FrxParameterForm',
  );
  $controls[] = array(
    'file' => 'renderers/FrxTitle.inc',
    'class' => 'FrxTitle',
  );
  if (forena_library_file('SVGGraph')) {
    $controls[] = array(
      'file' => 'renderers/FrxSVGGraph.inc',
      'class' => 'FrxSVGGraph',
    );
  }
  return $controls;
}

/**
 * Implements hook_forena_context().
 */
function forena_forena_context() {
  $m_path = drupal_get_path('module', 'forena');
  $contexts['FrxReport'] = array(
    'file' => "{$m_path}/contexts/FrxReportContext.inc",
    'class' => "FrxReportContext",
  );
  return $contexts;
}

/**
 * Implementation of forena_report_directory hook.
 */
function forena_forena_report_directory() {
  return drupal_get_path('module', 'forena') . '/repos/reports';
}

/**
 * Load the report repository path
 *
 * @return unknown
 */
function forena_report_path() {
  return Frx::File()->dir;
}

/**
 * Rename function for backwards compatibility
 */
function forena_current_user_uid() {
  return forena_current_user_id();
}

/**
 * Helper function for current user for the drupal instance
 *
 * @return unknown
 */
function forena_current_user_id() {
  global $user;
  return $user->uid;
}

/**
 * Helper function for current user for the drupal instance
 *
 * @return unknown
 */
function forena_current_user_name() {
  global $user;
  if (isset($user->name)) {
    return $user->name;
  }
}

/**
 * Helper function for current user for the drupal instance
 *
 * @return unknown
 */
function forena_current_user_email() {
  global $user;
  if (isset($user->name)) {
    return $user->mail;
  }
}

/**
 * Implememntation of hook_filter
 */
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;
}

/**
 * Process tag replacement for xml filters
 */
function _forena_filter_process($text = '') {
  require_once 'forena.admin.inc';
  global $language;

  // initial Parameters
  $in_parms = Frx::Data()
    ->getContext('parm');
  if (!$in_parms) {
    $parms = $_GET;
  }

  // Find the instances of [xmlreport:view,
  if (preg_match_all("/\\[report?:?([^\\]]+)\\]/i", $text, $match)) {
    foreach ($match[1] as $idx => $value) {
      $parms = $in_parms;

      // Separate view from parmeters
      @(list($report_name, $parmsStr) = explode(':', $value));

      // Get any static parmeters
      $pairs = explode(',', $parmsStr);
      if ($pairs) {
        foreach ($pairs as $pair) {
          @(list($key, $value) = explode('=', $pair));
          if ($key) {
            $parms[$key] = $value;
          }
        }
      }

      // Render it
      $output = forena_report($report_name, $parms, FALSE);

      // Finally replace the parameters
      $find[] = $match[0][$idx];
      $replace[] = $output;
    }
    return str_replace($find, $replace, $text);
  }

  // If we didn't find anything return the text.
  return $text;
}

/**
 * Impementation of hook_mail
 * Builds an email to send when mailing large numbers of users.
 */
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;
  }
}

/**
 * Make sure a drectory exists in the report path prior to save.
 *
 * @param $fullpath Full path to the drectory to be copied
 * @param $recursive Whether we are in a recursive call.
 */
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;

  // Path
  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;
    }
  }

  // Recurse to next file.
  if ($file && strpos($file, '/')) {
    _forena_verify_directory($file, TRUE);
  }
  return TRUE;
}

/**
 * Recursively ,  all report files from the source directory to the destination directory
 * @param $src_dir  Source directory to copy files from
 */
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) {

        // Recurse into sub directory
        $dir = $subdir ? $subdir . '/' . $rpt_file : $rpt_file;
        $i += _forena_revert_reports($dir);
      }
    }
  }
  if ($d) {
    $d
      ->close();
  }
  return $i;
}

/**
 *
 * Enter description here ...
 * @param $copy_reports If true, reports will by re-copied from
 *         module source files to destination.
 */
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',
    ),
  );
}

/**
 * Default theme function for forena web reports.
 * @param $variables Array of variables to theme
 */
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;
}

/**
 * Iemplents hook_views_api
 * @return multitype:number The Ambigous <The, string>
 */
function forena_views_api() {
  return array(
    'api' => 3,
    'path' => drupal_get_path('module', 'forena'),
    'template path' => drupal_get_path('module', 'forena'),
  );
}

/**
 * Implements hook_feeds_plugins().
 */
function forena_feeds_plugins() {
  module_load_include('inc', 'forena', 'feeds/forena_feeds');
  return _forena_feeds_plugins();
}

/**
 * Implements hook_bean_types_api_info().
 */
function forena_bean_types_api_info() {
  return array(
    'api' => 4,
  );
}

/**
 * Implements hook_bean_types().
 */
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 to reflect back forms that are built by classes
 * @param $formid
 * @param $form_state form state array
 * @param $form array of form elements to be reflected
 */
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;
}

/**
 * Custom override of machine_name validate that does not include
 * @param unknown $element
 * @param unknown $form_state
 */
function forena_machine_name_validate($element, &$form_state) {

  // Verify that the machine name not only consists of replacement tokens.
  if (preg_match('@^' . $element['#machine_name']['replace'] . '+$@', $element['#value'])) {
    form_error($element, t('The machine-readable name must contain unique characters.'));
  }

  // Verify that the machine name contains no disallowed characters.
  if (preg_match('@' . $element['#machine_name']['replace_pattern'] . '@', $element['#value'])) {
    if (!isset($element['#machine_name']['error'])) {

      // Since a hyphen is the most common alternative replacement character,
      // a corresponding validation error message is supported here.
      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;
}

/**
 * Create a derivative to the machine name field with relaxed restrictions.
 * @return multitype:boolean string NULL number multitype:string
 */
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;
}

Functions

Namesort descending Description
forena_admin_paths_alter Implements hook_admin_paths_alter().
forena_bean_types Implements hook_bean_types().
forena_bean_types_api_info Implements hook_bean_types_api_info().
forena_block_info Implementation of hook_block_info
forena_block_view Implementation of hook_block_view
forena_block_xml Send report block XML Enter description here ...
forena_categories_autocomplete Auto complete for categories
forena_check_all_access Used in hook_menu to test access to menu items.
forena_current_user_email Helper function for current user for the drupal instance
forena_current_user_id Helper function for current user for the drupal instance
forena_current_user_name Helper function for current user for the drupal instance
forena_current_user_uid Rename function for backwards compatibility
forena_data Get the raw data from a block if supported. Note that this may return a simplexml object or a recordset or an array depending on the support provided by the product.
forena_data_block_autocomplete Auto complete for data blocks
forena_element_info Create a derivative to the machine name field with relaxed restrictions.
forena_feeds_plugins Implements hook_feeds_plugins().
forena_fields_format_autocomplete Auto complete for formats
forena_filter_info Implememntation of hook_filter
forena_forena_context Implements hook_forena_context().
forena_forena_controls Self register controls with forena.
forena_forena_document_types Self register document formats with Forena
forena_forena_plugins Self register plugins with forena.
forena_forena_report_directory Implementation of forena_report_directory hook.
forena_form_reflector Function to reflect back forms that are built by classes
forena_include_data_tables Tries to load data tables libary and other libraries that help.
forena_json Output forena data as JSON objects.
forena_library Implements hook_library().
forena_library_file
forena_machine_name_validate Custom override of machine_name validate that does not include
forena_mail Impementation of hook_mail Builds an email to send when mailing large numbers of users.
forena_menu Implementation of hook_menu.
forena_parameters_callback Ajax form callback function Enter description here ...
forena_parameters_report Calls forena_parameter_form in forena.common.inc
forena_parameter_form
forena_parameter_form_submit gets the values from the params form redirects to the report page with the values in the querystring.
forena_permission Implementation of hook_perm
forena_process_machine_name
forena_render_report Render report with some data
forena_report Load and render a report based on a drupal path. In this function the arglist is used to get the full path to the report.
forena_reports_autocomplete
forena_report_include Render report as an inlcude. Don't perform the output fuctnions for the document
forena_report_menu_callback Menu callback for rendering the forena report.
forena_report_page_callback
forena_report_path Load the report repository path
forena_report_title_callback Callback for setting international titles
forena_requirements
forena_sync_reports Enter description here ...
forena_theme
forena_user_reports
forena_views_api Iemplents hook_views_api
forena_xml
theme_forena_web_report Default theme function for forena web reports.
_forena_filter_process Process tag replacement for xml filters
_forena_revert_reports Recursively , all report files from the source directory to the destination directory
_forena_verify_directory Make sure a drectory exists in the report path prior to save.