--- loncom/interface/lonmsgdisplay.pm 2006/07/19 16:01:45 1.35.2.4 +++ loncom/interface/lonmsgdisplay.pm 2006/11/29 19:31:47 1.45 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Routines for messaging display # -# $Id: lonmsgdisplay.pm,v 1.35.2.4 2006/07/19 16:01:45 albertel Exp $ +# $Id: lonmsgdisplay.pm,v 1.45 2006/11/29 19:31:47 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -270,12 +270,14 @@ sub discourse { &Apache::lonselstudent::get_people_in_class($env{'request.course.sec'}); unshift @$current_members, (@$course_personnel); my %defaultUsers; + + $result .= ''."\n"; - $result = &Apache::lonselstudent::render_student_list($current_members, - "compemail", - "current", - \%defaultUsers, - 1,"selectedusers",1); + $result .= &Apache::lonselstudent::render_student_list($current_members, + "compemail", + "current", + \%defaultUsers, + 1,"selectedusers",1); $result .= &Apache::lonselstudent::render_student_list($expired_members, "compemail", @@ -484,8 +486,8 @@ sub discrit { ''; my %what=&Apache::lonnet::dump('critical'); my $result = ''; - foreach (sort keys %what) { - my %content=&Apache::lonmsg::unpackagemsg($what{$_}); + foreach my $key (sort(keys(%what))) { + my %content=&Apache::lonmsg::unpackagemsg($what{$key}); next if ($content{'senderdomain'} eq ''); $result.='
'.&mt('From').': '. &Apache::loncommon::aboutmewrapper( @@ -498,8 +500,8 @@ $content{'sendername'}.':'. ''. &mt('You have to confirm that you received this message. After confirmation, this message will be moved to your regular inbox'). '
'. - ''. - ''. + ''; } # Check to see if there were any messages. @@ -638,7 +640,7 @@ sub disnew { my %lt=&Apache::lonlocal::texthash( 'nm' => 'New Messages', 'su' => 'Subject', - 'co' => 'Course', + 'co' => 'Course/Group', 'da' => 'Date', 'us' => 'Username', 'op' => 'Open', @@ -647,17 +649,15 @@ 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; - foreach (@msgids) { - my $msgid=&escape($_); + foreach my $id (@msgids) { + my $msgid=&escape($id); my ($sendtime,$shortsubj,$fromname,$fromdom,$status,$fromcid)= &Apache::lonmsg::unpackmsgid($msgid,undef,undef,\%status_cache); if (defined($sendtime) && $sendtime!~/error/) { @@ -666,7 +666,7 @@ sub disnew { $sendtime = &Apache::lonlocal::locallocaltime($sendtime); if ($status eq 'new') { if ($numsendtime >= $startblock && ($numsendtime <= $endblock && $endblock > 0) ) { - $blocked{$_} = 'ON'; + $blocked{$id} = 'ON'; $numblocked ++; } else { push @newmsgs, { @@ -692,8 +692,8 @@ TABLEHEAD $lt{'op'} ENDLINK - foreach ('sendtime','from','fromdom','shortsub','course') { - $r->print("$msg->{$_}"); + foreach my $item ('sendtime','from','fromdom','shortsub','course') { + $r->print("$msg->{$item}"); } $r->print(""); } @@ -704,16 +704,10 @@ ENDLINK if ($numblocked > 0) { my $beginblock = &Apache::lonlocal::locallocaltime($startblock); my $finishblock = &Apache::lonlocal::locallocaltime($endblock); - if ($numblocked == 1) { - $r->print("

".&mt('You have').' '.$numblocked.' '.&mt('blocked unread message').".

"); - $r->print(&mt('This message is not viewable because').' '); - } else { - $r->print("

".&mt('You have').' '.$numblocked.' '.&mt('blocked unread messages').".

"); - $r->print(&mt('These').' '.$numblocked.' '.&mt('messages are not viewable because ')); - } - $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('

'.&mt('You have [quant,_1,blocked unread message,blocked unread messages].',$numblocked).'

'."\n". + &mt('[quant,_1,message is,messages are] not viewable because display of LON-CAPA messages sent to you by other students between [_2] and [_3] is currently being blocked because of online exams.',$numblocked,$beginblock,$finishblock).'
'."\n". + &Apache::loncommon::build_block_table($startblock,$endblock, + \%setters)); } } @@ -738,10 +732,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() { @@ -764,7 +756,7 @@ sub disfolder { ENDDISHEADER my $fsqs='&folder='.$folder; - my @temp=sortedmessages(\%blocked,$startblock,$endblock,\$numblocked,$folder); + my @temp=&sortedmessages(\%blocked,$startblock,$endblock,\$numblocked,$folder); my $totalnumber=$#temp+1; unless ($totalnumber>0) { $r->print('

