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