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 (raw internal label)',
207 '$cust_status_label' => 'Status (display label)',
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#',
245 '$_date_pretty' => 'Invoice date',
246 '$due_date' => 'Invoice due date (timestamp)',
247 '$due_date2str' => 'Invoice due date (human readable)',
250 '$pkgnum' => 'Package#',
251 '$pkg' => 'Package description',
252 '$pkg_label' => 'Description + comment',
253 '$status' => 'Status',
254 '$statuscolor' => 'Status color code',
255 '$start_ymd' => 'Start date',
256 '$setup_ymd' => 'Setup date',
257 '$last_bill_ymd' => 'Last bill date',
258 '$next_bill_ymd' => 'Next bill date',
259 '$susp_ymd' => 'Suspended on date',
260 '$cancel_ymd' => 'Canceled on date',
261 '$adjourn_ymd' => 'Adjournment date',
262 '$expire_ymd' => 'Expiration date',
263 '$labels_short' => 'Service labels',
264 '$location_label' => 'Service location',
267 '$svcnum' => 'Service#',
268 '$username' => 'Login name',
269 '$password' => 'Password',
270 '$domain' => 'Domain name',
273 '$svcnum' => 'Service#',
274 '$domain' => 'Domain name',
275 '$registrar' => 'Registrar name',
276 '$catchall' => 'Catchall email',
279 '$svcnum' => 'Service#',
280 '$phonenum' => 'Phone number',
281 '$countrycode' => 'Country code',
282 '$domain' => 'Domain name'
285 '$svcnum' => 'Service#',
286 '$ip_addr' => 'IP address',
287 '$mac_addr' => 'MAC address',
288 '$speed_up' => 'Upstream speed',
289 '$speed_down' => 'Downstream speed',
292 '$paynum' => 'Payment#',
294 '$payby' => 'Payment method',
295 '$date' => 'Payment date',
296 '$payinfo' => 'Card/account# (masked)',
297 '$error' => 'Decline reason',
301 tie my %sections, 'Tie::IxHash', (
302 'contact' => 'Name and contact info (billing)',
303 'service' => 'Service address',
304 'cust_main' => 'Customer status and payment info',
305 'cust_pkg' => 'Package fields',
306 'cust_bill' => 'Invoice fields',
307 'cust_pay' => 'Payment fields',
308 'svc_acct' => 'Login service fields',
309 'svc_domain'=> 'Domain service fields',
310 'svc_phone' => 'Phone service fields',
311 'svc_broadband' => 'Broadband service fields',
314 my $widget = new HTML::Widgets::SelectLayers(
315 'options' => \%sections,
316 'form_name' => 'dummy',
317 'html_between'=>'</FORM><FONT SIZE=-1>',
318 'selected_layer'=>(keys(%sections))[0],
319 'layer_callback' => sub {
321 my $html = include('/elements/table-grid.html');
322 my @hints = @{ $substitutions{$section} };
324 my $key = shift @hints;
325 $html .= qq!\n<TR><TD><A href="javascript:insertHtml('{$key}')">$key</A></TD>!;
326 $html .= "\n<TD>".shift(@hints).'</TD></TR>';
328 $html .= "\n</TABLE>";
334 <SCRIPT TYPE="text/javascript">
335 function insertHtml(what) {
336 var oEditor = CKEDITOR.instances["body"];
337 oEditor.insertHtml(what);
340 function areyousure(url, message) {
341 if (confirm(message))
342 window.location.href = url;
345 <TD valign="top"><FORM name="dummy">
348 '<BR>Click links to insert.
349 <BR>Enclose substitutions and other Perl expressions in braces:
350 <BR>{ $name } = ExampleCo (Smith, John)
351 <BR>{ time2str("%D", time) } = '.time2str("%D", time).'
355 sub html_table_bottom {
357 $cgi->param('locale') =~ /^(\w+)$/;
360 if ( $locale and $locale ne 'new' ) {
361 # set up a delete link
362 my $msgnum = $object->msgnum;
363 my $url = $p."misc/delete-template_content.html?msgnum=$msgnum;locale=$1";
364 my $link = qq!<A HREF="javascript:areyousure('$url','Really delete this template?')">! .
365 'Delete this template' .
367 $html = qq!<TR><TD></TD>
368 <TD STYLE="font-style: italic; font-size: small">$link</TD></TR>!;