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