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