2 <& /elements/errorpage-popup.html, @error &>
4 <& /elements/header-popup.html, "Template ${actioned}" &>
5 <SCRIPT TYPE="text/javascript">
13 my $curuser = $FS::CurrentUser::CurrentUser;
14 my $conf = FS::Conf->new;
19 unless $curuser->access_right([ 'Edit templates', 'Edit global templates' ]);
21 my $msgnum = $cgi->param('msgnum');
22 $msgnum =~ /^\d+$/ or die "bad msgnum '$msgnum'";
23 my $msg_template = qsearchs({
24 table => 'msg_template',
25 hashref => { msgnum => $msgnum },
27 $curuser->agentnums_sql(null_right => 'Edit global templates'),
29 die "unknown msgnum $msgnum" unless $msg_template;
31 if ( $cgi->param('enable') ) {
32 $actioned = 'enabled';
33 $msg_template->set('disabled' => '');
35 $actioned = 'disabled';
36 # make sure it's not in use anywhere
39 # notice, letter, notice_to events (if they're enabled)
40 my @events = qsearch({
41 table => 'part_event_option',
42 addl_from => ' JOIN part_event USING (eventpart)',
44 optionname => 'msgnum',
45 optionvalue => $msgnum,
47 extra_sql => ' AND disabled IS NULL',
49 push @inuse, map {"Billing event #".$_->eventpart} @events;
51 # send_email and rt_ticket exports
52 my @exports = qsearch( 'part_export_option', {
53 optionname => { op => 'LIKE', value => '%_template' },
54 optionvalue => $msgnum,
56 push @inuse, map {"Export #".$_->exportnum} @exports;
58 # payment_receipt_msgnum, decline_msgnum, etc.
59 my @confs = qsearch( 'conf', {
60 name => { op => 'LIKE', value => '%_msgnum' },
63 push @inuse, map {"Configuration setting ".$_->name} @confs;
64 # XXX pending queue jobs?
66 @error = ("This template is in use. Check the following settings:",
71 $msg_template->set(disabled => 'Y');
74 my $error = $msg_template->replace;
75 push @error, $error if $error;