You are here

function userpoints_admin_manage in User Points 6

Same name and namespace in other branches
  1. 5.3 userpoints.module \userpoints_admin_manage()
  2. 5 userpoints.module \userpoints_admin_manage()
  3. 5.2 userpoints.module \userpoints_admin_manage()
1 string reference to 'userpoints_admin_manage'
userpoints_menu in ./userpoints.module
Implementation of hook_menu().

File

./userpoints.module, line 933

Code

function userpoints_admin_manage() {
  $tid = arg(4);
  $cat_count = count(userpoints_get_categories());
  $header = array(
    array(
      'data' => t('User'),
      'field' => 'uid',
    ),
    array(
      'data' => t('Time stamp'),
      'field' => 'time_stamp',
      'sort' => 'desc',
    ),
    array(
      'data' => t('!Points', userpoints_translation()),
      'field' => 'points',
    ),
    array(
      'data' => t('Operation'),
      'field' => 'operation',
    ),
    array(
      'data' => t('Category'),
      'field' => 'cat',
    ),
    array(
      'data' => t('Operation'),
    ),
  );
  $sql = "SELECT p.txn_id, p.uid, p.time_stamp, p.points, p.operation, p.status,\n          p.entity_type, p.entity_id, t.name as cat\n          FROM {userpoints_txn} p\n          LEFT JOIN {term_data} t ON p.tid = t.tid\n          WHERE p.status = %d";

  //Check for filtering
  if (is_numeric($tid) && $tid == 0) {
    $sql .= " AND (p.tid IS NULL OR p.tid = '')";
    $cat = t('!Uncategorized', userpoints_translation());
  }
  elseif (is_numeric($tid)) {
    $sql .= " AND p.tid = %d";
    $cat = db_result(db_query("SELECT name from {term_data} WHERE tid = %d", $tid));
  }
  else {
    $cat = t('All');
  }

  //Set the title of the page
  drupal_set_title(t($cat) . " " . t("!points", userpoints_translation()));
  $sql .= tablesort_sql($header);
  $pager_limit = variable_get(USERPOINTS_REPORT_USERCOUNT, 30);
  $result = pager_query($sql, $pager_limit, 0, NULL, USERPOINTS_TXN_STATUS_PENDING, $tid);
  $rows = array();
  while ($data = db_fetch_object($result)) {
    $user = user_load(array(
      'uid' => $data->uid,
    ));
    if (!$data->cat) {
      $data->cat = t('!Uncategorized', userpoints_translation());
    }
    $operations = module_invoke_all('userpoints', 'entity_type', $data);
    if (is_array($operations) && isset($operations[0])) {
      $operation = $operations[0];
    }
    else {
      switch ($data->entity_type) {
        case 'node':
          $node = node_load($data->entity_id);
          if ($node) {
            $operation = l($data->operation, 'node/' . $node->nid, array(
              'attributes' => array(
                'title' => $node->title,
              ),
            ));
          }
          else {
            $operation = check_plain($data->operation);
          }
          break;
        case 'comment':
          if (module_exists('comment')) {

            //We have to load the comment to get the nid for the comment
            $comment = _comment_load($data->entity_id);
            if ($comment) {
              $operation = l($data->operation, 'node/' . $comment->nid, array(
                'attributes' => array(
                  'title' => $comment->subject,
                ),
                'fragment' => 'comment-' . $comment->cid,
              ));
            }
            else {
              $operation = check_plain($data->operation);
            }
          }
          break;
        default:
          $operation = check_plain($data->operation);
      }
    }
    $rows[] = array(
      array(
        'data' => theme('username', $user),
      ),
      array(
        'data' => format_date($data->time_stamp, 'custom', 'Y-m-d H:i'),
      ),
      array(
        'data' => $data->points,
        'align' => 'right',
      ),
      array(
        'data' => $operation,
      ),
      array(
        'data' => $data->cat,
      ),
      array(
        'data' => l('approve', "admin/user/userpoints/approve/{$data->txn_id}") . ' ' . l('decline', "admin/user/userpoints/decline/{$data->txn_id}") . ' ' . l('edit', "admin/user/userpoints/edit/{$data->txn_id}"),
      ),
    );
  }
  if (!$rows) {

    //no points in moderation
    $rows[] = array(
      array(
        'data' => t('No !points awaiting moderation', userpoints_translation()),
        'colspan' => 6,
        'align' => 'center',
      ),
    );
  }
  if ($cat_count > 1) {
    $output = drupal_get_form('userpoints_filter_cat_select', 'admin/user/userpoints/moderate/', arg(4));
    $output .= theme('table', $header, $rows);
    $output .= theme('pager', NULL, $pager_limit, 0);
  }
  else {
    $output = theme('table', $header, $rows);
    $output .= theme('pager', NULL, $pager_limit, 0);
  }
  return $output;
}