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