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