File:  [LON-CAPA] / loncom / interface / lontrackstudent.pm
Revision 1.38: download - view: text, annotated - select for diffs
Mon Nov 24 02:36:30 2014 UTC (9 years, 5 months ago) by raeburn
Branches: MAIN
CVS tags: version_2_11_2_uiuc, version_2_11_2_educog, version_2_11_2, version_2_11_1, HEAD
- Bug 6740 Out-of-order recording of submissions (by time).
  - Check for new transactions made immediately before call to lonnet::cstore()
    &Apache::inputtags::hidealldata() called if correct then incorrect,
    where awarded >= 1 when correct (feedback on correctness enabled).
  - Check for transactions made immediately after call to lonnet::cstore()
    if reply from lond::store_handler() is delay:N (where N s the number of
    transactions between the last retrieved in &initialize_storage() and the
    last stored immediately before permanent storage of the current transaction.
    &Apache::grades::makehidden() called if correct then incorrect,
    where awarded >= 1 when correct (feedback on correctness enabled).

    1: # The LearningOnline Network with CAPA
    2: #
    3: # $Id: lontrackstudent.pm,v 1.38 2014/11/24 02:36:30 raeburn Exp $
    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);
   47: use Apache::lonmysql;
   48: use Apache::lonnet;
   49: use Apache::lonlocal;
   50: use Time::HiRes;
   51: use DateTime();
   52: use lib '/home/httpd/lib/perl/';
   53: use LONCAPA;
   54: 
   55: my $num_records=500;
   56: 
   57: sub get_data {
   58:     my ($r,$prog_state,$navmap,$mode) = @_;
   59:     ##
   60:     ## Compose the query
   61:     &Apache::lonhtmlcommon::Update_PrgWin
   62:         ($r,$prog_state,&mt('Composing Query'));
   63:     #
   64:     # Allow the other server to begin processing the data before we ask for it.
   65:     sleep(5);
   66:     #
   67:     my $max_time = &get_max_time_in_db($r,$prog_state);
   68:     if (defined($max_time)) {
   69:         $r->print('<h3>'.&mt('Activity data compiled up to [_1]',
   70:                              &Apache::lonlocal::locallocaltime($max_time)).
   71:                   '</h3>'.&mt('While data is processed, periodically reload this page for more recent activity').'<br />');
   72:         $r->rflush();
   73:     } else {
   74:         $r->print('<h3>'.&mt('Unable to retrieve any data.  Please reload this page and try again.').'</h3>');
   75:         return;
   76:     }
   77:     my $query = &build_query($mode);
   78:     ##
   79:     ## Send it along
   80:     my $home = $env{'course.'.$env{'request.course.id'}.'.home'};
   81:     my $reply=&Apache::lonnet::metadata_query($query,undef,undef,[$home]);
   82:     if (ref($reply) ne 'HASH') {
   83:         $r->print('<h2>'.
   84:                   &mt('Error contacting home server for course: [_1]',
   85:                       $reply).
   86:                   '</h2>');
   87:         return;
   88:     }
   89:     my $results_file = $r->dir_config('lonDaemons').'/tmp/'.$reply->{$home};
   90:     my $endfile = $results_file.'.end';
   91:     ##
   92:     ## Check for the results
   93:     &Apache::lonhtmlcommon::Update_PrgWin
   94:         ($r,$prog_state,&mt('Waiting for results'));
   95:     my $maxtime = 500;
   96:     my $starttime = time;
   97:     while (! -e $endfile && (time-$starttime < $maxtime)) {
   98:         &Apache::lonhtmlcommon::Update_PrgWin
   99:             ($r,$prog_state,&mt('Waiting up to [_1] seconds for results',
  100:                                 $starttime+$maxtime-time));
  101:         sleep(1);
  102:     }
  103:     if (! -e $endfile) {
  104:         $r->print('<h2>'.
  105:                   &mt('Unable to retrieve data.').'</h2>');
  106:         $r->print(&mt('Please try again in a few minutes.'));
  107:         return;
  108:     }
  109:     $r->rflush();
  110:     #
  111:     &Apache::lonhtmlcommon::Update_PrgWin
  112:         ($r,$prog_state,&mt('Parsing results'));
  113:     #
  114:     my $last = &output_results($r,$results_file,$navmap,$mode);
  115:     my ($sname,$sdom) = ($mode=~/^student:(.*):(.*)$/);
  116:     
  117:     my ($text,$inc);
  118:     if ( $last > 0 && (($last+1) >= $env{'form.start'}+$num_records) ) {
  119: 	$text = 'View more activity by this student';
  120: 	$inc  = $num_records;
  121: 	$r->print(&Apache::loncommon::track_student_link($text,$sname,$sdom,undef,
  122: 							 ($env{'form.start'}+$inc),
  123:                                                          $env{'form.only_body'}
  124: 							 ));
  125: 	$r->print('<br />');
  126:     }
  127:     $r->print('<hr />');
  128:     $text = 'Resubmit last request to check for newer data';
  129:     $r->print(&Apache::loncommon::track_student_link($text,$sname,$sdom,undef,
  130: 						     $env{'form.start'},
  131:                                                      $env{'form.only_body'}));
  132: 
  133:     &Apache::lonhtmlcommon::Update_PrgWin($r,$prog_state,&mt('Finished!'));
  134:     return;
  135: }
  136: 
  137: sub table_names {
  138:     my $cid = $env{'request.course.id'};
  139:     my $domain = $env{'course.'.$cid.'.domain'};
  140:     my $home = $env{'course.'.$cid.'.home'};
  141:     my $course = $env{'course.'.$cid.'.num'};
  142:     my $prefix = $course.'_'.$domain.'_';
  143:     #
  144:     my %tables = 
  145:         ( student =>&Apache::lonmysql::fix_table_name($prefix.'students'),
  146:           res     =>&Apache::lonmysql::fix_table_name($prefix.'resource'),
  147:           machine =>&Apache::lonmysql::fix_table_name($prefix.'machine_table'),
  148:           activity=>&Apache::lonmysql::fix_table_name($prefix.'activity'),
  149:           );
  150:     return %tables;
  151: }
  152: 
  153: sub get_max_time_in_db {
  154:     my ($r,$prog_state) = @_;
  155:     my %table = &table_names();
  156:     my $query = qq{SELECT MAX(time) FROM $table{'activity'} };
  157:     #
  158:     my $home = $env{'course.'.$env{'request.course.id'}.'.home'};
  159:     my $reply=&Apache::lonnet::metadata_query($query,undef,undef,[$home]);
  160:     if (ref($reply) ne 'HASH') {
  161:         return undef;
  162:     }
  163:     my $results_file = $r->dir_config('lonDaemons').'/tmp/'.$reply->{$home};
  164:     my $endfile = $results_file.'.end';
  165:     ##
  166:     ## Check for the results
  167:     &Apache::lonhtmlcommon::Update_PrgWin
  168:         ($r,$prog_state,&mt('Waiting for results'));
  169:     my $maxtime = 500;
  170:     my $starttime = time;
  171:     while (! -e $endfile && (time-$starttime < $maxtime)) {
  172:         &Apache::lonhtmlcommon::Update_PrgWin
  173:             ($r,$prog_state,&mt('Waiting up to [_1] seconds for results',
  174:                                 $starttime+$maxtime-time));
  175:         sleep(1);
  176:     }
  177:     if (! -e $endfile) {
  178:         $r->print('<h2>'.
  179:                   &mt('Unable to retrieve data.').'</h2>');
  180:         $r->print(&mt('Please try again in a few minutes.'));
  181:         return undef;
  182:     }
  183:     $r->rflush();
  184:     #
  185:     &Apache::lonhtmlcommon::Update_PrgWin
  186:         ($r,$prog_state,&mt('Parsing results'));
  187:     #
  188:     if (! open(TIMEDATA,$results_file)) {
  189:         $r->print('<p class="LC_error">'.&mt('Unable to read results file.').'</p>'.
  190:                   '<p>'.
  191:                   &mt('This is a serious error and has been logged.').
  192:                   '<br />'.
  193:                   &mt('Please alert your LON-CAPA administrator.').
  194:                   '</p>');
  195:         return;
  196:     }
  197:     #
  198:     my $timestr = '';
  199:     while (my $line = <TIMEDATA>) {
  200:         chomp($line);
  201:         $timestr = &unescape($line);
  202:     }
  203:     close(TIMEDATA);
  204:     return &Apache::lonmysql::unsqltime($timestr);
  205: }
  206: 
  207: sub build_query {
  208:     my ($mode) = @_;
  209:     my $cid = $env{'request.course.id'};
  210:     my $domain = $env{'course.'.$cid.'.domain'};
  211:     my $home = $env{'course.'.$cid.'.home'};
  212:     my $course = $env{'course.'.$cid.'.num'};
  213:     my $prefix = $course.'_'.$domain.'_';
  214:     my $start = ($env{'form.start'}+0);
  215:     #
  216:     my %table = &table_names();
  217:     #
  218:     my $query;
  219:     if ($mode eq 'full_class') {
  220:         $query = qq{
  221:         SELECT B.resource,A.time,C.student,A.action,E.machine,A.action_values 
  222:             FROM $table{'activity'} AS A
  223:             LEFT JOIN $table{'res'}      AS B ON B.res_id=A.res_id 
  224:             LEFT JOIN $table{'student'}  AS C ON C.student_id=A.student_id 
  225:             LEFT JOIN $table{'machine'}  AS E ON E.machine_id=A.machine_id
  226:             ORDER BY A.time DESC
  227:             LIMIT $start, $num_records
  228:         };
  229:     } elsif ($mode =~ /^student:(.*):(.*)$/) {
  230:         my $student = $1.':'.$2;
  231:         $query = qq{
  232:             SELECT B.resource,A.time,A.action,E.machine,A.action_values 
  233:                 FROM $table{'activity'} AS A
  234:                 LEFT JOIN $table{'res'}      AS B ON B.res_id=A.res_id 
  235:                 LEFT JOIN $table{'student'}  AS C ON C.student_id=A.student_id 
  236:                 LEFT JOIN $table{'machine'}  AS E ON E.machine_id=A.machine_id
  237:                 WHERE C.student='$student'
  238:                 ORDER BY A.time DESC
  239:                 LIMIT $start, $num_records
  240:             };
  241:     }
  242:     $query =~ s|$/||g;
  243:     return $query;
  244: }
  245: 
  246: ###################################################################
  247: ###################################################################
  248: sub output_results {
  249:     my ($r,$results_file,$navmap,$mode) = @_;
  250:     ##
  251:     ##
  252:     if (! -s $results_file) {
  253:         # results file is empty, just let them know there is no data
  254:         $r->print('<p class="LC_info">'.&mt('So far, no data has been returned for your request').'</p>');
  255:         return -1;
  256:     }
  257:     if (! open(ACTIVITYDATA,$results_file)) {
  258:         $r->print('<p class="LC_error">'.&mt('Unable to read results file.').'</p>'.
  259:                   '<p>'.
  260:                   &mt('This is a serious error and has been logged.').
  261:                   '<br />'.
  262:                   &mt('Please alert your LON-CAPA administrator.').
  263:                   '</p>');
  264:         return -2;
  265:     }
  266:     ##
  267:     ##
  268:     my $tableheader;
  269:     if ($mode eq 'full_class') { 
  270:         $tableheader = 
  271:             '<table><tr>'.
  272:             '<th>&nbsp;</th>'.
  273:             '<th>'.&mt('Resource').'</th>'.
  274:             '<th>'.&mt('Time').'</th>'.
  275:             '<th>'.&mt('Student').'</th>'.
  276:             '<th>'.&mt('Action').'</th>'.
  277:  #           '<th>'.&mt('Originating Server').'</th>'.
  278:             '<th align="left">'.&mt('Data').'</th>'.
  279:             '</tr>'.$/;
  280:     } elsif ($mode =~ /^student:(.*):(.*)$/) {
  281:         $tableheader = 
  282:             '<table><tr>'.
  283:             '<th>&nbsp;</th>'.
  284:             '<th>'.&mt('Resource').'</th>'.
  285:             '<th>'.&mt('Time').'</th>'.
  286:             '<th>'.&mt('Action').'</th>'.
  287:  #           '<th>'.&mt('Originating Server').'</th>'.
  288:             '<th align="left">'.&mt('Data').'</th>'.
  289:             '</tr>'.$/;
  290:     }
  291:     my $count = $env{'form.start'}-1;
  292:     $r->rflush();
  293:     ##
  294:     ##
  295: 
  296:     my $cid = $env{'request.course.id'};
  297:     my $cnum = $env{'course.'.$cid.'.num'};
  298:     my $cdom = $env{'course.'.$cid.'.domain'};   
  299:     my $server_timezone = &Apache::lonnet::get_server_timezone($cnum,$cdom);
  300:     if ($server_timezone ne '') {
  301:         if (&Apache::lonlocal::gettimezone($server_timezone) eq 'local') {
  302:             $server_timezone = '';
  303:         }
  304:     }
  305: 
  306:     while (my $line = <ACTIVITYDATA>) {
  307:         # FIXME: does not pass symbs along :(
  308:         chomp($line);
  309:         $line = &unescape($line);
  310:         if (++$count % 50 == 0) {
  311:             if ($count != 0) { 
  312:                 $r->print('</table>'.$/);
  313:                 $r->rflush();
  314:             }
  315:             $r->print($tableheader);
  316:         }
  317:         my ($symb,$timestamp,$student,$action,$machine,$values);
  318:         if ($mode eq 'full_class') {
  319:             ($symb,$timestamp,$student,$action,$machine,$values) = split(',',$line,6);
  320:         } else {
  321:             ($symb,$timestamp,$action,$machine,$values) = split(',',$line,5);
  322:         }
  323: 	foreach ($symb,$timestamp,$student,$action,$machine) {
  324: 	    $_=&unescape($_);
  325: 	}
  326:         my ($title,$src);
  327:         if ($symb =~ m:^/adm/:) {
  328:             $title = $symb;
  329:             $src = $symb;
  330:         } else {
  331:             my $nav_res = $navmap->getBySymb($symb);
  332:             if (defined($nav_res)) {
  333:                 $title = $nav_res->compTitle();
  334:                 $src   = $nav_res->src();
  335:             } else {
  336: 		$src = $symb;
  337: 		if ($src !~ m{/adm}) {
  338: 		    $title = &Apache::lonnet::gettitle($src);
  339: 		} elsif ($values =~ /^\s*$/ && 
  340: 		    (! defined($src) || $src =~ /^\s*$/)) {
  341:                     next;
  342:                 } elsif ($values =~ /^\s*$/) {
  343:                     $values = $src;
  344:                 } else {
  345:                     $title = 'unable to retrieve title';
  346:                     $src   = '/dev/null';
  347:                 }
  348:             }
  349:         }
  350:         my %classes;
  351:         my $class_count=0;
  352:         if (! exists($classes{$symb})) {
  353:             $classes{$symb} = $class_count++;
  354:         }
  355:         my $class = 'a';#.$classes{$symb};
  356:         #
  357:         if ($symb eq '/prtspool/') {
  358:             $class = 'print';
  359:             $title = 'retrieve printout';
  360:         } elsif ($symb =~ m|^/adm/([^/]+)|) {
  361:             $class = $1;
  362:         } elsif ($symb =~ m|^/adm/|) {
  363:             $class = 'adm';
  364:         }
  365:         if ($title eq 'unable to retrieve title') {
  366:             $title =~ s/ /\&nbsp;/g;
  367:             $class = 'warning';
  368:         }
  369:         if (! defined($title) || $title eq '') {
  370:             $title = 'untitled';
  371:             $class = 'warning';
  372:         }
  373:         # Clean up the values
  374: 	$values = &display_values($action,$values);
  375:         #
  376:         # Build the row for output
  377:         my $tablerow = qq{<tr class="$class"><td>}.($count+1).qq{</td>};
  378:         if ($src =~ m|^/adm/|) {
  379:             $tablerow .= 
  380:                 '<td valign="top"><span class="LC_nobreak">'.$title.'</span></td>';
  381:         } else {
  382:             $tablerow .= 
  383:                 '<td valign="top"><span class="LC_nobreak">'.
  384:                 '<a href="'.$src.'">'.$title.'</a>'.
  385:                 '</span></td>';
  386:         }
  387:         if ($server_timezone ne '') {
  388:             $timestamp = &convert_timezone($server_timezone,$timestamp);
  389:         }
  390:         $tablerow .= '<td valign="top"><span class="LC_nobreak">'.$timestamp.'</span></td>';
  391:         if ($mode eq 'full_class') {
  392:             $tablerow.='<td valign="top">'.$student.'</td>';
  393:         }
  394:         $tablerow .= 
  395:             '<td valign="top">'.$action.'</td>'.
  396: #            '<td>'.$machine.'</td>'.
  397:             '<td valign="top">'.$values.'</td>'.
  398:             '</tr>';
  399:         $r->print($tablerow.$/);
  400:     }
  401:     $r->print('</table>'.$/);### if (! $count % 50);
  402:     close(ACTIVITYDATA);
  403:     return $count;
  404: }
  405: 
  406: sub convert_timezone {
  407:     my ($server_timezone,$timestamp) = @_;
  408:     if ($server_timezone && $timestamp) {
  409:         my ($date,$time) = split(/\s+/,$timestamp);
  410:         my ($year,$month,$day) = split(/\-/,$date);
  411:         my ($hour,$minute,$sec) = split(/:/,$time);
  412:         foreach ($month,$day,$hour,$minute,$sec) {
  413:             return $timestamp if $_ eq '';
  414:             $_ =~ s/^0//;
  415:         }
  416:         my $dt = DateTime->new(year      => $year,
  417:                                month     => $month,
  418:                                day       => $day,
  419:                                hour      => $hour,
  420:                                minute    => $minute,
  421:                                second    => $sec,
  422:                                time_zone => $server_timezone,
  423:                               );
  424:         my $unixtime = $dt->epoch;
  425:         $timestamp = &Apache::lonlocal::locallocaltime($unixtime);
  426:     }
  427:     return $timestamp;
  428: }
  429: 
  430: ###################################################################
  431: ###################################################################
  432: sub display_values {
  433:     my ($action,$values)=@_;
  434:     my $result='<table>';
  435:     if (($action eq 'CSTORE') || ($action eq 'PUTSTORE')) {
  436:         my $is_anon;
  437: 	my %values=map {split('=',$_,-1)} split(/\&/,$values);
  438: 	foreach my $key (sort(keys(%values))) {
  439:             my $unesc_key = &unescape($key);
  440:             if ($values{$key} eq 'anonsurvey' || $values{$key} eq 'anonsurveycred') {
  441:                 if ($unesc_key =~ /^resource\..+\.type$/) {
  442:                     $is_anon = 1;
  443:                     last;
  444:                 }
  445:             }
  446: 	    $result.='<tr><td align="right">'.
  447: 		$unesc_key.
  448: 		'</td><td>=</td><td align="left">'.
  449: 		&unescape($values{$key}).'</td></tr>';
  450: 	}
  451: 	$result.='</table>';
  452:         if ($is_anon) {
  453:             $result = '<span class="LC_warning">'.&mt('Anonymous Survey Submission: details not shown').'</span>';
  454:         }
  455:     } elsif ($action eq 'POST') {
  456: 	my %values;
  457:         foreach my $pair (split(/\&/,$values)) {
  458:             my ($key,$value) = split('=',&unescape($pair),-1);
  459:             $values{$key} = $value;
  460:         }
  461: 	foreach my $key (sort(keys(%values))) {
  462: 	    if ($key eq 'counter') { next; }
  463: 	    $result.='<tr><td align="right">'.$key.'</td>'.
  464: 		'<td>=</td><td align="left">'.$values{$key}.'</td></tr>';
  465: 	}
  466: 	$result.='</table>';
  467:     } else {
  468: 	$result=&unescape($values)
  469:     }
  470:     return $result;
  471: }
  472: ###################################################################
  473: ###################################################################
  474: sub request_data_update {
  475:     my $command = 'prepare activity log';
  476:     my $cid = $env{'request.course.id'};
  477:     my $domain = $env{'course.'.$cid.'.domain'};
  478:     my $home = $env{'course.'.$cid.'.home'};
  479:     my $course = $env{'course.'.$cid.'.num'};
  480: #    &Apache::lonnet::logthis($command.' '.$course.' '.$domain.' '.$home);
  481:     my $result = &Apache::lonnet::metadata_query($command,$course,$domain,
  482:                                                  [$home]);
  483:     return $result;
  484: }
  485: 
  486: ###################################################################
  487: ###################################################################
  488: sub pick_student {
  489:     my ($r) = @_;
  490:     $r->print("Sorry, cannot display classlist at this time.  Come back another time.");
  491:     return;
  492: }
  493: 
  494: ###################################################################
  495: ###################################################################
  496: sub styles {
  497:     return <<END;
  498: <style type="text/css">
  499:     tr.warning   { background-color: \#CCCCCC; }
  500:     tr.chat      { background-color: \#CCCCCC; }
  501:     tr.chatfetch { background-color: \#CCCCCC; }
  502:     tr.navmaps   { background-color: \#CCCCCC; }
  503:     tr.roles     { background-color: \#CCCCCC; }
  504:     tr.flip      { background-color: \#CCCCCC; }
  505:     tr.adm       { background-color: \#CCCCCC; }
  506:     tr.print     { background-color: \#CCCCCC; }
  507:     tr.printout  { background-color: \#CCCCCC; }
  508:     tr.parmset   { background-color: \#CCCCCC; }
  509:     tr.grades    { background-color: \#CCCCCC; }
  510: </style>
  511: END
  512: } 
  513: 
  514: sub developer_centric_styles {
  515:     return <<END;
  516: <style type="text/css">
  517:     tr.warning   { background-color: red; }
  518:     tr.chat      { background-color: yellow; }
  519:     tr.chatfetch { background-color: yellow; }
  520:     tr.evaluate  { background-color: red; }
  521:     tr.navmaps   { background-color: \#777777; }
  522:     tr.roles     { background-color: \#999999; }
  523:     tr.flip      { background-color: \#BBBBBB; }
  524:     tr.adm       { background-color: green; }
  525:     tr.print     { background-color: blue; }
  526:     tr.parmset   { background-color: \#000088; }
  527:     tr.printout  { background-color: blue; }
  528:     tr.grades    { background-color: \#CCCCCC; }
  529: </style>
  530: END
  531: }
  532: 
  533: ###################################################################
  534: ###################################################################
  535: sub handler {
  536:     my $r=shift;
  537:     my $c = $r->connection();
  538:     #
  539:     # Check for access
  540:     if (! &Apache::lonnet::allowed('vsa',$env{'request.course.id'})) {
  541:         $env{'user.error.msg'}=
  542:             $r->uri.":vsa:0:0:Cannot student activity for complete course";
  543:         if (! 
  544:             &Apache::lonnet::allowed('vsa',
  545:                                      $env{'request.course.id'}.'/'.
  546:                                      $env{'request.course.sec'})) {
  547:             $env{'user.error.msg'}=
  548:                 $r->uri.":vsa:0:0:Cannot view student activity with given role";
  549:             return HTTP_NOT_ACCEPTABLE;
  550:         }
  551:     }
  552:     #
  553:     # Send the header
  554:     &Apache::loncommon::no_cache($r);
  555:     &Apache::loncommon::content_type($r,'text/html');
  556:     $r->send_http_header;
  557:     if ($r->header_only) { return OK; }
  558:     #
  559:     # Extract form elements from query string
  560:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
  561:                       ['selected_student','start','only_body']);
  562:     #
  563:     # We will almost always need this...
  564:     my $navmap = Apache::lonnavmaps::navmap->new();
  565:     if (!defined($navmap)) {
  566:         my $requrl = $r->uri;
  567:         $env{'user.error.msg'} = "$requrl:bre:0:0:Navmap initialization failed.";
  568:         return HTTP_NOT_ACCEPTABLE;
  569:     }
  570:     # 
  571:     &Apache::lonhtmlcommon::clear_breadcrumbs();
  572:     &Apache::lonhtmlcommon::add_breadcrumb({href=>'/adm/studentactivity',
  573:                                             title=>'Student Activity',
  574:                                             text =>'Student Activity',
  575:                                             faq=>139,
  576:                                             bug=>'instructor interface',
  577:                                             help=>'View_recent_activity'});
  578:     #
  579:     # Give the LON-CAPA page header
  580:     my $args;
  581:     if ($env{'form.only_body'}) {
  582:         $args = { only_body => 1, };
  583:     }
  584:     $r->print(&Apache::loncommon::start_page('Student Activity',&styles(),$args).
  585:               &Apache::lonhtmlcommon::breadcrumbs('Student Activity'));
  586:     $r->rflush();
  587:     #
  588:     # Begin form output
  589:     $r->print('<form name="trackstudent" method="post" action="/adm/trackstudent">');
  590:     $r->rflush();
  591:     my %prog_state=&Apache::lonhtmlcommon::Create_PrgWin($r);
  592:     &Apache::lonhtmlcommon::Update_PrgWin
  593:         ($r,\%prog_state,&mt('Contacting course home server'));
  594:     #
  595:     my $result = &request_data_update();
  596:     #
  597:     if (exists($env{'form.selected_student'})) {
  598:         # For now, just show all the data, in the future allow selection of
  599:         # a student
  600:         my ($sname,$sdom) = split(':',$env{'form.selected_student'});
  601:         if ($sname =~ /^$LONCAPA::username_re$/ 
  602: 	    && $sdom =~ /^$LONCAPA::domain_re$/) {
  603:             $r->print('<h2>'.
  604:                       &mt('Recent activity of [_1]',$sname.':'.$sdom).
  605:                       '</h2>');
  606:             $r->print('<p class="LC_info">'
  607:                      .&mt('Compiling student activity data can take a long time.'
  608:                          .' Your request continues to be processed while results are displayed.')
  609:                      .'</p>'
  610:             );
  611:             &get_data($r,\%prog_state,$navmap,
  612:                       'student:'.$env{'form.selected_student'});
  613:         } else {
  614:             $r->print(
  615:                 '<p class="LC_error">'
  616:                .&mt('Unable to process for [_1]:[_2]',$sname,$sdom)
  617:                .'</p>'
  618:             );
  619:         }
  620:     } else {
  621:         # For now, just show all the data instead of limiting it to one student
  622:         &get_data($r,\%prog_state,$navmap,'full_class');
  623:     }
  624:     #
  625:     &Apache::lonhtmlcommon::Update_PrgWin($r,\%prog_state,&mt('Done'));
  626:     &Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state);
  627:     #
  628:     $r->print("</form>\n");
  629:     $r->print(&Apache::loncommon::end_page());
  630:     $r->rflush();
  631:     #
  632:     return OK;
  633: }
  634: 
  635: 1;
  636: 
  637: #######################################################
  638: #######################################################
  639: 
  640: =pod
  641: 
  642: =back
  643: 
  644: =cut
  645: 
  646: #######################################################
  647: #######################################################
  648: 
  649: __END__
  650: 

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