--- loncom/auth/lonroles.pm 2008/03/12 02:47:34 1.186 +++ loncom/auth/lonroles.pm 2008/09/03 04:28:22 1.206 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # User Roles Screen # -# $Id: lonroles.pm,v 1.186 2008/03/12 02:47:34 raeburn Exp $ +# $Id: lonroles.pm,v 1.206 2008/09/03 04:28:22 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -43,6 +43,7 @@ use Apache::lonpageflip(); use Apache::lonnavdisplay(); use GDBM_File; use LONCAPA qw(:DEFAULT :match); +use HTML::Entities; sub redirect_user { @@ -106,6 +107,10 @@ sub handler { # ================================================================== Roles Init if ($env{'form.selectrole'}) { + + my $locknum=&Apache::lonnet::get_locks(); + if ($locknum) { return 409; } + if ($env{'form.newrole'}) { $env{'form.'.$env{'form.newrole'}}=1; } @@ -138,26 +143,54 @@ sub handler { } last; } -# Is this a recent ad-hoc CA-role? +# Is this an ad-hoc CA-role? if (my ($domain,$user) = ($envkey =~ m-^form\.ca\./($match_domain)/($match_username)$-)) { - if (($dcroles{$domain}) && (&is_author_homeserver($user,$domain))) { - &check_privs($domain,$user,$then,$now,'ca'); - } else { + if (($domain eq $env{'user.domain'}) && ($user eq $env{'user.name'})) { delete($env{$envkey}); + $env{'form.au./'.$domain.'/'} = 1; + my ($server_status,$home) = &check_author_homeserver($user,$domain); + if ($server_status eq 'switchserver') { + my $trolecode = 'au./'.$domain.'/'; + my $switchserver = '/adm/switchserver?otherserver='.$home.'&role='.$trolecode; + $r->internal_redirect($switchserver); + } + last; + } + if (my ($castart,$caend) = ($env{'user.role.ca./'.$domain.'/'.$user} =~ /^(\d*)\.(\d*)$/)) { + if (((($castart) && ($castart < $now)) || !$castart) && + ((!$caend) || (($caend) && ($caend > $now)))) { + my ($server_status,$home) = &check_author_homeserver($user,$domain); + if ($server_status eq 'switchserver') { + my $trolecode = 'ca./'.$domain.'/'.$user; + my $switchserver = '/adm/switchserver?otherserver='.$home.'&role='.$trolecode; + $r->internal_redirect($switchserver); + } + last; + } + } + # Check if author blocked ca-access + my %blocked=&Apache::lonnet::get('environment',['domcoord.author'],$domain,$user); + if ($blocked{'domcoord.author'} eq 'blocked') { + delete($env{$envkey}); + $env{'user.error.msg'}=':::1:User '.$user.' in domain '.$domain.' blocked domain coordinator access'; + last; } - last; - } -# Is this a new ad-hoc CA-role? - if (my ($domain) = - ($envkey =~ m-^form\.adhocca\./($match_domain)$-)) { if ($dcroles{$domain}) { - my $user=$env{'form.adhoccauname.'.$domain}; - if (!$user) { $user=$env{'form.adhoccaunamerecent.'.$domain} }; - if (($user) && ($user=~/$match_username/) && (&is_author_homeserver($user,$domain))) { - &check_privs($domain,$user,$then,$now,'ca'); - $env{'form.ca./'.$domain.'/'.$user}=1; - } + my ($server_status,$home) = &check_author_homeserver($user,$domain); + if (($server_status eq 'ok') || ($server_status eq 'switchserver')) { + &check_privs($domain,$user,$then,$now,'ca'); + if ($server_status eq 'switchserver') { + my $trolecode = 'ca./'.$domain.'/'.$user; + my $switchserver = '/adm/switchserver?' + .'otherserver='.$home.'&role='.$trolecode; + $r->internal_redirect($switchserver); + } + } else { + delete($env{$envkey}); + } + } else { + delete($env{$envkey}); } last; } @@ -219,8 +252,11 @@ sub handler { $cdom,$cnum, $env{'user.domain'}, $env{'user.name'}, - 'Assigned from '.$ENV{'REMOTE_ADDR'}.' at '.localtime().' for '. - $trolecode); + &mt('Assigned from [_1] at [_2] for [_3]' + ,$ENV{'REMOTE_ADDR'} + ,&Apache::lonlocal::locallocaltime() + ,$trolecode) + ); unless ($assignresult eq 'ok') { $assignresult=~s/^error\:\s*//; $message=&mt($assignresult). @@ -326,6 +362,10 @@ ENDENTERKEY } elsif ($env{'request.course.id'}) { if ($env{'form.destinationurl'}) { my $dest = $env{'form.destinationurl'}; + if ($env{'form.destsymb'} ne '') { + my $esc_symb = &HTML::Entities::encode($env{'form.destsymb'},'"<>&'); + $dest .= '?symb='.$esc_symb; + } &redirect_user($r,&mt('Entering [_1]', $env{'course.'.$courseid.'.description'}), $dest,$msg, @@ -340,7 +380,7 @@ ENDENTERKEY ) { my $startpage = &courseloadpage($courseid); unless ($startpage eq 'firstres') { - $msg = &mt('Entering [_1] ....', + $msg = &mt('Entering [_1] ...', $env{'course.'.$courseid.'.description'}); &redirect_user($r,&mt('New in course'), '/adm/whatsnew?refpage=start',$msg, @@ -447,16 +487,16 @@ ENDHEADER # -------------------------------------------------------- Generate Page Output # --------------------------------------------------------------- Error Header? if ($error) { - $r->print("
"); if ($priv ne '') { - $r->print("Access : ".&Apache::lonnet::plaintext($priv)."\n"); + $r->print(&mt('Access : ').&Apache::lonnet::plaintext($priv)."\n"); } if ($fn ne '') { - $r->print("Resource: ".&Apache::lonenc::check_encrypt($fn)."\n"); + $r->print(&mt('Resource: ').&Apache::lonenc::check_encrypt($fn)."\n"); } if ($msg ne '') { - $r->print("Action : $msg\n"); + $r->print(&mt('Action : ').$msg."\n"); } $r->print("
'.&mt('[_1]Visit the [_2]Course Catalog[_3] to view all [_4] LON-CAPA courses.','','','',$domdesc).'
'.&mt('If a course is [_1]not[_2] in your list of current courses below, you may be able to enroll if self-enrollment is permitted.','','').'
'); } - $r->print(' | '.&mt('User Role').' | '.&mt('Extent'). - ' | '.&mt('Start').' | '.&mt('End').' | |
---|---|---|---|---|---|
". - &mt('Recent Roles')." | "); + &mt('Recent Roles')."|||||
".&mt($type)." | |||||
'); + } else { + $r->print(' | '); } - $r->print($output); - } - } - my $tremark=''; - my $tfont='#003300'; - if ($env{'request.role'} eq 'cm') { - $r->print(' | ||||
'); - } else { - $r->print(' | '); - } - } - $r->print(' | '.&mt('No role specified'). - ' | '.$tremark. - ' | '.&mt('No role specified'). + ' | '.$tremark. + ' | '."\n"); + } $r->print('
This is LON-CAPA '.
- $r->dir_config('lonVersion').'
'.
- ''.&mt('Logout').'
'
+ .&mt('This is LON-CAPA [_1]',$r->dir_config('lonVersion'))
+ .'
'
+ .''.&mt('Logout').' '
+ .''
+ .&mt('Course Catalog')
+ .'
'); } + $r->print(' | '.&mt('User Role').' | '.&mt('Extent') + .' | '.&mt('Start').' | '.&mt('End') + .' | |||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
". + &mt($type)." | '; + $trolecode."','".$buttonname.'\');" />'; } elsif ($tryagain) { $roletext.= ' | '; + $trolecode."','".$buttonname.'\');" />'; } elsif ($advanced) { $roletext.= ' | '; + $trolecode."','".$buttonname.'\');" />'; } else { $roletext.=' | '; } @@ -920,18 +1061,39 @@ sub build_roletext { return $roletext; } -sub is_author_homeserver { +sub check_needs_switchserver { + my ($possiblerole) = @_; + my $needs_switchserver; + my ($role,$where) = split(/\./,$possiblerole,2); + my (undef,$tdom,$twho) = split(/\//,$where); + my ($server_status,$home); + if (($role eq 'ca') || ($role eq 'aa')) { + ($server_status,$home) = &check_author_homeserver($twho,$tdom); + } else { + ($server_status,$home) = &check_author_homeserver($env{'user.name'}, + $env{'user.domain'}); + } + if ($server_status eq 'switchserver') { + $needs_switchserver = 1; + } + return $needs_switchserver; +} + +sub check_author_homeserver { my ($uname,$udom)=@_; + if (($uname eq '') || ($udom eq '')) { + return ('fail',''); + } my $home = &Apache::lonnet::homeserver($uname,$udom); + if (&Apache::lonnet::host_domain($home) ne $udom) { + return ('fail',$home); + } my @ids=&Apache::lonnet::current_machine_ids(); - foreach my $id (@ids) { - if ($id eq $home) { - if (-e "/home/".$uname."/public_html") { - return 1; - } - } + if (grep(/^\Q$home\E$/,@ids)) { + return ('ok',$home); + } else { + return ('switchserver',$home); } - return 0; } sub check_privs { @@ -972,26 +1134,26 @@ sub check_fordc { sub adhoc_course_role { my ($then) = @_; my ($cdom,$cnum); - my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'}; - my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'}; + $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'}; + $cnum = $env{'course.'.$env{'request.course.id'}.'.num'}; if (&check_forcc($cdom,$cnum,$then)) { my $setprivs; - if (!defined($env{'user.role.'.$env{'form.selectrole'}})) { + if (!defined($env{'user.role.'.$env{'form.switchrole'}})) { $setprivs = 1; } else { - my ($start,$end) = split(/\./,$env{'user.role.'.$env{'form.selectrole'}}); + my ($start,$end) = split(/\./,$env{'user.role.'.$env{'form.switchrole'}}); if (($start && ($start>$then || $start == -1)) || ($end && $end<$then)) { $setprivs = 1; } } if ($setprivs) { - if ($env{'form.switchrole'} =~ m-^(in|ta|ep|ad|st|cr)([\w/]*)\./\Q$cdom\E/\Q$cnum\E(/?\w*)$-) { + if ($env{'form.switchrole'} =~ m-^(in|ta|ep|ad|st|cr)([\w/]*)\./\Q$cdom\E/\Q$cnum\E/?(\w*)$-) { my $role = $1; my $custom_role = $2; my $usec = $3; if ($role eq 'cr') { - if ($custom_role =~ m-^$match_domain/$match_courseid/\w+$-) { + if ($custom_role =~ m-^/$match_domain/$match_username/\w+$-) { $role .= $custom_role; } else { return; @@ -1033,7 +1195,7 @@ sub check_forcc { } sub courselink { - my ($dcdom,$rowtype,$selecttype) = @_; + my ($dcdom,$rowtype) = @_; my $courseform=&Apache::loncommon::selectcourse_link ('rolechoice','dccourse'.$rowtype.'_'.$dcdom, 'dcdomain'.$rowtype.'_'.$dcdom,'coursedesc'.$rowtype.'_'. @@ -1085,6 +1247,13 @@ END return $verify_script; } +sub coauthorlink { + my ($dcdom,$rowtype) = @_; + my $coauthorform=&Apache::loncommon::selectauthor_link('rolechoice',$dcdom); + my $hiddenitems = ''; + return $coauthorform.$hiddenitems; +} + sub display_cc_role { my $rolekey = shift; my $roletext; @@ -1117,28 +1286,22 @@ sub display_cc_role { return ($roletext); } -sub allcourses_row { +sub adhoc_roles_row { my ($dcdom,$rowtype) = @_; my $output = ' | |||||||||||||||||||
'; - my $selectlink = &courselink($dcdom,$rowtype); + ' |
| ||||||||||||||||||||||