[LON-CAPA-cvs] cvs: loncom /interface portfolio.pm
banghart
lon-capa-cvs@mail.lon-capa.org
Mon, 06 Sep 2004 23:59:05 -0000
banghart Mon Sep 6 19:59:05 2004 EDT
Modified files:
/loncom/interface portfolio.pm
Log:
Fixme #1 removed: Improved error message for trying to create
a subdirectory when a file or directory by that name already
exists.
Index: loncom/interface/portfolio.pm
diff -u loncom/interface/portfolio.pm:1.36 loncom/interface/portfolio.pm:1.37
--- loncom/interface/portfolio.pm:1.36 Mon Sep 6 19:11:57 2004
+++ loncom/interface/portfolio.pm Mon Sep 6 19:59:05 2004
@@ -407,20 +407,37 @@
sub createdir {
my ($r)=@_;
- #FIXME 1) file exists in place of dir (errormessage needs improvement)
my $newdir=&Apache::lonnet::clean_filename($ENV{'form.newdir'});
if ($newdir eq '') {
- $r->print('<font color="red">'.
- &mt("Error: no valid directory name was provided.").
- '</font><br />');
- $r->print(&done());
- return;
+ $r->print('<font color="red">'.
+ &mt("Error: no directory name was provided.").
+ '</font><br />');
+ $r->print(&done());
+ return;
}
- my $result=&Apache::lonnet::mkdiruserfile($ENV{'user.name'},
- $ENV{'user.domain'},'portfolio'.$ENV{'form.currentpath'}.$newdir);
- if ($result ne 'ok') {
- $r->print('<font color="red"> An errror occured ('.$result.
- ') while trying to create a new directory '.&display_file().'</font><br />');
+ my $portfolio_root = &Apache::loncommon::propath($ENV{'user.domain'},
+ $ENV{'user.name'}).
+ '/userfiles/portfolio';
+ my @dir_list=&Apache::lonnet::dirlist($ENV{'form.currentpath'},
+ $ENV{'user.domain'},
+ $ENV{'user.name'},$portfolio_root);
+ my $found_file = 0;
+ foreach my $line (@dir_list) {
+ my ($filename)=split(/\&/,$line,2);
+ if ($filename eq $newdir){
+ $found_file = 1;
+ }
+ }
+ if ($found_file){
+ $r->print('<font color="red"> Unable to create a directory named <strong>'.$newdir.
+ ' </strong>a file or directory by that name already exists.</font><br />');
+ } else {
+ my $result=&Apache::lonnet::mkdiruserfile($ENV{'user.name'},
+ $ENV{'user.domain'},'portfolio'.$ENV{'form.currentpath'}.$newdir);
+ if ($result ne 'ok') {
+ $r->print('<font color="red"> An errror occured ('.$result.
+ ') while trying to create a new directory '.&display_file().'</font><br />');
+ }
}
$r->print(&done());
}