You are here

function comment_admin_overview in Drupal 4

Same name and namespace in other branches
  1. 5 modules/comment/comment.module \comment_admin_overview()
  2. 6 modules/comment/comment.admin.inc \comment_admin_overview()
  3. 7 modules/comment/comment.admin.inc \comment_admin_overview()

Menu callback; present an administrative comment listing.

1 string reference to 'comment_admin_overview'
comment_menu in modules/comment.module
Implementation of hook_menu().

File

modules/comment.module, line 938
Enables users to comment on published content.

Code

function comment_admin_overview($type = 'new') {
  $edit = $_POST['edit'];
  if ($edit['operation'] == 'delete') {
    return comment_multiple_delete_confirm();
  }

  // build an 'Update options' form
  $form['options'] = array(
    '#type' => 'fieldset',
    '#title' => t('Update options'),
    '#prefix' => '<div class="container-inline">',
    '#suffix' => '</div>',
  );
  $options = array();
  foreach (comment_operations(arg(3) == 'approval' ? 'publish' : 'unpublish') as $key => $value) {
    $options[$key] = $value[0];
  }
  $form['options']['operation'] = array(
    '#type' => 'select',
    '#options' => $options,
    '#default_value' => 'publish',
  );
  $form['options']['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Update'),
  );

  // load the comments that we want to display
  $status = $type == 'approval' ? COMMENT_NOT_PUBLISHED : COMMENT_PUBLISHED;
  $form['header'] = array(
    '#type' => 'value',
    '#value' => array(
      NULL,
      array(
        'data' => t('Subject'),
        'field' => 'subject',
      ),
      array(
        'data' => t('Author'),
        'field' => 'name',
      ),
      array(
        'data' => t('Time'),
        'field' => 'timestamp',
        'sort' => 'desc',
      ),
      array(
        'data' => t('Operations'),
      ),
    ),
  );
  $result = pager_query('SELECT c.subject, c.nid, c.cid, c.comment, c.timestamp, c.status, c.name, c.homepage, u.name AS registered_name, u.uid FROM {comments} c INNER JOIN {users} u ON u.uid = c.uid WHERE c.status = %d' . tablesort_sql($form['header']['#value']), 50, 0, NULL, $status);

  // build a table listing the appropriate comments
  $destination = drupal_get_destination();
  while ($comment = db_fetch_object($result)) {
    $comments[$comment->cid] = '';
    $comment->name = $comment->uid ? $comment->registered_name : $comment->name;
    $form['subject'][$comment->cid] = array(
      '#value' => l($comment->subject, 'node/' . $comment->nid, array(
        'title' => truncate_utf8($comment->comment, 128),
      ), NULL, 'comment-' . $comment->cid),
    );
    $form['username'][$comment->cid] = array(
      '#value' => theme('username', $comment),
    );
    $form['timestamp'][$comment->cid] = array(
      '#value' => format_date($comment->timestamp, 'small'),
    );
    $form['operations'][$comment->cid] = array(
      '#value' => l(t('edit'), 'comment/edit/' . $comment->cid, array(), $destination),
    );
  }
  $form['comments'] = array(
    '#type' => 'checkboxes',
    '#options' => $comments,
  );
  $form['pager'] = array(
    '#value' => theme('pager', NULL, 50, 0),
  );
  return drupal_get_form('comment_admin_overview', $form);
}