[LON-CAPA-cvs] cvs: loncom /interface portfolio.pm

banghart lon-capa-cvs@mail.lon-capa.org
Sun, 20 Feb 2005 20:39:30 -0000


banghart		Sun Feb 20 15:39:30 2005 EDT

  Modified files:              
    /loncom/interface	portfolio.pm 
  Log:
  	Bug 3919: Better error messages for uploading files. 
  
  
Index: loncom/interface/portfolio.pm
diff -u loncom/interface/portfolio.pm:1.75 loncom/interface/portfolio.pm:1.76
--- loncom/interface/portfolio.pm:1.75	Thu Feb 17 03:29:43 2005
+++ loncom/interface/portfolio.pm	Sun Feb 20 15:39:30 2005
@@ -253,11 +253,15 @@
 }
 
 sub done {
+    my ($message)=@_;
+    unless (defined $message) {
+        $message='Done';
+    }
     return ('<h3><a href="/adm/portfolio?currentpath='.
 	    $ENV{'form.currentpath'}.
 	    '&fieldname='.$ENV{'form.fieldname'}.
 	    '&mode='.$ENV{'form.mode'}.
-	    '">'.&mt('Done').'</a></h3>');
+	    '">'.&mt($message).'</a></h3>');
 }
 
 sub delete {
@@ -268,7 +272,7 @@
 
     if (&Apache::lonnet::is_locked($file_name,$ENV{'user.domain'},$ENV{'user.name'} ) eq 'true') {
         $r->print ("The file is locked and cannot be deleted.<br />");
-        $r->print(&done());
+        $r->print(&done('Back'));
     } else {
         if (scalar(@files)) {
             &open_form($r);
@@ -431,29 +435,43 @@
 					  $ENV{'user.domain'},
 					  $ENV{'user.name'},$portfolio_root);
     my $found_file = 0;
+    my $locked_file = 0;
     foreach my $line (@dir_list) {
-        my ($filename)=split(/\&/,$line,2);
-        if ($filename eq $fname){
+        my ($file_name)=split(/\&/,$line,2);
+        if ($file_name eq $fname){
             $found_file = 1;
+            if (&Apache::lonnet::is_locked($ENV{'form.currentpath'}.$file_name,$ENV{'user.domain'},$ENV{'user.name'} ) eq 'true') {
+                $locked_file = 1;
+            } 
         }
     }
     my $current_disk_usage = &Apache::lonnet::diskusage($ENV{'user.domain'}, $ENV{'user.name'},$portfolio_root);
     if ((($current_disk_usage/1000) + $filesize) > $disk_quota){
         $r->print('<font color="red">Unable to upload <strong>'.$fname.' (size = '.$filesize.' kilobytes</strong>. Disk quota will be exceeded.'.
                   '<br />Disk quota is '.$disk_quota.' kilobytes. Your current disk usage is '.$current_disk_usage.' kilobytes.');
+        $r->print(&done('Back'));
     } 
-    elsif ($found_file){   
-        $r->print('<font color="red">Unable to upload <strong>'.$fname.'</strong>, a file by that name was found in <strong>'.$ENV{'form.currentpath'}.'</strong></font>'.
-                  '<br />To upload, rename or delete existing '.$fname.' in '.$ENV{'form.currentpath'});
+    elsif ($found_file){
+        if ($locked_file){
+            $r->print('<font color="red">Unable to upload <strong>'.$fname.'</strong>, a <strong>locked</strong> file by that name was found in <strong>portfolio'.$ENV{'form.currentpath'}.'</strong></font>'.
+                  '<br />You will be able to rename or delete existing '.$fname.' after a grade has been assigned.');
+            $r->print(&done('Back'));      
+        } else {   
+            $r->print('<font color="red">Unable to upload <strong>'.$fname.'</strong>, a file by that name was found in <strong>portfolio'.$ENV{'form.currentpath'}.'</strong></font>'.
+                  '<br />To upload, rename or delete existing '.$fname.' in portfolio'.$ENV{'form.currentpath'});
+            $r->print(&done('Back'));
+        }
     } else {
         my $result=&Apache::lonnet::userfileupload('uploaddoc','',
 	        	 'portfolio'.$ENV{'form.currentpath'});
         if ($result !~ m|^/uploaded/|) {
             $r->print('<font color="red"> An errror occured ('.$result.
 	              ') while trying to upload '.&display_file().'</font><br />');
+	    $r->print(&done('Back'));
+        } else {
+            $r->print(&done());
         }
     }
-    $r->print(&done());
 }
 
 sub createdir {