Annotation of loncom/auth/lonroles.pm, revision 1.269.2.32
1.1 harris41 1: # The LearningOnline Network with CAPA
2: # User Roles Screen
1.31 www 3: #
1.269.2.32! raeburn 4: # $Id: lonroles.pm,v 1.269.2.31 2017/01/30 18:55:33 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.269.2.32! raeburn 1668: my ($roletext,$roletext_end,$poss_adhoc);
! 1669: if ($trolecode =~ m/^d(c|h|a)\./) {
! 1670: $poss_adhoc = 1;
! 1671: }
! 1672: my $rowspan=($poss_adhoc) ? ''
1.132 albertel 1673: : ' rowspan="2" ';
1674:
1.110 raeburn 1675: unless ($nochoose) {
1.134 www 1676: my $buttonname=$trolecode;
1677: $buttonname=~s/\W//g;
1.110 raeburn 1678: if (!$button) {
1679: if ($switchserver) {
1.212 bisitz 1680: $roletext.='<td'.$rowspan.' class="'.$tbg.'">'
1681: .'<a href="/adm/switchserver?'.$switchserver.'">'
1682: .&mt('Switch Server')
1683: .'</a></td>';
1.110 raeburn 1684: } else {
1.212 bisitz 1685: $roletext.=('<td'.$rowspan.' class="'.$tbg.'"> </td>');
1.110 raeburn 1686: }
1.255 raeburn 1687: if ($switchwarning) {
1688: if ($tremark eq '') {
1689: $tremark = $switchwarning;
1690: } else {
1691: $tremark .= '<br />'.$switchwarning;
1692: }
1693: }
1.110 raeburn 1694: } elsif ($tstatus eq 'is') {
1.212 bisitz 1695: $roletext.='<td'.$rowspan.' class="'.$tbg.'">'.
1696: '<input name="'.$buttonname.'" type="button" value="'.
1.225 bisitz 1697: &mt('Select').'" onclick="javascript:enterrole(this.form,\''.
1.192 raeburn 1698: $trolecode."','".$buttonname.'\');" /></td>';
1.110 raeburn 1699: } elsif ($tryagain) {
1700: $roletext.=
1.212 bisitz 1701: '<td'.$rowspan.' class="'.$tbg.'">'.
1702: '<input name="'.$buttonname.'" type="button" value="'.
1.225 bisitz 1703: &mt('Try Selecting Again').'" onclick="javascript:enterrole(this.form,\''.
1.192 raeburn 1704: $trolecode."','".$buttonname.'\');" /></td>';
1.110 raeburn 1705: } elsif ($advanced) {
1706: $roletext.=
1.212 bisitz 1707: '<td'.$rowspan.' class="'.$tbg.'">'.
1708: '<input name="'.$buttonname.'" type="button" value="'.
1.225 bisitz 1709: &mt('Re-Initialize').'" onclick="javascript:enterrole(this.form,\''.
1.192 raeburn 1710: $trolecode."','".$buttonname.'\');" /></td>';
1.209 raeburn 1711: } elsif ($reinit) {
1712: $roletext.=
1.212 bisitz 1713: '<td'.$rowspan.' class="'.$tbg.'">'.
1714: '<input name="'.$buttonname.'" type="button" value="'.
1.225 bisitz 1715: &mt('Re-Select').'" onclick="javascript:enterrole(this.form,\''.
1.209 raeburn 1716: $trolecode."','".$buttonname.'\');" /></td>';
1.110 raeburn 1717: } else {
1.209 raeburn 1718: $roletext.=
1.212 bisitz 1719: '<td'.$rowspan.' class="'.$tbg.'">'.
1720: '<input name="'.$buttonname.'" type="button" value="'.
1.225 bisitz 1721: &mt('Re-Select').'" onclick="javascript:enterrole(this.form,\''.
1.209 raeburn 1722: $trolecode."','".$buttonname.'\');" /></td>';
1.110 raeburn 1723: }
1724: }
1.165 albertel 1725: if ($trolecode !~ m/^(dc|ca|au|aa)\./) {
1726: $tremark.=&Apache::lonannounce::showday(time,1,
1727: &Apache::lonannounce::readcalendar($tdom.'_'.$trest));
1728: }
1.212 bisitz 1729: $roletext.='<td>'.$trole.'</td>'
1730: .'<td>'.$twhere.'</td>'
1731: .'<td>'.$tpstart.'</td>'
1.223 raeburn 1732: .'<td>'.$tpend.'</td>';
1.269.2.32! raeburn 1733: unless ($poss_adhoc) {
1.223 raeburn 1734: $roletext_end = '<td colspan="4">'.
1735: $tremark.' '.
1736: '</td>';
1.132 albertel 1737: }
1.223 raeburn 1738: return ($roletext,$roletext_end);
1.110 raeburn 1739: }
1740:
1.193 raeburn 1741: sub check_author_homeserver {
1.183 www 1742: my ($uname,$udom)=@_;
1.193 raeburn 1743: if (($uname eq '') || ($udom eq '')) {
1744: return ('fail','');
1745: }
1.183 www 1746: my $home = &Apache::lonnet::homeserver($uname,$udom);
1.193 raeburn 1747: if (&Apache::lonnet::host_domain($home) ne $udom) {
1748: return ('fail',$home);
1749: }
1.183 www 1750: my @ids=&Apache::lonnet::current_machine_ids();
1.193 raeburn 1751: if (grep(/^\Q$home\E$/,@ids)) {
1752: return ('ok',$home);
1753: } else {
1754: return ('switchserver',$home);
1.183 www 1755: }
1756: }
1757:
1.269.2.27 raeburn 1758: sub check_for_adhoc {
1.269.2.31 raeburn 1759: my ($dcroles,$helpdeskroles,$update,$then) = @_;
1.104 raeburn 1760: my $numdc = 0;
1.269.2.31 raeburn 1761: my $numhelpdesk = 0;
1.269.2.27 raeburn 1762: my $numadhoc = 0;
1763: my $num_custom_adhoc = 0;
1.269.2.32! raeburn 1764: if (($env{'user.adv'}) || ($env{'user.rar'})) {
1.269.2.22 raeburn 1765: foreach my $envkey (sort(keys(%env))) {
1.269.2.31 raeburn 1766: if ($envkey=~/^user\.role\.(dc|dh|da)\.\/($match_domain)\/$/) {
1.269.2.27 raeburn 1767: my $role = $1;
1768: my $roledom = $2;
1769: my $liverole = 1;
1.118 albertel 1770: my ($tstart,$tend)=split(/\./,$env{$envkey});
1.260 raeburn 1771: my $limit = $update;
1.269.2.31 raeburn 1772: if ($env{'request.role'} eq "$role./$roledom/") {
1.260 raeburn 1773: $limit = $then;
1774: }
1.269.2.27 raeburn 1775: if ($tstart && $tstart>$limit) { $liverole = 0; }
1776: if ($tend && $tend <$limit) { $liverole = 0; }
1777: if ($liverole) {
1778: if ($role eq 'dc') {
1779: $dcroles->{$roledom} = $envkey;
1780: $numdc++;
1781: } else {
1.269.2.31 raeburn 1782: $helpdeskroles->{$roledom} = $envkey;
1.269.2.30 raeburn 1783: my %domdefaults = &Apache::lonnet::get_domain_defaults($roledom);
1784: if (ref($domdefaults{'adhocroles'}) eq 'HASH') {
1785: if (keys(%{$domdefaults{'adhocroles'}})) {
1786: $numadhoc ++;
1787: }
1.269.2.27 raeburn 1788: }
1.269.2.31 raeburn 1789: $numhelpdesk++;
1.269.2.27 raeburn 1790: }
1.104 raeburn 1791: }
1792: }
1793: }
1794: }
1.269.2.31 raeburn 1795: return ($numdc,$numhelpdesk,$numadhoc);
1.104 raeburn 1796: }
1797:
1.185 raeburn 1798: sub adhoc_course_role {
1.260 raeburn 1799: my ($refresh,$update,$then) = @_;
1.239 raeburn 1800: my ($cdom,$cnum,$crstype);
1.201 raeburn 1801: $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
1802: $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.239 raeburn 1803: $crstype = &Apache::loncommon::course_type();
1.260 raeburn 1804: if (&check_forcc($cdom,$cnum,$refresh,$update,$then,$crstype)) {
1.185 raeburn 1805: my $setprivs;
1.198 raeburn 1806: if (!defined($env{'user.role.'.$env{'form.switchrole'}})) {
1.185 raeburn 1807: $setprivs = 1;
1808: } else {
1.198 raeburn 1809: my ($start,$end) = split(/\./,$env{'user.role.'.$env{'form.switchrole'}});
1.232 raeburn 1810: if (($start && ($start>$refresh || $start == -1)) ||
1.260 raeburn 1811: ($end && $end<$update)) {
1.185 raeburn 1812: $setprivs = 1;
1813: }
1.232 raeburn 1814: }
1.269.2.5 raeburn 1815: unless ($setprivs) {
1816: if (!exists($env{'user.priv.'.$env{'form.switchrole'}.'./'})) {
1817: $setprivs = 1;
1818: }
1819: }
1.185 raeburn 1820: if ($setprivs) {
1.269.2.16 raeburn 1821: if ($env{'form.switchrole'} =~ m-^(in|ta|ep|ad|st|cr)(.*?)\./\Q$cdom\E/\Q$cnum\E/?(\w*)$-) {
1.185 raeburn 1822: my $role = $1;
1823: my $custom_role = $2;
1824: my $usec = $3;
1825: if ($role eq 'cr') {
1.199 raeburn 1826: if ($custom_role =~ m-^/$match_domain/$match_username/\w+$-) {
1.185 raeburn 1827: $role .= $custom_role;
1828: } else {
1829: return;
1830: }
1831: }
1.208 raeburn 1832: my (%userroles,%newrole,%newgroups,%group_privs);
1833: my %cgroups =
1834: &Apache::lonnet::get_active_groups($env{'user.domain'},
1835: $env{'user.name'},$cdom,$cnum);
1.269.2.29 raeburn 1836: my $ccrole;
1837: if ($crstype eq 'Community') {
1838: $ccrole = 'co';
1839: } else {
1840: $ccrole = 'cc';
1841: }
1.208 raeburn 1842: foreach my $group (keys(%cgroups)) {
1843: $group_privs{$group} =
1.269.2.29 raeburn 1844: $env{'user.priv.'.$ccrole.'./'.$cdom.'/'.$cnum.'./'.$cdom.'/'.$cnum.'/'.$group};
1.208 raeburn 1845: }
1846: $newgroups{'/'.$cdom.'/'.$cnum} = \%group_privs;
1.185 raeburn 1847: my $area = '/'.$cdom.'/'.$cnum;
1848: my $spec = $role.'.'.$area;
1849: if ($usec ne '') {
1850: $spec .= '/'.$usec;
1851: $area .= '/'.$usec;
1852: }
1.269.2.5 raeburn 1853: if ($role =~ /^cr/) {
1854: &Apache::lonnet::custom_roleprivs(\%newrole,$role,$cdom,$cnum,$spec,$area);
1855: } else {
1856: &Apache::lonnet::standard_roleprivs(\%newrole,$role,$cdom,$spec,$cnum,$area);
1857: }
1.208 raeburn 1858: &Apache::lonnet::set_userprivs(\%userroles,\%newrole,\%newgroups);
1.232 raeburn 1859: my $adhocstart = $refresh-1;
1.185 raeburn 1860: $userroles{'user.role.'.$spec} = $adhocstart.'.';
1.186 raeburn 1861: &Apache::lonnet::appenv(\%userroles,[$role,'cm']);
1.185 raeburn 1862: }
1863: }
1864: }
1865: return;
1866: }
1867:
1868: sub check_forcc {
1.260 raeburn 1869: my ($cdom,$cnum,$refresh,$update,$then,$crstype) = @_;
1.239 raeburn 1870: my ($is_cc,$ccrole);
1871: if ($crstype eq 'Community') {
1872: $ccrole = 'co';
1873: } else {
1874: $ccrole = 'cc';
1875: }
1.266 droeschl 1876: if (&Apache::lonnet::is_course($cdom,$cnum)) {
1877: my $envkey = 'user.role.'.$ccrole.'./'.$cdom.'/'.$cnum;
1878: if (defined($env{$envkey})) {
1879: $is_cc = 1;
1880: my ($tstart,$tend)=split(/\./,$env{$envkey});
1881: my $limit = $update;
1882: if ($env{'request.role'} eq $ccrole.'./'.$cdom.'/'.$cnum) {
1883: $limit = $then;
1.185 raeburn 1884: }
1.266 droeschl 1885: if ($tstart && $tstart>$refresh) { $is_cc = 0; }
1886: if ($tend && $tend <$limit) { $is_cc = 0; }
1.185 raeburn 1887: }
1888: }
1889: return $is_cc;
1890: }
1891:
1.108 raeburn 1892: sub courselink {
1.269.2.27 raeburn 1893: my ($roledom,$rowtype,$role) = @_;
1.109 raeburn 1894: my $courseform=&Apache::loncommon::selectcourse_link
1.269.2.27 raeburn 1895: ('rolechoice','course'.$rowtype.'_'.$roledom.'_'.$role,
1896: 'domain'.$rowtype.'_'.$roledom.'_'.$role,
1897: 'coursedesc'.$rowtype.'_'.$roledom.'_'.$role,
1898: $roledom.':'.$role,undef,'Course/Community');
1899: my $hiddenitems = '<input type="hidden" name="domain'.$rowtype.'_'.$roledom.'_'.$role.'" value="'.$roledom.'" />'.
1900: '<input type="hidden" name="origdom'.$rowtype.'_'.$roledom.'_'.$role.'" value="'.$roledom.'" />'.
1901: '<input type="hidden" name="course'.$rowtype.'_'.$roledom.'_'.$role.'" value="" />'.
1902: '<input type="hidden" name="coursedesc'.$rowtype.'_'.$roledom.'_'.$role.'" value="" />';
1.112 raeburn 1903: return $courseform.$hiddenitems;
1.109 raeburn 1904: }
1905:
1906: sub coursepick_jscript {
1.269.2.25 raeburn 1907: my %js_lt = &Apache::lonlocal::texthash(
1.239 raeburn 1908: 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 1909: youc => 'You can only use this screen to select courses and communities in the current domain.',
1.184 raeburn 1910: );
1.269.2.24 raeburn 1911: &js_escape(\%js_lt);
1.104 raeburn 1912: my $verify_script = <<"END";
1.179 raeburn 1913: <script type="text/javascript">
1.225 bisitz 1914: // <![CDATA[
1.108 raeburn 1915: function verifyCoursePick(caller) {
1916: var numbutton = getIndex(caller)
1.112 raeburn 1917: var pickedCourse = document.rolechoice.elements[numbutton+4].value
1918: var pickedDomain = document.rolechoice.elements[numbutton+2].value
1919: if (document.rolechoice.elements[numbutton+2].value == document.rolechoice.elements[numbutton+3].value) {
1.104 raeburn 1920: if (pickedCourse != '') {
1.108 raeburn 1921: if (numbutton != -1) {
1922: var courseTarget = "cc./"+pickedDomain+"/"+pickedCourse
1923: document.rolechoice.elements[numbutton+1].name = courseTarget
1924: document.rolechoice.submit()
1925: }
1.104 raeburn 1926: }
1927: else {
1.269.2.24 raeburn 1928: alert("$js_lt{'plsu'}");
1.104 raeburn 1929: }
1930: }
1931: else {
1.269.2.24 raeburn 1932: alert("$js_lt{'youc'}")
1.104 raeburn 1933: }
1934: }
1.109 raeburn 1935: function getIndex(caller) {
1.108 raeburn 1936: for (var i=0;i<document.rolechoice.elements.length;i++) {
1.109 raeburn 1937: if (document.rolechoice.elements[i] == caller) {
1.108 raeburn 1938: return i;
1939: }
1940: }
1941: return -1;
1942: }
1.225 bisitz 1943: // ]]>
1.104 raeburn 1944: </script>
1945: END
1.109 raeburn 1946: return $verify_script;
1.104 raeburn 1947: }
1948:
1.193 raeburn 1949: sub coauthorlink {
1950: my ($dcdom,$rowtype) = @_;
1951: my $coauthorform=&Apache::loncommon::selectauthor_link('rolechoice',$dcdom);
1952: my $hiddenitems = '<input type="hidden" name="adhoccauname'.$rowtype.'_'.$dcdom.'" value="" />';
1953: return $coauthorform.$hiddenitems;
1954: }
1955:
1.113 raeburn 1956: sub display_cc_role {
1957: my $rolekey = shift;
1.223 raeburn 1958: my ($roletext,$roletext_end);
1.118 albertel 1959: my $advanced = $env{'user.adv'};
1960: my $tryagain = $env{'form.tryagain'};
1.113 raeburn 1961: unless ($rolekey =~/^error\:/) {
1.240 raeburn 1962: if ($rolekey =~ m{^user\.role\.(cc|co)\./($match_domain)/($match_courseid)$}) {
1963: my $ccrole = $1;
1.249 raeburn 1964: my $tdom = $2;
1965: my $trest = $3;
1966: my $tcourseid = $tdom.'_'.$trest;
1967: my $trolecode = $ccrole.'./'.$tdom.'/'.$trest;
1.113 raeburn 1968: my $twhere;
1.152 raeburn 1969: my $ttype;
1.212 bisitz 1970: my $tbg='LC_roles_is';
1.113 raeburn 1971: my %newhash=&Apache::lonnet::coursedescription($tcourseid);
1972: if (%newhash) {
1973: $twhere=$newhash{'description'}.
1.261 bisitz 1974: ' <span class="LC_fontsize_small">'.
1.249 raeburn 1975: &Apache::loncommon::syllabuswrapper(&mt('Syllabus'),$trest,$tdom).
1.211 tempelho 1976: '</span>';
1.153 raeburn 1977: $ttype = $newhash{'type'};
1.113 raeburn 1978: } else {
1979: $twhere=&mt('Currently not available');
1.118 albertel 1980: $env{'course.'.$tcourseid.'.description'}=$twhere;
1.110 raeburn 1981: }
1.242 raeburn 1982: my $trole = &Apache::lonnet::plaintext($ccrole,$ttype,$tcourseid);
1.258 raeburn 1983: $twhere.="<br />".&mt('Domain').":".$tdom;
1.249 raeburn 1984: ($roletext,$roletext_end) = &build_roletext($trolecode,$tdom,$trest,'is',$tryagain,$advanced,'',$tbg,$trole,$twhere,'','','',1,'');
1.104 raeburn 1985: }
1986: }
1.223 raeburn 1987: return ($roletext,$roletext_end);
1.104 raeburn 1988: }
1989:
1.192 raeburn 1990: sub adhoc_roles_row {
1.138 raeburn 1991: my ($dcdom,$rowtype) = @_;
1.212 bisitz 1992: my $output = &Apache::loncommon::continue_data_table_row()
1.269.2.26 raeburn 1993: .' <td colspan="5" class="LC_textsize_mobile">'
1.212 bisitz 1994: .&mt('[_1]Ad hoc[_2] roles in domain [_3] --'
1995: ,'<span class="LC_cusr_emph">','</span>',$dcdom)
1.227 bisitz 1996: .' ';
1.269.2.27 raeburn 1997: my $role = 'cc';
1998: my $selectcclink = &courselink($dcdom,$rowtype,$role);
1.239 raeburn 1999: my $ccrole = &Apache::lonnet::plaintext('co',undef,undef,1);
1.182 www 2000: my $carole = &Apache::lonnet::plaintext('ca');
1.193 raeburn 2001: my $selectcalink = &coauthorlink($dcdom,$rowtype);
1.227 bisitz 2002: $output.=$ccrole.': '.$selectcclink
1.249 raeburn 2003: .' | '.$carole.': '.$selectcalink.'</td>'
1.212 bisitz 2004: .&Apache::loncommon::end_data_table_row();
1.108 raeburn 2005: return $output;
2006: }
2007:
1.269.2.27 raeburn 2008: sub adhoc_customroles_row {
1.269.2.30 raeburn 2009: my ($role,$dhdom,$rowtype,$update,$then) = @_;
2010: my $liverole = 1;
2011: my ($tstart,$tend)=split(/\./,$env{"user.role.$role./$dhdom/"});
2012: my $limit = $update;
2013: if (($role eq 'dh') && ($env{'request.role'} eq 'dh./'.$dhdom.'/')) {
2014: $limit = $then;
2015: }
2016: if ($tstart && $tstart>$limit) { $liverole = 0; }
2017: if ($tend && $tend <$limit) { $liverole = 0; }
2018: return unless ($liverole);
2019: my %domdefaults = &Apache::lonnet::get_domain_defaults($dhdom);
2020: if (ref($domdefaults{'adhocroles'}) eq 'HASH') {
2021: if (scalar(keys(%{$domdefaults{'adhocroles'}})) > 0) {
2022: return &Apache::loncommon::continue_data_table_row()
2023: .' <td colspan="5" class="LC_textsize_mobile">'
2024: .&mt('[_1]Ad hoc[_2] course/community roles in domain [_3] --',
2025: '<span class="LC_cusr_emph">','</span>',$dhdom)
2026: .' '.&courselink($dhdom,$rowtype,$role);
2027: }
1.269.2.27 raeburn 2028: }
2029: return;
2030: }
2031:
1.104 raeburn 2032: sub recent_filename {
2033: my $area=shift;
1.149 www 2034: return 'nohist_recent_'.&escape($area);
1.104 raeburn 2035: }
2036:
1.139 raeburn 2037: sub courseloadpage {
2038: my ($courseid) = @_;
2039: my $startpage;
1.144 albertel 2040: my %entry_settings = &Apache::lonnet::get('nohist_whatsnew',
2041: [$courseid.':courseinit']);
1.139 raeburn 2042: my ($tmp) = %entry_settings;
1.144 albertel 2043: unless ($tmp =~ /^error: 2 /) {
1.139 raeburn 2044: $startpage = $entry_settings{$courseid.':courseinit'};
2045: }
2046: if ($startpage eq '') {
2047: if (exists($env{'environment.course_init_display'})) {
2048: $startpage = $env{'environment.course_init_display'};
2049: }
2050: }
2051: return $startpage;
2052: }
2053:
1.260 raeburn 2054: sub update_session_roles {
2055: my $then=$env{'user.login.time'};
2056: my $refresh=$env{'user.refresh.time'};
2057: if (!$refresh) {
2058: $refresh = $then;
2059: }
2060: my $update = $env{'user.update.time'};
2061: if (!$update) {
2062: $update = $then;
2063: }
2064: my $now = time;
2065: my %roleshash =
2066: &Apache::lonnet::get_my_roles('','','userroles',
2067: ['active','future','previous'],
2068: undef,undef,1);
2069: my ($msg,@newsec,$oldsec,$currrole_expired,@changed_roles,
1.264 raeburn 2070: %changed_groups,%dbroles,%deletedroles,%allroles,%allgroups,
1.260 raeburn 2071: %userroles,%checkedgroup,%crprivs,$hasgroups,%rolechange,
2072: %groupchange,%newrole,%newgroup,%customprivchg,%groups_roles,
2073: @rolecodes);
2074: my @possroles = ('cr','st','ta','ad','ep','in','co','cc');
2075: my %courseroles;
2076: foreach my $item (keys(%roleshash)) {
2077: my ($uname,$udom,$role,$remainder) = split(/:/,$item,4);
2078: my ($tstart,$tend) = split(/:/,$roleshash{$item});
2079: my ($section,$group,@group_privs);
2080: if ($role =~ m{^gr/(\w*)$}) {
2081: $role = 'gr';
2082: my $priv = $1;
2083: next if ($tstart eq '-1');
2084: if (&curr_role_status($tstart,$tend,$refresh,$now) eq 'active') {
2085: if ($priv ne '') {
2086: push(@group_privs,$priv);
2087: }
2088: }
2089: if ($remainder =~ /:/) {
2090: (my $additional_privs,$group) =
2091: ($remainder =~ /^([\w:]+):([^:]+)$/);
2092: if ($additional_privs ne '') {
2093: if (&curr_role_status($tstart,$tend,$refresh,$now) eq 'active') {
2094: push(@group_privs,split(/:/,$additional_privs));
2095: @group_privs = sort(@group_privs);
2096: }
2097: }
2098: } else {
2099: $group = $remainder;
2100: }
2101: } else {
2102: $section = $remainder;
2103: }
2104: my $where = "/$udom/$uname";
2105: if ($section ne '') {
2106: $where .= "/$section";
2107: } elsif ($group ne '') {
2108: $where .= "/$group";
2109: }
2110: my $rolekey = "$role.$where";
2111: my $envkey = "user.role.$rolekey";
2112: $dbroles{$envkey} = 1;
2113: if (($env{'request.role'} eq $rolekey) && ($role ne 'st')) {
2114: if (&curr_role_status($tstart,$tend,$refresh,$now) ne 'active') {
2115: $currrole_expired = 1;
2116: }
2117: }
2118: if ($env{$envkey} eq '') {
2119: my $status_in_db =
1.269.2.2 raeburn 2120: &curr_role_status($tstart,$tend,$now,$now);
1.260 raeburn 2121: &gather_roleprivs(\%allroles,\%allgroups,\%userroles,$where,$role,$tstart,$tend,$status_in_db);
2122: if (($role eq 'st') && ($env{'request.role'} =~ m{^\Q$role\E\.\Q/$udom/$uname\E})) {
2123: if ($status_in_db eq 'active') {
2124: if ($section eq '') {
2125: push(@newsec,'none');
2126: } else {
2127: push(@newsec,$section);
2128: }
2129: }
2130: } else {
2131: unless (grep(/^\Q$role\E$/,@changed_roles)) {
2132: push(@changed_roles,$role);
2133: }
2134: if ($status_in_db ne 'previous') {
2135: if ($role eq 'gr') {
2136: $newgroup{$rolekey} = $status_in_db;
2137: if ($status_in_db eq 'active') {
2138: unless (ref($courseroles{$udom}) eq 'HASH') {
2139: %{$courseroles{$udom}} =
2140: &Apache::lonnet::get_my_roles('','','userroles',
2141: ['active'],\@possroles,
2142: [$udom],1);
2143: }
2144: &Apache::lonnet::get_groups_roles($udom,$uname,
2145: $courseroles{$udom},
2146: \@rolecodes,\%groups_roles);
2147: }
2148: } else {
2149: $newrole{$rolekey} = $status_in_db;
2150: }
2151: }
2152: }
2153: } else {
2154: my ($currstart,$currend) = split(/\./,$env{$envkey});
2155: if ($role eq 'gr') {
2156: if (&curr_role_status($currstart,$currend,$refresh,$update) ne 'previous') {
2157: $hasgroups = 1;
2158: }
2159: }
2160: if (($currstart ne $tstart) || ($currend ne $tend)) {
2161: my $status_in_env =
2162: &curr_role_status($currstart,$currend,$refresh,$update);
2163: my $status_in_db =
1.269.2.2 raeburn 2164: &curr_role_status($tstart,$tend,$now,$now);
1.260 raeburn 2165: if ($status_in_env ne $status_in_db) {
2166: if ($status_in_env eq 'active') {
2167: if ($role eq 'st') {
2168: if ($env{'request.role'} eq $rolekey) {
2169: my $switchsection;
2170: unless (ref($courseroles{$udom}) eq 'HASH') {
2171: %{$courseroles{$udom}} =
2172: &Apache::lonnet::get_my_roles('','','userroles',
2173: ['active'],
2174: \@possroles,[$udom],1);
2175: }
2176: foreach my $crsrole (keys(%{$courseroles{$udom}})) {
2177: if ($crsrole =~ /^\Q$uname\E:\Q$udom\E:st/) {
2178: $switchsection = 1;
2179: last;
2180: }
2181: }
2182: if ($switchsection) {
2183: if ($section eq '') {
2184: $oldsec = 'none';
2185: } else {
2186: $oldsec = $section;
2187: }
2188: &gather_roleprivs(\%allroles,\%allgroups,\%userroles,$where,$role,$tstart,$tend,$status_in_db);
2189: } else {
2190: $currrole_expired = 1;
2191: next;
2192: }
2193: }
2194: }
2195: unless ($rolekey eq $env{'request.role'}) {
2196: if ($role eq 'gr') {
2197: &Apache::lonnet::delete_env_groupprivs($where,\%courseroles,\@possroles);
2198: } else {
2199: &Apache::lonnet::delenv("user.priv.$rolekey",undef,[$role]);
2200: &Apache::lonnet::delenv("user.priv.cm.$where",undef,['cm']);
2201: }
2202: &gather_roleprivs(\%allroles,\%allgroups,\%userroles,$where,$role,$tstart,$tend,$status_in_db);
2203: }
2204: } elsif ($status_in_db eq 'active') {
2205: if (($role eq 'st') &&
2206: ($env{'request.role'} =~ m{^\Q$role\E\.\Q/$udom/$uname\E})) {
2207: if ($section eq '') {
2208: push(@newsec,'none');
2209: } else {
2210: push(@newsec,$section);
2211: }
2212: } elsif ($role eq 'gr') {
2213: unless (ref($courseroles{$udom}) eq 'HASH') {
2214: %{$courseroles{$udom}} =
2215: &Apache::lonnet::get_my_roles('','','userroles',
2216: ['active'],
2217: \@possroles,[$udom],1);
2218: }
2219: &Apache::lonnet::get_groups_roles($udom,$uname,
2220: $courseroles{$udom},
2221: \@rolecodes,\%groups_roles);
2222: }
2223: &gather_roleprivs(\%allroles,\%allgroups,\%userroles,$where,$role,$tstart,$tend,$status_in_db);
2224: }
2225: unless (grep(/^\Q$role\E$/,@changed_roles)) {
2226: push(@changed_roles,$role);
2227: }
2228: if ($role eq 'gr') {
2229: $groupchange{"/$udom/$uname"}{$group} = $status_in_db;
2230: } else {
2231: $rolechange{$rolekey} = $status_in_db;
2232: }
2233: }
2234: } else {
2235: if ($role eq 'gr') {
2236: unless ($checkedgroup{$where}) {
2237: my $status_in_db =
2238: &curr_role_status($tstart,$tend,$refresh,$now);
2239: if ($tstart eq '-1') {
2240: $status_in_db = 'deleted';
2241: }
2242: unless (ref($courseroles{$udom}) eq 'HASH') {
2243: %{$courseroles{$udom}} =
2244: &Apache::lonnet::get_my_roles('','','userroles',
2245: ['active'],
2246: \@possroles,[$udom],1);
2247: }
2248: if (ref($courseroles{$udom}) eq 'HASH') {
2249: foreach my $item (keys(%{$courseroles{$udom}})) {
2250: next unless ($item =~ /^\Q$uname\E/);
2251: my ($cnum,$cdom,$crsrole,$crssec) = split(/:/,$item);
2252: my $area = '/'.$cdom.'/'.$cnum;
2253: if ($crssec ne '') {
2254: $area .= '/'.$crssec;
2255: }
2256: my $crsrolekey = $crsrole.'.'.$area;
2257: my $currprivs = $env{'user.priv.'.$crsrole.'.'.$area.'.'.$where};
2258: $currprivs =~ s/^://;
2259: $currprivs =~ s/\&F$//;
2260: my @curr_grp_privs = split(/\&F:/,$currprivs);
2261: @curr_grp_privs = sort(@curr_grp_privs);
2262: my @diffs;
2263: if (@group_privs > 0 || @curr_grp_privs > 0) {
2264: @diffs = &Apache::loncommon::compare_arrays(\@group_privs,\@curr_grp_privs);
2265: }
2266: if (@diffs == 0) {
2267: last;
2268: } else {
2269: unless(grep(/^\Qgr\E$/,@rolecodes)) {
2270: push(@rolecodes,'gr');
2271: }
2272: &gather_roleprivs(\%allroles,\%allgroups,
2273: \%userroles,$where,$role,
2274: $tstart,$tend,$status_in_db);
2275: if ($status_in_db eq 'active') {
2276: &Apache::lonnet::get_groups_roles($udom,$uname,
2277: $courseroles{$udom},
2278: \@rolecodes,\%groups_roles);
2279: }
2280: $changed_groups{$udom.'_'.$uname}{$group} = $status_in_db;
2281: last;
2282: }
2283: }
2284: }
2285: $checkedgroup{$where} = 1;
2286: }
2287: } elsif ($role =~ /^cr/) {
2288: my $status_in_db =
2289: &curr_role_status($tstart,$tend,$refresh,$now);
2290: my ($rdummy,$rest) = split(/\//,$role,2);
2291: my %currpriv;
2292: unless (exists($crprivs{$rest})) {
2293: my ($rdomain,$rauthor,$rrole)=split(/\//,$rest);
2294: my $homsvr=&Apache::lonnet::homeserver($rauthor,$rdomain);
2295: if (&Apache::lonnet::hostname($homsvr) ne '') {
2296: my ($rdummy,$roledef)=
2297: &Apache::lonnet::get('roles',["rolesdef_$rrole"],
2298: $rdomain,$rauthor);
2299: if (($rdummy ne 'con_lost') && ($roledef ne '')) {
2300: my $i = 0;
2301: my @scopes = ('sys','dom','crs');
2302: my @privs = split(/\_/,$roledef);
2303: foreach my $priv (@privs) {
2304: my ($blank,@prv) = split(/:/,$priv);
2305: @prv = map { $_ .= (/\&\w+$/ ? '':'&F') } @prv;
1.264 raeburn 2306: if (@prv) {
2307: $priv = ':'.join(':',sort(@prv));
2308: }
1.260 raeburn 2309: $crprivs{$rest}{$scopes[$i]} = $priv;
2310: $i++;
2311: }
2312: }
2313: }
2314: }
1.269.2.6 raeburn 2315: my $status_in_env =
2316: &curr_role_status($currstart,$currend,$refresh,$update);
2317: if ($status_in_env eq 'active') {
2318: $currpriv{sys} = $env{"user.priv.$rolekey./"};
2319: $currpriv{dom} = $env{"user.priv.$rolekey./$udom/"};
2320: $currpriv{crs} = $env{"user.priv.$rolekey.$where"};
2321: if (keys(%crprivs)) {
2322: if (($crprivs{$rest}{sys} ne $currpriv{sys}) ||
2323: ($crprivs{$rest}{dom} ne $currpriv{dom})
1.260 raeburn 2324: ||
1.269.2.6 raeburn 2325: ($crprivs{$rest}{crs} ne $currpriv{crs})) {
2326: &gather_roleprivs(\%allroles,\%allgroups,
2327: \%userroles,$where,$role,
2328: $tstart,$tend,$status_in_db);
2329: unless (grep(/^\Q$role\E$/,@changed_roles)) {
2330: push(@changed_roles,$role);
2331: }
1.260 raeburn 2332: $customprivchg{$rolekey} = $status_in_env;
2333: }
2334: }
2335: }
2336: }
2337: }
2338: }
2339: }
2340: foreach my $envkey (keys(%env)) {
2341: next unless ($envkey =~ /^user\.role\./);
2342: next if ($dbroles{$envkey});
2343: next if ($envkey eq 'user.role.'.$env{'request.role'});
2344: my ($currstart,$currend) = split(/\./,$env{$envkey});
2345: my $status_in_env =
2346: &curr_role_status($currstart,$currend,$refresh,$update);
2347: my ($rolekey) = ($envkey =~ /^user\.role\.(.+)$/);
1.269.2.16 raeburn 2348: my ($role,$rest)=split(m{\./},$rolekey,2);
2349: $rest = '/'.$rest;
1.260 raeburn 2350: if (&Apache::lonnet::delenv($envkey,undef,[$role])) {
2351: if ($status_in_env eq 'active') {
2352: if ($role eq 'gr') {
2353: &Apache::lonnet::delete_env_groupprivs($rest,\%courseroles,
2354: \@possroles);
2355: } else {
2356: &Apache::lonnet::delenv("user.priv.$rolekey",undef,[$role]);
2357: &Apache::lonnet::delenv("user.priv.cm.$rest",undef,['cm']);
2358: }
2359: unless (grep(/^\Q$role\E$/,@changed_roles)) {
2360: push(@changed_roles,$role);
2361: }
2362: $deletedroles{$rolekey} = 1;
2363: }
2364: }
2365: }
2366: if (($oldsec) && (@newsec > 0)) {
2367: if (@newsec > 1) {
1.269.2.2 raeburn 2368: $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 2369: } else {
2370: my $newrole = $env{'request.role'};
2371: if ($newsec[0] eq 'none') {
2372: $newrole =~ s{(/[^/])$}{};
2373: } elsif ($oldsec eq 'none') {
2374: $newrole .= '/'.$newsec[0];
2375: } else {
2376: $newrole =~ s{([^/]+)$}{$newsec[0]};
2377: }
2378: my $coursedesc = $env{'course.'.$env{'request.course.id'}.'.description'};
2379: my ($curr_role) = ($env{'request.role'} =~ m{^(\w+)\./$match_domain/$match_courseid});
2380: my %temp=('logout_'.$env{'request.course.id'} => time);
2381: &Apache::lonnet::put('email_status',\%temp);
2382: &Apache::lonnet::delenv('user.state.'.$env{'request.course.id'});
2383: &Apache::lonnet::appenv({"request.course.id" => '',
2384: "request.course.fn" => '',
2385: "request.course.uri" => '',
2386: "request.course.sec" => '',
2387: "request.role" => 'cm',
2388: "request.role.adv" => $env{'user.adv'},
2389: "request.role.domain" => $env{'user.domain'}});
2390: my $rolename = &Apache::loncommon::plainname($curr_role);
2391: $msg = '<p><form name="reselectrole" action="/adm/roles" method="post" />'.
2392: '<input type="hidden" name="newrole" value="" />'.
2393: '<input type="hidden" name="selectrole" value="1" />'.
2394: '<span class="LC_info">'.
2395: &mt('Your section has changed for your current [_1] role in [_2].',$rolename,$coursedesc).'</span><br />';
2396: my $button = '<input type="button" name="sectionchanged" value="'.
2397: &mt('Re-Select').'" onclick="javascript:enterrole(this.form,'."'$newrole','sectionchanged'".')" />';
2398: if ($newsec[0] eq 'none') {
2399: $msg .= &mt('[_1] to continue with your new section-less role.',$button);
2400: } else {
2401: $msg .= &mt('[_1] to continue with your new role in section ([_2]).',$button,$newsec[0]);
2402: }
2403: $msg .= '</form></p>';
2404: }
2405: } elsif ($currrole_expired) {
1.269.2.2 raeburn 2406: $msg .= '<p class="LC_warning">';
1.260 raeburn 2407: if (&Apache::loncommon::show_course()) {
2408: $msg .= &mt('Your role in the current course has expired.');
2409: } else {
2410: $msg .= &mt('Your current role has expired.');
2411: }
1.269.2.2 raeburn 2412: $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 2413: }
1.269.2.6 raeburn 2414: &Apache::lonnet::set_userprivs(\%userroles,\%allroles,\%allgroups,\%groups_roles);
2415: my ($curr_is_adv,$curr_role_adv,$curr_author,$curr_role_author);
2416: $curr_author = $env{'user.author'};
2417: if (($env{'request.role'} =~/^au/) || ($env{'request.role'} =~/^ca/) ||
2418: ($env{'request.role'} =~/^aa/)) {
2419: $curr_role_author=1;
2420: }
2421: $curr_is_adv = $env{'user.adv'};
2422: $curr_role_adv = $env{'request.role.adv'};
2423: if (keys(%userroles) > 0) {
2424: foreach my $role (@changed_roles) {
2425: unless(grep(/^\Q$role\E$/,@rolecodes)) {
2426: push(@rolecodes,$role);
2427: }
2428: }
2429: unless(grep(/^\Qcm\E$/,@rolecodes)) {
2430: push(@rolecodes,'cm');
2431: }
2432: &Apache::lonnet::appenv(\%userroles,\@rolecodes);
2433: }
2434: my %newenv;
2435: if (&Apache::lonnet::is_advanced_user($env{'user.domain'},$env{'user.name'})) {
2436: unless ($curr_is_adv) {
2437: $newenv{'user.adv'} = 1;
2438: }
2439: } elsif ($curr_is_adv && !$curr_role_adv) {
2440: &Apache::lonnet::delenv('user.adv');
2441: }
2442: my %authorroleshash =
2443: &Apache::lonnet::get_my_roles('','','userroles',['active'],['au','ca','aa']);
2444: if (keys(%authorroleshash)) {
2445: unless ($curr_author) {
2446: $newenv{'user.author'} = 1;
2447: }
2448: } elsif ($curr_author && !$curr_role_author) {
2449: &Apache::lonnet::delenv('user.author');
2450: }
2451: if ($env{'request.course.id'}) {
2452: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
2453: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
2454: my (@activecrsgroups,$crsgroupschanged);
2455: if ($env{'request.course.groups'}) {
2456: @activecrsgroups = split(/:/,$env{'request.course.groups'});
2457: foreach my $item (keys(%deletedroles)) {
2458: if ($item =~ m{^gr\./\Q$cdom\E/\Q$cnum\E/(\w+)$}) {
2459: if (grep(/^\Q$1\E$/,@activecrsgroups)) {
2460: $crsgroupschanged = 1;
2461: last;
2462: }
2463: }
2464: }
2465: }
2466: unless ($crsgroupschanged) {
2467: foreach my $item (keys(%newgroup)) {
2468: if ($item =~ m{^gr\./\Q$cdom\E/\Q$cnum\E/(\w+)$}) {
2469: if ($newgroup{$item} eq 'active') {
2470: $crsgroupschanged = 1;
2471: last;
2472: }
2473: }
2474: }
2475: }
2476: if ((ref($changed_groups{$env{'request.course.id'}}) eq 'HASH') ||
2477: (ref($groupchange{"/$cdom/$cnum"}) eq 'HASH') ||
2478: ($crsgroupschanged)) {
2479: my %grouproles = &Apache::lonnet::get_my_roles('','','userroles',
2480: ['active'],['gr'],[$cdom],1);
2481: my @activegroups;
2482: foreach my $item (keys(%grouproles)) {
2483: next unless($item =~ /^\Q$cnum\E:\Q$cdom\E/);
2484: my $group;
2485: my ($crsn,$crsd,$role,$remainder) = split(/:/,$item,4);
2486: if ($remainder =~ /:/) {
2487: (my $other,$group) = ($remainder =~ /^([\w:]+):([^:]+)$/);
2488: } else {
2489: $group = $remainder;
2490: }
2491: if ($group ne '') {
2492: push(@activegroups,$group);
2493: }
2494: }
2495: $newenv{'request.course.groups'} = join(':',@activegroups);
2496: }
2497: }
2498: if (keys(%newenv)) {
2499: &Apache::lonnet::appenv(\%newenv);
2500: }
1.260 raeburn 2501: if (!@changed_roles || !(keys(%changed_groups))) {
1.264 raeburn 2502: my ($rolesmsg,$groupsmsg);
1.260 raeburn 2503: if (!@changed_roles) {
2504: if (&Apache::loncommon::show_course()) {
1.264 raeburn 2505: $rolesmsg = &mt('No new courses or communities');
1.260 raeburn 2506: } else {
1.264 raeburn 2507: $rolesmsg = &mt('No role changes');
1.260 raeburn 2508: }
2509: }
2510: if ($hasgroups && !(keys(%changed_groups)) && !(grep(/gr/,@changed_roles))) {
1.264 raeburn 2511: $groupsmsg = &mt('No changes in course/community groups');
1.260 raeburn 2512: }
2513: if (!@changed_roles && !(keys(%changed_groups))) {
1.264 raeburn 2514: if (($msg ne '') || ($groupsmsg ne '')) {
2515: $msg .= '<ul>';
2516: if ($rolesmsg) {
2517: $msg .= '<li>'.$rolesmsg.'</li>';
2518: }
2519: if ($groupsmsg) {
2520: $msg .= '<li>'.$groupsmsg.'</li>';
2521: }
2522: $msg .= '</ul>';
2523: } else {
1.269.2.2 raeburn 2524: $msg = ' <span class="LC_cusr_emph">'.$rolesmsg.'</span><br />';
1.264 raeburn 2525: }
1.260 raeburn 2526: return $msg;
2527: }
2528: }
2529: my $changemsg;
2530: if (@changed_roles > 0) {
2531: if (keys(%newgroup) > 0) {
2532: my $groupmsg;
1.269.2.6 raeburn 2533: my (%curr_groups,%groupdescs,$currcrs);
1.260 raeburn 2534: foreach my $item (sort(keys(%newgroup))) {
2535: if (&is_active_course($item,$refresh,$update,\%roleshash)) {
1.269.2.6 raeburn 2536: if ($item =~ m{^gr\./($match_domain/$match_courseid)/(\w+)$}) {
2537: my ($cdom,$cnum) = split(/\//,$1);
2538: my $group = $2;
2539: if ($currcrs ne $cdom.'_'.$cnum) {
2540: if ($currcrs) {
2541: $groupmsg .= '</ul><li>';
2542: }
2543: $groupmsg .= '<li><b>'.
2544: $env{'course.'.$cdom.'_'.$cnum.'.description'}.'</b><ul>';
1.269.2.7 raeburn 2545: $currcrs = $cdom.'_'.$cnum;
1.269.2.6 raeburn 2546: }
2547: my $groupdesc;
2548: unless (ref($curr_groups{$cdom.'_'.$cnum}) eq 'HASH') {
2549: %{$curr_groups{$cdom.'_'.$cnum}} =
2550: &Apache::longroup::coursegroups($cdom,$cnum);
2551: }
2552: unless ((ref($groupdescs{$cdom.'_'.$cnum}) eq 'HASH') &&
2553: ($groupdescs{$cdom.'_'.$cnum}{$group})) {
2554:
2555: my %groupinfo =
2556: &Apache::longroup::get_group_settings($curr_groups{$cdom.'_'.$cnum}{$group});
2557: $groupdescs{$cdom.'_'.$cnum}{$group} =
2558: &unescape($groupinfo{'description'});
2559: }
2560: $groupdesc = $groupdescs{$cdom.'_'.$cnum}{$group};
1.269.2.9 raeburn 2561: if ($groupdesc) {
2562: $groupmsg .= '<li>'.
2563: &mt('[_1] with status: [_2].',
2564: '<b>'.$groupdesc.'</b>',$newgroup{$item}).'</li>';
2565: }
1.269.2.6 raeburn 2566: }
2567: }
2568: if ($groupmsg) {
2569: $groupmsg .= '</ul></li>';
1.260 raeburn 2570: }
2571: }
2572: if ($groupmsg) {
2573: $changemsg .= '<li>'.
2574: &mt('Courses with new groups').'</li>'.
2575: '<ul>'.$groupmsg.'</ul></li>';
2576: }
2577: }
2578: if (keys(%newrole) > 0) {
1.269.2.9 raeburn 2579: my $newmsg;
1.260 raeburn 2580: foreach my $item (sort(keys(%newrole))) {
1.269.2.6 raeburn 2581: my $desc = &role_desc($item,$update,$refresh,$now);
1.269.2.9 raeburn 2582: if ($desc) {
2583: $newmsg .= '<li>'.
2584: &mt('[_1] with status: [_2].',
1.269.2.18 raeburn 2585: $desc,&mt($newrole{$item})).'</li>';
1.269.2.9 raeburn 2586: }
2587: }
2588: if ($newmsg) {
2589: $changemsg .= '<li>'.&mt('New roles').
2590: '<ul>'.$newmsg.'</ul>'.
2591: '</li>';
1.260 raeburn 2592: }
2593: }
2594: if (keys(%customprivchg) > 0) {
1.269.2.9 raeburn 2595: my $privmsg;
1.260 raeburn 2596: foreach my $item (sort(keys(%customprivchg))) {
1.269.2.6 raeburn 2597: my $desc = &role_desc($item,$update,$refresh,$now);
1.269.2.9 raeburn 2598: if ($desc) {
2599: $privmsg .= '<li>'.$desc.'</li>';
2600: }
1.260 raeburn 2601: }
1.269.2.9 raeburn 2602: if ($privmsg) {
2603: $changemsg .= '<li>'.
2604: &mt('Custom roles with privilege changes').
2605: '<ul>'.$privmsg.'</ul>'.
2606: '</li>';
2607: }
1.260 raeburn 2608: }
2609: if (keys(%rolechange) > 0) {
1.269.2.9 raeburn 2610: my $rolemsg;
1.260 raeburn 2611: foreach my $item (sort(keys(%rolechange))) {
1.269.2.9 raeburn 2612: my $desc = &role_desc($item,$update,$refresh,$now);
2613: if ($desc) {
2614: $rolemsg .= '<li>'.
2615: &mt('[_1] status now: [_2].',$desc,
2616: $rolechange{$item}).'</li>';
2617: }
2618: }
2619: if ($rolemsg) {
1.260 raeburn 2620: $changemsg .= '<li>'.
1.269.2.9 raeburn 2621: &mt('Existing roles with status changes').'</li>'.
2622: '<ul>'.$rolemsg.'</ul>'.
2623: '</li>';
1.260 raeburn 2624: }
2625: }
2626: if (keys(%deletedroles) > 0) {
1.269.2.9 raeburn 2627: my $delmsg;
1.260 raeburn 2628: foreach my $item (sort(keys(%deletedroles))) {
1.269.2.6 raeburn 2629: my $desc = &role_desc($item,$update,$refresh,$now);
1.269.2.9 raeburn 2630: if ($desc) {
2631: $delmsg .= '<li>'.$desc.'</li>';
2632: }
2633: }
2634: if ($delmsg) {
2635: $changemsg .= '<li>'.
2636: &mt('Existing roles now expired').'</li>'.
2637: '<ul>'.$delmsg.'</ul>'.
2638: '</li>';
1.260 raeburn 2639: }
2640: }
2641: }
2642: if ((keys(%changed_groups) > 0) || (keys(%groupchange) > 0)) {
2643: my $groupchgmsg;
2644: foreach my $key (sort(keys(%changed_groups))) {
2645: my $crs = 'gr/'.$key;
2646: $crs =~ s/_/\//;
2647: if (&is_active_course($crs,$refresh,$update,\%roleshash)) {
2648: if (ref($changed_groups{$key}) eq 'HASH') {
2649: my @showgroups;
2650: foreach my $group (sort(keys(%{$changed_groups{$key}}))) {
2651: if ($changed_groups{$key}{$group} eq 'active') {
2652: push(@showgroups,$group);
2653: }
2654: }
2655: if (@showgroups > 0) {
2656: $groupchgmsg .= '<li>'.
2657: &mt('Course: [_1], groups: [_2].',$key,
2658: join(', ',@showgroups)).
2659: '</li>';
2660: }
2661: }
2662: }
2663: }
2664: if (keys(%groupchange) > 0) {
2665: $groupchgmsg .= '<li>'.
2666: &mt('Existing course/community groups with status changes').'</li>'.
2667: '<ul>';
2668: foreach my $crs (sort(keys(%groupchange))) {
1.269.2.6 raeburn 2669: my $cid = $crs;
2670: $cid=~s{^/}{};
2671: $cid=~s{/}{_};
2672: my $crsdesc = $env{'course.'.$cid.'.description'};
2673: my $cdom = $env{'course.'.$cid.'.domain'};
2674: my $cnum = $env{'course.'.$cid.'.num'};
2675: my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum);
2676: my %groupdesc;
1.260 raeburn 2677: if (ref($groupchange{$crs}) eq 'HASH') {
1.269.2.6 raeburn 2678: $groupchgmsg .= '<li>'.&mt('Course/Community: [_1]','<b>'.$crsdesc.'</b><ul>');
1.260 raeburn 2679: foreach my $group (sort(keys(%{$groupchange{$crs}}))) {
1.269.2.6 raeburn 2680: unless ($groupdesc{$group}) {
2681: my %groupinfo = &Apache::longroup::get_group_settings($curr_groups{$group});
2682: $groupdesc{$group} = &unescape($groupinfo{'description'});
2683: }
2684: $groupchgmsg .= '<li>'.&mt('Group: [_1] status now: [_2].','<b>'.$groupdesc{$group}.'</b>',$groupchange{$crs}{$group}).'</li>';
1.260 raeburn 2685: }
2686: $groupchgmsg .= '</ul></li>';
2687: }
2688: }
2689: $groupchgmsg .= '</ul></li>';
2690: }
2691: if ($groupchgmsg) {
2692: $changemsg .= '<li>'.
2693: &mt('Courses with changes in groups').'</li>'.
2694: '<ul>'.$groupchgmsg.'</ul></li>';
2695: }
2696: }
2697: if ($changemsg) {
2698: $msg .= '<ul>'.$changemsg.'</ul>';
1.269.2.9 raeburn 2699: } else {
2700: if (&Apache::loncommon::show_course()) {
2701: $msg = &mt('No new courses or communities');
2702: } else {
2703: $msg = &mt('No role changes');
2704: }
1.260 raeburn 2705: }
1.269.2.6 raeburn 2706: return $msg;
2707: }
2708:
2709: sub role_desc {
2710: my ($item,$update,$refresh,$now) = @_;
2711: my ($where,$trolecode,$role,$tstatus,$tend,$tstart,$twhere,
2712: $trole,$tremark);
1.269.2.8 raeburn 2713: &Apache::lonnet::role_status('user.role.'.$item,$update,$refresh,
2714: $now,\$role,\$where,\$trolecode,
1.269.2.6 raeburn 2715: \$tstatus,\$tstart,\$tend);
1.269.2.9 raeburn 2716: return unless ($role);
1.269.2.6 raeburn 2717: if ($role =~ /^cr\//) {
2718: my ($rdummy,$rdomain,$rauthor,$rrole)=split(/\//,$role);
1.269.2.17 raeburn 2719: $tremark = &mt('Custom role defined by [_1].',$rauthor.':'.$rdomain);
1.269.2.6 raeburn 2720: }
2721: $trole=Apache::lonnet::plaintext($role);
2722: my ($tdom,$trest,$tsection)=
2723: split(/\//,Apache::lonnet::declutter($where));
2724: if (($role eq 'ca') || ($role eq 'aa')) {
2725: my $home = &Apache::lonnet::homeserver($trest,$tdom);
2726: $home = &Apache::lonnet::hostname($home);
2727: $twhere=&mt('User').': '.$trest.' '.&mt('Domain').
2728: ': '.$tdom.' '.&mt('Server').': '.$home;
2729: } elsif ($role eq 'au') {
2730: my $home = &Apache::lonnet::homeserver
2731: ($env{'user.name'},$env{'user.domain'});
2732: $home = &Apache::lonnet::hostname($home);
2733: $twhere=&mt('Domain').': '.$tdom.' '.&mt('Server').
2734: ': '.$home;
2735: } elsif ($trest) {
2736: my $tcourseid=$tdom.'_'.$trest;
2737: my $crstype = &Apache::loncommon::course_type($tcourseid);
2738: $trole = &Apache::lonnet::plaintext($role,$crstype,$tcourseid);
2739: if ($env{'course.'.$tcourseid.'.description'}) {
2740: $twhere=$env{'course.'.$tcourseid.'.description'};
2741: } else {
2742: my %newhash=&Apache::lonnet::coursedescription($tcourseid);
2743: if (%newhash) {
2744: $twhere=$newhash{'description'};
2745: } else {
2746: $twhere=&mt('Currently not available');
1.260 raeburn 2747: }
2748: }
1.269.2.6 raeburn 2749: if ($tsection) {
2750: $twhere.= ' '.&mt('Section').': '.$tsection;
1.260 raeburn 2751: }
1.269.2.6 raeburn 2752: if ($role ne 'st') {
2753: $twhere.= ' '.&mt('Domain').': '.$tdom;
1.260 raeburn 2754: }
1.269.2.6 raeburn 2755: } elsif ($tdom) {
2756: $twhere = &mt('Domain').': '.$tdom;
1.260 raeburn 2757: }
1.269.2.9 raeburn 2758: my $output;
2759: if ($trole) {
2760: $output = $trole;
2761: if ($twhere) {
2762: $output .= " -- $twhere";
2763: }
2764: if ($tremark) {
2765: $output .= '<br />'.$tremark;
2766: }
1.260 raeburn 2767: }
1.269.2.6 raeburn 2768: return $output;
1.260 raeburn 2769: }
2770:
2771: sub curr_role_status {
2772: my ($start,$end,$refresh,$update) = @_;
2773: if (($start) && ($start<0)) { return 'deleted' };
2774: my $status = 'active';
2775: if (($end) && ($end<=$update)) {
2776: $status = 'previous';
2777: }
2778: if (($start) && ($refresh<$start)) {
2779: $status = 'future';
2780: }
2781: return $status;
2782: }
2783:
2784: sub gather_roleprivs {
2785: my ($allroles,$allgroups,$userroles,$area,$role,$tstart,$tend,$status) = @_;
2786: return unless ((ref($allroles) eq 'HASH') && (ref($allgroups) eq 'HASH') && (ref($userroles) eq 'HASH'));
2787: if (($area ne '') && ($role ne '')) {
2788: &Apache::lonnet::userrolelog($role,$env{'user.name'},$env{'user.domain'},
2789: $area,$tstart,$tend);
2790: my $spec=$role.'.'.$area;
2791: $userroles->{'user.role.'.$spec} = $tstart.'.'.$tend;
2792: my ($tdummy,$tdomain,$trest)=split(/\//,$area);
2793: if ($status eq 'active') {
2794: if ($role =~ /^cr\//) {
2795: &Apache::lonnet::custom_roleprivs($allroles,$role,$tdomain,$trest,$spec,$area);
2796: } elsif ($role eq 'gr') {
2797: my %rolehash = &Apache::lonnet::get('roles',[$area.'_'.$role],
2798: $env{'user.domain'},
2799: $env{'user.name'});
2800: my ($trole) = split(/_/,$rolehash{$area.'_'.$role},2);
2801: (undef,my $group_privs) = split(/\//,$trole);
2802: $group_privs = &unescape($group_privs);
2803: &Apache::lonnet::group_roleprivs($allgroups,$area,$group_privs,$tend,$tstart);
2804: } else {
2805: &Apache::lonnet::standard_roleprivs($allroles,$role,$tdomain,$spec,$trest,$area);
2806: }
2807: }
2808: }
2809: return;
2810: }
2811:
2812: sub is_active_course {
2813: my ($rolekey,$refresh,$update,$roleshashref) = @_;
2814: return unless(ref($roleshashref) eq 'HASH');
2815: my ($role,$cdom,$cnum) = split(/\//,$rolekey);
2816: my $is_active;
2817: foreach my $key (keys(%{$roleshashref})) {
2818: if ($key =~ /^\Q$cnum\E:\Q$cdom\E:/) {
2819: my ($tstart,$tend) = split(/:/,$roleshashref->{$key});
2820: my $status = &curr_role_status($tstart,$tend,$refresh,$update);
2821: if ($status eq 'active') {
2822: $is_active = 1;
2823: last;
2824: }
2825: }
2826: }
2827: return $is_active;
2828: }
2829:
1.269.2.2 raeburn 2830: sub get_roles_functions {
1.269.2.18 raeburn 2831: my ($rolescount,$cattype) = @_;
1.269.2.2 raeburn 2832: my @links;
2833: push(@links,["javascript:rolesView('doupdate');",'start-here-22x22',&mt('Check for changes')]);
2834: if ($env{'environment.canrequest.author'}) {
2835: unless (&Apache::loncoursequeueadmin::is_active_author()) {
2836: push(@links,["javascript:rolesView('requestauthor');",'list-add-22x22',&mt('Request author role')]);
2837: }
2838: }
1.269.2.6 raeburn 2839: if (($rolescount > 3) || ($env{'environment.recentroles'})) {
2840: push(@links,['/adm/preferences?action=changerolespref&returnurl=/adm/roles','role_hotlist-22x22',&mt('Hotlist')]);
2841: }
1.269.2.2 raeburn 2842: if (&Apache::lonmenu::check_for_rcrs()) {
2843: push(@links,['/adm/requestcourse','rcrs-22x22',&mt('Request course')]);
2844: }
2845: if ($env{'form.state'} eq 'queued') {
2846: push(@links,["javascript:rolesView('noqueued');",'selfenrl-queue-22x22',&mt('Hide queued')]);
2847: } else {
2848: push(@links,["javascript:rolesView('queued');",'selfenrl-queue-22x22',&mt('Show queued')]);
2849: }
1.269.2.6 raeburn 2850: if ($env{'user.adv'}) {
2851: if ($env{'form.display'} eq 'showall') {
1.269.2.12 raeburn 2852: push(@links,["javascript:rolesView('noshowall');",'edit-redo-22x22',&mt('Exclude expired')]);
1.269.2.6 raeburn 2853: } else {
1.269.2.12 raeburn 2854: push(@links,["javascript:rolesView('showall');",'edit-undo-22x22',&mt('Include expired')]);
1.269.2.6 raeburn 2855: }
1.269.2.2 raeburn 2856: }
1.269.2.18 raeburn 2857: unless ($cattype eq 'none') {
1.269.2.13 raeburn 2858: push(@links,['/adm/coursecatalog','ccat-22x22',&mt('Course catalog')]);
1.269.2.12 raeburn 2859: }
1.269.2.26 raeburn 2860: my $funcs;
2861: if ($env{'browser.mobile'}) {
2862: my @functions;
2863: foreach my $link (@links) {
2864: push(@functions,[$link->[0],$link->[2]]);
2865: }
2866: my $title = 'Display options';
2867: if ($env{'user.adv'}) {
2868: $title = 'Roles options';
2869: }
2870: $funcs = &Apache::lonmenu::create_submenu('','',$title,\@functions,1,'LC_breadcrumbs_hoverable');
2871: $funcs = '<ol class="LC_primary_menu LC_floatright">'.$funcs.'</ol>';
2872: } else {
2873: $funcs = &Apache::lonhtmlcommon::start_funclist();
2874: foreach my $link (@links) {
2875: $funcs .= &Apache::lonhtmlcommon::add_item_funclist(
2876: '<a href="'.$link->[0].'" class="LC_menubuttons_link">'.
2877: '<img src="/res/adm/pages/'.$link->[1].'.png" class="LC_icon" alt="'.$link->[2].'" />'.
2878: $link->[2].'</a>');
2879: }
2880: $funcs .= &Apache::lonhtmlcommon::end_funclist();
2881: $funcs = &Apache::loncommon::head_subbox($funcs);
1.269.2.2 raeburn 2882: }
1.269.2.26 raeburn 2883: return $funcs;
1.269.2.2 raeburn 2884: }
2885:
2886: sub get_queued {
2887: my ($output,%reqcrs);
2888: my ($types,$typenames) = &Apache::loncommon::course_types();
2889: my %statusinfo = &Apache::lonnet::dump('courserequests',$env{'user.domain'},
2890: $env{'user.name'},'^status:');
2891: foreach my $key (keys(%statusinfo)) {
2892: next unless (($statusinfo{$key} eq 'approval') || ($statusinfo{$key} eq 'pending'));
1.269.2.16 raeburn 2893: (undef,my($cdom,$cnum)) = split(/:/,$key);
1.269.2.2 raeburn 2894: my $requestkey = $cdom.'_'.$cnum;
2895: if ($requestkey =~ /^($match_domain)_($match_courseid)$/) {
2896: my %history = &Apache::lonnet::restore($requestkey,'courserequests',
2897: $env{'user.domain'},$env{'user.name'});
2898: next if ((exists($history{'status'})) && ($history{'status'} eq 'created'));
2899: my $reqtime = $history{'reqtime'};
2900: my $lastupdate = $history{'timestamp'};
2901: my $showtype = $history{'crstype'};
2902: if (defined($typenames->{$history{'crstype'}})) {
2903: $showtype = $typenames->{$history{'crstype'}};
2904: }
2905: my $description;
2906: if (ref($history{'details'}) eq 'HASH') {
2907: $description = $history{details}{'cdescr'};
2908: }
2909: @{$reqcrs{$reqtime}} = ($description,$showtype);
2910: }
2911: }
2912: my @sortedtimes = sort {$a <=> $b} (keys(%reqcrs));
2913: if (@sortedtimes > 0) {
2914: $output .= '<p><b>'.&mt('Course/Community requests').'</b><br />'.
2915: &Apache::loncommon::start_data_table().
2916: &Apache::loncommon::start_data_table_header_row().
2917: '<th>'.&mt('Date requested').'</th>'.
2918: '<th>'.&mt('Course title').'</th>'.
2919: '<th>'.&mt('Course type').'</th>';
2920: &Apache::loncommon::end_data_table_header_row();
2921: foreach my $reqtime (@sortedtimes) {
2922: next unless (ref($reqcrs{$reqtime}) eq 'ARRAY');
2923: $output .= &Apache::loncommon::start_data_table_row().
2924: '<td>'.&Apache::lonlocal::locallocaltime($reqtime).'</td>'.
2925: '<td>'.join('</td><td>',@{$reqcrs{$reqtime}}).'</td>'.
2926: &Apache::loncommon::end_data_table_row();
2927: }
2928: $output .= &Apache::loncommon::end_data_table().
2929: '<br /></p>';
2930: }
2931: my $queuedselfenroll = &Apache::loncoursequeueadmin::queued_selfenrollment(1);
2932: if ($queuedselfenroll) {
2933: $output .= '<p><b>'.&mt('Enrollment requests').'</b><br />'.
2934: $queuedselfenroll.'<br /></p>';
2935: }
2936: if ($env{'environment.canrequest.author'}) {
2937: unless (&Apache::loncoursequeueadmin::is_active_author()) {
2938: my $requestauthor;
2939: my ($status,$timestamp) = split(/:/,$env{'environment.requestauthorqueued'});
2940: if (($status eq 'approval') || ($status eq 'approved')) {
2941: $output .= '<p><b>'.&mt('Author role request').'</b><br />';
2942: if ($status eq 'approval') {
1.269.2.18 raeburn 2943: $output .= &mt('A request for Authoring Space submitted on [_1] is awaiting approval',
1.269.2.2 raeburn 2944: &Apache::lonlocal::locallocaltime($timestamp));
2945: } elsif ($status eq 'approved') {
2946: my %roleshash =
2947: &Apache::lonnet::get_my_roles($env{'user.name'},$env{'user.domain'},'userroles',
2948: ['active'],['au'],[$env{'user.domain'}]);
2949: if (keys(%roleshash)) {
2950: $output .= '<span class="LC_info">'.
2951: &mt('Your request for an author role has been approved.').'<br />'.
2952: &mt('Use the "Check for changes" link to update your list of roles.').
2953: '</span>';
2954: }
2955: }
2956: $output .= '</p>';
2957: }
2958: }
2959: }
2960: unless ($output) {
2961: if ($env{'environment.canrequest.author'} || $env{'environment.canrequest.official'} ||
2962: $env{'environment.canrequest.unofficial'} || $env{'environment.canrequest.community'}) {
2963: $output = &mt('No requests for courses, communities or authoring currently queued');
2964: } else {
2965: $output = &mt('No enrollment requests currently queued awaiting approval');
2966: }
2967: }
2968: return '<div class="LC_left_float"><fieldset><legend>'.&mt('Queued requests').'</legend>'.
2969: $output.'</fieldset></div><br clear="all" />';
2970: }
2971:
1.1 harris41 2972: 1;
2973: __END__
1.32 harris41 2974:
2975: =head1 NAME
2976:
2977: Apache::lonroles - User Roles Screen
2978:
2979: =head1 SYNOPSIS
2980:
2981: Invoked by /etc/httpd/conf/srm.conf:
2982:
2983: <Location /adm/roles>
2984: PerlAccessHandler Apache::lonacc
2985: SetHandler perl-script
2986: PerlHandler Apache::lonroles
2987: ErrorDocument 403 /adm/login
2988: ErrorDocument 500 /adm/errorhandler
2989: </Location>
1.64 bowersj2 2990:
2991: =head1 OVERVIEW
2992:
2993: =head2 Choosing Roles
2994:
2995: C<lonroles> is a handler that allows a user to switch roles in
2996: mid-session. LON-CAPA attempts to work with "No Role Specified", the
2997: default role that a user has before selecting a role, as widely as
2998: possible, but certain handlers for example need specification which
2999: course they should act on, etc. Both in this scenario, and when the
3000: handler determines via C<lonnet>'s C<&allowed> function that a certain
3001: action is not allowed, C<lonroles> is used as error handler. This
3002: allows the user to select another role which may have permission to do
1.246 droeschl 3003: what they were trying to do.
1.64 bowersj2 3004:
3005: =begin latex
3006:
3007: \begin{figure}
3008: \begin{center}
3009: \includegraphics[width=0.45\paperwidth,keepaspectratio]{Sample_Roles_Screen}
3010: \caption{\label{Sample_Roles_Screen}Sample Roles Screen}
3011: \end{center}
3012: \end{figure}
3013:
3014: =end latex
3015:
3016: =head2 Role Initialization
3017:
3018: 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 3019:
3020: =head1 INTRODUCTION
3021:
3022: This module enables a user to select what role he wishes to
3023: operate under (instructor, student, teaching assistant, course
3024: coordinator, etc). These roles are pre-established by the actions
3025: of upper-level users.
3026:
3027: This is part of the LearningOnline Network with CAPA project
3028: described at http://www.lon-capa.org.
3029:
3030: =head1 HANDLER SUBROUTINE
3031:
3032: This routine is called by Apache and mod_perl.
3033:
3034: =over 4
3035:
3036: =item *
3037:
3038: Roles Initialization (yes/no)
3039:
3040: =item *
3041:
3042: Get Error Message from Environment
3043:
3044: =item *
3045:
3046: Who is this?
3047:
3048: =item *
3049:
3050: Generate Page Output
3051:
3052: =item *
3053:
3054: Choice or no choice
3055:
3056: =item *
3057:
3058: Table
3059:
3060: =item *
3061:
3062: Privileges
3063:
3064: =back
3065:
3066: =cut
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>