[LON-CAPA-cvs] cvs: modules /raeburn/register register.pm
raeburn
lon-capa-cvs-allow@mail.lon-capa.org
Wed, 02 Apr 2008 02:46:44 -0000
This is a MIME encoded message
--raeburn1207104404
Content-Type: text/plain
raeburn Tue Apr 1 22:46:44 2008 EDT
Modified files:
/modules/raeburn/register register.pm
Log:
- Support for more complex rules in product_dependencies table.
- Check to determine if registrant's choices dictate inclusion of a
product (of type conditional), evaluated in &check_conditions()
- Optional $feesmsg can be displayed beneath listing of fee structure.
--raeburn1207104404
Content-Type: text/plain
Content-Disposition: attachment; filename="raeburn-20080401224644.txt"
Index: modules/raeburn/register/register.pm
diff -u modules/raeburn/register/register.pm:1.15 modules/raeburn/register/register.pm:1.16
--- modules/raeburn/register/register.pm:1.15 Tue Apr 1 22:05:23 2008
+++ modules/raeburn/register/register.pm Tue Apr 1 22:46:42 2008
@@ -3,7 +3,7 @@
# Session-based registration for conferences/workshops
# Data read/written from MySQL database.
#
-# $Id: register.pm,v 1.15 2008/04/02 02:05:23 raeburn Exp $
+# $Id: register.pm,v 1.16 2008/04/02 02:46:42 raeburn Exp $
#
# Stuart P Raeburn
#
@@ -87,7 +87,7 @@
my $domain = $params{'domain'};
my %feeinfo;
my @consortium;
- my ($page,$year,$event,$portal,$returnpage,$event_id,$webpath,$year_quoted,$event_quoted,$fees,$condmail);
+ my ($page,$year,$event,$portal,$returnpage,$event_id,$webpath,$year_quoted,$event_quoted,$fees,$condmail,$feesmsg);
if (exists $params{'return'}) {
$returnpage = $params{'return'};
}
@@ -118,7 +118,7 @@
$sponsorinfo{$name}{orientation} = $orientation;
}
$sth->finish;
- ($event_id,$webpath,$fees,$condmail) = $dbh->selectrow_array("SELECT event_id,webpath,fees,condmail FROM event_config WHERE year=$year_quoted AND event=$event_quoted");
+ ($event_id,$webpath,$fees,$condmail,$feesmsg) = $dbh->selectrow_array("SELECT event_id,webpath,fees,condmail,feesmsg FROM event_config WHERE year=$year_quoted AND event=$event_quoted");
$portal = $webpath.$returnpage;
if ($event_id eq '') {
&invalid_event($r,$dbh,$page,$year,$event,$portal,$returnpage,$exitpage,\@sponsors,\%sponsorinfo,$domain);
@@ -126,15 +126,18 @@
} else {
# check for fees
if ($fees) {
- $sth = $dbh->prepare("SELECT iid,description,cost,required,longdesc,type,waiver FROM products WHERE event_id = '$event_id'");
+ $sth = $dbh->prepare("SELECT iid,description,cost,required,longdesc,type,waiver,infotext,displayorder,dependency FROM products WHERE event_id = '$event_id'");
$sth->execute;
- while ( my ($iid,$desc,$cost,$reqd,$longdesc,$type,$waiver) = $sth->fetchrow_array) {
+ while ( my ($iid,$desc,$cost,$reqd,$longdesc,$type,$waiver,$infotext,$displayorder,$dependency) = $sth->fetchrow_array) {
$feeinfo{$iid}{desc} = $desc;
$feeinfo{$iid}{cost} = $cost;
$feeinfo{$iid}{reqd} = $reqd;
$feeinfo{$iid}{longdesc} = $longdesc;
$feeinfo{$iid}{type} = $type;
$feeinfo{$iid}{waiver} = $waiver;
+ $feeinfo{$iid}{infotext} = $infotext;
+ $feeinfo{$iid}{displayorder} = $displayorder;
+ $feeinfo{$iid}{dependency} = $dependency;
}
$sth->finish;
$sth = $dbh->prepare("SELECT user_id FROM consortium");
@@ -227,7 +230,7 @@
} 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,\@consortium,$condmail);
} 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,\@consortium);
+ &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,\@consortium,$feesmsg);
}
return OK;
}
@@ -306,7 +309,7 @@
}
sub display_one() {
- my ($r,$event_id,$params,$user,$domain,$portal,$returnpage,$exitpage,$items,$info,$workshop,$dbh,$page,$contact_email,$contact_name,$form_elements,$rowitems,$rowtitles,$sponsors,$sponsorinfo,$fees,$feeinfo,$consortium) = @_;
+ my ($r,$event_id,$params,$user,$domain,$portal,$returnpage,$exitpage,$items,$info,$workshop,$dbh,$page,$contact_email,$contact_name,$form_elements,$rowitems,$rowtitles,$sponsors,$sponsorinfo,$fees,$feeinfo,$consortium,$feesmsg) = @_;
my $year = $$params{'year'};
my $event = $$params{'event'};
my $quoted_user = $dbh->quote( $user );
@@ -380,20 +383,18 @@
$curr{'attendancedays'} = '"'.$curr_attendancedays[0].'"';
}
if (@curr_attendancedays > 0) {
- my $check_ok = 0;
- my $statement = "SELECT name FROM product_dependencies WHERE event_id = '$event_id' AND tablename = 'attendancedays'";
+ my %check_ok;
+ $statement = "SELECT iid FROM products WHERE event_id = '$event_id' AND registration = 'Y'";
my $sth = $dbh->prepare($statement);
$sth->execute();
- while (my $name = $sth->fetchrow_array()) {
- my $statemnt = "SELECT COUNT(name) FROM attendancedays WHERE name = '$name' AND event_id = '$event_id' AND user_id = $quoted_user";
- my $count = $dbh->selectrow_array("$statemnt");
- if ($count) {
- $check_ok = 1;
- last;
- }
+ while (my $iid = $sth->fetchrow_array()) {
+ $check_ok{$iid} = &check_conditions($dbh,$iid,$event_id,$quoted_user);
}
- if ($check_ok) {
- $curr{'registration'} = 'Y';
+ $sth->finish;
+ foreach my $iid (keys(%check_ok)) {
+ if ($check_ok{$iid}) {
+ $curr{'registration'} = 'Y';
+ }
}
}
@@ -454,10 +455,14 @@
}
}
$sth->finish;
- my ($confcredit,$preconfcredit);
-
+ my %conditionals;
if ($status eq 'enroll' || $status eq 'cancel') {
foreach my $iid (sort(keys(%{$feeinfo}))) {
+ if ($$feeinfo{$iid}{'dependency'} ne '') {
+ if ($curr{$$feeinfo{$iid}{'dependency'}} eq 'Y') {
+ $curr{$$feeinfo{$iid}{desc}} = 'Y';
+ }
+ }
if ($$feeinfo{$iid}{reqd} eq 'Y') {
if ($$feeinfo{$iid}{'type'} eq 'accomm') {
my $quoted_type = $dbh->quote( $$feeinfo{$iid}{desc} );
@@ -477,19 +482,12 @@
my $nights = $dbh->selectrow_array("SELECT nights FROM event_accommodation WHERE (user_id = $quoted_user AND $event_id = '$event_id' AND type = $quoted_type)");
$total{$iid} = $nights;
} elsif ($$feeinfo{$iid}{'type'} eq 'conditional') {
- my $check_ok = 0;
- my $statement = "SELECT name,tablename FROM product_dependencies WHERE iid = '$iid'";
- my $sth = $dbh->prepare($statement);
- $sth->execute();
- while (my ($name,$table) = $sth->fetchrow_array()) {
- my $statemnt = "SELECT COUNT(name) FROM $table WHERE name = '$name' AND event_id = '$event_id' AND user_id = $quoted_user";
- my $count = $dbh->selectrow_array("$statemnt");
- if ($count) {
- $check_ok = 1;
- }
- }
+ my $check_ok = &check_conditions($dbh,$iid,$event_id,$quoted_user);
if ($check_ok) {
$total{$iid} = 1;
+ $conditionals{$iid} = 1;
+ } else {
+ $conditionals{$iid} = 0;
}
} else {
if ($total{$iid} eq '' || $total{$iid} == 0) {
@@ -505,7 +503,7 @@
foreach my $iid (keys(%balance)) {
if (($$feeinfo{$iid}{'waiver'} eq 'Y') && (grep/^\Q$user\E$/,@{$consortium})) {
$credit{$iid} = $balance{$iid};
- } else {
+ } else {
$credit{$iid} = $balance{$iid} - ($total{$iid} * $$feeinfo{$iid}{'cost'});
}
$credit{$iid} = sprintf("%.2f",$credit{$iid});
@@ -515,7 +513,9 @@
if (($$feeinfo{$iid}{'reqd'} eq 'Y') || ($curr{$$feeinfo{$iid}{'desc'}} eq 'Y')) {
if ($credit{$iid} == 0) {
if ($$feeinfo{$iid}{'cost'} > 0) {
- $payinfo .= 'You have paid the '.$$feeinfo{$iid}{'longdesc'}.' fee in full.';
+ if ((!exists($conditionals{$iid})) || ($conditionals{$iid})) {
+ $payinfo .= 'You have paid the '.$$feeinfo{$iid}{'longdesc'}.' fee in full.';
+ }
}
} elsif ($credit{$iid} > 0) {
$payinfo .= 'You have overpaid for the '.$$feeinfo{$iid}{'longdesc'}.' - a credit of $'.$credit{$iid}.' will be credited to you.';
@@ -657,7 +657,7 @@
}
# build function to verify form completion
- if ($regaccess eq 'current') {
+ if ($regaccess eq 'current' || $regaccess eq 'future') {
$verify_func = qq|
function validForm(caller) {
var checkok = 1
@@ -834,7 +834,7 @@
$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(&feedisplay($feeinfo,$feesmsg));
$r->print(&refund_info($endcredit,$now).'<br />');
}
}
@@ -849,7 +849,7 @@
$r->print("<b>Please submit your registration for the $year LON-CAPA $event.</b>");
if ($fees) {
if (keys(%{$feeinfo}) > 0) {
- $r->print(&feedisplay($feeinfo));
+ $r->print(&feedisplay($feeinfo,$feesmsg));
$r->print(&refund_info($endcredit,$now).'<br />');
}
}
@@ -1001,8 +1001,7 @@
} elsif ($$form_elements{$$rowitems[$i][$j]}{type} eq 'selectbox') {
my @items = split/\&/,$$form_elements{$$rowitems[$i][$j]}{contents};
my $multiple = '';
- if ($$form_elements{$$rowitems[$i][$j]}{multivalued} eq 'Y') {
- $multiple = "multiple";
+ if ($$form_elements{$$rowitems[$i][$j]}{multivalued} eq 'Y') { $multiple = "multiple";
}
$r->print('<select name="'.$$rowitems[$i][$j].
'"'.$multiple.'><option value="">Please select'."\n"
@@ -1107,15 +1106,17 @@
# Get fee information
my %feehash;
if ($fees) {
- $sth = $dbh->prepare("SELECT iid,description,cost,required,longdesc,type,waiver FROM products WHERE event_id = '$event_id'");
+ $sth = $dbh->prepare("SELECT iid,description,cost,required,longdesc,type,waiver,infotext,dependency FROM products WHERE event_id = '$event_id'");
$sth->execute;
- while (my ($iid,$desc,$cost,$required,$longdesc,$type,$waiver)=$sth->fetchrow_array) {
+ while (my ($iid,$desc,$cost,$required,$longdesc,$type,$waiver,$infotext,$dependency)=$sth->fetchrow_array) {
$feehash{$desc}{'iid'} = $iid;
$feehash{$desc}{'cost'} = $cost;
$feehash{$desc}{'reqd'} = $required;
$feehash{$desc}{'longdesc'} = $longdesc;
$feehash{$desc}{'type'} = $type;
$feehash{$desc}{'waiver'} = $waiver;
+ $feehash{$desc}{'infotext'} = $infotext;
+ $feehash{$desc}{'dependency'} = $dependency;
}
$sth->finish;
}
@@ -1579,22 +1580,20 @@
$sth->finish;
foreach my $key (keys(%feehash)) {
if (ref($feehash{$key}) eq 'HASH') {
+ if ($feehash{$key}{'dependency'} ne '') {
+ if ($finaldispdat{$feehash{$key}{'dependency'}} eq 'Y') {
+ $finaldispdat{$key} = 'Y';
+ }
+ }
+
if (($feehash{$key}{reqd} eq 'Y') || ($finaldispdat{$key} eq 'Y')) {
if ($currstatus eq 'enroll') {
if ($feehash{$key}{'type'} eq 'accomm') {
$quantities{$key} += $finaldispaccom{$key}{quant};
} elsif ($feehash{$key}{'type'} eq 'conditional') {
- my $check_ok = 0;
- my $statement = "SELECT name,tablename FROM product_dependencies WHERE iid = '$feehash{$key}{'iid'}'";
- my $sth = $dbh->prepare($statement);
- $sth->execute();
- while (my ($name,$table) = $sth->fetchrow_array()) {
- my $statemnt = "SELECT COUNT(name) FROM $table WHERE name = '$name' AND event_id = '$event_id' AND user_id = $quoted_user";
- my $count = $dbh->selectrow_array("$statemnt");
- if ($count) {
- $check_ok = 1;
- }
- }
+ my $iid = $feehash{$key}{'iid'};
+ my $check_ok =
+ &check_conditions($dbh,$iid,$event_id,$quoted_user);
if ($check_ok) {
$quantities{$key} ++;
}
@@ -2082,22 +2081,33 @@
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 appropriate registration fee(s) can be collected:<br />";
+ my ($feeinfo,$feesmsg) = @_;
+ 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 appropriate registration fee can be collected:<br />";
if (keys(%{$feeinfo}) > 0) {
+ my @products;
$output .= '<ul>';
- foreach my $item (sort(keys(%{$feeinfo}))) {
+ foreach my $item (keys(%{$feeinfo})) {
+ $products[$$feeinfo{$item}{'displayorder'}-1] = $item;
+ }
+ foreach my $item (sort { $a <=> $b } @products) {
$output .= '<li>';
if ($$feeinfo{$item}{reqd} eq 'N') {
$output .= 'optional ';
}
- $output .= $$feeinfo{$item}{longdesc}.' - $'.$$feeinfo{$item}{cost};
+ if ($$feeinfo{$item}{'infotext'} eq '') {
+ $output .= $$feeinfo{$item}{longdesc}.' - US$'.$$feeinfo{$item}{cost};
+ } else {
+ $output .= $$feeinfo{$item}{infotext};
+ }
if ($$feeinfo{$item}{'type'} eq 'accomm') {
$output .= ' (per night)';
}
$output .= '</li>';
}
$output .= '</ul>';
+ if ($feesmsg ne '') {
+ $output .= "<p>$feesmsg</p>";
+ }
}
return $output;
}
@@ -2319,6 +2329,66 @@
END_OF_BOX
}
+sub check_conditions {
+ my ($dbh,$iid,$event_id,$quoted_user) = @_;
+ my $check_ok = 0;
+ my (%passed,%failed,%needpass,@nums,$totalpasses,$totalfails,$statement,$sth);
+ $statement = "SELECT name,tablename,value,condition,num FROM product_dependencies WHERE iid = '$iid'";
+ $sth = $dbh->prepare($statement);
+ $sth->execute();
+ while (my ($name,$table,$value,$condition,$num) = $sth->fetchrow_array()) {
+ if (!grep(/^\Q$num\E$/,@nums)) {
+ push(@nums,$num);
+ }
+ my $statemnt;
+ if ($table eq 'attendancedays') {
+ if ($value eq '') {
+ $statemnt = "SELECT COUNT(name) FROM $table WHERE name = '$name' AND event_id = '$event_id' AND user_id = $quoted_user";
+ } else {
+ $statemnt = "SELECT COUNT(name) FROM $table WHERE name = '$name' AND event_id = '$event_id' AND value = '$value' AND user_id = $quoted_user";
+ }
+ } elsif ($table eq 'event_registration') {
+ if ($value eq '') {
+ $statemnt = "SELECT COUNT($name) FROM $table WHERE event_id = '$event_id' AND user_id = $quoted_user";
+ } else {
+ $statemnt = "SELECT COUNT($name) FROM $table WHERE $name = '$value' AND event_id = '$event_id' AND user_id = $quoted_user";
+ }
+ }
+ my $count = $dbh->selectrow_array("$statemnt");
+ if ($condition eq 'on') {
+ if ($count) {
+ $passed{$num} = 1;
+ }
+ $needpass{$num} = 1;
+ } elsif ($condition eq 'off') {
+ if ($count) {
+ $failed{$num} = 1;
+ }
+ }
+ }
+ $totalpasses = 0;
+ $totalfails = 0;
+ foreach my $num (@nums) {
+ if ($passed{$num}) {
+ $totalpasses ++;
+ }
+ if ($failed{$num}) {
+ $totalfails ++;
+ }
+ if ($needpass{$num}) {
+ if (!$passed{$num}) {
+ $totalfails ++;
+ }
+ }
+ }
+ if ($totalpasses && !$totalfails) {
+ $check_ok = 1;
+ } else {
+ $check_ok = 0;
+ }
+ return $check_ok;
+}
+
sub main_footer() {
my ($r,$page,$year,$event,$returnpage,$sponsors,$sponsorinfo,$domain) = @_;
$r->print(<<"START_OF_FOOT");
--raeburn1207104404--