function uc_recurring_admin_edit_form_submit in UC Recurring Payments and Subscriptions 6.2
Same name and namespace in other branches
- 6 uc_recurring.admin.inc \uc_recurring_admin_edit_form_submit()
- 7.2 uc_recurring.admin.inc \uc_recurring_admin_edit_form_submit()
File
- ./
uc_recurring.admin.inc, line 278 - Recurring payments administration page callbacks and form builder functions.
Code
function uc_recurring_admin_edit_form_submit($form, &$form_state) {
global $user;
$rfid = $form_state['values']['rfid'];
$fee = uc_recurring_fee_user_load($rfid);
$member = user_load($fee->uid);
$interval = $form_state['values']['regular_interval_value'] . ' ' . $form_state['values']['regular_interval_unit'];
$number_intervals = empty($form_state['values']['unlimited_intervals']) ? $form_state['values']['number_intervals'] : UC_RECURRING_UNLIMITED_INTERVALS;
$fee_amount = $form_state['values']['fee_amount'];
$fee_title = $form_state['values']['fee_title'];
$fee_status = $form_state['values']['fee_status'];
$next_charge = $fee->next_charge;
if ($form_state['values']['reset_next_charge']) {
$next_charge = strtotime('+' . $interval);
}
else {
if (!empty($form_state['values']['next_charge_time'])) {
$next_charge = strtotime($form_state['values']['next_charge_time']);
}
else {
if (!empty($form_state['values']['next_charge_date'])) {
extract($form_state['values']['next_charge_date']);
$hour = date('H', $fee->next_charge);
$min = date('i', $fee->next_charge);
$sec = date('s', $fee->next_charge);
$next_charge = mktime($hour, $min, $sec, $month, $day, $year);
}
}
}
$status = $fee->status;
if ($fee->status != UC_RECURRING_FEE_STATUS_ACTIVE && $number_intervals != 0) {
$status = UC_RECURRING_FEE_STATUS_ACTIVE;
}
// todo - replace with a drupal_write_record()
db_query("UPDATE {uc_recurring_users} SET fee_title = '%s', fee_amount = %f, regular_interval = '%s', " . "remaining_intervals = %d, next_charge = %d, status = %d WHERE rfid = %d", $fee_title, $fee_amount, $interval, $number_intervals, $next_charge, $status, $rfid);
$context = array(
'revision' => 'themed-original',
'location' => 'recurring-admin',
);
drupal_set_message(t('The changes to <a href="@user-link">@user</a> recurring fee @rfid (@title) has been saved. The next charge of !fee_amount will be on @date.', array(
'@user' => $member->name,
'@user-link' => url('user/' . $member->uid),
'@rfid' => $rfid,
'@title' => $fee_title,
'!fee_amount' => uc_price($fee_amount, $context),
'@date' => format_date($next_charge),
)));
// Fee was already cancelled and now has been resumed, add a comment to the order.
if ($fee->status != $status && $status == UC_RECURRING_FEE_STATUS_ACTIVE) {
uc_order_comment_save($fee->order_id, $user->uid, t('<a href="@user-link">@user</a> resumed the recurring fee <a href="@fee-link">@fee</a>.', array(
'@user-link' => url('user/' . $user->uid),
'@user' => $user->name,
'@fee-link' => url('admin/store/orders/recurring/view/fee/' . $rfid),
'@fee' => $rfid,
)));
}
// If the number of intervals was set to zero then also call cancel.
if ($fee->status == UC_RECURRING_FEE_STATUS_ACTIVE && $number_intervals == 0) {
uc_recurring_fee_cancel($rfid, $fee);
}
}