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