";
echo "
\n";
echo "
";
$settled = authorize_settled($order);
$status = authorize_get_status_action($order);
$table->data[] = array("
$authstrs->paymentmethod:",
($order->paymentmethod == AN_METHOD_CC ? $authstrs->methodcc : $authstrs->methodecheck));
$table->data[] = array("
$authstrs->orderid:", $orderno);
$table->data[] = array("
$authstrs->transid:", $order->transid);
$table->data[] = array("
$authstrs->amount:", "$order->currency $order->amount");
if (empty($cmdcapture) and empty($cmdrefund) and empty($cmdvoid) and empty($cmddelete)) {
$color = authorize_get_status_color($status->status);
$table->data[] = array("
$strs->course:", format_string($course->shortname));
$table->data[] = array("
$strs->status:", "
" . $authstrs->{$status->status} . "");
if ($order->paymentmethod == AN_METHOD_CC) {
$table->data[] = array("
$authstrs->nameoncard:", $order->ccname);
}
else {
$table->data[] = array("
$authstrs->echeckfirslasttname:", $order->ccname);
}
$table->data[] = array("
$strs->time:", userdate($order->timecreated));
$table->data[] = array("
$authstrs->settlementdate:", $settled ?
userdate($order->settletime) : $authstrs->notsettled);
}
$table->data[] = array(" ", "
\n");
if (!empty($cmdcapture) and confirm_sesskey()) { // CAPTURE
if (!in_array(ORDER_CAPTURE, $status->actions)) {
$a = new stdClass;
$a->action = $authstrs->capture;
print_error('youcantdo', 'enrol_authorize', '', $a);
}
if (empty($confirm)) {
$strcaptureyes = get_string('captureyes', 'enrol_authorize');
$table->data[] = array("
$strs->confirm:",
"$strcaptureyes
$strs->no");
}
else {
$message = '';
$extra = NULL;
if (AN_APPROVED != authorize_action($order, $message, $extra, AN_ACTION_PRIOR_AUTH_CAPTURE)) {
$table->data[] = array("
$strs->error:", $message);
}
else {
if (empty($CFG->an_test)) {
$user = get_record('user', 'id', $order->userid);
if (enrol_into_course($course, $user, 'authorize')) {
if (!empty($CFG->enrol_mailstudents)) {
send_welcome_messages($order->id);
}
redirect("index.php?order=$orderno");
}
else {
$table->data[] = array("
$strs->error:",
"Error while trying to enrol ".fullname($user)." in '" . format_string($course->shortname) . "'");
}
}
else {
$table->data[] = array(get_string('testmode', 'enrol_authorize'),
get_string('testwarning', 'enrol_authorize'));
}
}
}
print_table($table);
}
elseif (!empty($cmdrefund) and confirm_sesskey()) { // REFUND
if (!in_array(ORDER_REFUND, $status->actions)) {
$a = new stdClass;
$a->action = $authstrs->refund;
print_error('youcantdo', 'enrol_authorize', '', $a);
}
$refunded = 0.0;
$sql = "SELECT SUM(amount) AS refunded FROM {$CFG->prefix}enrol_authorize_refunds " .
"WHERE (orderid = '" . $orderno . "') AND (status = '" . AN_STATUS_CREDIT . "')";
if (($refundval = get_field_sql($sql))) {
$refunded = floatval($refundval);
}
$upto = round($order->amount - $refunded, 2);
if ($upto <= 0) {
error("Refunded to original amount.");
}
else {
$amount = round(optional_param('amount', $upto), 2);
if (($amount > $upto) or empty($confirm)) {
$a = new stdClass;
$a->upto = $upto;
$strcanbecredit = get_string('canbecredit', 'enrol_authorize', $a);
$strhowmuch = get_string('howmuch', 'enrol_authorize');
$cbunenrol = print_checkbox('unenrol', '1', !empty($unenrol), '', '', '', true);
$table->data[] = array("
$authstrs->unenrolstudent", $cbunenrol);
$table->data[] = array("
$strhowmuch",
"
$strcanbecredit
");
}
else {
$extra = new stdClass;
$extra->orderid = $orderno;
$extra->amount = $amount;
$message = '';
$success = authorize_action($order, $message, $extra, AN_ACTION_CREDIT);
if (AN_APPROVED == $success || AN_REVIEW == $success) {
if (empty($CFG->an_test)) {
if (empty($extra->id)) {
$table->data[] = array("
$strs->error:", 'insert record error');
}
else {
if (!empty($unenrol)) {
role_unassign(0, $order->userid, 0, $coursecontext->id);
}
redirect("index.php?order=$orderno");
}
}
else {
$table->data[] = array(get_string('testmode', 'enrol_authorize'),
get_string('testwarning', 'enrol_authorize'));
}
}
else {
$table->data[] = array("
$strs->error:", $message);
}
}
}
print_table($table);
}
elseif (!empty($cmdvoid) and confirm_sesskey()) { // VOID
$suborderno = optional_param('suborder', 0, PARAM_INT);
if (empty($suborderno)) { // cancel original transaction.
if (!in_array(ORDER_VOID, $status->actions)) {
$a = new stdClass;
$a->action = $authstrs->void;
print_error('youcantdo', 'enrol_authorize', '', $a);
}
if (empty($confirm)) {
$strvoidyes = get_string('voidyes', 'enrol_authorize');
$table->data[] = array("
$strs->confirm:",
"$strvoidyes
$strs->no");
}
else {
$extra = NULL;
$message = '';
if (AN_APPROVED == authorize_action($order, $message, $extra, AN_ACTION_VOID)) {
if (empty($CFG->an_test)) {
redirect("index.php?order=$orderno");
}
else {
$table->data[] = array(get_string('testmode', 'enrol_authorize'),
get_string('testwarning', 'enrol_authorize'));
}
}
else {
$table->data[] = array("
$strs->error:", $message);
}
}
}
else { // cancel refunded transaction
$sql = "SELECT r.*, e.courseid, e.paymentmethod FROM {$CFG->prefix}enrol_authorize_refunds r " .
"INNER JOIN {$CFG->prefix}enrol_authorize e ON r.orderid = e.id " .
"WHERE r.id = '$suborderno' AND r.orderid = '$orderno' AND r.status = '" .AN_STATUS_CREDIT. "'";
$suborder = get_record_sql($sql);
if (!$suborder) { // not found
error("Transaction can not be voided because of already been voided.");
}
else {
$refundedstatus = authorize_get_status_action($suborder);
if (!in_array(ORDER_VOID, $refundedstatus->actions)) {
$a = new stdClass;
$a->action = $authstrs->void;
print_error('youcantdo', 'enrol_authorize', '', $a);
}
unset($suborder->courseid);
if (empty($confirm)) {
$a = new stdClass;
$a->transid = $suborder->transid;
$a->amount = $suborder->amount;
$strsubvoidyes = get_string('subvoidyes', 'enrol_authorize', $a);
$cbunenrol = print_checkbox('unenrol', '1', !empty($unenrol), '', '', '', true);
$table->data[] = array("
$authstrs->unenrolstudent", $cbunenrol);
$table->data[] = array("
$strs->confirm:",
"$strsubvoidyes
$strs->no");
}
else {
$message = '';
$extra = NULL;
if (AN_APPROVED == authorize_action($suborder, $message, $extra, AN_ACTION_VOID)) {
if (empty($CFG->an_test)) {
if (!empty($unenrol)) {
role_unassign(0, $order->userid, 0, $coursecontext->id);
}
redirect("index.php?order=$orderno");
}
else {
$table->data[] = array(get_string('testmode', 'enrol_authorize'),
get_string('testwarning', 'enrol_authorize'));
}
}
else {
$table->data[] = array("
$strs->error:", $message);
}
}
}
}
print_table($table);
}
elseif (!empty($cmddelete) and confirm_sesskey()) { // DELETE
if (!in_array(ORDER_DELETE, $status->actions)) {
$a = new stdClass;
$a->action = $authstrs->delete;
print_error('youcantdo', 'enrol_authorize', '', $a);
}
if (empty($confirm)) {
$cbunenrol = print_checkbox('unenrol', '1', !empty($unenrol), '', '', '', true);
$table->data[] = array("
$authstrs->unenrolstudent", $cbunenrol);
$table->data[] = array("
$strs->confirm:",
"
$strs->no");
}
else {
if (!empty($unenrol)) {
role_unassign(0, $order->userid, 0, $coursecontext->id);
}
delete_records('enrol_authorize', 'id', $orderno);
redirect("index.php");
}
print_table($table);
}
else { // SHOW
$actions = '';
if (empty($status->actions)) {
if (($order->paymentmethod == AN_METHOD_ECHECK) && has_capability('enrol/authorize:uploadcsv', get_context_instance(CONTEXT_USER, $USER->id))) {
$actions .= '
'.get_string('uploadcsv', 'enrol_authorize').'';
}
else {
$actions .= $strs->none;
}
}
else {
foreach ($status->actions as $value) {
$actions .= "
";
}
}
$table->data[] = array("
$strs->action", $actions);
print_table($table);
if ($settled) { // show refunds.
$t2 = new stdClass;
$t2->size = array('45%', '15%', '20%', '10%', '10%');
$t2->align = array('right', 'right', 'right', 'right', 'right');
$t2->head = array($authstrs->settlementdate,
$authstrs->transid,
$strs->status,
$strs->action,
$authstrs->amount);
$sql = "SELECT r.*, e.courseid, e.paymentmethod FROM {$CFG->prefix}enrol_authorize_refunds r " .
"INNER JOIN {$CFG->prefix}enrol_authorize e ON r.orderid = e.id " .
"WHERE r.orderid = '$orderno'";
$refunds = get_records_sql($sql);
if ($refunds) {
$sumrefund = floatval(0.0);
foreach ($refunds as $rf) {
$substatus = authorize_get_status_action($rf);
$subactions = ' ';
if (empty($substatus->actions)) {
$subactions .= $strs->none;
}
else {
foreach ($substatus->actions as $vl) {
$subactions .=
"
{$authstrs->$vl} ";
}
}
$sign = '';
$color = authorize_get_status_color($substatus->status);
if ($substatus->status == 'refunded' or $substatus->status == 'settled') {
$sign = '-';
$sumrefund += floatval($rf->amount);
}
$t2->data[] = array(
userdate($rf->settletime),
$rf->transid,
"
" .$authstrs->{$substatus->status} . "",
$subactions,
format_float($sign . $rf->amount, 2)
);
}
$t2->data[] = array('','',get_string('total'),$order->currency,format_float('-'.$sumrefund, 2));
}
else {
$t2->data[] = array('','',get_string('noreturns', 'enrol_authorize'),'','');
}
echo "
" . get_string('returns', 'enrol_authorize') . "
\n";
print_table($t2);
}
}
echo '
';
echo '