Annotation of loncom/interface/lontrackstudent.pm, revision 1.22

1.1       matthew     1: # The LearningOnline Network with CAPA
                      2: #
1.22    ! albertel    3: # $Id: lontrackstudent.pm,v 1.21 2006/12/06 22:22:37 albertel Exp $
1.1       matthew     4: #
                      5: # Copyright Michigan State University Board of Trustees
                      6: #
                      7: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
                      8: #
                      9: # LON-CAPA is free software; you can redistribute it and/or modify
                     10: # it under the terms of the GNU General Public License as published by
                     11: # the Free Software Foundation; either version 2 of the License, or
                     12: # (at your option) any later version.
                     13: #
                     14: # LON-CAPA is distributed in the hope that it will be useful,
                     15: # but WITHOUT ANY WARRANTY; without even the implied warranty of
                     16: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
                     17: # GNU General Public License for more details.
                     18: #
                     19: # You should have received a copy of the GNU General Public License
                     20: # along with LON-CAPA; if not, write to the Free Software
                     21: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
                     22: #
                     23: # /home/httpd/html/adm/gpl.txt
                     24: #
                     25: # http://www.lon-capa.org/
                     26: #
                     27: ###
                     28: 
                     29: =pod
                     30: 
                     31: =head1 NAME
                     32: 
                     33: lontrackstudent
                     34: 
                     35: =head1 SYNOPSIS
                     36: 
                     37: Track student progress through course materials
                     38: 
                     39: =over 4
                     40: 
                     41: =cut
                     42: 
                     43: package Apache::lontrackstudent;
                     44: 
                     45: use strict;
                     46: use Apache::Constants qw(:common :http);
1.13      matthew    47: use Apache::lonmysql;
1.15      albertel   48: use Apache::lonnet;
1.1       matthew    49: use Apache::lonlocal;
                     50: use Time::HiRes;
1.20      www        51: use lib '/home/httpd/lib/perl/';
                     52: use LONCAPA;
1.1       matthew    53: 
1.16      albertel   54: my $num_records=500;
                     55: 
1.5       matthew    56: sub get_data {
                     57:     my ($r,$prog_state,$navmap,$mode) = @_;
1.2       matthew    58:     ##
                     59:     ## Compose the query
                     60:     &Apache::lonhtmlcommon::Update_PrgWin
                     61:         ($r,$prog_state,&mt('Composing Query'));
                     62:     #
1.9       matthew    63:     # Allow the other server to begin processing the data before we ask for it.
                     64:     sleep(5);
1.10      matthew    65:     #
                     66:     my $max_time = &get_max_time_in_db($r,$prog_state);
                     67:     if (defined($max_time)) {
1.17      www        68:         $r->print('<h3>'.&mt('Activity data compiled up to [_1]',
1.10      matthew    69:                              &Apache::lonlocal::locallocaltime($max_time)).
1.17      www        70:                   '</h3>'.&mt('While data is processed, periodically reload this page for more recent activity').'<br />');
1.10      matthew    71:         $r->rflush();
                     72:     } else {
                     73:         $r->print('<h3>'.&mt('Unable to retrieve any data.  Please reload this page and try again.').'</h3>');
                     74:         return;
                     75:     }
                     76:     my $query = &build_query($mode);
1.2       matthew    77:     ##
                     78:     ## Send it along
1.15      albertel   79:     my $home = $env{'course.'.$env{'request.course.id'}.'.home'};
1.2       matthew    80:     my $reply=&Apache::lonnet::metadata_query($query,undef,undef,[$home]);
                     81:     if (ref($reply) ne 'HASH') {
                     82:         $r->print('<h2>'.
                     83:                   &mt('Error contacting home server for course: [_1]',
                     84:                       $reply).
                     85:                   '</h2>');
                     86:         return;
                     87:     }
                     88:     my $results_file = $r->dir_config('lonDaemons').'/tmp/'.$reply->{$home};
                     89:     my $endfile = $results_file.'.end';
                     90:     ##
                     91:     ## Check for the results
                     92:     &Apache::lonhtmlcommon::Update_PrgWin
                     93:         ($r,$prog_state,&mt('Waiting for results'));
                     94:     my $maxtime = 500;
                     95:     my $starttime = time;
                     96:     while (! -e $endfile && (time-$starttime < $maxtime)) {
1.4       matthew    97:         &Apache::lonhtmlcommon::Update_PrgWin
                     98:             ($r,$prog_state,&mt('Waiting up to [_1] seconds for results',
                     99:                                 $starttime+$maxtime-time));
1.2       matthew   100:         sleep(1);
                    101:     }
                    102:     if (! -e $endfile) {
                    103:         $r->print('<h2>'.
                    104:                   &mt('Unable to retrieve data.').'</h2>');
                    105:         $r->print(&mt('Please try again in a few minutes.'));
                    106:         return;
                    107:     }
1.5       matthew   108:     $r->rflush();
1.10      matthew   109:     #
1.2       matthew   110:     &Apache::lonhtmlcommon::Update_PrgWin
                    111:         ($r,$prog_state,&mt('Parsing results'));
1.10      matthew   112:     #
1.22    ! albertel  113:     my $last = &output_results($r,$results_file,$navmap,$mode);
1.16      albertel  114:     my ($sname,$sdom) = ($mode=~/^student:(.*):(.*)$/);
1.22    ! albertel  115:     
        !           116:     my ($text,$inc);
        !           117:     if ( $last > 0 && (($last+1) >= $env{'form.start'}+$num_records) ) {
        !           118: 	$text = 'View more activity by this student';
        !           119: 	$inc  = $num_records;
        !           120: 	$r->print(&Apache::loncommon::track_student_link($text,$sname,$sdom,undef,
        !           121: 							 ($env{'form.start'}+$inc)
        !           122: 							 ));
        !           123: 	$r->print('<br />');
        !           124:     }
        !           125:     $text = 'Resubmit last request to check for newer data';
        !           126:     $r->print(&Apache::loncommon::track_student_link($text,$sname,$sdom,undef,
        !           127: 						     $env{'form.start'}));
1.16      albertel  128: 
1.5       matthew   129:     &Apache::lonhtmlcommon::Update_PrgWin($r,$prog_state,&mt('Finished!'));
1.4       matthew   130:     return;
                    131: }
                    132: 
