[LON-CAPA-cvs] cvs: loncom /interface loncommon.pm londropadd.pm

matthew lon-capa-cvs@mail.lon-capa.org
Thu, 09 May 2002 15:56:02 -0000


matthew		Thu May  9 11:56:02 2002 EDT

  Modified files:              
    /loncom/interface	loncommon.pm londropadd.pm 
  Log:
  Comma Seperated Values function added to loncommon (along with a little 
  documentation on get_unprocessed_cgi() ), and londropadd now uses the new
  csv function.  I forgot which bug this is for and I can't find it now.
  
  
Index: loncom/interface/loncommon.pm
diff -u loncom/interface/loncommon.pm:1.36 loncom/interface/loncommon.pm:1.37
--- loncom/interface/loncommon.pm:1.36	Fri Apr 26 14:57:27 2002
+++ loncom/interface/loncommon.pm	Thu May  9 11:56:02 2002
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # a pile of common routines
 #
-# $Id: loncommon.pm,v 1.36 2002/04/26 18:57:27 matthew Exp $
+# $Id: loncommon.pm,v 1.37 2002/05/09 15:56:02 matthew Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -336,6 +336,24 @@
 }   #  end of sub linked_select_forms {
 
 ###############################################################
+
+=item csv_translate($text) 
+
+Translate $text to allow it to be output as a 'comma seperated values' 
+format.
+
+=cut
+
+sub csv_translate {
+    my $text = shift;
+    $text =~ s/\"/\"\"/g;
+    $text =~ s/\n//g;
+    return $text;
+}
+
+###############################################################
+
+###############################################################
 ##        Home server <option> list generating code          ##
 ###############################################################
 #-------------------------------------------
@@ -856,6 +874,23 @@
   $userview=~s/action\s*\=/would_be_action\=/gi;
   return $userview;
 }
+
+###############################################
+
+=item get_unprocessed_cgi($query,$possible_names)
+
+Modify the %ENV hash to contain unprocessed CGI form parameters held in
+$query.  The parameters listed in $possible_names (an array reference),
+will be set in $ENV{'form.name'} if they do not already exist.
+
+Typically called with $ENV{'QUERY_STRING'} as the first parameter.  
+$possible_names is an ref to an array of form element names.  As an example:
+get_unprocessed_cgi($ENV{'QUERY_STRING'},['uname','udom']);
+will result in $ENV{'form.uname'} and $ENV{'form.udom'} being set.
+
+=cut
+
+###############################################
 
 sub get_unprocessed_cgi {
   my ($query,$possible_names)= @_;
Index: loncom/interface/londropadd.pm
diff -u loncom/interface/londropadd.pm:1.41 loncom/interface/londropadd.pm:1.42
--- loncom/interface/londropadd.pm:1.41	Mon May  6 13:48:57 2002
+++ loncom/interface/londropadd.pm	Thu May  9 11:56:02 2002
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Handler to drop and add students in courses 
 #
-# $Id: londropadd.pm,v 1.41 2002/05/06 17:48:57 matthew Exp $
+# $Id: londropadd.pm,v 1.42 2002/05/09 15:56:02 matthew Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -763,6 +763,7 @@
 sub show_class_list {
     my ($r,$mode,%currentlist)=@_;
     my $cid=$ENV{'request.course.id'};
+    # Print out header 
     if ($mode eq 'view') {
         $r->print(<<END);
 <p>
@@ -803,14 +804,16 @@
 </tr>
 END
             } elsif ($mode eq 'csv') {
-                $r->print($sname.','.
-                          $sdom.','.
-                          $reply{$sname}.','.
-                          $info{'lastname'}.','.
-                          $info{'firstname'}.','.
-                          $info{'middlename'}.','.
-                          $info{'generation'}.','.
-                          $ssec."\n");
+                my @line = ();
+                foreach ($sname,$sdom,$reply{$sname},
+                         $info{'lastname'},$info{'firstname'},
+                         $info{'middlename'},$info{'generation'},$ssec) {
+                    push @line,&Apache::loncommon::csv_translate($_);
+                }
+                my $tmp = $";
+                $" = '","';
+                $r->print("\"@line\"\n");
+                $" = $tmp;
             }
         }
     }