Annotation of loncom/auth/lonroles.pm, revision 1.269.2.27
1.1 harris41 1: # The LearningOnline Network with CAPA
2: # User Roles Screen
1.31 www 3: #
1.269.2.27! raeburn 4: # $Id: lonroles.pm,v 1.269.2.26 2016/08/13 21:17:38 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
1.246 droeschl 60: what they were trying to do.
1.210 jms 61:
62: =begin latex
63:
64: \begin{figure}
65: \begin{center}
66: \includegraphics[width=0.45\paperwidth,keepaspectratio]{Sample_Roles_Screen}
67: \caption{\label{Sample_Roles_Screen}Sample Roles Screen}
68: \end{center}
69: \end{figure}
70:
71: =end latex
72:
73: =head2 Role Initialization
74:
75: 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.
76:
77: =head1 INTRODUCTION
78:
79: This module enables a user to select what role he wishes to
80: operate under (instructor, student, teaching assistant, course
81: coordinator, etc). These roles are pre-established by the actions
82: of upper-level users.
83:
84: This is part of the LearningOnline Network with CAPA project
85: described at http://www.lon-capa.org.
86:
87: =head1 HANDLER SUBROUTINE
88:
89: This routine is called by Apache and mod_perl.
90:
91: =over 4
92:
93: =item *
94:
95: Roles Initialization (yes/no)
96:
97: =item *
98:
99: Get Error Message from Environment
100:
101: =item *
102:
103: Who is this?
104:
105: =item *
106:
107: Generate Page Output
108:
109: =item *
110:
111: Choice or no choice
112:
113: =item *
114:
115: Table
116:
117: =item *
118:
119: Privileges
120:
121: =back
122:
123: =cut
124:
125:
1.1 harris41 126: package Apache::lonroles;
127:
128: use strict;
1.118 albertel 129: use Apache::lonnet;
1.7 www 130: use Apache::lonuserstate();
1.269.2.20 raeburn 131: use Apache::Constants qw(:common REDIRECT);
1.2 www 132: use Apache::File();
1.26 www 133: use Apache::lonmenu;
1.29 albertel 134: use Apache::loncommon;
1.104 raeburn 135: use Apache::lonhtmlcommon;
1.57 www 136: use Apache::lonannounce;
1.72 www 137: use Apache::lonlocal;
1.151 www 138: use Apache::lonpageflip();
1.167 albertel 139: use Apache::lonnavdisplay();
1.241 raeburn 140: use Apache::loncoursequeueadmin;
1.269.2.6 raeburn 141: use Apache::longroup;
1.269.2.8 raeburn 142: use Apache::lonrss;
1.120 albertel 143: use GDBM_File;
1.170 albertel 144: use LONCAPA qw(:DEFAULT :match);
1.201 raeburn 145: use HTML::Entities;
1.149 www 146:
1.1 harris41 147:
1.62 matthew 148: sub redirect_user {
1.245 droeschl 149: my ($r,$title,$url,$msg) = @_;
1.62 matthew 150: $msg = $title if (! defined($msg));
1.73 www 151: &Apache::loncommon::content_type($r,'text/html');
1.62 matthew 152: &Apache::loncommon::no_cache($r);
153: $r->send_http_header;
1.269.2.1 raeburn 154: my $swinfo=&Apache::lonmenu::rawconfig();
1.228 bisitz 155:
156: # Breadcrumbs
157: my $brcrum = [{'href' => $url,
158: 'text' => 'Switching Role'},];
1.147 albertel 159: my $start_page = &Apache::loncommon::start_page('Switching Role',undef,
1.228 bisitz 160: {'redirect' => [1,$url],
161: 'bread_crumbs' => $brcrum,});
1.147 albertel 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.269.2.1 raeburn 169: <script type="text/javascript">
170: // <![CDATA[
171: $swinfo
172: // ]]>
173: </script>
1.222 bisitz 174: <p>$msg</p>
1.147 albertel 175: $end_page
1.62 matthew 176: ENDREDIR
177: return;
178: }
179:
1.150 www 180: sub error_page {
181: my ($r,$error,$dest)=@_;
182: &Apache::loncommon::content_type($r,'text/html');
183: &Apache::loncommon::no_cache($r);
184: $r->send_http_header;
185: return OK if $r->header_only;
1.228 bisitz 186: # Breadcrumbs
187: my $brcrum = [{'href' => $dest,
188: 'text' => 'Problems during Course Initialization'},];
189: $r->print(&Apache::loncommon::start_page('Problems during Course Initialization',
190: undef,
191: {'bread_crumbs' => $brcrum,})
192: );
193: $r->print(
1.225 bisitz 194: '<script type="text/javascript">'.
195: '// <![CDATA['.
196: &Apache::lonmenu::rawconfig().
197: '// ]]>'.
198: '</script>'.
199: '<p class="LC_error">'.&mt('The following problems occurred:').
1.228 bisitz 200: '<br />'.
1.150 www 201: $error.
1.228 bisitz 202: '</p><br /><a href="'.$dest.'">'.&mt('Continue').'</a>'
203: );
204: $r->print(&Apache::loncommon::end_page());
1.150 www 205: }
206:
1.1 harris41 207: sub handler {
1.10 www 208:
1.1 harris41 209: my $r = shift;
210:
1.269.2.20 raeburn 211: # Check for critical messages and redirect if present.
212: my ($redirect,$url) = &Apache::loncommon::critical_redirect(300);
213: if ($redirect) {
214: &Apache::loncommon::content_type($r,'text/html');
215: $r->header_out(Location => $url);
216: return REDIRECT;
217: }
218:
1.6 www 219: my $now=time;
1.118 albertel 220: my $then=$env{'user.login.time'};
1.226 raeburn 221: my $refresh=$env{'user.refresh.time'};
1.260 raeburn 222: my $update=$env{'user.update.time'};
1.226 raeburn 223: if (!$refresh) {
224: $refresh = $then;
225: }
1.260 raeburn 226: if (!$update) {
227: $update = $then;
228: }
229:
1.269.2.2 raeburn 230: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'});
231:
232: # -------------------------------------------------- Check if setting hot list
233: my $hotlist;
234: if ($env{'form.action'} eq 'verify_and_change_rolespref') {
235: $hotlist = &Apache::lonpreferences::verify_and_change_rolespref($r);
236: }
237:
1.260 raeburn 238: # -------------------------------------------------------- Check for new roles
239: my $updateresult;
1.269.2.2 raeburn 240: if ($env{'form.state'} eq 'doupdate') {
1.260 raeburn 241: my $show_course=&Apache::loncommon::show_course();
242: my $checkingtxt;
243: if ($show_course) {
244: $checkingtxt = &mt('Checking for new courses ...');
245: } else {
246: $checkingtxt = &mt('Checking for new roles ...');
247: }
1.269.2.2 raeburn 248: $updateresult = $checkingtxt;
1.260 raeburn 249: $updateresult .= &update_session_roles();
250: &Apache::lonnet::appenv({'user.update.time' => $now});
251: $update = $now;
1.269.2.2 raeburn 252: &Apache::loncoursequeueadmin::reqauthor_check();
253: }
254:
255: # -------------------------------------------------- Check for author requests
256: my $reqauthor;
257: if ($env{'form.state'} eq 'requestauthor') {
258: $reqauthor = &Apache::loncoursequeueadmin::process_reqauthor(\$update);
1.260 raeburn 259: }
260:
1.6 www 261: my $envkey;
1.107 raeburn 262: my %dcroles = ();
1.269.2.27! raeburn 263: my %dhroles = ();
! 264: my ($numdc,$numdh,$numadhoc) = &check_for_adhoc(\%dcroles,\%dhroles,$update,$then);
1.269.2.20 raeburn 265: my $loncaparev = $r->dir_config('lonVersion');
1.10 www 266:
1.6 www 267: # ================================================================== Roles Init
1.118 albertel 268: if ($env{'form.selectrole'}) {
1.188 www 269:
270: my $locknum=&Apache::lonnet::get_locks();
271: if ($locknum) { return 409; }
272:
1.269.2.27! raeburn 273: my $custom_adhoc;
1.134 www 274: if ($env{'form.newrole'}) {
275: $env{'form.'.$env{'form.newrole'}}=1;
1.269.2.27! raeburn 276: # Check if this is a Domain Helpdesk role trying to enter a course
! 277: if ($env{'form.newrole'} =~ m{^cr/($match_domain)/\1\-domainconfig/\w+\./\1/$match_courseid$}) {
! 278: if ($dhroles{$1}) {
! 279: $custom_adhoc = 1;
! 280: }
! 281: }
1.134 www 282: }
1.118 albertel 283: if ($env{'request.course.id'}) {
1.185 raeburn 284: # Check if user is CC trying to select a course role
285: if ($env{'form.switchrole'}) {
1.252 raeburn 286: my $switch_is_active;
287: if (defined($env{'user.role.'.$env{'form.switchrole'}})) {
288: my ($start,$end) = split(/\./,$env{'user.role.'.$env{'form.switchrole'}});
289: if (!$end || $end > $now) {
1.260 raeburn 290: if (!$start || $start < $update) {
1.252 raeburn 291: $switch_is_active = 1;
292: }
293: }
294: }
295: unless ($switch_is_active) {
1.260 raeburn 296: &adhoc_course_role($refresh,$update,$then);
1.185 raeburn 297: }
298: }
1.118 albertel 299: my %temp=('logout_'.$env{'request.course.id'} => time);
1.33 www 300: &Apache::lonnet::put('email_status',\%temp);
1.118 albertel 301: &Apache::lonnet::delenv('user.state.'.$env{'request.course.id'});
1.100 albertel 302: }
1.269.2.22 raeburn 303: &Apache::lonnet::appenv({"request.course.id" => '',
304: "request.course.fn" => '',
305: "request.course.uri" => '',
306: "request.course.sec" => '',
307: "request.course.tied" => '',
308: "request.course.timechecked" => '',
309: "request.role" => 'cm',
310: "request.role.adv" => $env{'user.adv'},
311: "request.role.domain" => $env{'user.domain'}});
1.269.2.27! raeburn 312: # Check if Domain Helpdesk role trying to enter a course needs privs to be created
! 313: if ($env{'form.newrole'} =~ m{^cr/($match_domain)/\1\-domainconfig/(\w+)\./\1/($match_courseid)$}) {
! 314: my $cdom = $1;
! 315: my $rolename = $2;
! 316: my $cnum = $3;
! 317: if ($custom_adhoc) {
! 318: my %adhocroles = &Apache::lonnet::userenvironment($env{'user.domain'},$env{'user.name'},
! 319: 'adhocroles.'.$cdom);
! 320: if (keys(%adhocroles)) {
! 321: my @adhoc = split(',',$adhocroles{'adhocroles.'.$cdom});
! 322: if (grep(/^\Q$rolename\E$/,@adhoc)) {
! 323: if (&Apache::lonnet::check_adhoc_privs($cdom,$cnum,$update,$refresh,$now,
! 324: "cr/$cdom/$cdom".'-domainconfig/'.$rolename)) {
! 325: &Apache::lonnet::appenv({"environment.internal.$cdom.$cnum.cr/$cdom/$cdom".'-domainconfig/'."$rolename.adhoc" => time});
! 326: }
! 327: }
! 328: }
! 329: }
! 330: } elsif ($numdc > 0) {
1.182 www 331: # Check if user is a DC trying to enter a course or author space and needs privs to be created
1.269.2.16 raeburn 332: foreach my $envkey (keys(%env)) {
1.240 raeburn 333: # Is this an ad-hoc Coordinator role?
334: if (my ($ccrole,$domain,$coursenum) =
335: ($envkey =~ m-^form\.(cc|co)\./($match_domain)/($match_courseid)$-)) {
1.146 raeburn 336: if ($dcroles{$domain}) {
1.269.2.2 raeburn 337: if (&Apache::lonnet::check_adhoc_privs($domain,$coursenum,
338: $update,$refresh,$now,$ccrole)) {
339: &Apache::lonnet::appenv({"environment.internal.$domain.$coursenum.$ccrole.adhoc" => time});
340: }
1.182 www 341: }
342: last;
343: }
1.193 raeburn 344: # Is this an ad-hoc CA-role?
1.183 www 345: if (my ($domain,$user) =
346: ($envkey =~ m-^form\.ca\./($match_domain)/($match_username)$-)) {
1.206 raeburn 347: if (($domain eq $env{'user.domain'}) && ($user eq $env{'user.name'})) {
348: delete($env{$envkey});
349: $env{'form.au./'.$domain.'/'} = 1;
350: my ($server_status,$home) = &check_author_homeserver($user,$domain);
351: if ($server_status eq 'switchserver') {
352: my $trolecode = 'au./'.$domain.'/';
1.248 raeburn 353: my $switchserver = '/adm/switchserver?otherserver='.$home.'&role='.$trolecode;
1.206 raeburn 354: $r->internal_redirect($switchserver);
1.269.2.8 raeburn 355: return OK;
1.206 raeburn 356: }
357: last;
358: }
359: if (my ($castart,$caend) = ($env{'user.role.ca./'.$domain.'/'.$user} =~ /^(\d*)\.(\d*)$/)) {
360: if (((($castart) && ($castart < $now)) || !$castart) &&
361: ((!$caend) || (($caend) && ($caend > $now)))) {
362: my ($server_status,$home) = &check_author_homeserver($user,$domain);
363: if ($server_status eq 'switchserver') {
364: my $trolecode = 'ca./'.$domain.'/'.$user;
1.248 raeburn 365: my $switchserver = '/adm/switchserver?otherserver='.$home.'&role='.$trolecode;
1.206 raeburn 366: $r->internal_redirect($switchserver);
1.269.2.8 raeburn 367: return OK;
1.206 raeburn 368: }
369: last;
370: }
371: }
372: # Check if author blocked ca-access
1.190 www 373: my %blocked=&Apache::lonnet::get('environment',['domcoord.author'],$domain,$user);
374: if ($blocked{'domcoord.author'} eq 'blocked') {
1.206 raeburn 375: delete($env{$envkey});
376: $env{'user.error.msg'}=':::1:User '.$user.' in domain '.$domain.' blocked domain coordinator access';
377: last;
1.190 www 378: }
1.193 raeburn 379: if ($dcroles{$domain}) {
380: my ($server_status,$home) = &check_author_homeserver($user,$domain);
381: if (($server_status eq 'ok') || ($server_status eq 'switchserver')) {
1.260 raeburn 382: &Apache::lonnet::check_adhoc_privs($domain,$user,$update,
1.230 raeburn 383: $refresh,$now,'ca');
1.193 raeburn 384: if ($server_status eq 'switchserver') {
385: my $trolecode = 'ca./'.$domain.'/'.$user;
386: my $switchserver = '/adm/switchserver?'
1.248 raeburn 387: .'otherserver='.$home.'&role='.$trolecode;
1.193 raeburn 388: $r->internal_redirect($switchserver);
1.269.2.8 raeburn 389: return OK;
1.193 raeburn 390: }
391: } else {
392: delete($env{$envkey});
393: }
1.183 www 394: } else {
395: delete($env{$envkey});
1.182 www 396: }
397: last;
398: }
1.107 raeburn 399: }
400: }
401:
1.269.2.16 raeburn 402: foreach $envkey (keys(%env)) {
1.40 matthew 403: next if ($envkey!~/^user\.role\./);
1.102 raeburn 404: my ($where,$trolecode,$role,$tstatus,$tend,$tstart);
1.260 raeburn 405: &Apache::lonnet::role_status($envkey,$update,$refresh,$now,\$role,\$where,
1.218 raeburn 406: \$trolecode,\$tstatus,\$tstart,\$tend);
1.118 albertel 407: if ($env{'form.'.$trolecode}) {
1.55 albertel 408: if ($tstatus eq 'is') {
409: $where=~s/^\///;
410: my ($cdom,$cnum,$csec)=split(/\//,$where);
1.255 raeburn 411: if (($cnum) && ($role ne 'ca') && ($role ne 'aa')) {
412: my $home = $env{'course.'.$cdom.'_'.$cnum.'.home'};
413: my @ids = &Apache::lonnet::current_machine_ids();
414: unless ($loncaparev eq '' && $home && grep(/^\Q$home\E$/,@ids)) {
415: my %curr_reqd_hash = &Apache::lonnet::userenvironment($cdom,$cnum,'internal.releaserequired');
1.256 raeburn 416: if ($curr_reqd_hash{'internal.releaserequired'} ne '') {
1.255 raeburn 417: my ($switchserver,$switchwarning) =
1.269.2.22 raeburn 418: &Apache::loncommon::check_release_required($loncaparev,$cdom.'_'.$cnum,$trolecode,
419: $curr_reqd_hash{'internal.releaserequired'});
1.256 raeburn 420: if ($switchwarning ne '' || $switchserver ne '') {
421: &Apache::loncommon::content_type($r,'text/html');
422: &Apache::loncommon::no_cache($r);
423: $r->send_http_header;
1.269.2.22 raeburn 424: $r->print(&Apache::loncommon::check_release_result($switchwarning,$switchserver));
1.256 raeburn 425: return OK;
1.255 raeburn 426: }
427: }
428: }
429: }
1.137 raeburn 430: # check for course groups
431: my %coursegroups = &Apache::lonnet::get_active_groups(
432: $env{'user.domain'},$env{'user.name'},$cdom, $cnum);
433: my $cgrps = join(':',keys(%coursegroups));
434:
1.111 albertel 435: # store role if recent_role list being kept
1.118 albertel 436: if ($env{'environment.recentroles'}) {
1.158 albertel 437: my %frozen_roles =
438: &Apache::lonhtmlcommon::get_recent_frozen('roles',$env{'environment.recentrolesn'});
1.111 albertel 439: &Apache::lonhtmlcommon::store_recent('roles',
1.158 albertel 440: $trolecode,' ',$frozen_roles{$trolecode});
1.111 albertel 441: }
442:
443:
1.53 www 444: # check for keyed access
1.55 albertel 445: if (($role eq 'st') &&
1.118 albertel 446: ($env{'course.'.$cdom.'_'.$cnum.'.keyaccess'} eq 'yes')) {
1.89 www 447: # who is key authority?
448: my $authdom=$cdom;
449: my $authnum=$cnum;
1.118 albertel 450: if ($env{'course.'.$cdom.'_'.$cnum.'.keyauth'}) {
1.89 www 451: ($authnum,$authdom)=
1.172 albertel 452: split(/:/,$env{'course.'.$cdom.'_'.$cnum.'.keyauth'});
1.89 www 453: }
454: # check with key authority
455: unless (&Apache::lonnet::validate_access_key(
1.118 albertel 456: $env{'environment.key.'.$cdom.'_'.$cnum},
1.89 www 457: $authdom,$authnum)) {
1.53 www 458: # there is no valid key
1.118 albertel 459: if ($env{'form.newkey'}) {
1.53 www 460: # student attempts to register a new key
1.89 www 461: &Apache::loncommon::content_type($r,'text/html');
462: &Apache::loncommon::no_cache($r);
463: $r->send_http_header;
464: my $swinfo=&Apache::lonmenu::rawconfig();
1.147 albertel 465: my $start_page=&Apache::loncommon::start_page
1.89 www 466: ('Verifying Access Key to Unlock this Course');
1.147 albertel 467: my $end_page=&Apache::loncommon::end_page();
1.90 www 468: my $buttontext=&mt('Enter Course');
469: my $message=&mt('Successfully registered key');
470: my $assignresult=
471: &Apache::lonnet::assign_access_key(
1.118 albertel 472: $env{'form.newkey'},
1.90 www 473: $authdom,$authnum,
1.91 www 474: $cdom,$cnum,
1.118 albertel 475: $env{'user.domain'},
476: $env{'user.name'},
1.204 bisitz 477: &mt('Assigned from [_1] at [_2] for [_3]'
478: ,$ENV{'REMOTE_ADDR'}
479: ,&Apache::lonlocal::locallocaltime()
480: ,$trolecode)
481: );
1.90 www 482: unless ($assignresult eq 'ok') {
483: $assignresult=~s/^error\:\s*//;
484: $message=&mt($assignresult).
485: '<br /><a href="/adm/logout">'.
1.89 www 486: &mt('Logout').'</a>';
1.90 www 487: $buttontext=&mt('Re-Enter Key');
488: }
1.89 www 489: $r->print(<<ENDENTEREDKEY);
1.147 albertel 490: $start_page
1.179 raeburn 491: <script type="text/javascript">
1.225 bisitz 492: // <![CDATA[
1.89 www 493: $swinfo
1.225 bisitz 494: // ]]>
1.89 www 495: </script>
1.225 bisitz 496: <form action="" method="post">
1.89 www 497: <input type="hidden" name="selectrole" value="1" />
498: <input type="hidden" name="$trolecode" value="1" />
1.211 tempelho 499: <span class="LC_fontsize_large">$message</span><br />
1.89 www 500: <input type="submit" value="$buttontext" />
501: </form>
1.147 albertel 502: $end_page
1.89 www 503: ENDENTEREDKEY
504: return OK;
1.55 albertel 505: } else {
1.53 www 506: # print form to enter a new key
1.73 www 507: &Apache::loncommon::content_type($r,'text/html');
1.55 albertel 508: &Apache::loncommon::no_cache($r);
509: $r->send_http_header;
510: my $swinfo=&Apache::lonmenu::rawconfig();
1.147 albertel 511: my $start_page=&Apache::loncommon::start_page
1.55 albertel 512: ('Enter Access Key to Unlock this Course');
1.147 albertel 513: my $end_page=&Apache::loncommon::end_page();
1.55 albertel 514: $r->print(<<ENDENTERKEY);
1.147 albertel 515: $start_page
1.179 raeburn 516: <script type="text/javascript">
1.225 bisitz 517: // <![CDATA[
1.53 www 518: $swinfo
1.225 bisitz 519: // ]]>
1.53 www 520: </script>
1.225 bisitz 521: <form action="" method="post">
1.89 www 522: <input type="hidden" name="selectrole" value="1" />
523: <input type="hidden" name="$trolecode" value="1" />
1.118 albertel 524: <input type="text" size="20" name="newkey" value="$env{'form.newkey'}" />
1.53 www 525: <input type="submit" value="Enter key" />
526: </form>
1.147 albertel 527: $end_page
1.53 www 528: ENDENTERKEY
1.55 albertel 529: return OK;
530: }
531: }
532: }
1.118 albertel 533: &Apache::lonnet::log($env{'user.domain'},
534: $env{'user.name'},
535: $env{'user.home'},
1.87 www 536: "Role ".$trolecode);
1.101 albertel 537:
1.56 www 538: &Apache::lonnet::appenv(
1.186 raeburn 539: {'request.role' => $trolecode,
540: 'request.role.domain' => $cdom,
541: 'request.course.sec' => $csec,
542: 'request.course.groups' => $cgrps});
1.101 albertel 543: my $tadv=0;
1.62 matthew 544:
1.125 www 545: if (($cnum) && ($role ne 'ca') && ($role ne 'aa')) {
1.152 raeburn 546: my $msg;
1.269.2.8 raeburn 547: my ($furl,$ferr)=
548: &Apache::lonuserstate::readmap($cdom.'/'.$cnum);
549: unless ($ferr) {
550: unless (($env{'form.switchrole'}) ||
551: ($env{"environment.internal.$cdom.$cnum.$role.adhoc"})) {
552: &Apache::lonnet::put('nohist_crslastlogin',
553: {$env{'user.name'}.':'.$env{'user.domain'}.
554: ':'.$csec.':'.$role => $now},$cdom,$cnum);
555: }
556: my ($feeds,$syllabus_time);
557: &Apache::lonrss::advertisefeeds($cnum,$cdom,undef,\$feeds);
558: &Apache::lonnet::appenv({'request.course.feeds' => $feeds});
1.269.2.11 raeburn 559: &Apache::lonnet::get_numsuppfiles($cnum,$cdom,1);
1.269.2.8 raeburn 560: unless ($env{'course.'.$cdom.'_'.$cnum.'.updatedsyllabus'}) {
561: unless (($env{'course.'.$cdom.'_'.$cnum.'.externalsyllabus'}) ||
562: ($env{'course.'.$cdom.'_'.$cnum.'.uploadedsyllabus'})) {
563: my %syllabus=&Apache::lonnet::dump('syllabus',$cdom,$cnum);
564: $syllabus_time = $syllabus{'uploaded.lastmodified'};
565: if ($syllabus_time) {
566: &Apache::lonnet::appenv({'request.course.syllabustime' => $syllabus_time});
567: }
568: }
569: }
1.269.2.2 raeburn 570: }
1.118 albertel 571: if (($env{'form.orgurl'}) &&
1.269.2.15 raeburn 572: ($env{'form.orgurl'}!~/^\/adm\/flip/) &&
573: ($env{'form.orgurl'} ne '/adm/roles')) {
1.118 albertel 574: my $dest=$env{'form.orgurl'};
1.219 raeburn 575: if ($env{'form.symb'}) {
576: if ($dest =~ /\?/) {
577: $dest .= '&';
578: } else {
1.269.2.15 raeburn 579: $dest .= '?';
1.219 raeburn 580: }
581: $dest .= 'symb='.$env{'form.symb'};
582: }
1.117 albertel 583: if (&Apache::lonnet::allowed('adv') eq 'F') { $tadv=1; }
1.186 raeburn 584: &Apache::lonnet::appenv({'request.role.adv'=>$tadv});
1.150 www 585: if (($ferr) && ($tadv)) {
586: &error_page($r,$ferr,$dest);
587: } else {
1.255 raeburn 588: if ($dest =~ m{^/adm/coursedocs\?folderpath}) {
589: if ($env{'request.course.id'} eq $cdom.'_'.$cnum) {
590: my $chome = &Apache::lonnet::homeserver($cnum,$cdom);
1.268 raeburn 591: &Apache::loncommon::update_content_constraints($cdom,$cnum,$chome,
592: $cdom.'_'.$cnum);
1.255 raeburn 593: }
594: }
1.150 www 595: $r->internal_redirect($dest);
596: }
1.55 albertel 597: return OK;
598: } else {
1.155 albertel 599: if (!$env{'request.course.id'}) {
1.55 albertel 600: &Apache::lonnet::appenv(
1.186 raeburn 601: {"request.course.id" => $cdom.'_'.$cnum});
1.61 www 602: $furl='/adm/roles?tryagain=1';
1.221 bisitz 603: $msg='<p><span class="LC_error">'
604: .&mt('Could not initialize [_1] at this time.',
605: $env{'course.'.$cdom.'_'.$cnum.'.description'})
606: .'</span></p>'
607: .'<p>'.&mt('Please try again.').'</p>'
608: .'<p>'.$ferr.'</p>';
1.55 albertel 609: }
1.117 albertel 610: if (&Apache::lonnet::allowed('adv') eq 'F') { $tadv=1; }
1.186 raeburn 611: &Apache::lonnet::appenv({'request.role.adv'=>$tadv});
1.152 raeburn 612:
1.150 www 613: if (($ferr) && ($tadv)) {
614: &error_page($r,$ferr,$furl);
615: } else {
616: # Check to see if the user is a CC entering a course
617: # for the first time
1.240 raeburn 618: if ((($role eq 'cc') || ($role eq 'co'))
1.269.2.18 raeburn 619: && ($env{'course.'.$cdom.'_'.$cnum.'.course.helper.not.run'})) {
1.150 www 620: $furl = "/adm/helper/course.initialization.helper";
621: # Send the user to the course they selected
622: } elsif ($env{'request.course.id'}) {
1.269.2.3 raeburn 623: my ($dest,$destsymb,$checkenc);
624: $dest = $env{'form.destinationurl'};
625: $destsymb = $env{'form.destsymb'};
626: if ($dest ne '') {
627: if ($env{'form.switchrole'}) {
628: if ($destsymb ne '') {
629: if ($destsymb !~ m{^/enc/}) {
630: unless ($env{'request.role.adv'}) {
631: $checkenc = 1;
632: }
633: }
634: }
635: if ($dest =~ m{^/enc/}) {
636: if ($env{'request.role.adv'}) {
637: $dest = &Apache::lonenc::unencrypted($dest);
638: if ($destsymb eq '') {
1.269.2.4 raeburn 639: ($destsymb) = ($dest =~ /(?:\?|\&)symb=([^\&]*)/);
1.269.2.3 raeburn 640: $destsymb = &unescape($destsymb);
641: }
642: }
643: } else {
644: if ($destsymb eq '') {
1.269.2.4 raeburn 645: ($destsymb) = ($dest =~ /(?:\?|\&)symb=([^\&]+)/);
1.269.2.3 raeburn 646: $destsymb = &unescape($destsymb);
647: }
648: unless ($env{'request.role.adv'}) {
649: $checkenc = 1;
650: }
651: }
652: if (($checkenc) && ($destsymb ne '')) {
653: my ($encstate,$unencsymb,$res);
1.269.2.7 raeburn 654: $unencsymb = &Apache::lonnet::symbclean($destsymb);
1.269.2.3 raeburn 655: (undef,undef,$res) = &Apache::lonnet::decode_symb($unencsymb);
656: &Apache::lonnet::symbverify($unencsymb,$res,\$encstate);
657: if ($encstate) {
658: if (($dest ne '') && ($dest !~ m{^/enc/})) {
659: $dest=&Apache::lonenc::encrypted($dest);
660: }
661: }
662: }
663: }
1.269.2.4 raeburn 664: unless (($dest =~ m{^/enc/}) || ($dest =~ /(\?|\&)symb=.+___\d+___.+/)) {
1.269.2.3 raeburn 665: if (($destsymb ne '') && ($destsymb !~ m{^/enc/})) {
666: my $esc_symb = &escape($destsymb);
667: $dest .= '?symb='.$esc_symb;
668: }
1.203 raeburn 669: }
1.245 droeschl 670: &redirect_user($r, &mt('Entering [_1]',
1.269.2.20 raeburn 671: $env{'course.'.$cdom.'_'.$cnum.'.description'}),
1.245 droeschl 672: $dest, $msg);
1.185 raeburn 673: return OK;
674: }
1.150 www 675: if (&Apache::lonnet::allowed('whn',
676: $env{'request.course.id'})
677: || &Apache::lonnet::allowed('whn',
678: $env{'request.course.id'}.'/'
679: .$env{'request.course.sec'})
680: ) {
1.269.2.16 raeburn 681: my $startpage = &courseloadpage($env{'request.course.id'});
1.150 www 682: unless ($startpage eq 'firstres') {
1.204 bisitz 683: $msg = &mt('Entering [_1] ...',
1.269.2.16 raeburn 684: $env{'course.'.$env{'request.course.id'}.'.description'});
1.245 droeschl 685: &redirect_user($r, &mt('New in course'),
686: '/adm/whatsnew?refpage=start', $msg);
1.150 www 687: return OK;
688: }
689: }
690: }
1.269.2.17 raeburn 691: # Are we allowed to look at the first resource?
1.269.2.23 raeburn 692: my $access;
1.269.2.17 raeburn 693: if ($furl =~ m{^(/adm/wrapper|)/ext/}) {
694: # If it's an external resource,
695: # strip off the symb argument and possible query
696: my ($exturl,$symb) = ($furl =~ m{^(.+)(?:\?|\&)symb=(.+)$});
697: # Unencode $symb
698: $symb = &unescape($symb);
699: # Then check for permission
1.269.2.23 raeburn 700: $access = &Apache::lonnet::allowed('bre',$exturl,$symb);
1.269.2.17 raeburn 701: # For other resources just check for permission
1.269.2.23 raeburn 702: } else {
703: $access = &Apache::lonnet::allowed('bre',$furl);
704: }
705: if (!$access) {
1.269.2.17 raeburn 706: $furl = &Apache::lonpageflip::first_accessible_resource();
1.269.2.23 raeburn 707: } elsif ($access eq 'B') {
708: $furl = '/adm/navmaps?showOnlyHomework=1';
1.269.2.17 raeburn 709: }
1.162 albertel 710: $msg = &mt('Entering [_1] ...',
1.269.2.16 raeburn 711: $env{'course.'.$cdom.'_'.$cnum.'.description'});
1.245 droeschl 712: &redirect_user($r, &mt('Entering [_1]',
1.269.2.16 raeburn 713: $env{'course.'.$cdom.'_'.$cnum.'.description'}),
1.245 droeschl 714: $furl, $msg);
1.58 bowersj2 715: }
1.124 albertel 716: return OK;
1.55 albertel 717: }
718: }
1.62 matthew 719: #
720: # Send the user to the construction space they selected
1.125 www 721: if ($role =~ /^(au|ca|aa)$/) {
1.62 matthew 722: my $redirect_url = '/priv/';
723: if ($role eq 'au') {
1.262 www 724: $redirect_url.=$env{'user.domain'}.'/'.$env{'user.name'};
1.62 matthew 725: } else {
1.263 www 726: $redirect_url .= $where;
1.62 matthew 727: }
728: $redirect_url .= '/';
1.269.2.10 raeburn 729: &redirect_user($r,&mt('Entering Authoring Space'),
1.62 matthew 730: $redirect_url);
731: return OK;
732: }
1.104 raeburn 733: if ($role eq 'dc') {
1.108 raeburn 734: my $redirect_url = '/adm/menu/';
735: &redirect_user($r,&mt('Loading Domain Coordinator Menu'),
1.104 raeburn 736: $redirect_url);
1.108 raeburn 737: return OK;
1.104 raeburn 738: }
1.269.2.27! raeburn 739: if ($role eq 'dh') {
! 740: my $redirect_url = '/adm/menu/';
! 741: &redirect_user($r,&mt('Loading Domain Helpdesk Menu'),
! 742: $redirect_url);
! 743: return OK;
! 744: }
1.220 raeburn 745: if ($role eq 'sc') {
746: my $redirect_url = '/adm/grades?command=scantronupload';
747: &redirect_user($r,&mt('Loading Data Upload Page'),
748: $redirect_url);
749: return OK;
750: }
1.55 albertel 751: }
752: }
1.6 www 753: }
1.40 matthew 754: }
1.44 www 755:
1.10 www 756:
1.6 www 757: # =============================================================== No Roles Init
1.10 www 758:
1.73 www 759: &Apache::loncommon::content_type($r,'text/html');
1.30 albertel 760: &Apache::loncommon::no_cache($r);
1.10 www 761: $r->send_http_header;
762: return OK if $r->header_only;
763:
1.224 raeburn 764: my $crumbtext = 'User Roles';
765: my $pagetitle = 'My Roles';
766: my $recent = &mt('Recent Roles');
1.269.2.10 raeburn 767: my $standby = &mt('Role selected. Please stand by.');
1.224 raeburn 768: my $show_course=&Apache::loncommon::show_course();
769: if ($show_course) {
770: $crumbtext = 'Courses';
771: $pagetitle = 'My Courses';
772: $recent = &mt('Recent Courses');
1.269.2.10 raeburn 773: $standby = &mt('Course selected. Please stand by.');
1.224 raeburn 774: }
775: my $brcrum =[{href=>"/adm/roles",text=>$crumbtext}];
1.269.2.2 raeburn 776:
777: my %roles_in_env;
778: my $showcount = &roles_from_env(\%roles_in_env,$update);
779:
1.52 www 780: my $swinfo=&Apache::lonmenu::rawconfig();
1.269.2.18 raeburn 781: my %domdefs=&Apache::lonnet::get_domain_defaults($env{'user.domain'});
782: my $cattype = 'std';
783: if ($domdefs{'catauth'}) {
784: $cattype = $domdefs{'catauth'};
785: }
786: my $funcs = &get_roles_functions($showcount,$cattype);
1.269.2.26 raeburn 787: my $crumbsright;
788: if ($env{'browser.mobile'}) {
789: $crumbsright = $funcs;
790: undef($funcs);
791: }
792: my $start_page=&Apache::loncommon::start_page($pagetitle,undef,{bread_crumbs=>$brcrum,
793: bread_crumbs_component=>$crumbsright});
1.269.2.24 raeburn 794: &js_escape(\$standby);
1.269.2.2 raeburn 795: my $noscript='<br /><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 796:
1.10 www 797: $r->print(<<ENDHEADER);
1.147 albertel 798: $start_page
1.269.2.2 raeburn 799: $funcs
1.179 raeburn 800: <noscript>
801: $noscript
802: </noscript>
803: <script type="text/javascript">
1.225 bisitz 804: // <![CDATA[
1.26 www 805: $swinfo
806: window.focus();
1.134 www 807:
808: active=true;
809:
810: function enterrole (thisform,rolecode,buttonname) {
811: if (active) {
812: active=false;
813: document.title='$standby';
814: window.status='$standby';
815: thisform.newrole.value=rolecode;
816: thisform.submit();
817: } else {
818: alert('$standby');
1.260 raeburn 819: }
820: }
821:
1.269.2.2 raeburn 822: function rolesView (caller) {
823: if ((caller == 'showall') || (caller == 'noshowall')) {
824: document.rolechoice.display.value = caller;
825: } else {
826: if ((caller == 'doupdate') || (caller == 'requestauthor') ||
827: (caller == 'queued')) {
828: document.rolechoice.state.value = caller;
829: }
830: }
831: document.rolechoice.selectrole.value='';
832: document.rolechoice.submit();
1.134 www 833: }
1.260 raeburn 834:
1.225 bisitz 835: // ]]>
1.26 www 836: </script>
1.10 www 837: ENDHEADER
1.6 www 838:
1.2 www 839: # ------------------------------------------ Get Error Message from Environment
840:
1.118 albertel 841: my ($fn,$priv,$nochoose,$error,$msg)=split(/:/,$env{'user.error.msg'});
842: if ($env{'user.error.msg'}) {
1.55 albertel 843: $r->log_reason(
1.118 albertel 844: "$msg for $env{'user.name'} domain $env{'user.domain'} access $priv",$fn);
1.12 www 845: }
1.1 harris41 846:
1.61 www 847: # ------------------------------------------------- Can this user re-init, etc?
1.6 www 848:
1.118 albertel 849: my $advanced=$env{'user.adv'};
1.61 www 850: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['tryagain']);
1.118 albertel 851: my $tryagain=$env{'form.tryagain'};
1.209 raeburn 852: my $reinit=$env{'user.reinit'};
853: delete $env{'user.reinit'};
1.6 www 854:
1.2 www 855: # -------------------------------------------------------- Generate Page Output
1.6 www 856: # --------------------------------------------------------------- Error Header?
1.2 www 857: if ($error) {
1.187 bisitz 858: $r->print("<h1>".&mt('LON-CAPA Access Control')."</h1>");
1.174 albertel 859: $r->print("<!-- LONCAPAACCESSCONTROLERRORSCREEN --><hr /><pre>");
860: if ($priv ne '') {
1.187 bisitz 861: $r->print(&mt('Access : ').&Apache::lonnet::plaintext($priv)."\n");
1.174 albertel 862: }
863: if ($fn ne '') {
1.187 bisitz 864: $r->print(&mt('Resource: ').&Apache::lonenc::check_encrypt($fn)."\n");
1.174 albertel 865: }
866: if ($msg ne '') {
1.187 bisitz 867: $r->print(&mt('Action : ').$msg."\n");
1.174 albertel 868: }
869: $r->print("</pre><hr />");
1.120 albertel 870: my $url=$fn;
871: my $last;
872: if (tie(my %hash,'GDBM_File',$env{'request.course.fn'}.'_symb.db',
873: &GDBM_READER(),0640)) {
874: $last=$hash{'last_known'};
875: untie(%hash);
876: }
1.149 www 877: if ($last) { $fn.='?symb='.&escape($last); }
1.120 albertel 878:
879: &Apache::londocs::changewarning($r,undef,'You have modified your course recently, [_1] may fix this access problem.',
880: &Apache::lonenc::check_encrypt($fn));
1.2 www 881: } else {
1.118 albertel 882: if ($env{'user.error.msg'}) {
1.209 raeburn 883: if ($reinit) {
884: $r->print(
885: '<h3><span class="LC_error">'.
1.234 raeburn 886: &mt('As your session file for the course or community has expired, you will need to re-select it.').'</span></h3>');
1.209 raeburn 887: } else {
888: $r->print(
1.157 albertel 889: '<h3><span class="LC_error">'.
1.235 bisitz 890: &mt('You need to choose another user role or enter a specific course or community for this function.').
891: '</span></h3>');
1.209 raeburn 892: }
893: }
1.2 www 894: }
895: if ($nochoose) {
1.177 www 896: $r->print("<h2>".&mt('Sorry ...')."</h2>\n<span class='LC_error'>".
897: &mt('This action is currently not authorized.').'</span>'.
1.150 www 898: &Apache::loncommon::end_page());
899: return OK;
1.6 www 900: } else {
1.269.2.2 raeburn 901: if ($updateresult || $reqauthor || $hotlist) {
902: my $showresult = '<div>';
903: if ($updateresult) {
904: $showresult .= &Apache::lonhtmlcommon::confirm_success($updateresult);
905: }
906: if ($reqauthor) {
907: $showresult .= &Apache::lonhtmlcommon::confirm_success($reqauthor);
908: }
909: if ($hotlist) {
910: $showresult .= $hotlist;
911: }
912: $showresult .= '</div>';
913: $r->print($showresult);
914: } elsif ($env{'form.state'} eq 'queued') {
915: $r->print(&get_queued());
916: }
1.18 www 917: if (($ENV{'REDIRECT_QUERY_STRING'}) && ($fn)) {
918: $fn.='?'.$ENV{'REDIRECT_QUERY_STRING'};
1.6 www 919: }
1.269.2.2 raeburn 920: my $display = ($env{'form.display'} =~ /^(showall)$/);
1.84 www 921: $r->print('<form method="post" name="rolechoice" action="'.(($fn)?$fn:$r->uri).'">');
1.116 albertel 922: $r->print('<input type="hidden" name="orgurl" value="'.$fn.'" />');
923: $r->print('<input type="hidden" name="selectrole" value="1" />');
1.134 www 924: $r->print('<input type="hidden" name="newrole" value="" />');
1.269.2.2 raeburn 925: $r->print('<input type="hidden" name="display" value="'.$display.'" />');
926: $r->print('<input type="hidden" name="state" value="" />');
1.6 www 927: }
1.259 raeburn 928: $r->rflush();
1.226 raeburn 929:
930: my (%roletext,%sortrole,%roleclass,%futureroles,%timezones);
931: my ($countactive,$countfuture,$inrole,$possiblerole) =
1.269.2.2 raeburn 932: &gather_roles($update,$refresh,$now,$reinit,$nochoose,\%roles_in_env,\%roletext,
933: \%sortrole,\%roleclass,\%futureroles,\%timezones,$loncaparev);
1.226 raeburn 934: $refresh = $now;
935: &Apache::lonnet::appenv({'user.refresh.time' => $refresh});
1.269.2.18 raeburn 936: if ((($cattype eq 'std') || ($cattype eq 'domonly')) && (!$env{'user.adv'})) {
1.196 raeburn 937: if ($countactive > 0) {
938: my $domdesc = &Apache::lonnet::domain($env{'user.domain'},'description');
1.201 raeburn 939: my $esc_dom = &HTML::Entities::encode($env{'user.domain'},'"<>&');
1.233 bisitz 940: $r->print(
941: '<p>'
1.269.2.16 raeburn 942: .&mt('[_1]Visit the [_2]Course/Community Catalog[_3][_4]'
943: .' to view all [_5] LON-CAPA courses and communities.'
1.233 bisitz 944: ,'<b>'
945: ,'<a href="/adm/coursecatalog?showdom='.$esc_dom.'">'
1.269.2.16 raeburn 946: ,'</a>'
947: ,'</b>'
1.269.2.18 raeburn 948: ,'"'.$domdesc.'"')
1.233 bisitz 949: .'<br />'
1.235 bisitz 950: .&mt('If a course or community is [_1]not[_2] in your list of current courses and communities below,'
1.233 bisitz 951: .' you may be able to enroll if self-enrollment is permitted.'
952: ,'<b>','</b>')
953: .'</p>'
954: );
1.196 raeburn 955: }
956: }
957:
1.84 www 958: # No active roles
959: if ($countactive==0) {
1.269.2.20 raeburn 960: &requestcourse_advice($r,$cattype,$inrole);
1.191 raeburn 961: $r->print('</form>');
962: if ($countfuture) {
963: $r->print(&mt('The following [quant,_1,role,roles] will become active in the future:',$countfuture));
964: my $doheaders = &roletable_headers($r,\%roleclass,\%sortrole,
965: $nochoose);
966: &print_rolerows($r,$doheaders,\%roleclass,\%sortrole,\%dcroles,
967: \%roletext);
968: my $tremark='';
1.212 bisitz 969: my $tbg;
1.191 raeburn 970: if ($env{'request.role'} eq 'cm') {
1.212 bisitz 971: $tbg="LC_roles_selected";
1.204 bisitz 972: $tremark=&mt('Currently selected.').' ';
1.191 raeburn 973: } else {
1.212 bisitz 974: $tbg="LC_roles_is";
1.191 raeburn 975: }
1.212 bisitz 976: $r->print(&Apache::loncommon::start_data_table_row()
977: .'<td class="'.$tbg.'"> </td>'
978: .'<td colspan="3">'
979: .&mt('No role specified')
980: .'</td>'
981: .'<td>'.$tremark.' </td>'
982: .&Apache::loncommon::end_data_table_row()
983: );
1.191 raeburn 984:
1.212 bisitz 985: $r->print(&Apache::loncommon::end_data_table());
1.191 raeburn 986: }
987: $r->print(&Apache::loncommon::end_page());
1.84 www 988: return OK;
989: }
990: # ----------------------------------------------------------------------- Table
1.247 raeburn 991:
1.269.2.27! raeburn 992: if (($numdc > 0) || (($numdh > 0) && ($numadhoc > 0))) {
1.247 raeburn 993: $r->print(&coursepick_jscript());
994: $r->print(&Apache::loncommon::coursebrowser_javascript().
995: &Apache::loncommon::authorbrowser_javascript());
996: }
997:
1.224 raeburn 998: unless ((!&Apache::loncommon::show_course()) || ($nochoose) || ($countactive==1)) {
1.173 albertel 999: $r->print("<h2>".&mt('Select a Course to Enter')."</h2>\n");
1.84 www 1000: }
1.229 raeburn 1001: if ($env{'form.destinationurl'}) {
1002: $r->print('<input type="hidden" name="destinationurl" value="'.
1003: $env{'form.destinationurl'}.'" />');
1004: if ($env{'form.destsymb'} ne '') {
1005: $r->print('<input type="hidden" name="destsymb" value="'.
1006: $env{'form.destsymb'}.'" />');
1007: }
1008: }
1.247 raeburn 1009:
1.191 raeburn 1010: my $doheaders = &roletable_headers($r,\%roleclass,\%sortrole,$nochoose);
1.118 albertel 1011: if ($env{'environment.recentroles'}) {
1.111 albertel 1012: my %recent_roles =
1.118 albertel 1013: &Apache::lonhtmlcommon::get_recent('roles',$env{'environment.recentrolesn'});
1.111 albertel 1014: my $output='';
1.247 raeburn 1015: foreach my $role (sort(keys(%recent_roles))) {
1016: if (ref($roletext{'user.role.'.$role}) eq 'ARRAY') {
1.223 raeburn 1017: $output.= &Apache::loncommon::start_data_table_row().
1.247 raeburn 1018: $roletext{'user.role.'.$role}->[0].
1.223 raeburn 1019: &Apache::loncommon::end_data_table_row();
1.249 raeburn 1020: if ($roletext{'user.role.'.$role}->[1] ne '') {
1021: $output .= &Apache::loncommon::continue_data_table_row().
1022: $roletext{'user.role.'.$role}->[1].
1023: &Apache::loncommon::end_data_table_row();
1024: }
1.269.2.27! raeburn 1025: if ($role =~ m{^dc\./($match_domain)/$}
1.170 albertel 1026: && $dcroles{$1}) {
1.192 raeburn 1027: $output .= &adhoc_roles_row($1,'recent');
1.269.2.27! raeburn 1028: } elsif ($role =~ m{^dh\./($match_domain)/$}
! 1029: && ($env{'environment.adhocroles.'.$1} ne '')) {
! 1030: $output .= &adhoc_customroles_row($1,'recent');
1.133 albertel 1031: }
1.113 raeburn 1032: } elsif ($numdc > 0) {
1.247 raeburn 1033: unless ($role =~/^error\:/) {
1.249 raeburn 1034: my ($roletext,$role_text_end) = &display_cc_role('user.role.'.$role);
1.259 raeburn 1035: if ($roletext) {
1036: $output.= &Apache::loncommon::start_data_table_row().
1037: $roletext.
1038: &Apache::loncommon::end_data_table_row();
1039: if ($role_text_end) {
1040: $output .= &Apache::loncommon::continue_data_table_row().
1041: $role_text_end.
1042: &Apache::loncommon::end_data_table_row();
1043: }
1044: }
1.113 raeburn 1045: }
1.247 raeburn 1046: }
1.111 albertel 1047: }
1048: if ($output) {
1.212 bisitz 1049: $r->print(&Apache::loncommon::start_data_table_empty_row()
1050: .'<td align="center" colspan="5">'
1.224 raeburn 1051: .$recent
1.212 bisitz 1052: .'</td>'
1053: .&Apache::loncommon::end_data_table_empty_row()
1054: );
1.111 albertel 1055: $r->print($output);
1.114 raeburn 1056: $doheaders ++;
1.111 albertel 1057: }
1058: }
1.191 raeburn 1059: &print_rolerows($r,$doheaders,\%roleclass,\%sortrole,\%dcroles,\%roletext);
1.202 raeburn 1060: if ($countactive > 1) {
1061: my $tremark='';
1.212 bisitz 1062: my $tbg;
1.202 raeburn 1063: if ($env{'request.role'} eq 'cm') {
1.212 bisitz 1064: $tbg="LC_roles_selected";
1.204 bisitz 1065: $tremark=&mt('Currently selected.').' ';
1.202 raeburn 1066: } else {
1.212 bisitz 1067: $tbg="LC_roles_is";
1.202 raeburn 1068: }
1.212 bisitz 1069: $r->print(&Apache::loncommon::start_data_table_row());
1.202 raeburn 1070: unless ($nochoose) {
1071: if ($env{'request.role'} ne 'cm') {
1.212 bisitz 1072: $r->print('<td class="'.$tbg.'"><input type="submit" value="'.
1.202 raeburn 1073: &mt('Select').'" name="cm" /></td>');
1074: } else {
1.212 bisitz 1075: $r->print('<td class="'.$tbg.'"> </td>');
1.202 raeburn 1076: }
1077: }
1.212 bisitz 1078: $r->print('<td colspan="3">'
1079: .&mt('No role specified')
1080: .'</td>'
1081: .'<td>'.$tremark.' </td>'
1082: .&Apache::loncommon::end_data_table_row()
1083: );
1.202 raeburn 1084: }
1.212 bisitz 1085: $r->print(&Apache::loncommon::end_data_table());
1.4 www 1086: unless ($nochoose) {
1087: $r->print("</form>\n");
1088: }
1.22 harris41 1089: # ------------------------------------------------------------ Privileges Info
1.118 albertel 1090: if (($advanced) && (($env{'user.error.msg'}) || ($error))) {
1.212 bisitz 1091: $r->print('<hr /><h2>'.&mt('Current Privileges').'</h2>');
1.175 albertel 1092: $r->print(&privileges_info());
1.4 www 1093: }
1.267 bisitz 1094: my $announcements = &Apache::lonnet::getannounce();
1095: $r->print(
1096: '<br />'.
1097: '<h2>'.&mt('Announcements').'</h2>'.
1098: $announcements
1099: ) unless (!$announcements);
1.65 www 1100: if ($advanced) {
1.201 raeburn 1101: my $esc_dom = &HTML::Entities::encode($env{'user.domain'},'"<>&');
1.231 bisitz 1102: $r->print('<p><small><i>'
1103: .&mt('This LON-CAPA server is version [_1]',$r->dir_config('lonVersion'))
1.269.2.21 raeburn 1104: .'</i></small></p>');
1.65 www 1105: }
1.147 albertel 1106: $r->print(&Apache::loncommon::end_page());
1.1 harris41 1107: return OK;
1.102 raeburn 1108: }
1109:
1.269.2.2 raeburn 1110: sub roles_from_env {
1111: my ($roleshash,$update) = @_;
1112: my $count = 0;
1113: if (ref($roleshash) eq 'HASH') {
1114: foreach my $envkey (keys(%env)) {
1115: if ($envkey =~ m{^user\.role\.(\w+)[./]}) {
1116: next if ($1 eq 'gr');
1117: $roleshash->{$envkey} = $env{$envkey};
1118: my ($start,$end) = split(/\./,$env{$envkey});
1119: unless ($end && $end<$update) {
1120: $count ++;
1121: }
1122: }
1123: }
1124: }
1125: return $count;
1126: }
1127:
1.226 raeburn 1128: sub gather_roles {
1.269.2.2 raeburn 1129: my ($update,$refresh,$now,$reinit,$nochoose,$roles_in_env,$roletext,$sortrole,$roleclass,$futureroles,
1130: $timezones,$loncaparev) = @_;
1.226 raeburn 1131: my ($countactive,$countfuture,$inrole,$possiblerole) = (0,0,0,'');
1132: my $advanced = $env{'user.adv'};
1133: my $tryagain = $env{'form.tryagain'};
1.254 raeburn 1134: my @ids = &Apache::lonnet::current_machine_ids();
1.269.2.2 raeburn 1135: if (ref($roles_in_env) eq 'HASH') {
1136: foreach my $envkey (sort(keys(%{$roles_in_env}))) {
1137: my $button = 1;
1138: my $switchserver='';
1139: my $switchwarning;
1140: my ($role_text,$role_text_end,$sortkey,$role,$where,$trolecode,$tstart,
1141: $tend,$tremark,$tstatus,$tpstart,$tpend);
1.260 raeburn 1142: &Apache::lonnet::role_status($envkey,$update,$refresh,$now,\$role,\$where,
1.226 raeburn 1143: \$trolecode,\$tstatus,\$tstart,\$tend);
1144: next if (!defined($role) || $role eq '' || $role =~ /^gr/);
1145: $tremark='';
1146: $tpstart=' ';
1147: $tpend=' ';
1148: if ($env{'request.role'} eq $trolecode) {
1149: $tstatus='selected';
1150: }
1151: my $tbg;
1152: if (($tstatus eq 'is')
1153: || ($tstatus eq 'selected')
1154: || ($tstatus eq 'future')
1.269.2.2 raeburn 1155: || ($env{'form.display'} eq 'showall')) {
1.259 raeburn 1156: my $timezone = &role_timezone($where,$timezones);
1157: if ($tstart) {
1158: $tpstart=&Apache::lonlocal::locallocaltime($tstart,$timezone);
1159: }
1160: if ($tend) {
1161: $tpend=&Apache::lonlocal::locallocaltime($tend,$timezone);
1162: }
1.226 raeburn 1163: if ($tstatus eq 'is') {
1164: $tbg='LC_roles_is';
1165: $possiblerole=$trolecode;
1166: $countactive++;
1167: } elsif ($tstatus eq 'future') {
1168: $tbg='LC_roles_future';
1169: $button=0;
1170: $futureroles->{$trolecode} = $tstart.':'.$tend;
1171: $countfuture ++;
1172: } elsif ($tstatus eq 'expired') {
1173: $tbg='LC_roles_expired';
1174: $button=0;
1175: } elsif ($tstatus eq 'will_not') {
1176: $tbg='LC_roles_will_not';
1177: $tremark.=&mt('Expired after logout.').' ';
1178: } elsif ($tstatus eq 'selected') {
1179: $tbg='LC_roles_selected';
1180: $inrole=1;
1181: $countactive++;
1182: $tremark.=&mt('Currently selected.').' ';
1183: }
1184: my $trole;
1185: if ($role =~ /^cr\//) {
1186: my ($rdummy,$rdomain,$rauthor,$rrole)=split(/\//,$role);
1187: if ($tremark) { $tremark.='<br />'; }
1.269.2.17 raeburn 1188: $tremark.=&mt('Custom role defined by [_1].',$rauthor.':'.$rdomain);
1.226 raeburn 1189: }
1190: $trole=Apache::lonnet::plaintext($role);
1191: my $ttype;
1192: my $twhere;
1193: my ($tdom,$trest,$tsection)=
1194: split(/\//,Apache::lonnet::declutter($where));
1195: # First, Co-Authorship roles
1196: if (($role eq 'ca') || ($role eq 'aa')) {
1197: my $home = &Apache::lonnet::homeserver($trest,$tdom);
1198: my $allowed=0;
1199: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
1200: if (!$allowed) {
1201: $button=0;
1.248 raeburn 1202: $switchserver='otherserver='.$home.'&role='.$trolecode;
1.226 raeburn 1203: }
1204: #next if ($home eq 'no_host');
1205: $home = &Apache::lonnet::hostname($home);
1.269.2.10 raeburn 1206: $ttype='Authoring Space';
1.226 raeburn 1207: $twhere=&mt('User').': '.$trest.'<br />'.&mt('Domain').
1208: ': '.$tdom.'<br />'.
1209: ' '.&mt('Server').': '.$home;
1210: $env{'course.'.$tdom.'_'.$trest.'.description'}='ca';
1211: $tremark.=&Apache::lonhtmlcommon::authorbombs('/res/'.$tdom.'/'.$trest.'/');
1212: $sortkey=$role."$trest:$tdom";
1213: } elsif ($role eq 'au') {
1214: # Authors
1215: my $home = &Apache::lonnet::homeserver
1216: ($env{'user.name'},$env{'user.domain'});
1217: my $allowed=0;
1218: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
1219: if (!$allowed) {
1220: $button=0;
1.248 raeburn 1221: $switchserver='otherserver='.$home.'&role='.$trolecode;
1.226 raeburn 1222: }
1223: #next if ($home eq 'no_host');
1224: $home = &Apache::lonnet::hostname($home);
1.269.2.10 raeburn 1225: $ttype='Authoring Space';
1.226 raeburn 1226: $twhere=&mt('Domain').': '.$tdom.'<br />'.&mt('Server').
1227: ': '.$home;
1228: $env{'course.'.$tdom.'_'.$trest.'.description'}='ca';
1229: $tremark.=&Apache::lonhtmlcommon::authorbombs('/res/'.$tdom.'/'.$env{'user.name'}.'/');
1230: $sortkey=$role;
1231: } elsif ($trest) {
1232: my $tcourseid=$tdom.'_'.$trest;
1233: $ttype = &Apache::loncommon::course_type($tcourseid);
1.242 raeburn 1234: $trole = &Apache::lonnet::plaintext($role,$ttype,$tcourseid);
1.226 raeburn 1235: if ($env{'course.'.$tcourseid.'.description'}) {
1.254 raeburn 1236: my $home=$env{'course.'.$tcourseid.'.home'};
1.226 raeburn 1237: $twhere=$env{'course.'.$tcourseid.'.description'};
1238: $sortkey=$role."\0".$tdom."\0".$twhere."\0".$envkey;
1.248 raeburn 1239: $twhere = &HTML::Entities::encode($twhere,'"<>&');
1.226 raeburn 1240: unless ($twhere eq &mt('Currently not available')) {
1241: $twhere.=' <span class="LC_fontsize_small">'.
1242: &Apache::loncommon::syllabuswrapper(&mt('Syllabus'),$trest,$tdom).
1243: '</span>';
1.254 raeburn 1244: unless ($home && grep(/^\Q$home\E$/,@ids) && $loncaparev eq '') {
1.255 raeburn 1245: my $required = $env{'course.'.$tcourseid.'.internal.releaserequired'};
1.259 raeburn 1246: if ($required ne '') {
1247: ($switchserver,$switchwarning) =
1.269.2.22 raeburn 1248: &Apache::loncommon::check_release_required($loncaparev,$tcourseid,$trolecode,$required);
1.259 raeburn 1249: if ($switchserver || $switchwarning) {
1250: $button = 0;
1251: }
1.254 raeburn 1252: }
1253: }
1.226 raeburn 1254: }
1255: } else {
1256: my %newhash=&Apache::lonnet::coursedescription($tcourseid);
1257: if (%newhash) {
1258: $sortkey=$role."\0".$tdom."\0".$newhash{'description'}.
1259: "\0".$envkey;
1.248 raeburn 1260: $twhere=&HTML::Entities::encode($newhash{'description'},'"<>&').
1261: ' <span class="LC_fontsize_small">'.
1262: &Apache::loncommon::syllabuswrapper(&mt('Syllabus'),$trest,$tdom).
1263: '</span>';
1.226 raeburn 1264: $ttype = $newhash{'type'};
1.243 raeburn 1265: $trole = &Apache::lonnet::plaintext($role,$ttype,$tcourseid);
1.254 raeburn 1266: my $home = $newhash{'home'};
1267: unless ($home && grep(/^\Q$home\E$/,@ids) && $loncaparev eq '') {
1.255 raeburn 1268: my $required = $newhash{'internal.releaserequired'};
1.259 raeburn 1269: if ($required ne '') {
1270: ($switchserver,$switchwarning) =
1.269.2.22 raeburn 1271: &Apache::loncommon::check_release_required($loncaparev,$tcourseid,$trolecode,$required);
1.259 raeburn 1272: if ($switchserver || $switchwarning) {
1273: $button = 0;
1274: }
1.254 raeburn 1275: }
1276: }
1.226 raeburn 1277: } else {
1278: $twhere=&mt('Currently not available');
1279: $env{'course.'.$tcourseid.'.description'}=$twhere;
1280: $sortkey=$role."\0".$tdom."\0".$twhere."\0".$envkey;
1281: $ttype = 'Unavailable';
1282: }
1283: }
1284: if ($tsection) {
1285: $twhere.='<br />'.&mt('Section').': '.$tsection;
1286: }
1287: if ($role ne 'st') { $twhere.="<br />".&mt('Domain').":".$tdom; }
1288: } elsif ($tdom) {
1289: $ttype='Domain';
1290: $twhere=$tdom;
1291: $sortkey=$role.$twhere;
1292: } else {
1293: $ttype='System';
1294: $twhere=&mt('system wide');
1295: $sortkey=$role.$twhere;
1296: }
1297: ($role_text,$role_text_end) =
1298: &build_roletext($trolecode,$tdom,$trest,$tstatus,$tryagain,
1299: $advanced,$tremark,$tbg,$trole,$twhere,$tpstart,
1.254 raeburn 1300: $tpend,$nochoose,$button,$switchserver,$reinit,$switchwarning);
1.226 raeburn 1301: $roletext->{$envkey}=[$role_text,$role_text_end];
1302: if (!$sortkey) {$sortkey=$twhere."\0".$envkey;}
1303: $sortrole->{$sortkey}=$envkey;
1304: $roleclass->{$envkey}=$ttype;
1305: }
1306: }
1307: }
1308: return ($countactive,$countfuture,$inrole,$possiblerole);
1309: }
1310:
1.215 raeburn 1311: sub role_timezone {
1312: my ($where,$timezones) = @_;
1313: my $timezone;
1314: if (ref($timezones) eq 'HASH') {
1315: if ($where =~ m{^/($match_domain)/($match_courseid)}) {
1316: my $cdom = $1;
1317: my $cnum = $2;
1318: if ($cdom && $cnum) {
1319: if (!exists($timezones->{$cdom.'_'.$cnum})) {
1.259 raeburn 1320: my $tz;
1321: if ($env{'course.'.$cdom.'_'.$cnum.'.description'}) {
1322: $tz = $env{'course.'.$cdom.'_'.$cnum.'.timezone'};
1323: } else {
1324: my %timehash =
1325: &Apache::lonnet::get('environment',['timezone'],$cdom,$cnum);
1326: $tz = $timehash{'timezone'};
1327: }
1328: if ($tz eq '') {
1.215 raeburn 1329: if (!exists($timezones->{$cdom})) {
1330: my %domdefaults =
1331: &Apache::lonnet::get_domain_defaults($cdom);
1332: if ($domdefaults{'timezone_def'} eq '') {
1333: $timezones->{$cdom} = 'local';
1334: } else {
1335: $timezones->{$cdom} = $domdefaults{'timezone_def'};
1336: }
1337: }
1338: $timezones->{$cdom.'_'.$cnum} = $timezones->{$cdom};
1339: } else {
1340: $timezones->{$cdom.'_'.$cnum} =
1.259 raeburn 1341: &Apache::lonlocal::gettimezone($tz);
1.215 raeburn 1342: }
1343: }
1344: $timezone = $timezones->{$cdom.'_'.$cnum};
1345: }
1346: } else {
1347: my ($tdom) = ($where =~ m{^/($match_domain)});
1348: if ($tdom) {
1349: if (!exists($timezones->{$tdom})) {
1350: my %domdefaults = &Apache::lonnet::get_domain_defaults($tdom);
1351: if ($domdefaults{'timezone_def'} eq '') {
1352: $timezones->{$tdom} = 'local';
1353: } else {
1354: $timezones->{$tdom} = $domdefaults{'timezone_def'};
1355: }
1356: }
1357: $timezone = $timezones->{$tdom};
1358: }
1359: }
1360: if ($timezone eq 'local') {
1361: $timezone = undef;
1362: }
1363: }
1364: return $timezone;
1365: }
1366:
1.191 raeburn 1367: sub roletable_headers {
1368: my ($r,$roleclass,$sortrole,$nochoose) = @_;
1369: my $doheaders;
1370: if ((ref($sortrole) eq 'HASH') && (ref($roleclass) eq 'HASH')) {
1.212 bisitz 1371: $r->print('<br />'
1.269.2.26 raeburn 1372: .&Apache::loncommon::start_data_table('LC_textsize_mobile')
1.212 bisitz 1373: .&Apache::loncommon::start_data_table_header_row()
1374: );
1.191 raeburn 1375: if (!$nochoose) { $r->print('<th> </th>'); }
1.212 bisitz 1376: $r->print('<th>'.&mt('User Role').'</th>'
1377: .'<th>'.&mt('Extent').'</th>'
1378: .'<th>'.&mt('Start').'</th>'
1379: .'<th>'.&mt('End').'</th>'
1380: .&Apache::loncommon::end_data_table_header_row()
1381: );
1.191 raeburn 1382: $doheaders=-1;
1383: my @roletypes = &roletypes();
1384: foreach my $type (@roletypes) {
1385: my $haverole=0;
1386: foreach my $which (sort {uc($a) cmp uc($b)} (keys(%{$sortrole}))) {
1387: if ($roleclass->{$sortrole->{$which}} =~ /^\Q$type\E/) {
1388: $haverole=1;
1389: }
1390: }
1391: if ($haverole) { $doheaders++; }
1392: }
1393: }
1394: return $doheaders;
1395: }
1396:
1397: sub roletypes {
1.269.2.10 raeburn 1398: my @types = ('Domain','Authoring Space','Course','Community','Unavailable','System');
1.191 raeburn 1399: return @types;
1400: }
1401:
1402: sub print_rolerows {
1403: my ($r,$doheaders,$roleclass,$sortrole,$dcroles,$roletext) = @_;
1404: if ((ref($roleclass) eq 'HASH') && (ref($sortrole) eq 'HASH')) {
1405: my @types = &roletypes();
1406: foreach my $type (@types) {
1407: my $output;
1408: foreach my $which (sort {uc($a) cmp uc($b)} (keys(%{$sortrole}))) {
1409: if ($roleclass->{$sortrole->{$which}} =~ /^\Q$type\E/) {
1410: if (ref($roletext) eq 'HASH') {
1.223 raeburn 1411: if (ref($roletext->{$sortrole->{$which}}) eq 'ARRAY') {
1412: $output.= &Apache::loncommon::start_data_table_row().
1413: $roletext->{$sortrole->{$which}}->[0].
1414: &Apache::loncommon::end_data_table_row();
1.251 raeburn 1415: if ($roletext->{$sortrole->{$which}}->[1] ne '') {
1416: $output .= &Apache::loncommon::continue_data_table_row().
1417: $roletext->{$sortrole->{$which}}->[1].
1418: &Apache::loncommon::end_data_table_row();
1419: }
1.223 raeburn 1420: }
1.269.2.27! raeburn 1421: if ($sortrole->{$which} =~ m{^user\.role\.dc\./($match_domain)/}) {
1.191 raeburn 1422: if (ref($dcroles) eq 'HASH') {
1423: if ($dcroles->{$1}) {
1.192 raeburn 1424: $output .= &adhoc_roles_row($1,'');
1.191 raeburn 1425: }
1426: }
1.269.2.27! raeburn 1427: } elsif (($sortrole->{$which} =~ m{^user\.role\.dh\./($match_domain)/}) &&
! 1428: ($env{'environment.adhocroles.'.$1} ne '')) {
! 1429: $output .= &adhoc_customroles_row($1,'');
1.191 raeburn 1430: }
1431: }
1432: }
1433: }
1434: if ($output) {
1435: if ($doheaders > 0) {
1.212 bisitz 1436: $r->print(&Apache::loncommon::start_data_table_empty_row()
1437: .'<td align="center" colspan="5">'
1438: .&mt($type)
1439: .'</td>'
1440: .&Apache::loncommon::end_data_table_empty_row()
1441: );
1.191 raeburn 1442: }
1443: $r->print($output);
1444: }
1445: }
1446: }
1447: }
1448:
1449: sub findcourse_advice {
1.269.2.18 raeburn 1450: my ($r,$cattype) = @_;
1.191 raeburn 1451: my $domdesc = &Apache::lonnet::domain($env{'user.domain'},'description');
1.201 raeburn 1452: my $esc_dom = &HTML::Entities::encode($env{'user.domain'},'"<>&');
1.200 raeburn 1453: if (&Apache::lonnet::auto_run(undef,$env{'user.domain'})) {
1.191 raeburn 1454: $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).'
1455: <ul>
1456: <li>'.&mt('The course has yet to be created.').'</li>
1457: <li>'.&mt('Automatic enrollment of registered students has not been enabled for the course.').'</li>
1458: <li>'.&mt('You are in a section of course for which automatic enrollment in the corresponding LON-CAPA course is not active.').'</li>
1459: <li>'.&mt('The start date for automated enrollment has yet to be reached.').'</li>
1460: <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>
1461: </ul>');
1462: } else {
1463: $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 />');
1464: }
1.269.2.18 raeburn 1465: if (($cattype eq 'std') || ($cattype eq 'domonly')) {
1466: $r->print('<h3>'.&mt('Self-Enrollment').'</h3>'.
1467: '<p>'.&mt('The [_1]Course/Community Catalog[_2] provides information about all [_3] classes for which LON-CAPA courses have been created, as well as any communities in the domain.','<a href="/adm/coursecatalog?showdom='.$esc_dom.'">','</a>',$domdesc).'<br />');
1468: $r->print(&mt('You can search for courses and communities which permit self-enrollment, if you would like to enroll in one.').'</p>'.
1469: &Apache::loncoursequeueadmin::queued_selfenrollment());
1470: }
1.216 raeburn 1471: return;
1472: }
1473:
1.234 raeburn 1474: sub requestcourse_advice {
1.269.2.20 raeburn 1475: my ($r,$cattype,$inrole) = @_;
1.234 raeburn 1476: my $domdesc = &Apache::lonnet::domain($env{'user.domain'},'description');
1477: my $esc_dom = &HTML::Entities::encode($env{'user.domain'},'"<>&');
1.269.2.20 raeburn 1478: my (%can_request,%request_doms,$output);
1.234 raeburn 1479: &Apache::lonnet::check_can_request($env{'user.domain'},\%can_request,\%request_doms);
1480: if (keys(%request_doms) > 0) {
1481: my ($types,$typename) = &Apache::loncommon::course_types();
1482: if ((ref($types) eq 'ARRAY') && (ref($typename) eq 'HASH')) {
1483: my (@reqdoms,@reqtypes);
1484: foreach my $type (sort(keys(%request_doms))) {
1485: push(@reqtypes,$type);
1486: if (ref($request_doms{$type}) eq 'ARRAY') {
1487: my $domstr = join(', ',map { &Apache::lonnet::domain($_) } sort(@{$request_doms{$type}}));
1.269.2.20 raeburn 1488: $output .=
1.238 bisitz 1489: '<li>'
1490: .&mt('[_1]'.$typename->{$type}.'[_2] in domain: [_3]',
1491: '<i>',
1492: '</i>',
1493: '<b>'.$domstr.'</b>')
1.269.2.20 raeburn 1494: .'</li>';
1.234 raeburn 1495: foreach my $dom (@{$request_doms{$type}}) {
1496: unless (grep(/^\Q$dom\E/,@reqdoms)) {
1497: push(@reqdoms,$dom);
1498: }
1499: }
1500: }
1501: }
1502: my @showtypes;
1503: foreach my $type (@{$types}) {
1504: if (grep(/^\Q$type\E$/,@reqtypes)) {
1505: push(@showtypes,$type);
1506: }
1507: }
1508: my $requrl = '/adm/requestcourse';
1509: if (@reqdoms == 1) {
1510: $requrl .= '?showdom='.$reqdoms[0];
1511: }
1512: if (@showtypes > 0) {
1513: $requrl.=(($requrl=~/\?/)?'&':'?').'crstype='.$showtypes[0];
1514: }
1515: if (@reqdoms == 1 || @showtypes > 0) {
1516: $requrl .= '&state=crstype&action=new';
1.269.2.20 raeburn 1517: }
1518: if ($output) {
1519: $r->print('<h3>'.&mt('Request creation of a course or community').'</h3>'.
1520: '<p>'.
1521: &mt('You have rights to request the creation of courses and/or communities in the following domain(s):').
1522: '<ul>'.
1523: $output.
1524: '</ul>'.
1525: &mt('Use the [_1]request form[_2] to submit a request for creation of a new course or community.',
1526: '<a href="'.$requrl.'">','</a>').
1527: '</p>');
1528: }
1.234 raeburn 1529: }
1.269.2.18 raeburn 1530: } elsif (!$env{'user.adv'}) {
1.269.2.20 raeburn 1531: if ($inrole) {
1532: $r->print('<h3>'.&mt('Currently no additional roles, courses or communities').'</h3>');
1533: } else {
1534: $r->print('<h3>'.&mt('Currently no active roles, courses or communities').'</h3>');
1535: }
1.269.2.18 raeburn 1536: &findcourse_advice($r,$cattype);
1.234 raeburn 1537: }
1538: return;
1539: }
1540:
1.175 albertel 1541: sub privileges_info {
1542: my ($which) = @_;
1543: my $output;
1544:
1545: $which ||= $env{'request.role'};
1546:
1547: foreach my $envkey (sort(keys(%env))) {
1548: next if ($envkey!~/^user\.priv\.\Q$which\E\.(.*)/);
1549:
1550: my $where=$1;
1551: my $ttype;
1552: my $twhere;
1553: my (undef,$tdom,$trest,$tsec)=split(m{/},$where);
1554: if ($trest) {
1555: if ($env{'course.'.$tdom.'_'.$trest.'.description'} eq 'ca') {
1.269.2.10 raeburn 1556: $ttype='Authoring Space';
1.175 albertel 1557: $twhere='User: '.$trest.', Domain: '.$tdom;
1558: } else {
1559: $ttype= &Apache::loncommon::course_type($tdom.'_'.$trest);
1560: $twhere=$env{'course.'.$tdom.'_'.$trest.'.description'};
1561: if ($tsec) {
1562: my $sec_type = 'Section';
1563: if (exists($env{"user.role.gr.$where"})) {
1564: $sec_type = 'Group';
1565: }
1566: $twhere.=' ('.$sec_type.': '.$tsec.')';
1567: }
1568: }
1569: } elsif ($tdom) {
1570: $ttype='Domain';
1571: $twhere=$tdom;
1572: } else {
1573: $ttype='System';
1574: $twhere='/';
1575: }
1.204 bisitz 1576: $output .= "\n<h3>".&mt($ttype).': '.$twhere.'</h3>'."\n<ul>";
1.175 albertel 1577: foreach my $priv (sort(split(/:/,$env{$envkey}))) {
1578: next if (!$priv);
1579:
1580: my ($prv,$restr)=split(/\&/,$priv);
1581: my $trestr='';
1582: if ($restr ne 'F') {
1583: $trestr.=' ('.
1584: join(', ',
1585: map { &Apache::lonnet::plaintext($_) }
1586: (split('',$restr))).') ';
1587: }
1588: $output .= "\n\t".
1589: '<li>'.&Apache::lonnet::plaintext($prv).$trestr.'</li>';
1590: }
1591: $output .= "\n".'</ul>';
1592: }
1593: return $output;
1594: }
1595:
1.110 raeburn 1596: sub build_roletext {
1.254 raeburn 1597: my ($trolecode,$tdom,$trest,$tstatus,$tryagain,$advanced,$tremark,$tbg,$trole,$twhere,$tpstart,$tpend,$nochoose,$button,$switchserver,$reinit,$switchwarning) = @_;
1.223 raeburn 1598: my ($roletext,$roletext_end);
1.132 albertel 1599: my $is_dc=($trolecode =~ m/^dc\./);
1600: my $rowspan=($is_dc) ? ''
1601: : ' rowspan="2" ';
1602:
1.110 raeburn 1603: unless ($nochoose) {
1.134 www 1604: my $buttonname=$trolecode;
1605: $buttonname=~s/\W//g;
1.110 raeburn 1606: if (!$button) {
1607: if ($switchserver) {
1.212 bisitz 1608: $roletext.='<td'.$rowspan.' class="'.$tbg.'">'
1609: .'<a href="/adm/switchserver?'.$switchserver.'">'
1610: .&mt('Switch Server')
1611: .'</a></td>';
1.110 raeburn 1612: } else {
1.212 bisitz 1613: $roletext.=('<td'.$rowspan.' class="'.$tbg.'"> </td>');
1.110 raeburn 1614: }
1.255 raeburn 1615: if ($switchwarning) {
1616: if ($tremark eq '') {
1617: $tremark = $switchwarning;
1618: } else {
1619: $tremark .= '<br />'.$switchwarning;
1620: }
1621: }
1.110 raeburn 1622: } elsif ($tstatus eq 'is') {
1.212 bisitz 1623: $roletext.='<td'.$rowspan.' class="'.$tbg.'">'.
1624: '<input name="'.$buttonname.'" type="button" value="'.
1.225 bisitz 1625: &mt('Select').'" onclick="javascript:enterrole(this.form,\''.
1.192 raeburn 1626: $trolecode."','".$buttonname.'\');" /></td>';
1.110 raeburn 1627: } elsif ($tryagain) {
1628: $roletext.=
1.212 bisitz 1629: '<td'.$rowspan.' class="'.$tbg.'">'.
1630: '<input name="'.$buttonname.'" type="button" value="'.
1.225 bisitz 1631: &mt('Try Selecting Again').'" onclick="javascript:enterrole(this.form,\''.
1.192 raeburn 1632: $trolecode."','".$buttonname.'\');" /></td>';
1.110 raeburn 1633: } elsif ($advanced) {
1634: $roletext.=
1.212 bisitz 1635: '<td'.$rowspan.' class="'.$tbg.'">'.
1636: '<input name="'.$buttonname.'" type="button" value="'.
1.225 bisitz 1637: &mt('Re-Initialize').'" onclick="javascript:enterrole(this.form,\''.
1.192 raeburn 1638: $trolecode."','".$buttonname.'\');" /></td>';
1.209 raeburn 1639: } elsif ($reinit) {
1640: $roletext.=
1.212 bisitz 1641: '<td'.$rowspan.' class="'.$tbg.'">'.
1642: '<input name="'.$buttonname.'" type="button" value="'.
1.225 bisitz 1643: &mt('Re-Select').'" onclick="javascript:enterrole(this.form,\''.
1.209 raeburn 1644: $trolecode."','".$buttonname.'\');" /></td>';
1.110 raeburn 1645: } else {
1.209 raeburn 1646: $roletext.=
1.212 bisitz 1647: '<td'.$rowspan.' class="'.$tbg.'">'.
1648: '<input name="'.$buttonname.'" type="button" value="'.
1.225 bisitz 1649: &mt('Re-Select').'" onclick="javascript:enterrole(this.form,\''.
1.209 raeburn 1650: $trolecode."','".$buttonname.'\');" /></td>';
1.110 raeburn 1651: }
1652: }
1.165 albertel 1653: if ($trolecode !~ m/^(dc|ca|au|aa)\./) {
1654: $tremark.=&Apache::lonannounce::showday(time,1,
1655: &Apache::lonannounce::readcalendar($tdom.'_'.$trest));
1656: }
1.212 bisitz 1657: $roletext.='<td>'.$trole.'</td>'
1658: .'<td>'.$twhere.'</td>'
1659: .'<td>'.$tpstart.'</td>'
1.223 raeburn 1660: .'<td>'.$tpend.'</td>';
1.132 albertel 1661: if (!$is_dc) {
1.223 raeburn 1662: $roletext_end = '<td colspan="4">'.
1663: $tremark.' '.
1664: '</td>';
1.132 albertel 1665: }
1.223 raeburn 1666: return ($roletext,$roletext_end);
1.110 raeburn 1667: }
1668:
1.193 raeburn 1669: sub check_author_homeserver {
1.183 www 1670: my ($uname,$udom)=@_;
1.193 raeburn 1671: if (($uname eq '') || ($udom eq '')) {
1672: return ('fail','');
1673: }
1.183 www 1674: my $home = &Apache::lonnet::homeserver($uname,$udom);
1.193 raeburn 1675: if (&Apache::lonnet::host_domain($home) ne $udom) {
1676: return ('fail',$home);
1677: }
1.183 www 1678: my @ids=&Apache::lonnet::current_machine_ids();
1.193 raeburn 1679: if (grep(/^\Q$home\E$/,@ids)) {
1680: return ('ok',$home);
1681: } else {
1682: return ('switchserver',$home);
1.183 www 1683: }
1684: }
1685:
1.269.2.27! raeburn 1686: sub check_for_adhoc {
! 1687: my ($dcroles,$dhroles,$update,$then) = @_;
1.104 raeburn 1688: my $numdc = 0;
1.269.2.27! raeburn 1689: my $numdh = 0;
! 1690: my $numadhoc = 0;
! 1691: my $num_custom_adhoc = 0;
1.118 albertel 1692: if ($env{'user.adv'}) {
1.269.2.22 raeburn 1693: foreach my $envkey (sort(keys(%env))) {
1.269.2.27! raeburn 1694: if ($envkey=~/^user\.role\.(dc|dh)\.\/($match_domain)\/$/) {
! 1695: my $role = $1;
! 1696: my $roledom = $2;
! 1697: my $liverole = 1;
1.118 albertel 1698: my ($tstart,$tend)=split(/\./,$env{$envkey});
1.260 raeburn 1699: my $limit = $update;
1.269.2.27! raeburn 1700: if ((($role eq 'dc') && ($env{'request.role'} eq 'dc./'.$roledom.'/')) ||
! 1701: (($role eq 'dh') && ($env{'request.role'} eq 'dh./'.$roledom.'/'))) {
1.260 raeburn 1702: $limit = $then;
1703: }
1.269.2.27! raeburn 1704: if ($tstart && $tstart>$limit) { $liverole = 0; }
! 1705: if ($tend && $tend <$limit) { $liverole = 0; }
! 1706: if ($liverole) {
! 1707: if ($role eq 'dc') {
! 1708: $dcroles->{$roledom} = $envkey;
! 1709: $numdc++;
! 1710: } else {
! 1711: $dhroles->{$roledom} = $envkey;
! 1712: if ($env{'environment.adhocroles.'.$roledom} ne '') {
! 1713: $numadhoc ++;
! 1714: }
! 1715: $numdh++;
! 1716: }
1.104 raeburn 1717: }
1718: }
1719: }
1720: }
1.269.2.27! raeburn 1721: return ($numdc,$numdh,$numadhoc);
1.104 raeburn 1722: }
1723:
1.185 raeburn 1724: sub adhoc_course_role {
1.260 raeburn 1725: my ($refresh,$update,$then) = @_;
1.239 raeburn 1726: my ($cdom,$cnum,$crstype);
1.201 raeburn 1727: $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
1728: $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.239 raeburn 1729: $crstype = &Apache::loncommon::course_type();
1.260 raeburn 1730: if (&check_forcc($cdom,$cnum,$refresh,$update,$then,$crstype)) {
1.185 raeburn 1731: my $setprivs;
1.198 raeburn 1732: if (!defined($env{'user.role.'.$env{'form.switchrole'}})) {
1.185 raeburn 1733: $setprivs = 1;
1734: } else {
1.198 raeburn 1735: my ($start,$end) = split(/\./,$env{'user.role.'.$env{'form.switchrole'}});
1.232 raeburn 1736: if (($start && ($start>$refresh || $start == -1)) ||
1.260 raeburn 1737: ($end && $end<$update)) {
1.185 raeburn 1738: $setprivs = 1;
1739: }
1.232 raeburn 1740: }
1.269.2.5 raeburn 1741: unless ($setprivs) {
1742: if (!exists($env{'user.priv.'.$env{'form.switchrole'}.'./'})) {
1743: $setprivs = 1;
1744: }
1745: }
1.185 raeburn 1746: if ($setprivs) {
1.269.2.16 raeburn 1747: if ($env{'form.switchrole'} =~ m-^(in|ta|ep|ad|st|cr)(.*?)\./\Q$cdom\E/\Q$cnum\E/?(\w*)$-) {
1.185 raeburn 1748: my $role = $1;
1749: my $custom_role = $2;
1750: my $usec = $3;
1751: if ($role eq 'cr') {
1.199 raeburn 1752: if ($custom_role =~ m-^/$match_domain/$match_username/\w+$-) {
1.185 raeburn 1753: $role .= $custom_role;
1754: } else {
1755: return;
1756: }
1757: }
1.208 raeburn 1758: my (%userroles,%newrole,%newgroups,%group_privs);
1759: my %cgroups =
1760: &Apache::lonnet::get_active_groups($env{'user.domain'},
1761: $env{'user.name'},$cdom,$cnum);
1762: foreach my $group (keys(%cgroups)) {
1763: $group_privs{$group} =
1764: $env{'user.priv.cc./'.$cdom.'/'.$cnum.'./'.$cdom.'/'.$cnum.'/'.$group};
1765: }
1766: $newgroups{'/'.$cdom.'/'.$cnum} = \%group_privs;
1.185 raeburn 1767: my $area = '/'.$cdom.'/'.$cnum;
1768: my $spec = $role.'.'.$area;
1769: if ($usec ne '') {
1770: $spec .= '/'.$usec;
1771: $area .= '/'.$usec;
1772: }
1.269.2.5 raeburn 1773: if ($role =~ /^cr/) {
1774: &Apache::lonnet::custom_roleprivs(\%newrole,$role,$cdom,$cnum,$spec,$area);
1775: } else {
1776: &Apache::lonnet::standard_roleprivs(\%newrole,$role,$cdom,$spec,$cnum,$area);
1777: }
1.208 raeburn 1778: &Apache::lonnet::set_userprivs(\%userroles,\%newrole,\%newgroups);
1.232 raeburn 1779: my $adhocstart = $refresh-1;
1.185 raeburn 1780: $userroles{'user.role.'.$spec} = $adhocstart.'.';
1.186 raeburn 1781: &Apache::lonnet::appenv(\%userroles,[$role,'cm']);
1.185 raeburn 1782: }
1783: }
1784: }
1785: return;
1786: }
1787:
1788: sub check_forcc {
1.260 raeburn 1789: my ($cdom,$cnum,$refresh,$update,$then,$crstype) = @_;
1.239 raeburn 1790: my ($is_cc,$ccrole);
1791: if ($crstype eq 'Community') {
1792: $ccrole = 'co';
1793: } else {
1794: $ccrole = 'cc';
1795: }
1.266 droeschl 1796: if (&Apache::lonnet::is_course($cdom,$cnum)) {
1797: my $envkey = 'user.role.'.$ccrole.'./'.$cdom.'/'.$cnum;
1798: if (defined($env{$envkey})) {
1799: $is_cc = 1;
1800: my ($tstart,$tend)=split(/\./,$env{$envkey});
1801: my $limit = $update;
1802: if ($env{'request.role'} eq $ccrole.'./'.$cdom.'/'.$cnum) {
1803: $limit = $then;
1.185 raeburn 1804: }
1.266 droeschl 1805: if ($tstart && $tstart>$refresh) { $is_cc = 0; }
1806: if ($tend && $tend <$limit) { $is_cc = 0; }
1.185 raeburn 1807: }
1808: }
1809: return $is_cc;
1810: }
1811:
1.108 raeburn 1812: sub courselink {
1.269.2.27! raeburn 1813: my ($roledom,$rowtype,$role) = @_;
1.109 raeburn 1814: my $courseform=&Apache::loncommon::selectcourse_link
1.269.2.27! raeburn 1815: ('rolechoice','course'.$rowtype.'_'.$roledom.'_'.$role,
! 1816: 'domain'.$rowtype.'_'.$roledom.'_'.$role,
! 1817: 'coursedesc'.$rowtype.'_'.$roledom.'_'.$role,
! 1818: $roledom.':'.$role,undef,'Course/Community');
! 1819: my $hiddenitems = '<input type="hidden" name="domain'.$rowtype.'_'.$roledom.'_'.$role.'" value="'.$roledom.'" />'.
! 1820: '<input type="hidden" name="origdom'.$rowtype.'_'.$roledom.'_'.$role.'" value="'.$roledom.'" />'.
! 1821: '<input type="hidden" name="course'.$rowtype.'_'.$roledom.'_'.$role.'" value="" />'.
! 1822: '<input type="hidden" name="coursedesc'.$rowtype.'_'.$roledom.'_'.$role.'" value="" />';
1.112 raeburn 1823: return $courseform.$hiddenitems;
1.109 raeburn 1824: }
1825:
1826: sub coursepick_jscript {
1.269.2.25 raeburn 1827: my %js_lt = &Apache::lonlocal::texthash(
1.239 raeburn 1828: plsu => "Please use the 'Select Course/Community' link to open a separate pick course window where you may select the course or community you wish to enter.",
1.234 raeburn 1829: youc => 'You can only use this screen to select courses and communities in the current domain.',
1.184 raeburn 1830: );
1.269.2.24 raeburn 1831: &js_escape(\%js_lt);
1.104 raeburn 1832: my $verify_script = <<"END";
1.179 raeburn 1833: <script type="text/javascript">
1.225 bisitz 1834: // <![CDATA[
1.108 raeburn 1835: function verifyCoursePick(caller) {
1836: var numbutton = getIndex(caller)
1.112 raeburn 1837: var pickedCourse = document.rolechoice.elements[numbutton+4].value
1838: var pickedDomain = document.rolechoice.elements[numbutton+2].value
1839: if (document.rolechoice.elements[numbutton+2].value == document.rolechoice.elements[numbutton+3].value) {
1.104 raeburn 1840: if (pickedCourse != '') {
1.108 raeburn 1841: if (numbutton != -1) {
1842: var courseTarget = "cc./"+pickedDomain+"/"+pickedCourse
1843: document.rolechoice.elements[numbutton+1].name = courseTarget
1844: document.rolechoice.submit()
1845: }
1.104 raeburn 1846: }
1847: else {
1.269.2.24 raeburn 1848: alert("$js_lt{'plsu'}");
1.104 raeburn 1849: }
1850: }
1851: else {
1.269.2.24 raeburn 1852: alert("$js_lt{'youc'}")
1.104 raeburn 1853: }
1854: }
1.109 raeburn 1855: function getIndex(caller) {
1.108 raeburn 1856: for (var i=0;i<document.rolechoice.elements.length;i++) {
1.109 raeburn 1857: if (document.rolechoice.elements[i] == caller) {
1.108 raeburn 1858: return i;
1859: }
1860: }
1861: return -1;
1862: }
1.225 bisitz 1863: // ]]>
1.104 raeburn 1864: </script>
1865: END
1.109 raeburn 1866: return $verify_script;
1.104 raeburn 1867: }
1868:
1.193 raeburn 1869: sub coauthorlink {
1870: my ($dcdom,$rowtype) = @_;
1871: my $coauthorform=&Apache::loncommon::selectauthor_link('rolechoice',$dcdom);
1872: my $hiddenitems = '<input type="hidden" name="adhoccauname'.$rowtype.'_'.$dcdom.'" value="" />';
1873: return $coauthorform.$hiddenitems;
1874: }
1875:
1.113 raeburn 1876: sub display_cc_role {
1877: my $rolekey = shift;
1.223 raeburn 1878: my ($roletext,$roletext_end);
1.118 albertel 1879: my $advanced = $env{'user.adv'};
1880: my $tryagain = $env{'form.tryagain'};
1.113 raeburn 1881: unless ($rolekey =~/^error\:/) {
1.240 raeburn 1882: if ($rolekey =~ m{^user\.role\.(cc|co)\./($match_domain)/($match_courseid)$}) {
1883: my $ccrole = $1;
1.249 raeburn 1884: my $tdom = $2;
1885: my $trest = $3;
1886: my $tcourseid = $tdom.'_'.$trest;
1887: my $trolecode = $ccrole.'./'.$tdom.'/'.$trest;
1.113 raeburn 1888: my $twhere;
1.152 raeburn 1889: my $ttype;
1.212 bisitz 1890: my $tbg='LC_roles_is';
1.113 raeburn 1891: my %newhash=&Apache::lonnet::coursedescription($tcourseid);
1892: if (%newhash) {
1893: $twhere=$newhash{'description'}.
1.261 bisitz 1894: ' <span class="LC_fontsize_small">'.
1.249 raeburn 1895: &Apache::loncommon::syllabuswrapper(&mt('Syllabus'),$trest,$tdom).
1.211 tempelho 1896: '</span>';
1.153 raeburn 1897: $ttype = $newhash{'type'};
1.113 raeburn 1898: } else {
1899: $twhere=&mt('Currently not available');
1.118 albertel 1900: $env{'course.'.$tcourseid.'.description'}=$twhere;
1.110 raeburn 1901: }
1.242 raeburn 1902: my $trole = &Apache::lonnet::plaintext($ccrole,$ttype,$tcourseid);
1.258 raeburn 1903: $twhere.="<br />".&mt('Domain').":".$tdom;
1.249 raeburn 1904: ($roletext,$roletext_end) = &build_roletext($trolecode,$tdom,$trest,'is',$tryagain,$advanced,'',$tbg,$trole,$twhere,'','','',1,'');
1.104 raeburn 1905: }
1906: }
1.223 raeburn 1907: return ($roletext,$roletext_end);
1.104 raeburn 1908: }
1909:
1.192 raeburn 1910: sub adhoc_roles_row {
1.138 raeburn 1911: my ($dcdom,$rowtype) = @_;
1.212 bisitz 1912: my $output = &Apache::loncommon::continue_data_table_row()
1.269.2.26 raeburn 1913: .' <td colspan="5" class="LC_textsize_mobile">'
1.212 bisitz 1914: .&mt('[_1]Ad hoc[_2] roles in domain [_3] --'
1915: ,'<span class="LC_cusr_emph">','</span>',$dcdom)
1.227 bisitz 1916: .' ';
1.269.2.27! raeburn 1917: my $role = 'cc';
! 1918: my $selectcclink = &courselink($dcdom,$rowtype,$role);
1.239 raeburn 1919: my $ccrole = &Apache::lonnet::plaintext('co',undef,undef,1);
1.182 www 1920: my $carole = &Apache::lonnet::plaintext('ca');
1.193 raeburn 1921: my $selectcalink = &coauthorlink($dcdom,$rowtype);
1.227 bisitz 1922: $output.=$ccrole.': '.$selectcclink
1.249 raeburn 1923: .' | '.$carole.': '.$selectcalink.'</td>'
1.212 bisitz 1924: .&Apache::loncommon::end_data_table_row();
1.108 raeburn 1925: return $output;
1926: }
1927:
1.269.2.27! raeburn 1928: sub adhoc_customroles_row {
! 1929: my ($dhdom,$rowtype) = @_;
! 1930: my $output = &Apache::loncommon::continue_data_table_row()
! 1931: .' <td colspan="5" class="LC_textsize_mobile">'
! 1932: .&mt('[_1]Ad hoc[_2] course/community roles in domain [_3] --',
! 1933: '<span class="LC_cusr_emph">','</span>',$dhdom);
! 1934: my @customroles = split(/,/,$env{'environment.adhocroles.'.$dhdom});
! 1935: my $count = 0;
! 1936: foreach my $role (@customroles) {
! 1937: next if (($role eq '') || ($role =~ /\W/));
! 1938: $output .= ' '.$role.': '.&courselink($dhdom,$rowtype,$role).' |';
! 1939: $count ++;
! 1940: }
! 1941: if ($count) {
! 1942: return $output;
! 1943: }
! 1944: return;
! 1945: }
! 1946:
1.104 raeburn 1947: sub recent_filename {
1948: my $area=shift;
1.149 www 1949: return 'nohist_recent_'.&escape($area);
1.104 raeburn 1950: }
1951:
1.139 raeburn 1952: sub courseloadpage {
1953: my ($courseid) = @_;
1954: my $startpage;
1.144 albertel 1955: my %entry_settings = &Apache::lonnet::get('nohist_whatsnew',
1956: [$courseid.':courseinit']);
1.139 raeburn 1957: my ($tmp) = %entry_settings;
1.144 albertel 1958: unless ($tmp =~ /^error: 2 /) {
1.139 raeburn 1959: $startpage = $entry_settings{$courseid.':courseinit'};
1960: }
1961: if ($startpage eq '') {
1962: if (exists($env{'environment.course_init_display'})) {
1963: $startpage = $env{'environment.course_init_display'};
1964: }
1965: }
1966: return $startpage;
1967: }
1968:
1.260 raeburn 1969: sub update_session_roles {
1970: my $then=$env{'user.login.time'};
1971: my $refresh=$env{'user.refresh.time'};
1972: if (!$refresh) {
1973: $refresh = $then;
1974: }
1975: my $update = $env{'user.update.time'};
1976: if (!$update) {
1977: $update = $then;
1978: }
1979: my $now = time;
1980: my %roleshash =
1981: &Apache::lonnet::get_my_roles('','','userroles',
1982: ['active','future','previous'],
1983: undef,undef,1);
1984: my ($msg,@newsec,$oldsec,$currrole_expired,@changed_roles,
1.264 raeburn 1985: %changed_groups,%dbroles,%deletedroles,%allroles,%allgroups,
1.260 raeburn 1986: %userroles,%checkedgroup,%crprivs,$hasgroups,%rolechange,
1987: %groupchange,%newrole,%newgroup,%customprivchg,%groups_roles,
1988: @rolecodes);
1989: my @possroles = ('cr','st','ta','ad','ep','in','co','cc');
1990: my %courseroles;
1991: foreach my $item (keys(%roleshash)) {
1992: my ($uname,$udom,$role,$remainder) = split(/:/,$item,4);
1993: my ($tstart,$tend) = split(/:/,$roleshash{$item});
1994: my ($section,$group,@group_privs);
1995: if ($role =~ m{^gr/(\w*)$}) {
1996: $role = 'gr';
1997: my $priv = $1;
1998: next if ($tstart eq '-1');
1999: if (&curr_role_status($tstart,$tend,$refresh,$now) eq 'active') {
2000: if ($priv ne '') {
2001: push(@group_privs,$priv);
2002: }
2003: }
2004: if ($remainder =~ /:/) {
2005: (my $additional_privs,$group) =
2006: ($remainder =~ /^([\w:]+):([^:]+)$/);
2007: if ($additional_privs ne '') {
2008: if (&curr_role_status($tstart,$tend,$refresh,$now) eq 'active') {
2009: push(@group_privs,split(/:/,$additional_privs));
2010: @group_privs = sort(@group_privs);
2011: }
2012: }
2013: } else {
2014: $group = $remainder;
2015: }
2016: } else {
2017: $section = $remainder;
2018: }
2019: my $where = "/$udom/$uname";
2020: if ($section ne '') {
2021: $where .= "/$section";
2022: } elsif ($group ne '') {
2023: $where .= "/$group";
2024: }
2025: my $rolekey = "$role.$where";
2026: my $envkey = "user.role.$rolekey";
2027: $dbroles{$envkey} = 1;
2028: if (($env{'request.role'} eq $rolekey) && ($role ne 'st')) {
2029: if (&curr_role_status($tstart,$tend,$refresh,$now) ne 'active') {
2030: $currrole_expired = 1;
2031: }
2032: }
2033: if ($env{$envkey} eq '') {
2034: my $status_in_db =
1.269.2.2 raeburn 2035: &curr_role_status($tstart,$tend,$now,$now);
1.260 raeburn 2036: &gather_roleprivs(\%allroles,\%allgroups,\%userroles,$where,$role,$tstart,$tend,$status_in_db);
2037: if (($role eq 'st') && ($env{'request.role'} =~ m{^\Q$role\E\.\Q/$udom/$uname\E})) {
2038: if ($status_in_db eq 'active') {
2039: if ($section eq '') {
2040: push(@newsec,'none');
2041: } else {
2042: push(@newsec,$section);
2043: }
2044: }
2045: } else {
2046: unless (grep(/^\Q$role\E$/,@changed_roles)) {
2047: push(@changed_roles,$role);
2048: }
2049: if ($status_in_db ne 'previous') {
2050: if ($role eq 'gr') {
2051: $newgroup{$rolekey} = $status_in_db;
2052: if ($status_in_db eq 'active') {
2053: unless (ref($courseroles{$udom}) eq 'HASH') {
2054: %{$courseroles{$udom}} =
2055: &Apache::lonnet::get_my_roles('','','userroles',
2056: ['active'],\@possroles,
2057: [$udom],1);
2058: }
2059: &Apache::lonnet::get_groups_roles($udom,$uname,
2060: $courseroles{$udom},
2061: \@rolecodes,\%groups_roles);
2062: }
2063: } else {
2064: $newrole{$rolekey} = $status_in_db;
2065: }
2066: }
2067: }
2068: } else {
2069: my ($currstart,$currend) = split(/\./,$env{$envkey});
2070: if ($role eq 'gr') {
2071: if (&curr_role_status($currstart,$currend,$refresh,$update) ne 'previous') {
2072: $hasgroups = 1;
2073: }
2074: }
2075: if (($currstart ne $tstart) || ($currend ne $tend)) {
2076: my $status_in_env =
2077: &curr_role_status($currstart,$currend,$refresh,$update);
2078: my $status_in_db =
1.269.2.2 raeburn 2079: &curr_role_status($tstart,$tend,$now,$now);
1.260 raeburn 2080: if ($status_in_env ne $status_in_db) {
2081: if ($status_in_env eq 'active') {
2082: if ($role eq 'st') {
2083: if ($env{'request.role'} eq $rolekey) {
2084: my $switchsection;
2085: unless (ref($courseroles{$udom}) eq 'HASH') {
2086: %{$courseroles{$udom}} =
2087: &Apache::lonnet::get_my_roles('','','userroles',
2088: ['active'],
2089: \@possroles,[$udom],1);
2090: }
2091: foreach my $crsrole (keys(%{$courseroles{$udom}})) {
2092: if ($crsrole =~ /^\Q$uname\E:\Q$udom\E:st/) {
2093: $switchsection = 1;
2094: last;
2095: }
2096: }
2097: if ($switchsection) {
2098: if ($section eq '') {
2099: $oldsec = 'none';
2100: } else {
2101: $oldsec = $section;
2102: }
2103: &gather_roleprivs(\%allroles,\%allgroups,\%userroles,$where,$role,$tstart,$tend,$status_in_db);
2104: } else {
2105: $currrole_expired = 1;
2106: next;
2107: }
2108: }
2109: }
2110: unless ($rolekey eq $env{'request.role'}) {
2111: if ($role eq 'gr') {
2112: &Apache::lonnet::delete_env_groupprivs($where,\%courseroles,\@possroles);
2113: } else {
2114: &Apache::lonnet::delenv("user.priv.$rolekey",undef,[$role]);
2115: &Apache::lonnet::delenv("user.priv.cm.$where",undef,['cm']);
2116: }
2117: &gather_roleprivs(\%allroles,\%allgroups,\%userroles,$where,$role,$tstart,$tend,$status_in_db);
2118: }
2119: } elsif ($status_in_db eq 'active') {
2120: if (($role eq 'st') &&
2121: ($env{'request.role'} =~ m{^\Q$role\E\.\Q/$udom/$uname\E})) {
2122: if ($section eq '') {
2123: push(@newsec,'none');
2124: } else {
2125: push(@newsec,$section);
2126: }
2127: } elsif ($role eq 'gr') {
2128: unless (ref($courseroles{$udom}) eq 'HASH') {
2129: %{$courseroles{$udom}} =
2130: &Apache::lonnet::get_my_roles('','','userroles',
2131: ['active'],
2132: \@possroles,[$udom],1);
2133: }
2134: &Apache::lonnet::get_groups_roles($udom,$uname,
2135: $courseroles{$udom},
2136: \@rolecodes,\%groups_roles);
2137: }
2138: &gather_roleprivs(\%allroles,\%allgroups,\%userroles,$where,$role,$tstart,$tend,$status_in_db);
2139: }
2140: unless (grep(/^\Q$role\E$/,@changed_roles)) {
2141: push(@changed_roles,$role);
2142: }
2143: if ($role eq 'gr') {
2144: $groupchange{"/$udom/$uname"}{$group} = $status_in_db;
2145: } else {
2146: $rolechange{$rolekey} = $status_in_db;
2147: }
2148: }
2149: } else {
2150: if ($role eq 'gr') {
2151: unless ($checkedgroup{$where}) {
2152: my $status_in_db =
2153: &curr_role_status($tstart,$tend,$refresh,$now);
2154: if ($tstart eq '-1') {
2155: $status_in_db = 'deleted';
2156: }
2157: unless (ref($courseroles{$udom}) eq 'HASH') {
2158: %{$courseroles{$udom}} =
2159: &Apache::lonnet::get_my_roles('','','userroles',
2160: ['active'],
2161: \@possroles,[$udom],1);
2162: }
2163: if (ref($courseroles{$udom}) eq 'HASH') {
2164: foreach my $item (keys(%{$courseroles{$udom}})) {
2165: next unless ($item =~ /^\Q$uname\E/);
2166: my ($cnum,$cdom,$crsrole,$crssec) = split(/:/,$item);
2167: my $area = '/'.$cdom.'/'.$cnum;
2168: if ($crssec ne '') {
2169: $area .= '/'.$crssec;
2170: }
2171: my $crsrolekey = $crsrole.'.'.$area;
2172: my $currprivs = $env{'user.priv.'.$crsrole.'.'.$area.'.'.$where};
2173: $currprivs =~ s/^://;
2174: $currprivs =~ s/\&F$//;
2175: my @curr_grp_privs = split(/\&F:/,$currprivs);
2176: @curr_grp_privs = sort(@curr_grp_privs);
2177: my @diffs;
2178: if (@group_privs > 0 || @curr_grp_privs > 0) {
2179: @diffs = &Apache::loncommon::compare_arrays(\@group_privs,\@curr_grp_privs);
2180: }
2181: if (@diffs == 0) {
2182: last;
2183: } else {
2184: unless(grep(/^\Qgr\E$/,@rolecodes)) {
2185: push(@rolecodes,'gr');
2186: }
2187: &gather_roleprivs(\%allroles,\%allgroups,
2188: \%userroles,$where,$role,
2189: $tstart,$tend,$status_in_db);
2190: if ($status_in_db eq 'active') {
2191: &Apache::lonnet::get_groups_roles($udom,$uname,
2192: $courseroles{$udom},
2193: \@rolecodes,\%groups_roles);
2194: }
2195: $changed_groups{$udom.'_'.$uname}{$group} = $status_in_db;
2196: last;
2197: }
2198: }
2199: }
2200: $checkedgroup{$where} = 1;
2201: }
2202: } elsif ($role =~ /^cr/) {
2203: my $status_in_db =
2204: &curr_role_status($tstart,$tend,$refresh,$now);
2205: my ($rdummy,$rest) = split(/\//,$role,2);
2206: my %currpriv;
2207: unless (exists($crprivs{$rest})) {
2208: my ($rdomain,$rauthor,$rrole)=split(/\//,$rest);
2209: my $homsvr=&Apache::lonnet::homeserver($rauthor,$rdomain);
2210: if (&Apache::lonnet::hostname($homsvr) ne '') {
2211: my ($rdummy,$roledef)=
2212: &Apache::lonnet::get('roles',["rolesdef_$rrole"],
2213: $rdomain,$rauthor);
2214: if (($rdummy ne 'con_lost') && ($roledef ne '')) {
2215: my $i = 0;
2216: my @scopes = ('sys','dom','crs');
2217: my @privs = split(/\_/,$roledef);
2218: foreach my $priv (@privs) {
2219: my ($blank,@prv) = split(/:/,$priv);
2220: @prv = map { $_ .= (/\&\w+$/ ? '':'&F') } @prv;
1.264 raeburn 2221: if (@prv) {
2222: $priv = ':'.join(':',sort(@prv));
2223: }
1.260 raeburn 2224: $crprivs{$rest}{$scopes[$i]} = $priv;
2225: $i++;
2226: }
2227: }
2228: }
2229: }
1.269.2.6 raeburn 2230: my $status_in_env =
2231: &curr_role_status($currstart,$currend,$refresh,$update);
2232: if ($status_in_env eq 'active') {
2233: $currpriv{sys} = $env{"user.priv.$rolekey./"};
2234: $currpriv{dom} = $env{"user.priv.$rolekey./$udom/"};
2235: $currpriv{crs} = $env{"user.priv.$rolekey.$where"};
2236: if (keys(%crprivs)) {
2237: if (($crprivs{$rest}{sys} ne $currpriv{sys}) ||
2238: ($crprivs{$rest}{dom} ne $currpriv{dom})
1.260 raeburn 2239: ||
1.269.2.6 raeburn 2240: ($crprivs{$rest}{crs} ne $currpriv{crs})) {
2241: &gather_roleprivs(\%allroles,\%allgroups,
2242: \%userroles,$where,$role,
2243: $tstart,$tend,$status_in_db);
2244: unless (grep(/^\Q$role\E$/,@changed_roles)) {
2245: push(@changed_roles,$role);
2246: }
1.260 raeburn 2247: $customprivchg{$rolekey} = $status_in_env;
2248: }
2249: }
2250: }
2251: }
2252: }
2253: }
2254: }
2255: foreach my $envkey (keys(%env)) {
2256: next unless ($envkey =~ /^user\.role\./);
2257: next if ($dbroles{$envkey});
2258: next if ($envkey eq 'user.role.'.$env{'request.role'});
2259: my ($currstart,$currend) = split(/\./,$env{$envkey});
2260: my $status_in_env =
2261: &curr_role_status($currstart,$currend,$refresh,$update);
2262: my ($rolekey) = ($envkey =~ /^user\.role\.(.+)$/);
1.269.2.16 raeburn 2263: my ($role,$rest)=split(m{\./},$rolekey,2);
2264: $rest = '/'.$rest;
1.260 raeburn 2265: if (&Apache::lonnet::delenv($envkey,undef,[$role])) {
2266: if ($status_in_env eq 'active') {
2267: if ($role eq 'gr') {
2268: &Apache::lonnet::delete_env_groupprivs($rest,\%courseroles,
2269: \@possroles);
2270: } else {
2271: &Apache::lonnet::delenv("user.priv.$rolekey",undef,[$role]);
2272: &Apache::lonnet::delenv("user.priv.cm.$rest",undef,['cm']);
2273: }
2274: unless (grep(/^\Q$role\E$/,@changed_roles)) {
2275: push(@changed_roles,$role);
2276: }
2277: $deletedroles{$rolekey} = 1;
2278: }
2279: }
2280: }
2281: if (($oldsec) && (@newsec > 0)) {
2282: if (@newsec > 1) {
1.269.2.2 raeburn 2283: $msg = '<p class="LC_warning">'.&mt('The section has changed for your current role. Log-out and log-in again to select a role for the new section.').'</p>';
1.260 raeburn 2284: } else {
2285: my $newrole = $env{'request.role'};
2286: if ($newsec[0] eq 'none') {
2287: $newrole =~ s{(/[^/])$}{};
2288: } elsif ($oldsec eq 'none') {
2289: $newrole .= '/'.$newsec[0];
2290: } else {
2291: $newrole =~ s{([^/]+)$}{$newsec[0]};
2292: }
2293: my $coursedesc = $env{'course.'.$env{'request.course.id'}.'.description'};
2294: my ($curr_role) = ($env{'request.role'} =~ m{^(\w+)\./$match_domain/$match_courseid});
2295: my %temp=('logout_'.$env{'request.course.id'} => time);
2296: &Apache::lonnet::put('email_status',\%temp);
2297: &Apache::lonnet::delenv('user.state.'.$env{'request.course.id'});
2298: &Apache::lonnet::appenv({"request.course.id" => '',
2299: "request.course.fn" => '',
2300: "request.course.uri" => '',
2301: "request.course.sec" => '',
2302: "request.role" => 'cm',
2303: "request.role.adv" => $env{'user.adv'},
2304: "request.role.domain" => $env{'user.domain'}});
2305: my $rolename = &Apache::loncommon::plainname($curr_role);
2306: $msg = '<p><form name="reselectrole" action="/adm/roles" method="post" />'.
2307: '<input type="hidden" name="newrole" value="" />'.
2308: '<input type="hidden" name="selectrole" value="1" />'.
2309: '<span class="LC_info">'.
2310: &mt('Your section has changed for your current [_1] role in [_2].',$rolename,$coursedesc).'</span><br />';
2311: my $button = '<input type="button" name="sectionchanged" value="'.
2312: &mt('Re-Select').'" onclick="javascript:enterrole(this.form,'."'$newrole','sectionchanged'".')" />';
2313: if ($newsec[0] eq 'none') {
2314: $msg .= &mt('[_1] to continue with your new section-less role.',$button);
2315: } else {
2316: $msg .= &mt('[_1] to continue with your new role in section ([_2]).',$button,$newsec[0]);
2317: }
2318: $msg .= '</form></p>';
2319: }
2320: } elsif ($currrole_expired) {
1.269.2.2 raeburn 2321: $msg .= '<p class="LC_warning">';
1.260 raeburn 2322: if (&Apache::loncommon::show_course()) {
2323: $msg .= &mt('Your role in the current course has expired.');
2324: } else {
2325: $msg .= &mt('Your current role has expired.');
2326: }
1.269.2.2 raeburn 2327: $msg .= '<br />'.&mt('However you can continue to use this role until you logout, click the "Re-Select" button, or your session has been idle for more than 24 hours.').'</p>';
1.260 raeburn 2328: }
1.269.2.6 raeburn 2329: &Apache::lonnet::set_userprivs(\%userroles,\%allroles,\%allgroups,\%groups_roles);
2330: my ($curr_is_adv,$curr_role_adv,$curr_author,$curr_role_author);
2331: $curr_author = $env{'user.author'};
2332: if (($env{'request.role'} =~/^au/) || ($env{'request.role'} =~/^ca/) ||
2333: ($env{'request.role'} =~/^aa/)) {
2334: $curr_role_author=1;
2335: }
2336: $curr_is_adv = $env{'user.adv'};
2337: $curr_role_adv = $env{'request.role.adv'};
2338: if (keys(%userroles) > 0) {
2339: foreach my $role (@changed_roles) {
2340: unless(grep(/^\Q$role\E$/,@rolecodes)) {
2341: push(@rolecodes,$role);
2342: }
2343: }
2344: unless(grep(/^\Qcm\E$/,@rolecodes)) {
2345: push(@rolecodes,'cm');
2346: }
2347: &Apache::lonnet::appenv(\%userroles,\@rolecodes);
2348: }
2349: my %newenv;
2350: if (&Apache::lonnet::is_advanced_user($env{'user.domain'},$env{'user.name'})) {
2351: unless ($curr_is_adv) {
2352: $newenv{'user.adv'} = 1;
2353: }
2354: } elsif ($curr_is_adv && !$curr_role_adv) {
2355: &Apache::lonnet::delenv('user.adv');
2356: }
2357: my %authorroleshash =
2358: &Apache::lonnet::get_my_roles('','','userroles',['active'],['au','ca','aa']);
2359: if (keys(%authorroleshash)) {
2360: unless ($curr_author) {
2361: $newenv{'user.author'} = 1;
2362: }
2363: } elsif ($curr_author && !$curr_role_author) {
2364: &Apache::lonnet::delenv('user.author');
2365: }
2366: if ($env{'request.course.id'}) {
2367: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
2368: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
2369: my (@activecrsgroups,$crsgroupschanged);
2370: if ($env{'request.course.groups'}) {
2371: @activecrsgroups = split(/:/,$env{'request.course.groups'});
2372: foreach my $item (keys(%deletedroles)) {
2373: if ($item =~ m{^gr\./\Q$cdom\E/\Q$cnum\E/(\w+)$}) {
2374: if (grep(/^\Q$1\E$/,@activecrsgroups)) {
2375: $crsgroupschanged = 1;
2376: last;
2377: }
2378: }
2379: }
2380: }
2381: unless ($crsgroupschanged) {
2382: foreach my $item (keys(%newgroup)) {
2383: if ($item =~ m{^gr\./\Q$cdom\E/\Q$cnum\E/(\w+)$}) {
2384: if ($newgroup{$item} eq 'active') {
2385: $crsgroupschanged = 1;
2386: last;
2387: }
2388: }
2389: }
2390: }
2391: if ((ref($changed_groups{$env{'request.course.id'}}) eq 'HASH') ||
2392: (ref($groupchange{"/$cdom/$cnum"}) eq 'HASH') ||
2393: ($crsgroupschanged)) {
2394: my %grouproles = &Apache::lonnet::get_my_roles('','','userroles',
2395: ['active'],['gr'],[$cdom],1);
2396: my @activegroups;
2397: foreach my $item (keys(%grouproles)) {
2398: next unless($item =~ /^\Q$cnum\E:\Q$cdom\E/);
2399: my $group;
2400: my ($crsn,$crsd,$role,$remainder) = split(/:/,$item,4);
2401: if ($remainder =~ /:/) {
2402: (my $other,$group) = ($remainder =~ /^([\w:]+):([^:]+)$/);
2403: } else {
2404: $group = $remainder;
2405: }
2406: if ($group ne '') {
2407: push(@activegroups,$group);
2408: }
2409: }
2410: $newenv{'request.course.groups'} = join(':',@activegroups);
2411: }
2412: }
2413: if (keys(%newenv)) {
2414: &Apache::lonnet::appenv(\%newenv);
2415: }
1.260 raeburn 2416: if (!@changed_roles || !(keys(%changed_groups))) {
1.264 raeburn 2417: my ($rolesmsg,$groupsmsg);
1.260 raeburn 2418: if (!@changed_roles) {
2419: if (&Apache::loncommon::show_course()) {
1.264 raeburn 2420: $rolesmsg = &mt('No new courses or communities');
1.260 raeburn 2421: } else {
1.264 raeburn 2422: $rolesmsg = &mt('No role changes');
1.260 raeburn 2423: }
2424: }
2425: if ($hasgroups && !(keys(%changed_groups)) && !(grep(/gr/,@changed_roles))) {
1.264 raeburn 2426: $groupsmsg = &mt('No changes in course/community groups');
1.260 raeburn 2427: }
2428: if (!@changed_roles && !(keys(%changed_groups))) {
1.264 raeburn 2429: if (($msg ne '') || ($groupsmsg ne '')) {
2430: $msg .= '<ul>';
2431: if ($rolesmsg) {
2432: $msg .= '<li>'.$rolesmsg.'</li>';
2433: }
2434: if ($groupsmsg) {
2435: $msg .= '<li>'.$groupsmsg.'</li>';
2436: }
2437: $msg .= '</ul>';
2438: } else {
1.269.2.2 raeburn 2439: $msg = ' <span class="LC_cusr_emph">'.$rolesmsg.'</span><br />';
1.264 raeburn 2440: }
1.260 raeburn 2441: return $msg;
2442: }
2443: }
2444: my $changemsg;
2445: if (@changed_roles > 0) {
2446: if (keys(%newgroup) > 0) {
2447: my $groupmsg;
1.269.2.6 raeburn 2448: my (%curr_groups,%groupdescs,$currcrs);
1.260 raeburn 2449: foreach my $item (sort(keys(%newgroup))) {
2450: if (&is_active_course($item,$refresh,$update,\%roleshash)) {
1.269.2.6 raeburn 2451: if ($item =~ m{^gr\./($match_domain/$match_courseid)/(\w+)$}) {
2452: my ($cdom,$cnum) = split(/\//,$1);
2453: my $group = $2;
2454: if ($currcrs ne $cdom.'_'.$cnum) {
2455: if ($currcrs) {
2456: $groupmsg .= '</ul><li>';
2457: }
2458: $groupmsg .= '<li><b>'.
2459: $env{'course.'.$cdom.'_'.$cnum.'.description'}.'</b><ul>';
1.269.2.7 raeburn 2460: $currcrs = $cdom.'_'.$cnum;
1.269.2.6 raeburn 2461: }
2462: my $groupdesc;
2463: unless (ref($curr_groups{$cdom.'_'.$cnum}) eq 'HASH') {
2464: %{$curr_groups{$cdom.'_'.$cnum}} =
2465: &Apache::longroup::coursegroups($cdom,$cnum);
2466: }
2467: unless ((ref($groupdescs{$cdom.'_'.$cnum}) eq 'HASH') &&
2468: ($groupdescs{$cdom.'_'.$cnum}{$group})) {
2469:
2470: my %groupinfo =
2471: &Apache::longroup::get_group_settings($curr_groups{$cdom.'_'.$cnum}{$group});
2472: $groupdescs{$cdom.'_'.$cnum}{$group} =
2473: &unescape($groupinfo{'description'});
2474: }
2475: $groupdesc = $groupdescs{$cdom.'_'.$cnum}{$group};
1.269.2.9 raeburn 2476: if ($groupdesc) {
2477: $groupmsg .= '<li>'.
2478: &mt('[_1] with status: [_2].',
2479: '<b>'.$groupdesc.'</b>',$newgroup{$item}).'</li>';
2480: }
1.269.2.6 raeburn 2481: }
2482: }
2483: if ($groupmsg) {
2484: $groupmsg .= '</ul></li>';
1.260 raeburn 2485: }
2486: }
2487: if ($groupmsg) {
2488: $changemsg .= '<li>'.
2489: &mt('Courses with new groups').'</li>'.
2490: '<ul>'.$groupmsg.'</ul></li>';
2491: }
2492: }
2493: if (keys(%newrole) > 0) {
1.269.2.9 raeburn 2494: my $newmsg;
1.260 raeburn 2495: foreach my $item (sort(keys(%newrole))) {
1.269.2.6 raeburn 2496: my $desc = &role_desc($item,$update,$refresh,$now);
1.269.2.9 raeburn 2497: if ($desc) {
2498: $newmsg .= '<li>'.
2499: &mt('[_1] with status: [_2].',
1.269.2.18 raeburn 2500: $desc,&mt($newrole{$item})).'</li>';
1.269.2.9 raeburn 2501: }
2502: }
2503: if ($newmsg) {
2504: $changemsg .= '<li>'.&mt('New roles').
2505: '<ul>'.$newmsg.'</ul>'.
2506: '</li>';
1.260 raeburn 2507: }
2508: }
2509: if (keys(%customprivchg) > 0) {
1.269.2.9 raeburn 2510: my $privmsg;
1.260 raeburn 2511: foreach my $item (sort(keys(%customprivchg))) {
1.269.2.6 raeburn 2512: my $desc = &role_desc($item,$update,$refresh,$now);
1.269.2.9 raeburn 2513: if ($desc) {
2514: $privmsg .= '<li>'.$desc.'</li>';
2515: }
1.260 raeburn 2516: }
1.269.2.9 raeburn 2517: if ($privmsg) {
2518: $changemsg .= '<li>'.
2519: &mt('Custom roles with privilege changes').
2520: '<ul>'.$privmsg.'</ul>'.
2521: '</li>';
2522: }
1.260 raeburn 2523: }
2524: if (keys(%rolechange) > 0) {
1.269.2.9 raeburn 2525: my $rolemsg;
1.260 raeburn 2526: foreach my $item (sort(keys(%rolechange))) {
1.269.2.9 raeburn 2527: my $desc = &role_desc($item,$update,$refresh,$now);
2528: if ($desc) {
2529: $rolemsg .= '<li>'.
2530: &mt('[_1] status now: [_2].',$desc,
2531: $rolechange{$item}).'</li>';
2532: }
2533: }
2534: if ($rolemsg) {
1.260 raeburn 2535: $changemsg .= '<li>'.
1.269.2.9 raeburn 2536: &mt('Existing roles with status changes').'</li>'.
2537: '<ul>'.$rolemsg.'</ul>'.
2538: '</li>';
1.260 raeburn 2539: }
2540: }
2541: if (keys(%deletedroles) > 0) {
1.269.2.9 raeburn 2542: my $delmsg;
1.260 raeburn 2543: foreach my $item (sort(keys(%deletedroles))) {
1.269.2.6 raeburn 2544: my $desc = &role_desc($item,$update,$refresh,$now);
1.269.2.9 raeburn 2545: if ($desc) {
2546: $delmsg .= '<li>'.$desc.'</li>';
2547: }
2548: }
2549: if ($delmsg) {
2550: $changemsg .= '<li>'.
2551: &mt('Existing roles now expired').'</li>'.
2552: '<ul>'.$delmsg.'</ul>'.
2553: '</li>';
1.260 raeburn 2554: }
2555: }
2556: }
2557: if ((keys(%changed_groups) > 0) || (keys(%groupchange) > 0)) {
2558: my $groupchgmsg;
2559: foreach my $key (sort(keys(%changed_groups))) {
2560: my $crs = 'gr/'.$key;
2561: $crs =~ s/_/\//;
2562: if (&is_active_course($crs,$refresh,$update,\%roleshash)) {
2563: if (ref($changed_groups{$key}) eq 'HASH') {
2564: my @showgroups;
2565: foreach my $group (sort(keys(%{$changed_groups{$key}}))) {
2566: if ($changed_groups{$key}{$group} eq 'active') {
2567: push(@showgroups,$group);
2568: }
2569: }
2570: if (@showgroups > 0) {
2571: $groupchgmsg .= '<li>'.
2572: &mt('Course: [_1], groups: [_2].',$key,
2573: join(', ',@showgroups)).
2574: '</li>';
2575: }
2576: }
2577: }
2578: }
2579: if (keys(%groupchange) > 0) {
2580: $groupchgmsg .= '<li>'.
2581: &mt('Existing course/community groups with status changes').'</li>'.
2582: '<ul>';
2583: foreach my $crs (sort(keys(%groupchange))) {
1.269.2.6 raeburn 2584: my $cid = $crs;
2585: $cid=~s{^/}{};
2586: $cid=~s{/}{_};
2587: my $crsdesc = $env{'course.'.$cid.'.description'};
2588: my $cdom = $env{'course.'.$cid.'.domain'};
2589: my $cnum = $env{'course.'.$cid.'.num'};
2590: my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum);
2591: my %groupdesc;
1.260 raeburn 2592: if (ref($groupchange{$crs}) eq 'HASH') {
1.269.2.6 raeburn 2593: $groupchgmsg .= '<li>'.&mt('Course/Community: [_1]','<b>'.$crsdesc.'</b><ul>');
1.260 raeburn 2594: foreach my $group (sort(keys(%{$groupchange{$crs}}))) {
1.269.2.6 raeburn 2595: unless ($groupdesc{$group}) {
2596: my %groupinfo = &Apache::longroup::get_group_settings($curr_groups{$group});
2597: $groupdesc{$group} = &unescape($groupinfo{'description'});
2598: }
2599: $groupchgmsg .= '<li>'.&mt('Group: [_1] status now: [_2].','<b>'.$groupdesc{$group}.'</b>',$groupchange{$crs}{$group}).'</li>';
1.260 raeburn 2600: }
2601: $groupchgmsg .= '</ul></li>';
2602: }
2603: }
2604: $groupchgmsg .= '</ul></li>';
2605: }
2606: if ($groupchgmsg) {
2607: $changemsg .= '<li>'.
2608: &mt('Courses with changes in groups').'</li>'.
2609: '<ul>'.$groupchgmsg.'</ul></li>';
2610: }
2611: }
2612: if ($changemsg) {
2613: $msg .= '<ul>'.$changemsg.'</ul>';
1.269.2.9 raeburn 2614: } else {
2615: if (&Apache::loncommon::show_course()) {
2616: $msg = &mt('No new courses or communities');
2617: } else {
2618: $msg = &mt('No role changes');
2619: }
1.260 raeburn 2620: }
1.269.2.6 raeburn 2621: return $msg;
2622: }
2623:
2624: sub role_desc {
2625: my ($item,$update,$refresh,$now) = @_;
2626: my ($where,$trolecode,$role,$tstatus,$tend,$tstart,$twhere,
2627: $trole,$tremark);
1.269.2.8 raeburn 2628: &Apache::lonnet::role_status('user.role.'.$item,$update,$refresh,
2629: $now,\$role,\$where,\$trolecode,
1.269.2.6 raeburn 2630: \$tstatus,\$tstart,\$tend);
1.269.2.9 raeburn 2631: return unless ($role);
1.269.2.6 raeburn 2632: if ($role =~ /^cr\//) {
2633: my ($rdummy,$rdomain,$rauthor,$rrole)=split(/\//,$role);
1.269.2.17 raeburn 2634: $tremark = &mt('Custom role defined by [_1].',$rauthor.':'.$rdomain);
1.269.2.6 raeburn 2635: }
2636: $trole=Apache::lonnet::plaintext($role);
2637: my ($tdom,$trest,$tsection)=
2638: split(/\//,Apache::lonnet::declutter($where));
2639: if (($role eq 'ca') || ($role eq 'aa')) {
2640: my $home = &Apache::lonnet::homeserver($trest,$tdom);
2641: $home = &Apache::lonnet::hostname($home);
2642: $twhere=&mt('User').': '.$trest.' '.&mt('Domain').
2643: ': '.$tdom.' '.&mt('Server').': '.$home;
2644: } elsif ($role eq 'au') {
2645: my $home = &Apache::lonnet::homeserver
2646: ($env{'user.name'},$env{'user.domain'});
2647: $home = &Apache::lonnet::hostname($home);
2648: $twhere=&mt('Domain').': '.$tdom.' '.&mt('Server').
2649: ': '.$home;
2650: } elsif ($trest) {
2651: my $tcourseid=$tdom.'_'.$trest;
2652: my $crstype = &Apache::loncommon::course_type($tcourseid);
2653: $trole = &Apache::lonnet::plaintext($role,$crstype,$tcourseid);
2654: if ($env{'course.'.$tcourseid.'.description'}) {
2655: $twhere=$env{'course.'.$tcourseid.'.description'};
2656: } else {
2657: my %newhash=&Apache::lonnet::coursedescription($tcourseid);
2658: if (%newhash) {
2659: $twhere=$newhash{'description'};
2660: } else {
2661: $twhere=&mt('Currently not available');
1.260 raeburn 2662: }
2663: }
1.269.2.6 raeburn 2664: if ($tsection) {
2665: $twhere.= ' '.&mt('Section').': '.$tsection;
1.260 raeburn 2666: }
1.269.2.6 raeburn 2667: if ($role ne 'st') {
2668: $twhere.= ' '.&mt('Domain').': '.$tdom;
1.260 raeburn 2669: }
1.269.2.6 raeburn 2670: } elsif ($tdom) {
2671: $twhere = &mt('Domain').': '.$tdom;
1.260 raeburn 2672: }
1.269.2.9 raeburn 2673: my $output;
2674: if ($trole) {
2675: $output = $trole;
2676: if ($twhere) {
2677: $output .= " -- $twhere";
2678: }
2679: if ($tremark) {
2680: $output .= '<br />'.$tremark;
2681: }
1.260 raeburn 2682: }
1.269.2.6 raeburn 2683: return $output;
1.260 raeburn 2684: }
2685:
2686: sub curr_role_status {
2687: my ($start,$end,$refresh,$update) = @_;
2688: if (($start) && ($start<0)) { return 'deleted' };
2689: my $status = 'active';
2690: if (($end) && ($end<=$update)) {
2691: $status = 'previous';
2692: }
2693: if (($start) && ($refresh<$start)) {
2694: $status = 'future';
2695: }
2696: return $status;
2697: }
2698:
2699: sub gather_roleprivs {
2700: my ($allroles,$allgroups,$userroles,$area,$role,$tstart,$tend,$status) = @_;
2701: return unless ((ref($allroles) eq 'HASH') && (ref($allgroups) eq 'HASH') && (ref($userroles) eq 'HASH'));
2702: if (($area ne '') && ($role ne '')) {
2703: &Apache::lonnet::userrolelog($role,$env{'user.name'},$env{'user.domain'},
2704: $area,$tstart,$tend);
2705: my $spec=$role.'.'.$area;
2706: $userroles->{'user.role.'.$spec} = $tstart.'.'.$tend;
2707: my ($tdummy,$tdomain,$trest)=split(/\//,$area);
2708: if ($status eq 'active') {
2709: if ($role =~ /^cr\//) {
2710: &Apache::lonnet::custom_roleprivs($allroles,$role,$tdomain,$trest,$spec,$area);
2711: } elsif ($role eq 'gr') {
2712: my %rolehash = &Apache::lonnet::get('roles',[$area.'_'.$role],
2713: $env{'user.domain'},
2714: $env{'user.name'});
2715: my ($trole) = split(/_/,$rolehash{$area.'_'.$role},2);
2716: (undef,my $group_privs) = split(/\//,$trole);
2717: $group_privs = &unescape($group_privs);
2718: &Apache::lonnet::group_roleprivs($allgroups,$area,$group_privs,$tend,$tstart);
2719: } else {
2720: &Apache::lonnet::standard_roleprivs($allroles,$role,$tdomain,$spec,$trest,$area);
2721: }
2722: }
2723: }
2724: return;
2725: }
2726:
2727: sub is_active_course {
2728: my ($rolekey,$refresh,$update,$roleshashref) = @_;
2729: return unless(ref($roleshashref) eq 'HASH');
2730: my ($role,$cdom,$cnum) = split(/\//,$rolekey);
2731: my $is_active;
2732: foreach my $key (keys(%{$roleshashref})) {
2733: if ($key =~ /^\Q$cnum\E:\Q$cdom\E:/) {
2734: my ($tstart,$tend) = split(/:/,$roleshashref->{$key});
2735: my $status = &curr_role_status($tstart,$tend,$refresh,$update);
2736: if ($status eq 'active') {
2737: $is_active = 1;
2738: last;
2739: }
2740: }
2741: }
2742: return $is_active;
2743: }
2744:
1.269.2.2 raeburn 2745: sub get_roles_functions {
1.269.2.18 raeburn 2746: my ($rolescount,$cattype) = @_;
1.269.2.2 raeburn 2747: my @links;
2748: push(@links,["javascript:rolesView('doupdate');",'start-here-22x22',&mt('Check for changes')]);
2749: if ($env{'environment.canrequest.author'}) {
2750: unless (&Apache::loncoursequeueadmin::is_active_author()) {
2751: push(@links,["javascript:rolesView('requestauthor');",'list-add-22x22',&mt('Request author role')]);
2752: }
2753: }
1.269.2.6 raeburn 2754: if (($rolescount > 3) || ($env{'environment.recentroles'})) {
2755: push(@links,['/adm/preferences?action=changerolespref&returnurl=/adm/roles','role_hotlist-22x22',&mt('Hotlist')]);
2756: }
1.269.2.2 raeburn 2757: if (&Apache::lonmenu::check_for_rcrs()) {
2758: push(@links,['/adm/requestcourse','rcrs-22x22',&mt('Request course')]);
2759: }
2760: if ($env{'form.state'} eq 'queued') {
2761: push(@links,["javascript:rolesView('noqueued');",'selfenrl-queue-22x22',&mt('Hide queued')]);
2762: } else {
2763: push(@links,["javascript:rolesView('queued');",'selfenrl-queue-22x22',&mt('Show queued')]);
2764: }
1.269.2.6 raeburn 2765: if ($env{'user.adv'}) {
2766: if ($env{'form.display'} eq 'showall') {
1.269.2.12 raeburn 2767: push(@links,["javascript:rolesView('noshowall');",'edit-redo-22x22',&mt('Exclude expired')]);
1.269.2.6 raeburn 2768: } else {
1.269.2.12 raeburn 2769: push(@links,["javascript:rolesView('showall');",'edit-undo-22x22',&mt('Include expired')]);
1.269.2.6 raeburn 2770: }
1.269.2.2 raeburn 2771: }
1.269.2.18 raeburn 2772: unless ($cattype eq 'none') {
1.269.2.13 raeburn 2773: push(@links,['/adm/coursecatalog','ccat-22x22',&mt('Course catalog')]);
1.269.2.12 raeburn 2774: }
1.269.2.26 raeburn 2775: my $funcs;
2776: if ($env{'browser.mobile'}) {
2777: my @functions;
2778: foreach my $link (@links) {
2779: push(@functions,[$link->[0],$link->[2]]);
2780: }
2781: my $title = 'Display options';
2782: if ($env{'user.adv'}) {
2783: $title = 'Roles options';
2784: }
2785: $funcs = &Apache::lonmenu::create_submenu('','',$title,\@functions,1,'LC_breadcrumbs_hoverable');
2786: $funcs = '<ol class="LC_primary_menu LC_floatright">'.$funcs.'</ol>';
2787: } else {
2788: $funcs = &Apache::lonhtmlcommon::start_funclist();
2789: foreach my $link (@links) {
2790: $funcs .= &Apache::lonhtmlcommon::add_item_funclist(
2791: '<a href="'.$link->[0].'" class="LC_menubuttons_link">'.
2792: '<img src="/res/adm/pages/'.$link->[1].'.png" class="LC_icon" alt="'.$link->[2].'" />'.
2793: $link->[2].'</a>');
2794: }
2795: $funcs .= &Apache::lonhtmlcommon::end_funclist();
2796: $funcs = &Apache::loncommon::head_subbox($funcs);
1.269.2.2 raeburn 2797: }
1.269.2.26 raeburn 2798: return $funcs;
1.269.2.2 raeburn 2799: }
2800:
2801: sub get_queued {
2802: my ($output,%reqcrs);
2803: my ($types,$typenames) = &Apache::loncommon::course_types();
2804: my %statusinfo = &Apache::lonnet::dump('courserequests',$env{'user.domain'},
2805: $env{'user.name'},'^status:');
2806: foreach my $key (keys(%statusinfo)) {
2807: next unless (($statusinfo{$key} eq 'approval') || ($statusinfo{$key} eq 'pending'));
1.269.2.16 raeburn 2808: (undef,my($cdom,$cnum)) = split(/:/,$key);
1.269.2.2 raeburn 2809: my $requestkey = $cdom.'_'.$cnum;
2810: if ($requestkey =~ /^($match_domain)_($match_courseid)$/) {
2811: my %history = &Apache::lonnet::restore($requestkey,'courserequests',
2812: $env{'user.domain'},$env{'user.name'});
2813: next if ((exists($history{'status'})) && ($history{'status'} eq 'created'));
2814: my $reqtime = $history{'reqtime'};
2815: my $lastupdate = $history{'timestamp'};
2816: my $showtype = $history{'crstype'};
2817: if (defined($typenames->{$history{'crstype'}})) {
2818: $showtype = $typenames->{$history{'crstype'}};
2819: }
2820: my $description;
2821: if (ref($history{'details'}) eq 'HASH') {
2822: $description = $history{details}{'cdescr'};
2823: }
2824: @{$reqcrs{$reqtime}} = ($description,$showtype);
2825: }
2826: }
2827: my @sortedtimes = sort {$a <=> $b} (keys(%reqcrs));
2828: if (@sortedtimes > 0) {
2829: $output .= '<p><b>'.&mt('Course/Community requests').'</b><br />'.
2830: &Apache::loncommon::start_data_table().
2831: &Apache::loncommon::start_data_table_header_row().
2832: '<th>'.&mt('Date requested').'</th>'.
2833: '<th>'.&mt('Course title').'</th>'.
2834: '<th>'.&mt('Course type').'</th>';
2835: &Apache::loncommon::end_data_table_header_row();
2836: foreach my $reqtime (@sortedtimes) {
2837: next unless (ref($reqcrs{$reqtime}) eq 'ARRAY');
2838: $output .= &Apache::loncommon::start_data_table_row().
2839: '<td>'.&Apache::lonlocal::locallocaltime($reqtime).'</td>'.
2840: '<td>'.join('</td><td>',@{$reqcrs{$reqtime}}).'</td>'.
2841: &Apache::loncommon::end_data_table_row();
2842: }
2843: $output .= &Apache::loncommon::end_data_table().
2844: '<br /></p>';
2845: }
2846: my $queuedselfenroll = &Apache::loncoursequeueadmin::queued_selfenrollment(1);
2847: if ($queuedselfenroll) {
2848: $output .= '<p><b>'.&mt('Enrollment requests').'</b><br />'.
2849: $queuedselfenroll.'<br /></p>';
2850: }
2851: if ($env{'environment.canrequest.author'}) {
2852: unless (&Apache::loncoursequeueadmin::is_active_author()) {
2853: my $requestauthor;
2854: my ($status,$timestamp) = split(/:/,$env{'environment.requestauthorqueued'});
2855: if (($status eq 'approval') || ($status eq 'approved')) {
2856: $output .= '<p><b>'.&mt('Author role request').'</b><br />';
2857: if ($status eq 'approval') {
1.269.2.18 raeburn 2858: $output .= &mt('A request for Authoring Space submitted on [_1] is awaiting approval',
1.269.2.2 raeburn 2859: &Apache::lonlocal::locallocaltime($timestamp));
2860: } elsif ($status eq 'approved') {
2861: my %roleshash =
2862: &Apache::lonnet::get_my_roles($env{'user.name'},$env{'user.domain'},'userroles',
2863: ['active'],['au'],[$env{'user.domain'}]);
2864: if (keys(%roleshash)) {
2865: $output .= '<span class="LC_info">'.
2866: &mt('Your request for an author role has been approved.').'<br />'.
2867: &mt('Use the "Check for changes" link to update your list of roles.').
2868: '</span>';
2869: }
2870: }
2871: $output .= '</p>';
2872: }
2873: }
2874: }
2875: unless ($output) {
2876: if ($env{'environment.canrequest.author'} || $env{'environment.canrequest.official'} ||
2877: $env{'environment.canrequest.unofficial'} || $env{'environment.canrequest.community'}) {
2878: $output = &mt('No requests for courses, communities or authoring currently queued');
2879: } else {
2880: $output = &mt('No enrollment requests currently queued awaiting approval');
2881: }
2882: }
2883: return '<div class="LC_left_float"><fieldset><legend>'.&mt('Queued requests').'</legend>'.
2884: $output.'</fieldset></div><br clear="all" />';
2885: }
2886:
1.1 harris41 2887: 1;
2888: __END__
1.32 harris41 2889:
2890: =head1 NAME
2891:
2892: Apache::lonroles - User Roles Screen
2893:
2894: =head1 SYNOPSIS
2895:
2896: Invoked by /etc/httpd/conf/srm.conf:
2897:
2898: <Location /adm/roles>
2899: PerlAccessHandler Apache::lonacc
2900: SetHandler perl-script
2901: PerlHandler Apache::lonroles
2902: ErrorDocument 403 /adm/login
2903: ErrorDocument 500 /adm/errorhandler
2904: </Location>
1.64 bowersj2 2905:
2906: =head1 OVERVIEW
2907:
2908: =head2 Choosing Roles
2909:
2910: C<lonroles> is a handler that allows a user to switch roles in
2911: mid-session. LON-CAPA attempts to work with "No Role Specified", the
2912: default role that a user has before selecting a role, as widely as
2913: possible, but certain handlers for example need specification which
2914: course they should act on, etc. Both in this scenario, and when the
2915: handler determines via C<lonnet>'s C<&allowed> function that a certain
2916: action is not allowed, C<lonroles> is used as error handler. This
2917: allows the user to select another role which may have permission to do
1.246 droeschl 2918: what they were trying to do.
1.64 bowersj2 2919:
2920: =begin latex
2921:
2922: \begin{figure}
2923: \begin{center}
2924: \includegraphics[width=0.45\paperwidth,keepaspectratio]{Sample_Roles_Screen}
2925: \caption{\label{Sample_Roles_Screen}Sample Roles Screen}
2926: \end{center}
2927: \end{figure}
2928:
2929: =end latex
2930:
2931: =head2 Role Initialization
2932:
2933: 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 2934:
2935: =head1 INTRODUCTION
2936:
2937: This module enables a user to select what role he wishes to
2938: operate under (instructor, student, teaching assistant, course
2939: coordinator, etc). These roles are pre-established by the actions
2940: of upper-level users.
2941:
2942: This is part of the LearningOnline Network with CAPA project
2943: described at http://www.lon-capa.org.
2944:
2945: =head1 HANDLER SUBROUTINE
2946:
2947: This routine is called by Apache and mod_perl.
2948:
2949: =over 4
2950:
2951: =item *
2952:
2953: Roles Initialization (yes/no)
2954:
2955: =item *
2956:
2957: Get Error Message from Environment
2958:
2959: =item *
2960:
2961: Who is this?
2962:
2963: =item *
2964:
2965: Generate Page Output
2966:
2967: =item *
2968:
2969: Choice or no choice
2970:
2971: =item *
2972:
2973: Table
2974:
2975: =item *
2976:
2977: Privileges
2978:
2979: =back
2980:
2981: =cut
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>