Diff for /loncom/auth/lonroles.pm between versions 1.209.2.1 and 1.211

version 1.209.2.1, 2009/01/05 16:50:02 version 1.211, 2008/12/04 08:53:04
Line 27 Line 27
 #  #
 ###  ###
   
   =pod
   
   =head1 NAME
   
   Apache::lonroles - User Roles Screen
   
   =head1 SYNOPSIS
   
   Invoked by /etc/httpd/conf/srm.conf:
   
    <Location /adm/roles>
    PerlAccessHandler       Apache::lonacc
    SetHandler perl-script
    PerlHandler Apache::lonroles
    ErrorDocument     403 /adm/login
    ErrorDocument  500 /adm/errorhandler
    </Location>
   
   =head1 OVERVIEW
   
   =head2 Choosing Roles
   
   C<lonroles> is a handler that allows a user to switch roles in
   mid-session. LON-CAPA attempts to work with "No Role Specified", the
   default role that a user has before selecting a role, as widely as
   possible, but certain handlers for example need specification which
   course they should act on, etc. Both in this scenario, and when the
   handler determines via C<lonnet>'s C<&allowed> function that a certain
   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
   what they were trying to do. C<lonroles> can also be accessed via the
   B<CRS> button in the Remote Control. 
   
   =begin latex
   
   \begin{figure}
   \begin{center}
   \includegraphics[width=0.45\paperwidth,keepaspectratio]{Sample_Roles_Screen}
     \caption{\label{Sample_Roles_Screen}Sample Roles Screen} 
   \end{center}
   \end{figure}
   
   =end latex
   
   =head2 Role Initialization
   
   The privileges for a user are established at login time and stored in the session environment. As a consequence, a new role does not become active till the next login. Handlers are able to query for privileges using C<lonnet>'s C<&allowed> function. When a user first logs in, their role is the "common" role, which means that they have the sum of all of their privileges. During a session it might become necessary to choose a particular role, which as a consequence also limits the user to only the privileges in that particular role.
   
   =head1 INTRODUCTION
   
   This module enables a user to select what role he wishes to
   operate under (instructor, student, teaching assistant, course
   coordinator, etc).  These roles are pre-established by the actions
   of upper-level users.
   
   This is part of the LearningOnline Network with CAPA project
   described at http://www.lon-capa.org.
   
   =head1 HANDLER SUBROUTINE
   
   This routine is called by Apache and mod_perl.
   
   =over 4
   
   =item *
   
   Roles Initialization (yes/no)
   
   =item *
   
   Get Error Message from Environment
   
   =item *
   
   Who is this?
   
   =item *
   
   Generate Page Output
   
   =item *
   
   Choice or no choice
   
   =item *
   
   Table
   
   =item *
   
   Privileges
   
   =back
   
   =cut
   
   
 package Apache::lonroles;  package Apache::lonroles;
   
 use strict;  use strict;
Line 272  $swinfo Line 369  $swinfo
 <form method="post">  <form method="post">
 <input type="hidden" name="selectrole" value="1" />  <input type="hidden" name="selectrole" value="1" />
 <input type="hidden" name="$trolecode" value="1" />  <input type="hidden" name="$trolecode" value="1" />
 <font size="+2">$message</font><br />  <span class="LC_fontsize_large">$message</span><br />
 <input type="submit" value="$buttontext" />  <input type="submit" value="$buttontext" />
 </form>  </form>
 $end_page  $end_page
