Annotation of loncom/interface/lonstatistics.pm, revision 1.34
1.1 albertel 1: # The LearningOnline Network with CAPA
2: # (Publication Handler
3: #
1.34 ! stredwic 4: # $Id: lonstatistics.pm,v 1.33 2002/07/26 16:22:09 stredwic Exp $
1.1 albertel 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: # (Navigate problems for statistical reports
29: # YEAR=2001
1.15 minaeibi 30: # 5/5,7/9,7/25/1,8/11,9/13,9/26,10/5,10/9,10/22,10/26 Behrouz Minaei
1.14 minaeibi 31: # 11/1,11/4,11/16,12/14,12/16,12/18,12/20,12/31 Behrouz Minaei
1.1 albertel 32: # YEAR=2002
1.18 minaeibi 33: # 1/22,2/1,2/6,2/25,3/2,3/6,3/17,3/21,3/22,3/26,4/7,5/6 Behrouz Minaei
1.31 minaeibi 34: # 5/12,5/14,5/15,5/19,5/26,7/16,25/7 Behrouz Minaei
1.14 minaeibi 35: #
1.1 albertel 36: ###
37:
1.3 minaeibi 38: package Apache::lonstatistics;
1.1 albertel 39:
1.30 stredwic 40: use strict;
1.1 albertel 41: use Apache::Constants qw(:common :http);
42: use Apache::lonnet();
43: use Apache::lonhomework;
1.12 minaeibi 44: use Apache::loncommon;
1.29 stredwic 45: use Apache::loncoursedata;
46: use Apache::lonhtmlcommon;
1.30 stredwic 47: use Apache::lonproblemanalysis;
48: use Apache::lonproblemstatistics;
49: use Apache::lonstudentassessment;
1.29 stredwic 50: use Apache::lonchart;
1.1 albertel 51: use HTML::TokeParser;
52: use GDBM_File;
53:
1.34 ! stredwic 54: #my $jr;
1.27 stredwic 55:
56: sub CheckFormElement {
57: my ($cache, $ENVName, $cacheName, $default)=@_;
58:
59: if(defined($ENV{'form.'.$ENVName})) {
60: $cache->{$cacheName} = $ENV{'form.'.$ENVName};
61: } elsif(!defined($cache->{$cacheName})) {
62: $cache->{$cacheName} = $default;
63: }
64:
65: return;
66: }
67:
68: sub ProcessFormData{
1.29 stredwic 69: my ($cache)=@_;
1.27 stredwic 70:
1.29 stredwic 71: $cache->{'reportKey'} = 'false';
1.27 stredwic 72:
1.29 stredwic 73: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.34 ! stredwic 74: ['sort','download',
! 75: 'reportSelected',
1.30 stredwic 76: 'StudentAssessmentStudent']);
1.29 stredwic 77: &CheckFormElement($cache, 'Status', 'Status', 'Active');
78: &CheckFormElement($cache, 'postdata', 'reportSelected', 'Class list');
79: &CheckFormElement($cache, 'reportSelected', 'reportSelected',
80: 'Class list');
1.30 stredwic 81: $cache->{'reportSelected'} =
82: &Apache::lonnet::unescape($cache->{'reportSelected'});
1.29 stredwic 83: &CheckFormElement($cache, 'DownloadAll', 'DownloadAll', 'false');
84: &CheckFormElement($cache, 'sort', 'sort', 'fullname');
85: &CheckFormElement($cache, 'download', 'download', 'false');
86:
87: if(defined($ENV{'form.CreateStudentAssessment'}) ||
88: defined($ENV{'form.NextStudent'}) ||
89: defined($ENV{'form.PreviousStudent'})) {
90: $cache->{'reportSelected'} = 'Student Assessment';
91: }
92: if(defined($ENV{'form.NextStudent'})) {
93: $cache->{'StudentAssessmentMove'} = 'next';
94: } elsif(defined($ENV{'form.PreviousStudent'})) {
95: $cache->{'StudentAssessmentMove'} = 'previous';
96: } else {
97: $cache->{'StudentAssessmentMove'} = 'selected';
98: }
99: &CheckFormElement($cache, 'StudentAssessmentStudent',
1.30 stredwic 100: 'StudentAssessmentStudent', 'All Students');
101: $cache->{'StudentAssessmentStudent'} =
102: &Apache::lonnet::unescape($cache->{'StudentAssessmentStudent'});
1.34 ! stredwic 103: &CheckFormElement($cache, 'DefaultColumns', 'DefaultColumns', 'false');
1.29 stredwic 104:
1.33 stredwic 105: if(defined($ENV{'form.Section'})) {
106: my @sectionsSelected = (ref($ENV{'form.Section'}) ?
107: @{$ENV{'form.Section'}} :
108: ($ENV{'form.Section'}));
109: $cache->{'sectionsSelected'} = join(':', @sectionsSelected);
110: } elsif(!defined($cache->{'sectionsSelected'})) {
111: $cache->{'sectionsSelected'} = $cache->{'sectionList'};
112: }
113:
1.34 ! stredwic 114: my @headingColumns=();
! 115: my @sequenceColumns=();
! 116: my $foundColumn = 0;
! 117: if(defined($ENV{'form.ReselectColumns'})) {
! 118: my @reselected = (ref($ENV{'form.ReselectColumns'}) ?
! 119: @{$ENV{'form.ReselectColumns'}}
! 120: : ($ENV{'form.ReselectColumns'}));
! 121: foreach (@reselected) {
! 122: if(/HeadingColumn/) {
! 123: push(@headingColumns, $_);
! 124: $foundColumn = 1;
! 125: } elsif(/SequenceColumn/) {
! 126: push(@sequenceColumns, $_);
! 127: $foundColumn = 1;
! 128: }
! 129: }
! 130: }
! 131:
1.29 stredwic 132: foreach (keys(%ENV)) {
133: if(/form\.Analyze:::/) {
134: # $cache->{'reportSelected'} = 'Analyze';
135: # $cache->{'reportKey'} = 'Problem Analysis';
136: my ($uri, $title, $part, $problem);
137: (undef, $uri, $title, $part, $problem)=split(':::', $_);
138: $cache->{'AnalyzeURI'} = $uri;
139: $cache->{'AnalyzeTitle'} = $title;
140: $cache->{'AnalyzePart'} = $part;
141: $cache->{'AnalyzeProblem'} = $problem;
142:
143: &CheckFormElement($cache, 'Interval', 'Interval', '1');
1.34 ! stredwic 144: } elsif(/form\.HeadingColumn/) {
! 145: my $value = $_;
! 146: $value =~ s/form\.//;
! 147: push(@headingColumns, $value);
! 148: $foundColumn=1;
! 149: } elsif(/form\.SequenceColumn/) {
! 150: my $value = $_;
! 151: $value =~ s/form\.//;
! 152: push(@sequenceColumns, $value);
! 153: $foundColumn=1;
1.27 stredwic 154: }
1.29 stredwic 155: }
1.27 stredwic 156:
1.34 ! stredwic 157: if($foundColumn) {
! 158: $cache->{'HeadingsFound'} = join(':', @headingColumns);
! 159: $cache->{'SequencesFound'} = join(':', @sequenceColumns);;
! 160: }
! 161: if(!defined($cache->{'HeadingsFound'}) ||
! 162: $cache->{'DefaultColumns'} ne 'false') {
! 163: $cache->{'HeadingsFound'}='HeadingColumnFull Name';
! 164: }
! 165: if(!defined($cache->{'SequencesFound'}) ||
! 166: $cache->{'DefaultColumns'} ne 'false') {
! 167: $cache->{'SequencesFound'}='All Sequences';
! 168: }
! 169: $cache->{'DefaultColumns'} = 'false';
! 170:
1.29 stredwic 171: return;
1.27 stredwic 172:
1.29 stredwic 173: # Select page to display
174: if(defined($ENV{'form.ProblemStatistics'}) ||
175: defined($ENV{'form.ProblemStatisticsRecalculate'}) ||
176: defined($ENV{'form.DisplayCSVFormat'})) {
177: $cache->{'GoToPage'} = 'ProblemStatistics';
178: &CheckFormElement($cache, 'DisplayCSVFormat',
179: 'DisplayFormat', 'Display Table Format');
180: &CheckFormElement($cache, 'Ascend','ProblemStatisticsAscend',
181: 'Ascending');
182: &CheckFormElement($cache, 'Maps', 'ProblemStatisticsMap',
183: 'All Maps');
184: } elsif(defined($ENV{'form.ProblemAnalysis'})) {
185: $cache->{'GoToPage'} = 'ProblemAnalysis';
186: &CheckFormElement($cache, 'Interval', 'Interval', '1');
187: } elsif(defined($ENV{'form.DoDiffGraph'})) {
188: $cache->{'GoToPage'} = 'DoDiffGraph';
189: } elsif(defined($ENV{'form.PercentWrongGraph'})) {
190: $cache->{'GoToPage'} = 'PercentWrongGraph';
191: } elsif(defined($ENV{'form.ActivityLog'})) {
192: $cache->{'GoToPage'} = 'ActivityLog';
193: } else {
194: $cache->{'GoToPage'} = 'Menu';
195: }
1.27 stredwic 196:
1.29 stredwic 197: &CheckFormElement($cache, 'Status', 'Status', 'Active');
1.27 stredwic 198:
199: return;
200: }
201:
202: =pod
203:
204: =item &SortStudents()
205:
206: Determines which students to display and in which order. Which are
207: displayed are determined by their status(active/expired). The order
208: is determined by the sort button pressed (default to username). The
209: type of sorting is username, lastname, or section.
210:
211: =over 4
212:
213: Input: $students, $CacheData
214:
215: $students: A array pointer to a list of students (username:domain)
216:
217: $CacheData: A pointer to the hash tied to the cached data
218:
219: Output: \@order
220:
221: @order: An ordered list of students (username:domain)
222:
223: =back
224:
225: =cut
226:
227: sub SortStudents {
1.29 stredwic 228: my ($cache)=@_;
1.27 stredwic 229:
1.29 stredwic 230: my @students = split(':::',$cache->{'NamesOfStudents'});
1.27 stredwic 231: my @sorted1Students=();
1.29 stredwic 232: foreach (@students) {
233: if($cache->{'Status'} eq 'Any' ||
234: $cache->{$_.':Status'} eq $cache->{'Status'}) {
235: push(@sorted1Students, $_);
236: }
1.1 albertel 237: }
1.27 stredwic 238:
1.29 stredwic 239: my $sortBy = '';
240: if(defined($cache->{'sort'})) {
241: $sortBy = ':'.$cache->{'sort'};
1.27 stredwic 242: }
1.29 stredwic 243: my @order = sort { $cache->{$a.$sortBy} cmp $cache->{$b.$sortBy} ||
244: $cache->{$a.':fullname'} cmp $cache->{$b.':fullname'} }
245: @sorted1Students;
1.27 stredwic 246:
247: return \@order;
248: }
249:
1.32 stredwic 250: =pod
251:
252: =item &SpaceColumns()
253:
254: Determines the width of all the columns in the chart. It is based on
255: the max of the data for that column and its header.
256:
257: =over 4
258:
259: Input: $students, $studentInformation, $headings, $ChartDB
260:
261: $students: An array pointer to a list of students (username:domain)
262:
263: $studentInformatin: The type of data for the student information. It is
264: used as part of the key in $CacheData.
265:
266: $headings: The name of the student information columns.
267:
268: $ChartDB: The name of the cache database which is opened for read/write.
269:
270: Output: None - All data stored in cache.
271:
272: =back
273:
274: =cut
275:
276: sub SpaceColumns {
277: my ($students,$studentInformation,$headings,$cache)=@_;
278:
279: # Initialize Lengths
280: for(my $index=0; $index<(scalar @$headings); $index++) {
281: my @titleLength=split(//,$headings->[$index]);
282: $cache->{$studentInformation->[$index].':columnWidth'}=
283: scalar @titleLength;
284: }
285:
286: foreach my $name (@$students) {
287: foreach (@$studentInformation) {
288: my @dataLength=split(//,$cache->{$name.':'.$_});
289: my $length=(scalar @dataLength);
290: if($length > $cache->{$_.':columnWidth'}) {
291: $cache->{$_.':columnWidth'}=$length;
292: }
293: }
294: }
295:
296: return;
297: }
298:
1.27 stredwic 299: sub PrepareData {
1.32 stredwic 300: my ($c, $cacheDB, $studentInformation, $headings)=@_;
1.27 stredwic 301:
302: # Test for access to the cache data
303: my $courseID=$ENV{'request.course.id'};
304: my $isRecalculate=0;
1.29 stredwic 305: if(defined($ENV{'form.Recalculate'})) {
1.27 stredwic 306: $isRecalculate=1;
307: }
308:
1.29 stredwic 309: my $isCached = &Apache::loncoursedata::TestCacheData($cacheDB,
310: $isRecalculate);
1.27 stredwic 311: if($isCached < 0) {
312: return "Unable to tie hash to db file.";
313: }
314:
315: # Download class list information if not using cached data
316: my %cache;
1.29 stredwic 317: unless(tie(%cache,'GDBM_File',$cacheDB,&GDBM_WRCREAT,0640)) {
318: return "Unable to tie hash to db file.";
319: }
320:
1.27 stredwic 321: if(!$isCached) {
322: my $processTopResourceMapReturn=
323: &Apache::loncoursedata::ProcessTopResourceMap(\%cache, $c);
324: if($processTopResourceMapReturn ne 'OK') {
325: untie(%cache);
326: return $processTopResourceMapReturn;
327: }
1.29 stredwic 328: }
1.27 stredwic 329:
1.29 stredwic 330: if($c->aborted()) {
331: untie(%cache);
332: return 'aborted';
333: }
1.27 stredwic 334:
1.29 stredwic 335: my $classlist=&Apache::loncoursedata::DownloadClasslist($courseID,
336: $cache{'ClasslistTimestamp'},
337: $c);
338: foreach (keys(%$classlist)) {
339: if(/^(con_lost|error|no_such_host)/i) {
1.27 stredwic 340: untie(%cache);
341: return "Error getting student data.";
342: }
1.29 stredwic 343: }
1.27 stredwic 344:
1.29 stredwic 345: if($c->aborted()) {
346: untie(%cache);
347: return 'aborted';
348: }
349:
350: # Active is a temporary solution, remember to change
351: Apache::loncoursedata::ProcessClasslist(\%cache,$classlist,$courseID,$c);
352: if($c->aborted()) {
353: untie(%cache);
354: return 'aborted';
355: }
1.27 stredwic 356:
1.29 stredwic 357: &ProcessFormData(\%cache);
358: my $students = &SortStudents(\%cache);
1.32 stredwic 359: &SpaceColumns($students, $studentInformation, $headings, \%cache);
360: $cache{'updateTime:columnWidth'}=24;
1.27 stredwic 361:
1.29 stredwic 362: if($cache{'download'} ne 'false') {
363: my $who = $cache{'download'};
364: my $courseData =
1.30 stredwic 365: &Apache::loncoursedata::DownloadCourseInformation(
1.29 stredwic 366: $who, $courseID,
367: $cache{$who.':lastDownloadTime'});
368: &Apache::loncoursedata::ProcessStudentData(\%cache, $courseData, $who);
369: $cache{'download'} = 'false';
370: } elsif($cache{'DownloadAll'} ne 'false') {
371: my @allStudents;
372: if($cache{'DownloadAll'} eq 'sorted') {
373: @allStudents = @$students;
374: } else {
375: @allStudents = split(':::', $cache{'NamesOfStudents'});
376: }
377: foreach (@allStudents) {
378: my $courseData =
1.30 stredwic 379: &Apache::loncoursedata::DownloadCourseInformation(
1.29 stredwic 380: $_, $courseID,
381: $cache{$_.':lastDownloadTime'});
382: &Apache::loncoursedata::ProcessStudentData(\%cache, $courseData,
383: $_);
384: if($c->aborted()) {
385: untie(%cache);
386: return 'aborted';
387: }
1.27 stredwic 388: }
1.29 stredwic 389: $cache{'DownloadAll'} = 'false';
390: }
1.27 stredwic 391:
1.29 stredwic 392: if($c->aborted()) {
1.27 stredwic 393: untie(%cache);
1.29 stredwic 394: return 'aborted';
395: }
396:
397: untie(%cache);
398:
399: return ('OK', $students);
1.27 stredwic 400: }
401:
1.31 minaeibi 402:
1.27 stredwic 403: # Create progress
404: sub Create_PrgWin {
1.31 minaeibi 405: my ($r)=@_;
1.27 stredwic 406: $r->print(<<ENDPOP);
407: <script>
408: popwin=open('','popwin','width=400,height=100');
409: popwin.document.writeln('<html><body bgcolor="#88DDFF">'+
410: '<title>LON-CAPA Statistics</title>'+
411: '<h4>Computation Progress</h4>'+
412: '<form name=popremain>'+
413: '<input type=text size=35 name=remaining value=Starting></form>'+
414: '</body></html>');
415: popwin.document.close();
416: </script>
417: ENDPOP
418:
419: $r->rflush();
1.1 albertel 420: }
421:
1.27 stredwic 422: # update progress
423: sub Update_PrgWin {
1.31 minaeibi 424: my ($totalStudents,$index,$name,$r)=@_;
1.27 stredwic 425: $r->print('<script>popwin.document.popremain.remaining.value="'.
426: 'Computing '.$index.'/'.$totalStudents.': '.
427: $name.'";</script>');
428: $r->rflush();
429: }
1.1 albertel 430:
1.27 stredwic 431: # close Progress Line
432: sub Close_PrgWin {
1.31 minaeibi 433: my ($r)=@_;
1.27 stredwic 434: $r->print('<script>popwin.close()</script>');
435: $r->rflush();
1.25 minaeibi 436: }
437:
438: # For loading the colored table for display or un-colored for print
439: sub setbgcolor {
440: my $PrintTable=shift;
1.31 minaeibi 441: my %color;
1.25 minaeibi 442: if ($PrintTable){
443: $color{"gb"}="#FFFFFF";
444: $color{"red"}="#FFFFFF";
445: $color{"yellow"}="#FFFFFF";
446: $color{"green"}="#FFFFFF";
447: $color{"purple"}="#FFFFFF";
448: } else {
449: $color{"gb"}="#DDFFFF";
450: $color{"red"}="#FFDDDD";
451: $color{"yellow"}="#EEFFCC";
452: $color{"green"}="#DDFFDD";
453: $color{"purple"}="#FFDDFF";
454: }
1.27 stredwic 455:
1.31 minaeibi 456: return \%color;
1.1 albertel 457: }
458:
1.29 stredwic 459: sub BuildClasslist {
1.32 stredwic 460: my ($cacheDB,$students,$studentInformation,$headings)=@_;
1.29 stredwic 461:
462: my %cache;
463: unless(tie(%cache,'GDBM_File',$cacheDB,&GDBM_READER,0640)) {
464: return '<html><body>Unable to tie database.</body></html>';
1.1 albertel 465: }
466:
1.29 stredwic 467: my $Str='';
468: $Str .= '<table border="0"><tr><td bgcolor="#777777">'."\n";
469: $Str .= '<table border="0" cellpadding="3"><tr bgcolor="#e6ffff">'."\n";
470:
471: my $displayString = '<td align="left"><a href="/adm/statistics?';
472: $displayString .= 'sort=LINKDATA">DISPLAYDATA </a></td>'."\n";
1.32 stredwic 473: $Str .= &Apache::lonhtmlcommon::CreateHeadings(\%cache, $studentInformation,
474: $headings, $displayString);
1.29 stredwic 475: $Str .= '</tr>'."\n";
476: my $alternate=0;
477: foreach (@$students) {
478: my ($username, $domain) = split(':', $_);
479: if($alternate) {
1.32 stredwic 480: $Str .= '<tr bgcolor="#ffffe6">';
1.29 stredwic 481: } else {
1.32 stredwic 482: $Str .= '<tr bgcolor="#ffffc6">';
1.29 stredwic 483: }
484: $alternate = ($alternate + 1) % 2;
485: foreach my $data (@$studentInformation) {
1.32 stredwic 486: $Str .= '<td>';
1.29 stredwic 487: if($data eq 'fullname') {
488: $Str .= '<a href="/adm/statistics?reportSelected=';
1.30 stredwic 489: $Str .= &Apache::lonnet::escape('Student Assessment');
490: $Str .= '&StudentAssessmentStudent=';
491: $Str .= &Apache::lonnet::escape($cache{$_.':'.$data}).'">';
1.32 stredwic 492: $Str .= $cache{$_.':'.$data}.' ';
1.29 stredwic 493: $Str .= '</a>';
1.32 stredwic 494: } elsif($data eq 'updateTime') {
495: $Str .= '<a href="/adm/statistics?reportSelected=';
496: $Str .= &Apache::lonnet::escape('Class list');
497: $Str .= '&download='.$_.'">';
498: $Str .= $cache{$_.':'.$data}.' ';
499: $Str .= ' </a>';
500: } else {
501: $Str .= $cache{$_.':'.$data}.' ';
1.29 stredwic 502: }
503:
1.32 stredwic 504: $Str .= '</td>'."\n";
1.29 stredwic 505: }
1.1 albertel 506: }
1.29 stredwic 507:
1.32 stredwic 508: $Str .= '</tr>'."\n";
1.29 stredwic 509: $Str .= '</table></td></tr></table>'."\n";
510:
1.27 stredwic 511: untie(%cache);
1.1 albertel 512:
1.29 stredwic 513: return $Str;
1.1 albertel 514: }
515:
1.33 stredwic 516: sub CreateMainMenu {
517: my ($status, $reports)=@_;
518:
519: my $Str = '';
520:
521: $Str .= '<table border="0"><tbody><tr>'."\n";
522: $Str .= '<td></td><td></td>'."\n";
523: $Str .= '<td align="center"><b>Analysis Reports:</b></td>'."\n";
524: $Str .= '<td align="center"><b>Student Status:</b></td></tr>'."\n";
525: $Str .= '<tr>'."\n";
526: $Str .= '<td align="center"><input type="submit" name="Refresh" ';
527: $Str .= 'value="Refresh" /></td>'."\n";
528: $Str .= '<td align="center"><input type="submit" name="DownloadAll" ';
529: $Str .= 'value="Update All Student Data" /></td>'."\n";
530: $Str .= '<td align="center">';
531: $Str .= '<select name="reportSelected" onchange="document.';
532: $Str .= 'Statistics.submit()">'."\n";
533:
534: foreach (sort(keys(%$reports))) {
535: next if($_ eq 'reportSelected');
536: $Str .= '<option name="'.$_.'"';
537: if($reports->{'reportSelected'} eq $reports->{$_}) {
538: $Str .= ' selected=""';
539: }
540: $Str .= '>'.$reports->{$_}.'</option>'."\n";
541: }
542: $Str .= '</select></td>'."\n";
543:
544: $Str .= '<td align="center">';
545: $Str .= &Apache::lonhtmlcommon::StatusOptions($status, 'Statistics');
546: $Str .= '</td>'."\n";
547:
548: $Str .= '</tr></tbody></table>'."\n";
549: $Str .= '<hr>'."\n";
550:
551: return $Str;
552: }
553:
1.29 stredwic 554: sub BuildStatistics {
555: my ($r)=@_;
556:
557: my $c = $r->connection;
1.32 stredwic 558: my @studentInformation=('fullname','section','id','domain','username',
559: 'updateTime');
560: my @headings=('Full Name', 'Section', 'PID', 'Domain', 'User Name',
561: 'Last Updated');
562: my $spacing = ' ';
1.29 stredwic 563: my %reports = ('classlist' => 'Class list',
564: 'problem_statistics' => 'Problem Statistics',
565: 'student_assessment' => 'Student Assessment',
566: 'reportSelected' => 'Class list');
1.27 stredwic 567:
568: my %cache;
1.29 stredwic 569: my $courseID=$ENV{'request.course.id'};
570: my $cacheDB = "/home/httpd/perl/tmp/$ENV{'user.name'}".
571: "_$ENV{'user.domain'}_$courseID\_statistics.db";
572:
1.31 minaeibi 573: my %color=&setbgcolor(0);
1.32 stredwic 574: my ($returnValue, $students) = &PrepareData($c, $cacheDB,
575: \@studentInformation,
576: \@headings);
1.29 stredwic 577: if($returnValue ne 'OK') {
578: $r->print('<html><body>'.$returnValue."\n".'</body></html>');
579: return OK;
580: }
581:
582: my $GoToPage;
583: if(tie(%cache,'GDBM_File',$cacheDB,&GDBM_READER,0640)) {
584: $GoToPage = $cache{'reportSelected'};
585: $reports{'reportSelected'} = $cache{'reportSelected'};
586: # if(defined($cache{'reportKey'}) && $cache{'reportKey'} ne 'false') {
587: # $reports{$cache{'reportKey'}} = $cache{'reportSelected'};
588: # }
589:
590: if(defined($cache{'OptionResponses'})) {
591: $reports{'problem_analysis'} = 'Problem Analysis';
592: }
593:
594: $r->print(&Apache::lonhtmlcommon::Title('LON-CAPA Statistics'));
595: $r->print('<form name="Statistics" ');
596: $r->print('method="post" action="/adm/statistics">');
1.33 stredwic 597: $r->print(&CreateMainMenu($cache{'Status'}, \%reports));
1.29 stredwic 598: untie(%cache);
599: } else {
1.27 stredwic 600: $r->print('<html><body>Unable to tie database.</body></html>');
1.29 stredwic 601: return OK;
602: }
603:
604: if($GoToPage eq 'Activity Log') {
1.30 stredwic 605: &Apache::lonproblemstatistics::Activity();
1.29 stredwic 606: } elsif($GoToPage eq 'Problem Statistics') {
1.30 stredwic 607: $r->print(
608: &Apache::lonproblemstatistics::BuildProblemStatisticsPage($cacheDB,
609: $students,
610: $courseID,
1.31 minaeibi 611: $c,$r,
612: \%color));
1.29 stredwic 613: } elsif($GoToPage eq 'Problem Analysis') {
1.30 stredwic 614: $r->print(
615: &Apache::lonproblemanalysis::BuildProblemAnalysisPage($cacheDB));
1.29 stredwic 616: } elsif($GoToPage eq 'Student Assessment') {
1.30 stredwic 617: $r->print(
618: &Apache::lonstudentassessment::BuildStudentAssessmentPage($cacheDB,
1.32 stredwic 619: $students,
620: $courseID,
621: 'Statistics',
622: \@headings,
623: $spacing,
624: \@studentInformation,
625: $r, $c));
1.29 stredwic 626: } elsif($GoToPage eq 'Analyze') {
1.30 stredwic 627: $r->print(&Apache::lonproblemanalysis::BuildAnalyzePage($cacheDB,
628: $students,
629: $courseID));
1.29 stredwic 630: } elsif($GoToPage eq 'DoDiffGraph') {
1.31 minaeibi 631: &Apache::lonproblemstatistics::BuildDiffGraph($r);
1.29 stredwic 632: } elsif($GoToPage eq 'PercentWrongGraph') {
1.31 minaeibi 633: &Apache::lonproblemstatistics::BuildWrongGraph($r);
1.29 stredwic 634: } elsif($GoToPage eq 'Class list') {
635: $r->print(&BuildClasslist($cacheDB, $students, \@studentInformation,
1.32 stredwic 636: \@headings));
1.27 stredwic 637: }
638:
639: $r->print('</form>'."\n");
1.29 stredwic 640: $r->print("\n".'</body>'."\n".'</html>');
641: $r->rflush();
1.27 stredwic 642:
1.29 stredwic 643: return OK;
1.27 stredwic 644: }
1.1 albertel 645:
646: # ================================================================ Main Handler
647:
648: sub handler {
1.31 minaeibi 649: my $r=shift;
1.34 ! stredwic 650:
! 651: # $jr = $r;
1.1 albertel 652:
1.27 stredwic 653: unless(&Apache::lonnet::allowed('vgr',$ENV{'request.course.id'})) {
654: $ENV{'user.error.msg'}=
655: $r->uri.":vgr:0:0:Cannot view grades for complete course";
656: return HTTP_NOT_ACCEPTABLE;
657: }
658:
659: # Set document type for header only
660: if($r->header_only) {
661: if ($ENV{'browser.mathml'}) {
662: $r->content_type('text/xml');
663: } else {
664: $r->content_type('text/html');
665: }
666: &Apache::loncommon::no_cache($r);
667: $r->send_http_header;
668: return OK;
669: }
670:
671: unless($ENV{'request.course.fn'}) {
1.1 albertel 672: my $requrl=$r->uri;
1.27 stredwic 673: $ENV{'user.error.msg'}="$requrl:bre:0:0:Course not initialized";
674: return HTTP_NOT_ACCEPTABLE;
675: }
1.1 albertel 676:
1.27 stredwic 677: $r->content_type('text/html');
678: $r->send_http_header;
1.1 albertel 679:
1.29 stredwic 680: &BuildStatistics($r);
1.27 stredwic 681:
682: return OK;
1.1 albertel 683: }
684: 1;
685: __END__
1.31 minaeibi 686:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>