[LON-CAPA-cvs] cvs: loncom /enrollment Enrollment.pm

raeburn lon-capa-cvs@mail.lon-capa.org
Mon, 15 Dec 2003 05:39:40 -0000


raeburn		Mon Dec 15 00:39:40 2003 EDT

  Modified files:              
    /loncom/enrollment	Enrollment.pm 
  Log:
  Added check_user_status subroutine.  Used to determine if a course coordinator role is active in a course. Used by lonpopulate.pm when building the notification display table. Avoids the problem of stale end dates in the nohist_userroles table for the course. 
  
  
Index: loncom/enrollment/Enrollment.pm
diff -u loncom/enrollment/Enrollment.pm:1.8 loncom/enrollment/Enrollment.pm:1.9
--- loncom/enrollment/Enrollment.pm:1.8	Wed Dec 10 22:26:15 2003
+++ loncom/enrollment/Enrollment.pm	Mon Dec 15 00:39:40 2003
@@ -1,5 +1,5 @@
 # Automated Enrollment manager
-# $Id: Enrollment.pm,v 1.8 2003/12/11 03:26:15 raeburn Exp $
+# $Id: Enrollment.pm,v 1.9 2003/12/15 05:39:40 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -543,6 +543,44 @@
         $passwd .= $item;
     }
     return ($passwd);
+}
+
+sub check_user_status {
+    my ($udom,$uname,$cdom,$crs,$role,$secgrp) = @_;
+    my %userinfo = &Apache::lonnet::dump('roles',$udom,$uname);
+    my @uroles = keys %userinfo;
+    my $srchstr;
+    my $active_chk = 'none';
+    if (@uroles > 0) {
+        if ( ($role eq 'cc') || ($secgrp eq '') || ( !defined($secgrp) ) ) {
+            $srchstr = '/'.$cdom.'/'.$crs.'_'.$role;
+        } else {
+            $srchstr = '/'.$cdom.'/'.$crs.'/'.$secgrp.'_'.$role;
+        }
+        if (grep/^$srchstr$/,@uroles) {
+            my $role_end = 0;
+            my $role_start = 0;
+            $active_chk = 'ok';
+            if ( $userinfo{$srchstr} =~ m/^($role)_(\d+)/ ) {
+                $role_end = $2;
+                if ( $userinfo{$srchstr} =~ m/^($role)_($role_end)_(\d+)$/ )
+                {
+                    $role_start = $3;
+                }
+            }   
+            if ($role_start > 0) {
+                if (time < $role_start) {
+                    $active_chk = 'expired';
+                }
+            }
+            if ($role_end > 0) {
+                if (time > $role_end) {
+                    $active_chk = 'expired';
+                }
+            }
+        }
+    }
+    return $active_chk;
 }
 
 sub CL_autharg { return 0; }