--- loncom/lonnet/perl/lonnet.pm	2004/11/11 22:39:05	1.569
+++ loncom/lonnet/perl/lonnet.pm	2004/12/04 18:35:27	1.573
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # TCP networking package
 #
-# $Id: lonnet.pm,v 1.569 2004/11/11 22:39:05 albertel Exp $
+# $Id: lonnet.pm,v 1.573 2004/12/04 18:35:27 banghart Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -38,7 +38,7 @@ use vars
 qw(%perlvar %hostname %homecache %badServerCache %hostip %iphost %spareid %hostdom 
    %libserv %pr %prp %metacache %packagetab %titlecache %courseresversioncache %resversioncache
    %courselogs %accesshash %userrolehash $processmarker $dumpcount 
-   %coursedombuf %coursenumbuf %coursehombuf %coursedescrbuf %courseinstcodebuf %courseresdatacache 
+   %coursedombuf %coursenumbuf %coursehombuf %coursedescrbuf %courseinstcodebuf %courseownerbuf %courseresdatacache 
    %userresdatacache %getsectioncache %domaindescription %domain_auth_def %domain_auth_arg_def 
    %domain_lang_def %domain_city %domain_longi %domain_lati $tmpdir $_64bit);
 
@@ -1407,9 +1407,9 @@ sub finishuserfileupload {
 # Save the file
     {
 	#&Apache::lonnet::logthis("Saving to $filepath $file");
-       open(my $fh,'>'.$filepath.'/'.$file);
-       print $fh $ENV{'form.'.$formname};
-       close($fh);
+	open(FH,'>'.$filepath.'/'.$file);
+	print FH $ENV{'form.'.$formname};
+	close(FH);
     }
 # Notify homeserver to grep it
 #
@@ -1490,12 +1490,12 @@ sub flushcourselogs {
         if ($courseidbuffer{$coursehombuf{$crsid}}) {
            $courseidbuffer{$coursehombuf{$crsid}}.='&'.
 			 &escape($crsid).'='.&escape($coursedescrbuf{$crsid}).
-                         '='.&escape($courseinstcodebuf{$crsid});
+                         ':'.&escape($courseinstcodebuf{$crsid}).':'.&escape($courseownerbuf{$crsid});
         } else {
            $courseidbuffer{$coursehombuf{$crsid}}=
 			 &escape($crsid).'='.&escape($coursedescrbuf{$crsid}).
-                         '='.&escape($courseinstcodebuf{$crsid});
-        }    
+                         ':'.&escape($courseinstcodebuf{$crsid}).':'.&escape($courseownerbuf{$crsid});
+        }
     }
 #
 # Write course id database (reverse lookup) to homeserver of courses 