'.&mt('Empty Folder').'

'); @@ -807,9 +799,9 @@ ENDDISHEADER } $r->print(''); if ($env{'form.sortedby'} eq "revcourse") { - $r->print(''.&mt('Course').''); + $r->print(''.&mt('Course/Group').''); } else { - $r->print(''.&mt('Course').''); + $r->print(''.&mt('Course/Group').''); } $r->print(''); if ($env{'form.sortedby'} eq "revstatus") { @@ -884,8 +876,9 @@ ENDDISHEADER my $beginblock = &Apache::lonlocal::locallocaltime($startblock); 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); + &mt('[_1,quant,message is, messages are] not viewable because display of LON-CAPA messages sent to you by other students between [_2] and [_3] is currently being blocked because of online exams.',$numblocked,$beginblock,$finishblock)); + $r->print(&Apache::loncommon::build_block_table($startblock,$endblock, + \%setters)); } } @@ -1037,7 +1030,7 @@ sub compout { my $latexHelp = Apache::loncommon::helpLatexCheatsheet(); if ($broadcast ne 'upload') { $r->print(<<"ENDCOMP"); -$lt{'ad'}
username\@domain,username\@domain, ... +$lt{'ad'}
username:domain,username:domain, ... $lt{'sb'}: @@ -1075,14 +1068,14 @@ Subject: The file format for the uploaded portion of the message is:
-username1\@domain1: text
-username2\@domain2: text
-username3\@domain1: text
+username1:domain1: text
+username2:domain2: text
+username3:domain1: text
 

The messages will be assembled from all lines with the respective -username\@domain, and appended to the general message text.

+username:domain, and appended to the general message text.

