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