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