Annotation of loncom/publisher/loncfile.pm, revision 1.1
1.1 ! www 1: # The LearningOnline Network with CAPA
! 2: # Handler to rename files, etc, in construction space
! 3: #
! 4: # (Handler to retrieve an old version of a file
! 5: #
! 6: # (Publication Handler
! 7: #
! 8: # (TeX Content Handler
! 9: #
! 10: # 05/29/00,05/30,10/11 Gerd Kortemeyer)
! 11: #
! 12: # 11/28,11/29,11/30,12/01,12/02,12/04,12/23 Gerd Kortemeyer
! 13: # 03/23 Guy Albertelli
! 14: # 03/24,03/29 Gerd Kortemeyer)
! 15: #
! 16: # 03/31,04/03,05/02,05/09,06/23 Gerd Kortemeyer)
! 17: #
! 18: # 06/23 Gerd Kortemeyer
! 19:
! 20: package Apache::loncfile;
! 21:
! 22: use strict;
! 23: use Apache::File;
! 24: use File::Copy;
! 25: use Apache::Constants qw(:common :http :methods);
! 26: use Apache::loncacc;
! 27:
! 28: sub phaseone {
! 29: my ($r,$fn,$uname,$udom)=@_;
! 30: my $docroot=$r->dir_config('lonDocRoot');
! 31:
! 32: my $urldir='/res/'.$udom.'/'.$uname.$fn;
! 33: $urldir=~s/\/[^\/]+$/\//;
! 34:
! 35: my $resfn=$docroot.'/res/'.$udom.'/'.$uname.$fn;
! 36: my $resdir=$resfn;
! 37: $resdir=~s/\/[^\/]+$/\//;
! 38:
! 39: $fn=~/\/([^\/]+)\.(\w+)$/;
! 40: my $main=$1;
! 41: my $suffix=$2;
! 42:
! 43: if (-e $resfn) {
! 44: $r->print('<form action=/adm/retrieve method=post>'.
! 45: '<input type=hidden name=filename value="/~'.$uname.$fn.'">'.
! 46: '<input type=hidden name=phase value=two>'.
! 47: '<table border=2><tr><th>Select</th><th>Version</th>'.
! 48: '<th>Became this version on ...</th>'.
! 49: '<th>Metadata</th></tr>');
! 50: my $filename;
! 51: opendir(DIR,$resdir);
! 52: while ($filename=readdir(DIR)) {
! 53: if ($filename=~/^$main\.(\d+)\.$suffix$/) {
! 54: my $version=$1;
! 55: my ($rdev,$rino,$rmode,$rnlink,
! 56: $ruid,$rgid,$rrdev,$rsize,
! 57: $ratime,$rmtime,$rctime,
! 58: $rblksize,$rblocks)=stat($resdir.'/'.$filename);
! 59: $r->print('<tr><td><input type=radio name=version value="'.
! 60: $version.'"></td><th>'.$version.'</th><td>'.
! 61: localtime($rmtime).'</td><td>'.
! 62: '<a href="'.$urldir.$filename.'.meta" target=cat>'.
! 63: 'Metadata Version '.$version.'</a>');
! 64: if (&Apache::lonnet::fileembstyle($suffix) eq 'ssi') {
! 65: $r->print(
! 66: ' <a target=cat href="/adm/diff?filename=/~'.
! 67: $uname.$fn.
! 68: '&versionone=priv&versiontwo='.$version.
! 69: '">Diffs with Version '.$version.'</a>');
! 70: }
! 71: $r->print('</a></td></tr>');
! 72: }
! 73: }
! 74: closedir(DIR);
! 75: my ($rdev,$rino,$rmode,$rnlink,
! 76: $ruid,$rgid,$rrdev,$rsize,
! 77: $ratime,$rmtime,$rctime,
! 78: $rblksize,$rblocks)=stat($resfn);
! 79: $r->print('<tr><td><input type=radio name=version value="new"></td>'.
! 80: '<th>Current</th><td>'.localtime($rmtime).
! 81: '</td><td><a href="'.$urldir.$main.'.'.$suffix.'.meta" target=cat>'.
! 82: 'Metadata current version</a>');
! 83: if (&Apache::lonnet::fileembstyle($suffix) eq 'ssi') {
! 84: $r->print(
! 85: ' <a target=cat href="/adm/diff?filename=/~'.
! 86: $uname.$fn.
! 87: '&versionone=priv'.
! 88: '">Diffs with current Version</a>');
! 89: }
! 90: $r->print('</td></tr></table><p>'.
! 91: '<font size=+1 color=red>Retrieval of an old version will '.
! 92: 'overwrite the file currently in construction space</font><p>'.
! 93: '<input type=submit value="Retrieve version"></form>');
! 94: } else {
! 95: $r->print('<h3>No previous versions published.</h3>');
! 96: }
! 97: }
! 98:
! 99: sub phasetwo {
! 100: my ($r,$fn,$uname,$udom)=@_;
! 101: if ($ENV{'form.version'}) {
! 102: my $version=$ENV{'form.version'};
! 103: if ($version eq 'new') {
! 104: $r->print('<h3>Retrieving current (most recent) version</h3>');
! 105: } else {
! 106: $r->print('<h3>Retrieving old version '.$version.'</h3>');
! 107: }
! 108: my $logfile;
! 109: my $ctarget='/home/'.$uname.'/public_html'.$fn;
! 110: my $vfn=$fn;
! 111: if ($version ne 'new') {
! 112: $vfn=~s/\.(\w+)$/\.$version\.$1/;
! 113: }
! 114: my $csource=$r->dir_config('lonDocRoot').'/res/'.$udom.'/'.$uname.$vfn;
! 115: unless ($logfile=Apache::File->new('>>'.$ctarget.'.log')) {
! 116: $r->print(
! 117: '<font color=red>No write permission to user directory, FAIL</font>');
! 118: }
! 119: print $logfile
! 120: "\n\n================= Retrieve ".localtime()." ================\n".
! 121: "Version: $version\nSource: $csource\nTarget: $ctarget\n";
! 122: $r->print('<p>Copying file: ');
! 123: if (copy($csource,$ctarget)) {
! 124: $r->print('ok<p>');
! 125: print $logfile "Copied sucessfully.\n\n";
! 126: } else {
! 127: my $error=$!;
! 128: $r->print('fail, '.$error.'<p>');
! 129: print $logfile "Copy failed: $error\n\n";
! 130: }
! 131: $r->print('<font size=+2><a href="/priv/'.$uname.$fn.
! 132: '">Back to '.$fn.'</a></font>');
! 133: } else {
! 134: $r->print(
! 135: '<font size=+1 color=red>Please pick a version to retrieve</font><p>');
! 136: &phaseone($r,$fn,$uname,$udom);
! 137: }
! 138: }
! 139:
! 140: sub handler {
! 141:
! 142: my $r=shift;
! 143:
! 144: my $fn;
! 145:
! 146: if ($ENV{'form.filename'}) {
! 147: $fn=$ENV{'form.filename'};
! 148: $fn=~s/^http\:\/\/[^\/]+//;
! 149: } else {
! 150: $r->log_reason($ENV{'user.name'}.' at '.$ENV{'user.domain'}.
! 151: ' unspecified filename for cfile', $r->filename);
! 152: return HTTP_NOT_FOUND;
! 153: }
! 154:
! 155: unless ($fn) {
! 156: $r->log_reason($ENV{'user.name'}.' at '.$ENV{'user.domain'}.
! 157: ' trying to cfile non-existing file', $r->filename);
! 158: return HTTP_NOT_FOUND;
! 159: }
! 160:
! 161: # ----------------------------------------------------------- Start page output
! 162: my $uname;
! 163: my $udom;
! 164:
! 165: ($uname,$udom)=
! 166: &Apache::loncacc::constructaccess($fn,$r->dir_config('lonDefDomain'));
! 167: unless (($uname) && ($udom)) {
! 168: $r->log_reason($uname.' at '.$udom.
! 169: ' trying to publish file '.$ENV{'form.filename'}.
! 170: ' ('.$fn.') - not authorized',
! 171: $r->filename);
! 172: return HTTP_NOT_ACCEPTABLE;
! 173: }
! 174:
! 175: $fn=~s/\/\~(\w+)//;
! 176:
! 177: $r->content_type('text/html');
! 178: $r->send_http_header;
! 179:
! 180: $r->print('<html><head><title>LON-CAPA Construction Space</title></head>');
! 181:
! 182: $r->print(
! 183: '<body bgcolor="#FFFFFF"><img align=right src=/adm/lonIcons/lonlogos.gif>');
! 184:
! 185:
! 186: $r->print('<h1>Construction Space <tt>'.$fn.'</tt></h1>');
! 187:
! 188: if (($uname ne $ENV{'user.name'}) || ($udom ne $ENV{'user.domain'})) {
! 189: $r->print('<h3><font color=red>Co-Author: '.$uname.' at '.$udom.
! 190: '</font></h3>');
! 191: }
! 192:
! 193:
! 194: if ($ENV{'form.phase'} eq 'two') {
! 195: # &phasetwo($r,$fn,$uname,$udom);
! 196: } else {
! 197: # &phaseone($r,$fn,$uname,$udom);
! 198: }
! 199:
! 200: $r->print('</body></html>');
! 201: return OK;
! 202: }
! 203:
! 204: 1;
! 205: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>