--- loncom/interface/Attic/londropadd.pm 2002/10/16 18:45:10 1.59 +++ loncom/interface/Attic/londropadd.pm 2002/11/08 20:51:48 1.60 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Handler to drop and add students in courses # -# $Id: londropadd.pm,v 1.59 2002/10/16 18:45:10 matthew Exp $ +# $Id: londropadd.pm,v 1.60 2002/11/08 20:51:48 matthew Exp $ # # Copyright Michigan State University Board of Trustees # @@ -41,6 +41,7 @@ use Apache::lonnet(); use Apache::loncommon(); use Apache::lonhtmlcommon(); use Apache::Constants qw(:common :http REDIRECT); +use Spreadsheet::WriteExcel; ############################################################### ############################################################### @@ -771,6 +772,7 @@ END $r->print(< CSV format +Excel format       END @@ -793,14 +795,15 @@ END } # ============================================== view classlist -sub print_csv_classlist { +sub print_formatted_classlist { my $r=shift; + my $mode = shift; my $cid=$ENV{'request.course.id'}; my ($classlist,$keylist)=&Apache::loncoursedata::get_classlist(); if (! defined($classlist)) { $r->print("There are no students currently enrolled.\n"); } else { - &show_class_list($r,'csv','nolink','csv', + &show_class_list($r,$mode,'nolink','csv', $ENV{'form.Status'},$classlist,$keylist); } } @@ -809,8 +812,10 @@ sub print_csv_classlist { sub show_class_list { my ($r,$mode,$linkto,$action,$statusmode,$classlist,$keylist)=@_; my $cid=$ENV{'request.course.id'}; -# &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'}, -# ['sortby']); + # + # Variables for excel output + my ($excel_workbook, $excel_sheet, $excel_filename,$row); + # my $sortby = $ENV{'form.sortby'}; if ($sortby !~ /^(username|domain|section|fullname|id)$/) { $sortby = 'username'; @@ -853,6 +858,22 @@ END $r->print('"'.join('","',("username","domain","ID","student name", "section")).'"'."\n"); } + } 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"]); } # # Sort the students @@ -917,9 +938,18 @@ END $" = '","'; $r->print("\"@line\"\n"); $" = $tmp; + } elsif ($mode eq 'excel') { + $excel_sheet->write($row++,0,[$username,$domain,$id, + $name,$section,$status]); } } - $r->print('
') if ($mode eq 'view'); + if ($mode eq 'view') { + $r->print('
'); + } elsif ($mode eq 'excel') { + $excel_workbook->close(); + $r->print('

'. + 'Your Excel spreadsheet is ready for download.

'."\n"); + } } @@ -1638,7 +1668,9 @@ sub handler { if (! exists($ENV{'form.state'})) { &print_html_classlist($r); } elsif ($ENV{'form.state'} eq 'csv') { - &print_csv_classlist($r); + &print_formatted_classlist($r,'csv'); + } elsif ($ENV{'form.state'} eq 'excel') { + &print_formatted_classlist($r,'excel'); } else { &print_html_classlist($r); }