Annotation of loncom/auth/lonroles.pm, revision 1.240.2.22
1.1 harris41 1: # The LearningOnline Network with CAPA
2: # User Roles Screen
1.31 www 3: #
1.240.2.22! raeburn 4: # $Id: lonroles.pm,v 1.240.2.21 2010/12/05 16:35:58 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
60: what they were trying to do. C<lonroles> can also be accessed via the
61: B<CRS> button in the Remote Control.
62:
63: =begin latex
64:
65: \begin{figure}
66: \begin{center}
67: \includegraphics[width=0.45\paperwidth,keepaspectratio]{Sample_Roles_Screen}
68: \caption{\label{Sample_Roles_Screen}Sample Roles Screen}
69: \end{center}
70: \end{figure}
71:
72: =end latex
73:
74: =head2 Role Initialization
75:
76: 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.
77:
78: =head1 INTRODUCTION
79:
80: This module enables a user to select what role he wishes to
81: operate under (instructor, student, teaching assistant, course
82: coordinator, etc). These roles are pre-established by the actions
83: of upper-level users.
84:
85: This is part of the LearningOnline Network with CAPA project
86: described at http://www.lon-capa.org.
87:
88: =head1 HANDLER SUBROUTINE
89:
90: This routine is called by Apache and mod_perl.
91:
92: =over 4
93:
94: =item *
95:
96: Roles Initialization (yes/no)
97:
98: =item *
99:
100: Get Error Message from Environment
101:
102: =item *
103:
104: Who is this?
105:
106: =item *
107:
108: Generate Page Output
109:
110: =item *
111:
112: Choice or no choice
113:
114: =item *
115:
116: Table
117:
118: =item *
119:
120: Privileges
121:
122: =back
123:
124: =cut
125:
126:
1.1 harris41 127: package Apache::lonroles;
128:
129: use strict;
1.118 albertel 130: use Apache::lonnet;
1.7 www 131: use Apache::lonuserstate();
1.1 harris41 132: use Apache::Constants qw(:common);
1.2 www 133: use Apache::File();
1.26 www 134: use Apache::lonmenu;
1.29 albertel 135: use Apache::loncommon;
1.104 raeburn 136: use Apache::lonhtmlcommon;
1.57 www 137: use Apache::lonannounce;
1.72 www 138: use Apache::lonlocal;
1.151 www 139: use Apache::lonpageflip();
1.167 albertel 140: use Apache::lonnavdisplay();
1.240.2.9 raeburn 141: use Apache::loncoursequeueadmin;
1.120 albertel 142: use GDBM_File;
1.170 albertel 143: use LONCAPA qw(:DEFAULT :match);
1.201 raeburn 144: use HTML::Entities;
1.149 www 145:
1.1 harris41 146:
1.62 matthew 147: sub redirect_user {
1.95 albertel 148: my ($r,$title,$url,$msg,$launch_nav) = @_;
1.62 matthew 149: $msg = $title if (! defined($msg));
1.73 www 150: &Apache::loncommon::content_type($r,'text/html');
1.62 matthew 151: &Apache::loncommon::no_cache($r);
152: $r->send_http_header;
153: my $swinfo=&Apache::lonmenu::rawconfig();
1.96 albertel 154: my $navwindow;
1.95 albertel 155: if ($launch_nav eq 'on') {
1.166 albertel 156: $navwindow.=&Apache::lonnavdisplay::launch_win('now',undef,undef,
157: ($url =~ m-^/adm/whatsnew-));
1.96 albertel 158: } else {
159: $navwindow.=&Apache::lonnavmaps::close();
1.95 albertel 160: }
1.228 bisitz 161:
162: # Breadcrumbs
163: my $brcrum = [{'href' => $url,
164: 'text' => 'Switching Role'},];
1.147 albertel 165: my $start_page = &Apache::loncommon::start_page('Switching Role',undef,
1.228 bisitz 166: {'redirect' => [1,$url],
167: 'bread_crumbs' => $brcrum,});
1.240.2.6 raeburn 168: &Apache::lonhtmlcommon::clear_breadcrumbs();
1.147 albertel 169: my $end_page = &Apache::loncommon::end_page();
170:
1.92 www 171: # Note to style police:
172: # This must only replace the spaces, nothing else, or it bombs elsewhere.
173: $url=~s/ /\%20/g;
1.93 albertel 174: $r->print(<<ENDREDIR);
1.147 albertel 175: $start_page
1.96 albertel 176: <script type="text/javascript">
1.225 bisitz 177: // <![CDATA[
1.62 matthew 178: $swinfo
1.225 bisitz 179: // ]]>
1.62 matthew 180: </script>
1.96 albertel 181: $navwindow
1.222 bisitz 182: <p>$msg</p>
1.147 albertel 183: $end_page
1.62 matthew 184: ENDREDIR
185: return;
186: }
187:
1.150 www 188: sub error_page {
189: my ($r,$error,$dest)=@_;
190: &Apache::loncommon::content_type($r,'text/html');
191: &Apache::loncommon::no_cache($r);
192: $r->send_http_header;
193: return OK if $r->header_only;
1.228 bisitz 194: # Breadcrumbs
195: my $brcrum = [{'href' => $dest,
196: 'text' => 'Problems during Course Initialization'},];
197: $r->print(&Apache::loncommon::start_page('Problems during Course Initialization',
198: undef,
199: {'bread_crumbs' => $brcrum,})
200: );
201: $r->print(
1.225 bisitz 202: '<script type="text/javascript">'.
203: '// <![CDATA['.
204: &Apache::lonmenu::rawconfig().
205: '// ]]>'.
206: '</script>'.
207: '<p class="LC_error">'.&mt('The following problems occurred:').
1.228 bisitz 208: '<br />'.
1.150 www 209: $error.
1.228 bisitz 210: '</p><br /><a href="'.$dest.'">'.&mt('Continue').'</a>'
211: );
212: $r->print(&Apache::loncommon::end_page());
1.150 www 213: }
214:
1.1 harris41 215: sub handler {
1.10 www 216:
1.1 harris41 217: my $r = shift;
218:
1.6 www 219: my $now=time;
1.118 albertel 220: my $then=$env{'user.login.time'};
1.226 raeburn 221: my $refresh=$env{'user.refresh.time'};
222: if (!$refresh) {
223: $refresh = $then;
224: }
1.6 www 225: my $envkey;
1.107 raeburn 226: my %dcroles = ();
227: my $numdc = &check_fordc(\%dcroles,$then);
1.148 albertel 228: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'});
1.240.2.3 raeburn 229: my $custommenu = &Apache::loncommon::needs_gci_custom();
1.10 www 230:
1.6 www 231: # ================================================================== Roles Init
1.118 albertel 232: if ($env{'form.selectrole'}) {
1.188 www 233:
234: my $locknum=&Apache::lonnet::get_locks();
235: if ($locknum) { return 409; }
236:
1.134 www 237: if ($env{'form.newrole'}) {
238: $env{'form.'.$env{'form.newrole'}}=1;
239: }
1.118 albertel 240: if ($env{'request.course.id'}) {
1.185 raeburn 241: # Check if user is CC trying to select a course role
242: if ($env{'form.switchrole'}) {
243: if (!defined($env{'user.role.'.$env{'form.switchrole'}})) {
1.232 raeburn 244: &adhoc_course_role($refresh,$then);
1.185 raeburn 245: }
246: }
1.118 albertel 247: my %temp=('logout_'.$env{'request.course.id'} => time);
1.33 www 248: &Apache::lonnet::put('email_status',\%temp);
1.118 albertel 249: &Apache::lonnet::delenv('user.state.'.$env{'request.course.id'});
1.100 albertel 250: }
1.186 raeburn 251: &Apache::lonnet::appenv({"request.course.id" => '',
252: "request.course.fn" => '',
253: "request.course.uri" => '',
254: "request.course.sec" => '',
255: "request.role" => 'cm',
256: "request.role.adv" => $env{'user.adv'},
257: "request.role.domain" => $env{'user.domain'}});
1.182 www 258: # Check if user is a DC trying to enter a course or author space and needs privs to be created
1.107 raeburn 259: if ($numdc > 0) {
1.118 albertel 260: foreach my $envkey (keys %env) {
1.240 raeburn 261: # Is this an ad-hoc Coordinator role?
262: if (my ($ccrole,$domain,$coursenum) =
263: ($envkey =~ m-^form\.(cc|co)\./($match_domain)/($match_courseid)$-)) {
1.146 raeburn 264: if ($dcroles{$domain}) {
1.218 raeburn 265: &Apache::lonnet::check_adhoc_privs($domain,$coursenum,
1.240 raeburn 266: $then,$refresh,$now,$ccrole);
1.182 www 267: }
268: last;
269: }
1.193 raeburn 270: # Is this an ad-hoc CA-role?
1.183 www 271: if (my ($domain,$user) =
272: ($envkey =~ m-^form\.ca\./($match_domain)/($match_username)$-)) {
1.206 raeburn 273: if (($domain eq $env{'user.domain'}) && ($user eq $env{'user.name'})) {
274: delete($env{$envkey});
275: $env{'form.au./'.$domain.'/'} = 1;
276: my ($server_status,$home) = &check_author_homeserver($user,$domain);
277: if ($server_status eq 'switchserver') {
278: my $trolecode = 'au./'.$domain.'/';
279: my $switchserver = '/adm/switchserver?otherserver='.$home.'&role='.$trolecode;
280: $r->internal_redirect($switchserver);
281: }
282: last;
283: }
284: if (my ($castart,$caend) = ($env{'user.role.ca./'.$domain.'/'.$user} =~ /^(\d*)\.(\d*)$/)) {
285: if (((($castart) && ($castart < $now)) || !$castart) &&
286: ((!$caend) || (($caend) && ($caend > $now)))) {
287: my ($server_status,$home) = &check_author_homeserver($user,$domain);
288: if ($server_status eq 'switchserver') {
289: my $trolecode = 'ca./'.$domain.'/'.$user;
290: my $switchserver = '/adm/switchserver?otherserver='.$home.'&role='.$trolecode;
291: $r->internal_redirect($switchserver);
292: }
293: last;
294: }
295: }
296: # Check if author blocked ca-access
1.190 www 297: my %blocked=&Apache::lonnet::get('environment',['domcoord.author'],$domain,$user);
298: if ($blocked{'domcoord.author'} eq 'blocked') {
1.206 raeburn 299: delete($env{$envkey});
300: $env{'user.error.msg'}=':::1:User '.$user.' in domain '.$domain.' blocked domain coordinator access';
301: last;
1.190 www 302: }
1.193 raeburn 303: if ($dcroles{$domain}) {
304: my ($server_status,$home) = &check_author_homeserver($user,$domain);
305: if (($server_status eq 'ok') || ($server_status eq 'switchserver')) {
1.218 raeburn 306: &Apache::lonnet::check_adhoc_privs($domain,$user,$then,
1.230 raeburn 307: $refresh,$now,'ca');
1.193 raeburn 308: if ($server_status eq 'switchserver') {
309: my $trolecode = 'ca./'.$domain.'/'.$user;
310: my $switchserver = '/adm/switchserver?'
311: .'otherserver='.$home.'&role='.$trolecode;
312: $r->internal_redirect($switchserver);
313: }
314: } else {
315: delete($env{$envkey});
316: }
1.183 www 317: } else {
318: delete($env{$envkey});
1.182 www 319: }
320: last;
321: }
1.107 raeburn 322: }
323: }
1.240.2.3 raeburn 324: if (($env{'form.cm'}) && ($env{'form.orgurl'})) {
1.240.2.2 raeburn 325: $r->internal_redirect($env{'form.orgurl'});
326: }
1.118 albertel 327: foreach $envkey (keys %env) {
1.40 matthew 328: next if ($envkey!~/^user\.role\./);
1.102 raeburn 329: my ($where,$trolecode,$role,$tstatus,$tend,$tstart);
1.226 raeburn 330: &Apache::lonnet::role_status($envkey,$then,$refresh,$now,\$role,\$where,
1.218 raeburn 331: \$trolecode,\$tstatus,\$tstart,\$tend);
1.118 albertel 332: if ($env{'form.'.$trolecode}) {
1.55 albertel 333: if ($tstatus eq 'is') {
334: $where=~s/^\///;
335: my ($cdom,$cnum,$csec)=split(/\//,$where);
1.137 raeburn 336: # check for course groups
337: my %coursegroups = &Apache::lonnet::get_active_groups(
338: $env{'user.domain'},$env{'user.name'},$cdom, $cnum);
339: my $cgrps = join(':',keys(%coursegroups));
340:
1.111 albertel 341: # store role if recent_role list being kept
1.118 albertel 342: if ($env{'environment.recentroles'}) {
1.158 albertel 343: my %frozen_roles =
344: &Apache::lonhtmlcommon::get_recent_frozen('roles',$env{'environment.recentrolesn'});
1.111 albertel 345: &Apache::lonhtmlcommon::store_recent('roles',
1.158 albertel 346: $trolecode,' ',$frozen_roles{$trolecode});
1.111 albertel 347: }
348:
349:
1.53 www 350: # check for keyed access
1.55 albertel 351: if (($role eq 'st') &&
1.118 albertel 352: ($env{'course.'.$cdom.'_'.$cnum.'.keyaccess'} eq 'yes')) {
1.89 www 353: # who is key authority?
354: my $authdom=$cdom;
355: my $authnum=$cnum;
1.118 albertel 356: if ($env{'course.'.$cdom.'_'.$cnum.'.keyauth'}) {
1.89 www 357: ($authnum,$authdom)=
1.172 albertel 358: split(/:/,$env{'course.'.$cdom.'_'.$cnum.'.keyauth'});
1.89 www 359: }
360: # check with key authority
361: unless (&Apache::lonnet::validate_access_key(
1.118 albertel 362: $env{'environment.key.'.$cdom.'_'.$cnum},
1.89 www 363: $authdom,$authnum)) {
1.53 www 364: # there is no valid key
1.118 albertel 365: if ($env{'form.newkey'}) {
1.53 www 366: # student attempts to register a new key
1.89 www 367: &Apache::loncommon::content_type($r,'text/html');
368: &Apache::loncommon::no_cache($r);
369: $r->send_http_header;
370: my $swinfo=&Apache::lonmenu::rawconfig();
1.147 albertel 371: my $start_page=&Apache::loncommon::start_page
1.89 www 372: ('Verifying Access Key to Unlock this Course');
1.147 albertel 373: my $end_page=&Apache::loncommon::end_page();
1.90 www 374: my $buttontext=&mt('Enter Course');
375: my $message=&mt('Successfully registered key');
376: my $assignresult=
377: &Apache::lonnet::assign_access_key(
1.118 albertel 378: $env{'form.newkey'},
1.90 www 379: $authdom,$authnum,
1.91 www 380: $cdom,$cnum,
1.118 albertel 381: $env{'user.domain'},
382: $env{'user.name'},
1.204 bisitz 383: &mt('Assigned from [_1] at [_2] for [_3]'
384: ,$ENV{'REMOTE_ADDR'}
385: ,&Apache::lonlocal::locallocaltime()
386: ,$trolecode)
387: );
1.90 www 388: unless ($assignresult eq 'ok') {
389: $assignresult=~s/^error\:\s*//;
390: $message=&mt($assignresult).
391: '<br /><a href="/adm/logout">'.
1.89 www 392: &mt('Logout').'</a>';
1.90 www 393: $buttontext=&mt('Re-Enter Key');
394: }
1.89 www 395: $r->print(<<ENDENTEREDKEY);
1.147 albertel 396: $start_page
1.179 raeburn 397: <script type="text/javascript">
1.225 bisitz 398: // <![CDATA[
1.89 www 399: $swinfo
1.225 bisitz 400: // ]]>
1.89 www 401: </script>
1.225 bisitz 402: <form action="" method="post">
1.89 www 403: <input type="hidden" name="selectrole" value="1" />
404: <input type="hidden" name="$trolecode" value="1" />
1.211 tempelho 405: <span class="LC_fontsize_large">$message</span><br />
1.89 www 406: <input type="submit" value="$buttontext" />
407: </form>
1.147 albertel 408: $end_page
1.89 www 409: ENDENTEREDKEY
410: return OK;
1.55 albertel 411: } else {
1.53 www 412: # print form to enter a new key
1.73 www 413: &Apache::loncommon::content_type($r,'text/html');
1.55 albertel 414: &Apache::loncommon::no_cache($r);
415: $r->send_http_header;
416: my $swinfo=&Apache::lonmenu::rawconfig();
1.147 albertel 417: my $start_page=&Apache::loncommon::start_page
1.55 albertel 418: ('Enter Access Key to Unlock this Course');
1.147 albertel 419: my $end_page=&Apache::loncommon::end_page();
1.55 albertel 420: $r->print(<<ENDENTERKEY);
1.147 albertel 421: $start_page
1.179 raeburn 422: <script type="text/javascript">
1.225 bisitz 423: // <![CDATA[
1.53 www 424: $swinfo
1.225 bisitz 425: // ]]>
1.53 www 426: </script>
1.225 bisitz 427: <form action="" method="post">
1.89 www 428: <input type="hidden" name="selectrole" value="1" />
429: <input type="hidden" name="$trolecode" value="1" />
1.118 albertel 430: <input type="text" size="20" name="newkey" value="$env{'form.newkey'}" />
1.53 www 431: <input type="submit" value="Enter key" />
432: </form>
1.147 albertel 433: $end_page
1.53 www 434: ENDENTERKEY
1.55 albertel 435: return OK;
436: }
437: }
438: }
1.118 albertel 439: &Apache::lonnet::log($env{'user.domain'},
440: $env{'user.name'},
441: $env{'user.home'},
1.87 www 442: "Role ".$trolecode);
1.101 albertel 443:
1.56 www 444: &Apache::lonnet::appenv(
1.186 raeburn 445: {'request.role' => $trolecode,
446: 'request.role.domain' => $cdom,
447: 'request.course.sec' => $csec,
448: 'request.course.groups' => $cgrps});
1.101 albertel 449: my $tadv=0;
1.62 matthew 450:
1.125 www 451: if (($cnum) && ($role ne 'ca') && ($role ne 'aa')) {
1.152 raeburn 452: my $msg;
1.240.2.4 raeburn 453: if (&Apache::lonnet::allowed('adv') eq 'F') { $tadv=1; }
454: &Apache::lonnet::appenv({'request.role.adv'=>$tadv});
1.55 albertel 455: my ($furl,$ferr)=
456: &Apache::lonuserstate::readmap($cdom.'/'.$cnum);
1.240.2.15 raeburn 457: if ($custommenu) {
458: unless (($ferr) || ($env{'form.switchrole'})) {
459: &Apache::lonnet::put('nohist_crslastlogin',{$env{'user.name'}.':'.$env{'user.domain'}.':'.$csec.':'.$role => $now},
460: $cdom,$cnum);
461: }
462: }
1.118 albertel 463: if (($env{'form.orgurl'}) &&
464: ($env{'form.orgurl'}!~/^\/adm\/flip/)) {
465: my $dest=$env{'form.orgurl'};
1.219 raeburn 466: if ($env{'form.symb'}) {
467: if ($dest =~ /\?/) {
468: $dest .= '&';
469: } else {
470: $dest .= '?'
471: }
472: $dest .= 'symb='.$env{'form.symb'};
473: }
1.150 www 474: if (($ferr) && ($tadv)) {
475: &error_page($r,$ferr,$dest);
476: } else {
477: $r->internal_redirect($dest);
478: }
1.55 albertel 479: return OK;
480: } else {
1.155 albertel 481: if (!$env{'request.course.id'}) {
1.55 albertel 482: &Apache::lonnet::appenv(
1.186 raeburn 483: {"request.course.id" => $cdom.'_'.$cnum});
1.61 www 484: $furl='/adm/roles?tryagain=1';
1.221 bisitz 485: $msg='<p><span class="LC_error">'
486: .&mt('Could not initialize [_1] at this time.',
487: $env{'course.'.$cdom.'_'.$cnum.'.description'})
488: .'</span></p>'
489: .'<p>'.&mt('Please try again.').'</p>'
490: .'<p>'.$ferr.'</p>';
1.55 albertel 491: }
1.152 raeburn 492:
1.150 www 493: if (($ferr) && ($tadv)) {
494: &error_page($r,$ferr,$furl);
495: } else {
496: # Check to see if the user is a CC entering a course
497: # for the first time
498: my (undef, undef, $role, $courseid) = split(/\./, $envkey);
499: if (substr($courseid, 0, 1) eq '/') {
500: $courseid = substr($courseid, 1);
501: }
502: $courseid =~ s/\//_/;
1.240.2.21 raeburn 503: if (($cdom !~ /^\w+citest$/) && (($role eq 'cc') || ($role eq 'co'))
1.240 raeburn 504: && ($env{'course.' . $courseid .'.course.helper.not.run'})) {
1.150 www 505: $furl = "/adm/helper/course.initialization.helper";
506: # Send the user to the course they selected
507: } elsif ($env{'request.course.id'}) {
1.185 raeburn 508: if ($env{'form.destinationurl'}) {
509: my $dest = $env{'form.destinationurl'};
1.203 raeburn 510: if ($env{'form.destsymb'} ne '') {
511: my $esc_symb = &HTML::Entities::encode($env{'form.destsymb'},'"<>&');
512: $dest .= '?symb='.$esc_symb;
513: }
1.185 raeburn 514: &redirect_user($r,&mt('Entering [_1]',
515: $env{'course.'.$courseid.'.description'}),
516: $dest,$msg,
517: $env{'environment.remotenavmap'});
518: return OK;
519: }
1.150 www 520: if (&Apache::lonnet::allowed('whn',
521: $env{'request.course.id'})
522: || &Apache::lonnet::allowed('whn',
523: $env{'request.course.id'}.'/'
524: .$env{'request.course.sec'})
525: ) {
526: my $startpage = &courseloadpage($courseid);
1.240.2.21 raeburn 527: unless (($startpage eq 'firstres') || ($cdom =~ /^\w+citest$/)) {
1.204 bisitz 528: $msg = &mt('Entering [_1] ...',
1.162 albertel 529: $env{'course.'.$courseid.'.description'});
1.150 www 530: &redirect_user($r,&mt('New in course'),
531: '/adm/whatsnew?refpage=start',$msg,
532: $env{'environment.remotenavmap'});
533: return OK;
534: }
535: }
536: }
1.151 www 537: # Are we allowed to look at the first resource?
1.169 albertel 538: if ($furl !~ m|^/adm/|) {
1.151 www 539: # Guess not ...
540: $furl=&Apache::lonpageflip::first_accessible_resource();
541: }
1.240.2.21 raeburn 542: if (($cdom =~ /^\w+citest$/) && ($custommenu)) {
1.240.2.3 raeburn 543: $furl = '/adm/navmaps';
544: }
1.162 albertel 545: $msg = &mt('Entering [_1] ...',
546: $env{'course.'.$courseid.'.description'});
547: &redirect_user($r,&mt('Entering [_1]',
548: $env{'course.'.$courseid.'.description'}),
1.150 www 549: $furl,$msg,
550: $env{'environment.remotenavmap'});
1.58 bowersj2 551: }
1.124 albertel 552: return OK;
1.55 albertel 553: }
554: }
1.62 matthew 555: #
556: # Send the user to the construction space they selected
1.125 www 557: if ($role =~ /^(au|ca|aa)$/) {
1.62 matthew 558: my $redirect_url = '/priv/';
559: if ($role eq 'au') {
1.118 albertel 560: $redirect_url.=$env{'user.name'};
1.62 matthew 561: } else {
562: $where =~ /\/(.*)$/;
563: $redirect_url .= $1;
564: }
565: $redirect_url .= '/';
1.78 sakharuk 566: &redirect_user($r,&mt('Entering Construction Space'),
1.62 matthew 567: $redirect_url);
568: return OK;
569: }
1.104 raeburn 570: if ($role eq 'dc') {
1.108 raeburn 571: my $redirect_url = '/adm/menu/';
572: &redirect_user($r,&mt('Loading Domain Coordinator Menu'),
1.104 raeburn 573: $redirect_url);
1.108 raeburn 574: return OK;
1.104 raeburn 575: }
1.220 raeburn 576: if ($role eq 'sc') {
577: my $redirect_url = '/adm/grades?command=scantronupload';
578: &redirect_user($r,&mt('Loading Data Upload Page'),
579: $redirect_url);
580: return OK;
581: }
1.55 albertel 582: }
583: }
1.6 www 584: }
1.40 matthew 585: }
1.44 www 586:
1.6 www 587: # =============================================================== No Roles Init
1.10 www 588:
1.73 www 589: &Apache::loncommon::content_type($r,'text/html');
1.30 albertel 590: &Apache::loncommon::no_cache($r);
1.10 www 591: $r->send_http_header;
592: return OK if $r->header_only;
593:
1.240.2.3 raeburn 594: my ($crumbtext,$pagetitle,$recent,$show_course);
1.240.2.18 raeburn 595: $show_course=&Apache::loncommon::show_course();
1.240.2.19 raeburn 596: my $noscript='<br /><span class="LC_error">'.&mt('Use of LON-CAPA requires Javascript to be enabled in your web browser.').'<br />'.&mt('As this is not the case, most functionality in the system will be unavailable.').'</span><br />';
1.240.2.3 raeburn 597: if ($custommenu) {
1.240.2.19 raeburn 598: my $start_page = &Apache::loncommon::start_page('Main Menu');
1.240.2.3 raeburn 599: $r->print(<<"ENDCUSTOM");
600: $start_page
601: <noscript>
602: $noscript
603: </noscript>
604: ENDCUSTOM
605: } else {
606: $crumbtext = 'User Roles';
607: $pagetitle = 'My Roles';
608: $recent = &mt('Recent Roles');
1.240.2.18 raeburn 609: my $standby=&mt('Role selected. Please stand by.');
1.240.2.3 raeburn 610: if ($show_course) {
611: $crumbtext = 'Courses';
612: $pagetitle = 'My Courses';
613: $recent = &mt('Recent Courses');
1.240.2.18 raeburn 614: $standby = &mt('Course selected. Please stand by.');
615: }
616: my $brcrum = [{ href => '/adm/roles',
617: text => $crumbtext,},
618: ];
619: my $args;
1.240.2.19 raeburn 620: if ($numdc) {
1.240.2.18 raeburn 621: $args = {bread_crumbs => $brcrum};
1.240.2.19 raeburn 622: } else {
623: $args = {bread_crumbs => $brcrum,
624: bread_crumbs_menulink => '_nomenu'};
1.240.2.3 raeburn 625: }
1.240.2.18 raeburn 626: my $start_page=&Apache::loncommon::start_page($pagetitle,undef,$args);
1.240.2.3 raeburn 627: my $swinfo=&Apache::lonmenu::rawconfig();
628: $standby=~s/\n/\\n/g;
629: $r->print(<<ENDHEADER);
1.147 albertel 630: $start_page
1.179 raeburn 631: <noscript>
632: $noscript
633: </noscript>
634: <script type="text/javascript">
1.225 bisitz 635: // <![CDATA[
1.26 www 636: $swinfo
637: window.focus();
1.134 www 638:
639: active=true;
640:
641: function enterrole (thisform,rolecode,buttonname) {
642: if (active) {
643: active=false;
644: document.title='$standby';
645: window.status='$standby';
646: thisform.newrole.value=rolecode;
647: thisform.submit();
648: } else {
649: alert('$standby');
650: }
651: }
1.225 bisitz 652: // ]]>
1.26 www 653: </script>
1.10 www 654: ENDHEADER
1.240.2.3 raeburn 655: }
1.6 www 656:
1.2 www 657: # ------------------------------------------ Get Error Message from Environment
658:
1.118 albertel 659: my ($fn,$priv,$nochoose,$error,$msg)=split(/:/,$env{'user.error.msg'});
660: if ($env{'user.error.msg'}) {
1.55 albertel 661: $r->log_reason(
1.118 albertel 662: "$msg for $env{'user.name'} domain $env{'user.domain'} access $priv",$fn);
1.12 www 663: }
1.1 harris41 664:
1.61 www 665: # ------------------------------------------------- Can this user re-init, etc?
1.6 www 666:
1.118 albertel 667: my $advanced=$env{'user.adv'};
1.61 www 668: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['tryagain']);
1.118 albertel 669: my $tryagain=$env{'form.tryagain'};
1.209 raeburn 670: my $reinit=$env{'user.reinit'};
671: delete $env{'user.reinit'};
1.6 www 672:
1.2 www 673: # -------------------------------------------------------- Generate Page Output
1.6 www 674: # --------------------------------------------------------------- Error Header?
1.2 www 675: if ($error) {
1.187 bisitz 676: $r->print("<h1>".&mt('LON-CAPA Access Control')."</h1>");
1.174 albertel 677: $r->print("<!-- LONCAPAACCESSCONTROLERRORSCREEN --><hr /><pre>");
678: if ($priv ne '') {
1.187 bisitz 679: $r->print(&mt('Access : ').&Apache::lonnet::plaintext($priv)."\n");
1.174 albertel 680: }
681: if ($fn ne '') {
1.187 bisitz 682: $r->print(&mt('Resource: ').&Apache::lonenc::check_encrypt($fn)."\n");
1.174 albertel 683: }
684: if ($msg ne '') {
1.187 bisitz 685: $r->print(&mt('Action : ').$msg."\n");
1.174 albertel 686: }
687: $r->print("</pre><hr />");
1.120 albertel 688: my $url=$fn;
689: my $last;
690: if (tie(my %hash,'GDBM_File',$env{'request.course.fn'}.'_symb.db',
691: &GDBM_READER(),0640)) {
692: $last=$hash{'last_known'};
693: untie(%hash);
694: }
1.149 www 695: if ($last) { $fn.='?symb='.&escape($last); }
1.120 albertel 696:
697: &Apache::londocs::changewarning($r,undef,'You have modified your course recently, [_1] may fix this access problem.',
698: &Apache::lonenc::check_encrypt($fn));
1.2 www 699: } else {
1.118 albertel 700: if ($env{'user.error.msg'}) {
1.209 raeburn 701: if ($reinit) {
702: $r->print(
703: '<h3><span class="LC_error">'.
1.234 raeburn 704: &mt('As your session file for the course or community has expired, you will need to re-select it.').'</span></h3>');
1.209 raeburn 705: } else {
706: $r->print(
1.157 albertel 707: '<h3><span class="LC_error">'.
1.235 bisitz 708: &mt('You need to choose another user role or enter a specific course or community for this function.').
709: '</span></h3>');
1.209 raeburn 710: }
711: }
1.2 www 712: }
1.6 www 713: # -------------------------------------------------------- Choice or no choice?
1.2 www 714: if ($nochoose) {
1.177 www 715: $r->print("<h2>".&mt('Sorry ...')."</h2>\n<span class='LC_error'>".
716: &mt('This action is currently not authorized.').'</span>'.
1.150 www 717: &Apache::loncommon::end_page());
718: return OK;
1.6 www 719: } else {
1.18 www 720: if (($ENV{'REDIRECT_QUERY_STRING'}) && ($fn)) {
721: $fn.='?'.$ENV{'REDIRECT_QUERY_STRING'};
1.6 www 722: }
1.240.2.3 raeburn 723: unless ($custommenu) {
724: $r->print('<form method="post" name="rolechoice" action="'.(($fn)?$fn:$r->uri).'">');
725: $r->print('<input type="hidden" name="orgurl" value="'.$fn.'" />');
726: $r->print('<input type="hidden" name="selectrole" value="1" />');
727: $r->print('<input type="hidden" name="newrole" value="" />');
728: }
1.6 www 729: }
1.226 raeburn 730:
731: my (%roletext,%sortrole,%roleclass,%futureroles,%timezones);
732: my ($countactive,$countfuture,$inrole,$possiblerole) =
733: &gather_roles($then,$refresh,$now,$reinit,$nochoose,\%roletext,\%sortrole,\%roleclass,
734: \%futureroles,\%timezones);
735:
736: $refresh = $now;
737: &Apache::lonnet::appenv({'user.refresh.time' => $refresh});
1.240.2.11 raeburn 738: if (!$countactive && !$countfuture) {
739: if (&Apache::loncommon::new_roles_update()) {
740: ($countactive,$countfuture,$inrole,$possiblerole) =
741: &gather_roles($then,$refresh,$now,$reinit,$nochoose,\%roletext,\%sortrole,
742: \%roleclass,\%futureroles,\%timezones);
743: }
744: }
1.240.2.3 raeburn 745: if ($custommenu) {
1.240.2.22! raeburn 746: if ($env{'form.destinationurl'} eq '/adm/ci_info') {
! 747: $r->print(&ci_info_page()).
1.240.2.5 raeburn 748: &Apache::loncommon::end_page();
749: return OK;
750: }
1.240.2.8 raeburn 751: my %courses = &Apache::loncommon::existing_gcitest_courses('cc');
1.240.2.3 raeburn 752: $env{'browser.interface'}='faketextual';
753: $env{'environment.remote'}='off';
754: my $numcourses = keys(%courses);
755: my $switcher;
756: if ($numcourses > 0) {
1.240.2.17 raeburn 757: $switcher = &Apache::loncommon::gcitest_switcher('cc',%courses);
1.240.2.3 raeburn 758: }
759: $r->print(&Apache::lonmenu::inlinemenu('gcicustom',$switcher).
760: &Apache::loncommon::end_page());
761: return OK;
1.240.2.6 raeburn 762: } else {
1.240.2.22! raeburn 763: if ($env{'form.destinationurl'} eq '/adm/ci_info') {
1.240.2.6 raeburn 764: delete($env{'form.destinationurl'});
765: }
1.240.2.3 raeburn 766: }
1.196 raeburn 767: if ($env{'user.adv'}) {
1.238 bisitz 768: $r->print('<p><label><input type="checkbox" name="showall"');
1.196 raeburn 769: if ($env{'form.showall'}) { $r->print(' checked="checked" '); }
1.238 bisitz 770: $r->print(' />'.&mt('Show all roles').'</label>'
771: .' <input type="submit" value="'.&mt('Update display').'" />'
772: .'</p>');
1.196 raeburn 773: } else {
774: if ($countactive > 0) {
1.240.2.9 raeburn 775: $r->print(&Apache::loncoursequeueadmin::queued_selfenrollment());
1.196 raeburn 776: my $domdesc = &Apache::lonnet::domain($env{'user.domain'},'description');
1.201 raeburn 777: my $esc_dom = &HTML::Entities::encode($env{'user.domain'},'"<>&');
1.240.2.21 raeburn 778: unless ($env{'user.domain'} =~ /^\w+citest$/) {
1.240.2.7 raeburn 779: $r->print(
780: '<p>'
781: .&mt('[_1]Visit the [_2]Course/Community Catalog[_3]'
782: .' to view all [_4] LON-CAPA courses and communities.'
783: ,'<b>'
784: ,'<a href="/adm/coursecatalog?showdom='.$esc_dom.'">'
785: ,'</a></b>',$domdesc)
786: .'<br />'
787: .&mt('If a course or community is [_1]not[_2] in your list of current courses and communities below,'
1.233 bisitz 788: .' you may be able to enroll if self-enrollment is permitted.'
789: ,'<b>','</b>')
1.240.2.7 raeburn 790: .'</p>'
791: );
792: }
1.196 raeburn 793: }
794: }
795:
1.84 www 796: # No active roles
797: if ($countactive==0) {
798: if ($inrole) {
1.234 raeburn 799: $r->print('<h2>'.&mt('Currently no additional roles, courses or communities').'</h2>');
1.84 www 800: } else {
1.240.2.18 raeburn 801: if ($show_course) {
1.240.2.21 raeburn 802: if ($env{'user.domain'} =~ /^\w+citest$/) {
1.240.2.18 raeburn 803: $r->print('<h2>'.&mt('Currently no active Concept Tests').'</h2>');
1.240.2.21 raeburn 804: } elsif ($env{'user.domain'} =~ /ci$/) {
1.240.2.19 raeburn 805: $r->print('<h2>'.&mt('Currently not assigned as a GCI contributor').'</h2>');
1.240.2.18 raeburn 806: }
807: } else {
808: $r->print('<h2>'.&mt('Currently no active roles, courses or communities').'</h2>');
809: }
1.84 www 810: }
1.240.2.21 raeburn 811: unless ($env{'user.domain'} =~ /^\w+citest$/) {
1.240.2.7 raeburn 812: &findcourse_advice($r);
813: &requestcourse_advice($r);
814: }
1.191 raeburn 815: $r->print('</form>');
816: if ($countfuture) {
1.240.2.18 raeburn 817: if ($show_course) {
1.240.2.21 raeburn 818: if ($env{'user.domain'} =~ /^\w+citest$/) {
1.240.2.18 raeburn 819: $r->print(&mt('The following [quant,_1,Concept Test] will be available in the future:',$countfuture));
820: } else {
821: $r->print(&mt('The following [quant,_1,course] will become active in the future:',$countfuture));
822: }
823: } else {
824: $r->print(&mt('The following [quant,_1,role,roles] will become active in the future:',$countfuture));
825: }
1.191 raeburn 826: my $doheaders = &roletable_headers($r,\%roleclass,\%sortrole,
827: $nochoose);
828: &print_rolerows($r,$doheaders,\%roleclass,\%sortrole,\%dcroles,
829: \%roletext);
830: my $tremark='';
1.212 bisitz 831: my $tbg;
1.191 raeburn 832: if ($env{'request.role'} eq 'cm') {
1.212 bisitz 833: $tbg="LC_roles_selected";
1.204 bisitz 834: $tremark=&mt('Currently selected.').' ';
1.191 raeburn 835: } else {
1.212 bisitz 836: $tbg="LC_roles_is";
1.191 raeburn 837: }
1.212 bisitz 838: $r->print(&Apache::loncommon::start_data_table_row()
839: .'<td class="'.$tbg.'"> </td>'
840: .'<td colspan="3">'
841: .&mt('No role specified')
842: .'</td>'
843: .'<td>'.$tremark.' </td>'
844: .&Apache::loncommon::end_data_table_row()
845: );
1.191 raeburn 846:
1.212 bisitz 847: $r->print(&Apache::loncommon::end_data_table());
1.191 raeburn 848: }
849: $r->print(&Apache::loncommon::end_page());
1.84 www 850: return OK;
1.240.2.1 raeburn 851: } elsif ($countactive==1) { # Is there only one choice?
852: my $needs_switchserver;
853: if ($env{'user.author'}) {
854: $needs_switchserver = &check_needs_switchserver($possiblerole);
855: }
856: if ((!$needs_switchserver) && ($env{'request.role'} eq 'cm')) {
857: $r->print('<h3>'.&mt('Please stand by.').'</h3>'.
858: '<input type="hidden" name="'.$possiblerole.'" value="1" />'.
859: '<noscript><br /><input type="submit" name="submit" value="'.&mt('Continue').'" /></noscript>');
860: $r->print("</form>\n");
861: $r->rflush();
862: $r->print('<script type="text/javascript">document.forms.rolechoice.submit();</script>');
863: $r->print(&Apache::loncommon::end_page());
864: return OK;
865: }
866: if ($needs_switchserver) {
867: $r->print("<h2>".&mt('Server Switch Required')."</h2>\n".
868: &mt('Construction Space access is only available from '.
869: 'the home server of the corresponding Author.').'<br />'.
870: &mt("Click the 'Switch Server' link to go there.").'<br />');
871: }
1.84 www 872: }
873: # ----------------------------------------------------------------------- Table
1.240.2.18 raeburn 874: unless ((!$show_course) || ($nochoose) || ($countactive==1)) {
1.173 albertel 875: $r->print("<h2>".&mt('Select a Course to Enter')."</h2>\n");
1.84 www 876: }
1.229 raeburn 877: if ($env{'form.destinationurl'}) {
878: $r->print('<input type="hidden" name="destinationurl" value="'.
879: $env{'form.destinationurl'}.'" />');
880: if ($env{'form.destsymb'} ne '') {
881: $r->print('<input type="hidden" name="destsymb" value="'.
882: $env{'form.destsymb'}.'" />');
883: }
884: }
1.191 raeburn 885: my $doheaders = &roletable_headers($r,\%roleclass,\%sortrole,$nochoose);
1.118 albertel 886: if ($env{'environment.recentroles'}) {
1.111 albertel 887: my %recent_roles =
1.118 albertel 888: &Apache::lonhtmlcommon::get_recent('roles',$env{'environment.recentrolesn'});
1.111 albertel 889: my $output='';
890: foreach (sort(keys(%recent_roles))) {
1.223 raeburn 891: if (ref($roletext{'user.role.'.$_}) eq 'ARRAY') {
892: $output.= &Apache::loncommon::start_data_table_row().
893: $roletext{'user.role.'.$_}->[0].
894: &Apache::loncommon::end_data_table_row().
895: &Apache::loncommon::continue_data_table_row().
896: $roletext{'user.role.'.$_}->[1].
897: &Apache::loncommon::end_data_table_row();
1.170 albertel 898: if ($_ =~ m-dc\./($match_domain)/-
899: && $dcroles{$1}) {
1.192 raeburn 900: $output .= &adhoc_roles_row($1,'recent');
1.133 albertel 901: }
1.113 raeburn 902: } elsif ($numdc > 0) {
903: unless ($_ =~/^error\:/) {
904: $output.=&display_cc_role('user.role.'.$_);
905: }
906: }
1.111 albertel 907: }
908: if ($output) {
1.212 bisitz 909: $r->print(&Apache::loncommon::start_data_table_empty_row()
910: .'<td align="center" colspan="5">'
1.224 raeburn 911: .$recent
1.212 bisitz 912: .'</td>'
913: .&Apache::loncommon::end_data_table_empty_row()
914: );
1.111 albertel 915: $r->print($output);
1.114 raeburn 916: $doheaders ++;
1.111 albertel 917: }
918: }
919:
1.104 raeburn 920: if ($numdc > 0) {
1.112 raeburn 921: $r->print(&coursepick_jscript());
1.193 raeburn 922: $r->print(&Apache::loncommon::coursebrowser_javascript().
923: &Apache::loncommon::authorbrowser_javascript());
1.108 raeburn 924: }
1.191 raeburn 925: &print_rolerows($r,$doheaders,\%roleclass,\%sortrole,\%dcroles,\%roletext);
1.202 raeburn 926: if ($countactive > 1) {
927: my $tremark='';
1.212 bisitz 928: my $tbg;
1.202 raeburn 929: if ($env{'request.role'} eq 'cm') {
1.212 bisitz 930: $tbg="LC_roles_selected";
1.204 bisitz 931: $tremark=&mt('Currently selected.').' ';
1.202 raeburn 932: } else {
1.212 bisitz 933: $tbg="LC_roles_is";
1.202 raeburn 934: }
1.212 bisitz 935: $r->print(&Apache::loncommon::start_data_table_row());
1.202 raeburn 936: unless ($nochoose) {
937: if ($env{'request.role'} ne 'cm') {
1.212 bisitz 938: $r->print('<td class="'.$tbg.'"><input type="submit" value="'.
1.202 raeburn 939: &mt('Select').'" name="cm" /></td>');
940: } else {
1.212 bisitz 941: $r->print('<td class="'.$tbg.'"> </td>');
1.202 raeburn 942: }
943: }
1.212 bisitz 944: $r->print('<td colspan="3">'
945: .&mt('No role specified')
946: .'</td>'
947: .'<td>'.$tremark.' </td>'
948: .&Apache::loncommon::end_data_table_row()
949: );
1.202 raeburn 950: }
1.212 bisitz 951: $r->print(&Apache::loncommon::end_data_table());
1.4 www 952: unless ($nochoose) {
953: $r->print("</form>\n");
954: }
1.22 harris41 955: # ------------------------------------------------------------ Privileges Info
1.118 albertel 956: if (($advanced) && (($env{'user.error.msg'}) || ($error))) {
1.212 bisitz 957: $r->print('<hr /><h2>'.&mt('Current Privileges').'</h2>');
1.175 albertel 958: $r->print(&privileges_info());
1.4 www 959: }
1.66 www 960: $r->print(&Apache::lonnet::getannounce());
1.65 www 961: if ($advanced) {
1.201 raeburn 962: my $esc_dom = &HTML::Entities::encode($env{'user.domain'},'"<>&');
1.231 bisitz 963: $r->print('<p><small><i>'
964: .&mt('This LON-CAPA server is version [_1]',$r->dir_config('lonVersion'))
965: .'</i><br />'
966: .'<a href="/adm/logout">'.&mt('Logout').'</a> '
1.201 raeburn 967: .'<a href="/adm/coursecatalog?showdom='.$esc_dom.'">'
1.233 bisitz 968: .&mt('Course/Community Catalog')
1.225 bisitz 969: .'</a></small></p>');
1.65 www 970: }
1.147 albertel 971: $r->print(&Apache::loncommon::end_page());
1.1 harris41 972: return OK;
1.102 raeburn 973: }
974:
1.240.2.22! raeburn 975: sub ci_info_page {
! 976: my %longname = (
! 977: GCI => 'Geoscience Concept Inventory',
! 978: SLCI => 'Science Literacy Concept Inventory',
! 979: );
! 980: my $inventory = uc($env{'user.domain'});
! 981: my %features = (
! 982: review => 'Review and comment on existing $inventory questions',
! 983: submit => "Submit $inventory questions of your own",
! 984: managetest => 'Create an online test for your students',
! 985: tutorial => 'View tutorials on creating online tests',
! 986: );
! 987: my $tabs = &Apache::loncommon::ci_tabs($env{'user.domain'});
! 988: my %info = (
! 989: GCI => '<p>For more information about writing and reviewing Concept Inventory questions please refer to the <a href="/res/gci/gci/internal/pdfs/GCIWorkbook.pdf">GCI Workbook</a>.</p>',
! 990: );
! 991: my $output = <<"END";
1.240.2.19 raeburn 992: <br clear="all">
993: <div>
1.240.2.22! raeburn 994: <h2>Welcome to the $longname{$inventory} WebCenter</h2>
1.240.2.5 raeburn 995: <p>
996: Use the tabs to navigate the WebCenter and...
997: <ul>
1.240.2.22! raeburn 998: END
! 999: if (ref($tabs) eq 'ARRAY') {
! 1000: foreach my $tab (@{$tabs}) {
! 1001: if ($features{$tab}) {
! 1002: $output .= '<li>'.$features{$tab}.'</li>'."\n";
! 1003: }
! 1004: }
! 1005: }
! 1006: $output .= <<"END";
1.240.2.5 raeburn 1007: </ul>
1008: </p>
1.240.2.22! raeburn 1009: $info{$inventory}
1.240.2.19 raeburn 1010: </div>
1.240.2.5 raeburn 1011: END
1.240.2.22! raeburn 1012:
1.240.2.5 raeburn 1013: }
1014:
1.226 raeburn 1015: sub gather_roles {
1016: my ($then,$refresh,$now,$reinit,$nochoose,$roletext,$sortrole,$roleclass,$futureroles,$timezones) = @_;
1017: my ($countactive,$countfuture,$inrole,$possiblerole) = (0,0,0,'');
1018: my $advanced = $env{'user.adv'};
1019: my $tryagain = $env{'form.tryagain'};
1020: foreach my $envkey (sort(keys(%env))) {
1021: my $button = 1;
1022: my $switchserver='';
1023: my ($role_text,$role_text_end,$sortkey);
1024: if ($envkey=~/^user\.role\./) {
1025: my ($role,$where,$trolecode,$tstart,$tend,$tremark,$tstatus,$tpstart,$tpend);
1026: &Apache::lonnet::role_status($envkey,$then,$refresh,$now,\$role,\$where,
1027: \$trolecode,\$tstatus,\$tstart,\$tend);
1028: next if (!defined($role) || $role eq '' || $role =~ /^gr/);
1029: my $timezone = &role_timezone($where,$timezones);
1030: $tremark='';
1031: $tpstart=' ';
1032: $tpend=' ';
1033: if ($tstart) {
1034: $tpstart=&Apache::lonlocal::locallocaltime($tstart,$timezone);
1035: }
1036: if ($tend) {
1037: $tpend=&Apache::lonlocal::locallocaltime($tend,$timezone);
1038: }
1039: if ($env{'request.role'} eq $trolecode) {
1040: $tstatus='selected';
1041: }
1042: my $tbg;
1043: if (($tstatus eq 'is')
1044: || ($tstatus eq 'selected')
1045: || ($tstatus eq 'future')
1046: || ($env{'form.showall'})) {
1047: if ($tstatus eq 'is') {
1048: $tbg='LC_roles_is';
1049: $possiblerole=$trolecode;
1050: $countactive++;
1051: } elsif ($tstatus eq 'future') {
1052: $tbg='LC_roles_future';
1053: $button=0;
1054: $futureroles->{$trolecode} = $tstart.':'.$tend;
1055: $countfuture ++;
1056: } elsif ($tstatus eq 'expired') {
1057: $tbg='LC_roles_expired';
1058: $button=0;
1059: } elsif ($tstatus eq 'will_not') {
1060: $tbg='LC_roles_will_not';
1061: $tremark.=&mt('Expired after logout.').' ';
1062: } elsif ($tstatus eq 'selected') {
1063: $tbg='LC_roles_selected';
1064: $inrole=1;
1065: $countactive++;
1066: $tremark.=&mt('Currently selected.').' ';
1067: }
1068: my $trole;
1069: if ($role =~ /^cr\//) {
1070: my ($rdummy,$rdomain,$rauthor,$rrole)=split(/\//,$role);
1071: if ($tremark) { $tremark.='<br />'; }
1072: $tremark.=&mt('Defined by [_1] at [_2].',$rauthor,$rdomain);
1073: }
1074: $trole=Apache::lonnet::plaintext($role);
1075: my $ttype;
1076: my $twhere;
1077: my ($tdom,$trest,$tsection)=
1078: split(/\//,Apache::lonnet::declutter($where));
1079: # First, Co-Authorship roles
1080: if (($role eq 'ca') || ($role eq 'aa')) {
1081: my $home = &Apache::lonnet::homeserver($trest,$tdom);
1082: my $allowed=0;
1083: my @ids=&Apache::lonnet::current_machine_ids();
1084: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
1085: if (!$allowed) {
1086: $button=0;
1087: $switchserver='otherserver='.$home.'&role='.$trolecode;
1088: }
1089: #next if ($home eq 'no_host');
1090: $home = &Apache::lonnet::hostname($home);
1091: $ttype='Construction Space';
1092: $twhere=&mt('User').': '.$trest.'<br />'.&mt('Domain').
1093: ': '.$tdom.'<br />'.
1094: ' '.&mt('Server').': '.$home;
1095: $env{'course.'.$tdom.'_'.$trest.'.description'}='ca';
1096: $tremark.=&Apache::lonhtmlcommon::authorbombs('/res/'.$tdom.'/'.$trest.'/');
1097: $sortkey=$role."$trest:$tdom";
1098: } elsif ($role eq 'au') {
1099: # Authors
1100: my $home = &Apache::lonnet::homeserver
1101: ($env{'user.name'},$env{'user.domain'});
1102: my $allowed=0;
1103: my @ids=&Apache::lonnet::current_machine_ids();
1104: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
1105: if (!$allowed) {
1106: $button=0;
1107: $switchserver='otherserver='.$home.'&role='.$trolecode;
1108: }
1109: #next if ($home eq 'no_host');
1110: $home = &Apache::lonnet::hostname($home);
1111: $ttype='Construction Space';
1112: $twhere=&mt('Domain').': '.$tdom.'<br />'.&mt('Server').
1113: ': '.$home;
1114: $env{'course.'.$tdom.'_'.$trest.'.description'}='ca';
1115: $tremark.=&Apache::lonhtmlcommon::authorbombs('/res/'.$tdom.'/'.$env{'user.name'}.'/');
1116: $sortkey=$role;
1117: } elsif ($trest) {
1118: my $tcourseid=$tdom.'_'.$trest;
1119: $ttype = &Apache::loncommon::course_type($tcourseid);
1.240.2.13 raeburn 1120: $trole = &Apache::lonnet::plaintext($role,$ttype,$tcourseid);
1.226 raeburn 1121: if ($env{'course.'.$tcourseid.'.description'}) {
1122: $twhere=$env{'course.'.$tcourseid.'.description'};
1123: $sortkey=$role."\0".$tdom."\0".$twhere."\0".$envkey;
1124: unless ($twhere eq &mt('Currently not available')) {
1125: $twhere.=' <span class="LC_fontsize_small">'.
1126: &Apache::loncommon::syllabuswrapper(&mt('Syllabus'),$trest,$tdom).
1127: '</span>';
1128: }
1129: } else {
1130: my %newhash=&Apache::lonnet::coursedescription($tcourseid);
1131: if (%newhash) {
1132: $sortkey=$role."\0".$tdom."\0".$newhash{'description'}.
1133: "\0".$envkey;
1134: $twhere=$newhash{'description'}.
1135: ' <span class="LC_fontsize_small">'.
1136: &Apache::loncommon::syllabuswrapper(&mt('Syllabus'),$trest,$tdom).
1137: '</span>';
1138: $ttype = $newhash{'type'};
1.240.2.12 raeburn 1139: $trole = &Apache::lonnet::plaintext($role,$ttype,$tcourseid);
1.226 raeburn 1140: } else {
1141: $twhere=&mt('Currently not available');
1142: $env{'course.'.$tcourseid.'.description'}=$twhere;
1143: $sortkey=$role."\0".$tdom."\0".$twhere."\0".$envkey;
1144: $ttype = 'Unavailable';
1145: }
1146: }
1147: if ($tsection) {
1148: $twhere.='<br />'.&mt('Section').': '.$tsection;
1149: }
1150: if ($role ne 'st') { $twhere.="<br />".&mt('Domain').":".$tdom; }
1151: } elsif ($tdom) {
1152: $ttype='Domain';
1153: $twhere=$tdom;
1154: $sortkey=$role.$twhere;
1155: } else {
1156: $ttype='System';
1157: $twhere=&mt('system wide');
1158: $sortkey=$role.$twhere;
1159: }
1160: ($role_text,$role_text_end) =
1161: &build_roletext($trolecode,$tdom,$trest,$tstatus,$tryagain,
1162: $advanced,$tremark,$tbg,$trole,$twhere,$tpstart,
1163: $tpend,$nochoose,$button,$switchserver,$reinit);
1164: $roletext->{$envkey}=[$role_text,$role_text_end];
1165: if (!$sortkey) {$sortkey=$twhere."\0".$envkey;}
1166: $sortrole->{$sortkey}=$envkey;
1167: $roleclass->{$envkey}=$ttype;
1168: }
1169: }
1170: }
1171: return ($countactive,$countfuture,$inrole,$possiblerole);
1172: }
1173:
1.215 raeburn 1174: sub role_timezone {
1175: my ($where,$timezones) = @_;
1176: my $timezone;
1177: if (ref($timezones) eq 'HASH') {
1178: if ($where =~ m{^/($match_domain)/($match_courseid)}) {
1179: my $cdom = $1;
1180: my $cnum = $2;
1181: if ($cdom && $cnum) {
1182: if (!exists($timezones->{$cdom.'_'.$cnum})) {
1183: my %timehash =
1184: &Apache::lonnet::get('environment',['timezone'],$cdom,$cnum);
1185: if ($timehash{'timezone'} eq '') {
1186: if (!exists($timezones->{$cdom})) {
1187: my %domdefaults =
1188: &Apache::lonnet::get_domain_defaults($cdom);
1189: if ($domdefaults{'timezone_def'} eq '') {
1190: $timezones->{$cdom} = 'local';
1191: } else {
1192: $timezones->{$cdom} = $domdefaults{'timezone_def'};
1193: }
1194: }
1195: $timezones->{$cdom.'_'.$cnum} = $timezones->{$cdom};
1196: } else {
1197: $timezones->{$cdom.'_'.$cnum} =
1198: &Apache::lonlocal::gettimezone($timehash{'timezone'});
1199: }
1200: }
1201: $timezone = $timezones->{$cdom.'_'.$cnum};
1202: }
1203: } else {
1204: my ($tdom) = ($where =~ m{^/($match_domain)});
1205: if ($tdom) {
1206: if (!exists($timezones->{$tdom})) {
1207: my %domdefaults = &Apache::lonnet::get_domain_defaults($tdom);
1208: if ($domdefaults{'timezone_def'} eq '') {
1209: $timezones->{$tdom} = 'local';
1210: } else {
1211: $timezones->{$tdom} = $domdefaults{'timezone_def'};
1212: }
1213: }
1214: $timezone = $timezones->{$tdom};
1215: }
1216: }
1217: if ($timezone eq 'local') {
1218: $timezone = undef;
1219: }
1220: }
1221: return $timezone;
1222: }
1223:
1.191 raeburn 1224: sub roletable_headers {
1225: my ($r,$roleclass,$sortrole,$nochoose) = @_;
1226: my $doheaders;
1227: if ((ref($sortrole) eq 'HASH') && (ref($roleclass) eq 'HASH')) {
1.212 bisitz 1228: $r->print('<br />'
1229: .&Apache::loncommon::start_data_table()
1230: .&Apache::loncommon::start_data_table_header_row()
1231: );
1.191 raeburn 1232: if (!$nochoose) { $r->print('<th> </th>'); }
1.212 bisitz 1233: $r->print('<th>'.&mt('User Role').'</th>'
1234: .'<th>'.&mt('Extent').'</th>'
1235: .'<th>'.&mt('Start').'</th>'
1236: .'<th>'.&mt('End').'</th>'
1237: .&Apache::loncommon::end_data_table_header_row()
1238: );
1.191 raeburn 1239: $doheaders=-1;
1240: my @roletypes = &roletypes();
1241: foreach my $type (@roletypes) {
1242: my $haverole=0;
1243: foreach my $which (sort {uc($a) cmp uc($b)} (keys(%{$sortrole}))) {
1244: if ($roleclass->{$sortrole->{$which}} =~ /^\Q$type\E/) {
1245: $haverole=1;
1246: }
1247: }
1248: if ($haverole) { $doheaders++; }
1249: }
1250: }
1251: return $doheaders;
1252: }
1253:
1254: sub roletypes {
1.237 raeburn 1255: my @types = ('Domain','Construction Space','Course','Community','Unavailable','System');
1.191 raeburn 1256: return @types;
1257: }
1258:
1259: sub print_rolerows {
1260: my ($r,$doheaders,$roleclass,$sortrole,$dcroles,$roletext) = @_;
1261: if ((ref($roleclass) eq 'HASH') && (ref($sortrole) eq 'HASH')) {
1262: my @types = &roletypes();
1263: foreach my $type (@types) {
1264: my $output;
1265: foreach my $which (sort {uc($a) cmp uc($b)} (keys(%{$sortrole}))) {
1266: if ($roleclass->{$sortrole->{$which}} =~ /^\Q$type\E/) {
1267: if (ref($roletext) eq 'HASH') {
1.223 raeburn 1268: if (ref($roletext->{$sortrole->{$which}}) eq 'ARRAY') {
1269: $output.= &Apache::loncommon::start_data_table_row().
1270: $roletext->{$sortrole->{$which}}->[0].
1271: &Apache::loncommon::end_data_table_row().
1272: &Apache::loncommon::continue_data_table_row().
1273: $roletext->{$sortrole->{$which}}->[1].
1274: &Apache::loncommon::end_data_table_row();
1275: }
1.191 raeburn 1276: if ($sortrole->{$which} =~ m-dc\./($match_domain)/-) {
1277: if (ref($dcroles) eq 'HASH') {
1278: if ($dcroles->{$1}) {
1.192 raeburn 1279: $output .= &adhoc_roles_row($1,'');
1.191 raeburn 1280: }
1281: }
1282: }
1283: }
1284: }
1285: }
1286: if ($output) {
1287: if ($doheaders > 0) {
1.212 bisitz 1288: $r->print(&Apache::loncommon::start_data_table_empty_row()
1289: .'<td align="center" colspan="5">'
1290: .&mt($type)
1291: .'</td>'
1292: .&Apache::loncommon::end_data_table_empty_row()
1293: );
1.191 raeburn 1294: }
1295: $r->print($output);
1296: }
1297: }
1298: }
1299: }
1300:
1301: sub findcourse_advice {
1302: my ($r) = @_;
1303: my $domdesc = &Apache::lonnet::domain($env{'user.domain'},'description');
1.201 raeburn 1304: my $esc_dom = &HTML::Entities::encode($env{'user.domain'},'"<>&');
1.200 raeburn 1305: if (&Apache::lonnet::auto_run(undef,$env{'user.domain'})) {
1.191 raeburn 1306: $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).'
1307: <ul>
1308: <li>'.&mt('The course has yet to be created.').'</li>
1309: <li>'.&mt('Automatic enrollment of registered students has not been enabled for the course.').'</li>
1310: <li>'.&mt('You are in a section of course for which automatic enrollment in the corresponding LON-CAPA course is not active.').'</li>
1311: <li>'.&mt('The start date for automated enrollment has yet to be reached.').'</li>
1312: <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>
1313: </ul>');
1314: } else {
1315: $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 />');
1316: }
1.240.2.19 raeburn 1317: my $queued = &Apache::loncoursequeueadmin::queued_selfenrollment();
1318: if ($queued) {
1319: $r->print($queued);
1320: } else {
1321: $r->print(&mt('You have no request for contributor access pending approval by the GCI WebCenter team.').'<ul>'.
1322: '<li>'.&mt('This may mean that action was taken on your request in the time since your most recent log-in.[_1]View [_2]Message[_3] to see if this is the case.','<br />','<a href="/adm/communicate">','</a>').'</li>'.
1323: '<li>'.&mt('If you logout and log-in again you may find you now have access to the Geoscience Concept Inventory, as a contributor.').'</li>'.
1324: '</ul>');
1325: }
1.216 raeburn 1326: return;
1327: }
1328:
1.234 raeburn 1329: sub requestcourse_advice {
1330: my ($r) = @_;
1331: my $domdesc = &Apache::lonnet::domain($env{'user.domain'},'description');
1332: my $esc_dom = &HTML::Entities::encode($env{'user.domain'},'"<>&');
1333: my (%can_request,%request_doms);
1334: &Apache::lonnet::check_can_request($env{'user.domain'},\%can_request,\%request_doms);
1335: if (keys(%request_doms) > 0) {
1336: my ($types,$typename) = &Apache::loncommon::course_types();
1337: if ((ref($types) eq 'ARRAY') && (ref($typename) eq 'HASH')) {
1338: $r->print('<h3>'.&mt('Request creation of a course or community').'</h3>'.
1.238 bisitz 1339: '<p>'.&mt('You have rights to request the creation of courses and/or communities in the following domain(s):').'<ul>');
1.234 raeburn 1340: my (@reqdoms,@reqtypes);
1341: foreach my $type (sort(keys(%request_doms))) {
1342: push(@reqtypes,$type);
1343: if (ref($request_doms{$type}) eq 'ARRAY') {
1344: my $domstr = join(', ',map { &Apache::lonnet::domain($_) } sort(@{$request_doms{$type}}));
1.238 bisitz 1345: $r->print(
1346: '<li>'
1347: .&mt('[_1]'.$typename->{$type}.'[_2] in domain: [_3]',
1348: '<i>',
1349: '</i>',
1350: '<b>'.$domstr.'</b>')
1351: .'</li>'
1352: );
1.234 raeburn 1353: foreach my $dom (@{$request_doms{$type}}) {
1354: unless (grep(/^\Q$dom\E/,@reqdoms)) {
1355: push(@reqdoms,$dom);
1356: }
1357: }
1358: }
1359: }
1360: my @showtypes;
1361: foreach my $type (@{$types}) {
1362: if (grep(/^\Q$type\E$/,@reqtypes)) {
1363: push(@showtypes,$type);
1364: }
1365: }
1366: my $requrl = '/adm/requestcourse';
1367: if (@reqdoms == 1) {
1368: $requrl .= '?showdom='.$reqdoms[0];
1369: }
1370: if (@showtypes > 0) {
1371: $requrl.=(($requrl=~/\?/)?'&':'?').'crstype='.$showtypes[0];
1372: }
1373: if (@reqdoms == 1 || @showtypes > 0) {
1374: $requrl .= '&state=crstype&action=new';
1375: }
1376: $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>');
1377: }
1378: }
1379: return;
1380: }
1381:
1.175 albertel 1382: sub privileges_info {
1383: my ($which) = @_;
1384: my $output;
1385:
1386: $which ||= $env{'request.role'};
1387:
1388: foreach my $envkey (sort(keys(%env))) {
1389: next if ($envkey!~/^user\.priv\.\Q$which\E\.(.*)/);
1390:
1391: my $where=$1;
1392: my $ttype;
1393: my $twhere;
1394: my (undef,$tdom,$trest,$tsec)=split(m{/},$where);
1395: if ($trest) {
1396: if ($env{'course.'.$tdom.'_'.$trest.'.description'} eq 'ca') {
1397: $ttype='Construction Space';
1398: $twhere='User: '.$trest.', Domain: '.$tdom;
1399: } else {
1400: $ttype= &Apache::loncommon::course_type($tdom.'_'.$trest);
1401: $twhere=$env{'course.'.$tdom.'_'.$trest.'.description'};
1402: if ($tsec) {
1403: my $sec_type = 'Section';
1404: if (exists($env{"user.role.gr.$where"})) {
1405: $sec_type = 'Group';
1406: }
1407: $twhere.=' ('.$sec_type.': '.$tsec.')';
1408: }
1409: }
1410: } elsif ($tdom) {
1411: $ttype='Domain';
1412: $twhere=$tdom;
1413: } else {
1414: $ttype='System';
1415: $twhere='/';
1416: }
1.204 bisitz 1417: $output .= "\n<h3>".&mt($ttype).': '.$twhere.'</h3>'."\n<ul>";
1.175 albertel 1418: foreach my $priv (sort(split(/:/,$env{$envkey}))) {
1419: next if (!$priv);
1420:
1421: my ($prv,$restr)=split(/\&/,$priv);
1422: my $trestr='';
1423: if ($restr ne 'F') {
1424: $trestr.=' ('.
1425: join(', ',
1426: map { &Apache::lonnet::plaintext($_) }
1427: (split('',$restr))).') ';
1428: }
1429: $output .= "\n\t".
1430: '<li>'.&Apache::lonnet::plaintext($prv).$trestr.'</li>';
1431: }
1432: $output .= "\n".'</ul>';
1433: }
1434: return $output;
1435: }
1436:
1.110 raeburn 1437: sub build_roletext {
1.212 bisitz 1438: my ($trolecode,$tdom,$trest,$tstatus,$tryagain,$advanced,$tremark,$tbg,$trole,$twhere,$tpstart,$tpend,$nochoose,$button,$switchserver,$reinit) = @_;
1.223 raeburn 1439: my ($roletext,$roletext_end);
1.132 albertel 1440: my $is_dc=($trolecode =~ m/^dc\./);
1441: my $rowspan=($is_dc) ? ''
1442: : ' rowspan="2" ';
1443:
1.110 raeburn 1444: unless ($nochoose) {
1.134 www 1445: my $buttonname=$trolecode;
1446: $buttonname=~s/\W//g;
1.110 raeburn 1447: if (!$button) {
1448: if ($switchserver) {
1.212 bisitz 1449: $roletext.='<td'.$rowspan.' class="'.$tbg.'">'
1450: .'<a href="/adm/switchserver?'.$switchserver.'">'
1451: .&mt('Switch Server')
1452: .'</a></td>';
1.110 raeburn 1453: } else {
1.212 bisitz 1454: $roletext.=('<td'.$rowspan.' class="'.$tbg.'"> </td>');
1.110 raeburn 1455: }
1456: } elsif ($tstatus eq 'is') {
1.212 bisitz 1457: $roletext.='<td'.$rowspan.' class="'.$tbg.'">'.
1458: '<input name="'.$buttonname.'" type="button" value="'.
1.225 bisitz 1459: &mt('Select').'" onclick="javascript:enterrole(this.form,\''.
1.192 raeburn 1460: $trolecode."','".$buttonname.'\');" /></td>';
1.110 raeburn 1461: } elsif ($tryagain) {
1462: $roletext.=
1.212 bisitz 1463: '<td'.$rowspan.' class="'.$tbg.'">'.
1464: '<input name="'.$buttonname.'" type="button" value="'.
1.225 bisitz 1465: &mt('Try Selecting Again').'" onclick="javascript:enterrole(this.form,\''.
1.192 raeburn 1466: $trolecode."','".$buttonname.'\');" /></td>';
1.110 raeburn 1467: } elsif ($advanced) {
1468: $roletext.=
1.212 bisitz 1469: '<td'.$rowspan.' class="'.$tbg.'">'.
1470: '<input name="'.$buttonname.'" type="button" value="'.
1.225 bisitz 1471: &mt('Re-Initialize').'" onclick="javascript:enterrole(this.form,\''.
1.192 raeburn 1472: $trolecode."','".$buttonname.'\');" /></td>';
1.209 raeburn 1473: } elsif ($reinit) {
1474: $roletext.=
1.212 bisitz 1475: '<td'.$rowspan.' class="'.$tbg.'">'.
1476: '<input name="'.$buttonname.'" type="button" value="'.
1.225 bisitz 1477: &mt('Re-Select').'" onclick="javascript:enterrole(this.form,\''.
1.209 raeburn 1478: $trolecode."','".$buttonname.'\');" /></td>';
1.110 raeburn 1479: } else {
1.209 raeburn 1480: $roletext.=
1.212 bisitz 1481: '<td'.$rowspan.' class="'.$tbg.'">'.
1482: '<input name="'.$buttonname.'" type="button" value="'.
1.225 bisitz 1483: &mt('Re-Select').'" onclick="javascript:enterrole(this.form,\''.
1.209 raeburn 1484: $trolecode."','".$buttonname.'\');" /></td>';
1.110 raeburn 1485: }
1486: }
1.165 albertel 1487: if ($trolecode !~ m/^(dc|ca|au|aa)\./) {
1488: $tremark.=&Apache::lonannounce::showday(time,1,
1489: &Apache::lonannounce::readcalendar($tdom.'_'.$trest));
1490: }
1.212 bisitz 1491: $roletext.='<td>'.$trole.'</td>'
1492: .'<td>'.$twhere.'</td>'
1493: .'<td>'.$tpstart.'</td>'
1.223 raeburn 1494: .'<td>'.$tpend.'</td>';
1.132 albertel 1495: if (!$is_dc) {
1.223 raeburn 1496: $roletext_end = '<td colspan="4">'.
1497: $tremark.' '.
1498: '</td>';
1.132 albertel 1499: }
1.223 raeburn 1500: return ($roletext,$roletext_end);
1.110 raeburn 1501: }
1502:
1.202 raeburn 1503: sub check_needs_switchserver {
1504: my ($possiblerole) = @_;
1505: my $needs_switchserver;
1506: my ($role,$where) = split(/\./,$possiblerole,2);
1507: my (undef,$tdom,$twho) = split(/\//,$where);
1508: my ($server_status,$home);
1509: if (($role eq 'ca') || ($role eq 'aa')) {
1510: ($server_status,$home) = &check_author_homeserver($twho,$tdom);
1511: } else {
1512: ($server_status,$home) = &check_author_homeserver($env{'user.name'},
1513: $env{'user.domain'});
1514: }
1515: if ($server_status eq 'switchserver') {
1516: $needs_switchserver = 1;
1517: }
1518: return $needs_switchserver;
1519: }
1520:
1.193 raeburn 1521: sub check_author_homeserver {
1.183 www 1522: my ($uname,$udom)=@_;
1.193 raeburn 1523: if (($uname eq '') || ($udom eq '')) {
1524: return ('fail','');
1525: }
1.183 www 1526: my $home = &Apache::lonnet::homeserver($uname,$udom);
1.193 raeburn 1527: if (&Apache::lonnet::host_domain($home) ne $udom) {
1528: return ('fail',$home);
1529: }
1.183 www 1530: my @ids=&Apache::lonnet::current_machine_ids();
1.193 raeburn 1531: if (grep(/^\Q$home\E$/,@ids)) {
1532: return ('ok',$home);
1533: } else {
1534: return ('switchserver',$home);
1.183 www 1535: }
1536: }
1537:
1.104 raeburn 1538: sub check_fordc {
1539: my ($dcroles,$then) = @_;
1540: my $numdc = 0;
1.118 albertel 1541: if ($env{'user.adv'}) {
1542: foreach my $envkey (sort keys %env) {
1.170 albertel 1543: if ($envkey=~/^user\.role\.dc\.\/($match_domain)\/$/) {
1.104 raeburn 1544: my $dcdom = $1;
1545: my $livedc = 1;
1.118 albertel 1546: my ($tstart,$tend)=split(/\./,$env{$envkey});
1.105 raeburn 1547: if ($tstart && $tstart>$then) { $livedc = 0; }
1548: if ($tend && $tend <$then) { $livedc = 0; }
1.104 raeburn 1549: if ($livedc) {
1550: $$dcroles{$dcdom} = $envkey;
1.105 raeburn 1551: $numdc++;
1.104 raeburn 1552: }
1553: }
1554: }
1555: }
1556: return $numdc;
1557: }
1558:
1.185 raeburn 1559: sub adhoc_course_role {
1.232 raeburn 1560: my ($refresh,$then) = @_;
1.239 raeburn 1561: my ($cdom,$cnum,$crstype);
1.201 raeburn 1562: $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
1563: $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.239 raeburn 1564: $crstype = &Apache::loncommon::course_type();
1565: if (&check_forcc($cdom,$cnum,$refresh,$then,$crstype)) {
1.185 raeburn 1566: my $setprivs;
1.198 raeburn 1567: if (!defined($env{'user.role.'.$env{'form.switchrole'}})) {
1.185 raeburn 1568: $setprivs = 1;
1569: } else {
1.198 raeburn 1570: my ($start,$end) = split(/\./,$env{'user.role.'.$env{'form.switchrole'}});
1.232 raeburn 1571: if (($start && ($start>$refresh || $start == -1)) ||
1.185 raeburn 1572: ($end && $end<$then)) {
1573: $setprivs = 1;
1574: }
1.232 raeburn 1575: }
1.185 raeburn 1576: if ($setprivs) {
1.198 raeburn 1577: if ($env{'form.switchrole'} =~ m-^(in|ta|ep|ad|st|cr)([\w/]*)\./\Q$cdom\E/\Q$cnum\E/?(\w*)$-) {
1.185 raeburn 1578: my $role = $1;
1579: my $custom_role = $2;
1580: my $usec = $3;
1581: if ($role eq 'cr') {
1.199 raeburn 1582: if ($custom_role =~ m-^/$match_domain/$match_username/\w+$-) {
1.185 raeburn 1583: $role .= $custom_role;
1584: } else {
1585: return;
1586: }
1587: }
1.208 raeburn 1588: my (%userroles,%newrole,%newgroups,%group_privs);
1589: my %cgroups =
1590: &Apache::lonnet::get_active_groups($env{'user.domain'},
1591: $env{'user.name'},$cdom,$cnum);
1592: foreach my $group (keys(%cgroups)) {
1593: $group_privs{$group} =
1594: $env{'user.priv.cc./'.$cdom.'/'.$cnum.'./'.$cdom.'/'.$cnum.'/'.$group};
1595: }
1596: $newgroups{'/'.$cdom.'/'.$cnum} = \%group_privs;
1.185 raeburn 1597: my $area = '/'.$cdom.'/'.$cnum;
1598: my $spec = $role.'.'.$area;
1599: if ($usec ne '') {
1600: $spec .= '/'.$usec;
1601: $area .= '/'.$usec;
1602: }
1603: &Apache::lonnet::standard_roleprivs(\%newrole,$role,$cdom,$spec,$cnum,$area);
1.208 raeburn 1604: &Apache::lonnet::set_userprivs(\%userroles,\%newrole,\%newgroups);
1.232 raeburn 1605: my $adhocstart = $refresh-1;
1.185 raeburn 1606: $userroles{'user.role.'.$spec} = $adhocstart.'.';
1.186 raeburn 1607: &Apache::lonnet::appenv(\%userroles,[$role,'cm']);
1.185 raeburn 1608: }
1609: }
1610: }
1611: return;
1612: }
1613:
1614: sub check_forcc {
1.239 raeburn 1615: my ($cdom,$cnum,$refresh,$then,$crstype) = @_;
1616: my ($is_cc,$ccrole);
1617: if ($crstype eq 'Community') {
1618: $ccrole = 'co';
1619: } else {
1620: $ccrole = 'cc';
1621: }
1.185 raeburn 1622: if ($cdom ne '' && $cnum ne '') {
1623: if (&Apache::lonnet::is_course($cdom,$cnum)) {
1.239 raeburn 1624: my $envkey = 'user.role.'.$ccrole.'./'.$cdom.'/'.$cnum;
1.185 raeburn 1625: if (defined($env{$envkey})) {
1626: $is_cc = 1;
1627: my ($tstart,$tend)=split(/\./,$env{$envkey});
1.232 raeburn 1628: if ($tstart && $tstart>$refresh) { $is_cc = 0; }
1.185 raeburn 1629: if ($tend && $tend <$then) { $is_cc = 0; }
1630: }
1631: }
1632: }
1633: return $is_cc;
1634: }
1635:
1.108 raeburn 1636: sub courselink {
1.193 raeburn 1637: my ($dcdom,$rowtype) = @_;
1.109 raeburn 1638: my $courseform=&Apache::loncommon::selectcourse_link
1.152 raeburn 1639: ('rolechoice','dccourse'.$rowtype.'_'.$dcdom,
1640: 'dcdomain'.$rowtype.'_'.$dcdom,'coursedesc'.$rowtype.'_'.
1.239 raeburn 1641: $dcdom,$dcdom,undef,'Course/Community');
1.138 raeburn 1642: my $hiddenitems = '<input type="hidden" name="dcdomain'.$rowtype.'_'.$dcdom.'" value="'.$dcdom.'" />'.
1643: '<input type="hidden" name="origdom'.$rowtype.'_'.$dcdom.'" value="'.$dcdom.'" />'.
1644: '<input type="hidden" name="dccourse'.$rowtype.'_'.$dcdom.'" value="" />'.
1645: '<input type="hidden" name="coursedesc'.$rowtype.'_'.$dcdom.'" value="" />';
1.112 raeburn 1646: return $courseform.$hiddenitems;
1.109 raeburn 1647: }
1648:
1649: sub coursepick_jscript {
1.184 raeburn 1650: my %lt = &Apache::lonlocal::texthash(
1.239 raeburn 1651: 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 1652: youc => 'You can only use this screen to select courses and communities in the current domain.',
1.184 raeburn 1653: );
1.104 raeburn 1654: my $verify_script = <<"END";
1.179 raeburn 1655: <script type="text/javascript">
1.225 bisitz 1656: // <![CDATA[
1.108 raeburn 1657: function verifyCoursePick(caller) {
1658: var numbutton = getIndex(caller)
1.112 raeburn 1659: var pickedCourse = document.rolechoice.elements[numbutton+4].value
1660: var pickedDomain = document.rolechoice.elements[numbutton+2].value
1661: if (document.rolechoice.elements[numbutton+2].value == document.rolechoice.elements[numbutton+3].value) {
1.104 raeburn 1662: if (pickedCourse != '') {
1.108 raeburn 1663: if (numbutton != -1) {
1664: var courseTarget = "cc./"+pickedDomain+"/"+pickedCourse
1665: document.rolechoice.elements[numbutton+1].name = courseTarget
1666: document.rolechoice.submit()
1667: }
1.104 raeburn 1668: }
1669: else {
1.184 raeburn 1670: alert("$lt{'plsu'}");
1.104 raeburn 1671: }
1672: }
1673: else {
1.184 raeburn 1674: alert("$lt{'youc'}")
1.104 raeburn 1675: }
1676: }
1.109 raeburn 1677: function getIndex(caller) {
1.108 raeburn 1678: for (var i=0;i<document.rolechoice.elements.length;i++) {
1.109 raeburn 1679: if (document.rolechoice.elements[i] == caller) {
1.108 raeburn 1680: return i;
1681: }
1682: }
1683: return -1;
1684: }
1.225 bisitz 1685: // ]]>
1.104 raeburn 1686: </script>
1687: END
1.109 raeburn 1688: return $verify_script;
1.104 raeburn 1689: }
1690:
1.193 raeburn 1691: sub coauthorlink {
1692: my ($dcdom,$rowtype) = @_;
1693: my $coauthorform=&Apache::loncommon::selectauthor_link('rolechoice',$dcdom);
1694: my $hiddenitems = '<input type="hidden" name="adhoccauname'.$rowtype.'_'.$dcdom.'" value="" />';
1695: return $coauthorform.$hiddenitems;
1696: }
1697:
1.113 raeburn 1698: sub display_cc_role {
1699: my $rolekey = shift;
1.223 raeburn 1700: my ($roletext,$roletext_end);
1.118 albertel 1701: my $advanced = $env{'user.adv'};
1702: my $tryagain = $env{'form.tryagain'};
1.113 raeburn 1703: unless ($rolekey =~/^error\:/) {
1.240 raeburn 1704: if ($rolekey =~ m{^user\.role\.(cc|co)\./($match_domain)/($match_courseid)$}) {
1705: my $ccrole = $1;
1706: my $tcourseid = $2.'_'.$3;
1707: my $trolecode = $1.'./'.$2.'/'.$3;
1.113 raeburn 1708: my $twhere;
1.152 raeburn 1709: my $ttype;
1.212 bisitz 1710: my $tbg='LC_roles_is';
1.113 raeburn 1711: my %newhash=&Apache::lonnet::coursedescription($tcourseid);
1712: if (%newhash) {
1713: $twhere=$newhash{'description'}.
1.211 tempelho 1714: ' <span style="LC_fontsize_small">'.
1.212 bisitz 1715: &Apache::loncommon::syllabuswrapper(&mt('Syllabus'),$2,$1).
1.211 tempelho 1716: '</span>';
1.153 raeburn 1717: $ttype = $newhash{'type'};
1.113 raeburn 1718: } else {
1719: $twhere=&mt('Currently not available');
1.118 albertel 1720: $env{'course.'.$tcourseid.'.description'}=$twhere;
1.110 raeburn 1721: }
1.240.2.12 raeburn 1722: my $trole = &Apache::lonnet::plaintext($ccrole,$ttype,$tcourseid);
1.113 raeburn 1723: $twhere.="<br />".&mt('Domain').":".$1;
1.223 raeburn 1724: ($roletext,$roletext_end) = &build_roletext($trolecode,$1,$2,'is',$tryagain,$advanced,'',$tbg,$trole,$twhere,'','','',1,'');
1.104 raeburn 1725: }
1726: }
1.223 raeburn 1727: return ($roletext,$roletext_end);
1.104 raeburn 1728: }
1729:
1.192 raeburn 1730: sub adhoc_roles_row {
1.138 raeburn 1731: my ($dcdom,$rowtype) = @_;
1.212 bisitz 1732: my $output = &Apache::loncommon::continue_data_table_row()
1733: .' <td colspan="5">'
1734: .&mt('[_1]Ad hoc[_2] roles in domain [_3] --'
1735: ,'<span class="LC_cusr_emph">','</span>',$dcdom)
1.227 bisitz 1736: .' ';
1.193 raeburn 1737: my $selectcclink = &courselink($dcdom,$rowtype);
1.239 raeburn 1738: my $ccrole = &Apache::lonnet::plaintext('co',undef,undef,1);
1.182 www 1739: my $carole = &Apache::lonnet::plaintext('ca');
1.193 raeburn 1740: my $selectcalink = &coauthorlink($dcdom,$rowtype);
1.227 bisitz 1741: $output.=$ccrole.': '.$selectcclink
1742: .' | '.$carole.': '.$selectcalink
1.212 bisitz 1743: .&Apache::loncommon::end_data_table_row();
1.108 raeburn 1744: return $output;
1745: }
1746:
1.104 raeburn 1747: sub recent_filename {
1748: my $area=shift;
1.149 www 1749: return 'nohist_recent_'.&escape($area);
1.104 raeburn 1750: }
1751:
1.139 raeburn 1752: sub courseloadpage {
1753: my ($courseid) = @_;
1754: my $startpage;
1.144 albertel 1755: my %entry_settings = &Apache::lonnet::get('nohist_whatsnew',
1756: [$courseid.':courseinit']);
1.139 raeburn 1757: my ($tmp) = %entry_settings;
1.144 albertel 1758: unless ($tmp =~ /^error: 2 /) {
1.139 raeburn 1759: $startpage = $entry_settings{$courseid.':courseinit'};
1760: }
1761: if ($startpage eq '') {
1762: if (exists($env{'environment.course_init_display'})) {
1763: $startpage = $env{'environment.course_init_display'};
1764: }
1765: }
1766: return $startpage;
1767: }
1768:
1.1 harris41 1769: 1;
1770: __END__
1.32 harris41 1771:
1772: =head1 NAME
1773:
1774: Apache::lonroles - User Roles Screen
1775:
1776: =head1 SYNOPSIS
1777:
1778: Invoked by /etc/httpd/conf/srm.conf:
1779:
1780: <Location /adm/roles>
1781: PerlAccessHandler Apache::lonacc
1782: SetHandler perl-script
1783: PerlHandler Apache::lonroles
1784: ErrorDocument 403 /adm/login
1785: ErrorDocument 500 /adm/errorhandler
1786: </Location>
1.64 bowersj2 1787:
1788: =head1 OVERVIEW
1789:
1790: =head2 Choosing Roles
1791:
1792: C<lonroles> is a handler that allows a user to switch roles in
1793: mid-session. LON-CAPA attempts to work with "No Role Specified", the
1794: default role that a user has before selecting a role, as widely as
1795: possible, but certain handlers for example need specification which
1796: course they should act on, etc. Both in this scenario, and when the
1797: handler determines via C<lonnet>'s C<&allowed> function that a certain
1798: action is not allowed, C<lonroles> is used as error handler. This
1799: allows the user to select another role which may have permission to do
1800: what they were trying to do. C<lonroles> can also be accessed via the
1801: B<CRS> button in the Remote Control.
1802:
1803: =begin latex
1804:
1805: \begin{figure}
1806: \begin{center}
1807: \includegraphics[width=0.45\paperwidth,keepaspectratio]{Sample_Roles_Screen}
1808: \caption{\label{Sample_Roles_Screen}Sample Roles Screen}
1809: \end{center}
1810: \end{figure}
1811:
1812: =end latex
1813:
1814: =head2 Role Initialization
1815:
1816: 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 1817:
1818: =head1 INTRODUCTION
1819:
1820: This module enables a user to select what role he wishes to
1821: operate under (instructor, student, teaching assistant, course
1822: coordinator, etc). These roles are pre-established by the actions
1823: of upper-level users.
1824:
1825: This is part of the LearningOnline Network with CAPA project
1826: described at http://www.lon-capa.org.
1827:
1828: =head1 HANDLER SUBROUTINE
1829:
1830: This routine is called by Apache and mod_perl.
1831:
1832: =over 4
1833:
1834: =item *
1835:
1836: Roles Initialization (yes/no)
1837:
1838: =item *
1839:
1840: Get Error Message from Environment
1841:
1842: =item *
1843:
1844: Who is this?
1845:
1846: =item *
1847:
1848: Generate Page Output
1849:
1850: =item *
1851:
1852: Choice or no choice
1853:
1854: =item *
1855:
1856: Table
1857:
1858: =item *
1859:
1860: Privileges
1861:
1862: =back
1863:
1864: =cut
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>