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