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

version 1.207, 2008/10/02 14:34:03 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 483  ENDHEADER Line 580  ENDHEADER
     my $advanced=$env{'user.adv'};      my $advanced=$env{'user.adv'};
     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['tryagain']);      &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['tryagain']);
     my $tryagain=$env{'form.tryagain'};      my $tryagain=$env{'form.tryagain'};
       my $reinit=$env{'user.reinit'};
       delete $env{'user.reinit'};
   
 # -------------------------------------------------------- Generate Page Output  # -------------------------------------------------------- Generate Page Output
 # --------------------------------------------------------------- Error Header?  # --------------------------------------------------------------- Error Header?
Line 512  ENDHEADER Line 611  ENDHEADER
  &Apache::lonenc::check_encrypt($fn));   &Apache::lonenc::check_encrypt($fn));
     } else {      } else {
         if ($env{'user.error.msg'}) {          if ($env{'user.error.msg'}) {
     $r->print(              if ($reinit) {
                   $r->print(
    '<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>');
               } else {
           $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 for this function').'</span></h3>');
  }      }
           }
     }      }
 # -------------------------------------------------------- Choice or no choice?  # -------------------------------------------------------- Choice or no choice?
     if ($nochoose) {      if ($nochoose) {
Line 654  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 664  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 689  ENDHEADER Line 794  ENDHEADER
                     $twhere=&mt('system wide');                      $twhere=&mt('system wide');
     $sortkey=$role.$twhere;      $sortkey=$role.$twhere;
                 }                  }
                 $roletext.=&build_roletext($trolecode,$tdom,$trest,$tstatus,$tryagain,$advanced,$tremark,$tbg,$tfont,$trole,$twhere,$tpstart,$tpend,$nochoose,$button,$switchserver);                  $roletext.=&build_roletext($trolecode,$tdom,$trest,$tstatus,$tryagain,$advanced,$tremark,$tbg,$tfont,$trole,$twhere,$tpstart,$tpend,$nochoose,$button,$switchserver,$reinit);
  $roletext{$envkey}=$roletext;   $roletext{$envkey}=$roletext;
  if (!$sortkey) {$sortkey=$twhere."\0".$envkey;}   if (!$sortkey) {$sortkey=$twhere."\0".$envkey;}
  $sortrole{$sortkey}=$envkey;   $sortrole{$sortkey}=$envkey;
Line 734  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 766  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 797  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 877  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 988  sub role_status { Line 1093  sub role_status {
 }  }
   
 sub build_roletext {  sub build_roletext {
     my ($trolecode,$tdom,$trest,$tstatus,$tryagain,$advanced,$tremark,$tbg,$tfont,$trole,$twhere,$tpstart,$tpend,$nochoose,$button,$switchserver) = @_;      my ($trolecode,$tdom,$trest,$tstatus,$tryagain,$advanced,$tremark,$tbg,$tfont,$trole,$twhere,$tpstart,$tpend,$nochoose,$button,$switchserver,$reinit) = @_;
     my $roletext='<tr bgcolor="'.$tbg.'" class="LC_rolesmenu_'.$tstatus.'">';      my $roletext='<tr bgcolor="'.$tbg.'" class="LC_rolesmenu_'.$tstatus.'">';
     my $is_dc=($trolecode =~ m/^dc\./);      my $is_dc=($trolecode =~ m/^dc\./);
     my $rowspan=($is_dc) ? ''      my $rowspan=($is_dc) ? ''
Line 1018  sub build_roletext { Line 1123  sub build_roletext {
                 '<td'.$rowspan.'><input name="'.$buttonname.'" type="button" value="'.                  '<td'.$rowspan.'><input name="'.$buttonname.'" type="button" value="'.
                 &mt('Re-Initialize').'" onClick="javascript:enterrole(this.form,\''.                  &mt('Re-Initialize').'" onClick="javascript:enterrole(this.form,\''.
                         $trolecode."','".$buttonname.'\');" /></td>';                          $trolecode."','".$buttonname.'\');" /></td>';
           } elsif ($reinit) {
               $roletext.= 
                   '<td'.$rowspan.'><input name="'.$buttonname.'" type="button" value="'.
                   &mt('Re-Select').'" onClick="javascript:enterrole(this.form,\''.
                           $trolecode."','".$buttonname.'\');" /></td>';
         } else {          } else {
             $roletext.='<td'.$rowspan.'>&nbsp;</td>';              $roletext.=
                   '<td'.$rowspan.'><input name="'.$buttonname.'" type="button" value="'.
                   &mt('Re-Initialize').'" onClick="javascript:enterrole(this.form,\''.
                           $trolecode."','".$buttonname.'\');" /></td>';
         }          }
     }      }
     if ($trolecode !~ m/^(dc|ca|au|aa)\./) {      if ($trolecode !~ m/^(dc|ca|au|aa)\./) {
  $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 1136  sub adhoc_course_role { Line 1249  sub adhoc_course_role {
                         return;                          return;
                     }                      }
                 }                  }
                 my (%userroles,%newrole,%newgroups);                  my (%userroles,%newrole,%newgroups,%group_privs);
                   my %cgroups =
                       &Apache::lonnet::get_active_groups($env{'user.domain'},
                                               $env{'user.name'},$cdom,$cnum);
                   foreach my $group (keys(%cgroups)) {
                       $group_privs{$group} =
                           $env{'user.priv.cc./'.$cdom.'/'.$cnum.'./'.$cdom.'/'.$cnum.'/'.$group};
                   }
                   $newgroups{'/'.$cdom.'/'.$cnum} = \%group_privs;
                 my $area = '/'.$cdom.'/'.$cnum;                  my $area = '/'.$cdom.'/'.$cnum;
                 my $spec = $role.'.'.$area;                  my $spec = $role.'.'.$area;
                 if ($usec ne '') {                  if ($usec ne '') {
Line 1144  sub adhoc_course_role { Line 1265  sub adhoc_course_role {
                     $area .= '/'.$usec;                      $area .= '/'.$usec;
                 }                  }
                 &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 = $then-1;
                 $userroles{'user.role.'.$spec} = $adhocstart.'.';                  $userroles{'user.role.'.$spec} = $adhocstart.'.';
                 &Apache::lonnet::appenv(\%userroles,[$role,'cm']);                  &Apache::lonnet::appenv(\%userroles,[$role,'cm']);
Line 1247  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.207  
changed lines
  Added in v.1.211


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