[LON-CAPA-cvs] cvs: loncom /lonnet/perl lonnet.pm

www lon-capa-cvs@mail.lon-capa.org
Thu, 23 May 2002 20:37:25 -0000


www		Thu May 23 16:37:25 2002 EDT

  Modified files:              
    /loncom/lonnet/perl	lonnet.pm 
  Log:
  New routine to find out if a resource is directly on the map, towards
  bug #461. Also remove "forward" - "back" pageflip problem from secondary
  pages
  
  
Index: loncom/lonnet/perl/lonnet.pm
diff -u loncom/lonnet/perl/lonnet.pm:1.231 loncom/lonnet/perl/lonnet.pm:1.232
--- loncom/lonnet/perl/lonnet.pm:1.231	Wed May 22 09:56:43 2002
+++ loncom/lonnet/perl/lonnet.pm	Thu May 23 16:37:25 2002
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # TCP networking package
 #
-# $Id: lonnet.pm,v 1.231 2002/05/22 13:56:43 stredwic Exp $
+# $Id: lonnet.pm,v 1.232 2002/05/23 20:37:25 www Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -1548,19 +1548,16 @@
 # the course
 
     if ($ENV{'request.course.id'}) {
+
        $courseprivid=$ENV{'request.course.id'};
        if ($ENV{'request.course.sec'}) {
           $courseprivid.='/'.$ENV{'request.course.sec'};
        }
        $courseprivid=~s/\_/\//;
        my $checkreferer=1;
-       my @uriparts=split(/\//,$uri);
-       my $filename=$uriparts[$#uriparts];
-       my $pathname=$uri;
-       $pathname=~s/\/$filename$//;
-       if ($ENV{'acc.res.'.$ENV{'request.course.id'}.'.'.$pathname}=~
-           /\&$filename\:([\d\|]+)\&/) {
-           $statecond=$1;
+       my ($match,$cond)=&is_on_map($uri);
+       if ($match) {
+           $statecond=$cond;
            if ($ENV{'user.priv.'.$ENV{'request.role'}.'./'.$courseprivid}
                =~/$priv\&([^\:]*)/) {
                $thisallowed.=$1;
@@ -1570,7 +1567,6 @@
        
        if ($checkreferer) {
 	  my $refuri=$ENV{'httpref.'.$orguri};
-
             unless ($refuri) {
                 foreach (keys %ENV) {
 		    if ($_=~/^httpref\..*\*/) {
@@ -1584,15 +1580,12 @@
                     }
                 }
             }
+
          if ($refuri) { 
 	  $refuri=&declutter($refuri);
-          my @uriparts=split(/\//,$refuri);
-          my $filename=$uriparts[$#uriparts];
-          my $pathname=$refuri;
-          $pathname=~s/\/$filename$//;
-            if ($ENV{'acc.res.'.$ENV{'request.course.id'}.'.'.$pathname}=~
-              /\&$filename\:([\d\|]+)\&/) {
-              my $refstatecond=$1;
+          my ($match,$cond)=&is_on_map($refuri);
+            if ($match) {
+              my $refstatecond=$cond;
               if ($ENV{'user.priv.'.$ENV{'request.role'}.'./'.$courseprivid}
                   =~/$priv\&([^\:]*)/) {
                   $thisallowed.=$1;
@@ -1731,6 +1724,24 @@
    }
 
    return 'F';
+}
+
+# --------------------------------------------------- Is a resource on the map?
+
+sub is_on_map {
+    my $uri=&declutter(shift);
+    my @uriparts=split(/\//,$uri);
+    my $filename=$uriparts[$#uriparts];
+    my $pathname=$uri;
+    $pathname=~s/\/$filename$//;
+    my $match=($ENV{'acc.res.'.$ENV{'request.course.id'}.'.'.$pathname}=~
+	       /\&$filename\:([\d\|]+)\&/);
+    &logthis('is: '.$uri.' '.$match.' '.$1);
+    if ($match) {
+       return (1,$1);
+   } else {
+       return (0,0);
+   }
 }
 
 # ----------------------------------------------------------------- Define Role