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