--- loncom/interface/lonmsgdisplay.pm 2006/10/04 20:26:48 1.41 +++ 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.41 2006/10/04 20:26:48 albertel Exp $ +# $Id: lonmsgdisplay.pm,v 1.44 2006/11/29 07:46:39 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -486,8 +486,8 @@ sub discrit { '<input type="hidden" name="confirm" value="true" />'; 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.='<hr />'.&mt('From').': <b>'. &Apache::loncommon::aboutmewrapper( @@ -500,8 +500,8 @@ $content{'sendername'}.':'. '</pre><small>'. &mt('You have to confirm that you received this message. After confirmation, this message will be moved to your regular inbox'). '</small><br />'. - '<input type="submit" name="rec_'.$_.'" value="'.&mt('Confirm Receipt').'" />'. - '<input type="submit" name="reprec_'.$_.'" '. + '<input type="submit" name="rec_'.$key.'" value="'.&mt('Confirm Receipt').'" />'. + '<input type="submit" name="reprec_'.$key.'" '. 'value="'.&mt('Confirm Receipt and Reply').'" />'; } # Check to see if there were any messages. @@ -649,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/) { @@ -668,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, { @@ -694,8 +692,8 @@ TABLEHEAD <tr class="LC_mail_new"> <td><a href="/adm/email?dismode=new&display=$msg->{'msgid'}">$lt{'op'}</a></td> ENDLINK - foreach ('sendtime','from','fromdom','shortsub','course') { - $r->print("<td>$msg->{$_}</td>"); + foreach my $item ('sendtime','from','fromdom','shortsub','course') { + $r->print("<td>$msg->{$item}</td>"); } $r->print("</td></tr>"); } @@ -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(<<ENDDISHEADER); <script type="text/javascript"> function checkall() { @@ -766,7 +763,7 @@ sub disfolder { </script> 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('<h2>'.&mt('Empty Folder').'</h2>'); @@ -887,7 +884,8 @@ ENDDISHEADER my $finishblock = &Apache::lonlocal::locallocaltime($endblock); $r->print('<br /><br />'. $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)); } } @@ -1039,7 +1037,7 @@ sub compout { my $latexHelp = Apache::loncommon::helpLatexCheatsheet(); if ($broadcast ne 'upload') { $r->print(<<"ENDCOMP"); -<tr><td>$lt{'ad'}<br /><tt>username\@domain,username\@domain, ... +<tr><td>$lt{'ad'}<br /><tt>username:domain,username:domain, ... </tt></td><td> <input type="text" size="50" name="additionalrec" /></td></tr> <tr><td>$lt{'sb'}:</td><td><input type="text" size="50" name="subject" value="$dissub" /> @@ -1077,14 +1075,14 @@ Subject: <input type="text" size="50" na <p> The file format for the uploaded portion of the message is: <pre> -username1\@domain1: text -username2\@domain2: text -username3\@domain1: text +username1:domain1: text +username2:domain2: text +username3:domain1: text </pre> </p> <p> The messages will be assembled from all lines with the respective -<tt>username\@domain</tt>, and appended to the general message text.</p> +<tt>username:domain</tt>, and appended to the general message text.</p> <p> <input type="file" name="upfile" size="40" /></p><p> $dispcrit @@ -1135,8 +1133,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'}); @@ -1163,8 +1161,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/) { @@ -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' @@ -1387,35 +1386,40 @@ sub blockstore { my $addtotal = 0; my %blocking = (); $r->print('<h3>'.$lt{'head'}.'</h3>'); - 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) { @@ -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"); <tr> - <th>$$ltext{'dura'}</th> - <th>$$ltext{'setb'}</th> - <th>$$ltext{'even'}</th> - <th>$$ltext{'actn'}?</th> + <th>$ltext->{'dura'}</th> + <th>$ltext->{'setb'}</th> + <th>$ltext->{'even'}</th> + <th>$ltext->{'blck'}</th> + <th>$ltext->{'actn'}?</th> </tr> 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"); - <td>$$ltext{'star'}: $startform<br/>$$ltext{'endd'}: $endform</td> + <td>$ltext->{'star'}: $startform<br/>$ltext->{'endd'}: $endform</td> <td>$settername</td> <td><input type="text" name="title_$parmcount" size="15" value="$title" /><input type="hidden" name="key_$parmcount" value="$record" /></td> + <td> +END + foreach my $block (@{$typeorder}) { + my $blockstatus = ''; + if ($blocks->{$block} eq 'on') { + $blockstatus = 'checked="true"'; + } + $r->print('<label><input type="checkbox" name="'.$block.'_'.$parmcount.'" '.$blockstatus.' value="1" />'.$types->{$block}.'</label><br />'); + } + $r->print(<<"END"); + </td> <td><label>$lt{'modi'}? <input type="checkbox" name="modify_$parmcount" /></label><br /><label>$lt{'canc'}? <input type="checkbox" name="cancel_$parmcount" /></label> 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"); <h4>$lt{'addn'}</h4> END $r->print(&Apache::loncommon::start_data_table()); $r->print(<<"END"); <tr> - <th>$$ltext{'dura'}</th> - <th>$$ltext{'even'} $lt{'exam'}</th> - <th>$$ltext{'actn'}?</th> + <th>$ltext->{'dura'}</th> + <th>$ltext->{'even'} $lt{'exam'}</th> + <th>$ltext->{'blck'}</th> + <th>$ltext->{'actn'}?</th> </tr> END - $r->print(&Apache::loncommon::start_data_table_row()); + $r->print(&Apache::loncommon::start_data_table_row()); $r->print(<<"END"); - <td>$$ltext{'star'}: $startform<br />$$ltext{'endd'}: $endform</td> + <td>$ltext->{'star'}: $startform<br />$ltext->{'endd'}: $endform</td> <td><input type="text" name="title_$parmcount" size="15" value="" /></td> + <td> +END + foreach my $block (@{$typeorder}) { + $r->print('<label><input type="checkbox" name="'.$block.'_'.$parmcount.'" value="1" />'.$types->{$block}.'</label><br />'); + } + $r->print(<<"END"); + </td> <td><label>$lt{'addb'}? <input type="checkbox" name="add_$parmcount" value="1" /></label></td> 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"); -<br /><br />$lt{'cacb'}:<br /><br /> -END - $r->print(&Apache::loncommon::start_data_table()); - $r->print(<<"END"); -<tr> - <th>$lt{'cour'}</th> - <th>$lt{'dura'}</th> - <th>$lt{'blse'}</th> -</tr> -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(). - '<td>'.$courseinfo{'description'}.'</td>'. - '<td>'.$openblock.' to '.$closeblock.'</td>'. - '<td>'.$fullname.' ('.$uname.':'.$udom. - ')</td>'. - &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')); @@ -1814,9 +1772,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; @@ -1833,8 +1791,8 @@ sub storedcommentlisting { $r->print(&mt('No stored comments yet.')); } else { my $found=0; - foreach (sort keys %msgs) { - $r->print("\n".$msgs{$_}."<hr />"); + foreach my $key (sort(keys(%msgs))) { + $r->print("\n".$msgs{$key}."<hr />"); $found=1; } unless ($found) { @@ -1906,9 +1864,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"; } } @@ -1918,8 +1877,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}=''; } @@ -2140,12 +2099,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('<b>'.&mt('Confirming Receipt').':</b> '. &Apache::lonmsg::user_crit_received($1).'<br>'); } - if ($_=~/^form\.reprec\_(.*)$/) { + if ($envkey=~/^form\.reprec\_(.*)$/) { my $msgid=$1; $r->print('<b>'.&mt('Confirming Receipt').':</b> '. &Apache::lonmsg::user_crit_received($msgid).'<br>'); @@ -2261,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());