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