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