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