[LON-CAPA-cvs] cvs: modules /raeburn/register register.pm
raeburn
lon-capa-cvs-allow@mail.lon-capa.org
Wed, 02 Apr 2008 02:05:25 -0000
This is a MIME encoded message
--raeburn1207101925
Content-Type: text/plain
raeburn Tue Apr 1 22:05:25 2008 EDT
Modified files:
/modules/raeburn/register register.pm
Log:
- Code to generate form elements moved to subroutine: &display_form_elements().
- formfields with checkboxes can have 'required attribute' - add javascript to ensure that at least one checkbox has been checked.
- Changes for conference at SFU
- attendance days checkboxes.
- fees required can depend on which days user is attending
- new table: product_dependencies (encapsulates conditions which determine which registration fee applies, based on choices of attendance/sessions.
- remove test referring to dorm accomodation from statements about fees.
- dorm fees are being collected separately at SFU.
--raeburn1207101925
Content-Type: text/plain
Content-Disposition: attachment; filename="raeburn-20080401220525.txt"
Index: modules/raeburn/register/register.pm
diff -u modules/raeburn/register/register.pm:1.14 modules/raeburn/register/register.pm:1.15
--- modules/raeburn/register/register.pm:1.14 Wed Jun 13 19:01:40 2007
+++ modules/raeburn/register/register.pm Tue Apr 1 22:05:23 2008
@@ -3,7 +3,7 @@
# Session-based registration for conferences/workshops
# Data read/written from MySQL database.
#
-# $Id: register.pm,v 1.14 2007/06/13 23:01:40 raeburn Exp $
+# $Id: register.pm,v 1.15 2008/04/02 02:05:23 raeburn Exp $
#
# Stuart P Raeburn
#
@@ -319,6 +319,7 @@
my @curr_values = ();
my @curr_info = ();
my @curr_workshops = ();
+ my @curr_attendancedays;
my %userinfo = ();
my $username;
@@ -363,6 +364,39 @@
$curr{$curr_values[$i]} = $row[$i];
}
+# Is there attendance days data for this user?
+ $statement = "SELECT name FROM attendancedays WHERE user_id = $quoted_user AND event_id = '$event_id'";
+ my $sth = $dbh->prepare("$statement");
+ $sth->execute();
+ while (my @row = $sth->fetchrow_array) {
+ if (@row > 0) {
+ push @curr_attendancedays, @row;
+ }
+ }
+ $sth->finish;
+ if (@curr_attendancedays > 1) {
+ $curr{'attendancedays'} = '"'.join('","',@curr_attendancedays).'"';
+ } elsif (@curr_attendancedays == 1) {
+ $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 $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;
+ }
+ }
+ if ($check_ok) {
+ $curr{'registration'} = 'Y';
+ }
+ }
+
# Is there workshop data for this user?
$statement = "SELECT name FROM workshop_registration WHERE user_id = $quoted_user AND event_id = '$event_id'";
my $sth = $dbh->prepare("$statement");
@@ -442,6 +476,21 @@
my $quoted_type = $dbh->quote( $$feeinfo{$iid}{desc} );
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;
+ }
+ }
+ if ($check_ok) {
+ $total{$iid} = 1;
+ }
} else {
if ($total{$iid} eq '' || $total{$iid} == 0) {
$total{$iid} = 1;
@@ -660,6 +709,27 @@
checkok = 0
}
|;
+ } elsif ($$form_elements{$_}{type} eq 'checkbox') {
+ $verify_func .= qq|
+ var $_ = 0;
+ if (document.regForm.$_.length > 0) {
+ for (var i=0; i<document.regForm.$_.length; i++) {
+ if (document.regForm.$_\[i].checked == true) {
+ $_ = 1
+ }
+ }
+ }
+ else
+ {
+ if (document.regForm.$_\.checked == true) {
+ $_ = 1;
+ }
+ }
+ if ($_ == 0) {
+ msg = msg + "Click at least one of the checkboxes for the $$form_elements{$_}{title} field.\\n"
+ checkok = 0
+ }
+ |;
}
}
}
@@ -817,15 +887,42 @@
$r->print(qq|
<input type="button" class="buttoncolored" name="register" value="Register" onClick="javascript:validForm('add')">|);
}
+
$r->print(<<"END_OF_BLOCK");
</td>
</tr>
</table><br />
+END_OF_BLOCK
+ &display_form_elements($r,$rowitems,$rowtitles,$form_elements,\%userinfo);
+ if ($status eq "enroll") {
+ $r->print(qq|
+ <input type="button" class="buttoncolored" name="modify" value="$modifybutton" onClick="javascript:validForm('modify')"> <input type="button" class="buttoncolored" value="$cancelbutton" name="cancel" onClick=javascript:validForm('cancel')
+ |);
+ } elsif ($status eq "cancel") {
+ $r->print(qq|
+ <input type="button" class="buttoncolored" name="reactivate" value="Re-register" onClick=
+"javascript:validForm('add')">|);
+ } else {
+ $r->print(qq|
+ <input type="button" class="buttoncolored" name="register" value="Register" onClick="javascript:validForm('add')">|);
+ }
+ $r->print (qq|
+ <br />
+ </td>
+ </tr>
+ </table>
+ |);
+ &main_footer($r,$page,$year,$event,$returnpage,$sponsors,$sponsorinfo,$$domain);
+}
+
+sub display_form_elements {
+ my ($r,$rowitems,$rowtitles,$form_elements,$userinfo) = @_;
+ $r->print(<<"END_OF_BLOCK");
<table>
<tr>
<td> </td>
<td>
- <table class="LC_regform">
+ <table class="LC_regform">
END_OF_BLOCK
for (my $i=0; $i<@{$rowitems}; $i++) {
my $leftcss = 'LC_leftinner';
@@ -846,7 +943,7 @@
if ($$form_elements{$$rowitems[$i][$j]}{preamble}) {
if ($$form_elements{$$rowitems[$i][$j]}{preamblerow}) {
my @items = split/\&/,$$form_elements{$$rowitems[$i][$j]}{contents};
- if (@items > 1) {
+ if (@items > 1) {
my $colspan = scalar(@items);
$r->print('<td colspan="'.$colspan.'">'.
$$form_elements{$$rowitems[$i][$j]}{preamble}.
@@ -880,8 +977,7 @@
}
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 '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};
$r->print('<nobr>');
@@ -925,7 +1021,7 @@
} else {
$r->print('<textarea name="'.$$rowitems[$i][$j].'">'."\n");
}
- $r->print($$form_elements{$$rowitems[$i][$j]}{content}.'</textarea>'."\n");
+ $r->print($$form_elements{$$rowitems[$i][$j]}{contents}.'</textarea>'."\n");
}
$r->print('
</td>
@@ -944,28 +1040,9 @@
</table>
<br />
ENDBLOCK
- if ($status eq "enroll") {
- $r->print(qq|
- <input type="button" class="buttoncolored" name="modify" value="$modifybutton" onClick="javascript:validForm('modify')"> <input type="button" class="buttoncolored" value="$cancelbutton" name="cancel" onClick=javascript:validForm('cancel')
- |);
- } elsif ($status eq "cancel") {
- $r->print(qq|
- <input type="button" class="buttoncolored" name="reactivate" value="Re-register" onClick=
-"javascript:validForm('add')">|);
- } else {
- $r->print(qq|
- <input type="button" class="buttoncolored" name="register" value="Register" onClick="javascript:validForm('add')">|);
- }
- $r->print (qq|
- <br />
- </td>
- </tr>
- </table>
- |);
- &main_footer($r,$page,$year,$event,$returnpage,$sponsors,$sponsorinfo,$$domain);
+ return;
}
-
sub display_two() {
my ($r,$event,$year,$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,$condmail) = @_;
my $enc_event = &HTML::Entities::encode($event);
@@ -995,11 +1072,21 @@
my @infochanges = ();
my @additions = ();
my @new_workshops = ();
+ my @attendancedays;
+ my @new_attendancedays;
+ my @outdays;
+ my @indays;
if (ref($$params{'workshop'}) eq 'ARRAY') {
@new_workshops = @{$$params{'workshop'}};
} else {
@new_workshops = ("$$params{'workshop'}");
}
+ if (ref($$params{'attendancedays'}) eq 'ARRAY') {
+ @new_attendancedays = @{$$params{'attendancedays'}};
+ } else {
+ @new_attendancedays = ("$$params{'attendancedays'}");
+ }
+
# 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;
@@ -1097,12 +1184,38 @@
}
}
}
+ $statement = "SELECT name from attendancedays WHERE user_id = $quoted_user AND event_id = '$event_id'";
+ $sth = $dbh->prepare("$statement");
+ $sth->execute();
+ while (my @row = $sth->fetchrow_array) {
+ if (@row > 0) {
+ push @attendancedays, @row;
+ }
+ }
+ $sth->finish;
+ foreach my $name (@attendancedays) {
+ unless (grep/^$name$/,@new_attendancedays) {
+ push @outdays,$name;
+ }
+ }
+ foreach my $name (@new_attendancedays) {
+ unless ($name eq '') {
+ unless (grep/^$name$/,@attendancedays) {
+ push @indays,$name;
+ }
+ }
+ }
} else {
foreach my $name (@new_workshops) {
unless ($name eq '') {
push @additions,$name;
}
}
+ foreach my $name (@new_attendancedays) {
+ unless ($name eq '') {
+ push @indays,$name;
+ }
+ }
}
# Is there any user data for this user?
@@ -1164,6 +1277,9 @@
foreach (@removals) {
$dbh->do("DELETE from workshop_registration WHERE user_id=$quoted_user AND event_id='$event_id' AND name='$_'");
}
+ foreach (@outdays) {
+ $dbh->do("DELETE from attendancedays WHERE user_id=$quoted_user AND event_id='$event_id' AND name='$_'");
+ }
my $statement = "UPDATE event_registration SET modified=NOW(),status='$newstatus'";
foreach (@changes) {
$statement .= ", $_ = '$$params{$_}'";
@@ -1189,6 +1305,9 @@
foreach (@additions) {
$dbh->do("INSERT INTO workshop_registration (user_id,event_id,name) VALUES ($quoted_user,'$event_id','$_')");
}
+ foreach (@indays) {
+ $dbh->do("INSERT INTO attendancedays (user_id,event_id,name) VALUES ($quoted_user,'$event_id','$_')");
+ }
my $newmsg .= "Your registration for the $year LON-CAPA $event has been reactivated";
$msg .= $newmsg."\n\n";
$webmsg .= "<li>".$newmsg."</li>";
@@ -1211,6 +1330,9 @@
foreach (@additions) {
$dbh->do("INSERT INTO workshop_registration (user_id,event_id,name) VALUES ($quoted_user,'$event_id','$_')");
}
+ foreach (@indays) {
+ $dbh->do("INSERT INTO attendancedays (user_id,event_id,name) VALUES ($quoted_user,'$event_id','$_')");
+ }
if ($params->{'accommodation'} eq 'dorm') {
if (ref($table_items{'event_accommodation'}) eq 'ARRAY') {
if (@{$table_items{'event_accommodation'}} > 0) {
@@ -1264,7 +1386,7 @@
$dbh->do("UPDATE event_accommodation SET nights='0' WHERE user_id=$quoted_user AND event_id ='$event_id'");
}
}
- if (@changes > 0 || @removals > 0 || @additions > 0) {
+ if (@changes > 0 || @removals > 0 || @additions > 0 || @outdays > 0|| @indays > 0) {
my $newmsg .= "Your registration for the $year LON-CAPA $event has been updated.";
$msg .= $newmsg."\n";
$webmsg .= "<li>".$newmsg."</li>";
@@ -1273,10 +1395,17 @@
foreach (@removals) {
$dbh->do("DELETE from workshop_registration WHERE user_id=$quoted_user AND event_id='$event_id' AND name='$_'");
}
+ foreach (@outdays) {
+ $dbh->do("DELETE from attendancedays WHERE user_id=$quoted_user AND event_id='$event_id' AND name='$_'");
+ }
foreach (@additions) {
my $statement = "INSERT INTO workshop_registration (user_id,event_id,name) VALUES ($quoted_user,'$event_id','$_')";
$dbh->do($statement);
}
+ foreach (@indays) {
+ my $statement = "INSERT INTO attendancedays (user_id,event_id,name) VALUES ($quoted_user,'$event_id','$_')";
+ $dbh->do($statement);
+ }
}
if ($msg eq '') {
$webmsg .= "No changes were made in your registration for the $year LON-CAPA $event.";
@@ -1348,6 +1477,36 @@
$finaldispdat{'workshop'} = 'None';
}
+# Get final attendance days
+ my @finalattendancedays = ();
+ my $statement = "SELECT name from attendancedays WHERE user_id = $quoted_user AND event_id = '$event_id'";
+ my $sth = $dbh->prepare("$statement");
+ $sth->execute();
+ while (my @row = $sth->fetchrow_array) {
+ push @finalattendancedays, @row;
+ }
+ $sth->finish;
+ if (@finalattendancedays > 0) {
+ @finalattendancedays = sort { $a <=> $b } @finalattendancedays;
+ my (@alldays,%daytitle,@displaydays);
+ @alldays = split(/&/,$form_elements->{'attendancedays'}{'contents'});
+ foreach my $item (@alldays) {
+ my ($key,$value) = split(/=/,$item);
+ $daytitle{$key} = $value;
+ }
+ foreach my $item (@finalattendancedays) {
+ push(@displaydays,$daytitle{$item});
+ }
+ $finaldispdat{'attendancedays'} = join(", ",@displaydays);
+ if ($finaldispdat{'attendancedays'} eq '') {
+ $finaldispdat{'attendancedays'} = 'None';
+ } else {
+ $finaldispdat{'registration'} = 'Y';
+ }
+ } else {
+ $finaldispdat{'attendancedays'} = 'None';
+ }
+
my %statusmsg = (
mail => '',
web => ''
@@ -1368,11 +1527,16 @@
$statusmsg{$target} .= '</b>';
}
for (my $i=0; $i<@{$rowitems}; $i++) {
- $statusmsg{$target} .= $$rowtitles[$i].': ';
+ my $rowinfo;
foreach (@{$$rowitems[$i]}) {
- $statusmsg{$target} .= "$finaldispdat{$_} ";
+ if ($finaldispdat{$_} ne '') {
+ $rowinfo .= "$finaldispdat{$_} ";
+ }
+ }
+ if ($rowinfo ne '') {
+ $statusmsg{$target} .= $$rowtitles[$i].': '.
+ $rowinfo.$linefeed{$target};
}
- $statusmsg{$target} .= "$linefeed{$target}";
}
}
}
@@ -1419,7 +1583,22 @@
if ($currstatus eq 'enroll') {
if ($feehash{$key}{'type'} eq 'accomm') {
$quantities{$key} += $finaldispaccom{$key}{quant};
- } else {
+ } 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;
+ }
+ }
+ if ($check_ok) {
+ $quantities{$key} ++;
+ }
+ } else {
$quantities{$key} ++;
}
if (($feehash{$key}{'waiver'} eq 'Y') && (grep/^\Q$user\E$/,@{$consortium})) {
@@ -1471,7 +1650,9 @@
$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 changed, 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 />';
+ } elsif ($feehash{$key}{'type'} eq 'attendancedays') {
+ $payinfo .= 'As your attendance plans 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 />';
}
@@ -1752,7 +1933,7 @@
</tr>
END_OF_D
}
- if ($order < 0) {
+ if ($order <= 0) {
$r->print(<<"END_OF_E");
<tr>
<td colspan="2"> </td>
@@ -1887,12 +2068,13 @@
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.';
+ $output = ' Any changes made to registration which result in a refund will be credited to the card originally used for payment.';
+# $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.';
+ $output = ' Any changes made by '.localtime($endcredit).' to registration 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.';
+ $output = ' The deadline for refunds has passed. Although you may make changes to your registration, refunds of prior payment(s) will not be made.';
}
}
return $output;
@@ -1901,7 +2083,7 @@
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 />";
+ 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 />";
if (keys(%{$feeinfo}) > 0) {
$output .= '<ul>';
foreach my $item (sort(keys(%{$feeinfo}))) {
--raeburn1207101925--