From 36814b9910bd50b5b641b38d25e0cfee7bed11b8 Mon Sep 17 00:00:00 2001 From: ethem Date: Mon, 11 Feb 2008 10:05:06 +0000 Subject: [PATCH] Accesbility Improvements: -New search option, cc last four; -Paging options --- enrol/authorize/authorizenetlib.php | 15 +- enrol/authorize/index.php | 36 +- enrol/authorize/locallib.php | 718 ++++++++++++++-------------- enrol/authorize/uploadcsv.php | 11 +- 4 files changed, 372 insertions(+), 408 deletions(-) diff --git a/enrol/authorize/authorizenetlib.php b/enrol/authorize/authorizenetlib.php index d1ab0d9c06..0350105792 100644 --- a/enrol/authorize/authorizenetlib.php +++ b/enrol/authorize/authorizenetlib.php @@ -196,21 +196,17 @@ function authorize_action(&$order, &$message, &$extra, $action=AN_ACTION_NONE, $ $message = "Order must be settled. Try VOID, check Cut-Off time if it fails!"; return AN_RETURNZERO; } + if (empty($extra->amount)) { + $message = "No valid amount!"; + return AN_RETURNZERO; + } $timenowsettle = authorize_getsettletime(time()); $timediff = $timenowsettle - (120 * 3600 * 24); if ($order->settletime < $timediff) { $message = "Order must be credited within 120 days!"; return AN_RETURNZERO; } - if (empty($extra)) { - $message = "Need extra fields to REFUND!"; - return AN_RETURNZERO; - } - $total = floatval($extra->sum) + floatval($extra->amount); - if (($extra->amount == 0) || ($total > $order->amount)) { - $message = "Can be credited up to original amount."; - return AN_RETURNZERO; - } + $pd['x_type'] = 'CREDIT'; $pd['x_trans_id'] = $order->transid; $pd['x_currency_code'] = $order->currency; @@ -312,7 +308,6 @@ function authorize_action(&$order, &$message, &$extra, $action=AN_ACTION_NONE, $ $extra->status = AN_STATUS_CREDIT; $extra->transid = $transid; $extra->settletime = authorize_getsettletime(time()); - unset($extra->sum); // this is not used in refunds table. if (! $extra->id = insert_record('enrol_authorize_refunds', $extra)) { unset($extra->id); email_to_admin("Error while trying to insert data " . diff --git a/enrol/authorize/index.php b/enrol/authorize/index.php index 7635cff43f..4bec39d7ea 100644 --- a/enrol/authorize/index.php +++ b/enrol/authorize/index.php @@ -2,7 +2,10 @@ /// Load libraries require_once('../../config.php'); + require_once('const.php'); require_once('locallib.php'); + require_once('localfuncs.php'); + require_once('authorizenetlib.php'); /// Parameters $orderid = optional_param('order', 0, PARAM_INT); @@ -14,36 +17,25 @@ error('Could not find that course'); } -/// Only site users can access to this page +/// Only SITE users can access to this page require_login(); // Don't use $courseid! User may want to see old orders. - if (has_capability('moodle/legacy:guest', get_context_instance(CONTEXT_SYSTEM), $USER->id, false)) { error("Guests cannot use this page."); } -/// Load strings. All strings should be defined here. locallib.php uses these strings. - $strs = get_strings(array('search','status','action','time','course','confirm','no','all','none','error')); + /// Load strings. All strings should be defined here. locallib.php uses these strings. + $strs = get_strings(array('search','status','action','time','course','confirm','yes','no','cancel','all','none','error')); $authstrs = get_strings(array('orderid','nameoncard','echeckfirslasttname','void','capture','refund','delete', - 'allpendingorders','authcaptured','authorizedpendingcapture','capturedpendingsettle','settled', - 'refunded','cancelled','expired','underreview','approvedreview','reviewfailed','tested','new', - 'paymentmethod','methodcc','methodecheck', - 'transid','settlementdate','notsettled','amount','unenrolstudent'), 'enrol_authorize'); - -/// Print header - $strpaymentmanagement = get_string('paymentmanagement', 'enrol_authorize'); - $navlinks = array(); - $navlinks[] = array('name' => $strpaymentmanagement, 'link' => 'index.php', 'type' => 'misc'); - $navigation = build_navigation($navlinks); - - print_header_simple($strpaymentmanagement, "", $navigation); + 'allpendingorders','authcaptured','authorizedpendingcapture','capturedpendingsettle','settled', + 'refunded','cancelled','expired','underreview','approvedreview','reviewfailed','tested','new', + 'paymentmethod','methodcc','methodecheck', 'paymentmanagement', 'orderdetails', 'cclastfour', 'isbusinesschecking','shipper', + 'transid','settlementdate','notsettled','amount','unenrolstudent'), 'enrol_authorize'); -/// If orderid is empty, user wants to see all orders + /// User wants to see all orders if (empty($orderid)) { authorize_print_orders($courseid, $userid); - } else { - authorize_print_order_details($orderid); } - -/// Print footer - print_footer(); + else { + authorize_print_order($orderid); + } ?> diff --git a/enrol/authorize/locallib.php b/enrol/authorize/locallib.php index 3cb3ff8a8a..1b4d9c54f0 100644 --- a/enrol/authorize/locallib.php +++ b/enrol/authorize/locallib.php @@ -4,9 +4,6 @@ if (!defined('MOODLE_INTERNAL')) { die('Direct access to this script is forbidden.'); } -require_once('const.php'); -require_once('authorizenetlib.php'); - define('ORDER_CAPTURE', 'capture'); define('ORDER_DELETE', 'delete'); define('ORDER_REFUND', 'refund'); @@ -18,76 +15,72 @@ define('ORDER_VOID', 'void'); */ function authorize_print_orders($courseid, $userid) { + global $course; global $CFG, $USER, $SITE; global $strs, $authstrs; require_once($CFG->libdir.'/tablelib.php'); - $perpage = 10; - $status = optional_param('status', AN_STATUS_NONE, PARAM_INT); - $searchtype = optional_param('searchtype', 'id', PARAM_ALPHA); - $idortransid = optional_param('idortransid', '0', PARAM_INT); + $perpage = optional_param('perpage', 10, PARAM_INT); $showonlymy = optional_param('showonlymy', 0, PARAM_BOOL); + $searchquery = optional_param('searchquery', '0', PARAM_INT); + $searchtype = optional_param('searchtype', 'id', PARAM_ALPHA); + $status = optional_param('status', AN_STATUS_NONE, PARAM_INT); - $canmanagepayments = has_capability('enrol/authorize:managepayments', get_context_instance(CONTEXT_COURSE, $courseid)); + $searchmenu = array('orderid' => $authstrs->orderid, 'transid' => $authstrs->transid, 'cclastfour' => $authstrs->cclastfour); + $buttons = "
"; + $buttons .= choose_from_menu($searchmenu, 'searchtype', $searchtype, '', '', '0', true); + $buttons .= ""; + $buttons .= ""; + $buttons .= "
"; + if (has_capability('enrol/authorize:uploadcsv', get_context_instance(CONTEXT_USER, $USER->id))) { + $buttons .= "
"; + } + + $canmanagepayments = has_capability('enrol/authorize:managepayments', get_context_instance(CONTEXT_COURSE, $courseid)); if ($showonlymy || !$canmanagepayments) { $userid = $USER->id; } - $baseurl = $CFG->wwwroot."/enrol/authorize/index.php?user=$userid"; - $statusmenu = array(AN_STATUS_NONE => $strs->all, - AN_STATUS_AUTH | AN_STATUS_UNDERREVIEW | AN_STATUS_APPROVEDREVIEW => $authstrs->allpendingorders, - AN_STATUS_AUTH => $authstrs->authorizedpendingcapture, - AN_STATUS_AUTHCAPTURE => $authstrs->authcaptured, - AN_STATUS_CREDIT => $authstrs->refunded, - AN_STATUS_VOID => $authstrs->cancelled, - AN_STATUS_EXPIRE => $authstrs->expired, - AN_STATUS_UNDERREVIEW => $authstrs->underreview, - AN_STATUS_APPROVEDREVIEW => $authstrs->approvedreview, - AN_STATUS_REVIEWFAILED => $authstrs->reviewfailed, - AN_STATUS_TEST => $authstrs->tested - ); + $baseurl = $CFG->wwwroot.'/enrol/authorize/index.php?user='.$userid; $sql = "SELECT c.id, c.fullname FROM {$CFG->prefix}course c INNER JOIN {$CFG->prefix}enrol_authorize e ON c.id = e.courseid "; - if ($userid > 0) { - $sql .= "WHERE (e.userid='$userid') "; - } + $sql .= ($userid > 0) ? "WHERE (e.userid='$userid') " : ''; $sql .= "ORDER BY c.sortorder, c.fullname"; if (($popupcrs = get_records_sql_menu($sql))) { $popupcrs = array($SITE->id => $SITE->fullname) + $popupcrs; - echo ""; - echo ""; - echo "\n"; - echo "\n"; - if (has_capability('enrol/authorize:uploadcsv', get_context_instance(CONTEXT_USER, $USER->id))) { - echo ""; - echo ""; - echo ""; - } - else { - echo ""; - } - echo "\n"; - - echo ""; $searchmenu = array('id' => $authstrs->orderid, 'transid' => $authstrs->transid); - echo ""; - echo ""; - echo ""; - echo ""; - echo "
$strs->status: "; - popup_form($baseurl.'&course='.$courseid.'&status=',$statusmenu,'statusmenu',$status,'','','',false); - if ($canmanagepayments) { - echo "
\n"; - print_checkbox('showonlymy', '1', $userid == $USER->id, get_string('mypaymentsonly', 'enrol_authorize'), '', - "var locationtogo = '{$CFG->wwwroot}/enrol/authorize/index.php?status=$status&course=$courseid'; + } + $popupmenu = empty($popupcrs) ? '' : popup_form($baseurl.'&status='.$status.'&course=',$popupcrs,'coursesmenu',$courseid,'','','',true); + $popupmenu .= '
'; + $statusmenu = array( + AN_STATUS_NONE => $strs->all, + AN_STATUS_AUTH | AN_STATUS_UNDERREVIEW | AN_STATUS_APPROVEDREVIEW => $authstrs->allpendingorders, + AN_STATUS_AUTH => $authstrs->authorizedpendingcapture, + AN_STATUS_AUTHCAPTURE => $authstrs->authcaptured, + AN_STATUS_CREDIT => $authstrs->refunded, + AN_STATUS_VOID => $authstrs->cancelled, + AN_STATUS_EXPIRE => $authstrs->expired, + AN_STATUS_UNDERREVIEW => $authstrs->underreview, + AN_STATUS_APPROVEDREVIEW => $authstrs->approvedreview, + AN_STATUS_REVIEWFAILED => $authstrs->reviewfailed, + AN_STATUS_TEST => $authstrs->tested + ); + $popupmenu .= popup_form($baseurl.'&course='.$courseid.'&status=',$statusmenu,'statusmenu',$status,'','','',true); + if ($canmanagepayments) { + $popupmenu .= '
'; + $popupmenu .= print_checkbox('showonlymy', '1', $userid == $USER->id, get_string('mypaymentsonly', 'enrol_authorize'), '', + "var locationtogo = '{$CFG->wwwroot}/enrol/authorize/index.php?status=$status'; locationtogo += '&user=' + (this.checked ? '$USER->id' : '0'); - top.location.href=locationtogo;"); - } - echo "
$strs->course: "; - popup_form($baseurl.'&status='.$status.'&course=',$popupcrs,'coursesmenu',$courseid,'','','',false);echo"
 
