Diff for /loncom/auth/lonroles.pm between versions 1.231.4.2 and 1.248

version 1.231.4.2, 2009/08/14 12:41:34 version 1.248, 2010/06/02 14:55:37
Line 57  course they should act on, etc. Both in Line 57  course they should act on, etc. Both in
 handler determines via C<lonnet>'s C<&allowed> function that a certain  handler determines via C<lonnet>'s C<&allowed> function that a certain
 action is not allowed, C<lonroles> is used as error handler. This  action is not allowed, C<lonroles> is used as error handler. This
 allows the user to select another role which may have permission to do  allows the user to select another role which may have permission to do
 what they were trying to do. C<lonroles> can also be accessed via the  what they were trying to do.
 B<CRS> button in the Remote Control.   
   
 =begin latex  =begin latex
   
Line 138  use Apache::lonannounce; Line 137  use Apache::lonannounce;
 use Apache::lonlocal;  use Apache::lonlocal;
 use Apache::lonpageflip();  use Apache::lonpageflip();
 use Apache::lonnavdisplay();  use Apache::lonnavdisplay();
   use Apache::loncoursequeueadmin;
 use GDBM_File;  use GDBM_File;
 use LONCAPA qw(:DEFAULT :match);  use LONCAPA qw(:DEFAULT :match);
 use HTML::Entities;  use HTML::Entities;
     
   
 sub redirect_user {  sub redirect_user {
     my ($r,$title,$url,$msg,$launch_nav) = @_;      my ($r,$title,$url,$msg) = @_;
     $msg = $title if (! defined($msg));      $msg = $title if (! defined($msg));
     &Apache::loncommon::content_type($r,'text/html');      &Apache::loncommon::content_type($r,'text/html');
     &Apache::loncommon::no_cache($r);      &Apache::loncommon::no_cache($r);
     $r->send_http_header;      $r->send_http_header;
     my $swinfo=&Apache::lonmenu::rawconfig();  
     my $navwindow;  
     if ($launch_nav eq 'on') {  
  $navwindow.=&Apache::lonnavdisplay::launch_win('now',undef,undef,  
        ($url =~ m-^/adm/whatsnew-));  
     } else {  
  $navwindow.=&Apache::lonnavmaps::close();  
     }  
   
       # Breadcrumbs
       my $brcrum = [{'href' => $url,
                      'text' => 'Switching Role'},];
     my $start_page = &Apache::loncommon::start_page('Switching Role',undef,      my $start_page = &Apache::loncommon::start_page('Switching Role',undef,
                                                     {'redirect' => [1,$url]});                                                      {'redirect' => [1,$url],
                                                        'bread_crumbs' => $brcrum,});
     my $end_page   = &Apache::loncommon::end_page();      my $end_page   = &Apache::loncommon::end_page();
   
 # Note to style police:   # Note to style police: 
Line 167  sub redirect_user { Line 163  sub redirect_user {
     $url=~s/ /\%20/g;      $url=~s/ /\%20/g;
     $r->print(<<ENDREDIR);      $r->print(<<ENDREDIR);
 $start_page  $start_page
 <script type="text/javascript">  
 // <![CDATA[  
 $swinfo  
 // ]]>  
 </script>  
 $navwindow  
 <p>$msg</p>  <p>$msg</p>
 $end_page  $end_page
 ENDREDIR  ENDREDIR
Line 185  sub error_page { Line 175  sub error_page {
     &Apache::loncommon::no_cache($r);      &Apache::loncommon::no_cache($r);
     $r->send_http_header;      $r->send_http_header;
     return OK if $r->header_only;      return OK if $r->header_only;
     $r->print(&Apache::loncommon::start_page('Problems during Course Initialization').      # Breadcrumbs
       my $brcrum = [{'href' => $dest,
                      'text' => 'Problems during Course Initialization'},];
       $r->print(&Apache::loncommon::start_page('Problems during Course Initialization',
                                                undef,
                                                {'bread_crumbs' => $brcrum,})
       );
       $r->print(
         '<script type="text/javascript">'.          '<script type="text/javascript">'.
         '// <![CDATA['.          '// <![CDATA['.
         &Apache::lonmenu::rawconfig().          &Apache::lonmenu::rawconfig().
         '// ]]>'.          '// ]]>'.
         '</script>'.          '</script>'.
       '<p class="LC_error">'.&mt('The following problems occurred:').        '<p class="LC_error">'.&mt('The following problems occurred:').
               '<br />'.            '<br />'.
       $error.        $error.
       '</p><br /><a href="'.$dest.'">'.&mt('Continue').'</a>'.        '</p><br /><a href="'.$dest.'">'.&mt('Continue').'</a>'
               &Apache::loncommon::end_page());      );
       $r->print(&Apache::loncommon::end_page());
 }  }
   
 sub handler {  sub handler {
Line 226  sub handler { Line 224  sub handler {
             # Check if user is CC trying to select a course role              # Check if user is CC trying to select a course role
             if ($env{'form.switchrole'}) {              if ($env{'form.switchrole'}) {
                 if (!defined($env{'user.role.'.$env{'form.switchrole'}})) {                  if (!defined($env{'user.role.'.$env{'form.switchrole'}})) {
                     &adhoc_course_role($then);                      &adhoc_course_role($refresh,$then);
                 }                  }
             }              }
     my %temp=('logout_'.$env{'request.course.id'} => time);      my %temp=('logout_'.$env{'request.course.id'} => time);
Line 243  sub handler { Line 241  sub handler {
 # 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) {          if ($numdc > 0) {
             foreach my $envkey (keys %env) {              foreach my $envkey (keys %env) {
 # Is this an ad-hoc CC-role?  # Is this an ad-hoc Coordinator role?
                 if (my ($domain,$coursenum) =                  if (my ($ccrole,$domain,$coursenum) =
     ($envkey =~ m-^form\.cc\./($match_domain)/($match_courseid)$-)) {      ($envkey =~ m-^form\.(cc|co)\./($match_domain)/($match_courseid)$-)) {
                     if ($dcroles{$domain}) {                      if ($dcroles{$domain}) {
                         &Apache::lonnet::check_adhoc_privs($domain,$coursenum,                          &Apache::lonnet::check_adhoc_privs($domain,$coursenum,
                                                            $then,$refresh,$now,'cc');                                                             $then,$refresh,$now,$ccrole);
                     }                      }
                     last;                      last;
                 }                  }
Line 261  sub handler { Line 259  sub handler {
                         my ($server_status,$home) = &check_author_homeserver($user,$domain);                          my ($server_status,$home) = &check_author_homeserver($user,$domain);
                         if ($server_status eq 'switchserver') {                          if ($server_status eq 'switchserver') {
                             my $trolecode = 'au./'.$domain.'/';                              my $trolecode = 'au./'.$domain.'/';
                             my $switchserver = '/adm/switchserver?otherserver='.$home.'&role='.$trolecode;                              my $switchserver = '/adm/switchserver?otherserver='.$home.'&amp;role='.$trolecode;
                             $r->internal_redirect($switchserver);                              $r->internal_redirect($switchserver);
                         }                          }
                         last;                          last;
Line 272  sub handler { Line 270  sub handler {
                             my ($server_status,$home) = &check_author_homeserver($user,$domain);                              my ($server_status,$home) = &check_author_homeserver($user,$domain);
                             if ($server_status eq 'switchserver') {                              if ($server_status eq 'switchserver') {
                                 my $trolecode = 'ca./'.$domain.'/'.$user;                                  my $trolecode = 'ca./'.$domain.'/'.$user;
                                 my $switchserver = '/adm/switchserver?otherserver='.$home.'&role='.$trolecode;                                  my $switchserver = '/adm/switchserver?otherserver='.$home.'&amp;role='.$trolecode;
                                 $r->internal_redirect($switchserver);                                  $r->internal_redirect($switchserver);
                             }                              }
                             last;                              last;
Line 293  sub handler { Line 291  sub handler {
                             if ($server_status eq 'switchserver') {                              if ($server_status eq 'switchserver') {
                                 my $trolecode = 'ca./'.$domain.'/'.$user;                                   my $trolecode = 'ca./'.$domain.'/'.$user; 
                                 my $switchserver = '/adm/switchserver?'                                  my $switchserver = '/adm/switchserver?'
                                                   .'otherserver='.$home.'&role='.$trolecode;                                                    .'otherserver='.$home.'&amp;role='.$trolecode;
                                 $r->internal_redirect($switchserver);                                  $r->internal_redirect($switchserver);
                             }                              }
                         } else {                          } else {
Line 479  ENDENTERKEY Line 477  ENDENTERKEY
     $courseid = substr($courseid, 1);      $courseid = substr($courseid, 1);
  }   }
  $courseid =~ s/\//_/;   $courseid =~ s/\//_/;
  if ($role eq 'cc' && $env{'course.' . $courseid .    if ((($role eq 'cc') || ($role eq 'co')) 
       '.course.helper.not.run'}) {                                      && ($env{'course.' . $courseid .'.course.helper.not.run'})) { 
     $furl = "/adm/helper/course.initialization.helper";      $furl = "/adm/helper/course.initialization.helper";
     # Send the user to the course they selected      # Send the user to the course they selected
  } elsif ($env{'request.course.id'}) {   } elsif ($env{'request.course.id'}) {
Line 490  ENDENTERKEY Line 488  ENDENTERKEY
                                             my $esc_symb = &HTML::Entities::encode($env{'form.destsymb'},'"<>&');                                              my $esc_symb = &HTML::Entities::encode($env{'form.destsymb'},'"<>&');
                                             $dest .= '?symb='.$esc_symb;                                              $dest .= '?symb='.$esc_symb;
                                         }                                          }
                                         &redirect_user($r,&mt('Entering [_1]',                                          &redirect_user($r, &mt('Entering [_1]',
                                                       $env{'course.'.$courseid.'.description'}),                                                         $env{'course.'.$courseid.'.description'}),
                                                $dest,$msg,                                                         $dest, $msg);
                                                $env{'environment.remotenavmap'});  
                                         return OK;                                          return OK;
                                     }                                      }
     if (&Apache::lonnet::allowed('whn',      if (&Apache::lonnet::allowed('whn',
Line 506  ENDENTERKEY Line 503  ENDENTERKEY
  unless ($startpage eq 'firstres') {            unless ($startpage eq 'firstres') {         
     $msg = &mt('Entering [_1] ...',      $msg = &mt('Entering [_1] ...',
        $env{'course.'.$courseid.'.description'});         $env{'course.'.$courseid.'.description'});
     &redirect_user($r,&mt('New in course'),      &redirect_user($r, &mt('New in course'),
    '/adm/whatsnew?refpage=start',$msg,                                         '/adm/whatsnew?refpage=start', $msg);
    $env{'environment.remotenavmap'});  
     return OK;      return OK;
  }   }
     }      }
Line 520  ENDENTERKEY Line 516  ENDENTERKEY
  }   }
                                 $msg = &mt('Entering [_1] ...',                                  $msg = &mt('Entering [_1] ...',
    $env{'course.'.$courseid.'.description'});     $env{'course.'.$courseid.'.description'});
  &redirect_user($r,&mt('Entering [_1]',   &redirect_user($r, &mt('Entering [_1]',
       $env{'course.'.$courseid.'.description'}),                                 $env{'course.'.$courseid.'.description'}),
        $furl,$msg,                                 $furl, $msg);
        $env{'environment.remotenavmap'});  
     }      }
     return OK;      return OK;
  }   }
Line 659  ENDHEADER Line 654  ENDHEADER
             if ($reinit) {              if ($reinit) {
                 $r->print(                  $r->print(
  '<h3><span class="LC_error">'.   '<h3><span class="LC_error">'.
  &mt('As your session file for the course has expired, you will need to re-select the course.').'</span></h3>');   &mt('As your session file for the course or community has expired, you will need to re-select it.').'</span></h3>');
             } else {              } else {
         $r->print(          $r->print(
  '<h3><span class="LC_error">'.   '<h3><span class="LC_error">'.
  &mt('You need to choose another user role or enter a specific course for this function').'</span></h3>');   &mt('You need to choose another user role or enter a specific course or community for this function.').
    '</span></h3>');
     }      }
         }          }
     }      }
Line 691  ENDHEADER Line 687  ENDHEADER
     $refresh = $now;      $refresh = $now;
     &Apache::lonnet::appenv({'user.refresh.time'  => $refresh});      &Apache::lonnet::appenv({'user.refresh.time'  => $refresh});
     if ($env{'user.adv'}) {      if ($env{'user.adv'}) {
         $r->print(          $r->print('<p><label><input type="checkbox" name="showall"');
               '<p><label>'.&mt('Show all roles').': <input type="checkbox" name="showall"');  
         if ($env{'form.showall'}) { $r->print(' checked="checked" '); }          if ($env{'form.showall'}) { $r->print(' checked="checked" '); }
         $r->print(' /></label><input type="submit" value="'.&mt('Display').'" /></p>');          $r->print(' />'.&mt('Show all roles').'</label>'
                    .' <input type="submit" value="'.&mt('Update display').'" />'
                    .'</p>');
     } else {      } else {
         if ($countactive > 0) {          if ($countactive > 0) {
             &queued_selfenrollment($r);              $r->print(&Apache::loncoursequeueadmin::queued_selfenrollment());
             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'},'"<>&'); 
             $r->print('<p>'.&mt('[_1]Visit the [_2]Course Catalog[_3] to view all [_4] LON-CAPA courses.','<b>','<a href="/adm/coursecatalog?showdom='.$esc_dom.'">','</a></b>',$domdesc).'<br />'.&mt('If a course is [_1]not[_2] in your list of current courses below, you may be able to enroll if self-enrollment is permitted.','<b>','</b>').'</p>');              $r->print(
                   '<p>'
                  .&mt('[_1]Visit the [_2]Course/Community Catalog[_3]'
                      .' to view all [_4] LON-CAPA courses and communities.'
                      ,'<b>'
                      ,'<a href="/adm/coursecatalog?showdom='.$esc_dom.'">'
                      ,'</a></b>',$domdesc)
                  .'<br />'
                  .&mt('If a course or community is [_1]not[_2] in your list of current courses and communities below,'
                      .' you may be able to enroll if self-enrollment is permitted.'
                      ,'<b>','</b>')
                  .'</p>'
               );
         }          }
     }      }
   
 # No active roles  # No active roles
     if ($countactive==0) {      if ($countactive==0) {
  if ($inrole) {   if ($inrole) {
     $r->print('<h2>'.&mt('Currently no additional roles or courses').'</h2>');      $r->print('<h2>'.&mt('Currently no additional roles, courses or communities').'</h2>');
  } else {   } else {
     $r->print('<h2>'.&mt('Currently no active roles or courses').'</h2>');      $r->print('<h2>'.&mt('Currently no active roles, courses or communities').'</h2>');
  }   }
         &findcourse_advice($r);          &findcourse_advice($r);
           &requestcourse_advice($r); 
  $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));
Line 742  ENDHEADER Line 752  ENDHEADER
  return OK;   return OK;
     }      }
 # ----------------------------------------------------------------------- Table  # ----------------------------------------------------------------------- Table
   
       if ($numdc > 0) {
           $r->print(&coursepick_jscript());
           $r->print(&Apache::loncommon::coursebrowser_javascript().
                     &Apache::loncommon::authorbrowser_javascript());
       }
   
     unless ((!&Apache::loncommon::show_course()) || ($nochoose) || ($countactive==1)) {      unless ((!&Apache::loncommon::show_course()) || ($nochoose) || ($countactive==1)) {
  $r->print("<h2>".&mt('Select a Course to Enter')."</h2>\n");   $r->print("<h2>".&mt('Select a Course to Enter')."</h2>\n");
     }      }
Line 753  ENDHEADER Line 770  ENDHEADER
                       $env{'form.destsymb'}.'" />');                        $env{'form.destsymb'}.'" />');
         }          }
     }      }
   
     my $doheaders = &roletable_headers($r,\%roleclass,\%sortrole,$nochoose);      my $doheaders = &roletable_headers($r,\%roleclass,\%sortrole,$nochoose);
     if ($env{'environment.recentroles'}) {      if ($env{'environment.recentroles'}) {
         my %recent_roles =          my %recent_roles =
                &Apache::lonhtmlcommon::get_recent('roles',$env{'environment.recentrolesn'});                 &Apache::lonhtmlcommon::get_recent('roles',$env{'environment.recentrolesn'});
  my $output='';   my $output='';
  foreach (sort(keys(%recent_roles))) {   foreach my $role (sort(keys(%recent_roles))) {
     if (ref($roletext{'user.role.'.$_}) eq 'ARRAY') {      if (ref($roletext{'user.role.'.$role}) eq 'ARRAY') {
  $output.= &Apache::loncommon::start_data_table_row().   $output.= &Apache::loncommon::start_data_table_row().
                           $roletext{'user.role.'.$_}->[0].                            $roletext{'user.role.'.$role}->[0].
                           &Apache::loncommon::end_data_table_row().                            &Apache::loncommon::end_data_table_row().
                           &Apache::loncommon::continue_data_table_row().                            &Apache::loncommon::continue_data_table_row().
                           $roletext{'user.role.'.$_}->[1].                            $roletext{'user.role.'.$role}->[1].
                           &Apache::loncommon::end_data_table_row();                            &Apache::loncommon::end_data_table_row();
                 if ($_ =~ 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 ($numdc > 0) {      } elsif ($numdc > 0) {
                 unless ($_ =~/^error\:/) {                  unless ($role =~/^error\:/) {
                     $output.=&display_cc_role('user.role.'.$_);                      $output.=&display_cc_role('user.role.'.$_);
                 }                  }
             }               }
  }   }
  if ($output) {   if ($output) {
     $r->print(&Apache::loncommon::start_data_table_empty_row()      $r->print(&Apache::loncommon::start_data_table_empty_row()
Line 787  ENDHEADER Line 805  ENDHEADER
             $doheaders ++;              $doheaders ++;
  }   }
     }      }
   
     if ($numdc > 0) {  
         $r->print(&coursepick_jscript());  
         $r->print(&Apache::loncommon::coursebrowser_javascript().  
                   &Apache::loncommon::authorbrowser_javascript());  
     }  
     &print_rolerows($r,$doheaders,\%roleclass,\%sortrole,\%dcroles,\%roletext);      &print_rolerows($r,$doheaders,\%roleclass,\%sortrole,\%dcroles,\%roletext);
     if ($countactive > 1) {      if ($countactive > 1) {
         my $tremark='';          my $tremark='';
Line 836  ENDHEADER Line 848  ENDHEADER
                  .'</i><br />'                   .'</i><br />'
                  .'<a href="/adm/logout">'.&mt('Logout').'</a>&nbsp;&nbsp;'                   .'<a href="/adm/logout">'.&mt('Logout').'</a>&nbsp;&nbsp;'
                  .'<a href="/adm/coursecatalog?showdom='.$esc_dom.'">'                   .'<a href="/adm/coursecatalog?showdom='.$esc_dom.'">'
                  .&mt('Course Catalog')                   .&mt('Course/Community Catalog')
                  .'</a></small></p>');                   .'</a></small></p>');
     }      }
     $r->print(&Apache::loncommon::end_page());      $r->print(&Apache::loncommon::end_page());
Line 915  sub gather_roles { Line 927  sub gather_roles {
                     foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }                      foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
                     if (!$allowed) {                      if (!$allowed) {
                         $button=0;                          $button=0;
                         $switchserver='otherserver='.$home.'&role='.$trolecode;                          $switchserver='otherserver='.$home.'&amp;role='.$trolecode;
                     }                      }
                     #next if ($home eq 'no_host');                      #next if ($home eq 'no_host');
                     $home = &Apache::lonnet::hostname($home);                      $home = &Apache::lonnet::hostname($home);
Line 935  sub gather_roles { Line 947  sub gather_roles {
                     foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }                      foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
                     if (!$allowed) {                      if (!$allowed) {
                         $button=0;                          $button=0;
                         $switchserver='otherserver='.$home.'&role='.$trolecode;                          $switchserver='otherserver='.$home.'&amp;role='.$trolecode;
                     }                      }
                     #next if ($home eq 'no_host');                      #next if ($home eq 'no_host');
                     $home = &Apache::lonnet::hostname($home);                      $home = &Apache::lonnet::hostname($home);
Line 948  sub gather_roles { Line 960  sub gather_roles {
                 } elsif ($trest) {                  } elsif ($trest) {
                     my $tcourseid=$tdom.'_'.$trest;                      my $tcourseid=$tdom.'_'.$trest;
                     $ttype = &Apache::loncommon::course_type($tcourseid);                      $ttype = &Apache::loncommon::course_type($tcourseid);
                     $trole = &Apache::lonnet::plaintext($role,$ttype);                      $trole = &Apache::lonnet::plaintext($role,$ttype,$tcourseid);
                     if ($env{'course.'.$tcourseid.'.description'}) {                      if ($env{'course.'.$tcourseid.'.description'}) {
                         $twhere=$env{'course.'.$tcourseid.'.description'};                          $twhere=$env{'course.'.$tcourseid.'.description'};
                         $sortkey=$role."\0".$tdom."\0".$twhere."\0".$envkey;                          $sortkey=$role."\0".$tdom."\0".$twhere."\0".$envkey;
                           $twhere = &HTML::Entities::encode($twhere,'"<>&');
                         unless ($twhere eq &mt('Currently not available')) {                          unless ($twhere eq &mt('Currently not available')) {
                             $twhere.=' <span class="LC_fontsize_small">'.                              $twhere.=' <span class="LC_fontsize_small">'.
         &Apache::loncommon::syllabuswrapper(&mt('Syllabus'),$trest,$tdom).          &Apache::loncommon::syllabuswrapper(&mt('Syllabus'),$trest,$tdom).
Line 962  sub gather_roles { Line 975  sub gather_roles {
                         if (%newhash) {                          if (%newhash) {
                             $sortkey=$role."\0".$tdom."\0".$newhash{'description'}.                              $sortkey=$role."\0".$tdom."\0".$newhash{'description'}.
                                 "\0".$envkey;                                  "\0".$envkey;
                             $twhere=$newhash{'description'}.                              $twhere=&HTML::Entities::encode($newhash{'description'},'"<>&').
                               ' <span class="LC_fontsize_small">'.                                      ' <span class="LC_fontsize_small">'.
         &Apache::loncommon::syllabuswrapper(&mt('Syllabus'),$trest,$tdom).                                       &Apache::loncommon::syllabuswrapper(&mt('Syllabus'),$trest,$tdom).
                               '</span>';                                      '</span>';
                             $ttype = $newhash{'type'};                              $ttype = $newhash{'type'};
                             $trole = &Apache::lonnet::plaintext($role,$ttype);                              $trole = &Apache::lonnet::plaintext($role,$ttype,$tcourseid);
                         } else {                          } else {
                             $twhere=&mt('Currently not available');                              $twhere=&mt('Currently not available');
                             $env{'course.'.$tcourseid.'.description'}=$twhere;                              $env{'course.'.$tcourseid.'.description'}=$twhere;
Line 1083  sub roletable_headers { Line 1096  sub roletable_headers {
 }  }
   
 sub roletypes {  sub roletypes {
     my @types = ('Domain','Construction Space','Course','Unavailable','System');      my @types = ('Domain','Construction Space','Course','Community','Unavailable','System');
     return @types;       return @types; 
 }  }
   
Line 1145  sub findcourse_advice { Line 1158  sub findcourse_advice {
     } 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(&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('The [_1]Course Catalog[_2] provides information about all [_3] classes for which LON-CAPA courses have been created.','<a href="/adm/coursecatalog?showdom='.$esc_dom.'">','</a>',$domdesc).'<br />');      $r->print('<h3>'.&mt('Self-Enrollment').'</h3>'.
     $r->print(&mt('You can search the course catalog for courses which permit self-enrollment, if you would like to enroll in a course.').'</p>');                '<p>'.&mt('The [_1]Course/Community Catalog[_2] provides information about all [_3] classes for which LON-CAPA courses have been created, as well as any communities in the domain.','<a href="/adm/coursecatalog?showdom='.$esc_dom.'">','</a>',$domdesc).'<br />');
     &queued_selfenrollment($r);      $r->print(&mt('You can search for courses and communities which permit self-enrollment, if you would like to enroll in one.').'</p>'.
                 &Apache::loncoursequeueadmin::queued_selfenrollment());
     return;      return;
 }  }
   
 sub queued_selfenrollment {  sub requestcourse_advice {
     my ($r) = @_;      my ($r) = @_;
     my %selfenrollrequests = &Apache::lonnet::dump('selfenrollrequests');      my $domdesc = &Apache::lonnet::domain($env{'user.domain'},'description');
     my %reqs_by_date;      my $esc_dom = &HTML::Entities::encode($env{'user.domain'},'"<>&');
     foreach my $item (keys(%selfenrollrequests)) {      my (%can_request,%request_doms);
         if (ref($selfenrollrequests{$item}) eq 'HASH') {      &Apache::lonnet::check_can_request($env{'user.domain'},\%can_request,\%request_doms);
             if ($selfenrollrequests{$item}{'status'} eq 'request') {      if (keys(%request_doms) > 0) {
                 if ($selfenrollrequests{$item}{'timestamp'}) {          my ($types,$typename) = &Apache::loncommon::course_types();
                     push(@{$reqs_by_date{$selfenrollrequests{$item}{'timestamp'}}},$item);          if ((ref($types) eq 'ARRAY') && (ref($typename) eq 'HASH')) { 
                 }              $r->print('<h3>'.&mt('Request creation of a course or community').'</h3>'.
             }                         '<p>'.&mt('You have rights to request the creation of courses and/or communities in the following domain(s):').'<ul>');
         }              my (@reqdoms,@reqtypes);
     }              foreach my $type (sort(keys(%request_doms))) {
     if (keys(%reqs_by_date)) {                  push(@reqtypes,$type); 
         my $rolename = &Apache::lonnet::plaintext('st');                  if (ref($request_doms{$type}) eq 'ARRAY') {
         $r->print('<b>'.&mt('Enrollment requests pending Course Coordinator approval').'</b><br />'.                      my $domstr = join(', ',map { &Apache::lonnet::domain($_) } sort(@{$request_doms{$type}}));
                   &Apache::loncommon::start_data_table().                      $r->print(
                   &Apache::loncommon::start_data_table_header_row().                          '<li>'
                   '<th>'.&mt('Date requested').'</th><th>'.&mt('Course title').'</th>'.                         .&mt('[_1]'.$typename->{$type}.'[_2] in domain: [_3]',
                   '<th>'.&mt('User role').'</th><th>'.&mt('Section').'</th>'.                              '<i>',
                  &Apache::loncommon::end_data_table_header_row());                              '</i>',
         my @sorted = sort { $a <=> $b } (keys(%reqs_by_date));                              '<b>'.$domstr.'</b>')
         foreach my $item (@sorted) {                         .'</li>'
             if (ref($reqs_by_date{$item}) eq 'ARRAY') {                      );
                 foreach my $crs (@{$reqs_by_date{$item}}) {                      foreach my $dom (@{$request_doms{$type}}) {
                     my %courseinfo = &Apache::lonnet::coursedescription($crs);                          unless (grep(/^\Q$dom\E/,@reqdoms)) {
                     my $usec = $selfenrollrequests{$crs}{'section'};                              push(@reqdoms,$dom);
                     if ($usec eq '') {                          }
                         $usec = &mt('No section');   
                     }                      }
                     $r->print(&Apache::loncommon::start_data_table_row().  
                              '<td>'.&Apache::lonlocal::locallocaltime($item).'</td>'.  
                              '<td>'.$courseinfo{'description'}.'</td>'.  
                              '<td>'.$rolename.'</td><td>'.$usec.'</td>'.  
                              &Apache::loncommon::end_data_table_row());  
                 }                  }
             }              }
               my @showtypes;
               foreach my $type (@{$types}) {
                   if (grep(/^\Q$type\E$/,@reqtypes)) {
                       push(@showtypes,$type);
                   }
               }
               my $requrl = '/adm/requestcourse';
               if (@reqdoms == 1) {
                   $requrl .= '?showdom='.$reqdoms[0];
               }
               if (@showtypes > 0) {
                   $requrl.=(($requrl=~/\?/)?'&':'?').'crstype='.$showtypes[0];
               }
               if (@reqdoms == 1 || @showtypes > 0) {
                   $requrl .= '&state=crstype&action=new';
               } 
               $r->print('</ul>'.&mt('Use the [_1]request form[_2] to submit a request for creation of a new course or community.','<a href="'.$requrl.'">','</a>').'</p>');
         }          }
         $r->print(&Apache::loncommon::end_data_table());  
     }      }
     return;      return;
 }  }
Line 1372  sub check_fordc { Line 1396  sub check_fordc {
 }  }
   
 sub adhoc_course_role {  sub adhoc_course_role {
     my ($then) = @_;       my ($refresh,$then) = @_;
     my ($cdom,$cnum);      my ($cdom,$cnum,$crstype);
     $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};      $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
     $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};      $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
     if (&check_forcc($cdom,$cnum,$then)) {      $crstype = &Apache::loncommon::course_type();
       if (&check_forcc($cdom,$cnum,$refresh,$then,$crstype)) {
         my $setprivs;          my $setprivs;
         if (!defined($env{'user.role.'.$env{'form.switchrole'}})) {          if (!defined($env{'user.role.'.$env{'form.switchrole'}})) {
             $setprivs = 1;              $setprivs = 1;
         } else {          } else {
             my ($start,$end) = split(/\./,$env{'user.role.'.$env{'form.switchrole'}});              my ($start,$end) = split(/\./,$env{'user.role.'.$env{'form.switchrole'}});
             if (($start && ($start>$then || $start == -1)) ||              if (($start && ($start>$refresh || $start == -1)) ||
                 ($end && $end<$then)) {                  ($end && $end<$then)) {
                 $setprivs = 1;                  $setprivs = 1;
             }              }
         }           }
         if ($setprivs) {          if ($setprivs) {
             if ($env{'form.switchrole'} =~ m-^(in|ta|ep|ad|st|cr)([\w/]*)\./\Q$cdom\E/\Q$cnum\E/?(\w*)$-) {              if ($env{'form.switchrole'} =~ m-^(in|ta|ep|ad|st|cr)([\w/]*)\./\Q$cdom\E/\Q$cnum\E/?(\w*)$-) {
                 my $role = $1;                  my $role = $1;
Line 1416  sub adhoc_course_role { Line 1441  sub adhoc_course_role {
                 }                  }
                 &Apache::lonnet::standard_roleprivs(\%newrole,$role,$cdom,$spec,$cnum,$area);                  &Apache::lonnet::standard_roleprivs(\%newrole,$role,$cdom,$spec,$cnum,$area);
                 &Apache::lonnet::set_userprivs(\%userroles,\%newrole,\%newgroups);                  &Apache::lonnet::set_userprivs(\%userroles,\%newrole,\%newgroups);
                 my $adhocstart = $then-1;                  my $adhocstart = $refresh-1;
                 $userroles{'user.role.'.$spec} = $adhocstart.'.';                  $userroles{'user.role.'.$spec} = $adhocstart.'.';
                 &Apache::lonnet::appenv(\%userroles,[$role,'cm']);                  &Apache::lonnet::appenv(\%userroles,[$role,'cm']);
             }              }
Line 1426  sub adhoc_course_role { Line 1451  sub adhoc_course_role {
 }  }
   
 sub check_forcc {  sub check_forcc {
     my ($cdom,$cnum,$then) = @_;      my ($cdom,$cnum,$refresh,$then,$crstype) = @_;
     my $is_cc;      my ($is_cc,$ccrole);
       if ($crstype eq 'Community') {
           $ccrole = 'co';
       } else {
           $ccrole = 'cc';
       }
     if ($cdom ne '' && $cnum ne '') {      if ($cdom ne '' && $cnum ne '') {
         if (&Apache::lonnet::is_course($cdom,$cnum)) {          if (&Apache::lonnet::is_course($cdom,$cnum)) {
             my $envkey = 'user.role.cc./'.$cdom.'/'.$cnum;              my $envkey = 'user.role.'.$ccrole.'./'.$cdom.'/'.$cnum;
             if (defined($env{$envkey})) {              if (defined($env{$envkey})) {
                 $is_cc = 1;                  $is_cc = 1;
                 my ($tstart,$tend)=split(/\./,$env{$envkey});                  my ($tstart,$tend)=split(/\./,$env{$envkey});
                 if ($tstart && $tstart>$then) { $is_cc = 0; }                  if ($tstart && $tstart>$refresh) { $is_cc = 0; }
                 if ($tend   && $tend  <$then) { $is_cc = 0; }                  if ($tend   && $tend  <$then) { $is_cc = 0; }
             }              }
         }          }
Line 1447  sub courselink { Line 1477  sub courselink {
     my $courseform=&Apache::loncommon::selectcourse_link      my $courseform=&Apache::loncommon::selectcourse_link
                    ('rolechoice','dccourse'.$rowtype.'_'.$dcdom,                     ('rolechoice','dccourse'.$rowtype.'_'.$dcdom,
                     'dcdomain'.$rowtype.'_'.$dcdom,'coursedesc'.$rowtype.'_'.                      'dcdomain'.$rowtype.'_'.$dcdom,'coursedesc'.$rowtype.'_'.
                     $dcdom,$dcdom,undef);                      $dcdom,$dcdom,undef,'Course/Community');
     my $hiddenitems = '<input type="hidden" name="dcdomain'.$rowtype.'_'.$dcdom.'" value="'.$dcdom.'" />'.      my $hiddenitems = '<input type="hidden" name="dcdomain'.$rowtype.'_'.$dcdom.'" value="'.$dcdom.'" />'.
                       '<input type="hidden" name="origdom'.$rowtype.'_'.$dcdom.'" value="'.$dcdom.'" />'.                        '<input type="hidden" name="origdom'.$rowtype.'_'.$dcdom.'" value="'.$dcdom.'" />'.
                       '<input type="hidden" name="dccourse'.$rowtype.'_'.$dcdom.'" value="" />'.                        '<input type="hidden" name="dccourse'.$rowtype.'_'.$dcdom.'" value="" />'.
Line 1457  sub courselink { Line 1487  sub courselink {
   
 sub coursepick_jscript {  sub coursepick_jscript {
     my %lt = &Apache::lonlocal::texthash(      my %lt = &Apache::lonlocal::texthash(
                   plsu => "Please use the 'Select Course' link to open a separate pick course window where you may select the course 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 in the current domain.',                    youc => 'You can only use this screen to select courses and communities in the current domain.',
              );               );
     my $verify_script = <<"END";      my $verify_script = <<"END";
 <script type="text/javascript">  <script type="text/javascript">
Line 1510  sub display_cc_role { Line 1540  sub display_cc_role {
     my $advanced = $env{'user.adv'};      my $advanced = $env{'user.adv'};
     my $tryagain = $env{'form.tryagain'};      my $tryagain = $env{'form.tryagain'};
     unless ($rolekey =~/^error\:/) {      unless ($rolekey =~/^error\:/) {
         if ($rolekey =~ m-^user\.role.cc\./($match_domain)/($match_courseid)$-) {          if ($rolekey =~ m{^user\.role\.(cc|co)\./($match_domain)/($match_courseid)$}) {
             my $tcourseid = $1.'_'.$2;              my $ccrole = $1;
             my $trolecode = 'cc./'.$1.'/'.$2;              my $tcourseid = $2.'_'.$3;
               my $trolecode = $1.'./'.$2.'/'.$3;
             my $twhere;              my $twhere;
             my $ttype;              my $ttype;
             my $tbg='LC_roles_is';              my $tbg='LC_roles_is';
Line 1527  sub display_cc_role { Line 1558  sub display_cc_role {
                 $twhere=&mt('Currently not available');                  $twhere=&mt('Currently not available');
                 $env{'course.'.$tcourseid.'.description'}=$twhere;                  $env{'course.'.$tcourseid.'.description'}=$twhere;
             }              }
             my $trole = &Apache::lonnet::plaintext('cc',$ttype);              my $trole = &Apache::lonnet::plaintext($ccrole,$ttype,$tcourseid);
             $twhere.="<br />".&mt('Domain').":".$1;              $twhere.="<br />".&mt('Domain').":".$1;
             ($roletext,$roletext_end) = &build_roletext($trolecode,$1,$2,'is',$tryagain,$advanced,'',$tbg,$trole,$twhere,'','','',1,'');              ($roletext,$roletext_end) = &build_roletext($trolecode,$1,$2,'is',$tryagain,$advanced,'',$tbg,$trole,$twhere,'','','',1,'');
         }          }
Line 1543  sub adhoc_roles_row { Line 1574  sub adhoc_roles_row {
                      ,'<span class="LC_cusr_emph">','</span>',$dcdom)                       ,'<span class="LC_cusr_emph">','</span>',$dcdom)
                  .' ';                   .' ';
     my $selectcclink = &courselink($dcdom,$rowtype);      my $selectcclink = &courselink($dcdom,$rowtype);
     my $ccrole = &Apache::lonnet::plaintext('cc');      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);
     $output.=$ccrole.': '.$selectcclink      $output.=$ccrole.': '.$selectcclink
Line 1605  course they should act on, etc. Both in Line 1636  course they should act on, etc. Both in
 handler determines via C<lonnet>'s C<&allowed> function that a certain  handler determines via C<lonnet>'s C<&allowed> function that a certain
 action is not allowed, C<lonroles> is used as error handler. This  action is not allowed, C<lonroles> is used as error handler. This
 allows the user to select another role which may have permission to do  allows the user to select another role which may have permission to do
 what they were trying to do. C<lonroles> can also be accessed via the  what they were trying to do.
 B<CRS> button in the Remote Control.   
   
 =begin latex  =begin latex
   

Removed from v.1.231.4.2  
changed lines
  Added in v.1.248


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