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