version 1.134, 2002/11/06 20:00:13
|
version 1.135, 2002/11/07 15:37:02
|
Line 1109 sub exportdata {
|
Line 1109 sub exportdata {
|
|
|
# ========================================================== End of Spreadsheet |
# ========================================================== End of Spreadsheet |
# ============================================================================= |
# ============================================================================= |
|
|
# |
# |
# Procedures for screen output |
# Procedures for spreadsheet output |
# |
# |
# --------------------------------------------- Produce output row n from sheet |
# --------------------------------------------- Produce output row n from sheet |
|
|
Line 1145 sub sort_indicies {
|
Line 1144 sub sort_indicies {
|
return @sortidx; |
return @sortidx; |
} |
} |
|
|
######################################################################## |
############################################################# |
######################################################################## |
### ### |
|
### Spreadsheet Output Routines ### |
|
### ### |
|
############################################################# |
|
|
|
############################################ |
|
## HTML output routines ## |
|
############################################ |
sub html_editable_cell { |
sub html_editable_cell { |
my ($cell,$bgcolor) = @_; |
my ($cell,$bgcolor) = @_; |
my $result; |
my $result; |
Line 1179 sub html_uneditable_cell {
|
Line 1184 sub html_uneditable_cell {
|
return ' '.$value.' '; |
return ' '.$value.' '; |
} |
} |
|
|
######################################################################## |
|
######################################################################## |
|
|
|
sub outsheet_html { |
sub outsheet_html { |
my ($sheet,$r) = @_; |
my ($sheet,$r) = @_; |
my ($num_uneditable,$realm,$row_type); |
my ($num_uneditable,$realm,$row_type); |
Line 1351 END
|
Line 1353 END
|
return 1; |
return 1; |
} |
} |
|
|
|
############################################ |
|
## csv output routines ## |
|
############################################ |
sub outsheet_csv { |
sub outsheet_csv { |
my ($sheet,$r) = @_; |
my ($sheet,$r) = @_; |
my $csvdata = ''; |
my $csvdata = ''; |
Line 1394 sub outsheet_csv {
|
Line 1399 sub outsheet_csv {
|
return 1; |
return 1; |
} |
} |
|
|
|
############################################ |
|
## Excel output routines ## |
|
############################################ |
|
sub outsheet_recursive_excel { |
|
my ($sheet,$r) = @_; |
|
return undef if ($sheet->{'sheettype'} ne 'classcalc'); |
|
my ($workbook,$filename) = &create_excel_spreadsheet($sheet,$r); |
|
return undef if (! defined($workbook)); |
|
# |
|
# Create main worksheet |
|
my $main_worksheet = $workbook->addworksheet('main'); |
|
# |
|
# Figure out who the students are |
|
my %f=&getformulas($sheet); |
|
my $count = 0; |
|
$r->print("<br />\n"); |
|
$r->rflush(); |
|
foreach (keys(%f)) { |
|
next if ($_!~/^A(\d+)/ || $1 == 0 || ($f{$_}=~/^[!~-]/)); |
|
$count++; |
|
my ($sname,$sdom) = split(':',$f{$_}); |
|
my $student_excel_worksheet=$workbook->addworksheet($sname.'@'.$sdom); |
|
# Create a new spreadsheet |
|
my $studentsheet = &makenewsheet($sname,$sdom,'studentcalc',undef); |
|
# Read in the spreadsheet definition |
|
&readsheet($studentsheet,'default_studentcalc'); |
|
# Determine the structure (contained assessments, etc) of the sheet |
|
&updatesheet($studentsheet); |
|
# Load in the (possibly cached) data from the assessment sheets |
|
&loadrows($studentsheet); |
|
# Compute the sheet |
|
&calcsheet($studentsheet); |
|
&Apache::lonnet::logthis("Sheet value for A0 = ".$sheet->{'values'}->{'A0'}); |
|
# Stuff the sheet into excel |
|
&export_sheet_as_excel($studentsheet,$student_excel_worksheet); |
|
if ($count % 5 == 0) { |
|
$r->print($count.' students completed<br />'); |
|
$r->rflush(); |
|
} |
|
} |
|
# |
|
$r->print('All students spreadsheets completed<br />'); |
|
$r->rflush(); |
|
# |
|
# &export_sheet_as_excel fills $worksheet with the data from $sheet |
|
&export_sheet_as_excel($sheet,$main_worksheet); |
|
# |
|
$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_excel { |
sub outsheet_excel { |
my ($sheet,$r) = @_; |
my ($sheet,$r) = @_; |
|
my ($workbook,$filename) = &create_excel_spreadsheet($sheet,$r); |
|
return undef if (! defined($workbook)); |
|
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); |
|
# |
|
# &export_sheet_as_excel fills $worksheet with the data from $sheet |
|
&export_sheet_as_excel($sheet,$worksheet); |
|
# |
|
$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 create_excel_spreadsheet { |
|
my ($sheet,$r) = @_; |
my $filename = '/prtspool/'. |
my $filename = '/prtspool/'. |
$ENV{'user.name'}.'_'.$ENV{'user.domain'}.'_'. |
$ENV{'user.name'}.'_'.$ENV{'user.domain'}.'_'. |
time.'_'.rand(1000000000).'.xls'; |
time.'_'.rand(1000000000).'.xls'; |
&Apache::lonnet::logthis("spreadsheet:filename = ".$filename); |
#&Apache::lonnet::logthis("spreadsheet:filename = ".$filename); |
my $workbook = Spreadsheet::WriteExcel->new('/home/httpd'.$filename); |
my $workbook = Spreadsheet::WriteExcel->new('/home/httpd'.$filename); |
if (! defined($workbook)) { |
if (! defined($workbook)) { |
$r->log_error("Error creating excel spreadsheet $filename: $!"); |
$r->log_error("Error creating excel spreadsheet $filename: $!"); |
$r->print("Problems creating new Excel file. ". |
$r->print("Problems creating new Excel file. ". |
"This error has been logged. ". |
"This error has been logged. ". |
"Please alert your LON-CAPA administrator"); |
"Please alert your LON-CAPA administrator"); |
return 0; |
return undef; |
} |
} |
# |
# |
# The spreadsheet stores temporary data in files, then put them |
# The spreadsheet stores temporary data in files, then put them |
Line 1416 sub outsheet_excel {
|
Line 1499 sub outsheet_excel {
|
$workbook->set_tempdir('/home/httpd/perl/tmp'); |
$workbook->set_tempdir('/home/httpd/perl/tmp'); |
# |
# |
# Determine the name to give the worksheet |
# Determine the name to give the worksheet |
my $sheetname; |
return ($workbook,$filename); |
if ($sheet->{'sheettype'} eq 'classcalc') { |
} |
$sheetname = 'Main'; |
|
} elsif ($sheet->{'sheettype'} eq 'studentcalc') { |
sub export_sheet_as_excel { |
$sheetname = $sheet->{'uname'}.'@'.$sheet->{'udom'}; |
my $sheet = shift; |
} elsif ($sheet->{'sheettype'} eq 'assesscalc') { |
my $worksheet = shift; |
$sheetname = $sheet->{'uname'}.'@'.$sheet->{'udom'}.' assessment'; |
|
} |
|
my $worksheet = $workbook->addworksheet($sheetname); |
|
#################################### |
#################################### |
# Prepare to output rows |
# Prepare to output rows |
#################################### |
#################################### |
Line 1446 sub outsheet_excel {
|
Line 1526 sub outsheet_excel {
|
} |
} |
$rows_output++; |
$rows_output++; |
} |
} |
# |
return; |
$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; |
|
} |
} |
|
|
|
############################################ |
|
## XML output routines ## |
|
############################################ |
sub outsheet_xml { |
sub outsheet_xml { |
my ($sheet,$r) = @_; |
my ($sheet,$r) = @_; |
|
## Someday XML |
|
## Will be rendered for the user |
|
## But not on this day |
} |
} |
|
|
|
## |
|
## Outsheet - calls other outsheet_* functions |
|
## |
sub outsheet { |
sub outsheet { |
my ($r,$sheet)=@_; |
my ($r,$sheet)=@_; |
if (! exists($ENV{'form.output'})) { |
if (! exists($ENV{'form.output'})) { |
Line 1467 sub outsheet {
|
Line 1551 sub outsheet {
|
&outsheet_csv($sheet,$r); |
&outsheet_csv($sheet,$r); |
} elsif (lc($ENV{'form.output'}) eq 'excel') { |
} elsif (lc($ENV{'form.output'}) eq 'excel') { |
&outsheet_excel($sheet,$r); |
&outsheet_excel($sheet,$r); |
|
} elsif (lc($ENV{'form.output'}) eq 'recursive excel') { |
|
&outsheet_recursive_excel($sheet,$r); |
# } elsif (lc($ENV{'form.output'}) eq 'xml' ) { |
# } elsif (lc($ENV{'form.output'}) eq 'xml' ) { |
# &outsheet_xml($sheet,$r); |
# &outsheet_xml($sheet,$r); |
} else { |
} else { |
Line 2074 sub updatestudentassesssheet {
|
Line 2160 sub updatestudentassesssheet {
|
|
|
# ------------------------------------------------ Load data for one assessment |
# ------------------------------------------------ Load data for one assessment |
|
|
sub loadstudent { |
sub loadstudent{ |
my ($sheet)=@_; |
my ($sheet)=@_; |
my %c=(); |
my %c=(); |
my %f=&getformulas($sheet); |
my %f=&getformulas($sheet); |
Line 2126 sub loadstudent {
|
Line 2212 sub loadstudent {
|
# |
# |
sub loadcourse { |
sub loadcourse { |
my ($sheet,$r)=@_; |
my ($sheet,$r)=@_; |
|
# |
my %c=(); |
my %c=(); |
my %f=&getformulas($sheet); |
my %f=&getformulas($sheet); |
|
# |
my $total=0; |
my $total=0; |
foreach (keys(%f)) { |
foreach (keys(%f)) { |
if ($_=~/^A(\d+)/) { |
if ($_=~/^A(\d+)/) { |
Line 2450 sub exportsheet {
|
Line 2538 sub exportsheet {
|
} |
} |
# |
# |
# Not cached |
# Not cached |
# |
# |
my ($newsheet)=&makenewsheet($uname,$udom,$stype,$usymb); |
my ($newsheet)=&makenewsheet($uname,$udom,$stype,$usymb); |
&readsheet($newsheet,$fn); |
&readsheet($newsheet,$fn); |
&updatesheet($newsheet); |
&updatesheet($newsheet); |
Line 2579 sub cachedssheets {
|
Line 2667 sub cachedssheets {
|
sub handler { |
sub handler { |
my $r=shift; |
my $r=shift; |
|
|
|
my ($sheettype) = ($r->uri=~/\/(\w+)$/); |
|
|
if (! exists($ENV{'form.Status'})) { |
if (! exists($ENV{'form.Status'})) { |
$ENV{'form.Status'} = 'Active'; |
$ENV{'form.Status'} = 'Active'; |
} |
} |
if (! exists($ENV{'form.output'})) { |
if ( ! exists($ENV{'form.output'}) || |
|
($sheettype ne 'classcalc' && |
|
lc($ENV{'form.output'}) eq 'recursive excel')) { |
$ENV{'form.output'} = 'HTML'; |
$ENV{'form.output'} = 'HTML'; |
} |
} |
# Check this server |
# Check this server |
Line 2688 ENDSCRIPT
|
Line 2780 ENDSCRIPT
|
undef %updatedata; |
undef %updatedata; |
} |
} |
# Read new sheet or modified worksheet |
# Read new sheet or modified worksheet |
$r->uri=~/\/(\w+)$/; |
my ($sheet)=&makenewsheet($aname,$adom,$sheettype,$ENV{'form.usymb'}); |
my ($sheet)=&makenewsheet($aname,$adom,$1,$ENV{'form.usymb'}); |
|
# |
# |
# If a new formula had been entered, go from work copy |
# If a new formula had been entered, go from work copy |
if ($ENV{'form.unewfield'}) { |
if ($ENV{'form.unewfield'}) { |
Line 2840 ENDSCRIPT
|
Line 2931 ENDSCRIPT
|
# CSV format checkbox (classcalc sheets only) |
# CSV format checkbox (classcalc sheets only) |
$r->print(' Output as <select name="output" size="1" onClick="submit()">'. |
$r->print(' Output as <select name="output" size="1" onClick="submit()">'. |
"\n"); |
"\n"); |
foreach my $mode (qw/HTML CSV EXCEL/) { |
foreach my $mode (qw/HTML CSV Excel/) { |
$r->print('<option value="'.$mode.'"'); |
$r->print('<option value="'.$mode.'"'); |
if ($ENV{'form.output'} eq $mode) { |
if ($ENV{'form.output'} eq $mode) { |
$r->print(' selected '); |
$r->print(' selected '); |
} |
} |
$r->print('>'.$mode.'</option>'."\n"); |
$r->print('>'.$mode.'</option>'."\n"); |
} |
} |
|
if ($sheet->{'sheettype'} eq 'classcalc') { |
|
$r->print('<option value="recursive excel"'); |
|
if ($ENV{'form.output'} eq 'recursive excel') { |
|
$r->print(' selected '); |
|
} |
|
$r->print(">Multi-Sheet Excel</option>\n"); |
|
} |
$r->print("</select>\n"); |
$r->print("</select>\n"); |
# |
# |
if ($sheet->{'sheettype'} eq 'classcalc') { |
if ($sheet->{'sheettype'} eq 'classcalc') { |