1.10      matthew   133: sub table_names {
1.15      albertel  134:     my $cid = $env{'request.course.id'};
                    135:     my $domain = $env{'course.'.$cid.'.domain'};
                    136:     my $home = $env{'course.'.$cid.'.home'};
                    137:     my $course = $env{'course.'.$cid.'.num'};
1.10      matthew   138:     my $prefix = $course.'_'.$domain.'_';
                    139:     #
                    140:     my %tables = 
1.13      matthew   141:         ( student =>&Apache::lonmysql::fix_table_name($prefix.'students'),
                    142:           res     =>&Apache::lonmysql::fix_table_name($prefix.'resource'),
                    143:           machine =>&Apache::lonmysql::fix_table_name($prefix.'machine_table'),
                    144:           activity=>&Apache::lonmysql::fix_table_name($prefix.'activity'),
1.10      matthew   145:           );
                    146:     return %tables;
                    147: }
                    148: 
                    149: sub get_max_time_in_db {
                    150:     my ($r,$prog_state) = @_;
                    151:     my %table = &table_names();
                    152:     my $query = qq{SELECT MAX(time) FROM $table{'activity'} };
                    153:     #
1.15      albertel  154:     my $home = $env{'course.'.$env{'request.course.id'}.'.home'};
1.10      matthew   155:     my $reply=&Apache::lonnet::metadata_query($query,undef,undef,[$home]);
                    156:     if (ref($reply) ne 'HASH') {
                    157:         return undef;
                    158:     }
                    159:     my $results_file = $r->dir_config('lonDaemons').'/tmp/'.$reply->{$home};
                    160:     my $endfile = $results_file.'.end';
                    161:     ##
                    162:     ## Check for the results
                    163:     &Apache::lonhtmlcommon::Update_PrgWin
                    164:         ($r,$prog_state,&mt('Waiting for results'));
                    165:     my $maxtime = 500;
                    166:     my $starttime = time;
                    167:     while (! -e $endfile && (time-$starttime < $maxtime)) {
                    168:         &Apache::lonhtmlcommon::Update_PrgWin
                    169:             ($r,$prog_state,&mt('Waiting up to [_1] seconds for results',
                    170:                                 $starttime+$maxtime-time));
                    171:         sleep(1);
                    172:     }
                    173:     if (! -e $endfile) {
                    174:         $r->print('<h2>'.
                    175:                   &mt('Unable to retrieve data.').'</h2>');
                    176:         $r->print(&mt('Please try again in a few minutes.'));
                    177:         return undef;
                    178:     }
                    179:     $r->rflush();
                    180:     #
                    181:     &Apache::lonhtmlcommon::Update_PrgWin
                    182:         ($r,$prog_state,&mt('Parsing results'));
                    183:     #
                    184:     if (! open(TIMEDATA,$results_file)) {
                    185:         $r->print('<h2>'.&mt('Unable to read results file.').'</h2>'.
                    186:                   '<p>'.
                    187:                   &mt('This is a serious error and has been logged.  '.
                    188:                       'You should contact your system administrator '.
                    189:                       'to resolve this issue.').
                    190:                   '</p>');
                    191:         return;
                    192:     }
                    193:     #
                    194:     my $timestr = '';
                    195:     while (my $line = <TIMEDATA>) {
                    196:         chomp($line);
1.20      www       197:         $timestr = &unescape($line);
1.10      matthew   198:     }
                    199:     close(TIMEDATA);
1.12      matthew   200:     return &Apache::lonmysql::unsqltime($timestr);
1.10      matthew   201: }
                    202: 
