Annotation of loncom/auth/lonroles.pm, revision 1.313
1.1 harris41 1: # The LearningOnline Network with CAPA
2: # User Roles Screen
1.31 www 3: #
1.313 ! raeburn 4: # $Id: lonroles.pm,v 1.312 2015/06/09 21:22:44 damieng 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: $start_page=&Apache::loncommon::start_page($pagetitle,undef,{bread_crumbs=>$brcrum});
! 786: $funcs = &get_roles_functions($showcount,$cattype);
! 787: }
1.312 damieng 788: &js_escape(\$standby);
1.274 raeburn 789: 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 790:
1.10 www 791: $r->print(<<ENDHEADER);
1.147 albertel 792: $start_page
1.274 raeburn 793: $funcs
1.179 raeburn 794: <noscript>
795: $noscript
796: </noscript>
797: <script type="text/javascript">
1.225 bisitz 798: // <![CDATA[
1.26 www 799: $swinfo
800: window.focus();
1.134 www 801:
802: active=true;
803:
804: function enterrole (thisform,rolecode,buttonname) {
805: if (active) {
806: active=false;
807: document.title='$standby';
808: window.status='$standby';
809: thisform.newrole.value=rolecode;
810: thisform.submit();
811: } else {
812: alert('$standby');
1.260 raeburn 813: }
814: }
815:
1.274 raeburn 816: function rolesView (caller) {
817: if ((caller == 'showall') || (caller == 'noshowall')) {
818: document.rolechoice.display.value = caller;
819: } else {
820: if ((caller == 'doupdate') || (caller == 'requestauthor') ||
821: (caller == 'queued')) {
822: document.rolechoice.state.value = caller;
823: }
824: }
825: document.rolechoice.selectrole.value='';
826: document.rolechoice.submit();
1.270 raeburn 827: }
828:
1.225 bisitz 829: // ]]>
1.26 www 830: </script>
1.10 www 831: ENDHEADER
1.6 www 832:
1.2 www 833: # ------------------------------------------ Get Error Message from Environment
834:
1.118 albertel 835: my ($fn,$priv,$nochoose,$error,$msg)=split(/:/,$env{'user.error.msg'});
836: if ($env{'user.error.msg'}) {
1.55 albertel 837: $r->log_reason(
1.118 albertel 838: "$msg for $env{'user.name'} domain $env{'user.domain'} access $priv",$fn);
1.12 www 839: }
1.1 harris41 840:
1.61 www 841: # ------------------------------------------------- Can this user re-init, etc?
1.6 www 842:
1.118 albertel 843: my $advanced=$env{'user.adv'};
1.61 www 844: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['tryagain']);
1.118 albertel 845: my $tryagain=$env{'form.tryagain'};
1.209 raeburn 846: my $reinit=$env{'user.reinit'};
847: delete $env{'user.reinit'};
1.6 www 848:
1.2 www 849: # -------------------------------------------------------- Generate Page Output
1.6 www 850: # --------------------------------------------------------------- Error Header?
1.2 www 851: if ($error) {
1.187 bisitz 852: $r->print("<h1>".&mt('LON-CAPA Access Control')."</h1>");
1.174 albertel 853: $r->print("<!-- LONCAPAACCESSCONTROLERRORSCREEN --><hr /><pre>");
854: if ($priv ne '') {
1.187 bisitz 855: $r->print(&mt('Access : ').&Apache::lonnet::plaintext($priv)."\n");
1.174 albertel 856: }
857: if ($fn ne '') {
1.187 bisitz 858: $r->print(&mt('Resource: ').&Apache::lonenc::check_encrypt($fn)."\n");
1.174 albertel 859: }
860: if ($msg ne '') {
1.187 bisitz 861: $r->print(&mt('Action : ').$msg."\n");
1.174 albertel 862: }
863: $r->print("</pre><hr />");
1.120 albertel 864: my $url=$fn;
865: my $last;
866: if (tie(my %hash,'GDBM_File',$env{'request.course.fn'}.'_symb.db',
867: &GDBM_READER(),0640)) {
868: $last=$hash{'last_known'};
869: untie(%hash);
870: }
1.149 www 871: if ($last) { $fn.='?symb='.&escape($last); }
1.120 albertel 872:
873: &Apache::londocs::changewarning($r,undef,'You have modified your course recently, [_1] may fix this access problem.',
874: &Apache::lonenc::check_encrypt($fn));
1.2 www 875: } else {
1.118 albertel 876: if ($env{'user.error.msg'}) {
1.209 raeburn 877: if ($reinit) {
878: $r->print(
879: '<h3><span class="LC_error">'.
1.234 raeburn 880: &mt('As your session file for the course or community has expired, you will need to re-select it.').'</span></h3>');
1.209 raeburn 881: } else {
882: $r->print(
1.157 albertel 883: '<h3><span class="LC_error">'.
1.235 bisitz 884: &mt('You need to choose another user role or enter a specific course or community for this function.').
885: '</span></h3>');
1.209 raeburn 886: }
887: }
1.2 www 888: }
889: if ($nochoose) {
1.177 www 890: $r->print("<h2>".&mt('Sorry ...')."</h2>\n<span class='LC_error'>".
891: &mt('This action is currently not authorized.').'</span>'.
1.150 www 892: &Apache::loncommon::end_page());
893: return OK;
1.6 www 894: } else {
1.274 raeburn 895: if ($updateresult || $reqauthor || $hotlist) {
896: my $showresult = '<div>';
897: if ($updateresult) {
898: $showresult .= &Apache::lonhtmlcommon::confirm_success($updateresult);
899: }
900: if ($reqauthor) {
901: $showresult .= &Apache::lonhtmlcommon::confirm_success($reqauthor);
902: }
903: if ($hotlist) {
904: $showresult .= $hotlist;
905: }
906: $showresult .= '</div>';
907: $r->print($showresult);
908: } elsif ($env{'form.state'} eq 'queued') {
909: $r->print(&get_queued());
1.270 raeburn 910: }
1.18 www 911: if (($ENV{'REDIRECT_QUERY_STRING'}) && ($fn)) {
912: $fn.='?'.$ENV{'REDIRECT_QUERY_STRING'};
1.6 www 913: }
1.274 raeburn 914: my $display = ($env{'form.display'} =~ /^(showall)$/);
1.84 www 915: $r->print('<form method="post" name="rolechoice" action="'.(($fn)?$fn:$r->uri).'">');
1.116 albertel 916: $r->print('<input type="hidden" name="orgurl" value="'.$fn.'" />');
917: $r->print('<input type="hidden" name="selectrole" value="1" />');
1.134 www 918: $r->print('<input type="hidden" name="newrole" value="" />');
1.274 raeburn 919: $r->print('<input type="hidden" name="display" value="'.$display.'" />');
920: $r->print('<input type="hidden" name="state" value="" />');
1.6 www 921: }
1.259 raeburn 922: $r->rflush();
1.226 raeburn 923:
924: my (%roletext,%sortrole,%roleclass,%futureroles,%timezones);
925: my ($countactive,$countfuture,$inrole,$possiblerole) =
1.274 raeburn 926: &gather_roles($update,$refresh,$now,$reinit,$nochoose,\%roles_in_env,\%roletext,
927: \%sortrole,\%roleclass,\%futureroles,\%timezones,$loncaparev);
1.226 raeburn 928: $refresh = $now;
929: &Apache::lonnet::appenv({'user.refresh.time' => $refresh});
1.313 ! raeburn 930: if ($countactive == 1) {
! 931: if ($env{'request.course.id'}) {
! 932: if ($env{'course.'.$env{'request.course.id'}.'.type'} eq 'Placement') {
! 933: $placementonly = 1;
! 934: }
! 935: } elsif ($possiblerole) {
! 936: if ($possiblerole =~ m{^st\./($match_domain)/($match_courseid)(?:/|$)}) {
! 937: if ($env{'course.'.$1.'_'.$2.'.type'} eq 'Placement') {
! 938: $placementonly = 1;
! 939: }
! 940: }
! 941: }
! 942: }
! 943: if ((($cattype eq 'std') || ($cattype eq 'domonly')) && (!$env{'user.adv'}) &&
! 944: (!$placementonly)) {
1.196 raeburn 945: if ($countactive > 0) {
946: my $domdesc = &Apache::lonnet::domain($env{'user.domain'},'description');
1.201 raeburn 947: my $esc_dom = &HTML::Entities::encode($env{'user.domain'},'"<>&');
1.233 bisitz 948: $r->print(
949: '<p>'
1.295 bisitz 950: .&mt('[_1]Visit the [_2]Course/Community Catalog[_3][_4]'
951: .' to view all [_5] LON-CAPA courses and communities.'
1.233 bisitz 952: ,'<b>'
953: ,'<a href="/adm/coursecatalog?showdom='.$esc_dom.'">'
1.295 bisitz 954: ,'</a>'
955: ,'</b>'
956: ,'"'.$domdesc.'"')
1.233 bisitz 957: .'<br />'
1.235 bisitz 958: .&mt('If a course or community is [_1]not[_2] in your list of current courses and communities below,'
1.233 bisitz 959: .' you may be able to enroll if self-enrollment is permitted.'
960: ,'<b>','</b>')
961: .'</p>'
962: );
1.196 raeburn 963: }
964: }
965:
1.84 www 966: # No active roles
967: if ($countactive==0) {
1.306 raeburn 968: &requestcourse_advice($r,$cattype,$inrole);
1.191 raeburn 969: $r->print('</form>');
970: if ($countfuture) {
971: $r->print(&mt('The following [quant,_1,role,roles] will become active in the future:',$countfuture));
972: my $doheaders = &roletable_headers($r,\%roleclass,\%sortrole,
973: $nochoose);
974: &print_rolerows($r,$doheaders,\%roleclass,\%sortrole,\%dcroles,
975: \%roletext);
976: my $tremark='';
1.212 bisitz 977: my $tbg;
1.191 raeburn 978: if ($env{'request.role'} eq 'cm') {
1.212 bisitz 979: $tbg="LC_roles_selected";
1.204 bisitz 980: $tremark=&mt('Currently selected.').' ';
1.191 raeburn 981: } else {
1.212 bisitz 982: $tbg="LC_roles_is";
1.191 raeburn 983: }
1.212 bisitz 984: $r->print(&Apache::loncommon::start_data_table_row()
985: .'<td class="'.$tbg.'"> </td>'
986: .'<td colspan="3">'
987: .&mt('No role specified')
988: .'</td>'
989: .'<td>'.$tremark.' </td>'
990: .&Apache::loncommon::end_data_table_row()
991: );
1.191 raeburn 992:
1.212 bisitz 993: $r->print(&Apache::loncommon::end_data_table());
1.191 raeburn 994: }
995: $r->print(&Apache::loncommon::end_page());
1.84 www 996: return OK;
1.313 ! raeburn 997: } elsif (($placementonly) && ($env{'request.role'} eq 'cm')) {
! 998: $r->print('<h3>'.&mt('Please stand by.').'</h3>
! 999: <input type="hidden" name="'.$possiblerole.'" value="1" />
! 1000: <noscript><br />
! 1001: <input type="submit" name="submit" value="'.&mt('Continue').'" />
! 1002: </noscript></form>');
! 1003: $r->rflush();
! 1004: $r->print('<script type="text/javascript">document.forms.rolechoice.submit();</script>');
! 1005: $r->print(&Apache::loncommon::end_page());
! 1006: return OK;
1.84 www 1007: }
1008: # ----------------------------------------------------------------------- Table
1.247 raeburn 1009:
1010: if ($numdc > 0) {
1011: $r->print(&coursepick_jscript());
1012: $r->print(&Apache::loncommon::coursebrowser_javascript().
1013: &Apache::loncommon::authorbrowser_javascript());
1014: }
1015:
1.224 raeburn 1016: unless ((!&Apache::loncommon::show_course()) || ($nochoose) || ($countactive==1)) {
1.173 albertel 1017: $r->print("<h2>".&mt('Select a Course to Enter')."</h2>\n");
1.84 www 1018: }
1.229 raeburn 1019: if ($env{'form.destinationurl'}) {
1020: $r->print('<input type="hidden" name="destinationurl" value="'.
1021: $env{'form.destinationurl'}.'" />');
1022: if ($env{'form.destsymb'} ne '') {
1023: $r->print('<input type="hidden" name="destsymb" value="'.
1024: $env{'form.destsymb'}.'" />');
1025: }
1026: }
1.247 raeburn 1027:
1.191 raeburn 1028: my $doheaders = &roletable_headers($r,\%roleclass,\%sortrole,$nochoose);
1.118 albertel 1029: if ($env{'environment.recentroles'}) {
1.111 albertel 1030: my %recent_roles =
1.118 albertel 1031: &Apache::lonhtmlcommon::get_recent('roles',$env{'environment.recentrolesn'});
1.111 albertel 1032: my $output='';
1.247 raeburn 1033: foreach my $role (sort(keys(%recent_roles))) {
1034: if (ref($roletext{'user.role.'.$role}) eq 'ARRAY') {
1.223 raeburn 1035: $output.= &Apache::loncommon::start_data_table_row().
1.247 raeburn 1036: $roletext{'user.role.'.$role}->[0].
1.223 raeburn 1037: &Apache::loncommon::end_data_table_row();
1.249 raeburn 1038: if ($roletext{'user.role.'.$role}->[1] ne '') {
1039: $output .= &Apache::loncommon::continue_data_table_row().
1040: $roletext{'user.role.'.$role}->[1].
1041: &Apache::loncommon::end_data_table_row();
1042: }
1.247 raeburn 1043: if ($role =~ m{dc\./($match_domain)/}
1.170 albertel 1044: && $dcroles{$1}) {
1.192 raeburn 1045: $output .= &adhoc_roles_row($1,'recent');
1.133 albertel 1046: }
1.113 raeburn 1047: } elsif ($numdc > 0) {
1.247 raeburn 1048: unless ($role =~/^error\:/) {
1.249 raeburn 1049: my ($roletext,$role_text_end) = &display_cc_role('user.role.'.$role);
1.259 raeburn 1050: if ($roletext) {
1051: $output.= &Apache::loncommon::start_data_table_row().
1052: $roletext.
1053: &Apache::loncommon::end_data_table_row();
1054: if ($role_text_end) {
1055: $output .= &Apache::loncommon::continue_data_table_row().
1056: $role_text_end.
1057: &Apache::loncommon::end_data_table_row();
1058: }
1059: }
1.113 raeburn 1060: }
1.247 raeburn 1061: }
1.111 albertel 1062: }
1063: if ($output) {
1.212 bisitz 1064: $r->print(&Apache::loncommon::start_data_table_empty_row()
1065: .'<td align="center" colspan="5">'
1.224 raeburn 1066: .$recent
1.212 bisitz 1067: .'</td>'
1068: .&Apache::loncommon::end_data_table_empty_row()
1069: );
1.111 albertel 1070: $r->print($output);
1.114 raeburn 1071: $doheaders ++;
1.111 albertel 1072: }
1073: }
1.191 raeburn 1074: &print_rolerows($r,$doheaders,\%roleclass,\%sortrole,\%dcroles,\%roletext);
1.202 raeburn 1075: if ($countactive > 1) {
1076: my $tremark='';
1.212 bisitz 1077: my $tbg;
1.202 raeburn 1078: if ($env{'request.role'} eq 'cm') {
1.212 bisitz 1079: $tbg="LC_roles_selected";
1.204 bisitz 1080: $tremark=&mt('Currently selected.').' ';
1.202 raeburn 1081: } else {
1.212 bisitz 1082: $tbg="LC_roles_is";
1.202 raeburn 1083: }
1.212 bisitz 1084: $r->print(&Apache::loncommon::start_data_table_row());
1.202 raeburn 1085: unless ($nochoose) {
1086: if ($env{'request.role'} ne 'cm') {
1.212 bisitz 1087: $r->print('<td class="'.$tbg.'"><input type="submit" value="'.
1.202 raeburn 1088: &mt('Select').'" name="cm" /></td>');
1089: } else {
1.212 bisitz 1090: $r->print('<td class="'.$tbg.'"> </td>');
1.202 raeburn 1091: }
1092: }
1.212 bisitz 1093: $r->print('<td colspan="3">'
1094: .&mt('No role specified')
1095: .'</td>'
1096: .'<td>'.$tremark.' </td>'
1097: .&Apache::loncommon::end_data_table_row()
1098: );
1.202 raeburn 1099: }
1.212 bisitz 1100: $r->print(&Apache::loncommon::end_data_table());
1.4 www 1101: unless ($nochoose) {
1102: $r->print("</form>\n");
1103: }
1.22 harris41 1104: # ------------------------------------------------------------ Privileges Info
1.118 albertel 1105: if (($advanced) && (($env{'user.error.msg'}) || ($error))) {
1.212 bisitz 1106: $r->print('<hr /><h2>'.&mt('Current Privileges').'</h2>');
1.175 albertel 1107: $r->print(&privileges_info());
1.4 www 1108: }
1.267 bisitz 1109: my $announcements = &Apache::lonnet::getannounce();
1110: $r->print(
1111: '<br />'.
1112: '<h2>'.&mt('Announcements').'</h2>'.
1113: $announcements
1114: ) unless (!$announcements);
1.65 www 1115: if ($advanced) {
1.201 raeburn 1116: my $esc_dom = &HTML::Entities::encode($env{'user.domain'},'"<>&');
1.231 bisitz 1117: $r->print('<p><small><i>'
1118: .&mt('This LON-CAPA server is version [_1]',$r->dir_config('lonVersion'))
1.308 raeburn 1119: .'</i></small></p>');
1.65 www 1120: }
1.147 albertel 1121: $r->print(&Apache::loncommon::end_page());
1.1 harris41 1122: return OK;
1.102 raeburn 1123: }
1124:
1.274 raeburn 1125: sub roles_from_env {
1126: my ($roleshash,$update) = @_;
1127: my $count = 0;
1128: if (ref($roleshash) eq 'HASH') {
1129: foreach my $envkey (keys(%env)) {
1130: if ($envkey =~ m{^user\.role\.(\w+)[./]}) {
1131: next if ($1 eq 'gr');
1132: $roleshash->{$envkey} = $env{$envkey};
1133: my ($start,$end) = split(/\./,$env{$envkey});
1134: unless ($end && $end<$update) {
1135: $count ++;
1136: }
1137: }
1138: }
1139: }
1140: return $count;
1141: }
1142:
1.226 raeburn 1143: sub gather_roles {
1.274 raeburn 1144: my ($update,$refresh,$now,$reinit,$nochoose,$roles_in_env,$roletext,$sortrole,$roleclass,$futureroles,
1145: $timezones,$loncaparev) = @_;
1.226 raeburn 1146: my ($countactive,$countfuture,$inrole,$possiblerole) = (0,0,0,'');
1147: my $advanced = $env{'user.adv'};
1148: my $tryagain = $env{'form.tryagain'};
1.254 raeburn 1149: my @ids = &Apache::lonnet::current_machine_ids();
1.274 raeburn 1150: if (ref($roles_in_env) eq 'HASH') {
1151: foreach my $envkey (sort(keys(%{$roles_in_env}))) {
1152: my $button = 1;
1153: my $switchserver='';
1154: my $switchwarning;
1155: my ($role_text,$role_text_end,$sortkey,$role,$where,$trolecode,$tstart,
1156: $tend,$tremark,$tstatus,$tpstart,$tpend);
1.260 raeburn 1157: &Apache::lonnet::role_status($envkey,$update,$refresh,$now,\$role,\$where,
1.226 raeburn 1158: \$trolecode,\$tstatus,\$tstart,\$tend);
1159: next if (!defined($role) || $role eq '' || $role =~ /^gr/);
1160: $tremark='';
1161: $tpstart=' ';
1162: $tpend=' ';
1163: if ($env{'request.role'} eq $trolecode) {
1164: $tstatus='selected';
1165: }
1166: my $tbg;
1167: if (($tstatus eq 'is')
1168: || ($tstatus eq 'selected')
1169: || ($tstatus eq 'future')
1.274 raeburn 1170: || ($env{'form.display'} eq 'showall')) {
1.259 raeburn 1171: my $timezone = &role_timezone($where,$timezones);
1172: if ($tstart) {
1173: $tpstart=&Apache::lonlocal::locallocaltime($tstart,$timezone);
1174: }
1175: if ($tend) {
1176: $tpend=&Apache::lonlocal::locallocaltime($tend,$timezone);
1177: }
1.226 raeburn 1178: if ($tstatus eq 'is') {
1179: $tbg='LC_roles_is';
1180: $possiblerole=$trolecode;
1181: $countactive++;
1182: } elsif ($tstatus eq 'future') {
1183: $tbg='LC_roles_future';
1184: $button=0;
1185: $futureroles->{$trolecode} = $tstart.':'.$tend;
1186: $countfuture ++;
1187: } elsif ($tstatus eq 'expired') {
1188: $tbg='LC_roles_expired';
1189: $button=0;
1190: } elsif ($tstatus eq 'will_not') {
1191: $tbg='LC_roles_will_not';
1192: $tremark.=&mt('Expired after logout.').' ';
1193: } elsif ($tstatus eq 'selected') {
1194: $tbg='LC_roles_selected';
1195: $inrole=1;
1196: $countactive++;
1197: $tremark.=&mt('Currently selected.').' ';
1198: }
1199: my $trole;
1200: if ($role =~ /^cr\//) {
1201: my ($rdummy,$rdomain,$rauthor,$rrole)=split(/\//,$role);
1202: if ($tremark) { $tremark.='<br />'; }
1.298 bisitz 1203: $tremark.=&mt('Custom role defined by [_1].',$rauthor.':'.$rdomain);
1.226 raeburn 1204: }
1205: $trole=Apache::lonnet::plaintext($role);
1206: my $ttype;
1207: my $twhere;
1.313 ! raeburn 1208: my $skipcal;
1.226 raeburn 1209: my ($tdom,$trest,$tsection)=
1210: split(/\//,Apache::lonnet::declutter($where));
1211: # First, Co-Authorship roles
1212: if (($role eq 'ca') || ($role eq 'aa')) {
1213: my $home = &Apache::lonnet::homeserver($trest,$tdom);
1214: my $allowed=0;
1215: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
1216: if (!$allowed) {
1217: $button=0;
1.248 raeburn 1218: $switchserver='otherserver='.$home.'&role='.$trolecode;
1.226 raeburn 1219: }
1220: #next if ($home eq 'no_host');
1221: $home = &Apache::lonnet::hostname($home);
1.288 raeburn 1222: $ttype='Authoring Space';
1.226 raeburn 1223: $twhere=&mt('User').': '.$trest.'<br />'.&mt('Domain').
1224: ': '.$tdom.'<br />'.
1225: ' '.&mt('Server').': '.$home;
1226: $env{'course.'.$tdom.'_'.$trest.'.description'}='ca';
1227: $tremark.=&Apache::lonhtmlcommon::authorbombs('/res/'.$tdom.'/'.$trest.'/');
1228: $sortkey=$role."$trest:$tdom";
1229: } elsif ($role eq 'au') {
1230: # Authors
1231: my $home = &Apache::lonnet::homeserver
1232: ($env{'user.name'},$env{'user.domain'});
1233: my $allowed=0;
1234: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
1235: if (!$allowed) {
1236: $button=0;
1.248 raeburn 1237: $switchserver='otherserver='.$home.'&role='.$trolecode;
1.226 raeburn 1238: }
1239: #next if ($home eq 'no_host');
1240: $home = &Apache::lonnet::hostname($home);
1.288 raeburn 1241: $ttype='Authoring Space';
1.226 raeburn 1242: $twhere=&mt('Domain').': '.$tdom.'<br />'.&mt('Server').
1243: ': '.$home;
1244: $env{'course.'.$tdom.'_'.$trest.'.description'}='ca';
1245: $tremark.=&Apache::lonhtmlcommon::authorbombs('/res/'.$tdom.'/'.$env{'user.name'}.'/');
1246: $sortkey=$role;
1247: } elsif ($trest) {
1248: my $tcourseid=$tdom.'_'.$trest;
1249: $ttype = &Apache::loncommon::course_type($tcourseid);
1.242 raeburn 1250: $trole = &Apache::lonnet::plaintext($role,$ttype,$tcourseid);
1.226 raeburn 1251: if ($env{'course.'.$tcourseid.'.description'}) {
1.254 raeburn 1252: my $home=$env{'course.'.$tcourseid.'.home'};
1.226 raeburn 1253: $twhere=$env{'course.'.$tcourseid.'.description'};
1254: $sortkey=$role."\0".$tdom."\0".$twhere."\0".$envkey;
1.248 raeburn 1255: $twhere = &HTML::Entities::encode($twhere,'"<>&');
1.226 raeburn 1256: unless ($twhere eq &mt('Currently not available')) {
1257: $twhere.=' <span class="LC_fontsize_small">'.
1258: &Apache::loncommon::syllabuswrapper(&mt('Syllabus'),$trest,$tdom).
1259: '</span>';
1.254 raeburn 1260: unless ($home && grep(/^\Q$home\E$/,@ids) && $loncaparev eq '') {
1.255 raeburn 1261: my $required = $env{'course.'.$tcourseid.'.internal.releaserequired'};
1.259 raeburn 1262: if ($required ne '') {
1263: ($switchserver,$switchwarning) =
1.310 raeburn 1264: &Apache::loncommon::check_release_required($loncaparev,$tcourseid,$trolecode,$required);
1.259 raeburn 1265: if ($switchserver || $switchwarning) {
1266: $button = 0;
1267: }
1.254 raeburn 1268: }
1269: }
1.226 raeburn 1270: }
1271: } else {
1272: my %newhash=&Apache::lonnet::coursedescription($tcourseid);
1273: if (%newhash) {
1274: $sortkey=$role."\0".$tdom."\0".$newhash{'description'}.
1275: "\0".$envkey;
1.248 raeburn 1276: $twhere=&HTML::Entities::encode($newhash{'description'},'"<>&').
1277: ' <span class="LC_fontsize_small">'.
1278: &Apache::loncommon::syllabuswrapper(&mt('Syllabus'),$trest,$tdom).
1279: '</span>';
1.226 raeburn 1280: $ttype = $newhash{'type'};
1.243 raeburn 1281: $trole = &Apache::lonnet::plaintext($role,$ttype,$tcourseid);
1.254 raeburn 1282: my $home = $newhash{'home'};
1283: unless ($home && grep(/^\Q$home\E$/,@ids) && $loncaparev eq '') {
1.255 raeburn 1284: my $required = $newhash{'internal.releaserequired'};
1.259 raeburn 1285: if ($required ne '') {
1286: ($switchserver,$switchwarning) =
1.310 raeburn 1287: &Apache::loncommon::check_release_required($loncaparev,$tcourseid,$trolecode,$required);
1.259 raeburn 1288: if ($switchserver || $switchwarning) {
1289: $button = 0;
1290: }
1.254 raeburn 1291: }
1292: }
1.226 raeburn 1293: } else {
1294: $twhere=&mt('Currently not available');
1295: $env{'course.'.$tcourseid.'.description'}=$twhere;
1296: $sortkey=$role."\0".$tdom."\0".$twhere."\0".$envkey;
1297: $ttype = 'Unavailable';
1.313 ! raeburn 1298: $skipcal = 1;
1.226 raeburn 1299: }
1300: }
1.313 ! raeburn 1301: if ($ttype eq 'Placement') {
! 1302: $ttype = 'Placement Test';
! 1303: }
1.226 raeburn 1304: if ($tsection) {
1305: $twhere.='<br />'.&mt('Section').': '.$tsection;
1306: }
1307: if ($role ne 'st') { $twhere.="<br />".&mt('Domain').":".$tdom; }
1308: } elsif ($tdom) {
1309: $ttype='Domain';
1310: $twhere=$tdom;
1311: $sortkey=$role.$twhere;
1312: } else {
1313: $ttype='System';
1314: $twhere=&mt('system wide');
1315: $sortkey=$role.$twhere;
1316: }
1317: ($role_text,$role_text_end) =
1318: &build_roletext($trolecode,$tdom,$trest,$tstatus,$tryagain,
1319: $advanced,$tremark,$tbg,$trole,$twhere,$tpstart,
1.313 ! raeburn 1320: $tpend,$nochoose,$button,$switchserver,$reinit,
! 1321: $switchwarning,$skipcal);
1.226 raeburn 1322: $roletext->{$envkey}=[$role_text,$role_text_end];
1323: if (!$sortkey) {$sortkey=$twhere."\0".$envkey;}
1324: $sortrole->{$sortkey}=$envkey;
1325: $roleclass->{$envkey}=$ttype;
1326: }
1327: }
1328: }
1329: return ($countactive,$countfuture,$inrole,$possiblerole);
1330: }
1331:
1.215 raeburn 1332: sub role_timezone {
1333: my ($where,$timezones) = @_;
1334: my $timezone;
1335: if (ref($timezones) eq 'HASH') {
1336: if ($where =~ m{^/($match_domain)/($match_courseid)}) {
1337: my $cdom = $1;
1338: my $cnum = $2;
1339: if ($cdom && $cnum) {
1340: if (!exists($timezones->{$cdom.'_'.$cnum})) {
1.259 raeburn 1341: my $tz;
1342: if ($env{'course.'.$cdom.'_'.$cnum.'.description'}) {
1343: $tz = $env{'course.'.$cdom.'_'.$cnum.'.timezone'};
1344: } else {
1345: my %timehash =
1346: &Apache::lonnet::get('environment',['timezone'],$cdom,$cnum);
1347: $tz = $timehash{'timezone'};
1348: }
1349: if ($tz eq '') {
1.215 raeburn 1350: if (!exists($timezones->{$cdom})) {
1351: my %domdefaults =
1352: &Apache::lonnet::get_domain_defaults($cdom);
1353: if ($domdefaults{'timezone_def'} eq '') {
1354: $timezones->{$cdom} = 'local';
1355: } else {
1356: $timezones->{$cdom} = $domdefaults{'timezone_def'};
1357: }
1358: }
1359: $timezones->{$cdom.'_'.$cnum} = $timezones->{$cdom};
1360: } else {
1361: $timezones->{$cdom.'_'.$cnum} =
1.259 raeburn 1362: &Apache::lonlocal::gettimezone($tz);
1.215 raeburn 1363: }
1364: }
1365: $timezone = $timezones->{$cdom.'_'.$cnum};
1366: }
1367: } else {
1368: my ($tdom) = ($where =~ m{^/($match_domain)});
1369: if ($tdom) {
1370: if (!exists($timezones->{$tdom})) {
1371: my %domdefaults = &Apache::lonnet::get_domain_defaults($tdom);
1372: if ($domdefaults{'timezone_def'} eq '') {
1373: $timezones->{$tdom} = 'local';
1374: } else {
1375: $timezones->{$tdom} = $domdefaults{'timezone_def'};
1376: }
1377: }
1378: $timezone = $timezones->{$tdom};
1379: }
1380: }
1381: if ($timezone eq 'local') {
1382: $timezone = undef;
1383: }
1384: }
1385: return $timezone;
1386: }
1387:
1.191 raeburn 1388: sub roletable_headers {
1389: my ($r,$roleclass,$sortrole,$nochoose) = @_;
1390: my $doheaders;
1391: if ((ref($sortrole) eq 'HASH') && (ref($roleclass) eq 'HASH')) {
1.212 bisitz 1392: $r->print('<br />'
1393: .&Apache::loncommon::start_data_table()
1394: .&Apache::loncommon::start_data_table_header_row()
1395: );
1.191 raeburn 1396: if (!$nochoose) { $r->print('<th> </th>'); }
1.212 bisitz 1397: $r->print('<th>'.&mt('User Role').'</th>'
1398: .'<th>'.&mt('Extent').'</th>'
1399: .'<th>'.&mt('Start').'</th>'
1400: .'<th>'.&mt('End').'</th>'
1401: .&Apache::loncommon::end_data_table_header_row()
1402: );
1.191 raeburn 1403: $doheaders=-1;
1404: my @roletypes = &roletypes();
1405: foreach my $type (@roletypes) {
1406: my $haverole=0;
1407: foreach my $which (sort {uc($a) cmp uc($b)} (keys(%{$sortrole}))) {
1408: if ($roleclass->{$sortrole->{$which}} =~ /^\Q$type\E/) {
1409: $haverole=1;
1410: }
1411: }
1412: if ($haverole) { $doheaders++; }
1413: }
1414: }
1415: return $doheaders;
1416: }
1417:
1418: sub roletypes {
1.313 ! raeburn 1419: my @types = ('Domain','Authoring Space','Course','Placement Test','Community','Unavailable','System');
1.191 raeburn 1420: return @types;
1421: }
1422:
1423: sub print_rolerows {
1424: my ($r,$doheaders,$roleclass,$sortrole,$dcroles,$roletext) = @_;
1425: if ((ref($roleclass) eq 'HASH') && (ref($sortrole) eq 'HASH')) {
1426: my @types = &roletypes();
1427: foreach my $type (@types) {
1428: my $output;
1429: foreach my $which (sort {uc($a) cmp uc($b)} (keys(%{$sortrole}))) {
1430: if ($roleclass->{$sortrole->{$which}} =~ /^\Q$type\E/) {
1431: if (ref($roletext) eq 'HASH') {
1.223 raeburn 1432: if (ref($roletext->{$sortrole->{$which}}) eq 'ARRAY') {
1433: $output.= &Apache::loncommon::start_data_table_row().
1434: $roletext->{$sortrole->{$which}}->[0].
1435: &Apache::loncommon::end_data_table_row();
1.251 raeburn 1436: if ($roletext->{$sortrole->{$which}}->[1] ne '') {
1437: $output .= &Apache::loncommon::continue_data_table_row().
1438: $roletext->{$sortrole->{$which}}->[1].
1439: &Apache::loncommon::end_data_table_row();
1440: }
1.223 raeburn 1441: }
1.191 raeburn 1442: if ($sortrole->{$which} =~ m-dc\./($match_domain)/-) {
1443: if (ref($dcroles) eq 'HASH') {
1444: if ($dcroles->{$1}) {
1.192 raeburn 1445: $output .= &adhoc_roles_row($1,'');
1.191 raeburn 1446: }
1447: }
1448: }
1449: }
1450: }
1451: }
1452: if ($output) {
1453: if ($doheaders > 0) {
1.212 bisitz 1454: $r->print(&Apache::loncommon::start_data_table_empty_row()
1455: .'<td align="center" colspan="5">'
1456: .&mt($type)
1457: .'</td>'
1458: .&Apache::loncommon::end_data_table_empty_row()
1459: );
1.191 raeburn 1460: }
1461: $r->print($output);
1462: }
1463: }
1464: }
1465: }
1466:
1467: sub findcourse_advice {
1.302 raeburn 1468: my ($r,$cattype) = @_;
1.191 raeburn 1469: my $domdesc = &Apache::lonnet::domain($env{'user.domain'},'description');
1.201 raeburn 1470: my $esc_dom = &HTML::Entities::encode($env{'user.domain'},'"<>&');
1.200 raeburn 1471: if (&Apache::lonnet::auto_run(undef,$env{'user.domain'})) {
1.191 raeburn 1472: $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).'
1473: <ul>
1474: <li>'.&mt('The course has yet to be created.').'</li>
1475: <li>'.&mt('Automatic enrollment of registered students has not been enabled for the course.').'</li>
1476: <li>'.&mt('You are in a section of course for which automatic enrollment in the corresponding LON-CAPA course is not active.').'</li>
1477: <li>'.&mt('The start date for automated enrollment has yet to be reached.').'</li>
1478: <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>
1479: </ul>');
1480: } else {
1481: $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 />');
1482: }
1.302 raeburn 1483: if (($cattype eq 'std') || ($cattype eq 'domonly')) {
1484: $r->print('<h3>'.&mt('Self-Enrollment').'</h3>'.
1485: '<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 />');
1486: $r->print(&mt('You can search for courses and communities which permit self-enrollment, if you would like to enroll in one.').'</p>'.
1487: &Apache::loncoursequeueadmin::queued_selfenrollment());
1488: }
1.216 raeburn 1489: return;
1490: }
1491:
1.234 raeburn 1492: sub requestcourse_advice {
1.306 raeburn 1493: my ($r,$cattype,$inrole) = @_;
1.234 raeburn 1494: my $domdesc = &Apache::lonnet::domain($env{'user.domain'},'description');
1495: my $esc_dom = &HTML::Entities::encode($env{'user.domain'},'"<>&');
1.306 raeburn 1496: my (%can_request,%request_doms,$output);
1.234 raeburn 1497: &Apache::lonnet::check_can_request($env{'user.domain'},\%can_request,\%request_doms);
1498: if (keys(%request_doms) > 0) {
1499: my ($types,$typename) = &Apache::loncommon::course_types();
1500: if ((ref($types) eq 'ARRAY') && (ref($typename) eq 'HASH')) {
1501: my (@reqdoms,@reqtypes);
1502: foreach my $type (sort(keys(%request_doms))) {
1503: push(@reqtypes,$type);
1504: if (ref($request_doms{$type}) eq 'ARRAY') {
1505: my $domstr = join(', ',map { &Apache::lonnet::domain($_) } sort(@{$request_doms{$type}}));
1.306 raeburn 1506: $output .=
1.238 bisitz 1507: '<li>'
1508: .&mt('[_1]'.$typename->{$type}.'[_2] in domain: [_3]',
1509: '<i>',
1510: '</i>',
1511: '<b>'.$domstr.'</b>')
1.306 raeburn 1512: .'</li>';
1.234 raeburn 1513: foreach my $dom (@{$request_doms{$type}}) {
1514: unless (grep(/^\Q$dom\E/,@reqdoms)) {
1515: push(@reqdoms,$dom);
1516: }
1517: }
1518: }
1519: }
1520: my @showtypes;
1521: foreach my $type (@{$types}) {
1522: if (grep(/^\Q$type\E$/,@reqtypes)) {
1523: push(@showtypes,$type);
1524: }
1525: }
1526: my $requrl = '/adm/requestcourse';
1527: if (@reqdoms == 1) {
1528: $requrl .= '?showdom='.$reqdoms[0];
1529: }
1530: if (@showtypes > 0) {
1531: $requrl.=(($requrl=~/\?/)?'&':'?').'crstype='.$showtypes[0];
1532: }
1533: if (@reqdoms == 1 || @showtypes > 0) {
1534: $requrl .= '&state=crstype&action=new';
1.306 raeburn 1535: }
1.307 raeburn 1536: if ($output) {
1537: $r->print('<h3>'.&mt('Request creation of a course or community').'</h3>'.
1538: '<p>'.
1539: &mt('You have rights to request the creation of courses and/or communities in the following domain(s):').
1540: '<ul>'.
1541: $output.
1542: '</ul>'.
1543: &mt('Use the [_1]request form[_2] to submit a request for creation of a new course or community.',
1544: '<a href="'.$requrl.'">','</a>').
1545: '</p>');
1546: }
1.234 raeburn 1547: }
1.302 raeburn 1548: } elsif (!$env{'user.adv'}) {
1.306 raeburn 1549: if ($inrole) {
1550: $r->print('<h3>'.&mt('Currently no additional roles, courses or communities').'</h3>');
1551: } else {
1552: $r->print('<h3>'.&mt('Currently no active roles, courses or communities').'</h3>');
1553: }
1.302 raeburn 1554: &findcourse_advice($r,$cattype);
1.234 raeburn 1555: }
1556: return;
1557: }
1558:
1.175 albertel 1559: sub privileges_info {
1560: my ($which) = @_;
1561: my $output;
1562:
1563: $which ||= $env{'request.role'};
1564:
1565: foreach my $envkey (sort(keys(%env))) {
1566: next if ($envkey!~/^user\.priv\.\Q$which\E\.(.*)/);
1567:
1568: my $where=$1;
1569: my $ttype;
1570: my $twhere;
1571: my (undef,$tdom,$trest,$tsec)=split(m{/},$where);
1572: if ($trest) {
1573: if ($env{'course.'.$tdom.'_'.$trest.'.description'} eq 'ca') {
1.288 raeburn 1574: $ttype='Authoring Space';
1.175 albertel 1575: $twhere='User: '.$trest.', Domain: '.$tdom;
1576: } else {
1577: $ttype= &Apache::loncommon::course_type($tdom.'_'.$trest);
1578: $twhere=$env{'course.'.$tdom.'_'.$trest.'.description'};
1579: if ($tsec) {
1580: my $sec_type = 'Section';
1581: if (exists($env{"user.role.gr.$where"})) {
1582: $sec_type = 'Group';
1583: }
1584: $twhere.=' ('.$sec_type.': '.$tsec.')';
1585: }
1586: }
1587: } elsif ($tdom) {
1588: $ttype='Domain';
1589: $twhere=$tdom;
1590: } else {
1591: $ttype='System';
1592: $twhere='/';
1593: }
1.204 bisitz 1594: $output .= "\n<h3>".&mt($ttype).': '.$twhere.'</h3>'."\n<ul>";
1.175 albertel 1595: foreach my $priv (sort(split(/:/,$env{$envkey}))) {
1596: next if (!$priv);
1597:
1598: my ($prv,$restr)=split(/\&/,$priv);
1599: my $trestr='';
1600: if ($restr ne 'F') {
1601: $trestr.=' ('.
1602: join(', ',
1603: map { &Apache::lonnet::plaintext($_) }
1604: (split('',$restr))).') ';
1605: }
1606: $output .= "\n\t".
1607: '<li>'.&Apache::lonnet::plaintext($prv).$trestr.'</li>';
1608: }
1609: $output .= "\n".'</ul>';
1610: }
1611: return $output;
1612: }
1613:
1.110 raeburn 1614: sub build_roletext {
1.313 ! raeburn 1615: my ($trolecode,$tdom,$trest,$tstatus,$tryagain,$advanced,$tremark,$tbg,$trole,$twhere,
! 1616: $tpstart,$tpend,$nochoose,$button,$switchserver,$reinit,$switchwarning,$skipcal) = @_;
1.223 raeburn 1617: my ($roletext,$roletext_end);
1.132 albertel 1618: my $is_dc=($trolecode =~ m/^dc\./);
1619: my $rowspan=($is_dc) ? ''
1620: : ' rowspan="2" ';
1621:
1.110 raeburn 1622: unless ($nochoose) {
1.134 www 1623: my $buttonname=$trolecode;
1624: $buttonname=~s/\W//g;
1.110 raeburn 1625: if (!$button) {
1626: if ($switchserver) {
1.212 bisitz 1627: $roletext.='<td'.$rowspan.' class="'.$tbg.'">'
1628: .'<a href="/adm/switchserver?'.$switchserver.'">'
1629: .&mt('Switch Server')
1630: .'</a></td>';
1.110 raeburn 1631: } else {
1.212 bisitz 1632: $roletext.=('<td'.$rowspan.' class="'.$tbg.'"> </td>');
1.110 raeburn 1633: }
1.255 raeburn 1634: if ($switchwarning) {
1635: if ($tremark eq '') {
1636: $tremark = $switchwarning;
1637: } else {
1638: $tremark .= '<br />'.$switchwarning;
1639: }
1640: }
1.110 raeburn 1641: } elsif ($tstatus eq 'is') {
1.212 bisitz 1642: $roletext.='<td'.$rowspan.' class="'.$tbg.'">'.
1643: '<input name="'.$buttonname.'" type="button" value="'.
1.225 bisitz 1644: &mt('Select').'" onclick="javascript:enterrole(this.form,\''.
1.192 raeburn 1645: $trolecode."','".$buttonname.'\');" /></td>';
1.110 raeburn 1646: } elsif ($tryagain) {
1647: $roletext.=
1.212 bisitz 1648: '<td'.$rowspan.' class="'.$tbg.'">'.
1649: '<input name="'.$buttonname.'" type="button" value="'.
1.225 bisitz 1650: &mt('Try Selecting Again').'" onclick="javascript:enterrole(this.form,\''.
1.192 raeburn 1651: $trolecode."','".$buttonname.'\');" /></td>';
1.110 raeburn 1652: } elsif ($advanced) {
1653: $roletext.=
1.212 bisitz 1654: '<td'.$rowspan.' class="'.$tbg.'">'.
1655: '<input name="'.$buttonname.'" type="button" value="'.
1.225 bisitz 1656: &mt('Re-Initialize').'" onclick="javascript:enterrole(this.form,\''.
1.192 raeburn 1657: $trolecode."','".$buttonname.'\');" /></td>';
1.209 raeburn 1658: } elsif ($reinit) {
1659: $roletext.=
1.212 bisitz 1660: '<td'.$rowspan.' class="'.$tbg.'">'.
1661: '<input name="'.$buttonname.'" type="button" value="'.
1.225 bisitz 1662: &mt('Re-Select').'" onclick="javascript:enterrole(this.form,\''.
1.209 raeburn 1663: $trolecode."','".$buttonname.'\');" /></td>';
1.110 raeburn 1664: } else {
1.209 raeburn 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: }
1671: }
1.313 ! raeburn 1672: if (($trolecode !~ m/^(dc|ca|au|aa)\./) && (!$skipcal)) {
1.165 albertel 1673: $tremark.=&Apache::lonannounce::showday(time,1,
1674: &Apache::lonannounce::readcalendar($tdom.'_'.$trest));
1675: }
1.212 bisitz 1676: $roletext.='<td>'.$trole.'</td>'
1677: .'<td>'.$twhere.'</td>'
1678: .'<td>'.$tpstart.'</td>'
1.223 raeburn 1679: .'<td>'.$tpend.'</td>';
1.132 albertel 1680: if (!$is_dc) {
1.223 raeburn 1681: $roletext_end = '<td colspan="4">'.
1682: $tremark.' '.
1683: '</td>';
1.132 albertel 1684: }
1.223 raeburn 1685: return ($roletext,$roletext_end);
1.110 raeburn 1686: }
1687:
1.193 raeburn 1688: sub check_author_homeserver {
1.183 www 1689: my ($uname,$udom)=@_;
1.193 raeburn 1690: if (($uname eq '') || ($udom eq '')) {
1691: return ('fail','');
1692: }
1.183 www 1693: my $home = &Apache::lonnet::homeserver($uname,$udom);
1.193 raeburn 1694: if (&Apache::lonnet::host_domain($home) ne $udom) {
1695: return ('fail',$home);
1696: }
1.183 www 1697: my @ids=&Apache::lonnet::current_machine_ids();
1.193 raeburn 1698: if (grep(/^\Q$home\E$/,@ids)) {
1699: return ('ok',$home);
1700: } else {
1701: return ('switchserver',$home);
1.183 www 1702: }
1703: }
1704:
1.104 raeburn 1705: sub check_fordc {
1.260 raeburn 1706: my ($dcroles,$update,$then) = @_;
1.104 raeburn 1707: my $numdc = 0;
1.118 albertel 1708: if ($env{'user.adv'}) {
1.309 raeburn 1709: foreach my $envkey (sort(keys(%env))) {
1.170 albertel 1710: if ($envkey=~/^user\.role\.dc\.\/($match_domain)\/$/) {
1.104 raeburn 1711: my $dcdom = $1;
1712: my $livedc = 1;
1.118 albertel 1713: my ($tstart,$tend)=split(/\./,$env{$envkey});
1.260 raeburn 1714: my $limit = $update;
1715: if ($env{'request.role'} eq 'dc./'.$dcdom.'/') {
1716: $limit = $then;
1717: }
1718: if ($tstart && $tstart>$limit) { $livedc = 0; }
1719: if ($tend && $tend <$limit) { $livedc = 0; }
1.104 raeburn 1720: if ($livedc) {
1721: $$dcroles{$dcdom} = $envkey;
1.105 raeburn 1722: $numdc++;
1.104 raeburn 1723: }
1724: }
1725: }
1726: }
1727: return $numdc;
1728: }
1729:
1.185 raeburn 1730: sub adhoc_course_role {
1.260 raeburn 1731: my ($refresh,$update,$then) = @_;
1.239 raeburn 1732: my ($cdom,$cnum,$crstype);
1.201 raeburn 1733: $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
1734: $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.239 raeburn 1735: $crstype = &Apache::loncommon::course_type();
1.260 raeburn 1736: if (&check_forcc($cdom,$cnum,$refresh,$update,$then,$crstype)) {
1.185 raeburn 1737: my $setprivs;
1.198 raeburn 1738: if (!defined($env{'user.role.'.$env{'form.switchrole'}})) {
1.185 raeburn 1739: $setprivs = 1;
1740: } else {
1.198 raeburn 1741: my ($start,$end) = split(/\./,$env{'user.role.'.$env{'form.switchrole'}});
1.232 raeburn 1742: if (($start && ($start>$refresh || $start == -1)) ||
1.260 raeburn 1743: ($end && $end<$update)) {
1.185 raeburn 1744: $setprivs = 1;
1745: }
1.232 raeburn 1746: }
1.278 raeburn 1747: unless ($setprivs) {
1748: if (!exists($env{'user.priv.'.$env{'form.switchrole'}.'./'})) {
1749: $setprivs = 1;
1750: }
1751: }
1.185 raeburn 1752: if ($setprivs) {
1.297 raeburn 1753: if ($env{'form.switchrole'} =~ m-^(in|ta|ep|ad|st|cr)(.*?)\./\Q$cdom\E/\Q$cnum\E/?(\w*)$-) {
1.185 raeburn 1754: my $role = $1;
1755: my $custom_role = $2;
1756: my $usec = $3;
1757: if ($role eq 'cr') {
1.199 raeburn 1758: if ($custom_role =~ m-^/$match_domain/$match_username/\w+$-) {
1.185 raeburn 1759: $role .= $custom_role;
1760: } else {
1761: return;
1762: }
1763: }
1.208 raeburn 1764: my (%userroles,%newrole,%newgroups,%group_privs);
1765: my %cgroups =
1766: &Apache::lonnet::get_active_groups($env{'user.domain'},
1767: $env{'user.name'},$cdom,$cnum);
1768: foreach my $group (keys(%cgroups)) {
1769: $group_privs{$group} =
1770: $env{'user.priv.cc./'.$cdom.'/'.$cnum.'./'.$cdom.'/'.$cnum.'/'.$group};
1771: }
1772: $newgroups{'/'.$cdom.'/'.$cnum} = \%group_privs;
1.185 raeburn 1773: my $area = '/'.$cdom.'/'.$cnum;
1774: my $spec = $role.'.'.$area;
1775: if ($usec ne '') {
1776: $spec .= '/'.$usec;
1777: $area .= '/'.$usec;
1778: }
1.278 raeburn 1779: if ($role =~ /^cr/) {
1780: &Apache::lonnet::custom_roleprivs(\%newrole,$role,$cdom,$cnum,$spec,$area);
1781: } else {
1782: &Apache::lonnet::standard_roleprivs(\%newrole,$role,$cdom,$spec,$cnum,$area);
1783: }
1.208 raeburn 1784: &Apache::lonnet::set_userprivs(\%userroles,\%newrole,\%newgroups);
1.232 raeburn 1785: my $adhocstart = $refresh-1;
1.185 raeburn 1786: $userroles{'user.role.'.$spec} = $adhocstart.'.';
1.186 raeburn 1787: &Apache::lonnet::appenv(\%userroles,[$role,'cm']);
1.185 raeburn 1788: }
1789: }
1790: }
1791: return;
1792: }
1793:
1794: sub check_forcc {
1.260 raeburn 1795: my ($cdom,$cnum,$refresh,$update,$then,$crstype) = @_;
1.239 raeburn 1796: my ($is_cc,$ccrole);
1797: if ($crstype eq 'Community') {
1798: $ccrole = 'co';
1799: } else {
1800: $ccrole = 'cc';
1801: }
1.266 droeschl 1802: if (&Apache::lonnet::is_course($cdom,$cnum)) {
1803: my $envkey = 'user.role.'.$ccrole.'./'.$cdom.'/'.$cnum;
1804: if (defined($env{$envkey})) {
1805: $is_cc = 1;
1806: my ($tstart,$tend)=split(/\./,$env{$envkey});
1807: my $limit = $update;
1808: if ($env{'request.role'} eq $ccrole.'./'.$cdom.'/'.$cnum) {
1809: $limit = $then;
1.185 raeburn 1810: }
1.266 droeschl 1811: if ($tstart && $tstart>$refresh) { $is_cc = 0; }
1812: if ($tend && $tend <$limit) { $is_cc = 0; }
1.185 raeburn 1813: }
1814: }
1815: return $is_cc;
1816: }
1817:
1.108 raeburn 1818: sub courselink {
1.193 raeburn 1819: my ($dcdom,$rowtype) = @_;
1.109 raeburn 1820: my $courseform=&Apache::loncommon::selectcourse_link
1.152 raeburn 1821: ('rolechoice','dccourse'.$rowtype.'_'.$dcdom,
1822: 'dcdomain'.$rowtype.'_'.$dcdom,'coursedesc'.$rowtype.'_'.
1.239 raeburn 1823: $dcdom,$dcdom,undef,'Course/Community');
1.138 raeburn 1824: my $hiddenitems = '<input type="hidden" name="dcdomain'.$rowtype.'_'.$dcdom.'" value="'.$dcdom.'" />'.
1825: '<input type="hidden" name="origdom'.$rowtype.'_'.$dcdom.'" value="'.$dcdom.'" />'.
1826: '<input type="hidden" name="dccourse'.$rowtype.'_'.$dcdom.'" value="" />'.
1827: '<input type="hidden" name="coursedesc'.$rowtype.'_'.$dcdom.'" value="" />';
1.112 raeburn 1828: return $courseform.$hiddenitems;
1.109 raeburn 1829: }
1830:
1831: sub coursepick_jscript {
1.312 damieng 1832: my %js_lt = &Apache::lonlocal::texthash(
1.239 raeburn 1833: plsu => "Please use the 'Select Course/Community' link to open a separate pick course window where you may select the course or community you wish to enter.",
1.234 raeburn 1834: youc => 'You can only use this screen to select courses and communities in the current domain.',
1.184 raeburn 1835: );
1.312 damieng 1836: &js_escape(\%js_lt);
1.104 raeburn 1837: my $verify_script = <<"END";
1.179 raeburn 1838: <script type="text/javascript">
1.225 bisitz 1839: // <![CDATA[
1.108 raeburn 1840: function verifyCoursePick(caller) {
1841: var numbutton = getIndex(caller)
1.112 raeburn 1842: var pickedCourse = document.rolechoice.elements[numbutton+4].value
1843: var pickedDomain = document.rolechoice.elements[numbutton+2].value
1844: if (document.rolechoice.elements[numbutton+2].value == document.rolechoice.elements[numbutton+3].value) {
1.104 raeburn 1845: if (pickedCourse != '') {
1.108 raeburn 1846: if (numbutton != -1) {
1847: var courseTarget = "cc./"+pickedDomain+"/"+pickedCourse
1848: document.rolechoice.elements[numbutton+1].name = courseTarget
1849: document.rolechoice.submit()
1850: }
1.104 raeburn 1851: }
1852: else {
1.312 damieng 1853: alert("$js_lt{'plsu'}");
1.104 raeburn 1854: }
1855: }
1856: else {
1.312 damieng 1857: alert("$js_lt{'youc'}")
1.104 raeburn 1858: }
1859: }
1.109 raeburn 1860: function getIndex(caller) {
1.108 raeburn 1861: for (var i=0;i<document.rolechoice.elements.length;i++) {
1.109 raeburn 1862: if (document.rolechoice.elements[i] == caller) {
1.108 raeburn 1863: return i;
1864: }
1865: }
1866: return -1;
1867: }
1.225 bisitz 1868: // ]]>
1.104 raeburn 1869: </script>
1870: END
1.109 raeburn 1871: return $verify_script;
1.104 raeburn 1872: }
1873:
1.193 raeburn 1874: sub coauthorlink {
1875: my ($dcdom,$rowtype) = @_;
1876: my $coauthorform=&Apache::loncommon::selectauthor_link('rolechoice',$dcdom);
1877: my $hiddenitems = '<input type="hidden" name="adhoccauname'.$rowtype.'_'.$dcdom.'" value="" />';
1878: return $coauthorform.$hiddenitems;
1879: }
1880:
1.113 raeburn 1881: sub display_cc_role {
1882: my $rolekey = shift;
1.223 raeburn 1883: my ($roletext,$roletext_end);
1.118 albertel 1884: my $advanced = $env{'user.adv'};
1885: my $tryagain = $env{'form.tryagain'};
1.113 raeburn 1886: unless ($rolekey =~/^error\:/) {
1.240 raeburn 1887: if ($rolekey =~ m{^user\.role\.(cc|co)\./($match_domain)/($match_courseid)$}) {
1888: my $ccrole = $1;
1.249 raeburn 1889: my $tdom = $2;
1890: my $trest = $3;
1891: my $tcourseid = $tdom.'_'.$trest;
1892: my $trolecode = $ccrole.'./'.$tdom.'/'.$trest;
1.113 raeburn 1893: my $twhere;
1.152 raeburn 1894: my $ttype;
1.313 ! raeburn 1895: my $skipcal;
1.212 bisitz 1896: my $tbg='LC_roles_is';
1.113 raeburn 1897: my %newhash=&Apache::lonnet::coursedescription($tcourseid);
1898: if (%newhash) {
1899: $twhere=$newhash{'description'}.
1.261 bisitz 1900: ' <span class="LC_fontsize_small">'.
1.249 raeburn 1901: &Apache::loncommon::syllabuswrapper(&mt('Syllabus'),$trest,$tdom).
1.211 tempelho 1902: '</span>';
1.153 raeburn 1903: $ttype = $newhash{'type'};
1.113 raeburn 1904: } else {
1905: $twhere=&mt('Currently not available');
1.118 albertel 1906: $env{'course.'.$tcourseid.'.description'}=$twhere;
1.313 ! raeburn 1907: $skipcal = 1;
1.110 raeburn 1908: }
1.242 raeburn 1909: my $trole = &Apache::lonnet::plaintext($ccrole,$ttype,$tcourseid);
1.258 raeburn 1910: $twhere.="<br />".&mt('Domain').":".$tdom;
1.313 ! raeburn 1911: ($roletext,$roletext_end) = &build_roletext($trolecode,$tdom,$trest,'is',$tryagain,$advanced,'',$tbg,$trole,$twhere,'','','',1,'','','',$skipcal);
1.104 raeburn 1912: }
1913: }
1.223 raeburn 1914: return ($roletext,$roletext_end);
1.104 raeburn 1915: }
1916:
1.192 raeburn 1917: sub adhoc_roles_row {
1.138 raeburn 1918: my ($dcdom,$rowtype) = @_;
1.212 bisitz 1919: my $output = &Apache::loncommon::continue_data_table_row()
1920: .' <td colspan="5">'
1921: .&mt('[_1]Ad hoc[_2] roles in domain [_3] --'
1922: ,'<span class="LC_cusr_emph">','</span>',$dcdom)
1.227 bisitz 1923: .' ';
1.193 raeburn 1924: my $selectcclink = &courselink($dcdom,$rowtype);
1.239 raeburn 1925: my $ccrole = &Apache::lonnet::plaintext('co',undef,undef,1);
1.182 www 1926: my $carole = &Apache::lonnet::plaintext('ca');
1.193 raeburn 1927: my $selectcalink = &coauthorlink($dcdom,$rowtype);
1.227 bisitz 1928: $output.=$ccrole.': '.$selectcclink
1.249 raeburn 1929: .' | '.$carole.': '.$selectcalink.'</td>'
1.212 bisitz 1930: .&Apache::loncommon::end_data_table_row();
1.108 raeburn 1931: return $output;
1932: }
1933:
1.104 raeburn 1934: sub recent_filename {
1935: my $area=shift;
1.149 www 1936: return 'nohist_recent_'.&escape($area);
1.104 raeburn 1937: }
1938:
1.139 raeburn 1939: sub courseloadpage {
1940: my ($courseid) = @_;
1941: my $startpage;
1.144 albertel 1942: my %entry_settings = &Apache::lonnet::get('nohist_whatsnew',
1943: [$courseid.':courseinit']);
1.139 raeburn 1944: my ($tmp) = %entry_settings;
1.144 albertel 1945: unless ($tmp =~ /^error: 2 /) {
1.139 raeburn 1946: $startpage = $entry_settings{$courseid.':courseinit'};
1947: }
1948: if ($startpage eq '') {
1949: if (exists($env{'environment.course_init_display'})) {
1950: $startpage = $env{'environment.course_init_display'};
1951: }
1952: }
1953: return $startpage;
1954: }
1955:
1.260 raeburn 1956: sub update_session_roles {
1957: my $then=$env{'user.login.time'};
1958: my $refresh=$env{'user.refresh.time'};
1959: if (!$refresh) {
1960: $refresh = $then;
1961: }
1962: my $update = $env{'user.update.time'};
1963: if (!$update) {
1964: $update = $then;
1965: }
1966: my $now = time;
1967: my %roleshash =
1968: &Apache::lonnet::get_my_roles('','','userroles',
1969: ['active','future','previous'],
1970: undef,undef,1);
1971: my ($msg,@newsec,$oldsec,$currrole_expired,@changed_roles,
1.264 raeburn 1972: %changed_groups,%dbroles,%deletedroles,%allroles,%allgroups,
1.260 raeburn 1973: %userroles,%checkedgroup,%crprivs,$hasgroups,%rolechange,
1974: %groupchange,%newrole,%newgroup,%customprivchg,%groups_roles,
1975: @rolecodes);
1976: my @possroles = ('cr','st','ta','ad','ep','in','co','cc');
1977: my %courseroles;
1978: foreach my $item (keys(%roleshash)) {
1979: my ($uname,$udom,$role,$remainder) = split(/:/,$item,4);
1980: my ($tstart,$tend) = split(/:/,$roleshash{$item});
1981: my ($section,$group,@group_privs);
1982: if ($role =~ m{^gr/(\w*)$}) {
1983: $role = 'gr';
1984: my $priv = $1;
1985: next if ($tstart eq '-1');
1986: if (&curr_role_status($tstart,$tend,$refresh,$now) eq 'active') {
1987: if ($priv ne '') {
1988: push(@group_privs,$priv);
1989: }
1990: }
1991: if ($remainder =~ /:/) {
1992: (my $additional_privs,$group) =
1993: ($remainder =~ /^([\w:]+):([^:]+)$/);
1994: if ($additional_privs ne '') {
1995: if (&curr_role_status($tstart,$tend,$refresh,$now) eq 'active') {
1996: push(@group_privs,split(/:/,$additional_privs));
1997: @group_privs = sort(@group_privs);
1998: }
1999: }
2000: } else {
2001: $group = $remainder;
2002: }
2003: } else {
2004: $section = $remainder;
2005: }
2006: my $where = "/$udom/$uname";
2007: if ($section ne '') {
2008: $where .= "/$section";
2009: } elsif ($group ne '') {
2010: $where .= "/$group";
2011: }
2012: my $rolekey = "$role.$where";
2013: my $envkey = "user.role.$rolekey";
2014: $dbroles{$envkey} = 1;
2015: if (($env{'request.role'} eq $rolekey) && ($role ne 'st')) {
2016: if (&curr_role_status($tstart,$tend,$refresh,$now) ne 'active') {
2017: $currrole_expired = 1;
2018: }
2019: }
2020: if ($env{$envkey} eq '') {
2021: my $status_in_db =
1.271 raeburn 2022: &curr_role_status($tstart,$tend,$now,$now);
1.260 raeburn 2023: &gather_roleprivs(\%allroles,\%allgroups,\%userroles,$where,$role,$tstart,$tend,$status_in_db);
2024: if (($role eq 'st') && ($env{'request.role'} =~ m{^\Q$role\E\.\Q/$udom/$uname\E})) {
2025: if ($status_in_db eq 'active') {
2026: if ($section eq '') {
2027: push(@newsec,'none');
2028: } else {
2029: push(@newsec,$section);
2030: }
2031: }
2032: } else {
2033: unless (grep(/^\Q$role\E$/,@changed_roles)) {
2034: push(@changed_roles,$role);
2035: }
2036: if ($status_in_db ne 'previous') {
2037: if ($role eq 'gr') {
2038: $newgroup{$rolekey} = $status_in_db;
2039: if ($status_in_db eq 'active') {
2040: unless (ref($courseroles{$udom}) eq 'HASH') {
2041: %{$courseroles{$udom}} =
2042: &Apache::lonnet::get_my_roles('','','userroles',
2043: ['active'],\@possroles,
2044: [$udom],1);
2045: }
2046: &Apache::lonnet::get_groups_roles($udom,$uname,
2047: $courseroles{$udom},
2048: \@rolecodes,\%groups_roles);
2049: }
2050: } else {
2051: $newrole{$rolekey} = $status_in_db;
2052: }
2053: }
2054: }
2055: } else {
2056: my ($currstart,$currend) = split(/\./,$env{$envkey});
2057: if ($role eq 'gr') {
2058: if (&curr_role_status($currstart,$currend,$refresh,$update) ne 'previous') {
2059: $hasgroups = 1;
2060: }
2061: }
2062: if (($currstart ne $tstart) || ($currend ne $tend)) {
2063: my $status_in_env =
2064: &curr_role_status($currstart,$currend,$refresh,$update);
2065: my $status_in_db =
1.271 raeburn 2066: &curr_role_status($tstart,$tend,$now,$now);
1.260 raeburn 2067: if ($status_in_env ne $status_in_db) {
2068: if ($status_in_env eq 'active') {
2069: if ($role eq 'st') {
2070: if ($env{'request.role'} eq $rolekey) {
2071: my $switchsection;
2072: unless (ref($courseroles{$udom}) eq 'HASH') {
2073: %{$courseroles{$udom}} =
2074: &Apache::lonnet::get_my_roles('','','userroles',
2075: ['active'],
2076: \@possroles,[$udom],1);
2077: }
2078: foreach my $crsrole (keys(%{$courseroles{$udom}})) {
2079: if ($crsrole =~ /^\Q$uname\E:\Q$udom\E:st/) {
2080: $switchsection = 1;
2081: last;
2082: }
2083: }
2084: if ($switchsection) {
2085: if ($section eq '') {
2086: $oldsec = 'none';
2087: } else {
2088: $oldsec = $section;
2089: }
2090: &gather_roleprivs(\%allroles,\%allgroups,\%userroles,$where,$role,$tstart,$tend,$status_in_db);
2091: } else {
2092: $currrole_expired = 1;
2093: next;
2094: }
2095: }
2096: }
2097: unless ($rolekey eq $env{'request.role'}) {
2098: if ($role eq 'gr') {
2099: &Apache::lonnet::delete_env_groupprivs($where,\%courseroles,\@possroles);
2100: } else {
2101: &Apache::lonnet::delenv("user.priv.$rolekey",undef,[$role]);
2102: &Apache::lonnet::delenv("user.priv.cm.$where",undef,['cm']);
2103: }
2104: &gather_roleprivs(\%allroles,\%allgroups,\%userroles,$where,$role,$tstart,$tend,$status_in_db);
2105: }
2106: } elsif ($status_in_db eq 'active') {
2107: if (($role eq 'st') &&
2108: ($env{'request.role'} =~ m{^\Q$role\E\.\Q/$udom/$uname\E})) {
2109: if ($section eq '') {
2110: push(@newsec,'none');
2111: } else {
2112: push(@newsec,$section);
2113: }
2114: } elsif ($role eq 'gr') {
2115: unless (ref($courseroles{$udom}) eq 'HASH') {
2116: %{$courseroles{$udom}} =
2117: &Apache::lonnet::get_my_roles('','','userroles',
2118: ['active'],
2119: \@possroles,[$udom],1);
2120: }
2121: &Apache::lonnet::get_groups_roles($udom,$uname,
2122: $courseroles{$udom},
2123: \@rolecodes,\%groups_roles);
2124: }
2125: &gather_roleprivs(\%allroles,\%allgroups,\%userroles,$where,$role,$tstart,$tend,$status_in_db);
2126: }
2127: unless (grep(/^\Q$role\E$/,@changed_roles)) {
2128: push(@changed_roles,$role);
2129: }
2130: if ($role eq 'gr') {
2131: $groupchange{"/$udom/$uname"}{$group} = $status_in_db;
2132: } else {
2133: $rolechange{$rolekey} = $status_in_db;
2134: }
2135: }
2136: } else {
2137: if ($role eq 'gr') {
2138: unless ($checkedgroup{$where}) {
2139: my $status_in_db =
2140: &curr_role_status($tstart,$tend,$refresh,$now);
2141: if ($tstart eq '-1') {
2142: $status_in_db = 'deleted';
2143: }
2144: unless (ref($courseroles{$udom}) eq 'HASH') {
2145: %{$courseroles{$udom}} =
2146: &Apache::lonnet::get_my_roles('','','userroles',
2147: ['active'],
2148: \@possroles,[$udom],1);
2149: }
2150: if (ref($courseroles{$udom}) eq 'HASH') {
2151: foreach my $item (keys(%{$courseroles{$udom}})) {
2152: next unless ($item =~ /^\Q$uname\E/);
2153: my ($cnum,$cdom,$crsrole,$crssec) = split(/:/,$item);
2154: my $area = '/'.$cdom.'/'.$cnum;
2155: if ($crssec ne '') {
2156: $area .= '/'.$crssec;
2157: }
2158: my $crsrolekey = $crsrole.'.'.$area;
2159: my $currprivs = $env{'user.priv.'.$crsrole.'.'.$area.'.'.$where};
2160: $currprivs =~ s/^://;
2161: $currprivs =~ s/\&F$//;
2162: my @curr_grp_privs = split(/\&F:/,$currprivs);
2163: @curr_grp_privs = sort(@curr_grp_privs);
2164: my @diffs;
2165: if (@group_privs > 0 || @curr_grp_privs > 0) {
2166: @diffs = &Apache::loncommon::compare_arrays(\@group_privs,\@curr_grp_privs);
2167: }
2168: if (@diffs == 0) {
2169: last;
2170: } else {
2171: unless(grep(/^\Qgr\E$/,@rolecodes)) {
2172: push(@rolecodes,'gr');
2173: }
2174: &gather_roleprivs(\%allroles,\%allgroups,
2175: \%userroles,$where,$role,
2176: $tstart,$tend,$status_in_db);
2177: if ($status_in_db eq 'active') {
2178: &Apache::lonnet::get_groups_roles($udom,$uname,
2179: $courseroles{$udom},
2180: \@rolecodes,\%groups_roles);
2181: }
2182: $changed_groups{$udom.'_'.$uname}{$group} = $status_in_db;
2183: last;
2184: }
2185: }
2186: }
2187: $checkedgroup{$where} = 1;
2188: }
2189: } elsif ($role =~ /^cr/) {
2190: my $status_in_db =
2191: &curr_role_status($tstart,$tend,$refresh,$now);
2192: my ($rdummy,$rest) = split(/\//,$role,2);
2193: my %currpriv;
2194: unless (exists($crprivs{$rest})) {
2195: my ($rdomain,$rauthor,$rrole)=split(/\//,$rest);
2196: my $homsvr=&Apache::lonnet::homeserver($rauthor,$rdomain);
2197: if (&Apache::lonnet::hostname($homsvr) ne '') {
2198: my ($rdummy,$roledef)=
2199: &Apache::lonnet::get('roles',["rolesdef_$rrole"],
2200: $rdomain,$rauthor);
2201: if (($rdummy ne 'con_lost') && ($roledef ne '')) {
2202: my $i = 0;
2203: my @scopes = ('sys','dom','crs');
2204: my @privs = split(/\_/,$roledef);
2205: foreach my $priv (@privs) {
2206: my ($blank,@prv) = split(/:/,$priv);
2207: @prv = map { $_ .= (/\&\w+$/ ? '':'&F') } @prv;
1.264 raeburn 2208: if (@prv) {
2209: $priv = ':'.join(':',sort(@prv));
2210: }
1.260 raeburn 2211: $crprivs{$rest}{$scopes[$i]} = $priv;
2212: $i++;
2213: }
2214: }
2215: }
2216: }
1.279 raeburn 2217: my $status_in_env =
2218: &curr_role_status($currstart,$currend,$refresh,$update);
2219: if ($status_in_env eq 'active') {
2220: $currpriv{sys} = $env{"user.priv.$rolekey./"};
2221: $currpriv{dom} = $env{"user.priv.$rolekey./$udom/"};
2222: $currpriv{crs} = $env{"user.priv.$rolekey.$where"};
2223: if (keys(%crprivs)) {
2224: if (($crprivs{$rest}{sys} ne $currpriv{sys}) ||
2225: ($crprivs{$rest}{dom} ne $currpriv{dom})
1.260 raeburn 2226: ||
1.279 raeburn 2227: ($crprivs{$rest}{crs} ne $currpriv{crs})) {
2228: &gather_roleprivs(\%allroles,\%allgroups,
2229: \%userroles,$where,$role,
2230: $tstart,$tend,$status_in_db);
2231: unless (grep(/^\Q$role\E$/,@changed_roles)) {
2232: push(@changed_roles,$role);
2233: }
1.260 raeburn 2234: $customprivchg{$rolekey} = $status_in_env;
2235: }
2236: }
2237: }
2238: }
2239: }
2240: }
2241: }
2242: foreach my $envkey (keys(%env)) {
2243: next unless ($envkey =~ /^user\.role\./);
2244: next if ($dbroles{$envkey});
2245: next if ($envkey eq 'user.role.'.$env{'request.role'});
2246: my ($currstart,$currend) = split(/\./,$env{$envkey});
2247: my $status_in_env =
2248: &curr_role_status($currstart,$currend,$refresh,$update);
2249: my ($rolekey) = ($envkey =~ /^user\.role\.(.+)$/);
1.297 raeburn 2250: my ($role,$rest)=split(m{\./},$rolekey,2);
2251: $rest = '/'.$rest;
1.260 raeburn 2252: if (&Apache::lonnet::delenv($envkey,undef,[$role])) {
2253: if ($status_in_env eq 'active') {
2254: if ($role eq 'gr') {
2255: &Apache::lonnet::delete_env_groupprivs($rest,\%courseroles,
2256: \@possroles);
2257: } else {
2258: &Apache::lonnet::delenv("user.priv.$rolekey",undef,[$role]);
2259: &Apache::lonnet::delenv("user.priv.cm.$rest",undef,['cm']);
2260: }
2261: unless (grep(/^\Q$role\E$/,@changed_roles)) {
2262: push(@changed_roles,$role);
2263: }
2264: $deletedroles{$rolekey} = 1;
2265: }
2266: }
2267: }
2268: if (($oldsec) && (@newsec > 0)) {
2269: if (@newsec > 1) {
1.274 raeburn 2270: $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 2271: } else {
2272: my $newrole = $env{'request.role'};
2273: if ($newsec[0] eq 'none') {
2274: $newrole =~ s{(/[^/])$}{};
2275: } elsif ($oldsec eq 'none') {
2276: $newrole .= '/'.$newsec[0];
2277: } else {
2278: $newrole =~ s{([^/]+)$}{$newsec[0]};
2279: }
2280: my $coursedesc = $env{'course.'.$env{'request.course.id'}.'.description'};
2281: my ($curr_role) = ($env{'request.role'} =~ m{^(\w+)\./$match_domain/$match_courseid});
2282: my %temp=('logout_'.$env{'request.course.id'} => time);
2283: &Apache::lonnet::put('email_status',\%temp);
2284: &Apache::lonnet::delenv('user.state.'.$env{'request.course.id'});
2285: &Apache::lonnet::appenv({"request.course.id" => '',
2286: "request.course.fn" => '',
2287: "request.course.uri" => '',
2288: "request.course.sec" => '',
2289: "request.role" => 'cm',
2290: "request.role.adv" => $env{'user.adv'},
2291: "request.role.domain" => $env{'user.domain'}});
2292: my $rolename = &Apache::loncommon::plainname($curr_role);
2293: $msg = '<p><form name="reselectrole" action="/adm/roles" method="post" />'.
2294: '<input type="hidden" name="newrole" value="" />'.
2295: '<input type="hidden" name="selectrole" value="1" />'.
2296: '<span class="LC_info">'.
2297: &mt('Your section has changed for your current [_1] role in [_2].',$rolename,$coursedesc).'</span><br />';
2298: my $button = '<input type="button" name="sectionchanged" value="'.
2299: &mt('Re-Select').'" onclick="javascript:enterrole(this.form,'."'$newrole','sectionchanged'".')" />';
2300: if ($newsec[0] eq 'none') {
2301: $msg .= &mt('[_1] to continue with your new section-less role.',$button);
2302: } else {
2303: $msg .= &mt('[_1] to continue with your new role in section ([_2]).',$button,$newsec[0]);
2304: }
2305: $msg .= '</form></p>';
2306: }
2307: } elsif ($currrole_expired) {
1.274 raeburn 2308: $msg .= '<p class="LC_warning">';
1.260 raeburn 2309: if (&Apache::loncommon::show_course()) {
2310: $msg .= &mt('Your role in the current course has expired.');
2311: } else {
2312: $msg .= &mt('Your current role has expired.');
2313: }
1.274 raeburn 2314: $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 2315: }
1.279 raeburn 2316: &Apache::lonnet::set_userprivs(\%userroles,\%allroles,\%allgroups,\%groups_roles);
2317: my ($curr_is_adv,$curr_role_adv,$curr_author,$curr_role_author);
2318: $curr_author = $env{'user.author'};
2319: if (($env{'request.role'} =~/^au/) || ($env{'request.role'} =~/^ca/) ||
2320: ($env{'request.role'} =~/^aa/)) {
2321: $curr_role_author=1;
2322: }
2323: $curr_is_adv = $env{'user.adv'};
2324: $curr_role_adv = $env{'request.role.adv'};
2325: if (keys(%userroles) > 0) {
2326: foreach my $role (@changed_roles) {
2327: unless(grep(/^\Q$role\E$/,@rolecodes)) {
2328: push(@rolecodes,$role);
2329: }
2330: }
2331: unless(grep(/^\Qcm\E$/,@rolecodes)) {
2332: push(@rolecodes,'cm');
2333: }
2334: &Apache::lonnet::appenv(\%userroles,\@rolecodes);
2335: }
2336: my %newenv;
2337: if (&Apache::lonnet::is_advanced_user($env{'user.domain'},$env{'user.name'})) {
2338: unless ($curr_is_adv) {
2339: $newenv{'user.adv'} = 1;
2340: }
2341: } elsif ($curr_is_adv && !$curr_role_adv) {
2342: &Apache::lonnet::delenv('user.adv');
2343: }
2344: my %authorroleshash =
2345: &Apache::lonnet::get_my_roles('','','userroles',['active'],['au','ca','aa']);
2346: if (keys(%authorroleshash)) {
2347: unless ($curr_author) {
2348: $newenv{'user.author'} = 1;
2349: }
2350: } elsif ($curr_author && !$curr_role_author) {
2351: &Apache::lonnet::delenv('user.author');
2352: }
2353: if ($env{'request.course.id'}) {
2354: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
2355: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
2356: my (@activecrsgroups,$crsgroupschanged);
2357: if ($env{'request.course.groups'}) {
2358: @activecrsgroups = split(/:/,$env{'request.course.groups'});
2359: foreach my $item (keys(%deletedroles)) {
2360: if ($item =~ m{^gr\./\Q$cdom\E/\Q$cnum\E/(\w+)$}) {
2361: if (grep(/^\Q$1\E$/,@activecrsgroups)) {
2362: $crsgroupschanged = 1;
2363: last;
2364: }
2365: }
2366: }
2367: }
2368: unless ($crsgroupschanged) {
2369: foreach my $item (keys(%newgroup)) {
2370: if ($item =~ m{^gr\./\Q$cdom\E/\Q$cnum\E/(\w+)$}) {
2371: if ($newgroup{$item} eq 'active') {
2372: $crsgroupschanged = 1;
2373: last;
2374: }
2375: }
2376: }
2377: }
2378: if ((ref($changed_groups{$env{'request.course.id'}}) eq 'HASH') ||
2379: (ref($groupchange{"/$cdom/$cnum"}) eq 'HASH') ||
2380: ($crsgroupschanged)) {
2381: my %grouproles = &Apache::lonnet::get_my_roles('','','userroles',
2382: ['active'],['gr'],[$cdom],1);
2383: my @activegroups;
2384: foreach my $item (keys(%grouproles)) {
2385: next unless($item =~ /^\Q$cnum\E:\Q$cdom\E/);
2386: my $group;
2387: my ($crsn,$crsd,$role,$remainder) = split(/:/,$item,4);
2388: if ($remainder =~ /:/) {
2389: (my $other,$group) = ($remainder =~ /^([\w:]+):([^:]+)$/);
2390: } else {
2391: $group = $remainder;
2392: }
2393: if ($group ne '') {
2394: push(@activegroups,$group);
2395: }
2396: }
2397: $newenv{'request.course.groups'} = join(':',@activegroups);
2398: }
2399: }
2400: if (keys(%newenv)) {
2401: &Apache::lonnet::appenv(\%newenv);
2402: }
1.260 raeburn 2403: if (!@changed_roles || !(keys(%changed_groups))) {
1.264 raeburn 2404: my ($rolesmsg,$groupsmsg);
1.260 raeburn 2405: if (!@changed_roles) {
2406: if (&Apache::loncommon::show_course()) {
1.264 raeburn 2407: $rolesmsg = &mt('No new courses or communities');
1.260 raeburn 2408: } else {
1.264 raeburn 2409: $rolesmsg = &mt('No role changes');
1.260 raeburn 2410: }
2411: }
2412: if ($hasgroups && !(keys(%changed_groups)) && !(grep(/gr/,@changed_roles))) {
1.264 raeburn 2413: $groupsmsg = &mt('No changes in course/community groups');
1.260 raeburn 2414: }
2415: if (!@changed_roles && !(keys(%changed_groups))) {
1.264 raeburn 2416: if (($msg ne '') || ($groupsmsg ne '')) {
2417: $msg .= '<ul>';
2418: if ($rolesmsg) {
2419: $msg .= '<li>'.$rolesmsg.'</li>';
2420: }
2421: if ($groupsmsg) {
2422: $msg .= '<li>'.$groupsmsg.'</li>';
2423: }
2424: $msg .= '</ul>';
2425: } else {
1.270 raeburn 2426: $msg = ' <span class="LC_cusr_emph">'.$rolesmsg.'</span><br />';
1.264 raeburn 2427: }
1.260 raeburn 2428: return $msg;
2429: }
2430: }
2431: my $changemsg;
2432: if (@changed_roles > 0) {
2433: if (keys(%newgroup) > 0) {
2434: my $groupmsg;
1.279 raeburn 2435: my (%curr_groups,%groupdescs,$currcrs);
1.260 raeburn 2436: foreach my $item (sort(keys(%newgroup))) {
2437: if (&is_active_course($item,$refresh,$update,\%roleshash)) {
1.279 raeburn 2438: if ($item =~ m{^gr\./($match_domain/$match_courseid)/(\w+)$}) {
2439: my ($cdom,$cnum) = split(/\//,$1);
2440: my $group = $2;
2441: if ($currcrs ne $cdom.'_'.$cnum) {
2442: if ($currcrs) {
2443: $groupmsg .= '</ul><li>';
2444: }
2445: $groupmsg .= '<li><b>'.
2446: $env{'course.'.$cdom.'_'.$cnum.'.description'}.'</b><ul>';
1.281 raeburn 2447: $currcrs = $cdom.'_'.$cnum;
1.279 raeburn 2448: }
2449: my $groupdesc;
2450: unless (ref($curr_groups{$cdom.'_'.$cnum}) eq 'HASH') {
2451: %{$curr_groups{$cdom.'_'.$cnum}} =
2452: &Apache::longroup::coursegroups($cdom,$cnum);
2453: }
2454: unless ((ref($groupdescs{$cdom.'_'.$cnum}) eq 'HASH') &&
2455: ($groupdescs{$cdom.'_'.$cnum}{$group})) {
2456:
2457: my %groupinfo =
2458: &Apache::longroup::get_group_settings($curr_groups{$cdom.'_'.$cnum}{$group});
2459: $groupdescs{$cdom.'_'.$cnum}{$group} =
2460: &unescape($groupinfo{'description'});
2461: }
2462: $groupdesc = $groupdescs{$cdom.'_'.$cnum}{$group};
1.286 raeburn 2463: if ($groupdesc) {
2464: $groupmsg .= '<li>'.
2465: &mt('[_1] with status: [_2].',
2466: '<b>'.$groupdesc.'</b>',$newgroup{$item}).'</li>';
2467: }
1.279 raeburn 2468: }
2469: }
2470: if ($groupmsg) {
2471: $groupmsg .= '</ul></li>';
1.260 raeburn 2472: }
2473: }
2474: if ($groupmsg) {
2475: $changemsg .= '<li>'.
2476: &mt('Courses with new groups').'</li>'.
2477: '<ul>'.$groupmsg.'</ul></li>';
2478: }
2479: }
2480: if (keys(%newrole) > 0) {
1.286 raeburn 2481: my $newmsg;
1.260 raeburn 2482: foreach my $item (sort(keys(%newrole))) {
1.279 raeburn 2483: my $desc = &role_desc($item,$update,$refresh,$now);
1.286 raeburn 2484: if ($desc) {
2485: $newmsg .= '<li>'.
2486: &mt('[_1] with status: [_2].',
1.293 bisitz 2487: $desc,&mt($newrole{$item})).'</li>';
1.286 raeburn 2488: }
2489: }
2490: if ($newmsg) {
2491: $changemsg .= '<li>'.&mt('New roles').
2492: '<ul>'.$newmsg.'</ul>'.
2493: '</li>';
1.260 raeburn 2494: }
2495: }
2496: if (keys(%customprivchg) > 0) {
1.286 raeburn 2497: my $privmsg;
1.260 raeburn 2498: foreach my $item (sort(keys(%customprivchg))) {
1.279 raeburn 2499: my $desc = &role_desc($item,$update,$refresh,$now);
1.286 raeburn 2500: if ($desc) {
2501: $privmsg .= '<li>'.$desc.'</li>';
2502: }
1.260 raeburn 2503: }
1.286 raeburn 2504: if ($privmsg) {
2505: $changemsg .= '<li>'.
2506: &mt('Custom roles with privilege changes').
2507: '<ul>'.$privmsg.'</ul>'.
2508: '</li>';
2509: }
1.260 raeburn 2510: }
2511: if (keys(%rolechange) > 0) {
1.286 raeburn 2512: my $rolemsg;
1.260 raeburn 2513: foreach my $item (sort(keys(%rolechange))) {
1.279 raeburn 2514: my $desc = &role_desc($item,$update,$refresh,$now);
1.286 raeburn 2515: if ($desc) {
2516: $rolemsg .= '<li>'.
2517: &mt('[_1] status now: [_2].',$desc,
2518: $rolechange{$item}).'</li>';
2519: }
2520: }
2521: if ($rolemsg) {
1.260 raeburn 2522: $changemsg .= '<li>'.
1.286 raeburn 2523: &mt('Existing roles with status changes').'</li>'.
2524: '<ul>'.$rolemsg.'</ul>'.
2525: '</li>';
1.260 raeburn 2526: }
2527: }
2528: if (keys(%deletedroles) > 0) {
1.286 raeburn 2529: my $delmsg;
1.260 raeburn 2530: foreach my $item (sort(keys(%deletedroles))) {
1.279 raeburn 2531: my $desc = &role_desc($item,$update,$refresh,$now);
1.286 raeburn 2532: if ($desc) {
2533: $delmsg .= '<li>'.$desc.'</li>';
2534: }
2535: }
2536: if ($delmsg) {
2537: $changemsg .= '<li>'.
2538: &mt('Existing roles now expired').'</li>'.
2539: '<ul>'.$delmsg.'</ul>'.
2540: '</li>';
1.260 raeburn 2541: }
2542: }
2543: }
2544: if ((keys(%changed_groups) > 0) || (keys(%groupchange) > 0)) {
2545: my $groupchgmsg;
2546: foreach my $key (sort(keys(%changed_groups))) {
2547: my $crs = 'gr/'.$key;
2548: $crs =~ s/_/\//;
2549: if (&is_active_course($crs,$refresh,$update,\%roleshash)) {
2550: if (ref($changed_groups{$key}) eq 'HASH') {
2551: my @showgroups;
2552: foreach my $group (sort(keys(%{$changed_groups{$key}}))) {
2553: if ($changed_groups{$key}{$group} eq 'active') {
2554: push(@showgroups,$group);
2555: }
2556: }
2557: if (@showgroups > 0) {
2558: $groupchgmsg .= '<li>'.
2559: &mt('Course: [_1], groups: [_2].',$key,
2560: join(', ',@showgroups)).
2561: '</li>';
2562: }
2563: }
2564: }
2565: }
2566: if (keys(%groupchange) > 0) {
2567: $groupchgmsg .= '<li>'.
2568: &mt('Existing course/community groups with status changes').'</li>'.
2569: '<ul>';
2570: foreach my $crs (sort(keys(%groupchange))) {
1.279 raeburn 2571: my $cid = $crs;
2572: $cid=~s{^/}{};
2573: $cid=~s{/}{_};
2574: my $crsdesc = $env{'course.'.$cid.'.description'};
2575: my $cdom = $env{'course.'.$cid.'.domain'};
2576: my $cnum = $env{'course.'.$cid.'.num'};
2577: my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum);
2578: my %groupdesc;
1.260 raeburn 2579: if (ref($groupchange{$crs}) eq 'HASH') {
1.279 raeburn 2580: $groupchgmsg .= '<li>'.&mt('Course/Community: [_1]','<b>'.$crsdesc.'</b><ul>');
1.260 raeburn 2581: foreach my $group (sort(keys(%{$groupchange{$crs}}))) {
1.279 raeburn 2582: unless ($groupdesc{$group}) {
2583: my %groupinfo = &Apache::longroup::get_group_settings($curr_groups{$group});
2584: $groupdesc{$group} = &unescape($groupinfo{'description'});
2585: }
2586: $groupchgmsg .= '<li>'.&mt('Group: [_1] status now: [_2].','<b>'.$groupdesc{$group}.'</b>',$groupchange{$crs}{$group}).'</li>';
1.260 raeburn 2587: }
2588: $groupchgmsg .= '</ul></li>';
2589: }
2590: }
2591: $groupchgmsg .= '</ul></li>';
2592: }
2593: if ($groupchgmsg) {
2594: $changemsg .= '<li>'.
2595: &mt('Courses with changes in groups').'</li>'.
2596: '<ul>'.$groupchgmsg.'</ul></li>';
2597: }
2598: }
2599: if ($changemsg) {
2600: $msg .= '<ul>'.$changemsg.'</ul>';
1.286 raeburn 2601: } else {
2602: if (&Apache::loncommon::show_course()) {
2603: $msg = &mt('No new courses or communities');
2604: } else {
2605: $msg = &mt('No role changes');
2606: }
1.260 raeburn 2607: }
1.279 raeburn 2608: return $msg;
2609: }
2610:
2611: sub role_desc {
2612: my ($item,$update,$refresh,$now) = @_;
2613: my ($where,$trolecode,$role,$tstatus,$tend,$tstart,$twhere,
2614: $trole,$tremark);
1.282 raeburn 2615: &Apache::lonnet::role_status('user.role.'.$item,$update,$refresh,
2616: $now,\$role,\$where,\$trolecode,
1.279 raeburn 2617: \$tstatus,\$tstart,\$tend);
1.286 raeburn 2618: return unless ($role);
1.279 raeburn 2619: if ($role =~ /^cr\//) {
2620: my ($rdummy,$rdomain,$rauthor,$rrole)=split(/\//,$role);
1.298 bisitz 2621: $tremark = &mt('Custom role defined by [_1].',$rauthor.':'.$rdomain);
1.279 raeburn 2622: }
2623: $trole=Apache::lonnet::plaintext($role);
2624: my ($tdom,$trest,$tsection)=
2625: split(/\//,Apache::lonnet::declutter($where));
2626: if (($role eq 'ca') || ($role eq 'aa')) {
2627: my $home = &Apache::lonnet::homeserver($trest,$tdom);
2628: $home = &Apache::lonnet::hostname($home);
2629: $twhere=&mt('User').': '.$trest.' '.&mt('Domain').
2630: ': '.$tdom.' '.&mt('Server').': '.$home;
2631: } elsif ($role eq 'au') {
2632: my $home = &Apache::lonnet::homeserver
2633: ($env{'user.name'},$env{'user.domain'});
2634: $home = &Apache::lonnet::hostname($home);
2635: $twhere=&mt('Domain').': '.$tdom.' '.&mt('Server').
2636: ': '.$home;
2637: } elsif ($trest) {
2638: my $tcourseid=$tdom.'_'.$trest;
2639: my $crstype = &Apache::loncommon::course_type($tcourseid);
2640: $trole = &Apache::lonnet::plaintext($role,$crstype,$tcourseid);
2641: if ($env{'course.'.$tcourseid.'.description'}) {
2642: $twhere=$env{'course.'.$tcourseid.'.description'};
2643: } else {
2644: my %newhash=&Apache::lonnet::coursedescription($tcourseid);
2645: if (%newhash) {
2646: $twhere=$newhash{'description'};
2647: } else {
2648: $twhere=&mt('Currently not available');
1.260 raeburn 2649: }
2650: }
1.279 raeburn 2651: if ($tsection) {
2652: $twhere.= ' '.&mt('Section').': '.$tsection;
1.260 raeburn 2653: }
1.279 raeburn 2654: if ($role ne 'st') {
2655: $twhere.= ' '.&mt('Domain').': '.$tdom;
1.260 raeburn 2656: }
1.279 raeburn 2657: } elsif ($tdom) {
2658: $twhere = &mt('Domain').': '.$tdom;
1.260 raeburn 2659: }
1.286 raeburn 2660: my $output;
2661: if ($trole) {
2662: $output = $trole;
2663: if ($twhere) {
2664: $output .= " -- $twhere";
2665: }
2666: if ($tremark) {
2667: $output .= '<br />'.$tremark;
2668: }
1.260 raeburn 2669: }
1.279 raeburn 2670: return $output;
1.260 raeburn 2671: }
2672:
2673: sub curr_role_status {
2674: my ($start,$end,$refresh,$update) = @_;
2675: if (($start) && ($start<0)) { return 'deleted' };
2676: my $status = 'active';
2677: if (($end) && ($end<=$update)) {
2678: $status = 'previous';
2679: }
2680: if (($start) && ($refresh<$start)) {
2681: $status = 'future';
2682: }
2683: return $status;
2684: }
2685:
2686: sub gather_roleprivs {
2687: my ($allroles,$allgroups,$userroles,$area,$role,$tstart,$tend,$status) = @_;
2688: return unless ((ref($allroles) eq 'HASH') && (ref($allgroups) eq 'HASH') && (ref($userroles) eq 'HASH'));
2689: if (($area ne '') && ($role ne '')) {
2690: &Apache::lonnet::userrolelog($role,$env{'user.name'},$env{'user.domain'},
2691: $area,$tstart,$tend);
2692: my $spec=$role.'.'.$area;
2693: $userroles->{'user.role.'.$spec} = $tstart.'.'.$tend;
2694: my ($tdummy,$tdomain,$trest)=split(/\//,$area);
2695: if ($status eq 'active') {
2696: if ($role =~ /^cr\//) {
2697: &Apache::lonnet::custom_roleprivs($allroles,$role,$tdomain,$trest,$spec,$area);
2698: } elsif ($role eq 'gr') {
2699: my %rolehash = &Apache::lonnet::get('roles',[$area.'_'.$role],
2700: $env{'user.domain'},
2701: $env{'user.name'});
2702: my ($trole) = split(/_/,$rolehash{$area.'_'.$role},2);
2703: (undef,my $group_privs) = split(/\//,$trole);
2704: $group_privs = &unescape($group_privs);
2705: &Apache::lonnet::group_roleprivs($allgroups,$area,$group_privs,$tend,$tstart);
2706: } else {
2707: &Apache::lonnet::standard_roleprivs($allroles,$role,$tdomain,$spec,$trest,$area);
2708: }
2709: }
2710: }
2711: return;
2712: }
2713:
2714: sub is_active_course {
2715: my ($rolekey,$refresh,$update,$roleshashref) = @_;
2716: return unless(ref($roleshashref) eq 'HASH');
2717: my ($role,$cdom,$cnum) = split(/\//,$rolekey);
2718: my $is_active;
2719: foreach my $key (keys(%{$roleshashref})) {
2720: if ($key =~ /^\Q$cnum\E:\Q$cdom\E:/) {
2721: my ($tstart,$tend) = split(/:/,$roleshashref->{$key});
2722: my $status = &curr_role_status($tstart,$tend,$refresh,$update);
2723: if ($status eq 'active') {
2724: $is_active = 1;
2725: last;
2726: }
2727: }
2728: }
2729: return $is_active;
2730: }
2731:
1.274 raeburn 2732: sub get_roles_functions {
1.302 raeburn 2733: my ($rolescount,$cattype) = @_;
1.274 raeburn 2734: my @links;
2735: push(@links,["javascript:rolesView('doupdate');",'start-here-22x22',&mt('Check for changes')]);
2736: if ($env{'environment.canrequest.author'}) {
2737: unless (&Apache::loncoursequeueadmin::is_active_author()) {
2738: push(@links,["javascript:rolesView('requestauthor');",'list-add-22x22',&mt('Request author role')]);
2739: }
2740: }
1.279 raeburn 2741: if (($rolescount > 3) || ($env{'environment.recentroles'})) {
2742: push(@links,['/adm/preferences?action=changerolespref&returnurl=/adm/roles','role_hotlist-22x22',&mt('Hotlist')]);
2743: }
1.274 raeburn 2744: if (&Apache::lonmenu::check_for_rcrs()) {
2745: push(@links,['/adm/requestcourse','rcrs-22x22',&mt('Request course')]);
2746: }
2747: if ($env{'form.state'} eq 'queued') {
2748: push(@links,["javascript:rolesView('noqueued');",'selfenrl-queue-22x22',&mt('Hide queued')]);
2749: } else {
2750: push(@links,["javascript:rolesView('queued');",'selfenrl-queue-22x22',&mt('Show queued')]);
2751: }
1.279 raeburn 2752: if ($env{'user.adv'}) {
2753: if ($env{'form.display'} eq 'showall') {
1.290 raeburn 2754: push(@links,["javascript:rolesView('noshowall');",'edit-redo-22x22',&mt('Exclude expired')]);
1.279 raeburn 2755: } else {
1.290 raeburn 2756: push(@links,["javascript:rolesView('showall');",'edit-undo-22x22',&mt('Include expired')]);
1.279 raeburn 2757: }
1.274 raeburn 2758: }
1.302 raeburn 2759: unless ($cattype eq 'none') {
1.291 raeburn 2760: push(@links,['/adm/coursecatalog','ccat-22x22',&mt('Course catalog')]);
1.290 raeburn 2761: }
1.274 raeburn 2762: my $funcs = &Apache::lonhtmlcommon::start_funclist();
2763: foreach my $link (@links) {
2764: $funcs .= &Apache::lonhtmlcommon::add_item_funclist(
2765: '<a href="'.$link->[0].'" class="LC_menubuttons_link">'.
2766: '<img src="/res/adm/pages/'.$link->[1].'.png" class="LC_icon" alt="'.$link->[2].'" />'.
2767: $link->[2].'</a>');
2768: }
2769: $funcs .= &Apache::lonhtmlcommon::end_funclist();
2770: return &Apache::loncommon::head_subbox($funcs);
2771: }
2772:
2773: sub get_queued {
2774: my ($output,%reqcrs);
2775: my ($types,$typenames) = &Apache::loncommon::course_types();
2776: my %statusinfo = &Apache::lonnet::dump('courserequests',$env{'user.domain'},
2777: $env{'user.name'},'^status:');
2778: foreach my $key (keys(%statusinfo)) {
2779: next unless (($statusinfo{$key} eq 'approval') || ($statusinfo{$key} eq 'pending'));
1.297 raeburn 2780: (undef,my($cdom,$cnum)) = split(/:/,$key);
1.274 raeburn 2781: my $requestkey = $cdom.'_'.$cnum;
2782: if ($requestkey =~ /^($match_domain)_($match_courseid)$/) {
2783: my %history = &Apache::lonnet::restore($requestkey,'courserequests',
2784: $env{'user.domain'},$env{'user.name'});
2785: next if ((exists($history{'status'})) && ($history{'status'} eq 'created'));
2786: my $reqtime = $history{'reqtime'};
2787: my $lastupdate = $history{'timestamp'};
2788: my $showtype = $history{'crstype'};
2789: if (defined($typenames->{$history{'crstype'}})) {
2790: $showtype = $typenames->{$history{'crstype'}};
2791: }
2792: my $description;
2793: if (ref($history{'details'}) eq 'HASH') {
2794: $description = $history{details}{'cdescr'};
2795: }
2796: @{$reqcrs{$reqtime}} = ($description,$showtype);
2797: }
2798: }
2799: my @sortedtimes = sort {$a <=> $b} (keys(%reqcrs));
2800: if (@sortedtimes > 0) {
2801: $output .= '<p><b>'.&mt('Course/Community requests').'</b><br />'.
2802: &Apache::loncommon::start_data_table().
2803: &Apache::loncommon::start_data_table_header_row().
2804: '<th>'.&mt('Date requested').'</th>'.
2805: '<th>'.&mt('Course title').'</th>'.
2806: '<th>'.&mt('Course type').'</th>';
2807: &Apache::loncommon::end_data_table_header_row();
2808: foreach my $reqtime (@sortedtimes) {
2809: next unless (ref($reqcrs{$reqtime}) eq 'ARRAY');
2810: $output .= &Apache::loncommon::start_data_table_row().
2811: '<td>'.&Apache::lonlocal::locallocaltime($reqtime).'</td>'.
2812: '<td>'.join('</td><td>',@{$reqcrs{$reqtime}}).'</td>'.
2813: &Apache::loncommon::end_data_table_row();
2814: }
2815: $output .= &Apache::loncommon::end_data_table().
2816: '<br /></p>';
2817: }
2818: my $queuedselfenroll = &Apache::loncoursequeueadmin::queued_selfenrollment(1);
2819: if ($queuedselfenroll) {
2820: $output .= '<p><b>'.&mt('Enrollment requests').'</b><br />'.
2821: $queuedselfenroll.'<br /></p>';
2822: }
2823: if ($env{'environment.canrequest.author'}) {
2824: unless (&Apache::loncoursequeueadmin::is_active_author()) {
2825: my $requestauthor;
2826: my ($status,$timestamp) = split(/:/,$env{'environment.requestauthorqueued'});
2827: if (($status eq 'approval') || ($status eq 'approved')) {
2828: $output .= '<p><b>'.&mt('Author role request').'</b><br />';
2829: if ($status eq 'approval') {
1.294 bisitz 2830: $output .= &mt('A request for Authoring Space submitted on [_1] is awaiting approval',
1.274 raeburn 2831: &Apache::lonlocal::locallocaltime($timestamp));
2832: } elsif ($status eq 'approved') {
2833: my %roleshash =
2834: &Apache::lonnet::get_my_roles($env{'user.name'},$env{'user.domain'},'userroles',
2835: ['active'],['au'],[$env{'user.domain'}]);
2836: if (keys(%roleshash)) {
2837: $output .= '<span class="LC_info">'.
2838: &mt('Your request for an author role has been approved.').'<br />'.
2839: &mt('Use the "Check for changes" link to update your list of roles.').
2840: '</span>';
2841: }
2842: }
2843: $output .= '</p>';
2844: }
2845: }
2846: }
2847: unless ($output) {
2848: if ($env{'environment.canrequest.author'} || $env{'environment.canrequest.official'} ||
2849: $env{'environment.canrequest.unofficial'} || $env{'environment.canrequest.community'}) {
2850: $output = &mt('No requests for courses, communities or authoring currently queued');
2851: } else {
2852: $output = &mt('No enrollment requests currently queued awaiting approval');
2853: }
2854: }
2855: return '<div class="LC_left_float"><fieldset><legend>'.&mt('Queued requests').'</legend>'.
2856: $output.'</fieldset></div><br clear="all" />';
2857: }
2858:
1.1 harris41 2859: 1;
2860: __END__
1.32 harris41 2861:
2862: =head1 NAME
2863:
2864: Apache::lonroles - User Roles Screen
2865:
2866: =head1 SYNOPSIS
2867:
2868: Invoked by /etc/httpd/conf/srm.conf:
2869:
2870: <Location /adm/roles>
2871: PerlAccessHandler Apache::lonacc
2872: SetHandler perl-script
2873: PerlHandler Apache::lonroles
2874: ErrorDocument 403 /adm/login
2875: ErrorDocument 500 /adm/errorhandler
2876: </Location>
1.64 bowersj2 2877:
2878: =head1 OVERVIEW
2879:
2880: =head2 Choosing Roles
2881:
2882: C<lonroles> is a handler that allows a user to switch roles in
2883: mid-session. LON-CAPA attempts to work with "No Role Specified", the
2884: default role that a user has before selecting a role, as widely as
2885: possible, but certain handlers for example need specification which
2886: course they should act on, etc. Both in this scenario, and when the
2887: handler determines via C<lonnet>'s C<&allowed> function that a certain
2888: action is not allowed, C<lonroles> is used as error handler. This
2889: allows the user to select another role which may have permission to do
1.246 droeschl 2890: what they were trying to do.
1.64 bowersj2 2891:
2892: =begin latex
2893:
2894: \begin{figure}
2895: \begin{center}
2896: \includegraphics[width=0.45\paperwidth,keepaspectratio]{Sample_Roles_Screen}
2897: \caption{\label{Sample_Roles_Screen}Sample Roles Screen}
2898: \end{center}
2899: \end{figure}
2900:
2901: =end latex
2902:
2903: =head2 Role Initialization
2904:
2905: 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 2906:
2907: =head1 INTRODUCTION
2908:
2909: This module enables a user to select what role he wishes to
2910: operate under (instructor, student, teaching assistant, course
2911: coordinator, etc). These roles are pre-established by the actions
2912: of upper-level users.
2913:
2914: This is part of the LearningOnline Network with CAPA project
2915: described at http://www.lon-capa.org.
2916:
2917: =head1 HANDLER SUBROUTINE
2918:
2919: This routine is called by Apache and mod_perl.
2920:
2921: =over 4
2922:
2923: =item *
2924:
2925: Roles Initialization (yes/no)
2926:
2927: =item *
2928:
2929: Get Error Message from Environment
2930:
2931: =item *
2932:
2933: Who is this?
2934:
2935: =item *
2936:
2937: Generate Page Output
2938:
2939: =item *
2940:
2941: Choice or no choice
2942:
2943: =item *
2944:
2945: Table
2946:
2947: =item *
2948:
2949: Privileges
2950:
2951: =back
2952:
2953: =cut
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>