Line 548  ENDHEADER Line 645  ENDHEADER
     my $possiblerole='';      my $possiblerole='';
     my %futureroles;      my %futureroles;
     my %roles_nextlogin;      my %roles_nextlogin;
     my %timezones;  
     foreach $envkey (sort keys %env) {      foreach $envkey (sort keys %env) {
         my $button = 1;          my $button = 1;
         my $switchserver='';          my $switchserver='';
Line 558  ENDHEADER Line 654  ENDHEADER
             my ($role,$where,$trolecode,$tstart,$tend,$tremark,$tstatus,$tpstart,$tpend,$tfont);              my ($role,$where,$trolecode,$tstart,$tend,$tremark,$tstatus,$tpstart,$tpend,$tfont);
             &role_status($envkey,$then,$now,\$role,\$where,\$trolecode,\$tstatus,\$tstart,\$tend);              &role_status($envkey,$then,$now,\$role,\$where,\$trolecode,\$tstatus,\$tstart,\$tend);
             next if (!defined($role) || $role eq '' || $role =~ /^gr/);              next if (!defined($role) || $role eq '' || $role =~ /^gr/);
             my $timezone = &role_timezone($where,\%timezones);  
             $tremark='';              $tremark='';
             $tpstart='&nbsp;';              $tpstart='&nbsp;';
             $tpend='&nbsp;';              $tpend='&nbsp;';
             $tfont='#000000';              $tfont='#000000';
             if ($tstart) {              if ($tstart) {
                 $tpstart=&Apache::lonlocal::locallocaltime($tstart,$timezone);                  $tpstart=&Apache::lonlocal::locallocaltime($tstart);
             }              }
             if ($tend) {              if ($tend) {
                 $tpend=&Apache::lonlocal::locallocaltime($tend,$timezone);                  $tpend=&Apache::lonlocal::locallocaltime($tend);
             }              }
             if ($env{'request.role'} eq $trolecode) {              if ($env{'request.role'} eq $trolecode) {
  $tstatus='selected';   $tstatus='selected';
Line 664  ENDHEADER Line 759  ENDHEADER
                         $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;
                         unless ($twhere eq &mt('Currently not available')) {                          unless ($twhere eq &mt('Currently not available')) {
     $twhere.=' <font size="-2">'.      $twhere.=' <span class="LC_fontsize_small">'.
         &Apache::loncommon::syllabuswrapper(&mt('Syllabus'),$trest,$tdom,$tfont).          &Apache::loncommon::syllabuswrapper(&mt('Syllabus'),$trest,$tdom,$tfont).
                                     '</font>';                                      '</span>';
  }   }
                     } else {                      } else {
                         my %newhash=&Apache::lonnet::coursedescription($tcourseid);                          my %newhash=&Apache::lonnet::coursedescription($tcourseid);
Line 674  ENDHEADER Line 769  ENDHEADER
     $sortkey=$role."\0".$tdom."\0".$newhash{'description'}.      $sortkey=$role."\0".$tdom."\0".$newhash{'description'}.
  "\0".$envkey;   "\0".$envkey;
                             $twhere=$newhash{'description'}.                              $twhere=$newhash{'description'}.
                               ' <font size="-2">'.                                ' <span class="LC_fontsize_small">'.
         &Apache::loncommon::syllabuswrapper(&mt('Syllabus'),$trest,$tdom,$tfont).          &Apache::loncommon::syllabuswrapper(&mt('Syllabus'),$trest,$tdom,$tfont).
                               '</font>';                                '</span>';
                             $ttype = $newhash{'type'};                              $ttype = $newhash{'type'};
                             $trole = &Apache::lonnet::plaintext($role,$ttype);                              $trole = &Apache::lonnet::plaintext($role,$ttype);
                         } else {                          } else {
Line 744  ENDHEADER Line 839  ENDHEADER
             } else {              } else {
                 $r->print('<tr bgcolor="#77FF77">');                  $r->print('<tr bgcolor="#77FF77">');
             }              }
             $r->print('<td></td><td colspan="3"><font color="'.$tfont.'"><span class="LC_rolesinfo">'.&mt('No role specified').              $r->print('<td></td><td colspan="3"><span style="color:'.$tfont.';"><span class="LC_rolesinfo">'.&mt('No role specified').
                       '</span></font></td><td><font color="'.$tfont.'">'.$tremark.                        '</span></font></td><td><span style="color:'.$tfont.';">'.$tremark.
                       '&nbsp;</font></td></tr>'."\n");                        '&nbsp;</font></td></tr>'."\n");
   
             $r->print('</table>');              $r->print('</table>');
Line 776  ENDHEADER Line 871  ENDHEADER
             }               } 
  }   }
  if ($output) {   if ($output) {
     $r->print("<tr><td align='center' colspan='5'><font face='arial'>".      $r->print("<tr><td align='center' colspan='5'>".
       &mt('Recent Roles')."</font></td></tr>");        &mt('Recent Roles')."</td></tr>");
     $r->print($output);      $r->print($output);
             $doheaders ++;              $doheaders ++;
  }   }
