You are here

function forena_reports_autocomplete in Forena Reports 6.2

Same name and namespace in other branches
  1. 7.5 forena.module \forena_reports_autocomplete()
  2. 7.2 forena.module \forena_reports_autocomplete()
  3. 7.3 forena.module \forena_reports_autocomplete()
  4. 7.4 forena.module \forena_reports_autocomplete()
1 string reference to 'forena_reports_autocomplete'
forena_menu in ./forena.module
Implementation of hook_menu.

File

./forena.module, line 512

Code

function forena_reports_autocomplete($string = '') {
  global $language;
  $reports = '';
  $string = '%' . $string . '%';
  $result = db_query("SELECT * FROM {forena_reports} where language='%s'\n\t  AND report_name like '%s'\n\t  ORDER BY category,title", $language->language, $string);
  while ($row = db_fetch_object($result)) {
    $access = TRUE;
    $cache = $row->cache;
    if ($cache) {
      $cache = unserialize($cache);

      // Check each callback function to see if we have an error.
      if ($cache['access']) {
        foreach ($cache['access'] as $callback => $args) {
          if ($callback) {
            foreach ($args as $arg) {
              $access = FALSE;
              if (function_exists($callback)) {
                $a = $callback($arg);
              }
              if ($a) {
                $access = TRUE;
              }
            }
          }
          else {
            $access = TRUE;
          }
        }
      }
    }
    if ($access) {
      $reports[$row->report_name] = $row->report_name . ' - ' . $row->title;
    }
  }
  return drupal_json($reports);
}