--- loncom/interface/lonmsgdisplay.pm 2006/11/29 05:54:34 1.43 +++ loncom/interface/lonmsgdisplay.pm 2006/11/29 07:46:39 1.44 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Routines for messaging display # -# $Id: lonmsgdisplay.pm,v 1.43 2006/11/29 05:54:34 raeburn Exp $ +# $Id: lonmsgdisplay.pm,v 1.44 2006/11/29 07:46:39 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -649,12 +649,10 @@ sub disnew { my @msgids = sort(&Apache::lonnet::getkeys('nohist_email')); my @newmsgs; my %setters = (); - my $startblock = 0; - my $endblock = 0; my %blocked = (); my $numblocked = 0; # Check for blocking of display because of scheduled online exams. - &blockcheck(\%setters,\$startblock,\$endblock); + my ($startblock,$endblock) = &Apache::loncommon::blockcheck(\%setters,'com'); my %status_cache = &Apache::lonnet::get('email_status',\@msgids); my %descriptions; @@ -715,7 +713,8 @@ ENDLINK } $r->print( &mt('display of LON-CAPA messages sent to you by other students between').' '.$beginblock.' '.&mt('and').' '.$finishblock.' '.&mt('is currently being blocked because of online exams').'.'); - &build_block_table($r,$startblock,$endblock,\%setters); + $r->print(&Apache::loncommon::build_block_table($startblock,$endblock, + \%setters)); } } @@ -740,10 +739,8 @@ sub disfolder { my ($r,$folder)=@_; my %blocked = (); my %setters = (); - my $startblock; - my $endblock; my $numblocked = 0; - &blockcheck(\%setters,\$startblock,\$endblock); + my ($startblock,$endblock) = &Apache::loncommon::blockcheck(\%setters,'com'); $r->print(< function checkall() { @@ -887,7 +884,8 @@ ENDDISHEADER my $finishblock = &Apache::lonlocal::locallocaltime($endblock); $r->print('

'. $numblocked.' '.&mt('message(s) is/are not viewable because display of LON-CAPA messages sent to you by other students between').' '.$beginblock.' '.&mt('and').' '.$finishblock.' '.&mt('is currently being blocked because of online exams.')); - &build_block_table($r,$startblock,$endblock,\%setters); + $r->print(&Apache::loncommon::build_block_table($startblock,$endblock, + \%setters)); } } @@ -1311,8 +1309,8 @@ ENDBFORM sub examblock { my ($r,$action) = @_; unless ($env{'request.course.id'}) { return;} - if (!&Apache::lonnet::allowed('srm',$env{'request.course.id'}) - && ! &Apache::lonnet::allowed('srm',$env{'request.course.id'}. + if (!&Apache::lonnet::allowed('dcm',$env{'request.course.id'}) + && ! &Apache::lonnet::allowed('dcm',$env{'request.course.id'}. '/'.$env{'request.course.sec'})) { $r->print('Not allowed'); return; @@ -1331,6 +1329,7 @@ sub examblock { 'dura' => 'Duration', 'setb' => 'Set by', 'even' => 'Event', + 'blck' => 'Blocked?', 'actn' => 'Action', 'star' => 'Start', 'endd' => 'End' @@ -1388,7 +1387,7 @@ sub blockstore { my %blocking = (); $r->print('

'.$lt{'head'}.'