$strs->search:
"; choose_from_menu($searchmenu, 'searchtype', $searchtype, ''); - echo " =
"; - echo "
"; + top.location.href = locationtogo;", true); + } + + $navlinks = array(); + if (SITEID != $courseid) { + $navlinks[] = array('name' => $course->shortname, 'link' => "$CFG->wwwroot/course/view.php?id=".$course->id, 'type' => 'misc'); } + $navlinks[] = array('name' => $authstrs->paymentmanagement, 'link' => 'index.php', 'type' => 'misc'); + $navigation = build_navigation($navlinks); + print_header("$course->shortname: $authstrs->paymentmanagement", $authstrs->paymentmanagement, $navigation, '', '', false, $buttons, $popupmenu); $table = new flexible_table('enrol-authorize'); $table->set_attribute('width', '100%'); @@ -96,21 +89,51 @@ function authorize_print_orders($courseid, $userid) $table->set_attribute('id', 'orders'); $table->set_attribute('class', 'generaltable generalbox'); + if ($perpage > 100) { $perpage = 100; } + $perpagemenus = array(5 => 5, 10 => 10, 20 => 20, 50 => 50, 100 => 100); + $perpagemenu = popup_form($baseurl.'&status='.$status.'&course='.$courseid.'&perpage=',$perpagemenus,'perpagemenu',$perpage,'','','',true); $table->define_columns(array('id', 'timecreated', 'userid', 'status', '')); - $table->define_headers(array($authstrs->orderid, $strs->time, $authstrs->nameoncard, $strs->status, $strs->action)); - $table->define_baseurl($baseurl."&status=$status&course=$courseid"); + $table->define_headers(array($authstrs->orderid, $authstrs->shipper, $strs->time, $strs->status, $perpagemenu)); + $table->define_baseurl($baseurl."&status=$status&course=$courseid&perpage=$perpage"); $table->sortable(true, 'id', SORT_DESC); $table->pageable(true); $table->setup(); - $select = "SELECT e.id, e.paymentmethod, e.transid, e.courseid, e.userid, e.status, e.ccname, e.timecreated, e.settletime "; + $select = "SELECT e.id, e.paymentmethod, e.refundinfo, e.transid, e.courseid, e.userid, e.status, e.ccname, e.timecreated, e.settletime "; $from = "FROM {$CFG->prefix}enrol_authorize e "; $where = "WHERE (1=1) "; - if ($status > AN_STATUS_NONE) { + if (!empty($searchquery)) { + switch($searchtype) { + case 'orderid': + $where = "WHERE (e.id = '$searchquery') "; + break; + + case 'transid': + $where = "WHERE (e.transid = '$searchquery') "; + break; + + case 'cclastfour': + $searchquery = sprintf("%04d", $searchquery); + $where = "WHERE (e.refundinfo = '$searchquery') AND (e.paymentmethod='" . AN_METHOD_CC . "') "; + break; + } + } + else { switch ($status) { + case AN_STATUS_NONE: + if (empty($CFG->an_test)) { + $where .= "AND (e.status != '" . AN_STATUS_NONE . "') "; + } + break; + + case AN_STATUS_TEST: + $newordertime = time() - 120; // -2 minutes. Order may be still in process. + $where .= "AND (e.status = '" . AN_STATUS_NONE . "') AND (e.transid = '0') AND (e.timecreated < $newordertime) "; + break; + case AN_STATUS_AUTH | AN_STATUS_UNDERREVIEW | AN_STATUS_APPROVEDREVIEW: $where .= 'AND (e.status IN('.AN_STATUS_AUTH.','.AN_STATUS_UNDERREVIEW.','.AN_STATUS_APPROVEDREVIEW.')) '; break; @@ -120,37 +143,17 @@ function authorize_print_orders($courseid, $userid) $where .= "AND (e.status = '" . AN_STATUS_AUTHCAPTURE . "') "; break; - case AN_STATUS_TEST: - $newordertime = time() - 120; // -2 minutes. Order may be still in process. - $where .= "AND (e.status = '" . AN_STATUS_NONE . "') AND (e.transid = '0') AND (e.timecreated < $newordertime) "; - break; - default: $where .= "AND (e.status = '$status') "; break; } - } - else { - if (empty($CFG->an_test)) { - $where .= "AND (e.status != '" . AN_STATUS_NONE . "') "; - } - } - - if ($courseid != SITEID) { - $where .= "AND (e.courseid = '" . $courseid . "') "; - } - if (!empty($idortransid)) { - // Ignore old where. - if ($searchtype == 'transid') { - $where = "WHERE (e.transid = $idortransid) "; - } - else { - $where = "WHERE (e.id = $idortransid) "; + if (SITEID != $courseid) { + $where .= "AND (e.courseid = '" . $courseid . "') "; } } - // This must be always last where!!! + // This must be always LAST where!!! if ($userid > 0) { $where .= "AND (e.userid = '" . $userid . "') "; } @@ -173,15 +176,15 @@ function authorize_print_orders($courseid, $userid) $actions .= $strs->none; } else { - foreach ($actionstatus->actions as $value) { - $actions .= "  {$authstrs->$value} "; + foreach ($actionstatus->actions as $val) { + $actions .= authorize_print_action_button($record->id, $val); } } $table->add_data(array( "$record->id", - userdate($record->timecreated), $record->ccname, + userdate($record->timecreated), "" . $authstrs->{$actionstatus->status} . "", $actions )); @@ -189,243 +192,222 @@ function authorize_print_orders($courseid, $userid) } $table->print_html(); + print_footer(); } /** - * authorize_print_order_details + * authorize_print_order * - * @param int $orderno + * @param object $order */ -function authorize_print_order_details($orderno) +function authorize_print_order($orderid) { global $CFG, $USER; global $strs, $authstrs; - $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); - + $do = optional_param('do', '', PARAM_ALPHA); $unenrol = optional_param('unenrol', 0, PARAM_BOOL); $confirm = optional_param('confirm', 0, PARAM_BOOL); - $table = new stdClass; - $table->width = '100%'; - $table->size = array('30%', '70%'); - $table->align = array('right', 'left'); + if (!$order = get_record('enrol_authorize', 'id', $orderid)) { + error("Order $orderid not found.", "$CFG->wwwroot/enrol/authorize/index.php"); + } - $order = get_record('enrol_authorize', 'id', $orderno); - if (!$order) { - notice("Order $orderno not found.", "index.php"); - return; + if (!$course = get_record('course', 'id', $order->courseid)) { + error("Could not find that course id $order->courseid", "$CFG->wwwroot/enrol/authorize/index.php"); } - $course = get_record('course', 'id', $order->courseid); - $coursecontext = get_context_instance(CONTEXT_COURSE, $course->id); + if (!$user = get_record('user', 'id', $order->userid)) { + error("Could not find that user id $order->userid", "$CFG->wwwroot/enrol/authorize/index.php"); + } + $coursecontext = get_context_instance(CONTEXT_COURSE, $course->id); if ($USER->id != $order->userid) { // Current user viewing someone else's order require_capability('enrol/authorize:managepayments', $coursecontext); } - echo "
\n"; - echo "
"; - echo "\n"; - echo ""; - $settled = authorize_settled($order); - $status = authorize_get_status_action($order); + $statusandactions = authorize_get_status_action($order); + $color = authorize_get_status_color($statusandactions->status); - $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); + $buttons = ''; + if (empty($do)) + { + if (empty($statusandactions->actions)) { + if ((AN_METHOD_ECHECK == $order->paymentmethod) && has_capability('enrol/authorize:uploadcsv', get_context_instance(CONTEXT_USER, $USER->id))) { + $buttons .= "
"; + } } else { - $table->data[] = array("$authstrs->echeckfirslasttname:", $order->ccname); + foreach ($statusandactions->actions as $val) { + $buttons .= authorize_print_action_button($orderid, $val); + } } - $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; - error(get_string('youcantdo', 'enrol_authorize', $a)); - } + $navlinks = array(); + if (SITEID != $course->id) { + $navlinks[] = array('name' => $course->shortname, 'link' => "$CFG->wwwroot/course/view.php?id=".$course->id, 'type' => 'misc'); + } + $navlinks[] = array('name' => $authstrs->paymentmanagement, 'link' => 'index.php?course='.$course->id, 'type' => 'misc'); + $navlinks[] = array('name' => $authstrs->orderid . ': ' . $orderid, 'link' => '', 'type' => 'misc'); + $navigation = build_navigation($navlinks); + print_header("$course->shortname: $authstrs->paymentmanagement", $authstrs->orderdetails, $navigation, '', '', false, $buttons); - if (empty($confirm)) { - $strcaptureyes = get_string('captureyes', 'enrol_authorize'); - $table->data[] = array("$strs->confirm:", - "$strcaptureyes
- -    $strs->no"); - } - else { + $table = new stdClass; + $table->width = '100%'; + $table->size = array('30%', '70%'); + $table->align = array('right', 'left'); + + if (AN_METHOD_CC == $order->paymentmethod) { + $table->data[] = array("$authstrs->paymentmethod:", $authstrs->methodcc); + $table->data[] = array("$authstrs->nameoncard:", $order->ccname . ' ('.fullname($user).')'); + $table->data[] = array("$authstrs->cclastfour:", $order->refundinfo); + } + else { + $table->data[] = array("$authstrs->paymentmethod:", $authstrs->methodecheck); + $table->data[] = array("$authstrs->echeckfirslasttname:", $order->ccname . ' ('.fullname($user).')'); + $table->data[] = array("$authstrs->isbusinesschecking:", ($order->refundinfo == 1) ? $strs->yes : $strs->no); + } + + $table->data[] = array("$authstrs->amount:", "$order->currency $order->amount"); + $table->data[] = array("$authstrs->transid:", $order->transid); + $table->data[] = array("$strs->time:", userdate($order->timecreated)); + $table->data[] = array("$authstrs->settlementdate:", $settled ? userdate($order->settletime) : $authstrs->notsettled); + $table->data[] = array("$strs->status:", "" . $authstrs->{$statusandactions->status} . ""); + + if (ORDER_CAPTURE == $do && in_array(ORDER_CAPTURE, $statusandactions->actions)) { + if ($confirm && confirm_sesskey()) { $message = ''; $extra = NULL; - if (AN_APPROVED != authorize_action($order, $message, $extra, AN_ACTION_PRIOR_AUTH_CAPTURE)) { - $table->data[] = array("$strs->error:", $message); - } - else { + if (AN_APPROVED == authorize_action($order, $message, $extra, AN_ACTION_PRIOR_AUTH_CAPTURE)) { 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); + send_welcome_messages($orderid); } - redirect("index.php?order=$orderno"); + redirect("$CFG->wwwroot/enrol/authorize/index.php?order=$orderid"); } else { - $table->data[] = array("$strs->error:", - "Error while trying to enrol ".fullname($user)." in '" . format_string($course->shortname) . "'"); + redirect("$CFG->wwwroot/enrol/authorize/index.php?order=$orderid", "Error while trying to enrol ".fullname($user)." in '" . format_string($course->shortname) . "'", 20); } } else { - $table->data[] = array(get_string('testmode', 'enrol_authorize'), - get_string('testwarning', 'enrol_authorize')); + redirect("$CFG->wwwroot/enrol/authorize/index.php?order=$orderid", get_string('testwarning', 'enrol_authorize'), 10); } } + else { + redirect("$CFG->wwwroot/enrol/authorize/index.php?order=$orderid", $message, 20); + } } + $table->data[] = array("$strs->confirm:", get_string('captureyes', 'enrol_authorize') . '
' . + authorize_print_action_button($orderid, ORDER_CAPTURE, 0, true, false, $strs->no)); print_table($table); } - elseif (!empty($cmdrefund) and confirm_sesskey()) { // REFUND - if (!in_array(ORDER_REFUND, $status->actions)) { - $a = new stdClass; - $a->action = $authstrs->refund; - error(get_string('youcantdo', 'enrol_authorize', $a)); - } - - $extra = new stdClass; - $extra->sum = 0.0; - $extra->orderid = $orderno; + elseif (ORDER_REFUND == $do && in_array(ORDER_REFUND, $statusandactions->actions)) { + $refunded = 0.0; + $sql = "SELECT SUM(amount) AS refunded + FROM {$CFG->prefix}enrol_authorize_refunds + WHERE (orderid = '" . $orderid . "') + AND (status = '" . AN_STATUS_CREDIT . "')"; - $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); + if (($refundval = get_field_sql($sql))) { + $refunded = floatval($refundval); } - $upto = round($order->amount - $extra->sum, 2); + $upto = round($order->amount - $refunded, 2); if ($upto <= 0) { - error("Refunded to original amount."); + error("Refunded to original amount: $order->amount", "$CFG->wwwroot/enrol/authorize/index.php?order=$orderid"); } - 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->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"); - } + $amount = round(optional_param('amount', $upto), 2); + if ($amount > $upto) { + error("Can be refunded to $upto", "$CFG->wwwroot/enrol/authorize/index.php?order=$orderid"); + } + if ($confirm && confirm_sesskey()) { + $extra = new stdClass; + $extra->orderid = $orderid; + $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)) { + redirect("$CFG->wwwroot/enrol/authorize/index.php?order=$orderid", "insert record error", 20); } else { - $table->data[] = array(get_string('testmode', 'enrol_authorize'), - get_string('testwarning', 'enrol_authorize')); + if (!empty($unenrol)) { + role_unassign(0, $order->userid, 0, $coursecontext->id); + } + redirect("$CFG->wwwroot/enrol/authorize/index.php?order=$orderid"); } } else { - $table->data[] = array("$strs->error:", $message); + redirect("$CFG->wwwroot/enrol/authorize/index.php?order=$orderid", get_string('testwarning', 'enrol_authorize'), 10); } } + else { + redirect("$CFG->wwwroot/enrol/authorize/index.php?order=$orderid", $message, 20); + } } + $a = new stdClass; + $a->upto = $upto; + $extrahtml = get_string('howmuch', 'enrol_authorize') . + ' ' . + get_string('canbecredit', 'enrol_authorize', $a) . '
'; + $table->data[] = array("$strs->confirm:", + authorize_print_action_button($orderid, ORDER_REFUND, 0, true, $authstrs->unenrolstudent, $strs->no, $extrahtml)); 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; - error(get_string('youcantdo', 'enrol_authorize', $a)); - } - if (empty($confirm)) { - $strvoidyes = get_string('voidyes', 'enrol_authorize'); - $table->data[] = array("$strs->confirm:", - "$strvoidyes
- - -     $strs->no"); + elseif (ORDER_DELETE == $do && in_array(ORDER_DELETE, $statusandactions->actions)) { + if ($confirm && confirm_sesskey()) { + if (!empty($unenrol)) { + role_unassign(0, $order->userid, 0, $coursecontext->id); } - else { + delete_records('enrol_authorize', 'id', $orderid); + redirect("$CFG->wwwroot/enrol/authorize/index.php"); + } + $table->data[] = array("$strs->confirm:", + authorize_print_action_button($orderid, ORDER_DELETE, 0, true, $authstrs->unenrolstudent,$strs->no)); + print_table($table); + } + elseif (ORDER_VOID == $do) { // special case: cancel original or refunded transaction? + $suborderid = optional_param('suborder', 0, PARAM_INT); + if (empty($suborderid) && in_array(ORDER_VOID, $statusandactions->actions)) { // cancel original + if ($confirm && confirm_sesskey()) { $extra = NULL; $message = ''; if (AN_APPROVED == authorize_action($order, $message, $extra, AN_ACTION_VOID)) { if (empty($CFG->an_test)) { - redirect("index.php?order=$orderno"); + redirect("$CFG->wwwroot/enrol/authorize/index.php?order=$orderid"); } else { - $table->data[] = array(get_string('testmode', 'enrol_authorize'), - get_string('testwarning', 'enrol_authorize')); + redirect("$CFG->wwwroot/enrol/authorize/index.php?order=$orderid", get_string('testwarning', 'enrol_authorize'), 10); } } else { - $table->data[] = array("$strs->error:", $message); + redirect("$CFG->wwwroot/enrol/authorize/index.php?order=$orderid", $message, 20); } } - } - 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. "'"; + $table->data[] = array("$strs->confirm:", get_string('voidyes', 'enrol_authorize') . '
' . + authorize_print_action_button($orderid, ORDER_VOID, 0, true, false, $strs->no)); + print_table($table); + } + elseif (!empty($suborderid)) { // cancel refunded + $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 = '$suborderid' + AND r.orderid = '$orderid' + 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."); + error("Transaction can not be voided because of already been voided.", "$CFG->wwwroot/enrol/authorize/index.php?order=$orderid"); } - else { - $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); - 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 { + $refundedstatus = authorize_get_status_action($suborder); + unset($suborder->courseid); + if (in_array(ORDER_VOID, $refundedstatus->actions)) { + if ($confirm && confirm_sesskey()) { $message = ''; $extra = NULL; if (AN_APPROVED == authorize_action($suborder, $message, $extra, AN_ACTION_VOID)) { @@ -433,89 +415,51 @@ function authorize_print_order_details($orderno) if (!empty($unenrol)) { role_unassign(0, $order->userid, 0, $coursecontext->id); } - redirect("index.php?order=$orderno"); + redirect("$CFG->wwwroot/enrol/authorize/index.php?order=$orderid"); } else { - $table->data[] = array(get_string('testmode', 'enrol_authorize'), - get_string('testwarning', 'enrol_authorize')); + redirect("$CFG->wwwroot/enrol/authorize/index.php?order=$orderid", get_string('testwarning', 'enrol_authorize'), 10); } } else { - $table->data[] = array("$strs->error:", $message); + redirect("$CFG->wwwroot/enrol/authorize/index.php?order=$orderid", $message, 20); } } + $a = new stdClass; + $a->transid = $suborder->transid; + $a->amount = $suborder->amount; + $table->data[] = array("$strs->confirm:", get_string('subvoidyes', 'enrol_authorize', $a) . '
' . + authorize_print_action_button($orderid, ORDER_VOID, $suborderid, true, $authstrs->unenrolstudent, $strs->no)); + print_table($table); } } - print_table($table); - } - elseif (!empty($cmddelete) and confirm_sesskey()) { // DELETE - if (!in_array(ORDER_DELETE, $status->actions)) { - $a = new stdClass; - $a->action = $authstrs->delete; - error(get_string('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); + else { 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) { + $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 = '$orderid'"; + + if (($refunds = get_records_sql($sql))) { $sumrefund = floatval(0.0); foreach ($refunds as $rf) { + $subactions = ''; $substatus = authorize_get_status_action($rf); - $subactions = ' '; if (empty($substatus->actions)) { $subactions .= $strs->none; } else { foreach ($substatus->actions as $vl) { - $subactions .= - "{$authstrs->$vl} "; + $subactions .= authorize_print_action_button($orderid, $vl, $rf->id); } } $sign = ''; @@ -527,7 +471,7 @@ function authorize_print_order_details($orderno) $t2->data[] = array( userdate($rf->settletime), $rf->transid, - "" .$authstrs->{$substatus->status} . "", + "" .$authstrs->{$substatus->status} . "", $subactions, format_float($sign . $rf->amount, 2) ); @@ -541,8 +485,8 @@ function authorize_print_order_details($orderno) print_table($t2); } } - echo '
'; - echo ''; + + print_footer(); } /** @@ -579,78 +523,78 @@ function authorize_get_status_action($order) } switch ($order->status) { - case AN_STATUS_AUTH: - if (authorize_expired($order)) { - if ($canmanage) { - $ret->actions = array(ORDER_DELETE); + case AN_STATUS_AUTH: + if (authorize_expired($order)) { + if ($canmanage) { + $ret->actions = array(ORDER_DELETE); + } + $ret->status = 'expired'; } - $ret->status = 'expired'; - } - else { - if ($canmanage) { - $ret->actions = array(ORDER_CAPTURE, ORDER_VOID); + else { + if ($canmanage) { + $ret->actions = array(ORDER_CAPTURE, ORDER_VOID); + } + $ret->status = 'authorizedpendingcapture'; } - $ret->status = 'authorizedpendingcapture'; - } - return $ret; + return $ret; - case AN_STATUS_AUTHCAPTURE: - if (authorize_settled($order)) { - if ($canmanage) { - if (($order->paymentmethod == AN_METHOD_CC) || ($order->paymentmethod == AN_METHOD_ECHECK && !empty($order->refundinfo))) { - $ret->actions = array(ORDER_REFUND); + case AN_STATUS_AUTHCAPTURE: + if (authorize_settled($order)) { + if ($canmanage) { + if (($order->paymentmethod == AN_METHOD_CC) || ($order->paymentmethod == AN_METHOD_ECHECK && !empty($order->refundinfo))) { + $ret->actions = array(ORDER_REFUND); + } } + $ret->status = 'settled'; } - $ret->status = 'settled'; - } - else { - if ($order->paymentmethod == AN_METHOD_CC && $canmanage) { - $ret->actions = array(ORDER_VOID); + else { + if ($order->paymentmethod == AN_METHOD_CC && $canmanage) { + $ret->actions = array(ORDER_VOID); + } + $ret->status = 'capturedpendingsettle'; } - $ret->status = 'capturedpendingsettle'; - } - return $ret; + return $ret; - case AN_STATUS_CREDIT: - if (authorize_settled($order)) { - $ret->status = 'settled'; - } - else { - if ($order->paymentmethod == AN_METHOD_CC && $canmanage) { - $ret->actions = array(ORDER_VOID); + case AN_STATUS_CREDIT: + if (authorize_settled($order)) { + $ret->status = 'settled'; } - $ret->status = 'refunded'; - } - return $ret; + else { + if ($order->paymentmethod == AN_METHOD_CC && $canmanage) { + $ret->actions = array(ORDER_VOID); + } + $ret->status = 'refunded'; + } + return $ret; - case AN_STATUS_VOID: - $ret->status = 'cancelled'; - return $ret; + case AN_STATUS_VOID: + $ret->status = 'cancelled'; + return $ret; - case AN_STATUS_EXPIRE: - if ($canmanage) { - $ret->actions = array(ORDER_DELETE); - } - $ret->status = 'expired'; - return $ret; + case AN_STATUS_EXPIRE: + if ($canmanage) { + $ret->actions = array(ORDER_DELETE); + } + $ret->status = 'expired'; + return $ret; - case AN_STATUS_UNDERREVIEW: - $ret->status = 'underreview'; - return $ret; + case AN_STATUS_UNDERREVIEW: + $ret->status = 'underreview'; + return $ret; - case AN_STATUS_APPROVEDREVIEW: - $ret->status = 'approvedreview'; - 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; + case AN_STATUS_REVIEWFAILED: + if ($canmanage) { + $ret->actions = array(ORDER_DELETE); + } + $ret->status = 'reviewfailed'; + return $ret; - default: - return $ret; + default: + return $ret; } } @@ -661,18 +605,21 @@ function authorize_get_status_color($status) switch ($status) { case 'settled': - case 'approvedreview': case 'capturedpendingsettle': $color = '#339900'; // green break; - case 'new': - case 'tested': case 'underreview': + case 'approvedreview': case 'authorizedpendingcapture': $color = '#FF6600'; // orange break; + case 'new': + case 'tested': + $color = '#003366'; // blue + break; + case 'expired': case 'cancelled': case 'refunded'; @@ -682,4 +629,31 @@ function authorize_get_status_color($status) } return $color; } + +function authorize_print_action_button($orderid, $do, $suborderid=0, $confirm=false, $unenrol=false, $nobutton=false, $extrahtml='') +{ + global $CFG; + global $authstrs; + + $ret = '
' . + '' . + '' . + ''; + if (!empty($suborderid)) { + $ret .= ''; + } + if (!empty($confirm)) { + $ret .= ''; + } + if (!empty($unenrol)) { + $ret .= print_checkbox('unenrol', '1', false, $unenrol, '', '', true) . '
'; + } + $ret .= $extrahtml; + $ret .= '' . + '
'; + if (!empty($nobutton)) { + $ret .= '
'; + } + return $ret; +} ?> diff --git a/enrol/authorize/uploadcsv.php b/enrol/authorize/uploadcsv.php index b96a1102be..0d68154de9 100644 --- a/enrol/authorize/uploadcsv.php +++ b/enrol/authorize/uploadcsv.php @@ -13,10 +13,13 @@ /// Print header $struploadcsv = get_string('uploadcsv', 'enrol_authorize'); $navlinks = array(); + $navlinks[] = array('name' => get_string('paymentmanagement', 'enrol_authorize'), 'link' => 'index.php', 'type' => 'misc'); $navlinks[] = array('name' => $struploadcsv, 'link' => "uploadcsv.php", 'type' => 'misc'); $navigation = build_navigation($navlinks); - print_header_simple($struploadcsv, "", $navigation); + $managebutton = "
"; + + print_header_simple($struploadcsv, '', $navigation, '', '', false, $managebutton); print_heading_with_help($struploadcsv, 'uploadcsv', 'enrol/authorize'); /// Handle CSV file @@ -36,12 +39,12 @@ /// Print submit form $maxuploadsize = get_max_upload_file_size(); - echo '
+ echo '
- '; + '; upload_print_form_fragment(1, array('csvfile'), array(get_string('file'))); echo ''; - echo '

'; + echo '

'; /// Print footer print_footer(); -- 2.39.5