Line 807  ENDHEADER Line 902  ENDHEADER
         $r->print('<td>&nbsp;</td>');          $r->print('<td>&nbsp;</td>');
     }      }
         }          }
         $r->print('<td colspan="3"><font color="'.$tfont.'"><span class="LC_rolesinfo">'.&mt('No role specified').          $r->print('<td colspan="3"><span style="color:'.$tfont.';"><span class="LC_rolesinfo">'.&mt('No role specified').
                   '</span></font></td><td><font color="'.$tfont.'">'.$tremark.                    '</span></span></td><td><span style="color:'.$tfont.';">'.$tremark.
                   '&nbsp;</font></td></tr>'."\n");                    '&nbsp;</span></td></tr>'."\n");
     }       } 
     $r->print('</table>');      $r->print('</table>');
     unless ($nochoose) {      unless ($nochoose) {
Line 835  ENDHEADER Line 930  ENDHEADER
     return OK;      return OK;
 }  }
   
 sub role_timezone {  
     my ($where,$timezones) = @_;  
     my $timezone;  
     if (ref($timezones) eq 'HASH') {  
         if ($where =~ m{^/($match_domain)/($match_courseid)}) {  
             my $cdom = $1;  
             my $cnum = $2;  
             if ($cdom && $cnum) {  
                 if (!exists($timezones->{$cdom.'_'.$cnum})) {  
                     my %timehash =  
                         &Apache::lonnet::get('environment',['timezone'],$cdom,$cnum);  
                     if ($timehash{'timezone'} eq '') {  
                         if (!exists($timezones->{$cdom})) {  
                             my %domdefaults =  
                                 &Apache::lonnet::get_domain_defaults($cdom);  
                             if ($domdefaults{'timezone_def'} eq '') {  
                                 $timezones->{$cdom} = 'local';  
                             } else {  
                                 $timezones->{$cdom} = $domdefaults{'timezone_def'};  
                             }  
                         }  
                         $timezones->{$cdom.'_'.$cnum} = $timezones->{$cdom};  
                     } else {  
                         $timezones->{$cdom.'_'.$cnum} =  
                             &Apache::lonlocal::gettimezone($timehash{'timezone'});  
                     }  
                 }  
                 $timezone = $timezones->{$cdom.'_'.$cnum};  
             }  
         } else {  
             my ($tdom) = ($where =~ m{^/($match_domain)});  
             if ($tdom) {  
                 if (!exists($timezones->{$tdom})) {  
                     my %domdefaults = &Apache::lonnet::get_domain_defaults($tdom);  
                     if ($domdefaults{'timezone_def'} eq '') {  
                         $timezones->{$tdom} = 'local';  
                     } else {  
                         $timezones->{$tdom} = $domdefaults{'timezone_def'};  
                     }  
                 }  
                 $timezone = $timezones->{$tdom};  
             }  
         }  
         if ($timezone eq 'local') {  
             $timezone = undef;  
         }  
     }  
     return $timezone;  
 }  
   
 sub roletable_headers {  sub roletable_headers {
     my ($r,$roleclass,$sortrole,$nochoose) = @_;      my ($r,$roleclass,$sortrole,$nochoose) = @_;
     my $doheaders;      my $doheaders;
Line 937  sub print_rolerows { Line 982  sub print_rolerows {
             if ($output) {              if ($output) {
                 if ($doheaders > 0) {                  if ($doheaders > 0) {
                     $r->print("<tr>".                      $r->print("<tr>".
                               "<td align='center' colspan='5'><font face='arial'>".                                "<td align='center' colspan='5'>".
                               &mt($type)."</font></td></tr>");                                &mt($type)."</td></tr>");
                 }                  }
                 $r->print($output);                  $r->print($output);
             }              }
Line 1094  sub build_roletext { Line 1139  sub build_roletext {
  $tremark.=&Apache::lonannounce::showday(time,1,   $tremark.=&Apache::lonannounce::showday(time,1,
  &Apache::lonannounce::readcalendar($tdom.'_'.$trest));   &Apache::lonannounce::readcalendar($tdom.'_'.$trest));
     }      }
     $roletext.='<td><font color="'.$tfont.'">'.$trole.      $roletext.='<td><span style="color:'.$tfont.';">'.$trole.
        '</font></td><td><font color="'.$tfont.'">'.$twhere.         '</span></td><td><span style="color:'.$tfont.';">'.$twhere.
                '</font></td><td><font color="'.$tfont.'">'.$tpstart.                 '</span></td><td><span style="color:'.$tfont.';">'.$tpstart.
                '</font></td><td><font color="'.$tfont.'">'.$tpend.                 '</span></td><td><span style="color:'.$tfont.';">'.$tpend.
                '</font></td></tr>';                 '</span></td></tr>';
     if (!$is_dc) {      if (!$is_dc) {
  $roletext.='<tr bgcolor="'.$tbg.'"><td colspan="4"><font color="'.$tfont.'"><span class="LC_rolesinfo">'.$tremark.   $roletext.='<tr bgcolor="'.$tbg.'"><td colspan="4"><span style="color:'.$tfont.';"><span class="LC_rolesinfo">'.$tremark.
     '</span>&nbsp;</font></td></tr><tr><td colspan="5" height="3"></td></tr>'."\n";      '</span>&nbsp;</span></td></tr><tr><td colspan="5" height="3"></td></tr>'."\n";
     }      }
     return $roletext;      return $roletext;
 }  }
Line 1323  sub display_cc_role { Line 1368  sub display_cc_role {
             my %newhash=&Apache::lonnet::coursedescription($tcourseid);              my %newhash=&Apache::lonnet::coursedescription($tcourseid);
             if (%newhash) {              if (%newhash) {
                 $twhere=$newhash{'description'}.                  $twhere=$newhash{'description'}.
                         ' <font size="-2">'.                          ' <span style="LC_fontsize_small">'.
                         &Apache::loncommon::syllabuswrapper(&mt('Syllabus'),$2,$1,$tfont).                          &Apache::loncommon::syllabuswrapper(&mt('Syllabus'),$2,$1,$tfont).
                         '</font>';                          '</span>';
                 $ttype = $newhash{'type'};                  $ttype = $newhash{'type'};
             } else {              } else {
                 $twhere=&mt('Currently not available');                  $twhere=&mt('Currently not available');

Removed from v.1.209.2.1  
changed lines
  Added in v.1.211


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