You are here

function views_ui_admin_page in Views (for Drupal 7) 5

1 string reference to 'views_ui_admin_page'
views_ui_menu in ./views_ui.module

File

./views_ui.module, line 209

Code

function views_ui_admin_page() {
  views_load_cache();
  $numViews = 25;
  drupal_set_title(t('Administer views'));
  $result = pager_query("SELECT vid, name, description, menu_title, page_title, block_title, url, page, menu, block FROM {view_view} ORDER BY name", $numViews);
  while ($view = db_fetch_object($result)) {
    $url = $view->page ? l($view->url, $view->url) : t('No Page View');
    $provides = array();
    if ($view->page) {
      $provides[] = 'Page';
    }
    if ($view->block) {
      $provides[] = 'Block';
    }
    if ($view->menu) {
      $provides[] = 'Menu';
    }
    $items[] = array(
      $view->name,
      filter_xss_admin(views_get_title($view, 'admin')),
      $view->description,
      implode(', ', $provides),
      $url,
      theme('links', array(
        array(
          'title' => t('Edit'),
          'href' => "admin/build/views/{$view->name}/edit",
        ),
        array(
          'title' => t('Export'),
          'href' => "admin/build/views/{$view->name}/export",
        ),
        array(
          'title' => t('Delete'),
          'href' => "admin/build/views/delete/{$view->vid}",
        ),
        array(
          'title' => t('Clone'),
          'href' => "admin/build/views/{$view->name}/clone",
        ),
      )),
    );
  }
  if ($items) {
    $output = theme('table', array(
      t('View'),
      t('Title'),
      t('Description'),
      t('Provides'),
      t('URL'),
      t('Actions'),
    ), $items, array(
      "cellpadding" => "4",
    ), t('Existing Views'));
    $output .= theme('pager', NULL, $numViews);
  }
  else {
    $output .= t('<p>No views have currently been defined.</p>');
  }
  $result = db_query("SELECT name FROM {view_view}");
  while ($view = db_fetch_object($result)) {
    $used[$view->name] = true;
  }
  $output .= t('<p>Below are system default views; if you edit one of these, a view will be created that will override any system use of the view.</p>');
  $items = array();
  $default_views = _views_get_default_views();
  $views_status = variable_get('views_defaults', array());
  foreach ($default_views as $view) {
    $url = $view->page ? l($view->url, $view->url) : t('No Page View');
    if ($used[$view->name]) {
      $status = t('Overridden');
    }
    else {
      if (isset($views_status[$view->name])) {
        if ($views_status[$view->name] == 'enabled') {
          $status = t('Enabled');
        }
        else {
          $status = t('Disabled');
        }
      }
      else {
        if ($view->disabled) {
          $status = t('Disabled');
        }
        else {
          $status = t('Enabled');
        }
      }
    }
    $provides = array();
    if ($view->page) {
      $provides[] = t('Page');
    }
    if ($view->block) {
      $provides[] = t('Block');
    }
    if ($view->menu) {
      $provides[] = t('Menu');
    }
    $links = array();
    $links[] = array(
      'title' => t('Add'),
      'href' => "admin/build/views/add/{$view->name}",
    );
    $token_enable = drupal_get_token('views-enable');
    $token_disable = drupal_get_token('views-disable');
    if ($status == t('Enabled')) {
      $links[] = array(
        'title' => t('Disable'),
        'href' => "admin/build/views/disable/{$view->name}",
        'query' => 'token=' . $token_disable,
      );
    }
    else {
      if ($status == t('Disabled')) {
        $links[] = array(
          'title' => t('Enable'),
          'href' => "admin/build/views/enable/{$view->name}",
          'query' => 'token=' . $token_enable,
        );
      }
    }
    $items[] = array(
      $view->name,
      filter_xss_admin(views_get_title($view, 'menu')),
      $view->description,
      implode(', ', $provides),
      $url,
      $status,
      theme('links', $links),
    );
  }
  if ($items) {
    $output .= theme('table', array(
      t('Default view'),
      t('Title'),
      t('Description'),
      t('Provides'),
      t('URL'),
      t('Status'),
      t('Actions'),
    ), $items, array(
      "cellpadding" => "4",
    ), t('Default Views'));
  }
  else {
    $output .= t('<p>No views have currently been defined.</p>');
  }
  return $output;
}