You are here

function page_manager_list_page in Chaos Tool Suite (ctools) 7

Same name and namespace in other branches
  1. 6 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 MENU_NOT_FOUND;
  }

  // TRUE if 'ajax', FALSE if otherwise.
  $js = $js == 'ajax';

  // If we do any form rendering, it's to completely replace a form on the
  // page, so don't let it force our ids to change.
  if ($js && isset($_POST['ajax_html_ids'])) {
    unset($_POST['ajax_html_ids']);
  }
  if (module_exists('advanced_help') && !$js) {
    drupal_set_message(theme('advanced_help_topic', array(
      'module' => 'page_manager',
      'topic' => 'getting-started',
      'type' => 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) {
      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.
  $form = drupal_build_form('page_manager_list_pages_form', $form_state);
  $header = array(
    array(
      'data' => t('Type'),
      'class' => array(
        'page-manager-page-type',
      ),
    ),
    array(
      'data' => t('Module'),
      'class' => array(
        'page-manager-page-module',
      ),
    ),
    array(
      'data' => t('Name'),
      'class' => array(
        'page-manager-page-name',
      ),
    ),
    array(
      'data' => t('Title'),
      'class' => array(
        'page-manager-page-title',
      ),
    ),
    array(
      'data' => t('Path'),
      'class' => array(
        'page-manager-page-path',
      ),
    ),
    array(
      'data' => t('Storage'),
      'class' => array(
        'page-manager-page-storage',
      ),
    ),
  );
  $header[] = array(
    'data' => t('Operations'),
    'class' => array(
      'page-manager-page-operations',
    ),
  );
  $table = theme('table', array(
    'header' => $header,
    'rows' => $pages['rows'],
    'attributes' => array(
      'id' => 'page-manager-list-pages',
    ),
  ));
  $operations = '<div id="page-manager-links" class="links">' . theme('links', array(
    'links' => $pages['operations'],
  )) . '</div>';
  drupal_add_css(drupal_get_path('module', 'page_manager') . '/css/page-manager.css');
  if (!$js) {
    return array(
      '#markup' => drupal_render($form) . $table . $operations,
    );
  }
  ctools_include('ajax');
  $commands = array();
  $commands[] = ajax_command_replace('#page-manager-list-pages', $table);
  if (!empty($replace_form)) {
    $commands[] = ajax_command_replace('#page-manager-list-pages-form', drupal_render($form));
  }
  print ajax_render($commands);
  ajax_footer();
}