Diff for /loncom/auth/lonroles.pm between versions 1.104 and 1.107

version 1.104, 2004/11/09 18:18:02 version 1.107, 2004/11/11 23:17:13
Line 83  sub handler { Line 83  sub handler {
     my $then=$ENV{'user.login.time'};      my $then=$ENV{'user.login.time'};
     my $envkey;      my $envkey;
     my $dcselect='';      my $dcselect='';
       my %dcroles = ();
       my $numdc = &check_fordc(\%dcroles,$then);
   
 # ================================================================== Roles Init  # ================================================================== Roles Init
     if ($ENV{'form.selectrole'}) {      if ($ENV{'form.selectrole'}) {
Line 120  sub handler { Line 121  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 to see if the user is a DC trying to enter a course and needs privs to be created
           if ($numdc > 0) {
               foreach my $envkey (keys %ENV) {
                   if ($envkey =~ m-^form\.cc\./(\w+)/(\w+)$-) {
                       if ($dcroles{$1}) {
                           unless ($ENV{'user.role.cc./'.$1.'/'.$2}) {
                               &set_privileges($1,$2);
                           }
                       }
                       last;
                   }
               }
           }
   
           if ($ENV{'form.dccourse'}) {
               my $dcdom = $ENV{'form.dcdomain'};
               my $pickedcourse = $ENV{'form.dccourse'};
               if ($dcdom && $pickedcourse) {
                   unless ($ENV{'user.role.cc./'.$dcdom.'/'.$pickedcourse}) {
                       if ($ENV{'user.role.dc./'.$dcdom.'/'}) {
                           &set_privileges($dcdom,$pickedcourse);
                       }
                   }
               }
           }
   
         foreach $envkey (keys %ENV) {          foreach $envkey (keys %ENV) {
             next if ($envkey!~/^user\.role\./);              next if ($envkey!~/^user\.role\./);
             my ($where,$trolecode,$role,$tstatus,$tend,$tstart);              my ($where,$trolecode,$role,$tstatus,$tend,$tstart);
Line 264  ENDENTERKEY Line 292  ENDENTERKEY
     }      }
                             # Check to see if the user is a DC coming from the                              # Check to see if the user is a DC coming from the
                             # course selection page                              # course selection page
                             my $dcflag = 0;  
                             if ($ENV{'form.dccourse'}) {                              if ($ENV{'form.dccourse'}) {
                                 my $formaction = '/adm/roles/';                                  my $formaction = '/adm/roles/';
                                 my ($dcdom,$pickedcourse) = split/_/,$courseid;                                  my ($dcdom,$pickedcourse) = split/_/,$courseid;
Line 408  ENDHEADER Line 435  ENDHEADER
  $r->print('><input type=submit value="'.&mt('Display').'">');   $r->print('><input type=submit value="'.&mt('Display').'">');
     }      }
   
     my %dcroles = ();  
     my $numdc = &check_fordc(\%dcroles,$then);  
   
     my (%roletext,%sortrole,%roleclass);      my (%roletext,%sortrole,%roleclass);
     my $countactive=0;      my $countactive=0;
     my $inrole=0;      my $inrole=0;
Line 539  ENDHEADER Line 563  ENDHEADER
                                     '</font>';                                      '</font>';
  }   }
                     } else {                      } else {
                         my %newhash=Apache::lonnet::coursedescription                          my %newhash=&Apache::lonnet::coursedescription($tcourseid);
                             ($tcourseid);  
                         if (%newhash) {                          if (%newhash) {
     $sortkey=$role."\0".$tdom."\0".$newhash{'description'}.      $sortkey=$role."\0".$tdom."\0".$newhash{'description'}.
  "\0".$envkey;   "\0".$envkey;
Line 676  ENDHEADER Line 699  ENDHEADER
              foreach my $which (sort {uc($a) cmp uc($b)} (keys(%sortrole))) {               foreach my $which (sort {uc($a) cmp uc($b)} (keys(%sortrole))) {
                 my $skiprole = 0;                  my $skiprole = 0;
                 foreach my $dcdom (keys %dcroles) {                  foreach my $dcdom (keys %dcroles) {
                     if ($sortrole{$which} =~ m-(dc|cc)\./$dcdom/-) {                      if ($sortrole{$which} =~ m-(dc)\./$dcdom/-) {
                         $skiprole = 1;                          $skiprole = 1;
                         last;                          last;
                     }                      }
Line 707  ENDHEADER Line 730  ENDHEADER
     $r->print("<tr bgcolor='#BBffBB'>".      $r->print("<tr bgcolor='#BBffBB'>".
       "<td align='center' colspan='7'>".&mt($type)."</td>");        "<td align='center' colspan='7'>".&mt($type)."</td>");
         }          }
         $r->print($output);              $r->print($output);
     }      }
         }          }
     }      }
Line 810  sub role_status { Line 833  sub role_status {
             $$trolecode=$$role.'.'.$$where;              $$trolecode=$$role.'.'.$$where;
             ($$tstart,$$tend)=split(/\./,$ENV{$rolekey});              ($$tstart,$$tend)=split(/\./,$ENV{$rolekey});
             $$tstatus='is';              $$tstatus='is';
             if ($$tstart) {              if ($$tstart && $$tstart>$then) {
                 if ($$tstart>$then) {   $$tstatus='future';
                     $$tstatus='future';   if ($$tstart<$now) { $$tstatus='will'; }
                     if ($$tstart<$now) { $$tstatus='will'; }  
                 }  
             }              }
             if ($$tend) {              if ($$tend) {
                 if ($$tend<$then) {                  if ($$tend<$then) {
Line 848  sub check_fordc { Line 869  sub check_fordc {
                 my $dcdom = $1;                  my $dcdom = $1;
                 my $livedc = 1;                  my $livedc = 1;
                 my ($tstart,$tend)=split(/\./,$ENV{$envkey});                  my ($tstart,$tend)=split(/\./,$ENV{$envkey});
                 if ($tstart) {                  if ($tstart && $tstart>$then) { $livedc = 0; }
                     if ($tstart>$then) {                  if ($tend   && $tend  <$then) { $livedc = 0; }
                         $livedc = 0;  
                     }  
                 }  
                 if ($tend) {  
                     if ($tend<$then) {  
                         $livedc = 0;  
                     }  
                 }  
                 if ($livedc) {                  if ($livedc) {
                     $$dcroles{$dcdom} = $envkey;                      $$dcroles{$dcdom} = $envkey;
                     $numdc ++;                      $numdc++;
                 }                  }
             }              }
         }          }
Line 1020  sub recent_filename { Line 1033  sub recent_filename {
     return 'nohist_recent_'.&Apache::lonnet::escape($area);      return 'nohist_recent_'.&Apache::lonnet::escape($area);
 }  }
   
   sub set_privileges {
       my ($dcdom,$pickedcourse) = @_;
       my $area = '/'.$dcdom.'/'.$pickedcourse;
       my $role = 'cc';
       my $spec = $role.'.'.$area;
       my $userroles = &Apache::lonnet::set_arearole($role,$area,'','',$dcdom,$ENV{'user.name'});
       my %ccrole = ();
       &Apache::lonnet::standard_roleprivs(\%ccrole,$role,$dcdom,$spec,$pickedcourse,$area);
       my ($author,$adv)= &Apache::lonnet::set_userprivs(\$userroles,\%ccrole);
       my @newprivs = split/\n/,$userroles;
       my %newccroles = ();
       foreach (@newprivs) {
           my ($key,$val) = split/=/,$_;
           $newccroles{$key} = $val;
       }
       &Apache::lonnet::appenv(%newccroles);
       &Apache::lonnet::log($ENV{'user.domain'},
                            $ENV{'user.name'},
                            $ENV{'user.home'},
                           "Role ".$role);
       &Apache::lonnet::appenv(
                             'request.role'        => $role,
                             'request.role.domain' => $dcdom,
                             'request.course.sec'  => '');
       my $tadv=0;
       if (&Apache::lonnet::allowed('adv') eq 'F') { $tadv=1; }
       &Apache::lonnet::appenv('request.role.adv'    => $tadv);
   }
   
 1;  1;
 __END__  __END__
   

Removed from v.1.104  
changed lines
  Added in v.1.107


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