# The LearningOnline Network # a pile of common routines # 2/13 Guy Albertelli # Makes a table out of the previous attempts # Inputs result_from_symbread, user, domain, course_id package Apache::loncommon; use strict; use POSIX qw(strftime); use Apache::Constants qw(:common); use Apache::lonmsg(); sub get_previous_attempt { my ($symb,$username,$domain,$course)=@_; my $prevattempts=''; if ($symb) { my (%returnhash)= &Apache::lonnet::restore($symb,$course,$domain,$username); if ($returnhash{'version'}) { my %lasthash=(); my $version; for ($version=1;$version<=$returnhash{'version'};$version++) { map { $lasthash{$_}=$returnhash{$version.':'.$_}; } sort(split(/\:/,$returnhash{$version.':keys'})); } $prevattempts=''; map { $prevattempts.=''; } sort(keys %lasthash); for ($version=1;$version<=$returnhash{'version'};$version++) { $prevattempts.=''; map { my $value; if ($_ =~ /timestamp/) { $value=scalar(localtime($returnhash{$version.':'.$_})); } else { $value=$returnhash{$version.':'.$_}; } $prevattempts.=''; } sort(keys %lasthash); } $prevattempts.=''; map { my $value; if ($_ =~ /timestamp/) { $value=scalar(localtime($lasthash{$_})); } else { $value=$lasthash{$_}; } $prevattempts.=''; } sort(keys %lasthash); $prevattempts.='
History'.$_.'
Attempt '.$version.''.$value.'
Current'.$value.'
'; } else { $prevattempts='Nothing submitted - no attempts.'; } } else { $prevattempts='No data.'; } } sub get_unprocessed_cgi { my ($query)= @_; map { my ($name, $value) = split(/=/,$_); $value =~ tr/+/ /; $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg; if (!defined($ENV{'form.'.$name})) { $ENV{'form.'.$name}=$value; } } (split(/&/,$query)); } sub cacheheader { my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime); my $output .=' '; return $output; } sub no_cache { my ($r) = @_; my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime); $r->no_cache(1); $r->header_out("Pragma" => "no-cache"); $r->header_out("Expires" => $date); } 1; __END__;