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