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, },
71 config=> { extraPlugins => 'blockprotect' },
79 { field => 'agentnum',
80 type => 'select-agent',
83 { field => 'msgname', type => 'fixed', },
84 { field => 'from_addr', type => 'fixed', },
85 { field => 'bcc_addr', type => 'fixed', },
86 { type => 'tablebreak-tabs',
87 include_opt_callback => \&menubar_opt_callback,
89 # template_content fields
90 { field => 'locale', type => 'hidden' },
91 { field => 'subject', type => 'fixed', },
101 my ($cgi, $object, $fields_listref, $opt_hashref) = @_;
102 my $template_content = new FS::template_content { 'locale' => '' };
103 $object->{'Hash'} = { $object->hash, $template_content->hash };
107 my ($cgi, $object, $fields_listref, $opt_hashref) = @_;
108 $cgi->param('locale') =~ /^(\w*)$/ or die 'bad locale '.$cgi->param('locale');
111 # fetch the content object and merge its fields
113 'msgnum' => $object->msgnum,
116 my $template_content = qsearchs('template_content', \%args)
117 || new FS::template_content( { %args });
118 $object->{'Hash'} = { $object->hash, $template_content->hash };
120 # set up the locale selector if this is a new content
121 if ( $locale eq 'new' ) {
123 # make a list of available locales
124 my $content_locales = $object->content_locales;
125 my @locales = grep { !exists($content_locales->{$_}) }
126 FS::Conf->new->config('available-locales');
129 my %info = FS::Locales->locale_info($_);
130 $labels{$_} = $info{'label'};
132 unshift @locales, 'new';
133 $labels{'new'} = 'Select language';
137 $i++ until ( $fields_listref->[$i]->{'field'} eq 'locale' );
138 my $locale_field = $fields_listref->[$i];
140 my $onchange_locale = "document.getElementById('submit').disabled =
141 (this.options[this.selectedIndex].value == 'new');";
146 options => \@locales,
149 onchange => $onchange_locale,
154 sub menubar_opt_callback {
156 # generate no tabs for new msg_templates.
157 my $msgnum = $object->msgnum or return;
158 my (@tabs, @options, %labels);
159 push @tabs, mt('Default'), '';
162 foreach my $l (FS::Locales->locales) {
163 if ( exists $object->content_locales->{$l} ) {
164 my %info = FS::Locales->locale_info($l);
168 $selected = $info{'label'} if $object->locale eq $l;
171 $display_new = 1; # there is at least one unused locale left
174 push @tabs, mt('New'), ';locale=new' if $display_new;
175 $selected = mt('New') if $object->locale eq 'new';
176 $selected ||= mt('Default');
178 'url_base' => $p.'edit/msg_template.html?msgnum='.$msgnum,
179 'selected' => $selected,
184 my $onchange_locale = '';
188 my %substitutions = (
190 '$display_custnum'=> 'Customer#',
191 '$agentnum' => 'Agent#',
192 '$agent_name' => 'Agent name',
193 '$payby' => 'Payment method',
194 '$paymask' => 'Card/account# (masked)',
195 '$payname' => 'Name on card/bank name',
196 '$paytype' => 'Account type',
197 '$payip' => 'IP address used to submit payment info',
198 '$num_ncancelled_pkgs' => '# of active packages',
199 '$num_cancelled_pkgs' => '# of cancelled packages',
200 '$num_pkgs' => '# of packages',
201 '$classname' => 'Customer class',
202 '$categoryname' => 'Customer category',
203 '$balance' => 'Current balance',
204 '$credit_limit' => 'Credit limit',
205 '$invoicing_list_emailonly' => 'Billing email address',
206 '$cust_status' => 'Status',
207 '$ucfirst_cust_status' => 'Status, capitalized',
208 '$cust_statuscolor' => 'Status color code',
209 '$company_name' => 'Our company name',
210 '$company_address'=> 'Our company address',
211 '$company_phonenum' => 'Our phone number',
212 '$selfservice_server_base_url' => 'Base URL of customer self-service',
214 'contact' => [ # duplicate this for shipping
215 '$name' => 'Company and contact name',
216 '$name_short' => 'Company or contact name',
217 '$company' => 'Company name',
218 '$contact' => 'Contact name (last, first)',
219 '$contact_firstlast'=> 'Contact name (first last)',
220 '$first' => 'First name',
221 '$last' => 'Last name',
222 '$address1' => 'Address line 1',
223 '$address2' => 'Address line 2',
225 '$county' => 'County',
228 '$country' => 'Country',
229 '$daytime' => 'Day phone',
230 '$night' => 'Night phone',
231 '$mobile' => 'Mobile phone',
235 '$ship_address1' => 'Address line 1',
236 '$ship_address2' => 'Address line 2',
237 '$ship_city' => 'City',
238 '$ship_county' => 'County',
239 '$ship_state' => 'State',
240 '$ship_zip' => 'Zip',
241 '$ship_country' => 'Country',
244 '$invnum' => 'Invoice#',
247 '$pkgnum' => 'Package#',
248 '$pkg' => 'Package description',
249 '$pkg_label' => 'Description + comment',
250 '$status' => 'Status',
251 '$statuscolor' => 'Status color code',
252 '$start_ymd' => 'Start date',
253 '$setup_ymd' => 'Setup date',
254 '$last_bill_ymd' => 'Last bill date',
255 '$next_bill_ymd' => 'Next bill date',
256 '$susp_ymd' => 'Suspended on date',
257 '$cancel_ymd' => 'Canceled on date',
258 '$adjourn_ymd' => 'Adjournment date',
259 '$expire_ymd' => 'Expiration date',
260 '$labels_short' => 'Service labels',
261 '$location_label' => 'Service location',
264 '$svcnum' => 'Service#',
265 '$username' => 'Login name',
266 '$password' => 'Password',
267 '$domain' => 'Domain name',
270 '$svcnum' => 'Service#',
271 '$domain' => 'Domain name',
272 '$registrar' => 'Registrar name',
273 '$catchall' => 'Catchall email',
276 '$svcnum' => 'Service#',
277 '$phonenum' => 'Phone number',
278 '$countrycode' => 'Country code',
279 '$domain' => 'Domain name'
282 '$svcnum' => 'Service#',
283 '$ip_addr' => 'IP address',
284 '$mac_addr' => 'MAC address',
285 '$speed_up' => 'Upstream speed',
286 '$speed_down' => 'Downstream speed',
289 '$paynum' => 'Payment#',
291 '$payby' => 'Payment method',
292 '$date' => 'Payment date',
293 '$payinfo' => 'Card/account# (masked)',
294 '$error' => 'Decline reason',
298 tie my %sections, 'Tie::IxHash', (
299 'contact' => 'Name and contact info (billing)',
300 'service' => 'Service address',
301 'cust_main' => 'Customer status and payment info',
302 'cust_pkg' => 'Package fields',
303 'cust_bill' => 'Invoice fields',
304 'cust_pay' => 'Payment fields',
305 'svc_acct' => 'Login service fields',
306 'svc_domain'=> 'Domain service fields',
307 'svc_phone' => 'Phone service fields',
308 'svc_broadband' => 'Broadband service fields',
311 my $widget = new HTML::Widgets::SelectLayers(
312 'options' => \%sections,
313 'form_name' => 'dummy',
314 'html_between'=>'</FORM><FONT SIZE=-1>',
315 'selected_layer'=>(keys(%sections))[0],
316 'layer_callback' => sub {
318 my $html = include('/elements/table-grid.html');
319 my @hints = @{ $substitutions{$section} };
321 my $key = shift @hints;
322 $html .= qq!\n<TR><TD><A href="javascript:insertHtml('{$key}')">$key</A></TD>!;
323 $html .= "\n<TD>".shift(@hints).'</TD></TR>';
325 $html .= "\n</TABLE>";
331 <SCRIPT TYPE="text/javascript">
332 function insertHtml(what) {
333 var oEditor = CKEDITOR.instances["body"];
334 oEditor.insertHtml(what);
337 function areyousure(url, message) {
338 if (confirm(message))
339 window.location.href = url;
342 <TD valign="top"><FORM name="dummy">
345 '<BR>Click links to insert.
346 <BR>Enclose substitutions and other Perl expressions in braces:
347 <BR>{ $name } = ExampleCo (Smith, John)
348 <BR>{ time2str("%D", time) } = '.time2str("%D", time).'
352 sub html_table_bottom {
354 $cgi->param('locale') =~ /^(\w+)$/;
357 if ( $locale and $locale ne 'new' ) {
358 # set up a delete link
359 my $msgnum = $object->msgnum;
360 my $url = $p."misc/delete-template_content.html?msgnum=$msgnum;locale=$1";
361 my $link = qq!<A HREF="javascript:areyousure('$url','Really delete this template?')">! .
362 'Delete this template' .
364 $html = qq!<TR><TD></TD>
365 <TD STYLE="font-style: italic; font-size: small">$link</TD></TR>!;