Annotation of loncom/publisher/lonretrieve.pm, revision 1.3
1.1 www 1: # The LearningOnline Network with CAPA
2: # Handler to retrieve an old version of a file
3: #
4: # (Publication Handler
5: #
6: # (TeX Content Handler
7: #
8: # 05/29/00,05/30,10/11 Gerd Kortemeyer)
9: #
10: # 11/28,11/29,11/30,12/01,12/02,12/04,12/23 Gerd Kortemeyer
11: # 03/23 Guy Albertelli
12: # 03/24,03/29 Gerd Kortemeyer)
13: #
1.3 ! www 14: # 03/31,04/03 Gerd Kortemeyer
1.1 www 15:
16: package Apache::lonretrieve;
17:
18: use strict;
19: use Apache::File;
20: use File::Copy;
21: use Apache::Constants qw(:common :http :methods);
22:
1.2 www 23: sub phaseone {
24: my ($r,$fn,$uname,$udom)=@_;
25: my $docroot=$r->dir_config('lonDocRoot');
26:
1.3 ! www 27: my $urldir='/res/'.$udom.'/'.$uname.$fn;
! 28: $urldir=~s/\/[^\/]+$/\//;
! 29:
! 30: my $resfn=$docroot.'/res/'.$udom.'/'.$uname.$fn;
! 31: my $resdir=$resfn;
1.2 www 32: $resdir=~s/\/[^\/]+$/\//;
33:
34: $fn=~/^\/(.+)\.(\w+)$/;
35: my $main=$1;
36: my $suffix=$2;
1.3 ! www 37:
! 38: $r->print('<form action=/adm/retrieve method=post>'.
! 39: '<input type=hidden name=filename value="'.$fn.'">'.
! 40: '<input type=hidden name=phase value=two>'.
! 41: '<table border=2><tr><th>Select</th><th>Version</th>'.
! 42: '<th>Became this version on ...</th>'.
! 43: '<th>Metadata</th></tr>');
1.2 www 44: my $filename;
45: opendir(DIR,$resdir);
46: while ($filename=readdir(DIR)) {
47: if ($filename=~/^$main\.(\d+)\.$suffix$/) {
1.3 ! www 48: my $version=$1;
! 49: my ($rdev,$rino,$rmode,$rnlink,
! 50: $ruid,$rgid,$rrdev,$rsize,
! 51: $ratime,$rmtime,$rctime,
! 52: $rblksize,$rblocks)=stat($resdir.'/'.$filename);
! 53: $r->print('<tr><td><input type=radio name=version value="'.
! 54: $version.'"></td><th>'.$version.'</th><td>'.
! 55: localtime($rmtime).'</td><td>'.
! 56: '<a href="'.$urldir.$filename.'.meta" target=cat>'.
! 57: 'Metadata Version '.$version.'</a></td></tr>');
1.2 www 58: }
59: }
60: closedir(DIR);
1.3 ! www 61: my ($rdev,$rino,$rmode,$rnlink,
! 62: $ruid,$rgid,$rrdev,$rsize,
! 63: $ratime,$rmtime,$rctime,
! 64: $rblksize,$rblocks)=stat($resfn);
! 65: $r->print('<tr><td><input type=radio name=version value="new"></td>'.
! 66: '<th>Current</th><td>'.localtime($rmtime).
! 67: '</td><td><a href="'.$urldir.$main.'.'.$suffix.'.meta" target=cat>'.
! 68: 'Metadata current version</a></td></tr></table><p>'.
! 69: '<input type=submit value="Retrieve version"></form>');
1.2 www 70: }
1.1 www 71:
72: sub handler {
73:
74: my $r=shift;
75:
76: my $fn;
77:
78: if ($ENV{'form.filename'}) {
79: $fn=$ENV{'form.filename'};
1.2 www 80: $fn=~s/^http\:\/\/[^\/]+\/\~(\w+)//;
1.1 www 81: } else {
1.2 www 82: $r->log_reason($ENV{'user.name'}.' at '.$ENV{'user.domain'}.
83: ' unspecified filename for retrieval', $r->filename);
84: return HTTP_NOT_FOUND;
1.1 www 85: }
86:
87: unless ($fn) {
88: $r->log_reason($ENV{'user.name'}.' at '.$ENV{'user.domain'}.
1.2 www 89: ' trying to retrieve non-existing file', $r->filename);
1.1 www 90: return HTTP_NOT_FOUND;
91: }
92:
93: # ----------------------------------------------------------- Start page output
94:
95: my $uname=$ENV{'user.name'};
96: my $udom=$ENV{'user.domain'};
97:
98: $r->content_type('text/html');
99: $r->send_http_header;
100:
101: $r->print('<html><head><title>LON-CAPA Construction Space</title></head>');
102:
103: $r->print(
104: '<body bgcolor="#FFFFFF"><img align=right src=/adm/lonIcons/lonlogos.gif>');
105:
106:
1.2 www 107: $r->print('<h1>Retrieve previous versions of <tt>'.$fn.'</tt></h1>');
1.1 www 108:
1.2 www 109: if ($ENV{'form.phase'} eq 'two') {
110: } else {
111: &phaseone($r,$fn,$uname,$udom);
112: }
1.1 www 113:
114: $r->print('</body></html>');
115: return OK;
116: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>