Annotation of loncom/auth/lonroles.pm, revision 1.164
1.1 harris41 1: # The LearningOnline Network with CAPA
2: # User Roles Screen
1.31 www 3: #
1.164 ! albertel 4: # $Id: lonroles.pm,v 1.163 2006/07/14 17:05:02 www 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.
1.156 albertel 91: '</p><br /><a href="'.$dest.'">'.&mt('Continue').'</a>'.
1.150 www 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.158 albertel 152: my %frozen_roles =
153: &Apache::lonhtmlcommon::get_recent_frozen('roles',$env{'environment.recentrolesn'});
1.111 albertel 154: &Apache::lonhtmlcommon::store_recent('roles',
1.158 albertel 155: $trolecode,' ',$frozen_roles{$trolecode});
1.111 albertel 156: }
157:
158:
1.53 www 159: # check for keyed access
1.55 albertel 160: if (($role eq 'st') &&
1.118 albertel 161: ($env{'course.'.$cdom.'_'.$cnum.'.keyaccess'} eq 'yes')) {
1.89 www 162: # who is key authority?
163: my $authdom=$cdom;
164: my $authnum=$cnum;
1.118 albertel 165: if ($env{'course.'.$cdom.'_'.$cnum.'.keyauth'}) {
1.89 www 166: ($authnum,$authdom)=
1.118 albertel 167: split(/\W/,$env{'course.'.$cdom.'_'.$cnum.'.keyauth'});
1.89 www 168: }
169: # check with key authority
170: unless (&Apache::lonnet::validate_access_key(
1.118 albertel 171: $env{'environment.key.'.$cdom.'_'.$cnum},
1.89 www 172: $authdom,$authnum)) {
1.53 www 173: # there is no valid key
1.118 albertel 174: if ($env{'form.newkey'}) {
1.53 www 175: # student attempts to register a new key
1.89 www 176: &Apache::loncommon::content_type($r,'text/html');
177: &Apache::loncommon::no_cache($r);
178: $r->send_http_header;
179: my $swinfo=&Apache::lonmenu::rawconfig();
1.147 albertel 180: my $start_page=&Apache::loncommon::start_page
1.89 www 181: ('Verifying Access Key to Unlock this Course');
1.147 albertel 182: my $end_page=&Apache::loncommon::end_page();
1.90 www 183: my $buttontext=&mt('Enter Course');
184: my $message=&mt('Successfully registered key');
185: my $assignresult=
186: &Apache::lonnet::assign_access_key(
1.118 albertel 187: $env{'form.newkey'},
1.90 www 188: $authdom,$authnum,
1.91 www 189: $cdom,$cnum,
1.118 albertel 190: $env{'user.domain'},
191: $env{'user.name'},
1.90 www 192: 'Assigned from '.$ENV{'REMOTE_ADDR'}.' at '.localtime().' for '.
193: $trolecode);
194: unless ($assignresult eq 'ok') {
195: $assignresult=~s/^error\:\s*//;
196: $message=&mt($assignresult).
197: '<br /><a href="/adm/logout">'.
1.89 www 198: &mt('Logout').'</a>';
1.90 www 199: $buttontext=&mt('Re-Enter Key');
200: }
1.89 www 201: $r->print(<<ENDENTEREDKEY);
1.147 albertel 202: $start_page
1.89 www 203: <script>
204: $swinfo
205: </script>
206: <form method="post">
207: <input type="hidden" name="selectrole" value="1" />
208: <input type="hidden" name="$trolecode" value="1" />
1.90 www 209: <font size="+2">$message</font><br />
1.89 www 210: <input type="submit" value="$buttontext" />
211: </form>
1.147 albertel 212: $end_page
1.89 www 213: ENDENTEREDKEY
214: return OK;
1.55 albertel 215: } else {
1.53 www 216: # print form to enter a new key
1.73 www 217: &Apache::loncommon::content_type($r,'text/html');
1.55 albertel 218: &Apache::loncommon::no_cache($r);
219: $r->send_http_header;
220: my $swinfo=&Apache::lonmenu::rawconfig();
1.147 albertel 221: my $start_page=&Apache::loncommon::start_page
1.55 albertel 222: ('Enter Access Key to Unlock this Course');
1.147 albertel 223: my $end_page=&Apache::loncommon::end_page();
1.55 albertel 224: $r->print(<<ENDENTERKEY);
1.147 albertel 225: $start_page
1.53 www 226: <script>
227: $swinfo
228: </script>
229: <form method="post">
1.89 www 230: <input type="hidden" name="selectrole" value="1" />
231: <input type="hidden" name="$trolecode" value="1" />
1.118 albertel 232: <input type="text" size="20" name="newkey" value="$env{'form.newkey'}" />
1.53 www 233: <input type="submit" value="Enter key" />
234: </form>
1.147 albertel 235: $end_page
1.53 www 236: ENDENTERKEY
1.55 albertel 237: return OK;
238: }
239: }
240: }
1.118 albertel 241: &Apache::lonnet::log($env{'user.domain'},
242: $env{'user.name'},
243: $env{'user.home'},
1.87 www 244: "Role ".$trolecode);
1.101 albertel 245:
1.56 www 246: &Apache::lonnet::appenv(
1.101 albertel 247: 'request.role' => $trolecode,
1.56 www 248: 'request.role.domain' => $cdom,
1.137 raeburn 249: 'request.course.sec' => $csec,
250: 'request.course.groups' => $cgrps);
1.101 albertel 251: my $tadv=0;
1.62 matthew 252:
1.125 www 253: if (($cnum) && ($role ne 'ca') && ($role ne 'aa')) {
1.152 raeburn 254: my $msg;
1.55 albertel 255: my ($furl,$ferr)=
256: &Apache::lonuserstate::readmap($cdom.'/'.$cnum);
1.118 albertel 257: if (($env{'form.orgurl'}) &&
258: ($env{'form.orgurl'}!~/^\/adm\/flip/)) {
259: my $dest=$env{'form.orgurl'};
1.117 albertel 260: if (&Apache::lonnet::allowed('adv') eq 'F') { $tadv=1; }
261: &Apache::lonnet::appenv('request.role.adv'=>$tadv);
1.150 www 262: if (($ferr) && ($tadv)) {
263: &error_page($r,$ferr,$dest);
264: } else {
265: $r->internal_redirect($dest);
266: }
1.55 albertel 267: return OK;
268: } else {
1.155 albertel 269: if (!$env{'request.course.id'}) {
1.55 albertel 270: &Apache::lonnet::appenv(
271: "request.course.id" => $cdom.'_'.$cnum);
1.61 www 272: $furl='/adm/roles?tryagain=1';
1.55 albertel 273: $msg=
1.157 albertel 274: '<h1><span class="LC_error">'.
1.162 albertel 275: &mt('Could not initialize [_1] at this time.',
276: $env{'course.'.$cdom.'_'.$cnum.'.description'}).
1.157 albertel 277: '</span></h1><h3>'.&mt('Please try again.').'</h3>'.$ferr;
1.55 albertel 278: }
1.117 albertel 279: if (&Apache::lonnet::allowed('adv') eq 'F') { $tadv=1; }
280: &Apache::lonnet::appenv('request.role.adv'=>$tadv);
1.152 raeburn 281:
1.150 www 282: if (($ferr) && ($tadv)) {
283: &error_page($r,$ferr,$furl);
284: } else {
285: # Check to see if the user is a CC entering a course
286: # for the first time
287: my (undef, undef, $role, $courseid) = split(/\./, $envkey);
288: if (substr($courseid, 0, 1) eq '/') {
289: $courseid = substr($courseid, 1);
290: }
291: $courseid =~ s/\//_/;
292: if ($role eq 'cc' && $env{'course.' . $courseid .
293: '.course.helper.not.run'}) {
294: $furl = "/adm/helper/course.initialization.helper";
295: # Send the user to the course they selected
296: } elsif ($env{'request.course.id'}) {
297: if (&Apache::lonnet::allowed('whn',
298: $env{'request.course.id'})
299: || &Apache::lonnet::allowed('whn',
300: $env{'request.course.id'}.'/'
301: .$env{'request.course.sec'})
302: ) {
303: my $startpage = &courseloadpage($courseid);
304: unless ($startpage eq 'firstres') {
1.162 albertel 305: $msg = &mt('Entering [_1] ....',
306: $env{'course.'.$courseid.'.description'});
1.150 www 307: &redirect_user($r,&mt('New in course'),
308: '/adm/whatsnew?refpage=start',$msg,
309: $env{'environment.remotenavmap'});
310: return OK;
311: }
312: }
313: }
1.151 www 314: # Are we allowed to look at the first resource?
315: if (!&Apache::lonnet::allowed('bre',$furl)) {
316: # Guess not ...
317: $furl=&Apache::lonpageflip::first_accessible_resource();
318: }
1.162 albertel 319: $msg = &mt('Entering [_1] ...',
320: $env{'course.'.$courseid.'.description'});
321: &redirect_user($r,&mt('Entering [_1]',
322: $env{'course.'.$courseid.'.description'}),
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.163 www 367:
1.10 www 368: $r->print(<<ENDHEADER);
1.147 albertel 369: $start_page
1.163 www 370: <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.157 albertel 427: '<h3><span class="LC_error">'.
428: &mt('You need to choose another user role or enter a specific course for this function').'</span></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.164 ! albertel 488: if (($tstatus eq 'is')
! 489: || ($tstatus eq 'selected')
! 490: || ($tstatus eq 'will')
! 491: || ($tstatus eq 'future')
! 492: || ($env{'form.showall'})) {
1.35 matthew 493: if ($tstatus eq 'is') {
494: $tbg='#77FF77';
1.47 www 495: $tfont='#003300';
1.84 www 496: $possiblerole=$trolecode;
497: $countactive++;
1.35 matthew 498: } elsif ($tstatus eq 'future') {
499: $tbg='#FFFF77';
1.49 www 500: $button=0;
1.35 matthew 501: } elsif ($tstatus eq 'will') {
502: $tbg='#FFAA77';
1.72 www 503: $tremark.=&mt('Active at next login. ');
1.35 matthew 504: } elsif ($tstatus eq 'expired') {
505: $tbg='#FF7777';
1.47 www 506: $tfont='#330000';
1.49 www 507: $button=0;
1.35 matthew 508: } elsif ($tstatus eq 'will_not') {
509: $tbg='#AAFF77';
1.72 www 510: $tremark.=&mt('Expired after logout. ');
1.35 matthew 511: } elsif ($tstatus eq 'selected') {
512: $tbg='#11CC55';
1.47 www 513: $tfont='#002200';
1.84 www 514: $inrole=1;
1.86 albertel 515: $countactive++;
1.72 www 516: $tremark.=&mt('Currently selected. ');
1.35 matthew 517: }
518: my $trole;
519: if ($role =~ /^cr\//) {
520: my ($rdummy,$rdomain,$rauthor,$rrole)=split(/\//,$role);
1.132 albertel 521: if ($tremark) { $tremark.='<br />'; }
522: $tremark.=&mt('Defined by ').$rauthor.
1.72 www 523: &mt(' at ').$rdomain.'.';
1.159 albertel 524: }
525: $trole=Apache::lonnet::plaintext($role);
1.35 matthew 526: my $ttype;
527: my $twhere;
528: my ($tdom,$trest,$tsection)=
529: split(/\//,Apache::lonnet::declutter($where));
530: # First, Co-Authorship roles
1.125 www 531: if (($role eq 'ca') || ($role eq 'aa')) {
1.39 stredwic 532: my $home = &Apache::lonnet::homeserver($trest,$tdom);
1.83 albertel 533: my $allowed=0;
534: my @ids=&Apache::lonnet::current_machine_ids();
535: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
536: if (!$allowed) {
1.49 www 537: $button=0;
1.130 albertel 538: $switchserver='otherserver='.$home.'&role='.$trolecode;
1.49 www 539: }
1.35 matthew 540: #next if ($home eq 'no_host');
541: $home = $Apache::lonnet::hostname{$home};
1.78 sakharuk 542: $ttype='Construction Space';
1.72 www 543: $twhere=&mt('User').': '.$trest.'<br />'.&mt('Domain').
544: ': '.$tdom.'<br />'.
545: ' '.&mt('Server').': '.$home;
1.118 albertel 546: $env{'course.'.$tdom.'_'.$trest.'.description'}='ca';
1.82 www 547: $tremark.=&Apache::lonhtmlcommon::authorbombs('/res/'.$tdom.'/'.$trest.'/');
1.75 albertel 548: $sortkey=$role."$trest:$tdom";
1.35 matthew 549: } elsif ($role eq 'au') {
550: # Authors
551: my $home = &Apache::lonnet::homeserver
1.118 albertel 552: ($env{'user.name'},$env{'user.domain'});
1.83 albertel 553: my $allowed=0;
554: my @ids=&Apache::lonnet::current_machine_ids();
555: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
556: if (!$allowed) {
1.49 www 557: $button=0;
1.143 albertel 558: $switchserver='otherserver='.$home.'&role='.$trolecode;
1.49 www 559: }
1.35 matthew 560: #next if ($home eq 'no_host');
561: $home = $Apache::lonnet::hostname{$home};
1.78 sakharuk 562: $ttype='Construction Space';
1.72 www 563: $twhere=&mt('Domain').': '.$tdom.'<br />'.&mt('Server').
564: ': '.$home;
1.118 albertel 565: $env{'course.'.$tdom.'_'.$trest.'.description'}='ca';
566: $tremark.=&Apache::lonhtmlcommon::authorbombs('/res/'.$tdom.'/'.$env{'user.name'}.'/');
1.75 albertel 567: $sortkey=$role;
1.35 matthew 568: } elsif ($trest) {
569: my $tcourseid=$tdom.'_'.$trest;
1.153 raeburn 570: $ttype = &Apache::loncommon::course_type($tcourseid);
571: $trole = &Apache::lonnet::plaintext($role,$ttype);
1.118 albertel 572: if ($env{'course.'.$tcourseid.'.description'}) {
573: $twhere=$env{'course.'.$tcourseid.'.description'};
1.80 albertel 574: $sortkey=$role."\0".$tdom."\0".$twhere."\0".$envkey;
1.72 www 575: unless ($twhere eq &mt('Currently not available')) {
1.55 albertel 576: $twhere.=' <font size="-2">'.
1.72 www 577: &Apache::loncommon::syllabuswrapper(&mt('Syllabus'),$trest,$tdom,$tfont).
1.49 www 578: '</font>';
1.55 albertel 579: }
1.8 www 580: } else {
1.105 raeburn 581: my %newhash=&Apache::lonnet::coursedescription($tcourseid);
1.35 matthew 582: if (%newhash) {
1.80 albertel 583: $sortkey=$role."\0".$tdom."\0".$newhash{'description'}.
1.77 albertel 584: "\0".$envkey;
1.49 www 585: $twhere=$newhash{'description'}.
586: ' <font size="-2">'.
1.72 www 587: &Apache::loncommon::syllabuswrapper(&mt('Syllabus'),$trest,$tdom,$tfont).
1.49 www 588: '</font>';
1.152 raeburn 589: $ttype = $newhash{'type'};
1.153 raeburn 590: $trole = &Apache::lonnet::plaintext($role,$ttype);
1.35 matthew 591: } else {
1.72 www 592: $twhere=&mt('Currently not available');
1.118 albertel 593: $env{'course.'.$tcourseid.'.description'}=$twhere;
1.80 albertel 594: $sortkey=$role."\0".$tdom."\0".$twhere."\0".$envkey;
1.152 raeburn 595: $ttype = 'Unavailable';
1.35 matthew 596: }
1.8 www 597: }
1.121 albertel 598: if ($tsection) {
599: $twhere.='<br />'.&mt('Section/Group').': '.$tsection;
600: }
1.72 www 601: if ($role ne 'st') { $twhere.="<br />".&mt('Domain').":".$tdom; }
1.35 matthew 602: } elsif ($tdom) {
1.78 sakharuk 603: $ttype='Domain';
1.35 matthew 604: $twhere=$tdom;
1.75 albertel 605: $sortkey=$role.$twhere;
1.35 matthew 606: } else {
1.78 sakharuk 607: $ttype='System';
1.72 www 608: $twhere=&mt('system wide');
1.75 albertel 609: $sortkey=$role.$twhere;
1.13 www 610: }
1.152 raeburn 611: $roletext.=&build_roletext($trolecode,$tdom,$trest,$tstatus,$tryagain,$advanced,$tremark,$tbg,$tfont,$trole,$twhere,$tpstart,$tpend,$nochoose,$button,$switchserver);
1.75 albertel 612: $roletext{$envkey}=$roletext;
613: if (!$sortkey) {$sortkey=$twhere."\0".$envkey;}
614: $sortrole{$sortkey}=$envkey;
615: $roleclass{$envkey}=$ttype;
1.55 albertel 616: }
1.4 www 617: }
1.75 albertel 618: }
1.84 www 619: # No active roles
620: if ($countactive==0) {
621: if ($inrole) {
622: $r->print('<h2>'.&mt('Currently no additional roles or courses').'</h2>');
623: } else {
624: $r->print('<h2>'.&mt('Currently no active roles or courses').'</h2>');
625: }
1.147 albertel 626: $r->print('</form>'.&Apache::loncommon::end_page());
1.84 www 627: return OK;
628: # Is there only one choice?
1.118 albertel 629: } elsif (($countactive==1) && ($env{'request.role'} eq 'cm')) {
1.84 www 630: $r->print('<h3>'.&mt('Please stand by.').'</h3>'.
631: '<input type="hidden" name="'.$possiblerole.'" value="1" />');
632: $r->print("</form>\n");
633: $r->rflush();
634: $r->print('<script>document.forms.rolechoice.submit();</script>');
1.147 albertel 635: $r->print(&Apache::loncommon::end_page());
1.84 www 636: return OK;
637: }
638: # More than one possible role
639: # ----------------------------------------------------------------------- Table
640: unless (($advanced) || ($nochoose)) {
1.152 raeburn 641: $r->print("<h2>".&mt('Select a Course/Group to Enter')."</h2>\n");
1.84 www 642: }
643: $r->print('<br /><table><tr>');
644: unless ($nochoose) { $r->print('<th> </th>'); }
1.121 albertel 645: $r->print('<th>'.&mt('User Role').'</th><th>'.&mt('Extent').
1.132 albertel 646: '</th><th>'.&mt('Start').'</th><th>'.&mt('End').'</th></tr>'."\n");
1.76 albertel 647: my $doheaders=-1;
1.152 raeburn 648: foreach my $type ('Domain','Construction Space','Course','Group','Unavailable','System') {
1.76 albertel 649: my $haverole=0;
1.75 albertel 650: foreach my $which (sort {uc($a) cmp uc($b)} (keys(%sortrole))) {
651: if ($roleclass{$sortrole{$which}} =~ /^\Q$type\E/) {
1.76 albertel 652: $haverole=1;
1.75 albertel 653: }
1.76 albertel 654: }
655: if ($haverole) { $doheaders++; }
656: }
1.111 albertel 657:
1.118 albertel 658: if ($env{'environment.recentroles'}) {
1.111 albertel 659: my %recent_roles =
1.118 albertel 660: &Apache::lonhtmlcommon::get_recent('roles',$env{'environment.recentrolesn'});
1.111 albertel 661: my $output='';
662: foreach (sort(keys(%recent_roles))) {
663: if (defined($roletext{'user.role.'.$_})) {
664: $output.=$roletext{'user.role.'.$_};
1.133 albertel 665: if ($_ =~ m-dc\./(\w+)/- && $dcroles{$1}) {
1.138 raeburn 666: $output .= &allcourses_row($1,'recent');
1.133 albertel 667: }
1.113 raeburn 668: } elsif ($numdc > 0) {
669: unless ($_ =~/^error\:/) {
670: $output.=&display_cc_role('user.role.'.$_);
671: }
672: }
1.111 albertel 673: }
674: if ($output) {
1.132 albertel 675: $r->print("<tr><td align='center' colspan='5'><font face='arial'>".
1.126 www 676: &mt('Recent Roles')."</font></td>");
1.111 albertel 677: $r->print($output);
678: $r->print("</tr>");
1.114 raeburn 679: $doheaders ++;
1.111 albertel 680: }
681: }
682:
1.104 raeburn 683: if ($numdc > 0) {
1.112 raeburn 684: $r->print(&coursepick_jscript());
685: $r->print(&Apache::loncommon::coursebrowser_javascript());
1.108 raeburn 686: }
1.152 raeburn 687: foreach my $type ('Construction Space','Domain','Course','Group','Unavailable','System') {
1.108 raeburn 688: my $output;
689: foreach my $which (sort {uc($a) cmp uc($b)} (keys(%sortrole))) {
690: if ($roleclass{$sortrole{$which}} =~ /^\Q$type\E/) {
691: $output.=$roletext{$sortrole{$which}};
692: if ($sortrole{$which} =~ m-dc\./(\w+)/-) {
693: if ($dcroles{$1}) {
1.138 raeburn 694: $output .= &allcourses_row($1,'');
1.104 raeburn 695: }
696: }
1.76 albertel 697: }
1.108 raeburn 698: }
699: if ($output) {
700: if ($doheaders > 0) {
1.126 www 701: $r->print("<tr>".
1.132 albertel 702: "<td align='center' colspan='5'><font face='arial'>".&mt($type)."</font></td></tr>");
1.76 albertel 703: }
1.108 raeburn 704: $r->print($output);
705: }
1.4 www 706: }
1.14 www 707: my $tremark='';
1.47 www 708: my $tfont='#003300';
1.118 albertel 709: if ($env{'request.role'} eq 'cm') {
1.19 www 710: $r->print('<tr bgcolor="#11CC55">');
1.72 www 711: $tremark=&mt('Currently selected. ');
1.47 www 712: $tfont='#002200';
1.14 www 713: } else {
714: $r->print('<tr bgcolor="#77FF77">');
715: }
716: unless ($nochoose) {
1.118 albertel 717: if ($env{'request.role'} ne 'cm') {
1.134 www 718: $r->print('<td><input type="submit" value="'.
1.72 www 719: &mt('Select').'" name="cm"></td>');
1.55 albertel 720: } else {
721: $r->print('<td> </td>');
722: }
1.14 www 723: }
1.132 albertel 724: $r->print('<td colspan="3"><font color="'.$tfont.'">'.&mt('No role specified').
1.47 www 725: '</font></td><td><font color="'.$tfont.'">'.$tremark.
726: ' </font></td></tr>'."\n");
1.4 www 727:
728: $r->print('</table>');
729: unless ($nochoose) {
730: $r->print("</form>\n");
731: }
1.22 harris41 732: # ------------------------------------------------------------ Privileges Info
1.118 albertel 733: if (($advanced) && (($env{'user.error.msg'}) || ($error))) {
1.127 albertel 734: $r->print('<hr /><h2>Current Privileges</h2>');
1.4 www 735:
1.118 albertel 736: foreach $envkey (sort keys %env) {
737: if ($envkey=~/^user\.priv\.$env{'request.role'}\./) {
1.55 albertel 738: my $where=$envkey;
1.118 albertel 739: $where=~s/^user\.priv\.$env{'request.role'}\.//;
1.55 albertel 740: my $ttype;
741: my $twhere;
742: my ($tdom,$trest,$tsec)=
743: split(/\//,Apache::lonnet::declutter($where));
744: if ($trest) {
1.118 albertel 745: if ($env{'course.'.$tdom.'_'.$trest.'.description'} eq 'ca') {
1.55 albertel 746: $ttype='Construction Space';
747: $twhere='User: '.$trest.', Domain: '.$tdom;
748: } else {
1.157 albertel 749: $ttype=
750: &Apache::loncommon::course_type($tdom.'_'.$trest);
1.118 albertel 751: $twhere=$env{'course.'.$tdom.'_'.$trest.'.description'};
1.55 albertel 752: if ($tsec) {
1.152 raeburn 753: $twhere.=' (Section: '.$tsec.')';
1.55 albertel 754: }
755: }
756: } elsif ($tdom) {
757: $ttype='Domain';
758: $twhere=$tdom;
759: } else {
760: $ttype='System';
761: $twhere='/';
762: }
763: $r->print("\n<h3>".$ttype.': '.$twhere.'</h3><ul>');
1.118 albertel 764: foreach (sort split(/:/,$env{$envkey})) {
1.55 albertel 765: if ($_) {
766: my ($prv,$restr)=split(/\&/,$_);
767: my $trestr='';
768: if ($restr ne 'F') {
769: my $i;
770: $trestr.=' (';
771: for ($i=0;$i<length($restr);$i++) {
772: $trestr.=
773: Apache::lonnet::plaintext(substr($restr,$i,1));
774: if ($i<length($restr)-1) { $trestr.=', '; }
775: }
776: $trestr.=')';
777: }
778: $r->print('<li>'.
779: Apache::lonnet::plaintext($prv).$trestr.
780: '</li>');
781: }
782: }
783: $r->print('</ul>');
784: }
785: }
1.4 www 786: }
1.66 www 787: $r->print(&Apache::lonnet::getannounce());
1.65 www 788: if ($advanced) {
789: $r->print('<p><small><i>This is LON-CAPA '.
1.85 www 790: $r->dir_config('lonVersion').'</i><br />'.
791: '<a href="/adm/logout">'.&mt('Logout').'</a></small></p>');
1.65 www 792: }
1.147 albertel 793: $r->print(&Apache::loncommon::end_page());
1.1 harris41 794: return OK;
1.102 raeburn 795: }
796:
797: sub role_status {
798: my ($rolekey,$then,$now,$role,$where,$trolecode,$tstatus,$tstart,$tend) = @_;
799: my @pwhere = ();
1.118 albertel 800: if (exists($env{$rolekey}) && $env{$rolekey} ne '') {
1.102 raeburn 801: (undef,undef,$$role,@pwhere)=split(/\./,$rolekey);
802: unless (!defined($$role) || $$role eq '') {
803: $$where=join('.',@pwhere);
804: $$trolecode=$$role.'.'.$$where;
1.118 albertel 805: ($$tstart,$$tend)=split(/\./,$env{$rolekey});
1.102 raeburn 806: $$tstatus='is';
1.105 raeburn 807: if ($$tstart && $$tstart>$then) {
808: $$tstatus='future';
809: if ($$tstart<$now) { $$tstatus='will'; }
1.102 raeburn 810: }
811: if ($$tend) {
812: if ($$tend<$then) {
813: $$tstatus='expired';
1.103 raeburn 814: } elsif ($$tend<$now) {
1.104 raeburn 815: $$tstatus='will_not';
1.102 raeburn 816: }
817: }
818: }
819: }
820: }
1.1 harris41 821:
1.110 raeburn 822: sub build_roletext {
1.152 raeburn 823: my ($trolecode,$tdom,$trest,$tstatus,$tryagain,$advanced,$tremark,$tbg,$tfont,$trole,$twhere,$tpstart,$tpend,$nochoose,$button,$switchserver) = @_;
1.127 albertel 824: my $roletext='<tr bgcolor="'.$tbg.'">';
1.132 albertel 825: my $is_dc=($trolecode =~ m/^dc\./);
826: my $rowspan=($is_dc) ? ''
827: : ' rowspan="2" ';
828:
1.110 raeburn 829: unless ($nochoose) {
1.134 www 830: my $buttonname=$trolecode;
831: $buttonname=~s/\W//g;
1.110 raeburn 832: if (!$button) {
833: if ($switchserver) {
1.132 albertel 834: $roletext.='<td'.$rowspan.'><a href="/adm/switchserver?'.
1.110 raeburn 835: $switchserver.'">'.&mt('Switch Server').'</a></td>';
836: } else {
1.164 ! albertel 837: $roletext.=('<td'.$rowspan.'> </td>');
1.110 raeburn 838: }
839: } elsif ($tstatus eq 'is') {
1.134 www 840: $roletext.='<td'.$rowspan.'><input name="'.$buttonname.'" type="button" value="'.
841: &mt('Select').'" onClick="javascript:enterrole(this.form,\''.
842: $trolecode."','".$buttonname.'\');"></td>';
1.110 raeburn 843: } elsif ($tryagain) {
844: $roletext.=
1.134 www 845: '<td'.$rowspan.'><input name="'.$buttonname.'" type="button" value="'.
846: &mt('Try Selecting Again').'" onClick="javascript:enterrole(this.form,\''.
847: $trolecode."','".$buttonname.'\');"></td>';
1.110 raeburn 848: } elsif ($advanced) {
849: $roletext.=
1.134 www 850: '<td'.$rowspan.'><input name="'.$buttonname.'" type="button" value="'.
851: &mt('Re-Initialize').'" onClick="javascript:enterrole(this.form,\''.
852: $trolecode."','".$buttonname.'\');"></td>';
1.110 raeburn 853: } else {
1.132 albertel 854: $roletext.='<td'.$rowspan.'> </td>';
1.110 raeburn 855: }
856: }
857: $tremark.=&Apache::lonannounce::showday(time,1,
858: &Apache::lonannounce::readcalendar($tdom.'_'.$trest));
859:
860: $roletext.='<td><font color="'.$tfont.'">'.$trole.
1.121 albertel 861: '</font></td><td><font color="'.$tfont.'">'.$twhere.
1.110 raeburn 862: '</font></td><td><font color="'.$tfont.'">'.$tpstart.
863: '</font></td><td><font color="'.$tfont.'">'.$tpend.
1.132 albertel 864: '</font></td></tr>';
865: if (!$is_dc) {
866: $roletext.='<tr bgcolor="'.$tbg.'"><td colspan="4"><font color="'.$tfont.'">'.$tremark.
867: ' </font></td></tr><tr><td colspan="5" height="3"></td></tr>'."\n";
868: }
1.110 raeburn 869: return $roletext;
870: }
871:
872: sub check_privs {
1.146 raeburn 873: my ($cdom,$cnum,$then,$now) = @_;
874: my $cckey = 'user.role.cc./'.$cdom.'/'.$cnum;
1.118 albertel 875: if ($env{$cckey}) {
1.110 raeburn 876: my ($role,$where,$trolecode,$tstart,$tend,$tremark,$tstatus,$tpstart,$tpend,$tfont);
877: &role_status($cckey,$then,$now,\$role,\$where,\$trolecode,\$tstatus,\$tstart,\$tend);
878: unless (($tstatus eq 'is') || ($tstatus eq 'will_not')) {
1.146 raeburn 879: &set_privileges($cdom,$cnum);
1.110 raeburn 880: }
881: } else {
1.146 raeburn 882: &set_privileges($cdom,$cnum);
1.110 raeburn 883: }
884: }
885:
1.104 raeburn 886: sub check_fordc {
887: my ($dcroles,$then) = @_;
888: my $numdc = 0;
1.118 albertel 889: if ($env{'user.adv'}) {
890: foreach my $envkey (sort keys %env) {
1.104 raeburn 891: if ($envkey=~/^user\.role\.dc\.\/(\w+)\/$/) {
892: my $dcdom = $1;
893: my $livedc = 1;
1.118 albertel 894: my ($tstart,$tend)=split(/\./,$env{$envkey});
1.105 raeburn 895: if ($tstart && $tstart>$then) { $livedc = 0; }
896: if ($tend && $tend <$then) { $livedc = 0; }
1.104 raeburn 897: if ($livedc) {
898: $$dcroles{$dcdom} = $envkey;
1.105 raeburn 899: $numdc++;
1.104 raeburn 900: }
901: }
902: }
903: }
904: return $numdc;
905: }
906:
1.108 raeburn 907: sub courselink {
1.152 raeburn 908: my ($dcdom,$rowtype,$selecttype) = @_;
1.109 raeburn 909: my $courseform=&Apache::loncommon::selectcourse_link
1.152 raeburn 910: ('rolechoice','dccourse'.$rowtype.'_'.$dcdom,
911: 'dcdomain'.$rowtype.'_'.$dcdom,'coursedesc'.$rowtype.'_'.
912: $dcdom,$dcdom,undef,$selecttype);
1.138 raeburn 913: my $hiddenitems = '<input type="hidden" name="dcdomain'.$rowtype.'_'.$dcdom.'" value="'.$dcdom.'" />'.
914: '<input type="hidden" name="origdom'.$rowtype.'_'.$dcdom.'" value="'.$dcdom.'" />'.
915: '<input type="hidden" name="dccourse'.$rowtype.'_'.$dcdom.'" value="" />'.
916: '<input type="hidden" name="coursedesc'.$rowtype.'_'.$dcdom.'" value="" />';
1.112 raeburn 917: return $courseform.$hiddenitems;
1.109 raeburn 918: }
919:
920: sub coursepick_jscript {
1.104 raeburn 921: my $verify_script = <<"END";
922: <script>
1.108 raeburn 923: function verifyCoursePick(caller) {
924: var numbutton = getIndex(caller)
1.112 raeburn 925: var pickedCourse = document.rolechoice.elements[numbutton+4].value
926: var pickedDomain = document.rolechoice.elements[numbutton+2].value
927: if (document.rolechoice.elements[numbutton+2].value == document.rolechoice.elements[numbutton+3].value) {
1.104 raeburn 928: if (pickedCourse != '') {
1.108 raeburn 929: if (numbutton != -1) {
930: var courseTarget = "cc./"+pickedDomain+"/"+pickedCourse
931: document.rolechoice.elements[numbutton+1].name = courseTarget
932: document.rolechoice.submit()
933: }
1.104 raeburn 934: }
935: else {
1.114 raeburn 936: 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 937: }
938: }
939: else {
940: alert("You can only use this screen to select courses in the current domain")
941: }
942: }
1.109 raeburn 943: function getIndex(caller) {
1.108 raeburn 944: for (var i=0;i<document.rolechoice.elements.length;i++) {
1.109 raeburn 945: if (document.rolechoice.elements[i] == caller) {
1.108 raeburn 946: return i;
947: }
948: }
949: return -1;
950: }
1.104 raeburn 951: </script>
952: END
1.109 raeburn 953: return $verify_script;
1.104 raeburn 954: }
955:
1.109 raeburn 956: sub processpick {
957: my $process_pick = <<"END";
958: <script>
959: function process_pick(dom) {
1.138 raeburn 960: var pickedCourse=opener.document.rolechoice.$env{'form.cnumelement'}.value;
961: var pickedDomain=opener.document.rolechoice.$env{'form.cdomelement'}.value;
962: var okDomain = 0;
963:
964: if (pickedDomain == dom) {
1.109 raeburn 965: if (pickedCourse != '') {
1.138 raeburn 966: var courseTarget = "cc./"+pickedDomain+"/"+pickedCourse
967: opener.document.title='Role selected. Please stand by.';
968: opener.status='Role selected. Please stand by.';
969: opener.document.rolechoice.newrole.value=courseTarget
970: opener.document.rolechoice.submit()
1.109 raeburn 971: }
1.138 raeburn 972: } else {
973: 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 974: }
975: }
976:
977: </script>
978: END
979: return $process_pick;
980: }
1.108 raeburn 981:
1.113 raeburn 982: sub display_cc_role {
983: my $rolekey = shift;
984: my $roletext;
1.118 albertel 985: my $advanced = $env{'user.adv'};
986: my $tryagain = $env{'form.tryagain'};
1.113 raeburn 987: unless ($rolekey =~/^error\:/) {
988: if ($rolekey =~ m-^user\.role.cc\./(\w+)/(\w+)$-) {
989: my $tcourseid = $1.'_'.$2;
990: my $trolecode = 'cc./'.$1.'/'.$2;
991: my $twhere;
1.152 raeburn 992: my $ttype;
1.113 raeburn 993: my $tbg='#77FF77';
994: my $tfont='#003300';
995: my %newhash=&Apache::lonnet::coursedescription($tcourseid);
996: if (%newhash) {
997: $twhere=$newhash{'description'}.
998: ' <font size="-2">'.
999: &Apache::loncommon::syllabuswrapper(&mt('Syllabus'),$2,$1,$tfont).
1000: '</font>';
1.153 raeburn 1001: $ttype = $newhash{'type'};
1.113 raeburn 1002: } else {
1003: $twhere=&mt('Currently not available');
1.118 albertel 1004: $env{'course.'.$tcourseid.'.description'}=$twhere;
1.110 raeburn 1005: }
1.153 raeburn 1006: my $trole = &Apache::lonnet::plaintext('cc',$ttype);
1.113 raeburn 1007: $twhere.="<br />".&mt('Domain').":".$1;
1.152 raeburn 1008: $roletext = &build_roletext($trolecode,$1,$2,'is',$tryagain,$advanced,'',$tbg,$tfont,$trole,$twhere,'','','',1,'');
1.104 raeburn 1009: }
1010: }
1.152 raeburn 1011: return ($roletext);
1.104 raeburn 1012: }
1013:
1.108 raeburn 1014: sub allcourses_row {
1.138 raeburn 1015: my ($dcdom,$rowtype) = @_;
1.132 albertel 1016: my $output = '<tr bgcolor="#77FF77">'.
1.152 raeburn 1017: ' <td colspan="5">';
1018: foreach my $type ('Course','Group') {
1019: my $selectlink = &courselink($dcdom,$rowtype,$type);
1.153 raeburn 1020: my $ccrole = &Apache::lonnet::plaintext('cc',$type);
1.152 raeburn 1021: $output.= '<font color="#002200">'.$ccrole.'</font>'.
1022: ' <b>'.$selectlink.'</b>'.
1023: ' from '.&mt('Domain').' '.$dcdom.'<br />';
1024: }
1025: $output .= '</tr><tr><td colspan="5" height="3"></td></tr>'."\n";
1.108 raeburn 1026: return $output;
1027: }
1028:
1.104 raeburn 1029: sub recent_filename {
1030: my $area=shift;
1.149 www 1031: return 'nohist_recent_'.&escape($area);
1.104 raeburn 1032: }
1033:
1.106 raeburn 1034: sub set_privileges {
1035: my ($dcdom,$pickedcourse) = @_;
1036: my $area = '/'.$dcdom.'/'.$pickedcourse;
1037: my $role = 'cc';
1038: my $spec = $role.'.'.$area;
1.154 albertel 1039: my %userroles = &Apache::lonnet::set_arearole($role,$area,'','',$dcdom,$env{'user.name'});
1.106 raeburn 1040: my %ccrole = ();
1041: &Apache::lonnet::standard_roleprivs(\%ccrole,$role,$dcdom,$spec,$pickedcourse,$area);
1.154 albertel 1042: my ($author,$adv)= &Apache::lonnet::set_userprivs(\%userroles,\%ccrole);
1043: &Apache::lonnet::appenv(%userroles);
1.118 albertel 1044: &Apache::lonnet::log($env{'user.domain'},
1045: $env{'user.name'},
1046: $env{'user.home'},
1.106 raeburn 1047: "Role ".$role);
1048: &Apache::lonnet::appenv(
1.146 raeburn 1049: 'request.role' => $spec,
1.106 raeburn 1050: 'request.role.domain' => $dcdom,
1051: 'request.course.sec' => '');
1052: my $tadv=0;
1053: if (&Apache::lonnet::allowed('adv') eq 'F') { $tadv=1; }
1054: &Apache::lonnet::appenv('request.role.adv' => $tadv);
1055: }
1056:
1.139 raeburn 1057: sub courseloadpage {
1058: my ($courseid) = @_;
1059: my $startpage;
1.144 albertel 1060: my %entry_settings = &Apache::lonnet::get('nohist_whatsnew',
1061: [$courseid.':courseinit']);
1.139 raeburn 1062: my ($tmp) = %entry_settings;
1.144 albertel 1063: unless ($tmp =~ /^error: 2 /) {
1.139 raeburn 1064: $startpage = $entry_settings{$courseid.':courseinit'};
1065: }
1066: if ($startpage eq '') {
1067: if (exists($env{'environment.course_init_display'})) {
1068: $startpage = $env{'environment.course_init_display'};
1069: }
1070: }
1071: return $startpage;
1072: }
1073:
1.1 harris41 1074: 1;
1075: __END__
1.32 harris41 1076:
1077: =head1 NAME
1078:
1079: Apache::lonroles - User Roles Screen
1080:
1081: =head1 SYNOPSIS
1082:
1083: Invoked by /etc/httpd/conf/srm.conf:
1084:
1085: <Location /adm/roles>
1086: PerlAccessHandler Apache::lonacc
1087: SetHandler perl-script
1088: PerlHandler Apache::lonroles
1089: ErrorDocument 403 /adm/login
1090: ErrorDocument 500 /adm/errorhandler
1091: </Location>
1.64 bowersj2 1092:
1093: =head1 OVERVIEW
1094:
1095: =head2 Choosing Roles
1096:
1097: C<lonroles> is a handler that allows a user to switch roles in
1098: mid-session. LON-CAPA attempts to work with "No Role Specified", the
1099: default role that a user has before selecting a role, as widely as
1100: possible, but certain handlers for example need specification which
1101: course they should act on, etc. Both in this scenario, and when the
1102: handler determines via C<lonnet>'s C<&allowed> function that a certain
1103: action is not allowed, C<lonroles> is used as error handler. This
1104: allows the user to select another role which may have permission to do
1105: what they were trying to do. C<lonroles> can also be accessed via the
1106: B<CRS> button in the Remote Control.
1107:
1108: =begin latex
1109:
1110: \begin{figure}
1111: \begin{center}
1112: \includegraphics[width=0.45\paperwidth,keepaspectratio]{Sample_Roles_Screen}
1113: \caption{\label{Sample_Roles_Screen}Sample Roles Screen}
1114: \end{center}
1115: \end{figure}
1116:
1117: =end latex
1118:
1119: =head2 Role Initialization
1120:
1121: 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 1122:
1123: =head1 INTRODUCTION
1124:
1125: This module enables a user to select what role he wishes to
1126: operate under (instructor, student, teaching assistant, course
1127: coordinator, etc). These roles are pre-established by the actions
1128: of upper-level users.
1129:
1130: This is part of the LearningOnline Network with CAPA project
1131: described at http://www.lon-capa.org.
1132:
1133: =head1 HANDLER SUBROUTINE
1134:
1135: This routine is called by Apache and mod_perl.
1136:
1137: =over 4
1138:
1139: =item *
1140:
1141: Roles Initialization (yes/no)
1142:
1143: =item *
1144:
1145: Get Error Message from Environment
1146:
1147: =item *
1148:
1149: Who is this?
1150:
1151: =item *
1152:
1153: Generate Page Output
1154:
1155: =item *
1156:
1157: Choice or no choice
1158:
1159: =item *
1160:
1161: Table
1162:
1163: =item *
1164:
1165: Privileges
1166:
1167: =back
1168:
1169: =cut
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>