version 1.133, 2002/11/05 15:00:27
|
version 1.134, 2002/11/06 20:00:13
|
Line 62 use GDBM_File;
|
Line 62 use GDBM_File;
|
use HTML::TokeParser; |
use HTML::TokeParser; |
use Apache::lonhtmlcommon; |
use Apache::lonhtmlcommon; |
use Apache::loncoursedata; |
use Apache::loncoursedata; |
|
use Apache::File(); |
|
use Spreadsheet::WriteExcel; |
# |
# |
# Caches for coursewide information |
# Caches for coursewide information |
# |
# |
Line 1370 sub outsheet_csv {
|
Line 1372 sub outsheet_csv {
|
@Values = (); |
@Values = (); |
} |
} |
# |
# |
$r->print('<pre>'.$csvdata."\n</pre>"); |
# Write the CSV data to a file and serve up a link |
|
# |
|
my $filename = '/prtspool/'. |
|
$ENV{'user.name'}.'_'.$ENV{'user.domain'}.'_'. |
|
time.'_'.rand(1000000000).'.csv'; |
|
my $file; |
|
unless ($file = Apache::File->new('>'.'/home/httpd'.$filename)) { |
|
$r->log_error("Couldn't open $filename for output $!"); |
|
$r->print("Problems occured in writing the csv file. ". |
|
"This error has been logged. ". |
|
"Please alert your LON-CAPA administrator."); |
|
$r->print("<pre>\n".$csvdata."</pre>\n"); |
|
return 0; |
|
} |
|
print $file $csvdata; |
|
close($file); |
|
$r->print('<br /><br />'. |
|
'<a href="'.$filename.'">Your CSV spreadsheet.</a>'."\n"); |
# |
# |
return 1; |
return 1; |
} |
} |
|
|
sub outsheet_excel { |
sub outsheet_excel { |
my ($sheet,$r) = @_; |
my ($sheet,$r) = @_; |
|
my $filename = '/prtspool/'. |
|
$ENV{'user.name'}.'_'.$ENV{'user.domain'}.'_'. |
|
time.'_'.rand(1000000000).'.xls'; |
|
&Apache::lonnet::logthis("spreadsheet:filename = ".$filename); |
|
my $workbook = Spreadsheet::WriteExcel->new('/home/httpd'.$filename); |
|
if (! defined($workbook)) { |
|
$r->log_error("Error creating excel spreadsheet $filename: $!"); |
|
$r->print("Problems creating new Excel file. ". |
|
"This error has been logged. ". |
|
"Please alert your LON-CAPA administrator"); |
|
return 0; |
|
} |
|
# |
|
# The spreadsheet stores temporary data in files, then put them |
|
# together. If needed we should be able to disable this (memory only). |
|
# The temporary directory must be specified before calling 'addworksheet'. |
|
# File::Temp is used to determine the temporary directory. |
|
$workbook->set_tempdir('/home/httpd/perl/tmp'); |
|
# |
|
# Determine the name to give the worksheet |
|
my $sheetname; |
|
if ($sheet->{'sheettype'} eq 'classcalc') { |
|
$sheetname = 'Main'; |
|
} elsif ($sheet->{'sheettype'} eq 'studentcalc') { |
|
$sheetname = $sheet->{'uname'}.'@'.$sheet->{'udom'}; |
|
} elsif ($sheet->{'sheettype'} eq 'assesscalc') { |
|
$sheetname = $sheet->{'uname'}.'@'.$sheet->{'udom'}.' assessment'; |
|
} |
|
my $worksheet = $workbook->addworksheet($sheetname); |
|
#################################### |
|
# Prepare to output rows |
|
#################################### |
|
my @Rows = &sort_indicies($sheet); |
|
# |
|
# Loop through the rows and output them one at a time |
|
my $rows_output=0; |
|
foreach my $rownum (@Rows) { |
|
my ($rowlabel,@rowdata) = &get_row($sheet,$rownum); |
|
my $cols_output = 0; |
|
my $label = &format_excel_rowlabel($rowlabel); |
|
$worksheet->write($rows_output,$cols_output++,$label); |
|
if (ref($label)) { |
|
$cols_output = (scalar(@$label)); |
|
} |
|
foreach my $cell (@rowdata) { |
|
$worksheet->write($rows_output,$cols_output++, |
|
$cell->{'value'}); |
|
} |
|
$rows_output++; |
|
} |
|
# |
|
$workbook->close(); |
|
# Okay, the spreadsheet is taken care of, so give the user a link. |
|
$r->print('<br /><br />'. |
|
'<a href="'.$filename.'">Your Excel spreadsheet.</a>'."\n"); |
|
return 1; |
} |
} |
|
|
sub outsheet_xml { |
sub outsheet_xml { |
Line 1385 sub outsheet_xml {
|
Line 1460 sub outsheet_xml {
|
|
|
sub outsheet { |
sub outsheet { |
my ($r,$sheet)=@_; |
my ($r,$sheet)=@_; |
if (exists($ENV{'form.showcsv'})) { |
if (! exists($ENV{'form.output'})) { |
|
$ENV{'form.output'} = 'HTML'; |
|
} |
|
if (lc($ENV{'form.output'}) eq 'csv') { |
&outsheet_csv($sheet,$r); |
&outsheet_csv($sheet,$r); |
# } elsif (exists($ENV{'form.excel'})) { |
} elsif (lc($ENV{'form.output'}) eq 'excel') { |
# &outsheet_excel($sheet,$r); |
&outsheet_excel($sheet,$r); |
# } elsif (exists($ENV{'form.xml'})) { |
# } elsif (lc($ENV{'form.output'}) eq 'xml' ) { |
# &outsheet_xml($sheet,$r); |
# &outsheet_xml($sheet,$r); |
} else { |
} else { |
&outsheet_html($sheet,$r); |
&outsheet_html($sheet,$r); |
Line 1533 sub makenewsheet {
|
Line 1611 sub makenewsheet {
|
$sheet->{'cnum'} = $ENV{'course.'.$ENV{'request.course.id'}.'.num'}; |
$sheet->{'cnum'} = $ENV{'course.'.$ENV{'request.course.id'}.'.num'}; |
$sheet->{'cdom'} = $ENV{'course.'.$ENV{'request.course.id'}.'.domain'}; |
$sheet->{'cdom'} = $ENV{'course.'.$ENV{'request.course.id'}.'.domain'}; |
$sheet->{'chome'} = $ENV{'course.'.$ENV{'request.course.id'}.'.home'}; |
$sheet->{'chome'} = $ENV{'course.'.$ENV{'request.course.id'}.'.home'}; |
|
$sheet->{'coursedesc'} = $ENV{'course.'.$ENV{'request.course.id'}. |
|
'description'}; |
$sheet->{'uhome'} = &Apache::lonnet::homeserver($uname,$udom); |
$sheet->{'uhome'} = &Apache::lonnet::homeserver($uname,$udom); |
# |
# |
# |
# |
Line 1776 sub format_csv_rowlabel {
|
Line 1856 sub format_csv_rowlabel {
|
return '"'.$result.'"'; |
return '"'.$result.'"'; |
} |
} |
|
|
sub format_plain_rowlabel { |
sub format_excel_rowlabel { |
my $rowlabel = shift; |
my $rowlabel = shift; |
return '' if ($rowlabel eq ''); |
return '' if ($rowlabel eq ''); |
my ($type,$labeldata) = split(':',$rowlabel,2); |
my ($type,$labeldata) = split(':',$rowlabel,2); |
Line 1787 sub format_plain_rowlabel {
|
Line 1867 sub format_plain_rowlabel {
|
$result = $title; |
$result = $title; |
} elsif ($type eq 'student') { |
} elsif ($type eq 'student') { |
my ($sname,$sdom,$fullname,$section,$id) = split(':',$labeldata); |
my ($sname,$sdom,$fullname,$section,$id) = split(':',$labeldata); |
$result = '"'. |
$section = '' if (! defined($section)); |
join('","',($sname,$sdom,$fullname,$section,$id).'"'); |
$id = '' if (! defined($id)); |
|
my @Data = ($sname,$sdom,$fullname,$section,$id); |
|
$result = \@Data; |
} elsif ($type eq 'parameter') { |
} elsif ($type eq 'parameter') { |
$labeldata =~ s/<br>/ /g; |
$labeldata =~ s/<br>/ /g; |
$result = $labeldata; |
$result = $labeldata; |
Line 2500 sub handler {
|
Line 2582 sub handler {
|
if (! exists($ENV{'form.Status'})) { |
if (! exists($ENV{'form.Status'})) { |
$ENV{'form.Status'} = 'Active'; |
$ENV{'form.Status'} = 'Active'; |
} |
} |
|
if (! exists($ENV{'form.output'})) { |
|
$ENV{'form.output'} = 'HTML'; |
|
} |
# Check this server |
# Check this server |
my $loaderror=&Apache::lonnet::overloaderror($r); |
my $loaderror=&Apache::lonnet::overloaderror($r); |
if ($loaderror) { return $loaderror; } |
if ($loaderror) { return $loaderror; } |
Line 2753 ENDSCRIPT
|
Line 2838 ENDSCRIPT
|
$r->print('>'); |
$r->print('>'); |
# |
# |
# CSV format checkbox (classcalc sheets only) |
# CSV format checkbox (classcalc sheets only) |
$r->print(' Output CSV format: <input type="checkbox" '. |
$r->print(' Output as <select name="output" size="1" onClick="submit()">'. |
'name="showcsv" onClick="submit()"'); |
"\n"); |
$r->print(' checked') if ($ENV{'form.showcsv'}); |
foreach my $mode (qw/HTML CSV EXCEL/) { |
$r->print('>'); |
$r->print('<option value="'.$mode.'"'); |
|
if ($ENV{'form.output'} eq $mode) { |
|
$r->print(' selected '); |
|
} |
|
$r->print('>'.$mode.'</option>'."\n"); |
|
} |
|
$r->print("</select>\n"); |
|
# |
if ($sheet->{'sheettype'} eq 'classcalc') { |
if ($sheet->{'sheettype'} eq 'classcalc') { |
$r->print(' Student Status: '. |
$r->print(' Student Status: '. |
&Apache::lonhtmlcommon::StatusOptions |
&Apache::lonhtmlcommon::StatusOptions |
Line 2764 ENDSCRIPT
|
Line 2856 ENDSCRIPT
|
} |
} |
# |
# |
# Buttons to insert rows |
# Buttons to insert rows |
$r->print(<<ENDINSERTBUTTONS); |
# $r->print(<<ENDINSERTBUTTONS); |
<br> |
#<br> |
<input type='button' onClick='insertrow("top");' |
#<input type='button' onClick='insertrow("top");' |
value='Insert Row Top'> |
#value='Insert Row Top'> |
<input type='button' onClick='insertrow("bottom");' |
#<input type='button' onClick='insertrow("bottom");' |
value='Insert Row Bottom'><br> |
#value='Insert Row Bottom'><br> |
ENDINSERTBUTTONS |
#ENDINSERTBUTTONS |
# Print out sheet |
# Print out sheet |
&outsheet($r,$sheet); |
&outsheet($r,$sheet); |
$r->print('</form></body></html>'); |
$r->print('</form></body></html>'); |