[LON-CAPA-cvs] cvs: modules /raeburn/register register.pm

raeburn lon-capa-cvs-allow@mail.lon-capa.org
Wed, 13 Jun 2007 23:01:42 -0000


raeburn		Wed Jun 13 19:01:42 2007 EDT

  Modified files:              
    /modules/raeburn/register	register.pm 
  Log:
  - iterate over keys of the hash.
  - prevent blank values being included in VALUES() part of MySQL INSERT statements.
  
  
Index: modules/raeburn/register/register.pm
diff -u modules/raeburn/register/register.pm:1.13 modules/raeburn/register/register.pm:1.14
--- modules/raeburn/register/register.pm:1.13	Tue May 22 14:55:06 2007
+++ modules/raeburn/register/register.pm	Wed Jun 13 19:01:40 2007
@@ -3,7 +3,7 @@
 # Session-based registration for conferences/workshops
 # Data read/written from MySQL database.
 #
-# $Id: register.pm,v 1.13 2007/05/22 18:55:06 raeburn Exp $
+# $Id: register.pm,v 1.14 2007/06/13 23:01:40 raeburn Exp $
 #
 # Stuart P Raeburn
 # 
@@ -975,7 +975,7 @@
     my $quoted_domain = $dbh->quote( $domain );
     my %quoted_params = ();
     my %table_items = (); 
-    foreach (%{$params}) { 
+    foreach (keys(%{$params})) { 
         unless (ref($$params{$_}) eq 'ARRAY') {
             $quoted_params{$_} = $dbh->quote( $$params{$_} );
         }
@@ -1128,6 +1128,9 @@
         if (@infochanges > 0) {
             my $statement = "UPDATE support_user SET modified=NOW()";
             foreach (@infochanges) {
+                if (!defined($quoted_params{$_})) {
+                    $quoted_params{$_} = $dbh->quote( $$params{$_} );
+                }
                 $statement .= ", $_=$quoted_params{$_}";
             }
             $statement .= " WHERE user_id=$quoted_user";
@@ -1172,6 +1175,10 @@
                     if (ref($table_items{'event_accommodation'}) eq 'ARRAY') {
                         if (@{$table_items{'event_accommodation'}} > 0) {
                             my $nights = $dbh->selectrow_array("select DATEDIFF(departure,arrival) from event_registration where event_id = '$event_id' AND user_id=$quoted_user");
+                            if (!defined($quoted_params{'dormroom'})) {
+                                $quoted_params{'dormroom'} = 
+                                    $dbh->quote( $$params{'dormroom'} );
+                            }
                             $dbh->do("UPDATE event_accommodation SET nights='$nights',type=$quoted_params{'dormroom'} WHERE user_id=$quoted_user AND event_id ='$event_id'");
                         }
                     }
@@ -1191,8 +1198,10 @@
             my $valuespart = "VALUES ($quoted_user,NOW(),'$newstatus','$event_id'";
             if (@{$table_items{'event_registration'}} > 0) {
                 foreach (@{$table_items{'event_registration'}}) {
-                    $insertpart .= ','.$_;
-                    $valuespart .= ','.$quoted_params{$_};
+                    if ($quoted_params{$_} ne "") {
+                        $insertpart .= ','.$_;
+                        $valuespart .= ','.$quoted_params{$_};
+                    }
                 }
                 $insertpart .= ')';
                 $valuespart .= ')';
@@ -1205,7 +1214,11 @@
             if ($params->{'accommodation'} eq 'dorm') {
                 if (ref($table_items{'event_accommodation'}) eq 'ARRAY') {
                     if (@{$table_items{'event_accommodation'}} > 0) {
-                        my $nights = $dbh->selectrow_array("select DATEDIFF(departure,arrival) from event_registration where event_id = '$event_id' AND user_id=$quoted_user");   
+                        my $nights = $dbh->selectrow_array("select DATEDIFF(departure,arrival) from event_registration where event_id = '$event_id' AND user_id=$quoted_user");
+                        if (!defined($quoted_params{'dormroom'})) {
+                            $quoted_params{'dormroom'} = 
+                                $dbh->quote( $$params{'dormroom'} );
+                        }
                         $dbh->do("INSERT INTO event_accommodation VALUES ($quoted_user,'$event_id','$nights',$quoted_params{dormroom})");
                     }
                 }
@@ -1240,6 +1253,10 @@
                 if (ref($table_items{'event_accommodation'}) eq 'ARRAY') {
                     if (@{$table_items{'event_accommodation'}} > 0) {
                         my $nights = $dbh->selectrow_array("select DATEDIFF(departure,arrival) from event_registration where event_id = '$event_id' AND user_id=$quoted_user");
+                        if (!defined($quoted_params{'dormroom'})) {
+                            $quoted_params{'dormroom'} = 
+                                $dbh->quote( $$params{'dormroom'} );
+                        }
                         $dbh->do("UPDATE event_accommodation SET nights='$nights',type=$quoted_params{'dormroom'} WHERE user_id=$quoted_user AND event_id ='$event_id'");
                     }
                 }