[LON-CAPA-cvs] cvs: modules /raeburn/register register.pm
raeburn
lon-capa-cvs-allow@mail.lon-capa.org
Mon, 02 Apr 2007 20:21:50 -0000
This is a MIME encoded message
--raeburn1175545310
Content-Type: text/plain
raeburn Mon Apr 2 16:21:50 2007 EDT
Modified files:
/modules/raeburn/register register.pm
Log:
Form can contain hidden form elements.
Additional book-keeping to keep track of credits from returned items used as payment for new purchases in same webcredit transaction.
Set e-mail for production
Point at production payment web site.
Message about refund deadline
Pending refund information stored in refunds table
Users in admin group can view registration form prior to open date.
--raeburn1175545310
Content-Type: text/plain
Content-Disposition: attachment; filename="raeburn-20070402162150.txt"
Index: modules/raeburn/register/register.pm
diff -u modules/raeburn/register/register.pm:1.11 modules/raeburn/register/register.pm:1.12
--- modules/raeburn/register/register.pm:1.11 Fri Mar 30 18:49:20 2007
+++ modules/raeburn/register/register.pm Mon Apr 2 16:21:47 2007
@@ -207,8 +207,7 @@
if ($current_page == 3) {
my $status = $dbh->selectrow_array("SELECT status FROM event_registration WHERE user_id = $quoted_user AND event_id = '$event_id'");
&display_three($r,$event,$year,$event_id,$status,$domain,$portal,$returnpage,$exitpage,$dbh,$current_page,$contact_email,$contact_name,\@sponsors,\%sponsorinfo);
- }
- if ($current_page == 2) {
+ } elsif ($current_page == 2) {
&display_two($r,$event,$year,$event_id,\%params,$user,$domain,$portal,$returnpage,$exitpage,\%items,\@info,\@workshop,$dbh,$current_page,$contact_email,$contact_name,\%form_elements,\@rowitems,\@rowtitles,\@sponsors,\%sponsorinfo,$fees,\%feeinfo);
} else {
&display_one($r,$event_id,\%params,$user,\$domain,$portal,$returnpage,$exitpage,\%items,\@info,\@workshop,$dbh,$current_page,$contact_email,$contact_name,\%form_elements,\@rowitems,\@rowtitles,\@sponsors,\%sponsorinfo,$fees,\%feeinfo);
@@ -394,10 +393,10 @@
my $payinfo;
if ($fees) {
my (%total,%balance,%credit);
- my $statement = "SELECT t.iid,t.quantity,t.status,t.amount FROM purchaser p, transactions t, webcredit w WHERE p.event_id = '$event_id' AND p.user_id = $quoted_user AND p.pid = t.pid AND w.wid = t.wid AND w.state IS NOT NULL ORDER BY t.tid";
+ my $statement = "SELECT t.tid,t.iid,t.quantity,t.status,t.amount FROM purchaser p, transactions t, webcredit w WHERE p.event_id = '$event_id' AND p.user_id = $quoted_user AND p.pid = t.pid AND w.wid = t.wid AND w.state IS NOT NULL ORDER BY t.tid";
my $sth = $dbh->prepare("$statement");
$sth->execute();
- while (my ($iid,$quant,$status,$amount) = $sth->fetchrow_array) {
+ while (my ($tid,$iid,$quant,$iidstatus,$amount) = $sth->fetchrow_array) {
if ($iid) {
$total{$iid} += $quant;
$balance{$iid} += $amount;
@@ -482,12 +481,16 @@
my ($registeropen,$registerclose,$creditclose) = $dbh->selectrow_array("SELECT registeropen,registerclose,endcredit FROM event_config WHERE event_id = '$event_id'");
my ($regopen,$regclose,$opendate,$closedate,$endcredit);
my $now = time;
+ $endcredit = 0;
+ if ($creditclose) {
+ $endcredit = &UnixDate($creditclose, "%s");
+ }
my $regaccess = 'current';
if (defined($registeropen)) {
$regopen = &UnixDate($registeropen, "%s");
$opendate = localtime($regopen);
if ($now < $regopen) {
- unless ($user eq 'raeburn:msu' || $user eq 'kortemey:msu' || $user eq 'astenger:uiuc' || $user eq 'mmichae:uiuc') {
+ if ((!(&authorized($dbh,$quoted_user,$event_id))) && ($user ne 'itds@msu.edu')) {
$regaccess = 'future';
}
}
@@ -731,12 +734,21 @@
} else {
$r->print('<br />');
}
+ if ($fees) {
+ $r->print(&refund_info($endcredit,$now).'<br />');
+ }
} elsif ($status eq 'cancel') {
$r->print("<b>Your previous registration for the $year LON-CAPA $event was cancelled.</b> ");
if ($regaccess eq 'current') {
- $r->print("<b>Use this form to reactivate your cancelled registration.</b><br /><br />");
+ $r->print("<b>Use this form to reactivate your cancelled registration.</b><br />");
+ if ($fees) {
+ if (keys(%{$feeinfo}) > 0) {
+ $r->print(&feedisplay($feeinfo));
+ $r->print(&refund_info($endcredit,$now).'<br />');
+ }
+ }
} elsif ($regaccess eq 'past') {
- $r->print("<b>Reactivation of cancelled registrations is not currently available as new registrations will not be allowed until $opendate");
+ $r->print("<b>Reactivation of cancelled registrations is not currently available as registration closed on $closedate");
}
if ($payinfo) {
$r->print('<br />'.$payinfo.'<br />');
@@ -745,21 +757,9 @@
if ($regaccess eq 'current') {
$r->print("<b>Please submit your registration for the $year LON-CAPA $event.</b>");
if ($fees) {
- $r->print("<br />After submitting this form you will be directed to MSU's secure payment site to provide your credit card details, so the registration fee(s) can be collected:<br />");
if (keys(%{$feeinfo}) > 0) {
- $r->print('<ul>');
- foreach my $item (sort(keys(%{$feeinfo}))) {
- $r->print('<li>');
- if ($$feeinfo{$item}{reqd} eq 'N') {
- $r->print('optional ');
- }
- $r->print($$feeinfo{$item}{longdesc}.' - $'.$$feeinfo{$item}{cost});
- if ($$feeinfo{$item}{'type'} eq 'accomm') {
- $r->print(' (per night)');
- }
- $r->print('</li>');
- }
- $r->print('</ul>');
+ $r->print(&feedisplay($feeinfo));
+ $r->print(&refund_info($endcredit,$now).'<br />');
}
}
} elsif ($regaccess eq 'future') {
@@ -851,11 +851,15 @@
if ($$form_elements{$$rowitems[$i][$j]}{text_position} eq 'above') {
$r->print('<br />');
} else {
- $r->print(': ');
+ if ($$form_elements{$$rowitems[$i][$j]}{title} ne '') {
+ $r->print(': ');
+ }
}
}
}
- if ($$form_elements{$$rowitems[$i][$j]}{type} eq 'textbox') {
+ if ($$form_elements{$$rowitems[$i][$j]}{type} eq 'hidden') {
+ $r->print('<input type="hidden" name="'.$$rowitems[$i][$j].'" value="'.$$form_elements{$$rowitems[$i][$j]}{contents}.'">');
+ } elsif ($$form_elements{$$rowitems[$i][$j]}{type} eq 'textbox') {
$r->print('<input type="text" size="'.$$form_elements{$$rowitems[$i][$j]}{size}.'" name="'.$$rowitems[$i][$j].'" value="'.$userinfo{$$rowitems[$i][$j]}.'">');
} elsif ($$form_elements{$$rowitems[$i][$j]}{type} eq 'radio') {
my @items = split/\&/,$$form_elements{$$rowitems[$i][$j]}{contents};
@@ -1350,10 +1354,10 @@
my $curr_pid = $dbh->selectrow_array("SELECT pid FROM purchaser WHERE event_id = '$event_id' AND user_id = $quoted_user");
my $currstatus = $dbh->selectrow_array("SELECT status FROM event_registration WHERE user_id = $quoted_user AND event_id = '$event_id'");
if ($fees) {
- my $statement = "SELECT t.iid,t.quantity,t.status,t.amount FROM purchaser p, transactions t, webcredit w WHERE p.event_id = '$event_id' AND p.user_id = $quoted_user AND p.pid = t.pid AND w.wid = t.wid AND w.state IS NOT NULL ORDER BY t.tid";
+ my $statement = "SELECT t.tid,t.iid,t.quantity,t.status,t.amount FROM purchaser p, transactions t, webcredit w WHERE (p.event_id = '$event_id' AND p.user_id = $quoted_user AND p.pid = t.pid AND w.wid = t.wid AND w.state IS NOT NULL) ORDER BY t.tid";
my $sth = $dbh->prepare("$statement");
$sth->execute();
- while (my ($iid,$quant,$status,$amount) = $sth->fetchrow_array) {
+ while (my ($tid,$iid,$quant,$iidstatus,$amount) = $sth->fetchrow_array) {
if ($iid) {
$total{$iid} += $quant;
$balance{$iid} += $amount;
@@ -1414,7 +1418,7 @@
$payinfo .= 'You have overpaid for '.$$feeinfo{$feehash{$key}{'iid'}}{'longdesc'}.' - a credit of $'.$ccard{$key}.' will be credited to you.<br />';
} else {
if ($feehash{$key}{'type'} eq 'accomm') {
- $payinfo .= 'As your dorm accommodation requirements have been reduced, a credit of $'.$ccard{$key}.' will be credited to you.<br />';
+ $payinfo .= 'As your dorm accommodation requirements have changed, a credit of $'.$ccard{$key}.' will be credited to you.<br />';
} else {
$payinfo .= 'As you will not be attending the '.$key.' a credit of $'.$ccard{$key}.' will be credited to you.<br />';
}
@@ -1444,8 +1448,13 @@
"Subject: LON-CAPA $event - $year\n".
"Thank you for your interest in the $year LON-CAPA $event.\n\n".
"The following changes were made to your registration: \n".
- "$msg\n"."$statusmsg{mail}\n".
- "MSU LON-CAPA support team\n".
+ "$msg\n"."$statusmsg{mail}\n";
+ if ($action eq 'modify' || $action eq 'add') {
+ if ($fees) {
+ $requestmail .= &refund_info($endcredit,$now)."\n\n";
+ }
+ }
+ $requestmail .= "MSU LON-CAPA support team\n".
"$contact_email\n";
if (open(MAIL, "|/usr/lib/sendmail -oi -t -odb")) {
print MAIL $requestmail;
@@ -1454,8 +1463,8 @@
&error_exit($r,$page,$year,$event,"Can't fork for sendmail:$!\n",$contact_name,$contact_email,$sponsors,$sponsorinfo,$domain);
return;
}
- my $mailcopy = "To: raeburn\@msu.edu\n".
- "From: $contact_email\n".
+ my $mailcopy = "To: helpdesk\@loncapa.org\n".
+ "From: loncapa\@loncapa.org\n".
"Subject: LON-CAPA conference/workshop change\n".
"The following transaction occurred for $user in the LON-CAPA events registration system: \n".
"$msg\n"."$statusmsg{mail}\n";
@@ -1539,27 +1548,34 @@
my $adminmsg;
if ($creditnum) {
if ((!$endcredit) || ($now <= $endcredit)) {
- my (%drop,%refund);
+ my (%drop,%refund,%dropped,%credited);
if ($curr_pid) {
foreach my $iid (sort(keys(%credtrans))) {
if (ref($credtrans{$iid}) eq 'HASH') {
my $remaining = -1 *$credtrans{$iid}{'quantity'};
my $moneyback = -1 * $credtrans{$iid}{'amount'};
- my $sth = $dbh->prepare("SELECT wid,quantity,amount FROM transactions WHERE (iid = '$iid' AND pid = '$curr_pid' AND status = 'payment') ORDER BY wid");
+ my $sth = $dbh->prepare("SELECT t.tid,t.wid,t.quantity,t.amount,t.dropped,t.credited FROM transactions t, webcredit w WHERE (t.iid = '$iid' AND t.pid = '$curr_pid' AND t.status = 'payment' AND t.wid=w.wid AND w.state IS NOT NULL) ORDER BY wid");
$sth->execute();
- while ((my ($oldwid,$quantity,$amount) = $sth->fetchrow_array) && ($remaining > 0)) {
- $drop{$oldwid}{$iid} = -1 * $remaining;
- $refund{$oldwid}{$iid} = -1 * $moneyback;
- $remaining -= $quantity;
- $moneyback -= $amount;
- if ($remaining > 0) {
- $drop{$oldwid}{$iid} = -1 * $quantity;
- }
- if ($moneyback > 0) {
- $refund{$oldwid}{$iid} = -1 * $amount;
+ while ((my ($oldtid,$oldwid,$quantity,$amount,$currdrop,$currcredit) = $sth->fetchrow_array) && ($moneyback > 0)) {
+ if (($quantity + $currdrop > 0) || ($amount + $currcredit > 0)) {
+ $drop{$oldwid}{$iid} = -1 * $remaining;
+ $refund{$oldwid}{$iid} = -1 * $moneyback;
+ $remaining -= ($quantity + $currdrop);
+ $moneyback -= ($amount + $currcredit);
+ if ($remaining > 0) {
+ $drop{$oldwid}{$iid} = -1 * ($quantity + $currdrop);
+ }
+ if ($moneyback > 0) {
+ $refund{$oldwid}{$iid} = -1 * ($amount + $currcredit);
+ }
+ $dropped{$oldtid} = $currdrop + $drop{$oldwid}{$iid};
+ $credited{$oldtid} = $currcredit + $refund{$oldwid}{$iid};
}
}
$sth->finish;
+ foreach my $oldtid (sort(keys(%credited))) {
+ $dbh->do("UPDATE transactions SET dropped='$dropped{$oldtid}',credited='$credited{$oldtid}' WHERE tid='$oldtid'");
+ }
}
}
foreach my $wid (sort(keys(%refund))) {
@@ -1579,16 +1595,17 @@
my $showrefund = -1 * $totalrefund;
$showrefund = sprintf("%.2f",$showrefund);
if ($showrefund > 0.00) {
- $available{$wid} = $showrefund;
+ $available{$wid}{'refund'} = $showrefund;
+ $available{$wid}{'orderid'} = $orderid;
}
if ($oldbal > 0.00) {
$oldbalance{$wid} = $oldbal;
}
$adminmsg .= 'This transaction includes a refund of $'.$showrefund.' to '."$firstname $lastname ($user_id)".' -webcredit item: '.$wid.' order#: '.$orderid.".\n";
}
- foreach my $wid (sort(keys(%drop))) {
- if (ref($drop{$wid}) eq 'HASH') {
- foreach my $iid (keys(%{$drop{$wid}})) {
+ foreach my $wid (sort(keys(%refund))) {
+ if (ref($refund{$wid}) eq 'HASH') {
+ foreach my $iid (keys(%{$refund{$wid}})) {
$dbh->do("INSERT INTO transactions (wid,pid,iid,quantity,status,amount) VALUES ('$wid','$curr_pid','$iid','$drop{$wid}{$iid}','$credtrans{$iid}{status}','$refund{$wid}{$iid}')");
}
}
@@ -1628,7 +1645,8 @@
$dbh->do("INSERT INTO transactions (wid,pid,iid,quantity,status,amount) VALUES ('$wid','$pid','$iid','$remnants{$iid}{toadd}','$transactions{$iid}{status}','$remnants{$iid}{topay}')");
}
}
- my $redirect = '/register?year='.$year.'&event='.$enc_event.'&page=2&go=NextPage';
+ my $protocol = ($ENV{'SERVER_PORT'} == 443?'https://':'http://');
+ my $redirect = 'year='.$year.'&event='.$enc_event;
my $webcreditform = &webcredit($paynum,$order,$wid,\%ccard,\%total, \%feehash,\%finaldispdat,\%costs,
\%quantities,$redirect);
$r->print('<br /><br />'.$webcreditform);
@@ -1636,8 +1654,8 @@
}
if ($creditnum) {
if ($adminmsg ne '') {
- $adminmsg = "To: raeburn\@msu.edu\n".
- "From: $contact_email\n".
+ $adminmsg = "To: helpdesk\@loncapa.org\n".
+ "From: loncapa\@loncapa.org\n".
"Subject: LON-CAPA refund(s)\n".
"$adminmsg\n";
if (open(MAIL, "|/usr/lib/sendmail -oi -t -odb")) {
@@ -1648,6 +1666,10 @@
return;
}
}
+ foreach my $oldwid (keys(%available)) {
+ my $statement = "INSERT INTO refunds (wid,refund,orderid,created) VALUES('$oldwid','$available{$oldwid}{refund}','$available{$oldwid}{orderid}',NOW())";
+ $dbh->do($statement);
+ }
}
$r->print(<<"END_OF_D");
</td>
@@ -1706,6 +1728,13 @@
<body>
END_OF_A
+# Check if new registrations are allowed, and the last date/time for credits.
+ my ($registeropen,$registerclose,$creditclose) = $dbh->selectrow_array("SELECT registeropen,registerclose,endcredit FROM event_config WHERE event_id = '$event_id'");
+ my $endcredit = 0;
+ if ($creditclose) {
+ $endcredit = &UnixDate($creditclose, "%s");
+ }
+ my $now = time;
&main_box($r,$year,$event);
my $logoutportal = $portal;
if ($logoutportal =~ /^\/update/) {
@@ -1716,7 +1745,7 @@
<table class="LC_breadcrumb">
<tr>
<td>
- <a HREF="http://loncapa.org/">Home</a> --> <a href="$exitpage">Events</a> --> <a href="$portal">Information</a>--> <a href="/register?year=$year&event=$enc_event">Add/Cancel/Modify registration</a> --> <b>Credit Card Coompletion</b>
+ <a HREF="http://loncapa.org/">Home</a> --> <a href="$exitpage">Events</a> --> <a href="$portal">Information</a>--> <a href="/register?year=$year&event=$enc_event">Add/Cancel/Modify registration</a> --> <b>Payment</b>
</td>
<td> </td>
<td align="right" valign="top">
@@ -1738,13 +1767,9 @@
</td>
</tr>
<tr>
- <td colspan="2"> </td>
- </tr>
- <tr>
- <tr>
<td> </td>
<td>
- Thank you for providing credit card information through MSU's secure webCredit site.
+ Thank you for paying through MSU's secure webCredit site.
</td>
</tr>
<tr>
@@ -1753,8 +1778,17 @@
<tr>
<td> </td>
<td>
- If you need to make modifications to your registration in the future, please return to the <a href="/register?year=$year&event=$enc_event">$year $event page</a> to $lateraction{$status} your registration. Thank you for your interest in LON-CAPA events.
+ If you need to make modifications to your registration in the future, please return to the <a href="/register?year=$year&event=$enc_event">$year $event page</a> to $lateraction{$status} your registration.
+END_OF_B
+ if ($status eq 'enroll') {
+ $r->print(&refund_info($endcredit,$now));
+ }
+ $r->print(<<"END_OF_C");
</td>
+ </tr>
+ <tr>
+ <td> </td>
+ <td> Thank you for your interest in LON-CAPA events.</td>
</tr>
<tr>
<td colspan="2"> </td>
@@ -1769,10 +1803,47 @@
<td colspan="2"> </td>
</tr>
</table>
-END_OF_B
+END_OF_C
&main_footer($r,$page,$year,$event,$returnpage,$sponsors,$sponsorinfo,$domain);
}
+sub refund_info {
+ my ($endcredit,$now) = @_;
+ my $output;
+ if (!$endcredit) {
+ $output = ' Any changes made to registration/dorm accommodation reservations which result in a refund will be credited to the card originally used for payment.';
+ } elsif ($endcredit) {
+ if ($endcredit > $now) {
+ $output = ' Any changes made by '.localtime($endcredit).' to registration/dorm accommodation reservations which result in a refund will be credited to the card originally used for payment. No refunds will be processed for changes made after this date.';
+ } else {
+ $output = ' The deadline for refunds has passed. Although you may make changes to registration/dorm accommodation reservations, refunds of prior payment(s) will not be made.';
+ }
+ }
+ return $output;
+}
+
+
+sub feedisplay {
+ my ($feeinfo) = @_;
+ my $output = "<br />After submitting this form you will be directed to MSU's secure payment site to provide your credit card details, so the registration fee(s) can be collected:<br />";
+ if (keys(%{$feeinfo}) > 0) {
+ $output .= '<ul>';
+ foreach my $item (sort(keys(%{$feeinfo}))) {
+ $output .= '<li>';
+ if ($$feeinfo{$item}{reqd} eq 'N') {
+ $output .= 'optional ';
+ }
+ $output .= $$feeinfo{$item}{longdesc}.' - $'.$$feeinfo{$item}{cost};
+ if ($$feeinfo{$item}{'type'} eq 'accomm') {
+ $output .= ' (per night)';
+ }
+ $output .= '</li>';
+ }
+ $output .= '</ul>';
+ }
+ return $output;
+}
+
sub webcredit {
my ($paynum,$order,$wid,$ccard,$total,$feehash,$finaldat,$costs,$quantities,
$redirect) = @_;
@@ -1788,9 +1859,10 @@
$citystate =~ s/\s+$//;
my ($city,$state) = ($citystate =~ /^(.+)\s+([^\s]+)$/);
my $output .= <<END_A;
-<form name="webcredit" action="https://payments.qual.ais.msu.edu/process/" method="post">
+<form name="webcredit" action="https://payments.msu.edu/process/" method="post">
<input type="hidden" name="Identifier" Value="32546LON">
<input type="hidden" name="Version" Value="3.2">
+<input type="hidden" name="Order_Comment" value="$redirect">
<input type="hidden" name="Card_Email" Value="$finaldat->{'email'}">
<input type="hidden" name="Card_Name" Value="$name">
<input type="hidden" name="Ship_Name" Value="$name">
@@ -1840,8 +1912,8 @@
my @sortedwids;
my (%remnants,%floats,%origrefunds);
foreach my $wid (keys(%{$available})) {
- $origrefunds{$wid} = $available->{$wid};
- push(@{$floats{$available->{$wid}}},$wid);
+ $origrefunds{$wid} = $available->{$wid}{'refund'};
+ push(@{$floats{$available->{$wid}{'refund'}}},$wid);
}
my @sorted = sort {$b <=> $a} keys(%floats);
my $totalspare = 0;
@@ -1864,16 +1936,16 @@
$currwid = $sortedwids[$widcount];
my $curramount;
my $currquant;
- if ($topay - $available->{$currwid} > 0) {
- $curramount = $available->{$currwid};
- $available->{$currwid} = 0;
+ if ($topay - $available->{$currwid}{'refund'} > 0) {
+ $curramount = $available->{$currwid}{'refund'};
+ $available->{$currwid}{'refund'} = 0;
$$adminmsg .= "refund of $origrefunds{$currwid} for webcredit item: $currwid all used for new purchases\n";
$dbh->do("UPDATE webcredit SET modified=NOW(),state='D',amount='$oldbalance->{$currwid}' WHERE wid='$currwid'");
$toadd -= $currquant;
$widcount ++;
} else {
$curramount = $topay;
- $available->{$currwid} -= $curramount;
+ $available->{$currwid}{'refund'} -= $curramount;
}
$currquant = floor($transactions->{$iid}{quantity} * $curramount/$transactions->{$iid}{amount});
$toadd -= $currquant;
@@ -1898,10 +1970,10 @@
}
}
if ($topay == 0) {
- my $newbal = $oldbalance->{$currwid} - $available->{$currwid};
+ my $newbal=$oldbalance->{$currwid}-$available->{$currwid}{'refund'};
$newbal = sprintf("%.2f",$newbal);
$dbh->do("UPDATE webcredit SET modified=NOW(),state='C',amount='$newbal' WHERE wid='$currwid'");
- $$adminmsg .= "refund of $origrefunds{$currwid} for webcredit item: $currwid partially used for new purchases - amount to refund is $available->{$currwid}\n";
+ $$adminmsg .= "refund of $origrefunds{$currwid} for webcredit item: $currwid partially used for new purchases - amount to refund is $available->{$currwid}{'refund'}\n";
}
return %remnants;
}
@@ -2027,6 +2099,13 @@
END_OF_FOOT
}
+sub authorized {
+ my ($dbh,$quoted_user,$event_id) = @_;
+ my $statement = "SELECT COUNT(event_id) FROM event_admin WHERE (user_id = $quoted_user AND event_id = '$event_id')";
+ my $admincount = $dbh->selectrow_array("$statement");
+ return $admincount;
+}
+
sub getnames {
my ($domain,$username,$userinfo) = @_;
my $URL = "http://s10.lite.msu.edu/cgi-bin/check_auth.pl";
--raeburn1175545310--