@@ -1570,6 +1570,8 @@ sub courselog {
        $ENV{'course.'.$ENV{'request.course.id'}.'.description'};
     $courseinstcodebuf{$ENV{'request.course.id'}}=
        $ENV{'course.'.$ENV{'request.course.id'}.'.internal.coursecode'};
+    $courseownerbuf{$ENV{'request.course.id'}}=
+       $ENV{'course.'.$ENV{'request.course.id'}.'.internal.courseowner'};
     if (defined $courselogs{$ENV{'request.course.id'}}) {
 	$courselogs{$ENV{'request.course.id'}}.='&'.$what;
     } else {
@@ -1713,7 +1715,7 @@ sub courseidput {
 }
 
 sub courseiddump {
-    my ($domfilter,$descfilter,$sincefilter,$hostidflag,$hostidref)=@_;
+    my ($domfilter,$descfilter,$sincefilter,$instcodefilter,$ownerfilter,$hostidflag,$hostidref)=@_;
     my %returnhash=();
     unless ($domfilter) { $domfilter=''; }
     foreach my $tryserver (keys %libserv) {
@@ -1721,7 +1723,8 @@ sub courseiddump {
 	    if ((!$domfilter) || ($hostdom{$tryserver} eq $domfilter)) {
 	        foreach (
                  split(/\&/,&reply('courseiddump:'.$hostdom{$tryserver}.':'.
-			       $sincefilter.':'.&escape($descfilter),
+			       $sincefilter.':'.&escape($descfilter).':'.
+                               &escape($instcodefilter).':'.&escape($ownerfilter),
                                $tryserver))) {
 		    my ($key,$value)=split(/\=/,$_);
                     if (($key) && ($value)) {
@@ -3687,7 +3690,7 @@ sub writecoursepref {
 # ---------------------------------------------------------- Make/modify course
 
 sub createcourse {
-    my ($udom,$description,$url,$course_server,$nonstandard,$inst_code)=@_;
+    my ($udom,$description,$url,$course_server,$nonstandard,$inst_code,$course_owner)=@_;
     $url=&declutter($url);
     my $cid='';
     unless (&allowed('ccc',$udom)) {
@@ -3722,7 +3725,7 @@ sub createcourse {
 # ----------------------------------------------------------------- Course made
 # log existence
     &courseidput($udom,&escape($udom.'_'.$uname).'='.&escape($description).
-                 '='.&escape($inst_code),$uhome);
+                 ':'.&escape($inst_code).':'.&escape($course_owner),$uhome);
     &flushcourselogs();
 # set toplevel url
     my $topurl=$url;
@@ -3809,6 +3812,72 @@ sub mark_as_readonly {
     return;
 }
 
+# ------------------------------------------------------------Save Selected Files
+
+sub save_selected_files {
+    my ($user, $path, @files) = @_;
+    my $filename = $user."savedfiles";
+    my @other_files = &files_not_in_path($user, $path);
+    foreach (@other_files) {
+        &logthis("other dir file $_");
+    }
+    foreach (@files) {
+        &logthis("current dir file $_");
+    }
+    open OUT, '>'.$Apache::lonnet::perlvar{'lonDaemons'}.'/tmp/'.$filename;
+    foreach my $file (@files) {
+        print OUT $ENV{'form.currentpath'}.$file."\n";
+    }
+    foreach my $file (@other_files) {
+        print OUT $file."\n";
+    }
+    close OUT;
+    return 'ok';
+}
+
+sub files_in_path {
+    my ($user, $path) = @_;
+    my $filename = $user."savedfiles";
+    my %return_files;
+    open IN, '<'.$Apache::lonnet::perlvar{'lonDaemons'}.'/tmp/'.$filename;
+    while (my $line_in = <IN>) {
+        chomp $line_in;
+        my @paths_and_file = split m!/!, $line_in;
+        my $file_part = pop @paths_and_file;
+        my $path_part = join '/', @paths_and_file;
+        $path_part.='/';
+        my $path_and_file = $path_part.$file_part;
+        if ($path_part eq $path) {
+            $return_files{$file_part}= 'selected';
+        }
+    }
+    close IN;
+    return \%return_files;
+}
+
+# called in portfolio select mode, to show files selected NOT in current directory
+sub files_not_in_path {
+    my ($user, $path) = @_;
+    my $filename = $user."savedfiles";
+    my @return_files;
+    my $path_part;
+    open IN, '<'.$Apache::lonnet::perlvar{'lonDaemons'}.'/tmp/'.$filename;
+    while (<IN>) {
+        #ok, I know it's clunky, but I want it to work
+        my @paths_and_file = split m!/!, $_;
+        my $file_part = pop @paths_and_file;
+        chomp $file_part;
+        my $path_part = join '/', @paths_and_file;
+        $path_part .= '/';
+        my $path_and_file = $path_part.$file_part;
+        if ($path_part ne $path) {
+            push @return_files, ($path_and_file);
+        }
+    }
+    close OUT;
+    return @return_files;
+}
+
 #--------------------------------------------------------------Get Marked as Read Only
 
 sub get_marked_as_readonly {