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