File:  [LON-CAPA] / loncom / interface / loncommon.pm
Revision 1.5: download - view: text, annotated - select for diffs
Thu Sep 13 19:59:33 2001 UTC (22 years, 9 months ago) by albertel
Branches: MAIN
CVS tags: HEAD
- prints out timestamps in a readable format

    1: # The LearningOnline Network
    2: # a pile of common routines
    3: # 2/13 Guy Albertelli
    4: 
    5: # Makes a table out of the previous attempts
    6: # Inputs result_from_symbread, user, domain, course_id
    7: 
    8: package Apache::loncommon;
    9: 
   10: use strict;
   11: use Apache::Constants qw(:common);
   12: use Apache::lonmsg();
   13: 
   14: sub get_previous_attempt {
   15:   my ($symb,$username,$domain,$course)=@_;
   16:   my $prevattempts='';
   17:   if ($symb) {
   18:     my (%returnhash)=
   19:       &Apache::lonnet::restore($symb,$course,$domain,$username);
   20:     if ($returnhash{'version'}) {
   21:       my %lasthash=();
   22:       my $version;
   23:       for ($version=1;$version<=$returnhash{'version'};$version++) {
   24:         map {
   25: 	  $lasthash{$_}=$returnhash{$version.':'.$_};
   26:         } sort(split(/\:/,$returnhash{$version.':keys'}));
   27:       }
   28:       $prevattempts='<table border=2></tr><th>History</th>';
   29:       map {
   30:         $prevattempts.='<th>'.$_.'</th>';
   31:       } sort(keys %lasthash);
   32:       for ($version=1;$version<=$returnhash{'version'};$version++) {
   33:         $prevattempts.='</tr><tr><th>Attempt '.$version.'</th>';
   34:         map {
   35: 	  my $value;
   36: 	  if ($_ =~ /timestamp/) {
   37: 	    $value=scalar(localtime($returnhash{$version.':'.$_}));
   38: 	  } else {
   39: 	    $value=$returnhash{$version.':'.$_};
   40: 	  }
   41: 	  $prevattempts.='<td>'.$value.'</td>';   
   42:         } sort(keys %lasthash);
   43:       }
   44:       $prevattempts.='</tr><tr><th>Current</th>';
   45:       map {
   46: 	my $value;
   47: 	if ($_ =~ /timestamp/) {
   48: 	  $value=scalar(localtime($lasthash{$_}));
   49: 	} else {
   50: 	  $value=$lasthash{$_};
   51: 	}
   52: 	$prevattempts.='<td>'.$value.'</td>';
   53:       } sort(keys %lasthash);
   54:       $prevattempts.='</tr></table>';
   55:     } else {
   56:       $prevattempts='Nothing submitted - no attempts.';
   57:     }
   58:   } else {
   59:     $prevattempts='No data.';
   60:   }
   61: }
   62: 
   63: 1;
   64: __END__;

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