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