You are here

function scheduler_list in Scheduler 6

Same name and namespace in other branches
  1. 5 scheduler.module \scheduler_list()
  2. 7 scheduler.admin.inc \scheduler_list()
1 string reference to 'scheduler_list'
scheduler_menu in ./scheduler.module
Implementation of hook_menu().

File

./scheduler.module, line 427

Code

function scheduler_list() {
  $header = array(
    array(
      'data' => t('Title'),
      'field' => 'n.title',
    ),
    array(
      'data' => t('Author'),
      'field' => 'u.name',
    ),
    array(
      'data' => t('Publish on'),
      'field' => 's.publish_on',
    ),
    array(
      'data' => t('Unpublish on'),
      'field' => 's.unpublish_on',
    ),
    array(
      'data' => t('Operations'),
    ),
  );

  // Default ordering
  if (!isset($_GET['order']) && !isset($_GET['sort'])) {
    $_GET['order'] = t('Publish on');
    $_GET['sort'] = 'ASC';
  }
  $sql = 'SELECT n.nid, n.uid, n.status, u.name, n.title, s.publish_on, s.unpublish_on FROM {scheduler} s LEFT JOIN {node} n ON s.nid = n.nid LEFT JOIN {users} u ON n.uid = u.uid ';

  // If this function is being called from a user account page then only select the nodes owned by
  // that user. If the current user is viewing another users profile and they do not have
  // 'administer nodes' permission then it won't even get this far, as the tab will not be accessible.
  $args = func_get_args();
  if ($args[0] == 'user_only') {
    $sql .= ' WHERE n.uid = ' . $args[1];
  }
  $sql .= tablesort_sql($header);
  $result = pager_query($sql, 50);
  $rows = array();
  while ($node = db_fetch_object($result)) {
    $rows[] = array(
      l($node->title, "node/{$node->nid}"),
      theme('username', $node),
      $node->publish_on ? format_date($node->publish_on) : ' ',
      $node->unpublish_on ? format_date($node->unpublish_on) : ' ',
      l(t('edit'), 'node/' . $node->nid . '/edit', array(), 'destination=admin/content/node/scheduler'),
    );
  }
  if (count($rows)) {
    if ($pager = theme('pager', NULL, 50, 0)) {
      $rows[] = array(
        array(
          'data' => $pager,
          'colspan' => 6,
        ),
      );
    }
    print theme('page', theme('table', $header, $rows));
  }
  else {
    print theme('page', t('There are no scheduled nodes.'));
  }
}