Diff for /loncom/interface/lonmenu.pm between versions 1.369.2.60 and 1.369.2.61

version 1.369.2.60, 2016/10/26 15:12:46 version 1.369.2.61, 2016/10/27 21:46:38
Line 2356  sub roles_selector { Line 2356  sub roles_selector {
     } else {      } else {
         $ccrole = 'cc';          $ccrole = 'cc';
     }      }
     my ($priv,$gotsymb,$destsymb);      my ($privref,$gotsymb,$destsymb);
     my $destinationurl = $ENV{'REQUEST_URI'};      my $destinationurl = $ENV{'REQUEST_URI'};
     if ($destinationurl =~ /\?symb=/) {      if ($destinationurl =~ /\?symb=/) {
         $gotsymb = 1;          $gotsymb = 1;
Line 2377  sub roles_selector { Line 2377  sub roles_selector {
         my $destination = $destinationurl;          my $destination = $destinationurl;
         $destination =~ s/(\?.*)$//;          $destination =~ s/(\?.*)$//;
         if (exists($reqprivs->{$destination})) {          if (exists($reqprivs->{$destination})) {
             $priv = $reqprivs->{$destination};              if ($reqprivs->{$destination} =~ /,/) {
                   @{$privref} = split(/,/,$reqprivs->{$destination});
               } else {
                   $privref = [$reqprivs->{$destination}];
               }
         }          }
     }      }
     if ($env{'user.role.'.$ccrole.'./'.$cdom.'/'.$cnum}) {      if ($env{'user.role.'.$ccrole.'./'.$cdom.'/'.$cnum}) {
         my ($start,$end) = split(/\./,$env{'user.role.'.$ccrole.'./'.$cdom.'/'.$cnum});          my ($start,$end) = split(/\./,$env{'user.role.'.$ccrole.'./'.$cdom.'/'.$cnum});
           
         if ((($start) && ($start<0)) ||           if ((($start) && ($start<0)) || 
             (($end) && ($end<$now))  ||              (($end) && ($end<$now))  ||
             (($start) && ($now<$start))) {              (($start) && ($now<$start))) {
Line 2392  sub roles_selector { Line 2395  sub roles_selector {
         }          }
     }      }
     if ($is_cc) {      if ($is_cc) {
         &get_all_courseroles($cdom,$cnum,\%courseroles,\%seccount,\%courseprivs,$priv);          &get_all_courseroles($cdom,$cnum,\%courseroles,\%seccount,\%courseprivs);
       } elsif ($env{'request.role'} =~ m{^\Qcr/$cdom/$cdom-domainconfig/\E(\w+)\.\Q/$cdom/$cnum\E}) {
           &get_customadhoc_roles($cdom,$cnum,\%courseroles,\%seccount,\%courseprivs,$privref);
     } else {      } else {
         my %gotnosection;          my %gotnosection;
         foreach my $item (keys(%env)) {          foreach my $item (keys(%env)) {
Line 2408  sub roles_selector { Line 2413  sub roles_selector {
                         $gotnosection{$role} = 1;                          $gotnosection{$role} = 1;
                     }                      }
                 }                  }
                 if ($priv ne '') {                  if ((ref($privref) eq 'ARRAY') && (@{$privref} > 0)) {
                     my $cnumsec = $cnum;                      my $cnumsec = $cnum;
                     if ($sec ne '') {                      if ($sec ne '') {
                         $cnumsec .= "/$sec";                          $cnumsec .= "/$sec";
Line 2446  sub roles_selector { Line 2451  sub roles_selector {
     }      }
     if ((keys(%seccount) > 1) || ($numdiffsec > 1)) {      if ((keys(%seccount) > 1) || ($numdiffsec > 1)) {
         my @submenu;          my @submenu;
         $js = &jump_to_role($cdom,$cnum,\%seccount,\%courseroles,\%courseprivs,$priv);          $js = &jump_to_role($cdom,$cnum,\%seccount,\%courseroles,\%courseprivs,$privref);
         $form =           $form = 
             '<form name="rolechooser" method="post" action="'.$httphost.'/adm/roles">'."\n".              '<form name="rolechooser" method="post" action="'.$httphost.'/adm/roles">'."\n".
             '  <input type="hidden" name="destinationurl" value="'.              '  <input type="hidden" name="destinationurl" value="'.
Line 2568  sub get_all_courseroles { Line 2573  sub get_all_courseroles {
     return;      return;
 }  }
   
   sub get_customadhoc_roles {
       my ($cdom,$cnum,$courseroles,$seccount,$courseprivs,$privref) = @_;
       unless ((ref($courseroles) eq 'HASH') && (ref($seccount) eq 'HASH') &&
               (ref($courseprivs) eq 'HASH')) {
           return;
       }
       if ($env{'environment.adhocroles.'.$cdom} ne '') {
           my @customroles = split(/,/,$env{'environment.adhocroles.'.$cdom});
           if (@customroles > 1) {
               if ($env{"user.role.dh./$cdom/"}) {
                   my ($start,$end)=split(/\./,$env{"user.role.dh./$cdom/"});
                   my $now = time;
                   if (!($start && ($now<$start)) & !($end && ($now>$end))) {
                       my $numsec = 1;
                       my @sections;
                       my ($allseclist,$cached) =
                           &Apache::lonnet::is_cached_new('courseseclist',$cdom.'_'.$cnum);
                       if (defined($cached)) {
                           if ($allseclist ne '') {
                               @sections = split(/,/,$allseclist);
                               $numsec += scalar(@sections);
                           }
                       } else {
                           my %sections_count = &Apache::loncommon::get_sections($cdom,$cnum);
                           $numsec += scalar(keys(%sections_count));
                           $allseclist = join(',',sort(keys(%sections_count)));
                           &Apache::lonnet::do_cache_new('courseseclist',$cdom.'_'.$cnum,$allseclist);
                       }
                       my (%adhoc,$gotprivs);
                       my $prefix = "cr/$cdom/$cdom".'-domainconfig';
                       foreach my $role (@customroles) {
                           next if (($role eq '') || ($role =~ /\W/));
                           $seccount->{"$prefix/$role"} = $numsec;
                           $courseroles->{"$prefix/$role"} = \@sections;
                           if ((ref($privref) eq 'ARRAY') && (@{$privref} > 0)) {
                               if (exists($env{"user.priv.$prefix/$role./$cdom/$cnum./"})) {
                                   $courseprivs->{"$prefix/$role./$cdom/$cnum./"} =
                                       $env{"user.priv.$prefix/$role./$cdom/$cnum./"};
                                   $courseprivs->{"$prefix/$role./$cdom/$cnum./$cdom/"} =
                                       $env{"user.priv.$prefix/$role./$cdom/$cnum./$cdom/"};
                                   $courseprivs->{"$prefix/$role./$cdom/$cnum./$cdom/$cnum"} =
                                       $env{"user.priv.$prefix/$role./$cdom/$cnum./$cdom/$cnum"};
                               } else {
                                   unless ($gotprivs) {
                                       my ($adhocroles,$privscached) =
                                           &Apache::lonnet::is_cached_new('adhocroles',$cdom);
                                       if ((defined($privscached)) && (ref($adhocroles) eq 'HASH')) {
                                           %adhoc = %{$adhocroles};
                                       } else {
                                           my $confname = &Apache::lonnet::get_domainconfiguser($cdom);
                                           my %roledefs = &Apache::lonnet::dump('roles',$cdom,$confname,'rolesdef_');
                                           foreach my $key (keys(%roledefs)) {
                                               (undef,my $rolename) = split(/_/,$key);
                                               if ($rolename ne '') {
                                                   $adhoc{$rolename} = $roledefs{$key};
                                               }
                                           }
                                           &Apache::lonnet::do_cache_new('adhocroles',$cdom,\%adhoc);
                                       }
                                       $gotprivs = 1;
                                   }
                                   ($courseprivs->{"$prefix/$role./$cdom/$cnum./"},
                                    $courseprivs->{"$prefix/$role./$cdom/$cnum./$cdom/"},
                                    $courseprivs->{"$prefix/$role./$cdom/$cnum./$cdom/$cnum"}) =
                                        split(/\_/,$adhoc{$role});
                               }
                           }
                       }
                   }
               }
           }
       }
       return;
   }
   
 sub jump_to_role {  sub jump_to_role {
     my ($cdom,$cnum,$seccount,$courseroles,$courseprivs,$priv) = @_;      my ($cdom,$cnum,$seccount,$courseroles,$courseprivs,$privref) = @_;
     my %lt = &Apache::lonlocal::texthash(      my %lt = &Apache::lonlocal::texthash(
                 this => 'This role has section(s) associated with it.',                  this => 'This role has section(s) associated with it.',
                 ente => 'Enter a specific section.',                  ente => 'Enter a specific section.',
Line 2602  sub jump_to_role { Line 2682  sub jump_to_role {
         }          }
     }      }
     my $checkroles = 0;      my $checkroles = 0;
     if ($priv && ref($courseprivs) eq 'HASH') {      if ((ref($privref) eq 'ARRAY') && (@{$privref} > 0) && (ref($courseprivs) eq 'HASH')) {
         my (%disallowed,%allowed,@disallow);          my %disallowed;
         foreach my $role (sort(keys(%{$courseprivs}))) {          foreach my $role (sort(keys(%{$courseprivs}))) {
             my $trole;              my $trole;
             if ($role =~ m{^(.+?)\Q./$cdom/$cnum\E}) {              if ($role =~ m{^(.+?)\Q./$cdom/$cnum\E}) {
                 $trole = $1;                  $trole = $1;
             }              }
             if (($trole ne '') && ($trole ne 'cm')) {              if (($trole ne '') && ($trole ne 'cm')) {
                 if ($courseprivs->{$role} =~ /\Q:$priv\E($|:|\&\w+)/) {                  $disallowed{$trole} = 1;
                     $allowed{$trole} = 1;                  foreach my $priv (@{$privref}) { 
                 } else {                      if ($courseprivs->{$role} =~ /\Q:$priv\E($|:|\&\w+)/) {
                     $disallowed{$trole} = 1;                          delete($disallowed{$trole});
                           last;
                       }
                 }                  }
             }              }
         }          }
         foreach my $trole (keys(%disallowed)) {          if (keys(%disallowed) > 0) {
             unless ($allowed{$trole}) {  
                 push(@disallow,$trole);  
             }  
         }  
         if (@disallow > 0) {  
             $checkroles = 1;              $checkroles = 1;
             $js .= "    var disallow = new Array('".join("','",@disallow)."');\n".              $js .= "    var disallow = new Array('".join("','",keys(%disallowed))."');\n".
                    "    var rolecheck = 1;\n";                     "    var rolecheck = 1;\n";
         }          }
     }      }
Line 2722  END Line 2799  END
   
 sub required_privs {  sub required_privs {
     my $privs =  {      my $privs =  {
              '/adm/parmset'      => 'opa',               '/adm/parmset'      => 'opa,vpa',
              '/adm/courseprefs'  => 'opa',               '/adm/courseprefs'  => 'opa,vpa',
              '/adm/whatsnew'     => 'whn',               '/adm/whatsnew'     => 'whn',
              '/adm/populate'     => 'cst',               '/adm/populate'     => 'cst',
              '/adm/trackstudent' => 'vsa',               '/adm/trackstudent' => 'vsa',
              '/adm/statistics'   => 'vgr',               '/adm/statistics'   => 'mgr,vgr',
              '/adm/setblock'     => 'dcm',               '/adm/setblock'     => 'dcm,vcb',
              '/adm/coursedocs'   => 'mdc',               '/adm/coursedocs'   => 'mdc',
            };             };
     unless ($env{'course.'.$env{'request.course.id'}.'.grading'} eq 'spreadsheet') {      unless ($env{'course.'.$env{'request.course.id'}.'.grading'} eq 'spreadsheet') {

Removed from v.1.369.2.60  
changed lines
  Added in v.1.369.2.61


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