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