Annotation of loncom/auth/lonroles.pm, revision 1.270
1.1 harris41 1: # The LearningOnline Network with CAPA
2: # User Roles Screen
1.31 www 3: #
1.270 ! raeburn 4: # $Id: lonroles.pm,v 1.269 2012/07/21 21:09:03 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.1 harris41 131: use Apache::Constants qw(:common);
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.120 albertel 141: use GDBM_File;
1.170 albertel 142: use LONCAPA qw(:DEFAULT :match);
1.201 raeburn 143: use HTML::Entities;
1.149 www 144:
1.1 harris41 145:
1.62 matthew 146: sub redirect_user {
1.245 droeschl 147: my ($r,$title,$url,$msg) = @_;
1.62 matthew 148: $msg = $title if (! defined($msg));
1.73 www 149: &Apache::loncommon::content_type($r,'text/html');
1.62 matthew 150: &Apache::loncommon::no_cache($r);
151: $r->send_http_header;
1.228 bisitz 152:
153: # Breadcrumbs
154: my $brcrum = [{'href' => $url,
155: 'text' => 'Switching Role'},];
1.147 albertel 156: my $start_page = &Apache::loncommon::start_page('Switching Role',undef,
1.228 bisitz 157: {'redirect' => [1,$url],
158: 'bread_crumbs' => $brcrum,});
1.147 albertel 159: my $end_page = &Apache::loncommon::end_page();
160:
1.92 www 161: # Note to style police:
162: # This must only replace the spaces, nothing else, or it bombs elsewhere.
163: $url=~s/ /\%20/g;
1.93 albertel 164: $r->print(<<ENDREDIR);
1.147 albertel 165: $start_page
1.222 bisitz 166: <p>$msg</p>
1.147 albertel 167: $end_page
1.62 matthew 168: ENDREDIR
169: return;
170: }
171:
1.150 www 172: sub error_page {
173: my ($r,$error,$dest)=@_;
174: &Apache::loncommon::content_type($r,'text/html');
175: &Apache::loncommon::no_cache($r);
176: $r->send_http_header;
177: return OK if $r->header_only;
1.228 bisitz 178: # Breadcrumbs
179: my $brcrum = [{'href' => $dest,
180: 'text' => 'Problems during Course Initialization'},];
181: $r->print(&Apache::loncommon::start_page('Problems during Course Initialization',
182: undef,
183: {'bread_crumbs' => $brcrum,})
184: );
185: $r->print(
1.225 bisitz 186: '<script type="text/javascript">'.
187: '// <![CDATA['.
188: &Apache::lonmenu::rawconfig().
189: '// ]]>'.
190: '</script>'.
191: '<p class="LC_error">'.&mt('The following problems occurred:').
1.228 bisitz 192: '<br />'.
1.150 www 193: $error.
1.228 bisitz 194: '</p><br /><a href="'.$dest.'">'.&mt('Continue').'</a>'
195: );
196: $r->print(&Apache::loncommon::end_page());
1.150 www 197: }
198:
1.1 harris41 199: sub handler {
1.10 www 200:
1.1 harris41 201: my $r = shift;
202:
1.6 www 203: my $now=time;
1.118 albertel 204: my $then=$env{'user.login.time'};
1.226 raeburn 205: my $refresh=$env{'user.refresh.time'};
1.260 raeburn 206: my $update=$env{'user.update.time'};
1.226 raeburn 207: if (!$refresh) {
208: $refresh = $then;
209: }
1.260 raeburn 210: if (!$update) {
211: $update = $then;
212: }
213:
214: # -------------------------------------------------------- Check for new roles
215: my $updateresult;
216: if ($env{'form.doupdate'}) {
217: my $show_course=&Apache::loncommon::show_course();
218: my $checkingtxt;
219: if ($show_course) {
220: $checkingtxt = &mt('Checking for new courses ...');
221: } else {
222: $checkingtxt = &mt('Checking for new roles ...');
223: }
1.264 raeburn 224: $updateresult = '<span class="LC_info">'.$checkingtxt.'</span>';
1.260 raeburn 225: $updateresult .= &update_session_roles();
226: &Apache::lonnet::appenv({'user.update.time' => $now});
227: $update = $now;
1.270 ! raeburn 228: &reqauthor_check();
! 229: }
! 230:
! 231: # -------------------------------------------------- Check for author requests
! 232:
! 233: my $reqauthor;
! 234: if ($env{'form.requestauthor'}) {
! 235: if ($env{'environment.canrequest.author'}) {
! 236: unless (&is_active_author()) {
! 237: my $queued = &reqauthor_check();
! 238: my $skipreq;
! 239: if ($queued =~ /^approval:\d+$/) {
! 240: my ($status,$timestamp) = split(/:/,$env{'environment.requestauthorqueued'});
! 241: if ($status eq 'approval') {
! 242: $reqauthor = '<span class="LC_info">'.
! 243: &mt('A request for authoring space submitted on [_1] is awaiting approval',
! 244: &Apache::lonlocal::locallocaltime($timestamp)).
! 245: '</span>';
! 246: }
! 247: $skipreq = 1;
! 248: } elsif ($queued =~ /^approved:\d+$/) {
! 249: my %roleshash = &Apache::lonnet::get_my_roles($env{'user.name'},$env{'user.domain'},'userroles',
! 250: ['active'],['au'],[$env{'user.domain'}]);
! 251: if (keys(%roleshash) > 0) {
! 252: $skipreq = 1;
! 253: }
! 254: }
! 255: unless ($skipreq) {
! 256: my (@inststatuses,%domconfig);
! 257: %domconfig =
! 258: &Apache::lonnet::get_dom('configuration',
! 259: ['requestauthor'],$env{'user.domain'});
! 260: my $val = &Apache::loncoursequeueadmin::get_processtype('requestauthor',$env{'user.name'},
! 261: $env{'user.domain'},$env{'user.adv'},
! 262: $env{'user.domain'},undef,
! 263: \@inststatuses,\%domconfig);
! 264: if ($val eq 'automatic') {
! 265: if (&Apache::lonnet::assignrole($env{'user.domain'},$env{'user.name'},'/'.$env{'user.domain'}.'/',
! 266: 'au',undef,$now,undef,undef,'requestauthor') eq 'ok') {
! 267: $reqauthor = '<span class="LC_info">'.
! 268: &mt('Access to authoring space has been activated').'</span><br />';
! 269: &update_session_roles();
! 270: &Apache::lonnet::appenv({'user.update.time' => $now});
! 271: $update = $now;
! 272: } else {
! 273: $reqauthor = '<span class="LC_info">'.
! 274: &mt('An error occurred while activating your access to authoring space');
! 275: }
! 276: } elsif ($val eq 'approval') {
! 277: my $domconfiguser = &Apache::lonnet::get_domainconfiguser($env{'user.domain'});
! 278: if (&Apache::lonnet::put('requestauthorqueue',{ $env{'user.name'}.'_'.$val => $now },
! 279: $env{'user.domain'},$domconfiguser) eq 'ok') {
! 280: my %userrequest = (
! 281: author => {
! 282: timestamp => $now,
! 283: status => $val,
! 284: },
! 285: author_status => $val,
! 286: );
! 287: my $req_notifylist;
! 288: if (ref($domconfig{'requestauthor'}) eq 'HASH') {
! 289: if (ref($domconfig{'requestauthor'}{'notify'}) eq 'HASH') {
! 290: my $req_notifylist = $domconfig{'requestauthor'}{'notify'}{'approval'};
! 291: if ($req_notifylist) {
! 292: my $fullname = &Apache::loncommon::plainname($env{'user.name'},
! 293: $env{'user.domain'});
! 294: my $sender = $env{'user.name'}.':'.$env{'user.domain'};
! 295: my $domdesc = &Apache::lonnet::domain($env{'user.domain'},'description');
! 296: &Apache::loncoursequeueadmin::send_selfserve_notification($req_notifylist,
! 297: "$fullname ($env{'user.name'}:$env{'user.domain'})",undef,$domdesc,
! 298: $now,'authorreq',$sender);
! 299: }
! 300: }
! 301: }
! 302: my $userresult =
! 303: &Apache::lonnet::put('requestauthor',\%userrequest,$env{'user.domain'},$env{'user.name'});
! 304: $reqauthor = '<span class="LC_info">'.
! 305: &mt('Your request for authoring space has been submitted for approval.').
! 306: '</span>';
! 307: &Apache::lonnet::appenv({'environment.requestauthorqueued' => $val.':'.$now});
! 308: } else {
! 309: $reqauthor = '<span class="LC_info">'.
! 310: &mt('An error occurred saving your request for authoring space.').
! 311: '</span>';
! 312: }
! 313: }
! 314: }
! 315: }
! 316: }
1.260 raeburn 317: }
318:
1.6 www 319: my $envkey;
1.107 raeburn 320: my %dcroles = ();
1.260 raeburn 321: my $numdc = &check_fordc(\%dcroles,$update,$then);
1.148 albertel 322: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'});
1.255 raeburn 323: my $loncaparev = $Apache::lonnet::perlvar{'lonVersion'};
1.10 www 324:
1.6 www 325: # ================================================================== Roles Init
1.118 albertel 326: if ($env{'form.selectrole'}) {
1.188 www 327:
328: my $locknum=&Apache::lonnet::get_locks();
329: if ($locknum) { return 409; }
330:
1.134 www 331: if ($env{'form.newrole'}) {
332: $env{'form.'.$env{'form.newrole'}}=1;
333: }
1.118 albertel 334: if ($env{'request.course.id'}) {
1.185 raeburn 335: # Check if user is CC trying to select a course role
336: if ($env{'form.switchrole'}) {
1.252 raeburn 337: my $switch_is_active;
338: if (defined($env{'user.role.'.$env{'form.switchrole'}})) {
339: my ($start,$end) = split(/\./,$env{'user.role.'.$env{'form.switchrole'}});
340: if (!$end || $end > $now) {
1.260 raeburn 341: if (!$start || $start < $update) {
1.252 raeburn 342: $switch_is_active = 1;
343: }
344: }
345: }
346: unless ($switch_is_active) {
1.260 raeburn 347: &adhoc_course_role($refresh,$update,$then);
1.185 raeburn 348: }
349: }
1.118 albertel 350: my %temp=('logout_'.$env{'request.course.id'} => time);
1.33 www 351: &Apache::lonnet::put('email_status',\%temp);
1.118 albertel 352: &Apache::lonnet::delenv('user.state.'.$env{'request.course.id'});
1.100 albertel 353: }
1.186 raeburn 354: &Apache::lonnet::appenv({"request.course.id" => '',
355: "request.course.fn" => '',
356: "request.course.uri" => '',
357: "request.course.sec" => '',
1.269 raeburn 358: "request.course.tied" => '',
1.186 raeburn 359: "request.role" => 'cm',
360: "request.role.adv" => $env{'user.adv'},
361: "request.role.domain" => $env{'user.domain'}});
1.182 www 362: # Check if user is a DC trying to enter a course or author space and needs privs to be created
1.107 raeburn 363: if ($numdc > 0) {
1.118 albertel 364: foreach my $envkey (keys %env) {
1.240 raeburn 365: # Is this an ad-hoc Coordinator role?
366: if (my ($ccrole,$domain,$coursenum) =
367: ($envkey =~ m-^form\.(cc|co)\./($match_domain)/($match_courseid)$-)) {
1.146 raeburn 368: if ($dcroles{$domain}) {
1.218 raeburn 369: &Apache::lonnet::check_adhoc_privs($domain,$coursenum,
1.260 raeburn 370: $update,$refresh,$now,$ccrole);
1.182 www 371: }
372: last;
373: }
1.193 raeburn 374: # Is this an ad-hoc CA-role?
1.183 www 375: if (my ($domain,$user) =
376: ($envkey =~ m-^form\.ca\./($match_domain)/($match_username)$-)) {
1.206 raeburn 377: if (($domain eq $env{'user.domain'}) && ($user eq $env{'user.name'})) {
378: delete($env{$envkey});
379: $env{'form.au./'.$domain.'/'} = 1;
380: my ($server_status,$home) = &check_author_homeserver($user,$domain);
381: if ($server_status eq 'switchserver') {
382: my $trolecode = 'au./'.$domain.'/';
1.248 raeburn 383: my $switchserver = '/adm/switchserver?otherserver='.$home.'&role='.$trolecode;
1.206 raeburn 384: $r->internal_redirect($switchserver);
385: }
386: last;
387: }
388: if (my ($castart,$caend) = ($env{'user.role.ca./'.$domain.'/'.$user} =~ /^(\d*)\.(\d*)$/)) {
389: if (((($castart) && ($castart < $now)) || !$castart) &&
390: ((!$caend) || (($caend) && ($caend > $now)))) {
391: my ($server_status,$home) = &check_author_homeserver($user,$domain);
392: if ($server_status eq 'switchserver') {
393: my $trolecode = 'ca./'.$domain.'/'.$user;
1.248 raeburn 394: my $switchserver = '/adm/switchserver?otherserver='.$home.'&role='.$trolecode;
1.206 raeburn 395: $r->internal_redirect($switchserver);
396: }
397: last;
398: }
399: }
400: # Check if author blocked ca-access
1.190 www 401: my %blocked=&Apache::lonnet::get('environment',['domcoord.author'],$domain,$user);
402: if ($blocked{'domcoord.author'} eq 'blocked') {
1.206 raeburn 403: delete($env{$envkey});
404: $env{'user.error.msg'}=':::1:User '.$user.' in domain '.$domain.' blocked domain coordinator access';
405: last;
1.190 www 406: }
1.193 raeburn 407: if ($dcroles{$domain}) {
408: my ($server_status,$home) = &check_author_homeserver($user,$domain);
409: if (($server_status eq 'ok') || ($server_status eq 'switchserver')) {
1.260 raeburn 410: &Apache::lonnet::check_adhoc_privs($domain,$user,$update,
1.230 raeburn 411: $refresh,$now,'ca');
1.193 raeburn 412: if ($server_status eq 'switchserver') {
413: my $trolecode = 'ca./'.$domain.'/'.$user;
414: my $switchserver = '/adm/switchserver?'
1.248 raeburn 415: .'otherserver='.$home.'&role='.$trolecode;
1.193 raeburn 416: $r->internal_redirect($switchserver);
417: }
418: } else {
419: delete($env{$envkey});
420: }
1.183 www 421: } else {
422: delete($env{$envkey});
1.182 www 423: }
424: last;
425: }
1.107 raeburn 426: }
427: }
428:
1.118 albertel 429: foreach $envkey (keys %env) {
1.40 matthew 430: next if ($envkey!~/^user\.role\./);
1.102 raeburn 431: my ($where,$trolecode,$role,$tstatus,$tend,$tstart);
1.260 raeburn 432: &Apache::lonnet::role_status($envkey,$update,$refresh,$now,\$role,\$where,
1.218 raeburn 433: \$trolecode,\$tstatus,\$tstart,\$tend);
1.118 albertel 434: if ($env{'form.'.$trolecode}) {
1.55 albertel 435: if ($tstatus eq 'is') {
436: $where=~s/^\///;
437: my ($cdom,$cnum,$csec)=split(/\//,$where);
1.255 raeburn 438: if (($cnum) && ($role ne 'ca') && ($role ne 'aa')) {
439: my $home = $env{'course.'.$cdom.'_'.$cnum.'.home'};
440: my @ids = &Apache::lonnet::current_machine_ids();
441: unless ($loncaparev eq '' && $home && grep(/^\Q$home\E$/,@ids)) {
442: my %curr_reqd_hash = &Apache::lonnet::userenvironment($cdom,$cnum,'internal.releaserequired');
1.256 raeburn 443: if ($curr_reqd_hash{'internal.releaserequired'} ne '') {
1.255 raeburn 444: my ($switchserver,$switchwarning) =
445: &check_release_required($loncaparev,$cdom.'_'.$cnum,$trolecode,$curr_reqd_hash{'internal.releaserequired'});
1.256 raeburn 446: if ($switchwarning ne '' || $switchserver ne '') {
447: &Apache::loncommon::content_type($r,'text/html');
448: &Apache::loncommon::no_cache($r);
449: $r->send_http_header;
450: my $end_page=&Apache::loncommon::end_page();
451: $r->print(&Apache::loncommon::start_page('Selected course unavailable on this server').
452: '<p class="LC_warning">');
453: if ($switchwarning) {
454: $r->print($switchwarning.'<br /><a href="/adm/roles">');
455: if (&Apache::loncommon::show_course()) {
456: $r->print(&mt('Display courses'));
457: } else {
458: $r->print(&mt('Display roles'));
459: }
460: $r->print('</a>');
461: } elsif ($switchserver) {
462: $r->print(&mt('This course requires a newer version of LON-CAPA than is installed on this server.').
463: '<br />'.
464: '<a href="/adm/switchserver?'.$switchserver.'">'.
465: &mt('Switch Server').
466: '</a>');
1.255 raeburn 467: }
1.256 raeburn 468: $r->print('</p>'.&Apache::loncommon::end_page());
469: return OK;
1.255 raeburn 470: }
471: }
472: }
473: }
1.137 raeburn 474: # check for course groups
475: my %coursegroups = &Apache::lonnet::get_active_groups(
476: $env{'user.domain'},$env{'user.name'},$cdom, $cnum);
477: my $cgrps = join(':',keys(%coursegroups));
478:
1.111 albertel 479: # store role if recent_role list being kept
1.118 albertel 480: if ($env{'environment.recentroles'}) {
1.158 albertel 481: my %frozen_roles =
482: &Apache::lonhtmlcommon::get_recent_frozen('roles',$env{'environment.recentrolesn'});
1.111 albertel 483: &Apache::lonhtmlcommon::store_recent('roles',
1.158 albertel 484: $trolecode,' ',$frozen_roles{$trolecode});
1.111 albertel 485: }
486:
487:
1.53 www 488: # check for keyed access
1.55 albertel 489: if (($role eq 'st') &&
1.118 albertel 490: ($env{'course.'.$cdom.'_'.$cnum.'.keyaccess'} eq 'yes')) {
1.89 www 491: # who is key authority?
492: my $authdom=$cdom;
493: my $authnum=$cnum;
1.118 albertel 494: if ($env{'course.'.$cdom.'_'.$cnum.'.keyauth'}) {
1.89 www 495: ($authnum,$authdom)=
1.172 albertel 496: split(/:/,$env{'course.'.$cdom.'_'.$cnum.'.keyauth'});
1.89 www 497: }
498: # check with key authority
499: unless (&Apache::lonnet::validate_access_key(
1.118 albertel 500: $env{'environment.key.'.$cdom.'_'.$cnum},
1.89 www 501: $authdom,$authnum)) {
1.53 www 502: # there is no valid key
1.118 albertel 503: if ($env{'form.newkey'}) {
1.53 www 504: # student attempts to register a new key
1.89 www 505: &Apache::loncommon::content_type($r,'text/html');
506: &Apache::loncommon::no_cache($r);
507: $r->send_http_header;
508: my $swinfo=&Apache::lonmenu::rawconfig();
1.147 albertel 509: my $start_page=&Apache::loncommon::start_page
1.89 www 510: ('Verifying Access Key to Unlock this Course');
1.147 albertel 511: my $end_page=&Apache::loncommon::end_page();
1.90 www 512: my $buttontext=&mt('Enter Course');
513: my $message=&mt('Successfully registered key');
514: my $assignresult=
515: &Apache::lonnet::assign_access_key(
1.118 albertel 516: $env{'form.newkey'},
1.90 www 517: $authdom,$authnum,
1.91 www 518: $cdom,$cnum,
1.118 albertel 519: $env{'user.domain'},
520: $env{'user.name'},
1.204 bisitz 521: &mt('Assigned from [_1] at [_2] for [_3]'
522: ,$ENV{'REMOTE_ADDR'}
523: ,&Apache::lonlocal::locallocaltime()
524: ,$trolecode)
525: );
1.90 www 526: unless ($assignresult eq 'ok') {
527: $assignresult=~s/^error\:\s*//;
528: $message=&mt($assignresult).
529: '<br /><a href="/adm/logout">'.
1.89 www 530: &mt('Logout').'</a>';
1.90 www 531: $buttontext=&mt('Re-Enter Key');
532: }
1.89 www 533: $r->print(<<ENDENTEREDKEY);
1.147 albertel 534: $start_page
1.179 raeburn 535: <script type="text/javascript">
1.225 bisitz 536: // <![CDATA[
1.89 www 537: $swinfo
1.225 bisitz 538: // ]]>
1.89 www 539: </script>
1.225 bisitz 540: <form action="" method="post">
1.89 www 541: <input type="hidden" name="selectrole" value="1" />
542: <input type="hidden" name="$trolecode" value="1" />
1.211 tempelho 543: <span class="LC_fontsize_large">$message</span><br />
1.89 www 544: <input type="submit" value="$buttontext" />
545: </form>
1.147 albertel 546: $end_page
1.89 www 547: ENDENTEREDKEY
548: return OK;
1.55 albertel 549: } else {
1.53 www 550: # print form to enter a new key
1.73 www 551: &Apache::loncommon::content_type($r,'text/html');
1.55 albertel 552: &Apache::loncommon::no_cache($r);
553: $r->send_http_header;
554: my $swinfo=&Apache::lonmenu::rawconfig();
1.147 albertel 555: my $start_page=&Apache::loncommon::start_page
1.55 albertel 556: ('Enter Access Key to Unlock this Course');
1.147 albertel 557: my $end_page=&Apache::loncommon::end_page();
1.55 albertel 558: $r->print(<<ENDENTERKEY);
1.147 albertel 559: $start_page
1.179 raeburn 560: <script type="text/javascript">
1.225 bisitz 561: // <![CDATA[
1.53 www 562: $swinfo
1.225 bisitz 563: // ]]>
1.53 www 564: </script>
1.225 bisitz 565: <form action="" method="post">
1.89 www 566: <input type="hidden" name="selectrole" value="1" />
567: <input type="hidden" name="$trolecode" value="1" />
1.118 albertel 568: <input type="text" size="20" name="newkey" value="$env{'form.newkey'}" />
1.53 www 569: <input type="submit" value="Enter key" />
570: </form>
1.147 albertel 571: $end_page
1.53 www 572: ENDENTERKEY
1.55 albertel 573: return OK;
574: }
575: }
576: }
1.118 albertel 577: &Apache::lonnet::log($env{'user.domain'},
578: $env{'user.name'},
579: $env{'user.home'},
1.87 www 580: "Role ".$trolecode);
1.101 albertel 581:
1.56 www 582: &Apache::lonnet::appenv(
1.186 raeburn 583: {'request.role' => $trolecode,
584: 'request.role.domain' => $cdom,
585: 'request.course.sec' => $csec,
586: 'request.course.groups' => $cgrps});
1.101 albertel 587: my $tadv=0;
1.62 matthew 588:
1.125 www 589: if (($cnum) && ($role ne 'ca') && ($role ne 'aa')) {
1.152 raeburn 590: my $msg;
1.55 albertel 591: my ($furl,$ferr)=
592: &Apache::lonuserstate::readmap($cdom.'/'.$cnum);
1.118 albertel 593: if (($env{'form.orgurl'}) &&
594: ($env{'form.orgurl'}!~/^\/adm\/flip/)) {
595: my $dest=$env{'form.orgurl'};
1.219 raeburn 596: if ($env{'form.symb'}) {
597: if ($dest =~ /\?/) {
598: $dest .= '&';
599: } else {
600: $dest .= '?'
601: }
602: $dest .= 'symb='.$env{'form.symb'};
603: }
1.117 albertel 604: if (&Apache::lonnet::allowed('adv') eq 'F') { $tadv=1; }
1.186 raeburn 605: &Apache::lonnet::appenv({'request.role.adv'=>$tadv});
1.150 www 606: if (($ferr) && ($tadv)) {
607: &error_page($r,$ferr,$dest);
608: } else {
1.255 raeburn 609: if ($dest =~ m{^/adm/coursedocs\?folderpath}) {
610: if ($env{'request.course.id'} eq $cdom.'_'.$cnum) {
611: my $chome = &Apache::lonnet::homeserver($cnum,$cdom);
1.268 raeburn 612: &Apache::loncommon::update_content_constraints($cdom,$cnum,$chome,
613: $cdom.'_'.$cnum);
1.255 raeburn 614: }
615: }
1.150 www 616: $r->internal_redirect($dest);
617: }
1.55 albertel 618: return OK;
619: } else {
1.155 albertel 620: if (!$env{'request.course.id'}) {
1.55 albertel 621: &Apache::lonnet::appenv(
1.186 raeburn 622: {"request.course.id" => $cdom.'_'.$cnum});
1.61 www 623: $furl='/adm/roles?tryagain=1';
1.221 bisitz 624: $msg='<p><span class="LC_error">'
625: .&mt('Could not initialize [_1] at this time.',
626: $env{'course.'.$cdom.'_'.$cnum.'.description'})
627: .'</span></p>'
628: .'<p>'.&mt('Please try again.').'</p>'
629: .'<p>'.$ferr.'</p>';
1.55 albertel 630: }
1.117 albertel 631: if (&Apache::lonnet::allowed('adv') eq 'F') { $tadv=1; }
1.186 raeburn 632: &Apache::lonnet::appenv({'request.role.adv'=>$tadv});
1.152 raeburn 633:
1.150 www 634: if (($ferr) && ($tadv)) {
635: &error_page($r,$ferr,$furl);
636: } else {
637: # Check to see if the user is a CC entering a course
638: # for the first time
639: my (undef, undef, $role, $courseid) = split(/\./, $envkey);
640: if (substr($courseid, 0, 1) eq '/') {
641: $courseid = substr($courseid, 1);
642: }
643: $courseid =~ s/\//_/;
1.240 raeburn 644: if ((($role eq 'cc') || ($role eq 'co'))
645: && ($env{'course.' . $courseid .'.course.helper.not.run'})) {
1.150 www 646: $furl = "/adm/helper/course.initialization.helper";
647: # Send the user to the course they selected
648: } elsif ($env{'request.course.id'}) {
1.185 raeburn 649: if ($env{'form.destinationurl'}) {
650: my $dest = $env{'form.destinationurl'};
1.203 raeburn 651: if ($env{'form.destsymb'} ne '') {
652: my $esc_symb = &HTML::Entities::encode($env{'form.destsymb'},'"<>&');
653: $dest .= '?symb='.$esc_symb;
654: }
1.245 droeschl 655: &redirect_user($r, &mt('Entering [_1]',
656: $env{'course.'.$courseid.'.description'}),
657: $dest, $msg);
1.185 raeburn 658: return OK;
659: }
1.150 www 660: if (&Apache::lonnet::allowed('whn',
661: $env{'request.course.id'})
662: || &Apache::lonnet::allowed('whn',
663: $env{'request.course.id'}.'/'
664: .$env{'request.course.sec'})
665: ) {
666: my $startpage = &courseloadpage($courseid);
667: unless ($startpage eq 'firstres') {
1.204 bisitz 668: $msg = &mt('Entering [_1] ...',
1.162 albertel 669: $env{'course.'.$courseid.'.description'});
1.245 droeschl 670: &redirect_user($r, &mt('New in course'),
671: '/adm/whatsnew?refpage=start', $msg);
1.150 www 672: return OK;
673: }
674: }
675: }
1.151 www 676: # Are we allowed to look at the first resource?
1.169 albertel 677: if ($furl !~ m|^/adm/|) {
1.151 www 678: # Guess not ...
679: $furl=&Apache::lonpageflip::first_accessible_resource();
680: }
1.162 albertel 681: $msg = &mt('Entering [_1] ...',
682: $env{'course.'.$courseid.'.description'});
1.245 droeschl 683: &redirect_user($r, &mt('Entering [_1]',
684: $env{'course.'.$courseid.'.description'}),
685: $furl, $msg);
1.58 bowersj2 686: }
1.124 albertel 687: return OK;
1.55 albertel 688: }
689: }
1.62 matthew 690: #
691: # Send the user to the construction space they selected
1.125 www 692: if ($role =~ /^(au|ca|aa)$/) {
1.62 matthew 693: my $redirect_url = '/priv/';
694: if ($role eq 'au') {
1.262 www 695: $redirect_url.=$env{'user.domain'}.'/'.$env{'user.name'};
1.62 matthew 696: } else {
1.263 www 697: $redirect_url .= $where;
1.62 matthew 698: }
699: $redirect_url .= '/';
1.78 sakharuk 700: &redirect_user($r,&mt('Entering Construction Space'),
1.62 matthew 701: $redirect_url);
702: return OK;
703: }
1.104 raeburn 704: if ($role eq 'dc') {
1.108 raeburn 705: my $redirect_url = '/adm/menu/';
706: &redirect_user($r,&mt('Loading Domain Coordinator Menu'),
1.104 raeburn 707: $redirect_url);
1.108 raeburn 708: return OK;
1.104 raeburn 709: }
1.220 raeburn 710: if ($role eq 'sc') {
711: my $redirect_url = '/adm/grades?command=scantronupload';
712: &redirect_user($r,&mt('Loading Data Upload Page'),
713: $redirect_url);
714: return OK;
715: }
1.55 albertel 716: }
717: }
1.6 www 718: }
1.40 matthew 719: }
1.44 www 720:
1.10 www 721:
1.6 www 722: # =============================================================== No Roles Init
1.10 www 723:
1.73 www 724: &Apache::loncommon::content_type($r,'text/html');
1.30 albertel 725: &Apache::loncommon::no_cache($r);
1.10 www 726: $r->send_http_header;
727: return OK if $r->header_only;
728:
1.224 raeburn 729: my $crumbtext = 'User Roles';
730: my $pagetitle = 'My Roles';
731: my $recent = &mt('Recent Roles');
732: my $show_course=&Apache::loncommon::show_course();
733: if ($show_course) {
734: $crumbtext = 'Courses';
735: $pagetitle = 'My Courses';
736: $recent = &mt('Recent Courses');
737: }
738: my $brcrum =[{href=>"/adm/roles",text=>$crumbtext}];
1.52 www 739: my $swinfo=&Apache::lonmenu::rawconfig();
1.224 raeburn 740: my $start_page=&Apache::loncommon::start_page($pagetitle,undef,{bread_crumbs=>$brcrum});
1.134 www 741: my $standby=&mt('Role selected. Please stand by.');
1.135 albertel 742: $standby=~s/\n/\\n/g;
1.184 raeburn 743: my $noscript='<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 744:
1.10 www 745: $r->print(<<ENDHEADER);
1.147 albertel 746: $start_page
1.163 www 747: <br />
1.179 raeburn 748: <noscript>
749: $noscript
750: </noscript>
751: <script type="text/javascript">
1.225 bisitz 752: // <![CDATA[
1.26 www 753: $swinfo
754: window.focus();
1.134 www 755:
756: active=true;
757:
758: function enterrole (thisform,rolecode,buttonname) {
759: if (active) {
760: active=false;
761: document.title='$standby';
762: window.status='$standby';
763: thisform.newrole.value=rolecode;
764: thisform.submit();
765: } else {
766: alert('$standby');
1.260 raeburn 767: }
768: }
769:
770: function setToUpdate(thisform) {
771: thisform.doupdate.value='1';
772: thisform.selectrole.value='';
773: thisform.submit();
1.134 www 774: }
1.260 raeburn 775:
1.270 ! raeburn 776: function setToRequestAuthor(thisform) {
! 777: thisform.requestauthor.value='1';
! 778: thisform.selectrole.value='';
! 779: thisform.submit();
! 780: }
! 781:
1.225 bisitz 782: // ]]>
1.26 www 783: </script>
1.10 www 784: ENDHEADER
1.6 www 785:
1.2 www 786: # ------------------------------------------ Get Error Message from Environment
787:
1.118 albertel 788: my ($fn,$priv,$nochoose,$error,$msg)=split(/:/,$env{'user.error.msg'});
789: if ($env{'user.error.msg'}) {
1.55 albertel 790: $r->log_reason(
1.118 albertel 791: "$msg for $env{'user.name'} domain $env{'user.domain'} access $priv",$fn);
1.12 www 792: }
1.1 harris41 793:
1.61 www 794: # ------------------------------------------------- Can this user re-init, etc?
1.6 www 795:
1.118 albertel 796: my $advanced=$env{'user.adv'};
1.61 www 797: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['tryagain']);
1.118 albertel 798: my $tryagain=$env{'form.tryagain'};
1.209 raeburn 799: my $reinit=$env{'user.reinit'};
800: delete $env{'user.reinit'};
1.6 www 801:
1.2 www 802: # -------------------------------------------------------- Generate Page Output
1.6 www 803: # --------------------------------------------------------------- Error Header?
1.2 www 804: if ($error) {
1.187 bisitz 805: $r->print("<h1>".&mt('LON-CAPA Access Control')."</h1>");
1.174 albertel 806: $r->print("<!-- LONCAPAACCESSCONTROLERRORSCREEN --><hr /><pre>");
807: if ($priv ne '') {
1.187 bisitz 808: $r->print(&mt('Access : ').&Apache::lonnet::plaintext($priv)."\n");
1.174 albertel 809: }
810: if ($fn ne '') {
1.187 bisitz 811: $r->print(&mt('Resource: ').&Apache::lonenc::check_encrypt($fn)."\n");
1.174 albertel 812: }
813: if ($msg ne '') {
1.187 bisitz 814: $r->print(&mt('Action : ').$msg."\n");
1.174 albertel 815: }
816: $r->print("</pre><hr />");
1.120 albertel 817: my $url=$fn;
818: my $last;
819: if (tie(my %hash,'GDBM_File',$env{'request.course.fn'}.'_symb.db',
820: &GDBM_READER(),0640)) {
821: $last=$hash{'last_known'};
822: untie(%hash);
823: }
1.149 www 824: if ($last) { $fn.='?symb='.&escape($last); }
1.120 albertel 825:
826: &Apache::londocs::changewarning($r,undef,'You have modified your course recently, [_1] may fix this access problem.',
827: &Apache::lonenc::check_encrypt($fn));
1.2 www 828: } else {
1.118 albertel 829: if ($env{'user.error.msg'}) {
1.209 raeburn 830: if ($reinit) {
831: $r->print(
832: '<h3><span class="LC_error">'.
1.234 raeburn 833: &mt('As your session file for the course or community has expired, you will need to re-select it.').'</span></h3>');
1.209 raeburn 834: } else {
835: $r->print(
1.157 albertel 836: '<h3><span class="LC_error">'.
1.235 bisitz 837: &mt('You need to choose another user role or enter a specific course or community for this function.').
838: '</span></h3>');
1.209 raeburn 839: }
840: }
1.2 www 841: }
842: if ($nochoose) {
1.177 www 843: $r->print("<h2>".&mt('Sorry ...')."</h2>\n<span class='LC_error'>".
844: &mt('This action is currently not authorized.').'</span>'.
1.150 www 845: &Apache::loncommon::end_page());
846: return OK;
1.6 www 847: } else {
1.270 ! raeburn 848: if ($updateresult || $reqauthor) {
! 849: $r->print('<div>'.
! 850: $updateresult.
! 851: $reqauthor.
! 852: '</div>');
! 853: }
1.18 www 854: if (($ENV{'REDIRECT_QUERY_STRING'}) && ($fn)) {
855: $fn.='?'.$ENV{'REDIRECT_QUERY_STRING'};
1.6 www 856: }
1.84 www 857: $r->print('<form method="post" name="rolechoice" action="'.(($fn)?$fn:$r->uri).'">');
1.116 albertel 858: $r->print('<input type="hidden" name="orgurl" value="'.$fn.'" />');
859: $r->print('<input type="hidden" name="selectrole" value="1" />');
1.134 www 860: $r->print('<input type="hidden" name="newrole" value="" />');
1.6 www 861: }
1.259 raeburn 862: $r->rflush();
1.226 raeburn 863:
864: my (%roletext,%sortrole,%roleclass,%futureroles,%timezones);
865: my ($countactive,$countfuture,$inrole,$possiblerole) =
1.260 raeburn 866: &gather_roles($update,$refresh,$now,$reinit,$nochoose,\%roletext,\%sortrole,\%roleclass,
1.254 raeburn 867: \%futureroles,\%timezones,$loncaparev);
1.226 raeburn 868: $refresh = $now;
869: &Apache::lonnet::appenv({'user.refresh.time' => $refresh});
1.260 raeburn 870: my $updatebutton = &mt('Check for role changes');
871: my $show_course=&Apache::loncommon::show_course();
872: if ($show_course) {
873: $updatebutton = &mt('Check for new courses');
874: }
875: my $do_update;
876: unless (($env{'form.source'} eq 'login') || ($env{'form.doupdate'})) {
877: $do_update = '<input type="hidden" name="doupdate" value="" />'.
878: '<input type="button" name="update" value="'.
879: $updatebutton.'" onclick="javascript:setToUpdate(this.form)" />';
880: }
1.270 ! raeburn 881: my ($requestauthor,$requestcrs);
! 882: unless ($reqauthor) {
! 883: if ($env{'environment.canrequest.author'}) {
! 884: unless (&is_active_author()) {
! 885: my ($status,$timestamp) = split(/:/,$env{'environment.requestauthorqueued'});
! 886: if ($status eq 'approval') {
! 887: $requestauthor = &mt('A request for authoring space submitted on [_1] is awaiting approval',&Apache::lonlocal::locallocaltime($timestamp));
! 888: } elsif (($status eq 'approved') && ($do_update)) {
! 889: my %roleshash = &Apache::lonnet::get_my_roles($env{'user.name'},$env{'user.domain'},'userroles',
! 890: ['active'],['au'],[$env{'user.domain'}]);
! 891: if (keys(%roleshash)) {
! 892: $requestauthor = &mt('Your request for an author role has been approved.').'<br />';
! 893: if ($show_course) {
! 894: $requestauthor .= &mt('Use the "Check for new courses" button to update your list of roles.');
! 895: } else {
! 896: $requestauthor .= &mt('Use the "Check for new roles" button to update your list of roles.');
! 897: }
! 898: $requestauthor = '<span class="LC_info">'.$requestauthor.'</span>';
! 899: }
! 900: }
! 901: unless ($requestauthor) {
! 902: $requestauthor =
! 903: '<input type="hidden" name="requestauthor" value="" />'.
! 904: '<input type="button" name="reqauthor" value="'.
! 905: &mt('Request author space').'" '.
! 906: 'onclick="javascript:setToRequestAuthor(this.form)" />';
! 907: }
! 908: }
! 909: }
! 910: }
! 911: my $do_update;
! 912: unless (($env{'form.source'} eq 'login') || ($env{'form.doupdate'})) {
! 913: $do_update = '<input type="hidden" name="doupdate" value="" />'.
! 914: '<input type="button" name="update" value="'.
! 915: $updatebutton.'" onclick="javascript:setToUpdate(this.form)" />';
! 916: }
1.196 raeburn 917: if ($env{'user.adv'}) {
1.260 raeburn 918: my $showall = '<label><input type="checkbox" name="showall"';
919: if ($env{'form.showall'}) {
920: $showall .= ' checked="checked" ';
921: }
1.264 raeburn 922: $showall .= ' />'.&mt('Show all roles').'</label> '.
1.260 raeburn 923: '<input type="submit" value="'.&mt('Update display').'" />';
1.270 ! raeburn 924: if ($do_update || $requestauthor) {
1.260 raeburn 925: $r->print('<div class="LC_left_float"><fieldset>'.
926: '<legend>'. &mt('Display').'</legend>'.
1.270 ! raeburn 927: $showall.'</fieldset></div>');
! 928: if ($do_update) {
! 929: $r->print('<div class="LC_left_float">'.
! 930: '<fieldset><legend>'.&mt('Changes?').'</legend>'.
! 931: $do_update.'</fieldset></div>');
! 932: }
! 933: if ($requestauthor) {
! 934: $r->print('<div class="LC_left_float">'.
! 935: '<fieldset><legend>'.&mt('Add author role').'</legend>'.
! 936: $requestauthor.'</fieldset>');
! 937: }
! 938: $r->print('</div><br clear="all" />');
1.260 raeburn 939: } else {
940: $r->print($showall);
941: }
1.196 raeburn 942: } else {
1.270 ! raeburn 943: if ($do_update && $requestauthor) {
! 944: $r->print('<div class="LC_left_float">'.
! 945: '<fieldset><legend>'.&mt('Changes?').'</legend>'.
! 946: $do_update.'</fieldset></div>'.
! 947: '<div class="LC_left_float">'.
! 948: '<fieldset><legend>'.&mt('Add author role').'</legend>'.
! 949: $requestauthor.'</fieldset></div><br clear="all" />');
! 950: } elsif ($do_update) {
! 951: $r->print('<p>'.$do_update.'</p>');
! 952: } elsif ($requestauthor) {
! 953: $r->print('<p>'.$requestauthor.'</p>');
! 954: }
1.196 raeburn 955: if ($countactive > 0) {
1.241 raeburn 956: $r->print(&Apache::loncoursequeueadmin::queued_selfenrollment());
1.196 raeburn 957: my $domdesc = &Apache::lonnet::domain($env{'user.domain'},'description');
1.201 raeburn 958: my $esc_dom = &HTML::Entities::encode($env{'user.domain'},'"<>&');
1.233 bisitz 959: $r->print(
960: '<p>'
961: .&mt('[_1]Visit the [_2]Course/Community Catalog[_3]'
962: .' to view all [_4] LON-CAPA courses and communities.'
963: ,'<b>'
964: ,'<a href="/adm/coursecatalog?showdom='.$esc_dom.'">'
965: ,'</a></b>',$domdesc)
966: .'<br />'
1.235 bisitz 967: .&mt('If a course or community is [_1]not[_2] in your list of current courses and communities below,'
1.233 bisitz 968: .' you may be able to enroll if self-enrollment is permitted.'
969: ,'<b>','</b>')
970: .'</p>'
971: );
1.196 raeburn 972: }
973: }
974:
1.84 www 975: # No active roles
976: if ($countactive==0) {
977: if ($inrole) {
1.234 raeburn 978: $r->print('<h2>'.&mt('Currently no additional roles, courses or communities').'</h2>');
1.84 www 979: } else {
1.234 raeburn 980: $r->print('<h2>'.&mt('Currently no active roles, courses or communities').'</h2>');
1.84 www 981: }
1.191 raeburn 982: &findcourse_advice($r);
1.234 raeburn 983: &requestcourse_advice($r);
1.191 raeburn 984: $r->print('</form>');
985: if ($countfuture) {
986: $r->print(&mt('The following [quant,_1,role,roles] will become active in the future:',$countfuture));
987: my $doheaders = &roletable_headers($r,\%roleclass,\%sortrole,
988: $nochoose);
989: &print_rolerows($r,$doheaders,\%roleclass,\%sortrole,\%dcroles,
990: \%roletext);
991: my $tremark='';
1.212 bisitz 992: my $tbg;
1.191 raeburn 993: if ($env{'request.role'} eq 'cm') {
1.212 bisitz 994: $tbg="LC_roles_selected";
1.204 bisitz 995: $tremark=&mt('Currently selected.').' ';
1.191 raeburn 996: } else {
1.212 bisitz 997: $tbg="LC_roles_is";
1.191 raeburn 998: }
1.212 bisitz 999: $r->print(&Apache::loncommon::start_data_table_row()
1000: .'<td class="'.$tbg.'"> </td>'
1001: .'<td colspan="3">'
1002: .&mt('No role specified')
1003: .'</td>'
1004: .'<td>'.$tremark.' </td>'
1005: .&Apache::loncommon::end_data_table_row()
1006: );
1.191 raeburn 1007:
1.212 bisitz 1008: $r->print(&Apache::loncommon::end_data_table());
1.191 raeburn 1009: }
1010: $r->print(&Apache::loncommon::end_page());
1.84 www 1011: return OK;
1012: }
1013: # ----------------------------------------------------------------------- Table
1.247 raeburn 1014:
1015: if ($numdc > 0) {
1016: $r->print(&coursepick_jscript());
1017: $r->print(&Apache::loncommon::coursebrowser_javascript().
1018: &Apache::loncommon::authorbrowser_javascript());
1019: }
1020:
1.224 raeburn 1021: unless ((!&Apache::loncommon::show_course()) || ($nochoose) || ($countactive==1)) {
1.173 albertel 1022: $r->print("<h2>".&mt('Select a Course to Enter')."</h2>\n");
1.84 www 1023: }
1.229 raeburn 1024: if ($env{'form.destinationurl'}) {
1025: $r->print('<input type="hidden" name="destinationurl" value="'.
1026: $env{'form.destinationurl'}.'" />');
1027: if ($env{'form.destsymb'} ne '') {
1028: $r->print('<input type="hidden" name="destsymb" value="'.
1029: $env{'form.destsymb'}.'" />');
1030: }
1031: }
1.247 raeburn 1032:
1.191 raeburn 1033: my $doheaders = &roletable_headers($r,\%roleclass,\%sortrole,$nochoose);
1.118 albertel 1034: if ($env{'environment.recentroles'}) {
1.111 albertel 1035: my %recent_roles =
1.118 albertel 1036: &Apache::lonhtmlcommon::get_recent('roles',$env{'environment.recentrolesn'});
1.111 albertel 1037: my $output='';
1.247 raeburn 1038: foreach my $role (sort(keys(%recent_roles))) {
1039: if (ref($roletext{'user.role.'.$role}) eq 'ARRAY') {
1.223 raeburn 1040: $output.= &Apache::loncommon::start_data_table_row().
1.247 raeburn 1041: $roletext{'user.role.'.$role}->[0].
1.223 raeburn 1042: &Apache::loncommon::end_data_table_row();
1.249 raeburn 1043: if ($roletext{'user.role.'.$role}->[1] ne '') {
1044: $output .= &Apache::loncommon::continue_data_table_row().
1045: $roletext{'user.role.'.$role}->[1].
1046: &Apache::loncommon::end_data_table_row();
1047: }
1.247 raeburn 1048: if ($role =~ m{dc\./($match_domain)/}
1.170 albertel 1049: && $dcroles{$1}) {
1.192 raeburn 1050: $output .= &adhoc_roles_row($1,'recent');
1.133 albertel 1051: }
1.113 raeburn 1052: } elsif ($numdc > 0) {
1.247 raeburn 1053: unless ($role =~/^error\:/) {
1.249 raeburn 1054: my ($roletext,$role_text_end) = &display_cc_role('user.role.'.$role);
1.259 raeburn 1055: if ($roletext) {
1056: $output.= &Apache::loncommon::start_data_table_row().
1057: $roletext.
1058: &Apache::loncommon::end_data_table_row();
1059: if ($role_text_end) {
1060: $output .= &Apache::loncommon::continue_data_table_row().
1061: $role_text_end.
1062: &Apache::loncommon::end_data_table_row();
1063: }
1064: }
1.113 raeburn 1065: }
1.247 raeburn 1066: }
1.111 albertel 1067: }
1068: if ($output) {
1.212 bisitz 1069: $r->print(&Apache::loncommon::start_data_table_empty_row()
1070: .'<td align="center" colspan="5">'
1.224 raeburn 1071: .$recent
1.212 bisitz 1072: .'</td>'
1073: .&Apache::loncommon::end_data_table_empty_row()
1074: );
1.111 albertel 1075: $r->print($output);
1.114 raeburn 1076: $doheaders ++;
1.111 albertel 1077: }
1078: }
1.191 raeburn 1079: &print_rolerows($r,$doheaders,\%roleclass,\%sortrole,\%dcroles,\%roletext);
1.202 raeburn 1080: if ($countactive > 1) {
1081: my $tremark='';
1.212 bisitz 1082: my $tbg;
1.202 raeburn 1083: if ($env{'request.role'} eq 'cm') {
1.212 bisitz 1084: $tbg="LC_roles_selected";
1.204 bisitz 1085: $tremark=&mt('Currently selected.').' ';
1.202 raeburn 1086: } else {
1.212 bisitz 1087: $tbg="LC_roles_is";
1.202 raeburn 1088: }
1.212 bisitz 1089: $r->print(&Apache::loncommon::start_data_table_row());
1.202 raeburn 1090: unless ($nochoose) {
1091: if ($env{'request.role'} ne 'cm') {
1.212 bisitz 1092: $r->print('<td class="'.$tbg.'"><input type="submit" value="'.
1.202 raeburn 1093: &mt('Select').'" name="cm" /></td>');
1094: } else {
1.212 bisitz 1095: $r->print('<td class="'.$tbg.'"> </td>');
1.202 raeburn 1096: }
1097: }
1.212 bisitz 1098: $r->print('<td colspan="3">'
1099: .&mt('No role specified')
1100: .'</td>'
1101: .'<td>'.$tremark.' </td>'
1102: .&Apache::loncommon::end_data_table_row()
1103: );
1.202 raeburn 1104: }
1.212 bisitz 1105: $r->print(&Apache::loncommon::end_data_table());
1.4 www 1106: unless ($nochoose) {
1107: $r->print("</form>\n");
1108: }
1.22 harris41 1109: # ------------------------------------------------------------ Privileges Info
1.118 albertel 1110: if (($advanced) && (($env{'user.error.msg'}) || ($error))) {
1.212 bisitz 1111: $r->print('<hr /><h2>'.&mt('Current Privileges').'</h2>');
1.175 albertel 1112: $r->print(&privileges_info());
1.4 www 1113: }
1.267 bisitz 1114: my $announcements = &Apache::lonnet::getannounce();
1115: $r->print(
1116: '<br />'.
1117: '<h2>'.&mt('Announcements').'</h2>'.
1118: $announcements
1119: ) unless (!$announcements);
1.65 www 1120: if ($advanced) {
1.201 raeburn 1121: my $esc_dom = &HTML::Entities::encode($env{'user.domain'},'"<>&');
1.231 bisitz 1122: $r->print('<p><small><i>'
1123: .&mt('This LON-CAPA server is version [_1]',$r->dir_config('lonVersion'))
1124: .'</i><br />'
1125: .'<a href="/adm/logout">'.&mt('Logout').'</a> '
1.201 raeburn 1126: .'<a href="/adm/coursecatalog?showdom='.$esc_dom.'">'
1.233 bisitz 1127: .&mt('Course/Community Catalog')
1.225 bisitz 1128: .'</a></small></p>');
1.65 www 1129: }
1.147 albertel 1130: $r->print(&Apache::loncommon::end_page());
1.1 harris41 1131: return OK;
1.102 raeburn 1132: }
1133:
1.270 ! raeburn 1134: sub is_active_author {
! 1135: if ($env{'user.role.au./'.$env{'user.domain'}.'/'} =~ /^(\d*)\.(\d*)$/) {
! 1136: if ((!$1 || $1 < time) &&
! 1137: (!$2 || $2 > time)) {
! 1138: return 1;
! 1139: }
! 1140: }
! 1141: return;
! 1142: }
! 1143:
! 1144: sub reqauthor_check {
! 1145: my $queued = $env{'environment.requestauthorqueued'};
! 1146: my %reqauthor = &Apache::lonnet::get('requestauthor',['author_status','author'],
! 1147: $env{'user.domain'},$env{'user.name'});
! 1148: my $reqstatus = $reqauthor{'author_status'};
! 1149: if (($reqstatus eq '' && $queued ne '') ||
! 1150: ($env{'environment.requestauthorqueued'} !~ /^\Q$reqstatus\E/)) {
! 1151: if (ref($reqauthor{'author'}) eq 'HASH') {
! 1152: $queued = $reqstatus.':'.$reqauthor{'author'}{'timestamp'};
! 1153: } else {
! 1154: undef($queued);
! 1155: }
! 1156: &Apache::lonnet::appenv({'environment.requestauthorqueued' => $queued});
! 1157: }
! 1158: return $queued;
! 1159: }
! 1160:
1.226 raeburn 1161: sub gather_roles {
1.260 raeburn 1162: my ($update,$refresh,$now,$reinit,$nochoose,$roletext,$sortrole,$roleclass,$futureroles,$timezones,$loncaparev) = @_;
1.226 raeburn 1163: my ($countactive,$countfuture,$inrole,$possiblerole) = (0,0,0,'');
1164: my $advanced = $env{'user.adv'};
1165: my $tryagain = $env{'form.tryagain'};
1.254 raeburn 1166: my @ids = &Apache::lonnet::current_machine_ids();
1.226 raeburn 1167: foreach my $envkey (sort(keys(%env))) {
1168: my $button = 1;
1169: my $switchserver='';
1.254 raeburn 1170: my $switchwarning;
1.226 raeburn 1171: my ($role_text,$role_text_end,$sortkey);
1172: if ($envkey=~/^user\.role\./) {
1173: my ($role,$where,$trolecode,$tstart,$tend,$tremark,$tstatus,$tpstart,$tpend);
1.260 raeburn 1174: &Apache::lonnet::role_status($envkey,$update,$refresh,$now,\$role,\$where,
1.226 raeburn 1175: \$trolecode,\$tstatus,\$tstart,\$tend);
1176: next if (!defined($role) || $role eq '' || $role =~ /^gr/);
1177: $tremark='';
1178: $tpstart=' ';
1179: $tpend=' ';
1180: if ($env{'request.role'} eq $trolecode) {
1181: $tstatus='selected';
1182: }
1183: my $tbg;
1184: if (($tstatus eq 'is')
1185: || ($tstatus eq 'selected')
1186: || ($tstatus eq 'future')
1187: || ($env{'form.showall'})) {
1.259 raeburn 1188: my $timezone = &role_timezone($where,$timezones);
1189: if ($tstart) {
1190: $tpstart=&Apache::lonlocal::locallocaltime($tstart,$timezone);
1191: }
1192: if ($tend) {
1193: $tpend=&Apache::lonlocal::locallocaltime($tend,$timezone);
1194: }
1.226 raeburn 1195: if ($tstatus eq 'is') {
1196: $tbg='LC_roles_is';
1197: $possiblerole=$trolecode;
1198: $countactive++;
1199: } elsif ($tstatus eq 'future') {
1200: $tbg='LC_roles_future';
1201: $button=0;
1202: $futureroles->{$trolecode} = $tstart.':'.$tend;
1203: $countfuture ++;
1204: } elsif ($tstatus eq 'expired') {
1205: $tbg='LC_roles_expired';
1206: $button=0;
1207: } elsif ($tstatus eq 'will_not') {
1208: $tbg='LC_roles_will_not';
1209: $tremark.=&mt('Expired after logout.').' ';
1210: } elsif ($tstatus eq 'selected') {
1211: $tbg='LC_roles_selected';
1212: $inrole=1;
1213: $countactive++;
1214: $tremark.=&mt('Currently selected.').' ';
1215: }
1216: my $trole;
1217: if ($role =~ /^cr\//) {
1218: my ($rdummy,$rdomain,$rauthor,$rrole)=split(/\//,$role);
1219: if ($tremark) { $tremark.='<br />'; }
1.253 bisitz 1220: $tremark.=&mt('Customrole defined by [_1].',$rauthor.':'.$rdomain);
1.226 raeburn 1221: }
1222: $trole=Apache::lonnet::plaintext($role);
1223: my $ttype;
1224: my $twhere;
1225: my ($tdom,$trest,$tsection)=
1226: split(/\//,Apache::lonnet::declutter($where));
1227: # First, Co-Authorship roles
1228: if (($role eq 'ca') || ($role eq 'aa')) {
1229: my $home = &Apache::lonnet::homeserver($trest,$tdom);
1230: my $allowed=0;
1231: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
1232: if (!$allowed) {
1233: $button=0;
1.248 raeburn 1234: $switchserver='otherserver='.$home.'&role='.$trolecode;
1.226 raeburn 1235: }
1236: #next if ($home eq 'no_host');
1237: $home = &Apache::lonnet::hostname($home);
1238: $ttype='Construction Space';
1239: $twhere=&mt('User').': '.$trest.'<br />'.&mt('Domain').
1240: ': '.$tdom.'<br />'.
1241: ' '.&mt('Server').': '.$home;
1242: $env{'course.'.$tdom.'_'.$trest.'.description'}='ca';
1243: $tremark.=&Apache::lonhtmlcommon::authorbombs('/res/'.$tdom.'/'.$trest.'/');
1244: $sortkey=$role."$trest:$tdom";
1245: } elsif ($role eq 'au') {
1246: # Authors
1247: my $home = &Apache::lonnet::homeserver
1248: ($env{'user.name'},$env{'user.domain'});
1249: my $allowed=0;
1250: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
1251: if (!$allowed) {
1252: $button=0;
1.248 raeburn 1253: $switchserver='otherserver='.$home.'&role='.$trolecode;
1.226 raeburn 1254: }
1255: #next if ($home eq 'no_host');
1256: $home = &Apache::lonnet::hostname($home);
1257: $ttype='Construction Space';
1258: $twhere=&mt('Domain').': '.$tdom.'<br />'.&mt('Server').
1259: ': '.$home;
1260: $env{'course.'.$tdom.'_'.$trest.'.description'}='ca';
1261: $tremark.=&Apache::lonhtmlcommon::authorbombs('/res/'.$tdom.'/'.$env{'user.name'}.'/');
1262: $sortkey=$role;
1263: } elsif ($trest) {
1264: my $tcourseid=$tdom.'_'.$trest;
1265: $ttype = &Apache::loncommon::course_type($tcourseid);
1.242 raeburn 1266: $trole = &Apache::lonnet::plaintext($role,$ttype,$tcourseid);
1.226 raeburn 1267: if ($env{'course.'.$tcourseid.'.description'}) {
1.254 raeburn 1268: my $home=$env{'course.'.$tcourseid.'.home'};
1.226 raeburn 1269: $twhere=$env{'course.'.$tcourseid.'.description'};
1270: $sortkey=$role."\0".$tdom."\0".$twhere."\0".$envkey;
1.248 raeburn 1271: $twhere = &HTML::Entities::encode($twhere,'"<>&');
1.226 raeburn 1272: unless ($twhere eq &mt('Currently not available')) {
1273: $twhere.=' <span class="LC_fontsize_small">'.
1274: &Apache::loncommon::syllabuswrapper(&mt('Syllabus'),$trest,$tdom).
1275: '</span>';
1.254 raeburn 1276: unless ($home && grep(/^\Q$home\E$/,@ids) && $loncaparev eq '') {
1.255 raeburn 1277: my $required = $env{'course.'.$tcourseid.'.internal.releaserequired'};
1.259 raeburn 1278: if ($required ne '') {
1279: ($switchserver,$switchwarning) =
1280: &check_release_required($loncaparev,$tcourseid,$trolecode,$required);
1281: if ($switchserver || $switchwarning) {
1282: $button = 0;
1283: }
1.254 raeburn 1284: }
1285: }
1.226 raeburn 1286: }
1287: } else {
1288: my %newhash=&Apache::lonnet::coursedescription($tcourseid);
1289: if (%newhash) {
1290: $sortkey=$role."\0".$tdom."\0".$newhash{'description'}.
1291: "\0".$envkey;
1.248 raeburn 1292: $twhere=&HTML::Entities::encode($newhash{'description'},'"<>&').
1293: ' <span class="LC_fontsize_small">'.
1294: &Apache::loncommon::syllabuswrapper(&mt('Syllabus'),$trest,$tdom).
1295: '</span>';
1.226 raeburn 1296: $ttype = $newhash{'type'};
1.243 raeburn 1297: $trole = &Apache::lonnet::plaintext($role,$ttype,$tcourseid);
1.254 raeburn 1298: my $home = $newhash{'home'};
1299: unless ($home && grep(/^\Q$home\E$/,@ids) && $loncaparev eq '') {
1.255 raeburn 1300: my $required = $newhash{'internal.releaserequired'};
1.259 raeburn 1301: if ($required ne '') {
1302: ($switchserver,$switchwarning) =
1303: &check_release_required($loncaparev,$tcourseid,$trolecode,$required);
1304: if ($switchserver || $switchwarning) {
1305: $button = 0;
1306: }
1.254 raeburn 1307: }
1308: }
1.226 raeburn 1309: } else {
1310: $twhere=&mt('Currently not available');
1311: $env{'course.'.$tcourseid.'.description'}=$twhere;
1312: $sortkey=$role."\0".$tdom."\0".$twhere."\0".$envkey;
1313: $ttype = 'Unavailable';
1314: }
1315: }
1316: if ($tsection) {
1317: $twhere.='<br />'.&mt('Section').': '.$tsection;
1318: }
1319: if ($role ne 'st') { $twhere.="<br />".&mt('Domain').":".$tdom; }
1320: } elsif ($tdom) {
1321: $ttype='Domain';
1322: $twhere=$tdom;
1323: $sortkey=$role.$twhere;
1324: } else {
1325: $ttype='System';
1326: $twhere=&mt('system wide');
1327: $sortkey=$role.$twhere;
1328: }
1329: ($role_text,$role_text_end) =
1330: &build_roletext($trolecode,$tdom,$trest,$tstatus,$tryagain,
1331: $advanced,$tremark,$tbg,$trole,$twhere,$tpstart,
1.254 raeburn 1332: $tpend,$nochoose,$button,$switchserver,$reinit,$switchwarning);
1.226 raeburn 1333: $roletext->{$envkey}=[$role_text,$role_text_end];
1334: if (!$sortkey) {$sortkey=$twhere."\0".$envkey;}
1335: $sortrole->{$sortkey}=$envkey;
1336: $roleclass->{$envkey}=$ttype;
1337: }
1338: }
1339: }
1340: return ($countactive,$countfuture,$inrole,$possiblerole);
1341: }
1342:
1.215 raeburn 1343: sub role_timezone {
1344: my ($where,$timezones) = @_;
1345: my $timezone;
1346: if (ref($timezones) eq 'HASH') {
1347: if ($where =~ m{^/($match_domain)/($match_courseid)}) {
1348: my $cdom = $1;
1349: my $cnum = $2;
1350: if ($cdom && $cnum) {
1351: if (!exists($timezones->{$cdom.'_'.$cnum})) {
1.259 raeburn 1352: my $tz;
1353: if ($env{'course.'.$cdom.'_'.$cnum.'.description'}) {
1354: $tz = $env{'course.'.$cdom.'_'.$cnum.'.timezone'};
1355: } else {
1356: my %timehash =
1357: &Apache::lonnet::get('environment',['timezone'],$cdom,$cnum);
1358: $tz = $timehash{'timezone'};
1359: }
1360: if ($tz eq '') {
1.215 raeburn 1361: if (!exists($timezones->{$cdom})) {
1362: my %domdefaults =
1363: &Apache::lonnet::get_domain_defaults($cdom);
1364: if ($domdefaults{'timezone_def'} eq '') {
1365: $timezones->{$cdom} = 'local';
1366: } else {
1367: $timezones->{$cdom} = $domdefaults{'timezone_def'};
1368: }
1369: }
1370: $timezones->{$cdom.'_'.$cnum} = $timezones->{$cdom};
1371: } else {
1372: $timezones->{$cdom.'_'.$cnum} =
1.259 raeburn 1373: &Apache::lonlocal::gettimezone($tz);
1.215 raeburn 1374: }
1375: }
1376: $timezone = $timezones->{$cdom.'_'.$cnum};
1377: }
1378: } else {
1379: my ($tdom) = ($where =~ m{^/($match_domain)});
1380: if ($tdom) {
1381: if (!exists($timezones->{$tdom})) {
1382: my %domdefaults = &Apache::lonnet::get_domain_defaults($tdom);
1383: if ($domdefaults{'timezone_def'} eq '') {
1384: $timezones->{$tdom} = 'local';
1385: } else {
1386: $timezones->{$tdom} = $domdefaults{'timezone_def'};
1387: }
1388: }
1389: $timezone = $timezones->{$tdom};
1390: }
1391: }
1392: if ($timezone eq 'local') {
1393: $timezone = undef;
1394: }
1395: }
1396: return $timezone;
1397: }
1398:
1.191 raeburn 1399: sub roletable_headers {
1400: my ($r,$roleclass,$sortrole,$nochoose) = @_;
1401: my $doheaders;
1402: if ((ref($sortrole) eq 'HASH') && (ref($roleclass) eq 'HASH')) {
1.212 bisitz 1403: $r->print('<br />'
1404: .&Apache::loncommon::start_data_table()
1405: .&Apache::loncommon::start_data_table_header_row()
1406: );
1.191 raeburn 1407: if (!$nochoose) { $r->print('<th> </th>'); }
1.212 bisitz 1408: $r->print('<th>'.&mt('User Role').'</th>'
1409: .'<th>'.&mt('Extent').'</th>'
1410: .'<th>'.&mt('Start').'</th>'
1411: .'<th>'.&mt('End').'</th>'
1412: .&Apache::loncommon::end_data_table_header_row()
1413: );
1.191 raeburn 1414: $doheaders=-1;
1415: my @roletypes = &roletypes();
1416: foreach my $type (@roletypes) {
1417: my $haverole=0;
1418: foreach my $which (sort {uc($a) cmp uc($b)} (keys(%{$sortrole}))) {
1419: if ($roleclass->{$sortrole->{$which}} =~ /^\Q$type\E/) {
1420: $haverole=1;
1421: }
1422: }
1423: if ($haverole) { $doheaders++; }
1424: }
1425: }
1426: return $doheaders;
1427: }
1428:
1429: sub roletypes {
1.237 raeburn 1430: my @types = ('Domain','Construction Space','Course','Community','Unavailable','System');
1.191 raeburn 1431: return @types;
1432: }
1433:
1434: sub print_rolerows {
1435: my ($r,$doheaders,$roleclass,$sortrole,$dcroles,$roletext) = @_;
1436: if ((ref($roleclass) eq 'HASH') && (ref($sortrole) eq 'HASH')) {
1437: my @types = &roletypes();
1438: foreach my $type (@types) {
1439: my $output;
1440: foreach my $which (sort {uc($a) cmp uc($b)} (keys(%{$sortrole}))) {
1441: if ($roleclass->{$sortrole->{$which}} =~ /^\Q$type\E/) {
1442: if (ref($roletext) eq 'HASH') {
1.223 raeburn 1443: if (ref($roletext->{$sortrole->{$which}}) eq 'ARRAY') {
1444: $output.= &Apache::loncommon::start_data_table_row().
1445: $roletext->{$sortrole->{$which}}->[0].
1446: &Apache::loncommon::end_data_table_row();
1.251 raeburn 1447: if ($roletext->{$sortrole->{$which}}->[1] ne '') {
1448: $output .= &Apache::loncommon::continue_data_table_row().
1449: $roletext->{$sortrole->{$which}}->[1].
1450: &Apache::loncommon::end_data_table_row();
1451: }
1.223 raeburn 1452: }
1.191 raeburn 1453: if ($sortrole->{$which} =~ m-dc\./($match_domain)/-) {
1454: if (ref($dcroles) eq 'HASH') {
1455: if ($dcroles->{$1}) {
1.192 raeburn 1456: $output .= &adhoc_roles_row($1,'');
1.191 raeburn 1457: }
1458: }
1459: }
1460: }
1461: }
1462: }
1463: if ($output) {
1464: if ($doheaders > 0) {
1.212 bisitz 1465: $r->print(&Apache::loncommon::start_data_table_empty_row()
1466: .'<td align="center" colspan="5">'
1467: .&mt($type)
1468: .'</td>'
1469: .&Apache::loncommon::end_data_table_empty_row()
1470: );
1.191 raeburn 1471: }
1472: $r->print($output);
1473: }
1474: }
1475: }
1476: }
1477:
1478: sub findcourse_advice {
1479: my ($r) = @_;
1480: my $domdesc = &Apache::lonnet::domain($env{'user.domain'},'description');
1.201 raeburn 1481: my $esc_dom = &HTML::Entities::encode($env{'user.domain'},'"<>&');
1.200 raeburn 1482: if (&Apache::lonnet::auto_run(undef,$env{'user.domain'})) {
1.191 raeburn 1483: $r->print(&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).'
1484: <ul>
1485: <li>'.&mt('The course has yet to be created.').'</li>
1486: <li>'.&mt('Automatic enrollment of registered students has not been enabled for the course.').'</li>
1487: <li>'.&mt('You are in a section of course for which automatic enrollment in the corresponding LON-CAPA course is not active.').'</li>
1488: <li>'.&mt('The start date for automated enrollment has yet to be reached.').'</li>
1489: <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>
1490: </ul>');
1491: } else {
1492: $r->print(&mt('If you were expecting to see an active role listed for a particular course, that course may not have been created yet.').'<br />');
1493: }
1.235 bisitz 1494: $r->print('<h3>'.&mt('Self-Enrollment').'</h3>'.
1.234 raeburn 1495: '<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 />');
1.241 raeburn 1496: $r->print(&mt('You can search for courses and communities which permit self-enrollment, if you would like to enroll in one.').'</p>'.
1497: &Apache::loncoursequeueadmin::queued_selfenrollment());
1.216 raeburn 1498: return;
1499: }
1500:
1.234 raeburn 1501: sub requestcourse_advice {
1502: my ($r) = @_;
1503: my $domdesc = &Apache::lonnet::domain($env{'user.domain'},'description');
1504: my $esc_dom = &HTML::Entities::encode($env{'user.domain'},'"<>&');
1505: my (%can_request,%request_doms);
1506: &Apache::lonnet::check_can_request($env{'user.domain'},\%can_request,\%request_doms);
1507: if (keys(%request_doms) > 0) {
1508: my ($types,$typename) = &Apache::loncommon::course_types();
1509: if ((ref($types) eq 'ARRAY') && (ref($typename) eq 'HASH')) {
1510: $r->print('<h3>'.&mt('Request creation of a course or community').'</h3>'.
1.238 bisitz 1511: '<p>'.&mt('You have rights to request the creation of courses and/or communities in the following domain(s):').'<ul>');
1.234 raeburn 1512: my (@reqdoms,@reqtypes);
1513: foreach my $type (sort(keys(%request_doms))) {
1514: push(@reqtypes,$type);
1515: if (ref($request_doms{$type}) eq 'ARRAY') {
1516: my $domstr = join(', ',map { &Apache::lonnet::domain($_) } sort(@{$request_doms{$type}}));
1.238 bisitz 1517: $r->print(
1518: '<li>'
1519: .&mt('[_1]'.$typename->{$type}.'[_2] in domain: [_3]',
1520: '<i>',
1521: '</i>',
1522: '<b>'.$domstr.'</b>')
1523: .'</li>'
1524: );
1.234 raeburn 1525: foreach my $dom (@{$request_doms{$type}}) {
1526: unless (grep(/^\Q$dom\E/,@reqdoms)) {
1527: push(@reqdoms,$dom);
1528: }
1529: }
1530: }
1531: }
1532: my @showtypes;
1533: foreach my $type (@{$types}) {
1534: if (grep(/^\Q$type\E$/,@reqtypes)) {
1535: push(@showtypes,$type);
1536: }
1537: }
1538: my $requrl = '/adm/requestcourse';
1539: if (@reqdoms == 1) {
1540: $requrl .= '?showdom='.$reqdoms[0];
1541: }
1542: if (@showtypes > 0) {
1543: $requrl.=(($requrl=~/\?/)?'&':'?').'crstype='.$showtypes[0];
1544: }
1545: if (@reqdoms == 1 || @showtypes > 0) {
1546: $requrl .= '&state=crstype&action=new';
1547: }
1548: $r->print('</ul>'.&mt('Use the [_1]request form[_2] to submit a request for creation of a new course or community.','<a href="'.$requrl.'">','</a>').'</p>');
1549: }
1550: }
1551: return;
1552: }
1553:
1.175 albertel 1554: sub privileges_info {
1555: my ($which) = @_;
1556: my $output;
1557:
1558: $which ||= $env{'request.role'};
1559:
1560: foreach my $envkey (sort(keys(%env))) {
1561: next if ($envkey!~/^user\.priv\.\Q$which\E\.(.*)/);
1562:
1563: my $where=$1;
1564: my $ttype;
1565: my $twhere;
1566: my (undef,$tdom,$trest,$tsec)=split(m{/},$where);
1567: if ($trest) {
1568: if ($env{'course.'.$tdom.'_'.$trest.'.description'} eq 'ca') {
1569: $ttype='Construction Space';
1570: $twhere='User: '.$trest.', Domain: '.$tdom;
1571: } else {
1572: $ttype= &Apache::loncommon::course_type($tdom.'_'.$trest);
1573: $twhere=$env{'course.'.$tdom.'_'.$trest.'.description'};
1574: if ($tsec) {
1575: my $sec_type = 'Section';
1576: if (exists($env{"user.role.gr.$where"})) {
1577: $sec_type = 'Group';
1578: }
1579: $twhere.=' ('.$sec_type.': '.$tsec.')';
1580: }
1581: }
1582: } elsif ($tdom) {
1583: $ttype='Domain';
1584: $twhere=$tdom;
1585: } else {
1586: $ttype='System';
1587: $twhere='/';
1588: }
1.204 bisitz 1589: $output .= "\n<h3>".&mt($ttype).': '.$twhere.'</h3>'."\n<ul>";
1.175 albertel 1590: foreach my $priv (sort(split(/:/,$env{$envkey}))) {
1591: next if (!$priv);
1592:
1593: my ($prv,$restr)=split(/\&/,$priv);
1594: my $trestr='';
1595: if ($restr ne 'F') {
1596: $trestr.=' ('.
1597: join(', ',
1598: map { &Apache::lonnet::plaintext($_) }
1599: (split('',$restr))).') ';
1600: }
1601: $output .= "\n\t".
1602: '<li>'.&Apache::lonnet::plaintext($prv).$trestr.'</li>';
1603: }
1604: $output .= "\n".'</ul>';
1605: }
1606: return $output;
1607: }
1608:
1.110 raeburn 1609: sub build_roletext {
1.254 raeburn 1610: my ($trolecode,$tdom,$trest,$tstatus,$tryagain,$advanced,$tremark,$tbg,$trole,$twhere,$tpstart,$tpend,$nochoose,$button,$switchserver,$reinit,$switchwarning) = @_;
1.223 raeburn 1611: my ($roletext,$roletext_end);
1.132 albertel 1612: my $is_dc=($trolecode =~ m/^dc\./);
1613: my $rowspan=($is_dc) ? ''
1614: : ' rowspan="2" ';
1615:
1.110 raeburn 1616: unless ($nochoose) {
1.134 www 1617: my $buttonname=$trolecode;
1618: $buttonname=~s/\W//g;
1.110 raeburn 1619: if (!$button) {
1620: if ($switchserver) {
1.212 bisitz 1621: $roletext.='<td'.$rowspan.' class="'.$tbg.'">'
1622: .'<a href="/adm/switchserver?'.$switchserver.'">'
1623: .&mt('Switch Server')
1624: .'</a></td>';
1.110 raeburn 1625: } else {
1.212 bisitz 1626: $roletext.=('<td'.$rowspan.' class="'.$tbg.'"> </td>');
1.110 raeburn 1627: }
1.255 raeburn 1628: if ($switchwarning) {
1629: if ($tremark eq '') {
1630: $tremark = $switchwarning;
1631: } else {
1632: $tremark .= '<br />'.$switchwarning;
1633: }
1634: }
1.110 raeburn 1635: } elsif ($tstatus eq 'is') {
1.212 bisitz 1636: $roletext.='<td'.$rowspan.' class="'.$tbg.'">'.
1637: '<input name="'.$buttonname.'" type="button" value="'.
1.225 bisitz 1638: &mt('Select').'" onclick="javascript:enterrole(this.form,\''.
1.192 raeburn 1639: $trolecode."','".$buttonname.'\');" /></td>';
1.110 raeburn 1640: } elsif ($tryagain) {
1641: $roletext.=
1.212 bisitz 1642: '<td'.$rowspan.' class="'.$tbg.'">'.
1643: '<input name="'.$buttonname.'" type="button" value="'.
1.225 bisitz 1644: &mt('Try Selecting Again').'" onclick="javascript:enterrole(this.form,\''.
1.192 raeburn 1645: $trolecode."','".$buttonname.'\');" /></td>';
1.110 raeburn 1646: } elsif ($advanced) {
1647: $roletext.=
1.212 bisitz 1648: '<td'.$rowspan.' class="'.$tbg.'">'.
1649: '<input name="'.$buttonname.'" type="button" value="'.
1.225 bisitz 1650: &mt('Re-Initialize').'" onclick="javascript:enterrole(this.form,\''.
1.192 raeburn 1651: $trolecode."','".$buttonname.'\');" /></td>';
1.209 raeburn 1652: } elsif ($reinit) {
1653: $roletext.=
1.212 bisitz 1654: '<td'.$rowspan.' class="'.$tbg.'">'.
1655: '<input name="'.$buttonname.'" type="button" value="'.
1.225 bisitz 1656: &mt('Re-Select').'" onclick="javascript:enterrole(this.form,\''.
1.209 raeburn 1657: $trolecode."','".$buttonname.'\');" /></td>';
1.110 raeburn 1658: } else {
1.209 raeburn 1659: $roletext.=
1.212 bisitz 1660: '<td'.$rowspan.' class="'.$tbg.'">'.
1661: '<input name="'.$buttonname.'" type="button" value="'.
1.225 bisitz 1662: &mt('Re-Select').'" onclick="javascript:enterrole(this.form,\''.
1.209 raeburn 1663: $trolecode."','".$buttonname.'\');" /></td>';
1.110 raeburn 1664: }
1665: }
1.165 albertel 1666: if ($trolecode !~ m/^(dc|ca|au|aa)\./) {
1667: $tremark.=&Apache::lonannounce::showday(time,1,
1668: &Apache::lonannounce::readcalendar($tdom.'_'.$trest));
1669: }
1.212 bisitz 1670: $roletext.='<td>'.$trole.'</td>'
1671: .'<td>'.$twhere.'</td>'
1672: .'<td>'.$tpstart.'</td>'
1.223 raeburn 1673: .'<td>'.$tpend.'</td>';
1.132 albertel 1674: if (!$is_dc) {
1.223 raeburn 1675: $roletext_end = '<td colspan="4">'.
1676: $tremark.' '.
1677: '</td>';
1.132 albertel 1678: }
1.223 raeburn 1679: return ($roletext,$roletext_end);
1.110 raeburn 1680: }
1681:
1.202 raeburn 1682: sub check_needs_switchserver {
1683: my ($possiblerole) = @_;
1684: my $needs_switchserver;
1685: my ($role,$where) = split(/\./,$possiblerole,2);
1686: my (undef,$tdom,$twho) = split(/\//,$where);
1687: my ($server_status,$home);
1688: if (($role eq 'ca') || ($role eq 'aa')) {
1689: ($server_status,$home) = &check_author_homeserver($twho,$tdom);
1690: } else {
1691: ($server_status,$home) = &check_author_homeserver($env{'user.name'},
1692: $env{'user.domain'});
1693: }
1694: if ($server_status eq 'switchserver') {
1695: $needs_switchserver = 1;
1696: }
1697: return $needs_switchserver;
1698: }
1699:
1.193 raeburn 1700: sub check_author_homeserver {
1.183 www 1701: my ($uname,$udom)=@_;
1.193 raeburn 1702: if (($uname eq '') || ($udom eq '')) {
1703: return ('fail','');
1704: }
1.183 www 1705: my $home = &Apache::lonnet::homeserver($uname,$udom);
1.193 raeburn 1706: if (&Apache::lonnet::host_domain($home) ne $udom) {
1707: return ('fail',$home);
1708: }
1.183 www 1709: my @ids=&Apache::lonnet::current_machine_ids();
1.193 raeburn 1710: if (grep(/^\Q$home\E$/,@ids)) {
1711: return ('ok',$home);
1712: } else {
1713: return ('switchserver',$home);
1.183 www 1714: }
1715: }
1716:
1.104 raeburn 1717: sub check_fordc {
1.260 raeburn 1718: my ($dcroles,$update,$then) = @_;
1.104 raeburn 1719: my $numdc = 0;
1.118 albertel 1720: if ($env{'user.adv'}) {
1721: foreach my $envkey (sort keys %env) {
1.170 albertel 1722: if ($envkey=~/^user\.role\.dc\.\/($match_domain)\/$/) {
1.104 raeburn 1723: my $dcdom = $1;
1724: my $livedc = 1;
1.118 albertel 1725: my ($tstart,$tend)=split(/\./,$env{$envkey});
1.260 raeburn 1726: my $limit = $update;
1727: if ($env{'request.role'} eq 'dc./'.$dcdom.'/') {
1728: $limit = $then;
1729: }
1730: if ($tstart && $tstart>$limit) { $livedc = 0; }
1731: if ($tend && $tend <$limit) { $livedc = 0; }
1.104 raeburn 1732: if ($livedc) {
1733: $$dcroles{$dcdom} = $envkey;
1.105 raeburn 1734: $numdc++;
1.104 raeburn 1735: }
1736: }
1737: }
1738: }
1739: return $numdc;
1740: }
1741:
1.185 raeburn 1742: sub adhoc_course_role {
1.260 raeburn 1743: my ($refresh,$update,$then) = @_;
1.239 raeburn 1744: my ($cdom,$cnum,$crstype);
1.201 raeburn 1745: $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
1746: $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.239 raeburn 1747: $crstype = &Apache::loncommon::course_type();
1.260 raeburn 1748: if (&check_forcc($cdom,$cnum,$refresh,$update,$then,$crstype)) {
1.185 raeburn 1749: my $setprivs;
1.198 raeburn 1750: if (!defined($env{'user.role.'.$env{'form.switchrole'}})) {
1.185 raeburn 1751: $setprivs = 1;
1752: } else {
1.198 raeburn 1753: my ($start,$end) = split(/\./,$env{'user.role.'.$env{'form.switchrole'}});
1.232 raeburn 1754: if (($start && ($start>$refresh || $start == -1)) ||
1.260 raeburn 1755: ($end && $end<$update)) {
1.185 raeburn 1756: $setprivs = 1;
1757: }
1.232 raeburn 1758: }
1.185 raeburn 1759: if ($setprivs) {
1.198 raeburn 1760: if ($env{'form.switchrole'} =~ m-^(in|ta|ep|ad|st|cr)([\w/]*)\./\Q$cdom\E/\Q$cnum\E/?(\w*)$-) {
1.185 raeburn 1761: my $role = $1;
1762: my $custom_role = $2;
1763: my $usec = $3;
1764: if ($role eq 'cr') {
1.199 raeburn 1765: if ($custom_role =~ m-^/$match_domain/$match_username/\w+$-) {
1.185 raeburn 1766: $role .= $custom_role;
1767: } else {
1768: return;
1769: }
1770: }
1.208 raeburn 1771: my (%userroles,%newrole,%newgroups,%group_privs);
1772: my %cgroups =
1773: &Apache::lonnet::get_active_groups($env{'user.domain'},
1774: $env{'user.name'},$cdom,$cnum);
1775: foreach my $group (keys(%cgroups)) {
1776: $group_privs{$group} =
1777: $env{'user.priv.cc./'.$cdom.'/'.$cnum.'./'.$cdom.'/'.$cnum.'/'.$group};
1778: }
1779: $newgroups{'/'.$cdom.'/'.$cnum} = \%group_privs;
1.185 raeburn 1780: my $area = '/'.$cdom.'/'.$cnum;
1781: my $spec = $role.'.'.$area;
1782: if ($usec ne '') {
1783: $spec .= '/'.$usec;
1784: $area .= '/'.$usec;
1785: }
1786: &Apache::lonnet::standard_roleprivs(\%newrole,$role,$cdom,$spec,$cnum,$area);
1.208 raeburn 1787: &Apache::lonnet::set_userprivs(\%userroles,\%newrole,\%newgroups);
1.232 raeburn 1788: my $adhocstart = $refresh-1;
1.185 raeburn 1789: $userroles{'user.role.'.$spec} = $adhocstart.'.';
1.186 raeburn 1790: &Apache::lonnet::appenv(\%userroles,[$role,'cm']);
1.185 raeburn 1791: }
1792: }
1793: }
1794: return;
1795: }
1796:
1797: sub check_forcc {
1.260 raeburn 1798: my ($cdom,$cnum,$refresh,$update,$then,$crstype) = @_;
1.239 raeburn 1799: my ($is_cc,$ccrole);
1800: if ($crstype eq 'Community') {
1801: $ccrole = 'co';
1802: } else {
1803: $ccrole = 'cc';
1804: }
1.266 droeschl 1805: if (&Apache::lonnet::is_course($cdom,$cnum)) {
1806: my $envkey = 'user.role.'.$ccrole.'./'.$cdom.'/'.$cnum;
1807: if (defined($env{$envkey})) {
1808: $is_cc = 1;
1809: my ($tstart,$tend)=split(/\./,$env{$envkey});
1810: my $limit = $update;
1811: if ($env{'request.role'} eq $ccrole.'./'.$cdom.'/'.$cnum) {
1812: $limit = $then;
1.185 raeburn 1813: }
1.266 droeschl 1814: if ($tstart && $tstart>$refresh) { $is_cc = 0; }
1815: if ($tend && $tend <$limit) { $is_cc = 0; }
1.185 raeburn 1816: }
1817: }
1818: return $is_cc;
1819: }
1820:
1.254 raeburn 1821: sub check_release_required {
1.255 raeburn 1822: my ($loncaparev,$tcourseid,$trolecode,$required) = @_;
1.254 raeburn 1823: my ($switchserver,$warning);
1.255 raeburn 1824: if ($required ne '') {
1825: my ($reqdmajor,$reqdminor) = ($required =~ /^(\d+)\.(\d+)$/);
1.257 raeburn 1826: my ($major,$minor) = ($loncaparev =~ /^\'?(\d+)\.(\d+)\.[\w.\-]+\'?$/);
1.254 raeburn 1827: if ($reqdmajor ne '' && $reqdminor ne '') {
1828: my $otherserver;
1829: if (($major eq '' && $minor eq '') ||
1830: (($reqdmajor > $major) || (($reqdmajor == $major) && ($reqdminor > $minor)))) {
1831: my ($userdomserver) = &Apache::lonnet::choose_server($env{'user.domain'});
1832: my $switchlcrev =
1833: &Apache::lonnet::get_server_loncaparev($env{'user.domain'},
1834: $userdomserver);
1.257 raeburn 1835: my ($swmajor,$swminor) = ($switchlcrev =~ /^\'?(\d+)\.(\d+)\.[\w.\-]+\'?$/);
1.254 raeburn 1836: if (($swmajor eq '' && $swminor eq '') || ($reqdmajor > $swmajor) ||
1837: (($reqdmajor == $swmajor) && ($reqdminor > $swminor))) {
1838: my $cdom = $env{'course.'.$tcourseid.'.domain'};
1839: if ($cdom ne $env{'user.domain'}) {
1840: my ($coursedomserver,$coursehostname) = &Apache::lonnet::choose_server($cdom);
1841: my $serverhomeID = &Apache::lonnet::get_server_homeID($coursehostname);
1842: my $serverhomedom = &Apache::lonnet::host_domain($serverhomeID);
1843: my %defdomdefaults = &Apache::lonnet::get_domain_defaults($serverhomedom);
1844: my %udomdefaults = &Apache::lonnet::get_domain_defaults($env{'user.domain'});
1845: my $remoterev = &Apache::lonnet::get_server_loncaparev($serverhomedom,$coursedomserver);
1846: my $canhost =
1847: &Apache::lonnet::can_host_session($env{'user.domain'},
1848: $coursedomserver,
1849: $remoterev,
1850: $udomdefaults{'remotesessions'},
1851: $defdomdefaults{'hostedsessions'});
1852:
1853: if ($canhost) {
1854: $otherserver = $coursedomserver;
1855: } else {
1856: $warning = &mt('Requires LON-CAPA version [_1].',$env{'course.'.$tcourseid.'.internal.releaserequired'}).'<br />'. &mt("No suitable server could be found amongst servers in either your own domain or in the course's domain.");
1857: }
1858: } else {
1859: $warning = &mt('Requires LON-CAPA version [_1].',$env{'course.'.$tcourseid.'.internal.releaserequired'}).'<br />'.&mt("No suitable server could be found amongst servers in your own domain (which is also the course's domain).");
1860: }
1861: } else {
1862: $otherserver = $userdomserver;
1863: }
1864: }
1865: if ($otherserver ne '') {
1866: $switchserver = 'otherserver='.$otherserver.'&role='.$trolecode;
1867: }
1868: }
1869: }
1870: return ($switchserver,$warning);
1871: }
1872:
1.108 raeburn 1873: sub courselink {
1.193 raeburn 1874: my ($dcdom,$rowtype) = @_;
1.109 raeburn 1875: my $courseform=&Apache::loncommon::selectcourse_link
1.152 raeburn 1876: ('rolechoice','dccourse'.$rowtype.'_'.$dcdom,
1877: 'dcdomain'.$rowtype.'_'.$dcdom,'coursedesc'.$rowtype.'_'.
1.239 raeburn 1878: $dcdom,$dcdom,undef,'Course/Community');
1.138 raeburn 1879: my $hiddenitems = '<input type="hidden" name="dcdomain'.$rowtype.'_'.$dcdom.'" value="'.$dcdom.'" />'.
1880: '<input type="hidden" name="origdom'.$rowtype.'_'.$dcdom.'" value="'.$dcdom.'" />'.
1881: '<input type="hidden" name="dccourse'.$rowtype.'_'.$dcdom.'" value="" />'.
1882: '<input type="hidden" name="coursedesc'.$rowtype.'_'.$dcdom.'" value="" />';
1.112 raeburn 1883: return $courseform.$hiddenitems;
1.109 raeburn 1884: }
1885:
1886: sub coursepick_jscript {
1.184 raeburn 1887: my %lt = &Apache::lonlocal::texthash(
1.239 raeburn 1888: 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 1889: youc => 'You can only use this screen to select courses and communities in the current domain.',
1.184 raeburn 1890: );
1.104 raeburn 1891: my $verify_script = <<"END";
1.179 raeburn 1892: <script type="text/javascript">
1.225 bisitz 1893: // <![CDATA[
1.108 raeburn 1894: function verifyCoursePick(caller) {
1895: var numbutton = getIndex(caller)
1.112 raeburn 1896: var pickedCourse = document.rolechoice.elements[numbutton+4].value
1897: var pickedDomain = document.rolechoice.elements[numbutton+2].value
1898: if (document.rolechoice.elements[numbutton+2].value == document.rolechoice.elements[numbutton+3].value) {
1.104 raeburn 1899: if (pickedCourse != '') {
1.108 raeburn 1900: if (numbutton != -1) {
1901: var courseTarget = "cc./"+pickedDomain+"/"+pickedCourse
1902: document.rolechoice.elements[numbutton+1].name = courseTarget
1903: document.rolechoice.submit()
1904: }
1.104 raeburn 1905: }
1906: else {
1.184 raeburn 1907: alert("$lt{'plsu'}");
1.104 raeburn 1908: }
1909: }
1910: else {
1.184 raeburn 1911: alert("$lt{'youc'}")
1.104 raeburn 1912: }
1913: }
1.109 raeburn 1914: function getIndex(caller) {
1.108 raeburn 1915: for (var i=0;i<document.rolechoice.elements.length;i++) {
1.109 raeburn 1916: if (document.rolechoice.elements[i] == caller) {
1.108 raeburn 1917: return i;
1918: }
1919: }
1920: return -1;
1921: }
1.225 bisitz 1922: // ]]>
1.104 raeburn 1923: </script>
1924: END
1.109 raeburn 1925: return $verify_script;
1.104 raeburn 1926: }
1927:
1.193 raeburn 1928: sub coauthorlink {
1929: my ($dcdom,$rowtype) = @_;
1930: my $coauthorform=&Apache::loncommon::selectauthor_link('rolechoice',$dcdom);
1931: my $hiddenitems = '<input type="hidden" name="adhoccauname'.$rowtype.'_'.$dcdom.'" value="" />';
1932: return $coauthorform.$hiddenitems;
1933: }
1934:
1.113 raeburn 1935: sub display_cc_role {
1936: my $rolekey = shift;
1.223 raeburn 1937: my ($roletext,$roletext_end);
1.118 albertel 1938: my $advanced = $env{'user.adv'};
1939: my $tryagain = $env{'form.tryagain'};
1.113 raeburn 1940: unless ($rolekey =~/^error\:/) {
1.240 raeburn 1941: if ($rolekey =~ m{^user\.role\.(cc|co)\./($match_domain)/($match_courseid)$}) {
1942: my $ccrole = $1;
1.249 raeburn 1943: my $tdom = $2;
1944: my $trest = $3;
1945: my $tcourseid = $tdom.'_'.$trest;
1946: my $trolecode = $ccrole.'./'.$tdom.'/'.$trest;
1.113 raeburn 1947: my $twhere;
1.152 raeburn 1948: my $ttype;
1.212 bisitz 1949: my $tbg='LC_roles_is';
1.113 raeburn 1950: my %newhash=&Apache::lonnet::coursedescription($tcourseid);
1951: if (%newhash) {
1952: $twhere=$newhash{'description'}.
1.261 bisitz 1953: ' <span class="LC_fontsize_small">'.
1.249 raeburn 1954: &Apache::loncommon::syllabuswrapper(&mt('Syllabus'),$trest,$tdom).
1.211 tempelho 1955: '</span>';
1.153 raeburn 1956: $ttype = $newhash{'type'};
1.113 raeburn 1957: } else {
1958: $twhere=&mt('Currently not available');
1.118 albertel 1959: $env{'course.'.$tcourseid.'.description'}=$twhere;
1.110 raeburn 1960: }
1.242 raeburn 1961: my $trole = &Apache::lonnet::plaintext($ccrole,$ttype,$tcourseid);
1.258 raeburn 1962: $twhere.="<br />".&mt('Domain').":".$tdom;
1.249 raeburn 1963: ($roletext,$roletext_end) = &build_roletext($trolecode,$tdom,$trest,'is',$tryagain,$advanced,'',$tbg,$trole,$twhere,'','','',1,'');
1.104 raeburn 1964: }
1965: }
1.223 raeburn 1966: return ($roletext,$roletext_end);
1.104 raeburn 1967: }
1968:
1.192 raeburn 1969: sub adhoc_roles_row {
1.138 raeburn 1970: my ($dcdom,$rowtype) = @_;
1.212 bisitz 1971: my $output = &Apache::loncommon::continue_data_table_row()
1972: .' <td colspan="5">'
1973: .&mt('[_1]Ad hoc[_2] roles in domain [_3] --'
1974: ,'<span class="LC_cusr_emph">','</span>',$dcdom)
1.227 bisitz 1975: .' ';
1.193 raeburn 1976: my $selectcclink = &courselink($dcdom,$rowtype);
1.239 raeburn 1977: my $ccrole = &Apache::lonnet::plaintext('co',undef,undef,1);
1.182 www 1978: my $carole = &Apache::lonnet::plaintext('ca');
1.193 raeburn 1979: my $selectcalink = &coauthorlink($dcdom,$rowtype);
1.227 bisitz 1980: $output.=$ccrole.': '.$selectcclink
1.249 raeburn 1981: .' | '.$carole.': '.$selectcalink.'</td>'
1.212 bisitz 1982: .&Apache::loncommon::end_data_table_row();
1.108 raeburn 1983: return $output;
1984: }
1985:
1.104 raeburn 1986: sub recent_filename {
1987: my $area=shift;
1.149 www 1988: return 'nohist_recent_'.&escape($area);
1.104 raeburn 1989: }
1990:
1.139 raeburn 1991: sub courseloadpage {
1992: my ($courseid) = @_;
1993: my $startpage;
1.144 albertel 1994: my %entry_settings = &Apache::lonnet::get('nohist_whatsnew',
1995: [$courseid.':courseinit']);
1.139 raeburn 1996: my ($tmp) = %entry_settings;
1.144 albertel 1997: unless ($tmp =~ /^error: 2 /) {
1.139 raeburn 1998: $startpage = $entry_settings{$courseid.':courseinit'};
1999: }
2000: if ($startpage eq '') {
2001: if (exists($env{'environment.course_init_display'})) {
2002: $startpage = $env{'environment.course_init_display'};
2003: }
2004: }
2005: return $startpage;
2006: }
2007:
1.260 raeburn 2008: sub update_session_roles {
2009: my $then=$env{'user.login.time'};
2010: my $refresh=$env{'user.refresh.time'};
2011: if (!$refresh) {
2012: $refresh = $then;
2013: }
2014: my $update = $env{'user.update.time'};
2015: if (!$update) {
2016: $update = $then;
2017: }
2018: my $now = time;
2019: my %roleshash =
2020: &Apache::lonnet::get_my_roles('','','userroles',
2021: ['active','future','previous'],
2022: undef,undef,1);
2023: my ($msg,@newsec,$oldsec,$currrole_expired,@changed_roles,
1.264 raeburn 2024: %changed_groups,%dbroles,%deletedroles,%allroles,%allgroups,
1.260 raeburn 2025: %userroles,%checkedgroup,%crprivs,$hasgroups,%rolechange,
2026: %groupchange,%newrole,%newgroup,%customprivchg,%groups_roles,
2027: @rolecodes);
2028: my @possroles = ('cr','st','ta','ad','ep','in','co','cc');
2029: my %courseroles;
2030: foreach my $item (keys(%roleshash)) {
2031: my ($uname,$udom,$role,$remainder) = split(/:/,$item,4);
2032: my ($tstart,$tend) = split(/:/,$roleshash{$item});
2033: my ($section,$group,@group_privs);
2034: if ($role =~ m{^gr/(\w*)$}) {
2035: $role = 'gr';
2036: my $priv = $1;
2037: next if ($tstart eq '-1');
2038: if (&curr_role_status($tstart,$tend,$refresh,$now) eq 'active') {
2039: if ($priv ne '') {
2040: push(@group_privs,$priv);
2041: }
2042: }
2043: if ($remainder =~ /:/) {
2044: (my $additional_privs,$group) =
2045: ($remainder =~ /^([\w:]+):([^:]+)$/);
2046: if ($additional_privs ne '') {
2047: if (&curr_role_status($tstart,$tend,$refresh,$now) eq 'active') {
2048: push(@group_privs,split(/:/,$additional_privs));
2049: @group_privs = sort(@group_privs);
2050: }
2051: }
2052: } else {
2053: $group = $remainder;
2054: }
2055: } else {
2056: $section = $remainder;
2057: }
2058: my $where = "/$udom/$uname";
2059: if ($section ne '') {
2060: $where .= "/$section";
2061: } elsif ($group ne '') {
2062: $where .= "/$group";
2063: }
2064: my $rolekey = "$role.$where";
2065: my $envkey = "user.role.$rolekey";
2066: $dbroles{$envkey} = 1;
2067: if (($env{'request.role'} eq $rolekey) && ($role ne 'st')) {
2068: if (&curr_role_status($tstart,$tend,$refresh,$now) ne 'active') {
2069: $currrole_expired = 1;
2070: }
2071: }
2072: if ($env{$envkey} eq '') {
2073: my $status_in_db =
2074: &curr_role_status($tstart,$tend,$refresh,$now);
2075: &gather_roleprivs(\%allroles,\%allgroups,\%userroles,$where,$role,$tstart,$tend,$status_in_db);
2076: if (($role eq 'st') && ($env{'request.role'} =~ m{^\Q$role\E\.\Q/$udom/$uname\E})) {
2077: if ($status_in_db eq 'active') {
2078: if ($section eq '') {
2079: push(@newsec,'none');
2080: } else {
2081: push(@newsec,$section);
2082: }
2083: }
2084: } else {
2085: unless (grep(/^\Q$role\E$/,@changed_roles)) {
2086: push(@changed_roles,$role);
2087: }
2088: if ($status_in_db ne 'previous') {
2089: if ($role eq 'gr') {
2090: $newgroup{$rolekey} = $status_in_db;
2091: if ($status_in_db eq 'active') {
2092: unless (ref($courseroles{$udom}) eq 'HASH') {
2093: %{$courseroles{$udom}} =
2094: &Apache::lonnet::get_my_roles('','','userroles',
2095: ['active'],\@possroles,
2096: [$udom],1);
2097: }
2098: &Apache::lonnet::get_groups_roles($udom,$uname,
2099: $courseroles{$udom},
2100: \@rolecodes,\%groups_roles);
2101: }
2102: } else {
2103: $newrole{$rolekey} = $status_in_db;
2104: }
2105: }
2106: }
2107: } else {
2108: my ($currstart,$currend) = split(/\./,$env{$envkey});
2109: if ($role eq 'gr') {
2110: if (&curr_role_status($currstart,$currend,$refresh,$update) ne 'previous') {
2111: $hasgroups = 1;
2112: }
2113: }
2114: if (($currstart ne $tstart) || ($currend ne $tend)) {
2115: my $status_in_env =
2116: &curr_role_status($currstart,$currend,$refresh,$update);
2117: my $status_in_db =
2118: &curr_role_status($tstart,$tend,$refresh,$now);
2119: if ($status_in_env ne $status_in_db) {
2120: if ($status_in_env eq 'active') {
2121: if ($role eq 'st') {
2122: if ($env{'request.role'} eq $rolekey) {
2123: my $switchsection;
2124: unless (ref($courseroles{$udom}) eq 'HASH') {
2125: %{$courseroles{$udom}} =
2126: &Apache::lonnet::get_my_roles('','','userroles',
2127: ['active'],
2128: \@possroles,[$udom],1);
2129: }
2130: foreach my $crsrole (keys(%{$courseroles{$udom}})) {
2131: if ($crsrole =~ /^\Q$uname\E:\Q$udom\E:st/) {
2132: $switchsection = 1;
2133: last;
2134: }
2135: }
2136: if ($switchsection) {
2137: if ($section eq '') {
2138: $oldsec = 'none';
2139: } else {
2140: $oldsec = $section;
2141: }
2142: &gather_roleprivs(\%allroles,\%allgroups,\%userroles,$where,$role,$tstart,$tend,$status_in_db);
2143: } else {
2144: $currrole_expired = 1;
2145: next;
2146: }
2147: }
2148: }
2149: unless ($rolekey eq $env{'request.role'}) {
2150: if ($role eq 'gr') {
2151: &Apache::lonnet::delete_env_groupprivs($where,\%courseroles,\@possroles);
2152: } else {
2153: &Apache::lonnet::delenv("user.priv.$rolekey",undef,[$role]);
2154: &Apache::lonnet::delenv("user.priv.cm.$where",undef,['cm']);
2155: }
2156: &gather_roleprivs(\%allroles,\%allgroups,\%userroles,$where,$role,$tstart,$tend,$status_in_db);
2157: }
2158: } elsif ($status_in_db eq 'active') {
2159: if (($role eq 'st') &&
2160: ($env{'request.role'} =~ m{^\Q$role\E\.\Q/$udom/$uname\E})) {
2161: if ($section eq '') {
2162: push(@newsec,'none');
2163: } else {
2164: push(@newsec,$section);
2165: }
2166: } elsif ($role eq 'gr') {
2167: unless (ref($courseroles{$udom}) eq 'HASH') {
2168: %{$courseroles{$udom}} =
2169: &Apache::lonnet::get_my_roles('','','userroles',
2170: ['active'],
2171: \@possroles,[$udom],1);
2172: }
2173: &Apache::lonnet::get_groups_roles($udom,$uname,
2174: $courseroles{$udom},
2175: \@rolecodes,\%groups_roles);
2176: }
2177: &gather_roleprivs(\%allroles,\%allgroups,\%userroles,$where,$role,$tstart,$tend,$status_in_db);
2178: }
2179: unless (grep(/^\Q$role\E$/,@changed_roles)) {
2180: push(@changed_roles,$role);
2181: }
2182: if ($role eq 'gr') {
2183: $groupchange{"/$udom/$uname"}{$group} = $status_in_db;
2184: } else {
2185: $rolechange{$rolekey} = $status_in_db;
2186: }
2187: }
2188: } else {
2189: if ($role eq 'gr') {
2190: unless ($checkedgroup{$where}) {
2191: my $status_in_db =
2192: &curr_role_status($tstart,$tend,$refresh,$now);
2193: if ($tstart eq '-1') {
2194: $status_in_db = 'deleted';
2195: }
2196: unless (ref($courseroles{$udom}) eq 'HASH') {
2197: %{$courseroles{$udom}} =
2198: &Apache::lonnet::get_my_roles('','','userroles',
2199: ['active'],
2200: \@possroles,[$udom],1);
2201: }
2202: if (ref($courseroles{$udom}) eq 'HASH') {
2203: foreach my $item (keys(%{$courseroles{$udom}})) {
2204: next unless ($item =~ /^\Q$uname\E/);
2205: my ($cnum,$cdom,$crsrole,$crssec) = split(/:/,$item);
2206: my $area = '/'.$cdom.'/'.$cnum;
2207: if ($crssec ne '') {
2208: $area .= '/'.$crssec;
2209: }
2210: my $crsrolekey = $crsrole.'.'.$area;
2211: my $currprivs = $env{'user.priv.'.$crsrole.'.'.$area.'.'.$where};
2212: $currprivs =~ s/^://;
2213: $currprivs =~ s/\&F$//;
2214: my @curr_grp_privs = split(/\&F:/,$currprivs);
2215: @curr_grp_privs = sort(@curr_grp_privs);
2216: my @diffs;
2217: if (@group_privs > 0 || @curr_grp_privs > 0) {
2218: @diffs = &Apache::loncommon::compare_arrays(\@group_privs,\@curr_grp_privs);
2219: }
2220: if (@diffs == 0) {
2221: last;
2222: } else {
2223: unless(grep(/^\Qgr\E$/,@rolecodes)) {
2224: push(@rolecodes,'gr');
2225: }
2226: &gather_roleprivs(\%allroles,\%allgroups,
2227: \%userroles,$where,$role,
2228: $tstart,$tend,$status_in_db);
2229: if ($status_in_db eq 'active') {
2230: &Apache::lonnet::get_groups_roles($udom,$uname,
2231: $courseroles{$udom},
2232: \@rolecodes,\%groups_roles);
2233: }
2234: $changed_groups{$udom.'_'.$uname}{$group} = $status_in_db;
2235: last;
2236: }
2237: }
2238: }
2239: $checkedgroup{$where} = 1;
2240: }
2241: } elsif ($role =~ /^cr/) {
2242: my $status_in_db =
2243: &curr_role_status($tstart,$tend,$refresh,$now);
2244: my ($rdummy,$rest) = split(/\//,$role,2);
2245: my ($rdummy,$rdomain,$rauthor,$rrole)=split(/\//,$role);
2246: my %currpriv;
2247: unless (exists($crprivs{$rest})) {
2248: my ($rdomain,$rauthor,$rrole)=split(/\//,$rest);
2249: my $homsvr=&Apache::lonnet::homeserver($rauthor,$rdomain);
2250: if (&Apache::lonnet::hostname($homsvr) ne '') {
2251: my ($rdummy,$roledef)=
2252: &Apache::lonnet::get('roles',["rolesdef_$rrole"],
2253: $rdomain,$rauthor);
2254: if (($rdummy ne 'con_lost') && ($roledef ne '')) {
2255: my $i = 0;
2256: my @scopes = ('sys','dom','crs');
2257: my @privs = split(/\_/,$roledef);
2258: foreach my $priv (@privs) {
2259: my ($blank,@prv) = split(/:/,$priv);
2260: @prv = map { $_ .= (/\&\w+$/ ? '':'&F') } @prv;
1.264 raeburn 2261: if (@prv) {
2262: $priv = ':'.join(':',sort(@prv));
2263: }
1.260 raeburn 2264: $crprivs{$rest}{$scopes[$i]} = $priv;
2265: $i++;
2266: }
2267: }
2268: }
2269: }
2270: $currpriv{sys} = $env{"user.priv.$rolekey./"};
2271: $currpriv{dom} = $env{"user.priv.$rolekey./$udom/"};
2272: $currpriv{crs} = $env{"user.priv.$rolekey.$where"};
2273: if (keys(%crprivs)) {
2274: if (($crprivs{$rest}{sys} ne $currpriv{sys}) ||
2275: ($crprivs{$rest}{dom} ne $currpriv{dom})
2276: ||
2277: ($crprivs{$rest}{crs} ne $currpriv{crs})) {
2278: &gather_roleprivs(\%allroles,\%allgroups,\%userroles,$where,$role,$tstart,$tend,$status_in_db);
2279: unless (grep(/^\Q$role\E$/,@changed_roles)) {
2280: push(@changed_roles,$role);
2281: }
2282: my $status_in_env =
2283: &curr_role_status($currstart,$currend,$refresh,$update);
2284: if ($status_in_env eq 'active') {
2285: $customprivchg{$rolekey} = $status_in_env;
2286: }
2287: }
2288: }
2289: }
2290: }
2291: }
2292: }
2293: foreach my $envkey (keys(%env)) {
2294: next unless ($envkey =~ /^user\.role\./);
2295: next if ($dbroles{$envkey});
2296: next if ($envkey eq 'user.role.'.$env{'request.role'});
2297: my ($currstart,$currend) = split(/\./,$env{$envkey});
2298: my $status_in_env =
2299: &curr_role_status($currstart,$currend,$refresh,$update);
2300: my ($rolekey) = ($envkey =~ /^user\.role\.(.+)$/);
2301: my ($role,$rest)=split(/\./,$rolekey,2);
2302: if (&Apache::lonnet::delenv($envkey,undef,[$role])) {
2303: if ($status_in_env eq 'active') {
2304: if ($role eq 'gr') {
2305: &Apache::lonnet::delete_env_groupprivs($rest,\%courseroles,
2306: \@possroles);
2307: } else {
2308: &Apache::lonnet::delenv("user.priv.$rolekey",undef,[$role]);
2309: &Apache::lonnet::delenv("user.priv.cm.$rest",undef,['cm']);
2310: }
2311: unless (grep(/^\Q$role\E$/,@changed_roles)) {
2312: push(@changed_roles,$role);
2313: }
2314: $deletedroles{$rolekey} = 1;
2315: }
2316: }
2317: }
2318: if (($oldsec) && (@newsec > 0)) {
2319: if (@newsec > 1) {
2320: $msg = '<div 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.').'</div>';
2321: } else {
2322: my $newrole = $env{'request.role'};
2323: if ($newsec[0] eq 'none') {
2324: $newrole =~ s{(/[^/])$}{};
2325: } elsif ($oldsec eq 'none') {
2326: $newrole .= '/'.$newsec[0];
2327: } else {
2328: $newrole =~ s{([^/]+)$}{$newsec[0]};
2329: }
2330: my $coursedesc = $env{'course.'.$env{'request.course.id'}.'.description'};
2331: my ($curr_role) = ($env{'request.role'} =~ m{^(\w+)\./$match_domain/$match_courseid});
2332: my %temp=('logout_'.$env{'request.course.id'} => time);
2333: &Apache::lonnet::put('email_status',\%temp);
2334: &Apache::lonnet::delenv('user.state.'.$env{'request.course.id'});
2335: &Apache::lonnet::appenv({"request.course.id" => '',
2336: "request.course.fn" => '',
2337: "request.course.uri" => '',
2338: "request.course.sec" => '',
2339: "request.role" => 'cm',
2340: "request.role.adv" => $env{'user.adv'},
2341: "request.role.domain" => $env{'user.domain'}});
2342: my $rolename = &Apache::loncommon::plainname($curr_role);
2343: $msg = '<p><form name="reselectrole" action="/adm/roles" method="post" />'.
2344: '<input type="hidden" name="newrole" value="" />'.
2345: '<input type="hidden" name="selectrole" value="1" />'.
2346: '<span class="LC_info">'.
2347: &mt('Your section has changed for your current [_1] role in [_2].',$rolename,$coursedesc).'</span><br />';
2348: my $button = '<input type="button" name="sectionchanged" value="'.
2349: &mt('Re-Select').'" onclick="javascript:enterrole(this.form,'."'$newrole','sectionchanged'".')" />';
2350: if ($newsec[0] eq 'none') {
2351: $msg .= &mt('[_1] to continue with your new section-less role.',$button);
2352: } else {
2353: $msg .= &mt('[_1] to continue with your new role in section ([_2]).',$button,$newsec[0]);
2354: }
2355: $msg .= '</form></p>';
2356: }
2357: } elsif ($currrole_expired) {
2358: $msg .= '<div class="LC_warning">';
2359: if (&Apache::loncommon::show_course()) {
2360: $msg .= &mt('Your role in the current course has expired.');
2361: } else {
2362: $msg .= &mt('Your current role has expired.');
2363: }
2364: $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.').'</div>';
2365: }
2366: if (!@changed_roles || !(keys(%changed_groups))) {
1.264 raeburn 2367: my ($rolesmsg,$groupsmsg);
1.260 raeburn 2368: if (!@changed_roles) {
2369: if (&Apache::loncommon::show_course()) {
1.264 raeburn 2370: $rolesmsg = &mt('No new courses or communities');
1.260 raeburn 2371: } else {
1.264 raeburn 2372: $rolesmsg = &mt('No role changes');
1.260 raeburn 2373: }
2374: }
2375: if ($hasgroups && !(keys(%changed_groups)) && !(grep(/gr/,@changed_roles))) {
1.264 raeburn 2376: $groupsmsg = &mt('No changes in course/community groups');
1.260 raeburn 2377: }
2378: if (!@changed_roles && !(keys(%changed_groups))) {
1.264 raeburn 2379: if (($msg ne '') || ($groupsmsg ne '')) {
2380: $msg .= '<ul>';
2381: if ($rolesmsg) {
2382: $msg .= '<li>'.$rolesmsg.'</li>';
2383: }
2384: if ($groupsmsg) {
2385: $msg .= '<li>'.$groupsmsg.'</li>';
2386: }
2387: $msg .= '</ul>';
2388: } else {
1.270 ! raeburn 2389: $msg = ' <span class="LC_cusr_emph">'.$rolesmsg.'</span><br />';
1.264 raeburn 2390: }
1.260 raeburn 2391: return $msg;
2392: }
2393: }
2394: my $changemsg;
2395: if (@changed_roles > 0) {
2396: if (keys(%newgroup) > 0) {
2397: my $groupmsg;
2398: foreach my $item (sort(keys(%newgroup))) {
2399: if (&is_active_course($item,$refresh,$update,\%roleshash)) {
2400: $groupmsg .= '<li>'.
2401: &mt('[_1] with status: [_2].',
2402: $item,$newgroup{$item}).'</li>';
2403: }
2404: }
2405: if ($groupmsg) {
2406: $changemsg .= '<li>'.
2407: &mt('Courses with new groups').'</li>'.
2408: '<ul>'.$groupmsg.'</ul></li>';
2409: }
2410: }
2411: if (keys(%newrole) > 0) {
2412: $changemsg .= '<li>'.&mt('New roles').
2413: '<ul>';
2414: foreach my $item (sort(keys(%newrole))) {
2415: $changemsg .= '<li>'.
2416: &mt('[_1] with status: [_2].',
2417: $item,$newrole{$item}).'</li>';
2418: }
2419: $changemsg .= '</ul></li>';
2420: }
2421: if (keys(%customprivchg) > 0) {
2422: $changemsg .= '<li>'.
2423: &mt('Custom roles with privilege changes').
2424: '<ul>';
2425: foreach my $item (sort(keys(%customprivchg))) {
2426: $changemsg .= '<li>'.$item.'</li>';
2427: }
2428: $changemsg .= '</ul></li>';
2429: }
2430: if (keys(%rolechange) > 0) {
2431: $changemsg .= '<li>'.
2432: &mt('Existing roles with status changes').'</li>'.
2433: '<ul>';
2434: foreach my $item (sort(keys(%rolechange))) {
2435: $changemsg .= '<li>'.
2436: &mt('[_1] status now: [_2].',$item,
2437: $rolechange{$item}).'</li>';
2438: }
2439: $changemsg .= '</ul></li>';
2440: }
2441: if (keys(%deletedroles) > 0) {
2442: $changemsg .= '<li>'.
1.268 raeburn 2443: &mt('Existing roles now expired').'</li>'.
1.260 raeburn 2444: '<ul>';
2445: foreach my $item (sort(keys(%deletedroles))) {
2446: $changemsg .= '<li>'.$item.'</li>';
2447: }
2448: $changemsg .= '</ul></li>';
2449: }
2450: }
2451: if ((keys(%changed_groups) > 0) || (keys(%groupchange) > 0)) {
2452: my $groupchgmsg;
2453: foreach my $key (sort(keys(%changed_groups))) {
2454: my $crs = 'gr/'.$key;
2455: $crs =~ s/_/\//;
2456: if (&is_active_course($crs,$refresh,$update,\%roleshash)) {
2457: if (ref($changed_groups{$key}) eq 'HASH') {
2458: my @showgroups;
2459: foreach my $group (sort(keys(%{$changed_groups{$key}}))) {
2460: if ($changed_groups{$key}{$group} eq 'active') {
2461: push(@showgroups,$group);
2462: }
2463: }
2464: if (@showgroups > 0) {
2465: $groupchgmsg .= '<li>'.
2466: &mt('Course: [_1], groups: [_2].',$key,
2467: join(', ',@showgroups)).
2468: '</li>';
2469: }
2470: }
2471: }
2472: }
2473: if (keys(%groupchange) > 0) {
2474: $groupchgmsg .= '<li>'.
2475: &mt('Existing course/community groups with status changes').'</li>'.
2476: '<ul>';
2477: foreach my $crs (sort(keys(%groupchange))) {
2478: if (ref($groupchange{$crs}) eq 'HASH') {
2479: $groupchgmsg .= '<li>'.&mt('Course/Community: [_1]','<b>'.$crs.'</b><ul>');
2480: foreach my $group (sort(keys(%{$groupchange{$crs}}))) {
2481: $groupchgmsg .= '<li>'.&mt('Group: [_1] status now: [_2].','<b>'.$group.'</b>',$groupchange{$crs}{$group}).'</li>';
2482: }
2483: $groupchgmsg .= '</ul></li>';
2484: }
2485: }
2486: $groupchgmsg .= '</ul></li>';
2487: }
2488: if ($groupchgmsg) {
2489: $changemsg .= '<li>'.
2490: &mt('Courses with changes in groups').'</li>'.
2491: '<ul>'.$groupchgmsg.'</ul></li>';
2492: }
2493: }
2494: if ($changemsg) {
2495: $msg .= '<ul>'.$changemsg.'</ul>';
2496: }
2497: &Apache::lonnet::set_userprivs(\%userroles,\%allroles,\%allgroups,\%groups_roles);
2498: my ($curr_is_adv,$curr_role_adv,$curr_author,$curr_role_author);
2499: $curr_author = $env{'user.author'};
2500: if (($env{'request.role'} =~/^au/) || ($env{'request.role'} =~/^ca/) ||
2501: ($env{'request.role'} =~/^aa/)) {
2502: $curr_role_author=1;
2503: }
2504: $curr_is_adv = $env{'user.adv'};
2505: $curr_role_adv = $env{'request.role.adv'};
2506: if (keys(%userroles) > 0) {
2507: foreach my $role (@changed_roles) {
2508: unless(grep(/^\Q$role\E$/,@rolecodes)) {
2509: push(@rolecodes,$role);
2510: }
2511: }
2512: unless(grep(/^\Qcm\E$/,@rolecodes)) {
2513: push(@rolecodes,'cm');
2514: }
2515: &Apache::lonnet::appenv(\%userroles,\@rolecodes);
2516: }
2517: my %newenv;
2518: if (&Apache::lonnet::is_advanced_user($env{'user.domain'},$env{'user.name'})) {
2519: unless ($curr_is_adv) {
2520: $newenv{'user.adv'} = 1;
2521: }
2522: } elsif ($curr_is_adv && !$curr_role_adv) {
2523: &Apache::lonnet::delenv('user.adv');
2524: }
2525: my %authorroleshash =
2526: &Apache::lonnet::get_my_roles('','','userroles',['active'],['au','ca','aa']);
2527: if (keys(%authorroleshash)) {
2528: unless ($curr_author) {
2529: $newenv{'user.author'} = 1;
2530: }
2531: } elsif ($curr_author && !$curr_role_author) {
2532: &Apache::lonnet::delenv('user.author');
2533: }
2534: if ($env{'request.course.id'}) {
2535: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
2536: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
2537: my (@activecrsgroups,$crsgroupschanged);
2538: if ($env{'request.course.groups'}) {
2539: @activecrsgroups = split(/:/,$env{'request.course.groups'});
2540: foreach my $item (keys(%deletedroles)) {
2541: if ($item =~ m{^gr\./\Q$cdom\E/\Q$cnum\E/(\w+)$}) {
2542: if (grep(/^\Q$1\E$/,@activecrsgroups)) {
2543: $crsgroupschanged = 1;
2544: last;
2545: }
2546: }
2547: }
2548: }
2549: unless ($crsgroupschanged) {
2550: foreach my $item (keys(%newgroup)) {
2551: if ($item =~ m{^gr\./\Q$cdom\E/\Q$cnum\E/(\w+)$}) {
2552: if ($newgroup{$item} eq 'active') {
2553: $crsgroupschanged = 1;
2554: last;
2555: }
2556: }
2557: }
2558: }
2559: if ((ref($changed_groups{$env{'request.course.id'}}) eq 'HASH') ||
2560: (ref($groupchange{"/$cdom/$cnum"}) eq 'HASH') ||
2561: ($crsgroupschanged)) {
2562: my %grouproles = &Apache::lonnet::get_my_roles('','','userroles',
2563: ['active'],['gr'],[$cdom],1);
2564: my @activegroups;
2565: foreach my $item (keys(%grouproles)) {
2566: next unless($item =~ /^\Q$cnum\E:\Q$cdom\E/);
2567: my $group;
2568: my ($crsn,$crsd,$role,$remainder) = split(/:/,$item,4);
2569: if ($remainder =~ /:/) {
2570: (my $other,$group) = ($remainder =~ /^([\w:]+):([^:]+)$/);
2571: } else {
2572: $group = $remainder;
2573: }
2574: if ($group ne '') {
2575: push(@activegroups,$group);
2576: }
2577: }
2578: $newenv{'request.course.groups'} = join(':',@activegroups);
2579: }
2580: }
2581: if (keys(%newenv)) {
2582: &Apache::lonnet::appenv(\%newenv);
2583: }
2584: return $msg;
2585: }
2586:
2587: sub curr_role_status {
2588: my ($start,$end,$refresh,$update) = @_;
2589: if (($start) && ($start<0)) { return 'deleted' };
2590: my $status = 'active';
2591: if (($end) && ($end<=$update)) {
2592: $status = 'previous';
2593: }
2594: if (($start) && ($refresh<$start)) {
2595: $status = 'future';
2596: }
2597: return $status;
2598: }
2599:
2600: sub gather_roleprivs {
2601: my ($allroles,$allgroups,$userroles,$area,$role,$tstart,$tend,$status) = @_;
2602: return unless ((ref($allroles) eq 'HASH') && (ref($allgroups) eq 'HASH') && (ref($userroles) eq 'HASH'));
2603: if (($area ne '') && ($role ne '')) {
2604: &Apache::lonnet::userrolelog($role,$env{'user.name'},$env{'user.domain'},
2605: $area,$tstart,$tend);
2606: my $spec=$role.'.'.$area;
2607: $userroles->{'user.role.'.$spec} = $tstart.'.'.$tend;
2608: my ($tdummy,$tdomain,$trest)=split(/\//,$area);
2609: if ($status eq 'active') {
2610: if ($role =~ /^cr\//) {
2611: &Apache::lonnet::custom_roleprivs($allroles,$role,$tdomain,$trest,$spec,$area);
2612: } elsif ($role eq 'gr') {
2613: my %rolehash = &Apache::lonnet::get('roles',[$area.'_'.$role],
2614: $env{'user.domain'},
2615: $env{'user.name'});
2616: my ($trole) = split(/_/,$rolehash{$area.'_'.$role},2);
2617: (undef,my $group_privs) = split(/\//,$trole);
2618: $group_privs = &unescape($group_privs);
2619: &Apache::lonnet::group_roleprivs($allgroups,$area,$group_privs,$tend,$tstart);
2620: } else {
2621: &Apache::lonnet::standard_roleprivs($allroles,$role,$tdomain,$spec,$trest,$area);
2622: }
2623: }
2624: }
2625: return;
2626: }
2627:
2628: sub is_active_course {
2629: my ($rolekey,$refresh,$update,$roleshashref) = @_;
2630: return unless(ref($roleshashref) eq 'HASH');
2631: my ($role,$cdom,$cnum) = split(/\//,$rolekey);
2632: my $is_active;
2633: foreach my $key (keys(%{$roleshashref})) {
2634: if ($key =~ /^\Q$cnum\E:\Q$cdom\E:/) {
2635: my ($tstart,$tend) = split(/:/,$roleshashref->{$key});
2636: my $status = &curr_role_status($tstart,$tend,$refresh,$update);
2637: if ($status eq 'active') {
2638: $is_active = 1;
2639: last;
2640: }
2641: }
2642: }
2643: return $is_active;
2644: }
2645:
1.1 harris41 2646: 1;
2647: __END__
1.32 harris41 2648:
2649: =head1 NAME
2650:
2651: Apache::lonroles - User Roles Screen
2652:
2653: =head1 SYNOPSIS
2654:
2655: Invoked by /etc/httpd/conf/srm.conf:
2656:
2657: <Location /adm/roles>
2658: PerlAccessHandler Apache::lonacc
2659: SetHandler perl-script
2660: PerlHandler Apache::lonroles
2661: ErrorDocument 403 /adm/login
2662: ErrorDocument 500 /adm/errorhandler
2663: </Location>
1.64 bowersj2 2664:
2665: =head1 OVERVIEW
2666:
2667: =head2 Choosing Roles
2668:
2669: C<lonroles> is a handler that allows a user to switch roles in
2670: mid-session. LON-CAPA attempts to work with "No Role Specified", the
2671: default role that a user has before selecting a role, as widely as
2672: possible, but certain handlers for example need specification which
2673: course they should act on, etc. Both in this scenario, and when the
2674: handler determines via C<lonnet>'s C<&allowed> function that a certain
2675: action is not allowed, C<lonroles> is used as error handler. This
2676: allows the user to select another role which may have permission to do
1.246 droeschl 2677: what they were trying to do.
1.64 bowersj2 2678:
2679: =begin latex
2680:
2681: \begin{figure}
2682: \begin{center}
2683: \includegraphics[width=0.45\paperwidth,keepaspectratio]{Sample_Roles_Screen}
2684: \caption{\label{Sample_Roles_Screen}Sample Roles Screen}
2685: \end{center}
2686: \end{figure}
2687:
2688: =end latex
2689:
2690: =head2 Role Initialization
2691:
2692: 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 2693:
2694: =head1 INTRODUCTION
2695:
2696: This module enables a user to select what role he wishes to
2697: operate under (instructor, student, teaching assistant, course
2698: coordinator, etc). These roles are pre-established by the actions
2699: of upper-level users.
2700:
2701: This is part of the LearningOnline Network with CAPA project
2702: described at http://www.lon-capa.org.
2703:
2704: =head1 HANDLER SUBROUTINE
2705:
2706: This routine is called by Apache and mod_perl.
2707:
2708: =over 4
2709:
2710: =item *
2711:
2712: Roles Initialization (yes/no)
2713:
2714: =item *
2715:
2716: Get Error Message from Environment
2717:
2718: =item *
2719:
2720: Who is this?
2721:
2722: =item *
2723:
2724: Generate Page Output
2725:
2726: =item *
2727:
2728: Choice or no choice
2729:
2730: =item *
2731:
2732: Table
2733:
2734: =item *
2735:
2736: Privileges
2737:
2738: =back
2739:
2740: =cut
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>