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