1.5       matthew   203: sub build_query {
                    204:     my ($mode) = @_;
1.15      albertel  205:     my $cid = $env{'request.course.id'};
                    206:     my $domain = $env{'course.'.$cid.'.domain'};
                    207:     my $home = $env{'course.'.$cid.'.home'};
                    208:     my $course = $env{'course.'.$cid.'.num'};
1.5       matthew   209:     my $prefix = $course.'_'.$domain.'_';
1.16      albertel  210:     my $start = ($env{'form.start'}+0);
1.5       matthew   211:     #
1.10      matthew   212:     my %table = &table_names();
1.5       matthew   213:     #
                    214:     my $query;
                    215:     if ($mode eq 'full_class') {
                    216:         $query = qq{
                    217:         SELECT B.resource,A.time,C.student,A.action,E.machine,A.action_values 
1.10      matthew   218:             FROM $table{'activity'} AS A
                    219:             LEFT JOIN $table{'res'}      AS B ON B.res_id=A.res_id 
                    220:             LEFT JOIN $table{'student'}  AS C ON C.student_id=A.student_id 
                    221:             LEFT JOIN $table{'machine'}  AS E ON E.machine_id=A.machine_id
1.5       matthew   222:             ORDER BY A.time DESC
1.16      albertel  223:             LIMIT $start, $num_records
1.5       matthew   224:         };
                    225:     } elsif ($mode =~ /^student:(.*):(.*)$/) {
                    226:         my $student = $1.':'.$2;
                    227:         $query = qq{
1.6       matthew   228:             SELECT B.resource,A.time,A.action,E.machine,A.action_values 
1.10      matthew   229:                 FROM $table{'activity'} AS A
                    230:                 LEFT JOIN $table{'res'}      AS B ON B.res_id=A.res_id 
                    231:                 LEFT JOIN $table{'student'}  AS C ON C.student_id=A.student_id 
                    232:                 LEFT JOIN $table{'machine'}  AS E ON E.machine_id=A.machine_id
1.6       matthew   233:                 WHERE C.student='$student'
                    234:                 ORDER BY A.time DESC
1.16      albertel  235:                 LIMIT $start, $num_records
1.6       matthew   236:             };
1.5       matthew   237:     }
                    238:     $query =~ s|$/||g;
                    239:     return $query;
                    240: }
                    241: 
                    242: ###################################################################
                    243: ###################################################################
