Annotation of loncom/auth/lonroles.pm, revision 1.256.2.8
1.1 harris41 1: # The LearningOnline Network with CAPA
2: # User Roles Screen
1.31 www 3: #
1.256.2.8! raeburn 4: # $Id: lonroles.pm,v 1.256.2.7 2014/03/25 10:18:04 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.256.2.4 raeburn 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.256.2.5 raeburn 582: if (($furl !~ m|^/adm/|) ||
583: (($env{'environment.remotenavmap'} eq 'on') &&
584: ($furl =~ m{^/adm/navmaps}))) {
1.151 www 585: # Guess not ...
586: $furl=&Apache::lonpageflip::first_accessible_resource();
587: }
1.162 albertel 588: $msg = &mt('Entering [_1] ...',
589: $env{'course.'.$courseid.'.description'});
1.256.2.1 raeburn 590: &redirect_user($r,&mt('Entering [_1]',
591: $env{'course.'.$courseid.'.description'}),
592: $furl,$msg,
593: $env{'environment.remotenavmap'});
1.58 bowersj2 594: }
1.124 albertel 595: return OK;
1.55 albertel 596: }
597: }
1.62 matthew 598: #
599: # Send the user to the construction space they selected
1.125 www 600: if ($role =~ /^(au|ca|aa)$/) {
1.62 matthew 601: my $redirect_url = '/priv/';
602: if ($role eq 'au') {
1.118 albertel 603: $redirect_url.=$env{'user.name'};
1.62 matthew 604: } else {
605: $where =~ /\/(.*)$/;
606: $redirect_url .= $1;
607: }
608: $redirect_url .= '/';
1.78 sakharuk 609: &redirect_user($r,&mt('Entering Construction Space'),
1.62 matthew 610: $redirect_url);
611: return OK;
612: }
1.104 raeburn 613: if ($role eq 'dc') {
1.108 raeburn 614: my $redirect_url = '/adm/menu/';
615: &redirect_user($r,&mt('Loading Domain Coordinator Menu'),
1.104 raeburn 616: $redirect_url);
1.108 raeburn 617: return OK;
1.104 raeburn 618: }
1.220 raeburn 619: if ($role eq 'sc') {
620: my $redirect_url = '/adm/grades?command=scantronupload';
621: &redirect_user($r,&mt('Loading Data Upload Page'),
622: $redirect_url);
623: return OK;
624: }
1.55 albertel 625: }
626: }
1.6 www 627: }
1.40 matthew 628: }
1.44 www 629:
1.10 www 630:
1.6 www 631: # =============================================================== No Roles Init
1.10 www 632:
1.73 www 633: &Apache::loncommon::content_type($r,'text/html');
1.30 albertel 634: &Apache::loncommon::no_cache($r);
1.10 www 635: $r->send_http_header;
636: return OK if $r->header_only;
637:
1.224 raeburn 638: my $crumbtext = 'User Roles';
639: my $pagetitle = 'My Roles';
640: my $recent = &mt('Recent Roles');
641: my $show_course=&Apache::loncommon::show_course();
642: if ($show_course) {
643: $crumbtext = 'Courses';
644: $pagetitle = 'My Courses';
645: $recent = &mt('Recent Courses');
646: }
647: my $brcrum =[{href=>"/adm/roles",text=>$crumbtext}];
1.52 www 648: my $swinfo=&Apache::lonmenu::rawconfig();
1.224 raeburn 649: my $start_page=&Apache::loncommon::start_page($pagetitle,undef,{bread_crumbs=>$brcrum});
1.134 www 650: my $standby=&mt('Role selected. Please stand by.');
1.135 albertel 651: $standby=~s/\n/\\n/g;
1.184 raeburn 652: 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 653:
1.10 www 654: $r->print(<<ENDHEADER);
1.147 albertel 655: $start_page
1.163 www 656: <br />
1.179 raeburn 657: <noscript>
658: $noscript
659: </noscript>
660: <script type="text/javascript">
1.225 bisitz 661: // <![CDATA[
1.26 www 662: $swinfo
663: window.focus();
1.134 www 664:
665: active=true;
666:
667: function enterrole (thisform,rolecode,buttonname) {
668: if (active) {
669: active=false;
670: document.title='$standby';
671: window.status='$standby';
672: thisform.newrole.value=rolecode;
673: thisform.submit();
674: } else {
675: alert('$standby');
676: }
677: }
1.225 bisitz 678: // ]]>
1.26 www 679: </script>
1.10 www 680: ENDHEADER
1.6 www 681:
1.2 www 682: # ------------------------------------------ Get Error Message from Environment
683:
1.118 albertel 684: my ($fn,$priv,$nochoose,$error,$msg)=split(/:/,$env{'user.error.msg'});
685: if ($env{'user.error.msg'}) {
1.55 albertel 686: $r->log_reason(
1.118 albertel 687: "$msg for $env{'user.name'} domain $env{'user.domain'} access $priv",$fn);
1.12 www 688: }
1.1 harris41 689:
1.61 www 690: # ------------------------------------------------- Can this user re-init, etc?
1.6 www 691:
1.118 albertel 692: my $advanced=$env{'user.adv'};
1.61 www 693: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['tryagain']);
1.118 albertel 694: my $tryagain=$env{'form.tryagain'};
1.209 raeburn 695: my $reinit=$env{'user.reinit'};
696: delete $env{'user.reinit'};
1.6 www 697:
1.2 www 698: # -------------------------------------------------------- Generate Page Output
1.6 www 699: # --------------------------------------------------------------- Error Header?
1.2 www 700: if ($error) {
1.187 bisitz 701: $r->print("<h1>".&mt('LON-CAPA Access Control')."</h1>");
1.174 albertel 702: $r->print("<!-- LONCAPAACCESSCONTROLERRORSCREEN --><hr /><pre>");
703: if ($priv ne '') {
1.187 bisitz 704: $r->print(&mt('Access : ').&Apache::lonnet::plaintext($priv)."\n");
1.174 albertel 705: }
706: if ($fn ne '') {
1.187 bisitz 707: $r->print(&mt('Resource: ').&Apache::lonenc::check_encrypt($fn)."\n");
1.174 albertel 708: }
709: if ($msg ne '') {
1.187 bisitz 710: $r->print(&mt('Action : ').$msg."\n");
1.174 albertel 711: }
712: $r->print("</pre><hr />");
1.120 albertel 713: my $url=$fn;
714: my $last;
715: if (tie(my %hash,'GDBM_File',$env{'request.course.fn'}.'_symb.db',
716: &GDBM_READER(),0640)) {
717: $last=$hash{'last_known'};
718: untie(%hash);
719: }
1.149 www 720: if ($last) { $fn.='?symb='.&escape($last); }
1.120 albertel 721:
722: &Apache::londocs::changewarning($r,undef,'You have modified your course recently, [_1] may fix this access problem.',
723: &Apache::lonenc::check_encrypt($fn));
1.2 www 724: } else {
1.118 albertel 725: if ($env{'user.error.msg'}) {
1.209 raeburn 726: if ($reinit) {
727: $r->print(
728: '<h3><span class="LC_error">'.
1.234 raeburn 729: &mt('As your session file for the course or community has expired, you will need to re-select it.').'</span></h3>');
1.209 raeburn 730: } else {
731: $r->print(
1.157 albertel 732: '<h3><span class="LC_error">'.
1.235 bisitz 733: &mt('You need to choose another user role or enter a specific course or community for this function.').
734: '</span></h3>');
1.209 raeburn 735: }
736: }
1.2 www 737: }
1.6 www 738: # -------------------------------------------------------- Choice or no choice?
1.2 www 739: if ($nochoose) {
1.177 www 740: $r->print("<h2>".&mt('Sorry ...')."</h2>\n<span class='LC_error'>".
741: &mt('This action is currently not authorized.').'</span>'.
1.150 www 742: &Apache::loncommon::end_page());
743: return OK;
1.6 www 744: } else {
1.18 www 745: if (($ENV{'REDIRECT_QUERY_STRING'}) && ($fn)) {
746: $fn.='?'.$ENV{'REDIRECT_QUERY_STRING'};
1.6 www 747: }
1.84 www 748: $r->print('<form method="post" name="rolechoice" action="'.(($fn)?$fn:$r->uri).'">');
1.116 albertel 749: $r->print('<input type="hidden" name="orgurl" value="'.$fn.'" />');
750: $r->print('<input type="hidden" name="selectrole" value="1" />');
1.134 www 751: $r->print('<input type="hidden" name="newrole" value="" />');
1.6 www 752: }
1.256.2.4 raeburn 753: $r->rflush();
1.226 raeburn 754:
755: my (%roletext,%sortrole,%roleclass,%futureroles,%timezones);
756: my ($countactive,$countfuture,$inrole,$possiblerole) =
757: &gather_roles($then,$refresh,$now,$reinit,$nochoose,\%roletext,\%sortrole,\%roleclass,
1.254 raeburn 758: \%futureroles,\%timezones,$loncaparev);
1.226 raeburn 759:
760: $refresh = $now;
761: &Apache::lonnet::appenv({'user.refresh.time' => $refresh});
1.196 raeburn 762: if ($env{'user.adv'}) {
1.238 bisitz 763: $r->print('<p><label><input type="checkbox" name="showall"');
1.196 raeburn 764: if ($env{'form.showall'}) { $r->print(' checked="checked" '); }
1.238 bisitz 765: $r->print(' />'.&mt('Show all roles').'</label>'
766: .' <input type="submit" value="'.&mt('Update display').'" />'
767: .'</p>');
1.196 raeburn 768: } else {
769: if ($countactive > 0) {
1.241 raeburn 770: $r->print(&Apache::loncoursequeueadmin::queued_selfenrollment());
1.196 raeburn 771: my $domdesc = &Apache::lonnet::domain($env{'user.domain'},'description');
1.201 raeburn 772: my $esc_dom = &HTML::Entities::encode($env{'user.domain'},'"<>&');
1.233 bisitz 773: $r->print(
774: '<p>'
775: .&mt('[_1]Visit the [_2]Course/Community Catalog[_3]'
776: .' to view all [_4] LON-CAPA courses and communities.'
777: ,'<b>'
778: ,'<a href="/adm/coursecatalog?showdom='.$esc_dom.'">'
779: ,'</a></b>',$domdesc)
780: .'<br />'
1.235 bisitz 781: .&mt('If a course or community is [_1]not[_2] in your list of current courses and communities below,'
1.233 bisitz 782: .' you may be able to enroll if self-enrollment is permitted.'
783: ,'<b>','</b>')
784: .'</p>'
785: );
1.196 raeburn 786: }
787: }
788:
1.84 www 789: # No active roles
790: if ($countactive==0) {
791: if ($inrole) {
1.234 raeburn 792: $r->print('<h2>'.&mt('Currently no additional roles, courses or communities').'</h2>');
1.84 www 793: } else {
1.234 raeburn 794: $r->print('<h2>'.&mt('Currently no active roles, courses or communities').'</h2>');
1.84 www 795: }
1.191 raeburn 796: &findcourse_advice($r);
1.234 raeburn 797: &requestcourse_advice($r);
1.191 raeburn 798: $r->print('</form>');
799: if ($countfuture) {
800: $r->print(&mt('The following [quant,_1,role,roles] will become active in the future:',$countfuture));
801: my $doheaders = &roletable_headers($r,\%roleclass,\%sortrole,
802: $nochoose);
803: &print_rolerows($r,$doheaders,\%roleclass,\%sortrole,\%dcroles,
804: \%roletext);
805: my $tremark='';
1.212 bisitz 806: my $tbg;
1.191 raeburn 807: if ($env{'request.role'} eq 'cm') {
1.212 bisitz 808: $tbg="LC_roles_selected";
1.204 bisitz 809: $tremark=&mt('Currently selected.').' ';
1.191 raeburn 810: } else {
1.212 bisitz 811: $tbg="LC_roles_is";
1.191 raeburn 812: }
1.212 bisitz 813: $r->print(&Apache::loncommon::start_data_table_row()
814: .'<td class="'.$tbg.'"> </td>'
815: .'<td colspan="3">'
816: .&mt('No role specified')
817: .'</td>'
818: .'<td>'.$tremark.' </td>'
819: .&Apache::loncommon::end_data_table_row()
820: );
1.191 raeburn 821:
1.212 bisitz 822: $r->print(&Apache::loncommon::end_data_table());
1.191 raeburn 823: }
824: $r->print(&Apache::loncommon::end_page());
1.84 www 825: return OK;
826: }
827: # ----------------------------------------------------------------------- Table
1.247 raeburn 828:
829: if ($numdc > 0) {
830: $r->print(&coursepick_jscript());
831: $r->print(&Apache::loncommon::coursebrowser_javascript().
832: &Apache::loncommon::authorbrowser_javascript());
833: }
834:
1.224 raeburn 835: unless ((!&Apache::loncommon::show_course()) || ($nochoose) || ($countactive==1)) {
1.173 albertel 836: $r->print("<h2>".&mt('Select a Course to Enter')."</h2>\n");
1.84 www 837: }
1.229 raeburn 838: if ($env{'form.destinationurl'}) {
839: $r->print('<input type="hidden" name="destinationurl" value="'.
840: $env{'form.destinationurl'}.'" />');
841: if ($env{'form.destsymb'} ne '') {
842: $r->print('<input type="hidden" name="destsymb" value="'.
843: $env{'form.destsymb'}.'" />');
844: }
845: }
1.247 raeburn 846:
1.191 raeburn 847: my $doheaders = &roletable_headers($r,\%roleclass,\%sortrole,$nochoose);
1.118 albertel 848: if ($env{'environment.recentroles'}) {
1.111 albertel 849: my %recent_roles =
1.118 albertel 850: &Apache::lonhtmlcommon::get_recent('roles',$env{'environment.recentrolesn'});
1.111 albertel 851: my $output='';
1.247 raeburn 852: foreach my $role (sort(keys(%recent_roles))) {
853: if (ref($roletext{'user.role.'.$role}) eq 'ARRAY') {
1.223 raeburn 854: $output.= &Apache::loncommon::start_data_table_row().
1.247 raeburn 855: $roletext{'user.role.'.$role}->[0].
1.223 raeburn 856: &Apache::loncommon::end_data_table_row();
1.249 raeburn 857: if ($roletext{'user.role.'.$role}->[1] ne '') {
858: $output .= &Apache::loncommon::continue_data_table_row().
859: $roletext{'user.role.'.$role}->[1].
860: &Apache::loncommon::end_data_table_row();
861: }
1.247 raeburn 862: if ($role =~ m{dc\./($match_domain)/}
1.170 albertel 863: && $dcroles{$1}) {
1.192 raeburn 864: $output .= &adhoc_roles_row($1,'recent');
1.133 albertel 865: }
1.113 raeburn 866: } elsif ($numdc > 0) {
1.247 raeburn 867: unless ($role =~/^error\:/) {
1.249 raeburn 868: my ($roletext,$role_text_end) = &display_cc_role('user.role.'.$role);
1.256.2.4 raeburn 869: if ($roletext) {
870: $output.= &Apache::loncommon::start_data_table_row().
871: $roletext.
872: &Apache::loncommon::end_data_table_row();
873: if ($role_text_end) {
874: $output .= &Apache::loncommon::continue_data_table_row().
875: $role_text_end.
876: &Apache::loncommon::end_data_table_row();
877: }
878: }
1.113 raeburn 879: }
1.247 raeburn 880: }
1.111 albertel 881: }
882: if ($output) {
1.212 bisitz 883: $r->print(&Apache::loncommon::start_data_table_empty_row()
884: .'<td align="center" colspan="5">'
1.224 raeburn 885: .$recent
1.212 bisitz 886: .'</td>'
887: .&Apache::loncommon::end_data_table_empty_row()
888: );
1.111 albertel 889: $r->print($output);
1.114 raeburn 890: $doheaders ++;
1.111 albertel 891: }
892: }
1.191 raeburn 893: &print_rolerows($r,$doheaders,\%roleclass,\%sortrole,\%dcroles,\%roletext);
1.202 raeburn 894: if ($countactive > 1) {
895: my $tremark='';
1.212 bisitz 896: my $tbg;
1.202 raeburn 897: if ($env{'request.role'} eq 'cm') {
1.212 bisitz 898: $tbg="LC_roles_selected";
1.204 bisitz 899: $tremark=&mt('Currently selected.').' ';
1.202 raeburn 900: } else {
1.212 bisitz 901: $tbg="LC_roles_is";
1.202 raeburn 902: }
1.212 bisitz 903: $r->print(&Apache::loncommon::start_data_table_row());
1.202 raeburn 904: unless ($nochoose) {
905: if ($env{'request.role'} ne 'cm') {
1.212 bisitz 906: $r->print('<td class="'.$tbg.'"><input type="submit" value="'.
1.202 raeburn 907: &mt('Select').'" name="cm" /></td>');
908: } else {
1.212 bisitz 909: $r->print('<td class="'.$tbg.'"> </td>');
1.202 raeburn 910: }
911: }
1.212 bisitz 912: $r->print('<td colspan="3">'
913: .&mt('No role specified')
914: .'</td>'
915: .'<td>'.$tremark.' </td>'
916: .&Apache::loncommon::end_data_table_row()
917: );
1.202 raeburn 918: }
1.212 bisitz 919: $r->print(&Apache::loncommon::end_data_table());
1.4 www 920: unless ($nochoose) {
921: $r->print("</form>\n");
922: }
1.22 harris41 923: # ------------------------------------------------------------ Privileges Info
1.118 albertel 924: if (($advanced) && (($env{'user.error.msg'}) || ($error))) {
1.212 bisitz 925: $r->print('<hr /><h2>'.&mt('Current Privileges').'</h2>');
1.175 albertel 926: $r->print(&privileges_info());
1.4 www 927: }
1.66 www 928: $r->print(&Apache::lonnet::getannounce());
1.65 www 929: if ($advanced) {
1.201 raeburn 930: my $esc_dom = &HTML::Entities::encode($env{'user.domain'},'"<>&');
1.231 bisitz 931: $r->print('<p><small><i>'
932: .&mt('This LON-CAPA server is version [_1]',$r->dir_config('lonVersion'))
933: .'</i><br />'
934: .'<a href="/adm/logout">'.&mt('Logout').'</a> '
1.201 raeburn 935: .'<a href="/adm/coursecatalog?showdom='.$esc_dom.'">'
1.233 bisitz 936: .&mt('Course/Community Catalog')
1.225 bisitz 937: .'</a></small></p>');
1.65 www 938: }
1.147 albertel 939: $r->print(&Apache::loncommon::end_page());
1.1 harris41 940: return OK;
1.102 raeburn 941: }
942:
1.226 raeburn 943: sub gather_roles {
1.254 raeburn 944: my ($then,$refresh,$now,$reinit,$nochoose,$roletext,$sortrole,$roleclass,$futureroles,$timezones,$loncaparev) = @_;
1.226 raeburn 945: my ($countactive,$countfuture,$inrole,$possiblerole) = (0,0,0,'');
946: my $advanced = $env{'user.adv'};
947: my $tryagain = $env{'form.tryagain'};
1.254 raeburn 948: my @ids = &Apache::lonnet::current_machine_ids();
1.226 raeburn 949: foreach my $envkey (sort(keys(%env))) {
950: my $button = 1;
951: my $switchserver='';
1.254 raeburn 952: my $switchwarning;
1.226 raeburn 953: my ($role_text,$role_text_end,$sortkey);
954: if ($envkey=~/^user\.role\./) {
955: my ($role,$where,$trolecode,$tstart,$tend,$tremark,$tstatus,$tpstart,$tpend);
956: &Apache::lonnet::role_status($envkey,$then,$refresh,$now,\$role,\$where,
957: \$trolecode,\$tstatus,\$tstart,\$tend);
958: next if (!defined($role) || $role eq '' || $role =~ /^gr/);
959: $tremark='';
960: $tpstart=' ';
961: $tpend=' ';
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'})) {
1.256.2.4 raeburn 970: my $timezone = &role_timezone($where,$timezones);
971: if ($tstart) {
972: $tpstart=&Apache::lonlocal::locallocaltime($tstart,$timezone);
973: }
974: if ($tend) {
975: $tpend=&Apache::lonlocal::locallocaltime($tend,$timezone);
976: }
1.226 raeburn 977: if ($tstatus eq 'is') {
978: $tbg='LC_roles_is';
979: $possiblerole=$trolecode;
980: $countactive++;
981: } elsif ($tstatus eq 'future') {
982: $tbg='LC_roles_future';
983: $button=0;
984: $futureroles->{$trolecode} = $tstart.':'.$tend;
985: $countfuture ++;
986: } elsif ($tstatus eq 'expired') {
987: $tbg='LC_roles_expired';
988: $button=0;
989: } elsif ($tstatus eq 'will_not') {
990: $tbg='LC_roles_will_not';
991: $tremark.=&mt('Expired after logout.').' ';
992: } elsif ($tstatus eq 'selected') {
993: $tbg='LC_roles_selected';
994: $inrole=1;
995: $countactive++;
996: $tremark.=&mt('Currently selected.').' ';
997: }
998: my $trole;
999: if ($role =~ /^cr\//) {
1000: my ($rdummy,$rdomain,$rauthor,$rrole)=split(/\//,$role);
1001: if ($tremark) { $tremark.='<br />'; }
1.253 bisitz 1002: $tremark.=&mt('Customrole defined by [_1].',$rauthor.':'.$rdomain);
1.226 raeburn 1003: }
1004: $trole=Apache::lonnet::plaintext($role);
1005: my $ttype;
1006: my $twhere;
1007: my ($tdom,$trest,$tsection)=
1008: split(/\//,Apache::lonnet::declutter($where));
1009: # First, Co-Authorship roles
1010: if (($role eq 'ca') || ($role eq 'aa')) {
1011: my $home = &Apache::lonnet::homeserver($trest,$tdom);
1012: my $allowed=0;
1013: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
1014: if (!$allowed) {
1015: $button=0;
1.248 raeburn 1016: $switchserver='otherserver='.$home.'&role='.$trolecode;
1.226 raeburn 1017: }
1018: #next if ($home eq 'no_host');
1019: $home = &Apache::lonnet::hostname($home);
1020: $ttype='Construction Space';
1021: $twhere=&mt('User').': '.$trest.'<br />'.&mt('Domain').
1022: ': '.$tdom.'<br />'.
1023: ' '.&mt('Server').': '.$home;
1024: $env{'course.'.$tdom.'_'.$trest.'.description'}='ca';
1025: $tremark.=&Apache::lonhtmlcommon::authorbombs('/res/'.$tdom.'/'.$trest.'/');
1026: $sortkey=$role."$trest:$tdom";
1027: } elsif ($role eq 'au') {
1028: # Authors
1029: my $home = &Apache::lonnet::homeserver
1030: ($env{'user.name'},$env{'user.domain'});
1031: my $allowed=0;
1032: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
1033: if (!$allowed) {
1034: $button=0;
1.248 raeburn 1035: $switchserver='otherserver='.$home.'&role='.$trolecode;
1.226 raeburn 1036: }
1037: #next if ($home eq 'no_host');
1038: $home = &Apache::lonnet::hostname($home);
1039: $ttype='Construction Space';
1040: $twhere=&mt('Domain').': '.$tdom.'<br />'.&mt('Server').
1041: ': '.$home;
1042: $env{'course.'.$tdom.'_'.$trest.'.description'}='ca';
1043: $tremark.=&Apache::lonhtmlcommon::authorbombs('/res/'.$tdom.'/'.$env{'user.name'}.'/');
1044: $sortkey=$role;
1045: } elsif ($trest) {
1046: my $tcourseid=$tdom.'_'.$trest;
1047: $ttype = &Apache::loncommon::course_type($tcourseid);
1.242 raeburn 1048: $trole = &Apache::lonnet::plaintext($role,$ttype,$tcourseid);
1.226 raeburn 1049: if ($env{'course.'.$tcourseid.'.description'}) {
1.254 raeburn 1050: my $home=$env{'course.'.$tcourseid.'.home'};
1.226 raeburn 1051: $twhere=$env{'course.'.$tcourseid.'.description'};
1052: $sortkey=$role."\0".$tdom."\0".$twhere."\0".$envkey;
1.248 raeburn 1053: $twhere = &HTML::Entities::encode($twhere,'"<>&');
1.226 raeburn 1054: unless ($twhere eq &mt('Currently not available')) {
1055: $twhere.=' <span class="LC_fontsize_small">'.
1056: &Apache::loncommon::syllabuswrapper(&mt('Syllabus'),$trest,$tdom).
1057: '</span>';
1.254 raeburn 1058: unless ($home && grep(/^\Q$home\E$/,@ids) && $loncaparev eq '') {
1.255 raeburn 1059: my $required = $env{'course.'.$tcourseid.'.internal.releaserequired'};
1.256.2.4 raeburn 1060: if ($required ne '') {
1061: ($switchserver,$switchwarning) =
1062: &check_release_required($loncaparev,$tcourseid,$trolecode,$required);
1063: if ($switchserver || $switchwarning) {
1064: $button = 0;
1065: }
1.254 raeburn 1066: }
1067: }
1.226 raeburn 1068: }
1069: } else {
1070: my %newhash=&Apache::lonnet::coursedescription($tcourseid);
1071: if (%newhash) {
1072: $sortkey=$role."\0".$tdom."\0".$newhash{'description'}.
1073: "\0".$envkey;
1.248 raeburn 1074: $twhere=&HTML::Entities::encode($newhash{'description'},'"<>&').
1075: ' <span class="LC_fontsize_small">'.
1076: &Apache::loncommon::syllabuswrapper(&mt('Syllabus'),$trest,$tdom).
1077: '</span>';
1.226 raeburn 1078: $ttype = $newhash{'type'};
1.243 raeburn 1079: $trole = &Apache::lonnet::plaintext($role,$ttype,$tcourseid);
1.254 raeburn 1080: my $home = $newhash{'home'};
1081: unless ($home && grep(/^\Q$home\E$/,@ids) && $loncaparev eq '') {
1.255 raeburn 1082: my $required = $newhash{'internal.releaserequired'};
1.256.2.4 raeburn 1083: if ($required ne '') {
1084: ($switchserver,$switchwarning) =
1085: &check_release_required($loncaparev,$tcourseid,$trolecode,$required);
1086: if ($switchserver || $switchwarning) {
1087: $button = 0;
1088: }
1.254 raeburn 1089: }
1090: }
1.226 raeburn 1091: } else {
1092: $twhere=&mt('Currently not available');
1093: $env{'course.'.$tcourseid.'.description'}=$twhere;
1094: $sortkey=$role."\0".$tdom."\0".$twhere."\0".$envkey;
1095: $ttype = 'Unavailable';
1096: }
1097: }
1098: if ($tsection) {
1099: $twhere.='<br />'.&mt('Section').': '.$tsection;
1100: }
1101: if ($role ne 'st') { $twhere.="<br />".&mt('Domain').":".$tdom; }
1102: } elsif ($tdom) {
1103: $ttype='Domain';
1104: $twhere=$tdom;
1105: $sortkey=$role.$twhere;
1106: } else {
1107: $ttype='System';
1108: $twhere=&mt('system wide');
1109: $sortkey=$role.$twhere;
1110: }
1111: ($role_text,$role_text_end) =
1112: &build_roletext($trolecode,$tdom,$trest,$tstatus,$tryagain,
1113: $advanced,$tremark,$tbg,$trole,$twhere,$tpstart,
1.254 raeburn 1114: $tpend,$nochoose,$button,$switchserver,$reinit,$switchwarning);
1.226 raeburn 1115: $roletext->{$envkey}=[$role_text,$role_text_end];
1116: if (!$sortkey) {$sortkey=$twhere."\0".$envkey;}
1117: $sortrole->{$sortkey}=$envkey;
1118: $roleclass->{$envkey}=$ttype;
1119: }
1120: }
1121: }
1122: return ($countactive,$countfuture,$inrole,$possiblerole);
1123: }
1124:
1.215 raeburn 1125: sub role_timezone {
1126: my ($where,$timezones) = @_;
1127: my $timezone;
1128: if (ref($timezones) eq 'HASH') {
1129: if ($where =~ m{^/($match_domain)/($match_courseid)}) {
1130: my $cdom = $1;
1131: my $cnum = $2;
1132: if ($cdom && $cnum) {
1133: if (!exists($timezones->{$cdom.'_'.$cnum})) {
1.256.2.4 raeburn 1134: my $tz;
1135: if ($env{'course.'.$cdom.'_'.$cnum.'.description'}) {
1136: $tz = $env{'course.'.$cdom.'_'.$cnum.'.timezone'};
1137: } else {
1138: my %timehash =
1139: &Apache::lonnet::get('environment',['timezone'],$cdom,$cnum);
1140: $tz = $timehash{'timezone'};
1141: }
1142: if ($tz eq '') {
1.215 raeburn 1143: if (!exists($timezones->{$cdom})) {
1144: my %domdefaults =
1145: &Apache::lonnet::get_domain_defaults($cdom);
1146: if ($domdefaults{'timezone_def'} eq '') {
1147: $timezones->{$cdom} = 'local';
1148: } else {
1149: $timezones->{$cdom} = $domdefaults{'timezone_def'};
1150: }
1151: }
1152: $timezones->{$cdom.'_'.$cnum} = $timezones->{$cdom};
1153: } else {
1154: $timezones->{$cdom.'_'.$cnum} =
1.256.2.4 raeburn 1155: &Apache::lonlocal::gettimezone($tz);
1.215 raeburn 1156: }
1157: }
1158: $timezone = $timezones->{$cdom.'_'.$cnum};
1159: }
1160: } else {
1161: my ($tdom) = ($where =~ m{^/($match_domain)});
1162: if ($tdom) {
1163: if (!exists($timezones->{$tdom})) {
1164: my %domdefaults = &Apache::lonnet::get_domain_defaults($tdom);
1165: if ($domdefaults{'timezone_def'} eq '') {
1166: $timezones->{$tdom} = 'local';
1167: } else {
1168: $timezones->{$tdom} = $domdefaults{'timezone_def'};
1169: }
1170: }
1171: $timezone = $timezones->{$tdom};
1172: }
1173: }
1174: if ($timezone eq 'local') {
1175: $timezone = undef;
1176: }
1177: }
1178: return $timezone;
1179: }
1180:
1.191 raeburn 1181: sub roletable_headers {
1182: my ($r,$roleclass,$sortrole,$nochoose) = @_;
1183: my $doheaders;
1184: if ((ref($sortrole) eq 'HASH') && (ref($roleclass) eq 'HASH')) {
1.212 bisitz 1185: $r->print('<br />'
1186: .&Apache::loncommon::start_data_table()
1187: .&Apache::loncommon::start_data_table_header_row()
1188: );
1.191 raeburn 1189: if (!$nochoose) { $r->print('<th> </th>'); }
1.212 bisitz 1190: $r->print('<th>'.&mt('User Role').'</th>'
1191: .'<th>'.&mt('Extent').'</th>'
1192: .'<th>'.&mt('Start').'</th>'
1193: .'<th>'.&mt('End').'</th>'
1194: .&Apache::loncommon::end_data_table_header_row()
1195: );
1.191 raeburn 1196: $doheaders=-1;
1197: my @roletypes = &roletypes();
1198: foreach my $type (@roletypes) {
1199: my $haverole=0;
1200: foreach my $which (sort {uc($a) cmp uc($b)} (keys(%{$sortrole}))) {
1201: if ($roleclass->{$sortrole->{$which}} =~ /^\Q$type\E/) {
1202: $haverole=1;
1203: }
1204: }
1205: if ($haverole) { $doheaders++; }
1206: }
1207: }
1208: return $doheaders;
1209: }
1210:
1211: sub roletypes {
1.237 raeburn 1212: my @types = ('Domain','Construction Space','Course','Community','Unavailable','System');
1.191 raeburn 1213: return @types;
1214: }
1215:
1216: sub print_rolerows {
1217: my ($r,$doheaders,$roleclass,$sortrole,$dcroles,$roletext) = @_;
1218: if ((ref($roleclass) eq 'HASH') && (ref($sortrole) eq 'HASH')) {
1219: my @types = &roletypes();
1220: foreach my $type (@types) {
1221: my $output;
1222: foreach my $which (sort {uc($a) cmp uc($b)} (keys(%{$sortrole}))) {
1223: if ($roleclass->{$sortrole->{$which}} =~ /^\Q$type\E/) {
1224: if (ref($roletext) eq 'HASH') {
1.223 raeburn 1225: if (ref($roletext->{$sortrole->{$which}}) eq 'ARRAY') {
1226: $output.= &Apache::loncommon::start_data_table_row().
1227: $roletext->{$sortrole->{$which}}->[0].
1228: &Apache::loncommon::end_data_table_row();
1.251 raeburn 1229: if ($roletext->{$sortrole->{$which}}->[1] ne '') {
1230: $output .= &Apache::loncommon::continue_data_table_row().
1231: $roletext->{$sortrole->{$which}}->[1].
1232: &Apache::loncommon::end_data_table_row();
1233: }
1.223 raeburn 1234: }
1.191 raeburn 1235: if ($sortrole->{$which} =~ m-dc\./($match_domain)/-) {
1236: if (ref($dcroles) eq 'HASH') {
1237: if ($dcroles->{$1}) {
1.192 raeburn 1238: $output .= &adhoc_roles_row($1,'');
1.191 raeburn 1239: }
1240: }
1241: }
1242: }
1243: }
1244: }
1245: if ($output) {
1246: if ($doheaders > 0) {
1.212 bisitz 1247: $r->print(&Apache::loncommon::start_data_table_empty_row()
1248: .'<td align="center" colspan="5">'
1249: .&mt($type)
1250: .'</td>'
1251: .&Apache::loncommon::end_data_table_empty_row()
1252: );
1.191 raeburn 1253: }
1254: $r->print($output);
1255: }
1256: }
1257: }
1258: }
1259:
1260: sub findcourse_advice {
1261: my ($r) = @_;
1262: my $domdesc = &Apache::lonnet::domain($env{'user.domain'},'description');
1.201 raeburn 1263: my $esc_dom = &HTML::Entities::encode($env{'user.domain'},'"<>&');
1.200 raeburn 1264: if (&Apache::lonnet::auto_run(undef,$env{'user.domain'})) {
1.191 raeburn 1265: $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).'
1266: <ul>
1267: <li>'.&mt('The course has yet to be created.').'</li>
1268: <li>'.&mt('Automatic enrollment of registered students has not been enabled for the course.').'</li>
1269: <li>'.&mt('You are in a section of course for which automatic enrollment in the corresponding LON-CAPA course is not active.').'</li>
1270: <li>'.&mt('The start date for automated enrollment has yet to be reached.').'</li>
1271: <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>
1272: </ul>');
1273: } else {
1274: $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 />');
1275: }
1.235 bisitz 1276: $r->print('<h3>'.&mt('Self-Enrollment').'</h3>'.
1.234 raeburn 1277: '<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 1278: $r->print(&mt('You can search for courses and communities which permit self-enrollment, if you would like to enroll in one.').'</p>'.
1279: &Apache::loncoursequeueadmin::queued_selfenrollment());
1.216 raeburn 1280: return;
1281: }
1282:
1.234 raeburn 1283: sub requestcourse_advice {
1284: my ($r) = @_;
1285: my $domdesc = &Apache::lonnet::domain($env{'user.domain'},'description');
1286: my $esc_dom = &HTML::Entities::encode($env{'user.domain'},'"<>&');
1287: my (%can_request,%request_doms);
1288: &Apache::lonnet::check_can_request($env{'user.domain'},\%can_request,\%request_doms);
1289: if (keys(%request_doms) > 0) {
1290: my ($types,$typename) = &Apache::loncommon::course_types();
1291: if ((ref($types) eq 'ARRAY') && (ref($typename) eq 'HASH')) {
1292: $r->print('<h3>'.&mt('Request creation of a course or community').'</h3>'.
1.238 bisitz 1293: '<p>'.&mt('You have rights to request the creation of courses and/or communities in the following domain(s):').'<ul>');
1.234 raeburn 1294: my (@reqdoms,@reqtypes);
1295: foreach my $type (sort(keys(%request_doms))) {
1296: push(@reqtypes,$type);
1297: if (ref($request_doms{$type}) eq 'ARRAY') {
1298: my $domstr = join(', ',map { &Apache::lonnet::domain($_) } sort(@{$request_doms{$type}}));
1.238 bisitz 1299: $r->print(
1300: '<li>'
1301: .&mt('[_1]'.$typename->{$type}.'[_2] in domain: [_3]',
1302: '<i>',
1303: '</i>',
1304: '<b>'.$domstr.'</b>')
1305: .'</li>'
1306: );
1.234 raeburn 1307: foreach my $dom (@{$request_doms{$type}}) {
1308: unless (grep(/^\Q$dom\E/,@reqdoms)) {
1309: push(@reqdoms,$dom);
1310: }
1311: }
1312: }
1313: }
1314: my @showtypes;
1315: foreach my $type (@{$types}) {
1316: if (grep(/^\Q$type\E$/,@reqtypes)) {
1317: push(@showtypes,$type);
1318: }
1319: }
1320: my $requrl = '/adm/requestcourse';
1321: if (@reqdoms == 1) {
1322: $requrl .= '?showdom='.$reqdoms[0];
1323: }
1324: if (@showtypes > 0) {
1325: $requrl.=(($requrl=~/\?/)?'&':'?').'crstype='.$showtypes[0];
1326: }
1327: if (@reqdoms == 1 || @showtypes > 0) {
1328: $requrl .= '&state=crstype&action=new';
1329: }
1330: $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>');
1331: }
1332: }
1333: return;
1334: }
1335:
1.175 albertel 1336: sub privileges_info {
1337: my ($which) = @_;
1338: my $output;
1339:
1340: $which ||= $env{'request.role'};
1341:
1342: foreach my $envkey (sort(keys(%env))) {
1343: next if ($envkey!~/^user\.priv\.\Q$which\E\.(.*)/);
1344:
1345: my $where=$1;
1346: my $ttype;
1347: my $twhere;
1348: my (undef,$tdom,$trest,$tsec)=split(m{/},$where);
1349: if ($trest) {
1350: if ($env{'course.'.$tdom.'_'.$trest.'.description'} eq 'ca') {
1351: $ttype='Construction Space';
1352: $twhere='User: '.$trest.', Domain: '.$tdom;
1353: } else {
1354: $ttype= &Apache::loncommon::course_type($tdom.'_'.$trest);
1355: $twhere=$env{'course.'.$tdom.'_'.$trest.'.description'};
1356: if ($tsec) {
1357: my $sec_type = 'Section';
1358: if (exists($env{"user.role.gr.$where"})) {
1359: $sec_type = 'Group';
1360: }
1361: $twhere.=' ('.$sec_type.': '.$tsec.')';
1362: }
1363: }
1364: } elsif ($tdom) {
1365: $ttype='Domain';
1366: $twhere=$tdom;
1367: } else {
1368: $ttype='System';
1369: $twhere='/';
1370: }
1.204 bisitz 1371: $output .= "\n<h3>".&mt($ttype).': '.$twhere.'</h3>'."\n<ul>";
1.175 albertel 1372: foreach my $priv (sort(split(/:/,$env{$envkey}))) {
1373: next if (!$priv);
1374:
1375: my ($prv,$restr)=split(/\&/,$priv);
1376: my $trestr='';
1377: if ($restr ne 'F') {
1378: $trestr.=' ('.
1379: join(', ',
1380: map { &Apache::lonnet::plaintext($_) }
1381: (split('',$restr))).') ';
1382: }
1383: $output .= "\n\t".
1384: '<li>'.&Apache::lonnet::plaintext($prv).$trestr.'</li>';
1385: }
1386: $output .= "\n".'</ul>';
1387: }
1388: return $output;
1389: }
1390:
1.110 raeburn 1391: sub build_roletext {
1.254 raeburn 1392: my ($trolecode,$tdom,$trest,$tstatus,$tryagain,$advanced,$tremark,$tbg,$trole,$twhere,$tpstart,$tpend,$nochoose,$button,$switchserver,$reinit,$switchwarning) = @_;
1.223 raeburn 1393: my ($roletext,$roletext_end);
1.132 albertel 1394: my $is_dc=($trolecode =~ m/^dc\./);
1395: my $rowspan=($is_dc) ? ''
1396: : ' rowspan="2" ';
1397:
1.110 raeburn 1398: unless ($nochoose) {
1.134 www 1399: my $buttonname=$trolecode;
1400: $buttonname=~s/\W//g;
1.110 raeburn 1401: if (!$button) {
1402: if ($switchserver) {
1.212 bisitz 1403: $roletext.='<td'.$rowspan.' class="'.$tbg.'">'
1404: .'<a href="/adm/switchserver?'.$switchserver.'">'
1405: .&mt('Switch Server')
1406: .'</a></td>';
1.110 raeburn 1407: } else {
1.212 bisitz 1408: $roletext.=('<td'.$rowspan.' class="'.$tbg.'"> </td>');
1.110 raeburn 1409: }
1.255 raeburn 1410: if ($switchwarning) {
1411: if ($tremark eq '') {
1412: $tremark = $switchwarning;
1413: } else {
1414: $tremark .= '<br />'.$switchwarning;
1415: }
1416: }
1.110 raeburn 1417: } elsif ($tstatus eq 'is') {
1.212 bisitz 1418: $roletext.='<td'.$rowspan.' class="'.$tbg.'">'.
1419: '<input name="'.$buttonname.'" type="button" value="'.
1.225 bisitz 1420: &mt('Select').'" onclick="javascript:enterrole(this.form,\''.
1.192 raeburn 1421: $trolecode."','".$buttonname.'\');" /></td>';
1.110 raeburn 1422: } elsif ($tryagain) {
1423: $roletext.=
1.212 bisitz 1424: '<td'.$rowspan.' class="'.$tbg.'">'.
1425: '<input name="'.$buttonname.'" type="button" value="'.
1.225 bisitz 1426: &mt('Try Selecting Again').'" onclick="javascript:enterrole(this.form,\''.
1.192 raeburn 1427: $trolecode."','".$buttonname.'\');" /></td>';
1.110 raeburn 1428: } elsif ($advanced) {
1429: $roletext.=
1.212 bisitz 1430: '<td'.$rowspan.' class="'.$tbg.'">'.
1431: '<input name="'.$buttonname.'" type="button" value="'.
1.225 bisitz 1432: &mt('Re-Initialize').'" onclick="javascript:enterrole(this.form,\''.
1.192 raeburn 1433: $trolecode."','".$buttonname.'\');" /></td>';
1.209 raeburn 1434: } elsif ($reinit) {
1435: $roletext.=
1.212 bisitz 1436: '<td'.$rowspan.' class="'.$tbg.'">'.
1437: '<input name="'.$buttonname.'" type="button" value="'.
1.225 bisitz 1438: &mt('Re-Select').'" onclick="javascript:enterrole(this.form,\''.
1.209 raeburn 1439: $trolecode."','".$buttonname.'\');" /></td>';
1.110 raeburn 1440: } else {
1.209 raeburn 1441: $roletext.=
1.212 bisitz 1442: '<td'.$rowspan.' class="'.$tbg.'">'.
1443: '<input name="'.$buttonname.'" type="button" value="'.
1.225 bisitz 1444: &mt('Re-Select').'" onclick="javascript:enterrole(this.form,\''.
1.209 raeburn 1445: $trolecode."','".$buttonname.'\');" /></td>';
1.110 raeburn 1446: }
1447: }
1.165 albertel 1448: if ($trolecode !~ m/^(dc|ca|au|aa)\./) {
1449: $tremark.=&Apache::lonannounce::showday(time,1,
1450: &Apache::lonannounce::readcalendar($tdom.'_'.$trest));
1451: }
1.212 bisitz 1452: $roletext.='<td>'.$trole.'</td>'
1453: .'<td>'.$twhere.'</td>'
1454: .'<td>'.$tpstart.'</td>'
1.223 raeburn 1455: .'<td>'.$tpend.'</td>';
1.132 albertel 1456: if (!$is_dc) {
1.223 raeburn 1457: $roletext_end = '<td colspan="4">'.
1458: $tremark.' '.
1459: '</td>';
1.132 albertel 1460: }
1.223 raeburn 1461: return ($roletext,$roletext_end);
1.110 raeburn 1462: }
1463:
1.202 raeburn 1464: sub check_needs_switchserver {
1465: my ($possiblerole) = @_;
1466: my $needs_switchserver;
1467: my ($role,$where) = split(/\./,$possiblerole,2);
1468: my (undef,$tdom,$twho) = split(/\//,$where);
1469: my ($server_status,$home);
1470: if (($role eq 'ca') || ($role eq 'aa')) {
1471: ($server_status,$home) = &check_author_homeserver($twho,$tdom);
1472: } else {
1473: ($server_status,$home) = &check_author_homeserver($env{'user.name'},
1474: $env{'user.domain'});
1475: }
1476: if ($server_status eq 'switchserver') {
1477: $needs_switchserver = 1;
1478: }
1479: return $needs_switchserver;
1480: }
1481:
1.193 raeburn 1482: sub check_author_homeserver {
1.183 www 1483: my ($uname,$udom)=@_;
1.193 raeburn 1484: if (($uname eq '') || ($udom eq '')) {
1485: return ('fail','');
1486: }
1.183 www 1487: my $home = &Apache::lonnet::homeserver($uname,$udom);
1.193 raeburn 1488: if (&Apache::lonnet::host_domain($home) ne $udom) {
1489: return ('fail',$home);
1490: }
1.183 www 1491: my @ids=&Apache::lonnet::current_machine_ids();
1.193 raeburn 1492: if (grep(/^\Q$home\E$/,@ids)) {
1493: return ('ok',$home);
1494: } else {
1495: return ('switchserver',$home);
1.183 www 1496: }
1497: }
1498:
1.104 raeburn 1499: sub check_fordc {
1500: my ($dcroles,$then) = @_;
1501: my $numdc = 0;
1.118 albertel 1502: if ($env{'user.adv'}) {
1503: foreach my $envkey (sort keys %env) {
1.170 albertel 1504: if ($envkey=~/^user\.role\.dc\.\/($match_domain)\/$/) {
1.104 raeburn 1505: my $dcdom = $1;
1506: my $livedc = 1;
1.118 albertel 1507: my ($tstart,$tend)=split(/\./,$env{$envkey});
1.105 raeburn 1508: if ($tstart && $tstart>$then) { $livedc = 0; }
1509: if ($tend && $tend <$then) { $livedc = 0; }
1.104 raeburn 1510: if ($livedc) {
1511: $$dcroles{$dcdom} = $envkey;
1.105 raeburn 1512: $numdc++;
1.104 raeburn 1513: }
1514: }
1515: }
1516: }
1517: return $numdc;
1518: }
1519:
1.185 raeburn 1520: sub adhoc_course_role {
1.232 raeburn 1521: my ($refresh,$then) = @_;
1.239 raeburn 1522: my ($cdom,$cnum,$crstype);
1.201 raeburn 1523: $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
1524: $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.239 raeburn 1525: $crstype = &Apache::loncommon::course_type();
1526: if (&check_forcc($cdom,$cnum,$refresh,$then,$crstype)) {
1.185 raeburn 1527: my $setprivs;
1.198 raeburn 1528: if (!defined($env{'user.role.'.$env{'form.switchrole'}})) {
1.185 raeburn 1529: $setprivs = 1;
1530: } else {
1.198 raeburn 1531: my ($start,$end) = split(/\./,$env{'user.role.'.$env{'form.switchrole'}});
1.232 raeburn 1532: if (($start && ($start>$refresh || $start == -1)) ||
1.185 raeburn 1533: ($end && $end<$then)) {
1534: $setprivs = 1;
1535: }
1.232 raeburn 1536: }
1.185 raeburn 1537: if ($setprivs) {
1.198 raeburn 1538: if ($env{'form.switchrole'} =~ m-^(in|ta|ep|ad|st|cr)([\w/]*)\./\Q$cdom\E/\Q$cnum\E/?(\w*)$-) {
1.185 raeburn 1539: my $role = $1;
1540: my $custom_role = $2;
1541: my $usec = $3;
1542: if ($role eq 'cr') {
1.199 raeburn 1543: if ($custom_role =~ m-^/$match_domain/$match_username/\w+$-) {
1.185 raeburn 1544: $role .= $custom_role;
1545: } else {
1546: return;
1547: }
1548: }
1.208 raeburn 1549: my (%userroles,%newrole,%newgroups,%group_privs);
1550: my %cgroups =
1551: &Apache::lonnet::get_active_groups($env{'user.domain'},
1552: $env{'user.name'},$cdom,$cnum);
1553: foreach my $group (keys(%cgroups)) {
1554: $group_privs{$group} =
1555: $env{'user.priv.cc./'.$cdom.'/'.$cnum.'./'.$cdom.'/'.$cnum.'/'.$group};
1556: }
1557: $newgroups{'/'.$cdom.'/'.$cnum} = \%group_privs;
1.185 raeburn 1558: my $area = '/'.$cdom.'/'.$cnum;
1559: my $spec = $role.'.'.$area;
1560: if ($usec ne '') {
1561: $spec .= '/'.$usec;
1562: $area .= '/'.$usec;
1563: }
1564: &Apache::lonnet::standard_roleprivs(\%newrole,$role,$cdom,$spec,$cnum,$area);
1.208 raeburn 1565: &Apache::lonnet::set_userprivs(\%userroles,\%newrole,\%newgroups);
1.232 raeburn 1566: my $adhocstart = $refresh-1;
1.185 raeburn 1567: $userroles{'user.role.'.$spec} = $adhocstart.'.';
1.186 raeburn 1568: &Apache::lonnet::appenv(\%userroles,[$role,'cm']);
1.185 raeburn 1569: }
1570: }
1571: }
1572: return;
1573: }
1574:
1575: sub check_forcc {
1.239 raeburn 1576: my ($cdom,$cnum,$refresh,$then,$crstype) = @_;
1577: my ($is_cc,$ccrole);
1578: if ($crstype eq 'Community') {
1579: $ccrole = 'co';
1580: } else {
1581: $ccrole = 'cc';
1582: }
1.185 raeburn 1583: if ($cdom ne '' && $cnum ne '') {
1584: if (&Apache::lonnet::is_course($cdom,$cnum)) {
1.239 raeburn 1585: my $envkey = 'user.role.'.$ccrole.'./'.$cdom.'/'.$cnum;
1.185 raeburn 1586: if (defined($env{$envkey})) {
1587: $is_cc = 1;
1588: my ($tstart,$tend)=split(/\./,$env{$envkey});
1.232 raeburn 1589: if ($tstart && $tstart>$refresh) { $is_cc = 0; }
1.185 raeburn 1590: if ($tend && $tend <$then) { $is_cc = 0; }
1591: }
1592: }
1593: }
1594: return $is_cc;
1595: }
1596:
1.254 raeburn 1597: sub check_release_required {
1.255 raeburn 1598: my ($loncaparev,$tcourseid,$trolecode,$required) = @_;
1.254 raeburn 1599: my ($switchserver,$warning);
1.255 raeburn 1600: if ($required ne '') {
1601: my ($reqdmajor,$reqdminor) = ($required =~ /^(\d+)\.(\d+)$/);
1.256.2.2 raeburn 1602: my ($major,$minor) = ($loncaparev =~ /^\'?(\d+)\.(\d+)\.[\w.\-]+\'?$/);
1.254 raeburn 1603: if ($reqdmajor ne '' && $reqdminor ne '') {
1604: my $otherserver;
1605: if (($major eq '' && $minor eq '') ||
1606: (($reqdmajor > $major) || (($reqdmajor == $major) && ($reqdminor > $minor)))) {
1.256.2.8! raeburn 1607: my ($userdomserver) = &Apache::lonnet::choose_server($env{'user.domain'},undef,$required,1);
1.254 raeburn 1608: my $switchlcrev =
1609: &Apache::lonnet::get_server_loncaparev($env{'user.domain'},
1610: $userdomserver);
1.256.2.2 raeburn 1611: my ($swmajor,$swminor) = ($switchlcrev =~ /^\'?(\d+)\.(\d+)\.[\w.\-]+\'?$/);
1.254 raeburn 1612: if (($swmajor eq '' && $swminor eq '') || ($reqdmajor > $swmajor) ||
1613: (($reqdmajor == $swmajor) && ($reqdminor > $swminor))) {
1614: my $cdom = $env{'course.'.$tcourseid.'.domain'};
1615: if ($cdom ne $env{'user.domain'}) {
1.256.2.8! raeburn 1616: my ($coursedomserver,$coursehostname) = &Apache::lonnet::choose_server($cdom,undef,$required,1);
1.254 raeburn 1617: my $serverhomeID = &Apache::lonnet::get_server_homeID($coursehostname);
1618: my $serverhomedom = &Apache::lonnet::host_domain($serverhomeID);
1619: my %defdomdefaults = &Apache::lonnet::get_domain_defaults($serverhomedom);
1620: my %udomdefaults = &Apache::lonnet::get_domain_defaults($env{'user.domain'});
1621: my $remoterev = &Apache::lonnet::get_server_loncaparev($serverhomedom,$coursedomserver);
1622: my $canhost =
1623: &Apache::lonnet::can_host_session($env{'user.domain'},
1624: $coursedomserver,
1625: $remoterev,
1626: $udomdefaults{'remotesessions'},
1627: $defdomdefaults{'hostedsessions'});
1628:
1629: if ($canhost) {
1630: $otherserver = $coursedomserver;
1631: } else {
1632: $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.");
1633: }
1634: } else {
1635: $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).");
1636: }
1637: } else {
1638: $otherserver = $userdomserver;
1639: }
1640: }
1641: if ($otherserver ne '') {
1642: $switchserver = 'otherserver='.$otherserver.'&role='.$trolecode;
1643: }
1644: }
1645: }
1646: return ($switchserver,$warning);
1647: }
1648:
1.255 raeburn 1649: sub update_content_constraints {
1650: my ($cdom,$cnum,$chome,$cid) = @_;
1651: my %curr_reqd_hash = &Apache::lonnet::userenvironment($cdom,$cnum,'internal.releaserequired');
1652: my ($reqdmajor,$reqdminor) = split(/\./,$curr_reqd_hash{'internal.releaserequired'});
1653: my %checkresponsetypes;
1654: foreach my $key (keys(%Apache::lonnet::needsrelease)) {
1655: my ($item,$name,$value) = split(/:/,$key);
1656: if ($item eq 'resourcetag') {
1657: if ($name eq 'responsetype') {
1658: $checkresponsetypes{$value} = $Apache::lonnet::needsrelease{$key}
1659: }
1660: }
1661: }
1662: my $navmap = Apache::lonnavmaps::navmap->new();
1663: if (defined($navmap)) {
1664: my %allresponses;
1665: foreach my $res ($navmap->retrieveResources(undef,sub { $_[0]->is_problem() },1,0)) {
1666: my %responses = $res->responseTypes();
1667: foreach my $key (keys(%responses)) {
1668: next unless(exists($checkresponsetypes{$key}));
1669: $allresponses{$key} += $responses{$key};
1670: }
1671: }
1672: foreach my $key (keys(%allresponses)) {
1673: my ($major,$minor) = split(/\./,$checkresponsetypes{$key});
1674: if (($major > $reqdmajor) || ($major == $reqdmajor && $minor > $reqdminor)) {
1675: ($reqdmajor,$reqdminor) = ($major,$minor);
1676: }
1677: }
1678: undef($navmap);
1679: }
1680: unless (($reqdmajor eq '') && ($reqdminor eq '')) {
1681: &Apache::lonnet::update_released_required($reqdmajor.'.'.$reqdminor,$cdom,$cnum,$chome,$cid);
1682: }
1683: return;
1684: }
1685:
1.108 raeburn 1686: sub courselink {
1.193 raeburn 1687: my ($dcdom,$rowtype) = @_;
1.109 raeburn 1688: my $courseform=&Apache::loncommon::selectcourse_link
1.152 raeburn 1689: ('rolechoice','dccourse'.$rowtype.'_'.$dcdom,
1690: 'dcdomain'.$rowtype.'_'.$dcdom,'coursedesc'.$rowtype.'_'.
1.239 raeburn 1691: $dcdom,$dcdom,undef,'Course/Community');
1.138 raeburn 1692: my $hiddenitems = '<input type="hidden" name="dcdomain'.$rowtype.'_'.$dcdom.'" value="'.$dcdom.'" />'.
1693: '<input type="hidden" name="origdom'.$rowtype.'_'.$dcdom.'" value="'.$dcdom.'" />'.
1694: '<input type="hidden" name="dccourse'.$rowtype.'_'.$dcdom.'" value="" />'.
1695: '<input type="hidden" name="coursedesc'.$rowtype.'_'.$dcdom.'" value="" />';
1.112 raeburn 1696: return $courseform.$hiddenitems;
1.109 raeburn 1697: }
1698:
1699: sub coursepick_jscript {
1.184 raeburn 1700: my %lt = &Apache::lonlocal::texthash(
1.239 raeburn 1701: 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 1702: youc => 'You can only use this screen to select courses and communities in the current domain.',
1.184 raeburn 1703: );
1.104 raeburn 1704: my $verify_script = <<"END";
1.179 raeburn 1705: <script type="text/javascript">
1.225 bisitz 1706: // <![CDATA[
1.108 raeburn 1707: function verifyCoursePick(caller) {
1708: var numbutton = getIndex(caller)
1.112 raeburn 1709: var pickedCourse = document.rolechoice.elements[numbutton+4].value
1710: var pickedDomain = document.rolechoice.elements[numbutton+2].value
1711: if (document.rolechoice.elements[numbutton+2].value == document.rolechoice.elements[numbutton+3].value) {
1.104 raeburn 1712: if (pickedCourse != '') {
1.108 raeburn 1713: if (numbutton != -1) {
1714: var courseTarget = "cc./"+pickedDomain+"/"+pickedCourse
1715: document.rolechoice.elements[numbutton+1].name = courseTarget
1716: document.rolechoice.submit()
1717: }
1.104 raeburn 1718: }
1719: else {
1.184 raeburn 1720: alert("$lt{'plsu'}");
1.104 raeburn 1721: }
1722: }
1723: else {
1.184 raeburn 1724: alert("$lt{'youc'}")
1.104 raeburn 1725: }
1726: }
1.109 raeburn 1727: function getIndex(caller) {
1.108 raeburn 1728: for (var i=0;i<document.rolechoice.elements.length;i++) {
1.109 raeburn 1729: if (document.rolechoice.elements[i] == caller) {
1.108 raeburn 1730: return i;
1731: }
1732: }
1733: return -1;
1734: }
1.225 bisitz 1735: // ]]>
1.104 raeburn 1736: </script>
1737: END
1.109 raeburn 1738: return $verify_script;
1.104 raeburn 1739: }
1740:
1.193 raeburn 1741: sub coauthorlink {
1742: my ($dcdom,$rowtype) = @_;
1743: my $coauthorform=&Apache::loncommon::selectauthor_link('rolechoice',$dcdom);
1744: my $hiddenitems = '<input type="hidden" name="adhoccauname'.$rowtype.'_'.$dcdom.'" value="" />';
1745: return $coauthorform.$hiddenitems;
1746: }
1747:
1.113 raeburn 1748: sub display_cc_role {
1749: my $rolekey = shift;
1.223 raeburn 1750: my ($roletext,$roletext_end);
1.118 albertel 1751: my $advanced = $env{'user.adv'};
1752: my $tryagain = $env{'form.tryagain'};
1.113 raeburn 1753: unless ($rolekey =~/^error\:/) {
1.240 raeburn 1754: if ($rolekey =~ m{^user\.role\.(cc|co)\./($match_domain)/($match_courseid)$}) {
1755: my $ccrole = $1;
1.249 raeburn 1756: my $tdom = $2;
1757: my $trest = $3;
1758: my $tcourseid = $tdom.'_'.$trest;
1759: my $trolecode = $ccrole.'./'.$tdom.'/'.$trest;
1.113 raeburn 1760: my $twhere;
1.152 raeburn 1761: my $ttype;
1.212 bisitz 1762: my $tbg='LC_roles_is';
1.113 raeburn 1763: my %newhash=&Apache::lonnet::coursedescription($tcourseid);
1764: if (%newhash) {
1765: $twhere=$newhash{'description'}.
1.256.2.6 raeburn 1766: ' <span class="LC_fontsize_small">'.
1.249 raeburn 1767: &Apache::loncommon::syllabuswrapper(&mt('Syllabus'),$trest,$tdom).
1.211 tempelho 1768: '</span>';
1.153 raeburn 1769: $ttype = $newhash{'type'};
1.113 raeburn 1770: } else {
1771: $twhere=&mt('Currently not available');
1.118 albertel 1772: $env{'course.'.$tcourseid.'.description'}=$twhere;
1.110 raeburn 1773: }
1.242 raeburn 1774: my $trole = &Apache::lonnet::plaintext($ccrole,$ttype,$tcourseid);
1.256.2.3 raeburn 1775: $twhere.="<br />".&mt('Domain').":".$tdom;
1.249 raeburn 1776: ($roletext,$roletext_end) = &build_roletext($trolecode,$tdom,$trest,'is',$tryagain,$advanced,'',$tbg,$trole,$twhere,'','','',1,'');
1.104 raeburn 1777: }
1778: }
1.223 raeburn 1779: return ($roletext,$roletext_end);
1.104 raeburn 1780: }
1781:
1.192 raeburn 1782: sub adhoc_roles_row {
1.138 raeburn 1783: my ($dcdom,$rowtype) = @_;
1.212 bisitz 1784: my $output = &Apache::loncommon::continue_data_table_row()
1785: .' <td colspan="5">'
1786: .&mt('[_1]Ad hoc[_2] roles in domain [_3] --'
1787: ,'<span class="LC_cusr_emph">','</span>',$dcdom)
1.227 bisitz 1788: .' ';
1.193 raeburn 1789: my $selectcclink = &courselink($dcdom,$rowtype);
1.239 raeburn 1790: my $ccrole = &Apache::lonnet::plaintext('co',undef,undef,1);
1.182 www 1791: my $carole = &Apache::lonnet::plaintext('ca');
1.193 raeburn 1792: my $selectcalink = &coauthorlink($dcdom,$rowtype);
1.227 bisitz 1793: $output.=$ccrole.': '.$selectcclink
1.249 raeburn 1794: .' | '.$carole.': '.$selectcalink.'</td>'
1.212 bisitz 1795: .&Apache::loncommon::end_data_table_row();
1.108 raeburn 1796: return $output;
1797: }
1798:
1.104 raeburn 1799: sub recent_filename {
1800: my $area=shift;
1.149 www 1801: return 'nohist_recent_'.&escape($area);
1.104 raeburn 1802: }
1803:
1.139 raeburn 1804: sub courseloadpage {
1805: my ($courseid) = @_;
1806: my $startpage;
1.144 albertel 1807: my %entry_settings = &Apache::lonnet::get('nohist_whatsnew',
1808: [$courseid.':courseinit']);
1.139 raeburn 1809: my ($tmp) = %entry_settings;
1.144 albertel 1810: unless ($tmp =~ /^error: 2 /) {
1.139 raeburn 1811: $startpage = $entry_settings{$courseid.':courseinit'};
1812: }
1813: if ($startpage eq '') {
1814: if (exists($env{'environment.course_init_display'})) {
1815: $startpage = $env{'environment.course_init_display'};
1816: }
1817: }
1818: return $startpage;
1819: }
1820:
1.1 harris41 1821: 1;
1822: __END__
1.32 harris41 1823:
1824: =head1 NAME
1825:
1826: Apache::lonroles - User Roles Screen
1827:
1828: =head1 SYNOPSIS
1829:
1830: Invoked by /etc/httpd/conf/srm.conf:
1831:
1832: <Location /adm/roles>
1833: PerlAccessHandler Apache::lonacc
1834: SetHandler perl-script
1835: PerlHandler Apache::lonroles
1836: ErrorDocument 403 /adm/login
1837: ErrorDocument 500 /adm/errorhandler
1838: </Location>
1.64 bowersj2 1839:
1840: =head1 OVERVIEW
1841:
1842: =head2 Choosing Roles
1843:
1844: C<lonroles> is a handler that allows a user to switch roles in
1845: mid-session. LON-CAPA attempts to work with "No Role Specified", the
1846: default role that a user has before selecting a role, as widely as
1847: possible, but certain handlers for example need specification which
1848: course they should act on, etc. Both in this scenario, and when the
1849: handler determines via C<lonnet>'s C<&allowed> function that a certain
1850: action is not allowed, C<lonroles> is used as error handler. This
1851: allows the user to select another role which may have permission to do
1.256.2.1 raeburn 1852: what they were trying to do. C<lonroles> can also be accessed via the
1853: B<CRS> button in the Remote Control.
1.64 bowersj2 1854:
1855: =begin latex
1856:
1857: \begin{figure}
1858: \begin{center}
1859: \includegraphics[width=0.45\paperwidth,keepaspectratio]{Sample_Roles_Screen}
1860: \caption{\label{Sample_Roles_Screen}Sample Roles Screen}
1861: \end{center}
1862: \end{figure}
1863:
1864: =end latex
1865:
1866: =head2 Role Initialization
1867:
1868: 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 1869:
1870: =head1 INTRODUCTION
1871:
1872: This module enables a user to select what role he wishes to
1873: operate under (instructor, student, teaching assistant, course
1874: coordinator, etc). These roles are pre-established by the actions
1875: of upper-level users.
1876:
1877: This is part of the LearningOnline Network with CAPA project
1878: described at http://www.lon-capa.org.
1879:
1880: =head1 HANDLER SUBROUTINE
1881:
1882: This routine is called by Apache and mod_perl.
1883:
1884: =over 4
1885:
1886: =item *
1887:
1888: Roles Initialization (yes/no)
1889:
1890: =item *
1891:
1892: Get Error Message from Environment
1893:
1894: =item *
1895:
1896: Who is this?
1897:
1898: =item *
1899:
1900: Generate Page Output
1901:
1902: =item *
1903:
1904: Choice or no choice
1905:
1906: =item *
1907:
1908: Table
1909:
1910: =item *
1911:
1912: Privileges
1913:
1914: =back
1915:
1916: =cut
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>