--- loncom/publisher/loncfile.pm 2007/04/26 21:17:16 1.83 +++ loncom/publisher/loncfile.pm 2009/03/26 16:50:12 1.94 @@ -9,7 +9,7 @@ # and displays a page showing the results of the action. # # -# $Id: loncfile.pm,v 1.83 2007/04/26 21:17:16 albertel Exp $ +# $Id: loncfile.pm,v 1.94 2009/03/26 16:50:12 bisitz Exp $ # # Copyright Michigan State University Board of Trustees # @@ -109,6 +109,17 @@ sub Debug { } } +sub done { + my ($url)=@_; + my $done=&mt("Done"); + return(<$done + +ENDDONE +} + =pod =item URLToPath($url) @@ -148,7 +159,7 @@ sub URLToPath { my $Url = shift; &Debug($r, "UrlToPath got: $Url"); $Url=~ s/\/+/\//g; - $Url=~ s/^http\:\/\/[^\/]+//; + $Url=~ s/^https?\:\/\/[^\/]+//; $Url=~ s/^\///; $Url=~ s/(\~|priv\/)($match_username)\//\/home\/$2\/public_html\//; &Debug($r, "Returning $Url \n"); @@ -165,7 +176,7 @@ sub url { sub display { my $fn=shift; $fn=~s-^/home/($match_username)/public_html-/priv/$1-; - return ''.$fn.''; + return ''.$fn.''; } @@ -226,12 +237,16 @@ sub empty_directory { =over 4 -=item $user - string [in] - Name of the user for which to check. +=item $user - string [in] - Name of the user for which to check. -=item $domain - string [in] - Name of the domain in which the resource +=item $domain - string [in] - Name of the domain in which the resource might have been published. -=item $file - string [in] - Name of the file. +=item $file - string [in] - Name of the file. + +=item $creating - string [in] - optional, type of object being created, + either 'directory' or 'file'. Defaults to + 'file' if unspecified. =back @@ -251,7 +266,9 @@ Returns: =cut sub exists { - my ($user, $domain, $construct) = @_; + my ($user, $domain, $construct, $creating) = @_; + $creating ||= 'file'; + my $published=$construct; $published=~ s{^/home/$user/public_html/}{/home/httpd/html/res/$domain/$user/}; @@ -266,8 +283,15 @@ sub exists { $type = 'warning'; $result.='

'.&mt('Warning: target file exists, and has been published!').'

'; } else { - $type = 'warning'; - $result.='

'.&mt('Warning: a published file of this names exists.').'

'; + my $published_type = (-d $published) ? 'directory' : 'file'; + + if ($published_type eq $creating) { + $type = 'warning'; + $result.='

'.&mt("Warning: a published $published_type of this name exists.").'

'; + } else { + $type = 'error'; + $result.='

'.&mt("Error: a published $published_type of this name exists.").'

'; + } } } elsif ( -e $construct) { $type = 'warning'; @@ -328,6 +352,7 @@ sub cleanDest { $foundbad=1; $dest=~s/\.//g; } + $dest =~ s/(\s+$|^\s+)//g; if ($dest=~/[\#\?&%\":]/) { $foundbad=1; $dest=~s/[\#\?&%\":]//g; @@ -336,10 +361,23 @@ sub cleanDest { my ($newpath)=($dest=~m|(.*)/|); $newpath=&relativeDest($fn,$newpath,$uname); if (! -d "$newpath") { - $request->print("

".&mt('You have requested to create file in directory [_1] which doesn\'t exist. The requested directory path has been removed from the requested file name.','"'.$newpath.'"')."

"); + $request->print('

' + .&mt("You have requested to create file in directory [_1] which doesn't exist. The requested directory path has been removed from the requested file name." + ,'"'.&display($newpath).'"') + .'

'); $dest=~s|.*/||; } } + if ($dest =~ /\.(\d+)\.(\w+)$/){ + $request->print('' + .&mt('Bad filename [_1]',''.&display($dest).'') + .'
' + .&mt('[_1](name).(number).(extension)[_2] not allowed.','','') + .'
' + .&mt('Removing the [_1].number.[_2] from requested filename.','','') + .'
'); + $dest =~ s/\.(\d+)(\.\w+)$/$2/; + } if ($foundbad) { $request->print("

".&mt('Invalid characters in requested name have been removed.')."

"); } @@ -415,7 +453,7 @@ Parameters: sub CloseForm2 { my ($request, $user, $fn) = @_; - $request->print('

'.&mt('Done').'

'); + $request->print(&done(&url($fn))); } =pod @@ -508,7 +546,7 @@ sub Rename1 { $request->print('

'.$action.' '.&display($fn). - '
to '.&display($newfilename).'?

'); + '


to '.&display($newfilename).'?

'); &CloseForm1($request, $fn); } else { $request->print('

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

'); @@ -674,9 +712,9 @@ causes the newdir operation to transitio sub NewDir1 { my ($request, $username, $domain, $fn, $newfilename, $mode) = @_; - my ($type, $result)=&exists($username,$domain,$newfilename); + my ($type, $result)=&exists($username,$domain,$newfilename,'directory'); $request->print($result); - if ($result) { + if ($type eq 'error') { $request->print(''); } else { if ($mode eq 'testbank') { @@ -852,6 +890,7 @@ sub phaseone { $env{'form.action'} eq 'newsequencefile' || $env{'form.action'} eq 'newrightsfile' || $env{'form.action'} eq 'newstyfile' || + $env{'form.action'} eq 'newtaskfile' || $env{'form.action'} eq 'newlibraryfile' || $env{'form.action'} eq 'Select Action') { my $empty=&mt('Type Name Here'); @@ -1107,8 +1146,8 @@ sub NewDir2 { sub decompress2 { my ($r, $user, $dir, $file) = @_; - &Apache::lonnet::appenv('cgi.file' => $file); - &Apache::lonnet::appenv('cgi.dir' => $dir); + &Apache::lonnet::appenv({'cgi.file' => $file}); + &Apache::lonnet::appenv({'cgi.dir' => $dir}); my $result=&Apache::lonnet::ssi_body('/cgi-bin/decompress.pl'); $r->print($result); &Apache::lonnet::delenv('cgi.file'); @@ -1235,7 +1274,7 @@ sub phasetwo { $r->print('

'.&mt('Return to Directory').'

'); $r->print('

'.$disp_newname.'

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

'.&mt('Done').'

'); + $r->print(&done(&url($dest))); } } } @@ -1309,10 +1348,9 @@ sub handler { $js = qq| |; @@ -1326,8 +1364,10 @@ function writeDone() { $r->print('

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

'); if (($uname ne $env{'user.name'}) || ($udom ne $env{'user.domain'})) { - $r->print('

'.&mt('Co-Author').': '.$uname.' at '.$udom. - '

'); + $r->print('

' + .&mt('Co-Author [_1]:[_2]',$uname,$udom) + .'

' + ); } @@ -1351,6 +1391,7 @@ function writeDone() { $env{'form.action'} eq 'newsequencefile' || $env{'form.action'} eq 'newrightsfile' || $env{'form.action'} eq 'newstyfile' || + $env{'form.action'} eq 'newtaskfile' || $env{'form.action'} eq 'newlibraryfile' || $env{'form.action'} eq 'Select Action' ) { $r->print('

'.&mt('New Resource').'

');