Diff for /loncom/auth/lonroles.pm between versions 1.269.2.29 and 1.269.2.37.2.1

version 1.269.2.29, 2016/11/09 17:48:38 version 1.269.2.37.2.1, 2020/09/08 04:33:36
Line 209  sub handler { Line 209  sub handler {
     my $r = shift;      my $r = shift;
   
     # Check for critical messages and redirect if present.      # Check for critical messages and redirect if present.
     my ($redirect,$url) = &Apache::loncommon::critical_redirect(300);      my ($redirect,$url) = &Apache::loncommon::critical_redirect(300,'roles');
     if ($redirect) {      if ($redirect) {
         &Apache::loncommon::content_type($r,'text/html');          &Apache::loncommon::content_type($r,'text/html');
         $r->header_out(Location => $url);          $r->header_out(Location => $url);
Line 260  sub handler { Line 260  sub handler {
   
     my $envkey;      my $envkey;
     my %dcroles = ();      my %dcroles = ();
     my %dhroles = ();      my %helpdeskroles = (); 
     my ($numdc,$numdh,$numadhoc) = &check_for_adhoc(\%dcroles,\%dhroles,$update,$then);      my ($numdc,$numhelpdesk,$numadhoc) =
           &check_for_adhoc(\%dcroles,\%helpdeskroles,$update,$then);
     my $loncaparev = $r->dir_config('lonVersion');      my $loncaparev = $r->dir_config('lonVersion');
   
 # ================================================================== Roles Init  # ================================================================== Roles Init
Line 273  sub handler { Line 274  sub handler {
         my $custom_adhoc;          my $custom_adhoc;
         if ($env{'form.newrole'}) {          if ($env{'form.newrole'}) {
             $env{'form.'.$env{'form.newrole'}}=1;              $env{'form.'.$env{'form.newrole'}}=1;
 # Check if this is a Domain Helpdesk role trying to enter a course  # Check if this is a Domain Helpdesk or Domain Helpdesk Assistant role trying to enter a course
             if ($env{'form.newrole'} =~ m{^cr/($match_domain)/\1\-domainconfig/\w+\./\1/$match_courseid$}) {              if ($env{'form.newrole'} =~ m{^cr/($match_domain)/\1\-domainconfig/\w+\./\1/$match_courseid$}) {
                 if ($dhroles{$1}) {                  if ($helpdeskroles{$1}) {
                     $custom_adhoc = 1;                      $custom_adhoc = 1;
                 }                  }
             }              }
Line 316  sub handler { Line 317  sub handler {
             my $cnum = $3;              my $cnum = $3;
             my $sec = $4;              my $sec = $4;
             if ($custom_adhoc) {              if ($custom_adhoc) {
                 my %adhocroles = &Apache::lonnet::userenvironment($env{'user.domain'},$env{'user.name'},                  my ($possroles,$description) = &Apache::lonnet::get_my_adhocroles($cdom.'_'.$cnum,1);
                                                                   'adhocroles.'.$cdom);                  if (ref($possroles) eq 'ARRAY') {
                 if (keys(%adhocroles)) {                      if (grep(/^\Q$rolename\E$/,@{$possroles})) {
                     my @adhoc = split(',',$adhocroles{'adhocroles.'.$cdom});  
                     if (grep(/^\Q$rolename\E$/,@adhoc)) {  
                         if (&Apache::lonnet::check_adhoc_privs($cdom,$cnum,$update,$refresh,$now,                          if (&Apache::lonnet::check_adhoc_privs($cdom,$cnum,$update,$refresh,$now,
                                                                "cr/$cdom/$cdom".'-domainconfig/'.$rolename,undef,$sec)) {                                                                 "cr/$cdom/$cdom".'-domainconfig/'.$rolename,undef,$sec)) {
                             &Apache::lonnet::appenv({"environment.internal.$cdom.$cnum.cr/$cdom/$cdom".'-domainconfig/'."$rolename.adhoc" => time});                              &Apache::lonnet::appenv({"environment.internal.$cdom.$cnum.cr/$cdom/$cdom".'-domainconfig/'."$rolename.adhoc" => time});
Line 328  sub handler { Line 327  sub handler {
                     }                      }
                 }                  }
             }              }
         } elsif (($numdc > 0) || ($numdh > 0)) {          } elsif (($numdc > 0) || ($numhelpdesk > 0)) {
 # Check if user is a DC trying to enter a course or author space and needs privs to be created  # Check if user is a DC trying to enter a course or author space and needs privs to be created
 # Check if user is a DH trying to enter a course and needs privs to be created  # Check if user is a DH or DA trying to enter a course and needs privs to be created
             foreach my $envkey (keys(%env)) {              foreach my $envkey (keys(%env)) {
                 if ($numdc) {                  if ($numdc) {
 # Is this an ad-hoc Coordinator role?  # Is this an ad-hoc Coordinator role?
Line 400  sub handler { Line 399  sub handler {
                         last;                          last;
                     }                      }
                 }                  }
                 if ($numdh) {                  if ($numhelpdesk) {
 # Is this an ad hoc custom role in a course/community?  # Is this an ad hoc custom role in a course/community?
                     if (my ($domain,$rolename,$coursenum,$sec) = ($envkey =~ m{^form\.cr/($match_domain)/\1\-domainconfig/(\w+)\./\1/($match_courseid)(?:/(\w+)|$)})) {                      if (my ($domain,$rolename,$coursenum,$sec) = ($envkey =~ m{^form\.cr/($match_domain)/\1\-domainconfig/(\w+)\./\1/($match_courseid)(?:/(\w+)|$)})) {
                         if ($dhroles{$domain}) {                          if ($helpdeskroles{$domain}) {
                             my @adhoc;                              my ($possroles,$description) = &Apache::lonnet::get_my_adhocroles($domain.'_'.$coursenum,1);
                             if ($env{'environment.adhocroles.'.$domain}) {                              if (ref($possroles) eq 'ARRAY') {
                                 @adhoc = split(',',$env{'environment.adhocroles.'.$domain});                                  if (grep(/^\Q$rolename\E$/,@{$possroles})) {
                             } else {  
                                 my %adhocroles = &Apache::lonnet::userenvironment($env{'user.domain'},$env{'user.name'},  
                                                                                   'adhocroles.'.$domain);  
                                 if (keys(%adhocroles)) {  
                                     @adhoc = split(',',$adhocroles{'adhocroles.'.$domain});  
                                 }  
                             }  
                             if ((@adhoc > 0) && ($rolename ne '')) {  
                                 if (grep(/^\Q$rolename\E$/,@adhoc)) {  
                                     if (&Apache::lonnet::check_adhoc_privs($domain,$coursenum,$update,$refresh,$now,                                      if (&Apache::lonnet::check_adhoc_privs($domain,$coursenum,$update,$refresh,$now,
                                                                            "cr/$domain/$domain".'-domainconfig/'.$rolename,                                                                             "cr/$domain/$domain".'-domainconfig/'.$rolename,
                                                                            undef,$sec)) {                                                                             undef,$sec)) {
Line 572  ENDENTERKEY Line 562  ENDENTERKEY
  $env{'user.name'},   $env{'user.name'},
  $env{'user.home'},   $env{'user.home'},
  "Role ".$trolecode);   "Role ".$trolecode);
       
     &Apache::lonnet::appenv(      &Apache::lonnet::appenv(
    {'request.role'        => $trolecode,     {'request.role'        => $trolecode,
     'request.role.domain' => $cdom,      'request.role.domain' => $cdom,
Line 581  ENDENTERKEY Line 571  ENDENTERKEY
                     my $tadv=0;                      my $tadv=0;
   
     if (($cnum) && ($role ne 'ca') && ($role ne 'aa')) {      if (($cnum) && ($role ne 'ca') && ($role ne 'aa')) {
                           if ($role =~ m{^\Qcr/$cdom/$cdom\E\-domainconfig/(\w+)$}) {
                               my $rolename = $1;
                               my %domdef = &Apache::lonnet::get_domain_defaults($cdom);
                               if (ref($domdef{'adhocroles'}) eq 'HASH') {
                                   if (ref($domdef{'adhocroles'}{$rolename}) eq 'HASH') {
                                       &Apache::lonnet::appenv({'request.role.desc' => $domdef{'adhocroles'}{$rolename}{'desc'}});
                                   }
                               }
                           }
                         my $msg;                          my $msg;
                         my ($furl,$ferr)=                          my ($furl,$ferr)=
                             &Apache::lonuserstate::readmap($cdom.'/'.$cnum);                              &Apache::lonuserstate::readmap($cdom.'/'.$cnum);
Line 591  ENDENTERKEY Line 590  ENDENTERKEY
                                     {$env{'user.name'}.':'.$env{'user.domain'}.                                      {$env{'user.name'}.':'.$env{'user.domain'}.
                                      ':'.$csec.':'.$role => $now},$cdom,$cnum);                                       ':'.$csec.':'.$role => $now},$cdom,$cnum);
                             }                              }
                               if (($env{"environment.internal.$cdom.$cnum.$role.adhoc"}) &&
                                   (&Apache::lonnet::allowed('vxc',$cdom.'_'.$cnum))) {
                                   my $owner = $env{'course.'.$cdom.'_'.$cnum.'.internal.courseowner'};
                                   my @coowners = split(/,/,$env{'course.'.$env{'request.course.id'}.'.internal.co-owners'});
                                   my %auaccess;
                                   foreach my $user ($owner,@coowners) {
                                       my ($cpname,$cpdom) = split(/:/,$user);
                                       my %auroles = &Apache::lonnet::get_my_roles($cpname,$cpdom,'userroles',undef,['au','ca','aa'],[$cdom]);
                                       foreach my $key (keys(%auroles)) {
                                           my ($auname,$audom,$aurole) = split(/:/,$key);
                                           if ($aurole eq 'au') {
                                               $auaccess{$cpname} = 1;
                                           } else {
                                               $auaccess{$auname} = 1;
                                           }
                                       }
                                   }
                                   &Apache::lonnet::appenv({'request.course.adhocsrcaccess' => join(',',sort(keys(%auaccess))) });
                               }
                             my ($feeds,$syllabus_time);                              my ($feeds,$syllabus_time);
                             &Apache::lonrss::advertisefeeds($cnum,$cdom,undef,\$feeds);                              &Apache::lonrss::advertisefeeds($cnum,$cdom,undef,\$feeds);
                             &Apache::lonnet::appenv({'request.course.feeds' => $feeds});                              &Apache::lonnet::appenv({'request.course.feeds' => $feeds});
Line 670  ENDENTERKEY Line 688  ENDENTERKEY
                                                     }                                                      }
                                                 }                                                  }
                                             }                                              }
                                               if (($dest =~ m{^\Q/public/$cdom/$cnum/syllabus\E.*(\?|\&)usehttp=1}) ||
                                                   ($dest =~ m{^\Q/adm/wrapper/ext/\E(?!https:)})) {
                                                   if ($ENV{'SERVER_PORT'} == 443) {
                                                       unless (&Apache::lonnet::uses_sts()) {
                                                           my $hostname = $r->hostname();
                                                           if ($hostname ne '') {
                                                               $dest = 'http://'.$hostname.$dest;
                                                           }
                                                       }
                                                   }
                                               }
                                             if ($dest =~ m{^/enc/}) {                                              if ($dest =~ m{^/enc/}) {
                                                 if ($env{'request.role.adv'}) {                                                  if ($env{'request.role.adv'}) {
                                                     $dest = &Apache::lonenc::unencrypted($dest);                                                      $dest = &Apache::lonenc::unencrypted($dest);
Line 702  ENDENTERKEY Line 731  ENDENTERKEY
                                         unless (($dest =~ m{^/enc/}) || ($dest =~ /(\?|\&)symb=.+___\d+___.+/)) {                                           unless (($dest =~ m{^/enc/}) || ($dest =~ /(\?|\&)symb=.+___\d+___.+/)) { 
                                             if (($destsymb ne '') && ($destsymb !~ m{^/enc/})) {                                              if (($destsymb ne '') && ($destsymb !~ m{^/enc/})) {
                                                 my $esc_symb = &escape($destsymb);                                                  my $esc_symb = &escape($destsymb);
                                                 $dest .= '?symb='.$esc_symb;                                                  $dest .= (($dest =~/\?/)? '&':'?').'symb='.$esc_symb;
                                             }                                              }
                                         }                                          }
                                         &redirect_user($r, &mt('Entering [_1]',                                          &redirect_user($r, &mt('Entering [_1]',
Line 780  ENDENTERKEY Line 809  ENDENTERKEY
                                        $redirect_url);                                         $redirect_url);
                         return OK;                          return OK;
                     }                      }
                       if ($role eq 'da') {
                           my $redirect_url = '/adm/menu/';
                           &redirect_user($r,&mt('Loading Domain Helpdesk Assistant Menu'),
                                          $redirect_url);
                           return OK;
                       }
                     if ($role eq 'sc') {                      if ($role eq 'sc') {
                         my $redirect_url = '/adm/grades?command=scantronupload';                          my $redirect_url = '/adm/grades?command=scantronupload';
                         &redirect_user($r,&mt('Loading Data Upload Page'),                          &redirect_user($r,&mt('Loading Data Upload Page'),
Line 995  ENDHEADER Line 1030  ENDHEADER
   
 # No active roles  # No active roles
     if ($countactive==0) {      if ($countactive==0) {
         &requestcourse_advice($r,$cattype,$inrole);           my $elapsed = 0;
           if ($now && $update) {
               $elapsed = $now - $update;
           }
           &requestcourse_advice($r,$cattype,$inrole,$elapsed); 
  $r->print('</form>');   $r->print('</form>');
         if ($countfuture) {          if ($countfuture) {
             $r->print(&mt('The following [quant,_1,role,roles] will become active in the future:',$countfuture));              $r->print(&mt('The following [quant,_1,role,roles] will become active in the future:',$countfuture));
             my $doheaders = &roletable_headers($r,\%roleclass,\%sortrole,              my $doheaders = &roletable_headers($r,\%roleclass,\%sortrole,
                                                $nochoose);                                                 $nochoose);
             &print_rolerows($r,$doheaders,\%roleclass,\%sortrole,\%dcroles,              &print_rolerows($r,$doheaders,\%roleclass,\%sortrole,\%dcroles,
                             \%roletext);                              \%roletext,$update,$then);
             my $tremark='';              my $tremark='';
             my $tbg;              my $tbg;
             if ($env{'request.role'} eq 'cm') {              if ($env{'request.role'} eq 'cm') {
Line 1027  ENDHEADER Line 1066  ENDHEADER
     }      }
 # ----------------------------------------------------------------------- Table  # ----------------------------------------------------------------------- Table
   
     if (($numdc > 0) || (($numdh > 0) && ($numadhoc > 0))) {      if (($numdc > 0) || (($numhelpdesk > 0) && ($numadhoc > 0))) {
         $r->print(&coursepick_jscript());          $r->print(&coursepick_jscript().
         $r->print(&Apache::loncommon::coursebrowser_javascript().                    &Apache::loncommon::coursebrowser_javascript());
                   &Apache::loncommon::authorbrowser_javascript());      }
       if ($numdc > 0) {
           $r->print(&Apache::loncommon::authorbrowser_javascript());
     }      }
   
     unless ((!&Apache::loncommon::show_course()) || ($nochoose) || ($countactive==1)) {      unless ((!&Apache::loncommon::show_course()) || ($nochoose) || ($countactive==1)) {
Line 1063  ENDHEADER Line 1104  ENDHEADER
                 if ($role =~ m{^dc\./($match_domain)/$}                   if ($role =~ m{^dc\./($match_domain)/$} 
     && $dcroles{$1}) {      && $dcroles{$1}) {
     $output .= &adhoc_roles_row($1,'recent');      $output .= &adhoc_roles_row($1,'recent');
                 } elsif ($role =~ m{^dh\./($match_domain)/$}                  } elsif ($role =~ m{^(dh|da)\./($match_domain)/$}) {
                          && ($env{'environment.adhocroles.'.$1} ne '')) {                      $output .= &adhoc_customroles_row($1,$2,'recent',$update,$then);
                     $output .= &adhoc_customroles_row($1,'recent');  
                 }                  }
     } elsif ($numdc > 0) {      } elsif ($numdc > 0) {
                 unless ($role =~/^error\:/) {                  unless ($role =~/^error\:/) {
Line 1094  ENDHEADER Line 1134  ENDHEADER
             $doheaders ++;              $doheaders ++;
  }   }
     }      }
     &print_rolerows($r,$doheaders,\%roleclass,\%sortrole,\%dcroles,\%roletext);      &print_rolerows($r,$doheaders,\%roleclass,\%sortrole,\%dcroles,\%roletext,$update,$then);
     if ($countactive > 1) {      if ($countactive > 1) {
         my $tremark='';          my $tremark='';
         my $tbg;          my $tbg;
Line 1171  sub gather_roles { Line 1211  sub gather_roles {
     my $tryagain = $env{'form.tryagain'};      my $tryagain = $env{'form.tryagain'};
     my @ids = &Apache::lonnet::current_machine_ids();      my @ids = &Apache::lonnet::current_machine_ids();
     if (ref($roles_in_env) eq 'HASH') {      if (ref($roles_in_env) eq 'HASH') {
           my %adhocdesc;
         foreach my $envkey (sort(keys(%{$roles_in_env}))) {          foreach my $envkey (sort(keys(%{$roles_in_env}))) {
             my $button = 1;              my $button = 1;
             my $switchserver='';              my $switchserver='';
Line 1273  sub gather_roles { Line 1314  sub gather_roles {
                     $ttype = &Apache::loncommon::course_type($tcourseid);                      $ttype = &Apache::loncommon::course_type($tcourseid);
                     if ($role !~ /^cr/) {                      if ($role !~ /^cr/) {
                         $trole = &Apache::lonnet::plaintext($role,$ttype,$tcourseid);                          $trole = &Apache::lonnet::plaintext($role,$ttype,$tcourseid);
                     } elsif ($role =~ m{^cr/($match_domain)/\1-domainconfig/(\w+)$}) {                      } elsif ($role =~ m{^\Qcr/$tdom/$tdom\E\-domainconfig/(\w+)$}) {
                         $trole = &mt('Helpdesk[_1]','&nbsp;'.$2);                          my $rolename = $1;
                           my $desc;
                           if (ref($adhocdesc{$tdom}) eq 'HASH') {
                               $desc = $adhocdesc{$tdom}{$rolename};
                           } else {
                               my %domdef = &Apache::lonnet::get_domain_defaults($tdom);
                               if (ref($domdef{'adhocroles'}) eq 'HASH') {
                                   foreach my $rolename (sort(keys(%{$domdef{'adhocroles'}}))) {
                                       if (ref($domdef{'adhocroles'}{$rolename}) eq 'HASH') {
                                           $adhocdesc{$tdom}{$rolename} = $domdef{'adhocroles'}{$rolename}{'desc'};
                                           $desc = $adhocdesc{$tdom}{$rolename};
                                       }
                                   }
                               }
                           }
                           if ($desc ne '') {
                               $trole = $desc;
                           } else {
                               $trole = &mt('Helpdesk[_1]','&nbsp;'.$rolename);
                           }
                     } else {                      } else {
                         $trole = (split(/\//,$role,4))[-1];                          $trole = (split(/\//,$role,4))[-1];
                     }                      }
Line 1446  sub roletypes { Line 1506  sub roletypes {
 }  }
   
 sub print_rolerows {  sub print_rolerows {
     my ($r,$doheaders,$roleclass,$sortrole,$dcroles,$roletext) = @_;      my ($r,$doheaders,$roleclass,$sortrole,$dcroles,$roletext,$update,$then) = @_;
     if ((ref($roleclass) eq 'HASH') && (ref($sortrole) eq 'HASH')) {      if ((ref($roleclass) eq 'HASH') && (ref($sortrole) eq 'HASH')) {
         my @types = &roletypes();          my @types = &roletypes();
         foreach my $type (@types) {          foreach my $type (@types) {
Line 1470  sub print_rolerows { Line 1530  sub print_rolerows {
                                     $output .= &adhoc_roles_row($1,'');                                      $output .= &adhoc_roles_row($1,'');
                                 }                                  }
                             }                              }
                         } elsif (($sortrole->{$which} =~ m{^user\.role\.dh\./($match_domain)/}) &&                          } elsif ($sortrole->{$which} =~ m{^user\.role\.(dh|da)\./($match_domain)/}) {
                                  ($env{'environment.adhocroles.'.$1} ne '')) {                              $output .= &adhoc_customroles_row($1,$2,'',$update,$then);
                             $output .= &adhoc_customroles_row($1,'');  
                         }                          }
                     }                      }
                 }                  }
Line 1493  sub print_rolerows { Line 1552  sub print_rolerows {
 }  }
   
 sub findcourse_advice {  sub findcourse_advice {
     my ($r,$cattype) = @_;      my ($r,$cattype,$elapsed) = @_;
     my $domdesc = &Apache::lonnet::domain($env{'user.domain'},'description');      my $domdesc = &Apache::lonnet::domain($env{'user.domain'},'description');
     my $esc_dom = &HTML::Entities::encode($env{'user.domain'},'"<>&');      my $esc_dom = &HTML::Entities::encode($env{'user.domain'},'"<>&');
     if (&Apache::lonnet::auto_run(undef,$env{'user.domain'})) {      if (&Apache::lonnet::auto_run(undef,$env{'user.domain'})) {
         $r->print(&mt('If you were expecting to see an active role listed for a particular course in the [_1] domain, it may be missing for one of the following reasons:',$domdesc).'          $r->print('<p>'.&mt('If you were expecting to see an active role listed for a particular course in the [_1] domain, it may be missing for one of the following reasons:',$domdesc).'
 <ul>  <ul>
  <li>'.&mt('The course has yet to be created.').'</li>   <li>'.&mt('The course has yet to be created.').'</li>
  <li>'.&mt('Automatic enrollment of registered students has not been enabled for the course.').'</li>   <li>'.&mt('Automatic enrollment of registered students has not been enabled for the course.').'</li>
  <li>'.&mt('You are in a section of course for which automatic enrollment in the corresponding LON-CAPA course is not active.').'</li>   <li>'.&mt('You are in a section of course for which automatic enrollment in the corresponding LON-CAPA course is not active.').'</li>
  <li>'.&mt('The start date for automated enrollment has yet to be reached.').'</li>   <li>'.&mt('The start date for automated enrollment has yet to be reached.').'</li>
  <li>'.&mt('You registered for the course recently and there is a time lag between the time you register, and the time this information becomes available for the update of LON-CAPA course rosters.').'</li>   <li>'.&mt('You registered for the course recently and there is a time lag between the time you register, and the time this information becomes available for the update of LON-CAPA course rosters.').'</li>
  </ul>');   <li>'.&mt('Automated enrollment added you to the course in the time since you last logged-in.').' '.&mt('If that is the case you can use the "Check for changes" link in the gray Functions bar to update the list of your available course roles.').'</li>
    </ul></p>');
     } else {      } else {
         $r->print(&mt('If you were expecting to see an active role listed for a particular course, that course may not have been created yet.').'<br />');          $r->print('<p>'.&mt('If you were expecting to see an active role listed for a particular course, that course may not have been created yet.').'</p>');
           if ($elapsed > 600) {
               $r->print('<p>'.&mt('You may also have been assigned to a course in the time since you last logged-in, or checked for changes.').
                         '<br />'.
                         &mt('If that is the case you can use the "Check for changes" link in the gray Functions bar to update the list of your available course roles.').'</p>');
           }
     }      }
     if (($cattype eq 'std') || ($cattype eq 'domonly')) {      if (($cattype eq 'std') || ($cattype eq 'domonly')) {
         $r->print('<h3>'.&mt('Self-Enrollment').'</h3>'.          $r->print('<h3>'.&mt('Self-Enrollment').'</h3>'.
Line 1518  sub findcourse_advice { Line 1583  sub findcourse_advice {
 }  }
   
 sub requestcourse_advice {  sub requestcourse_advice {
     my ($r,$cattype,$inrole) = @_;      my ($r,$cattype,$inrole,$elapsed) = @_;
     my $domdesc = &Apache::lonnet::domain($env{'user.domain'},'description');      my $domdesc = &Apache::lonnet::domain($env{'user.domain'},'description');
     my $esc_dom = &HTML::Entities::encode($env{'user.domain'},'"<>&');      my $esc_dom = &HTML::Entities::encode($env{'user.domain'},'"<>&');
     my (%can_request,%request_doms,$output);      my (%can_request,%request_doms,$output);
Line 1579  sub requestcourse_advice { Line 1644  sub requestcourse_advice {
         } else {          } else {
             $r->print('<h3>'.&mt('Currently no active roles, courses or communities').'</h3>');              $r->print('<h3>'.&mt('Currently no active roles, courses or communities').'</h3>');
         }          }
         &findcourse_advice($r,$cattype);          &findcourse_advice($r,$cattype,$elapsed);
     }      }
     return;      return;
 }  }
Line 1642  sub privileges_info { Line 1707  sub privileges_info {
 sub build_roletext {  sub build_roletext {
     my ($trolecode,$tdom,$trest,$tstatus,$tryagain,$advanced,$tremark,$tbg,$trole,$twhere,      my ($trolecode,$tdom,$trest,$tstatus,$tryagain,$advanced,$tremark,$tbg,$trole,$twhere,
         $tpstart,$tpend,$nochoose,$button,$switchserver,$reinit,$switchwarning) = @_;          $tpstart,$tpend,$nochoose,$button,$switchserver,$reinit,$switchwarning) = @_;
     my ($roletext,$roletext_end);      my ($roletext,$roletext_end,$poss_adhoc);
     my $is_dc=($trolecode =~ m/^dc\./);      if ($trolecode =~ m/^d(c|h|a)\./) {
     my $rowspan=($is_dc) ? ''          $poss_adhoc = 1;
       }
       my $rowspan=($poss_adhoc) ? ''
                          : ' rowspan="2" ';                           : ' rowspan="2" ';
   
     unless ($nochoose) {      unless ($nochoose) {
Line 1705  sub build_roletext { Line 1772  sub build_roletext {
               .'<td>'.$twhere.'</td>'                .'<td>'.$twhere.'</td>'
               .'<td>'.$tpstart.'</td>'                .'<td>'.$tpstart.'</td>'
               .'<td>'.$tpend.'</td>';                .'<td>'.$tpend.'</td>';
     if (!$is_dc) {      unless ($poss_adhoc) {
         $roletext_end = '<td colspan="4">'.          $roletext_end = '<td colspan="4">'.
                         $tremark.'&nbsp;'.                          $tremark.'&nbsp;'.
                         '</td>';                          '</td>';
Line 1731  sub check_author_homeserver { Line 1798  sub check_author_homeserver {
 }  }
   
 sub check_for_adhoc {  sub check_for_adhoc {
     my ($dcroles,$dhroles,$update,$then) = @_;      my ($dcroles,$helpdeskroles,$update,$then) = @_;
     my $numdc = 0;      my $numdc = 0;
     my $numdh = 0;      my $numhelpdesk = 0;
     my $numadhoc = 0;      my $numadhoc = 0;
     my $num_custom_adhoc = 0;      my $num_custom_adhoc = 0;
     if ($env{'user.adv'}) {      if (($env{'user.adv'}) || ($env{'user.rar'})) {
         foreach my $envkey (sort(keys(%env))) {          foreach my $envkey (sort(keys(%env))) {
             if ($envkey=~/^user\.role\.(dc|dh)\.\/($match_domain)\/$/) {              if ($envkey=~/^user\.role\.(dc|dh|da)\.\/($match_domain)\/$/) {
                 my $role = $1;                  my $role = $1;
                 my $roledom = $2;                  my $roledom = $2;
                 my $liverole = 1;                  my $liverole = 1;
                 my ($tstart,$tend)=split(/\./,$env{$envkey});                  my ($tstart,$tend)=split(/\./,$env{$envkey});
                 my $limit = $update;                  my $limit = $update;
                 if ((($role eq 'dc') && ($env{'request.role'} eq 'dc./'.$roledom.'/')) ||                  if ($env{'request.role'} eq "$role./$roledom/") {
                     (($role eq 'dh') && ($env{'request.role'} eq 'dh./'.$roledom.'/'))) {  
                     $limit = $then;                      $limit = $then;
                 }                  }
                 if ($tstart && $tstart>$limit) { $liverole = 0; }                  if ($tstart && $tstart>$limit) { $liverole = 0; }
Line 1755  sub check_for_adhoc { Line 1821  sub check_for_adhoc {
                         $dcroles->{$roledom} = $envkey;                          $dcroles->{$roledom} = $envkey;
                         $numdc++;                          $numdc++;
                     } else {                      } else {
                         $dhroles->{$roledom} = $envkey;                          $helpdeskroles->{$roledom} = $envkey;
                         if ($env{'environment.adhocroles.'.$roledom} ne '') {                          my %domdefaults = &Apache::lonnet::get_domain_defaults($roledom);
                             $numadhoc ++;                          if (ref($domdefaults{'adhocroles'}) eq 'HASH') {
                               if (keys(%{$domdefaults{'adhocroles'}})) {
                                   $numadhoc ++;
                               }
                         }                          }
                         $numdh++;                          $numhelpdesk++;
                     }                      }
                 }                  }
             }              }
         }          }
     }      }
     return ($numdc,$numdh,$numadhoc);      return ($numdc,$numhelpdesk,$numadhoc);
 }  }
   
 sub adhoc_course_role {  sub adhoc_course_role {
Line 1964  sub adhoc_roles_row { Line 2033  sub adhoc_roles_row {
     my ($dcdom,$rowtype) = @_;      my ($dcdom,$rowtype) = @_;
     my $output = &Apache::loncommon::continue_data_table_row()      my $output = &Apache::loncommon::continue_data_table_row()
                  .' <td colspan="5" class="LC_textsize_mobile">'                   .' <td colspan="5" class="LC_textsize_mobile">'
                  .&mt('[_1]Ad hoc[_2] roles in domain [_3] --'                   .&mt('[_1]Ad hoc[_2] roles in domain [_3]'
                      ,'<span class="LC_cusr_emph">','</span>',$dcdom)                       ,'<span class="LC_cusr_emph">','</span>',$dcdom)
                  .' ';                   .' -- ';
     my $role = 'cc';      my $role = 'cc';
     my $selectcclink = &courselink($dcdom,$rowtype,$role);      my $selectcclink = &courselink($dcdom,$rowtype,$role);
     my $ccrole = &Apache::lonnet::plaintext('co',undef,undef,1);      my $ccrole = &Apache::lonnet::plaintext('co',undef,undef,1);
Line 1979  sub adhoc_roles_row { Line 2048  sub adhoc_roles_row {
 }  }
   
 sub adhoc_customroles_row {  sub adhoc_customroles_row {
     my ($dhdom,$rowtype) = @_;      my ($role,$dhdom,$rowtype,$update,$then) = @_;
     my $output = &Apache::loncommon::continue_data_table_row()      my $liverole = 1;
                  .' <td colspan="5" class="LC_textsize_mobile">'      my ($tstart,$tend)=split(/\./,$env{"user.role.$role./$dhdom/"});
                  .&mt('[_1]Ad hoc[_2] course/community roles in domain [_3] --',      my $limit = $update;
                       '<span class="LC_cusr_emph">','</span>',$dhdom);      if (($role eq 'dh') && ($env{'request.role'} eq 'dh./'.$dhdom.'/')) {
     my @customroles = split(/,/,$env{'environment.adhocroles.'.$dhdom});          $limit = $then;
     my $count = 0;      }
     foreach my $role (@customroles) {      if ($tstart && $tstart>$limit) { $liverole = 0; }
         next if (($role eq '') || ($role =~ /\W/));      if ($tend   && $tend  <$limit) { $liverole = 0; }
         $output .= ' '.$role.': '.&courselink($dhdom,$rowtype,$role).' |';      return unless ($liverole);
         $count ++;      my %domdefaults = &Apache::lonnet::get_domain_defaults($dhdom);
     }      if (ref($domdefaults{'adhocroles'}) eq 'HASH') {
     if ($count) {          if (scalar(keys(%{$domdefaults{'adhocroles'}})) > 0) {
         return $output;              return &Apache::loncommon::continue_data_table_row()
                     .' <td colspan="5" class="LC_textsize_mobile">'
                     .&mt('[_1]Ad hoc[_2] course/community roles in domain [_3]',
                          '<span class="LC_cusr_emph">','</span>',$dhdom)
                     .' -- '.&courselink($dhdom,$rowtype,$role);
           }
     }      }
     return;      return;
 }  }

Removed from v.1.269.2.29  
changed lines
  Added in v.1.269.2.37.2.1


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>