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

banghart lon-capa-cvs@mail.lon-capa.org
Tue, 19 Oct 2004 19:13:04 -0000


banghart		Tue Oct 19 15:13:04 2004 EDT

  Modified files:              
    /loncom/interface	portfolio.pm 
  Log:
  	Permit upload of files during fileselect 
  	in responding to essay problem.
  	Still need to confirm ability to navigate directory structure,
  	and create directories in file select mode
  
  
Index: loncom/interface/portfolio.pm
diff -u loncom/interface/portfolio.pm:1.49 loncom/interface/portfolio.pm:1.50
--- loncom/interface/portfolio.pm:1.49	Mon Oct 18 16:37:30 2004
+++ loncom/interface/portfolio.pm	Tue Oct 19 15:13:04 2004
@@ -44,8 +44,10 @@
     $r->print('<table border="0" cellspacing="2" cellpadding="2"><tr valign="middle">');
     $r->print('<td bgcolor="#ccddaa" align="center">');
     my $displayOut = '<form method="post" enctype="multipart/form-data">';
-    $displayOut = $displayOut.'<input name="uploaddoc" type="file" />'.
+    $displayOut .= '<input name="uploaddoc" type="file" />'.
         '<input type="hidden" name="currentpath" value="'.$current_path.'" />'.
+        '<input type="hidden" name="action" value="'.$ENV{"form.action"}.'" />'.
+        '<input type="hidden" name="fieldname" value="'.$ENV{"form.fieldname"}.'" />'.
         '<input type="submit" name="storeupl" value="Upload" />'.
         '</form>';
     $r->print($displayOut);
@@ -53,6 +55,8 @@
     $displayOut = '<form method="post">';
     $displayOut .= '<input name="newdir" type="input" />'.
         '<input type="hidden" name="currentpath" value="'.$current_path.'" />'.
+        '<input type="hidden" name="action" value="'.$ENV{"form.action"}.'" />'.
+        '<input type="hidden" name="fieldname" value="'.$ENV{"form.fieldname"}.'" />'.
         '<input type="submit" name="createdir" value="'.&mt("Create Directory").'" />'.
         '</form>';
     $r->print($displayOut);
@@ -226,7 +230,9 @@
 
 sub done {
     return ('<h3><a href="/adm/portfolio?currentpath='.
-	    $ENV{'form.currentpath'}.'">'.&mt('Done').'</a></h3>');
+	    $ENV{'form.currentpath'}.
+	    '&fieldname='.$ENV{'form.fieldname'}.
+	    '">'.&mt('Done').'</a></h3>');
 }
 
 sub delete {
@@ -336,41 +342,6 @@
     $r->print($java_script);
     $r->print("<h1>Select portfolio files</h1>
                 Check as many as you wish in response to the essay problem.<br />");
-    my $portfolio_root = &Apache::loncommon::propath($ENV{'user.domain'},
-						 $ENV{'user.name'}).
-						'/userfiles/portfolio';
-    my $current_path='/';
-    if ($ENV{'form.currentpath'}) {
-	$current_path = $ENV{'form.currentpath'};
-    }
-    my @dir_list=&Apache::lonnet::dirlist($current_path,
-				    $ENV{'user.domain'},
-				    $ENV{'user.name'},$portfolio_root);
-    if ($dir_list[0] eq 'no_such_dir'){
-	# two main reasons for this:
-        #    1) never been here, so directory structure not created,
-	#    2) back-button navigation after deleting a directory
-        if ($current_path eq '/'){
-	        &Apache::lonnet::mkdiruserfile($ENV{'user.name'},
-					       $ENV{'user.domain'},'portfolio');
-	} else {
-                # some directory that snuck in get rid of the directory
-                # from the recent pulldown, just in case
-	&Apache::lonhtmlcommon::remove_recent('portfolio',
-					      [$current_path]);
-	$current_path = '/'; # force it back to the root        
-	}
-	    # now grab the directory list again, for the first time
-	    @dir_list=&Apache::lonnet::dirlist($current_path,
-					    $ENV{'user.domain'},
-					    $ENV{'user.name'},$portfolio_root);
-    }
-    # need to know if directory is empty so it can be removed if desired
-    my $is_empty=(@dir_list == 2);
-    &display_common($r,$current_path,$is_empty,\@dir_list);
-    &display_file_select($r,$current_path,$is_empty,\@dir_list);
-    $r->print("</body>\n</html>\n");
-    return OK;
 }
 sub upload {
     my ($r)=@_;
@@ -473,8 +444,6 @@
 	}
     if ($ENV{'form.uploaddoc.filename'}) {
 	&upload($r);
-    } elsif ($ENV{'form.action'} eq 'selectfile') {
-        &select_files($r);
     } elsif ($ENV{'form.action'} eq 'delete' && $ENV{'form.confirmed'}) {
 	&delete_confirmed($r);
     } elsif ($ENV{'form.action'} eq 'delete') {
@@ -519,7 +488,12 @@
 	# need to know if directory is empty so it can be removed if desired
 	my $is_empty=(@dir_list == 2);
 	&display_common($r,$current_path,$is_empty,\@dir_list);
-	&display_directory($r,$current_path,$is_empty,\@dir_list);
+	if ($ENV{"form.mode"}='selectfile'){
+	    &select_files($r);
+            &display_file_select($r,$current_path,$is_empty,\@dir_list);
+	} else {
+	    &display_directory($r,$current_path,$is_empty,\@dir_list);
+	}
 	$r->print("</body>\n</html>\n");
 	return OK;
     }