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

www lon-capa-cvs@mail.lon-capa.org
Fri, 02 May 2003 19:00:29 -0000


www		Fri May  2 15:00:29 2003 EDT

  Modified files:              
    /loncom/interface	lonmanagekeys.pm 
  Log:
  Looks like this works now.
  
  
Index: loncom/interface/lonmanagekeys.pm
diff -u loncom/interface/lonmanagekeys.pm:1.10 loncom/interface/lonmanagekeys.pm:1.11
--- loncom/interface/lonmanagekeys.pm:1.10	Fri May  2 12:58:56 2003
+++ loncom/interface/lonmanagekeys.pm	Fri May  2 15:00:29 2003
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Handler to manage course access keys 
 #
-# $Id: lonmanagekeys.pm,v 1.10 2003/05/02 16:58:56 www Exp $
+# $Id: lonmanagekeys.pm,v 1.11 2003/05/02 19:00:29 www Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -54,11 +54,12 @@
 
 # =================================================== Show student list to drop
 sub show_key_list {
-    my ($r,$comment,$newonly,$checkonly,%cenv)=@_;
+    my ($r,$csvlist,$comment,$newonly,$checkonly,%cenv)=@_;
     $comment=~s/\W/\./g;
     my %accesskeys=&Apache::lonnet::dump
 	('accesskeys',$cenv{'domain'},$cenv{'num'});
-    $r->print(<<ENDTABLEHEADER);
+    unless ($csvlist) {
+	$r->print(<<ENDTABLEHEADER);
 <script>
     function copyallcom(tf) {
 	for (i=0; i<tf.elements.length; i++) {
@@ -77,6 +78,7 @@
 <input type="button" value="Copy to All" onClick="copyallcom(this.form);" />
 </th></tr>
 ENDTABLEHEADER
+    }
     foreach (keys %accesskeys) {
         if ($_=~/^error\:/) {
 	    $r->print('<tr><td>No keys have been generated yet.</td></tr>');
@@ -87,78 +89,31 @@
             } else {
 		if ($newonly) { next; }
             }
-	   $r->print("\n<tr><td><tt>".$_.'</tt></td><td>'.($checkout?
+            unless ($csvlist) {
+		$r->print("\n<tr><td><tt>".$_.'</tt></td><td>'.($checkout?
                      $checkout:'-').'</td><td>'.
                      join('<br />',split(/\s*\;\s*/,$com)).
 		     '</td><td><input type="text" size="40" name="com_'.$_.
 		     '" value="" /></td></tr>');
+	    } else {
+		my @line = ();
+		push @line,&Apache::loncommon::csv_translate($_);
+		push @line,&Apache::loncommon::csv_translate($checkout);
+		foreach (split(/\s*\;\s*/,$com)) {
+ 		   push @line,&Apache::loncommon::csv_translate($_);
+		}
+		my $tmp = $";
+		$" = '","';
+		$r->print("\"@line\"\n");
+		$" = $tmp;
+	    }
        }
     }
-    $r->print('</table>');
-    $r->print('<input type="submit" name="addcom" value="Add Above Comments to Keys" /><hr />');
-    return '';
-#
-# Junk below
-#
-    my ($mode,$linkto,$action,$statusmode,$classlist,$keylist);
-#
-# Just junk so that this compiles
-#
-    my ($username,$domain,$id,$name,$section,$status,@Sorted_Students);
-#
-# 
-# 
-    my $cid=$ENV{'form.cid'};
-    #
-    # Variables for excel output
-    my ($excel_workbook, $excel_sheet, $excel_filename,$row);
-    #
-
-    # Print out header 
-    if ($mode eq 'view') {
-    } elsif ($mode eq 'excel') {
-        # Create the excel spreadsheet
-        $excel_filename = '/prtspool/'.
-            $ENV{'user.name'}.'_'.$ENV{'user.domain'}.'_'.
-                time.'_'.rand(1000000000).'.xls';
-        $excel_workbook = Spreadsheet::WriteExcel->new('/home/httpd'.
-                                                       $excel_filename);
-        $excel_workbook->set_tempdir('/home/httpd/perl/tmp');
-        $excel_sheet = $excel_workbook->addworksheet('classlist');
-        #
-        my $description = 'Classlist for '.
-            $ENV{'course.'.$ENV{'request.course.id'}.'.description'};
-        $excel_sheet->write($row++,0,$description);
-        #
-        $excel_sheet->write($row++,0,["username","domain","ID",
-                                      "student name","section","status"]);
-    }
-    foreach my $student (@Sorted_Students) {
-        if ($mode eq 'view') {
-        } elsif ($mode eq 'csv') {
-            # no need to bother with $linkto
-            my @line = ();
-            foreach ($username,$domain,$id,$name,$section) {
-                push @line,&Apache::loncommon::csv_translate($_);
-            }
-            if ($statusmode eq 'Any') {
-                push @line,&Apache::loncommon::csv_translate($status);
-            }
-            my $tmp = $";
-            $" = '","';
-            $r->print("\"@line\"\n");
-            $" = $tmp;
-        } elsif ($mode eq 'excel') {
-            $excel_sheet->write($row++,0,[$username,$domain,$id,
-                                          $name,$section,$status]);
-        }
-    }
-    if ($mode eq 'view') {
-    } elsif ($mode eq 'excel') {
-        $excel_workbook->close();
-        $r->print('<p><a href="'.$excel_filename.'">'.
-               'Your Excel spreadsheet</a> is ready for download.</p>'."\n");
+    unless ($csvlist) {
+	$r->print('</table>');
+	$r->print('<input type="submit" name="addcom" value="Add Above Comments to Keys" /><hr />');
     }
+    return '';
 }
 
 
@@ -236,14 +191,18 @@
     }
     if ($ENV{'form.cid'}) {
         my %cenv=&Apache::lonnet::coursedescription($ENV{'form.cid'});
-	if (exists($ENV{'form.state'}) && ($ENV{'form.state'} eq 'csv')) {
+	if ($ENV{'form.listkeyscsv'}) {
 #
 # CSV Output
 #
 	    $r->content_type('text/csv');
+            $r->send_http_header;
 #
 # Do CSV
 #
+	    &show_key_list($r,1,$ENV{'form.listcom'},
+                          $ENV{'form.newonly'},$ENV{'form.checkonly'},%cenv);
+
 	} else {
 #
 # Normal web stuff
@@ -266,7 +225,7 @@
                 $r->print($msg.'<br />');
 	    }
             if ($ENV{'form.listkeys'}) {
-		&show_key_list($r,$ENV{'form.listcom'},
+		&show_key_list($r,0,$ENV{'form.listcom'},
                           $ENV{'form.newonly'},$ENV{'form.checkonly'},%cenv);
             }
             if ($ENV{'form.addcom'}) {
@@ -285,11 +244,12 @@
 Comments/Remarks/Notes: <input type="text" name="comments" size="30" /><br />
 <input type="submit" name="genkeys" value="Generate Keys" />
 <hr /><h3>List Keys</h3>
-Comments/Remarks/Notes/User/Batch Number:
+Comments/Remarks/Notes/User/Batch Number Filter:
 <input type="text" name="listcom" size="30" value="$batchnumber" /><br />
 <input type="checkbox" name="newonly" /> Unused keys only<br />
 <input type="checkbox" name="checkonly" /> Used keys only<br />
-<input type="submit" name="listkeys" value="List Keys" />
+<input type="submit" name="listkeys" value="List Keys/Add Comments" />
+<input type="submit" name="listkeyscsv" value="CSV List of Keys" />
 ENDKEYMENU
 	    $r->print('</form></body></html>');
 	}