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