2006-08-30 10:29:10 +00:00
|
|
|
<?php // $Id$
|
2006-03-27 08:31:16 +00:00
|
|
|
|
2006-04-26 16:03:16 +00:00
|
|
|
if (!defined('MOODLE_INTERNAL')) {
|
2006-05-12 19:56:02 +00:00
|
|
|
die('Direct access to this script is forbidden.');
|
2006-04-26 16:03:16 +00:00
|
|
|
}
|
2006-04-24 17:15:13 +00:00
|
|
|
|
2006-04-26 16:03:16 +00:00
|
|
|
require_once('const.php');
|
2006-05-17 08:18:51 +00:00
|
|
|
require_once('authorizenetlib.php');
|
2006-03-27 08:31:16 +00:00
|
|
|
|
|
|
|
define('ORDER_CAPTURE', 'capture');
|
|
|
|
define('ORDER_DELETE', 'delete');
|
|
|
|
define('ORDER_REFUND', 'refund');
|
|
|
|
define('ORDER_VOID', 'void');
|
|
|
|
|
2006-04-05 05:28:56 +00:00
|
|
|
/**
|
2006-04-11 12:37:41 +00:00
|
|
|
* authorize_print_orders
|
2006-04-05 05:28:56 +00:00
|
|
|
*
|
|
|
|
*/
|
2006-09-15 12:35:08 +00:00
|
|
|
function authorize_print_orders($courseid, $userid)
|
2006-03-27 08:31:16 +00:00
|
|
|
{
|
|
|
|
global $CFG, $USER;
|
|
|
|
global $strs, $authstrs;
|
2006-06-01 08:51:20 +00:00
|
|
|
require_once($CFG->libdir.'/tablelib.php');
|
2006-03-27 08:31:16 +00:00
|
|
|
|
|
|
|
$perpage = 10;
|
|
|
|
$status = optional_param('status', AN_STATUS_NONE, PARAM_INT);
|
2006-10-16 09:39:08 +00:00
|
|
|
$searchtype = optional_param('searchtype', 'id', PARAM_ALPHA);
|
|
|
|
$idortransid = optional_param('idortransid', '0', PARAM_INT);
|
2006-03-27 08:31:16 +00:00
|
|
|
|
2006-09-15 11:40:37 +00:00
|
|
|
if (! has_capability('enrol/authorize:managepayments', get_context_instance(CONTEXT_COURSE, $courseid))) {
|
2006-03-27 08:31:16 +00:00
|
|
|
$userid = $USER->id;
|
|
|
|
}
|
|
|
|
|
|
|
|
$baseurl = $CFG->wwwroot."/enrol/authorize/index.php?user=$userid";
|
2006-04-24 16:46:39 +00:00
|
|
|
$statusmenu = array(AN_STATUS_NONE => $strs->all,
|
2006-03-27 08:31:16 +00:00
|
|
|
AN_STATUS_AUTH => $authstrs->authorizedpendingcapture,
|
|
|
|
AN_STATUS_AUTHCAPTURE => $authstrs->authcaptured,
|
|
|
|
AN_STATUS_CREDIT => $authstrs->refunded,
|
|
|
|
AN_STATUS_VOID => $authstrs->cancelled,
|
2006-05-12 19:56:02 +00:00
|
|
|
AN_STATUS_EXPIRE => $authstrs->expired,
|
2006-10-16 09:39:08 +00:00
|
|
|
AN_STATUS_UNDERREVIEW => $authstrs->underreview,
|
|
|
|
AN_STATUS_APPROVEDREVIEW => $authstrs->approvedreview,
|
|
|
|
AN_STATUS_REVIEWFAILED => $authstrs->reviewfailed,
|
2006-05-12 19:56:02 +00:00
|
|
|
AN_STATUS_TEST => $authstrs->tested
|
2006-03-27 08:31:16 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
if ($courses = get_courses('all', 'c.sortorder ASC', 'c.id,c.fullname,c.enrol')) {
|
|
|
|
$popupcrs = array();
|
|
|
|
foreach ($courses as $crs) {
|
|
|
|
if ($crs->enrol == 'authorize' || (empty($crs->enrol) && $CFG->enrol == 'authorize')) {
|
2006-05-12 19:56:02 +00:00
|
|
|
$popupcrs[intval($crs->id)] = $crs->fullname;
|
2006-03-27 08:31:16 +00:00
|
|
|
}
|
|
|
|
}
|
2006-05-12 19:56:02 +00:00
|
|
|
if (!empty($popupcrs)) {
|
2006-10-16 09:39:08 +00:00
|
|
|
echo "<table border='0' width='100%' cellspacing=0 cellpadding=3 class='generaltable generalbox'>";
|
|
|
|
echo "<tr>";
|
|
|
|
echo "<td width='5%'>$strs->status: </td><td width='10%'>";popup_form($baseurl.'&course='.$courseid.'&status=',$statusmenu,'statusmenu',$status,'','','',false);echo"</td>\n";
|
|
|
|
echo "<td width='5%'>$strs->course: </td><td width='10%'>";popup_form($baseurl.'&status='.$status.'&course=',$popupcrs,'coursesmenu',$courseid,'','','',false);echo"</td>\n";
|
|
|
|
if (has_capability('enrol/authorize:uploadcsv', get_context_instance(CONTEXT_USER, $USER->id))) {
|
|
|
|
echo "<form method='get' action='uploadcsv.php'>";
|
|
|
|
echo "<td rowspan=2 align='center' valign='middle' width='50%'><input type='submit' value='".get_string('uploadcsv', 'enrol_authorize')."'></td>";
|
|
|
|
echo "</form>";
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
echo "<td rowspan=2 width='100%'> </td>";
|
|
|
|
}
|
|
|
|
echo "</tr>\n";
|
|
|
|
|
|
|
|
echo "<tr><td>$strs->search: </td>"; $searchmenu = array('id' => $authstrs->orderid, 'transid' => $authstrs->transid);
|
|
|
|
echo "<form method='POST' action='index.php' autocomplete='off'>";
|
|
|
|
echo "<td colspan=3>"; choose_from_menu($searchmenu, 'searchtype', $searchtype, '');
|
|
|
|
echo " = <input type='text' size='14' name='idortransid' value='' /> ";
|
|
|
|
echo "<input type='submit' value='$strs->search' /></td>";
|
|
|
|
echo "</form>";
|
|
|
|
echo "</tr>";
|
|
|
|
echo "</table>";
|
2006-05-12 19:56:02 +00:00
|
|
|
}
|
2006-03-27 08:31:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$table = new flexible_table('enrol-authorize');
|
|
|
|
$table->set_attribute('width', '100%');
|
|
|
|
$table->set_attribute('cellspacing', '0');
|
|
|
|
$table->set_attribute('cellpadding', '3');
|
|
|
|
$table->set_attribute('id', 'orders');
|
|
|
|
$table->set_attribute('class', 'generaltable generalbox');
|
|
|
|
|
|
|
|
$table->define_columns(array('id', 'timecreated', 'userid', 'status', ''));
|
2006-06-09 11:00:18 +00:00
|
|
|
$table->define_headers(array($authstrs->orderid, $strs->time, $authstrs->nameoncard, $strs->status, $strs->action));
|
2006-03-27 08:31:16 +00:00
|
|
|
$table->define_baseurl($baseurl."&status=$status");
|
|
|
|
|
2006-05-12 19:56:02 +00:00
|
|
|
$table->sortable(true, 'id', SORT_DESC);
|
2006-03-27 08:31:16 +00:00
|
|
|
$table->pageable(true);
|
|
|
|
$table->setup();
|
|
|
|
|
2006-09-15 11:40:37 +00:00
|
|
|
$select = "SELECT e.id, e.paymentmethod, e.transid, e.courseid, e.userid, e.status, e.ccname, e.timecreated, e.settletime ";
|
|
|
|
$from = "FROM {$CFG->prefix}enrol_authorize e ";
|
2006-06-01 08:51:20 +00:00
|
|
|
$where = "WHERE (1=1) ";
|
2006-03-27 08:31:16 +00:00
|
|
|
|
|
|
|
if ($status > AN_STATUS_NONE) {
|
2006-05-13 08:33:55 +00:00
|
|
|
switch ($status)
|
|
|
|
{
|
|
|
|
case AN_STATUS_CREDIT:
|
2006-09-15 12:05:27 +00:00
|
|
|
$from .= "INNER JOIN {$CFG->prefix}enrol_authorize_refunds r ON e.id = r.orderid ";
|
2006-09-15 11:40:37 +00:00
|
|
|
$where .= "AND (e.status = '" . AN_STATUS_AUTHCAPTURE . "') ";
|
2006-06-01 08:51:20 +00:00
|
|
|
break;
|
2006-05-13 08:33:55 +00:00
|
|
|
|
|
|
|
case AN_STATUS_TEST:
|
2006-06-01 08:51:20 +00:00
|
|
|
$newordertime = time() - 120; // -2 minutes. Order may be still in process.
|
2006-09-15 11:40:37 +00:00
|
|
|
$where .= "AND (e.status = '" . AN_STATUS_NONE . "') AND (e.transid = '0') AND (e.timecreated < $newordertime) ";
|
2006-06-01 08:51:20 +00:00
|
|
|
break;
|
2006-05-13 08:33:55 +00:00
|
|
|
|
|
|
|
default:
|
2006-09-15 11:40:37 +00:00
|
|
|
$where .= "AND (e.status = '$status') ";
|
2006-06-01 08:51:20 +00:00
|
|
|
break;
|
2006-03-27 08:31:16 +00:00
|
|
|
}
|
|
|
|
}
|
2006-06-01 08:51:20 +00:00
|
|
|
else {
|
2006-03-27 08:31:16 +00:00
|
|
|
if (empty($CFG->an_test)) {
|
2006-09-15 11:40:37 +00:00
|
|
|
$where .= "AND (e.status != '" . AN_STATUS_NONE . "') ";
|
2006-03-27 08:31:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($courseid != SITEID) {
|
2006-09-15 11:40:37 +00:00
|
|
|
$where .= "AND (e.courseid = '" . $courseid . "') ";
|
2006-03-27 08:31:16 +00:00
|
|
|
}
|
|
|
|
|
2006-10-16 09:39:08 +00:00
|
|
|
if (!empty($idortransid)) {
|
|
|
|
// Ignore old where.
|
|
|
|
if ($searchtype == 'transid') {
|
|
|
|
$where = "WHERE (e.transid = $idortransid) ";
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$where = "WHERE (e.id = $idortransid) ";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// This must be always last where!!!
|
|
|
|
if ($userid > 0) {
|
|
|
|
$where .= "AND (e.userid = '" . $userid . "') ";
|
|
|
|
}
|
|
|
|
|
2006-03-27 08:31:16 +00:00
|
|
|
if ($sort = $table->get_sql_sort()) {
|
|
|
|
$sort = ' ORDER BY ' . $sort;
|
|
|
|
}
|
|
|
|
|
|
|
|
$totalcount = count_records_sql('SELECT COUNT(*) ' . $from . $where);
|
|
|
|
$table->initialbars($totalcount > $perpage);
|
|
|
|
$table->pagesize($perpage, $totalcount);
|
|
|
|
if ($table->get_page_start() !== '' && $table->get_page_size() !== '') {
|
|
|
|
$limit = ' ' . sql_paging_limit($table->get_page_start(), $table->get_page_size());
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$limit = '';
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($records = get_records_sql($select . $from . $where . $sort . $limit)) {
|
|
|
|
foreach ($records as $record) {
|
2006-04-11 12:37:41 +00:00
|
|
|
$actionstatus = authorize_get_status_action($record);
|
2006-08-18 17:10:30 +00:00
|
|
|
$color = authorize_get_status_color($actionstatus->status);
|
2006-03-27 08:31:16 +00:00
|
|
|
$actions = '';
|
|
|
|
|
|
|
|
if (empty($actionstatus->actions)) {
|
|
|
|
$actions .= $strs->none;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
foreach ($actionstatus->actions as $value) {
|
2006-05-16 15:34:24 +00:00
|
|
|
$actions .= " <a href='index.php?$value=y&sesskey=$USER->sesskey&order=$record->id'>{$authstrs->$value}</a> ";
|
2006-03-27 08:31:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$table->add_data(array(
|
|
|
|
"<a href='index.php?order=$record->id'>$record->id</a>",
|
|
|
|
userdate($record->timecreated),
|
|
|
|
$record->ccname,
|
2006-08-18 17:10:30 +00:00
|
|
|
"<font style='color:$color'>" . $authstrs->{$actionstatus->status} . "</font>",
|
2006-03-27 08:31:16 +00:00
|
|
|
$actions
|
|
|
|
));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$table->print_html();
|
|
|
|
}
|
|
|
|
|
2006-04-05 05:28:56 +00:00
|
|
|
/**
|
2006-04-11 12:37:41 +00:00
|
|
|
* authorize_print_order_details
|
2006-04-05 05:28:56 +00:00
|
|
|
*
|
|
|
|
* @param int $orderno
|
|
|
|
*/
|
2006-04-11 12:37:41 +00:00
|
|
|
function authorize_print_order_details($orderno)
|
2006-04-07 11:23:10 +00:00
|
|
|
{
|
2006-03-27 08:31:16 +00:00
|
|
|
global $CFG, $USER;
|
|
|
|
global $strs, $authstrs;
|
|
|
|
|
2006-04-05 05:28:56 +00:00
|
|
|
$cmdcapture = optional_param(ORDER_CAPTURE, '', PARAM_ALPHA);
|
|
|
|
$cmddelete = optional_param(ORDER_DELETE, '', PARAM_ALPHA);
|
|
|
|
$cmdrefund = optional_param(ORDER_REFUND, '', PARAM_ALPHA);
|
|
|
|
$cmdvoid = optional_param(ORDER_VOID, '', PARAM_ALPHA);
|
2006-03-27 08:31:16 +00:00
|
|
|
|
2006-06-01 08:51:20 +00:00
|
|
|
$unenrol = optional_param('unenrol', 0, PARAM_BOOL);
|
|
|
|
$confirm = optional_param('confirm', 0, PARAM_BOOL);
|
2006-04-05 10:08:57 +00:00
|
|
|
|
2006-06-01 08:51:20 +00:00
|
|
|
$table = new stdClass;
|
2006-03-27 08:31:16 +00:00
|
|
|
$table->width = '100%';
|
|
|
|
$table->size = array('30%', '70%');
|
|
|
|
$table->align = array('right', 'left');
|
|
|
|
|
2006-10-03 18:00:48 +00:00
|
|
|
$order = get_record('enrol_authorize', 'id', $orderno);
|
2006-03-27 08:31:16 +00:00
|
|
|
if (!$order) {
|
|
|
|
notice("Order $orderno not found.", "index.php");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2006-09-22 12:18:58 +00:00
|
|
|
$course = get_record('course', 'id', $order->courseid);
|
|
|
|
$coursecontext = get_context_instance(CONTEXT_COURSE, $course->id);
|
2006-09-18 17:32:43 +00:00
|
|
|
|
2006-03-27 08:31:16 +00:00
|
|
|
if ($USER->id != $order->userid) { // Current user viewing someone else's order
|
2006-10-16 09:39:08 +00:00
|
|
|
require_capability('enrol/authorize:managepayments', $coursecontext);
|
2006-03-27 08:31:16 +00:00
|
|
|
}
|
|
|
|
|
2006-05-16 15:34:24 +00:00
|
|
|
echo "<form action=\"index.php\" method=\"post\">\n";
|
|
|
|
echo "<input type=\"hidden\" name=\"order\" value=\"$orderno\">\n";
|
2006-05-18 07:55:12 +00:00
|
|
|
echo "<input type=\"hidden\" name=\"sesskey\" value=\"" . sesskey() . "\" />";
|
2006-03-27 08:31:16 +00:00
|
|
|
|
2006-07-10 10:17:23 +00:00
|
|
|
$settled = authorize_settled($order);
|
2006-04-11 12:37:41 +00:00
|
|
|
$status = authorize_get_status_action($order);
|
2006-03-27 08:31:16 +00:00
|
|
|
|
2006-09-01 16:43:52 +00:00
|
|
|
$table->data[] = array("<b>$authstrs->paymentmethod:</b>",
|
|
|
|
($order->paymentmethod == AN_METHOD_CC ? $authstrs->methodcc : $authstrs->methodecheck));
|
2006-03-27 08:31:16 +00:00
|
|
|
$table->data[] = array("<b>$authstrs->orderid:</b>", $orderno);
|
|
|
|
$table->data[] = array("<b>$authstrs->transid:</b>", $order->transid);
|
|
|
|
$table->data[] = array("<b>$authstrs->amount:</b>", "$order->currency $order->amount");
|
2006-04-05 10:08:57 +00:00
|
|
|
if (empty($cmdcapture) and empty($cmdrefund) and empty($cmdvoid) and empty($cmddelete)) {
|
2006-08-18 17:10:30 +00:00
|
|
|
$color = authorize_get_status_color($status->status);
|
2006-10-03 18:00:48 +00:00
|
|
|
$table->data[] = array("<b>$strs->course:</b>", $course->shortname);
|
2006-08-18 17:10:30 +00:00
|
|
|
$table->data[] = array("<b>$strs->status:</b>", "<font style='color:$color'>" . $authstrs->{$status->status} . "</font>");
|
2006-09-01 16:43:52 +00:00
|
|
|
if ($order->paymentmethod == AN_METHOD_CC) {
|
|
|
|
$table->data[] = array("<b>$authstrs->nameoncard:</b>", $order->ccname);
|
|
|
|
}
|
|
|
|
else {
|
2006-09-01 17:16:08 +00:00
|
|
|
$table->data[] = array("<b>$authstrs->echeckfirslasttname:</b>", $order->ccname);
|
2006-09-01 16:43:52 +00:00
|
|
|
}
|
2006-03-27 08:31:16 +00:00
|
|
|
$table->data[] = array("<b>$strs->time:</b>", userdate($order->timecreated));
|
|
|
|
$table->data[] = array("<b>$authstrs->settlementdate:</b>", $settled ?
|
|
|
|
userdate($order->settletime) : $authstrs->notsettled);
|
|
|
|
}
|
|
|
|
$table->data[] = array(" ", "<hr size='1' noshade>\n");
|
|
|
|
|
2006-05-16 15:34:24 +00:00
|
|
|
if (!empty($cmdcapture) and confirm_sesskey()) { // CAPTURE
|
2006-03-27 08:31:16 +00:00
|
|
|
if (!in_array(ORDER_CAPTURE, $status->actions)) {
|
2006-06-01 08:51:20 +00:00
|
|
|
$a = new stdClass;
|
2006-04-05 08:28:12 +00:00
|
|
|
$a->action = $authstrs->capture;
|
2006-03-27 08:31:16 +00:00
|
|
|
error(get_string('youcantdo', 'enrol_authorize', $a));
|
|
|
|
}
|
|
|
|
|
2006-04-05 10:08:57 +00:00
|
|
|
if (empty($confirm)) {
|
2006-06-07 18:47:09 +00:00
|
|
|
$strcaptureyes = get_string('captureyes', 'enrol_authorize');
|
2006-03-27 08:31:16 +00:00
|
|
|
$table->data[] = array("<b>$strs->confirm:</b>",
|
2006-08-18 14:54:08 +00:00
|
|
|
"$strcaptureyes <br />
|
|
|
|
<input type='hidden' name='confirm' value='1'><input type='submit' name='". ORDER_CAPTURE ."' value='$authstrs->capture' />
|
|
|
|
<a href='index.php?order=$orderno'>$strs->no</a>");
|
2006-03-27 08:31:16 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
$message = '';
|
|
|
|
$extra = NULL;
|
2006-10-16 09:39:08 +00:00
|
|
|
if (AN_APPROVED != authorize_action($order, $message, $extra, AN_ACTION_PRIOR_AUTH_CAPTURE)) {
|
2006-03-27 08:31:16 +00:00
|
|
|
$table->data[] = array("<b><font color='red'>$strs->error:</font></b>", $message);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (empty($CFG->an_test)) {
|
2006-09-22 12:18:58 +00:00
|
|
|
$user = get_record('user', 'id', $order->userid);
|
|
|
|
if (enrol_into_course($course, $user, 'manual')) {
|
2006-10-16 09:39:08 +00:00
|
|
|
if (!empty($CFG->enrol_mailstudents)) {
|
|
|
|
send_welcome_messages($order->id);
|
|
|
|
}
|
2006-03-27 08:31:16 +00:00
|
|
|
redirect("index.php?order=$orderno");
|
|
|
|
}
|
|
|
|
else {
|
2006-09-22 12:18:58 +00:00
|
|
|
$table->data[] = array("<b><font color=red>$strs->error:</font></b>",
|
2006-10-03 18:00:48 +00:00
|
|
|
"Error while trying to enrol ".fullname($user)." in '$course->shortname'");
|
2006-03-27 08:31:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$table->data[] = array(get_string('testmode', 'enrol_authorize'),
|
|
|
|
get_string('testwarning', 'enrol_authorize'));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
print_table($table);
|
|
|
|
}
|
2006-05-16 15:34:24 +00:00
|
|
|
elseif (!empty($cmdrefund) and confirm_sesskey()) { // REFUND
|
2006-03-27 08:31:16 +00:00
|
|
|
if (!in_array(ORDER_REFUND, $status->actions)) {
|
2006-06-01 08:51:20 +00:00
|
|
|
$a = new stdClass;
|
2006-04-05 08:28:12 +00:00
|
|
|
$a->action = $authstrs->refund;
|
2006-03-27 08:31:16 +00:00
|
|
|
error(get_string('youcantdo', 'enrol_authorize', $a));
|
|
|
|
}
|
|
|
|
|
2006-06-01 08:51:20 +00:00
|
|
|
$extra = new stdClass;
|
2006-03-27 08:31:16 +00:00
|
|
|
$extra->sum = 0.0;
|
|
|
|
$extra->orderid = $orderno;
|
|
|
|
|
|
|
|
$sql = "SELECT SUM(amount) AS refunded FROM {$CFG->prefix}enrol_authorize_refunds " .
|
|
|
|
"WHERE (orderid = '" . $orderno . "') AND (status = '" . AN_STATUS_CREDIT . "')";
|
|
|
|
|
|
|
|
if ($refund = get_record_sql($sql)) {
|
|
|
|
$extra->sum = floatval($refund->refunded);
|
|
|
|
}
|
|
|
|
$upto = format_float($order->amount - $extra->sum, 2);
|
|
|
|
if ($upto <= 0) {
|
|
|
|
error("Refunded to original amount.");
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$amount = format_float(optional_param('amount', $upto), 2);
|
2006-06-01 08:51:20 +00:00
|
|
|
if (($amount > $upto) or empty($confirm)) {
|
|
|
|
$a = new stdClass;
|
2006-03-27 08:31:16 +00:00
|
|
|
$a->upto = $upto;
|
|
|
|
$strcanbecredit = get_string('canbecredit', 'enrol_authorize', $a);
|
2006-06-07 18:47:09 +00:00
|
|
|
$strhowmuch = get_string('howmuch', 'enrol_authorize');
|
2006-06-01 08:51:20 +00:00
|
|
|
$cbunenrol = print_checkbox('unenrol', '1', !empty($unenrol), '', '', '', true);
|
2006-05-18 07:55:12 +00:00
|
|
|
$table->data[] = array("<b>$authstrs->unenrolstudent</b>", $cbunenrol);
|
2006-06-07 18:47:09 +00:00
|
|
|
$table->data[] = array("<b>$strhowmuch</b>",
|
2006-06-01 08:51:20 +00:00
|
|
|
"<input type='hidden' name='confirm' value='1'>
|
2006-03-27 08:31:16 +00:00
|
|
|
<input type='text' size='5' name='amount' value='$amount'>
|
2006-04-05 05:28:56 +00:00
|
|
|
$strcanbecredit<br /><input type='submit' name='".ORDER_REFUND."' value='$authstrs->refund'>");
|
2006-03-27 08:31:16 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
$extra->amount = $amount;
|
|
|
|
$message = '';
|
2006-10-16 09:39:08 +00:00
|
|
|
if (AN_APPROVED == authorize_action($order, $message, $extra, AN_ACTION_CREDIT)) {
|
2006-03-27 08:31:16 +00:00
|
|
|
if (empty($CFG->an_test)) {
|
2006-05-12 19:56:02 +00:00
|
|
|
if (empty($extra->id)) {
|
* Update record as soon as possible. If update/insert record fails email to admin to have update manually.
* ignore_user_abort(true) at critical section (before fwrite($fp, "POST /gateway/transact.dll).
This is last change to ignore request for user.
* Made some functions "static" to call function directly. So, no need new enrolment_plugin_authorize() instance.
Now, these are static:
get_list_of_creditcards, zero_cost, get_course_cost, prevent_double_paid, email_to_admin, check_openssl_loaded
* Some mtrace cleanup. Removed default new line.
This is big work. When PHP5 is required for moodle in the future, I will add static modifier to functions.
Now and future, this plugin is/will unbreakable; Merged from MOODLE_16_STABLE. :)
2006-07-24 12:19:20 +00:00
|
|
|
$table->data[] = array("<b><font color=red>$strs->error:</font></b>", 'insert record error');
|
2006-03-27 08:31:16 +00:00
|
|
|
}
|
2006-05-12 19:56:02 +00:00
|
|
|
else {
|
|
|
|
if (!empty($unenrol)) {
|
2006-09-18 17:32:43 +00:00
|
|
|
role_unassign(0, $order->userid, 0, $coursecontext->id);
|
2006-05-12 19:56:02 +00:00
|
|
|
}
|
2006-05-16 15:02:52 +00:00
|
|
|
redirect("index.php?order=$orderno");
|
2006-03-27 08:31:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$table->data[] = array(get_string('testmode', 'enrol_authorize'),
|
|
|
|
get_string('testwarning', 'enrol_authorize'));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$table->data[] = array("<b><font color=red>$strs->error:</font></b>", $message);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
print_table($table);
|
|
|
|
}
|
2006-05-16 15:34:24 +00:00
|
|
|
elseif (!empty($cmdvoid) and confirm_sesskey()) { // VOID
|
2006-03-27 08:31:16 +00:00
|
|
|
$suborderno = optional_param('suborder', 0, PARAM_INT);
|
|
|
|
if (empty($suborderno)) { // cancel original transaction.
|
2006-08-17 15:43:54 +00:00
|
|
|
if (!in_array(ORDER_VOID, $status->actions)) {
|
|
|
|
$a = new stdClass;
|
|
|
|
$a->action = $authstrs->void;
|
|
|
|
error(get_string('youcantdo', 'enrol_authorize', $a));
|
|
|
|
}
|
2006-04-05 10:08:57 +00:00
|
|
|
if (empty($confirm)) {
|
2006-03-27 08:31:16 +00:00
|
|
|
$strvoidyes = get_string('voidyes', 'enrol_authorize');
|
|
|
|
$table->data[] = array("<b>$strs->confirm:</b>",
|
2006-04-05 05:28:56 +00:00
|
|
|
"$strvoidyes<br /><input type='hidden' name='".ORDER_VOID."' value='y'>
|
2006-06-01 08:51:20 +00:00
|
|
|
<input type='hidden' name='confirm' value='1'>
|
2006-08-18 14:54:08 +00:00
|
|
|
<input type='submit' value='$authstrs->void'>
|
2006-03-27 08:31:16 +00:00
|
|
|
<a href='index.php?order=$orderno'>$strs->no</a>");
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$extra = NULL;
|
|
|
|
$message = '';
|
2006-10-16 09:39:08 +00:00
|
|
|
if (AN_APPROVED == authorize_action($order, $message, $extra, AN_ACTION_VOID)) {
|
2006-03-27 08:31:16 +00:00
|
|
|
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("<b><font color='red'>$strs->error:</font></b>", $message);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else { // cancel refunded transaction
|
2006-09-15 12:05:27 +00:00
|
|
|
$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. "'";
|
2006-08-17 15:43:54 +00:00
|
|
|
|
|
|
|
$suborder = get_record_sql($sql);
|
2006-03-27 08:31:16 +00:00
|
|
|
if (!$suborder) { // not found
|
|
|
|
error("Transaction can not be voided because of already been voided.");
|
|
|
|
}
|
|
|
|
else {
|
2006-08-17 15:43:54 +00:00
|
|
|
$refundedstatus = authorize_get_status_action($suborder);
|
|
|
|
if (!in_array(ORDER_VOID, $refundedstatus->actions)) {
|
|
|
|
$a = new stdClass;
|
|
|
|
$a->action = $authstrs->void;
|
|
|
|
error(get_string('youcantdo', 'enrol_authorize', $a));
|
|
|
|
}
|
|
|
|
unset($suborder->courseid);
|
2006-04-05 10:08:57 +00:00
|
|
|
if (empty($confirm)) {
|
2006-06-01 08:51:20 +00:00
|
|
|
$a = new stdClass;
|
2006-03-27 08:31:16 +00:00
|
|
|
$a->transid = $suborder->transid;
|
|
|
|
$a->amount = $suborder->amount;
|
|
|
|
$strsubvoidyes = get_string('subvoidyes', 'enrol_authorize', $a);
|
2006-06-01 08:51:20 +00:00
|
|
|
$cbunenrol = print_checkbox('unenrol', '1', !empty($unenrol), '', '', '', true);
|
2006-05-18 07:55:12 +00:00
|
|
|
$table->data[] = array("<b>$authstrs->unenrolstudent</b>", $cbunenrol);
|
2006-03-27 08:31:16 +00:00
|
|
|
$table->data[] = array("<b>$strs->confirm:</b>",
|
2006-04-05 05:28:56 +00:00
|
|
|
"$strsubvoidyes<br /><input type='hidden' name='".ORDER_VOID."' value='y'>
|
2006-06-01 08:51:20 +00:00
|
|
|
<input type='hidden' name='confirm' value='1'>
|
2006-03-27 08:31:16 +00:00
|
|
|
<input type='hidden' name='suborder' value='$suborderno'>
|
2006-08-18 14:54:08 +00:00
|
|
|
<input type='submit' value='$authstrs->void'>
|
2006-03-27 08:31:16 +00:00
|
|
|
<a href='index.php?order=$orderno'>$strs->no</a>");
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$message = '';
|
|
|
|
$extra = NULL;
|
2006-10-16 09:39:08 +00:00
|
|
|
if (AN_APPROVED == authorize_action($suborder, $message, $extra, AN_ACTION_VOID)) {
|
2006-03-27 08:31:16 +00:00
|
|
|
if (empty($CFG->an_test)) {
|
|
|
|
if (!empty($unenrol)) {
|
2006-09-18 17:32:43 +00:00
|
|
|
role_unassign(0, $order->userid, 0, $coursecontext->id);
|
2006-03-27 08:31:16 +00:00
|
|
|
}
|
|
|
|
redirect("index.php?order=$orderno");
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$table->data[] = array(get_string('testmode', 'enrol_authorize'),
|
|
|
|
get_string('testwarning', 'enrol_authorize'));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$table->data[] = array("<b><font color='red'>$strs->error:</font></b>", $message);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
print_table($table);
|
|
|
|
}
|
2006-05-16 15:34:24 +00:00
|
|
|
elseif (!empty($cmddelete) and confirm_sesskey()) { // DELETE
|
2006-03-27 08:31:16 +00:00
|
|
|
if (!in_array(ORDER_DELETE, $status->actions)) {
|
2006-06-01 08:51:20 +00:00
|
|
|
$a = new stdClass;
|
2006-04-05 08:28:12 +00:00
|
|
|
$a->action = $authstrs->delete;
|
2006-03-27 08:31:16 +00:00
|
|
|
error(get_string('youcantdo', 'enrol_authorize', $a));
|
|
|
|
}
|
2006-04-05 10:08:57 +00:00
|
|
|
if (empty($confirm)) {
|
2006-06-01 08:51:20 +00:00
|
|
|
$cbunenrol = print_checkbox('unenrol', '1', !empty($unenrol), '', '', '', true);
|
2006-05-18 07:55:12 +00:00
|
|
|
$table->data[] = array("<b>$authstrs->unenrolstudent</b>", $cbunenrol);
|
2006-03-27 08:31:16 +00:00
|
|
|
$table->data[] = array("<b>$strs->confirm:</b>",
|
2006-04-05 05:28:56 +00:00
|
|
|
"<input type='hidden' name='".ORDER_DELETE."' value='y'>
|
2006-06-01 08:51:20 +00:00
|
|
|
<input type='hidden' name='confirm' value='1'>
|
2006-08-18 14:54:08 +00:00
|
|
|
<input type='submit' value='$authstrs->delete'>
|
2006-03-27 08:31:16 +00:00
|
|
|
<a href='index.php?order=$orderno'>$strs->no</a>");
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (!empty($unenrol)) {
|
2006-09-18 17:32:43 +00:00
|
|
|
role_unassign(0, $order->userid, 0, $coursecontext->id);
|
2006-03-27 08:31:16 +00:00
|
|
|
}
|
|
|
|
delete_records('enrol_authorize', 'id', $orderno);
|
|
|
|
redirect("index.php");
|
|
|
|
}
|
|
|
|
print_table($table);
|
|
|
|
}
|
|
|
|
else { // SHOW
|
|
|
|
$actions = '';
|
|
|
|
if (empty($status->actions)) {
|
|
|
|
$actions .= $strs->none;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
foreach ($status->actions as $value) {
|
|
|
|
$actions .= "<input type='submit' name='$value' value='{$authstrs->$value}'> ";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$table->data[] = array("<b>$strs->action</b>", $actions);
|
|
|
|
print_table($table);
|
|
|
|
if ($settled) { // show refunds.
|
2006-06-01 08:51:20 +00:00
|
|
|
$t2 = new stdClass;
|
2006-08-18 16:01:47 +00:00
|
|
|
$t2->size = array('45%', '15%', '20%', '10%', '10%');
|
2006-05-12 19:56:02 +00:00
|
|
|
$t2->align = array('right', 'right', 'right', 'right', 'right');
|
2006-08-18 16:01:47 +00:00
|
|
|
$t2->head = array($authstrs->settlementdate,
|
|
|
|
$authstrs->transid,
|
2006-05-12 19:56:02 +00:00
|
|
|
$strs->status,
|
2006-08-18 16:01:47 +00:00
|
|
|
$strs->action,
|
|
|
|
$authstrs->amount);
|
2006-08-17 15:43:54 +00:00
|
|
|
|
2006-09-15 12:05:27 +00:00
|
|
|
$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'";
|
2006-08-17 15:43:54 +00:00
|
|
|
|
|
|
|
$refunds = get_records_sql($sql);
|
2006-03-27 08:31:16 +00:00
|
|
|
if ($refunds) {
|
2006-08-18 16:01:47 +00:00
|
|
|
$sumrefund = floatval(0.0);
|
2006-03-27 08:31:16 +00:00
|
|
|
foreach ($refunds as $rf) {
|
2006-04-11 12:37:41 +00:00
|
|
|
$substatus = authorize_get_status_action($rf);
|
2006-03-27 08:31:16 +00:00
|
|
|
$subactions = ' ';
|
|
|
|
if (empty($substatus->actions)) {
|
|
|
|
$subactions .= $strs->none;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
foreach ($substatus->actions as $vl) {
|
|
|
|
$subactions .=
|
2006-05-16 15:34:24 +00:00
|
|
|
"<a href='index.php?$vl=y&sesskey=$USER->sesskey&order=$orderno&suborder=$rf->id'>{$authstrs->$vl}</a> ";
|
2006-03-27 08:31:16 +00:00
|
|
|
}
|
|
|
|
}
|
2006-08-18 16:01:47 +00:00
|
|
|
$sign = '';
|
2006-08-18 17:10:30 +00:00
|
|
|
$color = authorize_get_status_color($substatus->status);
|
|
|
|
if ($substatus->status == 'refunded' or $substatus->status == 'settled') {
|
|
|
|
$sign = '-';
|
|
|
|
$sumrefund += floatval($rf->amount);
|
2006-08-18 16:01:47 +00:00
|
|
|
}
|
|
|
|
$t2->data[] = array(
|
|
|
|
userdate($rf->settletime),
|
|
|
|
$rf->transid,
|
2006-08-18 17:10:30 +00:00
|
|
|
"<font style='color:$color'>" .$authstrs->{$substatus->status} . "</font>",
|
2006-08-18 16:01:47 +00:00
|
|
|
$subactions,
|
2006-08-18 17:10:30 +00:00
|
|
|
format_float($sign . $rf->amount, 2)
|
2006-08-18 16:01:47 +00:00
|
|
|
);
|
2006-03-27 08:31:16 +00:00
|
|
|
}
|
2006-08-18 16:01:47 +00:00
|
|
|
$t2->data[] = array('','',get_string('total'),$order->currency,format_float('-'.$sumrefund, 2));
|
2006-03-27 08:31:16 +00:00
|
|
|
}
|
|
|
|
else {
|
2006-05-12 19:56:02 +00:00
|
|
|
$t2->data[] = array('','',get_string('noreturns', 'enrol_authorize'),'','');
|
2006-03-27 08:31:16 +00:00
|
|
|
}
|
2006-06-01 08:51:20 +00:00
|
|
|
echo "<h4>" . get_string('returns', 'enrol_authorize') . "</h4>\n";
|
2006-04-05 05:28:56 +00:00
|
|
|
print_table($t2);
|
2006-03-27 08:31:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
echo '</form>';
|
|
|
|
}
|
|
|
|
|
2006-04-05 05:28:56 +00:00
|
|
|
/**
|
2006-04-11 12:37:41 +00:00
|
|
|
* authorize_get_status_action
|
2006-04-05 05:28:56 +00:00
|
|
|
*
|
|
|
|
* @param object $order Order details.
|
|
|
|
* @return object
|
|
|
|
*/
|
2006-04-11 12:37:41 +00:00
|
|
|
function authorize_get_status_action($order)
|
2006-03-27 08:31:16 +00:00
|
|
|
{
|
2006-05-12 19:56:02 +00:00
|
|
|
global $CFG;
|
2006-07-10 10:17:23 +00:00
|
|
|
static $newordertime;
|
2006-04-07 11:23:10 +00:00
|
|
|
|
2006-07-10 10:17:23 +00:00
|
|
|
if (empty($newordertime)) {
|
|
|
|
$newordertime = time() - 120; // -2 minutes. Order may be still in process.
|
2006-04-07 11:23:10 +00:00
|
|
|
}
|
2006-03-27 08:31:16 +00:00
|
|
|
|
|
|
|
$ret = new stdClass();
|
|
|
|
$ret->actions = array();
|
|
|
|
|
2006-09-15 11:40:37 +00:00
|
|
|
$canmanage = has_capability('enrol/authorize:managepayments', get_context_instance(CONTEXT_COURSE, $order->courseid));
|
2006-08-14 14:23:01 +00:00
|
|
|
|
2006-05-12 19:56:02 +00:00
|
|
|
if (intval($order->transid) == 0) { // test transaction or new order
|
|
|
|
if ($order->timecreated < $newordertime) {
|
2006-09-15 11:40:37 +00:00
|
|
|
if ($canmanage) {
|
2006-05-12 19:56:02 +00:00
|
|
|
$ret->actions = array(ORDER_DELETE);
|
|
|
|
}
|
|
|
|
$ret->status = 'tested';
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$ret->status = 'new';
|
2006-03-27 08:31:16 +00:00
|
|
|
}
|
|
|
|
return $ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch ($order->status) {
|
|
|
|
case AN_STATUS_AUTH:
|
2006-07-10 10:17:23 +00:00
|
|
|
if (authorize_expired($order)) {
|
2006-09-15 11:40:37 +00:00
|
|
|
if ($canmanage) {
|
2006-03-27 08:31:16 +00:00
|
|
|
$ret->actions = array(ORDER_DELETE);
|
|
|
|
}
|
|
|
|
$ret->status = 'expired';
|
|
|
|
}
|
|
|
|
else {
|
2006-09-15 11:40:37 +00:00
|
|
|
if ($canmanage) {
|
2006-03-27 08:31:16 +00:00
|
|
|
$ret->actions = array(ORDER_CAPTURE, ORDER_VOID);
|
|
|
|
}
|
|
|
|
$ret->status = 'authorizedpendingcapture';
|
|
|
|
}
|
|
|
|
return $ret;
|
|
|
|
|
|
|
|
case AN_STATUS_AUTHCAPTURE:
|
2006-07-10 10:17:23 +00:00
|
|
|
if (authorize_settled($order)) {
|
2006-10-16 09:39:08 +00:00
|
|
|
if ($order->paymentmethod == AN_METHOD_CC && $canmanage) {
|
2006-03-27 08:31:16 +00:00
|
|
|
$ret->actions = array(ORDER_REFUND);
|
|
|
|
}
|
2006-10-16 09:39:08 +00:00
|
|
|
$ret->status = 'settled';
|
2006-03-27 08:31:16 +00:00
|
|
|
}
|
|
|
|
else {
|
2006-09-15 11:40:37 +00:00
|
|
|
if ($order->paymentmethod == AN_METHOD_CC && $canmanage) {
|
|
|
|
$ret->actions = array(ORDER_VOID);
|
2006-03-27 08:31:16 +00:00
|
|
|
}
|
|
|
|
$ret->status = 'capturedpendingsettle';
|
|
|
|
}
|
|
|
|
return $ret;
|
|
|
|
|
|
|
|
case AN_STATUS_CREDIT:
|
2006-07-10 10:17:23 +00:00
|
|
|
if (authorize_settled($order)) {
|
2006-03-27 08:31:16 +00:00
|
|
|
$ret->status = 'settled';
|
|
|
|
}
|
|
|
|
else {
|
2006-09-15 11:40:37 +00:00
|
|
|
if ($order->paymentmethod == AN_METHOD_CC && $canmanage) {
|
2006-03-27 08:31:16 +00:00
|
|
|
$ret->actions = array(ORDER_VOID);
|
|
|
|
}
|
|
|
|
$ret->status = 'refunded';
|
|
|
|
}
|
|
|
|
return $ret;
|
|
|
|
|
|
|
|
case AN_STATUS_VOID:
|
|
|
|
$ret->status = 'cancelled';
|
|
|
|
return $ret;
|
|
|
|
|
|
|
|
case AN_STATUS_EXPIRE:
|
2006-09-15 11:40:37 +00:00
|
|
|
if ($canmanage) {
|
2006-03-27 08:31:16 +00:00
|
|
|
$ret->actions = array(ORDER_DELETE);
|
|
|
|
}
|
|
|
|
$ret->status = 'expired';
|
|
|
|
return $ret;
|
|
|
|
|
2006-10-16 09:39:08 +00:00
|
|
|
case AN_STATUS_UNDERREVIEW:
|
|
|
|
$ret->status = 'underreview';
|
|
|
|
return $ret;
|
|
|
|
|
|
|
|
case AN_STATUS_APPROVEDREVIEW:
|
|
|
|
$ret->status = 'approvedreview';
|
|
|
|
return $ret;
|
|
|
|
|
|
|
|
case AN_STATUS_REVIEWFAILED:
|
|
|
|
if ($canmanage) {
|
|
|
|
$ret->actions = array(ORDER_DELETE);
|
|
|
|
}
|
|
|
|
$ret->status = 'reviewfailed';
|
|
|
|
return $ret;
|
|
|
|
|
2006-03-27 08:31:16 +00:00
|
|
|
default:
|
|
|
|
return $ret;
|
|
|
|
}
|
|
|
|
}
|
2006-08-18 17:10:30 +00:00
|
|
|
|
|
|
|
|
|
|
|
function authorize_get_status_color($status)
|
|
|
|
{
|
|
|
|
$color = 'black';
|
2006-10-16 09:39:08 +00:00
|
|
|
switch ($status)
|
|
|
|
{
|
|
|
|
case 'settled':
|
|
|
|
case 'approvedreview':
|
|
|
|
case 'capturedpendingsettle':
|
|
|
|
$color = '#339900'; // green
|
|
|
|
break;
|
|
|
|
|
2006-08-18 17:10:30 +00:00
|
|
|
case 'new':
|
|
|
|
case 'tested':
|
2006-10-16 09:39:08 +00:00
|
|
|
case 'underreview':
|
2006-08-18 17:10:30 +00:00
|
|
|
case 'authorizedpendingcapture':
|
|
|
|
$color = '#FF6600'; // orange
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'expired':
|
|
|
|
case 'cancelled':
|
|
|
|
case 'refunded';
|
2006-10-16 09:39:08 +00:00
|
|
|
case 'reviewfailed':
|
2006-08-18 17:10:30 +00:00
|
|
|
$color = '#FF0033'; // red
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return $color;
|
|
|
|
}
|
2006-03-27 08:31:16 +00:00
|
|
|
?>
|