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