--- loncom/interface/lonmsgdisplay.pm 2010/05/29 23:19:52 1.151 +++ loncom/interface/lonmsgdisplay.pm 2011/12/28 21:49:54 1.159 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Routines for messaging display # -# $Id: lonmsgdisplay.pm,v 1.151 2010/05/29 23:19:52 raeburn Exp $ +# $Id: lonmsgdisplay.pm,v 1.159 2011/12/28 21:49:54 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -110,7 +110,7 @@ use Apache::lonfeedback; use Apache::lonrss(); use Apache::lonselstudent(); use lib '/home/httpd/lib/perl/'; -use LONCAPA; +use LONCAPA qw(:DEFAULT :match); # Querystring component with sorting type my $sqs=''; @@ -225,18 +225,18 @@ function folder_choice(targetform,caller '); } $r->print('
'.$lt{'fold'}.'
'."\n". - &Apache::loncommon::select_form($folder,'folder',%formhash).' + &Apache::loncommon::select_form($folder,'folder',\%formhash).'
'.$lt{'show'}.'
'."\n". &Apache::loncommon::select_form($env{'form.interdis'},'interdis', - %show).' + \%show).'
'.$lt{'status'}.'
'."\n". - &Apache::loncommon::select_form($msgstatus,'msgstatus',%statushash).' + &Apache::loncommon::select_form($msgstatus,'msgstatus',\%statushash).'
'.$lt{'actn'}.'
'."\n".' '. - &Apache::loncommon::select_form('view','folderaction',%actions). + &Apache::loncommon::select_form('view','folderaction',\%actions). ' @@ -626,9 +626,7 @@ sub disgroup { return; } else { $hasfloat = 1; - unless($env{'environment.wysiwygeditor'} eq 'on') { - $r->print('
'); - } + $r->print('
'); my %Sortby = ( active => {}, previous => {}, @@ -701,9 +699,7 @@ sub disgroup { } } } - unless($env{'environment.wysiwygeditor'} eq 'on') { - $r->print('
'); - } + $r->print('
'); } return $hasfloat; } @@ -818,6 +814,15 @@ sub discrit { foreach my $key (sort(keys(%what))) { my %content=&Apache::lonmsg::unpackagemsg($what{$key}); next if ($content{'senderdomain'} eq ''); + my $description; + if ($content{'courseid'} ne '') { + if ($content{'courseid'} =~ m{/^$match_domain\_$match_courseid$}) { + my %courseinfo=&Apache::lonnet::coursedescription($content{'courseid'},{'one_time' => 1}); + if ($courseinfo{'description'} ne '') { + $description = $courseinfo{'description'}; + } + } + } $result .= &Apache::lonhtmlcommon::start_pick_box() .&Apache::lonhtmlcommon::row_title(&mt('From'),undef,'LC_oddrow_value') .''.&Apache::loncommon::aboutmewrapper( @@ -829,8 +834,13 @@ sub discrit { .&Apache::lonhtmlcommon::row_closure(1) .&Apache::lonhtmlcommon::row_title(&mt('Subject'),undef,'LC_oddrow_value') .$content{'subject'} - .&Apache::lonhtmlcommon::row_closure(1) - .&Apache::lonhtmlcommon::row_title(&mt('Message'),undef,'LC_evenrow_value') + .&Apache::lonhtmlcommon::row_closure(1); + if ($description ne '') { + $result .= &Apache::lonhtmlcommon::row_title(&mt('Course'),undef,'LC_oddrow_value') + .$description + .&Apache::lonhtmlcommon::row_closure(1); + } + $result .= &Apache::lonhtmlcommon::row_title(&mt('Message'),undef,'LC_evenrow_value') .'
'.&Apache::lontexconvert::msgtexconverted($content{'message'}).'
' .&Apache::lonhtmlcommon::row_closure() .&Apache::lonhtmlcommon::row_title('',undef,'LC_oddrow_value') @@ -985,10 +995,15 @@ sub get_course_desc { if (defined($env{'course.'.$fromcid.'.description'})) { $description = $env{'course.'.$fromcid.'.description'}; } else { - my %courseinfo=&Apache::lonnet::coursedescription($fromcid); - $description = $courseinfo{'description'}; + if ($fromcid =~ m{/^$match_domain\_$match_courseid$}) { + my %courseinfo=&Apache::lonnet::coursedescription($fromcid, + {'one_time' => 1}); + $description = $courseinfo{'description'}; + } + } + if ($description ne '') { + $$descriptions{$fromcid} = $description; } - $$descriptions{$fromcid} = $description; } return $description; } @@ -1257,7 +1272,7 @@ ENDDISHEADER $userfolders{$key} = $key; } $userfolders{''} = ""; - $r->print(&Apache::loncommon::select_form('','movetofolder',%userfolders). + $r->print(&Apache::loncommon::select_form('','movetofolder',\%userfolders). '
'. @@ -1423,11 +1438,7 @@ sub compout { if ($group eq '') { my $studentsel = &discourse(\%access_status); if ($studentsel) { - if ($env{'environment.wysiwygeditor'} eq 'on') { - $r->print($studentsel); - } else { - $r->print('
'.$studentsel.'
'); - } + $r->print('
'.$studentsel.'
'); $hasfloat = 1; } } else { @@ -1523,11 +1534,7 @@ ENDREPSCRIPT if ($env{'form.text'}) { $dismsg=$env{'form.text'}; } if ($env{'form.subject'}) { $dissub=$env{'form.subject'}; } if ($hasfloat) { - if ($env{'environment.wysiwygeditor'} eq 'on') { - $r->print($broadcast_js); - } else { - $r->print($broadcast_js.'
'); - } + $r->print($broadcast_js.'
'); $onsubmit = ' onsubmit="javascript:courseRecipients();" '; } $r->print( @@ -1637,7 +1644,11 @@ ENDREPSCRIPT } } my $latexHelp = &Apache::loncommon::helpLatexCheatsheet(undef,undef,1); - my $wysiwyglink=&Apache::lonhtmlcommon::htmlareaselectactive('message').'
'; + my $textareaclass; + if (&Apache::lonhtmlcommon::htmlareabrowser()) { + $r->print(&Apache::lonhtmlcommon::htmlareaselectactive()); + $textareaclass = 'class="LC_richDefaultOff"'; + } my $subj_size; if ($multiforward) { $r->print(&additional_rec_row(\%lt)); @@ -1659,8 +1670,7 @@ ENDREPSCRIPT
'."\n". $latexHelp."
\n". &mt("Any new text to display before the text of the original messages:").'
'."\n". -''. -$wysiwyglink); +''); my @to_forward = &Apache::loncommon::get_env_multiple('form.delmark'); foreach my $msg (@to_forward) { $r->print(''); @@ -1680,8 +1690,9 @@ $wysiwyglink); $attachrow

$latexHelp
-$wysiwyglink + +
$sendmode $dispcrit $disbase @@ -1706,8 +1717,8 @@ ENDCOMP Subject:

$lt{'gmt'}:
-$wysiwyglink

+

$lt{'tff'}: ENDBLOCK @@ -1733,9 +1744,7 @@ ENDUPLOAD } $r->print(''); if ($hasfloat) { - unless($env{'environment.wysiwygeditor'} eq 'on') { - $r->print('

'); - } + $r->print(''); } $r->print(&generate_preview_form); } @@ -2048,317 +2057,6 @@ ENDBFORM } } -# ----------------------------------------------------------- Blocking during exams - -sub examblock { - my ($r,$action) = @_; - unless ($env{'request.course.id'}) { return;} - 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; - } - my $usertype; - my $crstype = &Apache::loncommon::course_type(); - if ($crstype eq 'Community') { - $usertype = 'members'; - } else { - $usertype = 'students'; - } - my $lctype = lc($crstype); - my %lt=&Apache::lonlocal::texthash( - 'comb' => 'Communication Blocking', - 'cbds' => 'Communication blocking during scheduled exams', - 'desc' => "You can use communication blocking to prevent $usertype enrolled in this $lctype from displaying LON-CAPA messages sent by other $usertype during an online exam. As blocking of communication could potentially interrupt legitimate communication between $usertype who are also both enrolled in a different LON-CAPA course or community, please be careful that you select the correct start and end times for your scheduled exam when setting or modifying these parameters.", - 'mecb' => 'Modify existing communication blocking periods', - 'ncbc' => 'No communication blocks currently saved', - 'stor' => 'Save', - ); - - my %ltext = &Apache::lonlocal::texthash( - 'dura' => 'Duration', - 'setb' => 'Set by', - 'even' => 'Event', - 'blck' => 'Blocked?', - 'actn' => 'Action', - 'star' => 'Start', - 'endd' => 'End' - ); - - &printheader($r,'/adm/email?block=display',$lt{'comb'}); - $r->print('

'.$lt{'cbds'}.'

'); - - if ($action eq 'store') { - &blockstore($r); - } - - $r->print($lt{'desc'}.'

-
- '); - - $r->print('

'.$lt{'mecb'}.'

'); - my %records = (); - my $blockcount = 0; - my $parmcount = 0; - &get_blockdates(\%records,\$blockcount); - if ($blockcount > 0) { - $parmcount = &display_blocker_status($r,\%records,\%ltext); - } else { - $r->print($lt{'ncbc'}.'

'); - } - &display_addblocker_table($r,$parmcount,\%ltext); - my $end_page=&Apache::loncommon::end_page(); - $r->print(<<"END"); -
- - -
-$end_page -END - return; -} - -sub blockstore { - my $r = shift; - my %lt=&Apache::lonlocal::texthash( - 'tfcm' => 'The following changes were made', - 'ncwm' => 'No changes were made.' - ); - my %adds = (); - my %removals = (); - my %cancels = (); - my $modtotal = 0; - my $canceltotal = 0; - my $addtotal = 0; - my %blocking = (); - $r->print('

'.$lt{'head'}.'

'); - foreach my $envkey (keys(%env)) { - if ($envkey =~ m/^form\.modify_(\d+)$/) { - $adds{$1} = $1; - $removals{$1} = $1; - $modtotal ++; - } elsif ($envkey =~ m/^form\.cancel_(\d+)$/) { - $cancels{$1} = $1; - unless ( defined($removals{$1}) ) { - $removals{$1} = $1; - $canceltotal ++; - } - } elsif ($envkey =~ m/^form\.add_(\d+)$/) { - $adds{$1} = $1; - $addtotal ++; - } - } - - 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 my $key (keys(%adds)) { - unless ( defined($cancels{$key}) ) { - my ($newstart,$newend) = &get_dates_from_form($key); - my $newkey = $newstart.'____'.$newend; - 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) { - &Apache::lonnet::put('comm_block',\%blocking, - $env{'course.'.$env{'request.course.id'}.'.domain'}, - $env{'course.'.$env{'request.course.id'}.'.num'} - ); - } - my $chgestotal = $canceltotal + $modtotal + $addtotal; - if ($chgestotal > 0) { - $r->print($lt{'tfcm'}.''); - } else { - $r->print($lt{'ncwm'}); - } - $r->print('
'); - return; -} - -sub get_dates_from_form { - my $item = shift; - my $startdate = &Apache::lonhtmlcommon::get_date_from_form('startdate_'.$item); - my $enddate = &Apache::lonhtmlcommon::get_date_from_form('enddate_'.$item); - return ($startdate,$enddate); -} - -sub get_blockdates { - my ($records,$blockcount) = @_; - $$blockcount = 0; - %{$records} = &Apache::lonnet::dump('comm_block', - $env{'course.'.$env{'request.course.id'}.'.domain'}, - $env{'course.'.$env{'request.course.id'}.'.num'} - ); - $$blockcount = keys(%{$records}); - - if ((keys(%{$records}))[0] =~ /^error: 2 /) { - $records = {}; - $$blockcount = 0; - } -} - -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; - - my %lt = &Apache::lonlocal::texthash( - '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->{'blck'} - $ltext->{'actn'} - -END - foreach my $record (sort(keys(%{$records}))) { - my $onchange = 'onFocus="javascript:window.document.forms['. - "'blockform'].elements['modify_".$parmcount."'].". - 'checked=true;"'; - my ($start,$end) = split(/____/,$record); - 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,$blocks) = - &Apache::loncommon::parse_block_record($$records{$record}); - $title = &HTML::Entities::encode($title,'"<>&'); - 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 - $settername - - -END - foreach my $block (@{$typeorder}) { - my $blockstatus = ''; - if ($blocks->{$block} eq 'on') { - $blockstatus = 'checked="checked"'; - } - $r->print('
'); - } - $r->print(<<"END"); - -
- -END - $r->print(&Apache::loncommon::end_data_table_row()); - $parmcount++; - } - $r->print(<<"END"); - -
-
-END - return $parmcount; -} - -sub display_addblocker_table { - my ($r,$parmcount,$ltext) = @_; - my $start = time; - my $end = $start + (60 * 60 * 2); #Default is an exam of 2 hours duration. - my $onchange = 'onFocus="javascript:window.document.forms['. - "'blockform'].elements['add_".$parmcount."'].". - 'checked=true;"'; - my $startform = &Apache::lonhtmlcommon::date_setter('blockform','startdate_'.$parmcount,$start,$onchange); - my $endform = &Apache::lonhtmlcommon::date_setter('blockform','enddate_'.$parmcount,$end,$onchange); - my %lt = &Apache::lonlocal::texthash( - 'addb' => 'Add block', - '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->{'blck'} - $ltext->{'actn'} - -END - $r->print(&Apache::loncommon::start_data_table_row()); - $r->print(<<"END"); - $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()); - $r->print(&Apache::loncommon::end_data_table()); - return; -} - -sub blocktype_text { - my %types = &Apache::lonlocal::texthash( - 'com' => 'Messaging', - 'chat' => 'Chat Room', - 'boards' => 'Discussion', - 'port' => 'Portfolio', - 'groups' => 'Groups', - 'blogs' => 'Blogs', - ); - my $typeorder = ['com','chat','boards','port','groups','blogs']; - return ($typeorder,\%types); -} - # ----------------------------------------------------------- Display a message sub displaymessage { @@ -2375,7 +2073,6 @@ sub displaymessage { if ( $blocked{$msgid} eq 'ON' ) { &printheader($r,'/adm/email',&mt('Display a Message')); #$r->print(&mt('You attempted to display a message that is currently blocked because you are enrolled in one or more courses for which there is an ongoing online exam.')); - #&build_block_table($r,$startblock,$endblock,\%setters); my($blocked, $blocktext) = &Apache::loncommon::blocking_status("com"); $r->print("
".$blocktext); return; @@ -2412,7 +2109,6 @@ sub displaymessage { my $number_of_messages = scalar(@messages); #subtract 1 for last index # start output &printheader($r,'/adm/email?display='.&escape($msgid),'Display a Message','',$content{'baseurl'}); - my %courseinfo=&Apache::lonnet::coursedescription($content{'courseid'}); # Prepare available functions my @functionlist; @@ -2656,12 +2352,14 @@ sub displaymessage { } if ($content{'group'} ne '') { if (&check_group_priv($content{'group'})) { - $groupcclist = join(', ',@{$recipients{'group_cc_broadcast'}}); - if ($groupcclist) { - $r->print(&Apache::lonhtmlcommon::row_title(&mt('Group Cc')) - .$groupcclist - .&Apache::lonhtmlcommon::row_closure() - ); + if (ref($recipients{'group_cc_broadcast'}) eq 'ARRAY') { + $groupcclist = join(', ',@{$recipients{'group_cc_broadcast'}}); + if ($groupcclist) { + $r->print(&Apache::lonhtmlcommon::row_title(&mt('Group Cc')) + .$groupcclist + .&Apache::lonhtmlcommon::row_closure() + ); + } } } } @@ -2669,14 +2367,22 @@ sub displaymessage { } # Course - if ($content{'courseid'}) { - $r->print(&Apache::lonhtmlcommon::row_title(&mt($crstype)) - .$courseinfo{'description'} - ); - if ($content{'coursesec'}) { - $r->print(' ('.&mt('Section').': '.$content{'coursesec'}.')'); + if ($content{'courseid'} ne '') { + if ($content{'courseid'} =~ m{^$match_domain\_$match_courseid$}) { + my %courseinfo; + %courseinfo=&Apache::lonnet::coursedescription($content{'courseid'}, + {'one_time' => 1}); + my $description = $courseinfo{'description'}; + if ($description ne '') { + $r->print(&Apache::lonhtmlcommon::row_title(&mt($crstype)) + .$description + ); + if ($content{'coursesec'}) { + $r->print(' ('.&mt('Section').': '.$content{'coursesec'}.')'); + } + $r->print(&Apache::lonhtmlcommon::row_closure()); + } } - $r->print(&Apache::lonhtmlcommon::row_closure()); } $r->print(&Apache::lonhtmlcommon::row_title(&mt('Time')) .$content{'time'} @@ -3310,6 +3016,9 @@ sub sendoffmail { $r->print($message); } } + } else { + &printheader($r,'','Messages cancelled.'); + return 'cancelled'; } return $sendstatus; } @@ -3330,15 +3039,13 @@ sub handler { &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['display','replyto','forward','markread','markdel','markunread', 'sendreply','compose','sendmail','critical','recname','recdom', - 'recordftf','sortedby','block','folder','startdis','interdis', + 'recordftf','sortedby','folder','startdis','interdis', 'showcommentbaseurl','dismode','group','subject','text','ref', 'msgstatus']); $sqs='&sortedby='.$env{'form.sortedby'}; # ------------------------------------------------------ They checked for email - unless ($env{'form.block'}) { - &Apache::lonnet::put('email_status',{'recnewemail'=>0}); - } + &Apache::lonnet::put('email_status',{'recnewemail'=>0}); # ----------------------------------------------------------------- Breadcrumbs @@ -3541,8 +3248,6 @@ sub handler { &compout($r,'','',$env{'form.compose'}); } elsif ($env{'form.recordftf'}) { &facetoface($r,$env{'form.recordftf'}); - } elsif ($env{'form.block'}) { - &examblock($r,$env{'form.block'}); } elsif ($env{'form.sendmail'}) { if ($env{'form.multiforward'}) { &printheader($r,'','Messages being sent.');