1.4       matthew   244: sub output_results {
1.5       matthew   245:     my ($r,$results_file,$navmap,$mode) = @_;
1.6       matthew   246:     ##
                    247:     ##
1.12      matthew   248:     if (! -s $results_file) {
                    249:         # results file is empty, just let them know there is no data
1.17      www       250:         $r->print('<h2>'.&mt('So far, no data has been returned for your request').'</h2>');
1.22    ! albertel  251:         return -1;
1.12      matthew   252:     }
1.2       matthew   253:     if (! open(ACTIVITYDATA,$results_file)) {
1.4       matthew   254:         $r->print('<h2>'.&mt('Unable to read results file.').'</h2>'.
                    255:                   '<p>'.
                    256:                   &mt('This is a serious error and has been logged.  '.
                    257:                       'You should contact your system administrator '.
                    258:                       'to resolve this issue.').
                    259:                   '</p>');
1.22    ! albertel  260:         return -2;
1.2       matthew   261:     }
1.6       matthew   262:     ##
                    263:     ##
1.5       matthew   264:     my $tableheader;
                    265:     if ($mode eq 'full_class') { 
                    266:         $tableheader = 
                    267:             '<table><tr>'.
                    268:             '<th>'.&mt('Resource').'</th>'.
                    269:             '<th>'.&mt('Time').'</th>'.
                    270:             '<th>'.&mt('Student').'</th>'.
                    271:             '<th>'.&mt('Action').'</th>'.
1.6       matthew   272:  #           '<th>'.&mt('Originating Server').'</th>'.
                    273:             '<th align="left">'.&mt('Data').'</th>'.
                    274:             '</tr>'.$/;
                    275:     } elsif ($mode =~ /^student:(.*):(.*)$/) {
                    276:         $tableheader = 
                    277:             '<table><tr>'.
                    278:             '<th>'.&mt('Resource').'</th>'.
                    279:             '<th>'.&mt('Time').'</th>'.
                    280:             '<th>'.&mt('Action').'</th>'.
                    281:  #           '<th>'.&mt('Originating Server').'</th>'.
                    282:             '<th align="left">'.&mt('Data').'</th>'.
1.5       matthew   283:             '</tr>'.$/;
                    284:     }
1.16      albertel  285:     my $count = $env{'form.start'}-1;
1.2       matthew   286:     $r->rflush();
1.6       matthew   287:     ##
                    288:     ##
1.2       matthew   289:     while (my $line = <ACTIVITYDATA>) {
1.10      matthew   290:         # FIXME: does not pass symbs along :(
1.6       matthew   291:         chomp($line);
1.20      www       292:         $line = &unescape($line);
1.2       matthew   293:         if (++$count % 50 == 0) {
1.5       matthew   294:             if ($count != 0) { 
                    295:                 $r->print('</table>'.$/);
                    296:                 $r->rflush();
                    297:             }
1.2       matthew   298:             $r->print($tableheader);
                    299:         }
1.5       matthew   300:         my ($symb,$timestamp,$student,$action,$machine,$values);
                    301:         if ($mode eq 'full_class') {
1.11      albertel  302:             ($symb,$timestamp,$student,$action,$machine,$values) = split(',',$line,6);
1.5       matthew   303:         } else {
1.11      albertel  304:             ($symb,$timestamp,$action,$machine,$values) = split(',',$line,5);
1.5       matthew   305:         }
1.11      albertel  306: 	foreach ($symb,$timestamp,$student,$action,$machine) {
1.20      www       307: 	    $_=&unescape($_);
1.11      albertel  308: 	}
1.2       matthew   309:         my ($title,$src);
1.4       matthew   310:         if ($symb =~ m:^/adm/:) {
1.2       matthew   311:             $title = $symb;
                    312:             $src = $symb;
                    313:         } else {
1.4       matthew   314:             my $nav_res = $navmap->getBySymb($symb);
                    315:             if (defined($nav_res)) {
1.11      albertel  316:                 $title = $nav_res->compTitle();
1.4       matthew   317:                 $src   = $nav_res->src();
                    318:             } else {
1.6       matthew   319:                 if ($src =~ m|^/res|) {
                    320:                     $title = $src;
                    321:                 } elsif ($values =~ /^\s*$/ && 
                    322:                          (! defined($src) || $src =~ /^\s*$/)) {
                    323:                     next;
                    324:                 } elsif ($values =~ /^\s*$/) {
                    325:                     $values = $src;
                    326:                 } else {
                    327:                     $title = 'unable to retrieve title';
                    328:                     $src   = '/dev/null';
                    329:                 }
1.4       matthew   330:             }
1.2       matthew   331:         }
1.6       matthew   332:         my %classes;
                    333:         my $class_count=0;
                    334:         if (! exists($classes{$symb})) {
                    335:             $classes{$symb} = $class_count++;
                    336:         }
                    337:         my $class = 'a';#.$classes{$symb};
1.4       matthew   338:         #
1.5       matthew   339:         if ($symb eq '/prtspool/') {
1.4       matthew   340:             $class = 'print';
                    341:             $title = 'retrieve printout';
                    342:         } elsif ($symb =~ m|^/adm/([^/]+)|) {
                    343:             $class = $1;
                    344:         } elsif ($symb =~ m|^/adm/|) {
                    345:             $class = 'adm';
                    346:         }
                    347:         if ($title eq 'unable to retrieve title') {
                    348:             $title =~ s/ /\&nbsp;/g;
                    349:             $class = 'warning';
                    350:         }
                    351:         if (! defined($title) || $title eq '') {
                    352:             $title = 'untitled';
                    353:             $class = 'warning';
                    354:         }
1.6       matthew   355:         # Clean up the values
1.11      albertel  356: 	$values = &display_values($action,$values);
1.6       matthew   357:         #
                    358:         # Build the row for output
1.16      albertel  359:         my $tablerow = qq{<tr class="$class"><td>}.($count+1).qq{</td>};
1.6       matthew   360:         if ($src =~ m|^/adm/|) {
                    361:             $tablerow .= 
1.11      albertel  362:                 '<td valign="top"><nobr>'.$title.'</nobr></td>';
1.6       matthew   363:         } else {
                    364:             $tablerow .= 
1.11      albertel  365:                 '<td valign="top"><nobr>'.
1.6       matthew   366:                 '<a href="'.$src.'">'.$title.'</a>'.
                    367:                 '</nobr></td>';
1.5       matthew   368:         }
1.11      albertel  369:         $tablerow .= '<td valign="top"><nobr>'.$timestamp.'</nobr></td>';
1.5       matthew   370:         if ($mode eq 'full_class') {
1.11      albertel  371:             $tablerow.='<td valign="top">'.$student.'</td>';
1.5       matthew   372:         }
1.6       matthew   373:         $tablerow .= 
1.11      albertel  374:             '<td valign="top">'.$action.'</td>'.
1.6       matthew   375: #            '<td>'.$machine.'</td>'.
1.11      albertel  376:             '<td valign="top">'.$values.'</td>'.
1.6       matthew   377:             '</tr>';
                    378:         $r->print($tablerow.$/);
1.2       matthew   379:     }
1.16      albertel  380:     $r->print('</table>'.$/);### if (! $count % 50);
1.2       matthew   381:     close(ACTIVITYDATA);
1.22    ! albertel  382:     return $count;
1.2       matthew   383: }
                    384: 
