[LON-CAPA-cvs] cvs: loncom /interface lonmsgdisplay.pm
albertel
lon-capa-cvs@mail.lon-capa.org
Tue, 25 Apr 2006 21:25:16 -0000
albertel Tue Apr 25 17:25:16 2006 EDT
Modified files:
/loncom/interface lonmsgdisplay.pm
Log:
- blocking didn't work on students in section it now does
- additionaly modifed the returned structure so no futher parsing is needed
- add a function for parsng the block record to make it so further updates are easy to deal with
Index: loncom/interface/lonmsgdisplay.pm
diff -u loncom/interface/lonmsgdisplay.pm:1.14 loncom/interface/lonmsgdisplay.pm:1.15
--- loncom/interface/lonmsgdisplay.pm:1.14 Tue Apr 25 16:02:30 2006
+++ loncom/interface/lonmsgdisplay.pm Tue Apr 25 17:25:13 2006
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Routines for messaging display
#
-# $Id: lonmsgdisplay.pm,v 1.14 2006/04/25 20:02:30 albertel Exp $
+# $Id: lonmsgdisplay.pm,v 1.15 2006/04/25 21:25:13 albertel Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -1275,13 +1275,11 @@
$env{'course.'.$env{'request.course.id'}.'.domain'},
$env{'course.'.$env{'request.course.id'}.'.num'}
);
- $$blockcount = keys %{$records};
-
- foreach (keys %{$records}) {
- if ($_ eq 'error: 2 tie(GDBM) Failed while attempting dump') {
- $$blockcount = 0;
- last;
- }
+ $$blockcount = keys(%{$records});
+
+ if ((keys(%{$records}))[0] =~ /^error: 2 /) {
+ $records = {};
+ $$blockcount = 0;
}
}
@@ -1319,14 +1317,8 @@
my ($start,$end) = split/____/,$_;
my $startform = &Apache::lonhtmlcommon::date_setter('blockform','startdate_'.$parmcount,$start,$onchange);
my $endform = &Apache::lonhtmlcommon::date_setter('blockform','enddate_'.$parmcount,$end,$onchange);
- my (@data,$setuname,$setudom,$title);
- @data = split(/:/,$$records{$_},3);
- if (scalar(@data) eq 2) {
- $title = $data[1];
- ($setuname,$setudom) = split(/@/,$data[0]);
- } else {
- ($setuname,$setudom,$title) = @data;
- }
+
+ my ($setuname,$setudom,$title) = &parse_block_record($$records{$_});
my $settername = &Apache::loncommon::plainname($setuname,$setudom);
$r->print(<<"END");
<tr bgcolor="$bgcols[$iter]">
@@ -1352,6 +1344,19 @@
return $parmcount;
}
+sub parse_block_record {
+ my ($record) = @_;
+ my ($setuname,$setudom,$title);
+ my @data = split(/:/,$record,3);
+ if (scalar(@data) eq 2) {
+ $title = $data[1];
+ ($setuname,$setudom) = split(/@/,$data[0]);
+ } else {
+ ($setuname,$setudom,$title) = @data;
+ }
+ return ($setuname,$setudom,$title);
+}
+
sub display_addblocker_table {
my ($r,$parmcount,$ltext) = @_;
my $start = time;
@@ -1402,58 +1407,47 @@
sub blockcheck {
my ($setters,$startblock,$endblock) = @_;
# Retrieve active student roles and active course coordinator/instructor roles
- my @livecses = ();
- my @staffcses = ();
- $$startblock = 0;
- $$endblock = 0;
- foreach (keys %env) {
- if ($_ =~ m-^user\.role\.(st|cc|in)\./(.+)$-) {
- my $role = $1;
- my $cse = $2;
- $cse =~ s|/|_|;
- if ($env{$_} =~ m/^(\d*)\.(\d*)$/) {
- unless (($2 > 0 && $2 < time) || ($1 > time)) {
- if ($role eq 'st') {
- push @livecses, $cse;
- } else {
- unless (grep/^$cse$/,@staffcses) {
- push @staffcses, $cse;
- }
- }
- }
- }
- } elsif ($_ =~ m-user\.role\.cr/(\w+)/(\w+)/([^/]+)\./(.+)$- ) {
- my $rolepriv = $env{'user.role..rolesdef_'.$3};
- }
- }
- # Retrieve blocking times and identity of blocker for active courses for students.
- if (@livecses > 0) {
- foreach my $cse (@livecses) {
- my ($cdom,$crs) = split/_/,$cse;
- if ( (grep/^$cse$/,@staffcses) && ($env{'request.role'} !~ m-^st\./$cdom/$crs$-) ) {
- next;
- } else {
- %{$$setters{$cse}} = ();
- @{$$setters{$cse}{'staff'}} = ();
- @{$$setters{$cse}{'times'}} = ();
- my %records = &Apache::lonnet::dump('comm_block',$cdom,$crs);
- foreach (keys %records) {
- if ($_ =~ m/^(\d+)____(\d+)$/) {
- if ($1 <= time && $2 >= time) {
- my ($staff,$title) = split/:/,$records{$_};
- push @{$$setters{$cse}{'staff'}}, $staff;
- push @{$$setters{$cse}{'times'}}, $_;
- if ( ($$startblock == 0) || ($$startblock > $1) ) {
- $$startblock = $1;
- }
- if ( ($$endblock == 0) || ($$endblock < $2) ) {
- $$endblock = $2;
- }
- }
- }
- }
- }
- }
+ my %live_courses =
+ map { $_ => 1} &Apache::loncommon::findallcourses();
+ # FIXME should really probe for apriv, but ::allowed can only probe the
+ # currently active role
+ my %staff_of =
+ map { $_ => 1} &Apache::loncommon::findallcourses(['cc','in']);
+
+ # Retrieve blocking times and identity of blocker for active courses
+ # for students.
+ return if (!%live_courses);
+
+ &Apache::lonnet::logthis("hmm");
+ &Apache::lonnet::logthis(join(" ",%live_courses));
+ &Apache::lonnet::logthis(join(" ",%staff_of));
+
+ foreach my $course (keys(%live_courses)) {
+ my ($cdom,$cnum) = split(/_/,$course);
+
+ # if they are a staff member and are currently not playing student
+ next if ( $staff_of{$course}
+ && ($env{'request.role'} !~ m{^st\./$cdom/$cnum}));
+
+ $setters->{$course} = {};
+ $setters->{$course}{'staff'} = [];
+ $setters->{$course}{'times'} = [];
+ my %records = &Apache::lonnet::dump('comm_block',$cdom,$cnum);
+ foreach my $record (keys %records) {
+ my ($start,$end) = ($record =~ m/^(\d+)____(\d+)$/);
+ if ($start <= time && $end >= time) {
+ my ($staff_name,$staff_dom,$title) =
+ &parse_block_record($records{$record});
+ push(@{$$setters{$course}{'staff'}}, [$staff_name,$staff_dom]);
+ push(@{$$setters{$course}{'times'}}, [$start,$end]);
+ if ( ($$startblock == 0) || ($$startblock > $1) ) {
+ $$startblock = $1;
+ }
+ if ( ($$endblock == 0) || ($$endblock < $2) ) {
+ $$endblock = $2;
+ }
+ }
+ }
}
}
@@ -1486,9 +1480,9 @@
foreach (keys %{$setters}) {
my %courseinfo=&Apache::lonnet::coursedescription($_);
for (my $i=0; $i<@{$$setters{$_}{staff}}; $i++) {
- my ($uname,$udom) = split/\@/,$$setters{$_}{staff}[$i];
+ my ($uname,$udom) = @{$$setters{$_}{staff}[$i]};
my $fullname = &Apache::loncommon::plainname($uname,$udom);
- my ($openblock,$closeblock) = split/____/,$$setters{$_}{times}[$i];
+ my ($openblock,$closeblock) = @{$$setters{$_}{times}[$i]};
$openblock = &Apache::lonlocal::locallocaltime($openblock);
$closeblock= &Apache::lonlocal::locallocaltime($closeblock);
$r->print('<tr><td>'.$courseinfo{'description'}.'</td>'.