--- loncom/lonnet/perl/lonnet.pm	2017/01/05 18:44:41	1.1333
+++ loncom/lonnet/perl/lonnet.pm	2017/01/28 23:26:51	1.1336
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # TCP networking package
 #
-# $Id: lonnet.pm,v 1.1333 2017/01/05 18:44:41 raeburn Exp $
+# $Id: lonnet.pm,v 1.1336 2017/01/28 23:26:51 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -4116,7 +4116,7 @@ sub flushcourselogs {
         }
     }
 #
-# Reverse lookup of domain roles (dc, ad, li, sc, dh, au)
+# Reverse lookup of domain roles (dc, ad, li, sc, dh, da, au)
 #
     my %domrolebuffer = ();
     foreach my $entry (keys(%domainrolehash)) {
@@ -4263,7 +4263,7 @@ sub userrolelog {
          {$trole.':'.$username.':'.$domain.':'.$env{'user.name'}.':'.$env{'user.domain'}.':'}
                     =$tend.':'.$tstart;
     }
-    if ($trole =~ /^(dc|ad|li|au|dg|sc|dh)/ ) {
+    if ($trole =~ /^(dc|ad|li|au|dg|sc|dh|da)/ ) {
        my (undef,$rudom,$runame,$rsec)=split(/\//,$area);
        $domainrolehash
          {$trole.':'.$username.':'.$domain.':'.$runame.':'.$rudom.':'.$rsec}
@@ -4547,18 +4547,29 @@ sub get_my_adhocroles {
         }
     }
     if (($cdom ne '') && ($cnum ne ''))  {
-        if ($env{"user.role.dh./$cdom/"}) {
+        if (($env{"user.role.dh./$cdom/"}) || ($env{"user.role.da./$cdom/"})) {
             my $then=$env{'user.login.time'};
             my $update=$env{'user.update.time'};
-            my $liverole = 1;
-            my ($tstart,$tend)=split(/\./,$env{'user.role.dh./'.$cdom});
-            my $limit = $update;
-            if ($env{'request.role'} eq 'dh./'.$cdom.'/') {
-                $limit = $then;
-            }
-            if ($tstart && $tstart>$limit) { $liverole = 0; }
-            if ($tend   && $tend  <$limit) { $liverole = 0; }
-            if ($liverole) {
+            if (!$update) {
+                $update = $then;
+            }
+            my @liveroles;
+            foreach my $role ('dh','da') {
+                if ($env{"user.role.$role./$cdom/"}) {
+                    my ($tstart,$tend)=split(/\./,$env{"user.role.$role./$cdom/"});
+                    my $limit = $update;
+                    if ($env{'request.role'} eq "$role./$cdom/") {
+                        $limit = $then;
+                    }
+                    my $activerole = 1;
+                    if ($tstart && $tstart>$limit) { $activerole = 0; }
+                    if ($tend   && $tend  <$limit) { $activerole = 0; }
+                    if ($activerole) {
+                        push(@liveroles,$role);
+                    }
+                }
+            }
+            if (@liveroles) {
                 if (&homeserver($cnum,$cdom) ne 'no_host') {
                     my ($accessref,$accessinfo,%access_in_dom);
                     ($roles_by_num,$description,$accessref,$accessinfo) = &get_all_adhocroles($cdom);
@@ -4613,6 +4624,18 @@ sub get_my_adhocroles {
                                     next;
                                 } elsif ($curraccess eq 'all') {
                                     push(@possroles,$role);
+                                } elsif ($curraccess eq 'dh') {
+                                    if (grep(/^dh$/,@liveroles)) {
+                                        push(@possroles,$role);
+                                    } else {
+                                        next;
+                                    }
+                                } elsif ($curraccess eq 'da') {
+                                    if (grep(/^da$/,@liveroles)) {
+                                        push(@possroles,$role);
+                                    } else {
+                                        next;
+                                    }
                                 } elsif ($curraccess eq 'status') {
                                     if (@okstatus) {
                                         if (!@statuses) {
@@ -9127,7 +9150,8 @@ sub assignrole {
             &courserolelog($role,$uname,$udom,$url,$origstart,$origend,$delflag,
                            $selfenroll,$context);
         } elsif (($role eq 'li') || ($role eq 'dg') || ($role eq 'sc') ||
-                 ($role eq 'au') || ($role eq 'dc') || ($role eq 'dh')) {
+                 ($role eq 'au') || ($role eq 'dc') || ($role eq 'dh') ||
+                 ($role eq 'da')) {
             &domainrolelog($role,$uname,$udom,$url,$origstart,$origend,$delflag,
                            $context);
         } elsif (($role eq 'ca') || ($role eq 'aa')) {