You are here

function userpoints_admin_txn in User Points 5

Same name and namespace in other branches
  1. 5.3 userpoints.module \userpoints_admin_txn()
  2. 5.2 userpoints.module \userpoints_admin_txn()
  3. 6 userpoints.module \userpoints_admin_txn()
  4. 7.2 userpoints.admin.inc \userpoints_admin_txn()
  5. 7 userpoints.admin.inc \userpoints_admin_txn()
2 string references to 'userpoints_admin_txn'
userpoints_admin_txn_submit in ./userpoints.module
userpoints_menu in ./userpoints.module
Implementation of hook_menu().

File

./userpoints.module, line 451

Code

function userpoints_admin_txn() {
  global $user;
  $mode = arg(3);
  $txn_id = (int) arg(4);
  if ($txn_id) {
    $txn_user = user_load(array(
      'uid' => $txn_id,
    ));
  }
  $timestamp = format_date(time(), 'custom', 'Y-m-d H:i O');
  if ($mode == 'edit' && $txn_id) {
    $result = db_query('SELECT * FROM {userpoints_txn} WHERE txn_id = %d', $txn_id);
    $txn = db_fetch_object($result);
    $timestamp = format_date($txn->time_stamp, 'custom', 'Y-m-d H:i O');
  }
  $form['txn_user'] = array(
    '#type' => 'textfield',
    '#title' => t('User Name'),
    '#size' => 30,
    '#maxlength' => 60,
    '#default_value' => $txn_user->name,
    '#autocomplete_path' => 'user/autocomplete',
    '#description' => t('Drupal User ID for the user you want the points to affect'),
  );
  $form['points'] = array(
    '#type' => 'textfield',
    '#title' => t('Points'),
    '#size' => 10,
    '#maxlength' => 10,
    '#default_value' => $txn->points,
    '#description' => t('Number of points to add/subtract from the user. For example, 25 (to add points) or -25 (to subtract points).'),
  );
  $form['time_stamp'] = array(
    '#type' => 'textfield',
    '#title' => t('Date/Time'),
    '#default_value' => $timestamp,
    '#size' => 30,
    '#maxlength' => 30,
    '#description' => t('Date and time of this transaction, in the form YYYY-MM-DD HH:MM +ZZZZ'),
  );
  $form['description'] = array(
    '#type' => 'textarea',
    '#title' => t('Description'),
    '#default_value' => $txn->description,
    '#width' => 70,
    '#lines' => 5,
    '#description' => t('Enter an optional description for this transaction, such as the reason it is created.'),
  );
  $form['reference'] = array(
    '#type' => 'textfield',
    '#title' => t('Reference'),
    '#default_value' => $txn->reference,
    '#size' => 30,
    '#maxlength' => 128,
    '#description' => t('Enter optional reference for this transaction. This field will be indexed and searchable.'),
  );
  switch ($mode) {
    case 'add':
      $form['approver_uid'] = array(
        '#type' => 'hidden',
        '#value' => $user->uid,
      );
      $form['event'] = array(
        '#type' => 'hidden',
        '#value' => 'admin',
      );
      $form['status'] = array(
        '#type' => 'hidden',
        '#value' => USERPOINTS_TXN_STATUS_PENDING,
      );
      $form['mode'] = array(
        '#type' => 'hidden',
        '#value' => $mode,
      );
      break;
    case 'edit':
      $form['txn_user'] = array(
        '#type' => 'hidden',
        '#value' => $txn_user,
      );
      $form['approver_uid'] = array(
        '#type' => 'textfield',
        '#description' => t('Approver ID'),
        '#default_value' => $txn->approver_uid,
        '#size' => 10,
        '#maxlength' => 7,
        '#description' => t('The user ID of the person who approved this transaction. 0 means not yet approved.'),
      );
      $form['event'] = array(
        '#type' => 'textfield',
        '#description' => t('Event'),
        '#default_value' => $txn->event,
        '#size' => 20,
        '#maxlength' => 20,
        '#description' => t('The event type for this transaction. Normally, it is "admin".'),
      );
      $form['status'] = array(
        '#title' => t('Approval status'),
        '#type' => 'radios',
        '#options' => userpoints_txn_status(),
        '#description' => t('Approval status of the transaction.'),
        '#default_value' => $txn->status,
      );
      break;
  }
  $form['mode'] = array(
    '#type' => 'hidden',
    '#default_value' => $mode,
  );
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Save'),
  );
  return $form;
}