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

www lon-capa-cvs@mail.lon-capa.org
Fri, 10 Jun 2005 02:19:53 -0000


www		Thu Jun  9 22:19:53 2005 EDT

  Modified files:              
    /loncom/interface	groupsort.pm 
  Log:
  Saving my work, Bug #3738
  
  
Index: loncom/interface/groupsort.pm
diff -u loncom/interface/groupsort.pm:1.33 loncom/interface/groupsort.pm:1.34
--- loncom/interface/groupsort.pm:1.33	Thu Jun  9 18:06:09 2005
+++ loncom/interface/groupsort.pm	Thu Jun  9 22:19:51 2005
@@ -2,7 +2,7 @@
 # The LON-CAPA group sort handler
 # Allows for sorting prior to import into RAT.
 #
-# $Id: groupsort.pm,v 1.33 2005/06/09 22:06:09 www Exp $
+# $Id: groupsort.pm,v 1.34 2005/06/10 02:19:51 www Exp $
 # 
 # Copyright Michigan State University Board of Trustees
 #
@@ -180,8 +180,7 @@
 	    }
 	}
     } else {
-	$r->print('Unable to tie hash to db file</body></html>');
-	return OK;
+	$r->print('Unable to tie hash to db file');
     }
     untie %hash;
     return ($shash,$thash);
@@ -198,12 +197,48 @@
     }
 }
 
+# -------------------------------------------------------------- Read from file
+
+sub readfromfile {
+    my ($r,$shash,$thash)=@_;
+    my $cont=&Apache::lonnet::getfile
+	(&Apache::lonnet::filelocation('',$env{'form.readfile'}));
+    if ($cont==-1) {
+	$r->print('Unable to read file: '.
+		  &Apache::lonnet::filelocation('',$env{'form.readfile'}));
+    } else {
+        my $parser = HTML::TokeParser->new(\$cont);
+        my $token;
+        while ($token = $parser->get_token) {
+	    if ($token->[0] eq 'S') {
+                if ($token->[1] eq 'resource') {
+		    if ($env{'form.recover'}) {
+			if ($token->[2]->{'type'} ne 'zombie') { next; }
+		    } else {
+			if ($token->[2]->{'type'} eq 'zombie') { next; }
+		    }
+                    my $name=$token->[2]->{'title'};
+		    my $url=$token->[2]->{'src'};
+		    $name=~s/ \[\((\d+)\,(\w+)\,(\w+)\)\]$//;
+		    if ($1) {
+			$name.='<br />'.&mt('Removed by ').
+			    &Apache::loncommon::plainname($2,$3).', '.
+			    &Apache::lonlocal::locallocaltime($1);
+		    }
+		    $r->print('<br />'.$name);
+		}
+	    }
+	}
+    }
+    return ($shash,$thash);
+}
+
 # ---------------------------------------------------------------- Main Handler
 sub handler {
     my $r = shift;
  
    &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
-                                           ['acts','catalogmode','mode']);
+                      ['acts','catalogmode','mode','readfile','recover']);
     # color scheme
     my $fileclr = '#ffffe6';
     my $titleclr = '#ddffff';
@@ -292,7 +327,11 @@
     my %shash; # sort order (key is resource location, value is sort order)
     my %thash; # title (key is resource location, value is title)
 
-    &readfromdb($r,\%shash,\%thash);
+    if ($env{'form.readfile'}) {
+	&readfromfile($r,\%shash,\%thash);
+    } else {
+	&readfromdb($r,\%shash,\%thash);
+    }
 
     my $ctr = 0;
     my $clen = scalar(keys %shash);