#
# Copyright Michigan State University Board of Trustees
#
# This file is part of the LearningOnline Network with CAPA (LON-CAPA).
#
# LON-CAPA is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# LON-CAPA is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with LON-CAPA; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
# /home/httpd/html/adm/gpl.txt
#
# http://www.lon-capa.org/
#
package Apache::lonnotify;
use strict;
use Apache::lonnet;
use Apache::loncommon;
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) = @_;
&Apache::loncommon::content_type($r,'text/html');
$r->send_http_header;
if ($r->header_only) {
return OK;
}
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"});
if ($command eq 'process') {
&print_request_receipt($r,$command,$cdom,$tablecolor,$bodytag);
} elsif ($command eq 'compose') {
&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_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 .= '