function userpoints_admin_txn in User Points 6
Same name and namespace in other branches
- 5.3 userpoints.module \userpoints_admin_txn()
- 5 userpoints.module \userpoints_admin_txn()
- 5.2 userpoints.module \userpoints_admin_txn()
- 7.2 userpoints.admin.inc \userpoints_admin_txn()
- 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 1097
Code
function userpoints_admin_txn($form_state) {
global $user;
$mode = arg(3);
$timestamp = format_date(time(), 'custom', 'Y-m-d H:i O');
if ($mode == 'edit' && arg(4)) {
$txn_id = (int) arg(4);
$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');
$txn_user = user_load(array(
'uid' => $txn->uid,
));
}
elseif ($mode == 'add' && arg(4)) {
$uid = (int) arg(4);
$txn_user = user_load(array(
'uid' => $uid,
));
}
$form['txn_user'] = array(
'#type' => 'textfield',
'#title' => t('User Name'),
'#size' => 30,
'#maxlength' => 60,
'#default_value' => !empty($txn_user->name) ? $txn_user->name : '',
'#autocomplete_path' => 'user/autocomplete',
'#description' => t('User Name for the user you want the !points to affect', userpoints_translation()),
);
$form['points'] = array(
'#type' => 'textfield',
'#title' => t('Points'),
'#size' => 10,
'#maxlength' => 10,
'#default_value' => isset($txn->points) ? $txn->points : 0,
'#description' => t('Number of !points to add/subtract from the user. For example, 25 (to add !points) or -25 (to subtract !points).', userpoints_translation()),
);
$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'),
);
if (!empty($txn->txn_id)) {
if (!empty($txn->expirydate)) {
$expirydate = format_date($txn->expirydate, 'custom', 'Y-m-d H:i O');
}
}
else {
//If we're not editing we use site defaults
$expirydate = userpoints_get_default_expiry_date();
if ($expirydate) {
$expirydate = format_date($expirydate, 'custom', 'Y-m-d H:i O');
}
}
$form['expirydate'] = array(
'#type' => 'textfield',
'#title' => t('Expiration date'),
'#default_value' => $expirydate,
'#size' => 30,
'#maxlength' => 30,
'#description' => t('Date and time to expire these !points, in the form YYYY-MM-DD HH:MM +ZZZZ', userpoints_translation()) . '<br />' . t('Leave blank for non-expiring !points', userpoints_translation()),
);
if (module_exists('taxonomy')) {
$form['tid'] = array(
'#type' => 'select',
'#title' => t('Category'),
'#default_value' => variable_get(USERPOINTS_CATEGORY_DEFAULT_TID, 0),
'#options' => userpoints_get_categories(),
'#description' => t('Category to apply these !points to', userpoints_translation()),
);
}
$form['reference'] = array(
'#type' => 'textfield',
'#title' => t('Reference'),
'#default_value' => !empty($txn->reference) ? $txn->reference : '',
'#size' => 30,
'#maxlength' => 128,
'#description' => t('Enter optional reference for this transaction. This field will be indexed and searchable.'),
);
$form['description'] = array(
'#type' => 'textarea',
'#title' => t('Description'),
'#default_value' => !empty($txn->description) ? $txn->description : '',
'#width' => 70,
'#lines' => 5,
'#description' => t('Enter an optional description for this transaction, such as the reason it is created.'),
);
switch ($mode) {
case 'add':
$form['approver_uid'] = array(
'#type' => 'hidden',
'#value' => $user->uid,
);
$form['operation'] = 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']['#disabled'] = TRUE;
unset($form['txn_user']['#autocomplete_path']);
$form['txn_uid'] = array(
'#type' => 'value',
'#value' => $txn->uid,
);
$form['txn_id'] = array(
'#type' => 'value',
'#value' => $txn_id,
);
$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['operation'] = array(
'#type' => 'textfield',
'#description' => t('Operation'),
'#default_value' => $txn->operation,
'#size' => 20,
'#maxlength' => 20,
'#description' => t('The operation 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;
}