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