Annotation of loncom/auth/lonroles.pm, revision 1.307
1.1 harris41 1: # The LearningOnline Network with CAPA
2: # User Roles Screen
1.31 www 3: #
1.307 ! raeburn 4: # $Id: lonroles.pm,v 1.306 2014/05/22 14:17:53 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.246 droeschl 60: what they were trying to do.
1.210 jms 61:
62: =begin latex
63:
64: \begin{figure}
65: \begin{center}
66: \includegraphics[width=0.45\paperwidth,keepaspectratio]{Sample_Roles_Screen}
67: \caption{\label{Sample_Roles_Screen}Sample Roles Screen}
68: \end{center}
69: \end{figure}
70:
71: =end latex
72:
73: =head2 Role Initialization
74:
75: 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.
76:
77: =head1 INTRODUCTION
78:
79: This module enables a user to select what role he wishes to
80: operate under (instructor, student, teaching assistant, course
81: coordinator, etc). These roles are pre-established by the actions
82: of upper-level users.
83:
84: This is part of the LearningOnline Network with CAPA project
85: described at http://www.lon-capa.org.
86:
87: =head1 HANDLER SUBROUTINE
88:
89: This routine is called by Apache and mod_perl.
90:
91: =over 4
92:
93: =item *
94:
95: Roles Initialization (yes/no)
96:
97: =item *
98:
99: Get Error Message from Environment
100:
101: =item *
102:
103: Who is this?
104:
105: =item *
106:
107: Generate Page Output
108:
109: =item *
110:
111: Choice or no choice
112:
113: =item *
114:
115: Table
116:
117: =item *
118:
119: Privileges
120:
121: =back
122:
123: =cut
124:
125:
1.1 harris41 126: package Apache::lonroles;
127:
128: use strict;
1.118 albertel 129: use Apache::lonnet;
1.7 www 130: use Apache::lonuserstate();
1.304 musolffc 131: use Apache::Constants qw(:common REDIRECT);
1.2 www 132: use Apache::File();
1.26 www 133: use Apache::lonmenu;
1.29 albertel 134: use Apache::loncommon;
1.104 raeburn 135: use Apache::lonhtmlcommon;
1.57 www 136: use Apache::lonannounce;
1.72 www 137: use Apache::lonlocal;
1.151 www 138: use Apache::lonpageflip();
1.167 albertel 139: use Apache::lonnavdisplay();
1.241 raeburn 140: use Apache::loncoursequeueadmin;
1.279 raeburn 141: use Apache::longroup;
1.283 raeburn 142: use Apache::lonrss;
1.120 albertel 143: use GDBM_File;
1.170 albertel 144: use LONCAPA qw(:DEFAULT :match);
1.201 raeburn 145: use HTML::Entities;
1.276 raeburn 146:
1.1 harris41 147:
1.62 matthew 148: sub redirect_user {
1.245 droeschl 149: my ($r,$title,$url,$msg) = @_;
1.62 matthew 150: $msg = $title if (! defined($msg));
1.73 www 151: &Apache::loncommon::content_type($r,'text/html');
1.62 matthew 152: &Apache::loncommon::no_cache($r);
153: $r->send_http_header;
1.228 bisitz 154:
155: # Breadcrumbs
156: my $brcrum = [{'href' => $url,
157: 'text' => 'Switching Role'},];
1.147 albertel 158: my $start_page = &Apache::loncommon::start_page('Switching Role',undef,
1.228 bisitz 159: {'redirect' => [1,$url],
160: 'bread_crumbs' => $brcrum,});
1.147 albertel 161: my $end_page = &Apache::loncommon::end_page();
162:
1.92 www 163: # Note to style police:
164: # This must only replace the spaces, nothing else, or it bombs elsewhere.
165: $url=~s/ /\%20/g;
1.93 albertel 166: $r->print(<<ENDREDIR);
1.147 albertel 167: $start_page
1.222 bisitz 168: <p>$msg</p>
1.147 albertel 169: $end_page
1.62 matthew 170: ENDREDIR
171: return;
172: }
173:
1.150 www 174: sub error_page {
175: my ($r,$error,$dest)=@_;
176: &Apache::loncommon::content_type($r,'text/html');
177: &Apache::loncommon::no_cache($r);
178: $r->send_http_header;
179: return OK if $r->header_only;
1.228 bisitz 180: # Breadcrumbs
181: my $brcrum = [{'href' => $dest,
182: 'text' => 'Problems during Course Initialization'},];
183: $r->print(&Apache::loncommon::start_page('Problems during Course Initialization',
184: undef,
185: {'bread_crumbs' => $brcrum,})
186: );
187: $r->print(
1.225 bisitz 188: '<script type="text/javascript">'.
189: '// <![CDATA['.
190: &Apache::lonmenu::rawconfig().
191: '// ]]>'.
192: '</script>'.
193: '<p class="LC_error">'.&mt('The following problems occurred:').
1.228 bisitz 194: '<br />'.
1.150 www 195: $error.
1.228 bisitz 196: '</p><br /><a href="'.$dest.'">'.&mt('Continue').'</a>'
197: );
198: $r->print(&Apache::loncommon::end_page());
1.150 www 199: }
200:
1.1 harris41 201: sub handler {
1.10 www 202:
1.1 harris41 203: my $r = shift;
204:
1.304 musolffc 205: # Check for critical messages and redirect if present.
206: my ($redirect,$url) = &Apache::loncommon::critical_redirect(300);
207: if ($redirect) {
208: &Apache::loncommon::content_type($r,'text/html');
209: $r->header_out(Location => $url);
210: return REDIRECT;
211: }
212:
1.6 www 213: my $now=time;
1.118 albertel 214: my $then=$env{'user.login.time'};
1.226 raeburn 215: my $refresh=$env{'user.refresh.time'};
1.260 raeburn 216: my $update=$env{'user.update.time'};
1.226 raeburn 217: if (!$refresh) {
218: $refresh = $then;
219: }
1.260 raeburn 220: if (!$update) {
221: $update = $then;
222: }
223:
1.274 raeburn 224: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'});
225:
226: # -------------------------------------------------- Check if setting hot list
227: my $hotlist;
228: if ($env{'form.action'} eq 'verify_and_change_rolespref') {
229: $hotlist = &Apache::lonpreferences::verify_and_change_rolespref($r);
230: }
231:
1.260 raeburn 232: # -------------------------------------------------------- Check for new roles
233: my $updateresult;
1.274 raeburn 234: if ($env{'form.state'} eq 'doupdate') {
1.260 raeburn 235: my $show_course=&Apache::loncommon::show_course();
236: my $checkingtxt;
237: if ($show_course) {
238: $checkingtxt = &mt('Checking for new courses ...');
239: } else {
240: $checkingtxt = &mt('Checking for new roles ...');
241: }
1.274 raeburn 242: $updateresult = $checkingtxt;
1.260 raeburn 243: $updateresult .= &update_session_roles();
244: &Apache::lonnet::appenv({'user.update.time' => $now});
245: $update = $now;
1.272 raeburn 246: &Apache::loncoursequeueadmin::reqauthor_check();
1.270 raeburn 247: }
248:
249: # -------------------------------------------------- Check for author requests
250: my $reqauthor;
1.274 raeburn 251: if ($env{'form.state'} eq 'requestauthor') {
1.272 raeburn 252: $reqauthor = &Apache::loncoursequeueadmin::process_reqauthor(\$update);
1.260 raeburn 253: }
254:
1.6 www 255: my $envkey;
1.107 raeburn 256: my %dcroles = ();
1.260 raeburn 257: my $numdc = &check_fordc(\%dcroles,$update,$then);
1.304 musolffc 258: my $loncaparev = $r->dir_config('lonVersion');
1.10 www 259:
1.6 www 260: # ================================================================== Roles Init
1.118 albertel 261: if ($env{'form.selectrole'}) {
1.188 www 262:
263: my $locknum=&Apache::lonnet::get_locks();
264: if ($locknum) { return 409; }
265:
1.134 www 266: if ($env{'form.newrole'}) {
267: $env{'form.'.$env{'form.newrole'}}=1;
268: }
1.118 albertel 269: if ($env{'request.course.id'}) {
1.185 raeburn 270: # Check if user is CC trying to select a course role
271: if ($env{'form.switchrole'}) {
1.252 raeburn 272: my $switch_is_active;
273: if (defined($env{'user.role.'.$env{'form.switchrole'}})) {
274: my ($start,$end) = split(/\./,$env{'user.role.'.$env{'form.switchrole'}});
275: if (!$end || $end > $now) {
1.260 raeburn 276: if (!$start || $start < $update) {
1.252 raeburn 277: $switch_is_active = 1;
278: }
279: }
280: }
281: unless ($switch_is_active) {
1.260 raeburn 282: &adhoc_course_role($refresh,$update,$then);
1.185 raeburn 283: }
284: }
1.118 albertel 285: my %temp=('logout_'.$env{'request.course.id'} => time);
1.33 www 286: &Apache::lonnet::put('email_status',\%temp);
1.118 albertel 287: &Apache::lonnet::delenv('user.state.'.$env{'request.course.id'});
1.100 albertel 288: }
1.186 raeburn 289: &Apache::lonnet::appenv({"request.course.id" => '',
290: "request.course.fn" => '',
291: "request.course.uri" => '',
292: "request.course.sec" => '',
1.269 raeburn 293: "request.course.tied" => '',
1.186 raeburn 294: "request.role" => 'cm',
295: "request.role.adv" => $env{'user.adv'},
296: "request.role.domain" => $env{'user.domain'}});
1.182 www 297: # Check if user is a DC trying to enter a course or author space and needs privs to be created
1.107 raeburn 298: if ($numdc > 0) {
1.296 raeburn 299: foreach my $envkey (keys(%env)) {
1.240 raeburn 300: # Is this an ad-hoc Coordinator role?
301: if (my ($ccrole,$domain,$coursenum) =
302: ($envkey =~ m-^form\.(cc|co)\./($match_domain)/($match_courseid)$-)) {
1.146 raeburn 303: if ($dcroles{$domain}) {
1.275 raeburn 304: if (&Apache::lonnet::check_adhoc_privs($domain,$coursenum,
305: $update,$refresh,$now,$ccrole)) {
306: &Apache::lonnet::appenv({"environment.internal.$domain.$coursenum.$ccrole.adhoc" => time});
307: }
1.182 www 308: }
309: last;
310: }
1.193 raeburn 311: # Is this an ad-hoc CA-role?
1.183 www 312: if (my ($domain,$user) =
313: ($envkey =~ m-^form\.ca\./($match_domain)/($match_username)$-)) {
1.206 raeburn 314: if (($domain eq $env{'user.domain'}) && ($user eq $env{'user.name'})) {
315: delete($env{$envkey});
316: $env{'form.au./'.$domain.'/'} = 1;
317: my ($server_status,$home) = &check_author_homeserver($user,$domain);
318: if ($server_status eq 'switchserver') {
319: my $trolecode = 'au./'.$domain.'/';
1.248 raeburn 320: my $switchserver = '/adm/switchserver?otherserver='.$home.'&role='.$trolecode;
1.206 raeburn 321: $r->internal_redirect($switchserver);
1.285 raeburn 322: return OK;
1.206 raeburn 323: }
324: last;
325: }
326: if (my ($castart,$caend) = ($env{'user.role.ca./'.$domain.'/'.$user} =~ /^(\d*)\.(\d*)$/)) {
327: if (((($castart) && ($castart < $now)) || !$castart) &&
328: ((!$caend) || (($caend) && ($caend > $now)))) {
329: my ($server_status,$home) = &check_author_homeserver($user,$domain);
330: if ($server_status eq 'switchserver') {
331: my $trolecode = 'ca./'.$domain.'/'.$user;
1.248 raeburn 332: my $switchserver = '/adm/switchserver?otherserver='.$home.'&role='.$trolecode;
1.206 raeburn 333: $r->internal_redirect($switchserver);
1.285 raeburn 334: return OK;
1.206 raeburn 335: }
336: last;
337: }
338: }
339: # Check if author blocked ca-access
1.190 www 340: my %blocked=&Apache::lonnet::get('environment',['domcoord.author'],$domain,$user);
341: if ($blocked{'domcoord.author'} eq 'blocked') {
1.206 raeburn 342: delete($env{$envkey});
343: $env{'user.error.msg'}=':::1:User '.$user.' in domain '.$domain.' blocked domain coordinator access';
344: last;
1.190 www 345: }
1.193 raeburn 346: if ($dcroles{$domain}) {
347: my ($server_status,$home) = &check_author_homeserver($user,$domain);
348: if (($server_status eq 'ok') || ($server_status eq 'switchserver')) {
1.260 raeburn 349: &Apache::lonnet::check_adhoc_privs($domain,$user,$update,
1.230 raeburn 350: $refresh,$now,'ca');
1.193 raeburn 351: if ($server_status eq 'switchserver') {
352: my $trolecode = 'ca./'.$domain.'/'.$user;
353: my $switchserver = '/adm/switchserver?'
1.248 raeburn 354: .'otherserver='.$home.'&role='.$trolecode;
1.193 raeburn 355: $r->internal_redirect($switchserver);
1.285 raeburn 356: return OK;
1.193 raeburn 357: }
358: } else {
359: delete($env{$envkey});
360: }
1.183 www 361: } else {
362: delete($env{$envkey});
1.182 www 363: }
364: last;
365: }
1.107 raeburn 366: }
367: }
368:
1.296 raeburn 369: foreach $envkey (keys(%env)) {
1.40 matthew 370: next if ($envkey!~/^user\.role\./);
1.102 raeburn 371: my ($where,$trolecode,$role,$tstatus,$tend,$tstart);
1.260 raeburn 372: &Apache::lonnet::role_status($envkey,$update,$refresh,$now,\$role,\$where,
1.218 raeburn 373: \$trolecode,\$tstatus,\$tstart,\$tend);
1.118 albertel 374: if ($env{'form.'.$trolecode}) {
1.55 albertel 375: if ($tstatus eq 'is') {
376: $where=~s/^\///;
377: my ($cdom,$cnum,$csec)=split(/\//,$where);
1.255 raeburn 378: if (($cnum) && ($role ne 'ca') && ($role ne 'aa')) {
379: my $home = $env{'course.'.$cdom.'_'.$cnum.'.home'};
380: my @ids = &Apache::lonnet::current_machine_ids();
381: unless ($loncaparev eq '' && $home && grep(/^\Q$home\E$/,@ids)) {
382: my %curr_reqd_hash = &Apache::lonnet::userenvironment($cdom,$cnum,'internal.releaserequired');
1.256 raeburn 383: if ($curr_reqd_hash{'internal.releaserequired'} ne '') {
1.255 raeburn 384: my ($switchserver,$switchwarning) =
385: &check_release_required($loncaparev,$cdom.'_'.$cnum,$trolecode,$curr_reqd_hash{'internal.releaserequired'});
1.256 raeburn 386: if ($switchwarning ne '' || $switchserver ne '') {
387: &Apache::loncommon::content_type($r,'text/html');
388: &Apache::loncommon::no_cache($r);
389: $r->send_http_header;
390: my $end_page=&Apache::loncommon::end_page();
391: $r->print(&Apache::loncommon::start_page('Selected course unavailable on this server').
392: '<p class="LC_warning">');
393: if ($switchwarning) {
394: $r->print($switchwarning.'<br /><a href="/adm/roles">');
395: if (&Apache::loncommon::show_course()) {
396: $r->print(&mt('Display courses'));
397: } else {
398: $r->print(&mt('Display roles'));
399: }
400: $r->print('</a>');
401: } elsif ($switchserver) {
402: $r->print(&mt('This course requires a newer version of LON-CAPA than is installed on this server.').
403: '<br />'.
404: '<a href="/adm/switchserver?'.$switchserver.'">'.
405: &mt('Switch Server').
406: '</a>');
1.255 raeburn 407: }
1.256 raeburn 408: $r->print('</p>'.&Apache::loncommon::end_page());
409: return OK;
1.255 raeburn 410: }
411: }
412: }
413: }
1.137 raeburn 414: # check for course groups
415: my %coursegroups = &Apache::lonnet::get_active_groups(
416: $env{'user.domain'},$env{'user.name'},$cdom, $cnum);
417: my $cgrps = join(':',keys(%coursegroups));
418:
1.111 albertel 419: # store role if recent_role list being kept
1.118 albertel 420: if ($env{'environment.recentroles'}) {
1.158 albertel 421: my %frozen_roles =
422: &Apache::lonhtmlcommon::get_recent_frozen('roles',$env{'environment.recentrolesn'});
1.111 albertel 423: &Apache::lonhtmlcommon::store_recent('roles',
1.158 albertel 424: $trolecode,' ',$frozen_roles{$trolecode});
1.111 albertel 425: }
426:
427:
1.53 www 428: # check for keyed access
1.55 albertel 429: if (($role eq 'st') &&
1.118 albertel 430: ($env{'course.'.$cdom.'_'.$cnum.'.keyaccess'} eq 'yes')) {
1.89 www 431: # who is key authority?
432: my $authdom=$cdom;
433: my $authnum=$cnum;
1.118 albertel 434: if ($env{'course.'.$cdom.'_'.$cnum.'.keyauth'}) {
1.89 www 435: ($authnum,$authdom)=
1.172 albertel 436: split(/:/,$env{'course.'.$cdom.'_'.$cnum.'.keyauth'});
1.89 www 437: }
438: # check with key authority
439: unless (&Apache::lonnet::validate_access_key(
1.118 albertel 440: $env{'environment.key.'.$cdom.'_'.$cnum},
1.89 www 441: $authdom,$authnum)) {
1.53 www 442: # there is no valid key
1.118 albertel 443: if ($env{'form.newkey'}) {
1.53 www 444: # student attempts to register a new key
1.89 www 445: &Apache::loncommon::content_type($r,'text/html');
446: &Apache::loncommon::no_cache($r);
447: $r->send_http_header;
448: my $swinfo=&Apache::lonmenu::rawconfig();
1.147 albertel 449: my $start_page=&Apache::loncommon::start_page
1.89 www 450: ('Verifying Access Key to Unlock this Course');
1.147 albertel 451: my $end_page=&Apache::loncommon::end_page();
1.90 www 452: my $buttontext=&mt('Enter Course');
453: my $message=&mt('Successfully registered key');
454: my $assignresult=
455: &Apache::lonnet::assign_access_key(
1.118 albertel 456: $env{'form.newkey'},
1.90 www 457: $authdom,$authnum,
1.91 www 458: $cdom,$cnum,
1.118 albertel 459: $env{'user.domain'},
460: $env{'user.name'},
1.204 bisitz 461: &mt('Assigned from [_1] at [_2] for [_3]'
462: ,$ENV{'REMOTE_ADDR'}
463: ,&Apache::lonlocal::locallocaltime()
464: ,$trolecode)
465: );
1.90 www 466: unless ($assignresult eq 'ok') {
467: $assignresult=~s/^error\:\s*//;
468: $message=&mt($assignresult).
469: '<br /><a href="/adm/logout">'.
1.89 www 470: &mt('Logout').'</a>';
1.90 www 471: $buttontext=&mt('Re-Enter Key');
472: }
1.89 www 473: $r->print(<<ENDENTEREDKEY);
1.147 albertel 474: $start_page
1.179 raeburn 475: <script type="text/javascript">
1.225 bisitz 476: // <![CDATA[
1.89 www 477: $swinfo
1.225 bisitz 478: // ]]>
1.89 www 479: </script>
1.225 bisitz 480: <form action="" method="post">
1.89 www 481: <input type="hidden" name="selectrole" value="1" />
482: <input type="hidden" name="$trolecode" value="1" />
1.211 tempelho 483: <span class="LC_fontsize_large">$message</span><br />
1.89 www 484: <input type="submit" value="$buttontext" />
485: </form>
1.147 albertel 486: $end_page
1.89 www 487: ENDENTEREDKEY
488: return OK;
1.55 albertel 489: } else {
1.53 www 490: # print form to enter a new key
1.73 www 491: &Apache::loncommon::content_type($r,'text/html');
1.55 albertel 492: &Apache::loncommon::no_cache($r);
493: $r->send_http_header;
494: my $swinfo=&Apache::lonmenu::rawconfig();
1.147 albertel 495: my $start_page=&Apache::loncommon::start_page
1.55 albertel 496: ('Enter Access Key to Unlock this Course');
1.147 albertel 497: my $end_page=&Apache::loncommon::end_page();
1.55 albertel 498: $r->print(<<ENDENTERKEY);
1.147 albertel 499: $start_page
1.179 raeburn 500: <script type="text/javascript">
1.225 bisitz 501: // <![CDATA[
1.53 www 502: $swinfo
1.225 bisitz 503: // ]]>
1.53 www 504: </script>
1.225 bisitz 505: <form action="" method="post">
1.89 www 506: <input type="hidden" name="selectrole" value="1" />
507: <input type="hidden" name="$trolecode" value="1" />
1.118 albertel 508: <input type="text" size="20" name="newkey" value="$env{'form.newkey'}" />
1.53 www 509: <input type="submit" value="Enter key" />
510: </form>
1.147 albertel 511: $end_page
1.53 www 512: ENDENTERKEY
1.55 albertel 513: return OK;
514: }
515: }
516: }
1.118 albertel 517: &Apache::lonnet::log($env{'user.domain'},
518: $env{'user.name'},
519: $env{'user.home'},
1.87 www 520: "Role ".$trolecode);
1.101 albertel 521:
1.56 www 522: &Apache::lonnet::appenv(
1.186 raeburn 523: {'request.role' => $trolecode,
524: 'request.role.domain' => $cdom,
525: 'request.course.sec' => $csec,
526: 'request.course.groups' => $cgrps});
1.101 albertel 527: my $tadv=0;
1.62 matthew 528:
1.125 www 529: if (($cnum) && ($role ne 'ca') && ($role ne 'aa')) {
1.152 raeburn 530: my $msg;
1.55 albertel 531: my ($furl,$ferr)=
532: &Apache::lonuserstate::readmap($cdom.'/'.$cnum);
1.284 raeburn 533: unless ($ferr) {
534: unless (($env{'form.switchrole'}) ||
535: ($env{"environment.internal.$cdom.$cnum.$role.adhoc"})) {
536: &Apache::lonnet::put('nohist_crslastlogin',
537: {$env{'user.name'}.':'.$env{'user.domain'}.
538: ':'.$csec.':'.$role => $now},$cdom,$cnum);
539: }
540: my ($feeds,$syllabus_time);
1.283 raeburn 541: &Apache::lonrss::advertisefeeds($cnum,$cdom,undef,\$feeds);
1.284 raeburn 542: &Apache::lonnet::appenv({'request.course.feeds' => $feeds});
1.289 raeburn 543: &Apache::lonnet::get_numsuppfiles($cnum,$cdom,1);
1.284 raeburn 544: unless ($env{'course.'.$cdom.'_'.$cnum.'.updatedsyllabus'}) {
545: unless (($env{'course.'.$cdom.'_'.$cnum.'.externalsyllabus'}) ||
546: ($env{'course.'.$cdom.'_'.$cnum.'.uploadedsyllabus'})) {
547: my %syllabus=&Apache::lonnet::dump('syllabus',$cdom,$cnum);
548: $syllabus_time = $syllabus{'uploaded.lastmodified'};
549: if ($syllabus_time) {
550: &Apache::lonnet::appenv({'request.course.syllabustime' => $syllabus_time});
551: }
552: }
553: }
1.275 raeburn 554: }
1.118 albertel 555: if (($env{'form.orgurl'}) &&
1.292 raeburn 556: ($env{'form.orgurl'}!~/^\/adm\/flip/) &&
557: ($env{'form.orgurl'} ne '/adm/roles')) {
1.118 albertel 558: my $dest=$env{'form.orgurl'};
1.219 raeburn 559: if ($env{'form.symb'}) {
560: if ($dest =~ /\?/) {
561: $dest .= '&';
562: } else {
1.292 raeburn 563: $dest .= '?';
1.219 raeburn 564: }
565: $dest .= 'symb='.$env{'form.symb'};
566: }
1.117 albertel 567: if (&Apache::lonnet::allowed('adv') eq 'F') { $tadv=1; }
1.186 raeburn 568: &Apache::lonnet::appenv({'request.role.adv'=>$tadv});
1.150 www 569: if (($ferr) && ($tadv)) {
570: &error_page($r,$ferr,$dest);
571: } else {
1.255 raeburn 572: if ($dest =~ m{^/adm/coursedocs\?folderpath}) {
573: if ($env{'request.course.id'} eq $cdom.'_'.$cnum) {
574: my $chome = &Apache::lonnet::homeserver($cnum,$cdom);
1.268 raeburn 575: &Apache::loncommon::update_content_constraints($cdom,$cnum,$chome,
576: $cdom.'_'.$cnum);
1.255 raeburn 577: }
578: }
1.150 www 579: $r->internal_redirect($dest);
580: }
1.55 albertel 581: return OK;
582: } else {
1.155 albertel 583: if (!$env{'request.course.id'}) {
1.55 albertel 584: &Apache::lonnet::appenv(
1.186 raeburn 585: {"request.course.id" => $cdom.'_'.$cnum});
1.61 www 586: $furl='/adm/roles?tryagain=1';
1.221 bisitz 587: $msg='<p><span class="LC_error">'
588: .&mt('Could not initialize [_1] at this time.',
589: $env{'course.'.$cdom.'_'.$cnum.'.description'})
590: .'</span></p>'
591: .'<p>'.&mt('Please try again.').'</p>'
592: .'<p>'.$ferr.'</p>';
1.55 albertel 593: }
1.117 albertel 594: if (&Apache::lonnet::allowed('adv') eq 'F') { $tadv=1; }
1.186 raeburn 595: &Apache::lonnet::appenv({'request.role.adv'=>$tadv});
1.152 raeburn 596:
1.150 www 597: if (($ferr) && ($tadv)) {
598: &error_page($r,$ferr,$furl);
599: } else {
600: # Check to see if the user is a CC entering a course
601: # for the first time
1.240 raeburn 602: if ((($role eq 'cc') || ($role eq 'co'))
1.297 raeburn 603: && ($env{'course.'.$cdom.'_'.$cnum.'.course.helper.not.run'})) {
1.150 www 604: $furl = "/adm/helper/course.initialization.helper";
605: # Send the user to the course they selected
606: } elsif ($env{'request.course.id'}) {
1.276 raeburn 607: my ($dest,$destsymb,$checkenc);
608: $dest = $env{'form.destinationurl'};
609: $destsymb = $env{'form.destsymb'};
610: if ($dest ne '') {
611: if ($env{'form.switchrole'}) {
612: if ($destsymb ne '') {
613: if ($destsymb !~ m{^/enc/}) {
614: unless ($env{'request.role.adv'}) {
615: $checkenc = 1;
616: }
617: }
618: }
619: if ($dest =~ m{^/enc/}) {
620: if ($env{'request.role.adv'}) {
621: $dest = &Apache::lonenc::unencrypted($dest);
622: if ($destsymb eq '') {
1.277 raeburn 623: ($destsymb) = ($dest =~ /(?:\?|\&)symb=([^\&]*)/);
1.276 raeburn 624: $destsymb = &unescape($destsymb);
625: }
626: }
627: } else {
628: if ($destsymb eq '') {
1.280 raeburn 629: ($destsymb) = ($dest =~ /(?:\?|\&)symb=([^\&]+)/);
1.276 raeburn 630: $destsymb = &unescape($destsymb);
631: }
632: unless ($env{'request.role.adv'}) {
633: $checkenc = 1;
634: }
635: }
636: if (($checkenc) && ($destsymb ne '')) {
637: my ($encstate,$unencsymb,$res);
1.281 raeburn 638: $unencsymb = &Apache::lonnet::symbclean($destsymb);
1.276 raeburn 639: (undef,undef,$res) = &Apache::lonnet::decode_symb($unencsymb);
640: &Apache::lonnet::symbverify($unencsymb,$res,\$encstate);
641: if ($encstate) {
642: if (($dest ne '') && ($dest !~ m{^/enc/})) {
643: $dest=&Apache::lonenc::encrypted($dest);
644: }
645: }
646: }
647: }
1.277 raeburn 648: unless (($dest =~ m{^/enc/}) || ($dest =~ /(\?|\&)symb=.+___\d+___.+/)) {
1.276 raeburn 649: if (($destsymb ne '') && ($destsymb !~ m{^/enc/})) {
650: my $esc_symb = &escape($destsymb);
651: $dest .= '?symb='.$esc_symb;
652: }
1.203 raeburn 653: }
1.245 droeschl 654: &redirect_user($r, &mt('Entering [_1]',
1.297 raeburn 655: $env{'course.'.$cdom.'_'.$cnum.'.description'}),
1.245 droeschl 656: $dest, $msg);
1.185 raeburn 657: return OK;
658: }
1.150 www 659: if (&Apache::lonnet::allowed('whn',
660: $env{'request.course.id'})
661: || &Apache::lonnet::allowed('whn',
662: $env{'request.course.id'}.'/'
663: .$env{'request.course.sec'})
664: ) {
1.297 raeburn 665: my $startpage = &courseloadpage($env{'request.course.id'});
1.150 www 666: unless ($startpage eq 'firstres') {
1.204 bisitz 667: $msg = &mt('Entering [_1] ...',
1.297 raeburn 668: $env{'course.'.$env{'request.course.id'}.'.description'});
1.245 droeschl 669: &redirect_user($r, &mt('New in course'),
670: '/adm/whatsnew?refpage=start', $msg);
1.150 www 671: return OK;
672: }
673: }
674: }
1.300 raeburn 675: # Are we allowed to look at the first resource?
1.299 musolffc 676: if ($furl =~ m{^(/adm/wrapper|)/ext/}) {
1.300 raeburn 677: # If it's an external resource,
1.299 musolffc 678: # strip off the symb argument and possible query
679: my ($exturl,$symb) = ($furl =~ m{^(.+)(?:\?|\&)symb=(.+)$});
680: # Unencode $symb
681: $symb = &unescape($symb);
682: # Then check for permission
683: if (!&Apache::lonnet::allowed('bre',$exturl,$symb)) {
684: $furl = &Apache::lonpageflip::first_accessible_resource();
685: }
1.300 raeburn 686: # For other resources just check for permission
1.299 musolffc 687: } elsif (!&Apache::lonnet::allowed('bre',$furl)) {
688: $furl = &Apache::lonpageflip::first_accessible_resource();
689: }
690:
1.162 albertel 691: $msg = &mt('Entering [_1] ...',
1.297 raeburn 692: $env{'course.'.$cdom.'_'.$cnum.'.description'});
1.245 droeschl 693: &redirect_user($r, &mt('Entering [_1]',
1.297 raeburn 694: $env{'course.'.$cdom.'_'.$cnum.'.description'}),
1.245 droeschl 695: $furl, $msg);
1.58 bowersj2 696: }
1.124 albertel 697: return OK;
1.55 albertel 698: }
699: }
1.62 matthew 700: #
701: # Send the user to the construction space they selected
1.125 www 702: if ($role =~ /^(au|ca|aa)$/) {
1.62 matthew 703: my $redirect_url = '/priv/';
704: if ($role eq 'au') {
1.262 www 705: $redirect_url.=$env{'user.domain'}.'/'.$env{'user.name'};
1.62 matthew 706: } else {
1.263 www 707: $redirect_url .= $where;
1.62 matthew 708: }
709: $redirect_url .= '/';
1.288 raeburn 710: &redirect_user($r,&mt('Entering Authoring Space'),
1.62 matthew 711: $redirect_url);
712: return OK;
713: }
1.104 raeburn 714: if ($role eq 'dc') {
1.108 raeburn 715: my $redirect_url = '/adm/menu/';
716: &redirect_user($r,&mt('Loading Domain Coordinator Menu'),
1.104 raeburn 717: $redirect_url);
1.108 raeburn 718: return OK;
1.104 raeburn 719: }
1.220 raeburn 720: if ($role eq 'sc') {
721: my $redirect_url = '/adm/grades?command=scantronupload';
722: &redirect_user($r,&mt('Loading Data Upload Page'),
723: $redirect_url);
724: return OK;
725: }
1.55 albertel 726: }
727: }
1.6 www 728: }
1.40 matthew 729: }
1.44 www 730:
1.10 www 731:
1.6 www 732: # =============================================================== No Roles Init
1.10 www 733:
1.73 www 734: &Apache::loncommon::content_type($r,'text/html');
1.30 albertel 735: &Apache::loncommon::no_cache($r);
1.10 www 736: $r->send_http_header;
737: return OK if $r->header_only;
738:
1.224 raeburn 739: my $crumbtext = 'User Roles';
740: my $pagetitle = 'My Roles';
741: my $recent = &mt('Recent Roles');
1.287 raeburn 742: my $standby = &mt('Role selected. Please stand by.');
1.224 raeburn 743: my $show_course=&Apache::loncommon::show_course();
744: if ($show_course) {
745: $crumbtext = 'Courses';
746: $pagetitle = 'My Courses';
747: $recent = &mt('Recent Courses');
1.287 raeburn 748: $standby = &mt('Course selected. Please stand by.');
1.224 raeburn 749: }
750: my $brcrum =[{href=>"/adm/roles",text=>$crumbtext}];
1.274 raeburn 751:
752: my %roles_in_env;
753: my $showcount = &roles_from_env(\%roles_in_env,$update);
754:
1.52 www 755: my $swinfo=&Apache::lonmenu::rawconfig();
1.224 raeburn 756: my $start_page=&Apache::loncommon::start_page($pagetitle,undef,{bread_crumbs=>$brcrum});
1.302 raeburn 757: my %domdefs=&Apache::lonnet::get_domain_defaults($env{'user.domain'});
758: my $cattype = 'std';
759: if ($domdefs{'catauth'}) {
760: $cattype = $domdefs{'catauth'};
761: }
762: my $funcs = &get_roles_functions($showcount,$cattype);
1.135 albertel 763: $standby=~s/\n/\\n/g;
1.274 raeburn 764: my $noscript='<br /><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 765:
1.10 www 766: $r->print(<<ENDHEADER);
1.147 albertel 767: $start_page
1.274 raeburn 768: $funcs
1.179 raeburn 769: <noscript>
770: $noscript
771: </noscript>
772: <script type="text/javascript">
1.225 bisitz 773: // <![CDATA[
1.26 www 774: $swinfo
775: window.focus();
1.134 www 776:
777: active=true;
778:
779: function enterrole (thisform,rolecode,buttonname) {
780: if (active) {
781: active=false;
782: document.title='$standby';
783: window.status='$standby';
784: thisform.newrole.value=rolecode;
785: thisform.submit();
786: } else {
787: alert('$standby');
1.260 raeburn 788: }
789: }
790:
1.274 raeburn 791: function rolesView (caller) {
792: if ((caller == 'showall') || (caller == 'noshowall')) {
793: document.rolechoice.display.value = caller;
794: } else {
795: if ((caller == 'doupdate') || (caller == 'requestauthor') ||
796: (caller == 'queued')) {
797: document.rolechoice.state.value = caller;
798: }
799: }
800: document.rolechoice.selectrole.value='';
801: document.rolechoice.submit();
1.270 raeburn 802: }
803:
1.225 bisitz 804: // ]]>
1.26 www 805: </script>
1.10 www 806: ENDHEADER
1.6 www 807:
1.2 www 808: # ------------------------------------------ Get Error Message from Environment
809:
1.118 albertel 810: my ($fn,$priv,$nochoose,$error,$msg)=split(/:/,$env{'user.error.msg'});
811: if ($env{'user.error.msg'}) {
1.55 albertel 812: $r->log_reason(
1.118 albertel 813: "$msg for $env{'user.name'} domain $env{'user.domain'} access $priv",$fn);
1.12 www 814: }
1.1 harris41 815:
1.61 www 816: # ------------------------------------------------- Can this user re-init, etc?
1.6 www 817:
1.118 albertel 818: my $advanced=$env{'user.adv'};
1.61 www 819: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['tryagain']);
1.118 albertel 820: my $tryagain=$env{'form.tryagain'};
1.209 raeburn 821: my $reinit=$env{'user.reinit'};
822: delete $env{'user.reinit'};
1.6 www 823:
1.2 www 824: # -------------------------------------------------------- Generate Page Output
1.6 www 825: # --------------------------------------------------------------- Error Header?
1.2 www 826: if ($error) {
1.187 bisitz 827: $r->print("<h1>".&mt('LON-CAPA Access Control')."</h1>");
1.174 albertel 828: $r->print("<!-- LONCAPAACCESSCONTROLERRORSCREEN --><hr /><pre>");
829: if ($priv ne '') {
1.187 bisitz 830: $r->print(&mt('Access : ').&Apache::lonnet::plaintext($priv)."\n");
1.174 albertel 831: }
832: if ($fn ne '') {
1.187 bisitz 833: $r->print(&mt('Resource: ').&Apache::lonenc::check_encrypt($fn)."\n");
1.174 albertel 834: }
835: if ($msg ne '') {
1.187 bisitz 836: $r->print(&mt('Action : ').$msg."\n");
1.174 albertel 837: }
838: $r->print("</pre><hr />");
1.120 albertel 839: my $url=$fn;
840: my $last;
841: if (tie(my %hash,'GDBM_File',$env{'request.course.fn'}.'_symb.db',
842: &GDBM_READER(),0640)) {
843: $last=$hash{'last_known'};
844: untie(%hash);
845: }
1.149 www 846: if ($last) { $fn.='?symb='.&escape($last); }
1.120 albertel 847:
848: &Apache::londocs::changewarning($r,undef,'You have modified your course recently, [_1] may fix this access problem.',
849: &Apache::lonenc::check_encrypt($fn));
1.2 www 850: } else {
1.118 albertel 851: if ($env{'user.error.msg'}) {
1.209 raeburn 852: if ($reinit) {
853: $r->print(
854: '<h3><span class="LC_error">'.
1.234 raeburn 855: &mt('As your session file for the course or community has expired, you will need to re-select it.').'</span></h3>');
1.209 raeburn 856: } else {
857: $r->print(
1.157 albertel 858: '<h3><span class="LC_error">'.
1.235 bisitz 859: &mt('You need to choose another user role or enter a specific course or community for this function.').
860: '</span></h3>');
1.209 raeburn 861: }
862: }
1.2 www 863: }
864: if ($nochoose) {
1.177 www 865: $r->print("<h2>".&mt('Sorry ...')."</h2>\n<span class='LC_error'>".
866: &mt('This action is currently not authorized.').'</span>'.
1.150 www 867: &Apache::loncommon::end_page());
868: return OK;
1.6 www 869: } else {
1.274 raeburn 870: if ($updateresult || $reqauthor || $hotlist) {
871: my $showresult = '<div>';
872: if ($updateresult) {
873: $showresult .= &Apache::lonhtmlcommon::confirm_success($updateresult);
874: }
875: if ($reqauthor) {
876: $showresult .= &Apache::lonhtmlcommon::confirm_success($reqauthor);
877: }
878: if ($hotlist) {
879: $showresult .= $hotlist;
880: }
881: $showresult .= '</div>';
882: $r->print($showresult);
883: } elsif ($env{'form.state'} eq 'queued') {
884: $r->print(&get_queued());
1.270 raeburn 885: }
1.18 www 886: if (($ENV{'REDIRECT_QUERY_STRING'}) && ($fn)) {
887: $fn.='?'.$ENV{'REDIRECT_QUERY_STRING'};
1.6 www 888: }
1.274 raeburn 889: my $display = ($env{'form.display'} =~ /^(showall)$/);
1.84 www 890: $r->print('<form method="post" name="rolechoice" action="'.(($fn)?$fn:$r->uri).'">');
1.116 albertel 891: $r->print('<input type="hidden" name="orgurl" value="'.$fn.'" />');
892: $r->print('<input type="hidden" name="selectrole" value="1" />');
1.134 www 893: $r->print('<input type="hidden" name="newrole" value="" />');
1.274 raeburn 894: $r->print('<input type="hidden" name="display" value="'.$display.'" />');
895: $r->print('<input type="hidden" name="state" value="" />');
1.6 www 896: }
1.259 raeburn 897: $r->rflush();
1.226 raeburn 898:
899: my (%roletext,%sortrole,%roleclass,%futureroles,%timezones);
900: my ($countactive,$countfuture,$inrole,$possiblerole) =
1.274 raeburn 901: &gather_roles($update,$refresh,$now,$reinit,$nochoose,\%roles_in_env,\%roletext,
902: \%sortrole,\%roleclass,\%futureroles,\%timezones,$loncaparev);
1.226 raeburn 903: $refresh = $now;
904: &Apache::lonnet::appenv({'user.refresh.time' => $refresh});
1.302 raeburn 905: if ((($cattype eq 'std') || ($cattype eq 'domonly')) && (!$env{'user.adv'})) {
1.196 raeburn 906: if ($countactive > 0) {
907: my $domdesc = &Apache::lonnet::domain($env{'user.domain'},'description');
1.201 raeburn 908: my $esc_dom = &HTML::Entities::encode($env{'user.domain'},'"<>&');
1.233 bisitz 909: $r->print(
910: '<p>'
1.295 bisitz 911: .&mt('[_1]Visit the [_2]Course/Community Catalog[_3][_4]'
912: .' to view all [_5] LON-CAPA courses and communities.'
1.233 bisitz 913: ,'<b>'
914: ,'<a href="/adm/coursecatalog?showdom='.$esc_dom.'">'
1.295 bisitz 915: ,'</a>'
916: ,'</b>'
917: ,'"'.$domdesc.'"')
1.233 bisitz 918: .'<br />'
1.235 bisitz 919: .&mt('If a course or community is [_1]not[_2] in your list of current courses and communities below,'
1.233 bisitz 920: .' you may be able to enroll if self-enrollment is permitted.'
921: ,'<b>','</b>')
922: .'</p>'
923: );
1.196 raeburn 924: }
925: }
926:
1.84 www 927: # No active roles
928: if ($countactive==0) {
1.306 raeburn 929: &requestcourse_advice($r,$cattype,$inrole);
1.191 raeburn 930: $r->print('</form>');
931: if ($countfuture) {
932: $r->print(&mt('The following [quant,_1,role,roles] will become active in the future:',$countfuture));
933: my $doheaders = &roletable_headers($r,\%roleclass,\%sortrole,
934: $nochoose);
935: &print_rolerows($r,$doheaders,\%roleclass,\%sortrole,\%dcroles,
936: \%roletext);
937: my $tremark='';
1.212 bisitz 938: my $tbg;
1.191 raeburn 939: if ($env{'request.role'} eq 'cm') {
1.212 bisitz 940: $tbg="LC_roles_selected";
1.204 bisitz 941: $tremark=&mt('Currently selected.').' ';
1.191 raeburn 942: } else {
1.212 bisitz 943: $tbg="LC_roles_is";
1.191 raeburn 944: }
1.212 bisitz 945: $r->print(&Apache::loncommon::start_data_table_row()
946: .'<td class="'.$tbg.'"> </td>'
947: .'<td colspan="3">'
948: .&mt('No role specified')
949: .'</td>'
950: .'<td>'.$tremark.' </td>'
951: .&Apache::loncommon::end_data_table_row()
952: );
1.191 raeburn 953:
1.212 bisitz 954: $r->print(&Apache::loncommon::end_data_table());
1.191 raeburn 955: }
956: $r->print(&Apache::loncommon::end_page());
1.84 www 957: return OK;
958: }
959: # ----------------------------------------------------------------------- Table
1.247 raeburn 960:
961: if ($numdc > 0) {
962: $r->print(&coursepick_jscript());
963: $r->print(&Apache::loncommon::coursebrowser_javascript().
964: &Apache::loncommon::authorbrowser_javascript());
965: }
966:
1.224 raeburn 967: unless ((!&Apache::loncommon::show_course()) || ($nochoose) || ($countactive==1)) {
1.173 albertel 968: $r->print("<h2>".&mt('Select a Course to Enter')."</h2>\n");
1.84 www 969: }
1.229 raeburn 970: if ($env{'form.destinationurl'}) {
971: $r->print('<input type="hidden" name="destinationurl" value="'.
972: $env{'form.destinationurl'}.'" />');
973: if ($env{'form.destsymb'} ne '') {
974: $r->print('<input type="hidden" name="destsymb" value="'.
975: $env{'form.destsymb'}.'" />');
976: }
977: }
1.247 raeburn 978:
1.191 raeburn 979: my $doheaders = &roletable_headers($r,\%roleclass,\%sortrole,$nochoose);
1.118 albertel 980: if ($env{'environment.recentroles'}) {
1.111 albertel 981: my %recent_roles =
1.118 albertel 982: &Apache::lonhtmlcommon::get_recent('roles',$env{'environment.recentrolesn'});
1.111 albertel 983: my $output='';
1.247 raeburn 984: foreach my $role (sort(keys(%recent_roles))) {
985: if (ref($roletext{'user.role.'.$role}) eq 'ARRAY') {
1.223 raeburn 986: $output.= &Apache::loncommon::start_data_table_row().
1.247 raeburn 987: $roletext{'user.role.'.$role}->[0].
1.223 raeburn 988: &Apache::loncommon::end_data_table_row();
1.249 raeburn 989: if ($roletext{'user.role.'.$role}->[1] ne '') {
990: $output .= &Apache::loncommon::continue_data_table_row().
991: $roletext{'user.role.'.$role}->[1].
992: &Apache::loncommon::end_data_table_row();
993: }
1.247 raeburn 994: if ($role =~ m{dc\./($match_domain)/}
1.170 albertel 995: && $dcroles{$1}) {
1.192 raeburn 996: $output .= &adhoc_roles_row($1,'recent');
1.133 albertel 997: }
1.113 raeburn 998: } elsif ($numdc > 0) {
1.247 raeburn 999: unless ($role =~/^error\:/) {
1.249 raeburn 1000: my ($roletext,$role_text_end) = &display_cc_role('user.role.'.$role);
1.259 raeburn 1001: if ($roletext) {
1002: $output.= &Apache::loncommon::start_data_table_row().
1003: $roletext.
1004: &Apache::loncommon::end_data_table_row();
1005: if ($role_text_end) {
1006: $output .= &Apache::loncommon::continue_data_table_row().
1007: $role_text_end.
1008: &Apache::loncommon::end_data_table_row();
1009: }
1010: }
1.113 raeburn 1011: }
1.247 raeburn 1012: }
1.111 albertel 1013: }
1014: if ($output) {
1.212 bisitz 1015: $r->print(&Apache::loncommon::start_data_table_empty_row()
1016: .'<td align="center" colspan="5">'
1.224 raeburn 1017: .$recent
1.212 bisitz 1018: .'</td>'
1019: .&Apache::loncommon::end_data_table_empty_row()
1020: );
1.111 albertel 1021: $r->print($output);
1.114 raeburn 1022: $doheaders ++;
1.111 albertel 1023: }
1024: }
1.191 raeburn 1025: &print_rolerows($r,$doheaders,\%roleclass,\%sortrole,\%dcroles,\%roletext);
1.202 raeburn 1026: if ($countactive > 1) {
1027: my $tremark='';
1.212 bisitz 1028: my $tbg;
1.202 raeburn 1029: if ($env{'request.role'} eq 'cm') {
1.212 bisitz 1030: $tbg="LC_roles_selected";
1.204 bisitz 1031: $tremark=&mt('Currently selected.').' ';
1.202 raeburn 1032: } else {
1.212 bisitz 1033: $tbg="LC_roles_is";
1.202 raeburn 1034: }
1.212 bisitz 1035: $r->print(&Apache::loncommon::start_data_table_row());
1.202 raeburn 1036: unless ($nochoose) {
1037: if ($env{'request.role'} ne 'cm') {
1.212 bisitz 1038: $r->print('<td class="'.$tbg.'"><input type="submit" value="'.
1.202 raeburn 1039: &mt('Select').'" name="cm" /></td>');
1040: } else {
1.212 bisitz 1041: $r->print('<td class="'.$tbg.'"> </td>');
1.202 raeburn 1042: }
1043: }
1.212 bisitz 1044: $r->print('<td colspan="3">'
1045: .&mt('No role specified')
1046: .'</td>'
1047: .'<td>'.$tremark.' </td>'
1048: .&Apache::loncommon::end_data_table_row()
1049: );
1.202 raeburn 1050: }
1.212 bisitz 1051: $r->print(&Apache::loncommon::end_data_table());
1.4 www 1052: unless ($nochoose) {
1053: $r->print("</form>\n");
1054: }
1.22 harris41 1055: # ------------------------------------------------------------ Privileges Info
1.118 albertel 1056: if (($advanced) && (($env{'user.error.msg'}) || ($error))) {
1.212 bisitz 1057: $r->print('<hr /><h2>'.&mt('Current Privileges').'</h2>');
1.175 albertel 1058: $r->print(&privileges_info());
1.4 www 1059: }
1.267 bisitz 1060: my $announcements = &Apache::lonnet::getannounce();
1061: $r->print(
1062: '<br />'.
1063: '<h2>'.&mt('Announcements').'</h2>'.
1064: $announcements
1065: ) unless (!$announcements);
1.65 www 1066: if ($advanced) {
1.201 raeburn 1067: my $esc_dom = &HTML::Entities::encode($env{'user.domain'},'"<>&');
1.231 bisitz 1068: $r->print('<p><small><i>'
1069: .&mt('This LON-CAPA server is version [_1]',$r->dir_config('lonVersion'))
1070: .'</i><br />'
1071: .'<a href="/adm/logout">'.&mt('Logout').'</a> '
1.201 raeburn 1072: .'<a href="/adm/coursecatalog?showdom='.$esc_dom.'">'
1.233 bisitz 1073: .&mt('Course/Community Catalog')
1.225 bisitz 1074: .'</a></small></p>');
1.65 www 1075: }
1.147 albertel 1076: $r->print(&Apache::loncommon::end_page());
1.1 harris41 1077: return OK;
1.102 raeburn 1078: }
1079:
1.274 raeburn 1080: sub roles_from_env {
1081: my ($roleshash,$update) = @_;
1082: my $count = 0;
1083: if (ref($roleshash) eq 'HASH') {
1084: foreach my $envkey (keys(%env)) {
1085: if ($envkey =~ m{^user\.role\.(\w+)[./]}) {
1086: next if ($1 eq 'gr');
1087: $roleshash->{$envkey} = $env{$envkey};
1088: my ($start,$end) = split(/\./,$env{$envkey});
1089: unless ($end && $end<$update) {
1090: $count ++;
1091: }
1092: }
1093: }
1094: }
1095: return $count;
1096: }
1097:
1.226 raeburn 1098: sub gather_roles {
1.274 raeburn 1099: my ($update,$refresh,$now,$reinit,$nochoose,$roles_in_env,$roletext,$sortrole,$roleclass,$futureroles,
1100: $timezones,$loncaparev) = @_;
1.226 raeburn 1101: my ($countactive,$countfuture,$inrole,$possiblerole) = (0,0,0,'');
1102: my $advanced = $env{'user.adv'};
1103: my $tryagain = $env{'form.tryagain'};
1.254 raeburn 1104: my @ids = &Apache::lonnet::current_machine_ids();
1.274 raeburn 1105: if (ref($roles_in_env) eq 'HASH') {
1106: foreach my $envkey (sort(keys(%{$roles_in_env}))) {
1107: my $button = 1;
1108: my $switchserver='';
1109: my $switchwarning;
1110: my ($role_text,$role_text_end,$sortkey,$role,$where,$trolecode,$tstart,
1111: $tend,$tremark,$tstatus,$tpstart,$tpend);
1.260 raeburn 1112: &Apache::lonnet::role_status($envkey,$update,$refresh,$now,\$role,\$where,
1.226 raeburn 1113: \$trolecode,\$tstatus,\$tstart,\$tend);
1114: next if (!defined($role) || $role eq '' || $role =~ /^gr/);
1115: $tremark='';
1116: $tpstart=' ';
1117: $tpend=' ';
1118: if ($env{'request.role'} eq $trolecode) {
1119: $tstatus='selected';
1120: }
1121: my $tbg;
1122: if (($tstatus eq 'is')
1123: || ($tstatus eq 'selected')
1124: || ($tstatus eq 'future')
1.274 raeburn 1125: || ($env{'form.display'} eq 'showall')) {
1.259 raeburn 1126: my $timezone = &role_timezone($where,$timezones);
1127: if ($tstart) {
1128: $tpstart=&Apache::lonlocal::locallocaltime($tstart,$timezone);
1129: }
1130: if ($tend) {
1131: $tpend=&Apache::lonlocal::locallocaltime($tend,$timezone);
1132: }
1.226 raeburn 1133: if ($tstatus eq 'is') {
1134: $tbg='LC_roles_is';
1135: $possiblerole=$trolecode;
1136: $countactive++;
1137: } elsif ($tstatus eq 'future') {
1138: $tbg='LC_roles_future';
1139: $button=0;
1140: $futureroles->{$trolecode} = $tstart.':'.$tend;
1141: $countfuture ++;
1142: } elsif ($tstatus eq 'expired') {
1143: $tbg='LC_roles_expired';
1144: $button=0;
1145: } elsif ($tstatus eq 'will_not') {
1146: $tbg='LC_roles_will_not';
1147: $tremark.=&mt('Expired after logout.').' ';
1148: } elsif ($tstatus eq 'selected') {
1149: $tbg='LC_roles_selected';
1150: $inrole=1;
1151: $countactive++;
1152: $tremark.=&mt('Currently selected.').' ';
1153: }
1154: my $trole;
1155: if ($role =~ /^cr\//) {
1156: my ($rdummy,$rdomain,$rauthor,$rrole)=split(/\//,$role);
1157: if ($tremark) { $tremark.='<br />'; }
1.298 bisitz 1158: $tremark.=&mt('Custom role defined by [_1].',$rauthor.':'.$rdomain);
1.226 raeburn 1159: }
1160: $trole=Apache::lonnet::plaintext($role);
1161: my $ttype;
1162: my $twhere;
1163: my ($tdom,$trest,$tsection)=
1164: split(/\//,Apache::lonnet::declutter($where));
1165: # First, Co-Authorship roles
1166: if (($role eq 'ca') || ($role eq 'aa')) {
1167: my $home = &Apache::lonnet::homeserver($trest,$tdom);
1168: my $allowed=0;
1169: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
1170: if (!$allowed) {
1171: $button=0;
1.248 raeburn 1172: $switchserver='otherserver='.$home.'&role='.$trolecode;
1.226 raeburn 1173: }
1174: #next if ($home eq 'no_host');
1175: $home = &Apache::lonnet::hostname($home);
1.288 raeburn 1176: $ttype='Authoring Space';
1.226 raeburn 1177: $twhere=&mt('User').': '.$trest.'<br />'.&mt('Domain').
1178: ': '.$tdom.'<br />'.
1179: ' '.&mt('Server').': '.$home;
1180: $env{'course.'.$tdom.'_'.$trest.'.description'}='ca';
1181: $tremark.=&Apache::lonhtmlcommon::authorbombs('/res/'.$tdom.'/'.$trest.'/');
1182: $sortkey=$role."$trest:$tdom";
1183: } elsif ($role eq 'au') {
1184: # Authors
1185: my $home = &Apache::lonnet::homeserver
1186: ($env{'user.name'},$env{'user.domain'});
1187: my $allowed=0;
1188: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
1189: if (!$allowed) {
1190: $button=0;
1.248 raeburn 1191: $switchserver='otherserver='.$home.'&role='.$trolecode;
1.226 raeburn 1192: }
1193: #next if ($home eq 'no_host');
1194: $home = &Apache::lonnet::hostname($home);
1.288 raeburn 1195: $ttype='Authoring Space';
1.226 raeburn 1196: $twhere=&mt('Domain').': '.$tdom.'<br />'.&mt('Server').
1197: ': '.$home;
1198: $env{'course.'.$tdom.'_'.$trest.'.description'}='ca';
1199: $tremark.=&Apache::lonhtmlcommon::authorbombs('/res/'.$tdom.'/'.$env{'user.name'}.'/');
1200: $sortkey=$role;
1201: } elsif ($trest) {
1202: my $tcourseid=$tdom.'_'.$trest;
1203: $ttype = &Apache::loncommon::course_type($tcourseid);
1.242 raeburn 1204: $trole = &Apache::lonnet::plaintext($role,$ttype,$tcourseid);
1.226 raeburn 1205: if ($env{'course.'.$tcourseid.'.description'}) {
1.254 raeburn 1206: my $home=$env{'course.'.$tcourseid.'.home'};
1.226 raeburn 1207: $twhere=$env{'course.'.$tcourseid.'.description'};
1208: $sortkey=$role."\0".$tdom."\0".$twhere."\0".$envkey;
1.248 raeburn 1209: $twhere = &HTML::Entities::encode($twhere,'"<>&');
1.226 raeburn 1210: unless ($twhere eq &mt('Currently not available')) {
1211: $twhere.=' <span class="LC_fontsize_small">'.
1212: &Apache::loncommon::syllabuswrapper(&mt('Syllabus'),$trest,$tdom).
1213: '</span>';
1.254 raeburn 1214: unless ($home && grep(/^\Q$home\E$/,@ids) && $loncaparev eq '') {
1.255 raeburn 1215: my $required = $env{'course.'.$tcourseid.'.internal.releaserequired'};
1.259 raeburn 1216: if ($required ne '') {
1217: ($switchserver,$switchwarning) =
1218: &check_release_required($loncaparev,$tcourseid,$trolecode,$required);
1219: if ($switchserver || $switchwarning) {
1220: $button = 0;
1221: }
1.254 raeburn 1222: }
1223: }
1.226 raeburn 1224: }
1225: } else {
1226: my %newhash=&Apache::lonnet::coursedescription($tcourseid);
1227: if (%newhash) {
1228: $sortkey=$role."\0".$tdom."\0".$newhash{'description'}.
1229: "\0".$envkey;
1.248 raeburn 1230: $twhere=&HTML::Entities::encode($newhash{'description'},'"<>&').
1231: ' <span class="LC_fontsize_small">'.
1232: &Apache::loncommon::syllabuswrapper(&mt('Syllabus'),$trest,$tdom).
1233: '</span>';
1.226 raeburn 1234: $ttype = $newhash{'type'};
1.243 raeburn 1235: $trole = &Apache::lonnet::plaintext($role,$ttype,$tcourseid);
1.254 raeburn 1236: my $home = $newhash{'home'};
1237: unless ($home && grep(/^\Q$home\E$/,@ids) && $loncaparev eq '') {
1.255 raeburn 1238: my $required = $newhash{'internal.releaserequired'};
1.259 raeburn 1239: if ($required ne '') {
1240: ($switchserver,$switchwarning) =
1241: &check_release_required($loncaparev,$tcourseid,$trolecode,$required);
1242: if ($switchserver || $switchwarning) {
1243: $button = 0;
1244: }
1.254 raeburn 1245: }
1246: }
1.226 raeburn 1247: } else {
1248: $twhere=&mt('Currently not available');
1249: $env{'course.'.$tcourseid.'.description'}=$twhere;
1250: $sortkey=$role."\0".$tdom."\0".$twhere."\0".$envkey;
1251: $ttype = 'Unavailable';
1252: }
1253: }
1254: if ($tsection) {
1255: $twhere.='<br />'.&mt('Section').': '.$tsection;
1256: }
1257: if ($role ne 'st') { $twhere.="<br />".&mt('Domain').":".$tdom; }
1258: } elsif ($tdom) {
1259: $ttype='Domain';
1260: $twhere=$tdom;
1261: $sortkey=$role.$twhere;
1262: } else {
1263: $ttype='System';
1264: $twhere=&mt('system wide');
1265: $sortkey=$role.$twhere;
1266: }
1267: ($role_text,$role_text_end) =
1268: &build_roletext($trolecode,$tdom,$trest,$tstatus,$tryagain,
1269: $advanced,$tremark,$tbg,$trole,$twhere,$tpstart,
1.254 raeburn 1270: $tpend,$nochoose,$button,$switchserver,$reinit,$switchwarning);
1.226 raeburn 1271: $roletext->{$envkey}=[$role_text,$role_text_end];
1272: if (!$sortkey) {$sortkey=$twhere."\0".$envkey;}
1273: $sortrole->{$sortkey}=$envkey;
1274: $roleclass->{$envkey}=$ttype;
1275: }
1276: }
1277: }
1278: return ($countactive,$countfuture,$inrole,$possiblerole);
1279: }
1280:
1.215 raeburn 1281: sub role_timezone {
1282: my ($where,$timezones) = @_;
1283: my $timezone;
1284: if (ref($timezones) eq 'HASH') {
1285: if ($where =~ m{^/($match_domain)/($match_courseid)}) {
1286: my $cdom = $1;
1287: my $cnum = $2;
1288: if ($cdom && $cnum) {
1289: if (!exists($timezones->{$cdom.'_'.$cnum})) {
1.259 raeburn 1290: my $tz;
1291: if ($env{'course.'.$cdom.'_'.$cnum.'.description'}) {
1292: $tz = $env{'course.'.$cdom.'_'.$cnum.'.timezone'};
1293: } else {
1294: my %timehash =
1295: &Apache::lonnet::get('environment',['timezone'],$cdom,$cnum);
1296: $tz = $timehash{'timezone'};
1297: }
1298: if ($tz eq '') {
1.215 raeburn 1299: if (!exists($timezones->{$cdom})) {
1300: my %domdefaults =
1301: &Apache::lonnet::get_domain_defaults($cdom);
1302: if ($domdefaults{'timezone_def'} eq '') {
1303: $timezones->{$cdom} = 'local';
1304: } else {
1305: $timezones->{$cdom} = $domdefaults{'timezone_def'};
1306: }
1307: }
1308: $timezones->{$cdom.'_'.$cnum} = $timezones->{$cdom};
1309: } else {
1310: $timezones->{$cdom.'_'.$cnum} =
1.259 raeburn 1311: &Apache::lonlocal::gettimezone($tz);
1.215 raeburn 1312: }
1313: }
1314: $timezone = $timezones->{$cdom.'_'.$cnum};
1315: }
1316: } else {
1317: my ($tdom) = ($where =~ m{^/($match_domain)});
1318: if ($tdom) {
1319: if (!exists($timezones->{$tdom})) {
1320: my %domdefaults = &Apache::lonnet::get_domain_defaults($tdom);
1321: if ($domdefaults{'timezone_def'} eq '') {
1322: $timezones->{$tdom} = 'local';
1323: } else {
1324: $timezones->{$tdom} = $domdefaults{'timezone_def'};
1325: }
1326: }
1327: $timezone = $timezones->{$tdom};
1328: }
1329: }
1330: if ($timezone eq 'local') {
1331: $timezone = undef;
1332: }
1333: }
1334: return $timezone;
1335: }
1336:
1.191 raeburn 1337: sub roletable_headers {
1338: my ($r,$roleclass,$sortrole,$nochoose) = @_;
1339: my $doheaders;
1340: if ((ref($sortrole) eq 'HASH') && (ref($roleclass) eq 'HASH')) {
1.212 bisitz 1341: $r->print('<br />'
1342: .&Apache::loncommon::start_data_table()
1343: .&Apache::loncommon::start_data_table_header_row()
1344: );
1.191 raeburn 1345: if (!$nochoose) { $r->print('<th> </th>'); }
1.212 bisitz 1346: $r->print('<th>'.&mt('User Role').'</th>'
1347: .'<th>'.&mt('Extent').'</th>'
1348: .'<th>'.&mt('Start').'</th>'
1349: .'<th>'.&mt('End').'</th>'
1350: .&Apache::loncommon::end_data_table_header_row()
1351: );
1.191 raeburn 1352: $doheaders=-1;
1353: my @roletypes = &roletypes();
1354: foreach my $type (@roletypes) {
1355: my $haverole=0;
1356: foreach my $which (sort {uc($a) cmp uc($b)} (keys(%{$sortrole}))) {
1357: if ($roleclass->{$sortrole->{$which}} =~ /^\Q$type\E/) {
1358: $haverole=1;
1359: }
1360: }
1361: if ($haverole) { $doheaders++; }
1362: }
1363: }
1364: return $doheaders;
1365: }
1366:
1367: sub roletypes {
1.288 raeburn 1368: my @types = ('Domain','Authoring Space','Course','Community','Unavailable','System');
1.191 raeburn 1369: return @types;
1370: }
1371:
1372: sub print_rolerows {
1373: my ($r,$doheaders,$roleclass,$sortrole,$dcroles,$roletext) = @_;
1374: if ((ref($roleclass) eq 'HASH') && (ref($sortrole) eq 'HASH')) {
1375: my @types = &roletypes();
1376: foreach my $type (@types) {
1377: my $output;
1378: foreach my $which (sort {uc($a) cmp uc($b)} (keys(%{$sortrole}))) {
1379: if ($roleclass->{$sortrole->{$which}} =~ /^\Q$type\E/) {
1380: if (ref($roletext) eq 'HASH') {
1.223 raeburn 1381: if (ref($roletext->{$sortrole->{$which}}) eq 'ARRAY') {
1382: $output.= &Apache::loncommon::start_data_table_row().
1383: $roletext->{$sortrole->{$which}}->[0].
1384: &Apache::loncommon::end_data_table_row();
1.251 raeburn 1385: if ($roletext->{$sortrole->{$which}}->[1] ne '') {
1386: $output .= &Apache::loncommon::continue_data_table_row().
1387: $roletext->{$sortrole->{$which}}->[1].
1388: &Apache::loncommon::end_data_table_row();
1389: }
1.223 raeburn 1390: }
1.191 raeburn 1391: if ($sortrole->{$which} =~ m-dc\./($match_domain)/-) {
1392: if (ref($dcroles) eq 'HASH') {
1393: if ($dcroles->{$1}) {
1.192 raeburn 1394: $output .= &adhoc_roles_row($1,'');
1.191 raeburn 1395: }
1396: }
1397: }
1398: }
1399: }
1400: }
1401: if ($output) {
1402: if ($doheaders > 0) {
1.212 bisitz 1403: $r->print(&Apache::loncommon::start_data_table_empty_row()
1404: .'<td align="center" colspan="5">'
1405: .&mt($type)
1406: .'</td>'
1407: .&Apache::loncommon::end_data_table_empty_row()
1408: );
1.191 raeburn 1409: }
1410: $r->print($output);
1411: }
1412: }
1413: }
1414: }
1415:
1416: sub findcourse_advice {
1.302 raeburn 1417: my ($r,$cattype) = @_;
1.191 raeburn 1418: my $domdesc = &Apache::lonnet::domain($env{'user.domain'},'description');
1.201 raeburn 1419: my $esc_dom = &HTML::Entities::encode($env{'user.domain'},'"<>&');
1.200 raeburn 1420: if (&Apache::lonnet::auto_run(undef,$env{'user.domain'})) {
1.191 raeburn 1421: $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).'
1422: <ul>
1423: <li>'.&mt('The course has yet to be created.').'</li>
1424: <li>'.&mt('Automatic enrollment of registered students has not been enabled for the course.').'</li>
1425: <li>'.&mt('You are in a section of course for which automatic enrollment in the corresponding LON-CAPA course is not active.').'</li>
1426: <li>'.&mt('The start date for automated enrollment has yet to be reached.').'</li>
1427: <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>
1428: </ul>');
1429: } else {
1430: $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 />');
1431: }
1.302 raeburn 1432: if (($cattype eq 'std') || ($cattype eq 'domonly')) {
1433: $r->print('<h3>'.&mt('Self-Enrollment').'</h3>'.
1434: '<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 />');
1435: $r->print(&mt('You can search for courses and communities which permit self-enrollment, if you would like to enroll in one.').'</p>'.
1436: &Apache::loncoursequeueadmin::queued_selfenrollment());
1437: }
1.216 raeburn 1438: return;
1439: }
1440:
1.234 raeburn 1441: sub requestcourse_advice {
1.306 raeburn 1442: my ($r,$cattype,$inrole) = @_;
1.234 raeburn 1443: my $domdesc = &Apache::lonnet::domain($env{'user.domain'},'description');
1444: my $esc_dom = &HTML::Entities::encode($env{'user.domain'},'"<>&');
1.306 raeburn 1445: my (%can_request,%request_doms,$output);
1.234 raeburn 1446: &Apache::lonnet::check_can_request($env{'user.domain'},\%can_request,\%request_doms);
1447: if (keys(%request_doms) > 0) {
1448: my ($types,$typename) = &Apache::loncommon::course_types();
1449: if ((ref($types) eq 'ARRAY') && (ref($typename) eq 'HASH')) {
1450: my (@reqdoms,@reqtypes);
1451: foreach my $type (sort(keys(%request_doms))) {
1452: push(@reqtypes,$type);
1453: if (ref($request_doms{$type}) eq 'ARRAY') {
1454: my $domstr = join(', ',map { &Apache::lonnet::domain($_) } sort(@{$request_doms{$type}}));
1.306 raeburn 1455: $output .=
1.238 bisitz 1456: '<li>'
1457: .&mt('[_1]'.$typename->{$type}.'[_2] in domain: [_3]',
1458: '<i>',
1459: '</i>',
1460: '<b>'.$domstr.'</b>')
1.306 raeburn 1461: .'</li>';
1.234 raeburn 1462: foreach my $dom (@{$request_doms{$type}}) {
1463: unless (grep(/^\Q$dom\E/,@reqdoms)) {
1464: push(@reqdoms,$dom);
1465: }
1466: }
1467: }
1468: }
1469: my @showtypes;
1470: foreach my $type (@{$types}) {
1471: if (grep(/^\Q$type\E$/,@reqtypes)) {
1472: push(@showtypes,$type);
1473: }
1474: }
1475: my $requrl = '/adm/requestcourse';
1476: if (@reqdoms == 1) {
1477: $requrl .= '?showdom='.$reqdoms[0];
1478: }
1479: if (@showtypes > 0) {
1480: $requrl.=(($requrl=~/\?/)?'&':'?').'crstype='.$showtypes[0];
1481: }
1482: if (@reqdoms == 1 || @showtypes > 0) {
1483: $requrl .= '&state=crstype&action=new';
1.306 raeburn 1484: }
1.307 ! raeburn 1485: if ($output) {
! 1486: $r->print('<h3>'.&mt('Request creation of a course or community').'</h3>'.
! 1487: '<p>'.
! 1488: &mt('You have rights to request the creation of courses and/or communities in the following domain(s):').
! 1489: '<ul>'.
! 1490: $output.
! 1491: '</ul>'.
! 1492: &mt('Use the [_1]request form[_2] to submit a request for creation of a new course or community.',
! 1493: '<a href="'.$requrl.'">','</a>').
! 1494: '</p>');
! 1495: }
1.234 raeburn 1496: }
1.302 raeburn 1497: } elsif (!$env{'user.adv'}) {
1.306 raeburn 1498: if ($inrole) {
1499: $r->print('<h3>'.&mt('Currently no additional roles, courses or communities').'</h3>');
1500: } else {
1501: $r->print('<h3>'.&mt('Currently no active roles, courses or communities').'</h3>');
1502: }
1.302 raeburn 1503: &findcourse_advice($r,$cattype);
1.234 raeburn 1504: }
1505: return;
1506: }
1507:
1.175 albertel 1508: sub privileges_info {
1509: my ($which) = @_;
1510: my $output;
1511:
1512: $which ||= $env{'request.role'};
1513:
1514: foreach my $envkey (sort(keys(%env))) {
1515: next if ($envkey!~/^user\.priv\.\Q$which\E\.(.*)/);
1516:
1517: my $where=$1;
1518: my $ttype;
1519: my $twhere;
1520: my (undef,$tdom,$trest,$tsec)=split(m{/},$where);
1521: if ($trest) {
1522: if ($env{'course.'.$tdom.'_'.$trest.'.description'} eq 'ca') {
1.288 raeburn 1523: $ttype='Authoring Space';
1.175 albertel 1524: $twhere='User: '.$trest.', Domain: '.$tdom;
1525: } else {
1526: $ttype= &Apache::loncommon::course_type($tdom.'_'.$trest);
1527: $twhere=$env{'course.'.$tdom.'_'.$trest.'.description'};
1528: if ($tsec) {
1529: my $sec_type = 'Section';
1530: if (exists($env{"user.role.gr.$where"})) {
1531: $sec_type = 'Group';
1532: }
1533: $twhere.=' ('.$sec_type.': '.$tsec.')';
1534: }
1535: }
1536: } elsif ($tdom) {
1537: $ttype='Domain';
1538: $twhere=$tdom;
1539: } else {
1540: $ttype='System';
1541: $twhere='/';
1542: }
1.204 bisitz 1543: $output .= "\n<h3>".&mt($ttype).': '.$twhere.'</h3>'."\n<ul>";
1.175 albertel 1544: foreach my $priv (sort(split(/:/,$env{$envkey}))) {
1545: next if (!$priv);
1546:
1547: my ($prv,$restr)=split(/\&/,$priv);
1548: my $trestr='';
1549: if ($restr ne 'F') {
1550: $trestr.=' ('.
1551: join(', ',
1552: map { &Apache::lonnet::plaintext($_) }
1553: (split('',$restr))).') ';
1554: }
1555: $output .= "\n\t".
1556: '<li>'.&Apache::lonnet::plaintext($prv).$trestr.'</li>';
1557: }
1558: $output .= "\n".'</ul>';
1559: }
1560: return $output;
1561: }
1562:
1.110 raeburn 1563: sub build_roletext {
1.254 raeburn 1564: my ($trolecode,$tdom,$trest,$tstatus,$tryagain,$advanced,$tremark,$tbg,$trole,$twhere,$tpstart,$tpend,$nochoose,$button,$switchserver,$reinit,$switchwarning) = @_;
1.223 raeburn 1565: my ($roletext,$roletext_end);
1.132 albertel 1566: my $is_dc=($trolecode =~ m/^dc\./);
1567: my $rowspan=($is_dc) ? ''
1568: : ' rowspan="2" ';
1569:
1.110 raeburn 1570: unless ($nochoose) {
1.134 www 1571: my $buttonname=$trolecode;
1572: $buttonname=~s/\W//g;
1.110 raeburn 1573: if (!$button) {
1574: if ($switchserver) {
1.212 bisitz 1575: $roletext.='<td'.$rowspan.' class="'.$tbg.'">'
1576: .'<a href="/adm/switchserver?'.$switchserver.'">'
1577: .&mt('Switch Server')
1578: .'</a></td>';
1.110 raeburn 1579: } else {
1.212 bisitz 1580: $roletext.=('<td'.$rowspan.' class="'.$tbg.'"> </td>');
1.110 raeburn 1581: }
1.255 raeburn 1582: if ($switchwarning) {
1583: if ($tremark eq '') {
1584: $tremark = $switchwarning;
1585: } else {
1586: $tremark .= '<br />'.$switchwarning;
1587: }
1588: }
1.110 raeburn 1589: } elsif ($tstatus eq 'is') {
1.212 bisitz 1590: $roletext.='<td'.$rowspan.' class="'.$tbg.'">'.
1591: '<input name="'.$buttonname.'" type="button" value="'.
1.225 bisitz 1592: &mt('Select').'" onclick="javascript:enterrole(this.form,\''.
1.192 raeburn 1593: $trolecode."','".$buttonname.'\');" /></td>';
1.110 raeburn 1594: } elsif ($tryagain) {
1595: $roletext.=
1.212 bisitz 1596: '<td'.$rowspan.' class="'.$tbg.'">'.
1597: '<input name="'.$buttonname.'" type="button" value="'.
1.225 bisitz 1598: &mt('Try Selecting Again').'" onclick="javascript:enterrole(this.form,\''.
1.192 raeburn 1599: $trolecode."','".$buttonname.'\');" /></td>';
1.110 raeburn 1600: } elsif ($advanced) {
1601: $roletext.=
1.212 bisitz 1602: '<td'.$rowspan.' class="'.$tbg.'">'.
1603: '<input name="'.$buttonname.'" type="button" value="'.
1.225 bisitz 1604: &mt('Re-Initialize').'" onclick="javascript:enterrole(this.form,\''.
1.192 raeburn 1605: $trolecode."','".$buttonname.'\');" /></td>';
1.209 raeburn 1606: } elsif ($reinit) {
1607: $roletext.=
1.212 bisitz 1608: '<td'.$rowspan.' class="'.$tbg.'">'.
1609: '<input name="'.$buttonname.'" type="button" value="'.
1.225 bisitz 1610: &mt('Re-Select').'" onclick="javascript:enterrole(this.form,\''.
1.209 raeburn 1611: $trolecode."','".$buttonname.'\');" /></td>';
1.110 raeburn 1612: } else {
1.209 raeburn 1613: $roletext.=
1.212 bisitz 1614: '<td'.$rowspan.' class="'.$tbg.'">'.
1615: '<input name="'.$buttonname.'" type="button" value="'.
1.225 bisitz 1616: &mt('Re-Select').'" onclick="javascript:enterrole(this.form,\''.
1.209 raeburn 1617: $trolecode."','".$buttonname.'\');" /></td>';
1.110 raeburn 1618: }
1619: }
1.165 albertel 1620: if ($trolecode !~ m/^(dc|ca|au|aa)\./) {
1621: $tremark.=&Apache::lonannounce::showday(time,1,
1622: &Apache::lonannounce::readcalendar($tdom.'_'.$trest));
1623: }
1.212 bisitz 1624: $roletext.='<td>'.$trole.'</td>'
1625: .'<td>'.$twhere.'</td>'
1626: .'<td>'.$tpstart.'</td>'
1.223 raeburn 1627: .'<td>'.$tpend.'</td>';
1.132 albertel 1628: if (!$is_dc) {
1.223 raeburn 1629: $roletext_end = '<td colspan="4">'.
1630: $tremark.' '.
1631: '</td>';
1.132 albertel 1632: }
1.223 raeburn 1633: return ($roletext,$roletext_end);
1.110 raeburn 1634: }
1635:
1.193 raeburn 1636: sub check_author_homeserver {
1.183 www 1637: my ($uname,$udom)=@_;
1.193 raeburn 1638: if (($uname eq '') || ($udom eq '')) {
1639: return ('fail','');
1640: }
1.183 www 1641: my $home = &Apache::lonnet::homeserver($uname,$udom);
1.193 raeburn 1642: if (&Apache::lonnet::host_domain($home) ne $udom) {
1643: return ('fail',$home);
1644: }
1.183 www 1645: my @ids=&Apache::lonnet::current_machine_ids();
1.193 raeburn 1646: if (grep(/^\Q$home\E$/,@ids)) {
1647: return ('ok',$home);
1648: } else {
1649: return ('switchserver',$home);
1.183 www 1650: }
1651: }
1652:
1.104 raeburn 1653: sub check_fordc {
1.260 raeburn 1654: my ($dcroles,$update,$then) = @_;
1.104 raeburn 1655: my $numdc = 0;
1.118 albertel 1656: if ($env{'user.adv'}) {
1657: foreach my $envkey (sort keys %env) {
1.170 albertel 1658: if ($envkey=~/^user\.role\.dc\.\/($match_domain)\/$/) {
1.104 raeburn 1659: my $dcdom = $1;
1660: my $livedc = 1;
1.118 albertel 1661: my ($tstart,$tend)=split(/\./,$env{$envkey});
1.260 raeburn 1662: my $limit = $update;
1663: if ($env{'request.role'} eq 'dc./'.$dcdom.'/') {
1664: $limit = $then;
1665: }
1666: if ($tstart && $tstart>$limit) { $livedc = 0; }
1667: if ($tend && $tend <$limit) { $livedc = 0; }
1.104 raeburn 1668: if ($livedc) {
1669: $$dcroles{$dcdom} = $envkey;
1.105 raeburn 1670: $numdc++;
1.104 raeburn 1671: }
1672: }
1673: }
1674: }
1675: return $numdc;
1676: }
1677:
1.185 raeburn 1678: sub adhoc_course_role {
1.260 raeburn 1679: my ($refresh,$update,$then) = @_;
1.239 raeburn 1680: my ($cdom,$cnum,$crstype);
1.201 raeburn 1681: $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
1682: $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.239 raeburn 1683: $crstype = &Apache::loncommon::course_type();
1.260 raeburn 1684: if (&check_forcc($cdom,$cnum,$refresh,$update,$then,$crstype)) {
1.185 raeburn 1685: my $setprivs;
1.198 raeburn 1686: if (!defined($env{'user.role.'.$env{'form.switchrole'}})) {
1.185 raeburn 1687: $setprivs = 1;
1688: } else {
1.198 raeburn 1689: my ($start,$end) = split(/\./,$env{'user.role.'.$env{'form.switchrole'}});
1.232 raeburn 1690: if (($start && ($start>$refresh || $start == -1)) ||
1.260 raeburn 1691: ($end && $end<$update)) {
1.185 raeburn 1692: $setprivs = 1;
1693: }
1.232 raeburn 1694: }
1.278 raeburn 1695: unless ($setprivs) {
1696: if (!exists($env{'user.priv.'.$env{'form.switchrole'}.'./'})) {
1697: $setprivs = 1;
1698: }
1699: }
1.185 raeburn 1700: if ($setprivs) {
1.297 raeburn 1701: if ($env{'form.switchrole'} =~ m-^(in|ta|ep|ad|st|cr)(.*?)\./\Q$cdom\E/\Q$cnum\E/?(\w*)$-) {
1.185 raeburn 1702: my $role = $1;
1703: my $custom_role = $2;
1704: my $usec = $3;
1705: if ($role eq 'cr') {
1.199 raeburn 1706: if ($custom_role =~ m-^/$match_domain/$match_username/\w+$-) {
1.185 raeburn 1707: $role .= $custom_role;
1708: } else {
1709: return;
1710: }
1711: }
1.208 raeburn 1712: my (%userroles,%newrole,%newgroups,%group_privs);
1713: my %cgroups =
1714: &Apache::lonnet::get_active_groups($env{'user.domain'},
1715: $env{'user.name'},$cdom,$cnum);
1716: foreach my $group (keys(%cgroups)) {
1717: $group_privs{$group} =
1718: $env{'user.priv.cc./'.$cdom.'/'.$cnum.'./'.$cdom.'/'.$cnum.'/'.$group};
1719: }
1720: $newgroups{'/'.$cdom.'/'.$cnum} = \%group_privs;
1.185 raeburn 1721: my $area = '/'.$cdom.'/'.$cnum;
1722: my $spec = $role.'.'.$area;
1723: if ($usec ne '') {
1724: $spec .= '/'.$usec;
1725: $area .= '/'.$usec;
1726: }
1.278 raeburn 1727: if ($role =~ /^cr/) {
1728: &Apache::lonnet::custom_roleprivs(\%newrole,$role,$cdom,$cnum,$spec,$area);
1729: } else {
1730: &Apache::lonnet::standard_roleprivs(\%newrole,$role,$cdom,$spec,$cnum,$area);
1731: }
1.208 raeburn 1732: &Apache::lonnet::set_userprivs(\%userroles,\%newrole,\%newgroups);
1.232 raeburn 1733: my $adhocstart = $refresh-1;
1.185 raeburn 1734: $userroles{'user.role.'.$spec} = $adhocstart.'.';
1.186 raeburn 1735: &Apache::lonnet::appenv(\%userroles,[$role,'cm']);
1.185 raeburn 1736: }
1737: }
1738: }
1739: return;
1740: }
1741:
1742: sub check_forcc {
1.260 raeburn 1743: my ($cdom,$cnum,$refresh,$update,$then,$crstype) = @_;
1.239 raeburn 1744: my ($is_cc,$ccrole);
1745: if ($crstype eq 'Community') {
1746: $ccrole = 'co';
1747: } else {
1748: $ccrole = 'cc';
1749: }
1.266 droeschl 1750: if (&Apache::lonnet::is_course($cdom,$cnum)) {
1751: my $envkey = 'user.role.'.$ccrole.'./'.$cdom.'/'.$cnum;
1752: if (defined($env{$envkey})) {
1753: $is_cc = 1;
1754: my ($tstart,$tend)=split(/\./,$env{$envkey});
1755: my $limit = $update;
1756: if ($env{'request.role'} eq $ccrole.'./'.$cdom.'/'.$cnum) {
1757: $limit = $then;
1.185 raeburn 1758: }
1.266 droeschl 1759: if ($tstart && $tstart>$refresh) { $is_cc = 0; }
1760: if ($tend && $tend <$limit) { $is_cc = 0; }
1.185 raeburn 1761: }
1762: }
1763: return $is_cc;
1764: }
1765:
1.254 raeburn 1766: sub check_release_required {
1.255 raeburn 1767: my ($loncaparev,$tcourseid,$trolecode,$required) = @_;
1.254 raeburn 1768: my ($switchserver,$warning);
1.255 raeburn 1769: if ($required ne '') {
1770: my ($reqdmajor,$reqdminor) = ($required =~ /^(\d+)\.(\d+)$/);
1.257 raeburn 1771: my ($major,$minor) = ($loncaparev =~ /^\'?(\d+)\.(\d+)\.[\w.\-]+\'?$/);
1.254 raeburn 1772: if ($reqdmajor ne '' && $reqdminor ne '') {
1773: my $otherserver;
1774: if (($major eq '' && $minor eq '') ||
1775: (($reqdmajor > $major) || (($reqdmajor == $major) && ($reqdminor > $minor)))) {
1.303 raeburn 1776: my ($userdomserver) = &Apache::lonnet::choose_server($env{'user.domain'},undef,$required,1);
1.254 raeburn 1777: my $switchlcrev =
1778: &Apache::lonnet::get_server_loncaparev($env{'user.domain'},
1779: $userdomserver);
1.257 raeburn 1780: my ($swmajor,$swminor) = ($switchlcrev =~ /^\'?(\d+)\.(\d+)\.[\w.\-]+\'?$/);
1.254 raeburn 1781: if (($swmajor eq '' && $swminor eq '') || ($reqdmajor > $swmajor) ||
1782: (($reqdmajor == $swmajor) && ($reqdminor > $swminor))) {
1783: my $cdom = $env{'course.'.$tcourseid.'.domain'};
1784: if ($cdom ne $env{'user.domain'}) {
1.303 raeburn 1785: my ($coursedomserver,$coursehostname) = &Apache::lonnet::choose_server($cdom,undef,$required,1);
1.254 raeburn 1786: my $serverhomeID = &Apache::lonnet::get_server_homeID($coursehostname);
1787: my $serverhomedom = &Apache::lonnet::host_domain($serverhomeID);
1788: my %defdomdefaults = &Apache::lonnet::get_domain_defaults($serverhomedom);
1789: my %udomdefaults = &Apache::lonnet::get_domain_defaults($env{'user.domain'});
1790: my $remoterev = &Apache::lonnet::get_server_loncaparev($serverhomedom,$coursedomserver);
1791: my $canhost =
1792: &Apache::lonnet::can_host_session($env{'user.domain'},
1793: $coursedomserver,
1794: $remoterev,
1795: $udomdefaults{'remotesessions'},
1796: $defdomdefaults{'hostedsessions'});
1797:
1798: if ($canhost) {
1799: $otherserver = $coursedomserver;
1800: } else {
1801: $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.");
1802: }
1803: } else {
1804: $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).");
1805: }
1806: } else {
1807: $otherserver = $userdomserver;
1808: }
1809: }
1810: if ($otherserver ne '') {
1811: $switchserver = 'otherserver='.$otherserver.'&role='.$trolecode;
1812: }
1813: }
1814: }
1815: return ($switchserver,$warning);
1816: }
1817:
1.108 raeburn 1818: sub courselink {
1.193 raeburn 1819: my ($dcdom,$rowtype) = @_;
1.109 raeburn 1820: my $courseform=&Apache::loncommon::selectcourse_link
1.152 raeburn 1821: ('rolechoice','dccourse'.$rowtype.'_'.$dcdom,
1822: 'dcdomain'.$rowtype.'_'.$dcdom,'coursedesc'.$rowtype.'_'.
1.239 raeburn 1823: $dcdom,$dcdom,undef,'Course/Community');
1.138 raeburn 1824: my $hiddenitems = '<input type="hidden" name="dcdomain'.$rowtype.'_'.$dcdom.'" value="'.$dcdom.'" />'.
1825: '<input type="hidden" name="origdom'.$rowtype.'_'.$dcdom.'" value="'.$dcdom.'" />'.
1826: '<input type="hidden" name="dccourse'.$rowtype.'_'.$dcdom.'" value="" />'.
1827: '<input type="hidden" name="coursedesc'.$rowtype.'_'.$dcdom.'" value="" />';
1.112 raeburn 1828: return $courseform.$hiddenitems;
1.109 raeburn 1829: }
1830:
1831: sub coursepick_jscript {
1.184 raeburn 1832: my %lt = &Apache::lonlocal::texthash(
1.239 raeburn 1833: 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 1834: youc => 'You can only use this screen to select courses and communities in the current domain.',
1.184 raeburn 1835: );
1.104 raeburn 1836: my $verify_script = <<"END";
1.179 raeburn 1837: <script type="text/javascript">
1.225 bisitz 1838: // <![CDATA[
1.108 raeburn 1839: function verifyCoursePick(caller) {
1840: var numbutton = getIndex(caller)
1.112 raeburn 1841: var pickedCourse = document.rolechoice.elements[numbutton+4].value
1842: var pickedDomain = document.rolechoice.elements[numbutton+2].value
1843: if (document.rolechoice.elements[numbutton+2].value == document.rolechoice.elements[numbutton+3].value) {
1.104 raeburn 1844: if (pickedCourse != '') {
1.108 raeburn 1845: if (numbutton != -1) {
1846: var courseTarget = "cc./"+pickedDomain+"/"+pickedCourse
1847: document.rolechoice.elements[numbutton+1].name = courseTarget
1848: document.rolechoice.submit()
1849: }
1.104 raeburn 1850: }
1851: else {
1.184 raeburn 1852: alert("$lt{'plsu'}");
1.104 raeburn 1853: }
1854: }
1855: else {
1.184 raeburn 1856: alert("$lt{'youc'}")
1.104 raeburn 1857: }
1858: }
1.109 raeburn 1859: function getIndex(caller) {
1.108 raeburn 1860: for (var i=0;i<document.rolechoice.elements.length;i++) {
1.109 raeburn 1861: if (document.rolechoice.elements[i] == caller) {
1.108 raeburn 1862: return i;
1863: }
1864: }
1865: return -1;
1866: }
1.225 bisitz 1867: // ]]>
1.104 raeburn 1868: </script>
1869: END
1.109 raeburn 1870: return $verify_script;
1.104 raeburn 1871: }
1872:
1.193 raeburn 1873: sub coauthorlink {
1874: my ($dcdom,$rowtype) = @_;
1875: my $coauthorform=&Apache::loncommon::selectauthor_link('rolechoice',$dcdom);
1876: my $hiddenitems = '<input type="hidden" name="adhoccauname'.$rowtype.'_'.$dcdom.'" value="" />';
1877: return $coauthorform.$hiddenitems;
1878: }
1879:
1.113 raeburn 1880: sub display_cc_role {
1881: my $rolekey = shift;
1.223 raeburn 1882: my ($roletext,$roletext_end);
1.118 albertel 1883: my $advanced = $env{'user.adv'};
1884: my $tryagain = $env{'form.tryagain'};
1.113 raeburn 1885: unless ($rolekey =~/^error\:/) {
1.240 raeburn 1886: if ($rolekey =~ m{^user\.role\.(cc|co)\./($match_domain)/($match_courseid)$}) {
1887: my $ccrole = $1;
1.249 raeburn 1888: my $tdom = $2;
1889: my $trest = $3;
1890: my $tcourseid = $tdom.'_'.$trest;
1891: my $trolecode = $ccrole.'./'.$tdom.'/'.$trest;
1.113 raeburn 1892: my $twhere;
1.152 raeburn 1893: my $ttype;
1.212 bisitz 1894: my $tbg='LC_roles_is';
1.113 raeburn 1895: my %newhash=&Apache::lonnet::coursedescription($tcourseid);
1896: if (%newhash) {
1897: $twhere=$newhash{'description'}.
1.261 bisitz 1898: ' <span class="LC_fontsize_small">'.
1.249 raeburn 1899: &Apache::loncommon::syllabuswrapper(&mt('Syllabus'),$trest,$tdom).
1.211 tempelho 1900: '</span>';
1.153 raeburn 1901: $ttype = $newhash{'type'};
1.113 raeburn 1902: } else {
1903: $twhere=&mt('Currently not available');
1.118 albertel 1904: $env{'course.'.$tcourseid.'.description'}=$twhere;
1.110 raeburn 1905: }
1.242 raeburn 1906: my $trole = &Apache::lonnet::plaintext($ccrole,$ttype,$tcourseid);
1.258 raeburn 1907: $twhere.="<br />".&mt('Domain').":".$tdom;
1.249 raeburn 1908: ($roletext,$roletext_end) = &build_roletext($trolecode,$tdom,$trest,'is',$tryagain,$advanced,'',$tbg,$trole,$twhere,'','','',1,'');
1.104 raeburn 1909: }
1910: }
1.223 raeburn 1911: return ($roletext,$roletext_end);
1.104 raeburn 1912: }
1913:
1.192 raeburn 1914: sub adhoc_roles_row {
1.138 raeburn 1915: my ($dcdom,$rowtype) = @_;
1.212 bisitz 1916: my $output = &Apache::loncommon::continue_data_table_row()
1917: .' <td colspan="5">'
1918: .&mt('[_1]Ad hoc[_2] roles in domain [_3] --'
1919: ,'<span class="LC_cusr_emph">','</span>',$dcdom)
1.227 bisitz 1920: .' ';
1.193 raeburn 1921: my $selectcclink = &courselink($dcdom,$rowtype);
1.239 raeburn 1922: my $ccrole = &Apache::lonnet::plaintext('co',undef,undef,1);
1.182 www 1923: my $carole = &Apache::lonnet::plaintext('ca');
1.193 raeburn 1924: my $selectcalink = &coauthorlink($dcdom,$rowtype);
1.227 bisitz 1925: $output.=$ccrole.': '.$selectcclink
1.249 raeburn 1926: .' | '.$carole.': '.$selectcalink.'</td>'
1.212 bisitz 1927: .&Apache::loncommon::end_data_table_row();
1.108 raeburn 1928: return $output;
1929: }
1930:
1.104 raeburn 1931: sub recent_filename {
1932: my $area=shift;
1.149 www 1933: return 'nohist_recent_'.&escape($area);
1.104 raeburn 1934: }
1935:
1.139 raeburn 1936: sub courseloadpage {
1937: my ($courseid) = @_;
1938: my $startpage;
1.144 albertel 1939: my %entry_settings = &Apache::lonnet::get('nohist_whatsnew',
1940: [$courseid.':courseinit']);
1.139 raeburn 1941: my ($tmp) = %entry_settings;
1.144 albertel 1942: unless ($tmp =~ /^error: 2 /) {
1.139 raeburn 1943: $startpage = $entry_settings{$courseid.':courseinit'};
1944: }
1945: if ($startpage eq '') {
1946: if (exists($env{'environment.course_init_display'})) {
1947: $startpage = $env{'environment.course_init_display'};
1948: }
1949: }
1950: return $startpage;
1951: }
1952:
1.260 raeburn 1953: sub update_session_roles {
1954: my $then=$env{'user.login.time'};
1955: my $refresh=$env{'user.refresh.time'};
1956: if (!$refresh) {
1957: $refresh = $then;
1958: }
1959: my $update = $env{'user.update.time'};
1960: if (!$update) {
1961: $update = $then;
1962: }
1963: my $now = time;
1964: my %roleshash =
1965: &Apache::lonnet::get_my_roles('','','userroles',
1966: ['active','future','previous'],
1967: undef,undef,1);
1968: my ($msg,@newsec,$oldsec,$currrole_expired,@changed_roles,
1.264 raeburn 1969: %changed_groups,%dbroles,%deletedroles,%allroles,%allgroups,
1.260 raeburn 1970: %userroles,%checkedgroup,%crprivs,$hasgroups,%rolechange,
1971: %groupchange,%newrole,%newgroup,%customprivchg,%groups_roles,
1972: @rolecodes);
1973: my @possroles = ('cr','st','ta','ad','ep','in','co','cc');
1974: my %courseroles;
1975: foreach my $item (keys(%roleshash)) {
1976: my ($uname,$udom,$role,$remainder) = split(/:/,$item,4);
1977: my ($tstart,$tend) = split(/:/,$roleshash{$item});
1978: my ($section,$group,@group_privs);
1979: if ($role =~ m{^gr/(\w*)$}) {
1980: $role = 'gr';
1981: my $priv = $1;
1982: next if ($tstart eq '-1');
1983: if (&curr_role_status($tstart,$tend,$refresh,$now) eq 'active') {
1984: if ($priv ne '') {
1985: push(@group_privs,$priv);
1986: }
1987: }
1988: if ($remainder =~ /:/) {
1989: (my $additional_privs,$group) =
1990: ($remainder =~ /^([\w:]+):([^:]+)$/);
1991: if ($additional_privs ne '') {
1992: if (&curr_role_status($tstart,$tend,$refresh,$now) eq 'active') {
1993: push(@group_privs,split(/:/,$additional_privs));
1994: @group_privs = sort(@group_privs);
1995: }
1996: }
1997: } else {
1998: $group = $remainder;
1999: }
2000: } else {
2001: $section = $remainder;
2002: }
2003: my $where = "/$udom/$uname";
2004: if ($section ne '') {
2005: $where .= "/$section";
2006: } elsif ($group ne '') {
2007: $where .= "/$group";
2008: }
2009: my $rolekey = "$role.$where";
2010: my $envkey = "user.role.$rolekey";
2011: $dbroles{$envkey} = 1;
2012: if (($env{'request.role'} eq $rolekey) && ($role ne 'st')) {
2013: if (&curr_role_status($tstart,$tend,$refresh,$now) ne 'active') {
2014: $currrole_expired = 1;
2015: }
2016: }
2017: if ($env{$envkey} eq '') {
2018: my $status_in_db =
1.271 raeburn 2019: &curr_role_status($tstart,$tend,$now,$now);
1.260 raeburn 2020: &gather_roleprivs(\%allroles,\%allgroups,\%userroles,$where,$role,$tstart,$tend,$status_in_db);
2021: if (($role eq 'st') && ($env{'request.role'} =~ m{^\Q$role\E\.\Q/$udom/$uname\E})) {
2022: if ($status_in_db eq 'active') {
2023: if ($section eq '') {
2024: push(@newsec,'none');
2025: } else {
2026: push(@newsec,$section);
2027: }
2028: }
2029: } else {
2030: unless (grep(/^\Q$role\E$/,@changed_roles)) {
2031: push(@changed_roles,$role);
2032: }
2033: if ($status_in_db ne 'previous') {
2034: if ($role eq 'gr') {
2035: $newgroup{$rolekey} = $status_in_db;
2036: if ($status_in_db eq 'active') {
2037: unless (ref($courseroles{$udom}) eq 'HASH') {
2038: %{$courseroles{$udom}} =
2039: &Apache::lonnet::get_my_roles('','','userroles',
2040: ['active'],\@possroles,
2041: [$udom],1);
2042: }
2043: &Apache::lonnet::get_groups_roles($udom,$uname,
2044: $courseroles{$udom},
2045: \@rolecodes,\%groups_roles);
2046: }
2047: } else {
2048: $newrole{$rolekey} = $status_in_db;
2049: }
2050: }
2051: }
2052: } else {
2053: my ($currstart,$currend) = split(/\./,$env{$envkey});
2054: if ($role eq 'gr') {
2055: if (&curr_role_status($currstart,$currend,$refresh,$update) ne 'previous') {
2056: $hasgroups = 1;
2057: }
2058: }
2059: if (($currstart ne $tstart) || ($currend ne $tend)) {
2060: my $status_in_env =
2061: &curr_role_status($currstart,$currend,$refresh,$update);
2062: my $status_in_db =
1.271 raeburn 2063: &curr_role_status($tstart,$tend,$now,$now);
1.260 raeburn 2064: if ($status_in_env ne $status_in_db) {
2065: if ($status_in_env eq 'active') {
2066: if ($role eq 'st') {
2067: if ($env{'request.role'} eq $rolekey) {
2068: my $switchsection;
2069: unless (ref($courseroles{$udom}) eq 'HASH') {
2070: %{$courseroles{$udom}} =
2071: &Apache::lonnet::get_my_roles('','','userroles',
2072: ['active'],
2073: \@possroles,[$udom],1);
2074: }
2075: foreach my $crsrole (keys(%{$courseroles{$udom}})) {
2076: if ($crsrole =~ /^\Q$uname\E:\Q$udom\E:st/) {
2077: $switchsection = 1;
2078: last;
2079: }
2080: }
2081: if ($switchsection) {
2082: if ($section eq '') {
2083: $oldsec = 'none';
2084: } else {
2085: $oldsec = $section;
2086: }
2087: &gather_roleprivs(\%allroles,\%allgroups,\%userroles,$where,$role,$tstart,$tend,$status_in_db);
2088: } else {
2089: $currrole_expired = 1;
2090: next;
2091: }
2092: }
2093: }
2094: unless ($rolekey eq $env{'request.role'}) {
2095: if ($role eq 'gr') {
2096: &Apache::lonnet::delete_env_groupprivs($where,\%courseroles,\@possroles);
2097: } else {
2098: &Apache::lonnet::delenv("user.priv.$rolekey",undef,[$role]);
2099: &Apache::lonnet::delenv("user.priv.cm.$where",undef,['cm']);
2100: }
2101: &gather_roleprivs(\%allroles,\%allgroups,\%userroles,$where,$role,$tstart,$tend,$status_in_db);
2102: }
2103: } elsif ($status_in_db eq 'active') {
2104: if (($role eq 'st') &&
2105: ($env{'request.role'} =~ m{^\Q$role\E\.\Q/$udom/$uname\E})) {
2106: if ($section eq '') {
2107: push(@newsec,'none');
2108: } else {
2109: push(@newsec,$section);
2110: }
2111: } elsif ($role eq 'gr') {
2112: unless (ref($courseroles{$udom}) eq 'HASH') {
2113: %{$courseroles{$udom}} =
2114: &Apache::lonnet::get_my_roles('','','userroles',
2115: ['active'],
2116: \@possroles,[$udom],1);
2117: }
2118: &Apache::lonnet::get_groups_roles($udom,$uname,
2119: $courseroles{$udom},
2120: \@rolecodes,\%groups_roles);
2121: }
2122: &gather_roleprivs(\%allroles,\%allgroups,\%userroles,$where,$role,$tstart,$tend,$status_in_db);
2123: }
2124: unless (grep(/^\Q$role\E$/,@changed_roles)) {
2125: push(@changed_roles,$role);
2126: }
2127: if ($role eq 'gr') {
2128: $groupchange{"/$udom/$uname"}{$group} = $status_in_db;
2129: } else {
2130: $rolechange{$rolekey} = $status_in_db;
2131: }
2132: }
2133: } else {
2134: if ($role eq 'gr') {
2135: unless ($checkedgroup{$where}) {
2136: my $status_in_db =
2137: &curr_role_status($tstart,$tend,$refresh,$now);
2138: if ($tstart eq '-1') {
2139: $status_in_db = 'deleted';
2140: }
2141: unless (ref($courseroles{$udom}) eq 'HASH') {
2142: %{$courseroles{$udom}} =
2143: &Apache::lonnet::get_my_roles('','','userroles',
2144: ['active'],
2145: \@possroles,[$udom],1);
2146: }
2147: if (ref($courseroles{$udom}) eq 'HASH') {
2148: foreach my $item (keys(%{$courseroles{$udom}})) {
2149: next unless ($item =~ /^\Q$uname\E/);
2150: my ($cnum,$cdom,$crsrole,$crssec) = split(/:/,$item);
2151: my $area = '/'.$cdom.'/'.$cnum;
2152: if ($crssec ne '') {
2153: $area .= '/'.$crssec;
2154: }
2155: my $crsrolekey = $crsrole.'.'.$area;
2156: my $currprivs = $env{'user.priv.'.$crsrole.'.'.$area.'.'.$where};
2157: $currprivs =~ s/^://;
2158: $currprivs =~ s/\&F$//;
2159: my @curr_grp_privs = split(/\&F:/,$currprivs);
2160: @curr_grp_privs = sort(@curr_grp_privs);
2161: my @diffs;
2162: if (@group_privs > 0 || @curr_grp_privs > 0) {
2163: @diffs = &Apache::loncommon::compare_arrays(\@group_privs,\@curr_grp_privs);
2164: }
2165: if (@diffs == 0) {
2166: last;
2167: } else {
2168: unless(grep(/^\Qgr\E$/,@rolecodes)) {
2169: push(@rolecodes,'gr');
2170: }
2171: &gather_roleprivs(\%allroles,\%allgroups,
2172: \%userroles,$where,$role,
2173: $tstart,$tend,$status_in_db);
2174: if ($status_in_db eq 'active') {
2175: &Apache::lonnet::get_groups_roles($udom,$uname,
2176: $courseroles{$udom},
2177: \@rolecodes,\%groups_roles);
2178: }
2179: $changed_groups{$udom.'_'.$uname}{$group} = $status_in_db;
2180: last;
2181: }
2182: }
2183: }
2184: $checkedgroup{$where} = 1;
2185: }
2186: } elsif ($role =~ /^cr/) {
2187: my $status_in_db =
2188: &curr_role_status($tstart,$tend,$refresh,$now);
2189: my ($rdummy,$rest) = split(/\//,$role,2);
2190: my %currpriv;
2191: unless (exists($crprivs{$rest})) {
2192: my ($rdomain,$rauthor,$rrole)=split(/\//,$rest);
2193: my $homsvr=&Apache::lonnet::homeserver($rauthor,$rdomain);
2194: if (&Apache::lonnet::hostname($homsvr) ne '') {
2195: my ($rdummy,$roledef)=
2196: &Apache::lonnet::get('roles',["rolesdef_$rrole"],
2197: $rdomain,$rauthor);
2198: if (($rdummy ne 'con_lost') && ($roledef ne '')) {
2199: my $i = 0;
2200: my @scopes = ('sys','dom','crs');
2201: my @privs = split(/\_/,$roledef);
2202: foreach my $priv (@privs) {
2203: my ($blank,@prv) = split(/:/,$priv);
2204: @prv = map { $_ .= (/\&\w+$/ ? '':'&F') } @prv;
1.264 raeburn 2205: if (@prv) {
2206: $priv = ':'.join(':',sort(@prv));
2207: }
1.260 raeburn 2208: $crprivs{$rest}{$scopes[$i]} = $priv;
2209: $i++;
2210: }
2211: }
2212: }
2213: }
1.279 raeburn 2214: my $status_in_env =
2215: &curr_role_status($currstart,$currend,$refresh,$update);
2216: if ($status_in_env eq 'active') {
2217: $currpriv{sys} = $env{"user.priv.$rolekey./"};
2218: $currpriv{dom} = $env{"user.priv.$rolekey./$udom/"};
2219: $currpriv{crs} = $env{"user.priv.$rolekey.$where"};
2220: if (keys(%crprivs)) {
2221: if (($crprivs{$rest}{sys} ne $currpriv{sys}) ||
2222: ($crprivs{$rest}{dom} ne $currpriv{dom})
1.260 raeburn 2223: ||
1.279 raeburn 2224: ($crprivs{$rest}{crs} ne $currpriv{crs})) {
2225: &gather_roleprivs(\%allroles,\%allgroups,
2226: \%userroles,$where,$role,
2227: $tstart,$tend,$status_in_db);
2228: unless (grep(/^\Q$role\E$/,@changed_roles)) {
2229: push(@changed_roles,$role);
2230: }
1.260 raeburn 2231: $customprivchg{$rolekey} = $status_in_env;
2232: }
2233: }
2234: }
2235: }
2236: }
2237: }
2238: }
2239: foreach my $envkey (keys(%env)) {
2240: next unless ($envkey =~ /^user\.role\./);
2241: next if ($dbroles{$envkey});
2242: next if ($envkey eq 'user.role.'.$env{'request.role'});
2243: my ($currstart,$currend) = split(/\./,$env{$envkey});
2244: my $status_in_env =
2245: &curr_role_status($currstart,$currend,$refresh,$update);
2246: my ($rolekey) = ($envkey =~ /^user\.role\.(.+)$/);
1.297 raeburn 2247: my ($role,$rest)=split(m{\./},$rolekey,2);
2248: $rest = '/'.$rest;
1.260 raeburn 2249: if (&Apache::lonnet::delenv($envkey,undef,[$role])) {
2250: if ($status_in_env eq 'active') {
2251: if ($role eq 'gr') {
2252: &Apache::lonnet::delete_env_groupprivs($rest,\%courseroles,
2253: \@possroles);
2254: } else {
2255: &Apache::lonnet::delenv("user.priv.$rolekey",undef,[$role]);
2256: &Apache::lonnet::delenv("user.priv.cm.$rest",undef,['cm']);
2257: }
2258: unless (grep(/^\Q$role\E$/,@changed_roles)) {
2259: push(@changed_roles,$role);
2260: }
2261: $deletedroles{$rolekey} = 1;
2262: }
2263: }
2264: }
2265: if (($oldsec) && (@newsec > 0)) {
2266: if (@newsec > 1) {
1.274 raeburn 2267: $msg = '<p class="LC_warning">'.&mt('The section has changed for your current role. Log-out and log-in again to select a role for the new section.').'</p>';
1.260 raeburn 2268: } else {
2269: my $newrole = $env{'request.role'};
2270: if ($newsec[0] eq 'none') {
2271: $newrole =~ s{(/[^/])$}{};
2272: } elsif ($oldsec eq 'none') {
2273: $newrole .= '/'.$newsec[0];
2274: } else {
2275: $newrole =~ s{([^/]+)$}{$newsec[0]};
2276: }
2277: my $coursedesc = $env{'course.'.$env{'request.course.id'}.'.description'};
2278: my ($curr_role) = ($env{'request.role'} =~ m{^(\w+)\./$match_domain/$match_courseid});
2279: my %temp=('logout_'.$env{'request.course.id'} => time);
2280: &Apache::lonnet::put('email_status',\%temp);
2281: &Apache::lonnet::delenv('user.state.'.$env{'request.course.id'});
2282: &Apache::lonnet::appenv({"request.course.id" => '',
2283: "request.course.fn" => '',
2284: "request.course.uri" => '',
2285: "request.course.sec" => '',
2286: "request.role" => 'cm',
2287: "request.role.adv" => $env{'user.adv'},
2288: "request.role.domain" => $env{'user.domain'}});
2289: my $rolename = &Apache::loncommon::plainname($curr_role);
2290: $msg = '<p><form name="reselectrole" action="/adm/roles" method="post" />'.
2291: '<input type="hidden" name="newrole" value="" />'.
2292: '<input type="hidden" name="selectrole" value="1" />'.
2293: '<span class="LC_info">'.
2294: &mt('Your section has changed for your current [_1] role in [_2].',$rolename,$coursedesc).'</span><br />';
2295: my $button = '<input type="button" name="sectionchanged" value="'.
2296: &mt('Re-Select').'" onclick="javascript:enterrole(this.form,'."'$newrole','sectionchanged'".')" />';
2297: if ($newsec[0] eq 'none') {
2298: $msg .= &mt('[_1] to continue with your new section-less role.',$button);
2299: } else {
2300: $msg .= &mt('[_1] to continue with your new role in section ([_2]).',$button,$newsec[0]);
2301: }
2302: $msg .= '</form></p>';
2303: }
2304: } elsif ($currrole_expired) {
1.274 raeburn 2305: $msg .= '<p class="LC_warning">';
1.260 raeburn 2306: if (&Apache::loncommon::show_course()) {
2307: $msg .= &mt('Your role in the current course has expired.');
2308: } else {
2309: $msg .= &mt('Your current role has expired.');
2310: }
1.274 raeburn 2311: $msg .= '<br />'.&mt('However you can continue to use this role until you logout, click the "Re-Select" button, or your session has been idle for more than 24 hours.').'</p>';
1.260 raeburn 2312: }
1.279 raeburn 2313: &Apache::lonnet::set_userprivs(\%userroles,\%allroles,\%allgroups,\%groups_roles);
2314: my ($curr_is_adv,$curr_role_adv,$curr_author,$curr_role_author);
2315: $curr_author = $env{'user.author'};
2316: if (($env{'request.role'} =~/^au/) || ($env{'request.role'} =~/^ca/) ||
2317: ($env{'request.role'} =~/^aa/)) {
2318: $curr_role_author=1;
2319: }
2320: $curr_is_adv = $env{'user.adv'};
2321: $curr_role_adv = $env{'request.role.adv'};
2322: if (keys(%userroles) > 0) {
2323: foreach my $role (@changed_roles) {
2324: unless(grep(/^\Q$role\E$/,@rolecodes)) {
2325: push(@rolecodes,$role);
2326: }
2327: }
2328: unless(grep(/^\Qcm\E$/,@rolecodes)) {
2329: push(@rolecodes,'cm');
2330: }
2331: &Apache::lonnet::appenv(\%userroles,\@rolecodes);
2332: }
2333: my %newenv;
2334: if (&Apache::lonnet::is_advanced_user($env{'user.domain'},$env{'user.name'})) {
2335: unless ($curr_is_adv) {
2336: $newenv{'user.adv'} = 1;
2337: }
2338: } elsif ($curr_is_adv && !$curr_role_adv) {
2339: &Apache::lonnet::delenv('user.adv');
2340: }
2341: my %authorroleshash =
2342: &Apache::lonnet::get_my_roles('','','userroles',['active'],['au','ca','aa']);
2343: if (keys(%authorroleshash)) {
2344: unless ($curr_author) {
2345: $newenv{'user.author'} = 1;
2346: }
2347: } elsif ($curr_author && !$curr_role_author) {
2348: &Apache::lonnet::delenv('user.author');
2349: }
2350: if ($env{'request.course.id'}) {
2351: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
2352: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
2353: my (@activecrsgroups,$crsgroupschanged);
2354: if ($env{'request.course.groups'}) {
2355: @activecrsgroups = split(/:/,$env{'request.course.groups'});
2356: foreach my $item (keys(%deletedroles)) {
2357: if ($item =~ m{^gr\./\Q$cdom\E/\Q$cnum\E/(\w+)$}) {
2358: if (grep(/^\Q$1\E$/,@activecrsgroups)) {
2359: $crsgroupschanged = 1;
2360: last;
2361: }
2362: }
2363: }
2364: }
2365: unless ($crsgroupschanged) {
2366: foreach my $item (keys(%newgroup)) {
2367: if ($item =~ m{^gr\./\Q$cdom\E/\Q$cnum\E/(\w+)$}) {
2368: if ($newgroup{$item} eq 'active') {
2369: $crsgroupschanged = 1;
2370: last;
2371: }
2372: }
2373: }
2374: }
2375: if ((ref($changed_groups{$env{'request.course.id'}}) eq 'HASH') ||
2376: (ref($groupchange{"/$cdom/$cnum"}) eq 'HASH') ||
2377: ($crsgroupschanged)) {
2378: my %grouproles = &Apache::lonnet::get_my_roles('','','userroles',
2379: ['active'],['gr'],[$cdom],1);
2380: my @activegroups;
2381: foreach my $item (keys(%grouproles)) {
2382: next unless($item =~ /^\Q$cnum\E:\Q$cdom\E/);
2383: my $group;
2384: my ($crsn,$crsd,$role,$remainder) = split(/:/,$item,4);
2385: if ($remainder =~ /:/) {
2386: (my $other,$group) = ($remainder =~ /^([\w:]+):([^:]+)$/);
2387: } else {
2388: $group = $remainder;
2389: }
2390: if ($group ne '') {
2391: push(@activegroups,$group);
2392: }
2393: }
2394: $newenv{'request.course.groups'} = join(':',@activegroups);
2395: }
2396: }
2397: if (keys(%newenv)) {
2398: &Apache::lonnet::appenv(\%newenv);
2399: }
1.260 raeburn 2400: if (!@changed_roles || !(keys(%changed_groups))) {
1.264 raeburn 2401: my ($rolesmsg,$groupsmsg);
1.260 raeburn 2402: if (!@changed_roles) {
2403: if (&Apache::loncommon::show_course()) {
1.264 raeburn 2404: $rolesmsg = &mt('No new courses or communities');
1.260 raeburn 2405: } else {
1.264 raeburn 2406: $rolesmsg = &mt('No role changes');
1.260 raeburn 2407: }
2408: }
2409: if ($hasgroups && !(keys(%changed_groups)) && !(grep(/gr/,@changed_roles))) {
1.264 raeburn 2410: $groupsmsg = &mt('No changes in course/community groups');
1.260 raeburn 2411: }
2412: if (!@changed_roles && !(keys(%changed_groups))) {
1.264 raeburn 2413: if (($msg ne '') || ($groupsmsg ne '')) {
2414: $msg .= '<ul>';
2415: if ($rolesmsg) {
2416: $msg .= '<li>'.$rolesmsg.'</li>';
2417: }
2418: if ($groupsmsg) {
2419: $msg .= '<li>'.$groupsmsg.'</li>';
2420: }
2421: $msg .= '</ul>';
2422: } else {
1.270 raeburn 2423: $msg = ' <span class="LC_cusr_emph">'.$rolesmsg.'</span><br />';
1.264 raeburn 2424: }
1.260 raeburn 2425: return $msg;
2426: }
2427: }
2428: my $changemsg;
2429: if (@changed_roles > 0) {
2430: if (keys(%newgroup) > 0) {
2431: my $groupmsg;
1.279 raeburn 2432: my (%curr_groups,%groupdescs,$currcrs);
1.260 raeburn 2433: foreach my $item (sort(keys(%newgroup))) {
2434: if (&is_active_course($item,$refresh,$update,\%roleshash)) {
1.279 raeburn 2435: if ($item =~ m{^gr\./($match_domain/$match_courseid)/(\w+)$}) {
2436: my ($cdom,$cnum) = split(/\//,$1);
2437: my $group = $2;
2438: if ($currcrs ne $cdom.'_'.$cnum) {
2439: if ($currcrs) {
2440: $groupmsg .= '</ul><li>';
2441: }
2442: $groupmsg .= '<li><b>'.
2443: $env{'course.'.$cdom.'_'.$cnum.'.description'}.'</b><ul>';
1.281 raeburn 2444: $currcrs = $cdom.'_'.$cnum;
1.279 raeburn 2445: }
2446: my $groupdesc;
2447: unless (ref($curr_groups{$cdom.'_'.$cnum}) eq 'HASH') {
2448: %{$curr_groups{$cdom.'_'.$cnum}} =
2449: &Apache::longroup::coursegroups($cdom,$cnum);
2450: }
2451: unless ((ref($groupdescs{$cdom.'_'.$cnum}) eq 'HASH') &&
2452: ($groupdescs{$cdom.'_'.$cnum}{$group})) {
2453:
2454: my %groupinfo =
2455: &Apache::longroup::get_group_settings($curr_groups{$cdom.'_'.$cnum}{$group});
2456: $groupdescs{$cdom.'_'.$cnum}{$group} =
2457: &unescape($groupinfo{'description'});
2458: }
2459: $groupdesc = $groupdescs{$cdom.'_'.$cnum}{$group};
1.286 raeburn 2460: if ($groupdesc) {
2461: $groupmsg .= '<li>'.
2462: &mt('[_1] with status: [_2].',
2463: '<b>'.$groupdesc.'</b>',$newgroup{$item}).'</li>';
2464: }
1.279 raeburn 2465: }
2466: }
2467: if ($groupmsg) {
2468: $groupmsg .= '</ul></li>';
1.260 raeburn 2469: }
2470: }
2471: if ($groupmsg) {
2472: $changemsg .= '<li>'.
2473: &mt('Courses with new groups').'</li>'.
2474: '<ul>'.$groupmsg.'</ul></li>';
2475: }
2476: }
2477: if (keys(%newrole) > 0) {
1.286 raeburn 2478: my $newmsg;
1.260 raeburn 2479: foreach my $item (sort(keys(%newrole))) {
1.279 raeburn 2480: my $desc = &role_desc($item,$update,$refresh,$now);
1.286 raeburn 2481: if ($desc) {
2482: $newmsg .= '<li>'.
2483: &mt('[_1] with status: [_2].',
1.293 bisitz 2484: $desc,&mt($newrole{$item})).'</li>';
1.286 raeburn 2485: }
2486: }
2487: if ($newmsg) {
2488: $changemsg .= '<li>'.&mt('New roles').
2489: '<ul>'.$newmsg.'</ul>'.
2490: '</li>';
1.260 raeburn 2491: }
2492: }
2493: if (keys(%customprivchg) > 0) {
1.286 raeburn 2494: my $privmsg;
1.260 raeburn 2495: foreach my $item (sort(keys(%customprivchg))) {
1.279 raeburn 2496: my $desc = &role_desc($item,$update,$refresh,$now);
1.286 raeburn 2497: if ($desc) {
2498: $privmsg .= '<li>'.$desc.'</li>';
2499: }
1.260 raeburn 2500: }
1.286 raeburn 2501: if ($privmsg) {
2502: $changemsg .= '<li>'.
2503: &mt('Custom roles with privilege changes').
2504: '<ul>'.$privmsg.'</ul>'.
2505: '</li>';
2506: }
1.260 raeburn 2507: }
2508: if (keys(%rolechange) > 0) {
1.286 raeburn 2509: my $rolemsg;
1.260 raeburn 2510: foreach my $item (sort(keys(%rolechange))) {
1.279 raeburn 2511: my $desc = &role_desc($item,$update,$refresh,$now);
1.286 raeburn 2512: if ($desc) {
2513: $rolemsg .= '<li>'.
2514: &mt('[_1] status now: [_2].',$desc,
2515: $rolechange{$item}).'</li>';
2516: }
2517: }
2518: if ($rolemsg) {
1.260 raeburn 2519: $changemsg .= '<li>'.
1.286 raeburn 2520: &mt('Existing roles with status changes').'</li>'.
2521: '<ul>'.$rolemsg.'</ul>'.
2522: '</li>';
1.260 raeburn 2523: }
2524: }
2525: if (keys(%deletedroles) > 0) {
1.286 raeburn 2526: my $delmsg;
1.260 raeburn 2527: foreach my $item (sort(keys(%deletedroles))) {
1.279 raeburn 2528: my $desc = &role_desc($item,$update,$refresh,$now);
1.286 raeburn 2529: if ($desc) {
2530: $delmsg .= '<li>'.$desc.'</li>';
2531: }
2532: }
2533: if ($delmsg) {
2534: $changemsg .= '<li>'.
2535: &mt('Existing roles now expired').'</li>'.
2536: '<ul>'.$delmsg.'</ul>'.
2537: '</li>';
1.260 raeburn 2538: }
2539: }
2540: }
2541: if ((keys(%changed_groups) > 0) || (keys(%groupchange) > 0)) {
2542: my $groupchgmsg;
2543: foreach my $key (sort(keys(%changed_groups))) {
2544: my $crs = 'gr/'.$key;
2545: $crs =~ s/_/\//;
2546: if (&is_active_course($crs,$refresh,$update,\%roleshash)) {
2547: if (ref($changed_groups{$key}) eq 'HASH') {
2548: my @showgroups;
2549: foreach my $group (sort(keys(%{$changed_groups{$key}}))) {
2550: if ($changed_groups{$key}{$group} eq 'active') {
2551: push(@showgroups,$group);
2552: }
2553: }
2554: if (@showgroups > 0) {
2555: $groupchgmsg .= '<li>'.
2556: &mt('Course: [_1], groups: [_2].',$key,
2557: join(', ',@showgroups)).
2558: '</li>';
2559: }
2560: }
2561: }
2562: }
2563: if (keys(%groupchange) > 0) {
2564: $groupchgmsg .= '<li>'.
2565: &mt('Existing course/community groups with status changes').'</li>'.
2566: '<ul>';
2567: foreach my $crs (sort(keys(%groupchange))) {
1.279 raeburn 2568: my $cid = $crs;
2569: $cid=~s{^/}{};
2570: $cid=~s{/}{_};
2571: my $crsdesc = $env{'course.'.$cid.'.description'};
2572: my $cdom = $env{'course.'.$cid.'.domain'};
2573: my $cnum = $env{'course.'.$cid.'.num'};
2574: my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum);
2575: my %groupdesc;
1.260 raeburn 2576: if (ref($groupchange{$crs}) eq 'HASH') {
1.279 raeburn 2577: $groupchgmsg .= '<li>'.&mt('Course/Community: [_1]','<b>'.$crsdesc.'</b><ul>');
1.260 raeburn 2578: foreach my $group (sort(keys(%{$groupchange{$crs}}))) {
1.279 raeburn 2579: unless ($groupdesc{$group}) {
2580: my %groupinfo = &Apache::longroup::get_group_settings($curr_groups{$group});
2581: $groupdesc{$group} = &unescape($groupinfo{'description'});
2582: }
2583: $groupchgmsg .= '<li>'.&mt('Group: [_1] status now: [_2].','<b>'.$groupdesc{$group}.'</b>',$groupchange{$crs}{$group}).'</li>';
1.260 raeburn 2584: }
2585: $groupchgmsg .= '</ul></li>';
2586: }
2587: }
2588: $groupchgmsg .= '</ul></li>';
2589: }
2590: if ($groupchgmsg) {
2591: $changemsg .= '<li>'.
2592: &mt('Courses with changes in groups').'</li>'.
2593: '<ul>'.$groupchgmsg.'</ul></li>';
2594: }
2595: }
2596: if ($changemsg) {
2597: $msg .= '<ul>'.$changemsg.'</ul>';
1.286 raeburn 2598: } else {
2599: if (&Apache::loncommon::show_course()) {
2600: $msg = &mt('No new courses or communities');
2601: } else {
2602: $msg = &mt('No role changes');
2603: }
1.260 raeburn 2604: }
1.279 raeburn 2605: return $msg;
2606: }
2607:
2608: sub role_desc {
2609: my ($item,$update,$refresh,$now) = @_;
2610: my ($where,$trolecode,$role,$tstatus,$tend,$tstart,$twhere,
2611: $trole,$tremark);
1.282 raeburn 2612: &Apache::lonnet::role_status('user.role.'.$item,$update,$refresh,
2613: $now,\$role,\$where,\$trolecode,
1.279 raeburn 2614: \$tstatus,\$tstart,\$tend);
1.286 raeburn 2615: return unless ($role);
1.279 raeburn 2616: if ($role =~ /^cr\//) {
2617: my ($rdummy,$rdomain,$rauthor,$rrole)=split(/\//,$role);
1.298 bisitz 2618: $tremark = &mt('Custom role defined by [_1].',$rauthor.':'.$rdomain);
1.279 raeburn 2619: }
2620: $trole=Apache::lonnet::plaintext($role);
2621: my ($tdom,$trest,$tsection)=
2622: split(/\//,Apache::lonnet::declutter($where));
2623: if (($role eq 'ca') || ($role eq 'aa')) {
2624: my $home = &Apache::lonnet::homeserver($trest,$tdom);
2625: $home = &Apache::lonnet::hostname($home);
2626: $twhere=&mt('User').': '.$trest.' '.&mt('Domain').
2627: ': '.$tdom.' '.&mt('Server').': '.$home;
2628: } elsif ($role eq 'au') {
2629: my $home = &Apache::lonnet::homeserver
2630: ($env{'user.name'},$env{'user.domain'});
2631: $home = &Apache::lonnet::hostname($home);
2632: $twhere=&mt('Domain').': '.$tdom.' '.&mt('Server').
2633: ': '.$home;
2634: } elsif ($trest) {
2635: my $tcourseid=$tdom.'_'.$trest;
2636: my $crstype = &Apache::loncommon::course_type($tcourseid);
2637: $trole = &Apache::lonnet::plaintext($role,$crstype,$tcourseid);
2638: if ($env{'course.'.$tcourseid.'.description'}) {
2639: $twhere=$env{'course.'.$tcourseid.'.description'};
2640: } else {
2641: my %newhash=&Apache::lonnet::coursedescription($tcourseid);
2642: if (%newhash) {
2643: $twhere=$newhash{'description'};
2644: } else {
2645: $twhere=&mt('Currently not available');
1.260 raeburn 2646: }
2647: }
1.279 raeburn 2648: if ($tsection) {
2649: $twhere.= ' '.&mt('Section').': '.$tsection;
1.260 raeburn 2650: }
1.279 raeburn 2651: if ($role ne 'st') {
2652: $twhere.= ' '.&mt('Domain').': '.$tdom;
1.260 raeburn 2653: }
1.279 raeburn 2654: } elsif ($tdom) {
2655: $twhere = &mt('Domain').': '.$tdom;
1.260 raeburn 2656: }
1.286 raeburn 2657: my $output;
2658: if ($trole) {
2659: $output = $trole;
2660: if ($twhere) {
2661: $output .= " -- $twhere";
2662: }
2663: if ($tremark) {
2664: $output .= '<br />'.$tremark;
2665: }
1.260 raeburn 2666: }
1.279 raeburn 2667: return $output;
1.260 raeburn 2668: }
2669:
2670: sub curr_role_status {
2671: my ($start,$end,$refresh,$update) = @_;
2672: if (($start) && ($start<0)) { return 'deleted' };
2673: my $status = 'active';
2674: if (($end) && ($end<=$update)) {
2675: $status = 'previous';
2676: }
2677: if (($start) && ($refresh<$start)) {
2678: $status = 'future';
2679: }
2680: return $status;
2681: }
2682:
2683: sub gather_roleprivs {
2684: my ($allroles,$allgroups,$userroles,$area,$role,$tstart,$tend,$status) = @_;
2685: return unless ((ref($allroles) eq 'HASH') && (ref($allgroups) eq 'HASH') && (ref($userroles) eq 'HASH'));
2686: if (($area ne '') && ($role ne '')) {
2687: &Apache::lonnet::userrolelog($role,$env{'user.name'},$env{'user.domain'},
2688: $area,$tstart,$tend);
2689: my $spec=$role.'.'.$area;
2690: $userroles->{'user.role.'.$spec} = $tstart.'.'.$tend;
2691: my ($tdummy,$tdomain,$trest)=split(/\//,$area);
2692: if ($status eq 'active') {
2693: if ($role =~ /^cr\//) {
2694: &Apache::lonnet::custom_roleprivs($allroles,$role,$tdomain,$trest,$spec,$area);
2695: } elsif ($role eq 'gr') {
2696: my %rolehash = &Apache::lonnet::get('roles',[$area.'_'.$role],
2697: $env{'user.domain'},
2698: $env{'user.name'});
2699: my ($trole) = split(/_/,$rolehash{$area.'_'.$role},2);
2700: (undef,my $group_privs) = split(/\//,$trole);
2701: $group_privs = &unescape($group_privs);
2702: &Apache::lonnet::group_roleprivs($allgroups,$area,$group_privs,$tend,$tstart);
2703: } else {
2704: &Apache::lonnet::standard_roleprivs($allroles,$role,$tdomain,$spec,$trest,$area);
2705: }
2706: }
2707: }
2708: return;
2709: }
2710:
2711: sub is_active_course {
2712: my ($rolekey,$refresh,$update,$roleshashref) = @_;
2713: return unless(ref($roleshashref) eq 'HASH');
2714: my ($role,$cdom,$cnum) = split(/\//,$rolekey);
2715: my $is_active;
2716: foreach my $key (keys(%{$roleshashref})) {
2717: if ($key =~ /^\Q$cnum\E:\Q$cdom\E:/) {
2718: my ($tstart,$tend) = split(/:/,$roleshashref->{$key});
2719: my $status = &curr_role_status($tstart,$tend,$refresh,$update);
2720: if ($status eq 'active') {
2721: $is_active = 1;
2722: last;
2723: }
2724: }
2725: }
2726: return $is_active;
2727: }
2728:
1.274 raeburn 2729: sub get_roles_functions {
1.302 raeburn 2730: my ($rolescount,$cattype) = @_;
1.274 raeburn 2731: my @links;
2732: push(@links,["javascript:rolesView('doupdate');",'start-here-22x22',&mt('Check for changes')]);
2733: if ($env{'environment.canrequest.author'}) {
2734: unless (&Apache::loncoursequeueadmin::is_active_author()) {
2735: push(@links,["javascript:rolesView('requestauthor');",'list-add-22x22',&mt('Request author role')]);
2736: }
2737: }
1.279 raeburn 2738: if (($rolescount > 3) || ($env{'environment.recentroles'})) {
2739: push(@links,['/adm/preferences?action=changerolespref&returnurl=/adm/roles','role_hotlist-22x22',&mt('Hotlist')]);
2740: }
1.274 raeburn 2741: if (&Apache::lonmenu::check_for_rcrs()) {
2742: push(@links,['/adm/requestcourse','rcrs-22x22',&mt('Request course')]);
2743: }
2744: if ($env{'form.state'} eq 'queued') {
2745: push(@links,["javascript:rolesView('noqueued');",'selfenrl-queue-22x22',&mt('Hide queued')]);
2746: } else {
2747: push(@links,["javascript:rolesView('queued');",'selfenrl-queue-22x22',&mt('Show queued')]);
2748: }
1.279 raeburn 2749: if ($env{'user.adv'}) {
2750: if ($env{'form.display'} eq 'showall') {
1.290 raeburn 2751: push(@links,["javascript:rolesView('noshowall');",'edit-redo-22x22',&mt('Exclude expired')]);
1.279 raeburn 2752: } else {
1.290 raeburn 2753: push(@links,["javascript:rolesView('showall');",'edit-undo-22x22',&mt('Include expired')]);
1.279 raeburn 2754: }
1.274 raeburn 2755: }
1.302 raeburn 2756: unless ($cattype eq 'none') {
1.291 raeburn 2757: push(@links,['/adm/coursecatalog','ccat-22x22',&mt('Course catalog')]);
1.290 raeburn 2758: }
1.274 raeburn 2759: my $funcs = &Apache::lonhtmlcommon::start_funclist();
2760: foreach my $link (@links) {
2761: $funcs .= &Apache::lonhtmlcommon::add_item_funclist(
2762: '<a href="'.$link->[0].'" class="LC_menubuttons_link">'.
2763: '<img src="/res/adm/pages/'.$link->[1].'.png" class="LC_icon" alt="'.$link->[2].'" />'.
2764: $link->[2].'</a>');
2765: }
2766: $funcs .= &Apache::lonhtmlcommon::end_funclist();
2767: return &Apache::loncommon::head_subbox($funcs);
2768: }
2769:
2770: sub get_queued {
2771: my ($output,%reqcrs);
2772: my ($types,$typenames) = &Apache::loncommon::course_types();
2773: my %statusinfo = &Apache::lonnet::dump('courserequests',$env{'user.domain'},
2774: $env{'user.name'},'^status:');
2775: foreach my $key (keys(%statusinfo)) {
2776: next unless (($statusinfo{$key} eq 'approval') || ($statusinfo{$key} eq 'pending'));
1.297 raeburn 2777: (undef,my($cdom,$cnum)) = split(/:/,$key);
1.274 raeburn 2778: my $requestkey = $cdom.'_'.$cnum;
2779: if ($requestkey =~ /^($match_domain)_($match_courseid)$/) {
2780: my %history = &Apache::lonnet::restore($requestkey,'courserequests',
2781: $env{'user.domain'},$env{'user.name'});
2782: next if ((exists($history{'status'})) && ($history{'status'} eq 'created'));
2783: my $reqtime = $history{'reqtime'};
2784: my $lastupdate = $history{'timestamp'};
2785: my $showtype = $history{'crstype'};
2786: if (defined($typenames->{$history{'crstype'}})) {
2787: $showtype = $typenames->{$history{'crstype'}};
2788: }
2789: my $description;
2790: if (ref($history{'details'}) eq 'HASH') {
2791: $description = $history{details}{'cdescr'};
2792: }
2793: @{$reqcrs{$reqtime}} = ($description,$showtype);
2794: }
2795: }
2796: my @sortedtimes = sort {$a <=> $b} (keys(%reqcrs));
2797: if (@sortedtimes > 0) {
2798: $output .= '<p><b>'.&mt('Course/Community requests').'</b><br />'.
2799: &Apache::loncommon::start_data_table().
2800: &Apache::loncommon::start_data_table_header_row().
2801: '<th>'.&mt('Date requested').'</th>'.
2802: '<th>'.&mt('Course title').'</th>'.
2803: '<th>'.&mt('Course type').'</th>';
2804: &Apache::loncommon::end_data_table_header_row();
2805: foreach my $reqtime (@sortedtimes) {
2806: next unless (ref($reqcrs{$reqtime}) eq 'ARRAY');
2807: $output .= &Apache::loncommon::start_data_table_row().
2808: '<td>'.&Apache::lonlocal::locallocaltime($reqtime).'</td>'.
2809: '<td>'.join('</td><td>',@{$reqcrs{$reqtime}}).'</td>'.
2810: &Apache::loncommon::end_data_table_row();
2811: }
2812: $output .= &Apache::loncommon::end_data_table().
2813: '<br /></p>';
2814: }
2815: my $queuedselfenroll = &Apache::loncoursequeueadmin::queued_selfenrollment(1);
2816: if ($queuedselfenroll) {
2817: $output .= '<p><b>'.&mt('Enrollment requests').'</b><br />'.
2818: $queuedselfenroll.'<br /></p>';
2819: }
2820: if ($env{'environment.canrequest.author'}) {
2821: unless (&Apache::loncoursequeueadmin::is_active_author()) {
2822: my $requestauthor;
2823: my ($status,$timestamp) = split(/:/,$env{'environment.requestauthorqueued'});
2824: if (($status eq 'approval') || ($status eq 'approved')) {
2825: $output .= '<p><b>'.&mt('Author role request').'</b><br />';
2826: if ($status eq 'approval') {
1.294 bisitz 2827: $output .= &mt('A request for Authoring Space submitted on [_1] is awaiting approval',
1.274 raeburn 2828: &Apache::lonlocal::locallocaltime($timestamp));
2829: } elsif ($status eq 'approved') {
2830: my %roleshash =
2831: &Apache::lonnet::get_my_roles($env{'user.name'},$env{'user.domain'},'userroles',
2832: ['active'],['au'],[$env{'user.domain'}]);
2833: if (keys(%roleshash)) {
2834: $output .= '<span class="LC_info">'.
2835: &mt('Your request for an author role has been approved.').'<br />'.
2836: &mt('Use the "Check for changes" link to update your list of roles.').
2837: '</span>';
2838: }
2839: }
2840: $output .= '</p>';
2841: }
2842: }
2843: }
2844: unless ($output) {
2845: if ($env{'environment.canrequest.author'} || $env{'environment.canrequest.official'} ||
2846: $env{'environment.canrequest.unofficial'} || $env{'environment.canrequest.community'}) {
2847: $output = &mt('No requests for courses, communities or authoring currently queued');
2848: } else {
2849: $output = &mt('No enrollment requests currently queued awaiting approval');
2850: }
2851: }
2852: return '<div class="LC_left_float"><fieldset><legend>'.&mt('Queued requests').'</legend>'.
2853: $output.'</fieldset></div><br clear="all" />';
2854: }
2855:
1.1 harris41 2856: 1;
2857: __END__
1.32 harris41 2858:
2859: =head1 NAME
2860:
2861: Apache::lonroles - User Roles Screen
2862:
2863: =head1 SYNOPSIS
2864:
2865: Invoked by /etc/httpd/conf/srm.conf:
2866:
2867: <Location /adm/roles>
2868: PerlAccessHandler Apache::lonacc
2869: SetHandler perl-script
2870: PerlHandler Apache::lonroles
2871: ErrorDocument 403 /adm/login
2872: ErrorDocument 500 /adm/errorhandler
2873: </Location>
1.64 bowersj2 2874:
2875: =head1 OVERVIEW
2876:
2877: =head2 Choosing Roles
2878:
2879: C<lonroles> is a handler that allows a user to switch roles in
2880: mid-session. LON-CAPA attempts to work with "No Role Specified", the
2881: default role that a user has before selecting a role, as widely as
2882: possible, but certain handlers for example need specification which
2883: course they should act on, etc. Both in this scenario, and when the
2884: handler determines via C<lonnet>'s C<&allowed> function that a certain
2885: action is not allowed, C<lonroles> is used as error handler. This
2886: allows the user to select another role which may have permission to do
1.246 droeschl 2887: what they were trying to do.
1.64 bowersj2 2888:
2889: =begin latex
2890:
2891: \begin{figure}
2892: \begin{center}
2893: \includegraphics[width=0.45\paperwidth,keepaspectratio]{Sample_Roles_Screen}
2894: \caption{\label{Sample_Roles_Screen}Sample Roles Screen}
2895: \end{center}
2896: \end{figure}
2897:
2898: =end latex
2899:
2900: =head2 Role Initialization
2901:
2902: 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 2903:
2904: =head1 INTRODUCTION
2905:
2906: This module enables a user to select what role he wishes to
2907: operate under (instructor, student, teaching assistant, course
2908: coordinator, etc). These roles are pre-established by the actions
2909: of upper-level users.
2910:
2911: This is part of the LearningOnline Network with CAPA project
2912: described at http://www.lon-capa.org.
2913:
2914: =head1 HANDLER SUBROUTINE
2915:
2916: This routine is called by Apache and mod_perl.
2917:
2918: =over 4
2919:
2920: =item *
2921:
2922: Roles Initialization (yes/no)
2923:
2924: =item *
2925:
2926: Get Error Message from Environment
2927:
2928: =item *
2929:
2930: Who is this?
2931:
2932: =item *
2933:
2934: Generate Page Output
2935:
2936: =item *
2937:
2938: Choice or no choice
2939:
2940: =item *
2941:
2942: Table
2943:
2944: =item *
2945:
2946: Privileges
2947:
2948: =back
2949:
2950: =cut
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>