--- loncom/interface/groupsort.pm	2001/12/11 03:37:11	1.5
+++ loncom/interface/groupsort.pm	2002/05/09 20:57:26	1.8
@@ -2,7 +2,7 @@
 # The LON-CAPA group sort handler
 # Allows for sorting prior to import into RAT.
 #
-# $Id: groupsort.pm,v 1.5 2001/12/11 03:37:11 harris41 Exp $
+# $Id: groupsort.pm,v 1.8 2002/05/09 20:57:26 www Exp $
 # 
 # Copyright Michigan State University Board of Trustees
 #
@@ -28,6 +28,8 @@
 #
 # YEAR=2001
 # 8/7,8/8,10/14,10/15,12/10 Scott Harrison
+# YEAR=2002
+# 1/17 Scott Harrison
 #
 ###
 
@@ -53,7 +55,38 @@ sub handler {
     $r->send_http_header;
     return OK if $r->header_only;
 
-    # output start of web page
+# finish_import looks different for graphical or "simple" RAT
+    my $finishimport='';
+    if ($ENV{'form.mode'} eq 'simple') {
+        $finishimport=(<<ENDSMP);
+function finish_import() {
+    alert("Finishing a simple import");
+}
+ENDSMP
+    } else {
+        $finishimport=(<<ENDADV);
+function finish_import() {
+    var linkflag=false;
+    for (var num=0; num<document.forms.groupsort.fnum.value; num++) {
+	insertRowInLastRow();
+	placeResourceInLastRow(
+	       eval("document.forms.groupsort.title"+num+".value"),
+ 	       eval("document.forms.groupsort.filelink"+num+".value"),
+	       linkflag
+	);
+        linkflag=true;
+    }
+    opener.editmode=0;
+    opener.notclear=0;
+    opener.linkmode=0;
+    opener.draw();
+    self.close();
+}
+ENDADV
+    }
+
+# output start of web page
+
     $r->print(<<END);
 <html>
 <head>
@@ -73,24 +106,7 @@ function placeResourceInLastRow (title,u
     }
     opener.linkmode=opener.mostrecent;
 }
-function finish_import() {
-    var linkflag=false;
-    for (var num=0; num<document.forms.groupsort.fnum.value; num++) {
-	insertRowInLastRow();
-	placeResourceInLastRow(
-	       eval("document.forms.groupsort.title"+num+".value"),
- 	       eval("document.forms.groupsort.filelink"+num+".value"),
-	       linkflag
-	);
-        linkflag=true;
-    }
-    opener.editmode=0;
-    opener.notclear=0;
-    opener.linkmode=0;
-    opener.infoclear();
-    opener.draw();
-    self.close();
-}
+$finishimport
 function selectchange(val) {
     var newval=0+eval("document.forms.groupsort.alt"+val+".selectedIndex");
     orderchange(val,newval);
@@ -134,6 +150,29 @@ END
 	$diropendb = 
 	    "/home/httpd/perl/tmp/$domain\_$ENV{'user.name'}_indexer.db";
     }
+    else { # choose last accessed
+	my $dsearch; my $dindex;
+	my $dsearcht; my $dindext;
+	$dsearch =
+	    "/home/httpd/perl/tmp/$domain\_$ENV{'user.name'}_searchcat.db";
+	if (-e $dsearch) {
+	    $dsearcht=(stat($dsearch))[9];
+	}
+	$dindex =
+            "/home/httpd/perl/tmp/$domain\_$ENV{'user.name'}_indexer.db";
+	if (-e $dindex) {
+            $dindext=(stat($dindex))[9];
+        }
+	if (!$dsearcht and !$dindext) {
+	    $diropendb='';
+	}
+        elsif ($dsearcht>$dindext) {
+            $diropendb=$dsearch;
+        }
+	else {
+            $diropendb=$dindex;
+	}
+    }
     if (tie(%hash,'GDBM_File',$diropendb,&GDBM_WRCREAT,0640)) {
 	my $acts = $ENV{'form.acts'};
 	my @Acts = split(/b/,$acts);