You are here

function userpoints_admin_manage in User Points 5.3

Same name and namespace in other branches
  1. 5 userpoints.module \userpoints_admin_manage()
  2. 5.2 userpoints.module \userpoints_admin_manage()
  3. 6 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 804

Code

function userpoints_admin_manage() {
  $tid = arg(4);
  $cat_count = count(userpoints_get_categories());
  $header = array(
    array(
      'data' => t('User'),
      'field' => 'uid',
      'sort' => 'desc',
    ),
    array(
      'data' => t('Time stamp'),
      'field' => 'time_stamp',
    ),
    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);
  while ($data = db_fetch_object($result)) {
    $user = user_load(array(
      'uid' => $data->uid,
    ));
    if (!$data->cat) {
      $data->cat = t('!Uncategorized', userpoints_translation());
    }
    $operation = module_invoke_all('userpoints', 'entity_type', $data);
    if (!$operation) {
      switch ($data->entity_type) {
        case 'node':
          $node = node_load($data->entity_id);
          if ($node) {
            $operation = l($data->operation, 'node/' . $node->nid, array(
              'title' => $node->title,
            ));
          }
          else {
            $operation = $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(
                'title' => $comment->subject,
              ), NULL, 'comment-' . $comment->cid);
            }
            else {
              $operation = $data->operation;
            }
          }
          break;
        default:
          $operation = $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',
      ),
    );

    //$rows[]
  }
  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;
}