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

raeburn lon-capa-cvs-allow@mail.lon-capa.org
Sun, 11 May 2008 18:45:31 -0000


raeburn		Sun May 11 14:45:31 2008 EDT

  Modified files:              
    /modules/raeburn/register	registrations.pm 
  Log:
  - Allow $number in a submitted form without escaping the dollar sign (so prices can be displayed).
  - Fix loop used to reset v_position when a row was moved up the table.
  
  
Index: modules/raeburn/register/registrations.pm
diff -u modules/raeburn/register/registrations.pm:1.9 modules/raeburn/register/registrations.pm:1.10
--- modules/raeburn/register/registrations.pm:1.9	Sat Apr 19 15:22:23 2008
+++ modules/raeburn/register/registrations.pm	Sun May 11 14:45:28 2008
@@ -6,7 +6,7 @@
 # privilege for an event can edit the contents of the registration 
 # form. 
 #
-# $Id: registrations.pm,v 1.9 2008/04/19 19:22:23 raeburn Exp $
+# $Id: registrations.pm,v 1.10 2008/05/11 18:45:28 raeburn Exp $
 #
 # Stuart P Raeburn
 #
@@ -61,17 +61,17 @@
     &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{$_}};
-            for (my $i=0; $i<@{$params{$_}}; $i++) {
-                $params{$_}[$i] =~ s#(`)#'#g;
-                $params{$_}[$i] =~ s#\$#\(\$\)#g;
+    foreach my $param (keys(%qry_items)) {
+        if (@{$qry_items{$param}} > 1) {
+            @{$params{$param}} = @{$qry_items{$param}};
+            for (my $i=0; $i<@{$params{$param}}; $i++) {
+                $params{$param}[$i] =~ s#(`)#'#g;
+                $params{$param}[$i] =~ s#\$(\D)#\(\$\)$1#g;
             }
         } else {
-            $params{$_} = $qry_items{$_}[0];
-            $params{$_} =~ s#`#'#g;
-            $params{$_} =~ s#\$#\(\$\)#g;
+            $params{$param} = $qry_items{$param}[0];
+            $params{$param} =~ s#`#'#g;
+            $params{$param} =~ s#\$(\D)#\(\$\)$1#g;
         }
     }
 
@@ -87,8 +87,8 @@
     my @sponsors = ();
     my %sponsorinfo = ();
 
-    my ($year,$event,$portal,$returnpage,$event_id,$webpath,$year_quoted,$event_quoted,$branch,
-        $choice,$editaction,$phase);
+    my ($year,$event,$portal,$returnpage,$event_id,$webpath,$year_quoted,
+        $event_quoted,$branch,$choice,$editaction,$phase);
     $portal = "/registrations";
     if (exists $params{'return'}) {
         $returnpage = $params{'return'};
@@ -1317,8 +1317,8 @@
 }
 
 sub formfield_edits {
-    my ($r,$dbh,$event_id,$event,$year,$returnpage,$exitpage,$portal,$params,$rowitems,
-        $sponsors,$sponsorinfo) = @_;
+    my ($r,$dbh,$event_id,$event,$year,$returnpage,$exitpage,$portal,$params,
+        $rowitems,$sponsors,$sponsorinfo) = @_;
     if ($params->{'editaction'} eq 'modify') {
         &process_modify_row($r,$dbh,$event_id,$year,$event,$portal,$params,$rowitems,$returnpage,
                             $exitpage,$sponsors,$sponsorinfo);
@@ -1565,7 +1565,7 @@
     for (var j=0; j<document.$formname.rowedit.length; j++) {
         document.$formname.rowedit[j].checked = false;
     }
-    changePage(document.$formname,'edit','formfields','changepos','process');
+    changePage(document.$formname,'edit','formfields','changepos','');
     return;
 }
 
@@ -1928,7 +1928,7 @@
             }
         }
     }
-    if ($oldpos > 0) {
+    if (($oldpos > 0) && ($oldpos != $newpos)) {
         if ($event_id ne '') {
             my $tempmax = $maxv + 1;
             my $statement = "UPDATE event_formfields SET v_position = '$tempmax' WHERE (event_id = '$event_id' AND v_position = '$oldpos')";
@@ -1940,7 +1940,7 @@
                     $dbh->do($statement);
                 }
             } else {
-                for (my $j=$newpos; $j<$oldpos; $j++) {
+                for (my $j=$oldpos-1; $j>=$newpos; $j--) {
                     my $newidx = $j+1;
                     $statement = "UPDATE event_formfields SET v_position = '$newidx' WHERE (event_id = '$event_id' AND v_position = '$j')";
                     $dbh->do($statement);
@@ -2341,7 +2341,7 @@
                         }
                     }
                     my $newitem = $params->{'newitem_'.$modify_rows[$i]};
-                    my @newcols = @items; 
+                    my @newcols = @items;
                     my @newvals;
                     if ($newitem ne '') {
                         for (my $j=0; $j<@items; $j++) {
@@ -2361,7 +2361,7 @@
                         my $insert = "INSERT INTO event_formfields ($newcolstr) VALUES ('$newvalstr')";
                         $dbh->do($insert); 
                     }
-                    my @hpos = $dbh->selectrow_array("SELECT h_position FROM event_formfields WHERE (event_id = $eventid_quoted AND v_position = $vpos_quoted)");
+                    my @hpos = $dbh->selectrow_array("SELECT h_position FROM event_formfields WHERE (event_id = $eventid_quoted AND v_position = $vpos_quoted) ORDER BY h_position");
                     for (my $j=0; $j<@hpos; $j++) {
                         my $val = $j+1;
                         if ($hpos[$j] != $val) {
@@ -3403,7 +3403,7 @@
                 for (my $j=1; $j<@settings; $j++) {
                     my $parm = 'change_'.$iid.'_'.$settings[$j];
                     if (grep(/^\Q$parm\E$/,keys(%{$params}))) {
-                        $params->{$parm} =~ s#\(\$\)#\$#g;
+                        $params->{$parm} =~ s#\(\$\)(\d)#\$$1#g;
                         if ($params->{$parm} ne $current[$j]) {
                             $changes{$iid}{$settings[$j]} = $params->{$parm};
                         }