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