1.5       matthew   385: ###################################################################
                    386: ###################################################################
1.11      albertel  387: sub display_values {
                    388:     my ($action,$values)=@_;
                    389:     my $result='<table>';
                    390:     if ($action eq 'CSTORE') {
                    391: 	my %values=map {split('=',$_,-1)} split(/\&/,$values);
                    392: 	foreach my $key (sort(keys(%values))) {
                    393: 	    $result.='<tr><td align="right">'.
1.20      www       394: 		&unescape($key).
1.11      albertel  395: 		'</td><td>=</td><td align="left">'.
1.20      www       396: 		&unescape($values{$key}).'</td></tr>';
1.11      albertel  397: 	}
                    398: 	$result.='</table>';
                    399:     } elsif ($action eq 'POST') {
                    400: 	my %values=
1.20      www       401: 	    map {split('=',&unescape($_),-1)} split(/\&/,$values);
1.11      albertel  402: 	foreach my $key (sort(keys(%values))) {
                    403: 	    if ($key eq 'counter') { next; }
                    404: 	    $result.='<tr><td align="right">'.$key.'</td>'.
                    405: 		'<td>=</td><td align="left">'.$values{$key}.'</td></tr>';
                    406: 	}
                    407: 	$result.='</table>';
                    408:     } else {
1.20      www       409: 	$result=&unescape($values)
1.11      albertel  410:     }
                    411:     return $result;
                    412: }
                    413: ###################################################################
                    414: ###################################################################
