2 'html_init' => '<TABLE id="outerTable"><TR><TD>',
3 'body_etc' => $body_etc,
4 'name_singular' => 'template',
5 'table' => 'msg_template',
6 'viewall_dir' => 'browse',
9 'agent_null_right' => [ 'View global templates', 'Edit global templates' ],
13 'msgnum' => 'Template',
14 'agentnum' => 'Agent',
15 'msgname' => 'Template name',
16 'from_addr' => 'From: ',
17 'bcc_addr' => 'Bcc: ',
19 'subject' => 'Subject: ',
20 'body' => 'Message body',
22 'edit_callback' => \&edit_callback,
23 'error_callback' => \&edit_callback,
24 'html_bottom' => '</DIV>',
25 'html_table_bottom'=> \&html_table_bottom,
26 'html_foot' => ( $no_submit ? '' : "</TD>$sidebar</TR></TABLE>" ),
27 'no_submit' => $no_submit,
31 my $curuser = $FS::CurrentUser::CurrentUser;
34 unless $curuser->access_right([ 'View templates', 'View global templates',
35 'Edit templates', 'Edit global templates',
39 $body_etc = q!onload="document.getElementById('locale').onchange()"!
40 if $cgi->param('locale') eq 'new';
42 my $msgnum = $cgi->param('msgnum');
43 my $msg_template = $msgnum ? qsearchs('msg_template', {msgnum=>$msgnum}) : '';
47 if ( $curuser->access_right('Edit global templates')
48 || ( $curuser->access_right('Edit templates')
50 && $msg_template->agentnum
51 && $curuser->agentnums_href->{$msg_template->agentnum}
56 { field => 'agentnum',
57 type => 'select-agent',
59 { field => 'msgname', size=>60, },
60 { field => 'from_addr', size=>60, },
61 { field => 'bcc_addr', size=>60, },
62 { type => 'tablebreak-tabs',
63 include_opt_callback => \&menubar_opt_callback,
65 # template_content fields
66 { field => 'locale', type => 'hidden' },
67 { field => 'subject', size=>60, },
78 { field => 'agentnum',
79 type => 'select-agent',
82 { field => 'msgname', type => 'fixed', },
83 { field => 'from_addr', type => 'fixed', },
84 { field => 'bcc_addr', type => 'fixed', },
85 { type => 'tablebreak-tabs',
86 include_opt_callback => \&menubar_opt_callback,
88 # template_content fields
89 { field => 'locale', type => 'hidden' },
90 { field => 'subject', type => 'fixed', },
100 my ($cgi, $object, $fields_listref, $opt_hashref) = @_;
101 my $template_content = new FS::template_content { 'locale' => '' };
102 $object->{'Hash'} = { $object->hash, $template_content->hash };
106 my ($cgi, $object, $fields_listref, $opt_hashref) = @_;
107 $cgi->param('locale') =~ /^(\w*)$/ or die 'bad locale '.$cgi->param('locale');
110 # fetch the content object and merge its fields
112 'msgnum' => $object->msgnum,
115 my $template_content = qsearchs('template_content', \%args)
116 || new FS::template_content( { %args });
117 $object->{'Hash'} = { $object->hash, $template_content->hash };
119 # set up the locale selector if this is a new content
120 if ( $locale eq 'new' ) {
122 # make a list of available locales
123 my $content_locales = $object->content_locales;
124 my @locales = grep { !exists($content_locales->{$_}) }
125 FS::Conf->new->config('available-locales');
128 my %info = FS::Locales->locale_info($_);
129 $labels{$_} = $info{'label'};
131 unshift @locales, 'new';
132 $labels{'new'} = 'Select language';
136 $i++ until ( $fields_listref->[$i]->{'field'} eq 'locale' );
137 my $locale_field = $fields_listref->[$i];
139 my $onchange_locale = "document.getElementById('submit').disabled =
140 (this.options[this.selectedIndex].value == 'new');";
145 options => \@locales,
148 onchange => $onchange_locale,
153 sub menubar_opt_callback {
155 # generate no tabs for new msg_templates.
156 my $msgnum = $object->msgnum or return;
157 my (@tabs, @options, %labels);
158 push @tabs, mt('Default'), '';
161 foreach my $l (FS::Locales->locales) {
162 if ( exists $object->content_locales->{$l} ) {
163 my %info = FS::Locales->locale_info($l);
167 $selected = $info{'label'} if $object->locale eq $l;
170 $display_new = 1; # there is at least one unused locale left
173 push @tabs, mt('New'), ';locale=new' if $display_new;
174 $selected = mt('New') if $object->locale eq 'new';
175 $selected ||= mt('Default');
177 'url_base' => $p.'edit/msg_template.html?msgnum='.$msgnum,
178 'selected' => $selected,
183 my $onchange_locale = '';
187 my %substitutions = (
189 '$display_custnum'=> 'Customer#',
190 '$agentnum' => 'Agent#',
191 '$agent_name' => 'Agent name',
192 '$payby' => 'Payment method',
193 '$paymask' => 'Card/account# (masked)',
194 '$payname' => 'Name on card/bank name',
195 '$paytype' => 'Account type',
196 '$payip' => 'IP address used to submit payment info',
197 '$num_ncancelled_pkgs' => '# of active packages',
198 '$num_cancelled_pkgs' => '# of cancelled packages',
199 '$num_pkgs' => '# of packages',
200 '$classname' => 'Customer class',
201 '$categoryname' => 'Customer category',
202 '$balance' => 'Current balance',
203 '$credit_limit' => 'Credit limit',
204 '$invoicing_list_emailonly' => 'Billing email address',
205 '$cust_status' => 'Status',
206 '$ucfirst_cust_status' => 'Status, capitalized',
207 '$cust_statuscolor' => 'Status color code',
208 '$company_name' => 'Our company name',
209 '$company_address'=> 'Our company address',
210 '$company_phonenum' => 'Our phone number',
212 'contact' => [ # duplicate this for shipping
213 '$name' => 'Company and contact name',
214 '$name_short' => 'Company or contact name',
215 '$company' => 'Company name',
216 '$contact' => 'Contact name (last, first)',
217 '$contact_firstlast'=> 'Contact name (first last)',
218 '$first' => 'First name',
219 '$last' => 'Last name',
220 '$address1' => 'Address line 1',
221 '$address2' => 'Address line 2',
223 '$county' => 'County',
226 '$country' => 'Country',
227 '$daytime' => 'Day phone',
228 '$night' => 'Night phone',
229 '$mobile' => 'Mobile phone',
233 '$invnum' => 'Invoice#',
236 '$pkgnum' => 'Package#',
237 '$pkg' => 'Package description',
238 '$pkg_label' => 'Description + comment',
239 '$status' => 'Status',
240 '$statuscolor' => 'Status color code',
241 '$start_ymd' => 'Start date',
242 '$setup_ymd' => 'Setup date',
243 '$last_bill_ymd' => 'Last bill date',
244 '$next_bill_ymd' => 'Next bill date',
245 '$susp_ymd' => 'Suspended on date',
246 '$cancel_ymd' => 'Canceled on date',
247 '$adjourn_ymd' => 'Adjournment date',
248 '$expire_ymd' => 'Expiration date',
249 '$labels_short' => 'Service labels',
250 '$location_label' => 'Service location',
253 '$svcnum' => 'Service#',
254 '$username' => 'Login name',
255 '$password' => 'Password',
256 '$domain' => 'Domain name',
259 '$svcnum' => 'Service#',
260 '$domain' => 'Domain name',
261 '$registrar' => 'Registrar name',
262 '$catchall' => 'Catchall email',
265 '$svcnum' => 'Service#',
266 '$phonenum' => 'Phone number',
267 '$countrycode' => 'Country code',
268 '$domain' => 'Domain name'
271 '$svcnum' => 'Service#',
272 '$ip_addr' => 'IP address',
273 '$mac_addr' => 'MAC address',
274 '$speed_up' => 'Upstream speed',
275 '$speed_down' => 'Downstream speed',
278 '$paynum' => 'Payment#',
280 '$payby' => 'Payment method',
281 '$date' => 'Payment date',
282 '$payinfo' => 'Card/account# (masked)',
283 '$error' => 'Decline reason',
286 my @c = @{ $substitutions{'contact'} };
287 for (my $i=0; $i<scalar(@c); $i += 2) {
288 $c[$i] =~ s/\$(.*)/\$ship_$1/;
290 $substitutions{'shipping'} = \@c;
292 tie my %sections, 'Tie::IxHash', (
293 'contact' => 'Name and contact info (billing)',
294 'shipping' => 'Name and contact info (shipping)',
295 'cust_main' => 'Customer status and payment info',
296 'cust_pkg' => 'Package fields',
297 'cust_bill' => 'Invoice fields',
298 'cust_pay' => 'Payment fields',
299 'svc_acct' => 'Login service fields',
300 'svc_domain'=> 'Domain service fields',
301 'svc_phone' => 'Phone service fields',
302 'svc_broadband' => 'Broadband service fields',
305 my $widget = new HTML::Widgets::SelectLayers(
306 'options' => \%sections,
307 'form_name' => 'dummy',
308 'html_between'=>'</FORM><FONT SIZE=-1>',
309 'selected_layer'=>(keys(%sections))[0],
310 'layer_callback' => sub {
312 my $html = include('/elements/table-grid.html');
313 my @hints = @{ $substitutions{$section} };
315 my $key = shift @hints;
316 $html .= qq!\n<TR><TD><A href="javascript:insertHtml('{$key}')">$key</A></TD>!;
317 $html .= "\n<TD>".shift(@hints).'</TD></TR>';
319 $html .= "\n</TABLE>";
325 <SCRIPT TYPE="text/javascript">
326 function insertHtml(what) {
327 var oEditor = FCKeditorAPI.GetInstance("body");
328 oEditor.InsertHtml(what);
331 function areyousure(url, message) {
332 if (confirm(message))
333 window.location.href = url;
336 <TD valign="top"><FORM name="dummy">
339 '<BR>Click links to insert.
340 <BR>Enclose substitutions and other Perl expressions in braces:
341 <BR>{ $name } = ExampleCo (Smith, John)
342 <BR>{ time2str("%D", time) } = '.time2str("%D", time).'
346 sub html_table_bottom {
348 $cgi->param('locale') =~ /^(\w+)$/;
351 if ( $locale and $locale ne 'new' ) {
352 # set up a delete link
353 my $msgnum = $object->msgnum;
354 my $url = $p."misc/delete-template_content.html?msgnum=$msgnum;locale=$1";
355 my $link = qq!<A HREF="javascript:areyousure('$url','Really delete this template?')">! .
356 'Delete this template' .
358 $html = qq!<TR><TD></TD>
359 <TD STYLE="font-style: italic; font-size: small">$link</TD></TR>!;