Annotation of loncom/auth/lonroles.pm, revision 1.228
1.1 harris41 1: # The LearningOnline Network with CAPA
2: # User Roles Screen
1.31 www 3: #
1.228 ! bisitz 4: # $Id: lonroles.pm,v 1.227 2009/06/12 09:19:21 bisitz Exp $
1.31 www 5: #
6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23: #
24: # /home/httpd/html/adm/gpl.txt
25: #
26: # http://www.lon-capa.org/
27: #
1.32 harris41 28: ###
1.22 harris41 29:
1.210 jms 30: =pod
31:
32: =head1 NAME
33:
34: Apache::lonroles - User Roles Screen
35:
36: =head1 SYNOPSIS
37:
38: Invoked by /etc/httpd/conf/srm.conf:
39:
40: <Location /adm/roles>
41: PerlAccessHandler Apache::lonacc
42: SetHandler perl-script
43: PerlHandler Apache::lonroles
44: ErrorDocument 403 /adm/login
45: ErrorDocument 500 /adm/errorhandler
46: </Location>
47:
48: =head1 OVERVIEW
49:
50: =head2 Choosing Roles
51:
52: C<lonroles> is a handler that allows a user to switch roles in
53: mid-session. LON-CAPA attempts to work with "No Role Specified", the
54: default role that a user has before selecting a role, as widely as
55: possible, but certain handlers for example need specification which
56: course they should act on, etc. Both in this scenario, and when the
57: handler determines via C<lonnet>'s C<&allowed> function that a certain
58: action is not allowed, C<lonroles> is used as error handler. This
59: allows the user to select another role which may have permission to do
60: what they were trying to do. C<lonroles> can also be accessed via the
61: B<CRS> button in the Remote Control.
62:
63: =begin latex
64:
65: \begin{figure}
66: \begin{center}
67: \includegraphics[width=0.45\paperwidth,keepaspectratio]{Sample_Roles_Screen}
68: \caption{\label{Sample_Roles_Screen}Sample Roles Screen}
69: \end{center}
70: \end{figure}
71:
72: =end latex
73:
74: =head2 Role Initialization
75:
76: 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.
77:
78: =head1 INTRODUCTION
79:
80: This module enables a user to select what role he wishes to
81: operate under (instructor, student, teaching assistant, course
82: coordinator, etc). These roles are pre-established by the actions
83: of upper-level users.
84:
85: This is part of the LearningOnline Network with CAPA project
86: described at http://www.lon-capa.org.
87:
88: =head1 HANDLER SUBROUTINE
89:
90: This routine is called by Apache and mod_perl.
91:
92: =over 4
93:
94: =item *
95:
96: Roles Initialization (yes/no)
97:
98: =item *
99:
100: Get Error Message from Environment
101:
102: =item *
103:
104: Who is this?
105:
106: =item *
107:
108: Generate Page Output
109:
110: =item *
111:
112: Choice or no choice
113:
114: =item *
115:
116: Table
117:
118: =item *
119:
120: Privileges
121:
122: =back
123:
124: =cut
125:
126:
1.1 harris41 127: package Apache::lonroles;
128:
129: use strict;
1.118 albertel 130: use Apache::lonnet;
1.7 www 131: use Apache::lonuserstate();
1.1 harris41 132: use Apache::Constants qw(:common);
1.2 www 133: use Apache::File();
1.26 www 134: use Apache::lonmenu;
1.29 albertel 135: use Apache::loncommon;
1.104 raeburn 136: use Apache::lonhtmlcommon;
1.57 www 137: use Apache::lonannounce;
1.72 www 138: use Apache::lonlocal;
1.151 www 139: use Apache::lonpageflip();
1.167 albertel 140: use Apache::lonnavdisplay();
1.120 albertel 141: use GDBM_File;
1.170 albertel 142: use LONCAPA qw(:DEFAULT :match);
1.201 raeburn 143: use HTML::Entities;
1.149 www 144:
1.1 harris41 145:
1.62 matthew 146: sub redirect_user {
1.95 albertel 147: my ($r,$title,$url,$msg,$launch_nav) = @_;
1.62 matthew 148: $msg = $title if (! defined($msg));
1.73 www 149: &Apache::loncommon::content_type($r,'text/html');
1.62 matthew 150: &Apache::loncommon::no_cache($r);
151: $r->send_http_header;
152: my $swinfo=&Apache::lonmenu::rawconfig();
1.96 albertel 153: my $navwindow;
1.95 albertel 154: if ($launch_nav eq 'on') {
1.166 albertel 155: $navwindow.=&Apache::lonnavdisplay::launch_win('now',undef,undef,
156: ($url =~ m-^/adm/whatsnew-));
1.96 albertel 157: } else {
158: $navwindow.=&Apache::lonnavmaps::close();
1.95 albertel 159: }
1.228 ! bisitz 160:
! 161: # Breadcrumbs
! 162: my $brcrum = [{'href' => $url,
! 163: 'text' => 'Switching Role'},];
1.147 albertel 164: my $start_page = &Apache::loncommon::start_page('Switching Role',undef,
1.228 ! bisitz 165: {'redirect' => [1,$url],
! 166: 'bread_crumbs' => $brcrum,});
1.147 albertel 167: my $end_page = &Apache::loncommon::end_page();
168:
1.92 www 169: # Note to style police:
170: # This must only replace the spaces, nothing else, or it bombs elsewhere.
171: $url=~s/ /\%20/g;
1.93 albertel 172: $r->print(<<ENDREDIR);
1.147 albertel 173: $start_page
1.96 albertel 174: <script type="text/javascript">
1.225 bisitz 175: // <![CDATA[
1.62 matthew 176: $swinfo
1.225 bisitz 177: // ]]>
1.62 matthew 178: </script>
1.96 albertel 179: $navwindow
1.222 bisitz 180: <p>$msg</p>
1.147 albertel 181: $end_page
1.62 matthew 182: ENDREDIR
183: return;
184: }
185:
1.150 www 186: sub error_page {
187: my ($r,$error,$dest)=@_;
188: &Apache::loncommon::content_type($r,'text/html');
189: &Apache::loncommon::no_cache($r);
190: $r->send_http_header;
191: return OK if $r->header_only;
1.228 ! bisitz 192: # Breadcrumbs
! 193: my $brcrum = [{'href' => $dest,
! 194: 'text' => 'Problems during Course Initialization'},];
! 195: $r->print(&Apache::loncommon::start_page('Problems during Course Initialization',
! 196: undef,
! 197: {'bread_crumbs' => $brcrum,})
! 198: );
! 199: $r->print(
1.225 bisitz 200: '<script type="text/javascript">'.
201: '// <![CDATA['.
202: &Apache::lonmenu::rawconfig().
203: '// ]]>'.
204: '</script>'.
205: '<p class="LC_error">'.&mt('The following problems occurred:').
1.228 ! bisitz 206: '<br />'.
1.150 www 207: $error.
1.228 ! bisitz 208: '</p><br /><a href="'.$dest.'">'.&mt('Continue').'</a>'
! 209: );
! 210: $r->print(&Apache::loncommon::end_page());
1.150 www 211: }
212:
1.1 harris41 213: sub handler {
1.10 www 214:
1.1 harris41 215: my $r = shift;
216:
1.6 www 217: my $now=time;
1.118 albertel 218: my $then=$env{'user.login.time'};
1.226 raeburn 219: my $refresh=$env{'user.refresh.time'};
220: if (!$refresh) {
221: $refresh = $then;
222: }
1.6 www 223: my $envkey;
1.107 raeburn 224: my %dcroles = ();
225: my $numdc = &check_fordc(\%dcroles,$then);
1.148 albertel 226: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'});
1.10 www 227:
1.6 www 228: # ================================================================== Roles Init
1.118 albertel 229: if ($env{'form.selectrole'}) {
1.188 www 230:
231: my $locknum=&Apache::lonnet::get_locks();
232: if ($locknum) { return 409; }
233:
1.134 www 234: if ($env{'form.newrole'}) {
235: $env{'form.'.$env{'form.newrole'}}=1;
236: }
1.118 albertel 237: if ($env{'request.course.id'}) {
1.185 raeburn 238: # Check if user is CC trying to select a course role
239: if ($env{'form.switchrole'}) {
240: if (!defined($env{'user.role.'.$env{'form.switchrole'}})) {
241: &adhoc_course_role($then);
242: }
243: }
1.118 albertel 244: my %temp=('logout_'.$env{'request.course.id'} => time);
1.33 www 245: &Apache::lonnet::put('email_status',\%temp);
1.118 albertel 246: &Apache::lonnet::delenv('user.state.'.$env{'request.course.id'});
1.100 albertel 247: }
1.186 raeburn 248: &Apache::lonnet::appenv({"request.course.id" => '',
249: "request.course.fn" => '',
250: "request.course.uri" => '',
251: "request.course.sec" => '',
252: "request.role" => 'cm',
253: "request.role.adv" => $env{'user.adv'},
254: "request.role.domain" => $env{'user.domain'}});
1.182 www 255: # Check if user is a DC trying to enter a course or author space and needs privs to be created
1.107 raeburn 256: if ($numdc > 0) {
1.118 albertel 257: foreach my $envkey (keys %env) {
1.182 www 258: # Is this an ad-hoc CC-role?
1.146 raeburn 259: if (my ($domain,$coursenum) =
1.171 albertel 260: ($envkey =~ m-^form\.cc\./($match_domain)/($match_courseid)$-)) {
1.146 raeburn 261: if ($dcroles{$domain}) {
1.218 raeburn 262: &Apache::lonnet::check_adhoc_privs($domain,$coursenum,
263: $then,$now,'cc');
1.182 www 264: }
265: last;
266: }
1.193 raeburn 267: # Is this an ad-hoc CA-role?
1.183 www 268: if (my ($domain,$user) =
269: ($envkey =~ m-^form\.ca\./($match_domain)/($match_username)$-)) {
1.206 raeburn 270: if (($domain eq $env{'user.domain'}) && ($user eq $env{'user.name'})) {
271: delete($env{$envkey});
272: $env{'form.au./'.$domain.'/'} = 1;
273: my ($server_status,$home) = &check_author_homeserver($user,$domain);
274: if ($server_status eq 'switchserver') {
275: my $trolecode = 'au./'.$domain.'/';
276: my $switchserver = '/adm/switchserver?otherserver='.$home.'&role='.$trolecode;
277: $r->internal_redirect($switchserver);
278: }
279: last;
280: }
281: if (my ($castart,$caend) = ($env{'user.role.ca./'.$domain.'/'.$user} =~ /^(\d*)\.(\d*)$/)) {
282: if (((($castart) && ($castart < $now)) || !$castart) &&
283: ((!$caend) || (($caend) && ($caend > $now)))) {
284: my ($server_status,$home) = &check_author_homeserver($user,$domain);
285: if ($server_status eq 'switchserver') {
286: my $trolecode = 'ca./'.$domain.'/'.$user;
287: my $switchserver = '/adm/switchserver?otherserver='.$home.'&role='.$trolecode;
288: $r->internal_redirect($switchserver);
289: }
290: last;
291: }
292: }
293: # Check if author blocked ca-access
1.190 www 294: my %blocked=&Apache::lonnet::get('environment',['domcoord.author'],$domain,$user);
295: if ($blocked{'domcoord.author'} eq 'blocked') {
1.206 raeburn 296: delete($env{$envkey});
297: $env{'user.error.msg'}=':::1:User '.$user.' in domain '.$domain.' blocked domain coordinator access';
298: last;
1.190 www 299: }
1.193 raeburn 300: if ($dcroles{$domain}) {
301: my ($server_status,$home) = &check_author_homeserver($user,$domain);
302: if (($server_status eq 'ok') || ($server_status eq 'switchserver')) {
1.218 raeburn 303: &Apache::lonnet::check_adhoc_privs($domain,$user,$then,
304: $now,'ca');
1.193 raeburn 305: if ($server_status eq 'switchserver') {
306: my $trolecode = 'ca./'.$domain.'/'.$user;
307: my $switchserver = '/adm/switchserver?'
308: .'otherserver='.$home.'&role='.$trolecode;
309: $r->internal_redirect($switchserver);
310: }
311: } else {
312: delete($env{$envkey});
313: }
1.183 www 314: } else {
315: delete($env{$envkey});
1.182 www 316: }
317: last;
318: }
1.107 raeburn 319: }
320: }
321:
1.118 albertel 322: foreach $envkey (keys %env) {
1.40 matthew 323: next if ($envkey!~/^user\.role\./);
1.102 raeburn 324: my ($where,$trolecode,$role,$tstatus,$tend,$tstart);
1.226 raeburn 325: &Apache::lonnet::role_status($envkey,$then,$refresh,$now,\$role,\$where,
1.218 raeburn 326: \$trolecode,\$tstatus,\$tstart,\$tend);
1.118 albertel 327: if ($env{'form.'.$trolecode}) {
1.55 albertel 328: if ($tstatus eq 'is') {
329: $where=~s/^\///;
330: my ($cdom,$cnum,$csec)=split(/\//,$where);
1.137 raeburn 331: # check for course groups
332: my %coursegroups = &Apache::lonnet::get_active_groups(
333: $env{'user.domain'},$env{'user.name'},$cdom, $cnum);
334: my $cgrps = join(':',keys(%coursegroups));
335:
1.111 albertel 336: # store role if recent_role list being kept
1.118 albertel 337: if ($env{'environment.recentroles'}) {
1.158 albertel 338: my %frozen_roles =
339: &Apache::lonhtmlcommon::get_recent_frozen('roles',$env{'environment.recentrolesn'});
1.111 albertel 340: &Apache::lonhtmlcommon::store_recent('roles',
1.158 albertel 341: $trolecode,' ',$frozen_roles{$trolecode});
1.111 albertel 342: }
343:
344:
1.53 www 345: # check for keyed access
1.55 albertel 346: if (($role eq 'st') &&
1.118 albertel 347: ($env{'course.'.$cdom.'_'.$cnum.'.keyaccess'} eq 'yes')) {
1.89 www 348: # who is key authority?
349: my $authdom=$cdom;
350: my $authnum=$cnum;
1.118 albertel 351: if ($env{'course.'.$cdom.'_'.$cnum.'.keyauth'}) {
1.89 www 352: ($authnum,$authdom)=
1.172 albertel 353: split(/:/,$env{'course.'.$cdom.'_'.$cnum.'.keyauth'});
1.89 www 354: }
355: # check with key authority
356: unless (&Apache::lonnet::validate_access_key(
1.118 albertel 357: $env{'environment.key.'.$cdom.'_'.$cnum},
1.89 www 358: $authdom,$authnum)) {
1.53 www 359: # there is no valid key
1.118 albertel 360: if ($env{'form.newkey'}) {
1.53 www 361: # student attempts to register a new key
1.89 www 362: &Apache::loncommon::content_type($r,'text/html');
363: &Apache::loncommon::no_cache($r);
364: $r->send_http_header;
365: my $swinfo=&Apache::lonmenu::rawconfig();
1.147 albertel 366: my $start_page=&Apache::loncommon::start_page
1.89 www 367: ('Verifying Access Key to Unlock this Course');
1.147 albertel 368: my $end_page=&Apache::loncommon::end_page();
1.90 www 369: my $buttontext=&mt('Enter Course');
370: my $message=&mt('Successfully registered key');
371: my $assignresult=
372: &Apache::lonnet::assign_access_key(
1.118 albertel 373: $env{'form.newkey'},
1.90 www 374: $authdom,$authnum,
1.91 www 375: $cdom,$cnum,
1.118 albertel 376: $env{'user.domain'},
377: $env{'user.name'},
1.204 bisitz 378: &mt('Assigned from [_1] at [_2] for [_3]'
379: ,$ENV{'REMOTE_ADDR'}
380: ,&Apache::lonlocal::locallocaltime()
381: ,$trolecode)
382: );
1.90 www 383: unless ($assignresult eq 'ok') {
384: $assignresult=~s/^error\:\s*//;
385: $message=&mt($assignresult).
386: '<br /><a href="/adm/logout">'.
1.89 www 387: &mt('Logout').'</a>';
1.90 www 388: $buttontext=&mt('Re-Enter Key');
389: }
1.89 www 390: $r->print(<<ENDENTEREDKEY);
1.147 albertel 391: $start_page
1.179 raeburn 392: <script type="text/javascript">
1.225 bisitz 393: // <![CDATA[
1.89 www 394: $swinfo
1.225 bisitz 395: // ]]>
1.89 www 396: </script>
1.225 bisitz 397: <form action="" method="post">
1.89 www 398: <input type="hidden" name="selectrole" value="1" />
399: <input type="hidden" name="$trolecode" value="1" />
1.211 tempelho 400: <span class="LC_fontsize_large">$message</span><br />
1.89 www 401: <input type="submit" value="$buttontext" />
402: </form>
1.147 albertel 403: $end_page
1.89 www 404: ENDENTEREDKEY
405: return OK;
1.55 albertel 406: } else {
1.53 www 407: # print form to enter a new key
1.73 www 408: &Apache::loncommon::content_type($r,'text/html');
1.55 albertel 409: &Apache::loncommon::no_cache($r);
410: $r->send_http_header;
411: my $swinfo=&Apache::lonmenu::rawconfig();
1.147 albertel 412: my $start_page=&Apache::loncommon::start_page
1.55 albertel 413: ('Enter Access Key to Unlock this Course');
1.147 albertel 414: my $end_page=&Apache::loncommon::end_page();
1.55 albertel 415: $r->print(<<ENDENTERKEY);
1.147 albertel 416: $start_page
1.179 raeburn 417: <script type="text/javascript">
1.225 bisitz 418: // <![CDATA[
1.53 www 419: $swinfo
1.225 bisitz 420: // ]]>
1.53 www 421: </script>
1.225 bisitz 422: <form action="" method="post">
1.89 www 423: <input type="hidden" name="selectrole" value="1" />
424: <input type="hidden" name="$trolecode" value="1" />
1.118 albertel 425: <input type="text" size="20" name="newkey" value="$env{'form.newkey'}" />
1.53 www 426: <input type="submit" value="Enter key" />
427: </form>
1.147 albertel 428: $end_page
1.53 www 429: ENDENTERKEY
1.55 albertel 430: return OK;
431: }
432: }
433: }
1.118 albertel 434: &Apache::lonnet::log($env{'user.domain'},
435: $env{'user.name'},
436: $env{'user.home'},
1.87 www 437: "Role ".$trolecode);
1.101 albertel 438:
1.56 www 439: &Apache::lonnet::appenv(
1.186 raeburn 440: {'request.role' => $trolecode,
441: 'request.role.domain' => $cdom,
442: 'request.course.sec' => $csec,
443: 'request.course.groups' => $cgrps});
1.101 albertel 444: my $tadv=0;
1.62 matthew 445:
1.125 www 446: if (($cnum) && ($role ne 'ca') && ($role ne 'aa')) {
1.152 raeburn 447: my $msg;
1.55 albertel 448: my ($furl,$ferr)=
449: &Apache::lonuserstate::readmap($cdom.'/'.$cnum);
1.118 albertel 450: if (($env{'form.orgurl'}) &&
451: ($env{'form.orgurl'}!~/^\/adm\/flip/)) {
452: my $dest=$env{'form.orgurl'};
1.219 raeburn 453: if ($env{'form.symb'}) {
454: if ($dest =~ /\?/) {
455: $dest .= '&';
456: } else {
457: $dest .= '?'
458: }
459: $dest .= 'symb='.$env{'form.symb'};
460: }
1.117 albertel 461: if (&Apache::lonnet::allowed('adv') eq 'F') { $tadv=1; }
1.186 raeburn 462: &Apache::lonnet::appenv({'request.role.adv'=>$tadv});
1.150 www 463: if (($ferr) && ($tadv)) {
464: &error_page($r,$ferr,$dest);
465: } else {
466: $r->internal_redirect($dest);
467: }
1.55 albertel 468: return OK;
469: } else {
1.155 albertel 470: if (!$env{'request.course.id'}) {
1.55 albertel 471: &Apache::lonnet::appenv(
1.186 raeburn 472: {"request.course.id" => $cdom.'_'.$cnum});
1.61 www 473: $furl='/adm/roles?tryagain=1';
1.221 bisitz 474: $msg='<p><span class="LC_error">'
475: .&mt('Could not initialize [_1] at this time.',
476: $env{'course.'.$cdom.'_'.$cnum.'.description'})
477: .'</span></p>'
478: .'<p>'.&mt('Please try again.').'</p>'
479: .'<p>'.$ferr.'</p>';
1.55 albertel 480: }
1.117 albertel 481: if (&Apache::lonnet::allowed('adv') eq 'F') { $tadv=1; }
1.186 raeburn 482: &Apache::lonnet::appenv({'request.role.adv'=>$tadv});
1.152 raeburn 483:
1.150 www 484: if (($ferr) && ($tadv)) {
485: &error_page($r,$ferr,$furl);
486: } else {
487: # Check to see if the user is a CC entering a course
488: # for the first time
489: my (undef, undef, $role, $courseid) = split(/\./, $envkey);
490: if (substr($courseid, 0, 1) eq '/') {
491: $courseid = substr($courseid, 1);
492: }
493: $courseid =~ s/\//_/;
494: if ($role eq 'cc' && $env{'course.' . $courseid .
495: '.course.helper.not.run'}) {
496: $furl = "/adm/helper/course.initialization.helper";
497: # Send the user to the course they selected
498: } elsif ($env{'request.course.id'}) {
1.185 raeburn 499: if ($env{'form.destinationurl'}) {
500: my $dest = $env{'form.destinationurl'};
1.203 raeburn 501: if ($env{'form.destsymb'} ne '') {
502: my $esc_symb = &HTML::Entities::encode($env{'form.destsymb'},'"<>&');
503: $dest .= '?symb='.$esc_symb;
504: }
1.185 raeburn 505: &redirect_user($r,&mt('Entering [_1]',
506: $env{'course.'.$courseid.'.description'}),
507: $dest,$msg,
508: $env{'environment.remotenavmap'});
509: return OK;
510: }
1.150 www 511: if (&Apache::lonnet::allowed('whn',
512: $env{'request.course.id'})
513: || &Apache::lonnet::allowed('whn',
514: $env{'request.course.id'}.'/'
515: .$env{'request.course.sec'})
516: ) {
517: my $startpage = &courseloadpage($courseid);
518: unless ($startpage eq 'firstres') {
1.204 bisitz 519: $msg = &mt('Entering [_1] ...',
1.162 albertel 520: $env{'course.'.$courseid.'.description'});
1.150 www 521: &redirect_user($r,&mt('New in course'),
522: '/adm/whatsnew?refpage=start',$msg,
523: $env{'environment.remotenavmap'});
524: return OK;
525: }
526: }
527: }
1.151 www 528: # Are we allowed to look at the first resource?
1.169 albertel 529: if ($furl !~ m|^/adm/|) {
1.151 www 530: # Guess not ...
531: $furl=&Apache::lonpageflip::first_accessible_resource();
532: }
1.162 albertel 533: $msg = &mt('Entering [_1] ...',
534: $env{'course.'.$courseid.'.description'});
535: &redirect_user($r,&mt('Entering [_1]',
536: $env{'course.'.$courseid.'.description'}),
1.150 www 537: $furl,$msg,
538: $env{'environment.remotenavmap'});
1.58 bowersj2 539: }
1.124 albertel 540: return OK;
1.55 albertel 541: }
542: }
1.62 matthew 543: #
544: # Send the user to the construction space they selected
1.125 www 545: if ($role =~ /^(au|ca|aa)$/) {
1.62 matthew 546: my $redirect_url = '/priv/';
547: if ($role eq 'au') {
1.118 albertel 548: $redirect_url.=$env{'user.name'};
1.62 matthew 549: } else {
550: $where =~ /\/(.*)$/;
551: $redirect_url .= $1;
552: }
553: $redirect_url .= '/';
1.78 sakharuk 554: &redirect_user($r,&mt('Entering Construction Space'),
1.62 matthew 555: $redirect_url);
556: return OK;
557: }
1.104 raeburn 558: if ($role eq 'dc') {
1.108 raeburn 559: my $redirect_url = '/adm/menu/';
560: &redirect_user($r,&mt('Loading Domain Coordinator Menu'),
1.104 raeburn 561: $redirect_url);
1.108 raeburn 562: return OK;
1.104 raeburn 563: }
1.220 raeburn 564: if ($role eq 'sc') {
565: my $redirect_url = '/adm/grades?command=scantronupload';
566: &redirect_user($r,&mt('Loading Data Upload Page'),
567: $redirect_url);
568: return OK;
569: }
1.55 albertel 570: }
571: }
1.6 www 572: }
1.40 matthew 573: }
1.44 www 574:
1.10 www 575:
1.6 www 576: # =============================================================== No Roles Init
1.10 www 577:
1.73 www 578: &Apache::loncommon::content_type($r,'text/html');
1.30 albertel 579: &Apache::loncommon::no_cache($r);
1.10 www 580: $r->send_http_header;
581: return OK if $r->header_only;
582:
1.224 raeburn 583: my $crumbtext = 'User Roles';
584: my $pagetitle = 'My Roles';
585: my $recent = &mt('Recent Roles');
586: my $show_course=&Apache::loncommon::show_course();
587: if ($show_course) {
588: $crumbtext = 'Courses';
589: $pagetitle = 'My Courses';
590: $recent = &mt('Recent Courses');
591: }
592: my $brcrum =[{href=>"/adm/roles",text=>$crumbtext}];
1.52 www 593: my $swinfo=&Apache::lonmenu::rawconfig();
1.224 raeburn 594: my $start_page=&Apache::loncommon::start_page($pagetitle,undef,{bread_crumbs=>$brcrum});
1.134 www 595: my $standby=&mt('Role selected. Please stand by.');
1.135 albertel 596: $standby=~s/\n/\\n/g;
1.184 raeburn 597: my $noscript='<span class="LC_error">'.&mt('Use of LON-CAPA requires Javascript to be enabled in your web browser.').'<br />'.&mt('As this is not the case, most functionality in the system will be unavailable.').'</span><br />';
1.163 www 598:
1.10 www 599: $r->print(<<ENDHEADER);
1.147 albertel 600: $start_page
1.163 www 601: <br />
1.179 raeburn 602: <noscript>
603: $noscript
604: </noscript>
605: <script type="text/javascript">
1.225 bisitz 606: // <![CDATA[
1.26 www 607: $swinfo
608: window.focus();
1.134 www 609:
610: active=true;
611:
612: function enterrole (thisform,rolecode,buttonname) {
613: if (active) {
614: active=false;
615: document.title='$standby';
616: window.status='$standby';
617: thisform.newrole.value=rolecode;
618: thisform.submit();
619: } else {
620: alert('$standby');
621: }
622: }
1.225 bisitz 623: // ]]>
1.26 www 624: </script>
1.10 www 625: ENDHEADER
1.6 www 626:
1.2 www 627: # ------------------------------------------ Get Error Message from Environment
628:
1.118 albertel 629: my ($fn,$priv,$nochoose,$error,$msg)=split(/:/,$env{'user.error.msg'});
630: if ($env{'user.error.msg'}) {
1.55 albertel 631: $r->log_reason(
1.118 albertel 632: "$msg for $env{'user.name'} domain $env{'user.domain'} access $priv",$fn);
1.12 www 633: }
1.1 harris41 634:
1.61 www 635: # ------------------------------------------------- Can this user re-init, etc?
1.6 www 636:
1.118 albertel 637: my $advanced=$env{'user.adv'};
1.61 www 638: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['tryagain']);
1.118 albertel 639: my $tryagain=$env{'form.tryagain'};
1.209 raeburn 640: my $reinit=$env{'user.reinit'};
641: delete $env{'user.reinit'};
1.6 www 642:
1.2 www 643: # -------------------------------------------------------- Generate Page Output
1.6 www 644: # --------------------------------------------------------------- Error Header?
1.2 www 645: if ($error) {
1.187 bisitz 646: $r->print("<h1>".&mt('LON-CAPA Access Control')."</h1>");
1.174 albertel 647: $r->print("<!-- LONCAPAACCESSCONTROLERRORSCREEN --><hr /><pre>");
648: if ($priv ne '') {
1.187 bisitz 649: $r->print(&mt('Access : ').&Apache::lonnet::plaintext($priv)."\n");
1.174 albertel 650: }
651: if ($fn ne '') {
1.187 bisitz 652: $r->print(&mt('Resource: ').&Apache::lonenc::check_encrypt($fn)."\n");
1.174 albertel 653: }
654: if ($msg ne '') {
1.187 bisitz 655: $r->print(&mt('Action : ').$msg."\n");
1.174 albertel 656: }
657: $r->print("</pre><hr />");
1.120 albertel 658: my $url=$fn;
659: my $last;
660: if (tie(my %hash,'GDBM_File',$env{'request.course.fn'}.'_symb.db',
661: &GDBM_READER(),0640)) {
662: $last=$hash{'last_known'};
663: untie(%hash);
664: }
1.149 www 665: if ($last) { $fn.='?symb='.&escape($last); }
1.120 albertel 666:
667: &Apache::londocs::changewarning($r,undef,'You have modified your course recently, [_1] may fix this access problem.',
668: &Apache::lonenc::check_encrypt($fn));
1.2 www 669: } else {
1.118 albertel 670: if ($env{'user.error.msg'}) {
1.209 raeburn 671: if ($reinit) {
672: $r->print(
673: '<h3><span class="LC_error">'.
674: &mt('As your session file for the course has expired, you will need to re-select the course.').'</span></h3>');
675: } else {
676: $r->print(
1.157 albertel 677: '<h3><span class="LC_error">'.
678: &mt('You need to choose another user role or enter a specific course for this function').'</span></h3>');
1.209 raeburn 679: }
680: }
1.2 www 681: }
1.6 www 682: # -------------------------------------------------------- Choice or no choice?
1.2 www 683: if ($nochoose) {
1.177 www 684: $r->print("<h2>".&mt('Sorry ...')."</h2>\n<span class='LC_error'>".
685: &mt('This action is currently not authorized.').'</span>'.
1.150 www 686: &Apache::loncommon::end_page());
687: return OK;
1.6 www 688: } else {
1.18 www 689: if (($ENV{'REDIRECT_QUERY_STRING'}) && ($fn)) {
690: $fn.='?'.$ENV{'REDIRECT_QUERY_STRING'};
1.6 www 691: }
1.84 www 692: $r->print('<form method="post" name="rolechoice" action="'.(($fn)?$fn:$r->uri).'">');
1.116 albertel 693: $r->print('<input type="hidden" name="orgurl" value="'.$fn.'" />');
694: $r->print('<input type="hidden" name="selectrole" value="1" />');
1.134 www 695: $r->print('<input type="hidden" name="newrole" value="" />');
1.6 www 696: }
1.226 raeburn 697:
698: my (%roletext,%sortrole,%roleclass,%futureroles,%timezones);
699: my ($countactive,$countfuture,$inrole,$possiblerole) =
700: &gather_roles($then,$refresh,$now,$reinit,$nochoose,\%roletext,\%sortrole,\%roleclass,
701: \%futureroles,\%timezones);
702:
703: $refresh = $now;
704: &Apache::lonnet::appenv({'user.refresh.time' => $refresh});
1.196 raeburn 705: if ($env{'user.adv'}) {
706: $r->print(
1.212 bisitz 707: '<p><label>'.&mt('Show all roles').': <input type="checkbox" name="showall"');
1.196 raeburn 708: if ($env{'form.showall'}) { $r->print(' checked="checked" '); }
1.212 bisitz 709: $r->print(' /></label><input type="submit" value="'.&mt('Display').'" /></p>');
1.196 raeburn 710: } else {
711: if ($countactive > 0) {
1.216 raeburn 712: &queued_selfenrollment($r);
1.196 raeburn 713: my $domdesc = &Apache::lonnet::domain($env{'user.domain'},'description');
1.201 raeburn 714: my $esc_dom = &HTML::Entities::encode($env{'user.domain'},'"<>&');
715: $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>');
1.196 raeburn 716: }
717: }
718:
1.84 www 719: # No active roles
720: if ($countactive==0) {
721: if ($inrole) {
722: $r->print('<h2>'.&mt('Currently no additional roles or courses').'</h2>');
723: } else {
724: $r->print('<h2>'.&mt('Currently no active roles or courses').'</h2>');
725: }
1.191 raeburn 726: &findcourse_advice($r);
727: $r->print('</form>');
728: if ($countfuture) {
729: $r->print(&mt('The following [quant,_1,role,roles] will become active in the future:',$countfuture));
730: my $doheaders = &roletable_headers($r,\%roleclass,\%sortrole,
731: $nochoose);
732: &print_rolerows($r,$doheaders,\%roleclass,\%sortrole,\%dcroles,
733: \%roletext);
734: my $tremark='';
1.212 bisitz 735: my $tbg;
1.191 raeburn 736: if ($env{'request.role'} eq 'cm') {
1.212 bisitz 737: $tbg="LC_roles_selected";
1.204 bisitz 738: $tremark=&mt('Currently selected.').' ';
1.191 raeburn 739: } else {
1.212 bisitz 740: $tbg="LC_roles_is";
1.191 raeburn 741: }
1.212 bisitz 742: $r->print(&Apache::loncommon::start_data_table_row()
743: .'<td class="'.$tbg.'"> </td>'
744: .'<td colspan="3">'
745: .&mt('No role specified')
746: .'</td>'
747: .'<td>'.$tremark.' </td>'
748: .&Apache::loncommon::end_data_table_row()
749: );
1.191 raeburn 750:
1.212 bisitz 751: $r->print(&Apache::loncommon::end_data_table());
1.191 raeburn 752: }
753: $r->print(&Apache::loncommon::end_page());
1.84 www 754: return OK;
755: }
756: # ----------------------------------------------------------------------- Table
1.224 raeburn 757: unless ((!&Apache::loncommon::show_course()) || ($nochoose) || ($countactive==1)) {
1.173 albertel 758: $r->print("<h2>".&mt('Select a Course to Enter')."</h2>\n");
1.84 www 759: }
1.191 raeburn 760: my $doheaders = &roletable_headers($r,\%roleclass,\%sortrole,$nochoose);
1.118 albertel 761: if ($env{'environment.recentroles'}) {
1.111 albertel 762: my %recent_roles =
1.118 albertel 763: &Apache::lonhtmlcommon::get_recent('roles',$env{'environment.recentrolesn'});
1.111 albertel 764: my $output='';
765: foreach (sort(keys(%recent_roles))) {
1.223 raeburn 766: if (ref($roletext{'user.role.'.$_}) eq 'ARRAY') {
767: $output.= &Apache::loncommon::start_data_table_row().
768: $roletext{'user.role.'.$_}->[0].
769: &Apache::loncommon::end_data_table_row().
770: &Apache::loncommon::continue_data_table_row().
771: $roletext{'user.role.'.$_}->[1].
772: &Apache::loncommon::end_data_table_row();
1.170 albertel 773: if ($_ =~ m-dc\./($match_domain)/-
774: && $dcroles{$1}) {
1.192 raeburn 775: $output .= &adhoc_roles_row($1,'recent');
1.133 albertel 776: }
1.113 raeburn 777: } elsif ($numdc > 0) {
778: unless ($_ =~/^error\:/) {
779: $output.=&display_cc_role('user.role.'.$_);
780: }
781: }
1.111 albertel 782: }
783: if ($output) {
1.212 bisitz 784: $r->print(&Apache::loncommon::start_data_table_empty_row()
785: .'<td align="center" colspan="5">'
1.224 raeburn 786: .$recent
1.212 bisitz 787: .'</td>'
788: .&Apache::loncommon::end_data_table_empty_row()
789: );
1.111 albertel 790: $r->print($output);
1.114 raeburn 791: $doheaders ++;
1.111 albertel 792: }
793: }
794:
1.104 raeburn 795: if ($numdc > 0) {
1.112 raeburn 796: $r->print(&coursepick_jscript());
1.193 raeburn 797: $r->print(&Apache::loncommon::coursebrowser_javascript().
798: &Apache::loncommon::authorbrowser_javascript());
1.108 raeburn 799: }
1.191 raeburn 800: &print_rolerows($r,$doheaders,\%roleclass,\%sortrole,\%dcroles,\%roletext);
1.202 raeburn 801: if ($countactive > 1) {
802: my $tremark='';
1.212 bisitz 803: my $tbg;
1.202 raeburn 804: if ($env{'request.role'} eq 'cm') {
1.212 bisitz 805: $tbg="LC_roles_selected";
1.204 bisitz 806: $tremark=&mt('Currently selected.').' ';
1.202 raeburn 807: } else {
1.212 bisitz 808: $tbg="LC_roles_is";
1.202 raeburn 809: }
1.212 bisitz 810: $r->print(&Apache::loncommon::start_data_table_row());
1.202 raeburn 811: unless ($nochoose) {
812: if ($env{'request.role'} ne 'cm') {
1.212 bisitz 813: $r->print('<td class="'.$tbg.'"><input type="submit" value="'.
1.202 raeburn 814: &mt('Select').'" name="cm" /></td>');
815: } else {
1.212 bisitz 816: $r->print('<td class="'.$tbg.'"> </td>');
1.202 raeburn 817: }
818: }
1.212 bisitz 819: $r->print('<td colspan="3">'
820: .&mt('No role specified')
821: .'</td>'
822: .'<td>'.$tremark.' </td>'
823: .&Apache::loncommon::end_data_table_row()
824: );
1.202 raeburn 825: }
1.212 bisitz 826: $r->print(&Apache::loncommon::end_data_table());
1.4 www 827: unless ($nochoose) {
828: $r->print("</form>\n");
829: }
1.22 harris41 830: # ------------------------------------------------------------ Privileges Info
1.118 albertel 831: if (($advanced) && (($env{'user.error.msg'}) || ($error))) {
1.212 bisitz 832: $r->print('<hr /><h2>'.&mt('Current Privileges').'</h2>');
1.175 albertel 833: $r->print(&privileges_info());
1.4 www 834: }
1.66 www 835: $r->print(&Apache::lonnet::getannounce());
1.65 www 836: if ($advanced) {
1.201 raeburn 837: my $esc_dom = &HTML::Entities::encode($env{'user.domain'},'"<>&');
1.195 bisitz 838: $r->print('<p><small><i>'
839: .&mt('This is LON-CAPA [_1]',$r->dir_config('lonVersion'))
840: .'</i><br />'
1.197 raeburn 841: .'<a href="/adm/logout">'.&mt('Logout').'</a> '
1.201 raeburn 842: .'<a href="/adm/coursecatalog?showdom='.$esc_dom.'">'
843: .&mt('Course Catalog')
1.225 bisitz 844: .'</a></small></p>');
1.65 www 845: }
1.147 albertel 846: $r->print(&Apache::loncommon::end_page());
1.1 harris41 847: return OK;
1.102 raeburn 848: }
849:
1.226 raeburn 850: sub gather_roles {
851: my ($then,$refresh,$now,$reinit,$nochoose,$roletext,$sortrole,$roleclass,$futureroles,$timezones) = @_;
852: my ($countactive,$countfuture,$inrole,$possiblerole) = (0,0,0,'');
853: my $advanced = $env{'user.adv'};
854: my $tryagain = $env{'form.tryagain'};
855: foreach my $envkey (sort(keys(%env))) {
856: my $button = 1;
857: my $switchserver='';
858: my ($role_text,$role_text_end,$sortkey);
859: if ($envkey=~/^user\.role\./) {
860: my ($role,$where,$trolecode,$tstart,$tend,$tremark,$tstatus,$tpstart,$tpend);
861: &Apache::lonnet::role_status($envkey,$then,$refresh,$now,\$role,\$where,
862: \$trolecode,\$tstatus,\$tstart,\$tend);
863: next if (!defined($role) || $role eq '' || $role =~ /^gr/);
864: my $timezone = &role_timezone($where,$timezones);
865: $tremark='';
866: $tpstart=' ';
867: $tpend=' ';
868: if ($tstart) {
869: $tpstart=&Apache::lonlocal::locallocaltime($tstart,$timezone);
870: }
871: if ($tend) {
872: $tpend=&Apache::lonlocal::locallocaltime($tend,$timezone);
873: }
874: if ($env{'request.role'} eq $trolecode) {
875: $tstatus='selected';
876: }
877: my $tbg;
878: if (($tstatus eq 'is')
879: || ($tstatus eq 'selected')
880: || ($tstatus eq 'future')
881: || ($env{'form.showall'})) {
882: if ($tstatus eq 'is') {
883: $tbg='LC_roles_is';
884: $possiblerole=$trolecode;
885: $countactive++;
886: } elsif ($tstatus eq 'future') {
887: $tbg='LC_roles_future';
888: $button=0;
889: $futureroles->{$trolecode} = $tstart.':'.$tend;
890: $countfuture ++;
891: } elsif ($tstatus eq 'expired') {
892: $tbg='LC_roles_expired';
893: $button=0;
894: } elsif ($tstatus eq 'will_not') {
895: $tbg='LC_roles_will_not';
896: $tremark.=&mt('Expired after logout.').' ';
897: } elsif ($tstatus eq 'selected') {
898: $tbg='LC_roles_selected';
899: $inrole=1;
900: $countactive++;
901: $tremark.=&mt('Currently selected.').' ';
902: }
903: my $trole;
904: if ($role =~ /^cr\//) {
905: my ($rdummy,$rdomain,$rauthor,$rrole)=split(/\//,$role);
906: if ($tremark) { $tremark.='<br />'; }
907: $tremark.=&mt('Defined by [_1] at [_2].',$rauthor,$rdomain);
908: }
909: $trole=Apache::lonnet::plaintext($role);
910: my $ttype;
911: my $twhere;
912: my ($tdom,$trest,$tsection)=
913: split(/\//,Apache::lonnet::declutter($where));
914: # First, Co-Authorship roles
915: if (($role eq 'ca') || ($role eq 'aa')) {
916: my $home = &Apache::lonnet::homeserver($trest,$tdom);
917: my $allowed=0;
918: my @ids=&Apache::lonnet::current_machine_ids();
919: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
920: if (!$allowed) {
921: $button=0;
922: $switchserver='otherserver='.$home.'&role='.$trolecode;
923: }
924: #next if ($home eq 'no_host');
925: $home = &Apache::lonnet::hostname($home);
926: $ttype='Construction Space';
927: $twhere=&mt('User').': '.$trest.'<br />'.&mt('Domain').
928: ': '.$tdom.'<br />'.
929: ' '.&mt('Server').': '.$home;
930: $env{'course.'.$tdom.'_'.$trest.'.description'}='ca';
931: $tremark.=&Apache::lonhtmlcommon::authorbombs('/res/'.$tdom.'/'.$trest.'/');
932: $sortkey=$role."$trest:$tdom";
933: } elsif ($role eq 'au') {
934: # Authors
935: my $home = &Apache::lonnet::homeserver
936: ($env{'user.name'},$env{'user.domain'});
937: my $allowed=0;
938: my @ids=&Apache::lonnet::current_machine_ids();
939: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
940: if (!$allowed) {
941: $button=0;
942: $switchserver='otherserver='.$home.'&role='.$trolecode;
943: }
944: #next if ($home eq 'no_host');
945: $home = &Apache::lonnet::hostname($home);
946: $ttype='Construction Space';
947: $twhere=&mt('Domain').': '.$tdom.'<br />'.&mt('Server').
948: ': '.$home;
949: $env{'course.'.$tdom.'_'.$trest.'.description'}='ca';
950: $tremark.=&Apache::lonhtmlcommon::authorbombs('/res/'.$tdom.'/'.$env{'user.name'}.'/');
951: $sortkey=$role;
952: } elsif ($trest) {
953: my $tcourseid=$tdom.'_'.$trest;
954: $ttype = &Apache::loncommon::course_type($tcourseid);
955: $trole = &Apache::lonnet::plaintext($role,$ttype);
956: if ($env{'course.'.$tcourseid.'.description'}) {
957: $twhere=$env{'course.'.$tcourseid.'.description'};
958: $sortkey=$role."\0".$tdom."\0".$twhere."\0".$envkey;
959: unless ($twhere eq &mt('Currently not available')) {
960: $twhere.=' <span class="LC_fontsize_small">'.
961: &Apache::loncommon::syllabuswrapper(&mt('Syllabus'),$trest,$tdom).
962: '</span>';
963: }
964: } else {
965: my %newhash=&Apache::lonnet::coursedescription($tcourseid);
966: if (%newhash) {
967: $sortkey=$role."\0".$tdom."\0".$newhash{'description'}.
968: "\0".$envkey;
969: $twhere=$newhash{'description'}.
970: ' <span class="LC_fontsize_small">'.
971: &Apache::loncommon::syllabuswrapper(&mt('Syllabus'),$trest,$tdom).
972: '</span>';
973: $ttype = $newhash{'type'};
974: $trole = &Apache::lonnet::plaintext($role,$ttype);
975: } else {
976: $twhere=&mt('Currently not available');
977: $env{'course.'.$tcourseid.'.description'}=$twhere;
978: $sortkey=$role."\0".$tdom."\0".$twhere."\0".$envkey;
979: $ttype = 'Unavailable';
980: }
981: }
982: if ($tsection) {
983: $twhere.='<br />'.&mt('Section').': '.$tsection;
984: }
985: if ($role ne 'st') { $twhere.="<br />".&mt('Domain').":".$tdom; }
986: } elsif ($tdom) {
987: $ttype='Domain';
988: $twhere=$tdom;
989: $sortkey=$role.$twhere;
990: } else {
991: $ttype='System';
992: $twhere=&mt('system wide');
993: $sortkey=$role.$twhere;
994: }
995: ($role_text,$role_text_end) =
996: &build_roletext($trolecode,$tdom,$trest,$tstatus,$tryagain,
997: $advanced,$tremark,$tbg,$trole,$twhere,$tpstart,
998: $tpend,$nochoose,$button,$switchserver,$reinit);
999: $roletext->{$envkey}=[$role_text,$role_text_end];
1000: if (!$sortkey) {$sortkey=$twhere."\0".$envkey;}
1001: $sortrole->{$sortkey}=$envkey;
1002: $roleclass->{$envkey}=$ttype;
1003: }
1004: }
1005: }
1006: return ($countactive,$countfuture,$inrole,$possiblerole);
1007: }
1008:
1.215 raeburn 1009: sub role_timezone {
1010: my ($where,$timezones) = @_;
1011: my $timezone;
1012: if (ref($timezones) eq 'HASH') {
1013: if ($where =~ m{^/($match_domain)/($match_courseid)}) {
1014: my $cdom = $1;
1015: my $cnum = $2;
1016: if ($cdom && $cnum) {
1017: if (!exists($timezones->{$cdom.'_'.$cnum})) {
1018: my %timehash =
1019: &Apache::lonnet::get('environment',['timezone'],$cdom,$cnum);
1020: if ($timehash{'timezone'} eq '') {
1021: if (!exists($timezones->{$cdom})) {
1022: my %domdefaults =
1023: &Apache::lonnet::get_domain_defaults($cdom);
1024: if ($domdefaults{'timezone_def'} eq '') {
1025: $timezones->{$cdom} = 'local';
1026: } else {
1027: $timezones->{$cdom} = $domdefaults{'timezone_def'};
1028: }
1029: }
1030: $timezones->{$cdom.'_'.$cnum} = $timezones->{$cdom};
1031: } else {
1032: $timezones->{$cdom.'_'.$cnum} =
1033: &Apache::lonlocal::gettimezone($timehash{'timezone'});
1034: }
1035: }
1036: $timezone = $timezones->{$cdom.'_'.$cnum};
1037: }
1038: } else {
1039: my ($tdom) = ($where =~ m{^/($match_domain)});
1040: if ($tdom) {
1041: if (!exists($timezones->{$tdom})) {
1042: my %domdefaults = &Apache::lonnet::get_domain_defaults($tdom);
1043: if ($domdefaults{'timezone_def'} eq '') {
1044: $timezones->{$tdom} = 'local';
1045: } else {
1046: $timezones->{$tdom} = $domdefaults{'timezone_def'};
1047: }
1048: }
1049: $timezone = $timezones->{$tdom};
1050: }
1051: }
1052: if ($timezone eq 'local') {
1053: $timezone = undef;
1054: }
1055: }
1056: return $timezone;
1057: }
1058:
1.191 raeburn 1059: sub roletable_headers {
1060: my ($r,$roleclass,$sortrole,$nochoose) = @_;
1061: my $doheaders;
1062: if ((ref($sortrole) eq 'HASH') && (ref($roleclass) eq 'HASH')) {
1.212 bisitz 1063: $r->print('<br />'
1064: .&Apache::loncommon::start_data_table()
1065: .&Apache::loncommon::start_data_table_header_row()
1066: );
1.191 raeburn 1067: if (!$nochoose) { $r->print('<th> </th>'); }
1.212 bisitz 1068: $r->print('<th>'.&mt('User Role').'</th>'
1069: .'<th>'.&mt('Extent').'</th>'
1070: .'<th>'.&mt('Start').'</th>'
1071: .'<th>'.&mt('End').'</th>'
1072: .&Apache::loncommon::end_data_table_header_row()
1073: );
1.191 raeburn 1074: $doheaders=-1;
1075: my @roletypes = &roletypes();
1076: foreach my $type (@roletypes) {
1077: my $haverole=0;
1078: foreach my $which (sort {uc($a) cmp uc($b)} (keys(%{$sortrole}))) {
1079: if ($roleclass->{$sortrole->{$which}} =~ /^\Q$type\E/) {
1080: $haverole=1;
1081: }
1082: }
1083: if ($haverole) { $doheaders++; }
1084: }
1085: }
1086: return $doheaders;
1087: }
1088:
1089: sub roletypes {
1090: my @types = ('Domain','Construction Space','Course','Unavailable','System');
1091: return @types;
1092: }
1093:
1094: sub print_rolerows {
1095: my ($r,$doheaders,$roleclass,$sortrole,$dcroles,$roletext) = @_;
1096: if ((ref($roleclass) eq 'HASH') && (ref($sortrole) eq 'HASH')) {
1097: my @types = &roletypes();
1098: foreach my $type (@types) {
1099: my $output;
1100: foreach my $which (sort {uc($a) cmp uc($b)} (keys(%{$sortrole}))) {
1101: if ($roleclass->{$sortrole->{$which}} =~ /^\Q$type\E/) {
1102: if (ref($roletext) eq 'HASH') {
1.223 raeburn 1103: if (ref($roletext->{$sortrole->{$which}}) eq 'ARRAY') {
1104: $output.= &Apache::loncommon::start_data_table_row().
1105: $roletext->{$sortrole->{$which}}->[0].
1106: &Apache::loncommon::end_data_table_row().
1107: &Apache::loncommon::continue_data_table_row().
1108: $roletext->{$sortrole->{$which}}->[1].
1109: &Apache::loncommon::end_data_table_row();
1110: }
1.191 raeburn 1111: if ($sortrole->{$which} =~ m-dc\./($match_domain)/-) {
1112: if (ref($dcroles) eq 'HASH') {
1113: if ($dcroles->{$1}) {
1.192 raeburn 1114: $output .= &adhoc_roles_row($1,'');
1.191 raeburn 1115: }
1116: }
1117: }
1118: }
1119: }
1120: }
1121: if ($output) {
1122: if ($doheaders > 0) {
1.212 bisitz 1123: $r->print(&Apache::loncommon::start_data_table_empty_row()
1124: .'<td align="center" colspan="5">'
1125: .&mt($type)
1126: .'</td>'
1127: .&Apache::loncommon::end_data_table_empty_row()
1128: );
1.191 raeburn 1129: }
1130: $r->print($output);
1131: }
1132: }
1133: }
1134: }
1135:
1136: sub findcourse_advice {
1137: my ($r) = @_;
1138: my $domdesc = &Apache::lonnet::domain($env{'user.domain'},'description');
1.201 raeburn 1139: my $esc_dom = &HTML::Entities::encode($env{'user.domain'},'"<>&');
1.200 raeburn 1140: if (&Apache::lonnet::auto_run(undef,$env{'user.domain'})) {
1.191 raeburn 1141: $r->print(&mt('If you were expecting to see an active role listed for a particular course in the [_1] domain, it may be missing for one of the following reasons:',$domdesc).'
1142: <ul>
1143: <li>'.&mt('The course has yet to be created.').'</li>
1144: <li>'.&mt('Automatic enrollment of registered students has not been enabled for the course.').'</li>
1145: <li>'.&mt('You are in a section of course for which automatic enrollment in the corresponding LON-CAPA course is not active.').'</li>
1146: <li>'.&mt('The start date for automated enrollment has yet to be reached.').'</li>
1147: <li>'.&mt('You registered for the course recently and there is a time lag between the time you register, and the time this information becomes available for the update of LON-CAPA course rosters.').'</li>
1148: </ul>');
1149: } else {
1150: $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 />');
1151: }
1.201 raeburn 1152: $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 />');
1.191 raeburn 1153: $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>');
1.216 raeburn 1154: &queued_selfenrollment($r);
1155: return;
1156: }
1157:
1158: sub queued_selfenrollment {
1159: my ($r) = @_;
1160: my %selfenrollrequests = &Apache::lonnet::dump('selfenrollrequests');
1161: my %reqs_by_date;
1162: foreach my $item (keys(%selfenrollrequests)) {
1163: if (ref($selfenrollrequests{$item}) eq 'HASH') {
1164: if ($selfenrollrequests{$item}{'status'} eq 'request') {
1165: if ($selfenrollrequests{$item}{'timestamp'}) {
1166: push(@{$reqs_by_date{$selfenrollrequests{$item}{'timestamp'}}},$item);
1167: }
1168: }
1169: }
1170: }
1171: if (keys(%reqs_by_date)) {
1172: my $rolename = &Apache::lonnet::plaintext('st');
1173: $r->print('<b>'.&mt('Enrollment requests pending Course Coordinator approval').'</b><br />'.
1174: &Apache::loncommon::start_data_table().
1175: &Apache::loncommon::start_data_table_header_row().
1176: '<th>'.&mt('Date requested').'</th><th>'.&mt('Course title').'</th>'.
1177: '<th>'.&mt('User role').'</th><th>'.&mt('Section').'</th>'.
1178: &Apache::loncommon::end_data_table_header_row());
1179: my @sorted = sort { $a <=> $b } (keys(%reqs_by_date));
1180: foreach my $item (@sorted) {
1181: if (ref($reqs_by_date{$item}) eq 'ARRAY') {
1182: foreach my $crs (@{$reqs_by_date{$item}}) {
1183: my %courseinfo = &Apache::lonnet::coursedescription($crs);
1184: my $usec = $selfenrollrequests{$crs}{'section'};
1185: if ($usec eq '') {
1186: $usec = &mt('No section');
1187: }
1188: $r->print(&Apache::loncommon::start_data_table_row().
1189: '<td>'.&Apache::lonlocal::locallocaltime($item).'</td>'.
1190: '<td>'.$courseinfo{'description'}.'</td>'.
1191: '<td>'.$rolename.'</td><td>'.$usec.'</td>'.
1192: &Apache::loncommon::end_data_table_row());
1193: }
1194: }
1195: }
1196: $r->print(&Apache::loncommon::end_data_table());
1197: }
1.191 raeburn 1198: return;
1199: }
1200:
1.175 albertel 1201: sub privileges_info {
1202: my ($which) = @_;
1203: my $output;
1204:
1205: $which ||= $env{'request.role'};
1206:
1207: foreach my $envkey (sort(keys(%env))) {
1208: next if ($envkey!~/^user\.priv\.\Q$which\E\.(.*)/);
1209:
1210: my $where=$1;
1211: my $ttype;
1212: my $twhere;
1213: my (undef,$tdom,$trest,$tsec)=split(m{/},$where);
1214: if ($trest) {
1215: if ($env{'course.'.$tdom.'_'.$trest.'.description'} eq 'ca') {
1216: $ttype='Construction Space';
1217: $twhere='User: '.$trest.', Domain: '.$tdom;
1218: } else {
1219: $ttype= &Apache::loncommon::course_type($tdom.'_'.$trest);
1220: $twhere=$env{'course.'.$tdom.'_'.$trest.'.description'};
1221: if ($tsec) {
1222: my $sec_type = 'Section';
1223: if (exists($env{"user.role.gr.$where"})) {
1224: $sec_type = 'Group';
1225: }
1226: $twhere.=' ('.$sec_type.': '.$tsec.')';
1227: }
1228: }
1229: } elsif ($tdom) {
1230: $ttype='Domain';
1231: $twhere=$tdom;
1232: } else {
1233: $ttype='System';
1234: $twhere='/';
1235: }
1.204 bisitz 1236: $output .= "\n<h3>".&mt($ttype).': '.$twhere.'</h3>'."\n<ul>";
1.175 albertel 1237: foreach my $priv (sort(split(/:/,$env{$envkey}))) {
1238: next if (!$priv);
1239:
1240: my ($prv,$restr)=split(/\&/,$priv);
1241: my $trestr='';
1242: if ($restr ne 'F') {
1243: $trestr.=' ('.
1244: join(', ',
1245: map { &Apache::lonnet::plaintext($_) }
1246: (split('',$restr))).') ';
1247: }
1248: $output .= "\n\t".
1249: '<li>'.&Apache::lonnet::plaintext($prv).$trestr.'</li>';
1250: }
1251: $output .= "\n".'</ul>';
1252: }
1253: return $output;
1254: }
1255:
1.110 raeburn 1256: sub build_roletext {
1.212 bisitz 1257: my ($trolecode,$tdom,$trest,$tstatus,$tryagain,$advanced,$tremark,$tbg,$trole,$twhere,$tpstart,$tpend,$nochoose,$button,$switchserver,$reinit) = @_;
1.223 raeburn 1258: my ($roletext,$roletext_end);
1.132 albertel 1259: my $is_dc=($trolecode =~ m/^dc\./);
1260: my $rowspan=($is_dc) ? ''
1261: : ' rowspan="2" ';
1262:
1.110 raeburn 1263: unless ($nochoose) {
1.134 www 1264: my $buttonname=$trolecode;
1265: $buttonname=~s/\W//g;
1.110 raeburn 1266: if (!$button) {
1267: if ($switchserver) {
1.212 bisitz 1268: $roletext.='<td'.$rowspan.' class="'.$tbg.'">'
1269: .'<a href="/adm/switchserver?'.$switchserver.'">'
1270: .&mt('Switch Server')
1271: .'</a></td>';
1.110 raeburn 1272: } else {
1.212 bisitz 1273: $roletext.=('<td'.$rowspan.' class="'.$tbg.'"> </td>');
1.110 raeburn 1274: }
1275: } elsif ($tstatus eq 'is') {
1.212 bisitz 1276: $roletext.='<td'.$rowspan.' class="'.$tbg.'">'.
1277: '<input name="'.$buttonname.'" type="button" value="'.
1.225 bisitz 1278: &mt('Select').'" onclick="javascript:enterrole(this.form,\''.
1.192 raeburn 1279: $trolecode."','".$buttonname.'\');" /></td>';
1.110 raeburn 1280: } elsif ($tryagain) {
1281: $roletext.=
1.212 bisitz 1282: '<td'.$rowspan.' class="'.$tbg.'">'.
1283: '<input name="'.$buttonname.'" type="button" value="'.
1.225 bisitz 1284: &mt('Try Selecting Again').'" onclick="javascript:enterrole(this.form,\''.
1.192 raeburn 1285: $trolecode."','".$buttonname.'\');" /></td>';
1.110 raeburn 1286: } elsif ($advanced) {
1287: $roletext.=
1.212 bisitz 1288: '<td'.$rowspan.' class="'.$tbg.'">'.
1289: '<input name="'.$buttonname.'" type="button" value="'.
1.225 bisitz 1290: &mt('Re-Initialize').'" onclick="javascript:enterrole(this.form,\''.
1.192 raeburn 1291: $trolecode."','".$buttonname.'\');" /></td>';
1.209 raeburn 1292: } elsif ($reinit) {
1293: $roletext.=
1.212 bisitz 1294: '<td'.$rowspan.' class="'.$tbg.'">'.
1295: '<input name="'.$buttonname.'" type="button" value="'.
1.225 bisitz 1296: &mt('Re-Select').'" onclick="javascript:enterrole(this.form,\''.
1.209 raeburn 1297: $trolecode."','".$buttonname.'\');" /></td>';
1.110 raeburn 1298: } else {
1.209 raeburn 1299: $roletext.=
1.212 bisitz 1300: '<td'.$rowspan.' class="'.$tbg.'">'.
1301: '<input name="'.$buttonname.'" type="button" value="'.
1.225 bisitz 1302: &mt('Re-Select').'" onclick="javascript:enterrole(this.form,\''.
1.209 raeburn 1303: $trolecode."','".$buttonname.'\');" /></td>';
1.110 raeburn 1304: }
1305: }
1.165 albertel 1306: if ($trolecode !~ m/^(dc|ca|au|aa)\./) {
1307: $tremark.=&Apache::lonannounce::showday(time,1,
1308: &Apache::lonannounce::readcalendar($tdom.'_'.$trest));
1309: }
1.212 bisitz 1310: $roletext.='<td>'.$trole.'</td>'
1311: .'<td>'.$twhere.'</td>'
1312: .'<td>'.$tpstart.'</td>'
1.223 raeburn 1313: .'<td>'.$tpend.'</td>';
1.132 albertel 1314: if (!$is_dc) {
1.223 raeburn 1315: $roletext_end = '<td colspan="4">'.
1316: $tremark.' '.
1317: '</td>';
1.132 albertel 1318: }
1.223 raeburn 1319: return ($roletext,$roletext_end);
1.110 raeburn 1320: }
1321:
1.202 raeburn 1322: sub check_needs_switchserver {
1323: my ($possiblerole) = @_;
1324: my $needs_switchserver;
1325: my ($role,$where) = split(/\./,$possiblerole,2);
1326: my (undef,$tdom,$twho) = split(/\//,$where);
1327: my ($server_status,$home);
1328: if (($role eq 'ca') || ($role eq 'aa')) {
1329: ($server_status,$home) = &check_author_homeserver($twho,$tdom);
1330: } else {
1331: ($server_status,$home) = &check_author_homeserver($env{'user.name'},
1332: $env{'user.domain'});
1333: }
1334: if ($server_status eq 'switchserver') {
1335: $needs_switchserver = 1;
1336: }
1337: return $needs_switchserver;
1338: }
1339:
1.193 raeburn 1340: sub check_author_homeserver {
1.183 www 1341: my ($uname,$udom)=@_;
1.193 raeburn 1342: if (($uname eq '') || ($udom eq '')) {
1343: return ('fail','');
1344: }
1.183 www 1345: my $home = &Apache::lonnet::homeserver($uname,$udom);
1.193 raeburn 1346: if (&Apache::lonnet::host_domain($home) ne $udom) {
1347: return ('fail',$home);
1348: }
1.183 www 1349: my @ids=&Apache::lonnet::current_machine_ids();
1.193 raeburn 1350: if (grep(/^\Q$home\E$/,@ids)) {
1351: return ('ok',$home);
1352: } else {
1353: return ('switchserver',$home);
1.183 www 1354: }
1355: }
1356:
1.104 raeburn 1357: sub check_fordc {
1358: my ($dcroles,$then) = @_;
1359: my $numdc = 0;
1.118 albertel 1360: if ($env{'user.adv'}) {
1361: foreach my $envkey (sort keys %env) {
1.170 albertel 1362: if ($envkey=~/^user\.role\.dc\.\/($match_domain)\/$/) {
1.104 raeburn 1363: my $dcdom = $1;
1364: my $livedc = 1;
1.118 albertel 1365: my ($tstart,$tend)=split(/\./,$env{$envkey});
1.105 raeburn 1366: if ($tstart && $tstart>$then) { $livedc = 0; }
1367: if ($tend && $tend <$then) { $livedc = 0; }
1.104 raeburn 1368: if ($livedc) {
1369: $$dcroles{$dcdom} = $envkey;
1.105 raeburn 1370: $numdc++;
1.104 raeburn 1371: }
1372: }
1373: }
1374: }
1375: return $numdc;
1376: }
1377:
1.185 raeburn 1378: sub adhoc_course_role {
1379: my ($then) = @_;
1380: my ($cdom,$cnum);
1.201 raeburn 1381: $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
1382: $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.185 raeburn 1383: if (&check_forcc($cdom,$cnum,$then)) {
1384: my $setprivs;
1.198 raeburn 1385: if (!defined($env{'user.role.'.$env{'form.switchrole'}})) {
1.185 raeburn 1386: $setprivs = 1;
1387: } else {
1.198 raeburn 1388: my ($start,$end) = split(/\./,$env{'user.role.'.$env{'form.switchrole'}});
1.185 raeburn 1389: if (($start && ($start>$then || $start == -1)) ||
1390: ($end && $end<$then)) {
1391: $setprivs = 1;
1392: }
1393: }
1394: if ($setprivs) {
1.198 raeburn 1395: if ($env{'form.switchrole'} =~ m-^(in|ta|ep|ad|st|cr)([\w/]*)\./\Q$cdom\E/\Q$cnum\E/?(\w*)$-) {
1.185 raeburn 1396: my $role = $1;
1397: my $custom_role = $2;
1398: my $usec = $3;
1399: if ($role eq 'cr') {
1.199 raeburn 1400: if ($custom_role =~ m-^/$match_domain/$match_username/\w+$-) {
1.185 raeburn 1401: $role .= $custom_role;
1402: } else {
1403: return;
1404: }
1405: }
1.208 raeburn 1406: my (%userroles,%newrole,%newgroups,%group_privs);
1407: my %cgroups =
1408: &Apache::lonnet::get_active_groups($env{'user.domain'},
1409: $env{'user.name'},$cdom,$cnum);
1410: foreach my $group (keys(%cgroups)) {
1411: $group_privs{$group} =
1412: $env{'user.priv.cc./'.$cdom.'/'.$cnum.'./'.$cdom.'/'.$cnum.'/'.$group};
1413: }
1414: $newgroups{'/'.$cdom.'/'.$cnum} = \%group_privs;
1.185 raeburn 1415: my $area = '/'.$cdom.'/'.$cnum;
1416: my $spec = $role.'.'.$area;
1417: if ($usec ne '') {
1418: $spec .= '/'.$usec;
1419: $area .= '/'.$usec;
1420: }
1421: &Apache::lonnet::standard_roleprivs(\%newrole,$role,$cdom,$spec,$cnum,$area);
1.208 raeburn 1422: &Apache::lonnet::set_userprivs(\%userroles,\%newrole,\%newgroups);
1.185 raeburn 1423: my $adhocstart = $then-1;
1424: $userroles{'user.role.'.$spec} = $adhocstart.'.';
1.186 raeburn 1425: &Apache::lonnet::appenv(\%userroles,[$role,'cm']);
1.185 raeburn 1426: }
1427: }
1428: }
1429: return;
1430: }
1431:
1432: sub check_forcc {
1433: my ($cdom,$cnum,$then) = @_;
1434: my $is_cc;
1435: if ($cdom ne '' && $cnum ne '') {
1436: if (&Apache::lonnet::is_course($cdom,$cnum)) {
1437: my $envkey = 'user.role.cc./'.$cdom.'/'.$cnum;
1438: if (defined($env{$envkey})) {
1439: $is_cc = 1;
1440: my ($tstart,$tend)=split(/\./,$env{$envkey});
1441: if ($tstart && $tstart>$then) { $is_cc = 0; }
1442: if ($tend && $tend <$then) { $is_cc = 0; }
1443: }
1444: }
1445: }
1446: return $is_cc;
1447: }
1448:
1.108 raeburn 1449: sub courselink {
1.193 raeburn 1450: my ($dcdom,$rowtype) = @_;
1.109 raeburn 1451: my $courseform=&Apache::loncommon::selectcourse_link
1.152 raeburn 1452: ('rolechoice','dccourse'.$rowtype.'_'.$dcdom,
1453: 'dcdomain'.$rowtype.'_'.$dcdom,'coursedesc'.$rowtype.'_'.
1.173 albertel 1454: $dcdom,$dcdom,undef);
1.138 raeburn 1455: my $hiddenitems = '<input type="hidden" name="dcdomain'.$rowtype.'_'.$dcdom.'" value="'.$dcdom.'" />'.
1456: '<input type="hidden" name="origdom'.$rowtype.'_'.$dcdom.'" value="'.$dcdom.'" />'.
1457: '<input type="hidden" name="dccourse'.$rowtype.'_'.$dcdom.'" value="" />'.
1458: '<input type="hidden" name="coursedesc'.$rowtype.'_'.$dcdom.'" value="" />';
1.112 raeburn 1459: return $courseform.$hiddenitems;
1.109 raeburn 1460: }
1461:
1462: sub coursepick_jscript {
1.184 raeburn 1463: my %lt = &Apache::lonlocal::texthash(
1464: plsu => "Please use the 'Select Course' link to open a separate pick course window where you may select the course you wish to enter.",
1465: youc => 'You can only use this screen to select courses in the current domain.',
1466: );
1.104 raeburn 1467: my $verify_script = <<"END";
1.179 raeburn 1468: <script type="text/javascript">
1.225 bisitz 1469: // <![CDATA[
1.108 raeburn 1470: function verifyCoursePick(caller) {
1471: var numbutton = getIndex(caller)
1.112 raeburn 1472: var pickedCourse = document.rolechoice.elements[numbutton+4].value
1473: var pickedDomain = document.rolechoice.elements[numbutton+2].value
1474: if (document.rolechoice.elements[numbutton+2].value == document.rolechoice.elements[numbutton+3].value) {
1.104 raeburn 1475: if (pickedCourse != '') {
1.108 raeburn 1476: if (numbutton != -1) {
1477: var courseTarget = "cc./"+pickedDomain+"/"+pickedCourse
1478: document.rolechoice.elements[numbutton+1].name = courseTarget
1479: document.rolechoice.submit()
1480: }
1.104 raeburn 1481: }
1482: else {
1.184 raeburn 1483: alert("$lt{'plsu'}");
1.104 raeburn 1484: }
1485: }
1486: else {
1.184 raeburn 1487: alert("$lt{'youc'}")
1.104 raeburn 1488: }
1489: }
1.109 raeburn 1490: function getIndex(caller) {
1.108 raeburn 1491: for (var i=0;i<document.rolechoice.elements.length;i++) {
1.109 raeburn 1492: if (document.rolechoice.elements[i] == caller) {
1.108 raeburn 1493: return i;
1494: }
1495: }
1496: return -1;
1497: }
1.225 bisitz 1498: // ]]>
1.104 raeburn 1499: </script>
1500: END
1.109 raeburn 1501: return $verify_script;
1.104 raeburn 1502: }
1503:
1.193 raeburn 1504: sub coauthorlink {
1505: my ($dcdom,$rowtype) = @_;
1506: my $coauthorform=&Apache::loncommon::selectauthor_link('rolechoice',$dcdom);
1507: my $hiddenitems = '<input type="hidden" name="adhoccauname'.$rowtype.'_'.$dcdom.'" value="" />';
1508: return $coauthorform.$hiddenitems;
1509: }
1510:
1.113 raeburn 1511: sub display_cc_role {
1512: my $rolekey = shift;
1.223 raeburn 1513: my ($roletext,$roletext_end);
1.118 albertel 1514: my $advanced = $env{'user.adv'};
1515: my $tryagain = $env{'form.tryagain'};
1.113 raeburn 1516: unless ($rolekey =~/^error\:/) {
1.171 albertel 1517: if ($rolekey =~ m-^user\.role.cc\./($match_domain)/($match_courseid)$-) {
1.113 raeburn 1518: my $tcourseid = $1.'_'.$2;
1519: my $trolecode = 'cc./'.$1.'/'.$2;
1520: my $twhere;
1.152 raeburn 1521: my $ttype;
1.212 bisitz 1522: my $tbg='LC_roles_is';
1.113 raeburn 1523: my %newhash=&Apache::lonnet::coursedescription($tcourseid);
1524: if (%newhash) {
1525: $twhere=$newhash{'description'}.
1.211 tempelho 1526: ' <span style="LC_fontsize_small">'.
1.212 bisitz 1527: &Apache::loncommon::syllabuswrapper(&mt('Syllabus'),$2,$1).
1.211 tempelho 1528: '</span>';
1.153 raeburn 1529: $ttype = $newhash{'type'};
1.113 raeburn 1530: } else {
1531: $twhere=&mt('Currently not available');
1.118 albertel 1532: $env{'course.'.$tcourseid.'.description'}=$twhere;
1.110 raeburn 1533: }
1.153 raeburn 1534: my $trole = &Apache::lonnet::plaintext('cc',$ttype);
1.113 raeburn 1535: $twhere.="<br />".&mt('Domain').":".$1;
1.223 raeburn 1536: ($roletext,$roletext_end) = &build_roletext($trolecode,$1,$2,'is',$tryagain,$advanced,'',$tbg,$trole,$twhere,'','','',1,'');
1.104 raeburn 1537: }
1538: }
1.223 raeburn 1539: return ($roletext,$roletext_end);
1.104 raeburn 1540: }
1541:
1.192 raeburn 1542: sub adhoc_roles_row {
1.138 raeburn 1543: my ($dcdom,$rowtype) = @_;
1.212 bisitz 1544: my $output = &Apache::loncommon::continue_data_table_row()
1545: .' <td colspan="5">'
1546: .&mt('[_1]Ad hoc[_2] roles in domain [_3] --'
1547: ,'<span class="LC_cusr_emph">','</span>',$dcdom)
1.227 bisitz 1548: .' ';
1.193 raeburn 1549: my $selectcclink = &courselink($dcdom,$rowtype);
1.173 albertel 1550: my $ccrole = &Apache::lonnet::plaintext('cc');
1.182 www 1551: my $carole = &Apache::lonnet::plaintext('ca');
1.193 raeburn 1552: my $selectcalink = &coauthorlink($dcdom,$rowtype);
1.227 bisitz 1553: $output.=$ccrole.': '.$selectcclink
1554: .' | '.$carole.': '.$selectcalink
1.212 bisitz 1555: .&Apache::loncommon::end_data_table_row();
1.108 raeburn 1556: return $output;
1557: }
1558:
1.104 raeburn 1559: sub recent_filename {
1560: my $area=shift;
1.149 www 1561: return 'nohist_recent_'.&escape($area);
1.104 raeburn 1562: }
1563:
1.139 raeburn 1564: sub courseloadpage {
1565: my ($courseid) = @_;
1566: my $startpage;
1.144 albertel 1567: my %entry_settings = &Apache::lonnet::get('nohist_whatsnew',
1568: [$courseid.':courseinit']);
1.139 raeburn 1569: my ($tmp) = %entry_settings;
1.144 albertel 1570: unless ($tmp =~ /^error: 2 /) {
1.139 raeburn 1571: $startpage = $entry_settings{$courseid.':courseinit'};
1572: }
1573: if ($startpage eq '') {
1574: if (exists($env{'environment.course_init_display'})) {
1575: $startpage = $env{'environment.course_init_display'};
1576: }
1577: }
1578: return $startpage;
1579: }
1580:
1.1 harris41 1581: 1;
1582: __END__
1.32 harris41 1583:
1584: =head1 NAME
1585:
1586: Apache::lonroles - User Roles Screen
1587:
1588: =head1 SYNOPSIS
1589:
1590: Invoked by /etc/httpd/conf/srm.conf:
1591:
1592: <Location /adm/roles>
1593: PerlAccessHandler Apache::lonacc
1594: SetHandler perl-script
1595: PerlHandler Apache::lonroles
1596: ErrorDocument 403 /adm/login
1597: ErrorDocument 500 /adm/errorhandler
1598: </Location>
1.64 bowersj2 1599:
1600: =head1 OVERVIEW
1601:
1602: =head2 Choosing Roles
1603:
1604: C<lonroles> is a handler that allows a user to switch roles in
1605: mid-session. LON-CAPA attempts to work with "No Role Specified", the
1606: default role that a user has before selecting a role, as widely as
1607: possible, but certain handlers for example need specification which
1608: course they should act on, etc. Both in this scenario, and when the
1609: handler determines via C<lonnet>'s C<&allowed> function that a certain
1610: action is not allowed, C<lonroles> is used as error handler. This
1611: allows the user to select another role which may have permission to do
1612: what they were trying to do. C<lonroles> can also be accessed via the
1613: B<CRS> button in the Remote Control.
1614:
1615: =begin latex
1616:
1617: \begin{figure}
1618: \begin{center}
1619: \includegraphics[width=0.45\paperwidth,keepaspectratio]{Sample_Roles_Screen}
1620: \caption{\label{Sample_Roles_Screen}Sample Roles Screen}
1621: \end{center}
1622: \end{figure}
1623:
1624: =end latex
1625:
1626: =head2 Role Initialization
1627:
1628: 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.
1.32 harris41 1629:
1630: =head1 INTRODUCTION
1631:
1632: This module enables a user to select what role he wishes to
1633: operate under (instructor, student, teaching assistant, course
1634: coordinator, etc). These roles are pre-established by the actions
1635: of upper-level users.
1636:
1637: This is part of the LearningOnline Network with CAPA project
1638: described at http://www.lon-capa.org.
1639:
1640: =head1 HANDLER SUBROUTINE
1641:
1642: This routine is called by Apache and mod_perl.
1643:
1644: =over 4
1645:
1646: =item *
1647:
1648: Roles Initialization (yes/no)
1649:
1650: =item *
1651:
1652: Get Error Message from Environment
1653:
1654: =item *
1655:
1656: Who is this?
1657:
1658: =item *
1659:
1660: Generate Page Output
1661:
1662: =item *
1663:
1664: Choice or no choice
1665:
1666: =item *
1667:
1668: Table
1669:
1670: =item *
1671:
1672: Privileges
1673:
1674: =back
1675:
1676: =cut
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>