--- loncom/auth/lonroles.pm 2004/11/02 23:22:46 1.101 +++ loncom/auth/lonroles.pm 2004/11/09 15:52:29 1.102 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # User Roles Screen # -# $Id: lonroles.pm,v 1.101 2004/11/02 23:22:46 albertel Exp $ +# $Id: lonroles.pm,v 1.102 2004/11/09 15:52:29 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -99,21 +99,9 @@ sub handler { "request.role.domain" => $ENV{'user.domain'}); foreach $envkey (keys %ENV) { next if ($envkey!~/^user\.role\./); - my (undef,undef,$role,@pwhere)=split(/\./,$envkey); - my $where=join('.',@pwhere); - my $trolecode=$role.'.'.$where; + my ($where,$trolecode,$role,$tstatus,$tend,$tstart); + &role_status($envkey,$then,$now,\$role,\$where,\$trolecode,\$tstatus,\$tstart,\$tend); if ($ENV{'form.'.$trolecode}) { - my ($tstart,$tend)=split(/\./,$ENV{$envkey}); - my $tstatus='is'; - if ($tstart) { - if ($tstart>$then) { - $tstatus='future'; - } - } - if ($tend) { - if ($tend<$then) { $tstatus='expired'; } - if ($tend<$now) { $tstatus='will_not'; } - } if ($tstatus eq 'is') { $where=~s/^\///; my ($cdom,$cnum,$csec)=split(/\//,$where); @@ -380,16 +368,13 @@ ENDHEADER my $roletext; my $sortkey; if ($envkey=~/^user\.role\./) { - my (undef,undef,$role,@pwhere)=split(/\./,$envkey); + my ($role,$where,$trolecode,$tstart,$tend,$tremark,$tstatus,$tpstart,$tpend,$tfont); + &role_status($envkey,$then,$now,\$role,\$where,\$trolecode,\$tstatus,\$tstart,\$tend); next if (!defined($role) || $role eq ''); - my $where=join('.',@pwhere); - my $trolecode=$role.'.'.$where; - my ($tstart,$tend)=split(/\./,$ENV{$envkey}); - my $tremark=''; - my $tstatus='is'; - my $tpstart=' '; - my $tpend=' '; - my $tfont='#000000'; + $tremark=''; + $tpstart=' '; + $tpend=' '; + $tfont='#000000'; if ($tstart) { if ($tstart>$then) { $tstatus='future'; @@ -719,7 +704,33 @@ ENDHEADER } $r->print("\n"); return OK; -} +} + +sub role_status { + my ($rolekey,$then,$now,$role,$where,$trolecode,$tstatus,$tstart,$tend) = @_; + my @pwhere = (); + if (exists($ENV{$rolekey}) && $ENV{$rolekey} ne '') { + (undef,undef,$$role,@pwhere)=split(/\./,$rolekey); + unless (!defined($$role) || $$role eq '') { + $$where=join('.',@pwhere); + $$trolecode=$$role.'.'.$$where; + ($$tstart,$$tend)=split(/\./,$ENV{$rolekey}); + $$tstatus='is'; + if ($$tstart) { + if ($$tstart>$then) { + $$tstatus='future'; + if ($$tstart<$now) { $$tstatus='will'; } + } + } + if ($$tend) { + if ($$tend<$then) { + $$tstatus='expired'; + if ($$tend<$now) { $$tstatus='will_not'; } + } + } + } + } +} 1; __END__