--- loncom/interface/portfolio.pm	2004/11/10 05:57:53	1.56
+++ loncom/interface/portfolio.pm	2004/12/04 18:37:36	1.61
@@ -33,8 +33,8 @@ use Apache::lonlocal;
 # receives a file name and path stub from username/userfiles/portfolio/
 # returns an anchor tag consisting encoding filename and currentpath
 sub make_anchor {
-    my ($filename, $current_path) = @_;
-    my $anchor = '<a href="/adm/portfolio?selectfile='.$filename.'&currentpath='.$current_path.'">'.$filename.'</a>';
+    my ($filename, $current_path, $current_mode, $field_name) = @_;
+    my $anchor = '<a href="/adm/portfolio?selectfile='.$filename.'&currentpath='.$current_path.'&mode='.$current_mode.'&fieldname='.$field_name.'">'.$filename.'</a>';
     return $anchor;
 }
 my $dirptr=16384;
@@ -48,6 +48,7 @@ sub display_common {
         '<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="hidden" name="mode" value="'.$ENV{"form.mode"}.'" />'. 
         '<input type="submit" name="storeupl" value="Upload" />'.
         '</form>';
     $r->print($displayOut);
@@ -57,22 +58,23 @@ sub display_common {
         '<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="hidden" name="mode" value="'.$ENV{"form.mode"}.'" />'. 
         '<input type="submit" name="createdir" value="'.&mt("Create Directory").'" />'.
         '</form>';
     $r->print($displayOut);
     $r->print('</td></tr></table>');
     my @tree = split (/\//,$current_path);
-    $r->print('<font size="+2">'.&make_anchor('portfolio','/').'/');
+    $r->print('<font size="+2">'.&make_anchor('portfolio','/',$ENV{"form.mode"},$ENV{"form.fieldname"}).'/');
     if (@tree > 1){
         my $newCurrentPath = '';
         for (my $i = 1; $i< @tree; $i++){
             $newCurrentPath .= $tree[$i].'/';
-            $r->print(&make_anchor($tree[$i],'/'.$newCurrentPath).'/');
+            $r->print(&make_anchor($tree[$i],'/'.$newCurrentPath, $ENV{"form.mode"},$ENV{"form.fieldname"}).'/');
         }
     }
     $r->print('</font>');
     &Apache::lonhtmlcommon::store_recent('portfolio',$current_path,$current_path);
-    $r->print('<br /><form method=post action="/adm/portfolio">'.
+    $r->print('<br /><form method=post action="/adm/portfolio?mode='.$ENV{"form.mode"}.'&fieldname='.$ENV{"form.fieldname"}.'">'.
 	      &Apache::lonhtmlcommon::select_recent('portfolio','currentpath',
 						    'this.form.submit();'));
     $r->print("</form>");
@@ -110,18 +112,11 @@ sub display_directory {
     	#$strip holds directory/file name
     	#$dom 
     	my ($filename,$dom,undef,$testdir,undef,undef,undef,undef,$size,undef,$mtime,undef,undef,undef,$obs,undef)=split(/\&/,$line,16); 
-    	if ($Apache::lonhomework::results{"resource.$ENV{'user.domain'}.$ENV{'user.name'}.$filename"}eq'true'){
-    	    &Apache::lonnet::logthis("found submitted file");
-    	    &Apache::lonnet::logthis("resource.$ENV{'user.domain'}.$ENV{'user.name'}.$filename");
-    	} else {
-    	    &Apache::lonnet::logthis("$filename not found submitted file");
-    	    &Apache::lonnet::logthis("resource.$ENV{'user.domain'}.$ENV{'user.name'}.$filename");
-    	}
     	if (($filename ne '.') && ($filename ne '..')) {
             if ($dirptr&$testdir) {
                 $r->print('<tr bgcolor="#FFAA99"><td><img src="'.$iconpath.'folder_closed.gif"></td>');
                 $r->print('<td>Go to ...</td>');
-                $r->print('<td>'.&make_anchor($filename.'/',$current_path.$filename.'/').'</td>'); 
+                $r->print('<td>'.&make_anchor($filename.'/',$current_path.$filename.'/',$ENV{'form.mode'},$ENV{"form.fieldname"}).'</td>'); 
                 $r->print('</tr>'); 
             } else {
                 $r->print('<tr bgcolor="#CCCCFF">');
@@ -157,6 +152,10 @@ sub display_file_select {
     my ($r,$current_path,$is_empty,$dir_list)=@_;
     my $iconpath= $r->dir_config('lonIconsURL') . "/";
     my $display_out;
+    my $checked_files = &Apache::lonnet::files_in_path($ENV{'user.name'}, $ENV{'form.currentpath'});
+    foreach my $key (keys %$checked_files) {
+        &Apache::lonnet::logthis("a key is $key $$checked_files{$key} is the value");
+    }
     if ($is_empty && ($current_path ne '/')) {
         $display_out = '<form method="post" action="/adm/portfolio">'.
         '<input type="hidden" name="action" value="deletedir" />'.
@@ -182,17 +181,23 @@ sub display_file_select {
     	#$strip holds directory/file name
     	#$dom 
     	my ($filename,$dom,undef,$testdir,undef,undef,undef,undef,$size,undef,$mtime,undef,undef,undef,$obs,undef)=split(/\&/,$line,16); 
+    	$filename =~ s/\s+$//;
     	if (($filename ne '.') && ($filename ne '..')) {
             if ($dirptr&$testdir) {
                 $r->print('<tr bgcolor="#FFAA99"><td><img src="'.$iconpath.'folder_closed.gif"></td>');
                 $r->print('<td>Go to ...</td>');
-                $r->print('<td>'.&make_anchor($filename.'/',$current_path.$filename.'/').'</td>'); 
+                $r->print('<td>'.&make_anchor($filename.'/',$current_path.$filename.'/',$ENV{'form.mode'},$ENV{"form.fieldname"}).'</td>'); 
                 $r->print('</tr>'); 
             } else {
                 $r->print('<tr bgcolor="#CCCCFF">');
-                $r->print('<td>
-                        <input type="checkbox" name="selectedfile" value="'.$filename.'" >
-                    </td>');
+                $r->print('<td><input type="checkbox" name="selectedfile" value="'.$filename.'"'); 
+                if ($$checked_files{$filename} eq 'selected') {
+                    $r->print("CHECKED");
+                    &Apache::lonnet::logthis("checked");
+                } else {
+                    &Apache::lonnet::logthis("not checked $$checked_files{$filename} $filename");
+                }
+                $r->print('></td>');
                 $r->print('<td><img src="'.$iconpath.'unknown.gif"></td>');
                 $r->print('<td><a href="'.$href_location.$filename.'">'.
 			    $filename.'</a></td>'); 
@@ -203,6 +208,10 @@ sub display_file_select {
         }
     }
     $r->print('</table>
+            <input type="hidden" name="continue" value="true">
+            <input type="hidden" name="fieldname" value="'.$ENV{'form.fieldname'}.'">
+            <input type="hidden" name="mode" value="selectfile">
+            <input type="submit" name="submit" value="Select checked files, and continue selecting." /><br />
             <input type="button" name="doit" onClick= "finishSelect();" value="Select checked files, and close window" />
             <input type="hidden" name="currentpath" value="'.$current_path.'" />
     </form>');
@@ -244,6 +253,7 @@ sub done {
     return ('<h3><a href="/adm/portfolio?currentpath='.
 	    $ENV{'form.currentpath'}.
 	    '&fieldname='.$ENV{'form.fieldname'}.
+	    '&mode='.$ENV{'form.mode'}.
 	    '">'.&mt('Done').'</a></h3>');
 }
 
@@ -336,7 +346,7 @@ sub rename_confirmed {
     my $result=
 	&Apache::lonnet::renameuserfile($ENV{'user.name'},$ENV{'user.domain'},
             'portfolio'.$ENV{'form.currentpath'}.$ENV{'form.selectfile'},
-            'portfolio'.$ENV{'form.currentpath'}.$ENV{'form.filenewname'});
+            'portfolio'.$ENV{'form.currentpath'}.$filenewname);
     if ($result ne 'ok') {
 	$r->print('<font color="red"> An errror occured ('.$result.
 		  ') while trying to rename '.&display_file().' to '.
@@ -346,6 +356,12 @@ sub rename_confirmed {
 }
 sub select_files {
     my ($r)=@_;
+    if ($ENV{'form.continue'} eq 'true') {
+        # here we update the selections for the currentpath
+        # eventually, have to handle removing those not checked, but . . . 
+        my @items=&Apache::loncommon::get_env_multiple('form.selectedfile');
+        &Apache::lonnet::save_selected_files($ENV{'user.name'}, $ENV{'form.currentpath'}, @items);
+    }
     my $java_script =(<<ENDSMP);
         <script language='javascript'>
         function finishSelect() {
@@ -367,6 +383,10 @@ ENDSMP
     $r->print($java_script);
     $r->print("<h1>Select portfolio files</h1>
                 Check as many as you wish in response to the essay problem.<br />");
+    $r->print("<strong>Files selected from other directories:</strong><br />");
+    foreach (&Apache::lonnet::files_not_in_path($ENV{'user.name'}, $ENV{'form.currentpath'})) {
+        $r->print($_."<br />");
+    }
 }
 sub upload {
     my ($r)=@_;