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