[LON-CAPA-cvs] cvs: loncom /publisher loncfile.pm
albertel
lon-capa-cvs@mail.lon-capa.org
Tue, 04 Feb 2003 21:54:17 -0000
albertel Tue Feb 4 16:54:17 2003 EDT
Modified files:
/loncom/publisher loncfile.pm
Log:
- added code for new file creation
Index: loncom/publisher/loncfile.pm
diff -u loncom/publisher/loncfile.pm:1.21 loncom/publisher/loncfile.pm:1.22
--- loncom/publisher/loncfile.pm:1.21 Thu Jan 9 17:11:52 2003
+++ loncom/publisher/loncfile.pm Tue Feb 4 16:54:17 2003
@@ -10,7 +10,7 @@
#
#
-# $Id: loncfile.pm,v 1.21 2003/01/09 22:11:52 albertel Exp $
+# $Id: loncfile.pm,v 1.22 2003/02/04 21:54:17 albertel Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -128,7 +128,7 @@
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);
@@ -413,7 +413,7 @@
&Debug($request, "Cancel url is: ".$cancelurl);
$request->print('<p><input type=submit value=Continue></p></form>');
$request->print('<form action="'.$cancelurl.
- '" method=GET"><p><input type=submit value=Cancel><p></form>');
+ '" method="GET"><p><input type=submit value=Cancel><p></form>');
}
@@ -706,6 +706,84 @@
=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$/) {
+ $newfilename.=".$extension";
+ }
+ }
+
+ my $fullpath = $dir.'/'.$newfilename;
+
+ &Debug($request, "Full path is : ".$fullpath);
+
+ if(-e $fullpath) {
+ $request->print('<p>File exists.</p></form>');
+ }
+ else {
+ $request->print('<p>Make new file <tt>'.$newfilename.'</tt>?</p>');
+ my $dest=&MakeFinalUrl($request,$fullpath);
+ &Debug($request, "Cancel url is: ".$cancelurl);
+ &Debug($request, "Dest url is: ".$dest);
+ $request->print('</form>');
+ $request->print('<form action="'.$dest.
+ '" method="GET"><p><input type="submit" value="Continue" /></p></form>');
+ $request->print('<form action="'.$cancelurl.
+ '" method="GET"><p><input type="submit" value="Cancel" /></p></form>');
+ }
+}
+
+=pod
+
=item phaseone($r, $fn, $uname, $udom)
Peforms phase one processing of the request. In phase one, error messages
@@ -765,8 +843,20 @@
}
} elsif ($ENV{'form.action'} eq 'newdir') {
&NewDir1($r, $uname, $dir, $ENV{'form.newfilename'});
+ } elsif ($ENV{'form.action'} eq 'newfile' ||
+ $ENV{'form.action'} eq 'newhtmlfile' ||
+ $ENV{'form.action'} eq 'newproblemfile') {
+ if($ENV{'form.newfilename'}) {
+ my $newfilename = $ENV{'form.newfilename'};
+ if (!defined($dir)) {
+ $fn=~m:(.*)/:;
+ $dir=$1;
+ }
+ &NewFile1($r, $uname, $udom, $dir, $fn, $newfilename);
+ }else {
+ $r->print('<p>No new filename specified.</p></form>');
+ }
}
-
}
=pod
@@ -1059,19 +1149,24 @@
# Substitute for priv for the first home in $dir to get our
# construction space path.
#
+ $dest=&MakeFinalUrl($r,$dest);
+
+ $r->print('<h3><a href="'.$dest.'">Done</a></h3>');
+}
+
+sub MakeFinalUrl {
+ my($r,$dest)=@_;
&Debug($r, "Final url is: $dest");
$dest =~ s|/home/|/priv/|;
$dest =~ s|/public_html||;
-
+
my $base = &File::Basename::basename($dest);
my $dpath= &File::Basename::dirname($dest);
if ($base eq '.') { $base=''; }
$dest = &HTML::Entities::encode($dpath.'/'.$base);
-
&Debug($r, "Final url after rewrite: $dest");
-
- $r->print('<h3><a href="'.$dest.'">Done</a></h3>');
+ return $dest;
}
sub handler {
@@ -1086,7 +1181,7 @@
my $fn;
if ($ENV{'form.filename'}) {
- $fn=$ENV{'form.filename'};
+ $fn=&Apache::lonnet::unescape($ENV{'form.filename'});
&Debug($r, "loncfile::handler - raw url: $fn");
# $fn=~s/^http\:\/\/[^\/]+\/\~(\w+)/\/home\/$1\/public_html/;
# $fn=~s/^http\:\/\/[^\/]+//;
@@ -1153,6 +1248,10 @@
$r->print('<h3>New Directory</h3>');
} elsif ($ENV{'form.action'} eq 'copy') {
$r->print('<h3>Copy</h3>');
+ } elsif ($ENV{'form.action'} eq 'newfile' ||
+ $ENV{'form.action'} eq 'newhtmlfile' ||
+ $ENV{'form.action'} eq 'newproblemfile') {
+ $r->print('<h3>New Resource</h3>');
} else {
$r->print('<p>Unknown Action</body></html>');
return OK;