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