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