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