Diff for /loncom/auth/lonroles.pm between versions 1.269.2.22 and 1.269.2.27

version 1.269.2.22, 2015/03/11 04:53:15 version 1.269.2.27, 2016/10/23 18:30:32
Line 260  sub handler { Line 260  sub handler {
   
     my $envkey;      my $envkey;
     my %dcroles = ();      my %dcroles = ();
     my $numdc = &check_fordc(\%dcroles,$update,$then);      my %dhroles = ();
       my ($numdc,$numdh,$numadhoc) = &check_for_adhoc(\%dcroles,\%dhroles,$update,$then);
     my $loncaparev = $r->dir_config('lonVersion');      my $loncaparev = $r->dir_config('lonVersion');
   
 # ================================================================== Roles Init  # ================================================================== Roles Init
Line 269  sub handler { Line 270  sub handler {
         my $locknum=&Apache::lonnet::get_locks();          my $locknum=&Apache::lonnet::get_locks();
         if ($locknum) { return 409; }          if ($locknum) { return 409; }
   
           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
               if ($env{'form.newrole'} =~ m{^cr/($match_domain)/\1\-domainconfig/\w+\./\1/$match_courseid$}) {
                   if ($dhroles{$1}) {
                       $custom_adhoc = 1;
                   }
               }
  }   }
  if ($env{'request.course.id'}) {   if ($env{'request.course.id'}) {
             # Check if user is CC trying to select a course role              # Check if user is CC trying to select a course role
Line 301  sub handler { Line 309  sub handler {
  "request.role"                => 'cm',   "request.role"                => 'cm',
                                  "request.role.adv"            => $env{'user.adv'},                                   "request.role.adv"            => $env{'user.adv'},
  "request.role.domain"         => $env{'user.domain'}});   "request.role.domain"         => $env{'user.domain'}});
   # Check if Domain Helpdesk role trying to enter a course needs privs to be created
           if ($env{'form.newrole'} =~ m{^cr/($match_domain)/\1\-domainconfig/(\w+)\./\1/($match_courseid)$}) {
               my $cdom = $1;
               my $rolename = $2;
               my $cnum = $3;
               if ($custom_adhoc) {
                   my %adhocroles = &Apache::lonnet::userenvironment($env{'user.domain'},$env{'user.name'},
                                                                     'adhocroles.'.$cdom);
                   if (keys(%adhocroles)) {
                       my @adhoc = split(',',$adhocroles{'adhocroles.'.$cdom});
                       if (grep(/^\Q$rolename\E$/,@adhoc)) {
                           if (&Apache::lonnet::check_adhoc_privs($cdom,$cnum,$update,$refresh,$now,
                                                                  "cr/$cdom/$cdom".'-domainconfig/'.$rolename)) {
                               &Apache::lonnet::appenv({"environment.internal.$cdom.$cnum.cr/$cdom/$cdom".'-domainconfig/'."$rolename.adhoc" => time});
                           }
                       }
                   }
               }
           } elsif ($numdc > 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
         if ($numdc > 0) {  
             foreach my $envkey (keys(%env)) {              foreach my $envkey (keys(%env)) {
 # Is this an ad-hoc Coordinator role?  # Is this an ad-hoc Coordinator role?
                 if (my ($ccrole,$domain,$coursenum) =                  if (my ($ccrole,$domain,$coursenum) =
Line 663  ENDENTERKEY Line 689  ENDENTERKEY
     }      }
  }   }
                                 # Are we allowed to look at the first resource?                                  # Are we allowed to look at the first resource?
                                   my $access;
                                 if ($furl =~ m{^(/adm/wrapper|)/ext/}) {                                  if ($furl =~ m{^(/adm/wrapper|)/ext/}) {
                                     # If it's an external resource,                                      # If it's an external resource,
                                     # strip off the symb argument and possible query                                      # strip off the symb argument and possible query
Line 670  ENDENTERKEY Line 697  ENDENTERKEY
                                     # Unencode $symb                                      # Unencode $symb
                                     $symb = &unescape($symb);                                      $symb = &unescape($symb);
                                     # Then check for permission                                      # Then check for permission
                                     if (!&Apache::lonnet::allowed('bre',$exturl,$symb)) {                                      $access = &Apache::lonnet::allowed('bre',$exturl,$symb);
                                         $furl = &Apache::lonpageflip::first_accessible_resource();  
                                     }  
                                 # For other resources just check for permission                                  # For other resources just check for permission
                                 } elsif (!&Apache::lonnet::allowed('bre',$furl)) {                                  } else {
                                       $access = &Apache::lonnet::allowed('bre',$furl);
                                   }
                                   if (!$access) {
                                     $furl = &Apache::lonpageflip::first_accessible_resource();                                      $furl = &Apache::lonpageflip::first_accessible_resource();
                                   } elsif ($access eq 'B') {
                                       $furl = '/adm/navmaps?showOnlyHomework=1';
                                 }                                  }
   
                                 $msg = &mt('Entering [_1] ...',                                  $msg = &mt('Entering [_1] ...',
    $env{'course.'.$cdom.'_'.$cnum.'.description'});     $env{'course.'.$cdom.'_'.$cnum.'.description'});
  &redirect_user($r, &mt('Entering [_1]',   &redirect_user($r, &mt('Entering [_1]',
Line 707  ENDENTERKEY Line 736  ENDENTERKEY
                                        $redirect_url);                                         $redirect_url);
                         return OK;                          return OK;
                     }                      }
                       if ($role eq 'dh') {
                           my $redirect_url = '/adm/menu/';
                           &redirect_user($r,&mt('Loading Domain Helpdesk 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 743  ENDENTERKEY Line 778  ENDENTERKEY
     my $showcount = &roles_from_env(\%roles_in_env,$update);       my $showcount = &roles_from_env(\%roles_in_env,$update); 
   
     my $swinfo=&Apache::lonmenu::rawconfig();      my $swinfo=&Apache::lonmenu::rawconfig();
     my $start_page=&Apache::loncommon::start_page($pagetitle,undef,{bread_crumbs=>$brcrum});  
     my %domdefs=&Apache::lonnet::get_domain_defaults($env{'user.domain'});       my %domdefs=&Apache::lonnet::get_domain_defaults($env{'user.domain'}); 
     my $cattype = 'std';      my $cattype = 'std';
     if ($domdefs{'catauth'}) {      if ($domdefs{'catauth'}) {
         $cattype = $domdefs{'catauth'};          $cattype = $domdefs{'catauth'};
     }      }
     my $funcs = &get_roles_functions($showcount,$cattype);      my $funcs = &get_roles_functions($showcount,$cattype);
     $standby=~s/\n/\\n/g;      my $crumbsright;
       if ($env{'browser.mobile'}) {
           $crumbsright = $funcs;
           undef($funcs);
       }
       my $start_page=&Apache::loncommon::start_page($pagetitle,undef,{bread_crumbs=>$brcrum,
                                                                       bread_crumbs_component=>$crumbsright});
       &js_escape(\$standby);
     my $noscript='<br /><span class="LC_error">'.&mt('Use of LON-CAPA requires Javascript to be enabled in your web browser.').'<br />'.&mt('As this is not the case, most functionality in the system will be unavailable.').'</span><br />';      my $noscript='<br /><span class="LC_error">'.&mt('Use of LON-CAPA requires Javascript to be enabled in your web browser.').'<br />'.&mt('As this is not the case, most functionality in the system will be unavailable.').'</span><br />';
   
     $r->print(<<ENDHEADER);      $r->print(<<ENDHEADER);
Line 948  ENDHEADER Line 989  ENDHEADER
     }      }
 # ----------------------------------------------------------------------- Table  # ----------------------------------------------------------------------- Table
   
     if ($numdc > 0) {      if (($numdc > 0) || (($numdh > 0) && ($numadhoc > 0))) {
         $r->print(&coursepick_jscript());          $r->print(&coursepick_jscript());
         $r->print(&Apache::loncommon::coursebrowser_javascript().          $r->print(&Apache::loncommon::coursebrowser_javascript().
                   &Apache::loncommon::authorbrowser_javascript());                    &Apache::loncommon::authorbrowser_javascript());
Line 981  ENDHEADER Line 1022  ENDHEADER
                                $roletext{'user.role.'.$role}->[1].                                 $roletext{'user.role.'.$role}->[1].
                                &Apache::loncommon::end_data_table_row();                                 &Apache::loncommon::end_data_table_row();
                 }                  }
                 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)/$}
                            && ($env{'environment.adhocroles.'.$1} ne '')) {
                       $output .= &adhoc_customroles_row($1,'recent');
                 }                  }
     } elsif ($numdc > 0) {      } elsif ($numdc > 0) {
                 unless ($role =~/^error\:/) {                  unless ($role =~/^error\:/) {
Line 1325  sub roletable_headers { Line 1369  sub roletable_headers {
     my $doheaders;      my $doheaders;
     if ((ref($sortrole) eq 'HASH') && (ref($roleclass) eq 'HASH')) {      if ((ref($sortrole) eq 'HASH') && (ref($roleclass) eq 'HASH')) {
         $r->print('<br />'          $r->print('<br />'
                  .&Apache::loncommon::start_data_table()                   .&Apache::loncommon::start_data_table('LC_textsize_mobile')
                  .&Apache::loncommon::start_data_table_header_row()                   .&Apache::loncommon::start_data_table_header_row()
         );          );
         if (!$nochoose) { $r->print('<th>&nbsp;</th>'); }          if (!$nochoose) { $r->print('<th>&nbsp;</th>'); }
Line 1374  sub print_rolerows { Line 1418  sub print_rolerows {
                                            &Apache::loncommon::end_data_table_row();                                             &Apache::loncommon::end_data_table_row();
                             }                              }
                         }                          }
                         if ($sortrole->{$which} =~ m-dc\./($match_domain)/-) {                          if ($sortrole->{$which} =~ m{^user\.role\.dc\./($match_domain)/}) {
                             if (ref($dcroles) eq 'HASH') {                              if (ref($dcroles) eq 'HASH') {
                                 if ($dcroles->{$1}) {                                  if ($dcroles->{$1}) {
                                     $output .= &adhoc_roles_row($1,'');                                      $output .= &adhoc_roles_row($1,'');
                                 }                                  }
                             }                              }
                           } elsif (($sortrole->{$which} =~ m{^user\.role\.dh\./($match_domain)/}) &&
                                    ($env{'environment.adhocroles.'.$1} ne '')) {
                               $output .= &adhoc_customroles_row($1,'');
                         }                          }
                     }                      }
                 }                  }
Line 1636  sub check_author_homeserver { Line 1683  sub check_author_homeserver {
     }      }
 }  }
   
 sub check_fordc {  sub check_for_adhoc {
     my ($dcroles,$update,$then) = @_;      my ($dcroles,$dhroles,$update,$then) = @_;
     my $numdc = 0;      my $numdc = 0;
       my $numdh = 0;
       my $numadhoc = 0;
       my $num_custom_adhoc = 0;
     if ($env{'user.adv'}) {      if ($env{'user.adv'}) {
         foreach my $envkey (sort(keys(%env))) {          foreach my $envkey (sort(keys(%env))) {
             if ($envkey=~/^user\.role\.dc\.\/($match_domain)\/$/) {              if ($envkey=~/^user\.role\.(dc|dh)\.\/($match_domain)\/$/) {
                 my $dcdom = $1;                  my $role = $1;
                 my $livedc = 1;                  my $roledom = $2;
                   my $liverole = 1;
                 my ($tstart,$tend)=split(/\./,$env{$envkey});                  my ($tstart,$tend)=split(/\./,$env{$envkey});
                 my $limit = $update;                  my $limit = $update;
                 if ($env{'request.role'} eq 'dc./'.$dcdom.'/') {                  if ((($role eq 'dc') && ($env{'request.role'} eq 'dc./'.$roledom.'/')) ||
                       (($role eq 'dh') && ($env{'request.role'} eq 'dh./'.$roledom.'/'))) {
                     $limit = $then;                      $limit = $then;
                 }                  }
                 if ($tstart && $tstart>$limit) { $livedc = 0; }                  if ($tstart && $tstart>$limit) { $liverole = 0; }
                 if ($tend   && $tend  <$limit) { $livedc = 0; }                  if ($tend   && $tend  <$limit) { $liverole = 0; }
                 if ($livedc) {                  if ($liverole) {
                     $$dcroles{$dcdom} = $envkey;                      if ($role eq 'dc') {
                     $numdc++;                          $dcroles->{$roledom} = $envkey;
                           $numdc++;
                       } else {
                           $dhroles->{$roledom} = $envkey;
                           if ($env{'environment.adhocroles.'.$roledom} ne '') {
                               $numadhoc ++;
                           }
                           $numdh++;
                       }
                 }                  }
             }              }
         }          }
     }      }
     return $numdc;      return ($numdc,$numdh,$numadhoc);
 }  }
   
 sub adhoc_course_role {  sub adhoc_course_role {
Line 1750  sub check_forcc { Line 1810  sub check_forcc {
 }  }
   
 sub courselink {  sub courselink {
     my ($dcdom,$rowtype) = @_;      my ($roledom,$rowtype,$role) = @_;
     my $courseform=&Apache::loncommon::selectcourse_link      my $courseform=&Apache::loncommon::selectcourse_link
                    ('rolechoice','dccourse'.$rowtype.'_'.$dcdom,                     ('rolechoice','course'.$rowtype.'_'.$roledom.'_'.$role,
                     'dcdomain'.$rowtype.'_'.$dcdom,'coursedesc'.$rowtype.'_'.                      'domain'.$rowtype.'_'.$roledom.'_'.$role,
                     $dcdom,$dcdom,undef,'Course/Community');                      'coursedesc'.$rowtype.'_'.$roledom.'_'.$role,
     my $hiddenitems = '<input type="hidden" name="dcdomain'.$rowtype.'_'.$dcdom.'" value="'.$dcdom.'" />'.                      $roledom.':'.$role,undef,'Course/Community');
                       '<input type="hidden" name="origdom'.$rowtype.'_'.$dcdom.'" value="'.$dcdom.'" />'.      my $hiddenitems = '<input type="hidden" name="domain'.$rowtype.'_'.$roledom.'_'.$role.'" value="'.$roledom.'" />'.
                       '<input type="hidden" name="dccourse'.$rowtype.'_'.$dcdom.'" value="" />'.                        '<input type="hidden" name="origdom'.$rowtype.'_'.$roledom.'_'.$role.'" value="'.$roledom.'" />'.
                       '<input type="hidden" name="coursedesc'.$rowtype.'_'.$dcdom.'" value="" />';                        '<input type="hidden" name="course'.$rowtype.'_'.$roledom.'_'.$role.'" value="" />'.
                         '<input type="hidden" name="coursedesc'.$rowtype.'_'.$roledom.'_'.$role.'" value="" />';
     return $courseform.$hiddenitems;      return $courseform.$hiddenitems;
 }  }
   
 sub coursepick_jscript {  sub coursepick_jscript {
     my %lt = &Apache::lonlocal::texthash(      my %js_lt = &Apache::lonlocal::texthash(
                   plsu => "Please use the 'Select Course/Community' link to open a separate pick course window where you may select the course or community you wish to enter.",                    plsu => "Please use the 'Select Course/Community' link to open a separate pick course window where you may select the course or community you wish to enter.",
                   youc => 'You can only use this screen to select courses and communities in the current domain.',                    youc => 'You can only use this screen to select courses and communities in the current domain.',
              );               );
       &js_escape(\%js_lt);
     my $verify_script = <<"END";      my $verify_script = <<"END";
 <script type="text/javascript">  <script type="text/javascript">
 // <![CDATA[  // <![CDATA[
Line 1783  function verifyCoursePick(caller) { Line 1845  function verifyCoursePick(caller) {
             }              }
         }          }
         else {          else {
             alert("$lt{'plsu'}");              alert("$js_lt{'plsu'}");
         }          }
     }      }
     else {      else {
         alert("$lt{'youc'}")          alert("$js_lt{'youc'}")
     }      }
 }  }
 function getIndex(caller) {  function getIndex(caller) {
Line 1848  sub display_cc_role { Line 1910  sub display_cc_role {
 sub adhoc_roles_row {  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">'                   .' <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 $selectcclink = &courselink($dcdom,$rowtype);      my $role = 'cc';
       my $selectcclink = &courselink($dcdom,$rowtype,$role);
     my $ccrole = &Apache::lonnet::plaintext('co',undef,undef,1);      my $ccrole = &Apache::lonnet::plaintext('co',undef,undef,1);
     my $carole = &Apache::lonnet::plaintext('ca');      my $carole = &Apache::lonnet::plaintext('ca');
     my $selectcalink = &coauthorlink($dcdom,$rowtype);      my $selectcalink = &coauthorlink($dcdom,$rowtype);
Line 1862  sub adhoc_roles_row { Line 1925  sub adhoc_roles_row {
     return $output;      return $output;
 }  }
   
   sub adhoc_customroles_row {
       my ($dhdom,$rowtype) = @_;
       my $output = &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);
       my @customroles = split(/,/,$env{'environment.adhocroles.'.$dhdom});
       my $count = 0;
       foreach my $role (@customroles) {
           next if (($role eq '') || ($role =~ /\W/));
           $output .= ' '.$role.': '.&courselink($dhdom,$rowtype,$role).' |';
           $count ++;
       }
       if ($count) {
           return $output;
       }
       return;
   }
   
 sub recent_filename {  sub recent_filename {
     my $area=shift;      my $area=shift;
     return 'nohist_recent_'.&escape($area);      return 'nohist_recent_'.&escape($area);
Line 2690  sub get_roles_functions { Line 2772  sub get_roles_functions {
     unless ($cattype eq 'none') {      unless ($cattype eq 'none') {
         push(@links,['/adm/coursecatalog','ccat-22x22',&mt('Course catalog')]);          push(@links,['/adm/coursecatalog','ccat-22x22',&mt('Course catalog')]);
     }      }
     my $funcs = &Apache::lonhtmlcommon::start_funclist();      my $funcs;
     foreach my $link (@links) {      if ($env{'browser.mobile'}) {
         $funcs .= &Apache::lonhtmlcommon::add_item_funclist(          my @functions;
                       '<a href="'.$link->[0].'" class="LC_menubuttons_link">'.          foreach my $link (@links) {
                       '<img src="/res/adm/pages/'.$link->[1].'.png" class="LC_icon" alt="'.$link->[2].'" />'.              push(@functions,[$link->[0],$link->[2]]);
                       $link->[2].'</a>');          }
           my $title = 'Display options';
           if ($env{'user.adv'}) {
               $title = 'Roles options';
           }
           $funcs = &Apache::lonmenu::create_submenu('','',$title,\@functions,1,'LC_breadcrumbs_hoverable');
           $funcs = '<ol class="LC_primary_menu LC_floatright">'.$funcs.'</ol>';
       } else {
           $funcs = &Apache::lonhtmlcommon::start_funclist();
           foreach my $link (@links) {
               $funcs .= &Apache::lonhtmlcommon::add_item_funclist(
                             '<a href="'.$link->[0].'" class="LC_menubuttons_link">'.
                             '<img src="/res/adm/pages/'.$link->[1].'.png" class="LC_icon" alt="'.$link->[2].'" />'.
                             $link->[2].'</a>');
           }
           $funcs .= &Apache::lonhtmlcommon::end_funclist();
           $funcs = &Apache::loncommon::head_subbox($funcs);
     }      }
     $funcs .= &Apache::lonhtmlcommon::end_funclist();      return $funcs;
     return &Apache::loncommon::head_subbox($funcs);  
 }  }
   
 sub get_queued {  sub get_queued {

Removed from v.1.269.2.22  
changed lines
  Added in v.1.269.2.27


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