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