--- loncom/interface/lonnotify.pm 2005/08/02 05:03:10 1.1
+++ loncom/interface/lonnotify.pm 2006/03/16 20:09:35 1.12
@@ -31,6 +31,9 @@ use Apache::lonsupportreq;
use LONCAPA::Enrollment;
use Apache::Constants qw(:common :http);
use Apache::lonlocal;
+use Mail::Send;
+use HTML::TokeParser;
+use HTML::Entities;
sub handler {
my ($r) = @_;
@@ -40,31 +43,341 @@ sub handler {
if ($r->header_only) {
return OK;
}
-# my $codedom = $env{'request.role.domain'};
- my $cdom = 'northwood5';
- unless (&Apache::lonnet::allowed('psa',$env{'request.role.domain'})) {
+ my $cdom = $env{'request.role.domain'};
+ unless (&Apache::lonnet::allowed('psa',$cdom)) {
# Not allowed to broadcast e-mail system-wide
$env{'user.error.msg'}="/adm/notify:psa:0:0:Cannot broadcast e-mail systemwide";
return HTTP_NOT_ACCEPTABLE;
}
+ &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
+ ['command']);
my $command = $env{'form.command'};
+ my $origin = $env{'form.origin'};
+
&Apache::lonhtmlcommon::clear_breadcrumbs();
+
+ 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);
&Apache::lonhtmlcommon::add_breadcrumb
({href=>'/adm/notify',
- text=>"Broadcast e-mail"});
+ text=>"Broadcast E-mail"});
if ($command eq 'process') {
- &print_request_receipt($r,$cdom);
+ &print_request_receipt($r,$command,$cdom,$tablecolor,$bodytag);
} elsif ($command eq 'compose') {
- &print_composition_form($r,$cdom);
+ &print_composition_form($r,$command,$cdom,$tablecolor,$bodytag);
+ } elsif ($command eq 'pick_target') {
+ &print_selection_form($r,$command,$cdom,$tablecolor,$bodytag);
+ } elsif ($command eq 'pick_display') {
+ &print_display_option_form($r,$command,$cdom,$tablecolor,$bodytag);
+ } elsif ($command eq 'display') {
+ &print_display($r,$command,$cdom,$tablecolor,$bodytag);
} else {
- &print_selection_form($r,$cdom);
+ &print_front_page($r,'front',$cdom,$tablecolor,$bodytag);
}
return OK;
}
+sub add_script {
+ my ($js) = @_;
+ return '';
+}
+
+sub start_page {
+ my ($jscript,$bodytag,$bread_title,$formname) = @_;
+
+ my $html = &Apache::lonxml::xmlbegin();
+
+ my $head = &Apache::loncommon::head('Notification E-mail',$jscript);
+
+ my $breadcrumbs =
+ &Apache::lonhtmlcommon::breadcrumbs(undef,$bread_title,
+ 'Broadcast_system_email');
+ my $output = <<"ENDONE";
+$html
+$head
+$bodytag
+$breadcrumbs
+
+
'.&Apache::loncommon::end_page();
+}
+
+sub print_front_page {
+ my ($r,$formname,$cdom,$tablecolor,$bodytag) = @_;
+
+ my $jscript = qq|
+function next_page(caller) {
+ if (caller == 'view') {
+ document.front.command.value="pick_display"
+ }
+ else {
+ document.front.command.value="pick_target"
+ }
+ document.front.submit()
+}
+ |;
+
+ my $output = &start_page(&add_script($jscript), $bodytag,
+ 'Broadcast e-mail to Domain', $formname);
+
+ $output .= '';
+ $output .= &Apache::lonhtmlcommon::start_pick_box();
+ $output .= '';
+ $output .= &Apache::lonhtmlcommon::end_pick_box();
+ $output .= &end_page();
+
+ $r->print($output);
+ return;
+}
+
+sub print_display_option_form {
+ my ($r,$formname,$cdom,$tablecolor,$bodytag) = @_;
+ &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 $startdateform = &Apache::lonhtmlcommon::date_setter($formname,
+ 'startdate',
+ $now);
+ my $enddateform = &Apache::lonhtmlcommon::date_setter($formname,
+ 'enddate',
+ $now);
+ my %elements = (
+ startdate_month => 'selectbox',
+ startdate_hour => 'selectbox',
+ enddate_month => 'selectbox',
+ enddate_hour => 'selectbox',
+ startdate_day => 'text',
+ startdate_year => 'text',
+ startdate_minute => 'text',
+ startdate_second => 'text',
+ enddate_day => 'text',
+ enddate_year => 'text',
+ enddate_minute => 'text',
+ enddate_second => 'text',
+ sender => 'checkbox',
+ );
+ my $jscript = &Apache::lonhtmlcommon::set_form_elements(\%elements);
+
+ my $output = &start_page(&add_script($jscript), $bodytag,
+ '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 .= 'Earliest to display: | '.
+ $startdateform.' | ';
+ $output .= 'Latest to display: | '.$enddateform.
+ ' |
| ';
+ $output .= &Apache::lonhtmlcommon::row_closure();
+ $output .= &Apache::lonhtmlcommon::row_title($col_width,$tablecolor,&mt('Choose sender(s)'));
+ my %personnel = &Apache::lonnet::get_domain_roles($cdom,\@roles);
+ $output .= '';
+ my @domcc = ();
+ foreach my $server (keys %personnel) {
+ foreach my $user (sort(keys %{$personnel{$server}})) {
+ my ($trole,$uname,$udom,$runame,$rudom,$rsec) = split(/:/,$user);
+ unless (grep/^$uname:$udom$/,@domcc) {
+ my %userinfo = &Apache::lonnet::get('environment',['lastname','firstname'],$udom,$uname);
+ $output .= ' '.$userinfo{firstname}.' '.$userinfo{lastname}.' ('.$uname.':'.$udom.')';
+ push (@domcc,$uname.':'.$udom);
+ }
+ }
+ }
+ $output .= ' | ';
+ $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(
+
+
+