You are here

function forena_reports_autocomplete in Forena Reports 7.2

Same name and namespace in other branches
  1. 6.2 forena.module \forena_reports_autocomplete()
  2. 7.5 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 342

Code

function forena_reports_autocomplete($string = '', $string2 = '') {
  global $language;
  $reports = '';
  $link = '';

  // If we have two parameters.
  if ($string2) {
    $mode = $string;
    $string = $string2;
  }
  $string = '%' . $string . '%';
  $result = db_query('SELECT * FROM {forena_reports} where language=:language
	  AND report_name like :string
	  ORDER BY category,title', array(
    ':language' => $language->language,
    ':string' => $string,
  ));
  foreach ($result as $row) {
    $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) {
      $key = $row->report_name;
      if ($mode = 'link') {
        $key = 'reports/' . str_replace('/', '.', $key);
      }
      $reports[$key] = $key . ' - ' . $row->title;
    }
  }
  return drupal_json_output($reports);
}