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