[LON-CAPA-cvs] cvs: rat / lonpageflip.pm

albertel lon-capa-cvs@mail.lon-capa.org
Mon, 06 Mar 2006 23:41:08 -0000


albertel		Mon Mar  6 18:41:08 2006 EDT

  Modified files:              
    /rat	lonpageflip.pm 
  Log:
  - BUG#4692, trying to add a standardish way of adding form parameters to a url
  
  
Index: rat/lonpageflip.pm
diff -u rat/lonpageflip.pm:1.65 rat/lonpageflip.pm:1.66
--- rat/lonpageflip.pm:1.65	Mon Mar  6 18:35:43 2006
+++ rat/lonpageflip.pm	Mon Mar  6 18:41:07 2006
@@ -2,7 +2,7 @@
 #
 # Page flip handler
 #
-# $Id: lonpageflip.pm,v 1.65 2006/03/06 23:35:43 www Exp $
+# $Id: lonpageflip.pm,v 1.66 2006/03/06 23:41:07 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -84,6 +84,28 @@
     return ($hash{'src_'.$id},$symb);
 }
 
+# Inputs are a url, adn a hash ref of
+# form name => value pairs
+# takes care of properly adding the form name elements and values to the 
+# the url doing proper escaping of the values and joining with ? or & as 
+# needed
+
+sub add_get_param {
+    my ($url,$form_data) = @_;
+    my $needs_question_mark = ($url !~ /\?/);
+
+    while (my ($name,$value) = each(%$form_data)) {
+	if ($needs_question_mark) {
+	    $url.='?';
+	    $needs_question_mark = 0;
+	} else { 
+	    $url.='&';
+	}
+	$url.=$name.'='.&Apache::lonnet::escape($form_data->{$name});
+    }
+    return $url;
+}
+
 sub move {
     my ($rid,$mapurl,$direction)=@_;
     my $startoutrid=$rid;
@@ -399,7 +421,7 @@
 
 		  &Apache::loncommon::content_type($r,'text/html');
 		  my $url='http://'.$ENV{'HTTP_HOST'}.$redirecturl;
-		  if ($redirectsymb ne '') { $url.=($url=~/\?/?'&':'?').'symb='.&Apache::lonnet::escape($redirectsymb); }
+		  $url = &add_get_param($url, { 'symb' => $redirectsymb});
                   $r->header_out(Location => $url);
                   return REDIRECT;
 	      } else {
@@ -433,8 +455,10 @@
                      foreach my $id (@possibilities) {
                         $r->print(
                               '<tr><td><a href="'.
-                              $multichoicehash{'src_'.$id}.($multichoicehash{'src_'.$id}=~/\?/?'&':'?').'symb=' .
-                                  Apache::lonnet::escape($multichoicehash{'symb_'.$id}).'">'.
+				  &add_get_param($multichoicehash{'src_'.$id},
+						 {'symb' =>
+						      $multichoicehash{'symb_'.$id},
+						  }).'">'.
                               $multichoicehash{'title_'.$id}.
                               '</a></td><td>'.$multichoicehash{'type_'.$id}.
 			      '</td></tr>');