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