[LON-CAPA-cvs] cvs: modules /raeburn/register register.pm
raeburn
lon-capa-cvs@mail.lon-capa.org
Sat, 04 Feb 2006 01:33:51 -0000
This is a MIME encoded message
--raeburn1139016831
Content-Type: text/plain
raeburn Fri Feb 3 20:33:51 2006 EDT
Modified files:
/modules/raeburn/register register.pm
Log:
Routines in processform.pm now used to retrieve form parameters. Changes to e-mail addresses.
--raeburn1139016831
Content-Type: text/plain
Content-Disposition: attachment; filename="raeburn-20060203203351.txt"
Index: modules/raeburn/register/register.pm
diff -u modules/raeburn/register/register.pm:1.6 modules/raeburn/register/register.pm:1.7
--- modules/raeburn/register/register.pm:1.6 Wed Apr 27 13:01:02 2005
+++ modules/raeburn/register/register.pm Fri Feb 3 20:33:49 2006
@@ -1,12 +1,15 @@
package Apache::LON::register;
use strict;
-use Apache::Constants qw(OK SERVER_ERROR);
+use Apache::RequestRec();
+use Apache::Const qw(OK SERVER_ERROR);
use HTML::Entities;
use DBI;
use LWP;
use HTTP::Request;
use HTTP::Cookies;
+use CGI::Apache qw(:standard);
+use Apache::LON::processform;
sub handler {
my $r = shift;
@@ -30,7 +33,7 @@
return SERVER_ERROR;
}
- my $user = $ENV{REMOTE_USER};
+ my $user = $ENV{'REMOTE_USER'};
if ($user eq '') {
return SERVER_ERROR
}
@@ -39,17 +42,9 @@
my %qry_items = ();
my @rowitems = ();
my @rowtitles = ();
- my @query = split/&/,$r->args;
- push @query, split/&/,$r->content;
- foreach (@query) {
- my ($name, $value) = split(/=/,$_);
- $name =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
- $value =~ tr/+/ /;
- $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
- unless (grep/^$value$/,@{$qry_items{$name}}) {
- push @{$qry_items{$name}}, $value;
- }
- }
+ &Apache::LON::processform::postitems($r,\%qry_items);
+ &Apache::LON::processform::getitems($r->args,\%qry_items);
+
foreach (keys %qry_items) {
if (@{$qry_items{$_}} > 1) {
@{$params{$_}} = @{$qry_items{$_}};
@@ -76,18 +71,26 @@
my @info = ();
my @sponsors = ();
my %sponsorinfo = ();
- my $domain = $params{domain};
+ my $domain = $params{'domain'};
my ($page,$year,$event,$portal,$returnpage,$event_id,$webpath,$year_quoted,$event_quoted);
if (exists $params{'return'}) {
$returnpage = $params{'return'};
}
if (exists $params{'year'}) {
- $year = $params{'year'};
+ if (ref($params{'year'}) eq 'ARRAY') {
+ $year = $params{'year'}[0];
+ } else {
+ $year = $params{'year'};
+ }
$year_quoted = $dbh->quote( $year );
}
if (exists $params{'event'}) {
- $event = $params{'event'};
+ if (ref($params{'event'}) eq 'ARRAY') {
+ $event = $params{'event'}[0];
+ } else {
+ $event = $params{'event'};
+ }
$event_quoted = $dbh->quote( $event );
}
if ($year && $event) {
@@ -129,8 +132,10 @@
# get items that should appear in workshop_registration table
$sth = $dbh->prepare("SELECT name FROM event_formfields WHERE event_id = '$event_id' AND tablename = 'workshop_registration'");
$sth->execute;
- while (my $name = $sth->fetchrow_array) {
- push @workshop, $name;
+ while (my @row = $sth->fetchrow_array) {
+ if (@row > 0) {
+ push @workshop, @row;
+ }
}
$sth->finish;
# get formfield values
@@ -164,8 +169,10 @@
# get existing workshop registration data for this user and event
$sth= $dbh->prepare("SELECT name FROM workshop_registration WHERE user_id = $quoted_user AND event_id = '$event_id'");
$sth->execute();
- while (my $name = $sth->fetchrow_array) {
- push @curr_workshops, $name;
+ while (my @row = $sth->fetchrow_array) {
+ if (@row > 0) {
+ push @curr_workshops, @row;
+ }
}
$sth->finish;
}
@@ -173,7 +180,7 @@
&invalid_event($r,$dbh,$page,$year,$event,$portal,$returnpage,$exitpage,\@sponsors,\%sponsorinfo,$domain);
return OK;
}
- my $contact_email = "helpdesk\@msu.edu";
+ my $contact_email = "helpdesk\@lon-capa.org";
my $contact_name = "LON-CAPA support team";
# figure out what page we're on and where we're heading.
@@ -181,7 +188,7 @@
my $command = $params{'go'};
my $current_page = &calculate_page($page,$command);
if ($current_page == 2) {
- &display_two($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);
+ &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);
} 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);
}
@@ -200,6 +207,11 @@
if ($portal eq '') {
$portal = $exitpage;
}
+ my $logoutportal = $portal;
+ if ($logoutportal =~ /^\/update/) {
+ $logoutportal = '/register';
+ }
+
$r->print(<<"END_OF_A");
<html><head><title>LON-CAPA Event Registration</title>
<meta http-equiv="pragma" content="no-cache">
@@ -216,7 +228,7 @@
</head>
<body bgcolor="#ffffff" link="#003333" alink="#003333" vlink="#003333">
END_OF_A
- &main_box($r,$page,$returnpage,$year,$event);
+ &main_box($r,$year,$event);
$r->print(<<"END_OF_B");
<table cellpadding="0" cellspacing="0" width="100%" border="0">
<tr bgcolor="#ffffff">
@@ -227,7 +239,7 @@
<td align="right" valign="top">
<img border="0" src="/images/login/logout_red.gif" width="90" height="23" align="right" usemap="#event_header">
<map name = "event_header">
- <area shape='rect' coords=10,2,80,18' href="/logout?portal=$portal">
+ <area shape='rect' coords=10,2,80,18' href="/logout?portal=$logoutportal">
<area shape = 'default' nohref>
</map>
</td>
@@ -248,7 +260,10 @@
my $sth=$dbh->prepare("SELECT event,year,eventstart,eventend,location,webpath FROM event_config ORDER BY eventstart");
$sth->execute;
while ( my ($event,$year,$eventstart,$eventend,$location,$webpath) = $sth->fetchrow_array) {
- $r->print("<tr><td><a href='/$webpath'>LON-CAPA $event ($year)</a></td><td>$location</td><td>$eventstart - $eventend</td></tr>");
+ my $regurl = "event=$event&year=$year";
+ $regurl = &HTML::Entities::encode($regurl);
+ $regurl =~ tr/ /+/;
+ $r->print("<tr><td><a href='/register?$regurl'>LON-CAPA $event ($year)</a></td><td>$location</td><td>$eventstart - $eventend</td></tr>");
}
$sth->finish;
$r->print(<<"END_OF_C");
@@ -278,10 +293,10 @@
my $username;
# Is there LON-CAPA user data or MSU user data?
- if ($user =~ /[^\@]:[^\@]/) {
+ if ($user =~ /[^\@]+:[^\@]+/) {
($username,$$domain) = split/:/,$user;
- unless ($domain eq '') {
- my $response = &getdomaininfo($domain,\%userinfo);
+ unless ($$domain eq '') {
+ my $response = &getdomaininfo($$domain,\%userinfo);
}
unless ($$domain eq '' || $username eq '') {
my $response = &getnames($$domain,$username,\%userinfo);
@@ -320,7 +335,9 @@
my $sth = $dbh->prepare("$statement");
$sth->execute();
while (my @row = $sth->fetchrow_array) {
- push @curr_workshops, @row;
+ if (@row > 0) {
+ push @curr_workshops, @row;
+ }
}
$sth->finish;
if (@curr_workshops > 1) {
@@ -381,8 +398,11 @@
if (exists ($$items{'textbox'}) ) {
foreach (@{$$items{'textbox'}}) {
+ my $value = $curr{$_};
+ $value =~ s/[\r\f]//g;
+ $value =~ s/\n+/\\n/g;
$set_func .= qq|
- formName.$_.value = "$curr{$_}"
+ formName.$_.value = "$value"
\n|;
}
}
@@ -390,7 +410,8 @@
if (exists ($$items{'textarea'}) ) {
foreach (@{$$items{'textarea'}}) {
my $value = $curr{$_};
- $value =~ s/\n/\\n/g;
+ $value =~ s/[\r\f]//g;
+ $value =~ s/\n+/\\n/g;
$set_func .= qq|
formName.$_.value = "$value"
\n|;
@@ -543,6 +564,10 @@
END_OF_A
&main_box($r,$year,$event);
+ my $logoutportal = $portal;
+ if ($logoutportal =~ /^\/update/) {
+ $logoutportal = '/register';
+ }
$r->print(<<"END_OF_B");
<table cellpadding="0" cellspacing="0" width="100%" border="0">
@@ -554,7 +579,7 @@
<td align="right" valign="top">
<img border="0" src="/images/login/logout_red.gif" width="90" height="23" align="right" usemap="#event_header">
<map name = 'event_header'>
- <area shape='rect' coords=10,2,80,18' href="/logout?portal=$portal">
+ <area shape='rect' coords=10,2,80,18' href="/logout?portal=$logoutportal">
<area shape = 'default' nohref>
</map>
</td>
@@ -634,7 +659,7 @@
$r->print('<td colspan="'.$colspan.'">'.
$$form_elements{$$rowitems[$i][$j]}{preamble}.
'</td></tr><tr>'.
- '<td align="'.$$form_elements{$$rowitems[$i][$j]}{alignment}.'">'
+ '<td valign="top" align="'.$$form_elements{$$rowitems[$i][$j]}{alignment}.'">'
);
} else {
$r->print('<td>'.
@@ -672,9 +697,12 @@
for (my $k=0; $k<@items; $k++) {
my ($value,$name) = split/=/,$items[$k];
if ($k > 0) {
- $r->print('<td align="'.$$form_elements{$$rowitems[$i][$j]}{alignment}.'">');
+ if ($k%2 == 0 && $k<@items-1 ) {
+ $r->print('</tr><tr>');
+ }
+ $r->print('<td valign="top" align="'.$$form_elements{$$rowitems[$i][$j]}{alignment}.'">');
}
- $r->print('<input type="checkbox" name="'.$$rowitems[$i][$j].'" value="'.$value.'">'.$name.'</td>'."\n");
+ $r->print('<nobr><input type="checkbox" name="'.$$rowitems[$i][$j].'" value="'.$value.'">'.$name.'</nobr></td>'."\n");
}
} elsif ($$form_elements{$$rowitems[$i][$j]}{type} eq 'selectbox') {
my @items = split/\&/,$$form_elements{$$rowitems[$i][$j]}{contents};
@@ -758,9 +786,7 @@
sub display_two() {
- 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) = @_;
- my $year = $$params{'year'};
- my $event = $$params{'event'};
+ 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) = @_;
my $enc_event = &HTML::Entities::encode($event);
$enc_event =~ tr/ /+/;
my $action = $$params{'nextaction'};
@@ -791,14 +817,14 @@
} else {
@new_workshops = ("$$params{'workshop'}");
}
- my @workshops = ();
# Get form field types.
my $sth = $dbh->prepare("SELECT name,type FROM event_formfields WHERE event_id = '$event_id'");
$sth->execute();
while (my ($name,$type) = $sth->fetchrow_array) {
if ($type eq 'textarea') {
- $$params{$name} =~ s/[\n\r\f]/\n/g;
+ $$params{$name} =~ s/[\r\f]+//g;
+ $$params{$name} =~ s/\n+/\n/g;
}
}
$sth->finish;
@@ -846,7 +872,9 @@
my $sth = $dbh->prepare("$statement");
$sth->execute();
while (my @row = $sth->fetchrow_array) {
- push @workshops, @row;
+ if (@row > 0) {
+ push @workshops, @row;
+ }
}
$sth->finish;
foreach my $name (@workshops) {
@@ -855,15 +883,19 @@
}
}
foreach my $name (@new_workshops) {
- unless (grep/^$name$/,@workshops) {
+ unless ($name eq '') {
+ unless (grep/^$name$/,@workshops) {
+ push @additions,$name;
+ }
+ }
+ }
+ } else {
+ foreach my $name (@new_workshops) {
+ unless ($name eq '') {
push @additions,$name;
}
}
}
- my $newstr = join(':',@new_workshops);
- my $workstr = join(':',@workshops);
- my $remstr = join(':',@removals);
- my $addstr = join(':',@additions);
# Is there any user data for this user?
my $statement = "SELECT ";
@@ -894,7 +926,7 @@
$dbh->do($statement);
}
} else {
- my $insertpart = '"INSERT INTO support_user (user_id,created,domain';
+ my $insertpart = "INSERT INTO support_user (user_id,created,domain";
my $valuespart = "VALUES($quoted_user,NOW(),$quoted_domain";
foreach my $name (sort keys %quoted_params) {
if ($$form_elements{$name}{tablename} eq 'support_user') {
@@ -1039,6 +1071,9 @@
$sth->finish;
if (@finalworkshops) {
$finaldispdat{'workshop'} = join(", ",@finalworkshops);
+ if ($finaldispdat{'workshop'} eq '') {
+ $finaldispdat{'workshop'} = 'None';
+ }
} else {
$finaldispdat{'workshop'} = 'None';
}
@@ -1087,7 +1122,7 @@
&error_exit($r,$page,$year,$event,"Can't fork for sendmail:$!\n",$contact_name,$contact_email,$sponsors,$sponsorinfo,$domain);
return;
}
- my $mailcopy = "To: helen\@lon-capa.org\n".
+ my $mailcopy = "To: felicia\@lon-capa.org\n".
"From: $contact_email\n".
"Subject: LON-CAPA conference/workshop change\n".
"The following transaction occurred for $user in the LON-CAPA events registration system: \n".
@@ -1117,6 +1152,10 @@
END_OF_A
&main_box($r,$year,$event);
+ my $logoutportal = $portal;
+ if ($logoutportal =~ /^\/update/) {
+ $logoutportal = '/register';
+ }
$r->print(<<"END_OF_B");
<table cellpadding="0" cellspacing="0" width="100%" border="0">
@@ -1128,7 +1167,7 @@
<td align="right" valign="top">
<img border="0" src="/images/login/logout_red.gif" width="90" height="23" align="right" usemap="#event_header">
<map name = 'event_header'>
- <area shape='rect' coords=10,2,80,18' href="/logout?portal=$portal">
+ <area shape='rect' coords=10,2,80,18' href="/logout?portal=$logoutportal">
<area shape = 'default' nohref>
</map>
</td>
@@ -1362,7 +1401,7 @@
my $URL="https://ntweb1.ais.msu.edu/fsra/AppLogin.Asp";
my $request = HTTP::Request->new(POST => $URL);
$request->content_type('application/x-www-form-urlencoded');
- $request->content('AuthenticationMethod=MSU Net&AlternateID=itds0000&EncryptedStamp='.$stamp.'&'.$pname.'=testtest&App=');
+ $request->content('AuthenticationMethod=MSU Net&AlternateID=itds0000&EncryptedStamp='.$stamp.'&'.$pname.'=&App=');
$request->header('referer' => 'https://ntweb1.ais.msu.edu/fsra/AppLogin.Asp');
my $res = $ua->request($request);
--raeburn1139016831--