--- loncom/publisher/loncfile.pm 2002/10/28 23:23:41 1.19 +++ loncom/publisher/loncfile.pm 2003/02/10 23:26:15 1.26 @@ -7,10 +7,9 @@ # presents a page that describes the proposed action to the user # and requests confirmation. The second phase commits the action # and displays a page showing the results of the action. -# - # -# $Id: loncfile.pm,v 1.19 2002/10/28 23:23:41 albertel Exp $ +# +# $Id: loncfile.pm,v 1.26 2003/02/10 23:26:15 albertel Exp $ # # Copyright Michigan State University Board of Trustees # @@ -128,7 +127,7 @@ sub Debug { my $log = $r->log; my $message = shift; - # Put out the indicated message butonly if DEBUG is false. + # Put out the indicated message butonly if DEBUG is true. if ($DEBUG) { $log->debug($message); @@ -323,20 +322,24 @@ sub exists { my ($user, $domain, $dir, $file) = @_; # Create complete paths in publication and construction space. - - my $published = &PublicationPath($domain, $user, $dir, $file); - my $construct = &ConstructionPath($user, $dir, $file); + my $relativedir=$dir; + $relativedir=s|/home/\Q$user\E/public_html||; + my $published = &PublicationPath($domain, $user, $relativedir, $file); + my $construct = &ConstructionPath($user, $relativedir, $file); # If the resource exists in either space indicate this fact. # Note that the check for existence in resource space is stricter. my $result; + if ( -d $construct ) { + return 'Error: destination for operation is a directory.'; + } if ( -e $published) { - $result.='
Warning: target file exists, and has been published!
'; + $result.='Warning: target file exists, and has been published!
'; } elsif ( -e $construct) { - $result.='Warning: target file exists!
'; - } + $result.='Warning: target file exists!
'; + } return $result; @@ -380,7 +383,7 @@ sub checksuffix { if ($old=~m:(.*)/+([^/]+)\.(\w+)$:) { $oldsuffix=$3; } if ($oldsuffix ne $newsuffix) { $result.= - 'Warning: change of MIME type!
'; + 'Warning: change of MIME type!
'; } return $result; } @@ -407,9 +410,9 @@ sub CloseForm1 { &Debug($request, "Cancel url is: ".$cancelurl); - $request->print(''); + $request->print(''); $request->print(''); + '" method="GET">'); } @@ -441,7 +444,7 @@ Parameters: sub CloseForm2 { my ($request, $user, $directory) = @_; - $request->print('Rename '.$filename.'
to '.
+ '" />
Rename '.$filename.
+ '
to '.
$dest.'?
Delete '.$filename.'?
'); &CloseForm1($request, $cancelurl); } else { @@ -590,11 +605,16 @@ sub Copy1 { if(-e $filename) { $request->print(&checksuffix($filename,$newfilename)); - $request->print(&exists($user, $domain, $dir, $newfilename)); + my $return=&exists($user, $domain, $dir, $newfilename); + $request->print($return); + if ($return =~/^Error:/) { + $request->print('Copy '.$filename.'
to '.
+ '" />
Copy '.$filename.'
to '.
''.$dest.'?
Directory exists.
'); } else { - $request->print('Make new directory '. + $request->print('
Make new directory '. $path."/".$newdir.'?
'); &CloseForm1($request, $cancelurl); @@ -692,6 +712,88 @@ sub NewDir1 =pod +=item NewFile1 + + Does all phase 1 processing of file creation: + Ensures that the user provides a new filename, adds proper extension + if needed and that the file does not already exist, if it is a html, + problem, page, or sequence, it then creates a form link to hand the + actual creation off to the proper handler. + +Parameters: + +=over 4 + +=item $request - Apache Request Object [in] - Server request object for the + current url. + +=item $username - Name of the user that is requesting the directory creation. + +=item $domain - Name of the domain of the user + +=item $dir - current absolute diretory + +=item $newfilename + - Name of the file to be created; no path information +=back + +Side Effects: + +=over 4 + +=item 2 new forms are displayed. Clicking on the confirmation button +causes the browser to attempt to load the specfied URL, allowing the +proper handler to take care of file creation. There is also a Cancle +button which returns you to the driectory listing you came from + +=back + +=cut + + +sub NewFile1 { + my ($request, $user, $domain, $dir, $newfilename) = @_; + + &Debug($request, "Dir is : ".$dir); + &Debug($request, "Newfile is : ".$newfilename); + + my $cancelurl = "/priv/".$dir; + $cancelurl =~ s/\/home\///; + $cancelurl =~ s/\/public_html//; + + if ($ENV{'form.action'} =~ /new(.+)file/) { + my $extension=$1; + if ($newfilename !~ /\Q.$extension\E$/) { + if ($newfilename =~ m|^[^\.]*\.([^\.]+)$|) { + #already has an extension strip it and add in expected one + $newfilename =~ s|.([^\.]+)$||; + } + $newfilename.=".$extension"; + } + } + + my $fullpath = $dir.'/'.$newfilename; + + &Debug($request, "Full path is : ".$fullpath); + + if(-e $fullpath) { + $request->print('File exists.
'); + } + else { + $request->print('Make new file '.$dir.'/'.$newfilename.'?
'); + my $dest=&MakeFinalUrl($request,$fullpath); + &Debug($request, "Cancel url is: ".$cancelurl); + &Debug($request, "Dest url is: ".$dest); + $request->print(''); + $request->print(''); + $request->print(''); + } +} + +=pod + =item phaseone($r, $fn, $uname, $udom) Peforms phase one processing of the request. In phase one, error messages @@ -729,10 +831,10 @@ sub phaseone { # my $conspace=ConstructionPathFromRelative($uname, $fn); - $r->print(''); + } } - } =pod @@ -801,7 +915,7 @@ sub Rename2 { if(-e $oldfile) { unless(rename($oldfile, $directory.'/'.$newfile)) { - $request->print('Error: '.$!.''); + $request->print('Error: '.$!.''); return 0; } else {} } else { @@ -845,11 +959,11 @@ sub Delete2 { if(-e $filename) { unless(unlink($filename)) { - $request->print('Error: '.$!.''); + $request->print('Error: '.$!.''); return 0; } } else { - $request->print('No such file. print('
No such file.
print(' copy Error: '.$!.''); + $request->print(' copy Error: '.$!.''); return 0; } else { unless (chmod(0660, $newfile)) { - $request->print(' chmod error: '.$!.''); + $request->print(' chmod error: '.$!.''); return 0; } return 1; @@ -929,11 +1043,11 @@ sub NewDir2 { my ($request, $user, $newdirectory) = @_; unless(mkdir($newdirectory, 02770)) { - $request->print('Error: '.$!.''); + $request->print('Error: '.$!.''); return 0; } unless(chmod(02770, ($newdirectory))) { - $request->print(' Error: '.$!.''); + $request->print(' Error: '.$!.''); return 0; } return 1; @@ -1017,7 +1131,7 @@ sub phasetwo { # Once a resource is deleted, we just list the directory that # previously held it. # - $dest = $dir."/"; # Parent dir. + $dest = $dir."/."; # Parent dir. } elsif ($ENV{'form.action'} eq 'copy') { if($ENV{'form.newfilename'}) { if(!&Copy2($r, $uname, $dir, $fn, $ENV{'form.newfilename'})) { @@ -1026,7 +1140,7 @@ sub phasetwo { $dest = $ENV{'form.newfilename'}; } else { - $r->print('No New filename specified'); + $r->print('
No New filename specified
'); return; } @@ -1045,18 +1159,24 @@ sub phasetwo { # Substitute for priv for the first home in $dir to get our # construction space path. # + $dest=&MakeFinalUrl($r,$dest); + + $r->print('Unknown Action'); + $r->print('
Unknown Action