2 'body_etc' => $body_etc,
3 'name_singular' => 'invoice configuration',
4 'table' => 'invoice_conf',
5 'viewall_dir' => 'browse',
8 'new_callback' => \&new_callback,
9 'edit_callback' => \&edit_callback,
10 'error_callback' => \&error_callback,
11 'html_init' => \&html_init,
12 'html_table_bottom' => \&html_table_bottom,
13 'html_bottom' => '</DIV>', # close tablebreak-tabs
17 my $curuser = $FS::CurrentUser::CurrentUser;
21 unless $curuser->access_right([ 'Edit templates', 'Edit global templates' ]);
24 $body_etc = q!onload="document.getElementById('locale').onchange()"!
25 if $cgi->param('locale') eq 'new';
27 my $modenum = $cgi->param('modenum');
28 my $mode = $modenum ? qsearchs('invoice_mode', { modenum => $modenum }) : '';
30 my %textarea = (type => 'textarea', rows => 10, cols => 40);
32 { field => 'modenum', type => 'hidden' },
33 { field => 'agentnum',
34 type => 'select-agent',
36 { field => 'modename', size=>60, },
37 { type => 'tablebreak-tabs',
38 include_opt_callback => \&menubar_opt_callback,
40 { field => 'locale', type => 'hidden' },
41 { field => 'notice_name', size=>60, },
42 { field => 'subject', size=>60, },
43 { field => 'lpr', size=>60, },
45 { type => 'columnstart', aligned => 1 },
46 { type => 'title', value => '<BR>' },
47 map ( { +{ type => 'justtitle', value => $_ } }
56 { type => 'columnnext' },
57 { type => 'title', value => 'LaTeX' },
58 { field => 'latexnotes', %textarea },
59 { field => 'latexfooter', %textarea },
60 { field => 'latexsummary', %textarea },
61 { field => 'latexreturnaddress', %textarea },
62 { field => 'latexsmallfooter', %textarea },
63 { field => 'with_latexcoupon', type => 'checkbox', value => 'Y' },
65 { type => 'columnnext' },
66 { type => 'title', value => 'HTML' },
67 { field => 'htmlnotes', %textarea }, #htmlarea?
68 { field => 'htmlfooter', %textarea },
69 { field => 'htmlsummary', %textarea },
70 { field => 'htmlreturnaddress', %textarea },
73 { type => 'columnend' },
77 'confnum' => 'Configuration',
79 'agentnum' => 'Agent',
80 'modename' => 'Mode name',
81 'notice_name' => 'Notice name',
82 'subject' => 'Email Subject: header',
83 'lpr' => 'Alternate lpr command',
100 sub get_invoice_mode { # because we can't quite use agent_virt here
103 'table' => 'invoice_mode',
104 'hashref' => { 'modenum' => $modenum },
105 'extra_sql' => ' AND '.
106 $FS::CurrentUser::CurrentUser->agentnums_sql(
107 'null_right' => 'Edit global templates',
108 'viewall_right' => 'Edit global templates' ),
113 my ($cgi, $object) = @_;
114 foreach (qw(modename agentnum)) {
115 $object->set($_, $cgi->param($_));
117 if ($object->confnum) {
118 return edit_callback(@_);
120 return new_callback(@_);
125 my ($cgi, $object, $fields_arrayref, $opt_hashref) = @_;
127 if ( $cgi->param('locale') =~ /^(\w+)$/ ) {
128 $object->set('locale' => $1);
131 if ( $cgi->param('modenum') =~ /^(\d+)$/ ) {
132 $modenum = $1; # we're adding a locale to an existing mode
133 $object->set('modenum' => $modenum);
134 my $invoice_mode = get_invoice_mode($modenum)
135 or die "invoice mode $modenum not found";
137 $object->set('modename', $invoice_mode->modename);
138 $object->set('agentnum', $invoice_mode->agentnum);
140 # also, need to select a locale
141 # make a list of available locales
142 my %existing_locales = map { $_->locale }
143 qsearch('invoice_conf', { modenum => $modenum });
145 my @locales = grep { !exists($existing_locales{$_}) }
146 FS::Conf->new->config('available-locales');
149 my %info = FS::Locales->locale_info($_);
150 $labels{$_} = $info{'label'};
152 unshift @locales, 'new';
153 $labels{'new'} = 'Select language';
157 $i++ until ( $fields_arrayref->[$i]->{'field'} eq 'locale' );
158 my $locale_field = $fields_arrayref->[$i];
160 my $onchange_locale = "document.getElementById('submit').disabled =
161 (this.options[this.selectedIndex].value == 'new');";
166 options => \@locales,
169 onchange => $onchange_locale,
172 } # otherwise it's a completely new mode, so the locale is default
177 # massive false laziness with msg_template UI
178 my ($cgi, $object, $fields_arrayref, $opt_hashref) = @_;
180 # a little different here in that we treat the content object
181 # as "primary" (this is edit/invoice_conf.html, etc.)
182 # so all we need from the invoice_mode is its name
183 # (and agent identity)
184 my $modenum = $object->modenum;
185 my $invoice_mode = get_invoice_mode($modenum)
186 or die "invoice mode $modenum not found";
187 $object->set('modename', $invoice_mode->modename);
188 $object->set('agentnum', $invoice_mode->agentnum);
191 sub menubar_opt_callback {
193 my $modenum = $object->modenum or return;
194 my (@tabs, @options, %labels);
197 foreach my $l ('', FS::Conf->new->config('available-locales')) {
199 qsearchs('invoice_conf', { modenum => $modenum, locale => $l });
200 if ( $invoice_conf ) {
201 my %info = FS::Locales->locale_info($l) if $l;
202 my $label = $info{'label'} || mt('Default');
203 push @tabs, $label, $invoice_conf->confnum;
204 $selected = $label if $object->locale eq $l;
207 $display_new = 1; # there is at least one unused locale left
210 push @tabs, mt('New'), "modenum=$modenum;locale=new" if $display_new;
211 $selected = mt('New') if $object->locale eq 'new';
212 $selected ||= mt('Default');
214 'url_base' => $cgi->url() . '?',
215 'selected' => $selected,
223 .fstabcontainer th { vertical-align: middle; text-align: center }
228 sub html_table_bottom {
233 if ($object->locale =~ /^(\w+)$/) {
236 if ($object->modenum =~ /^(\d+)$/) {
241 # don't allow the default locale to be removed unless it's the last one
243 $show_delete = 0 if (
247 FS::invoice_conf->count("modenum = $modenum and locale is not null") > 0
251 if ( $show_delete ) {
252 # set up a delete link
253 my $confnum = $object->confnum;
254 my $url = $p."misc/delete-invoice_conf.html?$confnum";
255 my $link = qq!<A HREF="javascript:areyousure('$url','Really delete this configuration?')">! .
256 'Delete this configuration' .
258 $html = qq!<TR><TD></TD>
259 <TD STYLE="font-style: italic; font-size: small">$link</TD></TR>
260 <SCRIPT TYPE="text/javascript">
261 function areyousure(url, message) {
262 if (confirm(message)) window.location.href = url;