Automatic installer.php lang files by installer_builder (20070726)
[moodle-linuxchix.git] / enrol / authorize / locallib.php
blobfc722bc366daea82d4d302ecf9507f0de167cd93
1 <?php // $Id$
3 if (!defined('MOODLE_INTERNAL')) {
4 die('Direct access to this script is forbidden.');
7 require_once('const.php');
8 require_once('authorizenetlib.php');
10 define('ORDER_CAPTURE', 'capture');
11 define('ORDER_DELETE', 'delete');
12 define('ORDER_REFUND', 'refund');
13 define('ORDER_VOID', 'void');
15 /**
16 * authorize_print_orders
19 function authorize_print_orders($courseid, $userid)
21 global $CFG, $USER, $SITE;
22 global $strs, $authstrs;
23 require_once($CFG->libdir.'/tablelib.php');
25 $perpage = 10;
26 $status = optional_param('status', AN_STATUS_NONE, PARAM_INT);
27 $searchtype = optional_param('searchtype', 'id', PARAM_ALPHA);
28 $idortransid = optional_param('idortransid', '0', PARAM_INT);
29 $showonlymy = optional_param('showonlymy', 0, PARAM_BOOL);
31 $canmanagepayments = has_capability('enrol/authorize:managepayments', get_context_instance(CONTEXT_COURSE, $courseid));
33 if ($showonlymy || !$canmanagepayments) {
34 $userid = $USER->id;
37 $baseurl = $CFG->wwwroot."/enrol/authorize/index.php?user=$userid";
38 $statusmenu = array(AN_STATUS_NONE => $strs->all,
39 AN_STATUS_AUTH | AN_STATUS_UNDERREVIEW | AN_STATUS_APPROVEDREVIEW => $authstrs->allpendingorders,
40 AN_STATUS_AUTH => $authstrs->authorizedpendingcapture,
41 AN_STATUS_AUTHCAPTURE => $authstrs->authcaptured,
42 AN_STATUS_CREDIT => $authstrs->refunded,
43 AN_STATUS_VOID => $authstrs->cancelled,
44 AN_STATUS_EXPIRE => $authstrs->expired,
45 AN_STATUS_UNDERREVIEW => $authstrs->underreview,
46 AN_STATUS_APPROVEDREVIEW => $authstrs->approvedreview,
47 AN_STATUS_REVIEWFAILED => $authstrs->reviewfailed,
48 AN_STATUS_TEST => $authstrs->tested
51 $sql = "SELECT c.id, c.fullname FROM {$CFG->prefix}course c INNER JOIN {$CFG->prefix}enrol_authorize e ON c.id = e.courseid ";
52 if ($userid > 0) {
53 $sql .= "WHERE (e.userid='$userid') ";
55 $sql .= "ORDER BY c.sortorder, c.fullname";
56 if ($popupcrs = get_records_sql_menu($sql)) {
57 $popupcrs = array($SITE->id => $SITE->fullname) + $popupcrs;
58 echo "<table border='0' width='100%' cellspacing='0' cellpadding='3' class='generaltable generalbox'>";
59 echo "<tr>";
60 echo "<td width='5%' valign='top'>$strs->status: </td><td width='10%'>";
61 popup_form($baseurl.'&amp;course='.$courseid.'&amp;status=',$statusmenu,'statusmenu',$status,'','','',false);
62 if ($canmanagepayments) {
63 echo "<br />\n";
64 print_checkbox('showonlymy', '1', $userid == $USER->id, get_string('mypaymentsonly', 'enrol_authorize'), '',
65 "var locationtogo = '{$CFG->wwwroot}/enrol/authorize/index.php?status=$status&amp;course=$courseid';
66 locationtogo += '&amp;user=' + (this.checked ? '$USER->id' : '0');
67 top.location.href=locationtogo;");
69 echo "</td>\n";
70 echo "<td width='5%' valign='top'>$strs->course: </td><td width='10%' valign='top'>";
71 popup_form($baseurl.'&amp;status='.$status.'&amp;course=',$popupcrs,'coursesmenu',$courseid,'','','',false);echo"</td>\n";
72 if (has_capability('enrol/authorize:uploadcsv', get_context_instance(CONTEXT_USER, $USER->id))) {
73 echo "<form method='get' action='uploadcsv.php'>";
74 echo "<td rowspan='2' align='right' valign='middle' width='50%'><div><input type='submit' value='".get_string('uploadcsv', 'enrol_authorize')."' /></div></td>";
75 echo "</form>";
77 else {
78 echo "<td rowspan=2 width='100%'>&nbsp;</td>";
80 echo "</tr>\n";
82 echo "<tr><td>$strs->search: </td>"; $searchmenu = array('id' => $authstrs->orderid, 'transid' => $authstrs->transid);
83 echo "<form method='POST' action='index.php' autocomplete='off'>";
84 echo "<td colspan='3'>"; choose_from_menu($searchmenu, 'searchtype', $searchtype, '');
85 echo " = <fieldset class=\"invisiblefieldset\"><input type='text' size='14' name='idortransid' value='' /> ";
86 echo "<input type='submit' value='$strs->search' /></fieldset></td>";
87 echo "</form>";
88 echo "</tr>";
89 echo "</table>";
92 $table = new flexible_table('enrol-authorize');
93 $table->set_attribute('width', '100%');
94 $table->set_attribute('cellspacing', '0');
95 $table->set_attribute('cellpadding', '3');
96 $table->set_attribute('id', 'orders');
97 $table->set_attribute('class', 'generaltable generalbox');
99 $table->define_columns(array('id', 'timecreated', 'userid', 'status', ''));
100 $table->define_headers(array($authstrs->orderid, $strs->time, $authstrs->nameoncard, $strs->status, $strs->action));
101 $table->define_baseurl($baseurl."&amp;status=$status&amp;course=$courseid");
103 $table->sortable(true, 'id', SORT_DESC);
104 $table->pageable(true);
105 $table->setup();
107 $select = "SELECT e.id, e.paymentmethod, e.transid, e.courseid, e.userid, e.status, e.ccname, e.timecreated, e.settletime ";
108 $from = "FROM {$CFG->prefix}enrol_authorize e ";
109 $where = "WHERE (1=1) ";
111 if ($status > AN_STATUS_NONE) {
112 switch ($status)
114 case AN_STATUS_AUTH | AN_STATUS_UNDERREVIEW | AN_STATUS_APPROVEDREVIEW:
115 $where .= 'AND (e.status IN('.AN_STATUS_AUTH.','.AN_STATUS_UNDERREVIEW.','.AN_STATUS_APPROVEDREVIEW.')) ';
116 break;
118 case AN_STATUS_CREDIT:
119 $from .= "INNER JOIN {$CFG->prefix}enrol_authorize_refunds r ON e.id = r.orderid ";
120 $where .= "AND (e.status = '" . AN_STATUS_AUTHCAPTURE . "') ";
121 break;
123 case AN_STATUS_TEST:
124 $newordertime = time() - 120; // -2 minutes. Order may be still in process.
125 $where .= "AND (e.status = '" . AN_STATUS_NONE . "') AND (e.transid = '0') AND (e.timecreated < $newordertime) ";
126 break;
128 default:
129 $where .= "AND (e.status = '$status') ";
130 break;
133 else {
134 if (empty($CFG->an_test)) {
135 $where .= "AND (e.status != '" . AN_STATUS_NONE . "') ";
139 if ($courseid != SITEID) {
140 $where .= "AND (e.courseid = '" . $courseid . "') ";
143 if (!empty($idortransid)) {
144 // Ignore old where.
145 if ($searchtype == 'transid') {
146 $where = "WHERE (e.transid = $idortransid) ";
148 else {
149 $where = "WHERE (e.id = $idortransid) ";
153 // This must be always last where!!!
154 if ($userid > 0) {
155 $where .= "AND (e.userid = '" . $userid . "') ";
158 if ($sort = $table->get_sql_sort()) {
159 $sort = ' ORDER BY ' . $sort;
162 $totalcount = count_records_sql('SELECT COUNT(*) ' . $from . $where);
163 $table->initialbars($totalcount > $perpage);
164 $table->pagesize($perpage, $totalcount);
166 if ($records = get_records_sql($select . $from . $where . $sort, $table->get_page_start(), $table->get_page_size())) {
167 foreach ($records as $record) {
168 $actionstatus = authorize_get_status_action($record);
169 $color = authorize_get_status_color($actionstatus->status);
170 $actions = '';
172 if (empty($actionstatus->actions)) {
173 $actions .= $strs->none;
175 else {
176 foreach ($actionstatus->actions as $value) {
177 $actions .= "&nbsp;&nbsp;<a href='index.php?$value=y&amp;sesskey=$USER->sesskey&amp;order=$record->id'>{$authstrs->$value}</a> ";
181 $table->add_data(array(
182 "<a href='index.php?order=$record->id'>$record->id</a>",
183 userdate($record->timecreated),
184 $record->ccname,
185 "<font style='color:$color'>" . $authstrs->{$actionstatus->status} . "</font>",
186 $actions
191 $table->print_html();
195 * authorize_print_order_details
197 * @param int $orderno
199 function authorize_print_order_details($orderno)
201 global $CFG, $USER;
202 global $strs, $authstrs;
204 $cmdcapture = optional_param(ORDER_CAPTURE, '', PARAM_ALPHA);
205 $cmddelete = optional_param(ORDER_DELETE, '', PARAM_ALPHA);
206 $cmdrefund = optional_param(ORDER_REFUND, '', PARAM_ALPHA);
207 $cmdvoid = optional_param(ORDER_VOID, '', PARAM_ALPHA);
209 $unenrol = optional_param('unenrol', 0, PARAM_BOOL);
210 $confirm = optional_param('confirm', 0, PARAM_BOOL);
212 $table = new stdClass;
213 $table->width = '100%';
214 $table->size = array('30%', '70%');
215 $table->align = array('right', 'left');
217 $order = get_record('enrol_authorize', 'id', $orderno);
218 if (!$order) {
219 notice("Order $orderno not found.", "index.php");
220 return;
223 $course = get_record('course', 'id', $order->courseid);
224 $coursecontext = get_context_instance(CONTEXT_COURSE, $course->id);
226 if ($USER->id != $order->userid) { // Current user viewing someone else's order
227 require_capability('enrol/authorize:managepayments', $coursecontext);
230 echo "<form action=\"index.php\" method=\"post\">\n";
231 echo "<div>";
232 echo "<input type=\"hidden\" name=\"order\" value=\"$orderno\" />\n";
233 echo "<input type=\"hidden\" name=\"sesskey\" value=\"" . sesskey() . "\" />";
235 $settled = authorize_settled($order);
236 $status = authorize_get_status_action($order);
238 $table->data[] = array("<b>$authstrs->paymentmethod:</b>",
239 ($order->paymentmethod == AN_METHOD_CC ? $authstrs->methodcc : $authstrs->methodecheck));
240 $table->data[] = array("<b>$authstrs->orderid:</b>", $orderno);
241 $table->data[] = array("<b>$authstrs->transid:</b>", $order->transid);
242 $table->data[] = array("<b>$authstrs->amount:</b>", "$order->currency $order->amount");
243 if (empty($cmdcapture) and empty($cmdrefund) and empty($cmdvoid) and empty($cmddelete)) {
244 $color = authorize_get_status_color($status->status);
245 $table->data[] = array("<b>$strs->course:</b>", format_string($course->shortname));
246 $table->data[] = array("<b>$strs->status:</b>", "<font style='color:$color'>" . $authstrs->{$status->status} . "</font>");
247 if ($order->paymentmethod == AN_METHOD_CC) {
248 $table->data[] = array("<b>$authstrs->nameoncard:</b>", $order->ccname);
250 else {
251 $table->data[] = array("<b>$authstrs->echeckfirslasttname:</b>", $order->ccname);
253 $table->data[] = array("<b>$strs->time:</b>", userdate($order->timecreated));
254 $table->data[] = array("<b>$authstrs->settlementdate:</b>", $settled ?
255 userdate($order->settletime) : $authstrs->notsettled);
257 $table->data[] = array("&nbsp;", "<hr size='1' />\n");
259 if (!empty($cmdcapture) and confirm_sesskey()) { // CAPTURE
260 if (!in_array(ORDER_CAPTURE, $status->actions)) {
261 $a = new stdClass;
262 $a->action = $authstrs->capture;
263 error(get_string('youcantdo', 'enrol_authorize', $a));
266 if (empty($confirm)) {
267 $strcaptureyes = get_string('captureyes', 'enrol_authorize');
268 $table->data[] = array("<b>$strs->confirm:</b>",
269 "$strcaptureyes <br />
270 <input type='hidden' name='confirm' value='1' /><input type='submit' name='". ORDER_CAPTURE ."' value='$authstrs->capture' />
271 &nbsp;&nbsp;&nbsp;<a href='index.php?order=$orderno'>$strs->no</a>");
273 else {
274 $message = '';
275 $extra = NULL;
276 if (AN_APPROVED != authorize_action($order, $message, $extra, AN_ACTION_PRIOR_AUTH_CAPTURE)) {
277 $table->data[] = array("<b><font color='red'>$strs->error:</font></b>", $message);
279 else {
280 if (empty($CFG->an_test)) {
281 $user = get_record('user', 'id', $order->userid);
282 if (enrol_into_course($course, $user, 'manual')) {
283 if (!empty($CFG->enrol_mailstudents)) {
284 send_welcome_messages($order->id);
286 redirect("index.php?order=$orderno");
288 else {
289 $table->data[] = array("<b><font color='red'>$strs->error:</font></b>",
290 "Error while trying to enrol ".fullname($user)." in '" . format_string($course->shortname) . "'");
293 else {
294 $table->data[] = array(get_string('testmode', 'enrol_authorize'),
295 get_string('testwarning', 'enrol_authorize'));
299 print_table($table);
301 elseif (!empty($cmdrefund) and confirm_sesskey()) { // REFUND
302 if (!in_array(ORDER_REFUND, $status->actions)) {
303 $a = new stdClass;
304 $a->action = $authstrs->refund;
305 error(get_string('youcantdo', 'enrol_authorize', $a));
308 $extra = new stdClass;
309 $extra->sum = 0.0;
310 $extra->orderid = $orderno;
312 $sql = "SELECT SUM(amount) AS refunded FROM {$CFG->prefix}enrol_authorize_refunds " .
313 "WHERE (orderid = '" . $orderno . "') AND (status = '" . AN_STATUS_CREDIT . "')";
315 if ($refund = get_record_sql($sql)) {
316 $extra->sum = floatval($refund->refunded);
318 $upto = format_float($order->amount - $extra->sum, 2);
319 if ($upto <= 0) {
320 error("Refunded to original amount.");
322 else {
323 $amount = format_float(optional_param('amount', $upto), 2);
324 if (($amount > $upto) or empty($confirm)) {
325 $a = new stdClass;
326 $a->upto = $upto;
327 $strcanbecredit = get_string('canbecredit', 'enrol_authorize', $a);
328 $strhowmuch = get_string('howmuch', 'enrol_authorize');
329 $cbunenrol = print_checkbox('unenrol', '1', !empty($unenrol), '', '', '', true);
330 $table->data[] = array("<b>$authstrs->unenrolstudent</b>", $cbunenrol);
331 $table->data[] = array("<b>$strhowmuch</b>",
332 "<input type='hidden' name='confirm' value='1' />
333 <input type='text' size='5' name='amount' value='$amount' />
334 $strcanbecredit<br /><input type='submit' name='".ORDER_REFUND."' value='$authstrs->refund' />");
336 else {
337 $extra->amount = $amount;
338 $message = '';
339 $success = authorize_action($order, $message, $extra, AN_ACTION_CREDIT);
340 if (AN_APPROVED == $success || AN_REVIEW == $success) {
341 if (empty($CFG->an_test)) {
342 if (empty($extra->id)) {
343 $table->data[] = array("<b><font color='red'>$strs->error:</font></b>", 'insert record error');
345 else {
346 if (!empty($unenrol)) {
347 role_unassign(0, $order->userid, 0, $coursecontext->id);
349 redirect("index.php?order=$orderno");
352 else {
353 $table->data[] = array(get_string('testmode', 'enrol_authorize'),
354 get_string('testwarning', 'enrol_authorize'));
357 else {
358 $table->data[] = array("<b><font color='red'>$strs->error:</font></b>", $message);
362 print_table($table);
364 elseif (!empty($cmdvoid) and confirm_sesskey()) { // VOID
365 $suborderno = optional_param('suborder', 0, PARAM_INT);
366 if (empty($suborderno)) { // cancel original transaction.
367 if (!in_array(ORDER_VOID, $status->actions)) {
368 $a = new stdClass;
369 $a->action = $authstrs->void;
370 error(get_string('youcantdo', 'enrol_authorize', $a));
372 if (empty($confirm)) {
373 $strvoidyes = get_string('voidyes', 'enrol_authorize');
374 $table->data[] = array("<b>$strs->confirm:</b>",
375 "$strvoidyes<br /><input type='hidden' name='".ORDER_VOID."' value='y' />
376 <input type='hidden' name='confirm' value='1' />
377 <input type='submit' value='$authstrs->void' />
378 &nbsp;&nbsp;&nbsp;&nbsp;<a href='index.php?order=$orderno'>$strs->no</a>");
380 else {
381 $extra = NULL;
382 $message = '';
383 if (AN_APPROVED == authorize_action($order, $message, $extra, AN_ACTION_VOID)) {
384 if (empty($CFG->an_test)) {
385 redirect("index.php?order=$orderno");
387 else {
388 $table->data[] = array(get_string('testmode', 'enrol_authorize'),
389 get_string('testwarning', 'enrol_authorize'));
392 else {
393 $table->data[] = array("<b><font color='red'>$strs->error:</font></b>", $message);
397 else { // cancel refunded transaction
398 $sql = "SELECT r.*, e.courseid, e.paymentmethod FROM {$CFG->prefix}enrol_authorize_refunds r " .
399 "INNER JOIN {$CFG->prefix}enrol_authorize e ON r.orderid = e.id " .
400 "WHERE r.id = '$suborderno' AND r.orderid = '$orderno' AND r.status = '" .AN_STATUS_CREDIT. "'";
402 $suborder = get_record_sql($sql);
403 if (!$suborder) { // not found
404 error("Transaction can not be voided because of already been voided.");
406 else {
407 $refundedstatus = authorize_get_status_action($suborder);
408 if (!in_array(ORDER_VOID, $refundedstatus->actions)) {
409 $a = new stdClass;
410 $a->action = $authstrs->void;
411 error(get_string('youcantdo', 'enrol_authorize', $a));
413 unset($suborder->courseid);
414 if (empty($confirm)) {
415 $a = new stdClass;
416 $a->transid = $suborder->transid;
417 $a->amount = $suborder->amount;
418 $strsubvoidyes = get_string('subvoidyes', 'enrol_authorize', $a);
419 $cbunenrol = print_checkbox('unenrol', '1', !empty($unenrol), '', '', '', true);
420 $table->data[] = array("<b>$authstrs->unenrolstudent</b>", $cbunenrol);
421 $table->data[] = array("<b>$strs->confirm:</b>",
422 "$strsubvoidyes<br /><input type='hidden' name='".ORDER_VOID."' value='y' />
423 <input type='hidden' name='confirm' value='1' />
424 <input type='hidden' name='suborder' value='$suborderno' />
425 <input type='submit' value='$authstrs->void' />
426 &nbsp;&nbsp;&nbsp;&nbsp;<a href='index.php?order=$orderno'>$strs->no</a>");
428 else {
429 $message = '';
430 $extra = NULL;
431 if (AN_APPROVED == authorize_action($suborder, $message, $extra, AN_ACTION_VOID)) {
432 if (empty($CFG->an_test)) {
433 if (!empty($unenrol)) {
434 role_unassign(0, $order->userid, 0, $coursecontext->id);
436 redirect("index.php?order=$orderno");
438 else {
439 $table->data[] = array(get_string('testmode', 'enrol_authorize'),
440 get_string('testwarning', 'enrol_authorize'));
443 else {
444 $table->data[] = array("<b><font color='red'>$strs->error:</font></b>", $message);
449 print_table($table);
451 elseif (!empty($cmddelete) and confirm_sesskey()) { // DELETE
452 if (!in_array(ORDER_DELETE, $status->actions)) {
453 $a = new stdClass;
454 $a->action = $authstrs->delete;
455 error(get_string('youcantdo', 'enrol_authorize', $a));
457 if (empty($confirm)) {
458 $cbunenrol = print_checkbox('unenrol', '1', !empty($unenrol), '', '', '', true);
459 $table->data[] = array("<b>$authstrs->unenrolstudent</b>", $cbunenrol);
460 $table->data[] = array("<b>$strs->confirm:</b>",
461 "<input type='hidden' name='".ORDER_DELETE."' value='y' />
462 <input type='hidden' name='confirm' value='1' />
463 <input type='submit' value='$authstrs->delete' />
464 &nbsp;&nbsp;&nbsp;&nbsp;<a href='index.php?order=$orderno'>$strs->no</a>");
466 else {
467 if (!empty($unenrol)) {
468 role_unassign(0, $order->userid, 0, $coursecontext->id);
470 delete_records('enrol_authorize', 'id', $orderno);
471 redirect("index.php");
473 print_table($table);
475 else { // SHOW
476 $actions = '';
477 if (empty($status->actions)) {
478 if (($order->paymentmethod == AN_METHOD_ECHECK) && has_capability('enrol/authorize:uploadcsv', get_context_instance(CONTEXT_USER, $USER->id))) {
479 $actions .= '<a href="uploadcsv.php">'.get_string('uploadcsv', 'enrol_authorize').'</a>';
481 else {
482 $actions .= $strs->none;
485 else {
486 foreach ($status->actions as $value) {
487 $actions .= "<input type='submit' name='$value' value='{$authstrs->$value}' /> ";
490 $table->data[] = array("<b>$strs->action</b>", $actions);
491 print_table($table);
492 if ($settled) { // show refunds.
493 $t2 = new stdClass;
494 $t2->size = array('45%', '15%', '20%', '10%', '10%');
495 $t2->align = array('right', 'right', 'right', 'right', 'right');
496 $t2->head = array($authstrs->settlementdate,
497 $authstrs->transid,
498 $strs->status,
499 $strs->action,
500 $authstrs->amount);
502 $sql = "SELECT r.*, e.courseid, e.paymentmethod FROM {$CFG->prefix}enrol_authorize_refunds r " .
503 "INNER JOIN {$CFG->prefix}enrol_authorize e ON r.orderid = e.id " .
504 "WHERE r.orderid = '$orderno'";
506 $refunds = get_records_sql($sql);
507 if ($refunds) {
508 $sumrefund = floatval(0.0);
509 foreach ($refunds as $rf) {
510 $substatus = authorize_get_status_action($rf);
511 $subactions = '&nbsp;';
512 if (empty($substatus->actions)) {
513 $subactions .= $strs->none;
515 else {
516 foreach ($substatus->actions as $vl) {
517 $subactions .=
518 "<a href='index.php?$vl=y&amp;sesskey=$USER->sesskey&amp;order=$orderno&amp;suborder=$rf->id'>{$authstrs->$vl}</a> ";
521 $sign = '';
522 $color = authorize_get_status_color($substatus->status);
523 if ($substatus->status == 'refunded' or $substatus->status == 'settled') {
524 $sign = '-';
525 $sumrefund += floatval($rf->amount);
527 $t2->data[] = array(
528 userdate($rf->settletime),
529 $rf->transid,
530 "<font style='color:$color'>" .$authstrs->{$substatus->status} . "</font>",
531 $subactions,
532 format_float($sign . $rf->amount, 2)
535 $t2->data[] = array('','',get_string('total'),$order->currency,format_float('-'.$sumrefund, 2));
537 else {
538 $t2->data[] = array('','',get_string('noreturns', 'enrol_authorize'),'','');
540 echo "<h4>" . get_string('returns', 'enrol_authorize') . "</h4>\n";
541 print_table($t2);
544 echo '</div>';
545 echo '</form>';
549 * authorize_get_status_action
551 * @param object $order Order details.
552 * @return object
554 function authorize_get_status_action($order)
556 global $CFG;
557 static $newordertime;
559 if (empty($newordertime)) {
560 $newordertime = time() - 120; // -2 minutes. Order may be still in process.
563 $ret = new stdClass();
564 $ret->actions = array();
566 $canmanage = has_capability('enrol/authorize:managepayments', get_context_instance(CONTEXT_COURSE, $order->courseid));
568 if (intval($order->transid) == 0) { // test transaction or new order
569 if ($order->timecreated < $newordertime) {
570 if ($canmanage) {
571 $ret->actions = array(ORDER_DELETE);
573 $ret->status = 'tested';
575 else {
576 $ret->status = 'new';
578 return $ret;
581 switch ($order->status) {
582 case AN_STATUS_AUTH:
583 if (authorize_expired($order)) {
584 if ($canmanage) {
585 $ret->actions = array(ORDER_DELETE);
587 $ret->status = 'expired';
589 else {
590 if ($canmanage) {
591 $ret->actions = array(ORDER_CAPTURE, ORDER_VOID);
593 $ret->status = 'authorizedpendingcapture';
595 return $ret;
597 case AN_STATUS_AUTHCAPTURE:
598 if (authorize_settled($order)) {
599 if ($canmanage) {
600 if (($order->paymentmethod == AN_METHOD_CC) || ($order->paymentmethod == AN_METHOD_ECHECK && !empty($order->refundinfo))) {
601 $ret->actions = array(ORDER_REFUND);
604 $ret->status = 'settled';
606 else {
607 if ($order->paymentmethod == AN_METHOD_CC && $canmanage) {
608 $ret->actions = array(ORDER_VOID);
610 $ret->status = 'capturedpendingsettle';
612 return $ret;
614 case AN_STATUS_CREDIT:
615 if (authorize_settled($order)) {
616 $ret->status = 'settled';
618 else {
619 if ($order->paymentmethod == AN_METHOD_CC && $canmanage) {
620 $ret->actions = array(ORDER_VOID);
622 $ret->status = 'refunded';
624 return $ret;
626 case AN_STATUS_VOID:
627 $ret->status = 'cancelled';
628 return $ret;
630 case AN_STATUS_EXPIRE:
631 if ($canmanage) {
632 $ret->actions = array(ORDER_DELETE);
634 $ret->status = 'expired';
635 return $ret;
637 case AN_STATUS_UNDERREVIEW:
638 $ret->status = 'underreview';
639 return $ret;
641 case AN_STATUS_APPROVEDREVIEW:
642 $ret->status = 'approvedreview';
643 return $ret;
645 case AN_STATUS_REVIEWFAILED:
646 if ($canmanage) {
647 $ret->actions = array(ORDER_DELETE);
649 $ret->status = 'reviewfailed';
650 return $ret;
652 default:
653 return $ret;
658 function authorize_get_status_color($status)
660 $color = 'black';
661 switch ($status)
663 case 'settled':
664 case 'approvedreview':
665 case 'capturedpendingsettle':
666 $color = '#339900'; // green
667 break;
669 case 'new':
670 case 'tested':
671 case 'underreview':
672 case 'authorizedpendingcapture':
673 $color = '#FF6600'; // orange
674 break;
676 case 'expired':
677 case 'cancelled':
678 case 'refunded';
679 case 'reviewfailed':
680 $color = '#FF0033'; // red
681 break;
683 return $color;