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: sub get_unprocessed_cgi {
64: my ($query)= @_;
65: map {
66: my ($name, $value) = split(/=/,$_);
67: $value =~ tr/+/ /;
68: $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
69: if (!defined($ENV{'form.'.$name})) { $ENV{'form.'.$name}=$value; }
70: } (split(/&/,$query));
71: }
72:
73: sub cacheheader {
74: my $date=localtime;
75: my $output .='<meta HTTP-EQUIV="Expires" CONTENT="'.$date.'" />
76: <meta HTTP-EQUIV="Cache-control" CONTENT="no-cache" />
77: <meta HTTP-EQUIV="Pragma" CONTENT="no-cache" />';
78: return $output;
79: }
80:
81: 1;
82: __END__;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>