Annotation of loncom/auth/lonroles.pm, revision 1.269.2.39.2.5
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.4 2022/05/29 12:46:35 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.10 raeburn 1117: &redirect_user($r,&mt('Entering Authoring Space'),
1.62 matthew 1118: $redirect_url);
1119: return OK;
1120: }
1.104 raeburn 1121: if ($role eq 'dc') {
1.108 raeburn 1122: my $redirect_url = '/adm/menu/';
1123: &redirect_user($r,&mt('Loading Domain Coordinator Menu'),
1.104 raeburn 1124: $redirect_url);
1.108 raeburn 1125: return OK;
1.104 raeburn 1126: }
1.269.2.27 raeburn 1127: if ($role eq 'dh') {
1128: my $redirect_url = '/adm/menu/';
1129: &redirect_user($r,&mt('Loading Domain Helpdesk Menu'),
1130: $redirect_url);
1131: return OK;
1132: }
1.269.2.31 raeburn 1133: if ($role eq 'da') {
1134: my $redirect_url = '/adm/menu/';
1135: &redirect_user($r,&mt('Loading Domain Helpdesk Assistant Menu'),
1136: $redirect_url);
1137: return OK;
1138: }
1.220 raeburn 1139: if ($role eq 'sc') {
1140: my $redirect_url = '/adm/grades?command=scantronupload';
1141: &redirect_user($r,&mt('Loading Data Upload Page'),
1142: $redirect_url);
1143: return OK;
1144: }
1.55 albertel 1145: }
1146: }
1.6 www 1147: }
1.40 matthew 1148: }
1.44 www 1149:
1.10 www 1150:
1.6 www 1151: # =============================================================== No Roles Init
1.10 www 1152:
1.73 www 1153: &Apache::loncommon::content_type($r,'text/html');
1.30 albertel 1154: &Apache::loncommon::no_cache($r);
1.10 www 1155: $r->send_http_header;
1156: return OK if $r->header_only;
1157:
1.224 raeburn 1158: my $crumbtext = 'User Roles';
1159: my $pagetitle = 'My Roles';
1160: my $recent = &mt('Recent Roles');
1.269.2.10 raeburn 1161: my $standby = &mt('Role selected. Please stand by.');
1.224 raeburn 1162: my $show_course=&Apache::loncommon::show_course();
1163: if ($show_course) {
1164: $crumbtext = 'Courses';
1165: $pagetitle = 'My Courses';
1166: $recent = &mt('Recent Courses');
1.269.2.10 raeburn 1167: $standby = &mt('Course selected. Please stand by.');
1.224 raeburn 1168: }
1.269.2.39.2. (raeburn 1169:): if (($norolelist) && ((split(/:/,$env{'user.error.msg'}))[2])) {
1170:): $crumbtext = 'Access Denied';
1171:): $pagetitle = 'Unauthorized';
1172:): }
1.224 raeburn 1173: my $brcrum =[{href=>"/adm/roles",text=>$crumbtext}];
1.269.2.2 raeburn 1174:
1175: my %roles_in_env;
1176: my $showcount = &roles_from_env(\%roles_in_env,$update);
1177:
1.52 www 1178: my $swinfo=&Apache::lonmenu::rawconfig();
1.269.2.18 raeburn 1179: my %domdefs=&Apache::lonnet::get_domain_defaults($env{'user.domain'});
1180: my $cattype = 'std';
1181: if ($domdefs{'catauth'}) {
1182: $cattype = $domdefs{'catauth'};
1183: }
1.269.2.39 raeburn 1184: my ($funcs,$crumbsright);
1.269.2.39.2. (raeburn 1185:): unless (($norolelist) && ((split(/:/,$env{'user.error.msg'}))[2])) {
1186:): $funcs = &get_roles_functions($showcount,$cattype);
1187:): if ($env{'browser.mobile'}) {
1188:): $crumbsright = $funcs;
1189:): undef($funcs);
1190:): }
1.269.2.26 raeburn 1191: }
1192: my $start_page=&Apache::loncommon::start_page($pagetitle,undef,{bread_crumbs=>$brcrum,
1193: bread_crumbs_component=>$crumbsright});
1.269.2.24 raeburn 1194: &js_escape(\$standby);
1.269.2.2 raeburn 1195: 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 1196:
1.10 www 1197: $r->print(<<ENDHEADER);
1.147 albertel 1198: $start_page
1.269.2.2 raeburn 1199: $funcs
1.179 raeburn 1200: <noscript>
1201: $noscript
1202: </noscript>
1203: <script type="text/javascript">
1.225 bisitz 1204: // <![CDATA[
1.26 www 1205: $swinfo
1206: window.focus();
1.134 www 1207:
1208: active=true;
1209:
1210: function enterrole (thisform,rolecode,buttonname) {
1211: if (active) {
1212: active=false;
1213: document.title='$standby';
1214: window.status='$standby';
1215: thisform.newrole.value=rolecode;
1216: thisform.submit();
1217: } else {
1218: alert('$standby');
1.260 raeburn 1219: }
1220: }
1221:
1.269.2.2 raeburn 1222: function rolesView (caller) {
1223: if ((caller == 'showall') || (caller == 'noshowall')) {
1224: document.rolechoice.display.value = caller;
1225: } else {
1226: if ((caller == 'doupdate') || (caller == 'requestauthor') ||
1227: (caller == 'queued')) {
1228: document.rolechoice.state.value = caller;
1229: }
1230: }
1231: document.rolechoice.selectrole.value='';
1232: document.rolechoice.submit();
1.134 www 1233: }
1.260 raeburn 1234:
1.225 bisitz 1235: // ]]>
1.26 www 1236: </script>
1.10 www 1237: ENDHEADER
1.6 www 1238:
1.2 www 1239: # ------------------------------------------ Get Error Message from Environment
1240:
1.118 albertel 1241: my ($fn,$priv,$nochoose,$error,$msg)=split(/:/,$env{'user.error.msg'});
1242: if ($env{'user.error.msg'}) {
1.55 albertel 1243: $r->log_reason(
1.118 albertel 1244: "$msg for $env{'user.name'} domain $env{'user.domain'} access $priv",$fn);
1.12 www 1245: }
1.1 harris41 1246:
1.61 www 1247: # ------------------------------------------------- Can this user re-init, etc?
1.6 www 1248:
1.118 albertel 1249: my $advanced=$env{'user.adv'};
1.61 www 1250: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['tryagain']);
1.118 albertel 1251: my $tryagain=$env{'form.tryagain'};
1.209 raeburn 1252: my $reinit=$env{'user.reinit'};
1253: delete $env{'user.reinit'};
1.6 www 1254:
1.2 www 1255: # -------------------------------------------------------- Generate Page Output
1.6 www 1256: # --------------------------------------------------------------- Error Header?
1.2 www 1257: if ($error) {
1.187 bisitz 1258: $r->print("<h1>".&mt('LON-CAPA Access Control')."</h1>");
1.174 albertel 1259: $r->print("<!-- LONCAPAACCESSCONTROLERRORSCREEN --><hr /><pre>");
1260: if ($priv ne '') {
1.187 bisitz 1261: $r->print(&mt('Access : ').&Apache::lonnet::plaintext($priv)."\n");
1.174 albertel 1262: }
1263: if ($fn ne '') {
1.187 bisitz 1264: $r->print(&mt('Resource: ').&Apache::lonenc::check_encrypt($fn)."\n");
1.174 albertel 1265: }
1266: if ($msg ne '') {
1.187 bisitz 1267: $r->print(&mt('Action : ').$msg."\n");
1.174 albertel 1268: }
1269: $r->print("</pre><hr />");
1.120 albertel 1270: my $url=$fn;
1271: my $last;
1272: if (tie(my %hash,'GDBM_File',$env{'request.course.fn'}.'_symb.db',
1273: &GDBM_READER(),0640)) {
1274: $last=$hash{'last_known'};
1275: untie(%hash);
1276: }
1.149 www 1277: if ($last) { $fn.='?symb='.&escape($last); }
1.120 albertel 1278:
1279: &Apache::londocs::changewarning($r,undef,'You have modified your course recently, [_1] may fix this access problem.',
1280: &Apache::lonenc::check_encrypt($fn));
1.2 www 1281: } else {
1.118 albertel 1282: if ($env{'user.error.msg'}) {
1.209 raeburn 1283: if ($reinit) {
1284: $r->print(
1285: '<h3><span class="LC_error">'.
1.234 raeburn 1286: &mt('As your session file for the course or community has expired, you will need to re-select it.').'</span></h3>');
1.209 raeburn 1287: } else {
1288: $r->print(
1.157 albertel 1289: '<h3><span class="LC_error">'.
1.235 bisitz 1290: &mt('You need to choose another user role or enter a specific course or community for this function.').
1291: '</span></h3>');
1.209 raeburn 1292: }
1293: }
1.2 www 1294: }
1295: if ($nochoose) {
1.177 www 1296: $r->print("<h2>".&mt('Sorry ...')."</h2>\n<span class='LC_error'>".
1.269.2.39.2. (raeburn 1297:): &mt('This action is currently not authorized.').'</span>');
1298:): if ($error && $norolelist) {
1299:): $r->print('<br /><br /><h4><span class="LC_error">'.
1300:): &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.').
1301:): '</span></h4>'.
1302:): '<h4><span class="LC_error">'.
1303:): &mt('You may need to login to LON-CAPA directly, or re-launch from a different external system.').
1304:): '</span></h4>');
1305:): }
1306:): $r->print(&Apache::loncommon::end_page());
1.150 www 1307: return OK;
1.6 www 1308: } else {
1.269.2.2 raeburn 1309: if ($updateresult || $reqauthor || $hotlist) {
1310: my $showresult = '<div>';
1311: if ($updateresult) {
1312: $showresult .= &Apache::lonhtmlcommon::confirm_success($updateresult);
1313: }
1314: if ($reqauthor) {
1315: $showresult .= &Apache::lonhtmlcommon::confirm_success($reqauthor);
1316: }
1317: if ($hotlist) {
1318: $showresult .= $hotlist;
1319: }
1320: $showresult .= '</div>';
1321: $r->print($showresult);
1322: } elsif ($env{'form.state'} eq 'queued') {
1323: $r->print(&get_queued());
1324: }
1.18 www 1325: if (($ENV{'REDIRECT_QUERY_STRING'}) && ($fn)) {
1326: $fn.='?'.$ENV{'REDIRECT_QUERY_STRING'};
1.6 www 1327: }
1.269.2.2 raeburn 1328: my $display = ($env{'form.display'} =~ /^(showall)$/);
1.84 www 1329: $r->print('<form method="post" name="rolechoice" action="'.(($fn)?$fn:$r->uri).'">');
1.116 albertel 1330: $r->print('<input type="hidden" name="orgurl" value="'.$fn.'" />');
1331: $r->print('<input type="hidden" name="selectrole" value="1" />');
1.134 www 1332: $r->print('<input type="hidden" name="newrole" value="" />');
1.269.2.2 raeburn 1333: $r->print('<input type="hidden" name="display" value="'.$display.'" />');
1334: $r->print('<input type="hidden" name="state" value="" />');
1.269.2.39 raeburn 1335: if ($blocked_by_ip) {
1336: my $blocked_role = 'student';
1337: if ($blocked_type eq 'Community') {
1338: $blocked_role = 'member';
1339: }
1340: $r->print('<h3><span class="LC_error">'.
1341: &mt('The [_1] you selected is not available for access with a [_2] role from your current IP address: [_3].',
1342: lc($blocked_type),$blocked_role,$clientip).
1343: '</span></h3>');
1344: }
1.6 www 1345: }
1.259 raeburn 1346: $r->rflush();
1.226 raeburn 1347:
1348: my (%roletext,%sortrole,%roleclass,%futureroles,%timezones);
1349: my ($countactive,$countfuture,$inrole,$possiblerole) =
1.269.2.2 raeburn 1350: &gather_roles($update,$refresh,$now,$reinit,$nochoose,\%roles_in_env,\%roletext,
1351: \%sortrole,\%roleclass,\%futureroles,\%timezones,$loncaparev);
1.226 raeburn 1352: $refresh = $now;
1353: &Apache::lonnet::appenv({'user.refresh.time' => $refresh});
1.269.2.18 raeburn 1354: if ((($cattype eq 'std') || ($cattype eq 'domonly')) && (!$env{'user.adv'})) {
1.196 raeburn 1355: if ($countactive > 0) {
1356: my $domdesc = &Apache::lonnet::domain($env{'user.domain'},'description');
1.201 raeburn 1357: my $esc_dom = &HTML::Entities::encode($env{'user.domain'},'"<>&');
1.233 bisitz 1358: $r->print(
1359: '<p>'
1.269.2.16 raeburn 1360: .&mt('[_1]Visit the [_2]Course/Community Catalog[_3][_4]'
1361: .' to view all [_5] LON-CAPA courses and communities.'
1.233 bisitz 1362: ,'<b>'
1363: ,'<a href="/adm/coursecatalog?showdom='.$esc_dom.'">'
1.269.2.16 raeburn 1364: ,'</a>'
1365: ,'</b>'
1.269.2.18 raeburn 1366: ,'"'.$domdesc.'"')
1.233 bisitz 1367: .'<br />'
1.235 bisitz 1368: .&mt('If a course or community is [_1]not[_2] in your list of current courses and communities below,'
1.233 bisitz 1369: .' you may be able to enroll if self-enrollment is permitted.'
1370: ,'<b>','</b>')
1371: .'</p>'
1372: );
1.196 raeburn 1373: }
1374: }
1375:
1.269.2.39.2. (raeburn 1376:): if ($norolelist) {
1377:): if ($env{'request.role'}) {
1378:): my ($roletext,$role_text_end) = &display_curr_role($env{'request.role'});
1379:): if ($roletext) {
1380:): $r->print(&Apache::loncommon::start_data_table('LC_textsize_mobile').
1381:): &Apache::loncommon::start_data_table_row().
1382:): $roletext.
1383:): &Apache::loncommon::end_data_table_row());
1384:): if ($role_text_end) {
1385:): $r->print(&Apache::loncommon::continue_data_table_row().
1386:): $role_text_end.
1387:): &Apache::loncommon::end_data_table_row());
1388:): }
1389:): $r->print(&Apache::loncommon::end_data_table());
1390:): }
1391:): }
1392:): $r->print(&Apache::loncommon::end_page());
1393:): return OK;
1394:): }
1395:):
1.84 www 1396: # No active roles
1397: if ($countactive==0) {
1.269.2.37 raeburn 1398: my $elapsed = 0;
1399: if ($now && $update) {
1400: $elapsed = $now - $update;
1401: }
1402: &requestcourse_advice($r,$cattype,$inrole,$elapsed);
1.191 raeburn 1403: $r->print('</form>');
1404: if ($countfuture) {
1405: $r->print(&mt('The following [quant,_1,role,roles] will become active in the future:',$countfuture));
1406: my $doheaders = &roletable_headers($r,\%roleclass,\%sortrole,
1407: $nochoose);
1408: &print_rolerows($r,$doheaders,\%roleclass,\%sortrole,\%dcroles,
1.269.2.30 raeburn 1409: \%roletext,$update,$then);
1.191 raeburn 1410: my $tremark='';
1.212 bisitz 1411: my $tbg;
1.191 raeburn 1412: if ($env{'request.role'} eq 'cm') {
1.212 bisitz 1413: $tbg="LC_roles_selected";
1.204 bisitz 1414: $tremark=&mt('Currently selected.').' ';
1.191 raeburn 1415: } else {
1.212 bisitz 1416: $tbg="LC_roles_is";
1.191 raeburn 1417: }
1.212 bisitz 1418: $r->print(&Apache::loncommon::start_data_table_row()
1419: .'<td class="'.$tbg.'"> </td>'
1420: .'<td colspan="3">'
1421: .&mt('No role specified')
1422: .'</td>'
1423: .'<td>'.$tremark.' </td>'
1424: .&Apache::loncommon::end_data_table_row()
1425: );
1.191 raeburn 1426:
1.212 bisitz 1427: $r->print(&Apache::loncommon::end_data_table());
1.191 raeburn 1428: }
1429: $r->print(&Apache::loncommon::end_page());
1.84 www 1430: return OK;
1431: }
1432: # ----------------------------------------------------------------------- Table
1.247 raeburn 1433:
1.269.2.31 raeburn 1434: if (($numdc > 0) || (($numhelpdesk > 0) && ($numadhoc > 0))) {
1.269.2.33 raeburn 1435: $r->print(&coursepick_jscript().
1436: &Apache::loncommon::coursebrowser_javascript());
1437: }
1438: if ($numdc > 0) {
1439: $r->print(&Apache::loncommon::authorbrowser_javascript());
1.247 raeburn 1440: }
1441:
1.224 raeburn 1442: unless ((!&Apache::loncommon::show_course()) || ($nochoose) || ($countactive==1)) {
1.173 albertel 1443: $r->print("<h2>".&mt('Select a Course to Enter')."</h2>\n");
1.84 www 1444: }
1.229 raeburn 1445: if ($env{'form.destinationurl'}) {
1446: $r->print('<input type="hidden" name="destinationurl" value="'.
1447: $env{'form.destinationurl'}.'" />');
1448: if ($env{'form.destsymb'} ne '') {
1449: $r->print('<input type="hidden" name="destsymb" value="'.
1450: $env{'form.destsymb'}.'" />');
1451: }
1452: }
1.247 raeburn 1453:
1.191 raeburn 1454: my $doheaders = &roletable_headers($r,\%roleclass,\%sortrole,$nochoose);
1.118 albertel 1455: if ($env{'environment.recentroles'}) {
1.111 albertel 1456: my %recent_roles =
1.118 albertel 1457: &Apache::lonhtmlcommon::get_recent('roles',$env{'environment.recentrolesn'});
1.111 albertel 1458: my $output='';
1.247 raeburn 1459: foreach my $role (sort(keys(%recent_roles))) {
1460: if (ref($roletext{'user.role.'.$role}) eq 'ARRAY') {
1.223 raeburn 1461: $output.= &Apache::loncommon::start_data_table_row().
1.247 raeburn 1462: $roletext{'user.role.'.$role}->[0].
1.223 raeburn 1463: &Apache::loncommon::end_data_table_row();
1.249 raeburn 1464: if ($roletext{'user.role.'.$role}->[1] ne '') {
1465: $output .= &Apache::loncommon::continue_data_table_row().
1466: $roletext{'user.role.'.$role}->[1].
1467: &Apache::loncommon::end_data_table_row();
1468: }
1.269.2.27 raeburn 1469: if ($role =~ m{^dc\./($match_domain)/$}
1.170 albertel 1470: && $dcroles{$1}) {
1.192 raeburn 1471: $output .= &adhoc_roles_row($1,'recent');
1.269.2.31 raeburn 1472: } elsif ($role =~ m{^(dh|da)\./($match_domain)/$}) {
1.269.2.30 raeburn 1473: $output .= &adhoc_customroles_row($1,$2,'recent',$update,$then);
1.133 albertel 1474: }
1.113 raeburn 1475: } elsif ($numdc > 0) {
1.247 raeburn 1476: unless ($role =~/^error\:/) {
1.249 raeburn 1477: my ($roletext,$role_text_end) = &display_cc_role('user.role.'.$role);
1.259 raeburn 1478: if ($roletext) {
1479: $output.= &Apache::loncommon::start_data_table_row().
1480: $roletext.
1481: &Apache::loncommon::end_data_table_row();
1482: if ($role_text_end) {
1483: $output .= &Apache::loncommon::continue_data_table_row().
1484: $role_text_end.
1485: &Apache::loncommon::end_data_table_row();
1486: }
1487: }
1.113 raeburn 1488: }
1.247 raeburn 1489: }
1.111 albertel 1490: }
1491: if ($output) {
1.212 bisitz 1492: $r->print(&Apache::loncommon::start_data_table_empty_row()
1493: .'<td align="center" colspan="5">'
1.224 raeburn 1494: .$recent
1.212 bisitz 1495: .'</td>'
1496: .&Apache::loncommon::end_data_table_empty_row()
1497: );
1.111 albertel 1498: $r->print($output);
1.114 raeburn 1499: $doheaders ++;
1.111 albertel 1500: }
1501: }
1.269.2.30 raeburn 1502: &print_rolerows($r,$doheaders,\%roleclass,\%sortrole,\%dcroles,\%roletext,$update,$then);
1.202 raeburn 1503: if ($countactive > 1) {
1504: my $tremark='';
1.212 bisitz 1505: my $tbg;
1.202 raeburn 1506: if ($env{'request.role'} eq 'cm') {
1.212 bisitz 1507: $tbg="LC_roles_selected";
1.204 bisitz 1508: $tremark=&mt('Currently selected.').' ';
1.202 raeburn 1509: } else {
1.212 bisitz 1510: $tbg="LC_roles_is";
1.202 raeburn 1511: }
1.212 bisitz 1512: $r->print(&Apache::loncommon::start_data_table_row());
1.202 raeburn 1513: unless ($nochoose) {
1514: if ($env{'request.role'} ne 'cm') {
1.212 bisitz 1515: $r->print('<td class="'.$tbg.'"><input type="submit" value="'.
1.202 raeburn 1516: &mt('Select').'" name="cm" /></td>');
1517: } else {
1.212 bisitz 1518: $r->print('<td class="'.$tbg.'"> </td>');
1.202 raeburn 1519: }
1520: }
1.212 bisitz 1521: $r->print('<td colspan="3">'
1522: .&mt('No role specified')
1523: .'</td>'
1524: .'<td>'.$tremark.' </td>'
1525: .&Apache::loncommon::end_data_table_row()
1526: );
1.202 raeburn 1527: }
1.212 bisitz 1528: $r->print(&Apache::loncommon::end_data_table());
1.4 www 1529: unless ($nochoose) {
1530: $r->print("</form>\n");
1531: }
1.22 harris41 1532: # ------------------------------------------------------------ Privileges Info
1.118 albertel 1533: if (($advanced) && (($env{'user.error.msg'}) || ($error))) {
1.212 bisitz 1534: $r->print('<hr /><h2>'.&mt('Current Privileges').'</h2>');
1.175 albertel 1535: $r->print(&privileges_info());
1.4 www 1536: }
1.267 bisitz 1537: my $announcements = &Apache::lonnet::getannounce();
1538: $r->print(
1539: '<br />'.
1540: '<h2>'.&mt('Announcements').'</h2>'.
1541: $announcements
1542: ) unless (!$announcements);
1.65 www 1543: if ($advanced) {
1.201 raeburn 1544: my $esc_dom = &HTML::Entities::encode($env{'user.domain'},'"<>&');
1.231 bisitz 1545: $r->print('<p><small><i>'
1546: .&mt('This LON-CAPA server is version [_1]',$r->dir_config('lonVersion'))
1.269.2.21 raeburn 1547: .'</i></small></p>');
1.65 www 1548: }
1.147 albertel 1549: $r->print(&Apache::loncommon::end_page());
1.1 harris41 1550: return OK;
1.102 raeburn 1551: }
1552:
1.269.2.2 raeburn 1553: sub roles_from_env {
1554: my ($roleshash,$update) = @_;
1555: my $count = 0;
1556: if (ref($roleshash) eq 'HASH') {
1557: foreach my $envkey (keys(%env)) {
1558: if ($envkey =~ m{^user\.role\.(\w+)[./]}) {
1559: next if ($1 eq 'gr');
1560: $roleshash->{$envkey} = $env{$envkey};
1561: my ($start,$end) = split(/\./,$env{$envkey});
1562: unless ($end && $end<$update) {
1563: $count ++;
1564: }
1565: }
1566: }
1567: }
1568: return $count;
1569: }
1570:
1.226 raeburn 1571: sub gather_roles {
1.269.2.2 raeburn 1572: my ($update,$refresh,$now,$reinit,$nochoose,$roles_in_env,$roletext,$sortrole,$roleclass,$futureroles,
1573: $timezones,$loncaparev) = @_;
1.226 raeburn 1574: my ($countactive,$countfuture,$inrole,$possiblerole) = (0,0,0,'');
1575: my $advanced = $env{'user.adv'};
1576: my $tryagain = $env{'form.tryagain'};
1.254 raeburn 1577: my @ids = &Apache::lonnet::current_machine_ids();
1.269.2.2 raeburn 1578: if (ref($roles_in_env) eq 'HASH') {
1.269.2.30 raeburn 1579: my %adhocdesc;
1.269.2.2 raeburn 1580: foreach my $envkey (sort(keys(%{$roles_in_env}))) {
1581: my $button = 1;
1582: my $switchserver='';
1583: my $switchwarning;
1584: my ($role_text,$role_text_end,$sortkey,$role,$where,$trolecode,$tstart,
1585: $tend,$tremark,$tstatus,$tpstart,$tpend);
1.260 raeburn 1586: &Apache::lonnet::role_status($envkey,$update,$refresh,$now,\$role,\$where,
1.226 raeburn 1587: \$trolecode,\$tstatus,\$tstart,\$tend);
1588: next if (!defined($role) || $role eq '' || $role =~ /^gr/);
1589: $tremark='';
1590: $tpstart=' ';
1591: $tpend=' ';
1592: if ($env{'request.role'} eq $trolecode) {
1593: $tstatus='selected';
1594: }
1595: my $tbg;
1596: if (($tstatus eq 'is')
1597: || ($tstatus eq 'selected')
1598: || ($tstatus eq 'future')
1.269.2.2 raeburn 1599: || ($env{'form.display'} eq 'showall')) {
1.259 raeburn 1600: my $timezone = &role_timezone($where,$timezones);
1601: if ($tstart) {
1602: $tpstart=&Apache::lonlocal::locallocaltime($tstart,$timezone);
1603: }
1604: if ($tend) {
1605: $tpend=&Apache::lonlocal::locallocaltime($tend,$timezone);
1606: }
1.226 raeburn 1607: if ($tstatus eq 'is') {
1608: $tbg='LC_roles_is';
1609: $possiblerole=$trolecode;
1610: $countactive++;
1611: } elsif ($tstatus eq 'future') {
1612: $tbg='LC_roles_future';
1613: $button=0;
1614: $futureroles->{$trolecode} = $tstart.':'.$tend;
1615: $countfuture ++;
1616: } elsif ($tstatus eq 'expired') {
1617: $tbg='LC_roles_expired';
1618: $button=0;
1619: } elsif ($tstatus eq 'will_not') {
1620: $tbg='LC_roles_will_not';
1621: $tremark.=&mt('Expired after logout.').' ';
1622: } elsif ($tstatus eq 'selected') {
1623: $tbg='LC_roles_selected';
1624: $inrole=1;
1625: $countactive++;
1626: $tremark.=&mt('Currently selected.').' ';
1627: }
1628: my $trole;
1629: if ($role =~ /^cr\//) {
1630: my ($rdummy,$rdomain,$rauthor,$rrole)=split(/\//,$role);
1.269.2.29 raeburn 1631: unless ($rauthor eq $rdomain.'-domainconfig') {
1632: if ($tremark) { $tremark.='<br />'; }
1633: $tremark.=&mt('Custom role defined by [_1].',$rauthor.':'.$rdomain);
1634: }
1.226 raeburn 1635: }
1636: $trole=Apache::lonnet::plaintext($role);
1637: my $ttype;
1638: my $twhere;
1.269.2.39 raeburn 1639: my $skipcal;
1.226 raeburn 1640: my ($tdom,$trest,$tsection)=
1641: split(/\//,Apache::lonnet::declutter($where));
1642: # First, Co-Authorship roles
1643: if (($role eq 'ca') || ($role eq 'aa')) {
1644: my $home = &Apache::lonnet::homeserver($trest,$tdom);
1645: my $allowed=0;
1646: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
1647: if (!$allowed) {
1648: $button=0;
1.248 raeburn 1649: $switchserver='otherserver='.$home.'&role='.$trolecode;
1.226 raeburn 1650: }
1651: #next if ($home eq 'no_host');
1652: $home = &Apache::lonnet::hostname($home);
1.269.2.10 raeburn 1653: $ttype='Authoring Space';
1.226 raeburn 1654: $twhere=&mt('User').': '.$trest.'<br />'.&mt('Domain').
1655: ': '.$tdom.'<br />'.
1656: ' '.&mt('Server').': '.$home;
1657: $env{'course.'.$tdom.'_'.$trest.'.description'}='ca';
1658: $tremark.=&Apache::lonhtmlcommon::authorbombs('/res/'.$tdom.'/'.$trest.'/');
1659: $sortkey=$role."$trest:$tdom";
1660: } elsif ($role eq 'au') {
1661: # Authors
1662: my $home = &Apache::lonnet::homeserver
1663: ($env{'user.name'},$env{'user.domain'});
1664: my $allowed=0;
1665: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
1666: if (!$allowed) {
1667: $button=0;
1.248 raeburn 1668: $switchserver='otherserver='.$home.'&role='.$trolecode;
1.226 raeburn 1669: }
1670: #next if ($home eq 'no_host');
1671: $home = &Apache::lonnet::hostname($home);
1.269.2.10 raeburn 1672: $ttype='Authoring Space';
1.226 raeburn 1673: $twhere=&mt('Domain').': '.$tdom.'<br />'.&mt('Server').
1674: ': '.$home;
1675: $env{'course.'.$tdom.'_'.$trest.'.description'}='ca';
1676: $tremark.=&Apache::lonhtmlcommon::authorbombs('/res/'.$tdom.'/'.$env{'user.name'}.'/');
1677: $sortkey=$role;
1678: } elsif ($trest) {
1679: my $tcourseid=$tdom.'_'.$trest;
1680: $ttype = &Apache::loncommon::course_type($tcourseid);
1.269.2.29 raeburn 1681: if ($role !~ /^cr/) {
1682: $trole = &Apache::lonnet::plaintext($role,$ttype,$tcourseid);
1.269.2.30 raeburn 1683: } elsif ($role =~ m{^\Qcr/$tdom/$tdom\E\-domainconfig/(\w+)$}) {
1684: my $rolename = $1;
1685: my $desc;
1686: if (ref($adhocdesc{$tdom}) eq 'HASH') {
1687: $desc = $adhocdesc{$tdom}{$rolename};
1688: } else {
1689: my %domdef = &Apache::lonnet::get_domain_defaults($tdom);
1690: if (ref($domdef{'adhocroles'}) eq 'HASH') {
1691: foreach my $rolename (sort(keys(%{$domdef{'adhocroles'}}))) {
1692: if (ref($domdef{'adhocroles'}{$rolename}) eq 'HASH') {
1693: $adhocdesc{$tdom}{$rolename} = $domdef{'adhocroles'}{$rolename}{'desc'};
1694: $desc = $adhocdesc{$tdom}{$rolename};
1695: }
1696: }
1697: }
1698: }
1699: if ($desc ne '') {
1700: $trole = $desc;
1701: } else {
1702: $trole = &mt('Helpdesk[_1]',' '.$rolename);
1703: }
1.269.2.29 raeburn 1704: } else {
1705: $trole = (split(/\//,$role,4))[-1];
1706: }
1.226 raeburn 1707: if ($env{'course.'.$tcourseid.'.description'}) {
1.254 raeburn 1708: my $home=$env{'course.'.$tcourseid.'.home'};
1.226 raeburn 1709: $twhere=$env{'course.'.$tcourseid.'.description'};
1710: $sortkey=$role."\0".$tdom."\0".$twhere."\0".$envkey;
1.248 raeburn 1711: $twhere = &HTML::Entities::encode($twhere,'"<>&');
1.226 raeburn 1712: unless ($twhere eq &mt('Currently not available')) {
1713: $twhere.=' <span class="LC_fontsize_small">'.
1714: &Apache::loncommon::syllabuswrapper(&mt('Syllabus'),$trest,$tdom).
1715: '</span>';
1.254 raeburn 1716: unless ($home && grep(/^\Q$home\E$/,@ids) && $loncaparev eq '') {
1.255 raeburn 1717: my $required = $env{'course.'.$tcourseid.'.internal.releaserequired'};
1.259 raeburn 1718: if ($required ne '') {
1719: ($switchserver,$switchwarning) =
1.269.2.22 raeburn 1720: &Apache::loncommon::check_release_required($loncaparev,$tcourseid,$trolecode,$required);
1.259 raeburn 1721: if ($switchserver || $switchwarning) {
1722: $button = 0;
1723: }
1.254 raeburn 1724: }
1725: }
1.226 raeburn 1726: }
1727: } else {
1728: my %newhash=&Apache::lonnet::coursedescription($tcourseid);
1729: if (%newhash) {
1730: $sortkey=$role."\0".$tdom."\0".$newhash{'description'}.
1731: "\0".$envkey;
1.248 raeburn 1732: $twhere=&HTML::Entities::encode($newhash{'description'},'"<>&').
1733: ' <span class="LC_fontsize_small">'.
1734: &Apache::loncommon::syllabuswrapper(&mt('Syllabus'),$trest,$tdom).
1735: '</span>';
1.226 raeburn 1736: $ttype = $newhash{'type'};
1.243 raeburn 1737: $trole = &Apache::lonnet::plaintext($role,$ttype,$tcourseid);
1.254 raeburn 1738: my $home = $newhash{'home'};
1739: unless ($home && grep(/^\Q$home\E$/,@ids) && $loncaparev eq '') {
1.255 raeburn 1740: my $required = $newhash{'internal.releaserequired'};
1.259 raeburn 1741: if ($required ne '') {
1742: ($switchserver,$switchwarning) =
1.269.2.22 raeburn 1743: &Apache::loncommon::check_release_required($loncaparev,$tcourseid,$trolecode,$required);
1.259 raeburn 1744: if ($switchserver || $switchwarning) {
1745: $button = 0;
1746: }
1.254 raeburn 1747: }
1748: }
1.226 raeburn 1749: } else {
1750: $twhere=&mt('Currently not available');
1751: $env{'course.'.$tcourseid.'.description'}=$twhere;
1752: $sortkey=$role."\0".$tdom."\0".$twhere."\0".$envkey;
1753: $ttype = 'Unavailable';
1.269.2.39 raeburn 1754: $skipcal = 1;
1.226 raeburn 1755: }
1756: }
1757: if ($tsection) {
1758: $twhere.='<br />'.&mt('Section').': '.$tsection;
1759: }
1760: if ($role ne 'st') { $twhere.="<br />".&mt('Domain').":".$tdom; }
1761: } elsif ($tdom) {
1762: $ttype='Domain';
1763: $twhere=$tdom;
1764: $sortkey=$role.$twhere;
1765: } else {
1766: $ttype='System';
1767: $twhere=&mt('system wide');
1768: $sortkey=$role.$twhere;
1769: }
1770: ($role_text,$role_text_end) =
1771: &build_roletext($trolecode,$tdom,$trest,$tstatus,$tryagain,
1772: $advanced,$tremark,$tbg,$trole,$twhere,$tpstart,
1.269.2.39 raeburn 1773: $tpend,$nochoose,$button,$switchserver,$reinit,
1774: $switchwarning,$skipcal);
1.226 raeburn 1775: $roletext->{$envkey}=[$role_text,$role_text_end];
1776: if (!$sortkey) {$sortkey=$twhere."\0".$envkey;}
1777: $sortrole->{$sortkey}=$envkey;
1778: $roleclass->{$envkey}=$ttype;
1779: }
1780: }
1781: }
1782: return ($countactive,$countfuture,$inrole,$possiblerole);
1783: }
1784:
1.215 raeburn 1785: sub role_timezone {
1786: my ($where,$timezones) = @_;
1787: my $timezone;
1788: if (ref($timezones) eq 'HASH') {
1789: if ($where =~ m{^/($match_domain)/($match_courseid)}) {
1790: my $cdom = $1;
1791: my $cnum = $2;
1792: if ($cdom && $cnum) {
1793: if (!exists($timezones->{$cdom.'_'.$cnum})) {
1.259 raeburn 1794: my $tz;
1795: if ($env{'course.'.$cdom.'_'.$cnum.'.description'}) {
1796: $tz = $env{'course.'.$cdom.'_'.$cnum.'.timezone'};
1797: } else {
1798: my %timehash =
1799: &Apache::lonnet::get('environment',['timezone'],$cdom,$cnum);
1800: $tz = $timehash{'timezone'};
1801: }
1802: if ($tz eq '') {
1.215 raeburn 1803: if (!exists($timezones->{$cdom})) {
1804: my %domdefaults =
1805: &Apache::lonnet::get_domain_defaults($cdom);
1806: if ($domdefaults{'timezone_def'} eq '') {
1807: $timezones->{$cdom} = 'local';
1808: } else {
1809: $timezones->{$cdom} = $domdefaults{'timezone_def'};
1810: }
1811: }
1812: $timezones->{$cdom.'_'.$cnum} = $timezones->{$cdom};
1813: } else {
1814: $timezones->{$cdom.'_'.$cnum} =
1.259 raeburn 1815: &Apache::lonlocal::gettimezone($tz);
1.215 raeburn 1816: }
1817: }
1818: $timezone = $timezones->{$cdom.'_'.$cnum};
1819: }
1820: } else {
1821: my ($tdom) = ($where =~ m{^/($match_domain)});
1822: if ($tdom) {
1823: if (!exists($timezones->{$tdom})) {
1824: my %domdefaults = &Apache::lonnet::get_domain_defaults($tdom);
1825: if ($domdefaults{'timezone_def'} eq '') {
1826: $timezones->{$tdom} = 'local';
1827: } else {
1828: $timezones->{$tdom} = $domdefaults{'timezone_def'};
1829: }
1830: }
1831: $timezone = $timezones->{$tdom};
1832: }
1833: }
1834: if ($timezone eq 'local') {
1835: $timezone = undef;
1836: }
1837: }
1838: return $timezone;
1839: }
1840:
1.191 raeburn 1841: sub roletable_headers {
1842: my ($r,$roleclass,$sortrole,$nochoose) = @_;
1843: my $doheaders;
1844: if ((ref($sortrole) eq 'HASH') && (ref($roleclass) eq 'HASH')) {
1.212 bisitz 1845: $r->print('<br />'
1.269.2.26 raeburn 1846: .&Apache::loncommon::start_data_table('LC_textsize_mobile')
1.212 bisitz 1847: .&Apache::loncommon::start_data_table_header_row()
1848: );
1.191 raeburn 1849: if (!$nochoose) { $r->print('<th> </th>'); }
1.212 bisitz 1850: $r->print('<th>'.&mt('User Role').'</th>'
1851: .'<th>'.&mt('Extent').'</th>'
1852: .'<th>'.&mt('Start').'</th>'
1853: .'<th>'.&mt('End').'</th>'
1854: .&Apache::loncommon::end_data_table_header_row()
1855: );
1.191 raeburn 1856: $doheaders=-1;
1857: my @roletypes = &roletypes();
1858: foreach my $type (@roletypes) {
1859: my $haverole=0;
1860: foreach my $which (sort {uc($a) cmp uc($b)} (keys(%{$sortrole}))) {
1861: if ($roleclass->{$sortrole->{$which}} =~ /^\Q$type\E/) {
1862: $haverole=1;
1863: }
1864: }
1865: if ($haverole) { $doheaders++; }
1866: }
1867: }
1868: return $doheaders;
1869: }
1870:
1871: sub roletypes {
1.269.2.10 raeburn 1872: my @types = ('Domain','Authoring Space','Course','Community','Unavailable','System');
1.191 raeburn 1873: return @types;
1874: }
1875:
1876: sub print_rolerows {
1.269.2.30 raeburn 1877: my ($r,$doheaders,$roleclass,$sortrole,$dcroles,$roletext,$update,$then) = @_;
1.191 raeburn 1878: if ((ref($roleclass) eq 'HASH') && (ref($sortrole) eq 'HASH')) {
1879: my @types = &roletypes();
1880: foreach my $type (@types) {
1881: my $output;
1882: foreach my $which (sort {uc($a) cmp uc($b)} (keys(%{$sortrole}))) {
1883: if ($roleclass->{$sortrole->{$which}} =~ /^\Q$type\E/) {
1884: if (ref($roletext) eq 'HASH') {
1.223 raeburn 1885: if (ref($roletext->{$sortrole->{$which}}) eq 'ARRAY') {
1886: $output.= &Apache::loncommon::start_data_table_row().
1887: $roletext->{$sortrole->{$which}}->[0].
1888: &Apache::loncommon::end_data_table_row();
1.251 raeburn 1889: if ($roletext->{$sortrole->{$which}}->[1] ne '') {
1890: $output .= &Apache::loncommon::continue_data_table_row().
1891: $roletext->{$sortrole->{$which}}->[1].
1892: &Apache::loncommon::end_data_table_row();
1893: }
1.223 raeburn 1894: }
1.269.2.27 raeburn 1895: if ($sortrole->{$which} =~ m{^user\.role\.dc\./($match_domain)/}) {
1.191 raeburn 1896: if (ref($dcroles) eq 'HASH') {
1897: if ($dcroles->{$1}) {
1.192 raeburn 1898: $output .= &adhoc_roles_row($1,'');
1.191 raeburn 1899: }
1900: }
1.269.2.31 raeburn 1901: } elsif ($sortrole->{$which} =~ m{^user\.role\.(dh|da)\./($match_domain)/}) {
1.269.2.30 raeburn 1902: $output .= &adhoc_customroles_row($1,$2,'',$update,$then);
1.191 raeburn 1903: }
1904: }
1905: }
1906: }
1907: if ($output) {
1908: if ($doheaders > 0) {
1.212 bisitz 1909: $r->print(&Apache::loncommon::start_data_table_empty_row()
1910: .'<td align="center" colspan="5">'
1911: .&mt($type)
1912: .'</td>'
1913: .&Apache::loncommon::end_data_table_empty_row()
1914: );
1.191 raeburn 1915: }
1916: $r->print($output);
1917: }
1918: }
1919: }
1920: }
1921:
1922: sub findcourse_advice {
1.269.2.37 raeburn 1923: my ($r,$cattype,$elapsed) = @_;
1.191 raeburn 1924: my $domdesc = &Apache::lonnet::domain($env{'user.domain'},'description');
1.201 raeburn 1925: my $esc_dom = &HTML::Entities::encode($env{'user.domain'},'"<>&');
1.200 raeburn 1926: if (&Apache::lonnet::auto_run(undef,$env{'user.domain'})) {
1.269.2.37 raeburn 1927: $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 1928: <ul>
1929: <li>'.&mt('The course has yet to be created.').'</li>
1930: <li>'.&mt('Automatic enrollment of registered students has not been enabled for the course.').'</li>
1931: <li>'.&mt('You are in a section of course for which automatic enrollment in the corresponding LON-CAPA course is not active.').'</li>
1932: <li>'.&mt('The start date for automated enrollment has yet to be reached.').'</li>
1933: <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 1934: <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>
1935: </ul></p>');
1.191 raeburn 1936: } else {
1.269.2.37 raeburn 1937: $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>');
1938: if ($elapsed > 600) {
1939: $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.').
1940: '<br />'.
1941: &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>');
1942: }
1.191 raeburn 1943: }
1.269.2.18 raeburn 1944: if (($cattype eq 'std') || ($cattype eq 'domonly')) {
1945: $r->print('<h3>'.&mt('Self-Enrollment').'</h3>'.
1946: '<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 />');
1947: $r->print(&mt('You can search for courses and communities which permit self-enrollment, if you would like to enroll in one.').'</p>'.
1948: &Apache::loncoursequeueadmin::queued_selfenrollment());
1949: }
1.216 raeburn 1950: return;
1951: }
1952:
1.234 raeburn 1953: sub requestcourse_advice {
1.269.2.37 raeburn 1954: my ($r,$cattype,$inrole,$elapsed) = @_;
1.234 raeburn 1955: my $domdesc = &Apache::lonnet::domain($env{'user.domain'},'description');
1956: my $esc_dom = &HTML::Entities::encode($env{'user.domain'},'"<>&');
1.269.2.20 raeburn 1957: my (%can_request,%request_doms,$output);
1.234 raeburn 1958: &Apache::lonnet::check_can_request($env{'user.domain'},\%can_request,\%request_doms);
1959: if (keys(%request_doms) > 0) {
1960: my ($types,$typename) = &Apache::loncommon::course_types();
1961: if ((ref($types) eq 'ARRAY') && (ref($typename) eq 'HASH')) {
1962: my (@reqdoms,@reqtypes);
1963: foreach my $type (sort(keys(%request_doms))) {
1964: push(@reqtypes,$type);
1965: if (ref($request_doms{$type}) eq 'ARRAY') {
1966: my $domstr = join(', ',map { &Apache::lonnet::domain($_) } sort(@{$request_doms{$type}}));
1.269.2.20 raeburn 1967: $output .=
1.238 bisitz 1968: '<li>'
1969: .&mt('[_1]'.$typename->{$type}.'[_2] in domain: [_3]',
1970: '<i>',
1971: '</i>',
1972: '<b>'.$domstr.'</b>')
1.269.2.20 raeburn 1973: .'</li>';
1.234 raeburn 1974: foreach my $dom (@{$request_doms{$type}}) {
1975: unless (grep(/^\Q$dom\E/,@reqdoms)) {
1976: push(@reqdoms,$dom);
1977: }
1978: }
1979: }
1980: }
1981: my @showtypes;
1982: foreach my $type (@{$types}) {
1983: if (grep(/^\Q$type\E$/,@reqtypes)) {
1984: push(@showtypes,$type);
1985: }
1986: }
1987: my $requrl = '/adm/requestcourse';
1988: if (@reqdoms == 1) {
1989: $requrl .= '?showdom='.$reqdoms[0];
1990: }
1991: if (@showtypes > 0) {
1992: $requrl.=(($requrl=~/\?/)?'&':'?').'crstype='.$showtypes[0];
1993: }
1994: if (@reqdoms == 1 || @showtypes > 0) {
1995: $requrl .= '&state=crstype&action=new';
1.269.2.20 raeburn 1996: }
1997: if ($output) {
1998: $r->print('<h3>'.&mt('Request creation of a course or community').'</h3>'.
1999: '<p>'.
2000: &mt('You have rights to request the creation of courses and/or communities in the following domain(s):').
2001: '<ul>'.
2002: $output.
2003: '</ul>'.
2004: &mt('Use the [_1]request form[_2] to submit a request for creation of a new course or community.',
2005: '<a href="'.$requrl.'">','</a>').
2006: '</p>');
2007: }
1.234 raeburn 2008: }
1.269.2.18 raeburn 2009: } elsif (!$env{'user.adv'}) {
1.269.2.20 raeburn 2010: if ($inrole) {
2011: $r->print('<h3>'.&mt('Currently no additional roles, courses or communities').'</h3>');
2012: } else {
2013: $r->print('<h3>'.&mt('Currently no active roles, courses or communities').'</h3>');
2014: }
1.269.2.37 raeburn 2015: &findcourse_advice($r,$cattype,$elapsed);
1.234 raeburn 2016: }
2017: return;
2018: }
2019:
1.175 albertel 2020: sub privileges_info {
2021: my ($which) = @_;
2022: my $output;
2023:
2024: $which ||= $env{'request.role'};
2025:
2026: foreach my $envkey (sort(keys(%env))) {
2027: next if ($envkey!~/^user\.priv\.\Q$which\E\.(.*)/);
2028:
2029: my $where=$1;
2030: my $ttype;
2031: my $twhere;
2032: my (undef,$tdom,$trest,$tsec)=split(m{/},$where);
2033: if ($trest) {
2034: if ($env{'course.'.$tdom.'_'.$trest.'.description'} eq 'ca') {
1.269.2.10 raeburn 2035: $ttype='Authoring Space';
1.175 albertel 2036: $twhere='User: '.$trest.', Domain: '.$tdom;
2037: } else {
2038: $ttype= &Apache::loncommon::course_type($tdom.'_'.$trest);
2039: $twhere=$env{'course.'.$tdom.'_'.$trest.'.description'};
2040: if ($tsec) {
2041: my $sec_type = 'Section';
2042: if (exists($env{"user.role.gr.$where"})) {
2043: $sec_type = 'Group';
2044: }
2045: $twhere.=' ('.$sec_type.': '.$tsec.')';
2046: }
2047: }
2048: } elsif ($tdom) {
2049: $ttype='Domain';
2050: $twhere=$tdom;
2051: } else {
2052: $ttype='System';
2053: $twhere='/';
2054: }
1.204 bisitz 2055: $output .= "\n<h3>".&mt($ttype).': '.$twhere.'</h3>'."\n<ul>";
1.175 albertel 2056: foreach my $priv (sort(split(/:/,$env{$envkey}))) {
2057: next if (!$priv);
2058:
2059: my ($prv,$restr)=split(/\&/,$priv);
2060: my $trestr='';
2061: if ($restr ne 'F') {
2062: $trestr.=' ('.
2063: join(', ',
2064: map { &Apache::lonnet::plaintext($_) }
2065: (split('',$restr))).') ';
2066: }
2067: $output .= "\n\t".
2068: '<li>'.&Apache::lonnet::plaintext($prv).$trestr.'</li>';
2069: }
2070: $output .= "\n".'</ul>';
2071: }
2072: return $output;
2073: }
2074:
1.110 raeburn 2075: sub build_roletext {
1.269.2.29 raeburn 2076: my ($trolecode,$tdom,$trest,$tstatus,$tryagain,$advanced,$tremark,$tbg,$trole,$twhere,
1.269.2.39 raeburn 2077: $tpstart,$tpend,$nochoose,$button,$switchserver,$reinit,$switchwarning,$skipcal) = @_;
1.269.2.32 raeburn 2078: my ($roletext,$roletext_end,$poss_adhoc);
2079: if ($trolecode =~ m/^d(c|h|a)\./) {
2080: $poss_adhoc = 1;
2081: }
2082: my $rowspan=($poss_adhoc) ? ''
1.132 albertel 2083: : ' rowspan="2" ';
2084:
1.110 raeburn 2085: unless ($nochoose) {
1.134 www 2086: my $buttonname=$trolecode;
2087: $buttonname=~s/\W//g;
1.110 raeburn 2088: if (!$button) {
2089: if ($switchserver) {
1.212 bisitz 2090: $roletext.='<td'.$rowspan.' class="'.$tbg.'">'
2091: .'<a href="/adm/switchserver?'.$switchserver.'">'
2092: .&mt('Switch Server')
2093: .'</a></td>';
1.110 raeburn 2094: } else {
1.212 bisitz 2095: $roletext.=('<td'.$rowspan.' class="'.$tbg.'"> </td>');
1.110 raeburn 2096: }
1.255 raeburn 2097: if ($switchwarning) {
2098: if ($tremark eq '') {
2099: $tremark = $switchwarning;
2100: } else {
2101: $tremark .= '<br />'.$switchwarning;
2102: }
2103: }
1.110 raeburn 2104: } elsif ($tstatus eq 'is') {
1.212 bisitz 2105: $roletext.='<td'.$rowspan.' class="'.$tbg.'">'.
2106: '<input name="'.$buttonname.'" type="button" value="'.
1.225 bisitz 2107: &mt('Select').'" onclick="javascript:enterrole(this.form,\''.
1.192 raeburn 2108: $trolecode."','".$buttonname.'\');" /></td>';
1.110 raeburn 2109: } elsif ($tryagain) {
2110: $roletext.=
1.212 bisitz 2111: '<td'.$rowspan.' class="'.$tbg.'">'.
2112: '<input name="'.$buttonname.'" type="button" value="'.
1.225 bisitz 2113: &mt('Try Selecting Again').'" onclick="javascript:enterrole(this.form,\''.
1.192 raeburn 2114: $trolecode."','".$buttonname.'\');" /></td>';
1.110 raeburn 2115: } elsif ($advanced) {
2116: $roletext.=
1.212 bisitz 2117: '<td'.$rowspan.' class="'.$tbg.'">'.
2118: '<input name="'.$buttonname.'" type="button" value="'.
1.225 bisitz 2119: &mt('Re-Initialize').'" onclick="javascript:enterrole(this.form,\''.
1.192 raeburn 2120: $trolecode."','".$buttonname.'\');" /></td>';
1.209 raeburn 2121: } elsif ($reinit) {
2122: $roletext.=
1.212 bisitz 2123: '<td'.$rowspan.' class="'.$tbg.'">'.
2124: '<input name="'.$buttonname.'" type="button" value="'.
1.225 bisitz 2125: &mt('Re-Select').'" onclick="javascript:enterrole(this.form,\''.
1.209 raeburn 2126: $trolecode."','".$buttonname.'\');" /></td>';
1.110 raeburn 2127: } else {
1.209 raeburn 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: }
2134: }
1.269.2.39 raeburn 2135: if (($trolecode !~ m/^(dc|ca|au|aa)\./) && (!$skipcal)) {
1.165 albertel 2136: $tremark.=&Apache::lonannounce::showday(time,1,
2137: &Apache::lonannounce::readcalendar($tdom.'_'.$trest));
2138: }
1.212 bisitz 2139: $roletext.='<td>'.$trole.'</td>'
2140: .'<td>'.$twhere.'</td>'
2141: .'<td>'.$tpstart.'</td>'
1.223 raeburn 2142: .'<td>'.$tpend.'</td>';
1.269.2.32 raeburn 2143: unless ($poss_adhoc) {
1.223 raeburn 2144: $roletext_end = '<td colspan="4">'.
2145: $tremark.' '.
2146: '</td>';
1.132 albertel 2147: }
1.223 raeburn 2148: return ($roletext,$roletext_end);
1.110 raeburn 2149: }
2150:
1.193 raeburn 2151: sub check_author_homeserver {
1.183 www 2152: my ($uname,$udom)=@_;
1.193 raeburn 2153: if (($uname eq '') || ($udom eq '')) {
2154: return ('fail','');
2155: }
1.183 www 2156: my $home = &Apache::lonnet::homeserver($uname,$udom);
1.193 raeburn 2157: if (&Apache::lonnet::host_domain($home) ne $udom) {
2158: return ('fail',$home);
2159: }
1.183 www 2160: my @ids=&Apache::lonnet::current_machine_ids();
1.193 raeburn 2161: if (grep(/^\Q$home\E$/,@ids)) {
2162: return ('ok',$home);
2163: } else {
2164: return ('switchserver',$home);
1.183 www 2165: }
2166: }
2167:
1.269.2.27 raeburn 2168: sub check_for_adhoc {
1.269.2.31 raeburn 2169: my ($dcroles,$helpdeskroles,$update,$then) = @_;
1.104 raeburn 2170: my $numdc = 0;
1.269.2.31 raeburn 2171: my $numhelpdesk = 0;
1.269.2.27 raeburn 2172: my $numadhoc = 0;
2173: my $num_custom_adhoc = 0;
1.269.2.32 raeburn 2174: if (($env{'user.adv'}) || ($env{'user.rar'})) {
1.269.2.22 raeburn 2175: foreach my $envkey (sort(keys(%env))) {
1.269.2.31 raeburn 2176: if ($envkey=~/^user\.role\.(dc|dh|da)\.\/($match_domain)\/$/) {
1.269.2.27 raeburn 2177: my $role = $1;
2178: my $roledom = $2;
2179: my $liverole = 1;
1.118 albertel 2180: my ($tstart,$tend)=split(/\./,$env{$envkey});
1.260 raeburn 2181: my $limit = $update;
1.269.2.31 raeburn 2182: if ($env{'request.role'} eq "$role./$roledom/") {
1.260 raeburn 2183: $limit = $then;
2184: }
1.269.2.27 raeburn 2185: if ($tstart && $tstart>$limit) { $liverole = 0; }
2186: if ($tend && $tend <$limit) { $liverole = 0; }
2187: if ($liverole) {
2188: if ($role eq 'dc') {
2189: $dcroles->{$roledom} = $envkey;
2190: $numdc++;
2191: } else {
1.269.2.31 raeburn 2192: $helpdeskroles->{$roledom} = $envkey;
1.269.2.30 raeburn 2193: my %domdefaults = &Apache::lonnet::get_domain_defaults($roledom);
2194: if (ref($domdefaults{'adhocroles'}) eq 'HASH') {
2195: if (keys(%{$domdefaults{'adhocroles'}})) {
2196: $numadhoc ++;
2197: }
1.269.2.27 raeburn 2198: }
1.269.2.31 raeburn 2199: $numhelpdesk++;
1.269.2.27 raeburn 2200: }
1.104 raeburn 2201: }
2202: }
2203: }
2204: }
1.269.2.31 raeburn 2205: return ($numdc,$numhelpdesk,$numadhoc);
1.104 raeburn 2206: }
2207:
1.185 raeburn 2208: sub adhoc_course_role {
1.260 raeburn 2209: my ($refresh,$update,$then) = @_;
1.239 raeburn 2210: my ($cdom,$cnum,$crstype);
1.201 raeburn 2211: $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
2212: $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.239 raeburn 2213: $crstype = &Apache::loncommon::course_type();
1.260 raeburn 2214: if (&check_forcc($cdom,$cnum,$refresh,$update,$then,$crstype)) {
1.185 raeburn 2215: my $setprivs;
1.198 raeburn 2216: if (!defined($env{'user.role.'.$env{'form.switchrole'}})) {
1.185 raeburn 2217: $setprivs = 1;
2218: } else {
1.198 raeburn 2219: my ($start,$end) = split(/\./,$env{'user.role.'.$env{'form.switchrole'}});
1.232 raeburn 2220: if (($start && ($start>$refresh || $start == -1)) ||
1.260 raeburn 2221: ($end && $end<$update)) {
1.185 raeburn 2222: $setprivs = 1;
2223: }
1.232 raeburn 2224: }
1.269.2.5 raeburn 2225: unless ($setprivs) {
2226: if (!exists($env{'user.priv.'.$env{'form.switchrole'}.'./'})) {
2227: $setprivs = 1;
2228: }
2229: }
1.185 raeburn 2230: if ($setprivs) {
1.269.2.16 raeburn 2231: if ($env{'form.switchrole'} =~ m-^(in|ta|ep|ad|st|cr)(.*?)\./\Q$cdom\E/\Q$cnum\E/?(\w*)$-) {
1.185 raeburn 2232: my $role = $1;
2233: my $custom_role = $2;
2234: my $usec = $3;
2235: if ($role eq 'cr') {
1.199 raeburn 2236: if ($custom_role =~ m-^/$match_domain/$match_username/\w+$-) {
1.185 raeburn 2237: $role .= $custom_role;
2238: } else {
2239: return;
2240: }
2241: }
1.208 raeburn 2242: my (%userroles,%newrole,%newgroups,%group_privs);
2243: my %cgroups =
2244: &Apache::lonnet::get_active_groups($env{'user.domain'},
2245: $env{'user.name'},$cdom,$cnum);
1.269.2.29 raeburn 2246: my $ccrole;
2247: if ($crstype eq 'Community') {
2248: $ccrole = 'co';
2249: } else {
2250: $ccrole = 'cc';
2251: }
1.208 raeburn 2252: foreach my $group (keys(%cgroups)) {
2253: $group_privs{$group} =
1.269.2.29 raeburn 2254: $env{'user.priv.'.$ccrole.'./'.$cdom.'/'.$cnum.'./'.$cdom.'/'.$cnum.'/'.$group};
1.208 raeburn 2255: }
2256: $newgroups{'/'.$cdom.'/'.$cnum} = \%group_privs;
1.185 raeburn 2257: my $area = '/'.$cdom.'/'.$cnum;
2258: my $spec = $role.'.'.$area;
2259: if ($usec ne '') {
2260: $spec .= '/'.$usec;
2261: $area .= '/'.$usec;
2262: }
1.269.2.5 raeburn 2263: if ($role =~ /^cr/) {
2264: &Apache::lonnet::custom_roleprivs(\%newrole,$role,$cdom,$cnum,$spec,$area);
2265: } else {
2266: &Apache::lonnet::standard_roleprivs(\%newrole,$role,$cdom,$spec,$cnum,$area);
2267: }
1.208 raeburn 2268: &Apache::lonnet::set_userprivs(\%userroles,\%newrole,\%newgroups);
1.232 raeburn 2269: my $adhocstart = $refresh-1;
1.185 raeburn 2270: $userroles{'user.role.'.$spec} = $adhocstart.'.';
1.186 raeburn 2271: &Apache::lonnet::appenv(\%userroles,[$role,'cm']);
1.185 raeburn 2272: }
2273: }
2274: }
2275: return;
2276: }
2277:
2278: sub check_forcc {
1.260 raeburn 2279: my ($cdom,$cnum,$refresh,$update,$then,$crstype) = @_;
1.239 raeburn 2280: my ($is_cc,$ccrole);
2281: if ($crstype eq 'Community') {
2282: $ccrole = 'co';
2283: } else {
2284: $ccrole = 'cc';
2285: }
1.266 droeschl 2286: if (&Apache::lonnet::is_course($cdom,$cnum)) {
2287: my $envkey = 'user.role.'.$ccrole.'./'.$cdom.'/'.$cnum;
2288: if (defined($env{$envkey})) {
2289: $is_cc = 1;
2290: my ($tstart,$tend)=split(/\./,$env{$envkey});
2291: my $limit = $update;
2292: if ($env{'request.role'} eq $ccrole.'./'.$cdom.'/'.$cnum) {
2293: $limit = $then;
1.185 raeburn 2294: }
1.266 droeschl 2295: if ($tstart && $tstart>$refresh) { $is_cc = 0; }
2296: if ($tend && $tend <$limit) { $is_cc = 0; }
1.185 raeburn 2297: }
2298: }
2299: return $is_cc;
2300: }
2301:
1.108 raeburn 2302: sub courselink {
1.269.2.27 raeburn 2303: my ($roledom,$rowtype,$role) = @_;
1.109 raeburn 2304: my $courseform=&Apache::loncommon::selectcourse_link
1.269.2.27 raeburn 2305: ('rolechoice','course'.$rowtype.'_'.$roledom.'_'.$role,
2306: 'domain'.$rowtype.'_'.$roledom.'_'.$role,
2307: 'coursedesc'.$rowtype.'_'.$roledom.'_'.$role,
2308: $roledom.':'.$role,undef,'Course/Community');
2309: my $hiddenitems = '<input type="hidden" name="domain'.$rowtype.'_'.$roledom.'_'.$role.'" value="'.$roledom.'" />'.
2310: '<input type="hidden" name="origdom'.$rowtype.'_'.$roledom.'_'.$role.'" value="'.$roledom.'" />'.
2311: '<input type="hidden" name="course'.$rowtype.'_'.$roledom.'_'.$role.'" value="" />'.
2312: '<input type="hidden" name="coursedesc'.$rowtype.'_'.$roledom.'_'.$role.'" value="" />';
1.112 raeburn 2313: return $courseform.$hiddenitems;
1.109 raeburn 2314: }
2315:
2316: sub coursepick_jscript {
1.269.2.25 raeburn 2317: my %js_lt = &Apache::lonlocal::texthash(
1.239 raeburn 2318: 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 2319: youc => 'You can only use this screen to select courses and communities in the current domain.',
1.184 raeburn 2320: );
1.269.2.24 raeburn 2321: &js_escape(\%js_lt);
1.104 raeburn 2322: my $verify_script = <<"END";
1.179 raeburn 2323: <script type="text/javascript">
1.225 bisitz 2324: // <![CDATA[
1.108 raeburn 2325: function verifyCoursePick(caller) {
2326: var numbutton = getIndex(caller)
1.112 raeburn 2327: var pickedCourse = document.rolechoice.elements[numbutton+4].value
2328: var pickedDomain = document.rolechoice.elements[numbutton+2].value
2329: if (document.rolechoice.elements[numbutton+2].value == document.rolechoice.elements[numbutton+3].value) {
1.104 raeburn 2330: if (pickedCourse != '') {
1.108 raeburn 2331: if (numbutton != -1) {
2332: var courseTarget = "cc./"+pickedDomain+"/"+pickedCourse
2333: document.rolechoice.elements[numbutton+1].name = courseTarget
2334: document.rolechoice.submit()
2335: }
1.104 raeburn 2336: }
2337: else {
1.269.2.24 raeburn 2338: alert("$js_lt{'plsu'}");
1.104 raeburn 2339: }
2340: }
2341: else {
1.269.2.24 raeburn 2342: alert("$js_lt{'youc'}")
1.104 raeburn 2343: }
2344: }
1.109 raeburn 2345: function getIndex(caller) {
1.108 raeburn 2346: for (var i=0;i<document.rolechoice.elements.length;i++) {
1.109 raeburn 2347: if (document.rolechoice.elements[i] == caller) {
1.108 raeburn 2348: return i;
2349: }
2350: }
2351: return -1;
2352: }
1.225 bisitz 2353: // ]]>
1.104 raeburn 2354: </script>
2355: END
1.109 raeburn 2356: return $verify_script;
1.104 raeburn 2357: }
2358:
1.193 raeburn 2359: sub coauthorlink {
2360: my ($dcdom,$rowtype) = @_;
2361: my $coauthorform=&Apache::loncommon::selectauthor_link('rolechoice',$dcdom);
2362: my $hiddenitems = '<input type="hidden" name="adhoccauname'.$rowtype.'_'.$dcdom.'" value="" />';
2363: return $coauthorform.$hiddenitems;
2364: }
2365:
1.113 raeburn 2366: sub display_cc_role {
2367: my $rolekey = shift;
1.223 raeburn 2368: my ($roletext,$roletext_end);
1.118 albertel 2369: my $advanced = $env{'user.adv'};
2370: my $tryagain = $env{'form.tryagain'};
1.113 raeburn 2371: unless ($rolekey =~/^error\:/) {
1.240 raeburn 2372: if ($rolekey =~ m{^user\.role\.(cc|co)\./($match_domain)/($match_courseid)$}) {
2373: my $ccrole = $1;
1.249 raeburn 2374: my $tdom = $2;
2375: my $trest = $3;
2376: my $tcourseid = $tdom.'_'.$trest;
2377: my $trolecode = $ccrole.'./'.$tdom.'/'.$trest;
1.113 raeburn 2378: my $twhere;
1.152 raeburn 2379: my $ttype;
1.269.2.39 raeburn 2380: my $skipcal;
1.212 bisitz 2381: my $tbg='LC_roles_is';
1.113 raeburn 2382: my %newhash=&Apache::lonnet::coursedescription($tcourseid);
2383: if (%newhash) {
2384: $twhere=$newhash{'description'}.
1.261 bisitz 2385: ' <span class="LC_fontsize_small">'.
1.249 raeburn 2386: &Apache::loncommon::syllabuswrapper(&mt('Syllabus'),$trest,$tdom).
1.211 tempelho 2387: '</span>';
1.153 raeburn 2388: $ttype = $newhash{'type'};
1.113 raeburn 2389: } else {
2390: $twhere=&mt('Currently not available');
1.118 albertel 2391: $env{'course.'.$tcourseid.'.description'}=$twhere;
1.269.2.39 raeburn 2392: $skipcal = 1;
1.110 raeburn 2393: }
1.242 raeburn 2394: my $trole = &Apache::lonnet::plaintext($ccrole,$ttype,$tcourseid);
1.258 raeburn 2395: $twhere.="<br />".&mt('Domain').":".$tdom;
1.269.2.39 raeburn 2396: ($roletext,$roletext_end) = &build_roletext($trolecode,$tdom,$trest,'is',$tryagain,$advanced,'',$tbg,$trole,$twhere,'','','',1,'','','',$skipcal);
1.104 raeburn 2397: }
2398: }
1.223 raeburn 2399: return ($roletext,$roletext_end);
1.104 raeburn 2400: }
2401:
1.269.2.39.2. (raeburn 2402:): sub display_curr_role {
2403:): my ($currentrole) = @_;
2404:): my ($roletext,$roletext_end);
2405:): my $advanced = $env{'user.adv'};
2406:): my $tryagain = $env{'form.tryagain'};
2407:): my ($role,$rest) = split(m{\./},$currentrole,2);
2408:): unless (!defined($role) || $role eq '') {
2409:): if ($rest =~ m{^($match_domain)/($match_courseid)(?:/(\w+)|$)}) {
2410:): my $cdom = $1;
2411:): my $cnum = $2;
2412:): my $csec = $3;
2413:): my $cid = $cdom.'_'.$cnum;
2414:): my $ttype = $env{'course.'.$cid.'.type'};
2415:): my $skipcal = 1;
2416:): my $tbg='LC_roles_is';
2417:): my $twhere = $env{'course.'.$cid.'.description'}.
2418:): ' <span class="LC_fontsize_small">'.
2419:): &Apache::loncommon::syllabuswrapper(&mt('Syllabus'),$cnum,$cdom).
2420:): '</span>';
2421:): my $trole = &Apache::lonnet::plaintext($role,$ttype,$cid);
2422:): if ($csec) {
2423:): $twhere.= ' '.&mt('Section').': '.$csec;
2424:): }
2425:): if ($role ne 'st') {
2426:): $twhere.= ' '.&mt('Domain').': '.$cdom;
2427:): }
2428:): ($roletext,$roletext_end) = &build_roletext($currentrole,$cdom,$cnum,'is',$tryagain,$advanced,'',$tbg,$trole,$twhere,'','','',1,'','','',$skipcal);
2429:): }
2430:): }
2431:): return ($roletext,$roletext_end);
2432:): }
2433:):
1.192 raeburn 2434: sub adhoc_roles_row {
1.138 raeburn 2435: my ($dcdom,$rowtype) = @_;
1.212 bisitz 2436: my $output = &Apache::loncommon::continue_data_table_row()
1.269.2.26 raeburn 2437: .' <td colspan="5" class="LC_textsize_mobile">'
1.269.2.34 raeburn 2438: .&mt('[_1]Ad hoc[_2] roles in domain [_3]'
1.212 bisitz 2439: ,'<span class="LC_cusr_emph">','</span>',$dcdom)
1.269.2.34 raeburn 2440: .' -- ';
1.269.2.27 raeburn 2441: my $role = 'cc';
2442: my $selectcclink = &courselink($dcdom,$rowtype,$role);
1.239 raeburn 2443: my $ccrole = &Apache::lonnet::plaintext('co',undef,undef,1);
1.182 www 2444: my $carole = &Apache::lonnet::plaintext('ca');
1.193 raeburn 2445: my $selectcalink = &coauthorlink($dcdom,$rowtype);
1.227 bisitz 2446: $output.=$ccrole.': '.$selectcclink
1.249 raeburn 2447: .' | '.$carole.': '.$selectcalink.'</td>'
1.212 bisitz 2448: .&Apache::loncommon::end_data_table_row();
1.108 raeburn 2449: return $output;
2450: }
2451:
1.269.2.27 raeburn 2452: sub adhoc_customroles_row {
1.269.2.30 raeburn 2453: my ($role,$dhdom,$rowtype,$update,$then) = @_;
2454: my $liverole = 1;
2455: my ($tstart,$tend)=split(/\./,$env{"user.role.$role./$dhdom/"});
2456: my $limit = $update;
2457: if (($role eq 'dh') && ($env{'request.role'} eq 'dh./'.$dhdom.'/')) {
2458: $limit = $then;
2459: }
2460: if ($tstart && $tstart>$limit) { $liverole = 0; }
2461: if ($tend && $tend <$limit) { $liverole = 0; }
2462: return unless ($liverole);
2463: my %domdefaults = &Apache::lonnet::get_domain_defaults($dhdom);
2464: if (ref($domdefaults{'adhocroles'}) eq 'HASH') {
2465: if (scalar(keys(%{$domdefaults{'adhocroles'}})) > 0) {
2466: return &Apache::loncommon::continue_data_table_row()
2467: .' <td colspan="5" class="LC_textsize_mobile">'
1.269.2.34 raeburn 2468: .&mt('[_1]Ad hoc[_2] course/community roles in domain [_3]',
1.269.2.30 raeburn 2469: '<span class="LC_cusr_emph">','</span>',$dhdom)
1.269.2.34 raeburn 2470: .' -- '.&courselink($dhdom,$rowtype,$role);
1.269.2.30 raeburn 2471: }
1.269.2.27 raeburn 2472: }
2473: return;
2474: }
2475:
1.104 raeburn 2476: sub recent_filename {
2477: my $area=shift;
1.149 www 2478: return 'nohist_recent_'.&escape($area);
1.104 raeburn 2479: }
2480:
1.139 raeburn 2481: sub courseloadpage {
2482: my ($courseid) = @_;
2483: my $startpage;
1.144 albertel 2484: my %entry_settings = &Apache::lonnet::get('nohist_whatsnew',
2485: [$courseid.':courseinit']);
1.139 raeburn 2486: my ($tmp) = %entry_settings;
1.144 albertel 2487: unless ($tmp =~ /^error: 2 /) {
1.139 raeburn 2488: $startpage = $entry_settings{$courseid.':courseinit'};
2489: }
2490: if ($startpage eq '') {
2491: if (exists($env{'environment.course_init_display'})) {
2492: $startpage = $env{'environment.course_init_display'};
2493: }
2494: }
2495: return $startpage;
2496: }
2497:
1.260 raeburn 2498: sub update_session_roles {
2499: my $then=$env{'user.login.time'};
2500: my $refresh=$env{'user.refresh.time'};
2501: if (!$refresh) {
2502: $refresh = $then;
2503: }
2504: my $update = $env{'user.update.time'};
2505: if (!$update) {
2506: $update = $then;
2507: }
2508: my $now = time;
2509: my %roleshash =
2510: &Apache::lonnet::get_my_roles('','','userroles',
2511: ['active','future','previous'],
2512: undef,undef,1);
2513: my ($msg,@newsec,$oldsec,$currrole_expired,@changed_roles,
1.264 raeburn 2514: %changed_groups,%dbroles,%deletedroles,%allroles,%allgroups,
1.260 raeburn 2515: %userroles,%checkedgroup,%crprivs,$hasgroups,%rolechange,
2516: %groupchange,%newrole,%newgroup,%customprivchg,%groups_roles,
2517: @rolecodes);
2518: my @possroles = ('cr','st','ta','ad','ep','in','co','cc');
2519: my %courseroles;
2520: foreach my $item (keys(%roleshash)) {
2521: my ($uname,$udom,$role,$remainder) = split(/:/,$item,4);
2522: my ($tstart,$tend) = split(/:/,$roleshash{$item});
2523: my ($section,$group,@group_privs);
2524: if ($role =~ m{^gr/(\w*)$}) {
2525: $role = 'gr';
2526: my $priv = $1;
2527: next if ($tstart eq '-1');
2528: if (&curr_role_status($tstart,$tend,$refresh,$now) eq 'active') {
2529: if ($priv ne '') {
2530: push(@group_privs,$priv);
2531: }
2532: }
2533: if ($remainder =~ /:/) {
2534: (my $additional_privs,$group) =
2535: ($remainder =~ /^([\w:]+):([^:]+)$/);
2536: if ($additional_privs ne '') {
2537: if (&curr_role_status($tstart,$tend,$refresh,$now) eq 'active') {
2538: push(@group_privs,split(/:/,$additional_privs));
2539: @group_privs = sort(@group_privs);
2540: }
2541: }
2542: } else {
2543: $group = $remainder;
2544: }
2545: } else {
2546: $section = $remainder;
2547: }
2548: my $where = "/$udom/$uname";
2549: if ($section ne '') {
2550: $where .= "/$section";
2551: } elsif ($group ne '') {
2552: $where .= "/$group";
2553: }
2554: my $rolekey = "$role.$where";
2555: my $envkey = "user.role.$rolekey";
2556: $dbroles{$envkey} = 1;
2557: if (($env{'request.role'} eq $rolekey) && ($role ne 'st')) {
2558: if (&curr_role_status($tstart,$tend,$refresh,$now) ne 'active') {
2559: $currrole_expired = 1;
2560: }
2561: }
2562: if ($env{$envkey} eq '') {
2563: my $status_in_db =
1.269.2.2 raeburn 2564: &curr_role_status($tstart,$tend,$now,$now);
1.260 raeburn 2565: &gather_roleprivs(\%allroles,\%allgroups,\%userroles,$where,$role,$tstart,$tend,$status_in_db);
2566: if (($role eq 'st') && ($env{'request.role'} =~ m{^\Q$role\E\.\Q/$udom/$uname\E})) {
2567: if ($status_in_db eq 'active') {
2568: if ($section eq '') {
2569: push(@newsec,'none');
2570: } else {
2571: push(@newsec,$section);
2572: }
2573: }
2574: } else {
2575: unless (grep(/^\Q$role\E$/,@changed_roles)) {
2576: push(@changed_roles,$role);
2577: }
2578: if ($status_in_db ne 'previous') {
2579: if ($role eq 'gr') {
2580: $newgroup{$rolekey} = $status_in_db;
2581: if ($status_in_db eq 'active') {
2582: unless (ref($courseroles{$udom}) eq 'HASH') {
2583: %{$courseroles{$udom}} =
2584: &Apache::lonnet::get_my_roles('','','userroles',
2585: ['active'],\@possroles,
2586: [$udom],1);
2587: }
2588: &Apache::lonnet::get_groups_roles($udom,$uname,
2589: $courseroles{$udom},
2590: \@rolecodes,\%groups_roles);
2591: }
2592: } else {
2593: $newrole{$rolekey} = $status_in_db;
2594: }
2595: }
2596: }
2597: } else {
2598: my ($currstart,$currend) = split(/\./,$env{$envkey});
2599: if ($role eq 'gr') {
2600: if (&curr_role_status($currstart,$currend,$refresh,$update) ne 'previous') {
2601: $hasgroups = 1;
2602: }
2603: }
2604: if (($currstart ne $tstart) || ($currend ne $tend)) {
2605: my $status_in_env =
2606: &curr_role_status($currstart,$currend,$refresh,$update);
2607: my $status_in_db =
1.269.2.2 raeburn 2608: &curr_role_status($tstart,$tend,$now,$now);
1.260 raeburn 2609: if ($status_in_env ne $status_in_db) {
2610: if ($status_in_env eq 'active') {
2611: if ($role eq 'st') {
2612: if ($env{'request.role'} eq $rolekey) {
2613: my $switchsection;
2614: unless (ref($courseroles{$udom}) eq 'HASH') {
2615: %{$courseroles{$udom}} =
2616: &Apache::lonnet::get_my_roles('','','userroles',
2617: ['active'],
2618: \@possroles,[$udom],1);
2619: }
2620: foreach my $crsrole (keys(%{$courseroles{$udom}})) {
2621: if ($crsrole =~ /^\Q$uname\E:\Q$udom\E:st/) {
2622: $switchsection = 1;
2623: last;
2624: }
2625: }
2626: if ($switchsection) {
2627: if ($section eq '') {
2628: $oldsec = 'none';
2629: } else {
2630: $oldsec = $section;
2631: }
2632: &gather_roleprivs(\%allroles,\%allgroups,\%userroles,$where,$role,$tstart,$tend,$status_in_db);
2633: } else {
2634: $currrole_expired = 1;
2635: next;
2636: }
2637: }
2638: }
2639: unless ($rolekey eq $env{'request.role'}) {
2640: if ($role eq 'gr') {
2641: &Apache::lonnet::delete_env_groupprivs($where,\%courseroles,\@possroles);
2642: } else {
2643: &Apache::lonnet::delenv("user.priv.$rolekey",undef,[$role]);
2644: &Apache::lonnet::delenv("user.priv.cm.$where",undef,['cm']);
2645: }
2646: &gather_roleprivs(\%allroles,\%allgroups,\%userroles,$where,$role,$tstart,$tend,$status_in_db);
2647: }
2648: } elsif ($status_in_db eq 'active') {
2649: if (($role eq 'st') &&
2650: ($env{'request.role'} =~ m{^\Q$role\E\.\Q/$udom/$uname\E})) {
2651: if ($section eq '') {
2652: push(@newsec,'none');
2653: } else {
2654: push(@newsec,$section);
2655: }
2656: } elsif ($role eq 'gr') {
2657: unless (ref($courseroles{$udom}) eq 'HASH') {
2658: %{$courseroles{$udom}} =
2659: &Apache::lonnet::get_my_roles('','','userroles',
2660: ['active'],
2661: \@possroles,[$udom],1);
2662: }
2663: &Apache::lonnet::get_groups_roles($udom,$uname,
2664: $courseroles{$udom},
2665: \@rolecodes,\%groups_roles);
2666: }
2667: &gather_roleprivs(\%allroles,\%allgroups,\%userroles,$where,$role,$tstart,$tend,$status_in_db);
2668: }
2669: unless (grep(/^\Q$role\E$/,@changed_roles)) {
2670: push(@changed_roles,$role);
2671: }
2672: if ($role eq 'gr') {
2673: $groupchange{"/$udom/$uname"}{$group} = $status_in_db;
2674: } else {
2675: $rolechange{$rolekey} = $status_in_db;
2676: }
2677: }
2678: } else {
2679: if ($role eq 'gr') {
2680: unless ($checkedgroup{$where}) {
2681: my $status_in_db =
2682: &curr_role_status($tstart,$tend,$refresh,$now);
2683: if ($tstart eq '-1') {
2684: $status_in_db = 'deleted';
2685: }
2686: unless (ref($courseroles{$udom}) eq 'HASH') {
2687: %{$courseroles{$udom}} =
2688: &Apache::lonnet::get_my_roles('','','userroles',
2689: ['active'],
2690: \@possroles,[$udom],1);
2691: }
2692: if (ref($courseroles{$udom}) eq 'HASH') {
2693: foreach my $item (keys(%{$courseroles{$udom}})) {
2694: next unless ($item =~ /^\Q$uname\E/);
2695: my ($cnum,$cdom,$crsrole,$crssec) = split(/:/,$item);
2696: my $area = '/'.$cdom.'/'.$cnum;
2697: if ($crssec ne '') {
2698: $area .= '/'.$crssec;
2699: }
2700: my $crsrolekey = $crsrole.'.'.$area;
2701: my $currprivs = $env{'user.priv.'.$crsrole.'.'.$area.'.'.$where};
2702: $currprivs =~ s/^://;
2703: $currprivs =~ s/\&F$//;
2704: my @curr_grp_privs = split(/\&F:/,$currprivs);
2705: @curr_grp_privs = sort(@curr_grp_privs);
2706: my @diffs;
2707: if (@group_privs > 0 || @curr_grp_privs > 0) {
2708: @diffs = &Apache::loncommon::compare_arrays(\@group_privs,\@curr_grp_privs);
2709: }
2710: if (@diffs == 0) {
2711: last;
2712: } else {
2713: unless(grep(/^\Qgr\E$/,@rolecodes)) {
2714: push(@rolecodes,'gr');
2715: }
2716: &gather_roleprivs(\%allroles,\%allgroups,
2717: \%userroles,$where,$role,
2718: $tstart,$tend,$status_in_db);
2719: if ($status_in_db eq 'active') {
2720: &Apache::lonnet::get_groups_roles($udom,$uname,
2721: $courseroles{$udom},
2722: \@rolecodes,\%groups_roles);
2723: }
2724: $changed_groups{$udom.'_'.$uname}{$group} = $status_in_db;
2725: last;
2726: }
2727: }
2728: }
2729: $checkedgroup{$where} = 1;
2730: }
2731: } elsif ($role =~ /^cr/) {
2732: my $status_in_db =
2733: &curr_role_status($tstart,$tend,$refresh,$now);
2734: my ($rdummy,$rest) = split(/\//,$role,2);
2735: my %currpriv;
2736: unless (exists($crprivs{$rest})) {
2737: my ($rdomain,$rauthor,$rrole)=split(/\//,$rest);
2738: my $homsvr=&Apache::lonnet::homeserver($rauthor,$rdomain);
2739: if (&Apache::lonnet::hostname($homsvr) ne '') {
2740: my ($rdummy,$roledef)=
2741: &Apache::lonnet::get('roles',["rolesdef_$rrole"],
2742: $rdomain,$rauthor);
2743: if (($rdummy ne 'con_lost') && ($roledef ne '')) {
2744: my $i = 0;
2745: my @scopes = ('sys','dom','crs');
2746: my @privs = split(/\_/,$roledef);
2747: foreach my $priv (@privs) {
2748: my ($blank,@prv) = split(/:/,$priv);
2749: @prv = map { $_ .= (/\&\w+$/ ? '':'&F') } @prv;
1.264 raeburn 2750: if (@prv) {
2751: $priv = ':'.join(':',sort(@prv));
2752: }
1.260 raeburn 2753: $crprivs{$rest}{$scopes[$i]} = $priv;
2754: $i++;
2755: }
2756: }
2757: }
2758: }
1.269.2.6 raeburn 2759: my $status_in_env =
2760: &curr_role_status($currstart,$currend,$refresh,$update);
2761: if ($status_in_env eq 'active') {
2762: $currpriv{sys} = $env{"user.priv.$rolekey./"};
2763: $currpriv{dom} = $env{"user.priv.$rolekey./$udom/"};
2764: $currpriv{crs} = $env{"user.priv.$rolekey.$where"};
2765: if (keys(%crprivs)) {
2766: if (($crprivs{$rest}{sys} ne $currpriv{sys}) ||
2767: ($crprivs{$rest}{dom} ne $currpriv{dom})
1.260 raeburn 2768: ||
1.269.2.6 raeburn 2769: ($crprivs{$rest}{crs} ne $currpriv{crs})) {
2770: &gather_roleprivs(\%allroles,\%allgroups,
2771: \%userroles,$where,$role,
2772: $tstart,$tend,$status_in_db);
2773: unless (grep(/^\Q$role\E$/,@changed_roles)) {
2774: push(@changed_roles,$role);
2775: }
1.260 raeburn 2776: $customprivchg{$rolekey} = $status_in_env;
2777: }
2778: }
2779: }
2780: }
2781: }
2782: }
2783: }
2784: foreach my $envkey (keys(%env)) {
2785: next unless ($envkey =~ /^user\.role\./);
2786: next if ($dbroles{$envkey});
2787: next if ($envkey eq 'user.role.'.$env{'request.role'});
2788: my ($currstart,$currend) = split(/\./,$env{$envkey});
2789: my $status_in_env =
2790: &curr_role_status($currstart,$currend,$refresh,$update);
2791: my ($rolekey) = ($envkey =~ /^user\.role\.(.+)$/);
1.269.2.16 raeburn 2792: my ($role,$rest)=split(m{\./},$rolekey,2);
2793: $rest = '/'.$rest;
1.260 raeburn 2794: if (&Apache::lonnet::delenv($envkey,undef,[$role])) {
2795: if ($status_in_env eq 'active') {
2796: if ($role eq 'gr') {
2797: &Apache::lonnet::delete_env_groupprivs($rest,\%courseroles,
2798: \@possroles);
2799: } else {
2800: &Apache::lonnet::delenv("user.priv.$rolekey",undef,[$role]);
2801: &Apache::lonnet::delenv("user.priv.cm.$rest",undef,['cm']);
2802: }
2803: unless (grep(/^\Q$role\E$/,@changed_roles)) {
2804: push(@changed_roles,$role);
2805: }
2806: $deletedroles{$rolekey} = 1;
2807: }
2808: }
2809: }
2810: if (($oldsec) && (@newsec > 0)) {
2811: if (@newsec > 1) {
1.269.2.2 raeburn 2812: $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 2813: } else {
2814: my $newrole = $env{'request.role'};
2815: if ($newsec[0] eq 'none') {
2816: $newrole =~ s{(/[^/])$}{};
2817: } elsif ($oldsec eq 'none') {
2818: $newrole .= '/'.$newsec[0];
2819: } else {
2820: $newrole =~ s{([^/]+)$}{$newsec[0]};
2821: }
2822: my $coursedesc = $env{'course.'.$env{'request.course.id'}.'.description'};
2823: my ($curr_role) = ($env{'request.role'} =~ m{^(\w+)\./$match_domain/$match_courseid});
2824: my %temp=('logout_'.$env{'request.course.id'} => time);
2825: &Apache::lonnet::put('email_status',\%temp);
2826: &Apache::lonnet::delenv('user.state.'.$env{'request.course.id'});
2827: &Apache::lonnet::appenv({"request.course.id" => '',
2828: "request.course.fn" => '',
2829: "request.course.uri" => '',
2830: "request.course.sec" => '',
2831: "request.role" => 'cm',
2832: "request.role.adv" => $env{'user.adv'},
2833: "request.role.domain" => $env{'user.domain'}});
2834: my $rolename = &Apache::loncommon::plainname($curr_role);
2835: $msg = '<p><form name="reselectrole" action="/adm/roles" method="post" />'.
2836: '<input type="hidden" name="newrole" value="" />'.
2837: '<input type="hidden" name="selectrole" value="1" />'.
2838: '<span class="LC_info">'.
2839: &mt('Your section has changed for your current [_1] role in [_2].',$rolename,$coursedesc).'</span><br />';
2840: my $button = '<input type="button" name="sectionchanged" value="'.
2841: &mt('Re-Select').'" onclick="javascript:enterrole(this.form,'."'$newrole','sectionchanged'".')" />';
2842: if ($newsec[0] eq 'none') {
2843: $msg .= &mt('[_1] to continue with your new section-less role.',$button);
2844: } else {
2845: $msg .= &mt('[_1] to continue with your new role in section ([_2]).',$button,$newsec[0]);
2846: }
2847: $msg .= '</form></p>';
2848: }
2849: } elsif ($currrole_expired) {
1.269.2.2 raeburn 2850: $msg .= '<p class="LC_warning">';
1.260 raeburn 2851: if (&Apache::loncommon::show_course()) {
2852: $msg .= &mt('Your role in the current course has expired.');
2853: } else {
2854: $msg .= &mt('Your current role has expired.');
2855: }
1.269.2.2 raeburn 2856: $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 2857: }
1.269.2.6 raeburn 2858: &Apache::lonnet::set_userprivs(\%userroles,\%allroles,\%allgroups,\%groups_roles);
2859: my ($curr_is_adv,$curr_role_adv,$curr_author,$curr_role_author);
2860: $curr_author = $env{'user.author'};
2861: if (($env{'request.role'} =~/^au/) || ($env{'request.role'} =~/^ca/) ||
2862: ($env{'request.role'} =~/^aa/)) {
2863: $curr_role_author=1;
2864: }
2865: $curr_is_adv = $env{'user.adv'};
2866: $curr_role_adv = $env{'request.role.adv'};
2867: if (keys(%userroles) > 0) {
2868: foreach my $role (@changed_roles) {
2869: unless(grep(/^\Q$role\E$/,@rolecodes)) {
2870: push(@rolecodes,$role);
2871: }
2872: }
2873: unless(grep(/^\Qcm\E$/,@rolecodes)) {
2874: push(@rolecodes,'cm');
2875: }
2876: &Apache::lonnet::appenv(\%userroles,\@rolecodes);
2877: }
2878: my %newenv;
2879: if (&Apache::lonnet::is_advanced_user($env{'user.domain'},$env{'user.name'})) {
2880: unless ($curr_is_adv) {
2881: $newenv{'user.adv'} = 1;
2882: }
2883: } elsif ($curr_is_adv && !$curr_role_adv) {
2884: &Apache::lonnet::delenv('user.adv');
2885: }
2886: my %authorroleshash =
2887: &Apache::lonnet::get_my_roles('','','userroles',['active'],['au','ca','aa']);
2888: if (keys(%authorroleshash)) {
2889: unless ($curr_author) {
2890: $newenv{'user.author'} = 1;
2891: }
2892: } elsif ($curr_author && !$curr_role_author) {
2893: &Apache::lonnet::delenv('user.author');
2894: }
2895: if ($env{'request.course.id'}) {
2896: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
2897: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
2898: my (@activecrsgroups,$crsgroupschanged);
2899: if ($env{'request.course.groups'}) {
2900: @activecrsgroups = split(/:/,$env{'request.course.groups'});
2901: foreach my $item (keys(%deletedroles)) {
2902: if ($item =~ m{^gr\./\Q$cdom\E/\Q$cnum\E/(\w+)$}) {
2903: if (grep(/^\Q$1\E$/,@activecrsgroups)) {
2904: $crsgroupschanged = 1;
2905: last;
2906: }
2907: }
2908: }
2909: }
2910: unless ($crsgroupschanged) {
2911: foreach my $item (keys(%newgroup)) {
2912: if ($item =~ m{^gr\./\Q$cdom\E/\Q$cnum\E/(\w+)$}) {
2913: if ($newgroup{$item} eq 'active') {
2914: $crsgroupschanged = 1;
2915: last;
2916: }
2917: }
2918: }
2919: }
2920: if ((ref($changed_groups{$env{'request.course.id'}}) eq 'HASH') ||
2921: (ref($groupchange{"/$cdom/$cnum"}) eq 'HASH') ||
2922: ($crsgroupschanged)) {
2923: my %grouproles = &Apache::lonnet::get_my_roles('','','userroles',
2924: ['active'],['gr'],[$cdom],1);
2925: my @activegroups;
2926: foreach my $item (keys(%grouproles)) {
2927: next unless($item =~ /^\Q$cnum\E:\Q$cdom\E/);
2928: my $group;
2929: my ($crsn,$crsd,$role,$remainder) = split(/:/,$item,4);
2930: if ($remainder =~ /:/) {
2931: (my $other,$group) = ($remainder =~ /^([\w:]+):([^:]+)$/);
2932: } else {
2933: $group = $remainder;
2934: }
2935: if ($group ne '') {
2936: push(@activegroups,$group);
2937: }
2938: }
2939: $newenv{'request.course.groups'} = join(':',@activegroups);
2940: }
2941: }
2942: if (keys(%newenv)) {
2943: &Apache::lonnet::appenv(\%newenv);
2944: }
1.260 raeburn 2945: if (!@changed_roles || !(keys(%changed_groups))) {
1.264 raeburn 2946: my ($rolesmsg,$groupsmsg);
1.260 raeburn 2947: if (!@changed_roles) {
2948: if (&Apache::loncommon::show_course()) {
1.264 raeburn 2949: $rolesmsg = &mt('No new courses or communities');
1.260 raeburn 2950: } else {
1.264 raeburn 2951: $rolesmsg = &mt('No role changes');
1.260 raeburn 2952: }
2953: }
2954: if ($hasgroups && !(keys(%changed_groups)) && !(grep(/gr/,@changed_roles))) {
1.264 raeburn 2955: $groupsmsg = &mt('No changes in course/community groups');
1.260 raeburn 2956: }
2957: if (!@changed_roles && !(keys(%changed_groups))) {
1.264 raeburn 2958: if (($msg ne '') || ($groupsmsg ne '')) {
2959: $msg .= '<ul>';
2960: if ($rolesmsg) {
2961: $msg .= '<li>'.$rolesmsg.'</li>';
2962: }
2963: if ($groupsmsg) {
2964: $msg .= '<li>'.$groupsmsg.'</li>';
2965: }
2966: $msg .= '</ul>';
2967: } else {
1.269.2.2 raeburn 2968: $msg = ' <span class="LC_cusr_emph">'.$rolesmsg.'</span><br />';
1.264 raeburn 2969: }
1.260 raeburn 2970: return $msg;
2971: }
2972: }
2973: my $changemsg;
2974: if (@changed_roles > 0) {
2975: if (keys(%newgroup) > 0) {
2976: my $groupmsg;
1.269.2.6 raeburn 2977: my (%curr_groups,%groupdescs,$currcrs);
1.260 raeburn 2978: foreach my $item (sort(keys(%newgroup))) {
2979: if (&is_active_course($item,$refresh,$update,\%roleshash)) {
1.269.2.6 raeburn 2980: if ($item =~ m{^gr\./($match_domain/$match_courseid)/(\w+)$}) {
2981: my ($cdom,$cnum) = split(/\//,$1);
2982: my $group = $2;
2983: if ($currcrs ne $cdom.'_'.$cnum) {
2984: if ($currcrs) {
2985: $groupmsg .= '</ul><li>';
2986: }
2987: $groupmsg .= '<li><b>'.
2988: $env{'course.'.$cdom.'_'.$cnum.'.description'}.'</b><ul>';
1.269.2.7 raeburn 2989: $currcrs = $cdom.'_'.$cnum;
1.269.2.6 raeburn 2990: }
2991: my $groupdesc;
2992: unless (ref($curr_groups{$cdom.'_'.$cnum}) eq 'HASH') {
2993: %{$curr_groups{$cdom.'_'.$cnum}} =
2994: &Apache::longroup::coursegroups($cdom,$cnum);
2995: }
2996: unless ((ref($groupdescs{$cdom.'_'.$cnum}) eq 'HASH') &&
2997: ($groupdescs{$cdom.'_'.$cnum}{$group})) {
2998:
2999: my %groupinfo =
3000: &Apache::longroup::get_group_settings($curr_groups{$cdom.'_'.$cnum}{$group});
3001: $groupdescs{$cdom.'_'.$cnum}{$group} =
3002: &unescape($groupinfo{'description'});
3003: }
3004: $groupdesc = $groupdescs{$cdom.'_'.$cnum}{$group};
1.269.2.9 raeburn 3005: if ($groupdesc) {
3006: $groupmsg .= '<li>'.
3007: &mt('[_1] with status: [_2].',
3008: '<b>'.$groupdesc.'</b>',$newgroup{$item}).'</li>';
3009: }
1.269.2.6 raeburn 3010: }
3011: }
3012: if ($groupmsg) {
3013: $groupmsg .= '</ul></li>';
1.260 raeburn 3014: }
3015: }
3016: if ($groupmsg) {
3017: $changemsg .= '<li>'.
3018: &mt('Courses with new groups').'</li>'.
3019: '<ul>'.$groupmsg.'</ul></li>';
3020: }
3021: }
3022: if (keys(%newrole) > 0) {
1.269.2.9 raeburn 3023: my $newmsg;
1.260 raeburn 3024: foreach my $item (sort(keys(%newrole))) {
1.269.2.6 raeburn 3025: my $desc = &role_desc($item,$update,$refresh,$now);
1.269.2.9 raeburn 3026: if ($desc) {
3027: $newmsg .= '<li>'.
3028: &mt('[_1] with status: [_2].',
1.269.2.18 raeburn 3029: $desc,&mt($newrole{$item})).'</li>';
1.269.2.9 raeburn 3030: }
3031: }
3032: if ($newmsg) {
3033: $changemsg .= '<li>'.&mt('New roles').
3034: '<ul>'.$newmsg.'</ul>'.
3035: '</li>';
1.260 raeburn 3036: }
3037: }
3038: if (keys(%customprivchg) > 0) {
1.269.2.9 raeburn 3039: my $privmsg;
1.260 raeburn 3040: foreach my $item (sort(keys(%customprivchg))) {
1.269.2.6 raeburn 3041: my $desc = &role_desc($item,$update,$refresh,$now);
1.269.2.9 raeburn 3042: if ($desc) {
3043: $privmsg .= '<li>'.$desc.'</li>';
3044: }
1.260 raeburn 3045: }
1.269.2.9 raeburn 3046: if ($privmsg) {
3047: $changemsg .= '<li>'.
3048: &mt('Custom roles with privilege changes').
3049: '<ul>'.$privmsg.'</ul>'.
3050: '</li>';
3051: }
1.260 raeburn 3052: }
3053: if (keys(%rolechange) > 0) {
1.269.2.9 raeburn 3054: my $rolemsg;
1.260 raeburn 3055: foreach my $item (sort(keys(%rolechange))) {
1.269.2.9 raeburn 3056: my $desc = &role_desc($item,$update,$refresh,$now);
3057: if ($desc) {
3058: $rolemsg .= '<li>'.
3059: &mt('[_1] status now: [_2].',$desc,
3060: $rolechange{$item}).'</li>';
3061: }
3062: }
3063: if ($rolemsg) {
1.260 raeburn 3064: $changemsg .= '<li>'.
1.269.2.9 raeburn 3065: &mt('Existing roles with status changes').'</li>'.
3066: '<ul>'.$rolemsg.'</ul>'.
3067: '</li>';
1.260 raeburn 3068: }
3069: }
3070: if (keys(%deletedroles) > 0) {
1.269.2.9 raeburn 3071: my $delmsg;
1.260 raeburn 3072: foreach my $item (sort(keys(%deletedroles))) {
1.269.2.6 raeburn 3073: my $desc = &role_desc($item,$update,$refresh,$now);
1.269.2.9 raeburn 3074: if ($desc) {
3075: $delmsg .= '<li>'.$desc.'</li>';
3076: }
3077: }
3078: if ($delmsg) {
3079: $changemsg .= '<li>'.
3080: &mt('Existing roles now expired').'</li>'.
3081: '<ul>'.$delmsg.'</ul>'.
3082: '</li>';
1.260 raeburn 3083: }
3084: }
3085: }
3086: if ((keys(%changed_groups) > 0) || (keys(%groupchange) > 0)) {
3087: my $groupchgmsg;
3088: foreach my $key (sort(keys(%changed_groups))) {
3089: my $crs = 'gr/'.$key;
3090: $crs =~ s/_/\//;
3091: if (&is_active_course($crs,$refresh,$update,\%roleshash)) {
3092: if (ref($changed_groups{$key}) eq 'HASH') {
3093: my @showgroups;
3094: foreach my $group (sort(keys(%{$changed_groups{$key}}))) {
3095: if ($changed_groups{$key}{$group} eq 'active') {
3096: push(@showgroups,$group);
3097: }
3098: }
3099: if (@showgroups > 0) {
3100: $groupchgmsg .= '<li>'.
3101: &mt('Course: [_1], groups: [_2].',$key,
3102: join(', ',@showgroups)).
3103: '</li>';
3104: }
3105: }
3106: }
3107: }
3108: if (keys(%groupchange) > 0) {
3109: $groupchgmsg .= '<li>'.
3110: &mt('Existing course/community groups with status changes').'</li>'.
3111: '<ul>';
3112: foreach my $crs (sort(keys(%groupchange))) {
1.269.2.6 raeburn 3113: my $cid = $crs;
3114: $cid=~s{^/}{};
3115: $cid=~s{/}{_};
3116: my $crsdesc = $env{'course.'.$cid.'.description'};
3117: my $cdom = $env{'course.'.$cid.'.domain'};
3118: my $cnum = $env{'course.'.$cid.'.num'};
3119: my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum);
3120: my %groupdesc;
1.260 raeburn 3121: if (ref($groupchange{$crs}) eq 'HASH') {
1.269.2.6 raeburn 3122: $groupchgmsg .= '<li>'.&mt('Course/Community: [_1]','<b>'.$crsdesc.'</b><ul>');
1.260 raeburn 3123: foreach my $group (sort(keys(%{$groupchange{$crs}}))) {
1.269.2.6 raeburn 3124: unless ($groupdesc{$group}) {
3125: my %groupinfo = &Apache::longroup::get_group_settings($curr_groups{$group});
3126: $groupdesc{$group} = &unescape($groupinfo{'description'});
3127: }
3128: $groupchgmsg .= '<li>'.&mt('Group: [_1] status now: [_2].','<b>'.$groupdesc{$group}.'</b>',$groupchange{$crs}{$group}).'</li>';
1.260 raeburn 3129: }
3130: $groupchgmsg .= '</ul></li>';
3131: }
3132: }
3133: $groupchgmsg .= '</ul></li>';
3134: }
3135: if ($groupchgmsg) {
3136: $changemsg .= '<li>'.
3137: &mt('Courses with changes in groups').'</li>'.
3138: '<ul>'.$groupchgmsg.'</ul></li>';
3139: }
3140: }
3141: if ($changemsg) {
3142: $msg .= '<ul>'.$changemsg.'</ul>';
1.269.2.9 raeburn 3143: } else {
3144: if (&Apache::loncommon::show_course()) {
3145: $msg = &mt('No new courses or communities');
3146: } else {
3147: $msg = &mt('No role changes');
3148: }
1.260 raeburn 3149: }
1.269.2.6 raeburn 3150: return $msg;
3151: }
3152:
3153: sub role_desc {
3154: my ($item,$update,$refresh,$now) = @_;
3155: my ($where,$trolecode,$role,$tstatus,$tend,$tstart,$twhere,
3156: $trole,$tremark);
1.269.2.8 raeburn 3157: &Apache::lonnet::role_status('user.role.'.$item,$update,$refresh,
3158: $now,\$role,\$where,\$trolecode,
1.269.2.6 raeburn 3159: \$tstatus,\$tstart,\$tend);
1.269.2.9 raeburn 3160: return unless ($role);
1.269.2.6 raeburn 3161: if ($role =~ /^cr\//) {
3162: my ($rdummy,$rdomain,$rauthor,$rrole)=split(/\//,$role);
1.269.2.17 raeburn 3163: $tremark = &mt('Custom role defined by [_1].',$rauthor.':'.$rdomain);
1.269.2.6 raeburn 3164: }
3165: $trole=Apache::lonnet::plaintext($role);
3166: my ($tdom,$trest,$tsection)=
3167: split(/\//,Apache::lonnet::declutter($where));
3168: if (($role eq 'ca') || ($role eq 'aa')) {
3169: my $home = &Apache::lonnet::homeserver($trest,$tdom);
3170: $home = &Apache::lonnet::hostname($home);
3171: $twhere=&mt('User').': '.$trest.' '.&mt('Domain').
3172: ': '.$tdom.' '.&mt('Server').': '.$home;
3173: } elsif ($role eq 'au') {
3174: my $home = &Apache::lonnet::homeserver
3175: ($env{'user.name'},$env{'user.domain'});
3176: $home = &Apache::lonnet::hostname($home);
3177: $twhere=&mt('Domain').': '.$tdom.' '.&mt('Server').
3178: ': '.$home;
3179: } elsif ($trest) {
3180: my $tcourseid=$tdom.'_'.$trest;
3181: my $crstype = &Apache::loncommon::course_type($tcourseid);
3182: $trole = &Apache::lonnet::plaintext($role,$crstype,$tcourseid);
3183: if ($env{'course.'.$tcourseid.'.description'}) {
3184: $twhere=$env{'course.'.$tcourseid.'.description'};
3185: } else {
3186: my %newhash=&Apache::lonnet::coursedescription($tcourseid);
3187: if (%newhash) {
3188: $twhere=$newhash{'description'};
3189: } else {
3190: $twhere=&mt('Currently not available');
1.260 raeburn 3191: }
3192: }
1.269.2.6 raeburn 3193: if ($tsection) {
3194: $twhere.= ' '.&mt('Section').': '.$tsection;
1.260 raeburn 3195: }
1.269.2.6 raeburn 3196: if ($role ne 'st') {
3197: $twhere.= ' '.&mt('Domain').': '.$tdom;
1.260 raeburn 3198: }
1.269.2.6 raeburn 3199: } elsif ($tdom) {
3200: $twhere = &mt('Domain').': '.$tdom;
1.260 raeburn 3201: }
1.269.2.9 raeburn 3202: my $output;
3203: if ($trole) {
3204: $output = $trole;
3205: if ($twhere) {
3206: $output .= " -- $twhere";
3207: }
3208: if ($tremark) {
3209: $output .= '<br />'.$tremark;
3210: }
1.260 raeburn 3211: }
1.269.2.6 raeburn 3212: return $output;
1.260 raeburn 3213: }
3214:
3215: sub curr_role_status {
3216: my ($start,$end,$refresh,$update) = @_;
3217: if (($start) && ($start<0)) { return 'deleted' };
3218: my $status = 'active';
3219: if (($end) && ($end<=$update)) {
3220: $status = 'previous';
3221: }
3222: if (($start) && ($refresh<$start)) {
3223: $status = 'future';
3224: }
3225: return $status;
3226: }
3227:
3228: sub gather_roleprivs {
3229: my ($allroles,$allgroups,$userroles,$area,$role,$tstart,$tend,$status) = @_;
3230: return unless ((ref($allroles) eq 'HASH') && (ref($allgroups) eq 'HASH') && (ref($userroles) eq 'HASH'));
3231: if (($area ne '') && ($role ne '')) {
3232: &Apache::lonnet::userrolelog($role,$env{'user.name'},$env{'user.domain'},
3233: $area,$tstart,$tend);
3234: my $spec=$role.'.'.$area;
3235: $userroles->{'user.role.'.$spec} = $tstart.'.'.$tend;
3236: my ($tdummy,$tdomain,$trest)=split(/\//,$area);
3237: if ($status eq 'active') {
3238: if ($role =~ /^cr\//) {
3239: &Apache::lonnet::custom_roleprivs($allroles,$role,$tdomain,$trest,$spec,$area);
3240: } elsif ($role eq 'gr') {
3241: my %rolehash = &Apache::lonnet::get('roles',[$area.'_'.$role],
3242: $env{'user.domain'},
3243: $env{'user.name'});
3244: my ($trole) = split(/_/,$rolehash{$area.'_'.$role},2);
3245: (undef,my $group_privs) = split(/\//,$trole);
3246: $group_privs = &unescape($group_privs);
3247: &Apache::lonnet::group_roleprivs($allgroups,$area,$group_privs,$tend,$tstart);
3248: } else {
3249: &Apache::lonnet::standard_roleprivs($allroles,$role,$tdomain,$spec,$trest,$area);
3250: }
3251: }
3252: }
3253: return;
3254: }
3255:
3256: sub is_active_course {
3257: my ($rolekey,$refresh,$update,$roleshashref) = @_;
3258: return unless(ref($roleshashref) eq 'HASH');
3259: my ($role,$cdom,$cnum) = split(/\//,$rolekey);
3260: my $is_active;
3261: foreach my $key (keys(%{$roleshashref})) {
3262: if ($key =~ /^\Q$cnum\E:\Q$cdom\E:/) {
3263: my ($tstart,$tend) = split(/:/,$roleshashref->{$key});
3264: my $status = &curr_role_status($tstart,$tend,$refresh,$update);
3265: if ($status eq 'active') {
3266: $is_active = 1;
3267: last;
3268: }
3269: }
3270: }
3271: return $is_active;
3272: }
3273:
1.269.2.2 raeburn 3274: sub get_roles_functions {
1.269.2.18 raeburn 3275: my ($rolescount,$cattype) = @_;
1.269.2.2 raeburn 3276: my @links;
3277: push(@links,["javascript:rolesView('doupdate');",'start-here-22x22',&mt('Check for changes')]);
3278: if ($env{'environment.canrequest.author'}) {
3279: unless (&Apache::loncoursequeueadmin::is_active_author()) {
3280: push(@links,["javascript:rolesView('requestauthor');",'list-add-22x22',&mt('Request author role')]);
3281: }
3282: }
1.269.2.6 raeburn 3283: if (($rolescount > 3) || ($env{'environment.recentroles'})) {
3284: push(@links,['/adm/preferences?action=changerolespref&returnurl=/adm/roles','role_hotlist-22x22',&mt('Hotlist')]);
3285: }
1.269.2.2 raeburn 3286: if (&Apache::lonmenu::check_for_rcrs()) {
3287: push(@links,['/adm/requestcourse','rcrs-22x22',&mt('Request course')]);
3288: }
3289: if ($env{'form.state'} eq 'queued') {
3290: push(@links,["javascript:rolesView('noqueued');",'selfenrl-queue-22x22',&mt('Hide queued')]);
3291: } else {
3292: push(@links,["javascript:rolesView('queued');",'selfenrl-queue-22x22',&mt('Show queued')]);
3293: }
1.269.2.6 raeburn 3294: if ($env{'user.adv'}) {
3295: if ($env{'form.display'} eq 'showall') {
1.269.2.12 raeburn 3296: push(@links,["javascript:rolesView('noshowall');",'edit-redo-22x22',&mt('Exclude expired')]);
1.269.2.6 raeburn 3297: } else {
1.269.2.12 raeburn 3298: push(@links,["javascript:rolesView('showall');",'edit-undo-22x22',&mt('Include expired')]);
1.269.2.6 raeburn 3299: }
1.269.2.2 raeburn 3300: }
1.269.2.18 raeburn 3301: unless ($cattype eq 'none') {
1.269.2.13 raeburn 3302: push(@links,['/adm/coursecatalog','ccat-22x22',&mt('Course catalog')]);
1.269.2.12 raeburn 3303: }
1.269.2.26 raeburn 3304: my $funcs;
3305: if ($env{'browser.mobile'}) {
3306: my @functions;
3307: foreach my $link (@links) {
3308: push(@functions,[$link->[0],$link->[2]]);
3309: }
3310: my $title = 'Display options';
3311: if ($env{'user.adv'}) {
3312: $title = 'Roles options';
3313: }
3314: $funcs = &Apache::lonmenu::create_submenu('','',$title,\@functions,1,'LC_breadcrumbs_hoverable');
3315: $funcs = '<ol class="LC_primary_menu LC_floatright">'.$funcs.'</ol>';
3316: } else {
3317: $funcs = &Apache::lonhtmlcommon::start_funclist();
3318: foreach my $link (@links) {
3319: $funcs .= &Apache::lonhtmlcommon::add_item_funclist(
3320: '<a href="'.$link->[0].'" class="LC_menubuttons_link">'.
3321: '<img src="/res/adm/pages/'.$link->[1].'.png" class="LC_icon" alt="'.$link->[2].'" />'.
3322: $link->[2].'</a>');
3323: }
3324: $funcs .= &Apache::lonhtmlcommon::end_funclist();
3325: $funcs = &Apache::loncommon::head_subbox($funcs);
1.269.2.2 raeburn 3326: }
1.269.2.26 raeburn 3327: return $funcs;
1.269.2.2 raeburn 3328: }
3329:
3330: sub get_queued {
3331: my ($output,%reqcrs);
3332: my ($types,$typenames) = &Apache::loncommon::course_types();
3333: my %statusinfo = &Apache::lonnet::dump('courserequests',$env{'user.domain'},
3334: $env{'user.name'},'^status:');
3335: foreach my $key (keys(%statusinfo)) {
3336: next unless (($statusinfo{$key} eq 'approval') || ($statusinfo{$key} eq 'pending'));
1.269.2.16 raeburn 3337: (undef,my($cdom,$cnum)) = split(/:/,$key);
1.269.2.2 raeburn 3338: my $requestkey = $cdom.'_'.$cnum;
3339: if ($requestkey =~ /^($match_domain)_($match_courseid)$/) {
3340: my %history = &Apache::lonnet::restore($requestkey,'courserequests',
3341: $env{'user.domain'},$env{'user.name'});
3342: next if ((exists($history{'status'})) && ($history{'status'} eq 'created'));
3343: my $reqtime = $history{'reqtime'};
3344: my $lastupdate = $history{'timestamp'};
3345: my $showtype = $history{'crstype'};
3346: if (defined($typenames->{$history{'crstype'}})) {
3347: $showtype = $typenames->{$history{'crstype'}};
3348: }
3349: my $description;
3350: if (ref($history{'details'}) eq 'HASH') {
3351: $description = $history{details}{'cdescr'};
3352: }
3353: @{$reqcrs{$reqtime}} = ($description,$showtype);
3354: }
3355: }
3356: my @sortedtimes = sort {$a <=> $b} (keys(%reqcrs));
3357: if (@sortedtimes > 0) {
3358: $output .= '<p><b>'.&mt('Course/Community requests').'</b><br />'.
3359: &Apache::loncommon::start_data_table().
3360: &Apache::loncommon::start_data_table_header_row().
3361: '<th>'.&mt('Date requested').'</th>'.
3362: '<th>'.&mt('Course title').'</th>'.
3363: '<th>'.&mt('Course type').'</th>';
3364: &Apache::loncommon::end_data_table_header_row();
3365: foreach my $reqtime (@sortedtimes) {
3366: next unless (ref($reqcrs{$reqtime}) eq 'ARRAY');
3367: $output .= &Apache::loncommon::start_data_table_row().
3368: '<td>'.&Apache::lonlocal::locallocaltime($reqtime).'</td>'.
3369: '<td>'.join('</td><td>',@{$reqcrs{$reqtime}}).'</td>'.
3370: &Apache::loncommon::end_data_table_row();
3371: }
3372: $output .= &Apache::loncommon::end_data_table().
3373: '<br /></p>';
3374: }
3375: my $queuedselfenroll = &Apache::loncoursequeueadmin::queued_selfenrollment(1);
3376: if ($queuedselfenroll) {
3377: $output .= '<p><b>'.&mt('Enrollment requests').'</b><br />'.
3378: $queuedselfenroll.'<br /></p>';
3379: }
3380: if ($env{'environment.canrequest.author'}) {
3381: unless (&Apache::loncoursequeueadmin::is_active_author()) {
3382: my $requestauthor;
3383: my ($status,$timestamp) = split(/:/,$env{'environment.requestauthorqueued'});
3384: if (($status eq 'approval') || ($status eq 'approved')) {
3385: $output .= '<p><b>'.&mt('Author role request').'</b><br />';
3386: if ($status eq 'approval') {
1.269.2.18 raeburn 3387: $output .= &mt('A request for Authoring Space submitted on [_1] is awaiting approval',
1.269.2.2 raeburn 3388: &Apache::lonlocal::locallocaltime($timestamp));
3389: } elsif ($status eq 'approved') {
3390: my %roleshash =
3391: &Apache::lonnet::get_my_roles($env{'user.name'},$env{'user.domain'},'userroles',
3392: ['active'],['au'],[$env{'user.domain'}]);
3393: if (keys(%roleshash)) {
3394: $output .= '<span class="LC_info">'.
3395: &mt('Your request for an author role has been approved.').'<br />'.
3396: &mt('Use the "Check for changes" link to update your list of roles.').
3397: '</span>';
3398: }
3399: }
3400: $output .= '</p>';
3401: }
3402: }
3403: }
3404: unless ($output) {
3405: if ($env{'environment.canrequest.author'} || $env{'environment.canrequest.official'} ||
3406: $env{'environment.canrequest.unofficial'} || $env{'environment.canrequest.community'}) {
3407: $output = &mt('No requests for courses, communities or authoring currently queued');
3408: } else {
3409: $output = &mt('No enrollment requests currently queued awaiting approval');
3410: }
3411: }
3412: return '<div class="LC_left_float"><fieldset><legend>'.&mt('Queued requests').'</legend>'.
3413: $output.'</fieldset></div><br clear="all" />';
3414: }
3415:
1.269.2.39.2. (raeburn 3416:): sub set_deeplink_target {
3417:): my ($cnum,$cdom) = @_;
3418:): if (($cnum ne '') && ($cdom ne '')) {
3419:): my $deeplink_symb = &Apache::loncommon::deeplink_login_symb($cnum,$cdom);
3420:): if ($deeplink_symb ne '') {
3421:): my $deeplink;
3422:): if ($deeplink_symb =~ /\.(page|sequence)$/) {
3423:): my $mapname = &Apache::lonnet::deversion((&Apache::lonnet::decode_symb($deeplink_symb))[2]);
3424:): my $navmap = Apache::lonnavmaps::navmap->new();
3425:): if (ref($navmap)) {
3426:): $deeplink = $navmap->get_mapparam(undef,$mapname,'0.deeplink');
3427:): }
3428:): } elsif ($deeplink_symb ne '') {
3429:): $deeplink = &Apache::lonnet::EXT('resource.0.deeplink',$deeplink_symb);
3430:): }
3431:): if ($deeplink ne '') {
3432:): my ($state,$others,$listed,$scope,$protect,$display,$target) = split(/,/,$deeplink);
3433:): if ($target ne '') {
3434:): &Apache::lonnet::appenv({'request.deeplink.target' => $target});
3435:): } elsif (exists($env{'request.deeplink.target'})) {
3436:): &Apache::lonnet::delenv('request.deeplink.target');
3437:): }
3438:): }
3439:): }
3440:): }
3441:): return;
3442:): }
3443:):
1.1 harris41 3444: 1;
3445: __END__
1.32 harris41 3446:
3447: =head1 NAME
3448:
3449: Apache::lonroles - User Roles Screen
3450:
3451: =head1 SYNOPSIS
3452:
3453: Invoked by /etc/httpd/conf/srm.conf:
3454:
3455: <Location /adm/roles>
3456: PerlAccessHandler Apache::lonacc
3457: SetHandler perl-script
3458: PerlHandler Apache::lonroles
3459: ErrorDocument 403 /adm/login
3460: ErrorDocument 500 /adm/errorhandler
3461: </Location>
1.64 bowersj2 3462:
3463: =head1 OVERVIEW
3464:
3465: =head2 Choosing Roles
3466:
3467: C<lonroles> is a handler that allows a user to switch roles in
3468: mid-session. LON-CAPA attempts to work with "No Role Specified", the
3469: default role that a user has before selecting a role, as widely as
3470: possible, but certain handlers for example need specification which
3471: course they should act on, etc. Both in this scenario, and when the
3472: handler determines via C<lonnet>'s C<&allowed> function that a certain
3473: action is not allowed, C<lonroles> is used as error handler. This
3474: allows the user to select another role which may have permission to do
1.246 droeschl 3475: what they were trying to do.
1.64 bowersj2 3476:
3477: =begin latex
3478:
3479: \begin{figure}
3480: \begin{center}
3481: \includegraphics[width=0.45\paperwidth,keepaspectratio]{Sample_Roles_Screen}
3482: \caption{\label{Sample_Roles_Screen}Sample Roles Screen}
3483: \end{center}
3484: \end{figure}
3485:
3486: =end latex
3487:
3488: =head2 Role Initialization
3489:
3490: 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 3491:
3492: =head1 INTRODUCTION
3493:
3494: This module enables a user to select what role he wishes to
3495: operate under (instructor, student, teaching assistant, course
3496: coordinator, etc). These roles are pre-established by the actions
3497: of upper-level users.
3498:
3499: This is part of the LearningOnline Network with CAPA project
3500: described at http://www.lon-capa.org.
3501:
3502: =head1 HANDLER SUBROUTINE
3503:
3504: This routine is called by Apache and mod_perl.
3505:
3506: =over 4
3507:
3508: =item *
3509:
3510: Roles Initialization (yes/no)
3511:
3512: =item *
3513:
3514: Get Error Message from Environment
3515:
3516: =item *
3517:
3518: Who is this?
3519:
3520: =item *
3521:
3522: Generate Page Output
3523:
3524: =item *
3525:
3526: Choice or no choice
3527:
3528: =item *
3529:
3530: Table
3531:
3532: =item *
3533:
3534: Privileges
3535:
3536: =back
3537:
3538: =cut
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>