1.1       matthew   415: sub request_data_update {
                    416:     my $command = 'prepare activity log';
1.15      albertel  417:     my $cid = $env{'request.course.id'};
                    418:     my $domain = $env{'course.'.$cid.'.domain'};
                    419:     my $home = $env{'course.'.$cid.'.home'};
                    420:     my $course = $env{'course.'.$cid.'.num'};
1.6       matthew   421: #    &Apache::lonnet::logthis($command.' '.$course.' '.$domain.' '.$home);
1.1       matthew   422:     my $result = &Apache::lonnet::metadata_query($command,$course,$domain,
                    423:                                                  [$home]);
                    424:     return $result;
                    425: }
                    426: 
                    427: ###################################################################
                    428: ###################################################################
1.5       matthew   429: sub pick_student {
                    430:     my ($r) = @_;
                    431:     $r->print("Sorry, cannot display classlist at this time.  Come back another time.");
                    432:     return;
                    433: }
1.1       matthew   434: 
1.5       matthew   435: ###################################################################
                    436: ###################################################################
1.4       matthew   437: sub styles {
                    438:     return <<END;
1.5       matthew   439: <style type="text/css">
1.6       matthew   440:     tr.warning   { background-color: \#CCCCCC; }
                    441:     tr.chat      { background-color: \#CCCCCC; }
                    442:     tr.chatfetch { background-color: \#CCCCCC; }
                    443:     tr.navmaps   { background-color: \#CCCCCC; }
                    444:     tr.roles     { background-color: \#CCCCCC; }
                    445:     tr.flip      { background-color: \#CCCCCC; }
                    446:     tr.adm       { background-color: \#CCCCCC; }
                    447:     tr.print     { background-color: \#CCCCCC; }
                    448:     tr.printout  { background-color: \#CCCCCC; }
                    449:     tr.parmset   { background-color: \#CCCCCC; }
                    450:     tr.grades    { background-color: \#CCCCCC; }
                    451: </style>
                    452: END
                    453: } 
                    454: 
                    455: sub developer_centric_styles {
                    456:     return <<END;
                    457: <style type="text/css">
1.4       matthew   458:     tr.warning   { background-color: red; }
                    459:     tr.chat      { background-color: yellow; }
                    460:     tr.chatfetch { background-color: yellow; }
1.7       matthew   461:     tr.evaluate  { background-color: red; }
1.4       matthew   462:     tr.navmaps   { background-color: \#777777; }
                    463:     tr.roles     { background-color: \#999999; }
                    464:     tr.flip      { background-color: \#BBBBBB; }
                    465:     tr.adm       { background-color: green; }
                    466:     tr.print     { background-color: blue; }
1.6       matthew   467:     tr.parmset   { background-color: \#000088; }
1.4       matthew   468:     tr.printout  { background-color: blue; }
1.6       matthew   469:     tr.grades    { background-color: \#CCCCCC; }
1.5       matthew   470: </style>
1.4       matthew   471: END
                    472: }
1.1       matthew   473: 
                    474: ###################################################################
                    475: ###################################################################
                    476: sub handler {
                    477:     my $r=shift;
                    478:     my $c = $r->connection();
                    479:     #
                    480:     # Check for overloading here and on the course home server
                    481:     my $loaderror=&Apache::lonnet::overloaderror($r);
                    482:     if ($loaderror) { return $loaderror; }
                    483:     $loaderror=
                    484:         &Apache::lonnet::overloaderror
                    485:         ($r,
1.15      albertel  486:          $env{'course.'.$env{'request.course.id'}.'.home'});
1.1       matthew   487:     if ($loaderror) { return $loaderror; }
                    488:     #
                    489:     # Check for access
1.15      albertel  490:     if (! &Apache::lonnet::allowed('vsa',$env{'request.course.id'})) {
                    491:         $env{'user.error.msg'}=
1.1       matthew   492:             $r->uri.":vsa:0:0:Cannot student activity for complete course";
                    493:         if (! 
                    494:             &Apache::lonnet::allowed('vsa',
1.15      albertel  495:                                      $env{'request.course.id'}.'/'.
                    496:                                      $env{'request.course.sec'})) {
                    497:             $env{'user.error.msg'}=
1.1       matthew   498:                 $r->uri.":vsa:0:0:Cannot view student activity with given role";
                    499:             return HTTP_NOT_ACCEPTABLE;
                    500:         }
                    501:     }
                    502:     #
                    503:     # Send the header
                    504:     &Apache::loncommon::no_cache($r);
                    505:     &Apache::loncommon::content_type($r,'text/html');
                    506:     $r->send_http_header;
                    507:     if ($r->header_only) { return OK; }
                    508:     #
                    509:     # Extract form elements from query string
                    510:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.16      albertel  511:                                             ['selected_student','start']);
1.1       matthew   512:     #
1.2       matthew   513:     # We will almost always need this...
                    514:     my $navmap = Apache::lonnavmaps::navmap->new();
1.1       matthew   515:     # 
                    516:     &Apache::lonhtmlcommon::clear_breadcrumbs();
                    517:     &Apache::lonhtmlcommon::add_breadcrumb({href=>'/adm/studentactivity',
                    518:                                             title=>'Student Activity',
                    519:                                             text =>'Student Activity',
                    520:                                             faq=>139,
                    521:                                             bug=>'instructor interface'});
                    522:     #
1.2       matthew   523:     # Give the LON-CAPA page header
1.18      albertel  524:     $r->print(&Apache::loncommon::start_page('Student Activity',&styles()).
1.19      albertel  525:               &Apache::lonhtmlcommon::breadcrumbs('Student Activity'));
1.2       matthew   526:     $r->rflush();
                    527:     #
1.1       matthew   528:     # Begin form output
1.2       matthew   529:     $r->print('<form name="trackstudent" method="post" action="/adm/trackstudent">');
                    530:     $r->print('<br />');
                    531:     $r->print('<div name="statusline">'.
                    532:               &mt('Status:[_1]',
                    533:                   '<input type="text" name="status" size="60" value="" />').
                    534:               '</div>');
1.1       matthew   535:     $r->rflush();
1.2       matthew   536:     my %prog_state=&Apache::lonhtmlcommon::Create_PrgWin
                    537:         ($r,&mt('Student Activity Retrieval'),
                    538:          &mt('Student Activity Retrieval'),undef,'inline',undef,
                    539:          'trackstudent','status');
                    540:     &Apache::lonhtmlcommon::Update_PrgWin
                    541:         ($r,\%prog_state,&mt('Contacting course home server'));
1.1       matthew   542:     #
                    543:     my $result = &request_data_update();
                    544:     #
1.15      albertel  545:     if (exists($env{'form.selected_student'})) {
1.4       matthew   546:         # For now, just show all the data, in the future allow selection of
                    547:         # a student
1.15      albertel  548:         my ($sname,$sdom) = split(':',$env{'form.selected_student'});
1.21      albertel  549:         if ($sname =~ /^$LONCAPA::username_re$/ 
                    550: 	    && $sdom =~ /^$LONCAPA::domain_re$/) {
1.6       matthew   551:             $r->print('<h2>'.
1.21      albertel  552:                       &mt('Recent activity of [_1]:[_2]',$sname,$sdom).
1.6       matthew   553:                       '</h2>');
1.8       matthew   554:             $r->print('<p>'.&mt(<<END).'</p>');
                    555: Compiling student activity data can take a long time.
1.17      www       556: Your request continues to be processed while results are displayed.
1.8       matthew   557: END
1.6       matthew   558:             &get_data($r,\%prog_state,$navmap,
1.15      albertel  559:                       'student:'.$env{'form.selected_student'});
1.6       matthew   560:         } else {
1.21      albertel  561:             $r->print('<h2>'.&mt('Unable to process for [_1]:[_2]',
1.6       matthew   562:                                  $sname,$sdom).'</h2>');
                    563:         }
1.1       matthew   564:     } else {
1.4       matthew   565:         # For now, just show all the data instead of limiting it to one student
1.5       matthew   566:         &get_data($r,\%prog_state,$navmap,'full_class');
1.1       matthew   567:     }
                    568:     #
1.4       matthew   569:     &Apache::lonhtmlcommon::Update_PrgWin($r,\%prog_state,&mt('Done'));
                    570:     &Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state);
1.2       matthew   571:     #
1.1       matthew   572:     $r->print("</form>\n");
1.18      albertel  573:     $r->print(&Apache::loncommon::end_page());
1.1       matthew   574:     $r->rflush();
                    575:     #
                    576:     return OK;
                    577: }
                    578: 
                    579: 1;
                    580: 
                    581: #######################################################
                    582: #######################################################
                    583: 
                    584: =pod
                    585: 
                    586: =back
                    587: 
                    588: =cut
                    589: 
                    590: #######################################################
                    591: #######################################################
                    592: 
                    593: __END__
                    594: 

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>