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

raeburn raeburn at source.lon-capa.org
Thu Jan 5 13:44:42 EST 2017


raeburn		Thu Jan  5 18:44:42 2017 EDT

  Modified files:              
    /loncom/lonnet/perl	lonnet.pm 
  Log:
  - Ad hoc roles for helpdesk personnel
   - &get_all_adhocroles() provides information about all ad hoc roles defined
     for use by domain helpdesk personnel.
   - &get_my_adhocroles() provides information about just those ad hoc roles
     which are available in a specific course for the current user.
   - all custom ad hoc roles for helpdesk personnel are unavailable in "official" 
     courses in which user is a registered student (automated enrollment in use).  
  
  
-------------- next part --------------
Index: loncom/lonnet/perl/lonnet.pm
diff -u loncom/lonnet/perl/lonnet.pm:1.1332 loncom/lonnet/perl/lonnet.pm:1.1333
--- loncom/lonnet/perl/lonnet.pm:1.1332	Mon Jan  2 19:44:20 2017
+++ loncom/lonnet/perl/lonnet.pm	Thu Jan  5 18:44:41 2017
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # TCP networking package
 #
-# $Id: lonnet.pm,v 1.1332 2017/01/02 19:44:20 raeburn Exp $
+# $Id: lonnet.pm,v 1.1333 2017/01/05 18:44:41 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -4490,12 +4490,63 @@
     return %returnhash;
 }
 
