Annotation of loncom/auth/lonroles.pm, revision 1.296
1.1 harris41 1: # The LearningOnline Network with CAPA
2: # User Roles Screen
1.31 www 3: #
1.296 ! raeburn 4: # $Id: lonroles.pm,v 1.295 2014/01/15 14:46:21 bisitz 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.296 ! raeburn 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.296 ! raeburn 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>'
1.295 bisitz 892: .&mt('[_1]Visit the [_2]Course/Community Catalog[_3][_4]'
893: .' to view all [_5] LON-CAPA courses and communities.'
1.233 bisitz 894: ,'<b>'
895: ,'<a href="/adm/coursecatalog?showdom='.$esc_dom.'">'
1.295 bisitz 896: ,'</a>'
897: ,'</b>'
898: ,'"'.$domdesc.'"')
1.233 bisitz 899: .'<br />'
1.235 bisitz 900: .&mt('If a course or community is [_1]not[_2] in your list of current courses and communities below,'
1.233 bisitz 901: .' you may be able to enroll if self-enrollment is permitted.'
902: ,'<b>','</b>')
903: .'</p>'
904: );
1.196 raeburn 905: }
906: }
907:
1.84 www 908: # No active roles
909: if ($countactive==0) {
910: if ($inrole) {
1.234 raeburn 911: $r->print('<h2>'.&mt('Currently no additional roles, courses or communities').'</h2>');
1.84 www 912: } else {
1.234 raeburn 913: $r->print('<h2>'.&mt('Currently no active roles, courses or communities').'</h2>');
1.84 www 914: }
1.191 raeburn 915: &findcourse_advice($r);
1.234 raeburn 916: &requestcourse_advice($r);
1.191 raeburn 917: $r->print('</form>');
918: if ($countfuture) {
919: $r->print(&mt('The following [quant,_1,role,roles] will become active in the future:',$countfuture));
920: my $doheaders = &roletable_headers($r,\%roleclass,\%sortrole,
921: $nochoose);
922: &print_rolerows($r,$doheaders,\%roleclass,\%sortrole,\%dcroles,
923: \%roletext);
924: my $tremark='';
1.212 bisitz 925: my $tbg;
1.191 raeburn 926: if ($env{'request.role'} eq 'cm') {
1.212 bisitz 927: $tbg="LC_roles_selected";
1.204 bisitz 928: $tremark=&mt('Currently selected.').' ';
1.191 raeburn 929: } else {
1.212 bisitz 930: $tbg="LC_roles_is";
1.191 raeburn 931: }
1.212 bisitz 932: $r->print(&Apache::loncommon::start_data_table_row()
933: .'<td class="'.$tbg.'"> </td>'
934: .'<td colspan="3">'
935: .&mt('No role specified')
936: .'</td>'
937: .'<td>'.$tremark.' </td>'
938: .&Apache::loncommon::end_data_table_row()
939: );
1.191 raeburn 940:
1.212 bisitz 941: $r->print(&Apache::loncommon::end_data_table());
1.191 raeburn 942: }
943: $r->print(&Apache::loncommon::end_page());
1.84 www 944: return OK;
945: }
946: # ----------------------------------------------------------------------- Table
1.247 raeburn 947:
948: if ($numdc > 0) {
949: $r->print(&coursepick_jscript());
950: $r->print(&Apache::loncommon::coursebrowser_javascript().
951: &Apache::loncommon::authorbrowser_javascript());
952: }
953:
1.224 raeburn 954: unless ((!&Apache::loncommon::show_course()) || ($nochoose) || ($countactive==1)) {
1.173 albertel 955: $r->print("<h2>".&mt('Select a Course to Enter')."</h2>\n");
1.84 www 956: }
1.229 raeburn 957: if ($env{'form.destinationurl'}) {
958: $r->print('<input type="hidden" name="destinationurl" value="'.
959: $env{'form.destinationurl'}.'" />');
960: if ($env{'form.destsymb'} ne '') {
961: $r->print('<input type="hidden" name="destsymb" value="'.
962: $env{'form.destsymb'}.'" />');
963: }
964: }
1.247 raeburn 965:
1.191 raeburn 966: my $doheaders = &roletable_headers($r,\%roleclass,\%sortrole,$nochoose);
1.118 albertel 967: if ($env{'environment.recentroles'}) {
1.111 albertel 968: my %recent_roles =
1.118 albertel 969: &Apache::lonhtmlcommon::get_recent('roles',$env{'environment.recentrolesn'});
1.111 albertel 970: my $output='';
1.247 raeburn 971: foreach my $role (sort(keys(%recent_roles))) {
972: if (ref($roletext{'user.role.'.$role}) eq 'ARRAY') {
1.223 raeburn 973: $output.= &Apache::loncommon::start_data_table_row().
1.247 raeburn 974: $roletext{'user.role.'.$role}->[0].
1.223 raeburn 975: &Apache::loncommon::end_data_table_row();
1.249 raeburn 976: if ($roletext{'user.role.'.$role}->[1] ne '') {
977: $output .= &Apache::loncommon::continue_data_table_row().
978: $roletext{'user.role.'.$role}->[1].
979: &Apache::loncommon::end_data_table_row();
980: }
1.247 raeburn 981: if ($role =~ m{dc\./($match_domain)/}
1.170 albertel 982: && $dcroles{$1}) {
1.192 raeburn 983: $output .= &adhoc_roles_row($1,'recent');
1.133 albertel 984: }
1.113 raeburn 985: } elsif ($numdc > 0) {
1.247 raeburn 986: unless ($role =~/^error\:/) {
1.249 raeburn 987: my ($roletext,$role_text_end) = &display_cc_role('user.role.'.$role);
1.259 raeburn 988: if ($roletext) {
989: $output.= &Apache::loncommon::start_data_table_row().
990: $roletext.
991: &Apache::loncommon::end_data_table_row();
992: if ($role_text_end) {
993: $output .= &Apache::loncommon::continue_data_table_row().
994: $role_text_end.
995: &Apache::loncommon::end_data_table_row();
996: }
997: }
1.113 raeburn 998: }
1.247 raeburn 999: }
1.111 albertel 1000: }
1001: if ($output) {
1.212 bisitz 1002: $r->print(&Apache::loncommon::start_data_table_empty_row()
1003: .'<td align="center" colspan="5">'
1.224 raeburn 1004: .$recent
1.212 bisitz 1005: .'</td>'
1006: .&Apache::loncommon::end_data_table_empty_row()
1007: );
1.111 albertel 1008: $r->print($output);
1.114 raeburn 1009: $doheaders ++;
1.111 albertel 1010: }
1011: }
1.191 raeburn 1012: &print_rolerows($r,$doheaders,\%roleclass,\%sortrole,\%dcroles,\%roletext);
1.202 raeburn 1013: if ($countactive > 1) {
1014: my $tremark='';
1.212 bisitz 1015: my $tbg;
1.202 raeburn 1016: if ($env{'request.role'} eq 'cm') {
1.212 bisitz 1017: $tbg="LC_roles_selected";
1.204 bisitz 1018: $tremark=&mt('Currently selected.').' ';
1.202 raeburn 1019: } else {
1.212 bisitz 1020: $tbg="LC_roles_is";
1.202 raeburn 1021: }
1.212 bisitz 1022: $r->print(&Apache::loncommon::start_data_table_row());
1.202 raeburn 1023: unless ($nochoose) {
1024: if ($env{'request.role'} ne 'cm') {
1.212 bisitz 1025: $r->print('<td class="'.$tbg.'"><input type="submit" value="'.
1.202 raeburn 1026: &mt('Select').'" name="cm" /></td>');
1027: } else {
1.212 bisitz 1028: $r->print('<td class="'.$tbg.'"> </td>');
1.202 raeburn 1029: }
1030: }
1.212 bisitz 1031: $r->print('<td colspan="3">'
1032: .&mt('No role specified')
1033: .'</td>'
1034: .'<td>'.$tremark.' </td>'
1035: .&Apache::loncommon::end_data_table_row()
1036: );
1.202 raeburn 1037: }
1.212 bisitz 1038: $r->print(&Apache::loncommon::end_data_table());
1.4 www 1039: unless ($nochoose) {
1040: $r->print("</form>\n");
1041: }
1.22 harris41 1042: # ------------------------------------------------------------ Privileges Info
1.118 albertel 1043: if (($advanced) && (($env{'user.error.msg'}) || ($error))) {
1.212 bisitz 1044: $r->print('<hr /><h2>'.&mt('Current Privileges').'</h2>');
1.175 albertel 1045: $r->print(&privileges_info());
1.4 www 1046: }
1.267 bisitz 1047: my $announcements = &Apache::lonnet::getannounce();
1048: $r->print(
1049: '<br />'.
1050: '<h2>'.&mt('Announcements').'</h2>'.
1051: $announcements
1052: ) unless (!$announcements);
1.65 www 1053: if ($advanced) {
1.201 raeburn 1054: my $esc_dom = &HTML::Entities::encode($env{'user.domain'},'"<>&');
1.231 bisitz 1055: $r->print('<p><small><i>'
1056: .&mt('This LON-CAPA server is version [_1]',$r->dir_config('lonVersion'))
1057: .'</i><br />'
1058: .'<a href="/adm/logout">'.&mt('Logout').'</a> '
1.201 raeburn 1059: .'<a href="/adm/coursecatalog?showdom='.$esc_dom.'">'
1.233 bisitz 1060: .&mt('Course/Community Catalog')
1.225 bisitz 1061: .'</a></small></p>');
1.65 www 1062: }
1.147 albertel 1063: $r->print(&Apache::loncommon::end_page());
1.1 harris41 1064: return OK;
1.102 raeburn 1065: }
1066:
1.274 raeburn 1067: sub roles_from_env {
1068: my ($roleshash,$update) = @_;
1069: my $count = 0;
1070: if (ref($roleshash) eq 'HASH') {
1071: foreach my $envkey (keys(%env)) {
1072: if ($envkey =~ m{^user\.role\.(\w+)[./]}) {
1073: next if ($1 eq 'gr');
1074: $roleshash->{$envkey} = $env{$envkey};
1075: my ($start,$end) = split(/\./,$env{$envkey});
1076: unless ($end && $end<$update) {
1077: $count ++;
1078: }
1079: }
1080: }
1081: }
1082: return $count;
1083: }
1084:
1.226 raeburn 1085: sub gather_roles {
1.274 raeburn 1086: my ($update,$refresh,$now,$reinit,$nochoose,$roles_in_env,$roletext,$sortrole,$roleclass,$futureroles,
1087: $timezones,$loncaparev) = @_;
1.226 raeburn 1088: my ($countactive,$countfuture,$inrole,$possiblerole) = (0,0,0,'');
1089: my $advanced = $env{'user.adv'};
1090: my $tryagain = $env{'form.tryagain'};
1.254 raeburn 1091: my @ids = &Apache::lonnet::current_machine_ids();
1.274 raeburn 1092: if (ref($roles_in_env) eq 'HASH') {
1093: foreach my $envkey (sort(keys(%{$roles_in_env}))) {
1094: my $button = 1;
1095: my $switchserver='';
1096: my $switchwarning;
1097: my ($role_text,$role_text_end,$sortkey,$role,$where,$trolecode,$tstart,
1098: $tend,$tremark,$tstatus,$tpstart,$tpend);
1.260 raeburn 1099: &Apache::lonnet::role_status($envkey,$update,$refresh,$now,\$role,\$where,
1.226 raeburn 1100: \$trolecode,\$tstatus,\$tstart,\$tend);
1101: next if (!defined($role) || $role eq '' || $role =~ /^gr/);
1102: $tremark='';
1103: $tpstart=' ';
1104: $tpend=' ';
1105: if ($env{'request.role'} eq $trolecode) {
1106: $tstatus='selected';
1107: }
1108: my $tbg;
1109: if (($tstatus eq 'is')
1110: || ($tstatus eq 'selected')
1111: || ($tstatus eq 'future')
1.274 raeburn 1112: || ($env{'form.display'} eq 'showall')) {
1.259 raeburn 1113: my $timezone = &role_timezone($where,$timezones);
1114: if ($tstart) {
1115: $tpstart=&Apache::lonlocal::locallocaltime($tstart,$timezone);
1116: }
1117: if ($tend) {
1118: $tpend=&Apache::lonlocal::locallocaltime($tend,$timezone);
1119: }
1.226 raeburn 1120: if ($tstatus eq 'is') {
1121: $tbg='LC_roles_is';
1122: $possiblerole=$trolecode;
1123: $countactive++;
1124: } elsif ($tstatus eq 'future') {
1125: $tbg='LC_roles_future';
1126: $button=0;
1127: $futureroles->{$trolecode} = $tstart.':'.$tend;
1128: $countfuture ++;
1129: } elsif ($tstatus eq 'expired') {
1130: $tbg='LC_roles_expired';
1131: $button=0;
1132: } elsif ($tstatus eq 'will_not') {
1133: $tbg='LC_roles_will_not';
1134: $tremark.=&mt('Expired after logout.').' ';
1135: } elsif ($tstatus eq 'selected') {
1136: $tbg='LC_roles_selected';
1137: $inrole=1;
1138: $countactive++;
1139: $tremark.=&mt('Currently selected.').' ';
1140: }
1141: my $trole;
1142: if ($role =~ /^cr\//) {
1143: my ($rdummy,$rdomain,$rauthor,$rrole)=split(/\//,$role);
1144: if ($tremark) { $tremark.='<br />'; }
1.253 bisitz 1145: $tremark.=&mt('Customrole defined by [_1].',$rauthor.':'.$rdomain);
1.226 raeburn 1146: }
1147: $trole=Apache::lonnet::plaintext($role);
1148: my $ttype;
1149: my $twhere;
1150: my ($tdom,$trest,$tsection)=
1151: split(/\//,Apache::lonnet::declutter($where));
1152: # First, Co-Authorship roles
1153: if (($role eq 'ca') || ($role eq 'aa')) {
1154: my $home = &Apache::lonnet::homeserver($trest,$tdom);
1155: my $allowed=0;
1156: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
1157: if (!$allowed) {
1158: $button=0;
1.248 raeburn 1159: $switchserver='otherserver='.$home.'&role='.$trolecode;
1.226 raeburn 1160: }
1161: #next if ($home eq 'no_host');
1162: $home = &Apache::lonnet::hostname($home);
1.288 raeburn 1163: $ttype='Authoring Space';
1.226 raeburn 1164: $twhere=&mt('User').': '.$trest.'<br />'.&mt('Domain').
1165: ': '.$tdom.'<br />'.
1166: ' '.&mt('Server').': '.$home;
1167: $env{'course.'.$tdom.'_'.$trest.'.description'}='ca';
1168: $tremark.=&Apache::lonhtmlcommon::authorbombs('/res/'.$tdom.'/'.$trest.'/');
1169: $sortkey=$role."$trest:$tdom";
1170: } elsif ($role eq 'au') {
1171: # Authors
1172: my $home = &Apache::lonnet::homeserver
1173: ($env{'user.name'},$env{'user.domain'});
1174: my $allowed=0;
1175: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
1176: if (!$allowed) {
1177: $button=0;
1.248 raeburn 1178: $switchserver='otherserver='.$home.'&role='.$trolecode;
1.226 raeburn 1179: }
1180: #next if ($home eq 'no_host');
1181: $home = &Apache::lonnet::hostname($home);
1.288 raeburn 1182: $ttype='Authoring Space';
1.226 raeburn 1183: $twhere=&mt('Domain').': '.$tdom.'<br />'.&mt('Server').
1184: ': '.$home;
1185: $env{'course.'.$tdom.'_'.$trest.'.description'}='ca';
1186: $tremark.=&Apache::lonhtmlcommon::authorbombs('/res/'.$tdom.'/'.$env{'user.name'}.'/');
1187: $sortkey=$role;
1188: } elsif ($trest) {
1189: my $tcourseid=$tdom.'_'.$trest;
1190: $ttype = &Apache::loncommon::course_type($tcourseid);
1.242 raeburn 1191: $trole = &Apache::lonnet::plaintext($role,$ttype,$tcourseid);
1.226 raeburn 1192: if ($env{'course.'.$tcourseid.'.description'}) {
1.254 raeburn 1193: my $home=$env{'course.'.$tcourseid.'.home'};
1.226 raeburn 1194: $twhere=$env{'course.'.$tcourseid.'.description'};
1195: $sortkey=$role."\0".$tdom."\0".$twhere."\0".$envkey;
1.248 raeburn 1196: $twhere = &HTML::Entities::encode($twhere,'"<>&');
1.226 raeburn 1197: unless ($twhere eq &mt('Currently not available')) {
1198: $twhere.=' <span class="LC_fontsize_small">'.
1199: &Apache::loncommon::syllabuswrapper(&mt('Syllabus'),$trest,$tdom).
1200: '</span>';
1.254 raeburn 1201: unless ($home && grep(/^\Q$home\E$/,@ids) && $loncaparev eq '') {
1.255 raeburn 1202: my $required = $env{'course.'.$tcourseid.'.internal.releaserequired'};
1.259 raeburn 1203: if ($required ne '') {
1204: ($switchserver,$switchwarning) =
1205: &check_release_required($loncaparev,$tcourseid,$trolecode,$required);
1206: if ($switchserver || $switchwarning) {
1207: $button = 0;
1208: }
1.254 raeburn 1209: }
1210: }
1.226 raeburn 1211: }
1212: } else {
1213: my %newhash=&Apache::lonnet::coursedescription($tcourseid);
1214: if (%newhash) {
1215: $sortkey=$role."\0".$tdom."\0".$newhash{'description'}.
1216: "\0".$envkey;
1.248 raeburn 1217: $twhere=&HTML::Entities::encode($newhash{'description'},'"<>&').
1218: ' <span class="LC_fontsize_small">'.
1219: &Apache::loncommon::syllabuswrapper(&mt('Syllabus'),$trest,$tdom).
1220: '</span>';
1.226 raeburn 1221: $ttype = $newhash{'type'};
1.243 raeburn 1222: $trole = &Apache::lonnet::plaintext($role,$ttype,$tcourseid);
1.254 raeburn 1223: my $home = $newhash{'home'};
1224: unless ($home && grep(/^\Q$home\E$/,@ids) && $loncaparev eq '') {
1.255 raeburn 1225: my $required = $newhash{'internal.releaserequired'};
1.259 raeburn 1226: if ($required ne '') {
1227: ($switchserver,$switchwarning) =
1228: &check_release_required($loncaparev,$tcourseid,$trolecode,$required);
1229: if ($switchserver || $switchwarning) {
1230: $button = 0;
1231: }
1.254 raeburn 1232: }
1233: }
1.226 raeburn 1234: } else {
1235: $twhere=&mt('Currently not available');
1236: $env{'course.'.$tcourseid.'.description'}=$twhere;
1237: $sortkey=$role."\0".$tdom."\0".$twhere."\0".$envkey;
1238: $ttype = 'Unavailable';
1239: }
1240: }
1241: if ($tsection) {
1242: $twhere.='<br />'.&mt('Section').': '.$tsection;
1243: }
1244: if ($role ne 'st') { $twhere.="<br />".&mt('Domain').":".$tdom; }
1245: } elsif ($tdom) {
1246: $ttype='Domain';
1247: $twhere=$tdom;
1248: $sortkey=$role.$twhere;
1249: } else {
1250: $ttype='System';
1251: $twhere=&mt('system wide');
1252: $sortkey=$role.$twhere;
1253: }
1254: ($role_text,$role_text_end) =
1255: &build_roletext($trolecode,$tdom,$trest,$tstatus,$tryagain,
1256: $advanced,$tremark,$tbg,$trole,$twhere,$tpstart,
1.254 raeburn 1257: $tpend,$nochoose,$button,$switchserver,$reinit,$switchwarning);
1.226 raeburn 1258: $roletext->{$envkey}=[$role_text,$role_text_end];
1259: if (!$sortkey) {$sortkey=$twhere."\0".$envkey;}
1260: $sortrole->{$sortkey}=$envkey;
1261: $roleclass->{$envkey}=$ttype;
1262: }
1263: }
1264: }
1265: return ($countactive,$countfuture,$inrole,$possiblerole);
1266: }
1267:
1.215 raeburn 1268: sub role_timezone {
1269: my ($where,$timezones) = @_;
1270: my $timezone;
1271: if (ref($timezones) eq 'HASH') {
1272: if ($where =~ m{^/($match_domain)/($match_courseid)}) {
1273: my $cdom = $1;
1274: my $cnum = $2;
1275: if ($cdom && $cnum) {
1276: if (!exists($timezones->{$cdom.'_'.$cnum})) {
1.259 raeburn 1277: my $tz;
1278: if ($env{'course.'.$cdom.'_'.$cnum.'.description'}) {
1279: $tz = $env{'course.'.$cdom.'_'.$cnum.'.timezone'};
1280: } else {
1281: my %timehash =
1282: &Apache::lonnet::get('environment',['timezone'],$cdom,$cnum);
1283: $tz = $timehash{'timezone'};
1284: }
1285: if ($tz eq '') {
1.215 raeburn 1286: if (!exists($timezones->{$cdom})) {
1287: my %domdefaults =
1288: &Apache::lonnet::get_domain_defaults($cdom);
1289: if ($domdefaults{'timezone_def'} eq '') {
1290: $timezones->{$cdom} = 'local';
1291: } else {
1292: $timezones->{$cdom} = $domdefaults{'timezone_def'};
1293: }
1294: }
1295: $timezones->{$cdom.'_'.$cnum} = $timezones->{$cdom};
1296: } else {
1297: $timezones->{$cdom.'_'.$cnum} =
1.259 raeburn 1298: &Apache::lonlocal::gettimezone($tz);
1.215 raeburn 1299: }
1300: }
1301: $timezone = $timezones->{$cdom.'_'.$cnum};
1302: }
1303: } else {
1304: my ($tdom) = ($where =~ m{^/($match_domain)});
1305: if ($tdom) {
1306: if (!exists($timezones->{$tdom})) {
1307: my %domdefaults = &Apache::lonnet::get_domain_defaults($tdom);
1308: if ($domdefaults{'timezone_def'} eq '') {
1309: $timezones->{$tdom} = 'local';
1310: } else {
1311: $timezones->{$tdom} = $domdefaults{'timezone_def'};
1312: }
1313: }
1314: $timezone = $timezones->{$tdom};
1315: }
1316: }
1317: if ($timezone eq 'local') {
1318: $timezone = undef;
1319: }
1320: }
1321: return $timezone;
1322: }
1323:
1.191 raeburn 1324: sub roletable_headers {
1325: my ($r,$roleclass,$sortrole,$nochoose) = @_;
1326: my $doheaders;
1327: if ((ref($sortrole) eq 'HASH') && (ref($roleclass) eq 'HASH')) {
1.212 bisitz 1328: $r->print('<br />'
1329: .&Apache::loncommon::start_data_table()
1330: .&Apache::loncommon::start_data_table_header_row()
1331: );
1.191 raeburn 1332: if (!$nochoose) { $r->print('<th> </th>'); }
1.212 bisitz 1333: $r->print('<th>'.&mt('User Role').'</th>'
1334: .'<th>'.&mt('Extent').'</th>'
1335: .'<th>'.&mt('Start').'</th>'
1336: .'<th>'.&mt('End').'</th>'
1337: .&Apache::loncommon::end_data_table_header_row()
1338: );
1.191 raeburn 1339: $doheaders=-1;
1340: my @roletypes = &roletypes();
1341: foreach my $type (@roletypes) {
1342: my $haverole=0;
1343: foreach my $which (sort {uc($a) cmp uc($b)} (keys(%{$sortrole}))) {
1344: if ($roleclass->{$sortrole->{$which}} =~ /^\Q$type\E/) {
1345: $haverole=1;
1346: }
1347: }
1348: if ($haverole) { $doheaders++; }
1349: }
1350: }
1351: return $doheaders;
1352: }
1353:
1354: sub roletypes {
1.288 raeburn 1355: my @types = ('Domain','Authoring Space','Course','Community','Unavailable','System');
1.191 raeburn 1356: return @types;
1357: }
1358:
1359: sub print_rolerows {
1360: my ($r,$doheaders,$roleclass,$sortrole,$dcroles,$roletext) = @_;
1361: if ((ref($roleclass) eq 'HASH') && (ref($sortrole) eq 'HASH')) {
1362: my @types = &roletypes();
1363: foreach my $type (@types) {
1364: my $output;
1365: foreach my $which (sort {uc($a) cmp uc($b)} (keys(%{$sortrole}))) {
1366: if ($roleclass->{$sortrole->{$which}} =~ /^\Q$type\E/) {
1367: if (ref($roletext) eq 'HASH') {
1.223 raeburn 1368: if (ref($roletext->{$sortrole->{$which}}) eq 'ARRAY') {
1369: $output.= &Apache::loncommon::start_data_table_row().
1370: $roletext->{$sortrole->{$which}}->[0].
1371: &Apache::loncommon::end_data_table_row();
1.251 raeburn 1372: if ($roletext->{$sortrole->{$which}}->[1] ne '') {
1373: $output .= &Apache::loncommon::continue_data_table_row().
1374: $roletext->{$sortrole->{$which}}->[1].
1375: &Apache::loncommon::end_data_table_row();
1376: }
1.223 raeburn 1377: }
1.191 raeburn 1378: if ($sortrole->{$which} =~ m-dc\./($match_domain)/-) {
1379: if (ref($dcroles) eq 'HASH') {
1380: if ($dcroles->{$1}) {
1.192 raeburn 1381: $output .= &adhoc_roles_row($1,'');
1.191 raeburn 1382: }
1383: }
1384: }
1385: }
1386: }
1387: }
1388: if ($output) {
1389: if ($doheaders > 0) {
1.212 bisitz 1390: $r->print(&Apache::loncommon::start_data_table_empty_row()
1391: .'<td align="center" colspan="5">'
1392: .&mt($type)
1393: .'</td>'
1394: .&Apache::loncommon::end_data_table_empty_row()
1395: );
1.191 raeburn 1396: }
1397: $r->print($output);
1398: }
1399: }
1400: }
1401: }
1402:
1403: sub findcourse_advice {
1404: my ($r) = @_;
1405: my $domdesc = &Apache::lonnet::domain($env{'user.domain'},'description');
1.201 raeburn 1406: my $esc_dom = &HTML::Entities::encode($env{'user.domain'},'"<>&');
1.200 raeburn 1407: if (&Apache::lonnet::auto_run(undef,$env{'user.domain'})) {
1.191 raeburn 1408: $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).'
1409: <ul>
1410: <li>'.&mt('The course has yet to be created.').'</li>
1411: <li>'.&mt('Automatic enrollment of registered students has not been enabled for the course.').'</li>
1412: <li>'.&mt('You are in a section of course for which automatic enrollment in the corresponding LON-CAPA course is not active.').'</li>
1413: <li>'.&mt('The start date for automated enrollment has yet to be reached.').'</li>
1414: <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>
1415: </ul>');
1416: } else {
1417: $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 />');
1418: }
1.235 bisitz 1419: $r->print('<h3>'.&mt('Self-Enrollment').'</h3>'.
1.234 raeburn 1420: '<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 1421: $r->print(&mt('You can search for courses and communities which permit self-enrollment, if you would like to enroll in one.').'</p>'.
1422: &Apache::loncoursequeueadmin::queued_selfenrollment());
1.216 raeburn 1423: return;
1424: }
1425:
1.234 raeburn 1426: sub requestcourse_advice {
1427: my ($r) = @_;
1428: my $domdesc = &Apache::lonnet::domain($env{'user.domain'},'description');
1429: my $esc_dom = &HTML::Entities::encode($env{'user.domain'},'"<>&');
1430: my (%can_request,%request_doms);
1431: &Apache::lonnet::check_can_request($env{'user.domain'},\%can_request,\%request_doms);
1432: if (keys(%request_doms) > 0) {
1433: my ($types,$typename) = &Apache::loncommon::course_types();
1434: if ((ref($types) eq 'ARRAY') && (ref($typename) eq 'HASH')) {
1435: $r->print('<h3>'.&mt('Request creation of a course or community').'</h3>'.
1.238 bisitz 1436: '<p>'.&mt('You have rights to request the creation of courses and/or communities in the following domain(s):').'<ul>');
1.234 raeburn 1437: my (@reqdoms,@reqtypes);
1438: foreach my $type (sort(keys(%request_doms))) {
1439: push(@reqtypes,$type);
1440: if (ref($request_doms{$type}) eq 'ARRAY') {
1441: my $domstr = join(', ',map { &Apache::lonnet::domain($_) } sort(@{$request_doms{$type}}));
1.238 bisitz 1442: $r->print(
1443: '<li>'
1444: .&mt('[_1]'.$typename->{$type}.'[_2] in domain: [_3]',
1445: '<i>',
1446: '</i>',
1447: '<b>'.$domstr.'</b>')
1448: .'</li>'
1449: );
1.234 raeburn 1450: foreach my $dom (@{$request_doms{$type}}) {
1451: unless (grep(/^\Q$dom\E/,@reqdoms)) {
1452: push(@reqdoms,$dom);
1453: }
1454: }
1455: }
1456: }
1457: my @showtypes;
1458: foreach my $type (@{$types}) {
1459: if (grep(/^\Q$type\E$/,@reqtypes)) {
1460: push(@showtypes,$type);
1461: }
1462: }
1463: my $requrl = '/adm/requestcourse';
1464: if (@reqdoms == 1) {
1465: $requrl .= '?showdom='.$reqdoms[0];
1466: }
1467: if (@showtypes > 0) {
1468: $requrl.=(($requrl=~/\?/)?'&':'?').'crstype='.$showtypes[0];
1469: }
1470: if (@reqdoms == 1 || @showtypes > 0) {
1471: $requrl .= '&state=crstype&action=new';
1472: }
1473: $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>');
1474: }
1475: }
1476: return;
1477: }
1478:
1.175 albertel 1479: sub privileges_info {
1480: my ($which) = @_;
1481: my $output;
1482:
1483: $which ||= $env{'request.role'};
1484:
1485: foreach my $envkey (sort(keys(%env))) {
1486: next if ($envkey!~/^user\.priv\.\Q$which\E\.(.*)/);
1487:
1488: my $where=$1;
1489: my $ttype;
1490: my $twhere;
1491: my (undef,$tdom,$trest,$tsec)=split(m{/},$where);
1492: if ($trest) {
1493: if ($env{'course.'.$tdom.'_'.$trest.'.description'} eq 'ca') {
1.288 raeburn 1494: $ttype='Authoring Space';
1.175 albertel 1495: $twhere='User: '.$trest.', Domain: '.$tdom;
1496: } else {
1497: $ttype= &Apache::loncommon::course_type($tdom.'_'.$trest);
1498: $twhere=$env{'course.'.$tdom.'_'.$trest.'.description'};
1499: if ($tsec) {
1500: my $sec_type = 'Section';
1501: if (exists($env{"user.role.gr.$where"})) {
1502: $sec_type = 'Group';
1503: }
1504: $twhere.=' ('.$sec_type.': '.$tsec.')';
1505: }
1506: }
1507: } elsif ($tdom) {
1508: $ttype='Domain';
1509: $twhere=$tdom;
1510: } else {
1511: $ttype='System';
1512: $twhere='/';
1513: }
1.204 bisitz 1514: $output .= "\n<h3>".&mt($ttype).': '.$twhere.'</h3>'."\n<ul>";
1.175 albertel 1515: foreach my $priv (sort(split(/:/,$env{$envkey}))) {
1516: next if (!$priv);
1517:
1518: my ($prv,$restr)=split(/\&/,$priv);
1519: my $trestr='';
1520: if ($restr ne 'F') {
1521: $trestr.=' ('.
1522: join(', ',
1523: map { &Apache::lonnet::plaintext($_) }
1524: (split('',$restr))).') ';
1525: }
1526: $output .= "\n\t".
1527: '<li>'.&Apache::lonnet::plaintext($prv).$trestr.'</li>';
1528: }
1529: $output .= "\n".'</ul>';
1530: }
1531: return $output;
1532: }
1533:
1.110 raeburn 1534: sub build_roletext {
1.254 raeburn 1535: my ($trolecode,$tdom,$trest,$tstatus,$tryagain,$advanced,$tremark,$tbg,$trole,$twhere,$tpstart,$tpend,$nochoose,$button,$switchserver,$reinit,$switchwarning) = @_;
1.223 raeburn 1536: my ($roletext,$roletext_end);
1.132 albertel 1537: my $is_dc=($trolecode =~ m/^dc\./);
1538: my $rowspan=($is_dc) ? ''
1539: : ' rowspan="2" ';
1540:
1.110 raeburn 1541: unless ($nochoose) {
1.134 www 1542: my $buttonname=$trolecode;
1543: $buttonname=~s/\W//g;
1.110 raeburn 1544: if (!$button) {
1545: if ($switchserver) {
1.212 bisitz 1546: $roletext.='<td'.$rowspan.' class="'.$tbg.'">'
1547: .'<a href="/adm/switchserver?'.$switchserver.'">'
1548: .&mt('Switch Server')
1549: .'</a></td>';
1.110 raeburn 1550: } else {
1.212 bisitz 1551: $roletext.=('<td'.$rowspan.' class="'.$tbg.'"> </td>');
1.110 raeburn 1552: }
1.255 raeburn 1553: if ($switchwarning) {
1554: if ($tremark eq '') {
1555: $tremark = $switchwarning;
1556: } else {
1557: $tremark .= '<br />'.$switchwarning;
1558: }
1559: }
1.110 raeburn 1560: } elsif ($tstatus eq 'is') {
1.212 bisitz 1561: $roletext.='<td'.$rowspan.' class="'.$tbg.'">'.
1562: '<input name="'.$buttonname.'" type="button" value="'.
1.225 bisitz 1563: &mt('Select').'" onclick="javascript:enterrole(this.form,\''.
1.192 raeburn 1564: $trolecode."','".$buttonname.'\');" /></td>';
1.110 raeburn 1565: } elsif ($tryagain) {
1566: $roletext.=
1.212 bisitz 1567: '<td'.$rowspan.' class="'.$tbg.'">'.
1568: '<input name="'.$buttonname.'" type="button" value="'.
1.225 bisitz 1569: &mt('Try Selecting Again').'" onclick="javascript:enterrole(this.form,\''.
1.192 raeburn 1570: $trolecode."','".$buttonname.'\');" /></td>';
1.110 raeburn 1571: } elsif ($advanced) {
1572: $roletext.=
1.212 bisitz 1573: '<td'.$rowspan.' class="'.$tbg.'">'.
1574: '<input name="'.$buttonname.'" type="button" value="'.
1.225 bisitz 1575: &mt('Re-Initialize').'" onclick="javascript:enterrole(this.form,\''.
1.192 raeburn 1576: $trolecode."','".$buttonname.'\');" /></td>';
1.209 raeburn 1577: } elsif ($reinit) {
1578: $roletext.=
1.212 bisitz 1579: '<td'.$rowspan.' class="'.$tbg.'">'.
1580: '<input name="'.$buttonname.'" type="button" value="'.
1.225 bisitz 1581: &mt('Re-Select').'" onclick="javascript:enterrole(this.form,\''.
1.209 raeburn 1582: $trolecode."','".$buttonname.'\');" /></td>';
1.110 raeburn 1583: } else {
1.209 raeburn 1584: $roletext.=
1.212 bisitz 1585: '<td'.$rowspan.' class="'.$tbg.'">'.
1586: '<input name="'.$buttonname.'" type="button" value="'.
1.225 bisitz 1587: &mt('Re-Select').'" onclick="javascript:enterrole(this.form,\''.
1.209 raeburn 1588: $trolecode."','".$buttonname.'\');" /></td>';
1.110 raeburn 1589: }
1590: }
1.165 albertel 1591: if ($trolecode !~ m/^(dc|ca|au|aa)\./) {
1592: $tremark.=&Apache::lonannounce::showday(time,1,
1593: &Apache::lonannounce::readcalendar($tdom.'_'.$trest));
1594: }
1.212 bisitz 1595: $roletext.='<td>'.$trole.'</td>'
1596: .'<td>'.$twhere.'</td>'
1597: .'<td>'.$tpstart.'</td>'
1.223 raeburn 1598: .'<td>'.$tpend.'</td>';
1.132 albertel 1599: if (!$is_dc) {
1.223 raeburn 1600: $roletext_end = '<td colspan="4">'.
1601: $tremark.' '.
1602: '</td>';
1.132 albertel 1603: }
1.223 raeburn 1604: return ($roletext,$roletext_end);
1.110 raeburn 1605: }
1606:
1.202 raeburn 1607: sub check_needs_switchserver {
1608: my ($possiblerole) = @_;
1609: my $needs_switchserver;
1610: my ($role,$where) = split(/\./,$possiblerole,2);
1611: my (undef,$tdom,$twho) = split(/\//,$where);
1612: my ($server_status,$home);
1613: if (($role eq 'ca') || ($role eq 'aa')) {
1614: ($server_status,$home) = &check_author_homeserver($twho,$tdom);
1615: } else {
1616: ($server_status,$home) = &check_author_homeserver($env{'user.name'},
1617: $env{'user.domain'});
1618: }
1619: if ($server_status eq 'switchserver') {
1620: $needs_switchserver = 1;
1621: }
1622: return $needs_switchserver;
1623: }
1624:
1.193 raeburn 1625: sub check_author_homeserver {
1.183 www 1626: my ($uname,$udom)=@_;
1.193 raeburn 1627: if (($uname eq '') || ($udom eq '')) {
1628: return ('fail','');
1629: }
1.183 www 1630: my $home = &Apache::lonnet::homeserver($uname,$udom);
1.193 raeburn 1631: if (&Apache::lonnet::host_domain($home) ne $udom) {
1632: return ('fail',$home);
1633: }
1.183 www 1634: my @ids=&Apache::lonnet::current_machine_ids();
1.193 raeburn 1635: if (grep(/^\Q$home\E$/,@ids)) {
1636: return ('ok',$home);
1637: } else {
1638: return ('switchserver',$home);
1.183 www 1639: }
1640: }
1641:
1.104 raeburn 1642: sub check_fordc {
1.260 raeburn 1643: my ($dcroles,$update,$then) = @_;
1.104 raeburn 1644: my $numdc = 0;
1.118 albertel 1645: if ($env{'user.adv'}) {
1646: foreach my $envkey (sort keys %env) {
1.170 albertel 1647: if ($envkey=~/^user\.role\.dc\.\/($match_domain)\/$/) {
1.104 raeburn 1648: my $dcdom = $1;
1649: my $livedc = 1;
1.118 albertel 1650: my ($tstart,$tend)=split(/\./,$env{$envkey});
1.260 raeburn 1651: my $limit = $update;
1652: if ($env{'request.role'} eq 'dc./'.$dcdom.'/') {
1653: $limit = $then;
1654: }
1655: if ($tstart && $tstart>$limit) { $livedc = 0; }
1656: if ($tend && $tend <$limit) { $livedc = 0; }
1.104 raeburn 1657: if ($livedc) {
1658: $$dcroles{$dcdom} = $envkey;
1.105 raeburn 1659: $numdc++;
1.104 raeburn 1660: }
1661: }
1662: }
1663: }
1664: return $numdc;
1665: }
1666:
1.185 raeburn 1667: sub adhoc_course_role {
1.260 raeburn 1668: my ($refresh,$update,$then) = @_;
1.239 raeburn 1669: my ($cdom,$cnum,$crstype);
1.201 raeburn 1670: $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
1671: $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.239 raeburn 1672: $crstype = &Apache::loncommon::course_type();
1.260 raeburn 1673: if (&check_forcc($cdom,$cnum,$refresh,$update,$then,$crstype)) {
1.185 raeburn 1674: my $setprivs;
1.198 raeburn 1675: if (!defined($env{'user.role.'.$env{'form.switchrole'}})) {
1.185 raeburn 1676: $setprivs = 1;
1677: } else {
1.198 raeburn 1678: my ($start,$end) = split(/\./,$env{'user.role.'.$env{'form.switchrole'}});
1.232 raeburn 1679: if (($start && ($start>$refresh || $start == -1)) ||
1.260 raeburn 1680: ($end && $end<$update)) {
1.185 raeburn 1681: $setprivs = 1;
1682: }
1.232 raeburn 1683: }
1.278 raeburn 1684: unless ($setprivs) {
1685: if (!exists($env{'user.priv.'.$env{'form.switchrole'}.'./'})) {
1686: $setprivs = 1;
1687: }
1688: }
1.185 raeburn 1689: if ($setprivs) {
1.198 raeburn 1690: if ($env{'form.switchrole'} =~ m-^(in|ta|ep|ad|st|cr)([\w/]*)\./\Q$cdom\E/\Q$cnum\E/?(\w*)$-) {
1.185 raeburn 1691: my $role = $1;
1692: my $custom_role = $2;
1693: my $usec = $3;
1694: if ($role eq 'cr') {
1.199 raeburn 1695: if ($custom_role =~ m-^/$match_domain/$match_username/\w+$-) {
1.185 raeburn 1696: $role .= $custom_role;
1697: } else {
1698: return;
1699: }
1700: }
1.208 raeburn 1701: my (%userroles,%newrole,%newgroups,%group_privs);
1702: my %cgroups =
1703: &Apache::lonnet::get_active_groups($env{'user.domain'},
1704: $env{'user.name'},$cdom,$cnum);
1705: foreach my $group (keys(%cgroups)) {
1706: $group_privs{$group} =
1707: $env{'user.priv.cc./'.$cdom.'/'.$cnum.'./'.$cdom.'/'.$cnum.'/'.$group};
1708: }
1709: $newgroups{'/'.$cdom.'/'.$cnum} = \%group_privs;
1.185 raeburn 1710: my $area = '/'.$cdom.'/'.$cnum;
1711: my $spec = $role.'.'.$area;
1712: if ($usec ne '') {
1713: $spec .= '/'.$usec;
1714: $area .= '/'.$usec;
1715: }
1.278 raeburn 1716: if ($role =~ /^cr/) {
1717: &Apache::lonnet::custom_roleprivs(\%newrole,$role,$cdom,$cnum,$spec,$area);
1718: } else {
1719: &Apache::lonnet::standard_roleprivs(\%newrole,$role,$cdom,$spec,$cnum,$area);
1720: }
1.208 raeburn 1721: &Apache::lonnet::set_userprivs(\%userroles,\%newrole,\%newgroups);
1.232 raeburn 1722: my $adhocstart = $refresh-1;
1.185 raeburn 1723: $userroles{'user.role.'.$spec} = $adhocstart.'.';
1.186 raeburn 1724: &Apache::lonnet::appenv(\%userroles,[$role,'cm']);
1.185 raeburn 1725: }
1726: }
1727: }
1728: return;
1729: }
1730:
1731: sub check_forcc {
1.260 raeburn 1732: my ($cdom,$cnum,$refresh,$update,$then,$crstype) = @_;
1.239 raeburn 1733: my ($is_cc,$ccrole);
1734: if ($crstype eq 'Community') {
1735: $ccrole = 'co';
1736: } else {
1737: $ccrole = 'cc';
1738: }
1.266 droeschl 1739: if (&Apache::lonnet::is_course($cdom,$cnum)) {
1740: my $envkey = 'user.role.'.$ccrole.'./'.$cdom.'/'.$cnum;
1741: if (defined($env{$envkey})) {
1742: $is_cc = 1;
1743: my ($tstart,$tend)=split(/\./,$env{$envkey});
1744: my $limit = $update;
1745: if ($env{'request.role'} eq $ccrole.'./'.$cdom.'/'.$cnum) {
1746: $limit = $then;
1.185 raeburn 1747: }
1.266 droeschl 1748: if ($tstart && $tstart>$refresh) { $is_cc = 0; }
1749: if ($tend && $tend <$limit) { $is_cc = 0; }
1.185 raeburn 1750: }
1751: }
1752: return $is_cc;
1753: }
1754:
1.254 raeburn 1755: sub check_release_required {
1.255 raeburn 1756: my ($loncaparev,$tcourseid,$trolecode,$required) = @_;
1.254 raeburn 1757: my ($switchserver,$warning);
1.255 raeburn 1758: if ($required ne '') {
1759: my ($reqdmajor,$reqdminor) = ($required =~ /^(\d+)\.(\d+)$/);
1.257 raeburn 1760: my ($major,$minor) = ($loncaparev =~ /^\'?(\d+)\.(\d+)\.[\w.\-]+\'?$/);
1.254 raeburn 1761: if ($reqdmajor ne '' && $reqdminor ne '') {
1762: my $otherserver;
1763: if (($major eq '' && $minor eq '') ||
1764: (($reqdmajor > $major) || (($reqdmajor == $major) && ($reqdminor > $minor)))) {
1765: my ($userdomserver) = &Apache::lonnet::choose_server($env{'user.domain'});
1766: my $switchlcrev =
1767: &Apache::lonnet::get_server_loncaparev($env{'user.domain'},
1768: $userdomserver);
1.257 raeburn 1769: my ($swmajor,$swminor) = ($switchlcrev =~ /^\'?(\d+)\.(\d+)\.[\w.\-]+\'?$/);
1.254 raeburn 1770: if (($swmajor eq '' && $swminor eq '') || ($reqdmajor > $swmajor) ||
1771: (($reqdmajor == $swmajor) && ($reqdminor > $swminor))) {
1772: my $cdom = $env{'course.'.$tcourseid.'.domain'};
1773: if ($cdom ne $env{'user.domain'}) {
1774: my ($coursedomserver,$coursehostname) = &Apache::lonnet::choose_server($cdom);
1775: my $serverhomeID = &Apache::lonnet::get_server_homeID($coursehostname);
1776: my $serverhomedom = &Apache::lonnet::host_domain($serverhomeID);
1777: my %defdomdefaults = &Apache::lonnet::get_domain_defaults($serverhomedom);
1778: my %udomdefaults = &Apache::lonnet::get_domain_defaults($env{'user.domain'});
1779: my $remoterev = &Apache::lonnet::get_server_loncaparev($serverhomedom,$coursedomserver);
1780: my $canhost =
1781: &Apache::lonnet::can_host_session($env{'user.domain'},
1782: $coursedomserver,
1783: $remoterev,
1784: $udomdefaults{'remotesessions'},
1785: $defdomdefaults{'hostedsessions'});
1786:
1787: if ($canhost) {
1788: $otherserver = $coursedomserver;
1789: } else {
1790: $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.");
1791: }
1792: } else {
1793: $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).");
1794: }
1795: } else {
1796: $otherserver = $userdomserver;
1797: }
1798: }
1799: if ($otherserver ne '') {
1800: $switchserver = 'otherserver='.$otherserver.'&role='.$trolecode;
1801: }
1802: }
1803: }
1804: return ($switchserver,$warning);
1805: }
1806:
1.108 raeburn 1807: sub courselink {
1.193 raeburn 1808: my ($dcdom,$rowtype) = @_;
1.109 raeburn 1809: my $courseform=&Apache::loncommon::selectcourse_link
1.152 raeburn 1810: ('rolechoice','dccourse'.$rowtype.'_'.$dcdom,
1811: 'dcdomain'.$rowtype.'_'.$dcdom,'coursedesc'.$rowtype.'_'.
1.239 raeburn 1812: $dcdom,$dcdom,undef,'Course/Community');
1.138 raeburn 1813: my $hiddenitems = '<input type="hidden" name="dcdomain'.$rowtype.'_'.$dcdom.'" value="'.$dcdom.'" />'.
1814: '<input type="hidden" name="origdom'.$rowtype.'_'.$dcdom.'" value="'.$dcdom.'" />'.
1815: '<input type="hidden" name="dccourse'.$rowtype.'_'.$dcdom.'" value="" />'.
1816: '<input type="hidden" name="coursedesc'.$rowtype.'_'.$dcdom.'" value="" />';
1.112 raeburn 1817: return $courseform.$hiddenitems;
1.109 raeburn 1818: }
1819:
1820: sub coursepick_jscript {
1.184 raeburn 1821: my %lt = &Apache::lonlocal::texthash(
1.239 raeburn 1822: 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 1823: youc => 'You can only use this screen to select courses and communities in the current domain.',
1.184 raeburn 1824: );
1.104 raeburn 1825: my $verify_script = <<"END";
1.179 raeburn 1826: <script type="text/javascript">
1.225 bisitz 1827: // <![CDATA[
1.108 raeburn 1828: function verifyCoursePick(caller) {
1829: var numbutton = getIndex(caller)
1.112 raeburn 1830: var pickedCourse = document.rolechoice.elements[numbutton+4].value
1831: var pickedDomain = document.rolechoice.elements[numbutton+2].value
1832: if (document.rolechoice.elements[numbutton+2].value == document.rolechoice.elements[numbutton+3].value) {
1.104 raeburn 1833: if (pickedCourse != '') {
1.108 raeburn 1834: if (numbutton != -1) {
1835: var courseTarget = "cc./"+pickedDomain+"/"+pickedCourse
1836: document.rolechoice.elements[numbutton+1].name = courseTarget
1837: document.rolechoice.submit()
1838: }
1.104 raeburn 1839: }
1840: else {
1.184 raeburn 1841: alert("$lt{'plsu'}");
1.104 raeburn 1842: }
1843: }
1844: else {
1.184 raeburn 1845: alert("$lt{'youc'}")
1.104 raeburn 1846: }
1847: }
1.109 raeburn 1848: function getIndex(caller) {
1.108 raeburn 1849: for (var i=0;i<document.rolechoice.elements.length;i++) {
1.109 raeburn 1850: if (document.rolechoice.elements[i] == caller) {
1.108 raeburn 1851: return i;
1852: }
1853: }
1854: return -1;
1855: }
1.225 bisitz 1856: // ]]>
1.104 raeburn 1857: </script>
1858: END
1.109 raeburn 1859: return $verify_script;
1.104 raeburn 1860: }
1861:
1.193 raeburn 1862: sub coauthorlink {
1863: my ($dcdom,$rowtype) = @_;
1864: my $coauthorform=&Apache::loncommon::selectauthor_link('rolechoice',$dcdom);
1865: my $hiddenitems = '<input type="hidden" name="adhoccauname'.$rowtype.'_'.$dcdom.'" value="" />';
1866: return $coauthorform.$hiddenitems;
1867: }
1868:
1.113 raeburn 1869: sub display_cc_role {
1870: my $rolekey = shift;
1.223 raeburn 1871: my ($roletext,$roletext_end);
1.118 albertel 1872: my $advanced = $env{'user.adv'};
1873: my $tryagain = $env{'form.tryagain'};
1.113 raeburn 1874: unless ($rolekey =~/^error\:/) {
1.240 raeburn 1875: if ($rolekey =~ m{^user\.role\.(cc|co)\./($match_domain)/($match_courseid)$}) {
1876: my $ccrole = $1;
1.249 raeburn 1877: my $tdom = $2;
1878: my $trest = $3;
1879: my $tcourseid = $tdom.'_'.$trest;
1880: my $trolecode = $ccrole.'./'.$tdom.'/'.$trest;
1.113 raeburn 1881: my $twhere;
1.152 raeburn 1882: my $ttype;
1.212 bisitz 1883: my $tbg='LC_roles_is';
1.113 raeburn 1884: my %newhash=&Apache::lonnet::coursedescription($tcourseid);
1885: if (%newhash) {
1886: $twhere=$newhash{'description'}.
1.261 bisitz 1887: ' <span class="LC_fontsize_small">'.
1.249 raeburn 1888: &Apache::loncommon::syllabuswrapper(&mt('Syllabus'),$trest,$tdom).
1.211 tempelho 1889: '</span>';
1.153 raeburn 1890: $ttype = $newhash{'type'};
1.113 raeburn 1891: } else {
1892: $twhere=&mt('Currently not available');
1.118 albertel 1893: $env{'course.'.$tcourseid.'.description'}=$twhere;
1.110 raeburn 1894: }
1.242 raeburn 1895: my $trole = &Apache::lonnet::plaintext($ccrole,$ttype,$tcourseid);
1.258 raeburn 1896: $twhere.="<br />".&mt('Domain').":".$tdom;
1.249 raeburn 1897: ($roletext,$roletext_end) = &build_roletext($trolecode,$tdom,$trest,'is',$tryagain,$advanced,'',$tbg,$trole,$twhere,'','','',1,'');
1.104 raeburn 1898: }
1899: }
1.223 raeburn 1900: return ($roletext,$roletext_end);
1.104 raeburn 1901: }
1902:
1.192 raeburn 1903: sub adhoc_roles_row {
1.138 raeburn 1904: my ($dcdom,$rowtype) = @_;
1.212 bisitz 1905: my $output = &Apache::loncommon::continue_data_table_row()
1906: .' <td colspan="5">'
1907: .&mt('[_1]Ad hoc[_2] roles in domain [_3] --'
1908: ,'<span class="LC_cusr_emph">','</span>',$dcdom)
1.227 bisitz 1909: .' ';
1.193 raeburn 1910: my $selectcclink = &courselink($dcdom,$rowtype);
1.239 raeburn 1911: my $ccrole = &Apache::lonnet::plaintext('co',undef,undef,1);
1.182 www 1912: my $carole = &Apache::lonnet::plaintext('ca');
1.193 raeburn 1913: my $selectcalink = &coauthorlink($dcdom,$rowtype);
1.227 bisitz 1914: $output.=$ccrole.': '.$selectcclink
1.249 raeburn 1915: .' | '.$carole.': '.$selectcalink.'</td>'
1.212 bisitz 1916: .&Apache::loncommon::end_data_table_row();
1.108 raeburn 1917: return $output;
1918: }
1919:
1.104 raeburn 1920: sub recent_filename {
1921: my $area=shift;
1.149 www 1922: return 'nohist_recent_'.&escape($area);
1.104 raeburn 1923: }
1924:
1.139 raeburn 1925: sub courseloadpage {
1926: my ($courseid) = @_;
1927: my $startpage;
1.144 albertel 1928: my %entry_settings = &Apache::lonnet::get('nohist_whatsnew',
1929: [$courseid.':courseinit']);
1.139 raeburn 1930: my ($tmp) = %entry_settings;
1.144 albertel 1931: unless ($tmp =~ /^error: 2 /) {
1.139 raeburn 1932: $startpage = $entry_settings{$courseid.':courseinit'};
1933: }
1934: if ($startpage eq '') {
1935: if (exists($env{'environment.course_init_display'})) {
1936: $startpage = $env{'environment.course_init_display'};
1937: }
1938: }
1939: return $startpage;
1940: }
1941:
1.260 raeburn 1942: sub update_session_roles {
1943: my $then=$env{'user.login.time'};
1944: my $refresh=$env{'user.refresh.time'};
1945: if (!$refresh) {
1946: $refresh = $then;
1947: }
1948: my $update = $env{'user.update.time'};
1949: if (!$update) {
1950: $update = $then;
1951: }
1952: my $now = time;
1953: my %roleshash =
1954: &Apache::lonnet::get_my_roles('','','userroles',
1955: ['active','future','previous'],
1956: undef,undef,1);
1957: my ($msg,@newsec,$oldsec,$currrole_expired,@changed_roles,
1.264 raeburn 1958: %changed_groups,%dbroles,%deletedroles,%allroles,%allgroups,
1.260 raeburn 1959: %userroles,%checkedgroup,%crprivs,$hasgroups,%rolechange,
1960: %groupchange,%newrole,%newgroup,%customprivchg,%groups_roles,
1961: @rolecodes);
1962: my @possroles = ('cr','st','ta','ad','ep','in','co','cc');
1963: my %courseroles;
1964: foreach my $item (keys(%roleshash)) {
1965: my ($uname,$udom,$role,$remainder) = split(/:/,$item,4);
1966: my ($tstart,$tend) = split(/:/,$roleshash{$item});
1967: my ($section,$group,@group_privs);
1968: if ($role =~ m{^gr/(\w*)$}) {
1969: $role = 'gr';
1970: my $priv = $1;
1971: next if ($tstart eq '-1');
1972: if (&curr_role_status($tstart,$tend,$refresh,$now) eq 'active') {
1973: if ($priv ne '') {
1974: push(@group_privs,$priv);
1975: }
1976: }
1977: if ($remainder =~ /:/) {
1978: (my $additional_privs,$group) =
1979: ($remainder =~ /^([\w:]+):([^:]+)$/);
1980: if ($additional_privs ne '') {
1981: if (&curr_role_status($tstart,$tend,$refresh,$now) eq 'active') {
1982: push(@group_privs,split(/:/,$additional_privs));
1983: @group_privs = sort(@group_privs);
1984: }
1985: }
1986: } else {
1987: $group = $remainder;
1988: }
1989: } else {
1990: $section = $remainder;
1991: }
1992: my $where = "/$udom/$uname";
1993: if ($section ne '') {
1994: $where .= "/$section";
1995: } elsif ($group ne '') {
1996: $where .= "/$group";
1997: }
1998: my $rolekey = "$role.$where";
1999: my $envkey = "user.role.$rolekey";
2000: $dbroles{$envkey} = 1;
2001: if (($env{'request.role'} eq $rolekey) && ($role ne 'st')) {
2002: if (&curr_role_status($tstart,$tend,$refresh,$now) ne 'active') {
2003: $currrole_expired = 1;
2004: }
2005: }
2006: if ($env{$envkey} eq '') {
2007: my $status_in_db =
1.271 raeburn 2008: &curr_role_status($tstart,$tend,$now,$now);
1.260 raeburn 2009: &gather_roleprivs(\%allroles,\%allgroups,\%userroles,$where,$role,$tstart,$tend,$status_in_db);
2010: if (($role eq 'st') && ($env{'request.role'} =~ m{^\Q$role\E\.\Q/$udom/$uname\E})) {
2011: if ($status_in_db eq 'active') {
2012: if ($section eq '') {
2013: push(@newsec,'none');
2014: } else {
2015: push(@newsec,$section);
2016: }
2017: }
2018: } else {
2019: unless (grep(/^\Q$role\E$/,@changed_roles)) {
2020: push(@changed_roles,$role);
2021: }
2022: if ($status_in_db ne 'previous') {
2023: if ($role eq 'gr') {
2024: $newgroup{$rolekey} = $status_in_db;
2025: if ($status_in_db eq 'active') {
2026: unless (ref($courseroles{$udom}) eq 'HASH') {
2027: %{$courseroles{$udom}} =
2028: &Apache::lonnet::get_my_roles('','','userroles',
2029: ['active'],\@possroles,
2030: [$udom],1);
2031: }
2032: &Apache::lonnet::get_groups_roles($udom,$uname,
2033: $courseroles{$udom},
2034: \@rolecodes,\%groups_roles);
2035: }
2036: } else {
2037: $newrole{$rolekey} = $status_in_db;
2038: }
2039: }
2040: }
2041: } else {
2042: my ($currstart,$currend) = split(/\./,$env{$envkey});
2043: if ($role eq 'gr') {
2044: if (&curr_role_status($currstart,$currend,$refresh,$update) ne 'previous') {
2045: $hasgroups = 1;
2046: }
2047: }
2048: if (($currstart ne $tstart) || ($currend ne $tend)) {
2049: my $status_in_env =
2050: &curr_role_status($currstart,$currend,$refresh,$update);
2051: my $status_in_db =
1.271 raeburn 2052: &curr_role_status($tstart,$tend,$now,$now);
1.260 raeburn 2053: if ($status_in_env ne $status_in_db) {
2054: if ($status_in_env eq 'active') {
2055: if ($role eq 'st') {
2056: if ($env{'request.role'} eq $rolekey) {
2057: my $switchsection;
2058: unless (ref($courseroles{$udom}) eq 'HASH') {
2059: %{$courseroles{$udom}} =
2060: &Apache::lonnet::get_my_roles('','','userroles',
2061: ['active'],
2062: \@possroles,[$udom],1);
2063: }
2064: foreach my $crsrole (keys(%{$courseroles{$udom}})) {
2065: if ($crsrole =~ /^\Q$uname\E:\Q$udom\E:st/) {
2066: $switchsection = 1;
2067: last;
2068: }
2069: }
2070: if ($switchsection) {
2071: if ($section eq '') {
2072: $oldsec = 'none';
2073: } else {
2074: $oldsec = $section;
2075: }
2076: &gather_roleprivs(\%allroles,\%allgroups,\%userroles,$where,$role,$tstart,$tend,$status_in_db);
2077: } else {
2078: $currrole_expired = 1;
2079: next;
2080: }
2081: }
2082: }
2083: unless ($rolekey eq $env{'request.role'}) {
2084: if ($role eq 'gr') {
2085: &Apache::lonnet::delete_env_groupprivs($where,\%courseroles,\@possroles);
2086: } else {
2087: &Apache::lonnet::delenv("user.priv.$rolekey",undef,[$role]);
2088: &Apache::lonnet::delenv("user.priv.cm.$where",undef,['cm']);
2089: }
2090: &gather_roleprivs(\%allroles,\%allgroups,\%userroles,$where,$role,$tstart,$tend,$status_in_db);
2091: }
2092: } elsif ($status_in_db eq 'active') {
2093: if (($role eq 'st') &&
2094: ($env{'request.role'} =~ m{^\Q$role\E\.\Q/$udom/$uname\E})) {
2095: if ($section eq '') {
2096: push(@newsec,'none');
2097: } else {
2098: push(@newsec,$section);
2099: }
2100: } elsif ($role eq 'gr') {
2101: unless (ref($courseroles{$udom}) eq 'HASH') {
2102: %{$courseroles{$udom}} =
2103: &Apache::lonnet::get_my_roles('','','userroles',
2104: ['active'],
2105: \@possroles,[$udom],1);
2106: }
2107: &Apache::lonnet::get_groups_roles($udom,$uname,
2108: $courseroles{$udom},
2109: \@rolecodes,\%groups_roles);
2110: }
2111: &gather_roleprivs(\%allroles,\%allgroups,\%userroles,$where,$role,$tstart,$tend,$status_in_db);
2112: }
2113: unless (grep(/^\Q$role\E$/,@changed_roles)) {
2114: push(@changed_roles,$role);
2115: }
2116: if ($role eq 'gr') {
2117: $groupchange{"/$udom/$uname"}{$group} = $status_in_db;
2118: } else {
2119: $rolechange{$rolekey} = $status_in_db;
2120: }
2121: }
2122: } else {
2123: if ($role eq 'gr') {
2124: unless ($checkedgroup{$where}) {
2125: my $status_in_db =
2126: &curr_role_status($tstart,$tend,$refresh,$now);
2127: if ($tstart eq '-1') {
2128: $status_in_db = 'deleted';
2129: }
2130: unless (ref($courseroles{$udom}) eq 'HASH') {
2131: %{$courseroles{$udom}} =
2132: &Apache::lonnet::get_my_roles('','','userroles',
2133: ['active'],
2134: \@possroles,[$udom],1);
2135: }
2136: if (ref($courseroles{$udom}) eq 'HASH') {
2137: foreach my $item (keys(%{$courseroles{$udom}})) {
2138: next unless ($item =~ /^\Q$uname\E/);
2139: my ($cnum,$cdom,$crsrole,$crssec) = split(/:/,$item);
2140: my $area = '/'.$cdom.'/'.$cnum;
2141: if ($crssec ne '') {
2142: $area .= '/'.$crssec;
2143: }
2144: my $crsrolekey = $crsrole.'.'.$area;
2145: my $currprivs = $env{'user.priv.'.$crsrole.'.'.$area.'.'.$where};
2146: $currprivs =~ s/^://;
2147: $currprivs =~ s/\&F$//;
2148: my @curr_grp_privs = split(/\&F:/,$currprivs);
2149: @curr_grp_privs = sort(@curr_grp_privs);
2150: my @diffs;
2151: if (@group_privs > 0 || @curr_grp_privs > 0) {
2152: @diffs = &Apache::loncommon::compare_arrays(\@group_privs,\@curr_grp_privs);
2153: }
2154: if (@diffs == 0) {
2155: last;
2156: } else {
2157: unless(grep(/^\Qgr\E$/,@rolecodes)) {
2158: push(@rolecodes,'gr');
2159: }
2160: &gather_roleprivs(\%allroles,\%allgroups,
2161: \%userroles,$where,$role,
2162: $tstart,$tend,$status_in_db);
2163: if ($status_in_db eq 'active') {
2164: &Apache::lonnet::get_groups_roles($udom,$uname,
2165: $courseroles{$udom},
2166: \@rolecodes,\%groups_roles);
2167: }
2168: $changed_groups{$udom.'_'.$uname}{$group} = $status_in_db;
2169: last;
2170: }
2171: }
2172: }
2173: $checkedgroup{$where} = 1;
2174: }
2175: } elsif ($role =~ /^cr/) {
2176: my $status_in_db =
2177: &curr_role_status($tstart,$tend,$refresh,$now);
2178: my ($rdummy,$rest) = split(/\//,$role,2);
2179: my %currpriv;
2180: unless (exists($crprivs{$rest})) {
2181: my ($rdomain,$rauthor,$rrole)=split(/\//,$rest);
2182: my $homsvr=&Apache::lonnet::homeserver($rauthor,$rdomain);
2183: if (&Apache::lonnet::hostname($homsvr) ne '') {
2184: my ($rdummy,$roledef)=
2185: &Apache::lonnet::get('roles',["rolesdef_$rrole"],
2186: $rdomain,$rauthor);
2187: if (($rdummy ne 'con_lost') && ($roledef ne '')) {
2188: my $i = 0;
2189: my @scopes = ('sys','dom','crs');
2190: my @privs = split(/\_/,$roledef);
2191: foreach my $priv (@privs) {
2192: my ($blank,@prv) = split(/:/,$priv);
2193: @prv = map { $_ .= (/\&\w+$/ ? '':'&F') } @prv;
1.264 raeburn 2194: if (@prv) {
2195: $priv = ':'.join(':',sort(@prv));
2196: }
1.260 raeburn 2197: $crprivs{$rest}{$scopes[$i]} = $priv;
2198: $i++;
2199: }
2200: }
2201: }
2202: }
1.279 raeburn 2203: my $status_in_env =
2204: &curr_role_status($currstart,$currend,$refresh,$update);
2205: if ($status_in_env eq 'active') {
2206: $currpriv{sys} = $env{"user.priv.$rolekey./"};
2207: $currpriv{dom} = $env{"user.priv.$rolekey./$udom/"};
2208: $currpriv{crs} = $env{"user.priv.$rolekey.$where"};
2209: if (keys(%crprivs)) {
2210: if (($crprivs{$rest}{sys} ne $currpriv{sys}) ||
2211: ($crprivs{$rest}{dom} ne $currpriv{dom})
1.260 raeburn 2212: ||
1.279 raeburn 2213: ($crprivs{$rest}{crs} ne $currpriv{crs})) {
2214: &gather_roleprivs(\%allroles,\%allgroups,
2215: \%userroles,$where,$role,
2216: $tstart,$tend,$status_in_db);
2217: unless (grep(/^\Q$role\E$/,@changed_roles)) {
2218: push(@changed_roles,$role);
2219: }
1.260 raeburn 2220: $customprivchg{$rolekey} = $status_in_env;
2221: }
2222: }
2223: }
2224: }
2225: }
2226: }
2227: }
2228: foreach my $envkey (keys(%env)) {
2229: next unless ($envkey =~ /^user\.role\./);
2230: next if ($dbroles{$envkey});
2231: next if ($envkey eq 'user.role.'.$env{'request.role'});
2232: my ($currstart,$currend) = split(/\./,$env{$envkey});
2233: my $status_in_env =
2234: &curr_role_status($currstart,$currend,$refresh,$update);
2235: my ($rolekey) = ($envkey =~ /^user\.role\.(.+)$/);
2236: my ($role,$rest)=split(/\./,$rolekey,2);
2237: if (&Apache::lonnet::delenv($envkey,undef,[$role])) {
2238: if ($status_in_env eq 'active') {
2239: if ($role eq 'gr') {
2240: &Apache::lonnet::delete_env_groupprivs($rest,\%courseroles,
2241: \@possroles);
2242: } else {
2243: &Apache::lonnet::delenv("user.priv.$rolekey",undef,[$role]);
2244: &Apache::lonnet::delenv("user.priv.cm.$rest",undef,['cm']);
2245: }
2246: unless (grep(/^\Q$role\E$/,@changed_roles)) {
2247: push(@changed_roles,$role);
2248: }
2249: $deletedroles{$rolekey} = 1;
2250: }
2251: }
2252: }
2253: if (($oldsec) && (@newsec > 0)) {
2254: if (@newsec > 1) {
1.274 raeburn 2255: $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 2256: } else {
2257: my $newrole = $env{'request.role'};
2258: if ($newsec[0] eq 'none') {
2259: $newrole =~ s{(/[^/])$}{};
2260: } elsif ($oldsec eq 'none') {
2261: $newrole .= '/'.$newsec[0];
2262: } else {
2263: $newrole =~ s{([^/]+)$}{$newsec[0]};
2264: }
2265: my $coursedesc = $env{'course.'.$env{'request.course.id'}.'.description'};
2266: my ($curr_role) = ($env{'request.role'} =~ m{^(\w+)\./$match_domain/$match_courseid});
2267: my %temp=('logout_'.$env{'request.course.id'} => time);
2268: &Apache::lonnet::put('email_status',\%temp);
2269: &Apache::lonnet::delenv('user.state.'.$env{'request.course.id'});
2270: &Apache::lonnet::appenv({"request.course.id" => '',
2271: "request.course.fn" => '',
2272: "request.course.uri" => '',
2273: "request.course.sec" => '',
2274: "request.role" => 'cm',
2275: "request.role.adv" => $env{'user.adv'},
2276: "request.role.domain" => $env{'user.domain'}});
2277: my $rolename = &Apache::loncommon::plainname($curr_role);
2278: $msg = '<p><form name="reselectrole" action="/adm/roles" method="post" />'.
2279: '<input type="hidden" name="newrole" value="" />'.
2280: '<input type="hidden" name="selectrole" value="1" />'.
2281: '<span class="LC_info">'.
2282: &mt('Your section has changed for your current [_1] role in [_2].',$rolename,$coursedesc).'</span><br />';
2283: my $button = '<input type="button" name="sectionchanged" value="'.
2284: &mt('Re-Select').'" onclick="javascript:enterrole(this.form,'."'$newrole','sectionchanged'".')" />';
2285: if ($newsec[0] eq 'none') {
2286: $msg .= &mt('[_1] to continue with your new section-less role.',$button);
2287: } else {
2288: $msg .= &mt('[_1] to continue with your new role in section ([_2]).',$button,$newsec[0]);
2289: }
2290: $msg .= '</form></p>';
2291: }
2292: } elsif ($currrole_expired) {
1.274 raeburn 2293: $msg .= '<p class="LC_warning">';
1.260 raeburn 2294: if (&Apache::loncommon::show_course()) {
2295: $msg .= &mt('Your role in the current course has expired.');
2296: } else {
2297: $msg .= &mt('Your current role has expired.');
2298: }
1.274 raeburn 2299: $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 2300: }
1.279 raeburn 2301: &Apache::lonnet::set_userprivs(\%userroles,\%allroles,\%allgroups,\%groups_roles);
2302: my ($curr_is_adv,$curr_role_adv,$curr_author,$curr_role_author);
2303: $curr_author = $env{'user.author'};
2304: if (($env{'request.role'} =~/^au/) || ($env{'request.role'} =~/^ca/) ||
2305: ($env{'request.role'} =~/^aa/)) {
2306: $curr_role_author=1;
2307: }
2308: $curr_is_adv = $env{'user.adv'};
2309: $curr_role_adv = $env{'request.role.adv'};
2310: if (keys(%userroles) > 0) {
2311: foreach my $role (@changed_roles) {
2312: unless(grep(/^\Q$role\E$/,@rolecodes)) {
2313: push(@rolecodes,$role);
2314: }
2315: }
2316: unless(grep(/^\Qcm\E$/,@rolecodes)) {
2317: push(@rolecodes,'cm');
2318: }
2319: &Apache::lonnet::appenv(\%userroles,\@rolecodes);
2320: }
2321: my %newenv;
2322: if (&Apache::lonnet::is_advanced_user($env{'user.domain'},$env{'user.name'})) {
2323: unless ($curr_is_adv) {
2324: $newenv{'user.adv'} = 1;
2325: }
2326: } elsif ($curr_is_adv && !$curr_role_adv) {
2327: &Apache::lonnet::delenv('user.adv');
2328: }
2329: my %authorroleshash =
2330: &Apache::lonnet::get_my_roles('','','userroles',['active'],['au','ca','aa']);
2331: if (keys(%authorroleshash)) {
2332: unless ($curr_author) {
2333: $newenv{'user.author'} = 1;
2334: }
2335: } elsif ($curr_author && !$curr_role_author) {
2336: &Apache::lonnet::delenv('user.author');
2337: }
2338: if ($env{'request.course.id'}) {
2339: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
2340: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
2341: my (@activecrsgroups,$crsgroupschanged);
2342: if ($env{'request.course.groups'}) {
2343: @activecrsgroups = split(/:/,$env{'request.course.groups'});
2344: foreach my $item (keys(%deletedroles)) {
2345: if ($item =~ m{^gr\./\Q$cdom\E/\Q$cnum\E/(\w+)$}) {
2346: if (grep(/^\Q$1\E$/,@activecrsgroups)) {
2347: $crsgroupschanged = 1;
2348: last;
2349: }
2350: }
2351: }
2352: }
2353: unless ($crsgroupschanged) {
2354: foreach my $item (keys(%newgroup)) {
2355: if ($item =~ m{^gr\./\Q$cdom\E/\Q$cnum\E/(\w+)$}) {
2356: if ($newgroup{$item} eq 'active') {
2357: $crsgroupschanged = 1;
2358: last;
2359: }
2360: }
2361: }
2362: }
2363: if ((ref($changed_groups{$env{'request.course.id'}}) eq 'HASH') ||
2364: (ref($groupchange{"/$cdom/$cnum"}) eq 'HASH') ||
2365: ($crsgroupschanged)) {
2366: my %grouproles = &Apache::lonnet::get_my_roles('','','userroles',
2367: ['active'],['gr'],[$cdom],1);
2368: my @activegroups;
2369: foreach my $item (keys(%grouproles)) {
2370: next unless($item =~ /^\Q$cnum\E:\Q$cdom\E/);
2371: my $group;
2372: my ($crsn,$crsd,$role,$remainder) = split(/:/,$item,4);
2373: if ($remainder =~ /:/) {
2374: (my $other,$group) = ($remainder =~ /^([\w:]+):([^:]+)$/);
2375: } else {
2376: $group = $remainder;
2377: }
2378: if ($group ne '') {
2379: push(@activegroups,$group);
2380: }
2381: }
2382: $newenv{'request.course.groups'} = join(':',@activegroups);
2383: }
2384: }
2385: if (keys(%newenv)) {
2386: &Apache::lonnet::appenv(\%newenv);
2387: }
1.260 raeburn 2388: if (!@changed_roles || !(keys(%changed_groups))) {
1.264 raeburn 2389: my ($rolesmsg,$groupsmsg);
1.260 raeburn 2390: if (!@changed_roles) {
2391: if (&Apache::loncommon::show_course()) {
1.264 raeburn 2392: $rolesmsg = &mt('No new courses or communities');
1.260 raeburn 2393: } else {
1.264 raeburn 2394: $rolesmsg = &mt('No role changes');
1.260 raeburn 2395: }
2396: }
2397: if ($hasgroups && !(keys(%changed_groups)) && !(grep(/gr/,@changed_roles))) {
1.264 raeburn 2398: $groupsmsg = &mt('No changes in course/community groups');
1.260 raeburn 2399: }
2400: if (!@changed_roles && !(keys(%changed_groups))) {
1.264 raeburn 2401: if (($msg ne '') || ($groupsmsg ne '')) {
2402: $msg .= '<ul>';
2403: if ($rolesmsg) {
2404: $msg .= '<li>'.$rolesmsg.'</li>';
2405: }
2406: if ($groupsmsg) {
2407: $msg .= '<li>'.$groupsmsg.'</li>';
2408: }
2409: $msg .= '</ul>';
2410: } else {
1.270 raeburn 2411: $msg = ' <span class="LC_cusr_emph">'.$rolesmsg.'</span><br />';
1.264 raeburn 2412: }
1.260 raeburn 2413: return $msg;
2414: }
2415: }
2416: my $changemsg;
2417: if (@changed_roles > 0) {
2418: if (keys(%newgroup) > 0) {
2419: my $groupmsg;
1.279 raeburn 2420: my (%curr_groups,%groupdescs,$currcrs);
1.260 raeburn 2421: foreach my $item (sort(keys(%newgroup))) {
2422: if (&is_active_course($item,$refresh,$update,\%roleshash)) {
1.279 raeburn 2423: if ($item =~ m{^gr\./($match_domain/$match_courseid)/(\w+)$}) {
2424: my ($cdom,$cnum) = split(/\//,$1);
2425: my $group = $2;
2426: if ($currcrs ne $cdom.'_'.$cnum) {
2427: if ($currcrs) {
2428: $groupmsg .= '</ul><li>';
2429: }
2430: $groupmsg .= '<li><b>'.
2431: $env{'course.'.$cdom.'_'.$cnum.'.description'}.'</b><ul>';
1.281 raeburn 2432: $currcrs = $cdom.'_'.$cnum;
1.279 raeburn 2433: }
2434: my $groupdesc;
2435: unless (ref($curr_groups{$cdom.'_'.$cnum}) eq 'HASH') {
2436: %{$curr_groups{$cdom.'_'.$cnum}} =
2437: &Apache::longroup::coursegroups($cdom,$cnum);
2438: }
2439: unless ((ref($groupdescs{$cdom.'_'.$cnum}) eq 'HASH') &&
2440: ($groupdescs{$cdom.'_'.$cnum}{$group})) {
2441:
2442: my %groupinfo =
2443: &Apache::longroup::get_group_settings($curr_groups{$cdom.'_'.$cnum}{$group});
2444: $groupdescs{$cdom.'_'.$cnum}{$group} =
2445: &unescape($groupinfo{'description'});
2446: }
2447: $groupdesc = $groupdescs{$cdom.'_'.$cnum}{$group};
1.286 raeburn 2448: if ($groupdesc) {
2449: $groupmsg .= '<li>'.
2450: &mt('[_1] with status: [_2].',
2451: '<b>'.$groupdesc.'</b>',$newgroup{$item}).'</li>';
2452: }
1.279 raeburn 2453: }
2454: }
2455: if ($groupmsg) {
2456: $groupmsg .= '</ul></li>';
1.260 raeburn 2457: }
2458: }
2459: if ($groupmsg) {
2460: $changemsg .= '<li>'.
2461: &mt('Courses with new groups').'</li>'.
2462: '<ul>'.$groupmsg.'</ul></li>';
2463: }
2464: }
2465: if (keys(%newrole) > 0) {
1.286 raeburn 2466: my $newmsg;
1.260 raeburn 2467: foreach my $item (sort(keys(%newrole))) {
1.279 raeburn 2468: my $desc = &role_desc($item,$update,$refresh,$now);
1.286 raeburn 2469: if ($desc) {
2470: $newmsg .= '<li>'.
2471: &mt('[_1] with status: [_2].',
1.293 bisitz 2472: $desc,&mt($newrole{$item})).'</li>';
1.286 raeburn 2473: }
2474: }
2475: if ($newmsg) {
2476: $changemsg .= '<li>'.&mt('New roles').
2477: '<ul>'.$newmsg.'</ul>'.
2478: '</li>';
1.260 raeburn 2479: }
2480: }
2481: if (keys(%customprivchg) > 0) {
1.286 raeburn 2482: my $privmsg;
1.260 raeburn 2483: foreach my $item (sort(keys(%customprivchg))) {
1.279 raeburn 2484: my $desc = &role_desc($item,$update,$refresh,$now);
1.286 raeburn 2485: if ($desc) {
2486: $privmsg .= '<li>'.$desc.'</li>';
2487: }
1.260 raeburn 2488: }
1.286 raeburn 2489: if ($privmsg) {
2490: $changemsg .= '<li>'.
2491: &mt('Custom roles with privilege changes').
2492: '<ul>'.$privmsg.'</ul>'.
2493: '</li>';
2494: }
1.260 raeburn 2495: }
2496: if (keys(%rolechange) > 0) {
1.286 raeburn 2497: my $rolemsg;
1.260 raeburn 2498: foreach my $item (sort(keys(%rolechange))) {
1.279 raeburn 2499: my $desc = &role_desc($item,$update,$refresh,$now);
1.286 raeburn 2500: if ($desc) {
2501: $rolemsg .= '<li>'.
2502: &mt('[_1] status now: [_2].',$desc,
2503: $rolechange{$item}).'</li>';
2504: }
2505: }
2506: if ($rolemsg) {
1.260 raeburn 2507: $changemsg .= '<li>'.
1.286 raeburn 2508: &mt('Existing roles with status changes').'</li>'.
2509: '<ul>'.$rolemsg.'</ul>'.
2510: '</li>';
1.260 raeburn 2511: }
2512: }
2513: if (keys(%deletedroles) > 0) {
1.286 raeburn 2514: my $delmsg;
1.260 raeburn 2515: foreach my $item (sort(keys(%deletedroles))) {
1.279 raeburn 2516: my $desc = &role_desc($item,$update,$refresh,$now);
1.286 raeburn 2517: if ($desc) {
2518: $delmsg .= '<li>'.$desc.'</li>';
2519: }
2520: }
2521: if ($delmsg) {
2522: $changemsg .= '<li>'.
2523: &mt('Existing roles now expired').'</li>'.
2524: '<ul>'.$delmsg.'</ul>'.
2525: '</li>';
1.260 raeburn 2526: }
2527: }
2528: }
2529: if ((keys(%changed_groups) > 0) || (keys(%groupchange) > 0)) {
2530: my $groupchgmsg;
2531: foreach my $key (sort(keys(%changed_groups))) {
2532: my $crs = 'gr/'.$key;
2533: $crs =~ s/_/\//;
2534: if (&is_active_course($crs,$refresh,$update,\%roleshash)) {
2535: if (ref($changed_groups{$key}) eq 'HASH') {
2536: my @showgroups;
2537: foreach my $group (sort(keys(%{$changed_groups{$key}}))) {
2538: if ($changed_groups{$key}{$group} eq 'active') {
2539: push(@showgroups,$group);
2540: }
2541: }
2542: if (@showgroups > 0) {
2543: $groupchgmsg .= '<li>'.
2544: &mt('Course: [_1], groups: [_2].',$key,
2545: join(', ',@showgroups)).
2546: '</li>';
2547: }
2548: }
2549: }
2550: }
2551: if (keys(%groupchange) > 0) {
2552: $groupchgmsg .= '<li>'.
2553: &mt('Existing course/community groups with status changes').'</li>'.
2554: '<ul>';
2555: foreach my $crs (sort(keys(%groupchange))) {
1.279 raeburn 2556: my $cid = $crs;
2557: $cid=~s{^/}{};
2558: $cid=~s{/}{_};
2559: my $crsdesc = $env{'course.'.$cid.'.description'};
2560: my $cdom = $env{'course.'.$cid.'.domain'};
2561: my $cnum = $env{'course.'.$cid.'.num'};
2562: my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum);
2563: my %groupdesc;
1.260 raeburn 2564: if (ref($groupchange{$crs}) eq 'HASH') {
1.279 raeburn 2565: $groupchgmsg .= '<li>'.&mt('Course/Community: [_1]','<b>'.$crsdesc.'</b><ul>');
1.260 raeburn 2566: foreach my $group (sort(keys(%{$groupchange{$crs}}))) {
1.279 raeburn 2567: unless ($groupdesc{$group}) {
2568: my %groupinfo = &Apache::longroup::get_group_settings($curr_groups{$group});
2569: $groupdesc{$group} = &unescape($groupinfo{'description'});
2570: }
2571: $groupchgmsg .= '<li>'.&mt('Group: [_1] status now: [_2].','<b>'.$groupdesc{$group}.'</b>',$groupchange{$crs}{$group}).'</li>';
1.260 raeburn 2572: }
2573: $groupchgmsg .= '</ul></li>';
2574: }
2575: }
2576: $groupchgmsg .= '</ul></li>';
2577: }
2578: if ($groupchgmsg) {
2579: $changemsg .= '<li>'.
2580: &mt('Courses with changes in groups').'</li>'.
2581: '<ul>'.$groupchgmsg.'</ul></li>';
2582: }
2583: }
2584: if ($changemsg) {
2585: $msg .= '<ul>'.$changemsg.'</ul>';
1.286 raeburn 2586: } else {
2587: if (&Apache::loncommon::show_course()) {
2588: $msg = &mt('No new courses or communities');
2589: } else {
2590: $msg = &mt('No role changes');
2591: }
1.260 raeburn 2592: }
1.279 raeburn 2593: return $msg;
2594: }
2595:
2596: sub role_desc {
2597: my ($item,$update,$refresh,$now) = @_;
2598: my ($where,$trolecode,$role,$tstatus,$tend,$tstart,$twhere,
2599: $trole,$tremark);
1.282 raeburn 2600: &Apache::lonnet::role_status('user.role.'.$item,$update,$refresh,
2601: $now,\$role,\$where,\$trolecode,
1.279 raeburn 2602: \$tstatus,\$tstart,\$tend);
1.286 raeburn 2603: return unless ($role);
1.279 raeburn 2604: if ($role =~ /^cr\//) {
2605: my ($rdummy,$rdomain,$rauthor,$rrole)=split(/\//,$role);
2606: $tremark = &mt('Customrole defined by [_1].',$rauthor.':'.$rdomain);
2607: }
2608: $trole=Apache::lonnet::plaintext($role);
2609: my ($tdom,$trest,$tsection)=
2610: split(/\//,Apache::lonnet::declutter($where));
2611: if (($role eq 'ca') || ($role eq 'aa')) {
2612: my $home = &Apache::lonnet::homeserver($trest,$tdom);
2613: $home = &Apache::lonnet::hostname($home);
2614: $twhere=&mt('User').': '.$trest.' '.&mt('Domain').
2615: ': '.$tdom.' '.&mt('Server').': '.$home;
2616: } elsif ($role eq 'au') {
2617: my $home = &Apache::lonnet::homeserver
2618: ($env{'user.name'},$env{'user.domain'});
2619: $home = &Apache::lonnet::hostname($home);
2620: $twhere=&mt('Domain').': '.$tdom.' '.&mt('Server').
2621: ': '.$home;
2622: } elsif ($trest) {
2623: my $tcourseid=$tdom.'_'.$trest;
2624: my $crstype = &Apache::loncommon::course_type($tcourseid);
2625: $trole = &Apache::lonnet::plaintext($role,$crstype,$tcourseid);
2626: if ($env{'course.'.$tcourseid.'.description'}) {
2627: $twhere=$env{'course.'.$tcourseid.'.description'};
2628: } else {
2629: my %newhash=&Apache::lonnet::coursedescription($tcourseid);
2630: if (%newhash) {
2631: $twhere=$newhash{'description'};
2632: } else {
2633: $twhere=&mt('Currently not available');
1.260 raeburn 2634: }
2635: }
1.279 raeburn 2636: if ($tsection) {
2637: $twhere.= ' '.&mt('Section').': '.$tsection;
1.260 raeburn 2638: }
1.279 raeburn 2639: if ($role ne 'st') {
2640: $twhere.= ' '.&mt('Domain').': '.$tdom;
1.260 raeburn 2641: }
1.279 raeburn 2642: } elsif ($tdom) {
2643: $twhere = &mt('Domain').': '.$tdom;
1.260 raeburn 2644: }
1.286 raeburn 2645: my $output;
2646: if ($trole) {
2647: $output = $trole;
2648: if ($twhere) {
2649: $output .= " -- $twhere";
2650: }
2651: if ($tremark) {
2652: $output .= '<br />'.$tremark;
2653: }
1.260 raeburn 2654: }
1.279 raeburn 2655: return $output;
1.260 raeburn 2656: }
2657:
2658: sub curr_role_status {
2659: my ($start,$end,$refresh,$update) = @_;
2660: if (($start) && ($start<0)) { return 'deleted' };
2661: my $status = 'active';
2662: if (($end) && ($end<=$update)) {
2663: $status = 'previous';
2664: }
2665: if (($start) && ($refresh<$start)) {
2666: $status = 'future';
2667: }
2668: return $status;
2669: }
2670:
2671: sub gather_roleprivs {
2672: my ($allroles,$allgroups,$userroles,$area,$role,$tstart,$tend,$status) = @_;
2673: return unless ((ref($allroles) eq 'HASH') && (ref($allgroups) eq 'HASH') && (ref($userroles) eq 'HASH'));
2674: if (($area ne '') && ($role ne '')) {
2675: &Apache::lonnet::userrolelog($role,$env{'user.name'},$env{'user.domain'},
2676: $area,$tstart,$tend);
2677: my $spec=$role.'.'.$area;
2678: $userroles->{'user.role.'.$spec} = $tstart.'.'.$tend;
2679: my ($tdummy,$tdomain,$trest)=split(/\//,$area);
2680: if ($status eq 'active') {
2681: if ($role =~ /^cr\//) {
2682: &Apache::lonnet::custom_roleprivs($allroles,$role,$tdomain,$trest,$spec,$area);
2683: } elsif ($role eq 'gr') {
2684: my %rolehash = &Apache::lonnet::get('roles',[$area.'_'.$role],
2685: $env{'user.domain'},
2686: $env{'user.name'});
2687: my ($trole) = split(/_/,$rolehash{$area.'_'.$role},2);
2688: (undef,my $group_privs) = split(/\//,$trole);
2689: $group_privs = &unescape($group_privs);
2690: &Apache::lonnet::group_roleprivs($allgroups,$area,$group_privs,$tend,$tstart);
2691: } else {
2692: &Apache::lonnet::standard_roleprivs($allroles,$role,$tdomain,$spec,$trest,$area);
2693: }
2694: }
2695: }
2696: return;
2697: }
2698:
2699: sub is_active_course {
2700: my ($rolekey,$refresh,$update,$roleshashref) = @_;
2701: return unless(ref($roleshashref) eq 'HASH');
2702: my ($role,$cdom,$cnum) = split(/\//,$rolekey);
2703: my $is_active;
2704: foreach my $key (keys(%{$roleshashref})) {
2705: if ($key =~ /^\Q$cnum\E:\Q$cdom\E:/) {
2706: my ($tstart,$tend) = split(/:/,$roleshashref->{$key});
2707: my $status = &curr_role_status($tstart,$tend,$refresh,$update);
2708: if ($status eq 'active') {
2709: $is_active = 1;
2710: last;
2711: }
2712: }
2713: }
2714: return $is_active;
2715: }
2716:
1.274 raeburn 2717: sub get_roles_functions {
2718: my ($rolescount) = @_;
2719: my @links;
2720: push(@links,["javascript:rolesView('doupdate');",'start-here-22x22',&mt('Check for changes')]);
2721: if ($env{'environment.canrequest.author'}) {
2722: unless (&Apache::loncoursequeueadmin::is_active_author()) {
2723: push(@links,["javascript:rolesView('requestauthor');",'list-add-22x22',&mt('Request author role')]);
2724: }
2725: }
1.279 raeburn 2726: if (($rolescount > 3) || ($env{'environment.recentroles'})) {
2727: push(@links,['/adm/preferences?action=changerolespref&returnurl=/adm/roles','role_hotlist-22x22',&mt('Hotlist')]);
2728: }
1.274 raeburn 2729: if (&Apache::lonmenu::check_for_rcrs()) {
2730: push(@links,['/adm/requestcourse','rcrs-22x22',&mt('Request course')]);
2731: }
2732: if ($env{'form.state'} eq 'queued') {
2733: push(@links,["javascript:rolesView('noqueued');",'selfenrl-queue-22x22',&mt('Hide queued')]);
2734: } else {
2735: push(@links,["javascript:rolesView('queued');",'selfenrl-queue-22x22',&mt('Show queued')]);
2736: }
1.279 raeburn 2737: if ($env{'user.adv'}) {
2738: if ($env{'form.display'} eq 'showall') {
1.290 raeburn 2739: push(@links,["javascript:rolesView('noshowall');",'edit-redo-22x22',&mt('Exclude expired')]);
1.279 raeburn 2740: } else {
1.290 raeburn 2741: push(@links,["javascript:rolesView('showall');",'edit-undo-22x22',&mt('Include expired')]);
1.279 raeburn 2742: }
1.274 raeburn 2743: }
1.290 raeburn 2744: if (&Apache::loncommon::designparm('login.coursecatalog',$env{'user.domain'})) {
1.291 raeburn 2745: push(@links,['/adm/coursecatalog','ccat-22x22',&mt('Course catalog')]);
1.290 raeburn 2746: }
1.274 raeburn 2747: my $funcs = &Apache::lonhtmlcommon::start_funclist();
2748: foreach my $link (@links) {
2749: $funcs .= &Apache::lonhtmlcommon::add_item_funclist(
2750: '<a href="'.$link->[0].'" class="LC_menubuttons_link">'.
2751: '<img src="/res/adm/pages/'.$link->[1].'.png" class="LC_icon" alt="'.$link->[2].'" />'.
2752: $link->[2].'</a>');
2753: }
2754: $funcs .= &Apache::lonhtmlcommon::end_funclist();
2755: return &Apache::loncommon::head_subbox($funcs);
2756: }
2757:
2758: sub get_queued {
2759: my ($output,%reqcrs);
2760: my ($types,$typenames) = &Apache::loncommon::course_types();
2761: my %statusinfo = &Apache::lonnet::dump('courserequests',$env{'user.domain'},
2762: $env{'user.name'},'^status:');
2763: foreach my $key (keys(%statusinfo)) {
2764: next unless (($statusinfo{$key} eq 'approval') || ($statusinfo{$key} eq 'pending'));
2765: (undef,my($cdom,$cnum)) = split(':',$key);
2766: my $requestkey = $cdom.'_'.$cnum;
2767: if ($requestkey =~ /^($match_domain)_($match_courseid)$/) {
2768: my %history = &Apache::lonnet::restore($requestkey,'courserequests',
2769: $env{'user.domain'},$env{'user.name'});
2770: next if ((exists($history{'status'})) && ($history{'status'} eq 'created'));
2771: my $reqtime = $history{'reqtime'};
2772: my $lastupdate = $history{'timestamp'};
2773: my $showtype = $history{'crstype'};
2774: if (defined($typenames->{$history{'crstype'}})) {
2775: $showtype = $typenames->{$history{'crstype'}};
2776: }
2777: my $description;
2778: if (ref($history{'details'}) eq 'HASH') {
2779: $description = $history{details}{'cdescr'};
2780: }
2781: @{$reqcrs{$reqtime}} = ($description,$showtype);
2782: }
2783: }
2784: my @sortedtimes = sort {$a <=> $b} (keys(%reqcrs));
2785: if (@sortedtimes > 0) {
2786: $output .= '<p><b>'.&mt('Course/Community requests').'</b><br />'.
2787: &Apache::loncommon::start_data_table().
2788: &Apache::loncommon::start_data_table_header_row().
2789: '<th>'.&mt('Date requested').'</th>'.
2790: '<th>'.&mt('Course title').'</th>'.
2791: '<th>'.&mt('Course type').'</th>';
2792: &Apache::loncommon::end_data_table_header_row();
2793: foreach my $reqtime (@sortedtimes) {
2794: next unless (ref($reqcrs{$reqtime}) eq 'ARRAY');
2795: $output .= &Apache::loncommon::start_data_table_row().
2796: '<td>'.&Apache::lonlocal::locallocaltime($reqtime).'</td>'.
2797: '<td>'.join('</td><td>',@{$reqcrs{$reqtime}}).'</td>'.
2798: &Apache::loncommon::end_data_table_row();
2799: }
2800: $output .= &Apache::loncommon::end_data_table().
2801: '<br /></p>';
2802: }
2803: my $queuedselfenroll = &Apache::loncoursequeueadmin::queued_selfenrollment(1);
2804: if ($queuedselfenroll) {
2805: $output .= '<p><b>'.&mt('Enrollment requests').'</b><br />'.
2806: $queuedselfenroll.'<br /></p>';
2807: }
2808: if ($env{'environment.canrequest.author'}) {
2809: unless (&Apache::loncoursequeueadmin::is_active_author()) {
2810: my $requestauthor;
2811: my ($status,$timestamp) = split(/:/,$env{'environment.requestauthorqueued'});
2812: if (($status eq 'approval') || ($status eq 'approved')) {
2813: $output .= '<p><b>'.&mt('Author role request').'</b><br />';
2814: if ($status eq 'approval') {
1.294 bisitz 2815: $output .= &mt('A request for Authoring Space submitted on [_1] is awaiting approval',
1.274 raeburn 2816: &Apache::lonlocal::locallocaltime($timestamp));
2817: } elsif ($status eq 'approved') {
2818: my %roleshash =
2819: &Apache::lonnet::get_my_roles($env{'user.name'},$env{'user.domain'},'userroles',
2820: ['active'],['au'],[$env{'user.domain'}]);
2821: if (keys(%roleshash)) {
2822: $output .= '<span class="LC_info">'.
2823: &mt('Your request for an author role has been approved.').'<br />'.
2824: &mt('Use the "Check for changes" link to update your list of roles.').
2825: '</span>';
2826: }
2827: }
2828: $output .= '</p>';
2829: }
2830: }
2831: }
2832: unless ($output) {
2833: if ($env{'environment.canrequest.author'} || $env{'environment.canrequest.official'} ||
2834: $env{'environment.canrequest.unofficial'} || $env{'environment.canrequest.community'}) {
2835: $output = &mt('No requests for courses, communities or authoring currently queued');
2836: } else {
2837: $output = &mt('No enrollment requests currently queued awaiting approval');
2838: }
2839: }
2840: return '<div class="LC_left_float"><fieldset><legend>'.&mt('Queued requests').'</legend>'.
2841: $output.'</fieldset></div><br clear="all" />';
2842: }
2843:
1.1 harris41 2844: 1;
2845: __END__
1.32 harris41 2846:
2847: =head1 NAME
2848:
2849: Apache::lonroles - User Roles Screen
2850:
2851: =head1 SYNOPSIS
2852:
2853: Invoked by /etc/httpd/conf/srm.conf:
2854:
2855: <Location /adm/roles>
2856: PerlAccessHandler Apache::lonacc
2857: SetHandler perl-script
2858: PerlHandler Apache::lonroles
2859: ErrorDocument 403 /adm/login
2860: ErrorDocument 500 /adm/errorhandler
2861: </Location>
1.64 bowersj2 2862:
2863: =head1 OVERVIEW
2864:
2865: =head2 Choosing Roles
2866:
2867: C<lonroles> is a handler that allows a user to switch roles in
2868: mid-session. LON-CAPA attempts to work with "No Role Specified", the
2869: default role that a user has before selecting a role, as widely as
2870: possible, but certain handlers for example need specification which
2871: course they should act on, etc. Both in this scenario, and when the
2872: handler determines via C<lonnet>'s C<&allowed> function that a certain
2873: action is not allowed, C<lonroles> is used as error handler. This
2874: allows the user to select another role which may have permission to do
1.246 droeschl 2875: what they were trying to do.
1.64 bowersj2 2876:
2877: =begin latex
2878:
2879: \begin{figure}
2880: \begin{center}
2881: \includegraphics[width=0.45\paperwidth,keepaspectratio]{Sample_Roles_Screen}
2882: \caption{\label{Sample_Roles_Screen}Sample Roles Screen}
2883: \end{center}
2884: \end{figure}
2885:
2886: =end latex
2887:
2888: =head2 Role Initialization
2889:
2890: 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 2891:
2892: =head1 INTRODUCTION
2893:
2894: This module enables a user to select what role he wishes to
2895: operate under (instructor, student, teaching assistant, course
2896: coordinator, etc). These roles are pre-established by the actions
2897: of upper-level users.
2898:
2899: This is part of the LearningOnline Network with CAPA project
2900: described at http://www.lon-capa.org.
2901:
2902: =head1 HANDLER SUBROUTINE
2903:
2904: This routine is called by Apache and mod_perl.
2905:
2906: =over 4
2907:
2908: =item *
2909:
2910: Roles Initialization (yes/no)
2911:
2912: =item *
2913:
2914: Get Error Message from Environment
2915:
2916: =item *
2917:
2918: Who is this?
2919:
2920: =item *
2921:
2922: Generate Page Output
2923:
2924: =item *
2925:
2926: Choice or no choice
2927:
2928: =item *
2929:
2930: Table
2931:
2932: =item *
2933:
2934: Privileges
2935:
2936: =back
2937:
2938: =cut
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>