diff options
author | Mark Wells <mark@freeside.biz> | 2013-11-16 18:22:39 -0800 |
---|---|---|
committer | Mark Wells <mark@freeside.biz> | 2013-11-16 18:22:39 -0800 |
commit | 517ad7e0c5bd5a6329dfd3ef9c35f69afea9fc49 (patch) | |
tree | 3fe2e243630ff9acc7130e8085e268d21b9e8b22 /httemplate/misc | |
parent | cf5608f9ce868ccb91244f6cab58022869fc7c17 (diff) |
UI to disable message templates, #26035
Diffstat (limited to 'httemplate/misc')
-rw-r--r-- | httemplate/misc/disable-msg_template.cgi | 77 | ||||
-rw-r--r-- | httemplate/misc/email-customers.html | 1 |
2 files changed, 78 insertions, 0 deletions
diff --git a/httemplate/misc/disable-msg_template.cgi b/httemplate/misc/disable-msg_template.cgi new file mode 100644 index 000000000..1eb4d25e5 --- /dev/null +++ b/httemplate/misc/disable-msg_template.cgi @@ -0,0 +1,77 @@ +% if ( @error ) { +<& /elements/errorpage-popup.html, @error &> +% } else { +<& /elements/header-popup.html, "Template ${actioned}" &> + <SCRIPT TYPE="text/javascript"> + window.top.location.reload(); + </SCRIPT> +</BODY> +</HTML> +% } +<%init> + +my $curuser = $FS::CurrentUser::CurrentUser; +my $conf = FS::Conf->new; +my @error; +my $actioned; + +die "access denied" + unless $curuser->access_right([ 'Edit templates', 'Edit global templates' ]); + +my $msgnum = $cgi->param('msgnum'); +$msgnum =~ /^\d+$/ or die "bad msgnum '$msgnum'"; +my $msg_template = qsearchs({ + table => 'msg_template', + hashref => { msgnum => $msgnum }, + extra_sql => ' AND '. + $curuser->agentnums_sql(null_right => 'Edit global templates'), +}); +die "unknown msgnum $msgnum" unless $msg_template; + +if ( $cgi->param('enable') ) { + $actioned = 'enabled'; + $msg_template->set('disabled' => ''); +} else { + $actioned = 'disabled'; + # make sure it's not in use anywhere + my @inuse; + + # notice, letter, notice_to events (if they're enabled) + my @events = qsearch({ + table => 'part_event_option', + addl_from => ' JOIN part_event USING (eventpart)', + hashref => { + optionname => 'msgnum', + optionvalue => $msgnum, + }, + extra_sql => ' AND disabled IS NULL', + }); + push @inuse, map {"Billing event #".$_->eventpart} @events; + + # send_email and rt_ticket exports + my @exports = qsearch( 'part_export_option', { + optionname => { op => 'LIKE', value => '%_template' }, + optionvalue => $msgnum, + }); + push @inuse, map {"Export #".$_->exportnum} @exports; + + # payment_receipt_msgnum, decline_msgnum, etc. + my @confs = qsearch( 'conf', { + name => { op => 'LIKE', value => '%_msgnum' }, + value => $msgnum, + }); + push @inuse, map {"Configuration setting ".$_->name} @confs; + # XXX pending queue jobs? + if (@inuse) { + @error = ("This template is in use. Check the following settings:", + @inuse); + } + + # good to go + $msg_template->set(disabled => 'Y'); +} +if (!@error) { + my $error = $msg_template->replace; + push @error, $error if $error; +} +</%init> diff --git a/httemplate/misc/email-customers.html b/httemplate/misc/email-customers.html index ad67b8d7e..3b2ac3c5f 100644 --- a/httemplate/misc/email-customers.html +++ b/httemplate/misc/email-customers.html @@ -98,6 +98,7 @@ Template: <% include('/elements/select-table.html', 'label' => 'Template:', 'table' => 'msg_template', + 'hashref' => { disabled => '' }, 'name_col' => 'msgname', 'empty_label' => '(none)', 'onchange' => 'toggle(this)', |