--- loncom/interface/groupsort.pm	2005/06/10 15:17:35	1.35
+++ loncom/interface/groupsort.pm	2006/03/26 19:44:45	1.41
@@ -2,7 +2,7 @@
 # The LON-CAPA group sort handler
 # Allows for sorting prior to import into RAT.
 #
-# $Id: groupsort.pm,v 1.35 2005/06/10 15:17:35 www Exp $
+# $Id: groupsort.pm,v 1.41 2006/03/26 19:44:45 banghart Exp $
 # 
 # Copyright Michigan State University Board of Trustees
 #
@@ -195,6 +195,7 @@ sub cleanup {
 	    &Apache::lonnet::logthis('Failed cleanup groupsort: hash');
         }
     }
+    return OK;
 }
 
 # -------------------------------------------------------------- Read from file
@@ -227,6 +228,7 @@ sub readfromfile {
 			    &Apache::loncommon::plainname($2,$3).', '.
 			    &Apache::lonlocal::locallocaltime($1);
 		    }
+		    $name=~s/\&colon\;/\:/g;
 		    $$thash{$url}=$name;
                     $$shash{$url}=$n;
                     $n++;
@@ -253,14 +255,22 @@ sub handler {
 
 # finish_import looks different for graphical or "simple" RAT
     my $finishimport='';
+    my $begincondition='';
+    my $endcondition='';
+    if ($env{'form.readfile'}) {
+        $begincondition='if (eval("document.forms.groupsort.include"+num+".checked")) {';
+	$endcondition='}';
+    }
     if ($env{'form.mode'} eq 'simple' || $env{'form.mode'} eq '') {
         $finishimport=(<<ENDSMP);
 function finish_import() {
     opener.document.forms.simpleedit.importdetail.value='';
     for (var num=0; num<document.forms.groupsort.fnum.value; num++) {
+	$begincondition
 	opener.document.forms.simpleedit.importdetail.value+='&'+
               escape(eval("document.forms.groupsort.title"+num+".value"))+'='+
 	      escape(eval("document.forms.groupsort.filelink"+num+".value"));
+	$endcondition
     }
     opener.document.forms.simpleedit.submit();
     self.close();
@@ -271,6 +281,7 @@ ENDSMP
 function finish_import() {
     var linkflag=false;
     for (var num=0; num<document.forms.groupsort.fnum.value; num++) {
+	$begincondition
 	insertRowInLastRow();
 	placeResourceInLastRow(
 	       eval("document.forms.groupsort.title"+num+".value"),
@@ -278,6 +289,7 @@ function finish_import() {
 	       linkflag
 	);
         linkflag=true;
+	$endcondition
     }
     opener.editmode=0;
     opener.notclear=0;
@@ -289,12 +301,8 @@ ENDADV
     }
 
 # output start of web page
-    my $html=&Apache::lonxml::xmlbegin();
-    $r->print(<<END);
-$html
-<head>
-<title>The LearningOnline Network With CAPA Group Sorter</title>
-<script language='javascript'>
+    my $js = <<END;
+<script type="text/javascript">
 function insertRowInLastRow() {
     opener.insertrow(opener.maxrow);
     opener.addobj(opener.maxrow,'e&2');
@@ -322,7 +330,6 @@ function orderchange(val,newval) {
     document.forms.groupsort.submit();
 }
 </script>
-</head>
 END
     # read pertinent machine configuration
     my $domain  = $r->dir_config('lonDefDomain');
@@ -340,7 +347,7 @@ END
 
     my $ctr = 0;
     my $clen = scalar(keys %shash);
-    if ($clen > 1) {
+    if (($clen > 1) || ($env{'form.readfile'})) {
 	my %lt=&Apache::lonlocal::texthash(
 		'fin'=> 'Finalize order of resources',
 		'gb' => 'Go Back',
@@ -349,9 +356,11 @@ END
 		'ca' => 'Cancel',
 		'co' => 'Change Order',
 		'ti' => 'Title',
-		'pa' => 'Path'
+		'pa' => 'Path',
+                'in' => 'Include'
 		);
-	$r->print(&Apache::loncommon::bodytag('Sort Imported Resources'));
+	$r->print(&Apache::loncommon::start_page('Sort Imported Resources',
+						 $js));
 	$r->print(<<END);
 <b><font color="#888888">$lt{'fin'}</font></b>
 <form method='post' action='/adm/groupsort' name='groupsort'
@@ -360,6 +369,8 @@ END
 <input type="hidden" name="oldval" value="" />
 <input type="hidden" name="newval" value="" />
 <input type="hidden" name="mode" value="$env{'form.mode'}" />
+<input type="hidden" name="readfile" value="$env{'form.readfile'}" />
+<input type="hidden" name="recover" value="$env{'form.recover'}" />
 END
 
         # --- Expand here if "GO BACK" button desired
@@ -385,12 +396,17 @@ END
 END
         $r->print("<table border='0'><tr><td bgcolor='#eeeeee'>");
 	$r->print("<table border=0><tr>\n");
-	$r->print("<td colspan='2' bgcolor='$titleclr'><b>$lt{'co'}</b></td>\n");
+	if ($env{'form.readfile'}) { 
+	    $r->print("<td bgcolor='$titleclr'><b>$lt{'in'}</b></td>\n");
+	} else { 
+	    $r->print("<td colspan='2' bgcolor='$titleclr'><b>$lt{'co'}</b></td>\n"); 
+	}
 	$r->print("<td colspan='2' bgcolor='$titleclr'><b>$lt{'ti'}</b></td>\n");
 	$r->print("<td bgcolor='$titleclr'><b>$lt{'pa'}</b></td></tr>\n");
     } else {
+	$r->print(&Apache::loncommon::start_page(undef,$js,
+						 {'only_body' => 1}));
 	$r->print(<<END);
-<body>
 <form method='post' action='/adm/groupsort' name='groupsort'
       enctype='application/x-www-form-urlencoded'>
 <input type="hidden" name="fnum" value="$clen" />
@@ -403,22 +419,30 @@ END
 	my $key=$_;
 	$ctr++;
 	my $iconname=&Apache::loncommon::icon($key);
-	if ($clen > 1) {
+	if (($clen > 1) || ($env{'form.readfile'})) {
 	    $r->print("<tr><td bgcolor='$fileclr'>");
-	    $r->print(&movers($clen,$ctr));
+            if ($env{'form.readfile'}) {
+		$r->print(&checkbox($ctr-1));
+	    } else {
+		$r->print(&movers($clen,$ctr));
+	    }
 	}
 	$r->print(&hidden($ctr-1,$thash{$key},$key));
-	if ($clen > 1) {
-	    $r->print("</td><td bgcolor='$fileclr'>");
-	    $r->print(&select_box($clen,$ctr));
-	    $r->print("</td><td bgcolor='$fileclr'>");
+	if (($clen > 1)  || ($env{'form.readfile'})) {
+	    $r->print("</td>");
+            unless ($env{'form.readfile'}) {
+		$r->print("<td bgcolor='$fileclr'>".
+			  &select_box($clen,$ctr).
+			  "</td>");
+	    }
+	    $r->print("<td bgcolor='$fileclr'>");
 	    $r->print("<img src='$iconname' />");
 	    $r->print("</td><td bgcolor='$fileclr'>");
-	    $r->print("$thash{$key}</td><td bgcolor='$fileclr'>\n");
+	    $r->print("$thash{$key}$nhash{$key}</td><td bgcolor='$fileclr'>\n");
 	    $r->print("$key</td></tr>\n");
 	} 
     }
-    if ($clen > 1) {
+    if (($clen > 1) || ($env{'form.readfile'})) {
 	$r->print("</table></td></tr></table></form>");
     } else {
 	$r->print(<<END);
@@ -427,10 +451,8 @@ END
 </script>
 END
     }
-    $r->print(<<END);
-</body>
-</html>
-END
+
+    $r->print(&Apache::loncommon::end_page());
 
     return OK;
 }
@@ -470,7 +492,7 @@ sub select_box {
     my $string;
     $string = '<select name="alt'.$sel.'"';
     $string .= " onChange='selectchange($sel)'>";
-    $string .= "<option name='o0' value='0'>remove</option>";
+    $string .= "<option name='o0' value='0'>".&mt('discard')."</option>";
     for my $cur (1..$total) {
 	$string .= "<option name='o$cur' value='$cur'";
 	if ($cur == $sel) {
@@ -482,6 +504,15 @@ sub select_box {
     return $string;
 }
 
+# ------------------------------------------------------------------- Checkbox
+
+sub checkbox {
+    my $sel=shift;
+    return "<label><input type='checkbox' name='include$sel'".
+       ($env{"form.include$sel"}?' checked="checked"':'').
+       ' />'.&mt('Include').'</label>';
+}
+
 1;
 
 __END__