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