$dispcrit @@ -1133,8 +1126,8 @@ sub retrieve_instructor_comments { $env{'course.'.$env{'request.course.id'}.'.num'}, '%255b'.$user.'%253a'.$domain.'%255d'); my $result=''; - foreach (sort(keys(%records))) { - my %content=&Apache::lonmsg::unpackagemsg($records{$_}); + foreach my $key (sort(keys(%records))) { + my %content=&Apache::lonmsg::unpackagemsg($records{$key}); next if ($content{'senderdomain'} eq ''); next if ($content{'subject'} !~ /^Record/); # &Apache::lonfeedback::newline_to_br(\$content{'message'}); @@ -1161,8 +1154,8 @@ sub disfacetoface { $env{'course.'.$env{'request.course.id'}.'.num'}, '%255b'.$user.'%253a'.$domain.'%255d'); my $result=''; - foreach (sort keys %records) { - my %content=&Apache::lonmsg::unpackagemsg($records{$_}); + foreach my $key (sort(keys(%records))) { + my %content=&Apache::lonmsg::unpackagemsg($records{$key}); next if ($content{'senderdomain'} eq ''); &Apache::lonfeedback::newline_to_br(\$content{'message'}); if ($content{'subject'}=~/^Record/) { @@ -1309,8 +1302,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; @@ -1329,6 +1322,7 @@ sub examblock { 'dura' => 'Duration', 'setb' => 'Set by', 'even' => 'Event', + 'blck' => 'Blocked?', 'actn' => 'Action', 'star' => 'Start', 'endd' => 'End' @@ -1385,35 +1379,40 @@ sub blockstore { my $addtotal = 0; my %blocking = (); $r->print('

'.$lt{'head'}.'

'); - foreach (keys %env) { - if ($_ =~ m/^form\.modify_(\w+)$/) { + foreach my $envkey (keys(%env)) { + if ($envkey =~ m/^form\.modify_(\d+)$/) { $adds{$1} = $1; $removals{$1} = $1; $modtotal ++; - } elsif ($_ =~ m/^form\.cancel_(\d+)$/) { + } elsif ($envkey =~ m/^form\.cancel_(\d+)$/) { $cancels{$1} = $1; unless ( defined($removals{$1}) ) { $removals{$1} = $1; $canceltotal ++; } - } elsif ($_ =~ m/^form\.add_(\d+)$/) { + } elsif ($envkey =~ m/^form\.add_(\d+)$/) { $adds{$1} = $1; $addtotal ++; - } + } } - foreach (keys %removals) { - my $hashkey = $env{'form.key_'.$_}; + foreach my $key (keys(%removals)) { + my $hashkey = $env{'form.key_'.$key}; &Apache::lonnet::del('comm_block',["$hashkey"], $env{'course.'.$env{'request.course.id'}.'.domain'}, $env{'course.'.$env{'request.course.id'}.'.num'} ); } - foreach (keys %adds) { - unless ( defined($cancels{$_}) ) { - my ($newstart,$newend) = &get_dates_from_form($_); + foreach my $key (keys(%adds)) { + 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_'.$_}; + 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) { @@ -1464,6 +1463,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; @@ -1472,13 +1485,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}))) { @@ -1489,15 +1504,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()); @@ -1511,19 +1540,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; @@ -1538,21 +1554,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()); @@ -1560,86 +1585,17 @@ 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', - 'dura' => 'Duration', - 'blse' => 'Block set by' +sub blocktype_text { + my %types = &Apache::lonlocal::texthash( + 'com' => 'Messaging', + 'chat' => 'Chat', + 'boards' => 'Discussion', + 'port' => 'Portfolio', + 'groups' => 'Groups', + 'blogs' => 'Blogs', ); - $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','blogs']; + return ($typeorder,\%types); } # ----------------------------------------------------------- Display a message @@ -1649,13 +1605,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')); @@ -1788,7 +1742,7 @@ sub header { my $extra = &Apache::loncommon::studentbrowser_javascript(); if ($baseurl) { - $extra .= ""; + $extra .= ""; } $r->print(&Apache::loncommon::start_page('Communication and Messages', $extra)); @@ -1812,9 +1766,9 @@ sub storecomment { my ($r)=@_; my $msgtxt=&Apache::lonfeedback::clear_out_html($env{'form.message'}); my $cleanmsgtxt=''; - foreach (split(/[\n\r]/,$msgtxt)) { - unless ($_=~/^\s*(\>|\>\;)/) { - $cleanmsgtxt.=$_."\n"; + foreach my $line (split(/[\n\r]/,$msgtxt)) { + unless ($line=~/^\s*(\>|\>\;)/) { + $cleanmsgtxt.=$line."\n"; } } my $key=&escape($env{'form.baseurl'}).'___'.time; @@ -1831,8 +1785,8 @@ sub storedcommentlisting { $r->print(&mt('No stored comments yet.')); } else { my $found=0; - foreach (sort keys %msgs) { - $r->print("\n".$msgs{$_}."
"); + foreach my $key (sort(keys(%msgs))) { + $r->print("\n".$msgs{$key}."
"); $found=1; } unless ($found) { @@ -1904,9 +1858,10 @@ sub sendoffmail { } } elsif ($env{'form.sendmode'} eq 'upload') { foreach my $line (split(/[\n\r\f]+/,$env{'form.upfile'})) { - my ($rec,$txt)=split(/\s*\:\s*/,$line); + my ($rec,$txt) = ($line =~ /^([^:]+:[^:]+):(.*)$/); if ($txt) { - $rec=~s/\@/\:/; + $rec =~ s/^\s+//; + $rec =~ s/\s+$//; $toaddr{$rec}.=$txt."\n"; } } @@ -1916,8 +1871,8 @@ sub sendoffmail { } } if ($env{'form.additionalrec'}) { - foreach (split(/\,/,$env{'form.additionalrec'})) { - my ($auname,$audom)=split(/\@/,$_); + foreach my $rec (split(/\,/,$env{'form.additionalrec'})) { + my ($auname,$audom)=split(/:/,$rec); if (($auname ne "") && ($audom ne "")) { $toaddr{$auname.':'.$audom}=''; } @@ -2138,12 +2093,12 @@ sub handler { } elsif ($env{'form.confirm'}) { &printheader($r,'','Confirmed Receipt'); my $replying = 0; - foreach (keys %env) { - if ($_=~/^form\.rec\_(.*)$/) { + foreach my $envkey (keys(%env)) { + if ($envkey=~/^form\.rec\_(.*)$/) { $r->print(''.&mt('Confirming Receipt').': '. &Apache::lonmsg::user_crit_received($1).'
'); } - if ($_=~/^form\.reprec\_(.*)$/) { + if ($envkey=~/^form\.reprec\_(.*)$/) { my $msgid=$1; $r->print(''.&mt('Confirming Receipt').': '. &Apache::lonmsg::user_crit_received($msgid).'
'); @@ -2259,7 +2214,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());