File:
[LON-CAPA] /
loncom /
interface /
Attic /
lonchart.pm
Revision
1.53:
download - view:
text,
annotated -
select for diffs
Tue Jul 2 22:06:53 2002 UTC (23 years ago) by
stredwic
Branches:
MAIN
CVS tags:
HEAD
There was a problem where the offsets of the checkboxs above the columns
were not the same between Mozilla and Netscape. Mozilla's strayed way
far from their columns. To remedy this, I put the check boxes and the
column headers into a table. The current position for the check boxes
is center. It is almost center in both Netscape and Mozilla, but are definitely
above their respective columns. Left justified may look better, it puts
the checkbox directly above the first character of the header. This can
be changed. I had originally had the checkboxes centered and looks good
someplaces and only ok others. For now, I left it centered.
1: # The LearningOnline Network with CAPA
2: # (Publication Handler
3: #
4: # $Id: lonchart.pm,v 1.53 2002/07/02 22:06:53 stredwic Exp $
5: #
6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23: #
24: # /home/httpd/html/adm/gpl.txt
25: #
26: # http://www.lon-capa.org/
27: #
28: # Homework Performance Chart
29: #
30: # (Navigate Maps Handler
31: #
32: # (Page Handler
33: #
34: # (TeX Content Handler
35: # YEAR=2000
36: # 05/29/00,05/30 Gerd Kortemeyer)
37: # 08/30,08/31,09/06,09/14,09/15,09/16,09/19,09/20,09/21,09/23,
38: # 10/02,10/10,10/14,10/16,10/18,10/19,10/31,11/6,11/14,11/16 Gerd Kortemeyer)
39: # YEAR=2001
40: # 3/1/1,6/1,17/1,29/1,30/1,31/1 Gerd Kortemeyer)
41: # 7/10/01 Behrouz Minaei
42: # 9/8 Gerd Kortemeyer
43: # 10/1, 10/19, 11/17, 11/22, 11/24, 11/28 12/18 Behrouz Minaei
44: # YEAR=2002
45: # 2/1, 2/6, 2/19, 2/28 Behrouz Minaei
46: #
47: ###
48:
49: =pod
50:
51: =cut
52:
53: package Apache::lonchart;
54:
55: use strict;
56: use Apache::Constants qw(:common :http);
57: use Apache::lonnet();
58: use Apache::loncommon();
59: use HTML::TokeParser;
60: use GDBM_File;
61:
62: #my $jr;
63: # ----- FORMAT PRINT DATA ----------------------------------------------
64:
65: sub FormatStudentInformation {
66: my ($cache,$name,$studentInformation,$spacePadding)=@_;
67: my $Str='';
68:
69: for(my $index=0; $index<(scalar @$studentInformation); $index++) {
70: if(!&ShouldShowColumn($cache, 'heading'.$index)) {
71: next;
72: }
73: my $data=$cache->{$name.':'.$studentInformation->[$index]};
74: $Str .= $data;
75:
76: my @dataLength=split(//,$data);
77: my $length=scalar @dataLength;
78: $Str .= (' 'x($cache->{$studentInformation->[$index].'Length'}-
79: $length));
80: $Str .= $spacePadding;
81: }
82:
83: return $Str;
84: }
85:
86: sub FormatStudentData {
87: my ($name,$coid,$studentInformation,$spacePadding,$ChartDB)=@_;
88: my ($sname,$sdom) = split(/\:/,$name);
89: my $Str;
90: my %CacheData;
91:
92: unless(tie(%CacheData,'GDBM_File',$ChartDB,&GDBM_READER,0640)) {
93: return '';
94: }
95: # Handle Student information ------------------------------------------
96: # Handle user data
97: $Str=&FormatStudentInformation(\%CacheData, $name, $studentInformation,
98: $spacePadding);
99:
100: # Handle errors
101: if($CacheData{$name.':error'} =~ /environment/) {
102: $Str .= '<br>';
103: untie(%CacheData);
104: return $Str;
105: }
106:
107: if($CacheData{$name.':error'} =~ /course/) {
108: $Str .= '<br>';
109: untie(%CacheData);
110: return $Str;
111: }
112:
113: # Handle problem data ------------------------------------------------
114: my $Version;
115: my $problemsCorrect = 0;
116: my $totalProblems = 0;
117: my $problemsSolved = 0;
118: my $numberOfParts = 0;
119: foreach my $sequence (split(/\:/,$CacheData{'orderedSequences'})) {
120: if(!&ShouldShowColumn(\%CacheData, 'sequence'.$sequence)) {
121: next;
122: }
123:
124: my $characterCount=0;
125: foreach my $problemID (split(/\:/,$CacheData{$sequence.':problems'})) {
126: my $problem = $CacheData{$problemID.':problem'};
127: my $LatestVersion = $CacheData{$name.":version:$problem"};
128:
129: if(!$LatestVersion) {
130: foreach my $part (split(/\:/,$CacheData{$sequence.':'.
131: $problemID.
132: ':parts'})) {
133: $Str .= ' ';
134: $totalProblems++;
135: $characterCount++;
136: }
137: next;
138: }
139:
140: my %partData=undef;
141: #initialize data, displays skips correctly
142: foreach my $part (split(/\:/,$CacheData{$sequence.':'.
143: $problemID.
144: ':parts'})) {
145: $partData{$part.':tries'}=0;
146: $partData{$part.':code'}=' ';
147: }
148: for(my $Version=1; $Version<=$LatestVersion; $Version++) {
149: foreach my $part (split(/\:/,$CacheData{$sequence.':'.
150: $problemID.
151: ':parts'})) {
152:
153: if(!defined($CacheData{$name.":$Version:$problem".
154: ":resource.$part.solved"})) {
155: next;
156: }
157:
158: my $tries=0;
159: my $code=' ';
160:
161: $tries = $CacheData{$name.":$Version:$problem".
162: ":resource.$part.tries"};
163: $partData{$part.':tries'}=($tries) ? $tries : 0;
164:
165: my $val = $CacheData{$name.":$Version:$problem".
166: ":resource.$part.solved"};
167: if ($val eq 'correct_by_student') {$code = '*';}
168: elsif ($val eq 'correct_by_override') {$code = '+';}
169: elsif ($val eq 'incorrect_attempted') {$code = '.';}
170: elsif ($val eq 'incorrect_by_override'){$code = '-';}
171: elsif ($val eq 'excused') {$code = 'x';}
172: elsif ($val eq 'ungraded_attempted') {$code = '#';}
173: else {$code = ' ';}
174: $partData{$part.':code'}=$code;
175: }
176: }
177:
178: $Str.='<a href="/adm/grades?symb='.
179: &Apache::lonnet::escape($problem).
180: '&student='.$sname.'&domain='.$sdom.'&command=submission">';
181: foreach(split(/\:/,$CacheData{$sequence.':'.$problemID.
182: ':parts'})) {
183: if($partData{$_.':code'} eq '*') {
184: $problemsCorrect++;
185: if (($partData{$_.':tries'}<10) &&
186: ($partData{$_.':tries'} ne '')) {
187: $partData{$_.':code'}=$partData{$_.':tries'};
188: }
189: } elsif($partData{$_.':code'} eq '+') {
190: $problemsCorrect++;
191: }
192:
193: $Str .= $partData{$_.':code'};
194: $characterCount++;
195:
196: if($partData{$_.':code'} ne 'x') {
197: $totalProblems++;
198: }
199: }
200: $Str.='</a>';
201: }
202:
203: my $spacesNeeded=$CacheData{$sequence.':columnWidth'}-$characterCount;
204: $spacesNeeded -= 3;
205: $Str .= (' 'x$spacesNeeded);
206:
207: my $outputProblemsCorrect = sprintf( "%3d", $problemsCorrect );
208: $Str .= '<font color="#007700">'.$outputProblemsCorrect.'</font>';
209: $problemsSolved += $problemsCorrect;
210: $problemsCorrect=0;
211:
212: $Str .= $spacePadding;
213: }
214:
215: my $outputProblemsSolved = sprintf( "%4d", $problemsSolved );
216: my $outputTotalProblems = sprintf( "%4d", $totalProblems );
217: $Str .= '<font color="#000088">'.$outputProblemsSolved.
218: ' / '.$outputTotalProblems.'</font><br>';
219:
220: untie(%CacheData);
221: return $Str;
222: }
223:
224: sub CreateTableHeadings {
225: my ($CacheData,$studentInformation,$headings,$spacePadding)=@_;
226: my $Str='<tr>';
227:
228: for(my $index=0; $index<(scalar @$headings); $index++) {
229: if(!&ShouldShowColumn($CacheData, 'heading'.$index)) {
230: next;
231: }
232:
233: $Str .= '<td align="left"><pre>';
234: my $data=$$headings[$index];
235: $Str .= $data;
236:
237: my @dataLength=split(//,$data);
238: my $length=scalar @dataLength;
239: $Str .= (' 'x($CacheData->{$$studentInformation[$index].'Length'}-
240: $length));
241: $Str .= $spacePadding;
242: $Str .= '</pre></td>';
243: }
244:
245: foreach my $sequence (split(/\:/,$CacheData->{'orderedSequences'})) {
246: if(!&ShouldShowColumn($CacheData, 'sequence'.$sequence)) {
247: next;
248: }
249:
250: $Str .= '<td align="left"><pre>';
251: my $name = $CacheData->{$sequence.':title'};
252: $Str .= $name;
253: my @titleLength=split(//,$CacheData->{$sequence.':title'});
254: my $leftover=$CacheData->{$sequence.':columnWidth'}-
255: (scalar @titleLength);
256: $Str .= (' 'x$leftover);
257: $Str .= $spacePadding;
258: $Str .= '</pre></td>';
259: }
260:
261: $Str .= '<td>Total Solved/Total Problems</td>';
262: $Str .= '</tr></tbody></table>';
263:
264: return $Str;
265: }
266:
267: sub CreateColumnSelectionBox {
268: my ($CacheData,$studentInformation,$headings,$spacePadding)=@_;
269:
270: my $missing=0;
271: my $notThere='<tr><td align="right"><b>Select column to view:</b>';
272: my $name;
273: $notThere .= '<td align="left">';
274: $notThere .= '<select name="reselect" size="4" multiple="true">'."\n";
275:
276: for(my $index=0; $index<(scalar @$headings); $index++) {
277: if(&ShouldShowColumn($CacheData, 'heading'.$index)) {
278: next;
279: }
280: $name = $headings->[$index];
281: $notThere .= '<option value="heading'.$index.'">';
282: $notThere .= $name.'</option>'."\n";
283: $missing++;
284: }
285:
286: foreach my $sequence (split(/\:/,$CacheData->{'orderedSequences'})) {
287: if(&ShouldShowColumn($CacheData, 'sequence'.$sequence)) {
288: next;
289: }
290: $name = $CacheData->{$sequence.':title'};
291: $notThere .= '<option value="sequence'.$sequence.'">';
292: $notThere .= $name.'</option>'."\n";
293: $missing++;
294: }
295:
296: if($missing) {
297: $notThere .= '</select>';
298: } else {
299: $notThere='<tr><td>';
300: }
301:
302: return $notThere.'</td></tr></tbody></table>';
303: }
304:
305: sub CreateColumnSelectors {
306: my ($CacheData,$studentInformation,$headings,$spacePadding)=@_;
307:
308: my $found=0;
309: my ($name, $length, $position);
310: my $present='<table border="0" cellpadding="0" cellspacing="0">';
311: $present .= '</tbody><tr>';
312: for(my $index=0; $index<(scalar @$headings); $index++) {
313: if(!&ShouldShowColumn($CacheData, 'heading'.$index)) {
314: next;
315: }
316: $present .= '<td align="center">';
317: $name = $headings->[$index];
318: $present .= '<input type="checkbox" checked="on" ';
319: $present .= 'name="heading'.$index.'">';
320: $present .= '</td>';
321: $found++;
322: }
323:
324: foreach my $sequence (split(/\:/,$CacheData->{'orderedSequences'})) {
325: if(!&ShouldShowColumn($CacheData, 'sequence'.$sequence)) {
326: next;
327: }
328: $present .= '<td align="center">';
329: $name = $CacheData->{$sequence.':title'};
330: $present .= '<input type="checkbox" checked="on" ';
331: $present .= 'name="sequence'.$sequence.'">';
332: $present .= '</td>';
333: $found++;
334: }
335:
336: if($found) {
337: $present = $present;
338: } else {
339: $present = '<td></td>';
340: }
341:
342: return $present.'</tr></form>'."\n";;
343: }
344:
345: sub CreateForm {
346: my ($CacheData)=@_;
347: my $OpSel1='';
348: my $OpSel2='';
349: my $OpSel3='';
350: my $Status = $CacheData->{'form.status'};
351: if ( $Status eq 'Any' ) { $OpSel3='selected'; }
352: elsif ($Status eq 'Expired' ) { $OpSel2 = 'selected'; }
353: else { $OpSel1 = 'selected'; }
354:
355: my $Ptr .= '<form name="stat" method="post" action="/adm/chart" >'."\n";
356: $Ptr .= '<table border="0"><tbody>';
357: $Ptr .= '<tr><td align="right">';
358: $Ptr .= '</td><td align="left">';
359: $Ptr .= '<input type="submit" name="recalculate" ';
360: $Ptr .= 'value="Recalculate Chart"/>'."\n";
361: $Ptr .= ' ';
362: $Ptr .= '<input type="submit" name="refresh" ';
363: $Ptr .= 'value="Refresh Chart"/>'."\n";
364: $Ptr .= ' ';
365: $Ptr .= '<input type="submit" name="reset" ';
366: $Ptr .= 'value="Reset Selections"/></td>'."\n";
367: $Ptr .= '</tr><tr><td align="right">';
368: $Ptr .= '<b> Sort by: </b>'."\n";
369: $Ptr .= '</td><td align="left">';
370: $Ptr .= '<input type="submit" name="sort" value="User Name" />'."\n";
371: $Ptr .= ' ';
372: $Ptr .= '<input type="submit" name="sort" value="Last Name" />'."\n";
373: $Ptr .= ' ';
374: $Ptr .= '<input type="submit" name="sort" value="Section"/>'."\n";
375: $Ptr .= '</td></tr><tr><td align="right">';
376: $Ptr .= '<b> Student Status: </b>'."\n".
377: '</td><td align="left">'.
378: '<select name="status">'.
379: '<option '.$OpSel1.' >Active</option>'."\n".
380: '<option '.$OpSel2.' >Expired</option>'."\n".
381: '<option '.$OpSel3.' >Any</option> </select> '."\n";
382: $Ptr .= '</td></tr>';
383:
384: return $Ptr;
385: }
386:
387: sub CreateLegend {
388: my $Str = "<p><pre>".
389: "1..9: correct by student in 1..9 tries\n".
390: " *: correct by student in more than 9 tries\n".
391: " +: correct by override\n".
392: " -: incorrect by override\n".
393: " .: incorrect attempted\n".
394: " #: ungraded attempted\n".
395: " : not attempted\n".
396: " x: excused".
397: "</pre><p>";
398: return $Str;
399: }
400:
401: sub StartDocument {
402: my $Str = '';
403: $Str .= '<html>';
404: $Str .= '<head><title>';
405: $Str .= 'LON-CAPA Assessment Chart</title></head>';
406: $Str .= '<body bgcolor="#FFFFFF">';
407: $Str .= '<script>window.focus();</script>';
408: $Str .= '<img align=right src=/adm/lonIcons/lonlogos.gif>';
409: $Str .= '<h1>Assessment Chart</h1>';
410: $Str .= '<h3>'.localtime().'</h3>';
411: $Str .= '<h1>'.$ENV{'course.'.$ENV{'request.course.id'}.'.description'};
412: $Str .= '</h1>';
413:
414: return $Str;
415: }
416:
417: # ----- END FORMAT PRINT DATA ------------------------------------------
418:
419: # ----- DOWNLOAD INFORMATION -------------------------------------------
420:
421: sub DownloadPrerequisiteData {
422: my ($courseID, $c)=@_;
423: my ($courseDomain,$courseNumber)=split(/\_/,$courseID);
424:
425: my %classlist=&Apache::lonnet::dump('classlist',$courseDomain,
426: $courseNumber);
427: my ($checkForError)=keys (%classlist);
428: if($checkForError =~ /^(con_lost|error|no_such_host)/i) {
429: return \%classlist;
430: }
431:
432: foreach my $name (keys(%classlist)) {
433: if($c->aborted()) {
434: $classlist{'error'}='aborted';
435: return \%classlist;
436: }
437:
438: my ($studentName,$studentDomain) = split(/\:/,$name);
439: # Download student environment data, specifically the full name and id.
440: my %studentInformation=&Apache::lonnet::get('environment',
441: ['lastname','generation',
442: 'firstname','middlename',
443: 'id'],
444: $studentDomain,
445: $studentName);
446: $classlist{$name.':studentInformation'}=\%studentInformation;
447:
448: if($c->aborted()) {
449: $classlist{'error'}='aborted';
450: return \%classlist;
451: }
452:
453: #Section
454: my %section=&Apache::lonnet::dump('roles',$studentDomain,$studentName);
455: $classlist{$name.':section'}=\%section;
456: }
457:
458: return \%classlist;
459: }
460:
461: sub DownloadStudentCourseInformation {
462: my ($name,$courseID)=@_;
463: my ($studentName,$studentDomain) = split(/\:/,$name);
464:
465: # Download student course data
466: my %courseData=&Apache::lonnet::dump($courseID,$studentDomain,
467: $studentName);
468: return \%courseData;
469: }
470:
471: # ----- END DOWNLOAD INFORMATION ---------------------------------------
472:
473: # ----- END PROCESSING FUNCTIONS ---------------------------------------
474:
475: sub ProcessTopResourceMap {
476: my ($ChartDB,$c)=@_;
477: my %hash;
478: my $fn=$ENV{'request.course.fn'};
479: if(-e "$fn.db") {
480: my $tieTries=0;
481: while($tieTries < 3) {
482: if(tie(%hash,'GDBM_File',"$fn.db",&GDBM_READER,0640)) {
483: last;
484: }
485: $tieTries++;
486: sleep 1;
487: }
488: if($tieTries >= 3) {
489: return 'Coursemap undefined.';
490: }
491: } else {
492: return 'Can not open Coursemap.';
493: }
494:
495: my %CacheData;
496: unless(tie(%CacheData,'GDBM_File',$ChartDB,&GDBM_WRCREAT,0640)) {
497: untie(%hash);
498: return 'Could not tie cache hash.';
499: }
500:
501: my (@sequences, @currentResource, @finishResource);
502: my ($currentSequence, $currentResourceID, $lastResourceID);
503:
504: $currentResourceID=$hash{'ids_/res/'.$ENV{'request.course.uri'}};
505: push(@currentResource, $currentResourceID);
506: $lastResourceID=-1;
507: $currentSequence=-1;
508: my $topLevelSequenceNumber = $currentSequence;
509:
510: while(1) {
511: if($c->aborted()) {
512: last;
513: }
514: # HANDLE NEW SEQUENCE!
515: #if page || sequence
516: if(defined($hash{'map_pc_'.$hash{'src_'.$currentResourceID}})) {
517: push(@sequences, $currentSequence);
518: push(@currentResource, $currentResourceID);
519: push(@finishResource, $lastResourceID);
520:
521: $currentSequence=$hash{'map_pc_'.$hash{'src_'.$currentResourceID}};
522:
523: # Mark sequence as containing problems. If it doesn't, then
524: # it will be removed when processing for this sequence is
525: # complete. This allows the problems in a sequence
526: # to be outputed before problems in the subsequences
527: if(!defined($CacheData{'orderedSequences'})) {
528: $CacheData{'orderedSequences'}=$currentSequence;
529: } else {
530: $CacheData{'orderedSequences'}.=':'.$currentSequence;
531: }
532:
533: $lastResourceID=$hash{'map_finish_'.
534: $hash{'src_'.$currentResourceID}};
535: $currentResourceID=$hash{'map_start_'.
536: $hash{'src_'.$currentResourceID}};
537:
538: if(!($currentResourceID) || !($lastResourceID)) {
539: $currentSequence=pop(@sequences);
540: $currentResourceID=pop(@currentResource);
541: $lastResourceID=pop(@finishResource);
542: if($currentSequence eq $topLevelSequenceNumber) {
543: last;
544: }
545: }
546: }
547:
548: # Handle gradable resources: exams, problems, etc
549: $currentResourceID=~/(\d+)\.(\d+)/;
550: my $partA=$1;
551: my $partB=$2;
552: if($hash{'src_'.$currentResourceID}=~
553: /\.(problem|exam|quiz|assess|survey|form)$/ &&
554: $partA eq $currentSequence) {
555: my $Problem = &Apache::lonnet::symbclean(
556: &Apache::lonnet::declutter($hash{'map_id_'.$partA}).
557: '___'.$partB.'___'.
558: &Apache::lonnet::declutter($hash{'src_'.
559: $currentResourceID}));
560:
561: $CacheData{$currentResourceID.':problem'}=$Problem;
562: if(!defined($CacheData{$currentSequence.':problems'})) {
563: $CacheData{$currentSequence.':problems'}=$currentResourceID;
564: } else {
565: $CacheData{$currentSequence.':problems'}.=
566: ':'.$currentResourceID;
567: }
568:
569: #Get Parts for problem
570: my $meta=$hash{'src_'.$currentResourceID};
571: foreach (split(/\,/,&Apache::lonnet::metadata($meta,'keys'))) {
572: if($_=~/^stores\_(\d+)\_tries$/) {
573: my $Part=&Apache::lonnet::metadata($meta,$_.'.part');
574: if(!defined($CacheData{$currentSequence.':'.
575: $currentResourceID.':parts'})) {
576: $CacheData{$currentSequence.':'.$currentResourceID.
577: ':parts'}=$Part;
578: } else {
579: $CacheData{$currentSequence.':'.$currentResourceID.
580: ':parts'}.=':'.$Part;
581: }
582: }
583: }
584: }
585:
586: #if resource == finish resource
587: if($currentResourceID eq $lastResourceID) {
588: #pop off last resource of sequence
589: $currentResourceID=pop(@currentResource);
590: $lastResourceID=pop(@finishResource);
591:
592: if(defined($CacheData{$currentSequence.':problems'})) {
593: # Capture sequence information here
594: $CacheData{$currentSequence.':title'}=
595: $hash{'title_'.$currentResourceID};
596:
597: my $totalProblems=0;
598: foreach my $currentProblem (split(/\:/,
599: $CacheData{$currentSequence.
600: ':problems'})) {
601: foreach (split(/\:/,$CacheData{$currentSequence.':'.
602: $currentProblem.
603: ':parts'})) {
604: $totalProblems++;
605: }
606: }
607: my @titleLength=split(//,$CacheData{$currentSequence.
608: ':title'});
609: # $extra is 3 for problems correct and 3 for space
610: # between problems correct and problem output
611: my $extra = 6;
612: if(($totalProblems + $extra) > (scalar @titleLength)) {
613: $CacheData{$currentSequence.':columnWidth'}=
614: $totalProblems + $extra;
615: } else {
616: $CacheData{$currentSequence.':columnWidth'}=
617: (scalar @titleLength);
618: }
619: } else {
620: $CacheData{'orderedSequences'}=~s/$currentSequence//;
621: $CacheData{'orderedSequences'}=~s/::/:/g;
622: $CacheData{'orderedSequences'}=~s/^:|:$//g;
623: }
624:
625: $currentSequence=pop(@sequences);
626: if($currentSequence eq $topLevelSequenceNumber) {
627: last;
628: }
629: }
630:
631: # MOVE!!!
632: #move to next resource
633: unless(defined($hash{'to_'.$currentResourceID})) {
634: # big problem, need to handle. Next is probably wrong
635: last;
636: }
637: my @nextResources=();
638: foreach (split(/\,/,$hash{'to_'.$currentResourceID})) {
639: push(@nextResources, $hash{'goesto_'.$_});
640: }
641: push(@currentResource, @nextResources);
642: # Set the next resource to be processed
643: $currentResourceID=pop(@currentResource);
644: }
645:
646: unless (untie(%hash)) {
647: &Apache::lonnet::logthis("<font color=blue>WARNING: ".
648: "Could not untie coursemap $fn (browse)".
649: ".</font>");
650: }
651:
652: unless (untie(%CacheData)) {
653: &Apache::lonnet::logthis("<font color=blue>WARNING: ".
654: "Could not untie Cache Hash (browse)".
655: ".</font>");
656: }
657:
658: return 'OK';
659: }
660:
661: sub ProcessSection {
662: my ($sectionData, $courseid,$ActiveFlag)=@_;
663: $courseid=~s/\_/\//g;
664: $courseid=~s/^(\w)/\/$1/;
665:
666: my $cursection='-1';
667: my $oldsection='-1';
668: my $status='Expired';
669: my $section='';
670: foreach my $key (keys (%$sectionData)) {
671: my $value = $sectionData->{$key};
672: if ($key=~/^$courseid(?:\/)*(\w+)*\_st$/) {
673: $section=$1;
674: if($key eq $courseid.'_st') {
675: $section='';
676: }
677: my ($dummy,$end,$start)=split(/\_/,$value);
678: my $now=time;
679: my $notactive=0;
680: if ($start) {
681: if($now<$start) {
682: $notactive=1;
683: }
684: }
685: if($end) {
686: if ($now>$end) {
687: $notactive=1;
688: }
689: }
690: if($notactive == 0) {
691: $status='Active';
692: $cursection=$section;
693: last;
694: }
695: if($notactive == 1) {
696: $oldsection=$section;
697: }
698: }
699: }
700: if($status eq $ActiveFlag) {
701: if($cursection eq '-1') {
702: return $oldsection;
703: }
704: return $cursection;
705: }
706: if($ActiveFlag eq 'Any') {
707: if($cursection eq '-1') {
708: return $oldsection;
709: }
710: return $cursection;
711: }
712: return '-1';
713: }
714:
715: sub ProcessStudentInformation {
716: my ($CacheData,$studentInformation,$section,$date,$name,$courseID,$c)=@_;
717: my ($studentName,$studentDomain) = split(/\:/,$name);
718:
719: $CacheData->{$name.':username'}=$studentName;
720: $CacheData->{$name.':domain'}=$studentDomain;
721: $CacheData->{$name.':date'}=$date;
722:
723: my ($checkForError)=keys(%$studentInformation);
724: if($checkForError =~ /^(con_lost|error|no_such_host)/i) {
725: $CacheData->{$name.':error'}=
726: 'Could not download student environment data.';
727: $CacheData->{$name.':fullname'}='';
728: $CacheData->{$name.':id'}='';
729: } else {
730: $CacheData->{$name.':fullname'}=&ProcessFullName(
731: $studentInformation->{'lastname'},
732: $studentInformation->{'generation'},
733: $studentInformation->{'firstname'},
734: $studentInformation->{'middlename'});
735: $CacheData->{$name.':id'}=$studentInformation->{'id'};
736: }
737:
738: # Get student's section number
739: my $sec=&ProcessSection($section, $courseID, $CacheData->{'form.status'});
740: if($sec != -1) {
741: $CacheData->{$name.':section'}=$sec;
742: } else {
743: $CacheData->{$name.':section'}='';
744: }
745:
746: return 0;
747: }
748:
749: sub ProcessClassList {
750: my ($classlist,$courseID,$ChartDB,$c)=@_;
751: my @names=();
752:
753: my %CacheData;
754: if(tie(%CacheData,'GDBM_File',$ChartDB,&GDBM_WRCREAT,0640)) {
755: foreach my $name (keys(%$classlist)) {
756: if($name =~ /\:section/ || $name =~ /\:studentInformation/ ||
757: $name eq '') {
758: next;
759: }
760: if($c->aborted()) {
761: last;
762: }
763: push(@names,$name);
764: &ProcessStudentInformation(
765: \%CacheData,
766: $classlist->{$name.':studentInformation'},
767: $classlist->{$name.':section'},
768: $classlist->{$name},
769: $name,$courseID,$c);
770: }
771:
772: untie(%CacheData);
773: }
774:
775: return @names;
776: }
777:
778: # ----- END PROCESSING FUNCTIONS ---------------------------------------
779:
780: # ----- HELPER FUNCTIONS -----------------------------------------------
781:
782: sub SpaceColumns {
783: my ($students,$studentInformation,$headings,$ChartDB)=@_;
784:
785: my %CacheData;
786: if(tie(%CacheData,'GDBM_File',$ChartDB,&GDBM_WRCREAT,0640)) {
787: # Initialize Lengths
788: for(my $index=0; $index<(scalar @$headings); $index++) {
789: my @titleLength=split(//,$$headings[$index]);
790: $CacheData{$$studentInformation[$index].'Length'}=
791: scalar @titleLength;
792: }
793:
794: foreach my $name (@$students) {
795: foreach (@$studentInformation) {
796: my @dataLength=split(//,$CacheData{$name.':'.$_});
797: my $length=scalar @dataLength;
798: if($length > $CacheData{$_.'Length'}) {
799: $CacheData{$_.'Length'}=$length;
800: }
801: }
802: }
803: untie(%CacheData);
804: }
805:
806: return;
807: }
808:
809: sub ProcessFullName {
810: my ($lastname, $generation, $firstname, $middlename)=@_;
811: my $Str = '';
812:
813: if($lastname ne '') {
814: $Str .= $lastname.' ';
815: if($generation ne '') {
816: $Str .= $generation;
817: } else {
818: chop($Str);
819: }
820: $Str .= ', ';
821: if($firstname ne '') {
822: $Str .= $firstname.' ';
823: }
824: if($middlename ne '') {
825: $Str .= $middlename;
826: } else {
827: chop($Str);
828: if($firstname eq '') {
829: chop($Str);
830: }
831: }
832: } else {
833: if($firstname ne '') {
834: $Str .= $firstname.' ';
835: }
836: if($middlename ne '') {
837: $Str .= $middlename.' ';
838: }
839: if($generation ne '') {
840: $Str .= $generation;
841: } else {
842: chop($Str);
843: }
844: }
845:
846: return $Str;
847: }
848:
849: sub SortStudents {
850: my ($students,$CacheData)=@_;
851:
852: my @sorted1Students=();
853: foreach (@$students) {
854: my ($end,$start)=split(/\:/,$CacheData->{$_.':date'});
855: my $active=1;
856: my $now=time;
857: my $Status=$CacheData->{'form.status'};
858: $Status = ($Status) ? $Status : 'Active';
859: if((($end) && $now > $end) && (($Status eq 'Active'))) {
860: $active=0;
861: }
862: if(($Status eq 'Expired') && ($end == 0 || $now < $end)) {
863: $active=0;
864: }
865: if($active) {
866: push(@sorted1Students, $_);
867: }
868: }
869:
870: my $Pos = $CacheData->{'form.sort'};
871: my %sortData;
872: if($Pos eq 'Last Name') {
873: for(my $index=0; $index<scalar @sorted1Students; $index++) {
874: $sortData{$CacheData->{$sorted1Students[$index].':fullname'}}=
875: $sorted1Students[$index];
876: }
877: } elsif($Pos eq 'Section') {
878: for(my $index=0; $index<scalar @sorted1Students; $index++) {
879: $sortData{$CacheData->{$sorted1Students[$index].':section'}.
880: $sorted1Students[$index]}=$sorted1Students[$index];
881: }
882: } else {
883: # Sort by user name
884: for(my $index=0; $index<scalar @sorted1Students; $index++) {
885: $sortData{$sorted1Students[$index]}=$sorted1Students[$index];
886: }
887: }
888:
889: my @order = ();
890: foreach my $key (sort(keys(%sortData))) {
891: push (@order,$sortData{$key});
892: }
893:
894: return @order;
895: }
896:
897: sub TestCacheData {
898: my ($ChartDB)=@_;
899: my $isCached=-1;
900: my %testData;
901: my $tieTries=0;
902:
903: if ((-e "$ChartDB") && (!defined($ENV{'form.recalculate'}))) {
904: $isCached = 1;
905: } else {
906: $isCached = 0;
907: }
908:
909: while($tieTries < 10) {
910: my $result=0;
911: if($isCached) {
912: $result=tie(%testData,'GDBM_File',$ChartDB,&GDBM_READER,0640);
913: } else {
914: $result=tie(%testData,'GDBM_File',$ChartDB,&GDBM_NEWDB,0640);
915: }
916: if($result) {
917: last;
918: }
919: $tieTries++;
920: sleep 1;
921: }
922: if($tieTries >= 10) {
923: return -1;
924: }
925:
926: untie(%testData);
927:
928: return $isCached;
929: }
930:
931: sub ExtractStudentData {
932: my ($courseData, $name, $ChartDB)=@_;
933:
934: my %CacheData;
935: if(tie(%CacheData,'GDBM_File',$ChartDB,&GDBM_WRCREAT,0640)) {
936: my ($checkForError) = keys(%$courseData);
937: if($checkForError =~ /^(con_lost|error|no_such_host)/i) {
938: $CacheData{$name.':error'}='Could not download course data.';
939: } else {
940: foreach my $key (keys (%$courseData)) {
941: $CacheData{$name.':'.$key}=$courseData->{$key};
942: }
943: if(defined($CacheData{'NamesOfStudents'})) {
944: $CacheData{'NamesOfStudents'}.=':::'.$name;
945: } else {
946: $CacheData{'NamesOfStudents'}=$name;
947: }
948: }
949: untie(%CacheData);
950: }
951:
952: return;
953: }
954:
955: sub ShouldShowColumn {
956: my ($cache,$test)=@_;
957:
958: if($cache->{'form.reset'} eq 'true') {
959: return 1;
960: }
961:
962: my $headings=$cache->{'form.headings'};
963: my $sequences=$cache->{'form.sequences'};
964: if($headings eq 'ALLHEADINGS' || $sequences eq 'ALLSEQUENCES' ||
965: $headings=~/$test/ || $sequences=~/$test/) {
966: return 1;
967: }
968:
969: # my $reselected=$cache->{'form.reselect'};
970: # if($reselected=~/$test/) {
971: # return 1;
972: # }
973:
974: return 0;
975: }
976:
977: sub ProcessFormData {
978: my ($ChartDB)=@_;
979: my %CacheData;
980:
981: if(tie(%CacheData,'GDBM_File',$ChartDB,&GDBM_WRCREAT,0640)) {
982: if(defined($ENV{'form.sort'})) {
983: $CacheData{'form.sort'}=$ENV{'form.sort'};
984: } elsif(!defined($CacheData{'form.sort'})) {
985: $CacheData{'form.sort'}='username';
986: }
987:
988: # Ignore $ENV{'form.refresh'}
989: # Ignore $ENV{'form.recalculate'}
990:
991: if(defined($ENV{'form.status'})) {
992: $CacheData{'form.status'}=$ENV{'form.status'};
993: } elsif(!defined($CacheData{'form.status'})) {
994: $CacheData{'form.status'}='Active';
995: }
996:
997: my @headings=();
998: my @sequences=();
999: my $found=0;
1000: foreach (keys(%ENV)) {
1001: if(/form\.heading/) {
1002: $found++;
1003: push(@headings, $_);
1004: } elsif(/form\.sequence/) {
1005: $found++;
1006: push(@sequences, $_);
1007: } elsif(/form\./) {
1008: $found++;
1009: }
1010: }
1011:
1012: if($found) {
1013: $CacheData{'form.headings'}=join(":::",@headings);
1014: $CacheData{'form.sequences'}=join(":::",@sequences);
1015: }
1016:
1017: if(defined($ENV{'form.reselect'})) {
1018: my @reselected = (ref($ENV{'form.reselect'}) ?
1019: @{$ENV{'form.reselect'}}
1020: : ($ENV{'form.reselect'}));
1021: foreach (@reselected) {
1022: if(/heading/) {
1023: $CacheData{'form.headings'}.=":::".$_;
1024: } elsif(/sequence/) {
1025: $CacheData{'form.sequences'}.=":::".$_;
1026: }
1027: }
1028: }
1029:
1030: if(defined($ENV{'form.reset'})) {
1031: $CacheData{'form.reset'}='true';
1032: $CacheData{'form.status'}='Active';
1033: $CacheData{'form.sort'}='username';
1034: $CacheData{'form.headings'}='ALLHEADINGS';
1035: $CacheData{'form.sequences'}='ALLSEQUENCES';
1036: } else {
1037: $CacheData{'form.reset'}='false';
1038: }
1039:
1040: untie(%CacheData);
1041: }
1042:
1043: return;
1044: }
1045:
1046: # ----- END HELPER FUNCTIONS --------------------------------------------
1047:
1048: sub BuildChart {
1049: my ($r)=@_;
1050: my $c = $r->connection;
1051:
1052: # Start the lonchart document
1053: $r->content_type('text/html');
1054: $r->send_http_header;
1055: $r->print(&StartDocument());
1056: $r->rflush();
1057:
1058: # Test for access to the CacheData
1059: my $isCached=0;
1060: my $cid=$ENV{'request.course.id'};
1061: my $ChartDB = "/home/httpd/perl/tmp/$ENV{'user.name'}".
1062: "_$ENV{'user.domain'}_$cid\_chart.db";
1063:
1064: $isCached=&TestCacheData($ChartDB);
1065: if($isCached < 0) {
1066: $r->print("Unable to tie hash to db file");
1067: $r->rflush();
1068: return;
1069: }
1070: &ProcessFormData($ChartDB);
1071:
1072: # Download class list information if not using cached data
1073: my %CacheData;
1074: my @students=();
1075: my @studentInformation=('username','domain','section','id','fullname');
1076: my @headings=('User Name','Domain','Section','PID','Full Name');
1077: my $spacePadding=' ';
1078: if(!$isCached) {
1079: my $processTopResourceMapReturn=&ProcessTopResourceMap($ChartDB,$c);
1080: if($processTopResourceMapReturn ne 'OK') {
1081: $r->print($processTopResourceMapReturn);
1082: return;
1083: }
1084: if($c->aborted()) { return; }
1085: my $classlist=&DownloadPrerequisiteData($cid, $c);
1086: my ($checkForError)=keys(%$classlist);
1087: if($checkForError =~ /^(con_lost|error|no_such_host)/i ||
1088: defined($classlist->{'error'})) {
1089: return;
1090: }
1091: if($c->aborted()) { return; }
1092: @students=&ProcessClassList($classlist,$cid,$ChartDB,$c);
1093: if($c->aborted()) { return; }
1094: &SpaceColumns(\@students,\@studentInformation,\@headings,
1095: $ChartDB);
1096: if($c->aborted()) { return; }
1097: } else {
1098: if(!$c->aborted() && tie(%CacheData,'GDBM_File',$ChartDB,
1099: &GDBM_READER,0640)) {
1100: @students=split(/:::/,$CacheData{'NamesOfStudents'});
1101: }
1102: }
1103:
1104: # Sort students and print out table desciptive data
1105: if(tie(%CacheData,'GDBM_File',$ChartDB,&GDBM_READER,0640)) {
1106: if(!$c->aborted()) { @students=&SortStudents(\@students,\%CacheData); }
1107: if(!$c->aborted()) { $r->print('<h1>'.(scalar @students).
1108: ' students</h1>'); }
1109: if(!$c->aborted()) { $r->rflush(); }
1110: if(!$c->aborted()) { $r->print(&CreateLegend()); }
1111: if(!$c->aborted()) { $r->print(&CreateForm(\%CacheData)); }
1112: if(!$c->aborted()) { $r->print(&CreateColumnSelectionBox(
1113: \%CacheData,
1114: \@studentInformation,
1115: \@headings,
1116: $spacePadding)); }
1117: if(!$c->aborted()) { $r->print(&CreateColumnSelectors(
1118: \%CacheData,
1119: \@studentInformation,
1120: \@headings,
1121: $spacePadding)); }
1122: if(!$c->aborted()) { $r->print(&CreateTableHeadings(
1123: \%CacheData,
1124: \@studentInformation,
1125: \@headings,
1126: $spacePadding)); }
1127: if(!$c->aborted()) { $r->rflush(); }
1128: untie(%CacheData);
1129: } else {
1130: $r->print("Init2: Unable to tie hash to db file");
1131: return;
1132: }
1133:
1134: my @updateStudentList = ();
1135: my $courseData;
1136: $r->print('<pre>');
1137: foreach (@students) {
1138: if($c->aborted()) {
1139: last;
1140: }
1141:
1142: if(!$isCached) {
1143: $courseData=&DownloadStudentCourseInformation($_, $cid);
1144: if($c->aborted()) { last; }
1145: push(@updateStudentList, $_);
1146: &ExtractStudentData($courseData, $_, $ChartDB);
1147: }
1148: $r->print(&FormatStudentData($_, $cid, \@studentInformation,
1149: $spacePadding, $ChartDB));
1150: $r->rflush();
1151: }
1152:
1153: if(!$isCached && tie(%CacheData,'GDBM_File',$ChartDB,&GDBM_WRCREAT,0640)) {
1154: $CacheData{'NamesOfStudents'}=join(":::", @updateStudentList);
1155: # $CacheData{'NamesOfStudents'}=
1156: # &Apache::lonnet::arrayref2str(\@updateStudentList);
1157: untie(%CacheData);
1158: }
1159:
1160: $r->print('</pre></body></html>');
1161: $r->rflush();
1162:
1163: return;
1164: }
1165:
1166: # ================================================================ Main Handler
1167:
1168: sub handler {
1169: my $r=shift;
1170: # $jr=$r;
1171: unless(&Apache::lonnet::allowed('vgr',$ENV{'request.course.id'})) {
1172: $ENV{'user.error.msg'}=
1173: $r->uri.":vgr:0:0:Cannot view grades for complete course";
1174: return HTTP_NOT_ACCEPTABLE;
1175: }
1176:
1177: # Set document type for header only
1178: if ($r->header_only) {
1179: if($ENV{'browser.mathml'}) {
1180: $r->content_type('text/xml');
1181: } else {
1182: $r->content_type('text/html');
1183: }
1184: &Apache::loncommon::no_cache($r);
1185: $r->send_http_header;
1186: return OK;
1187: }
1188:
1189: unless($ENV{'request.course.fn'}) {
1190: my $requrl=$r->uri;
1191: $ENV{'user.error.msg'}="$requrl:bre:0:0:Course not initialized";
1192: return HTTP_NOT_ACCEPTABLE;
1193: }
1194:
1195: &BuildChart($r);
1196:
1197: return OK;
1198: }
1199: 1;
1200: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>