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-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
{
2008-02-11 10:05:06 +00:00
global $course ;
2006-10-30 08:33:00 +00:00
global $CFG , $USER , $SITE ;
2006-03-27 08:31:16 +00:00
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
2008-02-11 10:05:06 +00:00
$perpage = optional_param ( 'perpage' , 10 , PARAM_INT );
2006-11-13 07:36:58 +00:00
$showonlymy = optional_param ( 'showonlymy' , 0 , PARAM_BOOL );
2008-02-11 10:05:06 +00:00
$searchquery = optional_param ( 'searchquery' , '0' , PARAM_INT );
2008-02-11 13:52:47 +00:00
$searchtype = optional_param ( 'searchtype' , 'orderid' , PARAM_ALPHA );
2008-02-11 10:05:06 +00:00
$status = optional_param ( 'status' , AN_STATUS_NONE , PARAM_INT );
2006-03-27 08:31:16 +00:00
2008-02-11 10:05:06 +00:00
$searchmenu = array ( 'orderid' => $authstrs -> orderid , 'transid' => $authstrs -> transid , 'cclastfour' => $authstrs -> cclastfour );
2008-02-11 13:54:28 +00:00
$buttons = " <form method='post' action='index.php' autocomplete='off'><div> " ;
2008-02-11 10:05:06 +00:00
$buttons .= choose_from_menu ( $searchmenu , 'searchtype' , $searchtype , '' , '' , '0' , true );
$buttons .= " <input type='text' size='16' name='searchquery' value='' /> " ;
$buttons .= " <input type='submit' value=' $strs->search ' /> " ;
$buttons .= " </div></form> " ;
2006-11-13 07:36:58 +00:00
2008-02-11 10:05:06 +00:00
if ( has_capability ( 'enrol/authorize:uploadcsv' , get_context_instance ( CONTEXT_USER , $USER -> id ))) {
$buttons .= " <form method='get' action='uploadcsv.php'><div><input type='submit' value=' " . get_string ( 'uploadcsv' , 'enrol_authorize' ) . " ' /></div></form> " ;
}
$canmanagepayments = has_capability ( 'enrol/authorize:managepayments' , get_context_instance ( CONTEXT_COURSE , $courseid ));
2006-11-13 07:36:58 +00:00
if ( $showonlymy || ! $canmanagepayments ) {
2006-03-27 08:31:16 +00:00
$userid = $USER -> id ;
}
2008-02-11 10:05:06 +00:00
$baseurl = $CFG -> wwwroot . '/enrol/authorize/index.php?user=' . $userid ;
2006-03-27 08:31:16 +00:00
2006-10-30 08:33:00 +00:00
$sql = " SELECT c.id, c.fullname FROM { $CFG -> prefix } course c INNER JOIN { $CFG -> prefix } enrol_authorize e ON c.id = e.courseid " ;
2008-02-11 10:05:06 +00:00
$sql .= ( $userid > 0 ) ? " WHERE (e.userid=' $userid ') " : '' ;
2006-10-30 08:33:00 +00:00
$sql .= " ORDER BY c.sortorder, c.fullname " ;
2008-02-06 08:13:20 +00:00
if (( $popupcrs = get_records_sql_menu ( $sql ))) {
2006-11-03 12:36:52 +00:00
$popupcrs = array ( $SITE -> id => $SITE -> fullname ) + $popupcrs ;
2008-02-11 10:05:06 +00:00
}
$popupmenu = empty ( $popupcrs ) ? '' : popup_form ( $baseurl . '&status=' . $status . '&course=' , $popupcrs , 'coursesmenu' , $courseid , '' , '' , '' , true );
$popupmenu .= '<br />' ;
$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 .= '<br />' ;
$popupmenu .= print_checkbox ( 'showonlymy' , '1' , $userid == $USER -> id , get_string ( 'mypaymentsonly' , 'enrol_authorize' ), '' ,
" var locationtogo = ' { $CFG -> wwwroot } /enrol/authorize/index.php?status= $status ';
2006-11-13 07:36:58 +00:00
locationtogo += '&user=' + ( this . checked ? '$USER->id' : '0' );
2008-02-11 10:05:06 +00:00
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' );
2006-03-27 08:31:16 +00:00
}
2008-02-11 10:05:06 +00:00
$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 );
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' );
2008-02-11 10:05:06 +00:00
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 );
2008-04-04 02:54:20 +00:00
$table -> define_columns ( array ( 'id' , 'userid' , 'timecreated' , 'status' , 'action' ));
2008-02-11 10:44:09 +00:00
$table -> define_headers ( array ( $authstrs -> orderid , $authstrs -> shopper , $strs -> time , $strs -> status , $perpagemenu ));
2008-02-11 10:05:06 +00:00
$table -> define_baseurl ( $baseurl . " &status= $status &course= $courseid &perpage= $perpage " );
2006-03-27 08:31:16 +00:00
2008-04-04 02:54:20 +00:00
$table -> no_sorting ( 'action' );
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 ();
2008-02-11 10:05:06 +00:00
$select = " SELECT e.id, e.paymentmethod, e.refundinfo, e.transid, e.courseid, e.userid, e.status, e.ccname, e.timecreated, e.settletime " ;
2006-09-15 11:40:37 +00:00
$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
2008-02-11 10:05:06 +00:00
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 {
2006-05-13 08:33:55 +00:00
switch ( $status )
{
2008-02-11 10:05:06 +00:00
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 ;
2006-10-30 11:16:09 +00:00
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 ;
2006-05-13 08:33:55 +00:00
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
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
}
2008-02-11 10:05:06 +00:00
if ( SITEID != $courseid ) {
$where .= " AND (e.courseid = ' " . $courseid . " ') " ;
2006-10-16 09:39:08 +00:00
}
}
2008-02-11 10:05:06 +00:00
// This must be always LAST where!!!
2006-10-16 09:39:08 +00:00
if ( $userid > 0 ) {
$where .= " AND (e.userid = ' " . $userid . " ') " ;
}
2008-02-06 08:13:20 +00:00
if (( $sort = $table -> get_sql_sort ())) {
2006-03-27 08:31:16 +00:00
$sort = ' ORDER BY ' . $sort ;
}
$totalcount = count_records_sql ( 'SELECT COUNT(*) ' . $from . $where );
$table -> initialbars ( $totalcount > $perpage );
$table -> pagesize ( $perpage , $totalcount );
2008-02-06 08:13:20 +00:00
if (( $records = get_records_sql ( $select . $from . $where . $sort , $table -> get_page_start (), $table -> get_page_size ()))) {
2006-03-27 08:31:16 +00:00
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 {
2008-02-11 10:05:06 +00:00
foreach ( $actionstatus -> actions as $val ) {
$actions .= authorize_print_action_button ( $record -> id , $val );
2006-03-27 08:31:16 +00:00
}
}
$table -> add_data ( array (
" <a href='index.php?order= $record->id '> $record->id </a> " ,
$record -> ccname ,
2008-02-11 10:05:06 +00:00
userdate ( $record -> timecreated ),
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 ();
2008-02-11 10:05:06 +00:00
print_footer ();
2006-03-27 08:31:16 +00:00
}
2006-04-05 05:28:56 +00:00
/**
2008-02-11 10:05:06 +00:00
* authorize_print_order
2006-04-05 05:28:56 +00:00
*
2008-02-11 10:05:06 +00:00
* @ param object $order
2006-04-05 05:28:56 +00:00
*/
2008-02-11 10:05:06 +00:00
function authorize_print_order ( $orderid )
2006-04-07 11:23:10 +00:00
{
2006-03-27 08:31:16 +00:00
global $CFG , $USER ;
global $strs , $authstrs ;
2008-02-11 10:05:06 +00:00
$do = optional_param ( 'do' , '' , PARAM_ALPHA );
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
2008-02-11 10:05:06 +00:00
if ( ! $order = get_record ( 'enrol_authorize' , 'id' , $orderid )) {
2008-05-14 05:56:10 +00:00
print_error ( 'orderidnotfound' , '' ,
" $CFG->wwwroot /enrol/authorize/index.php " , $orderid );
2008-02-11 10:05:06 +00:00
}
2006-03-27 08:31:16 +00:00
2008-02-11 10:05:06 +00:00
if ( ! $course = get_record ( 'course' , 'id' , $order -> courseid )) {
2008-05-14 05:56:10 +00:00
print_error ( 'invalidcourseid' , '' , " $CFG->wwwroot /enrol/authorize/index.php " );
2006-03-27 08:31:16 +00:00
}
2008-02-11 10:05:06 +00:00
if ( ! $user = get_record ( 'user' , 'id' , $order -> userid )) {
2008-05-14 05:56:10 +00:00
print_error ( 'nousers' , '' , " $CFG->wwwroot /enrol/authorize/index.php " );
2008-02-11 10:05:06 +00:00
}
2006-09-18 17:32:43 +00:00
2008-02-11 10:05:06 +00:00
$coursecontext = get_context_instance ( CONTEXT_COURSE , $course -> id );
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
}
2008-04-04 02:54:20 +00:00
$settled = AuthorizeNet :: settled ( $order );
2008-02-11 10:05:06 +00:00
$statusandactions = authorize_get_status_action ( $order );
$color = authorize_get_status_color ( $statusandactions -> status );
2006-03-27 08:31:16 +00:00
2008-02-11 10:05:06 +00:00
$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 .= " <form method='get' action='uploadcsv.php'><div><input type='submit' value=' " . get_string ( 'uploadcsv' , 'enrol_authorize' ) . " ' /></div></form> " ;
}
2006-09-01 16:43:52 +00:00
}
else {
2008-02-11 10:05:06 +00:00
foreach ( $statusandactions -> actions as $val ) {
$buttons .= authorize_print_action_button ( $orderid , $val );
}
2006-09-01 16:43:52 +00:00
}
2006-03-27 08:31:16 +00:00
}
2008-02-11 10:05:06 +00:00
$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 );
2006-03-27 08:31:16 +00:00
2008-02-11 10:05:06 +00:00
$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 ( " <b> $authstrs->paymentmethod :</b> " , $authstrs -> methodcc );
$table -> data [] = array ( " <b> $authstrs->nameoncard :</b> " , $order -> ccname . ' (<b><a href="' . $CFG -> wwwroot . '/user/view.php?id=' . $user -> id . '">' . fullname ( $user ) . '</a></b>)' );
$table -> data [] = array ( " <b> $authstrs->cclastfour :</b> " , $order -> refundinfo );
}
else {
$table -> data [] = array ( " <b> $authstrs->paymentmethod :</b> " , $authstrs -> methodecheck );
$table -> data [] = array ( " <b> $authstrs->echeckfirslasttname :</b> " , $order -> ccname . ' (<b><a href="' . $CFG -> wwwroot . '/user/view.php?id=' . $user -> id . '">' . fullname ( $user ) . '</a></b>)' );
$table -> data [] = array ( " <b> $authstrs->isbusinesschecking :</b> " , ( $order -> refundinfo == 1 ) ? $strs -> yes : $strs -> no );
}
$table -> data [] = array ( " <b> $authstrs->amount :</b> " , " $order->currency $order->amount " );
$table -> data [] = array ( " <b> $authstrs->transid :</b> " , $order -> transid );
$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 ( " <b> $strs->status :</b> " , " <b><font style='color: $color '> " . $authstrs -> { $statusandactions -> status } . " </font></b> " );
if ( ORDER_CAPTURE == $do && in_array ( ORDER_CAPTURE , $statusandactions -> actions )) {
if ( $confirm && confirm_sesskey ()) {
2006-03-27 08:31:16 +00:00
$message = '' ;
$extra = NULL ;
2008-04-04 02:54:20 +00:00
if ( AN_APPROVED == AuthorizeNet :: process ( $order , $message , $extra , AN_ACTION_PRIOR_AUTH_CAPTURE )) {
2006-03-27 08:31:16 +00:00
if ( empty ( $CFG -> an_test )) {
2008-02-05 17:34:36 +00:00
if ( enrol_into_course ( $course , $user , 'authorize' )) {
2006-10-16 09:39:08 +00:00
if ( ! empty ( $CFG -> enrol_mailstudents )) {
2008-02-11 10:05:06 +00:00
send_welcome_messages ( $orderid );
2006-10-16 09:39:08 +00:00
}
2008-02-11 10:05:06 +00:00
redirect ( " $CFG->wwwroot /enrol/authorize/index.php?order= $orderid " );
2006-03-27 08:31:16 +00:00
}
else {
2008-02-11 10:05:06 +00:00
redirect ( " $CFG->wwwroot /enrol/authorize/index.php?order= $orderid " , " Error while trying to enrol " . fullname ( $user ) . " in ' " . format_string ( $course -> shortname ) . " ' " , 20 );
2006-03-27 08:31:16 +00:00
}
}
else {
2008-02-11 10:05:06 +00:00
redirect ( " $CFG->wwwroot /enrol/authorize/index.php?order= $orderid " , get_string ( 'testwarning' , 'enrol_authorize' ), 10 );
2006-03-27 08:31:16 +00:00
}
}
2008-02-11 10:05:06 +00:00
else {
redirect ( " $CFG->wwwroot /enrol/authorize/index.php?order= $orderid " , $message , 20 );
}
2006-03-27 08:31:16 +00:00
}
2008-02-11 10:05:06 +00:00
$table -> data [] = array ( " <b> $strs->confirm :</b> " , get_string ( 'captureyes' , 'enrol_authorize' ) . '<br />' .
authorize_print_action_button ( $orderid , ORDER_CAPTURE , 0 , true , false , $strs -> no ));
2006-03-27 08:31:16 +00:00
print_table ( $table );
}
2008-02-11 10:05:06 +00:00
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 . "' ) " ;
2006-03-27 08:31:16 +00:00
2008-02-11 10:05:06 +00:00
if (( $refundval = get_field_sql ( $sql ))) {
$refunded = floatval ( $refundval );
2006-03-27 08:31:16 +00:00
}
2008-02-11 10:05:06 +00:00
$upto = round ( $order -> amount - $refunded , 2 );
2006-03-27 08:31:16 +00:00
if ( $upto <= 0 ) {
2008-05-14 05:56:10 +00:00
print_error ( 'refoundtoorigi' , '' ,
" $CFG->wwwroot /enrol/authorize/index.php?order= $orderid " , $order -> amount );
2006-03-27 08:31:16 +00:00
}
2008-02-11 10:05:06 +00:00
$amount = round ( optional_param ( 'amount' , $upto ), 2 );
if ( $amount > $upto ) {
2008-05-14 05:56:10 +00:00
print_error ( 'refoundto' , '' ,
" $CFG->wwwroot /enrol/authorize/index.php?order= $orderid " , $upto );
2008-02-11 10:05:06 +00:00
}
if ( $confirm && confirm_sesskey ()) {
$extra = new stdClass ;
$extra -> orderid = $orderid ;
$extra -> amount = $amount ;
$message = '' ;
2008-04-04 02:54:20 +00:00
$success = AuthorizeNet :: process ( $order , $message , $extra , AN_ACTION_CREDIT );
2008-02-11 10:05:06 +00:00
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 );
2006-03-27 08:31:16 +00:00
}
else {
2008-02-11 10:05:06 +00:00
if ( ! empty ( $unenrol )) {
role_unassign ( 0 , $order -> userid , 0 , $coursecontext -> id );
}
redirect ( " $CFG->wwwroot /enrol/authorize/index.php?order= $orderid " );
2006-03-27 08:31:16 +00:00
}
}
else {
2008-02-11 10:05:06 +00:00
redirect ( " $CFG->wwwroot /enrol/authorize/index.php?order= $orderid " , get_string ( 'testwarning' , 'enrol_authorize' ), 10 );
2006-03-27 08:31:16 +00:00
}
}
2008-02-11 10:05:06 +00:00
else {
redirect ( " $CFG->wwwroot /enrol/authorize/index.php?order= $orderid " , $message , 20 );
}
2006-03-27 08:31:16 +00:00
}
2008-02-11 10:05:06 +00:00
$a = new stdClass ;
$a -> upto = $upto ;
$extrahtml = get_string ( 'howmuch' , 'enrol_authorize' ) .
' <input type="text" size="5" name="amount" value="' . $amount . '" /> ' .
get_string ( 'canbecredit' , 'enrol_authorize' , $a ) . '<br />' ;
$table -> data [] = array ( " <b> $strs->confirm :</b> " ,
authorize_print_action_button ( $orderid , ORDER_REFUND , 0 , true , $authstrs -> unenrolstudent , $strs -> no , $extrahtml ));
2006-03-27 08:31:16 +00:00
print_table ( $table );
}
2008-02-11 10:05:06 +00:00
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 );
2006-03-27 08:31:16 +00:00
}
2008-02-11 10:05:06 +00:00
delete_records ( 'enrol_authorize' , 'id' , $orderid );
redirect ( " $CFG->wwwroot /enrol/authorize/index.php " );
}
$table -> data [] = array ( " <b> $strs->confirm :</b> " ,
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 ()) {
2006-03-27 08:31:16 +00:00
$extra = NULL ;
$message = '' ;
2008-04-04 02:54:20 +00:00
if ( AN_APPROVED == AuthorizeNet :: process ( $order , $message , $extra , AN_ACTION_VOID )) {
2006-03-27 08:31:16 +00:00
if ( empty ( $CFG -> an_test )) {
2008-02-11 10:05:06 +00:00
redirect ( " $CFG->wwwroot /enrol/authorize/index.php?order= $orderid " );
2006-03-27 08:31:16 +00:00
}
else {
2008-02-11 10:05:06 +00:00
redirect ( " $CFG->wwwroot /enrol/authorize/index.php?order= $orderid " , get_string ( 'testwarning' , 'enrol_authorize' ), 10 );
2006-03-27 08:31:16 +00:00
}
}
else {
2008-02-11 10:05:06 +00:00
redirect ( " $CFG->wwwroot /enrol/authorize/index.php?order= $orderid " , $message , 20 );
2006-03-27 08:31:16 +00:00
}
}
2008-02-11 10:05:06 +00:00
$table -> data [] = array ( " <b> $strs->confirm :</b> " , get_string ( 'voidyes' , 'enrol_authorize' ) . '<br />' .
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. "' " ;
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
2008-05-14 05:56:10 +00:00
print_error ( 'transactionvoid' , '' , " $CFG->wwwroot /enrol/authorize/index.php?order= $orderid " );
2006-03-27 08:31:16 +00:00
}
2008-02-11 10:05:06 +00:00
$refundedstatus = authorize_get_status_action ( $suborder );
unset ( $suborder -> courseid );
if ( in_array ( ORDER_VOID , $refundedstatus -> actions )) {
if ( $confirm && confirm_sesskey ()) {
2006-03-27 08:31:16 +00:00
$message = '' ;
$extra = NULL ;
2008-04-04 02:54:20 +00:00
if ( AN_APPROVED == AuthorizeNet :: process ( $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
}
2008-02-11 10:05:06 +00:00
redirect ( " $CFG->wwwroot /enrol/authorize/index.php?order= $orderid " );
2006-03-27 08:31:16 +00:00
}
else {
2008-02-11 10:05:06 +00:00
redirect ( " $CFG->wwwroot /enrol/authorize/index.php?order= $orderid " , get_string ( 'testwarning' , 'enrol_authorize' ), 10 );
2006-03-27 08:31:16 +00:00
}
}
else {
2008-02-11 10:05:06 +00:00
redirect ( " $CFG->wwwroot /enrol/authorize/index.php?order= $orderid " , $message , 20 );
2006-03-27 08:31:16 +00:00
}
}
2008-02-11 10:05:06 +00:00
$a = new stdClass ;
$a -> transid = $suborder -> transid ;
$a -> amount = $suborder -> amount ;
$table -> data [] = array ( " <b> $strs->confirm :</b> " , get_string ( 'subvoidyes' , 'enrol_authorize' , $a ) . '<br />' .
authorize_print_action_button ( $orderid , ORDER_VOID , $suborderid , true , $authstrs -> unenrolstudent , $strs -> no ));
print_table ( $table );
2006-03-27 08:31:16 +00:00
}
}
}
2008-02-11 10:05:06 +00:00
else {
2006-03-27 08:31:16 +00:00
print_table ( $table );
2008-02-11 10:05:06 +00:00
2006-03-27 08:31:16 +00:00
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' );
2008-02-11 10:05:06 +00:00
$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 ))) {
2006-08-18 16:01:47 +00:00
$sumrefund = floatval ( 0.0 );
2006-03-27 08:31:16 +00:00
foreach ( $refunds as $rf ) {
2008-02-11 10:05:06 +00:00
$subactions = '' ;
2006-04-11 12:37:41 +00:00
$substatus = authorize_get_status_action ( $rf );
2006-03-27 08:31:16 +00:00
if ( empty ( $substatus -> actions )) {
$subactions .= $strs -> none ;
}
else {
foreach ( $substatus -> actions as $vl ) {
2008-02-11 10:05:06 +00:00
$subactions .= authorize_print_action_button ( $orderid , $vl , $rf -> id );
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 ,
2008-02-11 10:05:06 +00:00
" <b><font style='color: $color '> " . $authstrs -> { $substatus -> status } . " </font></b> " ,
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
}
}
2008-02-11 10:05:06 +00:00
print_footer ();
2006-03-27 08:31:16 +00:00
}
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 ) {
2008-02-11 10:05:06 +00:00
case AN_STATUS_AUTH :
2008-04-04 02:54:20 +00:00
if ( AuthorizeNet :: expired ( $order )) {
2008-02-11 10:05:06 +00:00
if ( $canmanage ) {
$ret -> actions = array ( ORDER_DELETE );
}
$ret -> status = 'expired' ;
2006-03-27 08:31:16 +00:00
}
2008-02-11 10:05:06 +00:00
else {
if ( $canmanage ) {
$ret -> actions = array ( ORDER_CAPTURE , ORDER_VOID );
}
$ret -> status = 'authorizedpendingcapture' ;
2006-03-27 08:31:16 +00:00
}
2008-02-11 10:05:06 +00:00
return $ret ;
2006-03-27 08:31:16 +00:00
2008-02-11 10:05:06 +00:00
case AN_STATUS_AUTHCAPTURE :
2008-04-04 02:54:20 +00:00
if ( AuthorizeNet :: settled ( $order )) {
2008-02-11 10:05:06 +00:00
if ( $canmanage ) {
if (( $order -> paymentmethod == AN_METHOD_CC ) || ( $order -> paymentmethod == AN_METHOD_ECHECK && ! empty ( $order -> refundinfo ))) {
$ret -> actions = array ( ORDER_REFUND );
}
2006-11-20 09:49:26 +00:00
}
2008-02-11 10:05:06 +00:00
$ret -> status = 'settled' ;
2006-03-27 08:31:16 +00:00
}
2008-02-11 10:05:06 +00:00
else {
if ( $order -> paymentmethod == AN_METHOD_CC && $canmanage ) {
$ret -> actions = array ( ORDER_VOID );
}
$ret -> status = 'capturedpendingsettle' ;
2006-03-27 08:31:16 +00:00
}
2008-02-11 10:05:06 +00:00
return $ret ;
2006-03-27 08:31:16 +00:00
2008-02-11 10:05:06 +00:00
case AN_STATUS_CREDIT :
2008-04-04 02:54:20 +00:00
if ( AuthorizeNet :: settled ( $order )) {
2008-02-11 10:05:06 +00:00
$ret -> status = 'settled' ;
2006-03-27 08:31:16 +00:00
}
2008-02-11 10:05:06 +00:00
else {
if ( $order -> paymentmethod == AN_METHOD_CC && $canmanage ) {
$ret -> actions = array ( ORDER_VOID );
}
$ret -> status = 'refunded' ;
}
return $ret ;
2006-03-27 08:31:16 +00:00
2008-02-11 10:05:06 +00:00
case AN_STATUS_VOID :
$ret -> status = 'cancelled' ;
return $ret ;
2006-03-27 08:31:16 +00:00
2008-02-11 10:05:06 +00:00
case AN_STATUS_EXPIRE :
if ( $canmanage ) {
$ret -> actions = array ( ORDER_DELETE );
}
$ret -> status = 'expired' ;
return $ret ;
2006-03-27 08:31:16 +00:00
2008-02-11 10:05:06 +00:00
case AN_STATUS_UNDERREVIEW :
$ret -> status = 'underreview' ;
return $ret ;
2006-10-16 09:39:08 +00:00
2008-02-11 10:05:06 +00:00
case AN_STATUS_APPROVEDREVIEW :
$ret -> status = 'approvedreview' ;
return $ret ;
2006-10-16 09:39:08 +00:00
2008-02-11 10:05:06 +00:00
case AN_STATUS_REVIEWFAILED :
if ( $canmanage ) {
$ret -> actions = array ( ORDER_DELETE );
}
$ret -> status = 'reviewfailed' ;
return $ret ;
2006-10-16 09:39:08 +00:00
2008-02-11 10:05:06 +00:00
default :
return $ret ;
2006-03-27 08:31:16 +00:00
}
}
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 'capturedpendingsettle' :
$color = '#339900' ; // green
break ;
case 'underreview' :
2008-02-11 10:05:06 +00:00
case 'approvedreview' :
2006-08-18 17:10:30 +00:00
case 'authorizedpendingcapture' :
$color = '#FF6600' ; // orange
break ;
2008-02-11 10:05:06 +00:00
case 'new' :
case 'tested' :
$color = '#003366' ; // blue
break ;
2006-08-18 17:10:30 +00:00
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 ;
}
2008-02-11 10:05:06 +00:00
function authorize_print_action_button ( $orderid , $do , $suborderid = 0 , $confirm = false , $unenrol = false , $nobutton = false , $extrahtml = '' )
{
global $CFG ;
global $authstrs ;
$ret = '<form action="' . $CFG -> wwwroot . '/enrol/authorize/index.php' . '" method="post"><div>' .
'<input type="hidden" name="order" value="' . $orderid . '" />' .
'<input type="hidden" name="do" value="' . $do . '" />' .
'<input type="hidden" name="sesskey" value="' . sesskey () . '" />' ;
if ( ! empty ( $suborderid )) {
$ret .= '<input type="hidden" name="suborder" value="' . $suborderid . '" />' ;
}
if ( ! empty ( $confirm )) {
$ret .= '<input type="hidden" name="confirm" value="1" />' ;
}
if ( ! empty ( $unenrol )) {
$ret .= print_checkbox ( 'unenrol' , '1' , false , $unenrol , '' , '' , true ) . '<br />' ;
}
$ret .= $extrahtml ;
$ret .= '<input type="submit" value="' . $authstrs -> $do . '" />' .
'</div></form>' ;
if ( ! empty ( $nobutton )) {
$ret .= '<form method="get" action="index.php"><div><input type="hidden" name="order" value="' . $orderid . '" /><input type="submit" value="' . $nobutton . '" /></div></form>' ;
}
return $ret ;
}
2006-03-27 08:31:16 +00:00
?>