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 => $_ } }
57 { type => 'columnnext' },
58 { type => 'title', value => 'LaTeX' },
59 { field => 'latexnotes', %textarea },
60 { field => 'latexfooter', %textarea },
61 { field => 'latexsummary', %textarea },
62 { field => 'latexreturnaddress', %textarea },
63 { field => 'latexwatermark', %textarea },
64 { field => 'latexsmallfooter', %textarea },
65 { field => 'with_latexcoupon', type => 'checkbox', value => 'Y' },
67 { type => 'columnnext' },
68 { type => 'title', value => 'HTML' },
69 { field => 'htmlnotes', %textarea }, #htmlarea?
70 { field => 'htmlfooter', %textarea },
71 { field => 'htmlsummary', %textarea },
72 { field => 'htmlreturnaddress', %textarea },
73 { field => 'htmlwatermark', %textarea },
76 { type => 'columnend' },
80 'confnum' => 'Configuration',
82 'agentnum' => 'Agent',
83 'modename' => 'Mode name',
84 'notice_name' => 'Notice name',
85 'subject' => 'Email Subject: header',
86 'lpr' => 'Alternate lpr command',
105 sub get_invoice_mode { # because we can't quite use agent_virt here
108 'table' => 'invoice_mode',
109 'hashref' => { 'modenum' => $modenum },
110 'extra_sql' => ' AND '.
111 $FS::CurrentUser::CurrentUser->agentnums_sql(
112 'null_right' => 'Edit global templates',
113 'viewall_right' => 'Edit global templates' ),
118 my ($cgi, $object) = @_;
119 foreach (qw(modename agentnum)) {
120 $object->set($_, $cgi->param($_));
122 if ($object->confnum) {
123 return edit_callback(@_);
125 return new_callback(@_);
130 my ($cgi, $object, $fields_arrayref, $opt_hashref) = @_;
132 if ( $cgi->param('locale') =~ /^(\w+)$/ ) {
133 $object->set('locale' => $1);
136 if ( $cgi->param('modenum') =~ /^(\d+)$/ ) {
137 $modenum = $1; # we're adding a locale to an existing mode
138 $object->set('modenum' => $modenum);
139 my $invoice_mode = get_invoice_mode($modenum)
140 or die "invoice mode $modenum not found";
142 $object->set('modename', $invoice_mode->modename);
143 $object->set('agentnum', $invoice_mode->agentnum);
145 # also, need to select a locale
146 # make a list of available locales
147 my %existing_locales = map { $_->locale }
148 qsearch('invoice_conf', { modenum => $modenum });
150 my @locales = grep { !exists($existing_locales{$_}) }
151 FS::Conf->new->config('available-locales');
154 my %info = FS::Locales->locale_info($_);
155 $labels{$_} = $info{'label'};
157 unshift @locales, 'new';
158 $labels{'new'} = 'Select language';
162 $i++ until ( $fields_arrayref->[$i]->{'field'} eq 'locale' );
163 my $locale_field = $fields_arrayref->[$i];
165 my $onchange_locale = "document.getElementById('submit').disabled =
166 (this.options[this.selectedIndex].value == 'new');";
171 options => \@locales,
174 onchange => $onchange_locale,
177 } # otherwise it's a completely new mode, so the locale is default
182 # massive false laziness with msg_template UI
183 my ($cgi, $object, $fields_arrayref, $opt_hashref) = @_;
185 # a little different here in that we treat the content object
186 # as "primary" (this is edit/invoice_conf.html, etc.)
187 # so all we need from the invoice_mode is its name
188 # (and agent identity)
189 my $modenum = $object->modenum;
190 my $invoice_mode = get_invoice_mode($modenum)
191 or die "invoice mode $modenum not found";
192 $object->set('modename', $invoice_mode->modename);
193 $object->set('agentnum', $invoice_mode->agentnum);
196 sub menubar_opt_callback {
198 my $modenum = $object->modenum or return;
199 my (@tabs, @options, %labels);
202 foreach my $l ('', FS::Conf->new->config('available-locales')) {
204 qsearchs('invoice_conf', { modenum => $modenum, locale => $l });
205 if ( $invoice_conf ) {
206 my %info = FS::Locales->locale_info($l) if $l;
207 my $label = $info{'label'} || mt('Default');
208 push @tabs, $label, $invoice_conf->confnum;
209 $selected = $label if $object->locale eq $l;
212 $display_new = 1; # there is at least one unused locale left
215 push @tabs, mt('New'), "modenum=$modenum;locale=new" if $display_new;
216 $selected = mt('New') if $object->locale eq 'new';
217 $selected ||= mt('Default');
219 'url_base' => $cgi->url() . '?',
220 'selected' => $selected,
228 .fstabcontainer th { vertical-align: middle; text-align: center }
233 sub html_table_bottom {
238 if ($object->locale =~ /^(\w+)$/) {
241 if ($object->modenum =~ /^(\d+)$/) {
246 # don't allow the default locale to be removed unless it's the last one
248 $show_delete = 0 if (
252 FS::invoice_conf->count("modenum = $modenum and locale is not null") > 0
256 if ( $show_delete ) {
257 # set up a delete link
258 my $confnum = $object->confnum;
259 my $url = $p."misc/delete-invoice_conf.html?$confnum";
260 my $link = qq!<A HREF="javascript:areyousure('$url','Really delete this configuration?')">! .
261 'Delete this configuration' .
263 $html = qq!<TR><TD></TD>
264 <TD STYLE="font-style: italic; font-size: small">$link</TD></TR>
265 <SCRIPT TYPE="text/javascript">
266 function areyousure(url, message) {
267 if (confirm(message)) window.location.href = url;