[LON-CAPA-cvs] cvs: rat / lonpageflip.pm

albertel lon-capa-cvs@mail.lon-capa.org
Fri, 20 Oct 2006 19:42:30 -0000


albertel		Fri Oct 20 15:42:30 2006 EDT

  Modified files:              
    /rat	lonpageflip.pm 
  Log:
  - handle the case of non-browseable resources stuck into the middle of a course
  
  
Index: rat/lonpageflip.pm
diff -u rat/lonpageflip.pm:1.71 rat/lonpageflip.pm:1.72
--- rat/lonpageflip.pm:1.71	Tue Sep 19 15:03:27 2006
+++ rat/lonpageflip.pm	Fri Oct 20 15:42:28 2006
@@ -2,7 +2,7 @@
 #
 # Page flip handler
 #
-# $Id: lonpageflip.pm,v 1.71 2006/09/19 19:03:27 albertel Exp $
+# $Id: lonpageflip.pm,v 1.72 2006/10/20 19:42:28 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -87,6 +87,39 @@
 }
 
 sub move {
+    my ($next,$endupmap,$direction) = @_;
+    my $safecount=0;
+    my $allowed=0;
+    do {
+	($next,$endupmap)=&get_next_possible_move($next,$endupmap,$direction);
+
+	my $url = $hash{'src_'.$next};
+	my ($mapid,$resid)=split(/\./,$next);
+	my $symb = &Apache::lonnet::encode_symb($hash{'map_id_'.$mapid},
+						$resid,$url);
+	if ($url eq '' || $symb eq '') {
+	    $allowed = 0;
+	} else {
+	    my $priv = &Apache::lonnet::allowed('bre',$url,$symb);
+	    $allowed = (($priv eq 'F') || ($priv eq '2'));
+	}
+	$safecount++;
+    } while (   ($next)
+	     && ($next!~/\,/)
+	     && (
+		    (!$hash{'src_'.$next})
+		 || (
+		        (!$env{'request.role.adv'})
+		     &&  $hash{'randomout_'.$next}
+		    )
+		 || (!$allowed)
+		)
+	     && ($safecount<10000));
+
+    return ($next,$endupmap);
+}
+
+sub get_next_possible_move {
     my ($rid,$mapurl,$direction)=@_;
     my $startoutrid=$rid;
 
@@ -342,14 +375,6 @@
               my $endupmap;
               ($next,$endupmap)=&move($rid,$startoutmap,$direction);
 # -------------------------------------- Do we have one and only one empty URL?
-              my $safecount=0;
-              while (($next) && ($next!~/\,/) && 
-                     ((!$hash{'src_'.$next}) || 
-		      ((!$env{'request.role.adv'}) && $hash{'randomout_'.$next}))
-                     && ($safecount<10000)) {
-                  ($next,$endupmap)=&move($next,$endupmap,$direction);
-                  $safecount++;
-              }
 # We are now at at least one non-empty URL
 # ----------------------------------------------------- Check out possibilities
               if ($next) {