--- loncom/interface/lonnotify.pm 2005/12/09 20:54:26 1.10 +++ loncom/interface/lonnotify.pm 2006/05/30 12:46:09 1.19 @@ -34,6 +34,8 @@ use Apache::lonlocal; use Mail::Send; use HTML::TokeParser; use HTML::Entities; +use lib '/home/httpd/lib/perl/'; +use LONCAPA; sub handler { my ($r) = @_; @@ -56,49 +58,78 @@ sub handler { my $origin = $env{'form.origin'}; &Apache::lonhtmlcommon::clear_breadcrumbs(); - my %ltext=&Apache::lonlocal::texthash( - 'note' => 'Notification E-mail', - ); + my $function = &Apache::loncommon::get_users_function(); - my $loadcode; my $tablecolor = &Apache::loncommon::designparm($function.'.tabbg'); - if ((defined($env{'form.origin'})) && ($command eq 'compose' || $command eq 'pick_target' || $command eq 'pick_display')) { - unless ($env{'form.origin'} eq '') { - $loadcode = 'javascript:setFormElements(document.'.$env{'form.command'}.')'; - if (($command eq 'pick_target') && ( - ($origin eq 'compose') || ($origin eq 'process'))) { - if ($env{'form.coursepick'} eq 'category') { - $loadcode .= ';javascript:setCourseCat(document.'.$env{'form.command'}.')'; - } - } - } - } - my $loaditems = ' onLoad="'.$loadcode.'" '; - my $bodytag = &Apache::loncommon::bodytag('Broadcast e-mail to users',$function,$loaditems); - my $html=&Apache::lonxml::xmlbegin(); + &Apache::lonhtmlcommon::add_breadcrumb ({href=>'/adm/notify', text=>"Broadcast E-mail"}); if ($command eq 'process') { - &print_request_receipt($r,$command,$cdom,$tablecolor,$bodytag,$html,\%ltext); + &print_request_receipt($r,$command,$cdom,$tablecolor); } elsif ($command eq 'compose') { - &print_composition_form($r,$command,$cdom,$tablecolor,$bodytag,$html,\%ltext); + &print_composition_form($r,$command,$cdom,$tablecolor); } elsif ($command eq 'pick_target') { - &print_selection_form($r,$command,$cdom,$tablecolor,$bodytag,$html,\%ltext); + &print_selection_form($r,$command,$cdom,$tablecolor); } elsif ($command eq 'pick_display') { - &print_display_option_form($r,$command,$cdom,$tablecolor,$bodytag,$html,\%ltext); + &print_display_option_form($r,$command,$cdom,$tablecolor); } elsif ($command eq 'display') { - &print_display($r,$command,$cdom,$tablecolor,$bodytag,$html,\%ltext); + &print_display($r,$command,$cdom,$tablecolor); } else { - &print_front_page($r,'front',$cdom,$tablecolor,$bodytag,$html,\%ltext); + &print_front_page($r,'front',$cdom,$tablecolor); } return OK; } +sub add_script { + my ($js) = @_; + return ''; +} + +sub start_page { + my ($jscript,$bread_title,$formname) = @_; + + my $loadcode; + if ((defined($env{'form.origin'})) + && ($env{'form.command'} eq 'compose' + || $env{'form.command'} eq 'pick_target' + || $env{'form.command'} eq 'pick_display')) { + if ($env{'form.origin'} ne '') { + $loadcode = 'javascript:setFormElements(document.'.$env{'form.command'}.')'; + if (($env{'form.command'} eq 'pick_target') + && (($env{'form.origin'} eq 'compose') + || ($env{'form.origin'} eq 'process'))) { + if ($env{'form.coursepick'} eq 'category') { + $loadcode .= ';javascript:setCourseCat(document.'.$env{'form.command'}.')'; + } + } + } + } + + my $start_page = + &Apache::loncommon::start_page('Broadcast e-mail to users', $jscript, + {'add_entries' => + {'onload' => $loadcode,},}); + my $breadcrumbs = + &Apache::lonhtmlcommon::breadcrumbs($bread_title, + 'Broadcast_system_email'); + my $output = <<"ENDONE"; +$start_page +$breadcrumbs +
+
+ENDONE + + return $output; +} + +sub end_page { + return '
'.&Apache::loncommon::end_page(); +} + sub print_front_page { - my ($r,$formname,$cdom,$tablecolor,$bodytag,$html,$ltext) = @_; - my $breadcrumbs = &Apache::lonhtmlcommon::breadcrumbs - (undef,'Broadcast e-mail to Domain','Broadcast_system_email'); + my ($r,$formname,$cdom,$tablecolor) = @_; + my $jscript = qq| function next_page(caller) { if (caller == 'view') { @@ -110,23 +141,11 @@ function next_page(caller) { document.front.submit() } |; - my %lt=&Apache::lonlocal::texthash( - 'note' => 'Notification E-mail', - ); - my $output = <<"ENDONE"; -$html - - LON-CAPA $lt{'note'} - - -$bodytag -$breadcrumbs -
-ENDONE - $output .= '
'. - ''; + + my $output = &start_page(&add_script($jscript), + 'Broadcast e-mail to Domain', $formname); + + $output .= ''; $output .= &Apache::lonhtmlcommon::start_pick_box(); $output .= ''. '
'. @@ -135,29 +154,23 @@ ENDONE 'Display e-mail sent by Domain Coordinators in this domain'. '
'; $output .= &Apache::lonhtmlcommon::end_pick_box(); - $output .= qq( -
- -); + $output .= &end_page(); + $r->print($output); return; } sub print_display_option_form { - my ($r,$formname,$cdom,$tablecolor,$bodytag,$html,$ltext) = @_; - &Apache::lonhtmlcommon::add_breadcrumb - ({text=>"Display options"}); - my $breadcrumbs = &Apache::lonhtmlcommon::breadcrumbs - (undef,'Broadcast e-mail display options','Broadcast_system_email'); + my ($r,$formname,$cdom,$tablecolor) = @_; + &Apache::lonhtmlcommon::add_breadcrumb({text=>"Display options"}); + my $table_width = ''; my $col_width = '200'; my $cmd = 'display'; my $submit_text = 'Display e-mail'; my @roles = ('dc'); my $now = time; - my %lt=&Apache::lonlocal::texthash( - 'note' => 'Notification E-mail', - ); + my $startdateform = &Apache::lonhtmlcommon::date_setter($formname, 'startdate', $now); @@ -180,19 +193,10 @@ sub print_display_option_form { sender => 'checkbox', ); my $jscript = &Apache::lonhtmlcommon::set_form_elements(\%elements); - my $output = <<"ENDONE"; -$html - - LON-CAPA $lt{'note'} - - -$bodytag -$breadcrumbs -
-
-ENDONE + + my $output = &start_page(&add_script($jscript), + 'Broadcast e-mail display options', $formname); + $output .= &Apache::lonhtmlcommon::start_pick_box($table_width); $output .= &Apache::lonhtmlcommon::row_title($col_width,$tablecolor,&mt('Date range')); $output .= ''."\n"; $rowNum ++; @@ -374,16 +366,13 @@ ENDONE $output .= qq(\n); $output .= qq(\n); $output .= qq(\n); - $output .= qq( - -); + $output .= &end_page(); $r->print($output); return; } sub print_selection_form { - my ($r,$formname,$cdom,$tablecolor,$bodytag,$html,$ltext) = @_; + my ($r,$formname,$cdom,$tablecolor) = @_; my %coursecodes = (); my %codes = (); my @codetitles = (); @@ -399,7 +388,6 @@ sub print_selection_form { my $table_width = '100%'; my $col_width = '200'; my %lt=&Apache::lonlocal::texthash( - 'note' => 'Notification E-mail', 'buil' => 'Building valid e-mail address from username, if missing from preferences:', 'kerb' => 'Kerberos: enter default for each realm used in the domain, with comma separation of entries', 'infs' => 'Internal, Filesystem and Local authentication: enter single default.', @@ -418,8 +406,6 @@ sub print_selection_form { } } - my $breadcrumbs = &Apache::lonhtmlcommon::breadcrumbs - (undef,'Choose e-mail audience','Broadcast_system_email'); my $cb_jscript = &Apache::loncommon::coursebrowser_javascript($cdom); my %elements = ( @@ -469,48 +455,36 @@ function setCourseCat(formname) { } |; } - my $output = <<"ENDONE"; -$html - - LON-CAPA $lt{'note'} - -$cb_jscript - -$bodytag -$breadcrumbs -
- -ENDONE - $output .= &Apache::lonhtmlcommon::start_pick_box($table_width); - my @roles = ('ow','cc','in','ta','ep','st','cr'); - my %longtypes = (); - my %authtypes = (); - &form_elements(\%longtypes,\%authtypes); - my $descrip = $lt{'buil'}.' + + + my $output = &start_page(&add_script($jscript).$cb_jscript, + 'Choose e-mail audience', $formname); + + $output .= &Apache::lonhtmlcommon::start_pick_box($table_width); + my @roles = ('ow','cc','in','ta','ep','st','cr'); + my %longtypes = (); + my %authtypes = (); + &form_elements(\%longtypes,\%authtypes); + my $descrip = $lt{'buil'}.' '."\n"; - my $submit_text = $lt{'comp'}; - my $cmd = 'compose'; - $output .= &Apache::lonhtmlcommon::role_select_row(\@roles,$col_width,$tablecolor,'Roles'); - $output .= &Apache::lonhtmlcommon::course_select_row($col_width,$tablecolor,'Courses',$formname,$totcodes,\@codetitles,\%idlist,\%idlist_titles); - $output .= &Apache::lonhtmlcommon::status_select_row(\%longtypes,$col_width,$tablecolor,&mt('Access status')); - $output .= &Apache::lonhtmlcommon::email_default_row(\%authtypes,$col_width,$tablecolor,&mt('Username -> Email conversion'),$descrip); - $output .= &Apache::lonhtmlcommon::submit_row($col_width,$tablecolor,&mt('Submit'),$cmd,$submit_text); - $output .= &Apache::lonhtmlcommon::end_pick_box(); - $output .= qq( - - -); + my $submit_text = $lt{'comp'}; + my $cmd = 'compose'; + $output .= &Apache::lonhtmlcommon::role_select_row(\@roles,$col_width,$tablecolor,'Roles'); + $output .= &Apache::lonhtmlcommon::course_select_row($col_width,$tablecolor,'Courses',$formname,$totcodes,\@codetitles,\%idlist,\%idlist_titles); + $output .= &Apache::lonhtmlcommon::status_select_row(\%longtypes,$col_width,$tablecolor,&mt('Access status')); + $output .= &Apache::lonhtmlcommon::email_default_row(\%authtypes,$col_width,$tablecolor,&mt('Username -> Email conversion'),$descrip); + $output .= &Apache::lonhtmlcommon::submit_row($col_width,$tablecolor,&mt('Submit'),$cmd,$submit_text); + $output .= &Apache::lonhtmlcommon::end_pick_box(); + $output .= &end_page(); $r->print($output); return; } sub print_composition_form { - my ($r,$formname,$cdom,$tablecolor,$bodytag,$html,$ltext) = @_; + my ($r,$formname,$cdom,$tablecolor) = @_; &Apache::lonhtmlcommon::add_breadcrumb ({href=>"javascript:goBack('pick_target')", text=>"Select Audience"}, @@ -522,11 +496,8 @@ function goBack(target) { document.$formname.submit(); } |; - my $breadcrumbs = (&Apache::lonhtmlcommon::breadcrumbs - (undef,'Broadcast e-mail to users','Broadcast_system_email')); my %lt=&Apache::lonlocal::texthash( - 'note' => 'Notification E-mail', 'nore' => 'No recipients identified', 'emad' => 'e-mail address', ); @@ -538,17 +509,9 @@ function goBack(target) { ); $jscript .= &Apache::lonhtmlcommon::set_form_elements(\%elements); - $r->print(< - LON-CAPA $lt{'note'} - - -$bodytag $breadcrumbs -
-ENDONE + $r->print(&start_page(&add_script($jscript), + 'Broadcast e-mail to users', $formname)); + my $coursefilter = $env{'form.coursepick'}; my %courses = (); if ($coursefilter eq 'all') { @@ -641,7 +604,7 @@ ENDONE } } } - my $output = '
'."\n"; + my $output; if ($totalrecip > 0) { $output .= &Apache::lonhtmlcommon::start_pick_box($table_width); @@ -663,7 +626,7 @@ ENDONE } foreach my $username (sort(keys(%recipients))) { if ($recipients{$username} =~ /\@/) { - my $value=&Apache::lonnet::escape($username).':'.&Apache::lonnet::escape($recipients{$username}); + my $value=&escape($username).':'.&escape($recipients{$username}); $output .= '
'; } } @@ -688,14 +651,14 @@ ENDONE } $output .= ''."\n"; $output .= &Apache::lonhtmlcommon::echo_form_input(['command','origin','subject','message','recipient','sender'],); - $output .= ''; + $output .= &end_page(); $r->print($output); return; } sub print_request_receipt { - my ($r,$formname,$dom,$tablecolor,$bodytag,$html,$ltext) =@_; + my ($r,$formname,$dom,$tablecolor) =@_; my @recipients = &Apache::loncommon::get_env_multiple('form.recipient'); my $subject = $env{'form.subject'}; my $message = $env{'form.message'}; @@ -706,6 +669,7 @@ function goBack(target) { document.$formname.submit(); } ENDSCRIPT + &Apache::lonhtmlcommon::add_breadcrumb ({href=>"javascript:goBack('pick_target')", text=>"Select audience"}); @@ -715,21 +679,11 @@ ENDSCRIPT &Apache::lonhtmlcommon::add_breadcrumb ({href=>"/adm/notify?command=process", text=>"Outcome"}); - my $breadcrumbs = &Apache::lonhtmlcommon::breadcrumbs - (undef,'E-mail Delivery','Broadcast_system_email'); - my $output = < - LON-CAPA Notification E-mail - - -$bodytag -$breadcrumbs -
-
-ENDONE + + + my $output = &start_page(&add_script($jscript), 'E-mail Delivery', + $formname); + $output .= &Apache::lonhtmlcommon::start_pick_box(); my @deliveries = (); &broadcast_email(\@recipients,$subject,$from,$message,\@deliveries); @@ -751,7 +705,7 @@ ENDONE
@@ -766,22 +720,19 @@ ENDONE $output .= ''."\n". ''."\n"; $output .= &Apache::lonhtmlcommon::echo_form_input(['command','origin']); - $output .= ' - - -'; + $output .= &end_page(); $r->print($output); return; } sub broadcast_email { - my ($recipients,$subject,$from,$message,$deliveries,$ltext)=@_; + my ($recipients,$subject,$from,$message,$deliveries)=@_; # Should implement staggered delivery for large numbers of recipients?. foreach my $user (@{$recipients}) { my $msg = new Mail::Send; my ($username,$to) = split(/:/,$user); - $username = &Apache::lonnet::unescape($username); - $to = &Apache::lonnet::unescape($to); + $username = &unescape($username); + $to = &unescape($to); $msg->to($to); $msg->subject($subject); $msg->add('From',"$from"); @@ -822,7 +773,7 @@ sub get_user_info { } sub form_elements { - my ($longtypes,$authtypes,$ltext) = @_; + my ($longtypes,$authtypes) = @_; %{$longtypes} = ( active => 'Currently has access', previous => 'Previously had access', @@ -839,7 +790,7 @@ sub form_elements { } sub store_mail { - my ($subject,$message,$domain,$recipients,$attachmenturl,$ltext) = @_; + my ($subject,$message,$domain,$recipients,$attachmenturl) = @_; my $msgid; ($msgid,$message) = &Apache::lonmsg::packagemsg($subject,$message,undef,undef, $attachmenturl,$recipients,undef,undef,'dcmail');
Earliest to display: '. @@ -218,23 +222,19 @@ ENDONE $output .= &Apache::lonhtmlcommon::row_closure(); $output .= &Apache::lonhtmlcommon::submit_row($col_width,$tablecolor,&mt('Submit'),$cmd,$submit_text); $output .= &Apache::lonhtmlcommon::end_pick_box(); - $output .= qq( - - - -); + $output .= qq(\n). + &end_page(); $r->print($output); return; } sub print_display { - my ($r,$formname,$cdom,$tablecolor,$bodytag,$html,$ltext) = @_; + my ($r,$formname,$cdom,$tablecolor) = @_; &Apache::lonhtmlcommon::add_breadcrumb ({href=>"javascript:goBack('pick_display')", text=>"Display options"}, {text=>"E-mail display"}); - my $breadcrumbs = &Apache::lonhtmlcommon::breadcrumbs - (undef,'Display Broadcast e-mail','Broadcast_system_email'); + my $table_width = ''; my $col_width = '200'; my $rowColor1 = "#ffffff"; @@ -259,19 +259,9 @@ function goBack(target) { } ENDSCRIPT - my $output = <<"ENDONE"; -$html - - LON-CAPA $$ltext{'note'} - - -$bodytag -$breadcrumbs -
-
-ENDONE + + my $output = &start_page(&add_script($jscript), + 'Display Broadcast e-mail', $formname); foreach my $msgid (keys(%sentmail)) { my %content = &Apache::lonmsg::unpackagemsg($sentmail{$msgid}); @@ -306,7 +296,8 @@ ENDONE $rowColor = $rowColor2; } my $recipients = ''; - my ($date,$subj,$sname,$sdom,$cdom) = split(/:/,$msgid,5); + my ($date,undef,$sname,$sdom) = + &Apache::lonmsg::unpackmsgid($msgid,undef,1); $date = &Apache::lonlocal::locallocaltime($date); foreach my $user (sort(keys(%{$dcmail{$msgid}{recipient}}))) { $recipients .= $dcmail{$msgid}{recipient}{$user}.', '; @@ -317,7 +308,8 @@ ENDONE } } else { foreach my $msgid (sort(keys(%dcmail))) { - my ($date,$subj,$sname,$sdom,$cdom) = split(/:/,$msgid,5); + my ($date,undef,$sname,$sdom) = + &Apache::lonmsg::unpackmsgid($msgid,undef,1); if ($env{'form.sortby'} eq 'subject') { push @{$Sortby{$dcmail{$msgid}{subject}}},$msgid; } elsif ($env{'form.sortby'} eq 'message') { @@ -351,8 +343,8 @@ ENDONE } $recipients =~ s/,\s$//; } - - my ($date,$subj,$sname,$sdom,$cdom) = split(/:/,$msgid,5); + my ($date,undef,$sname,$sdom) = + &Apache::lonmsg::unpackmsgid($msgid,undef,1); $date = &Apache::lonlocal::locallocaltime($date); $output .= '
'.$date.''.&cr_to_br($dcmail{$msgid}{subject}).''.$sname.':'.$sdom.''.&cr_to_br($dcmail{$msgid}{message}).''.$recipients.'
'.$username.'  '.$recipients{$username}.'
'; foreach my $person (@deliveries) { my ($username,$email) = split(/:/,$person); - $output .= &Apache::lonnet::unescape($email).' ('.&Apache::lonnet::unescape($username).')
'."\n"; + $output .= &unescape($email).' ('.&unescape($username).')
'."\n"; } $output .= '