+sub get_all_adhocroles {
+    my ($dom) = @_;
+    my @roles_by_num = ();
+    my %domdefaults = &get_domain_defaults($dom);
+    my (%description,%access_in_dom,%access_info);
+    if (ref($domdefaults{'adhocroles'}) eq 'HASH') {
+        my $count = 0;
+        my %domcurrent = %{$domdefaults{'adhocroles'}};
+        my %ordered;
+        foreach my $role (sort(keys(%domcurrent))) {
+            my ($order,$desc,$access_in_dom);
+            if (ref($domcurrent{$role}) eq 'HASH') {
+                $order = $domcurrent{$role}{'order'};
+                $desc = $domcurrent{$role}{'desc'};
+                $access_in_dom{$role} = $domcurrent{$role}{'access'};
+                $access_info{$role} = $domcurrent{$role}{$access_in_dom{$role}};
+            }
+            if ($order eq '') {
+                $order = $count;
+            }
+            $ordered{$order} = $role;
+            if ($desc ne '') {
+                $description{$role} = $desc;
+            } else {
+                $description{$role}= $role;
+            }
+            $count++;
+        }
+        foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
+            push(@roles_by_num,$ordered{$item});
+        }
+    }
+    return (\@roles_by_num,\%description,\%access_in_dom,\%access_info);
+}
+
 sub get_my_adhocroles {
-    my ($cid) = @_;
-    my (@possroles,%description);
-    if ($cid =~ /^($match_domain)_($match_courseid)$/) {
-        my $cdom = $1;
-        my $cnum = $2;
+    my ($cid,$checkreg) = @_;
+    my ($cdom,$cnum,%info, at possroles,$description,$roles_by_num);
+    if ($env{'request.course.id'} eq $cid) {
+        $cdom = $env{'course.'.$cid.'.domain'};
+        $cnum = $env{'course.'.$cid.'.num'};
+        $info{'internal.coursecode'} = $env{'course.'.$cid.'.internal.coursecode'};
+    } elsif ($cid =~ /^($match_domain)_($match_courseid)$/) {
+        $cdom = $1;
+        $cnum = $2;
+        %info = &Apache::lonnet::get('environment',['internal.coursecode'],
+                                     $cdom,$cnum);
+    }
+    if (($info{'internal.coursecode'} ne '') && ($checkreg)) {
+        my $user = $env{'user.name'}.':'.$env{'user.domain'};
+        my %rosterhash = &get('classlist',[$user],$cdom,$cnum);
+        if ($rosterhash{$user} ne '') {
+            my $type = (split(/:/,$rosterhash{$user}))[5];
+            return ([],{}) if ($type eq 'auto');
+        }
+    }
+    if (($cdom ne '') && ($cnum ne ''))  {
         if ($env{"user.role.dh./$cdom/"}) {
             my $then=$env{'user.login.time'};
             my $update=$env{'user.update.time'};
@@ -4509,34 +4560,10 @@
             if ($tend   && $tend  <$limit) { $liverole = 0; }
             if ($liverole) {
                 if (&homeserver($cnum,$cdom) ne 'no_host') {
-                    my %domdefaults = &get_domain_defaults($cdom);
-                    if (ref($domdefaults{'adhocroles'}) eq 'HASH') {
-                        my $count = 0;
-                        my %domcurrent = %{$domdefaults{'adhocroles'}};
-                        my (%ordered,%access_in_dom);
-                        foreach my $role (sort(keys(%domcurrent))) {
-                            my ($order,$desc,$access_in_dom);
-                            if (ref($domcurrent{$role}) eq 'HASH') {
-                                $order = $domcurrent{$role}{'order'};
-                                $desc = $domcurrent{$role}{'desc'};
-                                $access_in_dom{$role} = $domcurrent{$role}{'access'};
-                            }
-                            if ($order eq '') {
-                                $order = $count;
-                            }
-                            $ordered{$order} = $role;
-                            if ($desc ne '') {
-                                $description{$role} = $desc;
-                            } else {
-                                $description{$role}= $role;
-                            }
-                            $count++;
-                        }
-                        my @roles_by_num = ();
-                        foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
-                            push(@roles_by_num,$ordered{$item});
-                        }
-                        if (@roles_by_num) {
+                    my ($accessref,$accessinfo,%access_in_dom);
+                    ($roles_by_num,$description,$accessref,$accessinfo) = &get_all_adhocroles($cdom);
+                    if (ref($roles_by_num) eq 'ARRAY') {
+                        if (@{$roles_by_num}) {
                             my %settings;
                             if ($env{'request.course.id'} eq $cid) {
                                 foreach my $envkey (keys(%env)) {
@@ -4556,7 +4583,10 @@
                                 @statuses = split(/,/,$env{'environment.inststatus'});
                             }
                             my $user = $env{'user.name'}.':'.$env{'user.domain'};
-                            foreach my $role (@roles_by_num) {
+                            if (ref($accessref) eq 'HASH') {
+                                %access_in_dom = %{$accessref};
+                            }
+                            foreach my $role (@{$roles_by_num}) {
                                 my ($curraccess, at okstatus, at personnel);
                                 if ($setincrs{$role}) {
                                     ($curraccess,my $rest) = split(/=/,$settings{'internal.adhoc.'.$role});
@@ -4567,13 +4597,15 @@
                                     }
                                 } else {
                                     $curraccess = $access_in_dom{$role};
-                                    if ($curraccess eq 'status') {
-                                        if (ref($domcurrent{$role}{$curraccess}) eq 'ARRAY') {
-                                            @okstatus = @{$domcurrent{$role}{$curraccess}};
-                                        }
-                                    } elsif (($curraccess eq 'exc') || ($curraccess eq 'inc')) {
-                                        if (ref($domcurrent{$role}{$curraccess}) eq 'ARRAY') {
-                                            @personnel = @{$domcurrent{$role}{$curraccess}};
+                                    if (ref($accessinfo) eq 'HASH') {
+                                        if ($curraccess eq 'status') {
+                                            if (ref($accessinfo->{$role}) eq 'ARRAY') {
+                                                @okstatus = @{$accessinfo->{$role}};
+                                            }
+                                        } elsif (($curraccess eq 'exc') || ($curraccess eq 'inc')) {
+                                            if (ref($accessinfo->{$role}) eq 'ARRAY') {
+                                                @personnel = @{$accessinfo->{$role}};
+                                            }
                                         }
                                     }
                                 }
@@ -4612,7 +4644,16 @@
             }
         }
     }
-    return (\@possroles,\%description);
+    unless (ref($description) eq 'HASH') {
+        if (ref($roles_by_num) eq 'ARRAY') {
+            my %desc;
+            map { $desc{$_} = $_; } (@{$roles_by_num});
+            $description = \%desc;
+        } else {
+            $description = {};
+        }
+    }
+    return (\@possroles,$description);
 }
 
 # ----------------------------------------------------- Frontpage Announcements


More information about the LON-CAPA-cvs mailing list