--- loncom/publisher/loncfile.pm 2003/12/15 20:44:06 1.47 +++ loncom/publisher/loncfile.pm 2004/02/17 22:06:10 1.51 @@ -9,7 +9,7 @@ # and displays a page showing the results of the action. # # -# $Id: loncfile.pm,v 1.47 2003/12/15 20:44:06 sakharuk Exp $ +# $Id: loncfile.pm,v 1.51 2004/02/17 22:06:10 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -173,6 +173,28 @@ sub display { return ''.$fn.''; } + +# see if the file is +# a) published (return 0 if not) +# b) if, so obsolete (return 0 if not) + +sub obsolete_unpub { + my ($user,$domain,$construct)=@_; + my $published=$construct; + $published=~ + s/^\/home\/$user\/public\_html\//\/home\/httpd\/html\/res\/$domain\/$user\//; + if (-e $published) { + if (&Apache::lonnet::metadata($published,'obsolete')) { + return 1; + } + return 0; + } else { + return 1; + } +} + + + =pod =item exists($user, $domain, $file) @@ -414,6 +436,11 @@ sub Rename1 { $request->print('
'.&mt('Cancel').''); return; } + unless (&obsolete_unpub($user,$domain,$fn)) { + $request->print('

'.&mt('Cannot rename or move non-obsolete published file').'

'. + '
'.&mt('Cancel').''); + return; + } $request->print('

'.&mt('Rename').' '.&display($fn). @@ -459,6 +486,11 @@ sub Delete1 { if( -e $fn) { $request->print(''); + unless (&obsolete_unpub($user,$domain,$fn)) { + $request->print('

'.&mt('Cannot delete non-obsolete published file').'

'. + '
'.&mt('Cancel').''); + return; + } $request->print('

'.&mt('Delete').' '.&display($fn).'?

'); &CloseForm1($request, $fn); } else { @@ -567,12 +599,17 @@ causes the newdir operation to transitio sub NewDir1 { - my ($request, $username, $domain, $fn, $newfilename) = @_; + my ($request, $username, $domain, $fn, $newfilename, $mode) = @_; my $result=&exists($username,$domain,$newfilename); if ($result) { $request->print(''.$result.''); } else { + if ($mode eq 'testbank') { + $request->print(''); + } elsif ($mode eq 'imsimport') { + $request->print(''); + } $request->print('

'.&mt('Make new directory').' '. &display($newfilename).'?

'); @@ -717,7 +754,11 @@ sub phaseone { $r->print('

'.&mt('No new filename specified.').'

'); } } elsif ($ENV{'form.action'} eq 'newdir') { - &NewDir1($r, $uname, $udom, $fn, $newfilename); + my $mode = ''; + if (exists($ENV{'form.callingmode'}) ) { + $mode = $ENV{'form.callingmode'}; + } + &NewDir1($r, $uname, $udom, $fn, $newfilename, $mode); } elsif ($ENV{'form.action'} eq 'newfile' || $ENV{'form.action'} eq 'newhtmlfile' || $ENV{'form.action'} eq 'newproblemfile' || @@ -858,31 +899,25 @@ sub Delete2 { if(@files) { $request->print(' '.&mt('Error: Directory Non Empty').''); return 0; - } - else { + } else { if(-e $filename) { unless(rmdir($filename)) { $request->print(''.&mt('Error').': '.$!.''); return 0; } - } - else { - $request->print('

'.&mt('No such file').'.

print('

'.&mt('No such file').'.

'); return 0; } - } - - } - else { + } else { if(-e $filename) { unless(unlink($filename)) { $request->print(''.&mt('Error').': '.$!.''); return 0; } - } - else { - $request->print('

'.&mt('No such file').'.

print('

'.&mt('No such file').'.

'); return 0; } } @@ -1029,8 +1064,8 @@ sub phasetwo { $main=$2; # Filename. } if($main=~m:\.(\w+)$:){ # Fixes problems with filenames with no extensions - $main=$`; - $suffix=$1; + $main=$`; #This is what is before the match (.) so it's just the main filename, yea it's nasty + $suffix=$1; #This is the actually filename extension if it exists } my $dest; # On success this is where we'll go. @@ -1095,7 +1130,11 @@ sub phasetwo { } $dest = $newdir."/" } - $r->print('

'.&mt('Done').'

'); + if ( ($ENV{'form.action'} eq 'newdir') && ($ENV{'form.phase'} eq 'two') && ( ($ENV{'form.callingmode'} eq 'testbank') || ($ENV{'form.callingmode'} eq 'imsimport') ) ) { + $r->print('

'.&mt('Done').'

'); + } else { + $r->print('

'.&mt('Done').'

'); + } } sub handler { @@ -1160,12 +1199,27 @@ sub handler { } - $r->content_type('text/html'); + &Apache::loncommon::content_type($r,'text/html'); $r->send_http_header; - $r->print('LON-CAPA Construction Space'); - - $r->print(&Apache::loncommon::bodytag('Construction Space File Operation')); + if ( ($ENV{'form.action'} eq 'newdir') && ($ENV{'form.phase'} eq 'two') && ( ($ENV{'form.callingmode'} eq 'testbank') || ($ENV{'form.callingmode'} eq 'imsimport') ) ) { + my $newdirname = $ENV{'form.newfilename'}; + $r->print('LON-CAPA Construction Space + |); + my $loaditem = 'onLoad="writeDone()"'; + $r->print(&Apache::loncommon::bodytag('Construction Space File Operation','',$loaditem)); + } else { + $r->print('LON-CAPA Construction Space'); + $r->print(&Apache::loncommon::bodytag('Construction Space File Operation')); + } $r->print('

'.&mt('Location').': '.&display($fn).'

');