Annotation of loncom/auth/lonroles.pm, revision 1.256
1.1 harris41 1: # The LearningOnline Network with CAPA
2: # User Roles Screen
1.31 www 3: #
1.255 raeburn 4: # $Id: lonroles.pm,v 1.254 2010/07/26 21:52:15 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'};
206: if (!$refresh) {
207: $refresh = $then;
208: }
1.6 www 209: my $envkey;
1.107 raeburn 210: my %dcroles = ();
211: my $numdc = &check_fordc(\%dcroles,$then);
1.148 albertel 212: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'});
1.255 raeburn 213: my $loncaparev = $Apache::lonnet::perlvar{'lonVersion'};
1.10 www 214:
1.6 www 215: # ================================================================== Roles Init
1.118 albertel 216: if ($env{'form.selectrole'}) {
1.188 www 217:
218: my $locknum=&Apache::lonnet::get_locks();
219: if ($locknum) { return 409; }
220:
1.134 www 221: if ($env{'form.newrole'}) {
222: $env{'form.'.$env{'form.newrole'}}=1;
223: }
1.118 albertel 224: if ($env{'request.course.id'}) {
1.185 raeburn 225: # Check if user is CC trying to select a course role
226: if ($env{'form.switchrole'}) {
1.252 raeburn 227: my $switch_is_active;
228: if (defined($env{'user.role.'.$env{'form.switchrole'}})) {
229: my ($start,$end) = split(/\./,$env{'user.role.'.$env{'form.switchrole'}});
230: if (!$end || $end > $now) {
231: if (!$start || $start < $refresh) {
232: $switch_is_active = 1;
233: }
234: }
235: }
236: unless ($switch_is_active) {
1.232 raeburn 237: &adhoc_course_role($refresh,$then);
1.185 raeburn 238: }
239: }
1.118 albertel 240: my %temp=('logout_'.$env{'request.course.id'} => time);
1.33 www 241: &Apache::lonnet::put('email_status',\%temp);
1.118 albertel 242: &Apache::lonnet::delenv('user.state.'.$env{'request.course.id'});
1.100 albertel 243: }
1.186 raeburn 244: &Apache::lonnet::appenv({"request.course.id" => '',
245: "request.course.fn" => '',
246: "request.course.uri" => '',
247: "request.course.sec" => '',
248: "request.role" => 'cm',
249: "request.role.adv" => $env{'user.adv'},
250: "request.role.domain" => $env{'user.domain'}});
1.182 www 251: # Check if user is a DC trying to enter a course or author space and needs privs to be created
1.107 raeburn 252: if ($numdc > 0) {
1.118 albertel 253: foreach my $envkey (keys %env) {
1.240 raeburn 254: # Is this an ad-hoc Coordinator role?
255: if (my ($ccrole,$domain,$coursenum) =
256: ($envkey =~ m-^form\.(cc|co)\./($match_domain)/($match_courseid)$-)) {
1.146 raeburn 257: if ($dcroles{$domain}) {
1.218 raeburn 258: &Apache::lonnet::check_adhoc_privs($domain,$coursenum,
1.240 raeburn 259: $then,$refresh,$now,$ccrole);
1.182 www 260: }
261: last;
262: }
1.193 raeburn 263: # Is this an ad-hoc CA-role?
1.183 www 264: if (my ($domain,$user) =
265: ($envkey =~ m-^form\.ca\./($match_domain)/($match_username)$-)) {
1.206 raeburn 266: if (($domain eq $env{'user.domain'}) && ($user eq $env{'user.name'})) {
267: delete($env{$envkey});
268: $env{'form.au./'.$domain.'/'} = 1;
269: my ($server_status,$home) = &check_author_homeserver($user,$domain);
270: if ($server_status eq 'switchserver') {
271: my $trolecode = 'au./'.$domain.'/';
1.248 raeburn 272: my $switchserver = '/adm/switchserver?otherserver='.$home.'&role='.$trolecode;
1.206 raeburn 273: $r->internal_redirect($switchserver);
274: }
275: last;
276: }
277: if (my ($castart,$caend) = ($env{'user.role.ca./'.$domain.'/'.$user} =~ /^(\d*)\.(\d*)$/)) {
278: if (((($castart) && ($castart < $now)) || !$castart) &&
279: ((!$caend) || (($caend) && ($caend > $now)))) {
280: my ($server_status,$home) = &check_author_homeserver($user,$domain);
281: if ($server_status eq 'switchserver') {
282: my $trolecode = 'ca./'.$domain.'/'.$user;
1.248 raeburn 283: my $switchserver = '/adm/switchserver?otherserver='.$home.'&role='.$trolecode;
1.206 raeburn 284: $r->internal_redirect($switchserver);
285: }
286: last;
287: }
288: }
289: # Check if author blocked ca-access
1.190 www 290: my %blocked=&Apache::lonnet::get('environment',['domcoord.author'],$domain,$user);
291: if ($blocked{'domcoord.author'} eq 'blocked') {
1.206 raeburn 292: delete($env{$envkey});
293: $env{'user.error.msg'}=':::1:User '.$user.' in domain '.$domain.' blocked domain coordinator access';
294: last;
1.190 www 295: }
1.193 raeburn 296: if ($dcroles{$domain}) {
297: my ($server_status,$home) = &check_author_homeserver($user,$domain);
298: if (($server_status eq 'ok') || ($server_status eq 'switchserver')) {
1.218 raeburn 299: &Apache::lonnet::check_adhoc_privs($domain,$user,$then,
1.230 raeburn 300: $refresh,$now,'ca');
1.193 raeburn 301: if ($server_status eq 'switchserver') {
302: my $trolecode = 'ca./'.$domain.'/'.$user;
303: my $switchserver = '/adm/switchserver?'
1.248 raeburn 304: .'otherserver='.$home.'&role='.$trolecode;
1.193 raeburn 305: $r->internal_redirect($switchserver);
306: }
307: } else {
308: delete($env{$envkey});
309: }
1.183 www 310: } else {
311: delete($env{$envkey});
1.182 www 312: }
313: last;
314: }
1.107 raeburn 315: }
316: }
317:
1.118 albertel 318: foreach $envkey (keys %env) {
1.40 matthew 319: next if ($envkey!~/^user\.role\./);
1.102 raeburn 320: my ($where,$trolecode,$role,$tstatus,$tend,$tstart);
1.226 raeburn 321: &Apache::lonnet::role_status($envkey,$then,$refresh,$now,\$role,\$where,
1.218 raeburn 322: \$trolecode,\$tstatus,\$tstart,\$tend);
1.118 albertel 323: if ($env{'form.'.$trolecode}) {
1.55 albertel 324: if ($tstatus eq 'is') {
325: $where=~s/^\///;
326: my ($cdom,$cnum,$csec)=split(/\//,$where);
1.255 raeburn 327: if (($cnum) && ($role ne 'ca') && ($role ne 'aa')) {
328: my $home = $env{'course.'.$cdom.'_'.$cnum.'.home'};
329: my @ids = &Apache::lonnet::current_machine_ids();
330: unless ($loncaparev eq '' && $home && grep(/^\Q$home\E$/,@ids)) {
331: my %curr_reqd_hash = &Apache::lonnet::userenvironment($cdom,$cnum,'internal.releaserequired');
1.256 ! raeburn 332: if ($curr_reqd_hash{'internal.releaserequired'} ne '') {
1.255 raeburn 333: my ($switchserver,$switchwarning) =
334: &check_release_required($loncaparev,$cdom.'_'.$cnum,$trolecode,$curr_reqd_hash{'internal.releaserequired'});
1.256 ! raeburn 335: if ($switchwarning ne '' || $switchserver ne '') {
! 336: &Apache::loncommon::content_type($r,'text/html');
! 337: &Apache::loncommon::no_cache($r);
! 338: $r->send_http_header;
! 339: my $end_page=&Apache::loncommon::end_page();
! 340: $r->print(&Apache::loncommon::start_page('Selected course unavailable on this server').
! 341: '<p class="LC_warning">');
! 342: if ($switchwarning) {
! 343: $r->print($switchwarning.'<br /><a href="/adm/roles">');
! 344: if (&Apache::loncommon::show_course()) {
! 345: $r->print(&mt('Display courses'));
! 346: } else {
! 347: $r->print(&mt('Display roles'));
! 348: }
! 349: $r->print('</a>');
! 350: } elsif ($switchserver) {
! 351: $r->print(&mt('This course requires a newer version of LON-CAPA than is installed on this server.').
! 352: '<br />'.
! 353: '<a href="/adm/switchserver?'.$switchserver.'">'.
! 354: &mt('Switch Server').
! 355: '</a>');
1.255 raeburn 356: }
1.256 ! raeburn 357: $r->print('</p>'.&Apache::loncommon::end_page());
! 358: return OK;
1.255 raeburn 359: }
360: }
361: }
362: }
1.137 raeburn 363: # check for course groups
364: my %coursegroups = &Apache::lonnet::get_active_groups(
365: $env{'user.domain'},$env{'user.name'},$cdom, $cnum);
366: my $cgrps = join(':',keys(%coursegroups));
367:
1.111 albertel 368: # store role if recent_role list being kept
1.118 albertel 369: if ($env{'environment.recentroles'}) {
1.158 albertel 370: my %frozen_roles =
371: &Apache::lonhtmlcommon::get_recent_frozen('roles',$env{'environment.recentrolesn'});
1.111 albertel 372: &Apache::lonhtmlcommon::store_recent('roles',
1.158 albertel 373: $trolecode,' ',$frozen_roles{$trolecode});
1.111 albertel 374: }
375:
376:
1.53 www 377: # check for keyed access
1.55 albertel 378: if (($role eq 'st') &&
1.118 albertel 379: ($env{'course.'.$cdom.'_'.$cnum.'.keyaccess'} eq 'yes')) {
1.89 www 380: # who is key authority?
381: my $authdom=$cdom;
382: my $authnum=$cnum;
1.118 albertel 383: if ($env{'course.'.$cdom.'_'.$cnum.'.keyauth'}) {
1.89 www 384: ($authnum,$authdom)=
1.172 albertel 385: split(/:/,$env{'course.'.$cdom.'_'.$cnum.'.keyauth'});
1.89 www 386: }
387: # check with key authority
388: unless (&Apache::lonnet::validate_access_key(
1.118 albertel 389: $env{'environment.key.'.$cdom.'_'.$cnum},
1.89 www 390: $authdom,$authnum)) {
1.53 www 391: # there is no valid key
1.118 albertel 392: if ($env{'form.newkey'}) {
1.53 www 393: # student attempts to register a new key
1.89 www 394: &Apache::loncommon::content_type($r,'text/html');
395: &Apache::loncommon::no_cache($r);
396: $r->send_http_header;
397: my $swinfo=&Apache::lonmenu::rawconfig();
1.147 albertel 398: my $start_page=&Apache::loncommon::start_page
1.89 www 399: ('Verifying Access Key to Unlock this Course');
1.147 albertel 400: my $end_page=&Apache::loncommon::end_page();
1.90 www 401: my $buttontext=&mt('Enter Course');
402: my $message=&mt('Successfully registered key');
403: my $assignresult=
404: &Apache::lonnet::assign_access_key(
1.118 albertel 405: $env{'form.newkey'},
1.90 www 406: $authdom,$authnum,
1.91 www 407: $cdom,$cnum,
1.118 albertel 408: $env{'user.domain'},
409: $env{'user.name'},
1.204 bisitz 410: &mt('Assigned from [_1] at [_2] for [_3]'
411: ,$ENV{'REMOTE_ADDR'}
412: ,&Apache::lonlocal::locallocaltime()
413: ,$trolecode)
414: );
1.90 www 415: unless ($assignresult eq 'ok') {
416: $assignresult=~s/^error\:\s*//;
417: $message=&mt($assignresult).
418: '<br /><a href="/adm/logout">'.
1.89 www 419: &mt('Logout').'</a>';
1.90 www 420: $buttontext=&mt('Re-Enter Key');
421: }
1.89 www 422: $r->print(<<ENDENTEREDKEY);
1.147 albertel 423: $start_page
1.179 raeburn 424: <script type="text/javascript">
1.225 bisitz 425: // <![CDATA[
1.89 www 426: $swinfo
1.225 bisitz 427: // ]]>
1.89 www 428: </script>
1.225 bisitz 429: <form action="" method="post">
1.89 www 430: <input type="hidden" name="selectrole" value="1" />
431: <input type="hidden" name="$trolecode" value="1" />
1.211 tempelho 432: <span class="LC_fontsize_large">$message</span><br />
1.89 www 433: <input type="submit" value="$buttontext" />
434: </form>
1.147 albertel 435: $end_page
1.89 www 436: ENDENTEREDKEY
437: return OK;
1.55 albertel 438: } else {
1.53 www 439: # print form to enter a new key
1.73 www 440: &Apache::loncommon::content_type($r,'text/html');
1.55 albertel 441: &Apache::loncommon::no_cache($r);
442: $r->send_http_header;
443: my $swinfo=&Apache::lonmenu::rawconfig();
1.147 albertel 444: my $start_page=&Apache::loncommon::start_page
1.55 albertel 445: ('Enter Access Key to Unlock this Course');
1.147 albertel 446: my $end_page=&Apache::loncommon::end_page();
1.55 albertel 447: $r->print(<<ENDENTERKEY);
1.147 albertel 448: $start_page
1.179 raeburn 449: <script type="text/javascript">
1.225 bisitz 450: // <![CDATA[
1.53 www 451: $swinfo
1.225 bisitz 452: // ]]>
1.53 www 453: </script>
1.225 bisitz 454: <form action="" method="post">
1.89 www 455: <input type="hidden" name="selectrole" value="1" />
456: <input type="hidden" name="$trolecode" value="1" />
1.118 albertel 457: <input type="text" size="20" name="newkey" value="$env{'form.newkey'}" />
1.53 www 458: <input type="submit" value="Enter key" />
459: </form>
1.147 albertel 460: $end_page
1.53 www 461: ENDENTERKEY
1.55 albertel 462: return OK;
463: }
464: }
465: }
1.118 albertel 466: &Apache::lonnet::log($env{'user.domain'},
467: $env{'user.name'},
468: $env{'user.home'},
1.87 www 469: "Role ".$trolecode);
1.101 albertel 470:
1.56 www 471: &Apache::lonnet::appenv(
1.186 raeburn 472: {'request.role' => $trolecode,
473: 'request.role.domain' => $cdom,
474: 'request.course.sec' => $csec,
475: 'request.course.groups' => $cgrps});
1.101 albertel 476: my $tadv=0;
1.62 matthew 477:
1.125 www 478: if (($cnum) && ($role ne 'ca') && ($role ne 'aa')) {
1.152 raeburn 479: my $msg;
1.55 albertel 480: my ($furl,$ferr)=
481: &Apache::lonuserstate::readmap($cdom.'/'.$cnum);
1.118 albertel 482: if (($env{'form.orgurl'}) &&
483: ($env{'form.orgurl'}!~/^\/adm\/flip/)) {
484: my $dest=$env{'form.orgurl'};
1.219 raeburn 485: if ($env{'form.symb'}) {
486: if ($dest =~ /\?/) {
487: $dest .= '&';
488: } else {
489: $dest .= '?'
490: }
491: $dest .= 'symb='.$env{'form.symb'};
492: }
1.117 albertel 493: if (&Apache::lonnet::allowed('adv') eq 'F') { $tadv=1; }
1.186 raeburn 494: &Apache::lonnet::appenv({'request.role.adv'=>$tadv});
1.150 www 495: if (($ferr) && ($tadv)) {
496: &error_page($r,$ferr,$dest);
497: } else {
1.255 raeburn 498: if ($dest =~ m{^/adm/coursedocs\?folderpath}) {
499: if ($env{'request.course.id'} eq $cdom.'_'.$cnum) {
500: my $chome = &Apache::lonnet::homeserver($cnum,$cdom);
501: &update_content_constraints($cdom,$cnum,$chome,$cdom.'_'.$cnum);
502: }
503: }
1.150 www 504: $r->internal_redirect($dest);
505: }
1.55 albertel 506: return OK;
507: } else {
1.155 albertel 508: if (!$env{'request.course.id'}) {
1.55 albertel 509: &Apache::lonnet::appenv(
1.186 raeburn 510: {"request.course.id" => $cdom.'_'.$cnum});
1.61 www 511: $furl='/adm/roles?tryagain=1';
1.221 bisitz 512: $msg='<p><span class="LC_error">'
513: .&mt('Could not initialize [_1] at this time.',
514: $env{'course.'.$cdom.'_'.$cnum.'.description'})
515: .'</span></p>'
516: .'<p>'.&mt('Please try again.').'</p>'
517: .'<p>'.$ferr.'</p>';
1.55 albertel 518: }
1.117 albertel 519: if (&Apache::lonnet::allowed('adv') eq 'F') { $tadv=1; }
1.186 raeburn 520: &Apache::lonnet::appenv({'request.role.adv'=>$tadv});
1.152 raeburn 521:
1.150 www 522: if (($ferr) && ($tadv)) {
523: &error_page($r,$ferr,$furl);
524: } else {
525: # Check to see if the user is a CC entering a course
526: # for the first time
527: my (undef, undef, $role, $courseid) = split(/\./, $envkey);
528: if (substr($courseid, 0, 1) eq '/') {
529: $courseid = substr($courseid, 1);
530: }
531: $courseid =~ s/\//_/;
1.240 raeburn 532: if ((($role eq 'cc') || ($role eq 'co'))
533: && ($env{'course.' . $courseid .'.course.helper.not.run'})) {
1.150 www 534: $furl = "/adm/helper/course.initialization.helper";
535: # Send the user to the course they selected
536: } elsif ($env{'request.course.id'}) {
1.185 raeburn 537: if ($env{'form.destinationurl'}) {
538: my $dest = $env{'form.destinationurl'};
1.203 raeburn 539: if ($env{'form.destsymb'} ne '') {
540: my $esc_symb = &HTML::Entities::encode($env{'form.destsymb'},'"<>&');
541: $dest .= '?symb='.$esc_symb;
542: }
1.245 droeschl 543: &redirect_user($r, &mt('Entering [_1]',
544: $env{'course.'.$courseid.'.description'}),
545: $dest, $msg);
1.185 raeburn 546: return OK;
547: }
1.150 www 548: if (&Apache::lonnet::allowed('whn',
549: $env{'request.course.id'})
550: || &Apache::lonnet::allowed('whn',
551: $env{'request.course.id'}.'/'
552: .$env{'request.course.sec'})
553: ) {
554: my $startpage = &courseloadpage($courseid);
555: unless ($startpage eq 'firstres') {
1.204 bisitz 556: $msg = &mt('Entering [_1] ...',
1.162 albertel 557: $env{'course.'.$courseid.'.description'});
1.245 droeschl 558: &redirect_user($r, &mt('New in course'),
559: '/adm/whatsnew?refpage=start', $msg);
1.150 www 560: return OK;
561: }
562: }
563: }
1.151 www 564: # Are we allowed to look at the first resource?
1.169 albertel 565: if ($furl !~ m|^/adm/|) {
1.151 www 566: # Guess not ...
567: $furl=&Apache::lonpageflip::first_accessible_resource();
568: }
1.162 albertel 569: $msg = &mt('Entering [_1] ...',
570: $env{'course.'.$courseid.'.description'});
1.245 droeschl 571: &redirect_user($r, &mt('Entering [_1]',
572: $env{'course.'.$courseid.'.description'}),
573: $furl, $msg);
1.58 bowersj2 574: }
1.124 albertel 575: return OK;
1.55 albertel 576: }
577: }
1.62 matthew 578: #
579: # Send the user to the construction space they selected
1.125 www 580: if ($role =~ /^(au|ca|aa)$/) {
1.62 matthew 581: my $redirect_url = '/priv/';
582: if ($role eq 'au') {
1.118 albertel 583: $redirect_url.=$env{'user.name'};
1.62 matthew 584: } else {
585: $where =~ /\/(.*)$/;
586: $redirect_url .= $1;
587: }
588: $redirect_url .= '/';
1.78 sakharuk 589: &redirect_user($r,&mt('Entering Construction Space'),
1.62 matthew 590: $redirect_url);
591: return OK;
592: }
1.104 raeburn 593: if ($role eq 'dc') {
1.108 raeburn 594: my $redirect_url = '/adm/menu/';
595: &redirect_user($r,&mt('Loading Domain Coordinator Menu'),
1.104 raeburn 596: $redirect_url);
1.108 raeburn 597: return OK;
1.104 raeburn 598: }
1.220 raeburn 599: if ($role eq 'sc') {
600: my $redirect_url = '/adm/grades?command=scantronupload';
601: &redirect_user($r,&mt('Loading Data Upload Page'),
602: $redirect_url);
603: return OK;
604: }
1.55 albertel 605: }
606: }
1.6 www 607: }
1.40 matthew 608: }
1.44 www 609:
1.10 www 610:
1.6 www 611: # =============================================================== No Roles Init
1.10 www 612:
1.73 www 613: &Apache::loncommon::content_type($r,'text/html');
1.30 albertel 614: &Apache::loncommon::no_cache($r);
1.10 www 615: $r->send_http_header;
616: return OK if $r->header_only;
617:
1.224 raeburn 618: my $crumbtext = 'User Roles';
619: my $pagetitle = 'My Roles';
620: my $recent = &mt('Recent Roles');
621: my $show_course=&Apache::loncommon::show_course();
622: if ($show_course) {
623: $crumbtext = 'Courses';
624: $pagetitle = 'My Courses';
625: $recent = &mt('Recent Courses');
626: }
627: my $brcrum =[{href=>"/adm/roles",text=>$crumbtext}];
1.52 www 628: my $swinfo=&Apache::lonmenu::rawconfig();
1.224 raeburn 629: my $start_page=&Apache::loncommon::start_page($pagetitle,undef,{bread_crumbs=>$brcrum});
1.134 www 630: my $standby=&mt('Role selected. Please stand by.');
1.135 albertel 631: $standby=~s/\n/\\n/g;
1.184 raeburn 632: my $noscript='<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 633:
1.10 www 634: $r->print(<<ENDHEADER);
1.147 albertel 635: $start_page
1.163 www 636: <br />
1.179 raeburn 637: <noscript>
638: $noscript
639: </noscript>
640: <script type="text/javascript">
1.225 bisitz 641: // <![CDATA[
1.26 www 642: $swinfo
643: window.focus();
1.134 www 644:
645: active=true;
646:
647: function enterrole (thisform,rolecode,buttonname) {
648: if (active) {
649: active=false;
650: document.title='$standby';
651: window.status='$standby';
652: thisform.newrole.value=rolecode;
653: thisform.submit();
654: } else {
655: alert('$standby');
656: }
657: }
1.225 bisitz 658: // ]]>
1.26 www 659: </script>
1.10 www 660: ENDHEADER
1.6 www 661:
1.2 www 662: # ------------------------------------------ Get Error Message from Environment
663:
1.118 albertel 664: my ($fn,$priv,$nochoose,$error,$msg)=split(/:/,$env{'user.error.msg'});
665: if ($env{'user.error.msg'}) {
1.55 albertel 666: $r->log_reason(
1.118 albertel 667: "$msg for $env{'user.name'} domain $env{'user.domain'} access $priv",$fn);
1.12 www 668: }
1.1 harris41 669:
1.61 www 670: # ------------------------------------------------- Can this user re-init, etc?
1.6 www 671:
1.118 albertel 672: my $advanced=$env{'user.adv'};
1.61 www 673: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['tryagain']);
1.118 albertel 674: my $tryagain=$env{'form.tryagain'};
1.209 raeburn 675: my $reinit=$env{'user.reinit'};
676: delete $env{'user.reinit'};
1.6 www 677:
1.2 www 678: # -------------------------------------------------------- Generate Page Output
1.6 www 679: # --------------------------------------------------------------- Error Header?
1.2 www 680: if ($error) {
1.187 bisitz 681: $r->print("<h1>".&mt('LON-CAPA Access Control')."</h1>");
1.174 albertel 682: $r->print("<!-- LONCAPAACCESSCONTROLERRORSCREEN --><hr /><pre>");
683: if ($priv ne '') {
1.187 bisitz 684: $r->print(&mt('Access : ').&Apache::lonnet::plaintext($priv)."\n");
1.174 albertel 685: }
686: if ($fn ne '') {
1.187 bisitz 687: $r->print(&mt('Resource: ').&Apache::lonenc::check_encrypt($fn)."\n");
1.174 albertel 688: }
689: if ($msg ne '') {
1.187 bisitz 690: $r->print(&mt('Action : ').$msg."\n");
1.174 albertel 691: }
692: $r->print("</pre><hr />");
1.120 albertel 693: my $url=$fn;
694: my $last;
695: if (tie(my %hash,'GDBM_File',$env{'request.course.fn'}.'_symb.db',
696: &GDBM_READER(),0640)) {
697: $last=$hash{'last_known'};
698: untie(%hash);
699: }
1.149 www 700: if ($last) { $fn.='?symb='.&escape($last); }
1.120 albertel 701:
702: &Apache::londocs::changewarning($r,undef,'You have modified your course recently, [_1] may fix this access problem.',
703: &Apache::lonenc::check_encrypt($fn));
1.2 www 704: } else {
1.118 albertel 705: if ($env{'user.error.msg'}) {
1.209 raeburn 706: if ($reinit) {
707: $r->print(
708: '<h3><span class="LC_error">'.
1.234 raeburn 709: &mt('As your session file for the course or community has expired, you will need to re-select it.').'</span></h3>');
1.209 raeburn 710: } else {
711: $r->print(
1.157 albertel 712: '<h3><span class="LC_error">'.
1.235 bisitz 713: &mt('You need to choose another user role or enter a specific course or community for this function.').
714: '</span></h3>');
1.209 raeburn 715: }
716: }
1.2 www 717: }
1.6 www 718: # -------------------------------------------------------- Choice or no choice?
1.2 www 719: if ($nochoose) {
1.177 www 720: $r->print("<h2>".&mt('Sorry ...')."</h2>\n<span class='LC_error'>".
721: &mt('This action is currently not authorized.').'</span>'.
1.150 www 722: &Apache::loncommon::end_page());
723: return OK;
1.6 www 724: } else {
1.18 www 725: if (($ENV{'REDIRECT_QUERY_STRING'}) && ($fn)) {
726: $fn.='?'.$ENV{'REDIRECT_QUERY_STRING'};
1.6 www 727: }
1.84 www 728: $r->print('<form method="post" name="rolechoice" action="'.(($fn)?$fn:$r->uri).'">');
1.116 albertel 729: $r->print('<input type="hidden" name="orgurl" value="'.$fn.'" />');
730: $r->print('<input type="hidden" name="selectrole" value="1" />');
1.134 www 731: $r->print('<input type="hidden" name="newrole" value="" />');
1.6 www 732: }
1.226 raeburn 733:
734: my (%roletext,%sortrole,%roleclass,%futureroles,%timezones);
735: my ($countactive,$countfuture,$inrole,$possiblerole) =
736: &gather_roles($then,$refresh,$now,$reinit,$nochoose,\%roletext,\%sortrole,\%roleclass,
1.254 raeburn 737: \%futureroles,\%timezones,$loncaparev);
1.226 raeburn 738:
739: $refresh = $now;
740: &Apache::lonnet::appenv({'user.refresh.time' => $refresh});
1.196 raeburn 741: if ($env{'user.adv'}) {
1.238 bisitz 742: $r->print('<p><label><input type="checkbox" name="showall"');
1.196 raeburn 743: if ($env{'form.showall'}) { $r->print(' checked="checked" '); }
1.238 bisitz 744: $r->print(' />'.&mt('Show all roles').'</label>'
745: .' <input type="submit" value="'.&mt('Update display').'" />'
746: .'</p>');
1.196 raeburn 747: } else {
748: if ($countactive > 0) {
1.241 raeburn 749: $r->print(&Apache::loncoursequeueadmin::queued_selfenrollment());
1.196 raeburn 750: my $domdesc = &Apache::lonnet::domain($env{'user.domain'},'description');
1.201 raeburn 751: my $esc_dom = &HTML::Entities::encode($env{'user.domain'},'"<>&');
1.233 bisitz 752: $r->print(
753: '<p>'
754: .&mt('[_1]Visit the [_2]Course/Community Catalog[_3]'
755: .' to view all [_4] LON-CAPA courses and communities.'
756: ,'<b>'
757: ,'<a href="/adm/coursecatalog?showdom='.$esc_dom.'">'
758: ,'</a></b>',$domdesc)
759: .'<br />'
1.235 bisitz 760: .&mt('If a course or community is [_1]not[_2] in your list of current courses and communities below,'
1.233 bisitz 761: .' you may be able to enroll if self-enrollment is permitted.'
762: ,'<b>','</b>')
763: .'</p>'
764: );
1.196 raeburn 765: }
766: }
767:
1.84 www 768: # No active roles
769: if ($countactive==0) {
770: if ($inrole) {
1.234 raeburn 771: $r->print('<h2>'.&mt('Currently no additional roles, courses or communities').'</h2>');
1.84 www 772: } else {
1.234 raeburn 773: $r->print('<h2>'.&mt('Currently no active roles, courses or communities').'</h2>');
1.84 www 774: }
1.191 raeburn 775: &findcourse_advice($r);
1.234 raeburn 776: &requestcourse_advice($r);
1.191 raeburn 777: $r->print('</form>');
778: if ($countfuture) {
779: $r->print(&mt('The following [quant,_1,role,roles] will become active in the future:',$countfuture));
780: my $doheaders = &roletable_headers($r,\%roleclass,\%sortrole,
781: $nochoose);
782: &print_rolerows($r,$doheaders,\%roleclass,\%sortrole,\%dcroles,
783: \%roletext);
784: my $tremark='';
1.212 bisitz 785: my $tbg;
1.191 raeburn 786: if ($env{'request.role'} eq 'cm') {
1.212 bisitz 787: $tbg="LC_roles_selected";
1.204 bisitz 788: $tremark=&mt('Currently selected.').' ';
1.191 raeburn 789: } else {
1.212 bisitz 790: $tbg="LC_roles_is";
1.191 raeburn 791: }
1.212 bisitz 792: $r->print(&Apache::loncommon::start_data_table_row()
793: .'<td class="'.$tbg.'"> </td>'
794: .'<td colspan="3">'
795: .&mt('No role specified')
796: .'</td>'
797: .'<td>'.$tremark.' </td>'
798: .&Apache::loncommon::end_data_table_row()
799: );
1.191 raeburn 800:
1.212 bisitz 801: $r->print(&Apache::loncommon::end_data_table());
1.191 raeburn 802: }
803: $r->print(&Apache::loncommon::end_page());
1.84 www 804: return OK;
805: }
806: # ----------------------------------------------------------------------- Table
1.247 raeburn 807:
808: if ($numdc > 0) {
809: $r->print(&coursepick_jscript());
810: $r->print(&Apache::loncommon::coursebrowser_javascript().
811: &Apache::loncommon::authorbrowser_javascript());
812: }
813:
1.224 raeburn 814: unless ((!&Apache::loncommon::show_course()) || ($nochoose) || ($countactive==1)) {
1.173 albertel 815: $r->print("<h2>".&mt('Select a Course to Enter')."</h2>\n");
1.84 www 816: }
1.229 raeburn 817: if ($env{'form.destinationurl'}) {
818: $r->print('<input type="hidden" name="destinationurl" value="'.
819: $env{'form.destinationurl'}.'" />');
820: if ($env{'form.destsymb'} ne '') {
821: $r->print('<input type="hidden" name="destsymb" value="'.
822: $env{'form.destsymb'}.'" />');
823: }
824: }
1.247 raeburn 825:
1.191 raeburn 826: my $doheaders = &roletable_headers($r,\%roleclass,\%sortrole,$nochoose);
1.118 albertel 827: if ($env{'environment.recentroles'}) {
1.111 albertel 828: my %recent_roles =
1.118 albertel 829: &Apache::lonhtmlcommon::get_recent('roles',$env{'environment.recentrolesn'});
1.111 albertel 830: my $output='';
1.247 raeburn 831: foreach my $role (sort(keys(%recent_roles))) {
832: if (ref($roletext{'user.role.'.$role}) eq 'ARRAY') {
1.223 raeburn 833: $output.= &Apache::loncommon::start_data_table_row().
1.247 raeburn 834: $roletext{'user.role.'.$role}->[0].
1.223 raeburn 835: &Apache::loncommon::end_data_table_row();
1.249 raeburn 836: if ($roletext{'user.role.'.$role}->[1] ne '') {
837: $output .= &Apache::loncommon::continue_data_table_row().
838: $roletext{'user.role.'.$role}->[1].
839: &Apache::loncommon::end_data_table_row();
840: }
1.247 raeburn 841: if ($role =~ m{dc\./($match_domain)/}
1.170 albertel 842: && $dcroles{$1}) {
1.192 raeburn 843: $output .= &adhoc_roles_row($1,'recent');
1.133 albertel 844: }
1.113 raeburn 845: } elsif ($numdc > 0) {
1.247 raeburn 846: unless ($role =~/^error\:/) {
1.249 raeburn 847: my ($roletext,$role_text_end) = &display_cc_role('user.role.'.$role);
848: $output.= &Apache::loncommon::start_data_table_row().
849: $roletext.
850: &Apache::loncommon::end_data_table_row().
851: &Apache::loncommon::continue_data_table_row().
852: $role_text_end.
853: &Apache::loncommon::end_data_table_row();
1.113 raeburn 854: }
1.247 raeburn 855: }
1.111 albertel 856: }
857: if ($output) {
1.212 bisitz 858: $r->print(&Apache::loncommon::start_data_table_empty_row()
859: .'<td align="center" colspan="5">'
1.224 raeburn 860: .$recent
1.212 bisitz 861: .'</td>'
862: .&Apache::loncommon::end_data_table_empty_row()
863: );
1.111 albertel 864: $r->print($output);
1.114 raeburn 865: $doheaders ++;
1.111 albertel 866: }
867: }
1.191 raeburn 868: &print_rolerows($r,$doheaders,\%roleclass,\%sortrole,\%dcroles,\%roletext);
1.202 raeburn 869: if ($countactive > 1) {
870: my $tremark='';
1.212 bisitz 871: my $tbg;
1.202 raeburn 872: if ($env{'request.role'} eq 'cm') {
1.212 bisitz 873: $tbg="LC_roles_selected";
1.204 bisitz 874: $tremark=&mt('Currently selected.').' ';
1.202 raeburn 875: } else {
1.212 bisitz 876: $tbg="LC_roles_is";
1.202 raeburn 877: }
1.212 bisitz 878: $r->print(&Apache::loncommon::start_data_table_row());
1.202 raeburn 879: unless ($nochoose) {
880: if ($env{'request.role'} ne 'cm') {
1.212 bisitz 881: $r->print('<td class="'.$tbg.'"><input type="submit" value="'.
1.202 raeburn 882: &mt('Select').'" name="cm" /></td>');
883: } else {
1.212 bisitz 884: $r->print('<td class="'.$tbg.'"> </td>');
1.202 raeburn 885: }
886: }
1.212 bisitz 887: $r->print('<td colspan="3">'
888: .&mt('No role specified')
889: .'</td>'
890: .'<td>'.$tremark.' </td>'
891: .&Apache::loncommon::end_data_table_row()
892: );
1.202 raeburn 893: }
1.212 bisitz 894: $r->print(&Apache::loncommon::end_data_table());
1.4 www 895: unless ($nochoose) {
896: $r->print("</form>\n");
897: }
1.22 harris41 898: # ------------------------------------------------------------ Privileges Info
1.118 albertel 899: if (($advanced) && (($env{'user.error.msg'}) || ($error))) {
1.212 bisitz 900: $r->print('<hr /><h2>'.&mt('Current Privileges').'</h2>');
1.175 albertel 901: $r->print(&privileges_info());
1.4 www 902: }
1.66 www 903: $r->print(&Apache::lonnet::getannounce());
1.65 www 904: if ($advanced) {
1.201 raeburn 905: my $esc_dom = &HTML::Entities::encode($env{'user.domain'},'"<>&');
1.231 bisitz 906: $r->print('<p><small><i>'
907: .&mt('This LON-CAPA server is version [_1]',$r->dir_config('lonVersion'))
908: .'</i><br />'
909: .'<a href="/adm/logout">'.&mt('Logout').'</a> '
1.201 raeburn 910: .'<a href="/adm/coursecatalog?showdom='.$esc_dom.'">'
1.233 bisitz 911: .&mt('Course/Community Catalog')
1.225 bisitz 912: .'</a></small></p>');
1.65 www 913: }
1.147 albertel 914: $r->print(&Apache::loncommon::end_page());
1.1 harris41 915: return OK;
1.102 raeburn 916: }
917:
1.226 raeburn 918: sub gather_roles {
1.254 raeburn 919: my ($then,$refresh,$now,$reinit,$nochoose,$roletext,$sortrole,$roleclass,$futureroles,$timezones,$loncaparev) = @_;
1.226 raeburn 920: my ($countactive,$countfuture,$inrole,$possiblerole) = (0,0,0,'');
921: my $advanced = $env{'user.adv'};
922: my $tryagain = $env{'form.tryagain'};
1.254 raeburn 923: my @ids = &Apache::lonnet::current_machine_ids();
1.226 raeburn 924: foreach my $envkey (sort(keys(%env))) {
925: my $button = 1;
926: my $switchserver='';
1.254 raeburn 927: my $switchwarning;
1.226 raeburn 928: my ($role_text,$role_text_end,$sortkey);
929: if ($envkey=~/^user\.role\./) {
930: my ($role,$where,$trolecode,$tstart,$tend,$tremark,$tstatus,$tpstart,$tpend);
931: &Apache::lonnet::role_status($envkey,$then,$refresh,$now,\$role,\$where,
932: \$trolecode,\$tstatus,\$tstart,\$tend);
933: next if (!defined($role) || $role eq '' || $role =~ /^gr/);
934: my $timezone = &role_timezone($where,$timezones);
935: $tremark='';
936: $tpstart=' ';
937: $tpend=' ';
938: if ($tstart) {
939: $tpstart=&Apache::lonlocal::locallocaltime($tstart,$timezone);
940: }
941: if ($tend) {
942: $tpend=&Apache::lonlocal::locallocaltime($tend,$timezone);
943: }
944: if ($env{'request.role'} eq $trolecode) {
945: $tstatus='selected';
946: }
947: my $tbg;
948: if (($tstatus eq 'is')
949: || ($tstatus eq 'selected')
950: || ($tstatus eq 'future')
951: || ($env{'form.showall'})) {
952: if ($tstatus eq 'is') {
953: $tbg='LC_roles_is';
954: $possiblerole=$trolecode;
955: $countactive++;
956: } elsif ($tstatus eq 'future') {
957: $tbg='LC_roles_future';
958: $button=0;
959: $futureroles->{$trolecode} = $tstart.':'.$tend;
960: $countfuture ++;
961: } elsif ($tstatus eq 'expired') {
962: $tbg='LC_roles_expired';
963: $button=0;
964: } elsif ($tstatus eq 'will_not') {
965: $tbg='LC_roles_will_not';
966: $tremark.=&mt('Expired after logout.').' ';
967: } elsif ($tstatus eq 'selected') {
968: $tbg='LC_roles_selected';
969: $inrole=1;
970: $countactive++;
971: $tremark.=&mt('Currently selected.').' ';
972: }
973: my $trole;
974: if ($role =~ /^cr\//) {
975: my ($rdummy,$rdomain,$rauthor,$rrole)=split(/\//,$role);
976: if ($tremark) { $tremark.='<br />'; }
1.253 bisitz 977: $tremark.=&mt('Customrole defined by [_1].',$rauthor.':'.$rdomain);
1.226 raeburn 978: }
979: $trole=Apache::lonnet::plaintext($role);
980: my $ttype;
981: my $twhere;
982: my ($tdom,$trest,$tsection)=
983: split(/\//,Apache::lonnet::declutter($where));
984: # First, Co-Authorship roles
985: if (($role eq 'ca') || ($role eq 'aa')) {
986: my $home = &Apache::lonnet::homeserver($trest,$tdom);
987: my $allowed=0;
988: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
989: if (!$allowed) {
990: $button=0;
1.248 raeburn 991: $switchserver='otherserver='.$home.'&role='.$trolecode;
1.226 raeburn 992: }
993: #next if ($home eq 'no_host');
994: $home = &Apache::lonnet::hostname($home);
995: $ttype='Construction Space';
996: $twhere=&mt('User').': '.$trest.'<br />'.&mt('Domain').
997: ': '.$tdom.'<br />'.
998: ' '.&mt('Server').': '.$home;
999: $env{'course.'.$tdom.'_'.$trest.'.description'}='ca';
1000: $tremark.=&Apache::lonhtmlcommon::authorbombs('/res/'.$tdom.'/'.$trest.'/');
1001: $sortkey=$role."$trest:$tdom";
1002: } elsif ($role eq 'au') {
1003: # Authors
1004: my $home = &Apache::lonnet::homeserver
1005: ($env{'user.name'},$env{'user.domain'});
1006: my $allowed=0;
1007: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
1008: if (!$allowed) {
1009: $button=0;
1.248 raeburn 1010: $switchserver='otherserver='.$home.'&role='.$trolecode;
1.226 raeburn 1011: }
1012: #next if ($home eq 'no_host');
1013: $home = &Apache::lonnet::hostname($home);
1014: $ttype='Construction Space';
1015: $twhere=&mt('Domain').': '.$tdom.'<br />'.&mt('Server').
1016: ': '.$home;
1017: $env{'course.'.$tdom.'_'.$trest.'.description'}='ca';
1018: $tremark.=&Apache::lonhtmlcommon::authorbombs('/res/'.$tdom.'/'.$env{'user.name'}.'/');
1019: $sortkey=$role;
1020: } elsif ($trest) {
1021: my $tcourseid=$tdom.'_'.$trest;
1022: $ttype = &Apache::loncommon::course_type($tcourseid);
1.242 raeburn 1023: $trole = &Apache::lonnet::plaintext($role,$ttype,$tcourseid);
1.226 raeburn 1024: if ($env{'course.'.$tcourseid.'.description'}) {
1.254 raeburn 1025: my $home=$env{'course.'.$tcourseid.'.home'};
1.226 raeburn 1026: $twhere=$env{'course.'.$tcourseid.'.description'};
1027: $sortkey=$role."\0".$tdom."\0".$twhere."\0".$envkey;
1.248 raeburn 1028: $twhere = &HTML::Entities::encode($twhere,'"<>&');
1.226 raeburn 1029: unless ($twhere eq &mt('Currently not available')) {
1030: $twhere.=' <span class="LC_fontsize_small">'.
1031: &Apache::loncommon::syllabuswrapper(&mt('Syllabus'),$trest,$tdom).
1032: '</span>';
1.254 raeburn 1033: unless ($home && grep(/^\Q$home\E$/,@ids) && $loncaparev eq '') {
1.255 raeburn 1034: my $required = $env{'course.'.$tcourseid.'.internal.releaserequired'};
1.254 raeburn 1035: ($switchserver,$switchwarning) =
1.255 raeburn 1036: &check_release_required($loncaparev,$tcourseid,$trolecode,$required);
1.254 raeburn 1037: if ($switchserver || $switchwarning) {
1038: $button = 0;
1039: }
1040: }
1.226 raeburn 1041: }
1042: } else {
1043: my %newhash=&Apache::lonnet::coursedescription($tcourseid);
1044: if (%newhash) {
1045: $sortkey=$role."\0".$tdom."\0".$newhash{'description'}.
1046: "\0".$envkey;
1.248 raeburn 1047: $twhere=&HTML::Entities::encode($newhash{'description'},'"<>&').
1048: ' <span class="LC_fontsize_small">'.
1049: &Apache::loncommon::syllabuswrapper(&mt('Syllabus'),$trest,$tdom).
1050: '</span>';
1.226 raeburn 1051: $ttype = $newhash{'type'};
1.243 raeburn 1052: $trole = &Apache::lonnet::plaintext($role,$ttype,$tcourseid);
1.254 raeburn 1053: my $home = $newhash{'home'};
1054: unless ($home && grep(/^\Q$home\E$/,@ids) && $loncaparev eq '') {
1.255 raeburn 1055: my $required = $newhash{'internal.releaserequired'};
1.254 raeburn 1056: ($switchserver,$switchwarning) =
1.255 raeburn 1057: &check_release_required($loncaparev,$tcourseid,$trolecode,$required);
1.254 raeburn 1058: if ($switchserver || $switchwarning) {
1059: $button = 0;
1060: }
1061: }
1.226 raeburn 1062: } else {
1063: $twhere=&mt('Currently not available');
1064: $env{'course.'.$tcourseid.'.description'}=$twhere;
1065: $sortkey=$role."\0".$tdom."\0".$twhere."\0".$envkey;
1066: $ttype = 'Unavailable';
1067: }
1068: }
1069: if ($tsection) {
1070: $twhere.='<br />'.&mt('Section').': '.$tsection;
1071: }
1072: if ($role ne 'st') { $twhere.="<br />".&mt('Domain').":".$tdom; }
1073: } elsif ($tdom) {
1074: $ttype='Domain';
1075: $twhere=$tdom;
1076: $sortkey=$role.$twhere;
1077: } else {
1078: $ttype='System';
1079: $twhere=&mt('system wide');
1080: $sortkey=$role.$twhere;
1081: }
1082: ($role_text,$role_text_end) =
1083: &build_roletext($trolecode,$tdom,$trest,$tstatus,$tryagain,
1084: $advanced,$tremark,$tbg,$trole,$twhere,$tpstart,
1.254 raeburn 1085: $tpend,$nochoose,$button,$switchserver,$reinit,$switchwarning);
1.226 raeburn 1086: $roletext->{$envkey}=[$role_text,$role_text_end];
1087: if (!$sortkey) {$sortkey=$twhere."\0".$envkey;}
1088: $sortrole->{$sortkey}=$envkey;
1089: $roleclass->{$envkey}=$ttype;
1090: }
1091: }
1092: }
1093: return ($countactive,$countfuture,$inrole,$possiblerole);
1094: }
1095:
1.215 raeburn 1096: sub role_timezone {
1097: my ($where,$timezones) = @_;
1098: my $timezone;
1099: if (ref($timezones) eq 'HASH') {
1100: if ($where =~ m{^/($match_domain)/($match_courseid)}) {
1101: my $cdom = $1;
1102: my $cnum = $2;
1103: if ($cdom && $cnum) {
1104: if (!exists($timezones->{$cdom.'_'.$cnum})) {
1105: my %timehash =
1106: &Apache::lonnet::get('environment',['timezone'],$cdom,$cnum);
1107: if ($timehash{'timezone'} eq '') {
1108: if (!exists($timezones->{$cdom})) {
1109: my %domdefaults =
1110: &Apache::lonnet::get_domain_defaults($cdom);
1111: if ($domdefaults{'timezone_def'} eq '') {
1112: $timezones->{$cdom} = 'local';
1113: } else {
1114: $timezones->{$cdom} = $domdefaults{'timezone_def'};
1115: }
1116: }
1117: $timezones->{$cdom.'_'.$cnum} = $timezones->{$cdom};
1118: } else {
1119: $timezones->{$cdom.'_'.$cnum} =
1120: &Apache::lonlocal::gettimezone($timehash{'timezone'});
1121: }
1122: }
1123: $timezone = $timezones->{$cdom.'_'.$cnum};
1124: }
1125: } else {
1126: my ($tdom) = ($where =~ m{^/($match_domain)});
1127: if ($tdom) {
1128: if (!exists($timezones->{$tdom})) {
1129: my %domdefaults = &Apache::lonnet::get_domain_defaults($tdom);
1130: if ($domdefaults{'timezone_def'} eq '') {
1131: $timezones->{$tdom} = 'local';
1132: } else {
1133: $timezones->{$tdom} = $domdefaults{'timezone_def'};
1134: }
1135: }
1136: $timezone = $timezones->{$tdom};
1137: }
1138: }
1139: if ($timezone eq 'local') {
1140: $timezone = undef;
1141: }
1142: }
1143: return $timezone;
1144: }
1145:
1.191 raeburn 1146: sub roletable_headers {
1147: my ($r,$roleclass,$sortrole,$nochoose) = @_;
1148: my $doheaders;
1149: if ((ref($sortrole) eq 'HASH') && (ref($roleclass) eq 'HASH')) {
1.212 bisitz 1150: $r->print('<br />'
1151: .&Apache::loncommon::start_data_table()
1152: .&Apache::loncommon::start_data_table_header_row()
1153: );
1.191 raeburn 1154: if (!$nochoose) { $r->print('<th> </th>'); }
1.212 bisitz 1155: $r->print('<th>'.&mt('User Role').'</th>'
1156: .'<th>'.&mt('Extent').'</th>'
1157: .'<th>'.&mt('Start').'</th>'
1158: .'<th>'.&mt('End').'</th>'
1159: .&Apache::loncommon::end_data_table_header_row()
1160: );
1.191 raeburn 1161: $doheaders=-1;
1162: my @roletypes = &roletypes();
1163: foreach my $type (@roletypes) {
1164: my $haverole=0;
1165: foreach my $which (sort {uc($a) cmp uc($b)} (keys(%{$sortrole}))) {
1166: if ($roleclass->{$sortrole->{$which}} =~ /^\Q$type\E/) {
1167: $haverole=1;
1168: }
1169: }
1170: if ($haverole) { $doheaders++; }
1171: }
1172: }
1173: return $doheaders;
1174: }
1175:
1176: sub roletypes {
1.237 raeburn 1177: my @types = ('Domain','Construction Space','Course','Community','Unavailable','System');
1.191 raeburn 1178: return @types;
1179: }
1180:
1181: sub print_rolerows {
1182: my ($r,$doheaders,$roleclass,$sortrole,$dcroles,$roletext) = @_;
1183: if ((ref($roleclass) eq 'HASH') && (ref($sortrole) eq 'HASH')) {
1184: my @types = &roletypes();
1185: foreach my $type (@types) {
1186: my $output;
1187: foreach my $which (sort {uc($a) cmp uc($b)} (keys(%{$sortrole}))) {
1188: if ($roleclass->{$sortrole->{$which}} =~ /^\Q$type\E/) {
1189: if (ref($roletext) eq 'HASH') {
1.223 raeburn 1190: if (ref($roletext->{$sortrole->{$which}}) eq 'ARRAY') {
1191: $output.= &Apache::loncommon::start_data_table_row().
1192: $roletext->{$sortrole->{$which}}->[0].
1193: &Apache::loncommon::end_data_table_row();
1.251 raeburn 1194: if ($roletext->{$sortrole->{$which}}->[1] ne '') {
1195: $output .= &Apache::loncommon::continue_data_table_row().
1196: $roletext->{$sortrole->{$which}}->[1].
1197: &Apache::loncommon::end_data_table_row();
1198: }
1.223 raeburn 1199: }
1.191 raeburn 1200: if ($sortrole->{$which} =~ m-dc\./($match_domain)/-) {
1201: if (ref($dcroles) eq 'HASH') {
1202: if ($dcroles->{$1}) {
1.192 raeburn 1203: $output .= &adhoc_roles_row($1,'');
1.191 raeburn 1204: }
1205: }
1206: }
1207: }
1208: }
1209: }
1210: if ($output) {
1211: if ($doheaders > 0) {
1.212 bisitz 1212: $r->print(&Apache::loncommon::start_data_table_empty_row()
1213: .'<td align="center" colspan="5">'
1214: .&mt($type)
1215: .'</td>'
1216: .&Apache::loncommon::end_data_table_empty_row()
1217: );
1.191 raeburn 1218: }
1219: $r->print($output);
1220: }
1221: }
1222: }
1223: }
1224:
1225: sub findcourse_advice {
1226: my ($r) = @_;
1227: my $domdesc = &Apache::lonnet::domain($env{'user.domain'},'description');
1.201 raeburn 1228: my $esc_dom = &HTML::Entities::encode($env{'user.domain'},'"<>&');
1.200 raeburn 1229: if (&Apache::lonnet::auto_run(undef,$env{'user.domain'})) {
1.191 raeburn 1230: $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).'
1231: <ul>
1232: <li>'.&mt('The course has yet to be created.').'</li>
1233: <li>'.&mt('Automatic enrollment of registered students has not been enabled for the course.').'</li>
1234: <li>'.&mt('You are in a section of course for which automatic enrollment in the corresponding LON-CAPA course is not active.').'</li>
1235: <li>'.&mt('The start date for automated enrollment has yet to be reached.').'</li>
1236: <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>
1237: </ul>');
1238: } else {
1239: $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 />');
1240: }
1.235 bisitz 1241: $r->print('<h3>'.&mt('Self-Enrollment').'</h3>'.
1.234 raeburn 1242: '<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 1243: $r->print(&mt('You can search for courses and communities which permit self-enrollment, if you would like to enroll in one.').'</p>'.
1244: &Apache::loncoursequeueadmin::queued_selfenrollment());
1.216 raeburn 1245: return;
1246: }
1247:
1.234 raeburn 1248: sub requestcourse_advice {
1249: my ($r) = @_;
1250: my $domdesc = &Apache::lonnet::domain($env{'user.domain'},'description');
1251: my $esc_dom = &HTML::Entities::encode($env{'user.domain'},'"<>&');
1252: my (%can_request,%request_doms);
1253: &Apache::lonnet::check_can_request($env{'user.domain'},\%can_request,\%request_doms);
1254: if (keys(%request_doms) > 0) {
1255: my ($types,$typename) = &Apache::loncommon::course_types();
1256: if ((ref($types) eq 'ARRAY') && (ref($typename) eq 'HASH')) {
1257: $r->print('<h3>'.&mt('Request creation of a course or community').'</h3>'.
1.238 bisitz 1258: '<p>'.&mt('You have rights to request the creation of courses and/or communities in the following domain(s):').'<ul>');
1.234 raeburn 1259: my (@reqdoms,@reqtypes);
1260: foreach my $type (sort(keys(%request_doms))) {
1261: push(@reqtypes,$type);
1262: if (ref($request_doms{$type}) eq 'ARRAY') {
1263: my $domstr = join(', ',map { &Apache::lonnet::domain($_) } sort(@{$request_doms{$type}}));
1.238 bisitz 1264: $r->print(
1265: '<li>'
1266: .&mt('[_1]'.$typename->{$type}.'[_2] in domain: [_3]',
1267: '<i>',
1268: '</i>',
1269: '<b>'.$domstr.'</b>')
1270: .'</li>'
1271: );
1.234 raeburn 1272: foreach my $dom (@{$request_doms{$type}}) {
1273: unless (grep(/^\Q$dom\E/,@reqdoms)) {
1274: push(@reqdoms,$dom);
1275: }
1276: }
1277: }
1278: }
1279: my @showtypes;
1280: foreach my $type (@{$types}) {
1281: if (grep(/^\Q$type\E$/,@reqtypes)) {
1282: push(@showtypes,$type);
1283: }
1284: }
1285: my $requrl = '/adm/requestcourse';
1286: if (@reqdoms == 1) {
1287: $requrl .= '?showdom='.$reqdoms[0];
1288: }
1289: if (@showtypes > 0) {
1290: $requrl.=(($requrl=~/\?/)?'&':'?').'crstype='.$showtypes[0];
1291: }
1292: if (@reqdoms == 1 || @showtypes > 0) {
1293: $requrl .= '&state=crstype&action=new';
1294: }
1295: $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>');
1296: }
1297: }
1298: return;
1299: }
1300:
1.175 albertel 1301: sub privileges_info {
1302: my ($which) = @_;
1303: my $output;
1304:
1305: $which ||= $env{'request.role'};
1306:
1307: foreach my $envkey (sort(keys(%env))) {
1308: next if ($envkey!~/^user\.priv\.\Q$which\E\.(.*)/);
1309:
1310: my $where=$1;
1311: my $ttype;
1312: my $twhere;
1313: my (undef,$tdom,$trest,$tsec)=split(m{/},$where);
1314: if ($trest) {
1315: if ($env{'course.'.$tdom.'_'.$trest.'.description'} eq 'ca') {
1316: $ttype='Construction Space';
1317: $twhere='User: '.$trest.', Domain: '.$tdom;
1318: } else {
1319: $ttype= &Apache::loncommon::course_type($tdom.'_'.$trest);
1320: $twhere=$env{'course.'.$tdom.'_'.$trest.'.description'};
1321: if ($tsec) {
1322: my $sec_type = 'Section';
1323: if (exists($env{"user.role.gr.$where"})) {
1324: $sec_type = 'Group';
1325: }
1326: $twhere.=' ('.$sec_type.': '.$tsec.')';
1327: }
1328: }
1329: } elsif ($tdom) {
1330: $ttype='Domain';
1331: $twhere=$tdom;
1332: } else {
1333: $ttype='System';
1334: $twhere='/';
1335: }
1.204 bisitz 1336: $output .= "\n<h3>".&mt($ttype).': '.$twhere.'</h3>'."\n<ul>";
1.175 albertel 1337: foreach my $priv (sort(split(/:/,$env{$envkey}))) {
1338: next if (!$priv);
1339:
1340: my ($prv,$restr)=split(/\&/,$priv);
1341: my $trestr='';
1342: if ($restr ne 'F') {
1343: $trestr.=' ('.
1344: join(', ',
1345: map { &Apache::lonnet::plaintext($_) }
1346: (split('',$restr))).') ';
1347: }
1348: $output .= "\n\t".
1349: '<li>'.&Apache::lonnet::plaintext($prv).$trestr.'</li>';
1350: }
1351: $output .= "\n".'</ul>';
1352: }
1353: return $output;
1354: }
1355:
1.110 raeburn 1356: sub build_roletext {
1.254 raeburn 1357: my ($trolecode,$tdom,$trest,$tstatus,$tryagain,$advanced,$tremark,$tbg,$trole,$twhere,$tpstart,$tpend,$nochoose,$button,$switchserver,$reinit,$switchwarning) = @_;
1.223 raeburn 1358: my ($roletext,$roletext_end);
1.132 albertel 1359: my $is_dc=($trolecode =~ m/^dc\./);
1360: my $rowspan=($is_dc) ? ''
1361: : ' rowspan="2" ';
1362:
1.110 raeburn 1363: unless ($nochoose) {
1.134 www 1364: my $buttonname=$trolecode;
1365: $buttonname=~s/\W//g;
1.110 raeburn 1366: if (!$button) {
1367: if ($switchserver) {
1.212 bisitz 1368: $roletext.='<td'.$rowspan.' class="'.$tbg.'">'
1369: .'<a href="/adm/switchserver?'.$switchserver.'">'
1370: .&mt('Switch Server')
1371: .'</a></td>';
1.110 raeburn 1372: } else {
1.212 bisitz 1373: $roletext.=('<td'.$rowspan.' class="'.$tbg.'"> </td>');
1.110 raeburn 1374: }
1.255 raeburn 1375: if ($switchwarning) {
1376: if ($tremark eq '') {
1377: $tremark = $switchwarning;
1378: } else {
1379: $tremark .= '<br />'.$switchwarning;
1380: }
1381: }
1.110 raeburn 1382: } elsif ($tstatus eq 'is') {
1.212 bisitz 1383: $roletext.='<td'.$rowspan.' class="'.$tbg.'">'.
1384: '<input name="'.$buttonname.'" type="button" value="'.
1.225 bisitz 1385: &mt('Select').'" onclick="javascript:enterrole(this.form,\''.
1.192 raeburn 1386: $trolecode."','".$buttonname.'\');" /></td>';
1.110 raeburn 1387: } elsif ($tryagain) {
1388: $roletext.=
1.212 bisitz 1389: '<td'.$rowspan.' class="'.$tbg.'">'.
1390: '<input name="'.$buttonname.'" type="button" value="'.
1.225 bisitz 1391: &mt('Try Selecting Again').'" onclick="javascript:enterrole(this.form,\''.
1.192 raeburn 1392: $trolecode."','".$buttonname.'\');" /></td>';
1.110 raeburn 1393: } elsif ($advanced) {
1394: $roletext.=
1.212 bisitz 1395: '<td'.$rowspan.' class="'.$tbg.'">'.
1396: '<input name="'.$buttonname.'" type="button" value="'.
1.225 bisitz 1397: &mt('Re-Initialize').'" onclick="javascript:enterrole(this.form,\''.
1.192 raeburn 1398: $trolecode."','".$buttonname.'\');" /></td>';
1.209 raeburn 1399: } elsif ($reinit) {
1400: $roletext.=
1.212 bisitz 1401: '<td'.$rowspan.' class="'.$tbg.'">'.
1402: '<input name="'.$buttonname.'" type="button" value="'.
1.225 bisitz 1403: &mt('Re-Select').'" onclick="javascript:enterrole(this.form,\''.
1.209 raeburn 1404: $trolecode."','".$buttonname.'\');" /></td>';
1.110 raeburn 1405: } else {
1.209 raeburn 1406: $roletext.=
1.212 bisitz 1407: '<td'.$rowspan.' class="'.$tbg.'">'.
1408: '<input name="'.$buttonname.'" type="button" value="'.
1.225 bisitz 1409: &mt('Re-Select').'" onclick="javascript:enterrole(this.form,\''.
1.209 raeburn 1410: $trolecode."','".$buttonname.'\');" /></td>';
1.110 raeburn 1411: }
1412: }
1.165 albertel 1413: if ($trolecode !~ m/^(dc|ca|au|aa)\./) {
1414: $tremark.=&Apache::lonannounce::showday(time,1,
1415: &Apache::lonannounce::readcalendar($tdom.'_'.$trest));
1416: }
1.212 bisitz 1417: $roletext.='<td>'.$trole.'</td>'
1418: .'<td>'.$twhere.'</td>'
1419: .'<td>'.$tpstart.'</td>'
1.223 raeburn 1420: .'<td>'.$tpend.'</td>';
1.132 albertel 1421: if (!$is_dc) {
1.223 raeburn 1422: $roletext_end = '<td colspan="4">'.
1423: $tremark.' '.
1424: '</td>';
1.132 albertel 1425: }
1.223 raeburn 1426: return ($roletext,$roletext_end);
1.110 raeburn 1427: }
1428:
1.202 raeburn 1429: sub check_needs_switchserver {
1430: my ($possiblerole) = @_;
1431: my $needs_switchserver;
1432: my ($role,$where) = split(/\./,$possiblerole,2);
1433: my (undef,$tdom,$twho) = split(/\//,$where);
1434: my ($server_status,$home);
1435: if (($role eq 'ca') || ($role eq 'aa')) {
1436: ($server_status,$home) = &check_author_homeserver($twho,$tdom);
1437: } else {
1438: ($server_status,$home) = &check_author_homeserver($env{'user.name'},
1439: $env{'user.domain'});
1440: }
1441: if ($server_status eq 'switchserver') {
1442: $needs_switchserver = 1;
1443: }
1444: return $needs_switchserver;
1445: }
1446:
1.193 raeburn 1447: sub check_author_homeserver {
1.183 www 1448: my ($uname,$udom)=@_;
1.193 raeburn 1449: if (($uname eq '') || ($udom eq '')) {
1450: return ('fail','');
1451: }
1.183 www 1452: my $home = &Apache::lonnet::homeserver($uname,$udom);
1.193 raeburn 1453: if (&Apache::lonnet::host_domain($home) ne $udom) {
1454: return ('fail',$home);
1455: }
1.183 www 1456: my @ids=&Apache::lonnet::current_machine_ids();
1.193 raeburn 1457: if (grep(/^\Q$home\E$/,@ids)) {
1458: return ('ok',$home);
1459: } else {
1460: return ('switchserver',$home);
1.183 www 1461: }
1462: }
1463:
1.104 raeburn 1464: sub check_fordc {
1465: my ($dcroles,$then) = @_;
1466: my $numdc = 0;
1.118 albertel 1467: if ($env{'user.adv'}) {
1468: foreach my $envkey (sort keys %env) {
1.170 albertel 1469: if ($envkey=~/^user\.role\.dc\.\/($match_domain)\/$/) {
1.104 raeburn 1470: my $dcdom = $1;
1471: my $livedc = 1;
1.118 albertel 1472: my ($tstart,$tend)=split(/\./,$env{$envkey});
1.105 raeburn 1473: if ($tstart && $tstart>$then) { $livedc = 0; }
1474: if ($tend && $tend <$then) { $livedc = 0; }
1.104 raeburn 1475: if ($livedc) {
1476: $$dcroles{$dcdom} = $envkey;
1.105 raeburn 1477: $numdc++;
1.104 raeburn 1478: }
1479: }
1480: }
1481: }
1482: return $numdc;
1483: }
1484:
1.185 raeburn 1485: sub adhoc_course_role {
1.232 raeburn 1486: my ($refresh,$then) = @_;
1.239 raeburn 1487: my ($cdom,$cnum,$crstype);
1.201 raeburn 1488: $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
1489: $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.239 raeburn 1490: $crstype = &Apache::loncommon::course_type();
1491: if (&check_forcc($cdom,$cnum,$refresh,$then,$crstype)) {
1.185 raeburn 1492: my $setprivs;
1.198 raeburn 1493: if (!defined($env{'user.role.'.$env{'form.switchrole'}})) {
1.185 raeburn 1494: $setprivs = 1;
1495: } else {
1.198 raeburn 1496: my ($start,$end) = split(/\./,$env{'user.role.'.$env{'form.switchrole'}});
1.232 raeburn 1497: if (($start && ($start>$refresh || $start == -1)) ||
1.185 raeburn 1498: ($end && $end<$then)) {
1499: $setprivs = 1;
1500: }
1.232 raeburn 1501: }
1.185 raeburn 1502: if ($setprivs) {
1.198 raeburn 1503: if ($env{'form.switchrole'} =~ m-^(in|ta|ep|ad|st|cr)([\w/]*)\./\Q$cdom\E/\Q$cnum\E/?(\w*)$-) {
1.185 raeburn 1504: my $role = $1;
1505: my $custom_role = $2;
1506: my $usec = $3;
1507: if ($role eq 'cr') {
1.199 raeburn 1508: if ($custom_role =~ m-^/$match_domain/$match_username/\w+$-) {
1.185 raeburn 1509: $role .= $custom_role;
1510: } else {
1511: return;
1512: }
1513: }
1.208 raeburn 1514: my (%userroles,%newrole,%newgroups,%group_privs);
1515: my %cgroups =
1516: &Apache::lonnet::get_active_groups($env{'user.domain'},
1517: $env{'user.name'},$cdom,$cnum);
1518: foreach my $group (keys(%cgroups)) {
1519: $group_privs{$group} =
1520: $env{'user.priv.cc./'.$cdom.'/'.$cnum.'./'.$cdom.'/'.$cnum.'/'.$group};
1521: }
1522: $newgroups{'/'.$cdom.'/'.$cnum} = \%group_privs;
1.185 raeburn 1523: my $area = '/'.$cdom.'/'.$cnum;
1524: my $spec = $role.'.'.$area;
1525: if ($usec ne '') {
1526: $spec .= '/'.$usec;
1527: $area .= '/'.$usec;
1528: }
1529: &Apache::lonnet::standard_roleprivs(\%newrole,$role,$cdom,$spec,$cnum,$area);
1.208 raeburn 1530: &Apache::lonnet::set_userprivs(\%userroles,\%newrole,\%newgroups);
1.232 raeburn 1531: my $adhocstart = $refresh-1;
1.185 raeburn 1532: $userroles{'user.role.'.$spec} = $adhocstart.'.';
1.186 raeburn 1533: &Apache::lonnet::appenv(\%userroles,[$role,'cm']);
1.185 raeburn 1534: }
1535: }
1536: }
1537: return;
1538: }
1539:
1540: sub check_forcc {
1.239 raeburn 1541: my ($cdom,$cnum,$refresh,$then,$crstype) = @_;
1542: my ($is_cc,$ccrole);
1543: if ($crstype eq 'Community') {
1544: $ccrole = 'co';
1545: } else {
1546: $ccrole = 'cc';
1547: }
1.185 raeburn 1548: if ($cdom ne '' && $cnum ne '') {
1549: if (&Apache::lonnet::is_course($cdom,$cnum)) {
1.239 raeburn 1550: my $envkey = 'user.role.'.$ccrole.'./'.$cdom.'/'.$cnum;
1.185 raeburn 1551: if (defined($env{$envkey})) {
1552: $is_cc = 1;
1553: my ($tstart,$tend)=split(/\./,$env{$envkey});
1.232 raeburn 1554: if ($tstart && $tstart>$refresh) { $is_cc = 0; }
1.185 raeburn 1555: if ($tend && $tend <$then) { $is_cc = 0; }
1556: }
1557: }
1558: }
1559: return $is_cc;
1560: }
1561:
1.254 raeburn 1562: sub check_release_required {
1.255 raeburn 1563: my ($loncaparev,$tcourseid,$trolecode,$required) = @_;
1.254 raeburn 1564: my ($switchserver,$warning);
1.255 raeburn 1565: if ($required ne '') {
1566: my ($reqdmajor,$reqdminor) = ($required =~ /^(\d+)\.(\d+)$/);
1.254 raeburn 1567: my ($major,$minor) = ($loncaparev =~ /^\'?(\d+)\.(\d+)\.[\d.\-]+\'?$/);
1568: if ($reqdmajor ne '' && $reqdminor ne '') {
1569: my $otherserver;
1570: if (($major eq '' && $minor eq '') ||
1571: (($reqdmajor > $major) || (($reqdmajor == $major) && ($reqdminor > $minor)))) {
1572: my ($userdomserver) = &Apache::lonnet::choose_server($env{'user.domain'});
1573: my $switchlcrev =
1574: &Apache::lonnet::get_server_loncaparev($env{'user.domain'},
1575: $userdomserver);
1576: my ($swmajor,$swminor) = ($switchlcrev =~ /^\'?(\d+)\.(\d+)\.[\d.\-]+\'?$/);
1577: if (($swmajor eq '' && $swminor eq '') || ($reqdmajor > $swmajor) ||
1578: (($reqdmajor == $swmajor) && ($reqdminor > $swminor))) {
1579: my $cdom = $env{'course.'.$tcourseid.'.domain'};
1580: if ($cdom ne $env{'user.domain'}) {
1581: my ($coursedomserver,$coursehostname) = &Apache::lonnet::choose_server($cdom);
1582: my $serverhomeID = &Apache::lonnet::get_server_homeID($coursehostname);
1583: my $serverhomedom = &Apache::lonnet::host_domain($serverhomeID);
1584: my %defdomdefaults = &Apache::lonnet::get_domain_defaults($serverhomedom);
1585: my %udomdefaults = &Apache::lonnet::get_domain_defaults($env{'user.domain'});
1586: my $remoterev = &Apache::lonnet::get_server_loncaparev($serverhomedom,$coursedomserver);
1587: my $canhost =
1588: &Apache::lonnet::can_host_session($env{'user.domain'},
1589: $coursedomserver,
1590: $remoterev,
1591: $udomdefaults{'remotesessions'},
1592: $defdomdefaults{'hostedsessions'});
1593:
1594: if ($canhost) {
1595: $otherserver = $coursedomserver;
1596: } else {
1597: $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.");
1598: }
1599: } else {
1600: $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).");
1601: }
1602: } else {
1603: $otherserver = $userdomserver;
1604: }
1605: }
1606: if ($otherserver ne '') {
1607: $switchserver = 'otherserver='.$otherserver.'&role='.$trolecode;
1608: }
1609: }
1610: }
1611: return ($switchserver,$warning);
1612: }
1613:
1.255 raeburn 1614: sub update_content_constraints {
1615: my ($cdom,$cnum,$chome,$cid) = @_;
1616: my %curr_reqd_hash = &Apache::lonnet::userenvironment($cdom,$cnum,'internal.releaserequired');
1617: my ($reqdmajor,$reqdminor) = split(/\./,$curr_reqd_hash{'internal.releaserequired'});
1618: my %checkresponsetypes;
1619: foreach my $key (keys(%Apache::lonnet::needsrelease)) {
1620: my ($item,$name,$value) = split(/:/,$key);
1621: if ($item eq 'resourcetag') {
1622: if ($name eq 'responsetype') {
1623: $checkresponsetypes{$value} = $Apache::lonnet::needsrelease{$key}
1624: }
1625: }
1626: }
1627: my $navmap = Apache::lonnavmaps::navmap->new();
1628: if (defined($navmap)) {
1629: my %allresponses;
1630: foreach my $res ($navmap->retrieveResources(undef,sub { $_[0]->is_problem() },1,0)) {
1631: my %responses = $res->responseTypes();
1632: foreach my $key (keys(%responses)) {
1633: next unless(exists($checkresponsetypes{$key}));
1634: $allresponses{$key} += $responses{$key};
1635: }
1636: }
1637: foreach my $key (keys(%allresponses)) {
1638: my ($major,$minor) = split(/\./,$checkresponsetypes{$key});
1639: if (($major > $reqdmajor) || ($major == $reqdmajor && $minor > $reqdminor)) {
1640: ($reqdmajor,$reqdminor) = ($major,$minor);
1641: }
1642: }
1643: undef($navmap);
1644: }
1645: unless (($reqdmajor eq '') && ($reqdminor eq '')) {
1646: &Apache::lonnet::update_released_required($reqdmajor.'.'.$reqdminor,$cdom,$cnum,$chome,$cid);
1647: }
1648: return;
1649: }
1650:
1.108 raeburn 1651: sub courselink {
1.193 raeburn 1652: my ($dcdom,$rowtype) = @_;
1.109 raeburn 1653: my $courseform=&Apache::loncommon::selectcourse_link
1.152 raeburn 1654: ('rolechoice','dccourse'.$rowtype.'_'.$dcdom,
1655: 'dcdomain'.$rowtype.'_'.$dcdom,'coursedesc'.$rowtype.'_'.
1.239 raeburn 1656: $dcdom,$dcdom,undef,'Course/Community');
1.138 raeburn 1657: my $hiddenitems = '<input type="hidden" name="dcdomain'.$rowtype.'_'.$dcdom.'" value="'.$dcdom.'" />'.
1658: '<input type="hidden" name="origdom'.$rowtype.'_'.$dcdom.'" value="'.$dcdom.'" />'.
1659: '<input type="hidden" name="dccourse'.$rowtype.'_'.$dcdom.'" value="" />'.
1660: '<input type="hidden" name="coursedesc'.$rowtype.'_'.$dcdom.'" value="" />';
1.112 raeburn 1661: return $courseform.$hiddenitems;
1.109 raeburn 1662: }
1663:
1664: sub coursepick_jscript {
1.184 raeburn 1665: my %lt = &Apache::lonlocal::texthash(
1.239 raeburn 1666: 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 1667: youc => 'You can only use this screen to select courses and communities in the current domain.',
1.184 raeburn 1668: );
1.104 raeburn 1669: my $verify_script = <<"END";
1.179 raeburn 1670: <script type="text/javascript">
1.225 bisitz 1671: // <![CDATA[
1.108 raeburn 1672: function verifyCoursePick(caller) {
1673: var numbutton = getIndex(caller)
1.112 raeburn 1674: var pickedCourse = document.rolechoice.elements[numbutton+4].value
1675: var pickedDomain = document.rolechoice.elements[numbutton+2].value
1676: if (document.rolechoice.elements[numbutton+2].value == document.rolechoice.elements[numbutton+3].value) {
1.104 raeburn 1677: if (pickedCourse != '') {
1.108 raeburn 1678: if (numbutton != -1) {
1679: var courseTarget = "cc./"+pickedDomain+"/"+pickedCourse
1680: document.rolechoice.elements[numbutton+1].name = courseTarget
1681: document.rolechoice.submit()
1682: }
1.104 raeburn 1683: }
1684: else {
1.184 raeburn 1685: alert("$lt{'plsu'}");
1.104 raeburn 1686: }
1687: }
1688: else {
1.184 raeburn 1689: alert("$lt{'youc'}")
1.104 raeburn 1690: }
1691: }
1.109 raeburn 1692: function getIndex(caller) {
1.108 raeburn 1693: for (var i=0;i<document.rolechoice.elements.length;i++) {
1.109 raeburn 1694: if (document.rolechoice.elements[i] == caller) {
1.108 raeburn 1695: return i;
1696: }
1697: }
1698: return -1;
1699: }
1.225 bisitz 1700: // ]]>
1.104 raeburn 1701: </script>
1702: END
1.109 raeburn 1703: return $verify_script;
1.104 raeburn 1704: }
1705:
1.193 raeburn 1706: sub coauthorlink {
1707: my ($dcdom,$rowtype) = @_;
1708: my $coauthorform=&Apache::loncommon::selectauthor_link('rolechoice',$dcdom);
1709: my $hiddenitems = '<input type="hidden" name="adhoccauname'.$rowtype.'_'.$dcdom.'" value="" />';
1710: return $coauthorform.$hiddenitems;
1711: }
1712:
1.113 raeburn 1713: sub display_cc_role {
1714: my $rolekey = shift;
1.223 raeburn 1715: my ($roletext,$roletext_end);
1.118 albertel 1716: my $advanced = $env{'user.adv'};
1717: my $tryagain = $env{'form.tryagain'};
1.113 raeburn 1718: unless ($rolekey =~/^error\:/) {
1.240 raeburn 1719: if ($rolekey =~ m{^user\.role\.(cc|co)\./($match_domain)/($match_courseid)$}) {
1720: my $ccrole = $1;
1.249 raeburn 1721: my $tdom = $2;
1722: my $trest = $3;
1723: my $tcourseid = $tdom.'_'.$trest;
1724: my $trolecode = $ccrole.'./'.$tdom.'/'.$trest;
1.113 raeburn 1725: my $twhere;
1.152 raeburn 1726: my $ttype;
1.212 bisitz 1727: my $tbg='LC_roles_is';
1.113 raeburn 1728: my %newhash=&Apache::lonnet::coursedescription($tcourseid);
1729: if (%newhash) {
1730: $twhere=$newhash{'description'}.
1.211 tempelho 1731: ' <span style="LC_fontsize_small">'.
1.249 raeburn 1732: &Apache::loncommon::syllabuswrapper(&mt('Syllabus'),$trest,$tdom).
1.211 tempelho 1733: '</span>';
1.153 raeburn 1734: $ttype = $newhash{'type'};
1.113 raeburn 1735: } else {
1736: $twhere=&mt('Currently not available');
1.118 albertel 1737: $env{'course.'.$tcourseid.'.description'}=$twhere;
1.110 raeburn 1738: }
1.242 raeburn 1739: my $trole = &Apache::lonnet::plaintext($ccrole,$ttype,$tcourseid);
1.113 raeburn 1740: $twhere.="<br />".&mt('Domain').":".$1;
1.249 raeburn 1741: ($roletext,$roletext_end) = &build_roletext($trolecode,$tdom,$trest,'is',$tryagain,$advanced,'',$tbg,$trole,$twhere,'','','',1,'');
1.104 raeburn 1742: }
1743: }
1.223 raeburn 1744: return ($roletext,$roletext_end);
1.104 raeburn 1745: }
1746:
1.192 raeburn 1747: sub adhoc_roles_row {
1.138 raeburn 1748: my ($dcdom,$rowtype) = @_;
1.212 bisitz 1749: my $output = &Apache::loncommon::continue_data_table_row()
1750: .' <td colspan="5">'
1751: .&mt('[_1]Ad hoc[_2] roles in domain [_3] --'
1752: ,'<span class="LC_cusr_emph">','</span>',$dcdom)
1.227 bisitz 1753: .' ';
1.193 raeburn 1754: my $selectcclink = &courselink($dcdom,$rowtype);
1.239 raeburn 1755: my $ccrole = &Apache::lonnet::plaintext('co',undef,undef,1);
1.182 www 1756: my $carole = &Apache::lonnet::plaintext('ca');
1.193 raeburn 1757: my $selectcalink = &coauthorlink($dcdom,$rowtype);
1.227 bisitz 1758: $output.=$ccrole.': '.$selectcclink
1.249 raeburn 1759: .' | '.$carole.': '.$selectcalink.'</td>'
1.212 bisitz 1760: .&Apache::loncommon::end_data_table_row();
1.108 raeburn 1761: return $output;
1762: }
1763:
1.104 raeburn 1764: sub recent_filename {
1765: my $area=shift;
1.149 www 1766: return 'nohist_recent_'.&escape($area);
1.104 raeburn 1767: }
1768:
1.139 raeburn 1769: sub courseloadpage {
1770: my ($courseid) = @_;
1771: my $startpage;
1.144 albertel 1772: my %entry_settings = &Apache::lonnet::get('nohist_whatsnew',
1773: [$courseid.':courseinit']);
1.139 raeburn 1774: my ($tmp) = %entry_settings;
1.144 albertel 1775: unless ($tmp =~ /^error: 2 /) {
1.139 raeburn 1776: $startpage = $entry_settings{$courseid.':courseinit'};
1777: }
1778: if ($startpage eq '') {
1779: if (exists($env{'environment.course_init_display'})) {
1780: $startpage = $env{'environment.course_init_display'};
1781: }
1782: }
1783: return $startpage;
1784: }
1785:
1.1 harris41 1786: 1;
1787: __END__
1.32 harris41 1788:
1789: =head1 NAME
1790:
1791: Apache::lonroles - User Roles Screen
1792:
1793: =head1 SYNOPSIS
1794:
1795: Invoked by /etc/httpd/conf/srm.conf:
1796:
1797: <Location /adm/roles>
1798: PerlAccessHandler Apache::lonacc
1799: SetHandler perl-script
1800: PerlHandler Apache::lonroles
1801: ErrorDocument 403 /adm/login
1802: ErrorDocument 500 /adm/errorhandler
1803: </Location>
1.64 bowersj2 1804:
1805: =head1 OVERVIEW
1806:
1807: =head2 Choosing Roles
1808:
1809: C<lonroles> is a handler that allows a user to switch roles in
1810: mid-session. LON-CAPA attempts to work with "No Role Specified", the
1811: default role that a user has before selecting a role, as widely as
1812: possible, but certain handlers for example need specification which
1813: course they should act on, etc. Both in this scenario, and when the
1814: handler determines via C<lonnet>'s C<&allowed> function that a certain
1815: action is not allowed, C<lonroles> is used as error handler. This
1816: allows the user to select another role which may have permission to do
1.246 droeschl 1817: what they were trying to do.
1.64 bowersj2 1818:
1819: =begin latex
1820:
1821: \begin{figure}
1822: \begin{center}
1823: \includegraphics[width=0.45\paperwidth,keepaspectratio]{Sample_Roles_Screen}
1824: \caption{\label{Sample_Roles_Screen}Sample Roles Screen}
1825: \end{center}
1826: \end{figure}
1827:
1828: =end latex
1829:
1830: =head2 Role Initialization
1831:
1832: 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 1833:
1834: =head1 INTRODUCTION
1835:
1836: This module enables a user to select what role he wishes to
1837: operate under (instructor, student, teaching assistant, course
1838: coordinator, etc). These roles are pre-established by the actions
1839: of upper-level users.
1840:
1841: This is part of the LearningOnline Network with CAPA project
1842: described at http://www.lon-capa.org.
1843:
1844: =head1 HANDLER SUBROUTINE
1845:
1846: This routine is called by Apache and mod_perl.
1847:
1848: =over 4
1849:
1850: =item *
1851:
1852: Roles Initialization (yes/no)
1853:
1854: =item *
1855:
1856: Get Error Message from Environment
1857:
1858: =item *
1859:
1860: Who is this?
1861:
1862: =item *
1863:
1864: Generate Page Output
1865:
1866: =item *
1867:
1868: Choice or no choice
1869:
1870: =item *
1871:
1872: Table
1873:
1874: =item *
1875:
1876: Privileges
1877:
1878: =back
1879:
1880: =cut
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>