Annotation of loncom/interface/spreadsheet/assesscalc.pm, revision 1.11
1.1 matthew 1: #
1.11 ! matthew 2: # $Id: assesscalc.pm,v 1.10 2003/05/27 20:20:25 matthew Exp $
1.1 matthew 3: #
4: # Copyright Michigan State University Board of Trustees
5: #
6: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
7: #
8: # LON-CAPA is free software; you can redistribute it and/or modify
9: # it under the terms of the GNU General Public License as published by
10: # the Free Software Foundation; either version 2 of the License, or
11: # (at your option) any later version.
12: #
13: # LON-CAPA is distributed in the hope that it will be useful,
14: # but WITHOUT ANY WARRANTY; without even the implied warranty of
15: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16: # GNU General Public License for more details.
17: #
18: # You should have received a copy of the GNU General Public License
19: # along with LON-CAPA; if not, write to the Free Software
20: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21: #
22: # /home/httpd/html/adm/gpl.txt
23: #
24: # http://www.lon-capa.org/
25: #
26: # The LearningOnline Network with CAPA
27: # Spreadsheet/Grades Display Handler
28: #
29: # POD required stuff:
30:
31: =head1 NAME
32:
33: assesscalc
34:
35: =head1 SYNOPSIS
36:
37: =head1 DESCRIPTION
38:
39: =cut
40:
41: ###################################################
42: ### AssessSheet ###
43: ###################################################
44: package Apache::assesscalc;
45:
46: use strict;
47: use Apache::Constants qw(:common :http);
48: use Apache::lonnet;
1.2 matthew 49: use Apache::loncommon;
1.1 matthew 50: use Apache::Spreadsheet;
51: use HTML::Entities();
52: use Spreadsheet::WriteExcel;
53: use GDBM_File;
54: use Time::HiRes;
55:
56: @Apache::assesscalc::ISA = ('Apache::Spreadsheet');
57:
58: ########################################################
59: ########################################################
60:
61: =pod
62:
63: =head2 Package Variables
64:
65: =over 4
66:
67: =item %Exportrows
68:
69: =item $current_name
70:
71: =item $current_domain
72:
73: =item $current_course
74:
75: =item %parmhash
76:
77: =item %nice_parameter_name
78:
79: =item %useropt
80:
81: =item %courseopt
82:
83: =back
84:
85: =cut
86:
87: ########################################################
88: ########################################################
89:
90: my %Exportrows;
91:
92: my $current_name;
93: my $current_domain;
94: my $current_course;
95:
96: my %parmhash;
97: my %nice_parameter_name;
98:
99: my %useropt;
100: my %courseopt;
101:
102: ########################################################
103: ########################################################
104:
105: =pod
106:
107: =head2 Package Subroutines
108:
109: =item &clear_package()
110:
111: Reset all package variables.
112:
113: =cut
114:
115: ########################################################
116: ########################################################
117: sub clear_package {
118: undef(%Exportrows);
119: undef($current_name);
120: undef($current_domain);
121: undef($current_course);
122: undef(%useropt);
123: undef(%courseopt);
124: }
125:
1.11 ! matthew 126: sub initialize {
! 127: &clear_package();
! 128: }
! 129:
1.1 matthew 130: ########################################################
131: ########################################################
132:
133: =pod
134:
135: =item &initialize_package()
136:
137: =cut
138:
139: ########################################################
140: ########################################################
141: sub initialize_package {
142: my ($sname,$sdomain) = @_;
143: $current_course = $ENV{'request.course.id'};
144: $current_name = $sname;
145: $current_domain = $sdomain;
146: undef(%courseopt);
147: &load_cached_export_rows();
148: &load_parameter_caches();
149: }
150:
151: ########################################################
152: ########################################################
153:
154: =pod
155:
156: =item &load_parameter_caches()
157:
158: =cut
159:
160: ########################################################
161: ########################################################
162: sub load_parameter_caches {
163: my $userprefix = $current_name.':'.$current_domain.'_';
164: $userprefix =~ s/:/_/g;
165: #
166: # Course Parameters Cache
167: if (! %courseopt) {
168: &Apache::lonnet::logthis("loading course options");
169: $current_course = $ENV{'request.course.id'};
170: undef(%courseopt);
171: if (! defined($current_name) || ! defined($current_domain)) {
172: &Apache::lonnet::logthis('bad call to setup_parameter_caches');
173: return;
174: }
175: my $dom = $ENV{'course.'.$ENV{'request.course.id'}.'.domain'};
176: my $id = $ENV{'course.'.$ENV{'request.course.id'}.'.num'};
177: my %Tmp = &Apache::lonnet::dump('resourcedata',$dom,$id);
178: while (my ($name,$value) = each(%Tmp)) {
1.3 matthew 179: $courseopt{$name}=$value;
1.1 matthew 180: }
181: }
182: if (! %useropt) {
183: my %Tmp = &Apache::lonnet::dump('resourcedata',
184: $current_domain,$current_name);
185: while (my ($name,$value) = each(%Tmp)) {
186: if ($name =~ /^error: 2/ || $name =~ /no such file/) {
187: undef(%useropt);
188: last;
189: }
190: $useropt{$userprefix.$name}=$value;
191: }
192: }
193: }
194:
195: ########################################################
196: ########################################################
197:
198: =pod
199:
200: =head2 assesscalc object methods
201:
202: =cut
203:
204: ########################################################
205: ########################################################
206: sub ensure_current_parameter_caches {
207: my $self = shift;
208: if (! defined($current_course) ||
209: $current_course ne $ENV{'request.course.id'} ) {
210: $current_course = $ENV{'request.course.id'};
211: undef(%courseopt);
212: }
213: if (! defined($current_name) || $current_name ne $self->{'name'} ||
214: ! defined($current_domain) || $current_domain ne $self->{'domain'}) {
215: $current_domain = $self->{'domain'};
216: $current_name = $self->{'name'};
217: undef(%useropt);
218: }
219: &load_parameter_caches();
220: }
221:
222: ##################################################
223: ##################################################
224:
225: =pod
226:
227: =item &parmval()
228:
229: Determine the value of a parameter.
230:
231: Inputs: $what, the parameter needed, $symb, $uname, $udom, $csec
232:
233: Returns: The value of a parameter, or '' if none.
234:
235: This function cascades through the possible levels searching for a value for
236: a parameter. The levels are checked in the following order:
237: user, course (at section level and course level), map, and lonnet::metadata.
238: This function uses %parmhash, which must be tied prior to calling it.
239: This function also requires %courseopt and %useropt to be initialized for
240: this user and course.
241:
242: =cut
243:
244: ##################################################
245: ##################################################
246: sub parmval {
247: my $self = shift;
248: my ($what,$symb,$uname,$udom,$csec)=@_;
249: $uname = $self->{'name'} if (! defined($uname));
250: $udom = $self->{'domain'} if (! defined($udom));
251: $csec = $self->{'section'} if (! defined($csec));
252: $symb = $self->{'symb'} if (! defined($symb));
253: #
254: my $result='';
255: #
256: # This should be a
257: my ($mapname,$id,$fn)=split(/___/,$symb);
258: # Cascading lookup scheme
259: my $rwhat=$what;
260: $what =~ s/^parameter\_//;
261: $what =~ s/\_([^\_]+)$/\.$1/;
262: #
263: my $symbparm = $symb.'.'.$what;
264: my $mapparm = $mapname.'___(all).'.$what;
1.3 matthew 265: my $courseprefix = $self->{'cid'};
1.1 matthew 266: my $usercourseprefix = $uname.'_'.$udom.'_'.$self->{'cid'};
267: #
1.3 matthew 268: my $seclevel = $courseprefix.'.['.$csec.'].'.$what;
269: my $seclevelr = $courseprefix.'.['.$csec.'].'.$symbparm;
270: my $seclevelm = $courseprefix.'.['.$csec.'].'.$mapparm;
271: #
272: my $courselevel = $courseprefix.'.'.$what;
273: my $courselevelr = $courseprefix.'.'.$symbparm;
274: my $courselevelm = $courseprefix.'.'.$mapparm;
275: #
276: my $ucourselevel = $usercourseprefix.'.'.$what;
277: my $ucourselevelr = $usercourseprefix.'.'.$symbparm;
278: my $ucourselevelm = $usercourseprefix.'.'.$mapparm;
1.1 matthew 279: # check user
280: if (defined($uname)) {
1.3 matthew 281: return $useropt{$ucourselevelr} if (defined($useropt{$ucourselevelr}));
282: return $useropt{$ucourselevelm} if (defined($useropt{$ucourselevelm}));
283: return $useropt{$ucourselevel} if (defined($useropt{$ucourselevel}));
1.1 matthew 284: }
285: # check section
286: if (defined($csec)) {
287: return $courseopt{$seclevelr} if (defined($courseopt{$seclevelr}));
288: return $courseopt{$seclevelm} if (defined($courseopt{$seclevelm}));
289: return $courseopt{$seclevel} if (defined($courseopt{$seclevel}));
290: }
291: #
292: # check course
293: return $courseopt{$courselevelr} if (defined($courseopt{$courselevelr}));
294: return $courseopt{$courselevelm} if (defined($courseopt{$courselevelm}));
295: return $courseopt{$courselevel} if (defined($courseopt{$courselevel}));
296: # check map parms
297: my $thisparm = $parmhash{$symbparm};
298: return $thisparm if (defined($thisparm));
299: # check default
300: $thisparm = &Apache::lonnet::metadata($fn,$rwhat.'.default');
301: return $thisparm if (defined($thisparm));
302: #
303: # Cascade Up
304: my $space=$what;
305: $space=~s/\.\w+$//;
306: if ($space ne '0') {
307: my @parts=split(/_/,$space);
308: my $id=pop(@parts);
309: my $part=join('_',@parts);
310: if ($part eq '') { $part='0'; }
311: my $newwhat=$rwhat;
312: $newwhat=~s/\Q$space\E/$part/;
313: my $partgeneral=$self->parmval($newwhat,$symb,$uname,$udom,$csec);
314: if (defined($partgeneral)) { return $partgeneral; }
315: }
316: #nothing defined
317: return '';
318: }
319:
1.8 matthew 320: sub get_html_title {
321: my $self = shift;
322: my ($assess_title,$name,$time) = $self->get_title();
323: my $title = '<h1>'.$assess_title.'</h1>'.
324: '<h2>'.$name.', '.
325: &Apache::loncommon::aboutmewrapper
326: ($self->{'name'}.'@'.$self->{'domain'},
327: $self->{'name'},$self->{'domain'});
328: $title .= '<h3>'.$time.'</h3>';
329: return $title;
330: }
331:
1.1 matthew 332: sub get_title {
333: my $self = shift;
1.8 matthew 334: my @title = ();
1.1 matthew 335: if (($self->{'usymb'} eq '_feedback') ||
336: ($self->{'usymb'} eq '_evaluation') ||
337: ($self->{'usymb'} eq '_discussion') ||
338: ($self->{'usymb'} eq '_tutoring')) {
1.8 matthew 339: my $assess_title = ucfirst($self->{'usymb'});
340: $assess_title =~ s/^_//;
341: push(@title,$assess_title);
1.1 matthew 342: } else {
1.8 matthew 343: push(@title,&Apache::lonnet::gettitle($self->{'symb'}));
1.1 matthew 344: }
1.2 matthew 345: # Look up the users identifying information
346: # Get the users information
347: my %userenv = &Apache::loncoursedata::GetUserName($self->{'name'},
348: $self->{'domain'});
349: my $name =
350: join(' ',@userenv{'firstname','middlename','lastname','generation'});
351: $name =~ s/\s+$//;
1.8 matthew 352: push (@title,$name);
353: push (@title,scalar(localtime(time)));
354: return @title;
1.1 matthew 355: }
356:
357: sub parent_link {
358: my $self = shift;
359: my $link .= '<p><a href="/adm/studentcalc?'.
360: 'sname='.$self->{'name'}.
361: '&sdomain='.$self->{'domain'}.'">'.
362: 'Student level sheet</a></p>'."\n";
363: return $link;
364: }
365:
366: sub outsheet_html {
367: my $self = shift;
368: my ($r) = @_;
369: ###################################
370: # Determine table structure
371: ###################################
372: my $num_uneditable = 1;
373: my $num_left = 52-$num_uneditable;
374: my $tableheader =<<"END";
375: <table border="2">
376: <tr>
377: <th colspan="2" rowspan="2"><font size="+2">Assessment</font></th>
378: <td bgcolor="#FFDDDD" colspan="$num_uneditable"> </td>
379: <td colspan="$num_left">
380: <b><font size="+1">Calculations</font></b></td>
381: </tr><tr>
382: END
383: my $label_num = 0;
384: foreach (split(//,'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz')){
385: if ($label_num<$num_uneditable) {
386: $tableheader .= '<td bgcolor="#FFDDDD">';
387: } else {
388: $tableheader .= '<td>';
389: }
390: $tableheader .= "<b><font size=+1>$_</font></b></td>";
391: $label_num++;
392: }
393: $tableheader.="</tr>\n";
394: #
395: $r->print($tableheader);
396: #
397: # Print out template row
398: $r->print('<tr><td>Template</td><td> </td>'.
399: $self->html_template_row($num_uneditable)."</tr>\n");
400: #
401: # Print out summary/export row
402: $r->print('<tr><td>Export</td><td>0</td>'.
403: $self->html_export_row()."</tr>\n");
404: #
405: # Prepare to output rows
406: $tableheader =<<"END";
407: <table border="2">
408: <tr><th>row</th><th>Item</th>
409: END
410: foreach (split(//,'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz')){
411: if ($label_num<$num_uneditable) {
412: $tableheader.='<th bgcolor="#FFDDDD">';
413: } else {
414: $tableheader.='<th>';
415: }
416: $tableheader.="<b><font size=+1>$_</font></b></th>";
417: }
418: #
419: my $num_output = 0;
1.8 matthew 420: foreach my $rownum (sort {$a <=> $b} ($self->rows())) {
1.1 matthew 421: if ($num_output++ % 50 == 0) {
422: $r->print("</table>\n".$tableheader);
423: }
424: $r->print('<tr><td>'.$rownum.'</td>'.
1.10 matthew 425: $self->assess_html_row($rownum)."</tr>\n");
1.1 matthew 426: }
427: $r->print("</table>\n");
428: return;
429: }
430:
431: sub assess_html_row {
432: my $self = shift();
1.10 matthew 433: my ($row) = @_;
1.1 matthew 434: my $parameter_name = $self->{'formulas'}->{'A'.$row};
435: my @rowdata = $self->get_row($row);
436: my $num_cols_output = 0;
437: my $row_html;
438: if (exists($nice_parameter_name{$parameter_name})) {
439: my $name = $nice_parameter_name{$parameter_name};
440: $name =~ s/ /\ /g;
441: $row_html .= '<td>'.$name.'<br />'.$parameter_name.'</td>';
442: } else {
443: $row_html .= '<td>'.$parameter_name.'</td>';
444: }
445: foreach my $cell (@rowdata) {
1.10 matthew 446: if ($num_cols_output < 1) {
447: $row_html .= '<td bgcolor="#FFDDDD">';
448: $row_html .= &Apache::Spreadsheet::html_uneditable_cell($cell,
449: '#FFDDDD');
450: } else {
451: $row_html .= '<td bgcolor="#EOFFDD">';
452: $row_html .= &Apache::Spreadsheet::html_editable_cell($cell,
453: '#E0FFDD',1);
454: }
1.1 matthew 455: $row_html .= '</td>';
1.10 matthew 456: $num_cols_output++;
1.1 matthew 457: }
458: return $row_html;
459: }
460:
1.9 matthew 461: sub csv_rows {
462: # writes the meat of the spreadsheet to an excel worksheet. Called
463: # by Spreadsheet::outsheet_excel;
1.1 matthew 464: my $self = shift;
1.9 matthew 465: my ($filehandle) = @_;
466: #
467: # Write a header row
468: $self->csv_output_row($filehandle,undef,
469: ('Parameter','Description','Value'));
470: #
471: # Write each row
472: foreach my $rownum (sort {$a <=> $b} ($self->rows())) {
473: my $parameter_name = $self->{'formulas'}->{'A'.$rownum};
474: my $description = '';
475: if (exists($nice_parameter_name{$parameter_name})) {
476: $description = $nice_parameter_name{$parameter_name};
477: }
478: $self->csv_output_row($filehandle,$rownum,
479: $parameter_name,$description);
480: }
481: return;
1.1 matthew 482: }
483:
1.8 matthew 484: sub excel_rows {
485: # writes the meat of the spreadsheet to an excel worksheet. Called
486: # by Spreadsheet::outsheet_excel;
1.1 matthew 487: my $self = shift;
1.8 matthew 488: my ($worksheet,$cols_output,$rows_output) = @_;
489: #
490: # Write a header row
491: $cols_output = 0;
492: foreach my $value ('Parameter','Description','Value') {
493: $worksheet->write($rows_output,$cols_output++,$value);
494: }
495: $rows_output++;
496: #
497: # Write each row
498: foreach my $rownum (sort {$a <=> $b} ($self->rows())) {
499: my $parameter_name = $self->{'formulas'}->{'A'.$rownum};
500: my $description = '';
501: if (exists($nice_parameter_name{$parameter_name})) {
502: $description = $nice_parameter_name{$parameter_name};
503: }
504: $self->excel_output_row($worksheet,$rownum,$rows_output++,
505: $parameter_name,$description);
506: }
507: return;
1.1 matthew 508: }
509:
510: sub compute {
511: my $self = shift;
512: $self->logthis('computing');
513: $self->initialize_safe_space();
1.11 ! matthew 514: #########################################
! 515: #########################################
! 516: ### ###
! 517: ### Retrieve the problem parameters ###
! 518: ### ###
! 519: #########################################
! 520: #########################################
! 521: my @Mandatory_parameters = ("stores_0_solved",
! 522: "stores_0_awarddetail",
! 523: "stores_0_awarded",
! 524: "timestamp",
! 525: "stores_0_tries",
! 526: "stores_0_award");
1.1 matthew 527: #
528: # Definitions
529: undef(%nice_parameter_name);
530: my %parameters; # holds underscored parameters by name
531: #
532: # Get the metadata fields and determine their proper names
533: my ($symap,$syid,$srcf)=split(/___/,$self->{'symb'});
534: my @Metadata = split(/\,/,&Apache::lonnet::metadata($srcf,'keys'));
1.11 ! matthew 535: foreach my $parm (@Mandatory_parameters,@Metadata) {
1.1 matthew 536: next if ($parm !~ /^(resource\.|stores|parameter)_/);
537: my $cleaned_name = $parm;
538: $cleaned_name =~ s/^resource\./stores_/;
539: $cleaned_name =~ s/\./_/g;
540: my $display = &Apache::lonnet::metadata($srcf,
541: $cleaned_name.'.display');
542: if (! $display) {
543: $display .= &Apache::lonnet::metadata($srcf,$cleaned_name.'.name');
544: }
545: $parameters{$cleaned_name}++;
546: $nice_parameter_name{$cleaned_name} = $display;
547: }
548: #
549: # Get the values of the metadata fields
550: $self->ensure_current_parameter_caches();
551: my $filename = $self->{'coursefilename'}.'_parms.db';
552: if (tie(%parmhash,'GDBM_File',
553: $self->{'coursefilename'}.'_parms.db',&GDBM_READER(),0640)) {
554: foreach my $parmname (keys(%parameters)) {
1.3 matthew 555: my $value = $self->parmval($parmname);
1.1 matthew 556: $parameters{$parmname} =$value;
557: }
558: untie(%parmhash);
559: } else {
560: $self->logthis('unable to tie '.$filename);
561: }
562: #
563: # Clean out unnecessary parameters
564: foreach (keys(%parameters)) {
565: delete($parameters{$_}) if (! /(resource\.|stores_|parameter_)/);
566: }
567: #
568: # Get the students performance data
569: my %student_parameters =
570: &Apache::loncoursedata::get_current_state($self->{'name'},
571: $self->{'domain'},
572: $self->{'symb'},
573: $self->{'cid'});
574: while (my ($parm,$value) = each(%student_parameters)) {
575: $parm =~ s/^resource\./stores_/;
576: $parm =~ s/\./_/g;
577: $parameters{$parm} = $value;
578: }
579: #
580: # Set up the formulas and parameter values
581: my %f=$self->formulas();
582: my %c;
583: #
1.5 matthew 584: # Check for blackout requirements
585: if ((!exists($ENV{'request.role.adv'}) || !$ENV{'request.role.adv'})) {
586: while (my ($parm,$value) = each(%parameters)) {
587: last if ($self->blackout());
588: next if ($parm !~ /^(parameter_.*)_problemstatus$/);
589: next if ($parameters{$1.'_answerdate'}<time);
590: if (lc($value) eq 'no') {
591: # We must blackout this sheet
592: $self->blackout(1);
593: }
594: }
595: }
596: #
597: # Move the parameters into the spreadsheet
1.1 matthew 598: while (my ($parm,$value) = each(%parameters)) {
599: my $cell = 'A'.$self->get_row_number_from_key($parm);
600: $f{$cell} = $parm;
1.6 matthew 601: $value = '"'.$value.'"' if ($value =~/[^0-9.]/);
602: $c{$parm} = $value;
1.1 matthew 603: }
1.6 matthew 604: $self->formulas(\%f);
605: $self->constants(\%c);
1.1 matthew 606: $self->calcsheet();
607: #
608: # Store export row in cache
609: my @exportarray = $self->exportrow();
610: $Exportrows{$self->{'symb'}}->{'time'} = time;
611: $Exportrows{$self->{'symb'}}->{$self->{'filename'}} = \@exportarray;
612: #
613: # Save the export data
614: $self->save_export_data();
615: return;
616: }
617:
618: ##
619: ## sett overrides Spreadsheet::sett
620: ##
621: sub sett {
622: my $self = shift;
623: my %t=();
624: #
625: # Deal with the template row by copying the template formulas into each
626: # row.
627: foreach my $col ($self->template_cells()) {
628: next if ($col=~/^A/);
629: foreach my $row ($self->rows()) {
630: # Get the name of this cell
631: my $cell=$col.$row;
632: # Grab the template declaration
633: $t{$cell}=$self->formula('template_'.$col);
634: # Replace '#' with the row number
635: $t{$cell}=~s/\#/$row/g;
636: # Replace '....' with ','
637: $t{$cell}=~s/\.\.+/\,/g;
638: # Replace 'A0' with the value from 'A0'
639: $t{$cell}=~s/(^|[^\"\'])([A-Za-z]\d+)/$1\$sheet_values\{\'$2\'\}/g;
640: # Replace parameters
641: $t{$cell}=~s/(^|[^\"\'])\[([^\]]+)\]/$1.$self->expandnamed($2)/ge;
642: }
643: }
644: #
645: # Deal with the cells which have formulas
646: while (my ($cell,$formula) = each(%{$self->{'formulas'}})) {
647: next if ($cell =~ /template_/);
648: if ($cell =~ /^A/ && $cell ne 'A0') {
649: if ($formula !~ /^\!/) {
650: $t{$cell}=$self->{'constants'}->{$formula};
651: }
652: } else {
653: $t{$cell}=$formula;
654: $t{$cell}=~s/\.\.+/\,/g;
655: $t{$cell}=~s/(^|[^\"\'])([A-Za-z]\d+)/$1\$sheet_values\{\'$2\'\}/g;
656: $t{$cell}=~s/(^|[^\"\'])\[([^\]]+)\]/$1.$self->expandnamed($2)/ge;
657: }
658: }
659: # Put %t into the safe space
660: %{$self->{'safe'}->varglob('t')}=%t;
661: }
662:
663:
664: ########################################################
665: ########################################################
666:
667: =pod
668:
669: =item &load_cached_export_rows()
670:
671: Retrieves and parsers the export rows of the assessment spreadsheets.
672: These rows are saved in the students directory in the format:
673:
674: sname:sdom:assesscalc:symb.time => time
675:
676: sname:sdom:assesscalc:symb => filename___=___Adata___;___Bdata___;___ ...
677:
678: =cut
679:
680: ########################################################
681: ########################################################
682: sub load_cached_export_rows {
683: %Exportrows = undef;
684: my @tmp = &Apache::lonnet::dump('nohist_calculatedsheets_'.
685: $ENV{'request.course.id'},
686: $current_domain,$current_name,undef);
687: if ($tmp[0]!~/^error/) {
688: my %tmp = @tmp;
689: my $default_filename = $ENV{'course.'.$ENV{'request.course.id'}.
690: '.spreadsheet_default_assesscalc'};
691: # We only got one key, so we will access it directly.
692: while (my ($key,$sheetdata) = each(%tmp)) {
693: my ($sname,$sdom,$sheettype,$symb) = split(':',$key);
694: if ($symb =~ /\.time$/) {
695: $symb =~ s/\.time$//;
696: $Exportrows{$symb}->{'time'} = $sheetdata;
697: } else {
698: $sheetdata =~ s/^(.*)___=___//;
699: my $filename = $1;
700: $filename = $default_filename if (! defined($filename));
701: my @Data = split('___;___',$sheetdata);
702: $Exportrows{$symb}->{$filename} = \@Data;
703: }
704: }
705: }
706: }
707:
708: #############################################
709: #############################################
710:
711: =pod
712:
713: =item &export_data
714:
715: Returns the export data associated with the spreadsheet. Computes the
716: spreadsheet only if necessary.
717:
718: =cut
719:
720: #############################################
721: #############################################
722: sub export_data {
723: my $self = shift;
724: my $symb = $self->{'symb'};
1.5 matthew 725: if (! exists($ENV{'request.role.adv'}) || ! $ENV{'request.role.adv'} ||
726: ! exists($Exportrows{$symb}) || ! defined($Exportrows{$symb}) ||
1.1 matthew 727: ! $self->check_expiration_time($Exportrows{$symb}->{'time'}) ||
728: ! exists($Exportrows{$symb}->{$self->{'filename'}}) ||
729: ! defined($Exportrows{$symb}->{$self->{'filename'}})) {
730: $self->compute();
731: }
732: my @Data = @{$Exportrows{$symb}->{$self->{'filename'}}};
733: if ($Data[0] =~ /^(.*)___=___/) {
734: $self->{'sheetname'} = $1;
735: $Data[0] =~ s/^(.*)___=___//;
736: }
737: for (my $i=0;$i<$#Data;$i++) {
738: $Data[$i]="'".$Data[$i]."'" if ($Data[$i]=~/\D/ && defined($Data[$i]));
739: }
740: return @Data;
741: }
742:
743: #############################################
744: #############################################
745:
746: =pod
747:
748: =item &save_export_data()
749:
750: Writes the export data for this spreadsheet to the students cache.
751:
752: =cut
753:
754: #############################################
755: #############################################
756: sub save_export_data {
757: my $self = shift;
1.7 matthew 758: return if ($self->temporary());
1.1 matthew 759: my $student = $self->{'name'}.':'.$self->{'domain'};
760: my $symb = $self->{'symb'};
761: if (! exists($Exportrows{$symb}) ||
762: ! exists($Exportrows{$symb}->{$self->{'filename'}})) {
763: return;
764: }
765: my $key = join(':',($self->{'name'},$self->{'domain'},'assesscalc',$symb));
766: my $timekey = $key.'.time';
767: my $newstore= join('___;___',@{$Exportrows{$symb}->{$self->{'filename'}}});
768: $newstore = $self->{'filename'}.'___=___'.$newstore;
769: my $result = &Apache::lonnet::put
770: ('nohist_calculatedsheets_'.$ENV{'request.course.id'},
771: { $key => $newstore,
772: $timekey => $Exportrows{$symb}->{'time'} },
773: $self->{'domain'},
774: $self->{'name'});
775:
776: return;
777: }
778:
779: 1;
780:
781: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>