You are here

function page_manager_list_page in Chaos Tool Suite (ctools) 6

Same name and namespace in other branches
  1. 7 page_manager/page_manager.admin.inc \page_manager_list_page()

Output a list of pages that are managed.

1 string reference to 'page_manager_list_page'
page_manager_menu in page_manager/page_manager.module
Delegated implementation of hook_menu().

File

page_manager/page_manager.admin.inc, line 14
Administrative functions for the page manager.

Code

function page_manager_list_page($js = NULL) {

  // Prevent this page from showing up when random other links fail.
  if ($js && $js != 'ajax' && $js != 'nojs') {
    return drupal_not_found();
  }

  // TRUE if 'ajax', FALSE if otherwise.
  $js = $js == 'ajax';
  if (module_exists('advanced_help') && !$js) {
    drupal_set_message(theme('advanced_help_topic', 'page_manager', 'getting-started', t('See the getting started guide for more information.')));
  }
  $tasks = page_manager_get_tasks_by_type('page');
  $pages = array(
    'operations' => array(),
    'tasks' => array(),
  );
  page_manager_get_pages($tasks, $pages);

  // Add lock icon to all locked tasks.
  global $user;
  ctools_include('object-cache');
  $locks = ctools_object_cache_test_objects('page_manager_page', $pages['tasks']);
  foreach ($locks as $task_name => $lock) {
    if ($lock->uid == $user->uid) {
      $pages['rows'][$task_name]['class'] .= ' page-manager-locked';
      $pages['rows'][$task_name]['title'] = t('This page is currently locked for editing by you. Nobody else may edit this page until these changes are saved or canceled.');
    }
    else {
      $pages['rows'][$task_name]['class'] .= ' page-manager-locked-other';
      $pages['rows'][$task_name]['title'] = t('This page is currently locked for editing by another user. You may not edit this page without breaking the lock.');
    }
  }
  $input = $_POST;

  // Respond to a reset command by clearing session and doing a drupal goto
  // back to the base URL.
  if (isset($input['op']) && $input['op'] == t('Reset')) {
    unset($_SESSION['page_manager']['#admin']);
    if (!$js) {
      return drupal_goto($_GET['q']);
    }

    // clear everything but form id, form build id and form token:
    $keys = array_keys($input);
    foreach ($keys as $id) {
      if ($id != 'form_id' && $id != 'form_build_id' && $id != 'form_token') {
        unset($input[$id]);
      }
    }
    $replace_form = TRUE;
  }
  if (count($input) <= 1) {
    if (isset($_SESSION['page_manager']['#admin']) && is_array($_SESSION['page_manager']['#admin'])) {
      $input = $_SESSION['page_manager']['#admin'];
    }
  }
  else {
    $_SESSION['page_manager']['#admin'] = $input;
    unset($_SESSION['page_manager']['#admin']['q']);
  }
  $form_state = array(
    'pages' => &$pages,
    'input' => $input,
    'rerender' => TRUE,
    'no_redirect' => TRUE,
  );

  // This form will sort and filter the pages.
  ctools_include('form');
  $form = ctools_build_form('page_manager_list_pages_form', $form_state);
  $header = array(
    array(
      'data' => t('Type'),
      'class' => 'page-manager-page-type',
    ),
    array(
      'data' => t('Name'),
      'class' => 'page-manager-page-name',
    ),
    array(
      'data' => t('Title'),
      'class' => 'page-manager-page-title',
    ),
    array(
      'data' => t('Path'),
      'class' => 'page-manager-page-path',
    ),
    array(
      'data' => t('Storage'),
      'class' => 'page-manager-page-storage',
    ),
  );
  $header[] = array(
    'data' => t('Operations'),
    'class' => 'page-manager-page-operations',
  );
  $table = theme('table', $header, $pages['rows'], array(
    'id' => 'page-manager-list-pages',
  ));
  $operations = '<div id="page-manager-links" class="links">' . theme('links', $pages['operations']) . '</div>';
  drupal_add_css(drupal_get_path('module', 'page_manager') . '/css/page-manager.css');
  if (!$js) {
    return $form . $table . $operations;
  }
  ctools_include('ajax');
  $commands = array();
  $commands[] = ctools_ajax_command_replace('#page-manager-list-pages', $table);
  if (!empty($replace_form)) {
    $commands[] = ctools_ajax_command_replace('#page-manager-list-pages-form', $form);
  }
  ctools_ajax_render($commands);
}