You are here

function dynamic_banner_admin_page in Dynamic Banner 6

Same name and namespace in other branches
  1. 7.2 dynamic_banner.module \dynamic_banner_admin_page()
  2. 7 includes/callbacks.inc \dynamic_banner_admin_page()
  3. 8.x dynamic_banner.module \dynamic_banner_admin_page()

Return a listing of all defined URL aliases. When filter key passed, perform a standard search on the given key, and return the list of matching URL aliases.

1 string reference to 'dynamic_banner_admin_page'
dynamic_banner_menu in ./dynamic_banner.module
Implements hook_menu().

File

includes/callbacks.inc, line 16
Dynamic Banner Admin Pages and various other functions to make them work Most of the code in this file was derived from path module

Code

function dynamic_banner_admin_page($keys = NULL) {

  // Add the filter form above the overview table.
  $output = drupal_get_form('dynamic_banner_admin_filter_form', $keys);
  if ($keys) {

    // Replace wildcards with MySQL/PostgreSQL wildcards.
    $keys = preg_replace('!\\*+!', '%', $keys);
    $sql = "SELECT * FROM {dynamic_banner} WHERE path LIKE '%%%s%%'";
  }
  else {
    $sql = 'SELECT * FROM {dynamic_banner}';
  }

  // construct the headers of the table
  $header = array(
    array(
      'data' => t('Url'),
      'field' => 'path',
      'sort' => 'asc',
    ),
    array(
      'data' => t('ImgUrl'),
      'field' => 'imgurl',
    ),
    array(
      'data' => t('Text'),
      'field' => 'text',
    ),
    array(
      'data' => t('Link'),
      'field' => 'link',
    ),
    array(
      'data' => t('Operations'),
      'colspan' => '2',
    ),
  );

  // allows us to sort the table
  $sql .= tablesort_sql($header);

  // get the current page of results
  $result = pager_query($sql, 50, 0, NULL, $keys);

  // start constructing the individual rows
  $rows = array();
  while ($data = db_fetch_object($result)) {
    $rows[] = array(
      $data->path,
      $data->imgurl,
      $data->text,
      $data->link,
      l(t('edit'), "admin/build/banners/edit/{$data->dbid}"),
      l(t('delete'), "admin/build/banners/delete/{$data->dbid}"),
    );
  }

  // deal with an empty set
  if (empty($rows)) {
    $empty_message = $keys ? t('No Banners Found.') : t('No Banner Urls found.');
    $rows[] = array(
      array(
        'data' => $empty_message,
      ),
    );
  }

  // display the information
  $output .= theme('table', $header, $rows);
  $output .= theme('pager', NULL, 50, 0);

  // let drupal handle print and echo
  return $output;
}