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