'); foreach my $envkey (keys(%env)) { - if ($envkey =~ m/^form\.modify_(\w+)$/) { + if ($envkey =~ m/^form\.modify_(\d+)$/) { $adds{$1} = $1; $removals{$1} = $1; $modtotal ++; @@ -1401,7 +1400,7 @@ sub blockstore { } elsif ($envkey =~ m/^form\.add_(\d+)$/) { $adds{$1} = $1; $addtotal ++; - } + } } foreach my $key (keys(%removals)) { @@ -1415,7 +1414,12 @@ sub blockstore { unless ( defined($cancels{$key}) ) { my ($newstart,$newend) = &get_dates_from_form($key); my $newkey = $newstart.'____'.$newend; - $blocking{$newkey} = $env{'user.name'}.':'.$env{'user.domain'}.':'.$env{'form.title_'.$key}; + my $blocktypes = &get_block_choices($key); + $blocking{$newkey} = { + setter => $env{'user.name'}.':'.$env{'user.domain'}, + event => &escape($env{'form.title_'.$key}), + blocks => $blocktypes, + }; } } if ($addtotal + $modtotal > 0) { @@ -1466,6 +1470,20 @@ sub get_blockdates { } } +sub get_block_choices { + my $item = shift; + my $blocklist; + my ($typeorder,$types) = &blocktype_text(); + foreach my $type (@{$typeorder}) { + if ($env{'form.'.$type.'_'.$item}) { + $blocklist->{$type} = 'on'; + } else { + $blocklist->{$type} = 'off'; + } + } + return $blocklist; +} + sub display_blocker_status { my ($r,$records,$ltext) = @_; my $parmcount = 0; @@ -1474,13 +1492,15 @@ sub display_blocker_status { 'modi' => 'Modify', 'canc' => 'Cancel', ); + my ($typeorder,$types) = &blocktype_text(); $r->print(&Apache::loncommon::start_data_table()); $r->print(<<"END"); - $$ltext{'dura'} - $$ltext{'setb'} - $$ltext{'even'} - $$ltext{'actn'}? + $ltext->{'dura'} + $ltext->{'setb'} + $ltext->{'even'} + $ltext->{'blck'} + $ltext->{'actn'}? END foreach my $record (sort(keys(%{$records}))) { @@ -1491,15 +1511,29 @@ END my $startform = &Apache::lonhtmlcommon::date_setter('blockform','startdate_'.$parmcount,$start,$onchange); my $endform = &Apache::lonhtmlcommon::date_setter('blockform','enddate_'.$parmcount,$end,$onchange); - my ($setuname,$setudom,$title) = - &parse_block_record($$records{$record}); + my ($setuname,$setudom,$title,$blocks) = + &Apache::loncommon::parse_block_record($$records{$record}); $title = &HTML::Entities::encode($title,'"<>&'); - my $settername = &Apache::loncommon::plainname($setuname,$setudom); + my $settername = + &Apache::loncommon::aboutmewrapper( + &Apache::loncommon::plainname($setuname,$setudom), + $setuname,$setudom); $r->print(&Apache::loncommon::start_data_table_row()); $r->print(<<"END"); - $$ltext{'star'}: $startform
$$ltext{'endd'}:  $endform + $ltext->{'star'}: $startform
$ltext->{'endd'}:  $endform $settername + +END + foreach my $block (@{$typeorder}) { + my $blockstatus = ''; + if ($blocks->{$block} eq 'on') { + $blockstatus = 'checked="true"'; + } + $r->print('
'); + } + $r->print(<<"END"); +
END $r->print(&Apache::loncommon::end_data_table_row()); @@ -1513,19 +1547,6 @@ END 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; @@ -1540,21 +1561,30 @@ sub display_addblocker_table { 'exam' => 'e.g., Exam 1', 'addn' => 'Add new communication blocking periods' ); + my ($typeorder,$types) = &blocktype_text(); $r->print(<<"END");

$lt{'addn'}

END $r->print(&Apache::loncommon::start_data_table()); $r->print(<<"END"); - $$ltext{'dura'} - $$ltext{'even'} $lt{'exam'} - $$ltext{'actn'}? + $ltext->{'dura'} + $ltext->{'even'} $lt{'exam'} + $ltext->{'blck'} + $ltext->{'actn'}? END - $r->print(&Apache::loncommon::start_data_table_row()); + $r->print(&Apache::loncommon::start_data_table_row()); $r->print(<<"END"); - $$ltext{'star'}: $startform
$$ltext{'endd'}:  $endform + $ltext->{'star'}: $startform
$ltext->{'endd'}:  $endform + +END + foreach my $block (@{$typeorder}) { + $r->print('
'); + } + $r->print(<<"END"); + END $r->print(&Apache::loncommon::end_data_table_row()); @@ -1562,86 +1592,16 @@ END return; } -sub blockcheck { - my ($setters,$startblock,$endblock) = @_; - # Retrieve active student roles and active course coordinator/instructor roles - 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); - - foreach my $course (keys(%live_courses)) { - my $cdom = $env{'course.'.$course.'.domain'}; - my $cnum = $env{'course.'.$course.'.num'}; - - # 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; - } - } - } - } -} - -sub build_block_table { - my ($r,$startblock,$endblock,$setters) = @_; - my %lt = &Apache::lonlocal::texthash( - 'cacb' => 'Currently active communication blocks', - 'cour' => 'Course/Group', - 'dura' => 'Duration', - 'blse' => 'Block set by' +sub blocktype_text { + my %types = &Apache::lonlocal::texthash( + 'com' => 'Messaging', + 'chat' => 'Chat', + 'boards' => 'Discussion', + 'port' => 'Portfolio', + 'groups' => 'Groups' ); - $r->print(<<"END"); -

$lt{'cacb'}:

-END - $r->print(&Apache::loncommon::start_data_table()); - $r->print(<<"END"); - - $lt{'cour'} - $lt{'dura'} - $lt{'blse'} - -END - foreach my $course (keys(%{$setters})) { - my %courseinfo=&Apache::lonnet::coursedescription($course); - for (my $i=0; $i<@{$$setters{$course}{staff}}; $i++) { - my ($uname,$udom) = @{$$setters{$course}{staff}[$i]}; - my $fullname = &Apache::loncommon::plainname($uname,$udom); - my ($openblock,$closeblock) = @{$$setters{$course}{times}[$i]}; - $openblock = &Apache::lonlocal::locallocaltime($openblock); - $closeblock= &Apache::lonlocal::locallocaltime($closeblock); - $r->print(&Apache::loncommon::start_data_table_row(). - ''.$courseinfo{'description'}.''. - ''.$openblock.' to '.$closeblock.''. - ''.$fullname.' ('.$uname.':'.$udom. - ')'. - &Apache::loncommon::end_data_table_row()); - } - } - $r->print(&Apache::loncommon::end_data_table()); + my $typeorder = ['com','chat','boards','port','groups']; + return ($typeorder,\%types); } # ----------------------------------------------------------- Display a message @@ -1651,13 +1611,11 @@ sub displaymessage { my $suffix=&Apache::lonmsg::foldersuffix($folder); my %blocked = (); my %setters = (); - my $startblock = 0; - my $endblock = 0; my $numblocked = 0; my $crstype = &Apache::loncommon::course_type(); # info to generate "next" and "previous" buttons and check if message is blocked - &blockcheck(\%setters,\$startblock,\$endblock); + my ($startblock,$endblock) = &Apache::loncommon::blockcheck(\%setters,'com'); my @messages=&sortedmessages(\%blocked,$startblock,$endblock,\$numblocked,$folder); if ( $blocked{$msgid} eq 'ON' ) { &printheader($r,'/adm/email',&mt('Display a Message')); @@ -1909,7 +1867,7 @@ sub sendoffmail { my ($rec,$txt) = ($line =~ /^([^:]+:[^:]+):(.*)$/); if ($txt) { $rec =~ s/^\s+//; - $rec =~ ~s/\s+$//; + $rec =~ s/\s+$//; $toaddr{$rec}.=$txt."\n"; } } @@ -2262,7 +2220,7 @@ sub handler { &storedcommentlisting($r); } else { &printheader($r,'','Display All Messages'); - &Apache::loncommunicate::menu($r); + &Apache::loncommunicate::menu($r); &disall($r,($folder?$folder:$dismode)); } $r->print(&Apache::loncommon::end_page());