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