Annotation of loncom/interface/lonspreadsheet.pm, revision 1.23
1.1 www 1: # The LearningOnline Network with CAPA
2: # Spreadsheet/Grades Display Handler
3: #
1.15 www 4: # 11/11,11/15,11/27,12/04,12/05,12/06,12/07,
1.23 ! www 5: # 12/08,12/09,12/11,12/12,12/15,12/16,12/18,12/19,12/30,
! 6: # 01/01/01 Gerd Kortemeyer
1.1 www 7:
8: package Apache::lonspreadsheet;
9:
10: use strict;
11: use Safe;
1.3 www 12: use Safe::Hole;
1.1 www 13: use Opcode;
14: use Apache::lonnet;
1.7 www 15: use Apache::Constants qw(:common :http);
1.19 www 16: use GDBM_File;
1.3 www 17: use HTML::TokeParser;
18:
1.11 www 19: #
20: # These cache hashes need to be independent of user, resource and course
21: # (user and course are in the keys)
22: #
23: use vars qw(%spreadsheets %courserdatas %userrdatas);
24: #
25: # These global hashes are dependent on user, course and resource,
26: # and need to be initialized every time when a sheet is calculated
27: #
28: my %courseopt;
29: my %useropt;
30: my %parmhash;
31: my $csec;
32: my $uname;
33: my $udom;
34:
1.5 www 35: # =============================================================================
36: # ===================================== Implements an instance of a spreadsheet
1.4 www 37:
38: sub initsheet {
39: my $safeeval = new Safe;
40: my $safehole = new Safe::Hole;
41: $safeeval->permit("entereval");
42: $safeeval->permit(":base_math");
43: $safeeval->permit("sort");
44: $safeeval->deny(":base_io");
45: $safehole->wrap(\&Apache::lonnet::EXT,$safeeval,'&EXT');
46: my $code=<<'ENDDEFS';
47: # ---------------------------------------------------- Inside of the safe space
48:
1.3 www 49: #
50: # f: formulas
1.4 www 51: # t: intermediate format (variable references expanded)
52: # v: output values
1.6 www 53: # c: preloaded constants (A-column)
54: # rl: row label
1.3 www 55:
1.4 www 56: %v=();
57: %t=();
58: %f=();
1.6 www 59: %c=();
60: %rl=();
61:
62: $maxrow=0;
1.5 www 63: $sheettype='';
64: $filename='';
1.1 www 65:
66: sub mask {
67: my ($lower,$upper)=@_;
68:
1.7 www 69: $lower=~/([A-Za-z]|\*)(\d+|\*)/;
1.1 www 70: my $la=$1;
71: my $ld=$2;
72:
1.7 www 73: $upper=~/([A-Za-z]|\*)(\d+|\*)/;
1.1 www 74: my $ua=$1;
75: my $ud=$2;
76: my $alpha='';
77: my $num='';
78:
79: if (($la eq '*') || ($ua eq '*')) {
1.7 www 80: $alpha='[A-Za-z]';
1.1 www 81: } else {
1.7 www 82: if (($la=~/[A-Z]/) && ($ua=~/[A-Z]/) ||
83: ($la=~/[a-z]/) && ($ua=~/[a-z]/)) {
84: $alpha='['.$la.'-'.$ua.']';
85: } else {
86: $alpha='['.$la.'-Za-'.$ua.']';
87: }
1.1 www 88: }
89:
90: if (($ld eq '*') || ($ud eq '*')) {
91: $num='\d+';
92: } else {
93: if (length($ld)!=length($ud)) {
94: $num.='(';
95: map {
96: $num.='['.$_.'-9]';
97: } ($ld=~m/\d/g);
98: if (length($ud)-length($ld)>1) {
99: $num.='|\d{'.(length($ld)+1).','.(length($ud)-1).'}';
100: }
101: $num.='|';
102: map {
103: $num.='[0-'.$_.']';
104: } ($ud=~m/\d/g);
105: $num.=')';
106: } else {
107: my @lda=($ld=~m/\d/g);
108: my @uda=($ud=~m/\d/g);
1.7 www 109: my $i; $j=0; $notdone=1;
110: for ($i=0;($i<=$#lda)&&($notdone);$i++) {
1.1 www 111: if ($lda[$i]==$uda[$i]) {
112: $num.=$lda[$i];
113: $j=$i;
1.7 www 114: } else {
115: $notdone=0;
1.1 www 116: }
117: }
118: if ($j<$#lda-1) {
119: $num.='('.$lda[$j+1];
120: for ($i=$j+2;$i<=$#lda;$i++) {
121: $num.='['.$lda[$i].'-9]';
122: }
123: if ($uda[$j+1]-$lda[$j+1]>1) {
124: $num.='|['.($lda[$j+1]+1).'-'.($uda[$j+1]-1).']\d{'.
125: ($#lda-$j-1).'}';
126: }
127: $num.='|'.$uda[$j+1];
128: for ($i=$j+2;$i<=$#uda;$i++) {
129: $num.='[0-'.$uda[$i].']';
130: }
131: $num.=')';
132: } else {
1.7 www 133: if ($lda[$#lda]!=$uda[$#uda]) {
134: $num.='['.$lda[$#lda].'-'.$uda[$#uda].']';
135: }
1.1 www 136: }
137: }
138: }
1.4 www 139: return '^'.$alpha.$num."\$";
1.1 www 140: }
141:
142: sub NUM {
143: my $mask=mask(@_);
144: my $num=0;
145: map {
146: $num++;
147: } grep /$mask/,keys %v;
148: return $num;
149: }
150:
151: sub BIN {
152: my ($low,$high,$lower,$upper)=@_;
153: my $mask=mask($lower,$upper);
154: my $num=0;
155: map {
156: if (($v{$_}>=$low) && ($v{$_}<=$high)) {
157: $num++;
158: }
159: } grep /$mask/,keys %v;
160: return $num;
161: }
162:
163:
164: sub SUM {
165: my $mask=mask(@_);
166: my $sum=0;
167: map {
168: $sum+=$v{$_};
169: } grep /$mask/,keys %v;
170: return $sum;
171: }
172:
173: sub MEAN {
174: my $mask=mask(@_);
175: my $sum=0; my $num=0;
176: map {
177: $sum+=$v{$_};
178: $num++;
179: } grep /$mask/,keys %v;
180: if ($num) {
181: return $sum/$num;
182: } else {
183: return undef;
184: }
185: }
186:
187: sub STDDEV {
188: my $mask=mask(@_);
189: my $sum=0; my $num=0;
190: map {
191: $sum+=$v{$_};
192: $num++;
193: } grep /$mask/,keys %v;
194: unless ($num>1) { return undef; }
195: my $mean=$sum/$num;
196: $sum=0;
197: map {
198: $sum+=($v{$_}-$mean)**2;
199: } grep /$mask/,keys %v;
200: return sqrt($sum/($num-1));
201: }
202:
203: sub PROD {
204: my $mask=mask(@_);
205: my $prod=1;
206: map {
207: $prod*=$v{$_};
208: } grep /$mask/,keys %v;
209: return $prod;
210: }
211:
212: sub MAX {
213: my $mask=mask(@_);
214: my $max='-';
215: map {
216: unless ($max) { $max=$v{$_}; }
217: if (($v{$_}>$max) || ($max eq '-')) { $max=$v{$_}; }
218: } grep /$mask/,keys %v;
219: return $max;
220: }
221:
222: sub MIN {
223: my $mask=mask(@_);
224: my $min='-';
225: map {
226: unless ($max) { $max=$v{$_}; }
227: if (($v{$_}<$min) || ($min eq '-')) { $min=$v{$_}; }
228: } grep /$mask/,keys %v;
229: return $min;
230: }
231:
232: sub SUMMAX {
233: my ($num,$lower,$upper)=@_;
234: my $mask=mask($lower,$upper);
235: my @inside=();
236: map {
237: $inside[$#inside+1]=$v{$_};
238: } grep /$mask/,keys %v;
239: @inside=sort(@inside);
240: my $sum=0; my $i;
241: for ($i=$#inside;(($i>$#inside-$num) && ($i>=0));$i--) {
242: $sum+=$inside[$i];
243: }
244: return $sum;
245: }
246:
247: sub SUMMIN {
248: my ($num,$lower,$upper)=@_;
249: my $mask=mask($lower,$upper);
250: my @inside=();
251: map {
252: $inside[$#inside+1]=$v{$_};
253: } grep /$mask/,keys %v;
254: @inside=sort(@inside);
255: my $sum=0; my $i;
256: for ($i=0;(($i<$num) && ($i<=$#inside));$i++) {
257: $sum+=$inside[$i];
258: }
259: return $sum;
260: }
261:
262: sub sett {
263: %t=();
1.16 www 264: my $pattern='';
265: if ($sheettype eq 'assesscalc') {
266: $pattern='A';
267: } else {
268: $pattern='[A-Z]';
269: }
1.1 www 270: map {
1.20 www 271: if ($_=~/template\_(\w)/) {
272: my $col=$1;
273: unless ($col=~/^$pattern/) {
274: map {
275: if ($_=~/A(\d+)/) {
276: my $trow=$1;
277: if ($trow) {
278: my $lb=$col.$trow;
279: $t{$lb}=$f{'template_'.$col};
280: $t{$lb}=~s/\#/$trow/g;
281: $t{$lb}=~s/\.\.+/\,/g;
282: $t{$lb}=~s/(^|[^\"\'])([A-Za-z]\d+)/$1\$v\{\'$2\'\}/g;
283: }
284: }
285: } keys %f;
286: }
287: }
288: } keys %f;
289: map {
290: if (($f{$_}) && ($_!~/template\_/)) {
1.16 www 291: if ($_=~/^$pattern/) {
1.6 www 292: unless ($f{$_}=~/^\!/) {
293: $t{$_}=$c{$_};
294: }
295: } else {
296: $t{$_}=$f{$_};
1.7 www 297: $t{$_}=~s/\.\.+/\,/g;
298: $t{$_}=~s/(^|[^\"\'])([A-Za-z]\d+)/$1\$v\{\'$2\'\}/g;
1.6 www 299: }
1.1 www 300: }
301: } keys %f;
1.17 www 302: $t{'A0'}=$f{'A0'};
303: $t{'A0'}=~s/\.\.+/\,/g;
304: $t{'A0'}=~s/(^|[^\"\'])([A-Za-z]\d+)/$1\$v\{\'$2\'\}/g;
1.1 www 305: }
306:
1.4 www 307: sub calc {
1.1 www 308: %v=();
1.4 www 309: &sett();
1.1 www 310: my $notfinished=1;
311: my $depth=0;
312: while ($notfinished) {
313: $notfinished=0;
314: map {
315: my $old=$v{$_};
1.4 www 316: $v{$_}=eval($t{$_});
1.1 www 317: if ($@) {
318: %v=();
319: return $@;
320: }
321: if ($v{$_} ne $old) { $notfinished=1; }
322: } keys %t;
323: $depth++;
324: if ($depth>100) {
325: %v=();
326: return 'Maximum calculation depth exceeded';
327: }
328: }
329: return '';
330: }
331:
1.21 www 332: sub templaterow {
333: my @cols=();
334: $cols[0]='<b><font size=+1>Template</font></b>';
335: map {
336: my $fm=$f{'template_'.$_};
337: $fm=~s/[\'\"]/\&\#34;/g;
338: $cols[$#cols+1]="'template_$_','$fm'".'___eq___'.$fm;
339: } ('A','B','C','D','E','F','G','H','I','J','K','L','M',
340: 'N','O','P','Q','R','S','T','U','V','W','X','Y','Z',
341: 'a','b','c','d','e','f','g','h','i','j','k','l','m',
342: 'n','o','p','q','r','s','t','u','v','w','x','y','z');
343: return @cols;
344: }
345:
1.16 www 346: sub outrowassess {
1.6 www 347: my $n=shift;
348: my @cols=();
349: if ($n) {
350: $cols[0]=$rl{$f{'A'.$n}};
351: } else {
352: $cols[0]='<b><font size=+1>Export</font></b>';
353: }
354: map {
355: my $fm=$f{$_.$n};
356: $fm=~s/[\'\"]/\&\#34;/g;
357: $cols[$#cols+1]="'$_$n','$fm'".'___eq___'.$v{$_.$n};
358: } ('A','B','C','D','E','F','G','H','I','J','K','L','M',
1.7 www 359: 'N','O','P','Q','R','S','T','U','V','W','X','Y','Z',
360: 'a','b','c','d','e','f','g','h','i','j','k','l','m',
361: 'n','o','p','q','r','s','t','u','v','w','x','y','z');
1.6 www 362: return @cols;
363: }
364:
1.18 www 365: sub outrow {
366: my $n=shift;
367: my @cols=();
368: if ($n) {
1.21 www 369: $cols[0]=$rl{$f{'A'.$n}};
1.18 www 370: } else {
371: $cols[0]='<b><font size=+1>Export</font></b>';
372: }
373: map {
374: my $fm=$f{$_.$n};
375: $fm=~s/[\'\"]/\&\#34;/g;
376: $cols[$#cols+1]="'$_$n','$fm'".'___eq___'.$v{$_.$n};
377: } ('A','B','C','D','E','F','G','H','I','J','K','L','M',
378: 'N','O','P','Q','R','S','T','U','V','W','X','Y','Z',
379: 'a','b','c','d','e','f','g','h','i','j','k','l','m',
380: 'n','o','p','q','r','s','t','u','v','w','x','y','z');
381: return @cols;
382: }
383:
1.14 www 384: sub exportrowa {
385: my $rowa='';
386: map {
1.18 www 387: $rowa.=$v{$_.'0'}."___;___";
1.14 www 388: } ('A','B','C','D','E','F','G','H','I','J','K','L','M',
389: 'N','O','P','Q','R','S','T','U','V','W','X','Y','Z');
1.18 www 390: $rowa=~s/\_\_\_\;\_\_\_$//;
1.14 www 391: return $rowa;
392: }
393:
1.4 www 394: # ------------------------------------------- End of "Inside of the safe space"
395: ENDDEFS
396: $safeeval->reval($code);
397: return $safeeval;
398: }
399:
400: # ------------------------------------------------ Add or change formula values
401:
402: sub setformulas {
403: my ($safeeval,@f)=@_;
1.6 www 404: $safeeval->reval('%f='."('".join("','",@f)."');");
405: }
406:
407: # ------------------------------------------------ Add or change formula values
408:
409: sub setconstants {
410: my ($safeeval,@c)=@_;
411: $safeeval->reval('%c='."('".join("','",@c)."');");
412: }
413:
414: # ------------------------------------------------ Add or change formula values
415:
416: sub setrowlabels {
417: my ($safeeval,@rl)=@_;
418: $safeeval->reval('%rl='."('".join("','",@rl)."');");
1.4 www 419: }
420:
421: # ------------------------------------------------------- Calculate spreadsheet
422:
423: sub calcsheet {
424: my $safeeval=shift;
425: $safeeval->reval('&calc();');
426: }
427:
428: # ------------------------------------------------------------------ Get values
429:
430: sub getvalues {
431: my $safeeval=shift;
432: return $safeeval->reval('%v');
433: }
434:
435: # ---------------------------------------------------------------- Get formulas
436:
437: sub getformulas {
438: my $safeeval=shift;
439: return $safeeval->reval('%f');
440: }
441:
1.5 www 442: # -------------------------------------------------------------------- Set type
443:
444: sub settype {
445: my ($safeeval,$type)=@_;
1.11 www 446: $safeeval->reval('$sheettype="'.$type.'";');
1.5 www 447: }
448:
449: # -------------------------------------------------------------------- Get type
450:
451: sub gettype {
452: my $safeeval=shift;
453: return $safeeval->reval('$sheettype');
454: }
1.6 www 455: # ------------------------------------------------------------------ Set maxrow
456:
457: sub setmaxrow {
458: my ($safeeval,$row)=@_;
459: $safeeval->reval('$maxrow='.$row.';');
460: }
461:
462: # ------------------------------------------------------------------ Get maxrow
463:
464: sub getmaxrow {
465: my $safeeval=shift;
466: return $safeeval->reval('$maxrow');
467: }
1.5 www 468:
1.6 www 469: # ---------------------------------------------------------------- Set filename
1.5 www 470:
471: sub setfilename {
472: my ($safeeval,$fn)=@_;
1.11 www 473: $safeeval->reval('$filename="'.$fn.'";');
1.5 www 474: }
475:
1.6 www 476: # ---------------------------------------------------------------- Get filename
1.5 www 477:
478: sub getfilename {
479: my $safeeval=shift;
480: return $safeeval->reval('$filename');
481: }
1.14 www 482:
483: # ------------------------------------------------------------- Export of A-row
484:
485: sub exportrow {
486: my $safeeval=shift;
487: return $safeeval->reval('&exportrowa()');
488: }
489:
1.5 www 490: # ========================================================== End of Spreadsheet
491: # =============================================================================
492:
493:
1.6 www 494: # --------------------------------------------- Produce output row n from sheet
495:
496: sub rown {
497: my ($safeeval,$n)=@_;
1.21 www 498: my $defaultbg;
499: unless ($n eq '-') {
500: $defaultbg=((($n-1)/5)==int(($n-1)/5))?'#E0E0':'#FFFF';
501: } else {
502: $defaultbg='#E0FF';
503: }
1.6 www 504: my $rowdata="\n<tr><td><b><font size=+1>$n</font></b></td>";
505: my $showf=0;
1.16 www 506: my $proc;
1.18 www 507: my $maxred;
1.16 www 508: if (&gettype($safeeval) eq 'assesscalc') {
509: $proc='&outrowassess';
1.18 www 510: $maxred=1;
1.16 www 511: } else {
512: $proc='&outrow';
1.18 www 513: $maxred=26;
1.16 www 514: }
1.21 www 515: if ($n eq '-') { $proc='&templaterow'; $n=-1; }
1.6 www 516: map {
1.9 www 517: my $bgcolor=$defaultbg.((($showf-1)/5==int(($showf-1)/5))?'99':'DD');
1.6 www 518: my ($fm,$vl)=split(/\_\_\_eq\_\_\_/,$_);
519: if ($showf==0) { $vl=$_; }
1.18 www 520: if ($showf<=$maxred) { $bgcolor='#FFDDDD'; }
1.9 www 521: if (($n==0) && ($showf<=26)) { $bgcolor='#CCCCFF'; }
1.18 www 522: if (($showf>$maxred) || ((!$n) && ($showf>0))) {
1.6 www 523: if ($vl eq '') {
1.9 www 524: $vl='<font size=+2 color='.$bgcolor.'>#</font>';
1.6 www 525: }
526: $rowdata.=
1.10 www 527: '<td bgcolor='.$bgcolor.'><a href="javascript:celledit('.$fm.');">'.$vl.
1.6 www 528: '</a></td>';
529: } else {
1.9 www 530: $rowdata.='<td bgcolor='.$bgcolor.'> '.$vl.' </td>';
1.6 www 531: }
532: $showf++;
1.16 www 533: } $safeeval->reval($proc.'('.$n.')');
1.6 www 534: return $rowdata.'</tr>';
535: }
536:
537: # ------------------------------------------------------------- Print out sheet
538:
539: sub outsheet {
540: my $safeeval=shift;
1.18 www 541: my $maxred;
542: my $realm;
543: if (&gettype($safeeval) eq 'assesscalc') {
544: $maxred=1;
545: $realm='Assessment';
546: } elsif (&gettype($safeeval) eq 'studentcalc') {
547: $maxred=26;
548: $realm='User';
549: } else {
550: $maxred=26;
551: $realm='Course';
552: }
553: my $maxyellow=52-$maxred;
554: my $tabledata='<table border=2><tr><th colspan=2 rowspan=2><font size=+2>'.
555: $realm.'</font></th>'.
556: '<td bgcolor=#FFDDDD colspan='.$maxred.
557: '><b><font size=+1>Import</font></b></td>'.
558: '<td colspan='.$maxyellow.
559: '><b><font size=+1>Calculations</font></b></td></tr><tr>';
560: my $showf=0;
1.6 www 561: map {
1.18 www 562: $showf++;
563: if ($showf<=$maxred) {
564: $tabledata.='<td bgcolor="#FFDDDD">';
565: } else {
566: $tabledata.='<td>';
567: }
568: $tabledata.="<b><font size=+1>$_</font></b></td>";
569: } ('A','B','C','D','E','F','G','H','I','J','K','L','M',
1.7 www 570: 'N','O','P','Q','R','S','T','U','V','W','X','Y','Z',
571: 'a','b','c','d','e','f','g','h','i','j','k','l','m',
572: 'n','o','p','q','r','s','t','u','v','w','x','y','z');
1.6 www 573: $tabledata.='</tr>';
574: my $row;
575: my $maxrow=&getmaxrow($safeeval);
1.21 www 576: $tabledata.=&rown($safeeval,'-');
1.6 www 577: for ($row=0;$row<=$maxrow;$row++) {
578: $tabledata.=&rown($safeeval,$row);
579: }
580: $tabledata.='</table>';
581: }
582:
583:
1.5 www 584:
1.19 www 585: # ------------------------------------- Read spreadsheet formulas from a course
1.3 www 586:
1.5 www 587: sub readsheet {
1.19 www 588: my ($safeeval,$fn,$r)=@_;
1.4 www 589: my %f=();
1.21 www 590: if (($fn eq '') || ($fn=~/^default\_/)) {
1.19 www 591: my $sheetxml='';
1.10 www 592: {
593: my $fh;
1.19 www 594: if ($fh=Apache::File->new($r->dir_config('lonIncludes').
595: '/default.'.&gettype($safeeval))) {
596: $sheetxml=join('',<$fh>);
597: }
598: }
599: my $parser=HTML::TokeParser->new(\$sheetxml);
600: my $token;
601: while ($token=$parser->get_token) {
602: if ($token->[0] eq 'S') {
603: if ($token->[1] eq 'field') {
604: $f{$token->[2]->{'col'}.$token->[2]->{'row'}}=
605: $parser->get_text('/field');
606: }
1.20 www 607: if ($token->[1] eq 'template') {
608: $f{'template_'.$token->[2]->{'col'}}=
609: $parser->get_text('/template');
610: }
1.19 www 611: }
612: }
613: &setfilename($safeeval,'default_'.&gettype($safeeval));
614: } else {
615: &setfilename($safeeval,$fn);
616: unless ($spreadsheets{$fn}) {
617: $spreadsheets{$fn}='';
618: my $reply=&Apache::lonnet::reply('dump:'.
619: $ENV{'course.'.$ENV{'request.course.id'}.'.domain'}.':'.
620: $ENV{'course.'.$ENV{'request.course.id'}.'.num'}.':'.$fn,
621: $ENV{'course.'.$ENV{'request.course.id'}.'.home'});
622: unless ($reply=~/^error\:/) {
623: $spreadsheets{$fn}=$reply;
624: }
1.10 www 625: }
1.19 www 626: map {
627: my ($name,$value)=split(/\=/,$_);
628: $f{&Apache::lonnet::unescape($name)}=
629: &Apache::lonnet::unescape($value);
630: } split(/\&/,$spreadsheets{$fn});
1.3 www 631: }
1.20 www 632:
1.5 www 633: &setformulas($safeeval,%f);
1.3 www 634: }
635:
1.19 www 636: # ------------------------------------------------------------ Save spreadsheet
637:
638: sub writesheet {
639: my $safeeval=shift;
640: if (&Apache::lonnet::allowed('opa',$ENV{'request.course.id'})) {
641: my %f=&getformulas($safeeval);
642: my $sheetdata='';
643: map {
644: $sheetdata.=&Apache::lonnet::escape($_).'='.
645: &Apache::lonnet::escape($f{$_}).'&';
646: } keys %f;
647: $sheetdata=~s/\&$//;
648: my $reply=&Apache::lonnet::reply('put:'.
649: $ENV{'course.'.$ENV{'request.course.id'}.'.domain'}.':'.
650: $ENV{'course.'.$ENV{'request.course.id'}.'.num'}.':'.
651: &getfilename($safeeval).':'.
652: $sheetdata,
653: $ENV{'course.'.$ENV{'request.course.id'}.'.home'});
1.22 www 654: if ($reply eq 'ok') {
655: return &Apache::lonnet::reply('put:'.
656: $ENV{'course.'.$ENV{'request.course.id'}.'.domain'}.':'.
657: $ENV{'course.'.$ENV{'request.course.id'}.'.num'}.':'.
658: &gettype($safeeval).'_spreadsheets:'.
659: &Apache::lonnet::escape(&getfilename($safeeval)).'='.
660: $ENV{'user.name'},
661: $ENV{'course.'.$ENV{'request.course.id'}.'.home'});
662: } else {
663: return $reply;
664: }
665: }
666: return 'unauthorized';
1.19 www 667: }
668:
1.10 www 669: # ----------------------------------------------- Make a temp copy of the sheet
670:
671: sub tmpwrite {
1.11 www 672: my ($safeeval,$tmpdir,$symb)=@_;
1.21 www 673: my $fn=$uname.'_'.$udom.'_spreadsheet_'.$symb.'_'.&getfilename($safeeval);
1.10 www 674: $fn=~s/\W/\_/g;
675: $fn=$tmpdir.$fn.'.tmp';
676: my $fh;
677: if ($fh=Apache::File->new('>'.$fn)) {
678: print $fh join("\n",&getformulas($safeeval));
679: }
680: }
681:
682: # ---------------------------------------------------------- Read the temp copy
683:
684: sub tmpread {
1.11 www 685: my ($safeeval,$tmpdir,$symb,$nfield,$nform)=@_;
1.21 www 686: my $fn=$uname.'_'.$udom.'_spreadsheet_'.$symb.'_'.&getfilename($safeeval);
1.10 www 687: $fn=~s/\W/\_/g;
688: $fn=$tmpdir.$fn.'.tmp';
689: my $fh;
690: my %fo=();
691: if ($fh=Apache::File->new($fn)) {
692: my $name;
693: while ($name=<$fh>) {
694: chomp($name);
695: my $value=<$fh>;
696: chomp($value);
697: $fo{$name}=$value;
698: }
699: }
1.22 www 700: if ($nfield) { $fo{$nfield}=$nform; }
1.10 www 701: &setformulas($safeeval,%fo);
702: }
703:
1.3 www 704: # --------------------------------------------------------------- Read metadata
705:
706: sub readmeta {
707: my $fn=shift;
708: unless ($fn=~/\.meta$/) { $fn.='meta'; }
709: my $content;
710: my %returnhash=();
711: {
712: my $fh=Apache::File->new($fn);
713: $content=join('',<$fh>);
714: }
715: my $parser=HTML::TokeParser->new(\$content);
716: my $token;
717: while ($token=$parser->get_token) {
718: if ($token->[0] eq 'S') {
719: my $entry=$token->[1];
720: if (($entry eq 'stores') || ($entry eq 'parameter')) {
721: my $unikey=$entry;
722: $unikey.='_'.$token->[2]->{'part'};
723: $unikey.='_'.$token->[2]->{'name'};
724: $returnhash{$unikey}=$token->[2]->{'display'};
725: }
726: }
727: }
728: return %returnhash;
729: }
730:
1.11 www 731: # ================================================================== Parameters
732: # -------------------------------------------- Figure out a cascading parameter
733:
734: sub parmval {
735: my ($what,$symb)=@_;
736:
737: unless ($symb) { return ''; }
738: my $result='';
739:
740: my ($mapname,$id,$fn)=split(/\_\_\_/,$symb);
741: # ----------------------------------------------------- Cascading lookup scheme
1.12 www 742: my $rwhat=$what;
743: $what=~s/^parameter\_//;
744: $what=~s/\_/\./;
1.11 www 745:
746: my $symbparm=$symb.'.'.$what;
747: my $mapparm=$mapname.'___(all).'.$what;
748:
749: my $seclevel=
750: $ENV{'request.course.id'}.'.['.
751: $csec.'].'.$what;
752: my $seclevelr=
753: $ENV{'request.course.id'}.'.['.
754: $csec.'].'.$symbparm;
755: my $seclevelm=
756: $ENV{'request.course.id'}.'.['.
757: $csec.'].'.$mapparm;
758:
759: my $courselevel=
760: $ENV{'request.course.id'}.'.'.$what;
761: my $courselevelr=
762: $ENV{'request.course.id'}.'.'.$symbparm;
763: my $courselevelm=
764: $ENV{'request.course.id'}.'.'.$mapparm;
1.12 www 765:
1.11 www 766: # ---------------------------------------------------------- fourth, check user
767:
768: if ($uname) {
769:
770: if ($useropt{$courselevelr}) { return $useropt{$courselevelr}; }
771:
772: if ($useropt{$courselevelm}) { return $useropt{$courselevelm}; }
773:
774: if ($useropt{$courselevel}) { return $useropt{$courselevel}; }
775:
776: }
777:
778: # --------------------------------------------------------- third, check course
779:
780: if ($csec) {
781:
782: if ($courseopt{$seclevelr}) { return $courseopt{$seclevelr}; }
783:
784: if ($courseopt{$seclevelm}) { return $courseopt{$seclevelm}; }
785:
786: if ($courseopt{$seclevel}) { return $courseopt{$seclevel}; }
787:
788: }
789:
790: if ($courseopt{$courselevelr}) { return $courseopt{$courselevelr}; }
791:
792: if ($courseopt{$courselevelm}) { return $courseopt{$courselevelm}; }
793:
794: if ($courseopt{$courselevel}) { return $courseopt{$courselevel}; }
795:
796: # ----------------------------------------------------- second, check map parms
797:
798: my $thisparm=$parmhash{$symbparm};
799: if ($thisparm) { return $thisparm; }
800:
801: # -------------------------------------------------------- first, check default
802:
1.12 www 803: return &Apache::lonnet::metadata($fn,$rwhat.'.default');
1.11 www 804:
805: }
806:
1.23 ! www 807: # ---------------------------------------------- Update rows for course listing
1.11 www 808:
1.23 ! www 809: sub updatestudentrows {
! 810: my $safeeval=shift;
! 811: my $cid=$ENV{'request.course.id'};
! 812: my $classlst=&Apache::lonnet::reply
! 813: ('dump:'.$ENV{'course.'.$cid.'.domain'}.':'.
! 814: $ENV{'course.'.$cid.'.num'}.':classlist',
! 815: $ENV{'course.'.$cid.'.home'});
! 816: my %currentlist=();
! 817: my $now=time;
! 818: unless ($classlst=~/^error\:/) {
! 819: map {
! 820: my ($name,$value)=split(/\=/,$_);
! 821: my ($end,$start)=split(/\_/,&Apache::lonnet::unescape($value));
! 822: my $active=1;
! 823: if (($end) && ($now>$end)) { $active=0; }
! 824: if ($active) {
! 825: $currentlist{&Apache::lonnet::unescape($name)}=1;
! 826: }
! 827: } split(/\&/,$classlst);
! 828: #
! 829: # -------------------- Find discrepancies between the course row table and this
! 830: #
! 831: my %f=&getformulas($safeeval);
! 832: my $changed=0;
! 833:
! 834: my $maxrow=0;
! 835: my %existing=();
! 836:
! 837: # ----------------------------------------------------------- Now obsolete rows
! 838: map {
! 839: if ($_=~/^A(\d+)/) {
! 840: $maxrow=($1>$maxrow)?$1:$maxrow;
! 841: $existing{$f{$_}}=1;
! 842: unless ((defined($currentlist{$f{$_}})) || (!$1)) {
! 843: $f{$_}='!!! Obsolete';
! 844: $changed=1;
! 845: }
! 846: }
! 847: } keys %f;
! 848:
! 849: # -------------------------------------------------------- New and unknown keys
! 850:
! 851: map {
! 852: unless ($existing{$_}) {
! 853: $changed=1;
! 854: $maxrow++;
! 855: $f{'A'.$maxrow}=$_;
! 856: }
! 857: } keys %currentlist;
! 858:
! 859: if ($changed) { &setformulas($safeeval,%f); }
! 860:
! 861: &setmaxrow($safeeval,$maxrow);
! 862: &setrowlabels($safeeval,%currentlist);
! 863:
! 864: } else {
! 865: return 'Could not access course data';
! 866: }
! 867: }
1.5 www 868: # ----------------------------------------------------------------- Update rows
869:
870: sub updaterows {
871: my $safeeval=shift;
872: my %bighash;
873: # -------------------------------------------------------------------- Tie hash
874: if (tie(%bighash,'GDBM_File',$ENV{'request.course.fn'}.'.db',
875: &GDBM_READER,0640)) {
876: # --------------------------------------------------------- Get all assessments
877:
878: my %allkeys=();
879: my %allassess=();
880:
881: my $stype=&gettype($safeeval);
882:
883: map {
884: if ($_=~/^src\_(\d+)\.(\d+)$/) {
885: my $mapid=$1;
886: my $resid=$2;
887: my $id=$mapid.'.'.$resid;
888: my $srcf=$bighash{$_};
889: if ($srcf=~/\.(problem|exam|quiz|assess|survey|form)$/) {
890: my $symb=
891: &Apache::lonnet::declutter($bighash{'map_id_'.$mapid}).
892: '___'.$resid.'___'.
893: &Apache::lonnet::declutter($srcf);
894: $allassess{$symb}=$bighash{'title_'.$id};
1.8 www 895:
1.6 www 896: if ($stype eq 'assesscalc') {
1.5 www 897: map {
1.11 www 898: if (($_=~/^stores\_(.*)/) || ($_=~/^parameter\_(.*)/)) {
1.5 www 899: my $key=$_;
900: my $display=
901: &Apache::lonnet::metadata($srcf,$key.'.display');
902: unless ($display) {
903: $display=
904: &Apache::lonnet::metadata($srcf,$key.'.name');
905: }
906: $allkeys{$key}=$display;
907: }
908: } split(/\,/,&Apache::lonnet::metadata($srcf,'keys'));
909: }
910: }
911: }
912: } keys %bighash;
913: untie(%bighash);
914:
915: #
1.11 www 916: # %allkeys has a list of storage and parameter displays by unikey
1.5 www 917: # %allassess has a list of all resource displays by symb
918: #
919: # -------------------- Find discrepancies between the course row table and this
920: #
921: my %f=&getformulas($safeeval);
1.6 www 922: my $changed=0;
923:
924: my %current=();
925: if ($stype eq 'assesscalc') {
926: %current=%allkeys;
927: } elsif ($stype eq 'studentcalc') {
928: %current=%allassess;
929: }
930:
931: my $maxrow=0;
932: my %existing=();
933:
934: # ----------------------------------------------------------- Now obsolete rows
1.5 www 935: map {
1.6 www 936: if ($_=~/^A(\d+)/) {
937: $maxrow=($1>$maxrow)?$1:$maxrow;
938: $existing{$f{$_}}=1;
1.17 www 939: unless ((defined($current{$f{$_}})) || (!$1)) {
1.6 www 940: $f{$_}='!!! Obsolete';
941: $changed=1;
1.5 www 942: }
943: }
944: } keys %f;
1.6 www 945:
946: # -------------------------------------------------------- New and unknown keys
947:
948: map {
949: unless ($existing{$_}) {
950: $changed=1;
951: $maxrow++;
952: $f{'A'.$maxrow}=$_;
953: }
954: } keys %current;
955:
956: if ($changed) { &setformulas($safeeval,%f); }
957:
958: &setmaxrow($safeeval,$maxrow);
959: &setrowlabels($safeeval,%current);
1.5 www 960:
961: } else {
962: return 'Could not access course data';
963: }
964: }
1.3 www 965:
1.16 www 966: # --------------------------------------------------- Load data for one student
967:
968: sub rowazstudent {
969: my $safeeval=shift;
970: my %c=();
971: my %f=&getformulas($safeeval);
972: map {
1.17 www 973: if ($_=~/^A(\d+)/) {
974: my $row=$1;
1.16 www 975: unless ($f{$_}=~/^\!/) {
1.18 www 976: my @assessdata=split(/\_\_\_\;\_\_\_/,
1.17 www 977: &Apache::lonnet::ssi(
1.16 www 978: '/res/msu/korte/junk.assesscalc',('utarget' => 'export',
979: 'uname' => $uname,
980: 'udom' => $udom,
1.17 www 981: 'usymb' => $f{$_})));
982: my $index=0;
983: map {
1.18 www 984: if ($assessdata[$index]) {
985: $c{$_.$row}=$assessdata[$index];
986: unless ($_ eq 'A') {
987: $f{$_.$row}='import';
988: }
989: }
1.17 www 990: $index++;
991: } ('A','B','C','D','E','F','G','H','I','J','K','L','M',
992: 'N','O','P','Q','R','S','T','U','V','W','X','Y','Z');
1.16 www 993: }
994: }
995: } keys %f;
1.18 www 996: &setformulas($safeeval,%f);
1.16 www 997: &setconstants($safeeval,%c);
998: }
999:
1.6 www 1000: # ------------------------------------------------ Load data for one assessment
1001:
1002: sub rowaassess {
1.11 www 1003: my ($safeeval,$symb)=@_;
1.6 www 1004: my $uhome=&Apache::lonnet::homeserver($uname,$udom);
1005: my $namespace;
1006: unless ($namespace=$ENV{'request.course.id'}) { return ''; }
1.11 www 1007:
1008: # ----------------------------------------------------------- Get stored values
1009: my $answer=&Apache::lonnet::reply(
1.15 www 1010: "restore:$udom:$uname:".
1011: &Apache::lonnet::escape($namespace).":".
1012: &Apache::lonnet::escape($symb),$uhome);
1.6 www 1013: my %returnhash=();
1014: map {
1015: my ($name,$value)=split(/\=/,$_);
1.11 www 1016: $returnhash{&Apache::lonnet::unescape($name)}=
1017: &Apache::lonnet::unescape($value);
1.6 www 1018: } split(/\&/,$answer);
1019: my $version;
1020: for ($version=1;$version<=$returnhash{'version'};$version++) {
1021: map {
1022: $returnhash{$_}=$returnhash{$version.':'.$_};
1023: } split(/\:/,$returnhash{$version.':keys'});
1024: }
1.11 www 1025: # ----------------------------- returnhash now has all stores for this resource
1026:
1027: # ---------------------------- initialize coursedata and userdata for this user
1028: %courseopt=();
1029: %useropt=();
1030: my $uhome=&Apache::lonnet::homeserver($uname,$udom);
1031: unless ($uhome eq 'no_host') {
1032: # -------------------------------------------------------------- Get coursedata
1.13 www 1033: unless
1034: ((time-$courserdatas{$ENV{'request.course.id'}.'.last_cache'})<120) {
1.11 www 1035: my $reply=&Apache::lonnet::reply('dump:'.
1036: $ENV{'course.'.$ENV{'request.course.id'}.'.domain'}.':'.
1037: $ENV{'course.'.$ENV{'request.course.id'}.'.num'}.':resourcedata',
1038: $ENV{'course.'.$ENV{'request.course.id'}.'.home'});
1039: if ($reply!~/^error\:/) {
1040: $courserdatas{$ENV{'request.course.id'}}=$reply;
1.13 www 1041: $courserdatas{$ENV{'request.course.id'}.'.last_cache'}=time;
1.11 www 1042: }
1043: }
1044: map {
1045: my ($name,$value)=split(/\=/,$_);
1046: $courseopt{&Apache::lonnet::unescape($name)}=
1047: &Apache::lonnet::unescape($value);
1048: } split(/\&/,$courserdatas{$ENV{'request.course.id'}});
1049: # --------------------------------------------------- Get userdata (if present)
1.13 www 1050: unless
1051: ((time-$userrdatas{$uname.'___'.$udom.'.last_cache'})<120) {
1.11 www 1052: my $reply=
1053: &Apache::lonnet::reply('dump:'.$udom.':'.$uname.':resourcedata',$uhome);
1054: if ($reply!~/^error\:/) {
1055: $userrdatas{$uname.'___'.$udom}=$reply;
1.13 www 1056: $userrdatas{$uname.'___'.$udom.'.last_cache'}=time;
1.11 www 1057: }
1058: }
1059: map {
1060: my ($name,$value)=split(/\=/,$_);
1061: $useropt{&Apache::lonnet::unescape($name)}=
1.15 www 1062: &Apache::lonnet::unescape($value);
1.11 www 1063: } split(/\&/,$userrdatas{$uname.'___'.$udom});
1064: }
1065: # -- now courseopt, useropt initialized for this user and course (used parmval)
1.6 www 1066:
1067: my %c=();
1068: my %f=&getformulas($safeeval);
1069: map {
1070: if ($_=~/^A/) {
1071: unless ($f{$_}=~/^\!/) {
1.11 www 1072: if ($f{$_}=~/^parameter/) {
1073: $c{$_}=&parmval($f{$_},$symb);
1074: } else {
1.15 www 1075: my $key=$f{$_};
1076: $key=~s/^stores\_/resource\./;
1077: $key=~s/\_/\./;
1078: $c{$_}=$returnhash{$key};
1.11 www 1079: }
1080: }
1.6 www 1081: }
1082: } keys %f;
1.11 www 1083:
1.6 www 1084: &setconstants($safeeval,%c);
1085: }
1086:
1.10 www 1087: # --------------------------------------------------------- Various form fields
1088:
1089: sub textfield {
1090: my ($title,$name,$value)=@_;
1091: return "\n<p><b>$title:</b><br>".
1092: '<input type=text name="'.$name.'" size=80 value="'.$value.'">';
1093: }
1094:
1095: sub hiddenfield {
1096: my ($name,$value)=@_;
1097: return "\n".'<input type=hidden name="'.$name.'" value="'.$value.'">';
1098: }
1099:
1100: sub selectbox {
1101: my ($title,$name,$value,%options)=@_;
1102: my $selout="\n<p><b>$title:</b><br>".'<select name="'.$name.'">';
1103: map {
1104: $selout.='<option value="'.$_.'"';
1105: if ($_ eq $value) { $selout.=' selected'; }
1106: $selout.='>'.$options{$_}.'</option>';
1107: } sort keys %options;
1108: return $selout.'</select>';
1109: }
1110:
1.12 www 1111: # ================================================================ Main handler
1.3 www 1112:
1113: sub handler {
1.7 www 1114: my $r=shift;
1115:
1.11 www 1116: $uname='';
1117: $udom='';
1118: $csec='';
1119:
1.7 www 1120: if ($r->header_only) {
1121: $r->content_type('text/html');
1122: $r->send_http_header;
1123: return OK;
1124: }
1.3 www 1125:
1.7 www 1126: # ----------------------------------------------------- Needs to be in a course
1.3 www 1127:
1.7 www 1128: if (($ENV{'request.course.fn'}) ||
1129: ($ENV{'request.state'} eq 'construct')) {
1.10 www 1130:
1131: # --------------------------- Get query string for limited number of parameters
1.17 www 1132:
1.10 www 1133: map {
1134: my ($name, $value) = split(/=/,$_);
1135: $value =~ tr/+/ /;
1136: $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
1.19 www 1137: if (($name eq 'uname') || ($name eq 'udom') ||
1138: ($name eq 'usymb') || ($name eq 'ufn')) {
1.10 www 1139: unless ($ENV{'form.'.$name}) {
1140: $ENV{'form.'.$name}=$value;
1141: }
1142: }
1143: } (split(/&/,$ENV{'QUERY_STRING'}));
1144:
1145: # ------------------------------------------- Nothing there? Must be login user
1146: unless ($ENV{'form.uname'}) {
1.11 www 1147: $uname=$ENV{'user.name'};
1148: $udom=$ENV{'user.domain'};
1149: } else {
1150: $uname=$ENV{'form.uname'};
1151: $udom=$ENV{'form.udom'};
1.10 www 1152: }
1.14 www 1153: # ----------------------------------------------------------- Change of target?
1154:
1.16 www 1155: my $reroute=($ENV{'form.utarget'} eq 'export');
1.14 www 1156:
1.10 www 1157: # ------------------------------------------------------------------- Open page
1158:
1.7 www 1159: $r->content_type('text/html');
1.11 www 1160: $r->header_out('Cache-control','no-cache');
1161: $r->header_out('Pragma','no-cache');
1.7 www 1162: $r->send_http_header;
1.3 www 1163:
1.14 www 1164: # --------------------------------------------------------------- Screen output
1165:
1166: unless ($reroute) {
1.10 www 1167: $r->print('<html><head><title>LON-CAPA Spreadsheet</title>');
1168: $r->print(<<ENDSCRIPT);
1169: <script language="JavaScript">
1170:
1171: function celledit(cn,cf) {
1172: var cnf=prompt(cn,cf);
1173: if (cnf!=null) {
1174: document.sheet.unewfield.value=cn;
1175: document.sheet.unewformula.value=cnf;
1176: document.sheet.submit();
1177: }
1178: }
1179:
1180: </script>
1181: ENDSCRIPT
1182: $r->print('</head><body bgcolor="#FFFFFF">'.
1.21 www 1183: '<img align=right src=/adm/lonIcons/lonlogos.gif>'.
1184: '<h1>LON-CAPA Spreadsheet</h1>'.
1.10 www 1185: '<form action="'.$r->uri.'" name=sheet method=post>'.
1186: &hiddenfield('uname',$ENV{'form.uname'}).
1187: &hiddenfield('udom',$ENV{'form.udom'}).
1188: &hiddenfield('usymb',$ENV{'form.usymb'}).
1189: &hiddenfield('unewfield','').
1190: &hiddenfield('unewformula',''));
1.14 www 1191: }
1192:
1193: # ---------------------------------------- Read new sheet or modified worksheet
1194:
1.4 www 1195: my $sheetone=initsheet();
1.19 www 1196: $r->uri=~/\/(\w+)$/;
1197: &settype($sheetone,$1);
1.10 www 1198: if ($ENV{'form.unewfield'}) {
1199: $r->print('<h2>Modified Workcopy</h2>');
1200: $ENV{'form.unewformula'}=~s/\'/\"/g;
1.22 www 1201: $r->print('<p>New formula: '.$ENV{'form.unewfield'}.'='.
1202: $ENV{'form.unewformula'}.'<p>');
1.19 www 1203: &setfilename($sheetone,$ENV{'form.ufn'});
1.10 www 1204: &tmpread($sheetone,$r->dir_config('lonDaemons').'/tmp/',
1.11 www 1205: $ENV{'form.usymb'},
1.10 www 1206: $ENV{'form.unewfield'},$ENV{'form.unewformula'});
1.22 www 1207: } elsif ($ENV{'form.saveas'}) {
1208: &setfilename($sheetone,$ENV{'form.ufn'});
1209: &tmpread($sheetone,$r->dir_config('lonDaemons').'/tmp/',
1210: $ENV{'form.usymb'});
1.11 www 1211: } else {
1.19 www 1212: &readsheet($sheetone,$ENV{'form.ufn'},$r);
1.21 www 1213: $ENV{'form.ufn'}=&getfilename($sheetone);
1.11 www 1214: }
1.14 www 1215:
1.23 ! www 1216: if (&gettype($sheetone) eq 'classcalc') {
! 1217: # ---------------------------------- For course view: get courselist and update
! 1218: &updatestudentrows($sheetone);
! 1219: } else {
! 1220: # ----------------- For assessment and student: See if all import rows uptodate
1.14 www 1221:
1.11 www 1222: if (tie(%parmhash,'GDBM_File',
1223: $ENV{'request.course.fn'}.'_parms.db',&GDBM_READER,0640)) {
1224: $csec=&Apache::lonnet::usection($udom,$uname,$ENV{'request.course.id'});
1225: if ($csec eq '-1') {
1226: $r->print('<h3><font color=red>'.
1227: "User '$uname' at domain '$udom' not a student in this course</font></h3>");
1228: }
1229: &updaterows($sheetone);
1230: untie(%parmhash);
1.10 www 1231: } else {
1.11 www 1232: $r->print('<h3><font color=red>'.
1233: 'Could not initialize import fields (not in a course)</font></h3>');
1234: }
1.23 ! www 1235: }
1.22 www 1236: # ---------------------------------------------------- See if something to save
1237: if (&Apache::lonnet::allowed('opa',$ENV{'request.course.id'})) {
1238: my $fname='';
1239: if ($ENV{'form.saveas'} && ($fname=$ENV{'form.newfn'})) {
1240: $fname=~s/\W/\_/g;
1241: if ($fname eq 'default') { $fname='course_default'; }
1242: $fname.='_'.&gettype($sheetone);
1243: &setfilename($sheetone,$fname);
1244: $ENV{'form.ufn'}=$fname;
1245: my $reply=&writesheet($sheetone);
1246: unless ($reroute) {
1247: $r->print('<p>Saving spreadsheet: '.$reply.'<p>');
1248: }
1249: }
1250: }
1.14 www 1251: # ------------------------------------------------ Write the modified worksheet
1252:
1.11 www 1253: &tmpwrite($sheetone,$r->dir_config('lonDaemons').'/tmp/',
1254: $ENV{'form.usymb'});
1.14 www 1255:
1256: # ----------------------------------------------------- Print user, course, etc
1257: unless ($reroute) {
1.22 www 1258: if (&Apache::lonnet::allowed('opa',$ENV{'request.course.id'})) {
1259: my $fname=$ENV{'form.ufn'};
1260: $fname=~s/\_[^\_]+$//;
1261: if ($fname eq 'default') { $fname='course_default'; }
1262: $r->print('<input type=submit name=saveas value="Save as ...">'.
1263: '<input type=text size=20 name=newfn value="'.$fname.'"><p>');
1264: }
1.23 ! www 1265: $r->print(&hiddenfield('ufn',$ENV{'form.ufn'}));
! 1266: unless (&gettype($sheetone) eq 'classcalc') {
! 1267: $r->print('<br><b>User:</b> '.$uname.'<br><b>Domain:</b> '.$udom);
! 1268: }
! 1269: $r->print('<h1>'.
! 1270: $ENV{'course.'.$ENV{'request.course.id'}.'.description'}.'</h1>');
1.11 www 1271: if ($csec) {
1.23 ! www 1272: $r->print('<h3>Group/Section: '.$csec.'</h3>');
1.11 www 1273: }
1.14 www 1274: }
1275: # -------------------------------------------------------- Import and calculate
1276:
1.11 www 1277: if (&gettype($sheetone) eq 'assesscalc') {
1278: &rowaassess($sheetone,$ENV{'form.usymb'});
1.16 www 1279: } elsif (&gettype($sheetone) eq 'studentcalc') {
1280: &rowazstudent($sheetone);
1.10 www 1281: }
1.18 www 1282: my $calcoutput=&calcsheet($sheetone);
1283: unless ($reroute) {
1284: $r->print('<h3><font color=red>'.$calcoutput.'</h3></font>');
1285: }
1.14 www 1286:
1287: # ------------------------------------------------------- Print or export sheet
1288: unless ($reroute) {
1.6 www 1289: $r->print(&outsheet($sheetone));
1.8 www 1290:
1.10 www 1291: $r->print('</form></body></html>');
1.14 www 1292: } else {
1.18 www 1293: $r->print(&exportrow($sheetone));
1.14 www 1294: }
1295: # ------------------------------------------------------------------------ Done
1.7 www 1296: } else {
1297: # ----------------------------- Not in a course, or not allowed to modify parms
1298: $ENV{'user.error.msg'}=
1299: $r->uri.":opa:0:0:Cannot modify spreadsheet";
1300: return HTTP_NOT_ACCEPTABLE;
1301: }
1.3 www 1302: return OK;
1.1 www 1303: }
1304:
1305: 1;
1306: __END__
1307:
1308:
1309:
1310:
1311:
1312:
1313:
1314:
1315:
1316:
1317:
1318:
1319:
1320:
1321:
1322:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>