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