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