1 <& /edit/elements/edit.html,
2 'post_url' => $fsurl.'edit/process/msg_template.html',
3 'html_init' => '<TABLE id="outerTable"><TR><TD>',
4 'body_etc' => $body_etc,
5 'name_singular' => 'template',
6 'table' => 'msg_template',
7 'viewall_url' => $fsurl.'browse/msg_template/email.html',
10 'agent_null_right' => [ 'View global templates', 'Edit global templates' ],
14 'msgnum' => 'Template',
15 'agentnum' => 'Agent',
16 'msgname' => 'Template name',
17 'from_addr' => 'From: ',
18 'bcc_addr' => 'Bcc: ',
20 'subject' => 'Subject: ',
21 'body' => 'Message body',
23 'edit_callback' => \&edit_callback,
24 'error_callback' => \&edit_callback,
25 'html_bottom' => '</DIV>',
26 'html_table_bottom'=> \&html_table_bottom,
27 'html_foot' => ( $no_submit ? '' : "</TD>$sidebar</TR></TABLE>" ),
28 'no_submit' => $no_submit,
31 use FS::template_image;
33 my $curuser = $FS::CurrentUser::CurrentUser;
36 unless $curuser->access_right([ 'View templates', 'View global templates',
37 'Edit templates', 'Edit global templates',
41 $body_etc = q!onload="document.getElementById('locale').onchange()"!
42 if $cgi->param('locale') eq 'new';
44 my $msgnum = $cgi->param('msgnum');
45 my $msg_template = $msgnum ? qsearchs('msg_template', {msgnum=>$msgnum}) : '';
49 if ( $curuser->access_right('Edit global templates')
50 || ( $curuser->access_right('Edit templates')
52 && $msg_template->agentnum
53 && $curuser->agentnums_href->{$msg_template->agentnum}
58 { field => 'msgclass',
62 { field => 'agentnum',
63 type => 'select-agent',
65 { field => 'msgname', size=>60, },
66 { field => 'from_addr', size=>60, },
67 { field => 'bcc_addr', size=>60, },
68 { type => 'tablebreak-tabs',
69 include_opt_callback => \&menubar_opt_callback,
71 # template_content fields
72 { field => 'locale', type => 'hidden' },
73 { field => 'subject', size=>60, },
77 config=> { extraPlugins => 'blockprotect' },
85 { field => 'agentnum',
86 type => 'select-agent',
89 { field => 'msgname', type => 'fixed', },
90 { field => 'from_addr', type => 'fixed', },
91 { field => 'bcc_addr', type => 'fixed', },
92 { type => 'tablebreak-tabs',
93 include_opt_callback => \&menubar_opt_callback,
95 # template_content fields
96 { field => 'locale', type => 'hidden' },
97 { field => 'subject', type => 'fixed', },
107 my ($cgi, $object, $fields_listref, $opt_hashref) = @_;
108 my $template_content = new FS::template_content { 'locale' => '' };
109 $object->{'Hash'} = { $object->hash, $template_content->hash };
113 my ($cgi, $object, $fields_listref, $opt_hashref) = @_;
114 $cgi->param('locale') =~ /^(\w*)$/ or die 'bad locale '.$cgi->param('locale');
117 # fetch the content object and merge its fields
119 'msgnum' => $object->msgnum,
122 my $template_content = qsearchs('template_content', \%args)
123 || new FS::template_content( { %args });
124 $object->{'Hash'} = { $object->hash, $template_content->hash };
126 # set up the locale selector if this is a new content
127 if ( $locale eq 'new' ) {
129 # make a list of available locales
130 my $content_locales = $object->content_locales;
131 my @locales = grep { !exists($content_locales->{$_}) }
132 FS::Conf->new->config('available-locales');
135 my %info = FS::Locales->locale_info($_);
136 $labels{$_} = $info{'label'};
138 unshift @locales, 'new';
139 $labels{'new'} = 'Select language';
143 $i++ until ( $fields_listref->[$i]->{'field'} eq 'locale' );
144 my $locale_field = $fields_listref->[$i];
146 my $onchange_locale = "document.getElementById('submit').disabled =
147 (this.options[this.selectedIndex].value == 'new');";
152 options => \@locales,
155 onchange => $onchange_locale,
160 sub menubar_opt_callback {
162 # generate no tabs for new msg_templates.
163 my $msgnum = $object->msgnum or return;
164 my (@tabs, @options, %labels);
165 push @tabs, mt('Default'), '';
168 foreach my $l (FS::Locales->locales) {
169 if ( exists $object->content_locales->{$l} ) {
170 my %info = FS::Locales->locale_info($l);
174 $selected = $info{'label'} if $object->locale eq $l;
177 $display_new = 1; # there is at least one unused locale left
180 push @tabs, mt('New'), ';locale=new' if $display_new;
181 $selected = mt('New') if $object->locale eq 'new';
182 $selected ||= mt('Default');
184 'url_base' => $fsurl.'edit/msg_template.html?msgnum='.$msgnum,
185 'selected' => $selected,
190 my $onchange_locale = '';
194 my %substitutions = (
196 '$display_custnum'=> 'Customer#',
197 '$agentnum' => 'Agent#',
198 '$agent_name' => 'Agent name',
199 '$payby' => 'Payment method',
200 '$paymask' => 'Card/account# (masked)',
201 '$payname' => 'Name on card/bank name',
202 '$paytype' => 'Account type',
203 '$payip' => 'IP address used to submit payment info',
204 '$num_ncancelled_pkgs' => '# of active packages',
205 '$num_cancelled_pkgs' => '# of cancelled packages',
206 '$num_pkgs' => '# of packages',
207 '$classname' => 'Customer class',
208 '$categoryname' => 'Customer category',
209 '$balance' => 'Current balance',
210 '$credit_limit' => 'Credit limit',
211 '$invoicing_list_emailonly' => 'Billing email address',
212 #'$cust_status' => 'Status (raw internal label)',
213 '$cust_status_label' => 'Status (display label)',
214 '$cust_statuscolor' => 'Status color code',
215 '$company_name' => 'Our company name',
216 '$company_address'=> 'Our company address',
217 '$company_phonenum' => 'Our phone number',
218 '$selfservice_server_base_url' => 'Base URL of customer self-service',
220 'contact' => [ # duplicate this for shipping
221 '$name' => 'Company and contact name',
222 '$name_short' => 'Company or contact name',
223 '$company' => 'Company name',
224 '$contact' => 'Contact name (last, first)',
225 '$contact_firstlast'=> 'Contact name (first last)',
226 '$first' => 'First name',
227 '$last' => 'Last name',
228 '$address1' => 'Address line 1',
229 '$address2' => 'Address line 2',
231 '$county' => 'County',
234 '$country' => 'Country',
235 '$daytime' => 'Day phone',
236 '$night' => 'Night phone',
237 '$mobile' => 'Mobile phone',
241 '$ship_address1' => 'Address line 1',
242 '$ship_address2' => 'Address line 2',
243 '$ship_city' => 'City',
244 '$ship_county' => 'County',
245 '$ship_state' => 'State',
246 '$ship_zip' => 'Zip',
247 '$ship_country' => 'Country',
250 '$invnum' => 'Invoice#',
251 '$_date_pretty' => 'Invoice date',
252 '$due_date' => 'Invoice due date (timestamp)',
253 '$due_date2str' => 'Invoice due date (human readable)',
256 '$pkgnum' => 'Package#',
257 '$pkg' => 'Package description',
258 '$pkg_label' => 'Description + comment',
259 '$status' => 'Status',
260 '$statuscolor' => 'Status color code',
261 '$start_ymd' => 'Start date',
262 '$setup_ymd' => 'Setup date',
263 '$last_bill_ymd' => 'Last bill date',
264 '$next_bill_ymd' => 'Next bill date',
265 '$susp_ymd' => 'Suspended on date',
266 '$cancel_ymd' => 'Canceled on date',
267 '$adjourn_ymd' => 'Adjournment date',
268 '$expire_ymd' => 'Expiration date',
269 '$labels_short' => 'Service labels',
270 '$location_label' => 'Service location',
273 '$svcnum' => 'Service#',
274 '$username' => 'Login name',
275 '$password' => 'Password',
276 '$domain' => 'Domain name',
279 '$svcnum' => 'Service#',
280 '$domain' => 'Domain name',
281 '$registrar' => 'Registrar name',
282 '$catchall' => 'Catchall email',
285 '$svcnum' => 'Service#',
286 '$phonenum' => 'Phone number',
287 '$countrycode' => 'Country code',
288 '$domain' => 'Domain name'
291 '$svcnum' => 'Service#',
292 '$ip_addr' => 'IP address',
293 '$mac_addr' => 'MAC address',
294 '$speed_up' => 'Upstream speed',
295 '$speed_down' => 'Downstream speed',
298 '$paynum' => 'Payment#',
300 '$processing_fee' => 'Processing fee',
301 '$payby' => 'Payment method',
302 '$date' => 'Payment date',
303 '$payinfo' => 'Card/account# (masked)',
304 '$payinfo_end' => 'Card/account last 4 digits',
305 '$error' => 'Decline reason',
308 '$refundnum' => 'Refund#',
309 '$refund' => 'Refund Amount',
310 '$payby' => 'Refund method',
311 '$date' => 'Refund date',
312 '$payinfo' => 'Card/account# (masked)',
313 '$payinfo_end' => 'Card/account last 4 digits',
316 '$logmessage' => 'Log entry message',
317 '$loglevel' => 'Log entry level',
318 '$logcontext' => 'Log entry context',
322 tie my %sections, 'Tie::IxHash', (
323 'contact' => 'Name and contact info (billing)',
324 'service' => 'Service address',
325 'cust_main' => 'Customer status and payment info',
326 'cust_pkg' => 'Package fields',
327 'cust_refund' => 'Refund fields',
328 'cust_bill' => 'Invoice fields',
329 'cust_pay' => 'Payment fields',
330 'svc_acct' => 'Login service fields',
331 'svc_domain'=> 'Domain service fields',
332 'svc_phone' => 'Phone service fields',
333 'svc_broadband' => 'Broadband service fields',
334 'system_log' => 'System log fields',
337 my $widget = new HTML::Widgets::SelectLayers(
338 'options' => \%sections,
339 'form_name' => 'dummy',
340 'html_between'=>'</FORM><FONT SIZE=-1>',
341 'selected_layer'=>(keys(%sections))[0],
342 'layer_callback' => sub {
344 my $html = include('/elements/table-grid.html');
345 my @hints = @{ $substitutions{$section} };
347 my $key = shift @hints;
348 $html .= qq!\n<TR><TD><A href="javascript:insertHtml('{$key}')">$key</A></TD>!;
349 $html .= "\n<TD>".shift(@hints).'</TD></TR>';
351 $html .= "\n</TABLE>";
357 <SCRIPT TYPE="text/javascript">
358 function insertHtml(what) {
359 var oEditor = CKEDITOR.instances["body"];
360 oEditor.insertHtml(what);
363 function areyousure(url, message) {
364 if (confirm(message))
365 window.location.href = url;
368 <TD valign="top"><FORM name="dummy">
371 '<P>Click above links to insert substitution code.</P>
373 Enclose substitutions and other Perl expressions in braces:
374 <BR>{ $name } = ExampleCo (Smith, John)
375 <BR>{ time2str("%D", time) } = '.time2str("%D", time).'
376 <BR>{ "processing fee of $processing_fee" if $processing_fee; } = Will display text if there is a processing fee
378 $sidebar .= include('/elements/template_image-dialog.html',
379 'callback' => 'insertHtml'
381 $sidebar .= '<P><A HREF="javascript:insertImageDialog()">Insert Uploaded Image</A></P>
385 sub html_table_bottom {
387 $cgi->param('locale') =~ /^(\w+)$/;
390 if ( $locale and $locale ne 'new' ) {
391 # set up a delete link
392 my $msgnum = $object->msgnum;
393 my $url = $fsurl."misc/delete-template_content.html?msgnum=$msgnum;locale=$1";
394 my $link = qq!<A HREF="javascript:areyousure('$url','Really delete this template?')">! .
395 'Delete this template' .
397 $html = qq!<TR><TD></TD>
398 <TD STYLE="font-style: italic; font-size: small">$link</TD></TR>!;