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