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