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

raeburn raeburn@source.lon-capa.org
Mon, 15 Mar 2010 05:10:04 -0000


raeburn		Mon Mar 15 05:10:04 2010 EDT

  Modified files:              
    /loncom	lond 
    /loncom/lonnet/perl	lonnet.pm 
  Log:
  - Retrieve last access time for courses from nohist_courseids.db
    - lonnet.pm: New routines: &courselastaccess() and &extract_lastaccess()
    - lond: New routine: &course_lastaccess_handler()   
  
  
Index: loncom/lond
diff -u loncom/lond:1.437 loncom/lond:1.438
--- loncom/lond:1.437	Sun Feb 21 02:02:51 2010
+++ loncom/lond	Mon Mar 15 05:09:59 2010
@@ -2,7 +2,7 @@
 # The LearningOnline Network
 # lond "LON Daemon" Server (port "LOND" 5663)
 #
-# $Id: lond,v 1.437 2010/02/21 02:02:51 raeburn Exp $
+# $Id: lond,v 1.438 2010/03/15 05:09:59 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -59,7 +59,7 @@
 my $status='';
 my $lastlog='';
 
-my $VERSION='$Revision: 1.437 $'; #' stupid emacs
+my $VERSION='$Revision: 1.438 $'; #' stupid emacs
 my $remoteVERSION;
 my $currenthostid="default";
 my $currentdomainid;
@@ -4083,6 +4083,53 @@
 }
 &register_handler("courseiddump", \&dump_course_id_handler, 0, 1, 0);
 
+sub course_lastaccess_handler {
+    my ($cmd, $tail, $client) = @_;
+    my $userinput = "$cmd:$tail";
+    my ($cdom,$cnum) = split(':',$tail); 
+    my (%lastaccess,$qresult);
+    my $hashref = &tie_domain_hash($cdom, "nohist_courseids", &GDBM_WRCREAT());
+    if ($hashref) {
+        while (my ($key,$value) = each(%$hashref)) {
+            my ($unesc_key,$lasttime);
+            $unesc_key = &unescape($key);
+            if ($cnum) {
+                next unless ($unesc_key =~ /\Q$cdom\E_\Q$cnum\E$/);
+            }
+            if ($unesc_key =~ /^lasttime:($LONCAPA::match_domain\_$LONCAPA::match_courseid)/) {
+                $lastaccess{$1} = $value;
+            } else {
+                my $items = &Apache::lonnet::thaw_unescape($value);
+                if (ref($items) eq 'HASH') {
+                    unless ($lastaccess{$unesc_key}) {
+                        $lastaccess{$unesc_key} = '';
+                    }
+                } else {
+                    my @courseitems = split(':',$value);
+                    $lastaccess{$unesc_key} = pop(@courseitems);
+                }
+            }
+        }
+        foreach my $cid (sort(keys(%lastaccess))) {
+            $qresult.=&escape($cid).'='.$lastaccess{$cid}.'&'; 
+        }
+        if (&untie_domain_hash($hashref)) {
+            if ($qresult) {
+                chop($qresult);
+            }
+            &Reply($client, \$qresult, $userinput);
+        } else {
+            &Failure($client, "error: ".($!+0)." untie(GDBM) Failed ".
+                    "while attempting lastacourseaccess\n", $userinput);
+        }
+    } else {
+        &Failure($client, "error: ".($!+0)." tie(GDBM) Failed ".
+                "while attempting lastcourseaccess\n", $userinput);
+    }
+    return 1;
+}
+&register_handler("courselastaccess",\&course_lastaccess_handler, 0, 1, 0);
+
 #
 # Puts an unencrypted entry in a namespace db file at the domain level 
 #
Index: loncom/lonnet/perl/lonnet.pm
diff -u loncom/lonnet/perl/lonnet.pm:1.1054 loncom/lonnet/perl/lonnet.pm:1.1055
--- loncom/lonnet/perl/lonnet.pm:1.1054	Sat Mar 13 19:47:33 2010
+++ loncom/lonnet/perl/lonnet.pm	Mon Mar 15 05:10:03 2010
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # TCP networking package
 #
-# $Id: lonnet.pm,v 1.1054 2010/03/13 19:47:33 raeburn Exp $
+# $Id: lonnet.pm,v 1.1055 2010/03/15 05:10:03 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -3104,6 +3104,49 @@
     return %returnhash;
 }
 
+sub courselastaccess {
+    my ($cdom,$cnum,$hostidref) = @_;
+    my %returnhash;
+    if ($cdom && $cnum) {
+        my $chome = &homeserver($cnum,$cdom);
+        if ($chome ne 'no_host') {
+            my $rep = &reply('courselastaccess:'.$cdom.':'.$cnum,$chome);
+            &extract_lastaccess(\%returnhash,$rep);
+        }
+    } else {
+        if (!$cdom) { $cdom=''; }
+        my %libserv = &all_library();
+        foreach my $tryserver (keys(%libserv)) {
+            if (ref($hostidref) eq 'ARRAY') {
+                next unless (grep(/^\Q$tryserver\E$/,@{$hostidref}));
+            } 
+            if (($cdom eq '') || (&host_domain($tryserver) eq $cdom)) {
+                my $rep = &reply('courselastaccess:'.&host_domain($tryserver).':',$tryserver);
+                &extract_lastaccess(\%returnhash,$rep);
+            }
+        }
+    }
+    return %returnhash;
+}
+
+sub extract_lastaccess {
+    my ($returnhash,$rep) = @_;
+    if (ref($returnhash) eq 'HASH') {
+        unless ($rep eq 'unknown_command' || $rep eq 'no_such_host' || 
+                $rep eq 'con_lost' || $rep eq 'rejected' || $rep eq 'refused' ||
+                 $rep eq '') {
+            my @pairs=split(/\&/,$rep);
+            foreach my $item (@pairs) {
+                my ($key,$value)=split(/\=/,$item,2);
+                $key = &unescape($key);
+                next if ($key =~ /^error: 2 /);
+                $returnhash->{$key} = &thaw_unescape($value);
+            }
+        }
+    }
+    return;
+}
+
 # ---------------------------------------------------------- DC e-mail
 
 sub dcmailput {