File:
[LON-CAPA] /
loncom /
auth /
lonroles.pm
Revision
1.191:
download - view:
text,
annotated -
select for diffs
Wed May 14 23:52:52 2008 UTC (16 years, 3 months ago) by
raeburn
Branches:
MAIN
CVS tags:
HEAD
- If user has no active roles, now display any future roles, and a link to the course catalog.
- if automated enrollment is in use in the user's domain, display a message about reasons why enrollment might not have occurred so far.
- moved some code from handler() into subroutines - roletable_headers(), print_rolerows() and roletypes().
1: # The LearningOnline Network with CAPA
2: # User Roles Screen
3: #
4: # $Id: lonroles.pm,v 1.191 2008/05/14 23:52:52 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: '</font></span></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 .= &allcourses_row($1,'recent').
756: &allcoauthors_row($1,'recent');
757: }
758: } elsif ($numdc > 0) {
759: unless ($_ =~/^error\:/) {
760: $output.=&display_cc_role('user.role.'.$_);
761: }
762: }
763: }
764: if ($output) {
765: $r->print("<tr><td align='center' colspan='5'><font face='arial'>".
766: &mt('Recent Roles')."</font></td>");
767: $r->print($output);
768: $r->print("</tr>");
769: $doheaders ++;
770: }
771: }
772:
773: if ($numdc > 0) {
774: $r->print(&coursepick_jscript());
775: $r->print(&Apache::loncommon::coursebrowser_javascript());
776: }
777: &print_rolerows($r,$doheaders,\%roleclass,\%sortrole,\%dcroles,\%roletext);
778: my $tremark='';
779: my $tfont='#003300';
780: if ($env{'request.role'} eq 'cm') {
781: $r->print('<tr bgcolor="#11CC55">');
782: $tremark=&mt('Currently selected. ');
783: $tfont='#002200';
784: } else {
785: $r->print('<tr bgcolor="#77FF77">');
786: }
787: unless ($nochoose) {
788: if ($env{'request.role'} ne 'cm') {
789: $r->print('<td><input type="submit" value="'.
790: &mt('Select').'" name="cm"></td>');
791: } else {
792: $r->print('<td> </td>');
793: }
794: }
795: $r->print('<td colspan="3"><font color="'.$tfont.'"><span class="LC_rolesinfo">'.&mt('No role specified').
796: '</font></span></td><td><font color="'.$tfont.'">'.$tremark.
797: ' </font></td></tr>'."\n");
798:
799: $r->print('</table>');
800: unless ($nochoose) {
801: $r->print("</form>\n");
802: }
803: # ------------------------------------------------------------ Privileges Info
804: if (($advanced) && (($env{'user.error.msg'}) || ($error))) {
805: $r->print('<hr /><h2>Current Privileges</h2>');
806: $r->print(&privileges_info());
807: }
808: $r->print(&Apache::lonnet::getannounce());
809: if ($advanced) {
810: $r->print('<p><small><i>This is LON-CAPA '.
811: $r->dir_config('lonVersion').'</i><br />'.
812: '<a href="/adm/logout">'.&mt('Logout').'</a></small></p>');
813: }
814: $r->print(&Apache::loncommon::end_page());
815: return OK;
816: }
817:
818: sub roletable_headers {
819: my ($r,$roleclass,$sortrole,$nochoose) = @_;
820: my $doheaders;
821: if ((ref($sortrole) eq 'HASH') && (ref($roleclass) eq 'HASH')) {
822: $r->print('<br /><table id="LC_rolesmenu"><tr>');
823: if (!$nochoose) { $r->print('<th> </th>'); }
824: $r->print('<th>'.&mt('User Role').'</th><th>'.&mt('Extent')
825: .'</th><th>'.&mt('Start').'</th><th>'.&mt('End')
826: .'</th></tr>'."\n");
827: $doheaders=-1;
828: my @roletypes = &roletypes();
829: foreach my $type (@roletypes) {
830: my $haverole=0;
831: foreach my $which (sort {uc($a) cmp uc($b)} (keys(%{$sortrole}))) {
832: if ($roleclass->{$sortrole->{$which}} =~ /^\Q$type\E/) {
833: $haverole=1;
834: }
835: }
836: if ($haverole) { $doheaders++; }
837: }
838: }
839: return $doheaders;
840: }
841:
842: sub roletypes {
843: my @types = ('Domain','Construction Space','Course','Unavailable','System');
844: return @types;
845: }
846:
847: sub print_rolerows {
848: my ($r,$doheaders,$roleclass,$sortrole,$dcroles,$roletext) = @_;
849: if ((ref($roleclass) eq 'HASH') && (ref($sortrole) eq 'HASH')) {
850: my @types = &roletypes();
851: foreach my $type (@types) {
852: my $output;
853: foreach my $which (sort {uc($a) cmp uc($b)} (keys(%{$sortrole}))) {
854: if ($roleclass->{$sortrole->{$which}} =~ /^\Q$type\E/) {
855: if (ref($roletext) eq 'HASH') {
856: $output.=$roletext->{$sortrole->{$which}};
857: if ($sortrole->{$which} =~ m-dc\./($match_domain)/-) {
858: if (ref($dcroles) eq 'HASH') {
859: if ($dcroles->{$1}) {
860: $output .= &allcourses_row($1,'').
861: &allcoauthors_row($1,'');
862: }
863: }
864: }
865: }
866: }
867: }
868: if ($output) {
869: if ($doheaders > 0) {
870: $r->print("<tr>".
871: "<td align='center' colspan='5'><font face='arial'>".
872: &mt($type)."</font></td></tr>");
873: }
874: $r->print($output);
875: }
876: }
877: }
878: }
879:
880: sub findcourse_advice {
881: my ($r) = @_;
882: my $domdesc = &Apache::lonnet::domain($env{'user.domain'},'description');
883: if (&check_autoenroll($env{'user.domain'})) {
884: $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).'
885: <ul>
886: <li>'.&mt('The course has yet to be created.').'</li>
887: <li>'.&mt('Automatic enrollment of registered students has not been enabled for the course.').'</li>
888: <li>'.&mt('You are in a section of course for which automatic enrollment in the corresponding LON-CAPA course is not active.').'</li>
889: <li>'.&mt('The start date for automated enrollment has yet to be reached.').'</li>
890: <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>
891: </ul>');
892: } else {
893: $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 />');
894: }
895: $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 />');
896: $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>');
897: return;
898: }
899:
900: sub privileges_info {
901: my ($which) = @_;
902: my $output;
903:
904: $which ||= $env{'request.role'};
905:
906: foreach my $envkey (sort(keys(%env))) {
907: next if ($envkey!~/^user\.priv\.\Q$which\E\.(.*)/);
908:
909: my $where=$1;
910: my $ttype;
911: my $twhere;
912: my (undef,$tdom,$trest,$tsec)=split(m{/},$where);
913: if ($trest) {
914: if ($env{'course.'.$tdom.'_'.$trest.'.description'} eq 'ca') {
915: $ttype='Construction Space';
916: $twhere='User: '.$trest.', Domain: '.$tdom;
917: } else {
918: $ttype= &Apache::loncommon::course_type($tdom.'_'.$trest);
919: $twhere=$env{'course.'.$tdom.'_'.$trest.'.description'};
920: if ($tsec) {
921: my $sec_type = 'Section';
922: if (exists($env{"user.role.gr.$where"})) {
923: $sec_type = 'Group';
924: }
925: $twhere.=' ('.$sec_type.': '.$tsec.')';
926: }
927: }
928: } elsif ($tdom) {
929: $ttype='Domain';
930: $twhere=$tdom;
931: } else {
932: $ttype='System';
933: $twhere='/';
934: }
935: $output .= "\n<h3>".$ttype.': '.$twhere.'</h3>'."\n<ul>";
936: foreach my $priv (sort(split(/:/,$env{$envkey}))) {
937: next if (!$priv);
938:
939: my ($prv,$restr)=split(/\&/,$priv);
940: my $trestr='';
941: if ($restr ne 'F') {
942: $trestr.=' ('.
943: join(', ',
944: map { &Apache::lonnet::plaintext($_) }
945: (split('',$restr))).') ';
946: }
947: $output .= "\n\t".
948: '<li>'.&Apache::lonnet::plaintext($prv).$trestr.'</li>';
949: }
950: $output .= "\n".'</ul>';
951: }
952: return $output;
953: }
954:
955: sub role_status {
956: my ($rolekey,$then,$now,$role,$where,$trolecode,$tstatus,$tstart,$tend) = @_;
957: my @pwhere = ();
958: if (exists($env{$rolekey}) && $env{$rolekey} ne '') {
959: (undef,undef,$$role,@pwhere)=split(/\./,$rolekey);
960: unless (!defined($$role) || $$role eq '') {
961: $$where=join('.',@pwhere);
962: $$trolecode=$$role.'.'.$$where;
963: ($$tstart,$$tend)=split(/\./,$env{$rolekey});
964: $$tstatus='is';
965: if ($$tstart && $$tstart>$then) {
966: $$tstatus='future';
967: if ($$tstart<$now) { $$tstatus='will'; }
968: }
969: if ($$tend) {
970: if ($$tend<$then) {
971: $$tstatus='expired';
972: } elsif ($$tend<$now) {
973: $$tstatus='will_not';
974: }
975: }
976: }
977: }
978: }
979:
980: sub build_roletext {
981: my ($trolecode,$tdom,$trest,$tstatus,$tryagain,$advanced,$tremark,$tbg,$tfont,$trole,$twhere,$tpstart,$tpend,$nochoose,$button,$switchserver) = @_;
982: my $roletext='<tr bgcolor="'.$tbg.'" class="LC_rolesmenu_'.$tstatus.'">';
983: my $is_dc=($trolecode =~ m/^dc\./);
984: my $rowspan=($is_dc) ? ''
985: : ' rowspan="2" ';
986:
987: unless ($nochoose) {
988: my $buttonname=$trolecode;
989: $buttonname=~s/\W//g;
990: if (!$button) {
991: if ($switchserver) {
992: $roletext.='<td'.$rowspan.'><span class="LC_rolesinfo"><a href="/adm/switchserver?'.
993: $switchserver.'">'.&mt('Switch Server').'</a></span></td>';
994: } else {
995: $roletext.=('<td'.$rowspan.'> </td>');
996: }
997: } elsif ($tstatus eq 'is') {
998: $roletext.='<td'.$rowspan.'><input name="'.$buttonname.'" type="button" value="'.
999: &mt('Select').'" onClick="javascript:enterrole(this.form,\''.
1000: $trolecode."','".$buttonname.'\');"></td>';
1001: } elsif ($tryagain) {
1002: $roletext.=
1003: '<td'.$rowspan.'><input name="'.$buttonname.'" type="button" value="'.
1004: &mt('Try Selecting Again').'" onClick="javascript:enterrole(this.form,\''.
1005: $trolecode."','".$buttonname.'\');"></td>';
1006: } elsif ($advanced) {
1007: $roletext.=
1008: '<td'.$rowspan.'><input name="'.$buttonname.'" type="button" value="'.
1009: &mt('Re-Initialize').'" onClick="javascript:enterrole(this.form,\''.
1010: $trolecode."','".$buttonname.'\');"></td>';
1011: } else {
1012: $roletext.='<td'.$rowspan.'> </td>';
1013: }
1014: }
1015: if ($trolecode !~ m/^(dc|ca|au|aa)\./) {
1016: $tremark.=&Apache::lonannounce::showday(time,1,
1017: &Apache::lonannounce::readcalendar($tdom.'_'.$trest));
1018: }
1019: $roletext.='<td><font color="'.$tfont.'">'.$trole.
1020: '</font></td><td><font color="'.$tfont.'">'.$twhere.
1021: '</font></td><td><font color="'.$tfont.'">'.$tpstart.
1022: '</font></td><td><font color="'.$tfont.'">'.$tpend.
1023: '</font></td></tr>';
1024: if (!$is_dc) {
1025: $roletext.='<tr bgcolor="'.$tbg.'"><td colspan="4"><font color="'.$tfont.'"><span class="LC_rolesinfo">'.$tremark.
1026: '</span> </font></td></tr><tr><td colspan="5" height="3"></td></tr>'."\n";
1027: }
1028: return $roletext;
1029: }
1030:
1031: sub is_author_homeserver {
1032: my ($uname,$udom)=@_;
1033: my $home = &Apache::lonnet::homeserver($uname,$udom);
1034: my @ids=&Apache::lonnet::current_machine_ids();
1035: foreach my $id (@ids) {
1036: if ($id eq $home) {
1037: if (-e "/home/".$uname."/public_html") {
1038: return 1;
1039: }
1040: }
1041: }
1042: return 0;
1043: }
1044:
1045: sub check_privs {
1046: my ($cdom,$cnum,$then,$now,$checkrole) = @_;
1047: my $cckey = 'user.role.'.$checkrole.'./'.$cdom.'/'.$cnum;
1048: if ($env{$cckey}) {
1049: my ($role,$where,$trolecode,$tstart,$tend,$tremark,$tstatus,$tpstart,$tpend,$tfont);
1050: &role_status($cckey,$then,$now,\$role,\$where,\$trolecode,\$tstatus,\$tstart,\$tend);
1051: unless (($tstatus eq 'is') || ($tstatus eq 'will_not')) {
1052: &set_privileges($cdom,$cnum,$checkrole);
1053: }
1054: } else {
1055: &set_privileges($cdom,$cnum,$checkrole);
1056: }
1057: }
1058:
1059: sub check_fordc {
1060: my ($dcroles,$then) = @_;
1061: my $numdc = 0;
1062: if ($env{'user.adv'}) {
1063: foreach my $envkey (sort keys %env) {
1064: if ($envkey=~/^user\.role\.dc\.\/($match_domain)\/$/) {
1065: my $dcdom = $1;
1066: my $livedc = 1;
1067: my ($tstart,$tend)=split(/\./,$env{$envkey});
1068: if ($tstart && $tstart>$then) { $livedc = 0; }
1069: if ($tend && $tend <$then) { $livedc = 0; }
1070: if ($livedc) {
1071: $$dcroles{$dcdom} = $envkey;
1072: $numdc++;
1073: }
1074: }
1075: }
1076: }
1077: return $numdc;
1078: }
1079:
1080: sub adhoc_course_role {
1081: my ($then) = @_;
1082: my ($cdom,$cnum);
1083: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
1084: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1085: if (&check_forcc($cdom,$cnum,$then)) {
1086: my $setprivs;
1087: if (!defined($env{'user.role.'.$env{'form.selectrole'}})) {
1088: $setprivs = 1;
1089: } else {
1090: my ($start,$end) = split(/\./,$env{'user.role.'.$env{'form.selectrole'}});
1091: if (($start && ($start>$then || $start == -1)) ||
1092: ($end && $end<$then)) {
1093: $setprivs = 1;
1094: }
1095: }
1096: if ($setprivs) {
1097: if ($env{'form.switchrole'} =~ m-^(in|ta|ep|ad|st|cr)([\w/]*)\./\Q$cdom\E/\Q$cnum\E(/?\w*)$-) {
1098: my $role = $1;
1099: my $custom_role = $2;
1100: my $usec = $3;
1101: if ($role eq 'cr') {
1102: if ($custom_role =~ m-^$match_domain/$match_courseid/\w+$-) {
1103: $role .= $custom_role;
1104: } else {
1105: return;
1106: }
1107: }
1108: my (%userroles,%newrole,%newgroups);
1109: my $area = '/'.$cdom.'/'.$cnum;
1110: my $spec = $role.'.'.$area;
1111: if ($usec ne '') {
1112: $spec .= '/'.$usec;
1113: $area .= '/'.$usec;
1114: }
1115: &Apache::lonnet::standard_roleprivs(\%newrole,$role,$cdom,$spec,$cnum,$area);
1116: &Apache::lonnet::set_userprivs(\%userroles,\%newrole,%newgroups);
1117: my $adhocstart = $then-1;
1118: $userroles{'user.role.'.$spec} = $adhocstart.'.';
1119: &Apache::lonnet::appenv(\%userroles,[$role,'cm']);
1120: }
1121: }
1122: }
1123: return;
1124: }
1125:
1126: sub check_forcc {
1127: my ($cdom,$cnum,$then) = @_;
1128: my $is_cc;
1129: if ($cdom ne '' && $cnum ne '') {
1130: if (&Apache::lonnet::is_course($cdom,$cnum)) {
1131: my $envkey = 'user.role.cc./'.$cdom.'/'.$cnum;
1132: if (defined($env{$envkey})) {
1133: $is_cc = 1;
1134: my ($tstart,$tend)=split(/\./,$env{$envkey});
1135: if ($tstart && $tstart>$then) { $is_cc = 0; }
1136: if ($tend && $tend <$then) { $is_cc = 0; }
1137: }
1138: }
1139: }
1140: return $is_cc;
1141: }
1142:
1143: sub courselink {
1144: my ($dcdom,$rowtype,$selecttype) = @_;
1145: my $courseform=&Apache::loncommon::selectcourse_link
1146: ('rolechoice','dccourse'.$rowtype.'_'.$dcdom,
1147: 'dcdomain'.$rowtype.'_'.$dcdom,'coursedesc'.$rowtype.'_'.
1148: $dcdom,$dcdom,undef);
1149: my $hiddenitems = '<input type="hidden" name="dcdomain'.$rowtype.'_'.$dcdom.'" value="'.$dcdom.'" />'.
1150: '<input type="hidden" name="origdom'.$rowtype.'_'.$dcdom.'" value="'.$dcdom.'" />'.
1151: '<input type="hidden" name="dccourse'.$rowtype.'_'.$dcdom.'" value="" />'.
1152: '<input type="hidden" name="coursedesc'.$rowtype.'_'.$dcdom.'" value="" />';
1153: return $courseform.$hiddenitems;
1154: }
1155:
1156: sub coursepick_jscript {
1157: my %lt = &Apache::lonlocal::texthash(
1158: plsu => "Please use the 'Select Course' link to open a separate pick course window where you may select the course you wish to enter.",
1159: youc => 'You can only use this screen to select courses in the current domain.',
1160: );
1161: my $verify_script = <<"END";
1162: <script type="text/javascript">
1163: function verifyCoursePick(caller) {
1164: var numbutton = getIndex(caller)
1165: var pickedCourse = document.rolechoice.elements[numbutton+4].value
1166: var pickedDomain = document.rolechoice.elements[numbutton+2].value
1167: if (document.rolechoice.elements[numbutton+2].value == document.rolechoice.elements[numbutton+3].value) {
1168: if (pickedCourse != '') {
1169: if (numbutton != -1) {
1170: var courseTarget = "cc./"+pickedDomain+"/"+pickedCourse
1171: document.rolechoice.elements[numbutton+1].name = courseTarget
1172: document.rolechoice.submit()
1173: }
1174: }
1175: else {
1176: alert("$lt{'plsu'}");
1177: }
1178: }
1179: else {
1180: alert("$lt{'youc'}")
1181: }
1182: }
1183: function getIndex(caller) {
1184: for (var i=0;i<document.rolechoice.elements.length;i++) {
1185: if (document.rolechoice.elements[i] == caller) {
1186: return i;
1187: }
1188: }
1189: return -1;
1190: }
1191: </script>
1192: END
1193: return $verify_script;
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 allcourses_row {
1229: my ($dcdom,$rowtype) = @_;
1230: my $output = '<tr bgcolor="#77FF77">'.
1231: ' <td colspan="5">';
1232: my $selectlink = &courselink($dcdom,$rowtype);
1233: my $ccrole = &Apache::lonnet::plaintext('cc');
1234: $output.= '<span class="LC_rolesinfo">'.
1235: &mt('[_1]: [_2] from domain [_3]',$ccrole,$selectlink,$dcdom).
1236: '</span><br /></tr>'."\n";
1237: return $output;
1238: }
1239:
1240: sub allcoauthors_row {
1241: my ($dcdom,$rowtype) = @_;
1242: my $output = '<tr bgcolor="#77FF77">'.
1243: ' <td colspan="5">';
1244: my $carole = &Apache::lonnet::plaintext('ca');
1245: my $inputlink='<input type="text" size="10" name="adhoccauname'.$rowtype.'.'.$dcdom.'" />';
1246: my $gobutton='<input type="submit" name="adhocca./'.$dcdom.'" value="'.&mt('Go').'" />';
1247: $output.= '<span class="LC_rolesinfo">'.
1248: &mt('[_1]: [_2] in domain [_3] [_4]',$carole,$inputlink,$dcdom,$gobutton).
1249: '</span><br /></tr><tr><td colspan="5" height="3"></td></tr>'."\n";
1250: return $output;
1251: }
1252:
1253: sub recent_filename {
1254: my $area=shift;
1255: return 'nohist_recent_'.&escape($area);
1256: }
1257:
1258: sub set_privileges {
1259: # role can be cc or ca
1260: my ($dcdom,$pickedcourse,$role) = @_;
1261: my $area = '/'.$dcdom.'/'.$pickedcourse;
1262: my $spec = $role.'.'.$area;
1263: my %userroles = &Apache::lonnet::set_arearole($role,$area,'','',
1264: $env{'user.domain'},
1265: $env{'user.name'});
1266: my %ccrole = ();
1267: &Apache::lonnet::standard_roleprivs(\%ccrole,$role,$dcdom,$spec,$pickedcourse,$area);
1268: my ($author,$adv)= &Apache::lonnet::set_userprivs(\%userroles,\%ccrole);
1269: &Apache::lonnet::appenv(\%userroles,[$role,'cm']);
1270:
1271: &Apache::lonnet::log($env{'user.domain'},
1272: $env{'user.name'},
1273: $env{'user.home'},
1274: "Role ".$role);
1275: &Apache::lonnet::appenv(
1276: {'request.role' => $spec,
1277: 'request.role.domain' => $dcdom,
1278: 'request.course.sec' => ''});
1279: my $tadv=0;
1280: if (&Apache::lonnet::allowed('adv') eq 'F') { $tadv=1; }
1281: &Apache::lonnet::appenv({'request.role.adv' => $tadv});
1282: }
1283:
1284: sub courseloadpage {
1285: my ($courseid) = @_;
1286: my $startpage;
1287: my %entry_settings = &Apache::lonnet::get('nohist_whatsnew',
1288: [$courseid.':courseinit']);
1289: my ($tmp) = %entry_settings;
1290: unless ($tmp =~ /^error: 2 /) {
1291: $startpage = $entry_settings{$courseid.':courseinit'};
1292: }
1293: if ($startpage eq '') {
1294: if (exists($env{'environment.course_init_display'})) {
1295: $startpage = $env{'environment.course_init_display'};
1296: }
1297: }
1298: return $startpage;
1299: }
1300:
1301: sub check_autoenroll {
1302: my ($dom) = @_;
1303: my $run_enroll = 0;
1304: my $settings;
1305: my %domconfig =
1306: &Apache::lonnet::get_dom('configuration',['autoenroll'],$dom);
1307: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
1308: $settings = $domconfig{'autoenroll'};
1309: if ($settings->{'run'} eq '1') {
1310: $run_enroll = 1;
1311: }
1312: } else {
1313: $run_enroll = &localenroll::run($dom);
1314: }
1315: return $run_enroll;
1316: }
1317:
1318:
1319: 1;
1320: __END__
1321:
1322: =head1 NAME
1323:
1324: Apache::lonroles - User Roles Screen
1325:
1326: =head1 SYNOPSIS
1327:
1328: Invoked by /etc/httpd/conf/srm.conf:
1329:
1330: <Location /adm/roles>
1331: PerlAccessHandler Apache::lonacc
1332: SetHandler perl-script
1333: PerlHandler Apache::lonroles
1334: ErrorDocument 403 /adm/login
1335: ErrorDocument 500 /adm/errorhandler
1336: </Location>
1337:
1338: =head1 OVERVIEW
1339:
1340: =head2 Choosing Roles
1341:
1342: C<lonroles> is a handler that allows a user to switch roles in
1343: mid-session. LON-CAPA attempts to work with "No Role Specified", the
1344: default role that a user has before selecting a role, as widely as
1345: possible, but certain handlers for example need specification which
1346: course they should act on, etc. Both in this scenario, and when the
1347: handler determines via C<lonnet>'s C<&allowed> function that a certain
1348: action is not allowed, C<lonroles> is used as error handler. This
1349: allows the user to select another role which may have permission to do
1350: what they were trying to do. C<lonroles> can also be accessed via the
1351: B<CRS> button in the Remote Control.
1352:
1353: =begin latex
1354:
1355: \begin{figure}
1356: \begin{center}
1357: \includegraphics[width=0.45\paperwidth,keepaspectratio]{Sample_Roles_Screen}
1358: \caption{\label{Sample_Roles_Screen}Sample Roles Screen}
1359: \end{center}
1360: \end{figure}
1361:
1362: =end latex
1363:
1364: =head2 Role Initialization
1365:
1366: 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.
1367:
1368: =head1 INTRODUCTION
1369:
1370: This module enables a user to select what role he wishes to
1371: operate under (instructor, student, teaching assistant, course
1372: coordinator, etc). These roles are pre-established by the actions
1373: of upper-level users.
1374:
1375: This is part of the LearningOnline Network with CAPA project
1376: described at http://www.lon-capa.org.
1377:
1378: =head1 HANDLER SUBROUTINE
1379:
1380: This routine is called by Apache and mod_perl.
1381:
1382: =over 4
1383:
1384: =item *
1385:
1386: Roles Initialization (yes/no)
1387:
1388: =item *
1389:
1390: Get Error Message from Environment
1391:
1392: =item *
1393:
1394: Who is this?
1395:
1396: =item *
1397:
1398: Generate Page Output
1399:
1400: =item *
1401:
1402: Choice or no choice
1403:
1404: =item *
1405:
1406: Table
1407:
1408: =item *
1409:
1410: Privileges
1411:
1412: =back
1413:
1414: =cut
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>