Diff for /loncom/auth/lonroles.pm between versions 1.143 and 1.151

version 1.143, 2006/01/03 17:46:35 version 1.151, 2006/05/30 19:47:36
Line 39  use Apache::loncommon; Line 39  use Apache::loncommon;
 use Apache::lonhtmlcommon;  use Apache::lonhtmlcommon;
 use Apache::lonannounce;  use Apache::lonannounce;
 use Apache::lonlocal;  use Apache::lonlocal;
   use Apache::lonpageflip();
 use GDBM_File;  use GDBM_File;
   use LONCAPA;
    
   
 sub redirect_user {  sub redirect_user {
     my ($r,$title,$url,$msg,$launch_nav) = @_;      my ($r,$title,$url,$msg,$launch_nav) = @_;
Line 55  sub redirect_user { Line 58  sub redirect_user {
     } else {      } else {
  $navwindow.=&Apache::lonnavmaps::close();   $navwindow.=&Apache::lonnavmaps::close();
     }      }
     my $bodytag=&Apache::loncommon::bodytag('Switching Role');      my $start_page = &Apache::loncommon::start_page('Switching Role',undef,
       {'redirect' => [1,$url],});
       my $end_page   = &Apache::loncommon::end_page();
   
 # Note to style police:   # Note to style police: 
 # This must only replace the spaces, nothing else, or it bombs elsewhere.  # This must only replace the spaces, nothing else, or it bombs elsewhere.
     $url=~s/ /\%20/g;      $url=~s/ /\%20/g;
     $r->print(<<ENDREDIR);      $r->print(<<ENDREDIR);
 <head><title>$title</title>  $start_page
 <meta HTTP-EQUIV="Refresh" CONTENT="1; url=$url">  
 </head>  
 <html>  
 $bodytag  
 <script type="text/javascript">  <script type="text/javascript">
 $swinfo  $swinfo
 </script>  </script>
 $navwindow  $navwindow
 <h1>$msg</h1>  <h1>$msg</h1>
 <a href="$url">Continue</a>  $end_page
 </body>  
 </html>  
 ENDREDIR  ENDREDIR
     return;      return;
 }  }
   
   sub error_page {
       my ($r,$error,$dest)=@_;
       &Apache::loncommon::content_type($r,'text/html');
       &Apache::loncommon::no_cache($r);
       $r->send_http_header;
       return OK if $r->header_only;
       $r->print(&Apache::loncommon::start_page('Problems during Course Initialization').
         '<script type="text/javascript">'.
         &Apache::lonmenu::rawconfig().'</script>'.
         '<p>'.&mt('The following problems occurred:').
         $error.
         '</p><br /><a href="'.$dest.'>'.&mt('Continue').'</a>'.
         &Apache::loncommon::end_page());
   }
   
 sub handler {  sub handler {
   
     my $r = shift;      my $r = shift;
Line 86  sub handler { Line 101  sub handler {
     my $envkey;      my $envkey;
     my %dcroles = ();      my %dcroles = ();
     my $numdc = &check_fordc(\%dcroles,$then);      my $numdc = &check_fordc(\%dcroles,$then);
       &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'});
   
 # ================================================================== Roles Init  # ================================================================== Roles Init
     if ($env{'form.selectrole'}) {      if ($env{'form.selectrole'}) {
Line 108  sub handler { Line 124  sub handler {
 # Check if user is a DC trying to enter a course and needs privs to be created  # Check if user is a DC trying to enter a course and needs privs to be created
         if ($numdc > 0) {          if ($numdc > 0) {
             foreach my $envkey (keys %env) {              foreach my $envkey (keys %env) {
                 if ($envkey =~ m-^form\.cc\./(\w+)/(\w+)$-) {                  if (my ($domain,$coursenum) =
                     if ($dcroles{$1}) {                                      ($envkey =~ m-^form\.cc\./(\w+)/(\w+)$-)) {
                         my $cckey = 'user.role.cc./'.$1.'/'.$2;                      if ($dcroles{$domain}) {
                         &check_privs($cckey,$then,$now);                          &check_privs($domain,$coursenum,$then,$now);
                     }                      }
                     last;                      last;
                 }                  }
Line 159  sub handler { Line 175  sub handler {
  &Apache::loncommon::no_cache($r);   &Apache::loncommon::no_cache($r);
  $r->send_http_header;   $r->send_http_header;
  my $swinfo=&Apache::lonmenu::rawconfig();   my $swinfo=&Apache::lonmenu::rawconfig();
  my $bodytag=&Apache::loncommon::bodytag   my $start_page=&Apache::loncommon::start_page
     ('Verifying Access Key to Unlock this Course');      ('Verifying Access Key to Unlock this Course');
    my $end_page=&Apache::loncommon::end_page();
  my $buttontext=&mt('Enter Course');   my $buttontext=&mt('Enter Course');
  my $message=&mt('Successfully registered key');   my $message=&mt('Successfully registered key');
  my $assignresult=   my $assignresult=
Line 180  sub handler { Line 197  sub handler {
      $buttontext=&mt('Re-Enter Key');       $buttontext=&mt('Re-Enter Key');
  }   }
  $r->print(<<ENDENTEREDKEY);   $r->print(<<ENDENTEREDKEY);
 <head><title>Verifying Course Access Key</title>  $start_page
 </head>  
 <html>  
 $bodytag  
 <script>  <script>
 $swinfo  $swinfo
 </script>  </script>
Line 193  $swinfo Line 207  $swinfo
 <font size="+2">$message</font><br />  <font size="+2">$message</font><br />
 <input type="submit" value="$buttontext" />  <input type="submit" value="$buttontext" />
 </form>  </form>
 </body></html>  $end_page
 ENDENTEREDKEY  ENDENTEREDKEY
                                  return OK;                                   return OK;
      } else {       } else {
Line 202  ENDENTEREDKEY Line 216  ENDENTEREDKEY
  &Apache::loncommon::no_cache($r);   &Apache::loncommon::no_cache($r);
  $r->send_http_header;   $r->send_http_header;
  my $swinfo=&Apache::lonmenu::rawconfig();   my $swinfo=&Apache::lonmenu::rawconfig();
  my $bodytag=&Apache::loncommon::bodytag   my $start_page=&Apache::loncommon::start_page
     ('Enter Access Key to Unlock this Course');      ('Enter Access Key to Unlock this Course');
    my $end_page=&Apache::loncommon::end_page();
  $r->print(<<ENDENTERKEY);   $r->print(<<ENDENTERKEY);
 <head><title>Entering Course Access Key</title>  $start_page
 </head>  
 <html>  
 $bodytag  
 <script>  <script>
 $swinfo  $swinfo
 </script>  </script>
Line 218  $swinfo Line 230  $swinfo
 <input type="text" size="20" name="newkey" value="$env{'form.newkey'}" />  <input type="text" size="20" name="newkey" value="$env{'form.newkey'}" />
 <input type="submit" value="Enter key" />  <input type="submit" value="Enter key" />
 </form>  </form>
 </body></html>  $end_page
 ENDENTERKEY  ENDENTERKEY
  return OK;   return OK;
      }       }
Line 245  ENDENTERKEY Line 257  ENDENTERKEY
     my $dest=$env{'form.orgurl'};      my $dest=$env{'form.orgurl'};
     if (&Apache::lonnet::allowed('adv') eq 'F') { $tadv=1; }      if (&Apache::lonnet::allowed('adv') eq 'F') { $tadv=1; }
     &Apache::lonnet::appenv('request.role.adv'=>$tadv);      &Apache::lonnet::appenv('request.role.adv'=>$tadv);
     $r->internal_redirect($dest);                              if (($ferr) && ($tadv)) {
    &error_page($r,$ferr,$dest);
       } else {
    $r->internal_redirect($dest);
       }
     return OK;      return OK;
  } else {   } else {
     unless ($env{'request.course.id'}) {      unless ($env{'request.course.id'}) {
Line 259  ENDENTERKEY Line 275  ENDENTERKEY
     }      }
     if (&Apache::lonnet::allowed('adv') eq 'F') { $tadv=1; }      if (&Apache::lonnet::allowed('adv') eq 'F') { $tadv=1; }
     &Apache::lonnet::appenv('request.role.adv'=>$tadv);      &Apache::lonnet::appenv('request.role.adv'=>$tadv);
       if (($ferr) && ($tadv)) {
     # Check to see if the user is a CC entering a course    &error_page($r,$ferr,$furl);
     # for the first time      } else {
     my (undef, undef, $role, $courseid) = split(/\./, $envkey);   # Check to see if the user is a CC entering a course 
     if (substr($courseid, 0, 1) eq '/') {   # for the first time
  $courseid = substr($courseid, 1);   my (undef, undef, $role, $courseid) = split(/\./, $envkey);
     }   if (substr($courseid, 0, 1) eq '/') {
     $courseid =~ s/\//_/;      $courseid = substr($courseid, 1);
     if ($role eq 'cc' && $env{'course.' . $courseid .    }
   '.course.helper.not.run'}) {   $courseid =~ s/\//_/;
  $furl = "/adm/helper/course.initialization.helper";   if ($role eq 'cc' && $env{'course.' . $courseid . 
  # Send the user to the course they selected        '.course.helper.not.run'}) {
     } elsif ($env{'request.course.id'}) {      $furl = "/adm/helper/course.initialization.helper";
                                 if (&Apache::lonnet::allowed('whn',      # Send the user to the course they selected
                                                   $env{'request.course.id'})) {   } elsif ($env{'request.course.id'}) {
                                     my $startpage = &courseloadpage($courseid);      if (&Apache::lonnet::allowed('whn',
                                     unless ($startpage eq 'firstres') {            $env{'request.course.id'})
         $msg = &mt('Entering course ....');   || &Apache::lonnet::allowed('whn',
         &redirect_user($r,&mt('New in course'),      $env{'request.course.id'}.'/'
      '/adm/whatsnew?refpage=start',$msg,      .$env{'request.course.sec'})
      $env{'environment.remotenavmap'});   ) {
         return OK;   my $startpage = &courseloadpage($courseid);
                                     }   unless ($startpage eq 'firstres') {         
                                 }      $msg = &mt('Entering course ....');
       &redirect_user($r,&mt('New in course'),
      '/adm/whatsnew?refpage=start',$msg,
      $env{'environment.remotenavmap'});
       return OK;
    }
       }
    }
   # Are we allowed to look at the first resource?
    if (!&Apache::lonnet::allowed('bre',$furl)) {
   # Guess not ...
       $furl=&Apache::lonpageflip::first_accessible_resource();
    }
    &redirect_user($r,&mt('Entering Course'),
          $furl,$msg,
          $env{'environment.remotenavmap'});
     }      }
     &redirect_user($r,&mt('Entering Course'),  
                                            $furl,$msg,  
    $env{'environment.remotenavmap'});  
     return OK;      return OK;
  }   }
     }      }
Line 325  ENDENTERKEY Line 353  ENDENTERKEY
     return OK if $r->header_only;      return OK if $r->header_only;
   
     my $swinfo=&Apache::lonmenu::rawconfig();      my $swinfo=&Apache::lonmenu::rawconfig();
     my $bodytag=&Apache::loncommon::bodytag('User Roles');      my $start_page=&Apache::loncommon::start_page('User Roles');
     my $standby=&mt('Role selected. Please stand by.');      my $standby=&mt('Role selected. Please stand by.');
     $standby=~s/\n/\\n/g;      $standby=~s/\n/\\n/g;
     my $helptag='<table><tr><td>'.&Apache::loncommon::help_open_menu('','General Intro','General_Intro','User Roles',1,undef,undef,undef,undef,,&mt("Click here for help")).'</td></td></tr></table>';      my $helptag='<table><tr><td>'.&Apache::loncommon::help_open_menu('','General Intro','General_Intro','User Roles',1,undef,undef,undef,undef,,&mt("Click here for help")).'</td></td></tr></table>';
     $r->print(<<ENDHEADER);      $r->print(<<ENDHEADER);
 <html>  $start_page
 <head>  
 <title>LON-CAPA User Roles</title>  
 </head>  
 $bodytag  
 $helptag<br />  $helptag<br />
 <script>  <script>
 $swinfo  $swinfo
Line 385  ENDHEADER Line 409  ENDHEADER
     $last=$hash{'last_known'};      $last=$hash{'last_known'};
     untie(%hash);      untie(%hash);
  }   }
  if ($last) { $fn.='?symb='.&Apache::lonnet::escape($last); }   if ($last) { $fn.='?symb='.&escape($last); }
   
  &Apache::londocs::changewarning($r,undef,'You have modified your course recently, [_1] may fix this access problem.',   &Apache::londocs::changewarning($r,undef,'You have modified your course recently, [_1] may fix this access problem.',
  &Apache::lonenc::check_encrypt($fn));   &Apache::lonenc::check_encrypt($fn));
Line 398  ENDHEADER Line 422  ENDHEADER
     }      }
 # -------------------------------------------------------- Choice or no choice?  # -------------------------------------------------------- Choice or no choice?
     if ($nochoose) {      if ($nochoose) {
         if ($advanced) {   $r->print("<h2>".&mt('Sorry ...')."</h2>\n".
     $r->print("<h2>".&mt('Assigned User Roles')."</h2>\n");    &mt('This action is currently not authorized.').
         } else {    &Apache::loncommon::end_page());
     $r->print("<h2>".&mt('Sorry ...')."</h2>\n".   return OK;
       &mt('This resource might be part of'));  
     if ($env{'request.course.id'}) {  
  $r->print(&mt(' another'));  
     } else {  
  $r->print(&mt(' a certain'));  
     }   
     $r->print(&mt(' course.').'</body></html>');  
     return OK;  
         }   
     } else {      } else {
         if ($advanced) {          if ($advanced) {
     $r->print(&mt("Your home server is ").      $r->print(&mt("Your home server is ").
Line 597  ENDHEADER Line 612  ENDHEADER
  } else {   } else {
     $r->print('<h2>'.&mt('Currently no active roles or courses').'</h2>');      $r->print('<h2>'.&mt('Currently no active roles or courses').'</h2>');
  }   }
  $r->print('</form></body></html>');   $r->print('</form>'.&Apache::loncommon::end_page());
  return OK;   return OK;
 # Is there only one choice?  # Is there only one choice?
     } elsif (($countactive==1) && ($env{'request.role'} eq 'cm')) {      } elsif (($countactive==1) && ($env{'request.role'} eq 'cm')) {
Line 606  ENDHEADER Line 621  ENDHEADER
  $r->print("</form>\n");   $r->print("</form>\n");
  $r->rflush();   $r->rflush();
  $r->print('<script>document.forms.rolechoice.submit();</script>');   $r->print('<script>document.forms.rolechoice.submit();</script>');
  $r->print('</body></html>');   $r->print(&Apache::loncommon::end_page());
  return OK;   return OK;
     }      }
 # More than one possible role  # More than one possible role
Line 763  ENDHEADER Line 778  ENDHEADER
   $r->dir_config('lonVersion').'</i><br />'.    $r->dir_config('lonVersion').'</i><br />'.
   '<a href="/adm/logout">'.&mt('Logout').'</a></small></p>');    '<a href="/adm/logout">'.&mt('Logout').'</a></small></p>');
     }      }
     $r->print("</body></html>\n");      $r->print(&Apache::loncommon::end_page());
     return OK;      return OK;
 }  }
   
Line 843  sub build_roletext { Line 858  sub build_roletext {
 }  }
   
 sub check_privs {  sub check_privs {
     my ($cckey,$then,$now) = @_;      my ($cdom,$cnum,$then,$now) = @_;
       my $cckey = 'user.role.cc./'.$cdom.'/'.$cnum; 
     if ($env{$cckey}) {      if ($env{$cckey}) {
         my ($role,$where,$trolecode,$tstart,$tend,$tremark,$tstatus,$tpstart,$tpend,$tfont);          my ($role,$where,$trolecode,$tstart,$tend,$tremark,$tstatus,$tpstart,$tpend,$tfont);
         &role_status($cckey,$then,$now,\$role,\$where,\$trolecode,\$tstatus,\$tstart,\$tend);          &role_status($cckey,$then,$now,\$role,\$where,\$trolecode,\$tstatus,\$tstart,\$tend);
         unless (($tstatus eq 'is') || ($tstatus eq 'will_not')) {          unless (($tstatus eq 'is') || ($tstatus eq 'will_not')) {
             &set_privileges($1,$2);              &set_privileges($cdom,$cnum);
         }          }
     } else {      } else {
         &set_privileges($1,$2);          &set_privileges($cdom,$cnum);
     }      }
 }  }
   
Line 994  sub allcourses_row { Line 1010  sub allcourses_row {
   
 sub recent_filename {  sub recent_filename {
     my $area=shift;      my $area=shift;
     return 'nohist_recent_'.&Apache::lonnet::escape($area);      return 'nohist_recent_'.&escape($area);
 }  }
   
 sub set_privileges {  sub set_privileges {
Line 1018  sub set_privileges { Line 1034  sub set_privileges {
                          $env{'user.home'},                           $env{'user.home'},
                         "Role ".$role);                          "Role ".$role);
     &Apache::lonnet::appenv(      &Apache::lonnet::appenv(
                           'request.role'        => $role,                            'request.role'        => $spec,
                           'request.role.domain' => $dcdom,                            'request.role.domain' => $dcdom,
                           'request.course.sec'  => '');                            'request.course.sec'  => '');
     my $tadv=0;      my $tadv=0;
Line 1029  sub set_privileges { Line 1045  sub set_privileges {
 sub courseloadpage {  sub courseloadpage {
     my ($courseid) = @_;      my ($courseid) = @_;
     my $startpage;      my $startpage;
     my %entry_settings =      my %entry_settings = &Apache::lonnet::get('nohist_whatsnew',
               &Apache::lonnet::dump('nohist_whatsnew',$env{'user.domain'},        [$courseid.':courseinit']);
                                     $env{'user.name'},$courseid.':courseinit');  
     my ($tmp) = %entry_settings;      my ($tmp) = %entry_settings;
     unless ($tmp =~ /^Error/) {      unless ($tmp =~ /^error: 2 /) {
         $startpage = $entry_settings{$courseid.':courseinit'};          $startpage = $entry_settings{$courseid.':courseinit'};
     }      }
     if ($startpage eq '') {      if ($startpage eq '') {

Removed from v.1.143  
changed lines
  Added in v.1.151


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