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

albertel lon-capa-cvs@mail.lon-capa.org
Thu, 28 Dec 2006 17:36:52 -0000


albertel		Thu Dec 28 12:36:52 2006 EDT

  Modified files:              
    /loncom/lonnet/perl	lonnet.pm 
  Log:
  - fixing regression in getsection
  
  
Index: loncom/lonnet/perl/lonnet.pm
diff -u loncom/lonnet/perl/lonnet.pm:1.814 loncom/lonnet/perl/lonnet.pm:1.815
--- loncom/lonnet/perl/lonnet.pm:1.814	Mon Dec 11 09:06:05 2006
+++ loncom/lonnet/perl/lonnet.pm	Thu Dec 28 12:36:51 2006
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # TCP networking package
 #
-# $Id: lonnet.pm,v 1.814 2006/12/11 14:06:05 raeburn Exp $
+# $Id: lonnet.pm,v 1.815 2006/12/28 17:36:51 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -53,7 +53,6 @@
 use Cache::Memcached;
 use Digest::MD5;
 use Math::Random;
-use lib '/home/httpd/lib/perl';
 use LONCAPA qw(:DEFAULT :match);
 use LONCAPA::Configuration;
 
@@ -878,6 +877,25 @@
     &devalidate_cache_new('getsection',$hashid);
 }
 
+sub courseid_to_courseurl {
+    my ($courseid) = @_;
+    #already url style courseid
+    return $courseid if ($courseid =~ m{^/});
+
+    if (exists($env{'course.'.$courseid.'.num'})) {
+	my $cnum = $env{'course.'.$courseid.'.num'};
+	my $cdom = $env{'course.'.$courseid.'.domain'};
+	return "/$cdom/$cnum";
+    }
+
+    my %courseinfo=&Apache::lonnet::coursedescription($courseid);
+    if (exists($courseinfo{'num'})) {
+	return "/$courseinfo{'domain'}/$courseinfo{'num'}";
+    }
+
+    return undef;
+}
+
 sub getsection {
     my ($udom,$unam,$courseid)=@_;
     my $cachetime=1800;
@@ -901,6 +919,7 @@
     # If there is more than one expired role, choose the one which ended last.
     # If there is a role which has expired, return it.
     #
+    $courseid = &courseid_to_courseurl($courseid);
     foreach my $line (split(/\&/,&reply('dump:'.$udom.':'.$unam.':roles',
 					&homeserver($unam,$udom)))) {
         my ($key,$value)=split(/\=/,$line,2);