Added check for <text> fields that contain markup (an error!)
[moodle-linuxchix.git] / enrol / authorize / locallib.php
blob748125b827698f509f53c1dbe85a108f68687c64
1 <?php // $Id$
3 if (!defined('MOODLE_INTERNAL')) {
4 die('Direct access to this script is forbidden.');
7 define('ORDER_CAPTURE', 'capture');
8 define('ORDER_DELETE', 'delete');
9 define('ORDER_REFUND', 'refund');
10 define('ORDER_VOID', 'void');
12 /**
13 * authorize_print_orders
16 function authorize_print_orders($courseid, $userid)
18 global $CFG, $USER, $SITE;
19 global $strs, $authstrs;
20 require_once($CFG->libdir.'/tablelib.php');
22 $perpage = 10;
23 $status = optional_param('status', AN_STATUS_NONE, PARAM_INT);
24 $searchtype = optional_param('searchtype', 'id', PARAM_ALPHA);
25 $idortransid = optional_param('idortransid', '0', PARAM_INT);
26 $showonlymy = optional_param('showonlymy', 0, PARAM_BOOL);
28 $canmanagepayments = has_capability('enrol/authorize:managepayments', get_context_instance(CONTEXT_COURSE, $courseid));
30 if ($showonlymy || !$canmanagepayments) {
31 $userid = $USER->id;
34 $baseurl = $CFG->wwwroot."/enrol/authorize/index.php?user=$userid";
35 $statusmenu = array(AN_STATUS_NONE => $strs->all,
36 AN_STATUS_AUTH | AN_STATUS_UNDERREVIEW | AN_STATUS_APPROVEDREVIEW => $authstrs->allpendingorders,
37 AN_STATUS_AUTH => $authstrs->authorizedpendingcapture,
38 AN_STATUS_AUTHCAPTURE => $authstrs->authcaptured,
39 AN_STATUS_CREDIT => $authstrs->refunded,
40 AN_STATUS_VOID => $authstrs->cancelled,
41 AN_STATUS_EXPIRE => $authstrs->expired,
42 AN_STATUS_UNDERREVIEW => $authstrs->underreview,
43 AN_STATUS_APPROVEDREVIEW => $authstrs->approvedreview,
44 AN_STATUS_REVIEWFAILED => $authstrs->reviewfailed,
45 AN_STATUS_TEST => $authstrs->tested
48 $sql = "SELECT c.id, c.fullname FROM {$CFG->prefix}course c INNER JOIN {$CFG->prefix}enrol_authorize e ON c.id = e.courseid ";
49 if ($userid > 0) {
50 $sql .= "WHERE (e.userid='$userid') ";
52 $sql .= "ORDER BY c.sortorder, c.fullname";
53 if (($popupcrs = get_records_sql_menu($sql))) {
54 $popupcrs = array($SITE->id => $SITE->fullname) + $popupcrs;
55 echo "<table border='0' width='100%' cellspacing='0' cellpadding='3' class='generaltable generalbox'>";
56 echo "<tr>";
57 echo "<td width='5%' valign='top'>$strs->status: </td><td width='10%'>";
58 popup_form($baseurl.'&amp;course='.$courseid.'&amp;status=',$statusmenu,'statusmenu',$status,'','','',false);
59 if ($canmanagepayments) {
60 echo "<br />\n";
61 print_checkbox('showonlymy', '1', $userid == $USER->id, get_string('mypaymentsonly', 'enrol_authorize'), '',
62 "var locationtogo = '{$CFG->wwwroot}/enrol/authorize/index.php?status=$status&amp;course=$courseid';
63 locationtogo += '&amp;user=' + (this.checked ? '$USER->id' : '0');
64 top.location.href=locationtogo;");
66 echo "</td>\n";
67 echo "<td width='5%' valign='top'>$strs->course: </td><td width='10%' valign='top'>";
68 popup_form($baseurl.'&amp;status='.$status.'&amp;course=',$popupcrs,'coursesmenu',$courseid,'','','',false);echo"</td>\n";
69 if (has_capability('enrol/authorize:uploadcsv', get_context_instance(CONTEXT_USER, $USER->id))) {
70 echo "<form method='get' action='uploadcsv.php'>";
71 echo "<td rowspan='2' align='right' valign='middle' width='50%'><div><input type='submit' value='".get_string('uploadcsv', 'enrol_authorize')."' /></div></td>";
72 echo "</form>";
74 else {
75 echo "<td rowspan=2 width='100%'>&nbsp;</td>";
77 echo "</tr>\n";
79 echo "<tr><td>$strs->search: </td>"; $searchmenu = array('id' => $authstrs->orderid, 'transid' => $authstrs->transid);
80 echo "<form method='POST' action='index.php' autocomplete='off'>";
81 echo "<td colspan='3'>"; choose_from_menu($searchmenu, 'searchtype', $searchtype, '');
82 echo " = <fieldset class=\"invisiblefieldset\"><input type='text' size='14' name='idortransid' value='' /> ";
83 echo "<input type='submit' value='$strs->search' /></fieldset></td>";
84 echo "</form>";
85 echo "</tr>";
86 echo "</table>";
89 $table = new flexible_table('enrol-authorize');
90 $table->set_attribute('width', '100%');
91 $table->set_attribute('cellspacing', '0');
92 $table->set_attribute('cellpadding', '3');
93 $table->set_attribute('id', 'orders');
94 $table->set_attribute('class', 'generaltable generalbox');
96 $table->define_columns(array('id', 'timecreated', 'userid', 'status', ''));
97 $table->define_headers(array($authstrs->orderid, $strs->time, $authstrs->nameoncard, $strs->status, $strs->action));
98 $table->define_baseurl($baseurl."&amp;status=$status&amp;course=$courseid");
100 $table->sortable(true, 'id', SORT_DESC);
101 $table->pageable(true);
102 $table->setup();
104 $select = "SELECT e.id, e.paymentmethod, e.transid, e.courseid, e.userid, e.status, e.ccname, e.timecreated, e.settletime ";
105 $from = "FROM {$CFG->prefix}enrol_authorize e ";
106 $where = "WHERE (1=1) ";
108 if ($status > AN_STATUS_NONE) {
109 switch ($status)
111 case AN_STATUS_AUTH | AN_STATUS_UNDERREVIEW | AN_STATUS_APPROVEDREVIEW:
112 $where .= 'AND (e.status IN('.AN_STATUS_AUTH.','.AN_STATUS_UNDERREVIEW.','.AN_STATUS_APPROVEDREVIEW.')) ';
113 break;
115 case AN_STATUS_CREDIT:
116 $from .= "INNER JOIN {$CFG->prefix}enrol_authorize_refunds r ON e.id = r.orderid ";
117 $where .= "AND (e.status = '" . AN_STATUS_AUTHCAPTURE . "') ";
118 break;
120 case AN_STATUS_TEST:
121 $newordertime = time() - 120; // -2 minutes. Order may be still in process.
122 $where .= "AND (e.status = '" . AN_STATUS_NONE . "') AND (e.transid = '0') AND (e.timecreated < $newordertime) ";
123 break;
125 default:
126 $where .= "AND (e.status = '$status') ";
127 break;
130 else {
131 if (empty($CFG->an_test)) {
132 $where .= "AND (e.status != '" . AN_STATUS_NONE . "') ";
136 if ($courseid != SITEID) {
137 $where .= "AND (e.courseid = '" . $courseid . "') ";
140 if (!empty($idortransid)) {
141 // Ignore old where.
142 if ($searchtype == 'transid') {
143 $where = "WHERE (e.transid = $idortransid) ";
145 else {
146 $where = "WHERE (e.id = $idortransid) ";
150 // This must be always last where!!!
151 if ($userid > 0) {
152 $where .= "AND (e.userid = '" . $userid . "') ";
155 if (($sort = $table->get_sql_sort())) {
156 $sort = ' ORDER BY ' . $sort;
159 $totalcount = count_records_sql('SELECT COUNT(*) ' . $from . $where);
160 $table->initialbars($totalcount > $perpage);
161 $table->pagesize($perpage, $totalcount);
163 if (($records = get_records_sql($select . $from . $where . $sort, $table->get_page_start(), $table->get_page_size()))) {
164 foreach ($records as $record) {
165 $actionstatus = authorize_get_status_action($record);
166 $color = authorize_get_status_color($actionstatus->status);
167 $actions = '';
169 if (empty($actionstatus->actions)) {
170 $actions .= $strs->none;
172 else {
173 foreach ($actionstatus->actions as $value) {
174 $actions .= "&nbsp;&nbsp;<a href='index.php?$value=y&amp;sesskey=$USER->sesskey&amp;order=$record->id'>{$authstrs->$value}</a> ";
178 $table->add_data(array(
179 "<a href='index.php?order=$record->id'>$record->id</a>",
180 userdate($record->timecreated),
181 $record->ccname,
182 "<font style='color:$color'>" . $authstrs->{$actionstatus->status} . "</font>",
183 $actions
188 $table->print_html();
192 * authorize_print_order_details
194 * @param int $orderno
196 function authorize_print_order_details($orderno)
198 global $CFG, $USER;
199 global $strs, $authstrs;
201 $cmdcapture = optional_param(ORDER_CAPTURE, '', PARAM_ALPHA);
202 $cmddelete = optional_param(ORDER_DELETE, '', PARAM_ALPHA);
203 $cmdrefund = optional_param(ORDER_REFUND, '', PARAM_ALPHA);
204 $cmdvoid = optional_param(ORDER_VOID, '', PARAM_ALPHA);
206 $unenrol = optional_param('unenrol', 0, PARAM_BOOL);
207 $confirm = optional_param('confirm', 0, PARAM_BOOL);
209 $table = new stdClass;
210 $table->width = '100%';
211 $table->size = array('30%', '70%');
212 $table->align = array('right', 'left');
214 $order = get_record('enrol_authorize', 'id', $orderno);
215 if (!$order) {
216 notice("Order $orderno not found.", "index.php");
217 return;
220 $course = get_record('course', 'id', $order->courseid);
221 $coursecontext = get_context_instance(CONTEXT_COURSE, $course->id);
223 if ($USER->id != $order->userid) { // Current user viewing someone else's order
224 require_capability('enrol/authorize:managepayments', $coursecontext);
227 echo "<form action=\"index.php\" method=\"post\">\n";
228 echo "<div>";
229 echo "<input type=\"hidden\" name=\"order\" value=\"$orderno\" />\n";
230 echo "<input type=\"hidden\" name=\"sesskey\" value=\"" . sesskey() . "\" />";
232 $settled = authorize_settled($order);
233 $status = authorize_get_status_action($order);
235 $table->data[] = array("<b>$authstrs->paymentmethod:</b>",
236 ($order->paymentmethod == AN_METHOD_CC ? $authstrs->methodcc : $authstrs->methodecheck));
237 $table->data[] = array("<b>$authstrs->orderid:</b>", $orderno);
238 $table->data[] = array("<b>$authstrs->transid:</b>", $order->transid);
239 $table->data[] = array("<b>$authstrs->amount:</b>", "$order->currency $order->amount");
240 if (empty($cmdcapture) and empty($cmdrefund) and empty($cmdvoid) and empty($cmddelete)) {
241 $color = authorize_get_status_color($status->status);
242 $table->data[] = array("<b>$strs->course:</b>", format_string($course->shortname));
243 $table->data[] = array("<b>$strs->status:</b>", "<font style='color:$color'>" . $authstrs->{$status->status} . "</font>");
244 if ($order->paymentmethod == AN_METHOD_CC) {
245 $table->data[] = array("<b>$authstrs->nameoncard:</b>", $order->ccname);
247 else {
248 $table->data[] = array("<b>$authstrs->echeckfirslasttname:</b>", $order->ccname);
250 $table->data[] = array("<b>$strs->time:</b>", userdate($order->timecreated));
251 $table->data[] = array("<b>$authstrs->settlementdate:</b>", $settled ?
252 userdate($order->settletime) : $authstrs->notsettled);
254 $table->data[] = array("&nbsp;", "<hr size='1' />\n");
256 if (!empty($cmdcapture) and confirm_sesskey()) { // CAPTURE
257 if (!in_array(ORDER_CAPTURE, $status->actions)) {
258 $a = new stdClass;
259 $a->action = $authstrs->capture;
260 error(get_string('youcantdo', 'enrol_authorize', $a));
263 if (empty($confirm)) {
264 $strcaptureyes = get_string('captureyes', 'enrol_authorize');
265 $table->data[] = array("<b>$strs->confirm:</b>",
266 "$strcaptureyes <br />
267 <input type='hidden' name='confirm' value='1' /><input type='submit' name='". ORDER_CAPTURE ."' value='$authstrs->capture' />
268 &nbsp;&nbsp;&nbsp;<a href='index.php?order=$orderno'>$strs->no</a>");
270 else {
271 $message = '';
272 $extra = NULL;
273 if (AN_APPROVED != authorize_action($order, $message, $extra, AN_ACTION_PRIOR_AUTH_CAPTURE)) {
274 $table->data[] = array("<b><font color='red'>$strs->error:</font></b>", $message);
276 else {
277 if (empty($CFG->an_test)) {
278 $user = get_record('user', 'id', $order->userid);
279 if (enrol_into_course($course, $user, 'authorize')) {
280 if (!empty($CFG->enrol_mailstudents)) {
281 send_welcome_messages($order->id);
283 redirect("index.php?order=$orderno");
285 else {
286 $table->data[] = array("<b><font color='red'>$strs->error:</font></b>",
287 "Error while trying to enrol ".fullname($user)." in '" . format_string($course->shortname) . "'");
290 else {
291 $table->data[] = array(get_string('testmode', 'enrol_authorize'),
292 get_string('testwarning', 'enrol_authorize'));
296 print_table($table);
298 elseif (!empty($cmdrefund) and confirm_sesskey()) { // REFUND
299 if (!in_array(ORDER_REFUND, $status->actions)) {
300 $a = new stdClass;
301 $a->action = $authstrs->refund;
302 error(get_string('youcantdo', 'enrol_authorize', $a));
305 $refunded = 0.0;
306 $sql = "SELECT SUM(amount) AS refunded FROM {$CFG->prefix}enrol_authorize_refunds " .
307 "WHERE (orderid = '" . $orderno . "') AND (status = '" . AN_STATUS_CREDIT . "')";
309 if (($refundval = get_field_sql($sql))) {
310 $refunded = floatval($refundval);
312 $upto = round($order->amount - $refunded, 2);
313 if ($upto <= 0) {
314 error("Refunded to original amount.");
316 else {
317 $amount = round(optional_param('amount', $upto), 2);
318 if (($amount > $upto) or empty($confirm)) {
319 $a = new stdClass;
320 $a->upto = $upto;
321 $strcanbecredit = get_string('canbecredit', 'enrol_authorize', $a);
322 $strhowmuch = get_string('howmuch', 'enrol_authorize');
323 $cbunenrol = print_checkbox('unenrol', '1', !empty($unenrol), '', '', '', true);
324 $table->data[] = array("<b>$authstrs->unenrolstudent</b>", $cbunenrol);
325 $table->data[] = array("<b>$strhowmuch</b>",
326 "<input type='hidden' name='confirm' value='1' />
327 <input type='text' size='5' name='amount' value='$amount' />
328 $strcanbecredit<br /><input type='submit' name='".ORDER_REFUND."' value='$authstrs->refund' />");
330 else {
331 $extra = new stdClass;
332 $extra->orderid = $orderno;
333 $extra->amount = $amount;
334 $message = '';
335 $success = authorize_action($order, $message, $extra, AN_ACTION_CREDIT);
336 if (AN_APPROVED == $success || AN_REVIEW == $success) {
337 if (empty($CFG->an_test)) {
338 if (empty($extra->id)) {
339 $table->data[] = array("<b><font color='red'>$strs->error:</font></b>", 'insert record error');
341 else {
342 if (!empty($unenrol)) {
343 role_unassign(0, $order->userid, 0, $coursecontext->id);
345 redirect("index.php?order=$orderno");
348 else {
349 $table->data[] = array(get_string('testmode', 'enrol_authorize'),
350 get_string('testwarning', 'enrol_authorize'));
353 else {
354 $table->data[] = array("<b><font color='red'>$strs->error:</font></b>", $message);
358 print_table($table);
360 elseif (!empty($cmdvoid) and confirm_sesskey()) { // VOID
361 $suborderno = optional_param('suborder', 0, PARAM_INT);
362 if (empty($suborderno)) { // cancel original transaction.
363 if (!in_array(ORDER_VOID, $status->actions)) {
364 $a = new stdClass;
365 $a->action = $authstrs->void;
366 error(get_string('youcantdo', 'enrol_authorize', $a));
368 if (empty($confirm)) {
369 $strvoidyes = get_string('voidyes', 'enrol_authorize');
370 $table->data[] = array("<b>$strs->confirm:</b>",
371 "$strvoidyes<br /><input type='hidden' name='".ORDER_VOID."' value='y' />
372 <input type='hidden' name='confirm' value='1' />
373 <input type='submit' value='$authstrs->void' />
374 &nbsp;&nbsp;&nbsp;&nbsp;<a href='index.php?order=$orderno'>$strs->no</a>");
376 else {
377 $extra = NULL;
378 $message = '';
379 if (AN_APPROVED == authorize_action($order, $message, $extra, AN_ACTION_VOID)) {
380 if (empty($CFG->an_test)) {
381 redirect("index.php?order=$orderno");
383 else {
384 $table->data[] = array(get_string('testmode', 'enrol_authorize'),
385 get_string('testwarning', 'enrol_authorize'));
388 else {
389 $table->data[] = array("<b><font color='red'>$strs->error:</font></b>", $message);
393 else { // cancel refunded transaction
394 $sql = "SELECT r.*, e.courseid, e.paymentmethod FROM {$CFG->prefix}enrol_authorize_refunds r " .
395 "INNER JOIN {$CFG->prefix}enrol_authorize e ON r.orderid = e.id " .
396 "WHERE r.id = '$suborderno' AND r.orderid = '$orderno' AND r.status = '" .AN_STATUS_CREDIT. "'";
398 $suborder = get_record_sql($sql);
399 if (!$suborder) { // not found
400 error("Transaction can not be voided because of already been voided.");
402 else {
403 $refundedstatus = authorize_get_status_action($suborder);
404 if (!in_array(ORDER_VOID, $refundedstatus->actions)) {
405 $a = new stdClass;
406 $a->action = $authstrs->void;
407 error(get_string('youcantdo', 'enrol_authorize', $a));
409 unset($suborder->courseid);
410 if (empty($confirm)) {
411 $a = new stdClass;
412 $a->transid = $suborder->transid;
413 $a->amount = $suborder->amount;
414 $strsubvoidyes = get_string('subvoidyes', 'enrol_authorize', $a);
415 $cbunenrol = print_checkbox('unenrol', '1', !empty($unenrol), '', '', '', true);
416 $table->data[] = array("<b>$authstrs->unenrolstudent</b>", $cbunenrol);
417 $table->data[] = array("<b>$strs->confirm:</b>",
418 "$strsubvoidyes<br /><input type='hidden' name='".ORDER_VOID."' value='y' />
419 <input type='hidden' name='confirm' value='1' />
420 <input type='hidden' name='suborder' value='$suborderno' />
421 <input type='submit' value='$authstrs->void' />
422 &nbsp;&nbsp;&nbsp;&nbsp;<a href='index.php?order=$orderno'>$strs->no</a>");
424 else {
425 $message = '';
426 $extra = NULL;
427 if (AN_APPROVED == authorize_action($suborder, $message, $extra, AN_ACTION_VOID)) {
428 if (empty($CFG->an_test)) {
429 if (!empty($unenrol)) {
430 role_unassign(0, $order->userid, 0, $coursecontext->id);
432 redirect("index.php?order=$orderno");
434 else {
435 $table->data[] = array(get_string('testmode', 'enrol_authorize'),
436 get_string('testwarning', 'enrol_authorize'));
439 else {
440 $table->data[] = array("<b><font color='red'>$strs->error:</font></b>", $message);
445 print_table($table);
447 elseif (!empty($cmddelete) and confirm_sesskey()) { // DELETE
448 if (!in_array(ORDER_DELETE, $status->actions)) {
449 $a = new stdClass;
450 $a->action = $authstrs->delete;
451 error(get_string('youcantdo', 'enrol_authorize', $a));
453 if (empty($confirm)) {
454 $cbunenrol = print_checkbox('unenrol', '1', !empty($unenrol), '', '', '', true);
455 $table->data[] = array("<b>$authstrs->unenrolstudent</b>", $cbunenrol);
456 $table->data[] = array("<b>$strs->confirm:</b>",
457 "<input type='hidden' name='".ORDER_DELETE."' value='y' />
458 <input type='hidden' name='confirm' value='1' />
459 <input type='submit' value='$authstrs->delete' />
460 &nbsp;&nbsp;&nbsp;&nbsp;<a href='index.php?order=$orderno'>$strs->no</a>");
462 else {
463 if (!empty($unenrol)) {
464 role_unassign(0, $order->userid, 0, $coursecontext->id);
466 delete_records('enrol_authorize', 'id', $orderno);
467 redirect("index.php");
469 print_table($table);
471 else { // SHOW
472 $actions = '';
473 if (empty($status->actions)) {
474 if (($order->paymentmethod == AN_METHOD_ECHECK) && has_capability('enrol/authorize:uploadcsv', get_context_instance(CONTEXT_USER, $USER->id))) {
475 $actions .= '<a href="uploadcsv.php">'.get_string('uploadcsv', 'enrol_authorize').'</a>';
477 else {
478 $actions .= $strs->none;
481 else {
482 foreach ($status->actions as $value) {
483 $actions .= "<input type='submit' name='$value' value='{$authstrs->$value}' /> ";
486 $table->data[] = array("<b>$strs->action</b>", $actions);
487 print_table($table);
488 if ($settled) { // show refunds.
489 $t2 = new stdClass;
490 $t2->size = array('45%', '15%', '20%', '10%', '10%');
491 $t2->align = array('right', 'right', 'right', 'right', 'right');
492 $t2->head = array($authstrs->settlementdate,
493 $authstrs->transid,
494 $strs->status,
495 $strs->action,
496 $authstrs->amount);
498 $sql = "SELECT r.*, e.courseid, e.paymentmethod FROM {$CFG->prefix}enrol_authorize_refunds r " .
499 "INNER JOIN {$CFG->prefix}enrol_authorize e ON r.orderid = e.id " .
500 "WHERE r.orderid = '$orderno'";
502 $refunds = get_records_sql($sql);
503 if ($refunds) {
504 $sumrefund = floatval(0.0);
505 foreach ($refunds as $rf) {
506 $substatus = authorize_get_status_action($rf);
507 $subactions = '&nbsp;';
508 if (empty($substatus->actions)) {
509 $subactions .= $strs->none;
511 else {
512 foreach ($substatus->actions as $vl) {
513 $subactions .=
514 "<a href='index.php?$vl=y&amp;sesskey=$USER->sesskey&amp;order=$orderno&amp;suborder=$rf->id'>{$authstrs->$vl}</a> ";
517 $sign = '';
518 $color = authorize_get_status_color($substatus->status);
519 if ($substatus->status == 'refunded' or $substatus->status == 'settled') {
520 $sign = '-';
521 $sumrefund += floatval($rf->amount);
523 $t2->data[] = array(
524 userdate($rf->settletime),
525 $rf->transid,
526 "<font style='color:$color'>" .$authstrs->{$substatus->status} . "</font>",
527 $subactions,
528 format_float($sign . $rf->amount, 2)
531 $t2->data[] = array('','',get_string('total'),$order->currency,format_float('-'.$sumrefund, 2));
533 else {
534 $t2->data[] = array('','',get_string('noreturns', 'enrol_authorize'),'','');
536 echo "<h4>" . get_string('returns', 'enrol_authorize') . "</h4>\n";
537 print_table($t2);
540 echo '</div>';
541 echo '</form>';
545 * authorize_get_status_action
547 * @param object $order Order details.
548 * @return object
550 function authorize_get_status_action($order)
552 global $CFG;
553 static $newordertime;
555 if (empty($newordertime)) {
556 $newordertime = time() - 120; // -2 minutes. Order may be still in process.
559 $ret = new stdClass();
560 $ret->actions = array();
562 $canmanage = has_capability('enrol/authorize:managepayments', get_context_instance(CONTEXT_COURSE, $order->courseid));
564 if (intval($order->transid) == 0) { // test transaction or new order
565 if ($order->timecreated < $newordertime) {
566 if ($canmanage) {
567 $ret->actions = array(ORDER_DELETE);
569 $ret->status = 'tested';
571 else {
572 $ret->status = 'new';
574 return $ret;
577 switch ($order->status) {
578 case AN_STATUS_AUTH:
579 if (authorize_expired($order)) {
580 if ($canmanage) {
581 $ret->actions = array(ORDER_DELETE);
583 $ret->status = 'expired';
585 else {
586 if ($canmanage) {
587 $ret->actions = array(ORDER_CAPTURE, ORDER_VOID);
589 $ret->status = 'authorizedpendingcapture';
591 return $ret;
593 case AN_STATUS_AUTHCAPTURE:
594 if (authorize_settled($order)) {
595 if ($canmanage) {
596 if (($order->paymentmethod == AN_METHOD_CC) || ($order->paymentmethod == AN_METHOD_ECHECK && !empty($order->refundinfo))) {
597 $ret->actions = array(ORDER_REFUND);
600 $ret->status = 'settled';
602 else {
603 if ($order->paymentmethod == AN_METHOD_CC && $canmanage) {
604 $ret->actions = array(ORDER_VOID);
606 $ret->status = 'capturedpendingsettle';
608 return $ret;
610 case AN_STATUS_CREDIT:
611 if (authorize_settled($order)) {
612 $ret->status = 'settled';
614 else {
615 if ($order->paymentmethod == AN_METHOD_CC && $canmanage) {
616 $ret->actions = array(ORDER_VOID);
618 $ret->status = 'refunded';
620 return $ret;
622 case AN_STATUS_VOID:
623 $ret->status = 'cancelled';
624 return $ret;
626 case AN_STATUS_EXPIRE:
627 if ($canmanage) {
628 $ret->actions = array(ORDER_DELETE);
630 $ret->status = 'expired';
631 return $ret;
633 case AN_STATUS_UNDERREVIEW:
634 $ret->status = 'underreview';
635 return $ret;
637 case AN_STATUS_APPROVEDREVIEW:
638 $ret->status = 'approvedreview';
639 return $ret;
641 case AN_STATUS_REVIEWFAILED:
642 if ($canmanage) {
643 $ret->actions = array(ORDER_DELETE);
645 $ret->status = 'reviewfailed';
646 return $ret;
648 default:
649 return $ret;
654 function authorize_get_status_color($status)
656 $color = 'black';
657 switch ($status)
659 case 'settled':
660 case 'approvedreview':
661 case 'capturedpendingsettle':
662 $color = '#339900'; // green
663 break;
665 case 'new':
666 case 'tested':
667 case 'underreview':
668 case 'authorizedpendingcapture':
669 $color = '#FF6600'; // orange
670 break;
672 case 'expired':
673 case 'cancelled':
674 case 'refunded';
675 case 'reviewfailed':
676 $color = '#FF0033'; // red
677 break;
679 return $color;