version 1.138, 2002/11/12 20:14:51
|
version 1.139, 2002/11/12 22:44:28
|
Line 1086 sub geterrorlog {
|
Line 1086 sub geterrorlog {
|
return ${$sheet->{'safe'}->varglob('errorlog')}; |
return ${$sheet->{'safe'}->varglob('errorlog')}; |
} |
} |
|
|
|
sub gettitle { |
|
my $sheet = shift; |
|
if ($sheet->{'sheettype'} eq 'classcalc') { |
|
return $sheet->{'coursedesc'}; |
|
} elsif ($sheet->{'sheettype'} eq 'studentcalc') { |
|
return 'Grades for '.$sheet->{'uname'}.'@'.$sheet->{'udom'}; |
|
} elsif ($sheet->{'sheettype'} eq 'assesscalc') { |
|
if (($sheet->{'usymb'} eq '_feedback') || |
|
($sheet->{'usymb'} eq '_evaluation') || |
|
($sheet->{'usymb'} eq '_discussion') || |
|
($sheet->{'usymb'} eq '_tutoring')) { |
|
my $title = $sheet->{'usymb'}; |
|
$title =~ s/^_//; |
|
$title = ucfirst($title); |
|
return $title; |
|
} |
|
return if (! defined($sheet->{'mapid'}) || |
|
$sheet->{'mapid'} !~ /^\d+$/); |
|
my $mapid = $sheet->{'mapid'}; |
|
return if (! defined($sheet->{'resid'}) || |
|
$sheet->{'resid'} !~ /^\d+$/); |
|
my $resid = $sheet->{'resid'}; |
|
my %course_db; |
|
tie(%course_db,'GDBM_File',$sheet->{'coursefilename'}.'.db', |
|
&GDBM_READER(),0640); |
|
return if (! tied(%course_db)); |
|
my $key = 'title_'.$mapid.'.'.$resid; |
|
my $title = ''; |
|
if (exists($course_db{$key})) { |
|
$title = $course_db{$key}; |
|
} else { |
|
$title = $sheet->{'usymb'}; |
|
} |
|
untie (%course_db); |
|
return $title; |
|
} |
|
} |
|
|
# ----------------------------------------------------- Get value of $f{'A'.$n} |
# ----------------------------------------------------- Get value of $f{'A'.$n} |
sub getfa { |
sub getfa { |
my $sheet = shift; |
my $sheet = shift; |
Line 1153 sub sort_indicies {
|
Line 1191 sub sort_indicies {
|
# |
# |
my @sortby=(); |
my @sortby=(); |
my @sortidx=(); |
my @sortidx=(); |
|
# Skip row 0 |
for (my $row=1;$row<=$sheet->{'maxrow'};$row++) { |
for (my $row=1;$row<=$sheet->{'maxrow'};$row++) { |
push (@sortby, $sheet->{'safe'}->reval('$f{"A'.$row.'"}')); |
push (@sortby, $sheet->{'safe'}->reval('$f{"A'.$row.'"}')); |
push (@sortidx, $row); |
push (@sortidx, $row); |
Line 1268 END
|
Line 1307 END
|
# Print out summary/export row |
# Print out summary/export row |
#################################### |
#################################### |
my ($rowlabel,@rowdata) = &get_row($sheet,'0'); |
my ($rowlabel,@rowdata) = &get_row($sheet,'0'); |
my $rowcount = 0; |
|
$row_html = '<tr><td>'.&format_html_rowlabel($rowlabel).'</td>'; |
$row_html = '<tr><td>'.&format_html_rowlabel($rowlabel).'</td>'; |
$num_cols_output = 0; |
$num_cols_output = 0; |
foreach my $cell (@rowdata) { |
foreach my $cell (@rowdata) { |
Line 1543 sub create_excel_spreadsheet {
|
Line 1581 sub create_excel_spreadsheet {
|
sub export_sheet_as_excel { |
sub export_sheet_as_excel { |
my $sheet = shift; |
my $sheet = shift; |
my $worksheet = shift; |
my $worksheet = shift; |
|
# |
|
my $rows_output = 0; |
|
my $cols_output = 0; |
|
#################################### |
|
# Write an identifying row # |
|
#################################### |
|
my @Headerinfo = ($sheet->{'coursedesc'}); |
|
my $title = &gettitle($sheet); |
|
$cols_output = 0; |
|
if (defined($title)) { |
|
$worksheet->write($rows_output++,$cols_output++,$title); |
|
} |
|
#################################### |
|
# Write the summary/export row # |
|
#################################### |
|
my ($rowlabel,@rowdata) = &get_row($sheet,'0'); |
|
my $label = &format_excel_rowlabel($rowlabel); |
|
$cols_output = 0; |
|
$worksheet->write($rows_output,$cols_output++,$label); |
|
foreach my $cell (@rowdata) { |
|
$worksheet->write($rows_output,$cols_output++,$cell->{'value'}); |
|
} |
|
$rows_output+= 2; # Skip a row, just for fun |
#################################### |
#################################### |
# Prepare to output rows |
# Prepare to output rows |
#################################### |
#################################### |
my @Rows = &sort_indicies($sheet); |
my @Rows = &sort_indicies($sheet); |
# |
# |
# Loop through the rows and output them one at a time |
# Loop through the rows and output them one at a time |
my $rows_output=0; |
|
foreach my $rownum (@Rows) { |
foreach my $rownum (@Rows) { |
my ($rowlabel,@rowdata) = &get_row($sheet,$rownum); |
my ($rowlabel,@rowdata) = &get_row($sheet,$rownum); |
next if ($rowlabel =~ /^\s*$/); |
next if ($rowlabel =~ /^\s*$/); |
my $cols_output = 0; |
$cols_output = 0; |
my $label = &format_excel_rowlabel($rowlabel); |
my $label = &format_excel_rowlabel($rowlabel); |
$worksheet->write($rows_output,$cols_output++,$label); |
$worksheet->write($rows_output,$cols_output++,$label); |
if (ref($label)) { |
if (ref($label)) { |
$cols_output = (scalar(@$label)); |
$cols_output = (scalar(@$label)); |
} |
} |
foreach my $cell (@rowdata) { |
foreach my $cell (@rowdata) { |
$worksheet->write($rows_output,$cols_output++, |
$worksheet->write($rows_output,$cols_output++,$cell->{'value'}); |
$cell->{'value'}); |
|
} |
} |
$rows_output++; |
$rows_output++; |
} |
} |
Line 1730 sub makenewsheet {
|
Line 1789 sub makenewsheet {
|
$sheet->{'udom'} = $udom; |
$sheet->{'udom'} = $udom; |
$sheet->{'sheettype'} = $stype; |
$sheet->{'sheettype'} = $stype; |
$sheet->{'usymb'} = $usymb; |
$sheet->{'usymb'} = $usymb; |
|
$sheet->{'mapid'} = $ENV{'form.mapid'}; |
|
$sheet->{'resid'} = $ENV{'form.resid'}; |
$sheet->{'cid'} = $ENV{'request.course.id'}; |
$sheet->{'cid'} = $ENV{'request.course.id'}; |
$sheet->{'csec'} = $Section{$uname.':'.$udom}; |
$sheet->{'csec'} = $Section{$uname.':'.$udom}; |
$sheet->{'coursefilename'} = $ENV{'request.course.fn'}; |
$sheet->{'coursefilename'} = $ENV{'request.course.fn'}; |
Line 1737 sub makenewsheet {
|
Line 1798 sub makenewsheet {
|
$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'}. |
$sheet->{'coursedesc'} = $ENV{'course.'.$ENV{'request.course.id'}. |
'description'}; |
'.description'}; |
$sheet->{'uhome'} = &Apache::lonnet::homeserver($uname,$udom); |
$sheet->{'uhome'} = &Apache::lonnet::homeserver($uname,$udom); |
# |
# |
# |
# |
Line 1943 sub format_html_rowlabel {
|
Line 2004 sub format_html_rowlabel {
|
my ($type,$labeldata) = split(':',$rowlabel,2); |
my ($type,$labeldata) = split(':',$rowlabel,2); |
my $result = ''; |
my $result = ''; |
if ($type eq 'symb') { |
if ($type eq 'symb') { |
my ($symb,$uname,$udom,$title) = split(':',$labeldata); |
my ($symb,$uname,$udom,$mapid,$resid,$title) = split(':',$labeldata); |
$symb = &Apache::lonnet::unescape($symb); |
$symb = &Apache::lonnet::unescape($symb); |
$result = '<a href="/adm/assesscalc?usymb='.$symb. |
$result = '<a href="/adm/assesscalc?usymb='.$symb. |
'&uname='.$uname.'&udom='.$udom.'">'.$title.'</a>'; |
'&uname='.$uname.'&udom='.$udom. |
|
'&mapid='.$mapid.'&resid='.$resid.'">'.$title.'</a>'; |
} 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 ='<a href="/adm/studentcalc?uname='.$sname. |
$result ='<a href="/adm/studentcalc?uname='.$sname. |
Line 1966 sub format_csv_rowlabel {
|
Line 2028 sub format_csv_rowlabel {
|
my ($type,$labeldata) = split(':',$rowlabel,2); |
my ($type,$labeldata) = split(':',$rowlabel,2); |
my $result = ''; |
my $result = ''; |
if ($type eq 'symb') { |
if ($type eq 'symb') { |
my ($symb,$uname,$udom,$title) = split(':',$labeldata); |
my ($symb,$uname,$udom,$mapid,$resid,$title) = split(':',$labeldata); |
$symb = &Apache::lonnet::unescape($symb); |
$symb = &Apache::lonnet::unescape($symb); |
$result = $title; |
$result = $title; |
} elsif ($type eq 'student') { |
} elsif ($type eq 'student') { |
Line 1987 sub format_excel_rowlabel {
|
Line 2049 sub format_excel_rowlabel {
|
my ($type,$labeldata) = split(':',$rowlabel,2); |
my ($type,$labeldata) = split(':',$rowlabel,2); |
my $result = ''; |
my $result = ''; |
if ($type eq 'symb') { |
if ($type eq 'symb') { |
my ($symb,$uname,$udom,$title) = split(':',$labeldata); |
my ($symb,$uname,$udom,$mapid,$resid,$title) = split(':',$labeldata); |
$symb = &Apache::lonnet::unescape($symb); |
$symb = &Apache::lonnet::unescape($symb); |
$result = $title; |
$result = $title; |
} elsif ($type eq 'student') { |
} elsif ($type eq 'student') { |
Line 2025 sub updateclasssheet {
|
Line 2087 sub updateclasssheet {
|
foreach my $student (keys(%$classlist)) { |
foreach my $student (keys(%$classlist)) { |
my ($studentDomain,$studentName,$end,$start,$id,$studentSection, |
my ($studentDomain,$studentName,$end,$start,$id,$studentSection, |
$fullname,$status) = @{$classlist->{$student}}; |
$fullname,$status) = @{$classlist->{$student}}; |
|
$Section{$studentName.':'.$studentDomain} = $studentSection; |
if ($ENV{'form.Status'} eq $status || $ENV{'form.Status'} eq 'Any') { |
if ($ENV{'form.Status'} eq $status || $ENV{'form.Status'} eq 'Any') { |
$currentlist{$student}=join(':',('student',$studentName, |
$currentlist{$student}=join(':',('student',$studentName, |
$studentDomain,$fullname, |
$studentDomain,$fullname, |
Line 2098 sub get_student_rowlabels {
|
Line 2161 sub get_student_rowlabels {
|
my %assesslist; |
my %assesslist; |
foreach ('Feedback','Evaluation','Tutoring','Discussion') { |
foreach ('Feedback','Evaluation','Tutoring','Discussion') { |
my $symb = '_'.lc($_); |
my $symb = '_'.lc($_); |
$assesslist{$symb} = join(':',('symb',$symb,$uname,$udom,$_)); |
$assesslist{$symb} = join(':',('symb',$symb,$uname,$udom,0,0,$_)); |
} |
} |
# |
# |
while (my ($key,$srcf) = each(%course_db)) { |
while (my ($key,$srcf) = each(%course_db)) { |
Line 2111 sub get_student_rowlabels {
|
Line 2174 sub get_student_rowlabels {
|
&Apache::lonnet::declutter($course_db{'map_id_'.$mapid}). |
&Apache::lonnet::declutter($course_db{'map_id_'.$mapid}). |
'___'.$resid.'___'.&Apache::lonnet::declutter($srcf); |
'___'.$resid.'___'.&Apache::lonnet::declutter($srcf); |
$assesslist{$symb}='symb:'.&Apache::lonnet::escape($symb).':' |
$assesslist{$symb}='symb:'.&Apache::lonnet::escape($symb).':' |
.$uname.':'.$udom.':'.$course_db{'title_'.$id}; |
.$uname.':'.$udom.':'.$mapid.':'.$resid.':'. |
|
$course_db{'title_'.$id}; |
} |
} |
} |
} |
untie(%course_db); |
untie(%course_db); |
Line 2786 sub handler {
|
Line 2850 sub handler {
|
# |
# |
# Get query string for limited number of parameters |
# Get query string for limited number of parameters |
# |
# |
&Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'}, |
&Apache::loncommon::get_unprocessed_cgi |
['uname','udom','usymb','ufn']); |
($ENV{'QUERY_STRING'},['uname','udom','usymb','ufn','mapid','resid']); |
# |
# |
# Deal with restricted student permissions |
# Deal with restricted student permissions |
# |
# |
Line 2907 ENDSCRIPT
|
Line 2971 ENDSCRIPT
|
# Read new sheet or modified worksheet |
# Read new sheet or modified worksheet |
my ($sheet)=&makenewsheet($aname,$adom,$sheettype,$ENV{'form.usymb'}); |
my ($sheet)=&makenewsheet($aname,$adom,$sheettype,$ENV{'form.usymb'}); |
# |
# |
|
# Check user permissions |
|
if (($sheet->{'sheettype'} eq 'classcalc' ) || |
|
($sheet->{'uname'} ne $ENV{'user.name'} ) || |
|
($sheet->{'udom'} ne $ENV{'user.domain'})) { |
|
unless (&Apache::lonnet::allowed('vgr',$sheet->{'cid'})) { |
|
$r->print('<h1>Access Permission Denied</h1>'. |
|
'</form></body></html>'); |
|
return OK; |
|
} |
|
} |
|
# Print out user information |
|
$r->print('<h2>'.$sheet->{'coursedesc'}.'</h2>'); |
|
if ($sheet->{'sheettype'} ne 'classcalc') { |
|
$r->print('<h2>'.&gettitle($sheet).'</h2><p>'); |
|
} |
|
if ($sheet->{'sheettype'} eq 'assesscalc') { |
|
$r->print('<b>User:</b> '.$sheet->{'uname'}. |
|
'<br /><b>Domain:</b> '.$sheet->{'udom'}.'<br />'); |
|
} |
|
if ($sheet->{'sheettype'} eq 'studentcalc' || |
|
$sheet->{'sheettype'} eq 'assesscalc') { |
|
$r->print('<b>Section/Group:</b>'.$sheet->{'csec'}.'</p>'); |
|
} |
|
# |
# 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'}) { |
$r->print('<h2>Modified Workcopy</h2>'); |
$r->print('<h2>Modified Workcopy</h2>'); |
Line 2921 ENDSCRIPT
|
Line 3009 ENDSCRIPT
|
} else { |
} else { |
&readsheet($sheet,$ENV{'form.ufn'}); |
&readsheet($sheet,$ENV{'form.ufn'}); |
} |
} |
# Print out user information |
|
if ($sheet->{'sheettype'} ne 'classcalc') { |
|
$r->print('<p><b>User:</b> '.$sheet->{'uname'}. |
|
'<br><b>Domain:</b> '.$sheet->{'udom'}); |
|
$r->print('<br><b>Section/Group:</b> '.$sheet->{'csec'}); |
|
if ($ENV{'form.usymb'}) { |
|
$r->print('<br><b>Assessment:</b> <tt>'. |
|
$ENV{'form.usymb'}.'</tt>'); |
|
} |
|
} |
|
# |
|
# Check user permissions |
|
if (($sheet->{'sheettype'} eq 'classcalc' ) || |
|
($sheet->{'uname'} ne $ENV{'user.name'} ) || |
|
($sheet->{'udom'} ne $ENV{'user.domain'})) { |
|
unless (&Apache::lonnet::allowed('vgr',$sheet->{'cid'})) { |
|
$r->print('<h1>Access Permission Denied</h1>'. |
|
'</form></body></html>'); |
|
return OK; |
|
} |
|
} |
|
# Additional options |
# Additional options |
$r->print('<br />'. |
|
'<input type="submit" name="forcerecalc" '. |
|
'value="Completely Recalculate Sheet"><p>'); |
|
if ($sheet->{'sheettype'} eq 'assesscalc') { |
if ($sheet->{'sheettype'} eq 'assesscalc') { |
$r->print('<p><font size=+2>'. |
$r->print('<p><font size=+2>'. |
'<a href="/adm/studentcalc?'. |
'<a href="/adm/studentcalc?'. |
'uname='.$sheet->{'uname'}. |
'uname='.$sheet->{'uname'}. |
'&udom='.$sheet->{'udom'}.'">'. |
'&udom='.$sheet->{'udom'}.'">'. |
'Level up: Student Sheet</a></font><p>'); |
'Level up: Student Sheet</a></font></p>'); |
} |
} |
if (($sheet->{'sheettype'} eq 'studentcalc') && |
if (($sheet->{'sheettype'} eq 'studentcalc') && |
(&Apache::lonnet::allowed('vgr',$sheet->{'cid'}))) { |
(&Apache::lonnet::allowed('vgr',$sheet->{'cid'}))) { |
$r->print ('<p><font size=+2><a href="/adm/classcalc">'. |
$r->print ('<p><font size=+2><a href="/adm/classcalc">'. |
'Level up: Course Sheet</a></font><p>'); |
'Level up: Course Sheet</a></font></p>'); |
} |
} |
|
# Recalc button |
|
$r->print('<br />'. |
|
'<input type="submit" name="forcerecalc" '. |
|
'value="Completely Recalculate Sheet"></p>'); |
# Save dialog |
# Save dialog |
if (&Apache::lonnet::allowed('opa',$ENV{'request.course.id'})) { |
if (&Apache::lonnet::allowed('opa',$ENV{'request.course.id'})) { |
my $fname=$ENV{'form.ufn'}; |
my $fname=$ENV{'form.ufn'}; |
Line 3037 ENDSCRIPT
|
Line 3105 ENDSCRIPT
|
} |
} |
# |
# |
# Write the modified worksheet |
# Write the modified worksheet |
$r->print('<b>Current sheet:</b> '.$sheet->{'filename'}.'<p>'); |
$r->print('<b>Current sheet:</b> '.$sheet->{'filename'}.'</p>'); |
&tmpwrite($sheet); |
&tmpwrite($sheet); |
if ($sheet->{'sheettype'} eq 'studentcalc') { |
if ($sheet->{'sheettype'} eq 'studentcalc') { |
$r->print('<br>Show rows with empty A column: '); |
$r->print('<p>Show rows with empty A column: '); |
} else { |
} else { |
$r->print('<br>Show empty rows: '); |
$r->print('<p>>Show empty rows: '); |
} |
} |
# |
# |
$r->print(&hiddenfield('userselhidden','true'). |
$r->print(&hiddenfield('userselhidden','true'). |