File:
[LON-CAPA] /
loncom /
auth /
lonroles.pm
Revision
1.185:
download - view:
text,
annotated -
select for diffs
Mon Mar 10 23:47:24 2008 UTC (16 years, 5 months ago) by
raeburn
Branches:
MAIN
CVS tags:
HEAD
- Improving ease of use (cf. Moodle).
Inline navigation includes dropdown to change to a different role in the course.
Course Coordinator - can switch to any role currently used in the course.
Other users - can switch to any other course roles assigned to them.
Work in progress.
- Needs additional dropdown for section context.
- Needs to maintain display of encrypted URLs as unencrypted when switching into CC role.
1: # The LearningOnline Network with CAPA
2: # User Roles Screen
3: #
4: # $Id: lonroles.pm,v 1.185 2008/03/10 23:47:24 raeburn Exp $
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: #
28: ###
29:
30: package Apache::lonroles;
31:
32: use strict;
33: use Apache::lonnet;
34: use Apache::lonuserstate();
35: use Apache::Constants qw(:common);
36: use Apache::File();
37: use Apache::lonmenu;
38: use Apache::loncommon;
39: use Apache::lonhtmlcommon;
40: use Apache::lonannounce;
41: use Apache::lonlocal;
42: use Apache::lonpageflip();
43: use Apache::lonnavdisplay();
44: use GDBM_File;
45: use LONCAPA qw(:DEFAULT :match);
46:
47:
48: sub redirect_user {
49: my ($r,$title,$url,$msg,$launch_nav) = @_;
50: $msg = $title if (! defined($msg));
51: &Apache::loncommon::content_type($r,'text/html');
52: &Apache::loncommon::no_cache($r);
53: $r->send_http_header;
54: my $swinfo=&Apache::lonmenu::rawconfig();
55: my $navwindow;
56: if ($launch_nav eq 'on') {
57: $navwindow.=&Apache::lonnavdisplay::launch_win('now',undef,undef,
58: ($url =~ m-^/adm/whatsnew-));
59: } else {
60: $navwindow.=&Apache::lonnavmaps::close();
61: }
62: my $start_page = &Apache::loncommon::start_page('Switching Role',undef,
63: {'redirect' => [1,$url],});
64: my $end_page = &Apache::loncommon::end_page();
65:
66: # Note to style police:
67: # This must only replace the spaces, nothing else, or it bombs elsewhere.
68: $url=~s/ /\%20/g;
69: $r->print(<<ENDREDIR);
70: $start_page
71: <script type="text/javascript">
72: $swinfo
73: </script>
74: $navwindow
75: <h1>$msg</h1>
76: $end_page
77: ENDREDIR
78: return;
79: }
80:
81: sub error_page {
82: my ($r,$error,$dest)=@_;
83: &Apache::loncommon::content_type($r,'text/html');
84: &Apache::loncommon::no_cache($r);
85: $r->send_http_header;
86: return OK if $r->header_only;
87: $r->print(&Apache::loncommon::start_page('Problems during Course Initialization').
88: '<script type="text/javascript">'.
89: &Apache::lonmenu::rawconfig().'</script>'.
90: '<p>'.&mt('The following problems occurred:').
91: $error.
92: '</p><br /><a href="'.$dest.'">'.&mt('Continue').'</a>'.
93: &Apache::loncommon::end_page());
94: }
95:
96: sub handler {
97:
98: my $r = shift;
99:
100: my $now=time;
101: my $then=$env{'user.login.time'};
102: my $envkey;
103: my %dcroles = ();
104: my $numdc = &check_fordc(\%dcroles,$then);
105: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'});
106:
107: # ================================================================== Roles Init
108: if ($env{'form.selectrole'}) {
109: if ($env{'form.newrole'}) {
110: $env{'form.'.$env{'form.newrole'}}=1;
111: }
112: if ($env{'request.course.id'}) {
113: # Check if user is CC trying to select a course role
114: if ($env{'form.switchrole'}) {
115: if (!defined($env{'user.role.'.$env{'form.switchrole'}})) {
116: &adhoc_course_role($then);
117: }
118: }
119: my %temp=('logout_'.$env{'request.course.id'} => time);
120: &Apache::lonnet::put('email_status',\%temp);
121: &Apache::lonnet::delenv('user.state.'.$env{'request.course.id'});
122: }
123: &Apache::lonnet::appenv("request.course.id" => '',
124: "request.course.fn" => '',
125: "request.course.uri" => '',
126: "request.course.sec" => '',
127: "request.role" => 'cm',
128: "request.role.adv" => $env{'user.adv'},
129: "request.role.domain" => $env{'user.domain'});
130: # Check if user is a DC trying to enter a course or author space and needs privs to be created
131: if ($numdc > 0) {
132: foreach my $envkey (keys %env) {
133: # Is this an ad-hoc CC-role?
134: if (my ($domain,$coursenum) =
135: ($envkey =~ m-^form\.cc\./($match_domain)/($match_courseid)$-)) {
136: if ($dcroles{$domain}) {
137: &check_privs($domain,$coursenum,$then,$now,'cc');
138: }
139: last;
140: }
141: # Is this a recent ad-hoc CA-role?
142: if (my ($domain,$user) =
143: ($envkey =~ m-^form\.ca\./($match_domain)/($match_username)$-)) {
144: if (($dcroles{$domain}) && (&is_author_homeserver($user,$domain))) {
145: &check_privs($domain,$user,$then,$now,'ca');
146: } else {
147: delete($env{$envkey});
148: }
149: last;
150: }
151: # Is this a new ad-hoc CA-role?
152: if (my ($domain) =
153: ($envkey =~ m-^form\.adhocca\./($match_domain)$-)) {
154: if ($dcroles{$domain}) {
155: my $user=$env{'form.adhoccauname.'.$domain};
156: if (!$user) { $user=$env{'form.adhoccaunamerecent.'.$domain} };
157: if (($user) && ($user=~/$match_username/) && (&is_author_homeserver($user,$domain))) {
158: &check_privs($domain,$user,$then,$now,'ca');
159: $env{'form.ca./'.$domain.'/'.$user}=1;
160: }
161: }
162: last;
163: }
164: }
165: }
166:
167: foreach $envkey (keys %env) {
168: next if ($envkey!~/^user\.role\./);
169: my ($where,$trolecode,$role,$tstatus,$tend,$tstart);
170: &role_status($envkey,$then,$now,\$role,\$where,\$trolecode,\$tstatus,\$tstart,\$tend);
171: if ($env{'form.'.$trolecode}) {
172: if ($tstatus eq 'is') {
173: $where=~s/^\///;
174: my ($cdom,$cnum,$csec)=split(/\//,$where);
175: # check for course groups
176: my %coursegroups = &Apache::lonnet::get_active_groups(
177: $env{'user.domain'},$env{'user.name'},$cdom, $cnum);
178: my $cgrps = join(':',keys(%coursegroups));
179:
180: # store role if recent_role list being kept
181: if ($env{'environment.recentroles'}) {
182: my %frozen_roles =
183: &Apache::lonhtmlcommon::get_recent_frozen('roles',$env{'environment.recentrolesn'});
184: &Apache::lonhtmlcommon::store_recent('roles',
185: $trolecode,' ',$frozen_roles{$trolecode});
186: }
187:
188:
189: # check for keyed access
190: if (($role eq 'st') &&
191: ($env{'course.'.$cdom.'_'.$cnum.'.keyaccess'} eq 'yes')) {
192: # who is key authority?
193: my $authdom=$cdom;
194: my $authnum=$cnum;
195: if ($env{'course.'.$cdom.'_'.$cnum.'.keyauth'}) {
196: ($authnum,$authdom)=
197: split(/:/,$env{'course.'.$cdom.'_'.$cnum.'.keyauth'});
198: }
199: # check with key authority
200: unless (&Apache::lonnet::validate_access_key(
201: $env{'environment.key.'.$cdom.'_'.$cnum},
202: $authdom,$authnum)) {
203: # there is no valid key
204: if ($env{'form.newkey'}) {
205: # student attempts to register a new key
206: &Apache::loncommon::content_type($r,'text/html');
207: &Apache::loncommon::no_cache($r);
208: $r->send_http_header;
209: my $swinfo=&Apache::lonmenu::rawconfig();
210: my $start_page=&Apache::loncommon::start_page
211: ('Verifying Access Key to Unlock this Course');
212: my $end_page=&Apache::loncommon::end_page();
213: my $buttontext=&mt('Enter Course');
214: my $message=&mt('Successfully registered key');
215: my $assignresult=
216: &Apache::lonnet::assign_access_key(
217: $env{'form.newkey'},
218: $authdom,$authnum,
219: $cdom,$cnum,
220: $env{'user.domain'},
221: $env{'user.name'},
222: 'Assigned from '.$ENV{'REMOTE_ADDR'}.' at '.localtime().' for '.
223: $trolecode);
224: unless ($assignresult eq 'ok') {
225: $assignresult=~s/^error\:\s*//;
226: $message=&mt($assignresult).
227: '<br /><a href="/adm/logout">'.
228: &mt('Logout').'</a>';
229: $buttontext=&mt('Re-Enter Key');
230: }
231: $r->print(<<ENDENTEREDKEY);
232: $start_page
233: <script type="text/javascript">
234: $swinfo
235: </script>
236: <form method="post">
237: <input type="hidden" name="selectrole" value="1" />
238: <input type="hidden" name="$trolecode" value="1" />
239: <font size="+2">$message</font><br />
240: <input type="submit" value="$buttontext" />
241: </form>
242: $end_page
243: ENDENTEREDKEY
244: return OK;
245: } else {
246: # print form to enter a new key
247: &Apache::loncommon::content_type($r,'text/html');
248: &Apache::loncommon::no_cache($r);
249: $r->send_http_header;
250: my $swinfo=&Apache::lonmenu::rawconfig();
251: my $start_page=&Apache::loncommon::start_page
252: ('Enter Access Key to Unlock this Course');
253: my $end_page=&Apache::loncommon::end_page();
254: $r->print(<<ENDENTERKEY);
255: $start_page
256: <script type="text/javascript">
257: $swinfo
258: </script>
259: <form method="post">
260: <input type="hidden" name="selectrole" value="1" />
261: <input type="hidden" name="$trolecode" value="1" />
262: <input type="text" size="20" name="newkey" value="$env{'form.newkey'}" />
263: <input type="submit" value="Enter key" />
264: </form>
265: $end_page
266: ENDENTERKEY
267: return OK;
268: }
269: }
270: }
271: &Apache::lonnet::log($env{'user.domain'},
272: $env{'user.name'},
273: $env{'user.home'},
274: "Role ".$trolecode);
275:
276: &Apache::lonnet::appenv(
277: 'request.role' => $trolecode,
278: 'request.role.domain' => $cdom,
279: 'request.course.sec' => $csec,
280: 'request.course.groups' => $cgrps);
281: my $tadv=0;
282:
283: if (($cnum) && ($role ne 'ca') && ($role ne 'aa')) {
284: my $msg;
285: my ($furl,$ferr)=
286: &Apache::lonuserstate::readmap($cdom.'/'.$cnum);
287: if (($env{'form.orgurl'}) &&
288: ($env{'form.orgurl'}!~/^\/adm\/flip/)) {
289: my $dest=$env{'form.orgurl'};
290: if (&Apache::lonnet::allowed('adv') eq 'F') { $tadv=1; }
291: &Apache::lonnet::appenv('request.role.adv'=>$tadv);
292: if (($ferr) && ($tadv)) {
293: &error_page($r,$ferr,$dest);
294: } else {
295: $r->internal_redirect($dest);
296: }
297: return OK;
298: } else {
299: if (!$env{'request.course.id'}) {
300: &Apache::lonnet::appenv(
301: "request.course.id" => $cdom.'_'.$cnum);
302: $furl='/adm/roles?tryagain=1';
303: $msg=
304: '<h1><span class="LC_error">'.
305: &mt('Could not initialize [_1] at this time.',
306: $env{'course.'.$cdom.'_'.$cnum.'.description'}).
307: '</span></h1><h3>'.&mt('Please try again.').'</h3>'.$ferr;
308: }
309: if (&Apache::lonnet::allowed('adv') eq 'F') { $tadv=1; }
310: &Apache::lonnet::appenv('request.role.adv'=>$tadv);
311:
312: if (($ferr) && ($tadv)) {
313: &error_page($r,$ferr,$furl);
314: } else {
315: # Check to see if the user is a CC entering a course
316: # for the first time
317: my (undef, undef, $role, $courseid) = split(/\./, $envkey);
318: if (substr($courseid, 0, 1) eq '/') {
319: $courseid = substr($courseid, 1);
320: }
321: $courseid =~ s/\//_/;
322: if ($role eq 'cc' && $env{'course.' . $courseid .
323: '.course.helper.not.run'}) {
324: $furl = "/adm/helper/course.initialization.helper";
325: # Send the user to the course they selected
326: } elsif ($env{'request.course.id'}) {
327: if ($env{'form.destinationurl'}) {
328: my $dest = $env{'form.destinationurl'};
329: &redirect_user($r,&mt('Entering [_1]',
330: $env{'course.'.$courseid.'.description'}),
331: $dest,$msg,
332: $env{'environment.remotenavmap'});
333: return OK;
334: }
335: if (&Apache::lonnet::allowed('whn',
336: $env{'request.course.id'})
337: || &Apache::lonnet::allowed('whn',
338: $env{'request.course.id'}.'/'
339: .$env{'request.course.sec'})
340: ) {
341: my $startpage = &courseloadpage($courseid);
342: unless ($startpage eq 'firstres') {
343: $msg = &mt('Entering [_1] ....',
344: $env{'course.'.$courseid.'.description'});
345: &redirect_user($r,&mt('New in course'),
346: '/adm/whatsnew?refpage=start',$msg,
347: $env{'environment.remotenavmap'});
348: return OK;
349: }
350: }
351: }
352: # Are we allowed to look at the first resource?
353: if ($furl !~ m|^/adm/|) {
354: # Guess not ...
355: $furl=&Apache::lonpageflip::first_accessible_resource();
356: }
357: $msg = &mt('Entering [_1] ...',
358: $env{'course.'.$courseid.'.description'});
359: &redirect_user($r,&mt('Entering [_1]',
360: $env{'course.'.$courseid.'.description'}),
361: $furl,$msg,
362: $env{'environment.remotenavmap'});
363: }
364: return OK;
365: }
366: }
367: #
368: # Send the user to the construction space they selected
369: if ($role =~ /^(au|ca|aa)$/) {
370: my $redirect_url = '/priv/';
371: if ($role eq 'au') {
372: $redirect_url.=$env{'user.name'};
373: } else {
374: $where =~ /\/(.*)$/;
375: $redirect_url .= $1;
376: }
377: $redirect_url .= '/';
378: &redirect_user($r,&mt('Entering Construction Space'),
379: $redirect_url);
380: return OK;
381: }
382: if ($role eq 'dc') {
383: my $redirect_url = '/adm/menu/';
384: &redirect_user($r,&mt('Loading Domain Coordinator Menu'),
385: $redirect_url);
386: return OK;
387: }
388: }
389: }
390: }
391: }
392:
393:
394: # =============================================================== No Roles Init
395:
396: &Apache::loncommon::content_type($r,'text/html');
397: &Apache::loncommon::no_cache($r);
398: $r->send_http_header;
399: return OK if $r->header_only;
400:
401: my $swinfo=&Apache::lonmenu::rawconfig();
402: my $start_page=&Apache::loncommon::start_page('User Roles');
403: my $standby=&mt('Role selected. Please stand by.');
404: $standby=~s/\n/\\n/g;
405: 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 />';
406:
407: $r->print(<<ENDHEADER);
408: $start_page
409: <br />
410: <noscript>
411: $noscript
412: </noscript>
413: <script type="text/javascript">
414: $swinfo
415: window.focus();
416:
417: active=true;
418:
419: function enterrole (thisform,rolecode,buttonname) {
420: if (active) {
421: active=false;
422: document.title='$standby';
423: window.status='$standby';
424: thisform.newrole.value=rolecode;
425: thisform.submit();
426: } else {
427: alert('$standby');
428: }
429: }
430: </script>
431: ENDHEADER
432:
433: # ------------------------------------------ Get Error Message from Environment
434:
435: my ($fn,$priv,$nochoose,$error,$msg)=split(/:/,$env{'user.error.msg'});
436: if ($env{'user.error.msg'}) {
437: $r->log_reason(
438: "$msg for $env{'user.name'} domain $env{'user.domain'} access $priv",$fn);
439: }
440:
441: # ------------------------------------------------- Can this user re-init, etc?
442:
443: my $advanced=$env{'user.adv'};
444: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['tryagain']);
445: my $tryagain=$env{'form.tryagain'};
446:
447: # -------------------------------------------------------- Generate Page Output
448: # --------------------------------------------------------------- Error Header?
449: if ($error) {
450: $r->print("<h1>LON-CAPA Access Control</h1>");
451: $r->print("<!-- LONCAPAACCESSCONTROLERRORSCREEN --><hr /><pre>");
452: if ($priv ne '') {
453: $r->print("Access : ".&Apache::lonnet::plaintext($priv)."\n");
454: }
455: if ($fn ne '') {
456: $r->print("Resource: ".&Apache::lonenc::check_encrypt($fn)."\n");
457: }
458: if ($msg ne '') {
459: $r->print("Action : $msg\n");
460: }
461: $r->print("</pre><hr />");
462: my $url=$fn;
463: my $last;
464: if (tie(my %hash,'GDBM_File',$env{'request.course.fn'}.'_symb.db',
465: &GDBM_READER(),0640)) {
466: $last=$hash{'last_known'};
467: untie(%hash);
468: }
469: if ($last) { $fn.='?symb='.&escape($last); }
470:
471: &Apache::londocs::changewarning($r,undef,'You have modified your course recently, [_1] may fix this access problem.',
472: &Apache::lonenc::check_encrypt($fn));
473: } else {
474: if ($env{'user.error.msg'}) {
475: $r->print(
476: '<h3><span class="LC_error">'.
477: &mt('You need to choose another user role or enter a specific course for this function').'</span></h3>');
478: }
479: }
480: # -------------------------------------------------------- Choice or no choice?
481: if ($nochoose) {
482: $r->print("<h2>".&mt('Sorry ...')."</h2>\n<span class='LC_error'>".
483: &mt('This action is currently not authorized.').'</span>'.
484: &Apache::loncommon::end_page());
485: return OK;
486: } else {
487: if (($ENV{'REDIRECT_QUERY_STRING'}) && ($fn)) {
488: $fn.='?'.$ENV{'REDIRECT_QUERY_STRING'};
489: }
490: $r->print('<form method="post" name="rolechoice" action="'.(($fn)?$fn:$r->uri).'">');
491: $r->print('<input type="hidden" name="orgurl" value="'.$fn.'" />');
492: $r->print('<input type="hidden" name="selectrole" value="1" />');
493: $r->print('<input type="hidden" name="newrole" value="" />');
494: }
495: if ($env{'user.adv'}) {
496: $r->print(
497: '<br /><span class="LC_rolesinfo"><label>'.&mt('Show all roles').': <input type="checkbox" name="showall"');
498: if ($env{'form.showall'}) { $r->print(' checked="checked" '); }
499: $r->print(' /></label><input type="submit" value="'.&mt('Display').'" /></span>');
500: }
501:
502: my (%roletext,%sortrole,%roleclass);
503: my $countactive=0;
504: my $inrole=0;
505: my $possiblerole='';
506: foreach $envkey (sort keys %env) {
507: my $button = 1;
508: my $switchserver='';
509: my $roletext;
510: my $sortkey;
511: if ($envkey=~/^user\.role\./) {
512: my ($role,$where,$trolecode,$tstart,$tend,$tremark,$tstatus,$tpstart,$tpend,$tfont);
513: &role_status($envkey,$then,$now,\$role,\$where,\$trolecode,\$tstatus,\$tstart,\$tend);
514: next if (!defined($role) || $role eq '' || $role =~ /^gr/);
515: $tremark='';
516: $tpstart=' ';
517: $tpend=' ';
518: $tfont='#000000';
519: if ($tstart) {
520: $tpstart=&Apache::lonlocal::locallocaltime($tstart);
521: }
522: if ($tend) {
523: $tpend=&Apache::lonlocal::locallocaltime($tend);
524: }
525: if ($env{'request.role'} eq $trolecode) {
526: $tstatus='selected';
527: }
528: my $tbg;
529: if (($tstatus eq 'is')
530: || ($tstatus eq 'selected')
531: || ($tstatus eq 'will')
532: || ($tstatus eq 'future')
533: || ($env{'form.showall'})) {
534: if ($tstatus eq 'is') {
535: $tbg='#77FF77';
536: $tfont='#003300';
537: $possiblerole=$trolecode;
538: $countactive++;
539: } elsif ($tstatus eq 'future') {
540: $tbg='#FFFF77';
541: $button=0;
542: } elsif ($tstatus eq 'will') {
543: $tbg='#FFAA77';
544: $tremark.=&mt('Active at next login. ');
545: } elsif ($tstatus eq 'expired') {
546: $tbg='#FF7777';
547: $tfont='#330000';
548: $button=0;
549: } elsif ($tstatus eq 'will_not') {
550: $tbg='#AAFF77';
551: $tremark.=&mt('Expired after logout. ');
552: } elsif ($tstatus eq 'selected') {
553: $tbg='#11CC55';
554: $tfont='#002200';
555: $inrole=1;
556: $countactive++;
557: $tremark.=&mt('Currently selected. ');
558: }
559: my $trole;
560: if ($role =~ /^cr\//) {
561: my ($rdummy,$rdomain,$rauthor,$rrole)=split(/\//,$role);
562: if ($tremark) { $tremark.='<br />'; }
563: $tremark.=&mt('Defined by ').$rauthor.
564: &mt(' at ').$rdomain.'.';
565: }
566: $trole=Apache::lonnet::plaintext($role);
567: my $ttype;
568: my $twhere;
569: my ($tdom,$trest,$tsection)=
570: split(/\//,Apache::lonnet::declutter($where));
571: # First, Co-Authorship roles
572: if (($role eq 'ca') || ($role eq 'aa')) {
573: my $home = &Apache::lonnet::homeserver($trest,$tdom);
574: my $allowed=0;
575: my @ids=&Apache::lonnet::current_machine_ids();
576: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
577: if (!$allowed) {
578: $button=0;
579: $switchserver='otherserver='.$home.'&role='.$trolecode;
580: }
581: #next if ($home eq 'no_host');
582: $home = &Apache::lonnet::hostname($home);
583: $ttype='Construction Space';
584: $twhere=&mt('User').': '.$trest.'<br />'.&mt('Domain').
585: ': '.$tdom.'<br />'.
586: ' '.&mt('Server').': '.$home;
587: $env{'course.'.$tdom.'_'.$trest.'.description'}='ca';
588: $tremark.=&Apache::lonhtmlcommon::authorbombs('/res/'.$tdom.'/'.$trest.'/');
589: $sortkey=$role."$trest:$tdom";
590: } elsif ($role eq 'au') {
591: # Authors
592: my $home = &Apache::lonnet::homeserver
593: ($env{'user.name'},$env{'user.domain'});
594: my $allowed=0;
595: my @ids=&Apache::lonnet::current_machine_ids();
596: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
597: if (!$allowed) {
598: $button=0;
599: $switchserver='otherserver='.$home.'&role='.$trolecode;
600: }
601: #next if ($home eq 'no_host');
602: $home = &Apache::lonnet::hostname($home);
603: $ttype='Construction Space';
604: $twhere=&mt('Domain').': '.$tdom.'<br />'.&mt('Server').
605: ': '.$home;
606: $env{'course.'.$tdom.'_'.$trest.'.description'}='ca';
607: $tremark.=&Apache::lonhtmlcommon::authorbombs('/res/'.$tdom.'/'.$env{'user.name'}.'/');
608: $sortkey=$role;
609: } elsif ($trest) {
610: my $tcourseid=$tdom.'_'.$trest;
611: $ttype = &Apache::loncommon::course_type($tcourseid);
612: $trole = &Apache::lonnet::plaintext($role,$ttype);
613: if ($env{'course.'.$tcourseid.'.description'}) {
614: $twhere=$env{'course.'.$tcourseid.'.description'};
615: $sortkey=$role."\0".$tdom."\0".$twhere."\0".$envkey;
616: unless ($twhere eq &mt('Currently not available')) {
617: $twhere.=' <font size="-2">'.
618: &Apache::loncommon::syllabuswrapper(&mt('Syllabus'),$trest,$tdom,$tfont).
619: '</font>';
620: }
621: } else {
622: my %newhash=&Apache::lonnet::coursedescription($tcourseid);
623: if (%newhash) {
624: $sortkey=$role."\0".$tdom."\0".$newhash{'description'}.
625: "\0".$envkey;
626: $twhere=$newhash{'description'}.
627: ' <font size="-2">'.
628: &Apache::loncommon::syllabuswrapper(&mt('Syllabus'),$trest,$tdom,$tfont).
629: '</font>';
630: $ttype = $newhash{'type'};
631: $trole = &Apache::lonnet::plaintext($role,$ttype);
632: } else {
633: $twhere=&mt('Currently not available');
634: $env{'course.'.$tcourseid.'.description'}=$twhere;
635: $sortkey=$role."\0".$tdom."\0".$twhere."\0".$envkey;
636: $ttype = 'Unavailable';
637: }
638: }
639: if ($tsection) {
640: $twhere.='<br />'.&mt('Section').': '.$tsection;
641: }
642: if ($role ne 'st') { $twhere.="<br />".&mt('Domain').":".$tdom; }
643: } elsif ($tdom) {
644: $ttype='Domain';
645: $twhere=$tdom;
646: $sortkey=$role.$twhere;
647: } else {
648: $ttype='System';
649: $twhere=&mt('system wide');
650: $sortkey=$role.$twhere;
651: }
652: $roletext.=&build_roletext($trolecode,$tdom,$trest,$tstatus,$tryagain,$advanced,$tremark,$tbg,$tfont,$trole,$twhere,$tpstart,$tpend,$nochoose,$button,$switchserver);
653: $roletext{$envkey}=$roletext;
654: if (!$sortkey) {$sortkey=$twhere."\0".$envkey;}
655: $sortrole{$sortkey}=$envkey;
656: $roleclass{$envkey}=$ttype;
657: }
658: }
659: }
660: # No active roles
661: if ($countactive==0) {
662: if ($inrole) {
663: $r->print('<h2>'.&mt('Currently no additional roles or courses').'</h2>');
664: } else {
665: $r->print('<h2>'.&mt('Currently no active roles or courses').'</h2>');
666: }
667: $r->print('</form>'.&Apache::loncommon::end_page());
668: return OK;
669: # Is there only one choice?
670: } elsif (($countactive==1) && ($env{'request.role'} eq 'cm')) {
671: $r->print('<h3>'.&mt('Please stand by.').'</h3>'.
672: '<input type="hidden" name="'.$possiblerole.'" value="1" />'.
673: '<noscript><br /><input type="submit" name="submit" value="'.&mt('Continue').'" /></noscript>');
674: $r->print("</form>\n");
675: $r->rflush();
676: $r->print('<script type="text/javascript">document.forms.rolechoice.submit();</script>');
677: $r->print(&Apache::loncommon::end_page());
678: return OK;
679: }
680: # More than one possible role
681: # ----------------------------------------------------------------------- Table
682: unless ((!&Apache::lonmenu::show_course()) || ($nochoose)) {
683: $r->print("<h2>".&mt('Select a Course to Enter')."</h2>\n");
684: }
685: $r->print('<br /><table id="LC_rolesmenu"><tr>');
686: unless ($nochoose) { $r->print('<th> </th>'); }
687: $r->print('<th>'.&mt('User Role').'</th><th>'.&mt('Extent').
688: '</th><th>'.&mt('Start').'</th><th>'.&mt('End').'</th></tr>'."\n");
689: my $doheaders=-1;
690: foreach my $type ('Domain','Construction Space','Course','Unavailable','System') {
691: my $haverole=0;
692: foreach my $which (sort {uc($a) cmp uc($b)} (keys(%sortrole))) {
693: if ($roleclass{$sortrole{$which}} =~ /^\Q$type\E/) {
694: $haverole=1;
695: }
696: }
697: if ($haverole) { $doheaders++; }
698: }
699:
700: if ($env{'environment.recentroles'}) {
701: my %recent_roles =
702: &Apache::lonhtmlcommon::get_recent('roles',$env{'environment.recentrolesn'});
703: my $output='';
704: foreach (sort(keys(%recent_roles))) {
705: if (defined($roletext{'user.role.'.$_})) {
706: $output.=$roletext{'user.role.'.$_};
707: if ($_ =~ m-dc\./($match_domain)/-
708: && $dcroles{$1}) {
709: $output .= &allcourses_row($1,'recent').
710: &allcoauthors_row($1,'recent');
711: }
712: } elsif ($numdc > 0) {
713: unless ($_ =~/^error\:/) {
714: $output.=&display_cc_role('user.role.'.$_);
715: }
716: }
717: }
718: if ($output) {
719: $r->print("<tr><td align='center' colspan='5'><font face='arial'>".
720: &mt('Recent Roles')."</font></td>");
721: $r->print($output);
722: $r->print("</tr>");
723: $doheaders ++;
724: }
725: }
726:
727: if ($numdc > 0) {
728: $r->print(&coursepick_jscript());
729: $r->print(&Apache::loncommon::coursebrowser_javascript());
730: }
731: foreach my $type ('Construction Space','Domain','Course','Unavailable','System') {
732: my $output;
733: foreach my $which (sort {uc($a) cmp uc($b)} (keys(%sortrole))) {
734: if ($roleclass{$sortrole{$which}} =~ /^\Q$type\E/) {
735: $output.=$roletext{$sortrole{$which}};
736: if ($sortrole{$which} =~ m-dc\./($match_domain)/-) {
737: if ($dcroles{$1}) {
738: $output .= &allcourses_row($1,'').
739: &allcoauthors_row($1,'');
740: }
741: }
742: }
743: }
744: if ($output) {
745: if ($doheaders > 0) {
746: $r->print("<tr>".
747: "<td align='center' colspan='5'><font face='arial'>".&mt($type)."</font></td></tr>");
748: }
749: $r->print($output);
750: }
751: }
752: my $tremark='';
753: my $tfont='#003300';
754: if ($env{'request.role'} eq 'cm') {
755: $r->print('<tr bgcolor="#11CC55">');
756: $tremark=&mt('Currently selected. ');
757: $tfont='#002200';
758: } else {
759: $r->print('<tr bgcolor="#77FF77">');
760: }
761: unless ($nochoose) {
762: if ($env{'request.role'} ne 'cm') {
763: $r->print('<td><input type="submit" value="'.
764: &mt('Select').'" name="cm"></td>');
765: } else {
766: $r->print('<td> </td>');
767: }
768: }
769: $r->print('<td colspan="3"><font color="'.$tfont.'"><span class="LC_rolesinfo">'.&mt('No role specified').
770: '</font></span></td><td><font color="'.$tfont.'">'.$tremark.
771: ' </font></td></tr>'."\n");
772:
773: $r->print('</table>');
774: unless ($nochoose) {
775: $r->print("</form>\n");
776: }
777: # ------------------------------------------------------------ Privileges Info
778: if (($advanced) && (($env{'user.error.msg'}) || ($error))) {
779: $r->print('<hr /><h2>Current Privileges</h2>');
780: $r->print(&privileges_info());
781: }
782: $r->print(&Apache::lonnet::getannounce());
783: if ($advanced) {
784: $r->print('<p><small><i>This is LON-CAPA '.
785: $r->dir_config('lonVersion').'</i><br />'.
786: '<a href="/adm/logout">'.&mt('Logout').'</a></small></p>');
787: }
788: $r->print(&Apache::loncommon::end_page());
789: return OK;
790: }
791:
792: sub privileges_info {
793: my ($which) = @_;
794: my $output;
795:
796: $which ||= $env{'request.role'};
797:
798: foreach my $envkey (sort(keys(%env))) {
799: next if ($envkey!~/^user\.priv\.\Q$which\E\.(.*)/);
800:
801: my $where=$1;
802: my $ttype;
803: my $twhere;
804: my (undef,$tdom,$trest,$tsec)=split(m{/},$where);
805: if ($trest) {
806: if ($env{'course.'.$tdom.'_'.$trest.'.description'} eq 'ca') {
807: $ttype='Construction Space';
808: $twhere='User: '.$trest.', Domain: '.$tdom;
809: } else {
810: $ttype= &Apache::loncommon::course_type($tdom.'_'.$trest);
811: $twhere=$env{'course.'.$tdom.'_'.$trest.'.description'};
812: if ($tsec) {
813: my $sec_type = 'Section';
814: if (exists($env{"user.role.gr.$where"})) {
815: $sec_type = 'Group';
816: }
817: $twhere.=' ('.$sec_type.': '.$tsec.')';
818: }
819: }
820: } elsif ($tdom) {
821: $ttype='Domain';
822: $twhere=$tdom;
823: } else {
824: $ttype='System';
825: $twhere='/';
826: }
827: $output .= "\n<h3>".$ttype.': '.$twhere.'</h3>'."\n<ul>";
828: foreach my $priv (sort(split(/:/,$env{$envkey}))) {
829: next if (!$priv);
830:
831: my ($prv,$restr)=split(/\&/,$priv);
832: my $trestr='';
833: if ($restr ne 'F') {
834: $trestr.=' ('.
835: join(', ',
836: map { &Apache::lonnet::plaintext($_) }
837: (split('',$restr))).') ';
838: }
839: $output .= "\n\t".
840: '<li>'.&Apache::lonnet::plaintext($prv).$trestr.'</li>';
841: }
842: $output .= "\n".'</ul>';
843: }
844: return $output;
845: }
846:
847: sub role_status {
848: my ($rolekey,$then,$now,$role,$where,$trolecode,$tstatus,$tstart,$tend) = @_;
849: my @pwhere = ();
850: if (exists($env{$rolekey}) && $env{$rolekey} ne '') {
851: (undef,undef,$$role,@pwhere)=split(/\./,$rolekey);
852: unless (!defined($$role) || $$role eq '') {
853: $$where=join('.',@pwhere);
854: $$trolecode=$$role.'.'.$$where;
855: ($$tstart,$$tend)=split(/\./,$env{$rolekey});
856: $$tstatus='is';
857: if ($$tstart && $$tstart>$then) {
858: $$tstatus='future';
859: if ($$tstart<$now) { $$tstatus='will'; }
860: }
861: if ($$tend) {
862: if ($$tend<$then) {
863: $$tstatus='expired';
864: } elsif ($$tend<$now) {
865: $$tstatus='will_not';
866: }
867: }
868: }
869: }
870: }
871:
872: sub build_roletext {
873: my ($trolecode,$tdom,$trest,$tstatus,$tryagain,$advanced,$tremark,$tbg,$tfont,$trole,$twhere,$tpstart,$tpend,$nochoose,$button,$switchserver) = @_;
874: my $roletext='<tr bgcolor="'.$tbg.'" class="LC_rolesmenu_'.$tstatus.'">';
875: my $is_dc=($trolecode =~ m/^dc\./);
876: my $rowspan=($is_dc) ? ''
877: : ' rowspan="2" ';
878:
879: unless ($nochoose) {
880: my $buttonname=$trolecode;
881: $buttonname=~s/\W//g;
882: if (!$button) {
883: if ($switchserver) {
884: $roletext.='<td'.$rowspan.'><span class="LC_rolesinfo"><a href="/adm/switchserver?'.
885: $switchserver.'">'.&mt('Switch Server').'</a></span></td>';
886: } else {
887: $roletext.=('<td'.$rowspan.'> </td>');
888: }
889: } elsif ($tstatus eq 'is') {
890: $roletext.='<td'.$rowspan.'><input name="'.$buttonname.'" type="button" value="'.
891: &mt('Select').'" onClick="javascript:enterrole(this.form,\''.
892: $trolecode."','".$buttonname.'\');"></td>';
893: } elsif ($tryagain) {
894: $roletext.=
895: '<td'.$rowspan.'><input name="'.$buttonname.'" type="button" value="'.
896: &mt('Try Selecting Again').'" onClick="javascript:enterrole(this.form,\''.
897: $trolecode."','".$buttonname.'\');"></td>';
898: } elsif ($advanced) {
899: $roletext.=
900: '<td'.$rowspan.'><input name="'.$buttonname.'" type="button" value="'.
901: &mt('Re-Initialize').'" onClick="javascript:enterrole(this.form,\''.
902: $trolecode."','".$buttonname.'\');"></td>';
903: } else {
904: $roletext.='<td'.$rowspan.'> </td>';
905: }
906: }
907: if ($trolecode !~ m/^(dc|ca|au|aa)\./) {
908: $tremark.=&Apache::lonannounce::showday(time,1,
909: &Apache::lonannounce::readcalendar($tdom.'_'.$trest));
910: }
911: $roletext.='<td><font color="'.$tfont.'">'.$trole.
912: '</font></td><td><font color="'.$tfont.'">'.$twhere.
913: '</font></td><td><font color="'.$tfont.'">'.$tpstart.
914: '</font></td><td><font color="'.$tfont.'">'.$tpend.
915: '</font></td></tr>';
916: if (!$is_dc) {
917: $roletext.='<tr bgcolor="'.$tbg.'"><td colspan="4"><font color="'.$tfont.'"><span class="LC_rolesinfo">'.$tremark.
918: '</span> </font></td></tr><tr><td colspan="5" height="3"></td></tr>'."\n";
919: }
920: return $roletext;
921: }
922:
923: sub is_author_homeserver {
924: my ($uname,$udom)=@_;
925: my $home = &Apache::lonnet::homeserver($uname,$udom);
926: my @ids=&Apache::lonnet::current_machine_ids();
927: foreach my $id (@ids) {
928: if ($id eq $home) {
929: if (-e "/home/".$uname."/public_html") {
930: return 1;
931: }
932: }
933: }
934: return 0;
935: }
936:
937: sub check_privs {
938: my ($cdom,$cnum,$then,$now,$checkrole) = @_;
939: my $cckey = 'user.role.'.$checkrole.'./'.$cdom.'/'.$cnum;
940: if ($env{$cckey}) {
941: my ($role,$where,$trolecode,$tstart,$tend,$tremark,$tstatus,$tpstart,$tpend,$tfont);
942: &role_status($cckey,$then,$now,\$role,\$where,\$trolecode,\$tstatus,\$tstart,\$tend);
943: unless (($tstatus eq 'is') || ($tstatus eq 'will_not')) {
944: &set_privileges($cdom,$cnum,$checkrole);
945: }
946: } else {
947: &set_privileges($cdom,$cnum,$checkrole);
948: }
949: }
950:
951: sub check_fordc {
952: my ($dcroles,$then) = @_;
953: my $numdc = 0;
954: if ($env{'user.adv'}) {
955: foreach my $envkey (sort keys %env) {
956: if ($envkey=~/^user\.role\.dc\.\/($match_domain)\/$/) {
957: my $dcdom = $1;
958: my $livedc = 1;
959: my ($tstart,$tend)=split(/\./,$env{$envkey});
960: if ($tstart && $tstart>$then) { $livedc = 0; }
961: if ($tend && $tend <$then) { $livedc = 0; }
962: if ($livedc) {
963: $$dcroles{$dcdom} = $envkey;
964: $numdc++;
965: }
966: }
967: }
968: }
969: return $numdc;
970: }
971:
972: sub adhoc_course_role {
973: my ($then) = @_;
974: my ($cdom,$cnum);
975: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
976: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
977: if (&check_forcc($cdom,$cnum,$then)) {
978: my $setprivs;
979: if (!defined($env{'user.role.'.$env{'form.selectrole'}})) {
980: $setprivs = 1;
981: } else {
982: my ($start,$end) = split(/\./,$env{'user.role.'.$env{'form.selectrole'}});
983: if (($start && ($start>$then || $start == -1)) ||
984: ($end && $end<$then)) {
985: $setprivs = 1;
986: }
987: }
988: if ($setprivs) {
989: if ($env{'form.switchrole'} =~ m-^(in|ta|ep|ad|st|cr)([\w/]*)\./\Q$cdom\E/\Q$cnum\E(/?\w*)$-) {
990: my $role = $1;
991: my $custom_role = $2;
992: my $usec = $3;
993: if ($role eq 'cr') {
994: if ($custom_role =~ m-^$match_domain/$match_courseid/\w+$-) {
995: $role .= $custom_role;
996: } else {
997: return;
998: }
999: }
1000: my (%userroles,%newrole,%newgroups);
1001: my $area = '/'.$cdom.'/'.$cnum;
1002: my $spec = $role.'.'.$area;
1003: if ($usec ne '') {
1004: $spec .= '/'.$usec;
1005: $area .= '/'.$usec;
1006: }
1007: &Apache::lonnet::standard_roleprivs(\%newrole,$role,$cdom,$spec,$cnum,$area);
1008: &Apache::lonnet::set_userprivs(\%userroles,\%newrole,%newgroups);
1009: my $adhocstart = $then-1;
1010: $userroles{'user.role.'.$spec} = $adhocstart.'.';
1011: &Apache::lonnet::appenv(%userroles);
1012: }
1013: }
1014: }
1015: return;
1016: }
1017:
1018: sub check_forcc {
1019: my ($cdom,$cnum,$then) = @_;
1020: my $is_cc;
1021: if ($cdom ne '' && $cnum ne '') {
1022: if (&Apache::lonnet::is_course($cdom,$cnum)) {
1023: my $envkey = 'user.role.cc./'.$cdom.'/'.$cnum;
1024: if (defined($env{$envkey})) {
1025: $is_cc = 1;
1026: my ($tstart,$tend)=split(/\./,$env{$envkey});
1027: if ($tstart && $tstart>$then) { $is_cc = 0; }
1028: if ($tend && $tend <$then) { $is_cc = 0; }
1029: }
1030: }
1031: }
1032: return $is_cc;
1033: }
1034:
1035: sub courselink {
1036: my ($dcdom,$rowtype,$selecttype) = @_;
1037: my $courseform=&Apache::loncommon::selectcourse_link
1038: ('rolechoice','dccourse'.$rowtype.'_'.$dcdom,
1039: 'dcdomain'.$rowtype.'_'.$dcdom,'coursedesc'.$rowtype.'_'.
1040: $dcdom,$dcdom,undef);
1041: my $hiddenitems = '<input type="hidden" name="dcdomain'.$rowtype.'_'.$dcdom.'" value="'.$dcdom.'" />'.
1042: '<input type="hidden" name="origdom'.$rowtype.'_'.$dcdom.'" value="'.$dcdom.'" />'.
1043: '<input type="hidden" name="dccourse'.$rowtype.'_'.$dcdom.'" value="" />'.
1044: '<input type="hidden" name="coursedesc'.$rowtype.'_'.$dcdom.'" value="" />';
1045: return $courseform.$hiddenitems;
1046: }
1047:
1048: sub coursepick_jscript {
1049: my %lt = &Apache::lonlocal::texthash(
1050: plsu => "Please use the 'Select Course' link to open a separate pick course window where you may select the course you wish to enter.",
1051: youc => 'You can only use this screen to select courses in the current domain.',
1052: );
1053: my $verify_script = <<"END";
1054: <script type="text/javascript">
1055: function verifyCoursePick(caller) {
1056: var numbutton = getIndex(caller)
1057: var pickedCourse = document.rolechoice.elements[numbutton+4].value
1058: var pickedDomain = document.rolechoice.elements[numbutton+2].value
1059: if (document.rolechoice.elements[numbutton+2].value == document.rolechoice.elements[numbutton+3].value) {
1060: if (pickedCourse != '') {
1061: if (numbutton != -1) {
1062: var courseTarget = "cc./"+pickedDomain+"/"+pickedCourse
1063: document.rolechoice.elements[numbutton+1].name = courseTarget
1064: document.rolechoice.submit()
1065: }
1066: }
1067: else {
1068: alert("$lt{'plsu'}");
1069: }
1070: }
1071: else {
1072: alert("$lt{'youc'}")
1073: }
1074: }
1075: function getIndex(caller) {
1076: for (var i=0;i<document.rolechoice.elements.length;i++) {
1077: if (document.rolechoice.elements[i] == caller) {
1078: return i;
1079: }
1080: }
1081: return -1;
1082: }
1083: </script>
1084: END
1085: return $verify_script;
1086: }
1087:
1088: sub display_cc_role {
1089: my $rolekey = shift;
1090: my $roletext;
1091: my $advanced = $env{'user.adv'};
1092: my $tryagain = $env{'form.tryagain'};
1093: unless ($rolekey =~/^error\:/) {
1094: if ($rolekey =~ m-^user\.role.cc\./($match_domain)/($match_courseid)$-) {
1095: my $tcourseid = $1.'_'.$2;
1096: my $trolecode = 'cc./'.$1.'/'.$2;
1097: my $twhere;
1098: my $ttype;
1099: my $tbg='#77FF77';
1100: my $tfont='#003300';
1101: my %newhash=&Apache::lonnet::coursedescription($tcourseid);
1102: if (%newhash) {
1103: $twhere=$newhash{'description'}.
1104: ' <font size="-2">'.
1105: &Apache::loncommon::syllabuswrapper(&mt('Syllabus'),$2,$1,$tfont).
1106: '</font>';
1107: $ttype = $newhash{'type'};
1108: } else {
1109: $twhere=&mt('Currently not available');
1110: $env{'course.'.$tcourseid.'.description'}=$twhere;
1111: }
1112: my $trole = &Apache::lonnet::plaintext('cc',$ttype);
1113: $twhere.="<br />".&mt('Domain').":".$1;
1114: $roletext = &build_roletext($trolecode,$1,$2,'is',$tryagain,$advanced,'',$tbg,$tfont,$trole,$twhere,'','','',1,'');
1115: }
1116: }
1117: return ($roletext);
1118: }
1119:
1120: sub allcourses_row {
1121: my ($dcdom,$rowtype) = @_;
1122: my $output = '<tr bgcolor="#77FF77">'.
1123: ' <td colspan="5">';
1124: my $selectlink = &courselink($dcdom,$rowtype);
1125: my $ccrole = &Apache::lonnet::plaintext('cc');
1126: $output.= '<span class="LC_rolesinfo">'.
1127: &mt('[_1]: [_2] from domain [_3]',$ccrole,$selectlink,$dcdom).
1128: '</span><br /></tr>'."\n";
1129: return $output;
1130: }
1131:
1132: sub allcoauthors_row {
1133: my ($dcdom,$rowtype) = @_;
1134: my $output = '<tr bgcolor="#77FF77">'.
1135: ' <td colspan="5">';
1136: my $carole = &Apache::lonnet::plaintext('ca');
1137: my $inputlink='<input type="text" size="10" name="adhoccauname'.$rowtype.'.'.$dcdom.'" />';
1138: my $gobutton='<input type="submit" name="adhocca./'.$dcdom.'" value="'.&mt('Go').'" />';
1139: $output.= '<span class="LC_rolesinfo">'.
1140: &mt('[_1]: [_2] in domain [_3] [_4]',$carole,$inputlink,$dcdom,$gobutton).
1141: '</span><br /></tr><tr><td colspan="5" height="3"></td></tr>'."\n";
1142: return $output;
1143: }
1144:
1145: sub recent_filename {
1146: my $area=shift;
1147: return 'nohist_recent_'.&escape($area);
1148: }
1149:
1150: sub set_privileges {
1151: # role can be cc or ca
1152: my ($dcdom,$pickedcourse,$role) = @_;
1153: my $area = '/'.$dcdom.'/'.$pickedcourse;
1154: my $spec = $role.'.'.$area;
1155: my %userroles = &Apache::lonnet::set_arearole($role,$area,'','',
1156: $env{'user.domain'},
1157: $env{'user.name'});
1158: my %ccrole = ();
1159: &Apache::lonnet::standard_roleprivs(\%ccrole,$role,$dcdom,$spec,$pickedcourse,$area);
1160: my ($author,$adv)= &Apache::lonnet::set_userprivs(\%userroles,\%ccrole);
1161: &Apache::lonnet::appenv(%userroles);
1162:
1163: &Apache::lonnet::log($env{'user.domain'},
1164: $env{'user.name'},
1165: $env{'user.home'},
1166: "Role ".$role);
1167: &Apache::lonnet::appenv(
1168: 'request.role' => $spec,
1169: 'request.role.domain' => $dcdom,
1170: 'request.course.sec' => '');
1171: my $tadv=0;
1172: if (&Apache::lonnet::allowed('adv') eq 'F') { $tadv=1; }
1173: &Apache::lonnet::appenv('request.role.adv' => $tadv);
1174: }
1175:
1176: sub courseloadpage {
1177: my ($courseid) = @_;
1178: my $startpage;
1179: my %entry_settings = &Apache::lonnet::get('nohist_whatsnew',
1180: [$courseid.':courseinit']);
1181: my ($tmp) = %entry_settings;
1182: unless ($tmp =~ /^error: 2 /) {
1183: $startpage = $entry_settings{$courseid.':courseinit'};
1184: }
1185: if ($startpage eq '') {
1186: if (exists($env{'environment.course_init_display'})) {
1187: $startpage = $env{'environment.course_init_display'};
1188: }
1189: }
1190: return $startpage;
1191: }
1192:
1193: 1;
1194: __END__
1195:
1196: =head1 NAME
1197:
1198: Apache::lonroles - User Roles Screen
1199:
1200: =head1 SYNOPSIS
1201:
1202: Invoked by /etc/httpd/conf/srm.conf:
1203:
1204: <Location /adm/roles>
1205: PerlAccessHandler Apache::lonacc
1206: SetHandler perl-script
1207: PerlHandler Apache::lonroles
1208: ErrorDocument 403 /adm/login
1209: ErrorDocument 500 /adm/errorhandler
1210: </Location>
1211:
1212: =head1 OVERVIEW
1213:
1214: =head2 Choosing Roles
1215:
1216: C<lonroles> is a handler that allows a user to switch roles in
1217: mid-session. LON-CAPA attempts to work with "No Role Specified", the
1218: default role that a user has before selecting a role, as widely as
1219: possible, but certain handlers for example need specification which
1220: course they should act on, etc. Both in this scenario, and when the
1221: handler determines via C<lonnet>'s C<&allowed> function that a certain
1222: action is not allowed, C<lonroles> is used as error handler. This
1223: allows the user to select another role which may have permission to do
1224: what they were trying to do. C<lonroles> can also be accessed via the
1225: B<CRS> button in the Remote Control.
1226:
1227: =begin latex
1228:
1229: \begin{figure}
1230: \begin{center}
1231: \includegraphics[width=0.45\paperwidth,keepaspectratio]{Sample_Roles_Screen}
1232: \caption{\label{Sample_Roles_Screen}Sample Roles Screen}
1233: \end{center}
1234: \end{figure}
1235:
1236: =end latex
1237:
1238: =head2 Role Initialization
1239:
1240: 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.
1241:
1242: =head1 INTRODUCTION
1243:
1244: This module enables a user to select what role he wishes to
1245: operate under (instructor, student, teaching assistant, course
1246: coordinator, etc). These roles are pre-established by the actions
1247: of upper-level users.
1248:
1249: This is part of the LearningOnline Network with CAPA project
1250: described at http://www.lon-capa.org.
1251:
1252: =head1 HANDLER SUBROUTINE
1253:
1254: This routine is called by Apache and mod_perl.
1255:
1256: =over 4
1257:
1258: =item *
1259:
1260: Roles Initialization (yes/no)
1261:
1262: =item *
1263:
1264: Get Error Message from Environment
1265:
1266: =item *
1267:
1268: Who is this?
1269:
1270: =item *
1271:
1272: Generate Page Output
1273:
1274: =item *
1275:
1276: Choice or no choice
1277:
1278: =item *
1279:
1280: Table
1281:
1282: =item *
1283:
1284: Privileges
1285:
1286: =back
1287:
1288: =cut
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>