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