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