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: ',
18 'locale' => 'Language',
19 'subject' => 'Subject: ',
20 'body' => 'Message body',
22 'edit_callback' => \&edit_callback,
23 'error_callback' => \&edit_callback,
24 'html_bottom' => '</DIV>',
25 'html_foot' => ( $no_submit ? '' : "</TD>$sidebar</TR></TABLE>" ),
26 'no_submit' => $no_submit,
30 my $curuser = $FS::CurrentUser::CurrentUser;
33 unless $curuser->access_right([ 'View templates', 'View global templates',
34 'Edit templates', 'Edit global templates',
38 $body_etc = q!onload="document.getElementById('locale').onchange()"!
39 if $cgi->param('locale') eq 'new';
41 my $msgnum = $cgi->param('msgnum');
42 my $msg_template = $msgnum ? qsearchs('msg_template', {msgnum=>$msgnum}) : '';
46 if ( $curuser->access_right('Edit global templates')
47 || ( $curuser->access_right('Edit templates')
49 && $msg_template->agentnum
50 && $curuser->agentnums_href->{$msg_template->agentnum}
55 { field => 'agentnum',
56 type => 'select-agent',
58 { field => 'msgname', size=>60, },
59 { field => 'from_addr', size=>60, },
60 { field => 'bcc_addr', size=>60, },
61 { type => 'tablebreak-tabs',
62 include_opt_callback => \&menubar_opt_callback,
64 # template_content fields
65 { field => 'locale', type => 'hidden' },
66 { field => 'subject', size=>60, },
77 { field => 'agentnum',
78 type => 'select-agent',
81 { field => 'msgname', type => 'fixed', },
82 { field => 'from_addr', type => 'fixed', },
83 { field => 'bcc_addr', type => 'fixed', },
84 { type => 'tablebreak-tabs',
85 include_opt_callback => \&menubar_opt_callback,
87 # template_content fields
88 { field => 'locale', type => 'hidden' },
89 { field => 'subject', type => 'fixed', },
99 my ($cgi, $object, $fields_listref, $opt_hashref) = @_;
100 my $template_content = new FS::template_content { 'locale' => '' };
101 $object->{'Hash'} = { $object->hash, $template_content->hash };
105 my ($cgi, $object, $fields_listref, $opt_hashref) = @_;
106 $cgi->param('locale') =~ /^(\w*)$/ or die 'bad locale '.$cgi->param('locale');
109 # fetch the content object and merge its fields
111 'msgnum' => $object->msgnum,
114 my $template_content = qsearchs('template_content', \%args)
115 || new FS::template_content( { %args });
116 $object->{'Hash'} = { $object->hash, $template_content->hash };
118 # set up the locale selector if this is a new content
119 if ( $locale eq 'new' ) {
121 # make a list of available locales
122 my $content_locales = $object->content_locales;
123 my @locales = grep { !exists($content_locales->{$_}) } FS::Locales->locales;
126 my %info = FS::Locales->locale_info($_);
127 $labels{$_} = $info{'name'}; # ignoring country for now
129 unshift @locales, 'new';
130 $labels{'new'} = 'Select language';
134 $i++ until ( $fields_listref->[$i]->{'field'} eq 'locale' );
135 my $locale_field = $fields_listref->[$i];
137 my $onchange_locale = "document.getElementById('submit').disabled =
138 (this.options[this.selectedIndex].value == 'new');";
143 options => \@locales,
146 onchange => $onchange_locale,
148 } # else it's already set up correctly
151 sub menubar_opt_callback {
153 # generate no tabs for new msg_templates.
154 my $msgnum = $object->msgnum or return;
155 my (@tabs, @options, %labels);
156 push @tabs, mt('Default'), '';
159 foreach my $l (FS::Locales->locales) {
160 if ( exists $object->content_locales->{$l} ) {
161 my %info = FS::Locales->locale_info($l);
165 $selected = $info{'name'} if $object->locale eq $l;
168 $display_new = 1; # there is at least one unused locale left
171 push @tabs, mt('New'), ';locale=new' if $display_new;
172 $selected = mt('New') if $object->locale eq 'new';
173 $selected ||= mt('Default');
175 'url_base' => $p.'edit/msg_template.html?msgnum='.$msgnum,
176 'selected' => $selected,
181 my $onchange_locale = '';
185 my %substitutions = (
187 '$display_custnum'=> 'Customer#',
188 '$agentnum' => 'Agent#',
189 '$agent_name' => 'Agent name',
190 '$payby' => 'Payment method',
191 '$paymask' => 'Card/account# (masked)',
192 '$payname' => 'Name on card/bank name',
193 '$paytype' => 'Account type',
194 '$payip' => 'IP address used to submit payment info',
195 '$num_ncancelled_pkgs' => '# of active packages',
196 '$num_cancelled_pkgs' => '# of cancelled packages',
197 '$num_pkgs' => '# of packages',
198 '$classname' => 'Customer class',
199 '$categoryname' => 'Customer category',
200 '$balance' => 'Current balance',
201 '$credit_limit' => 'Credit limit',
202 '$invoicing_list_emailonly' => 'Billing email address',
203 '$cust_status' => 'Status',
204 '$ucfirst_cust_status' => 'Status, capitalized',
205 '$cust_statuscolor' => 'Status color code',
206 '$company_name' => 'Our company name',
207 '$company_address'=> 'Our company address',
208 '$company_phonenum' => 'Our phone number',
210 'contact' => [ # duplicate this for shipping
211 '$name' => 'Company and contact name',
212 '$name_short' => 'Company or contact name',
213 '$company' => 'Company name',
214 '$contact' => 'Contact name (last, first)',
215 '$contact_firstlast'=> 'Contact name (first last)',
216 '$first' => 'First name',
217 '$last' => 'Last name',
218 '$address1' => 'Address line 1',
219 '$address2' => 'Address line 2',
221 '$county' => 'County',
224 '$country' => 'Country',
225 '$daytime' => 'Day phone',
226 '$night' => 'Night phone',
227 '$mobile' => 'Mobile phone',
231 '$ship_address1' => 'Address line 1',
232 '$ship_address2' => 'Address line 2',
233 '$ship_city' => 'City',
234 '$ship_county' => 'County',
235 '$ship_state' => 'State',
236 '$ship_zip' => 'Zip',
237 '$ship_country' => 'Country',
240 '$invnum' => 'Invoice#',
243 '$pkgnum' => 'Package#',
244 '$pkg' => 'Package description',
245 '$pkg_label' => 'Description + comment',
246 '$status' => 'Status',
247 '$statuscolor' => 'Status color code',
248 '$start_ymd' => 'Start date',
249 '$setup_ymd' => 'Setup date',
250 '$last_bill_ymd' => 'Last bill date',
251 '$next_bill_ymd' => 'Next bill date',
252 '$susp_ymd' => 'Suspended on date',
253 '$cancel_ymd' => 'Canceled on date',
254 '$adjourn_ymd' => 'Adjournment date',
255 '$expire_ymd' => 'Expiration date',
256 '$labels_short' => 'Service labels',
257 '$location_label' => 'Service location',
260 '$svcnum' => 'Service#',
261 '$username' => 'Login name',
262 '$password' => 'Password',
263 '$domain' => 'Domain name',
266 '$svcnum' => 'Service#',
267 '$domain' => 'Domain name',
268 '$registrar' => 'Registrar name',
269 '$catchall' => 'Catchall email',
272 '$svcnum' => 'Service#',
273 '$phonenum' => 'Phone number',
274 '$countrycode' => 'Country code',
275 '$domain' => 'Domain name'
278 '$svcnum' => 'Service#',
279 '$ip_addr' => 'IP address',
280 '$mac_addr' => 'MAC address',
281 '$speed_up' => 'Upstream speed',
282 '$speed_down' => 'Downstream speed',
285 '$paynum' => 'Payment#',
287 '$payby' => 'Payment method',
288 '$date' => 'Payment date',
289 '$payinfo' => 'Card/account# (masked)',
290 '$error' => 'Decline reason',
294 tie my %sections, 'Tie::IxHash', (
295 'contact' => 'Name and contact info (billing)',
296 'service' => 'Service address',
297 'cust_main' => 'Customer status and payment info',
298 'cust_pkg' => 'Package fields',
299 'cust_bill' => 'Invoice fields',
300 'cust_pay' => 'Payment fields',
301 'svc_acct' => 'Login service fields',
302 'svc_domain'=> 'Domain service fields',
303 'svc_phone' => 'Phone service fields',
304 'svc_broadband' => 'Broadband service fields',
307 my $widget = new HTML::Widgets::SelectLayers(
308 'options' => \%sections,
309 'form_name' => 'dummy',
310 'html_between'=>'</FORM><FONT SIZE=-1>',
311 'selected_layer'=>(keys(%sections))[0],
312 'layer_callback' => sub {
314 my $html = include('/elements/table-grid.html');
315 my @hints = @{ $substitutions{$section} };
317 my $key = shift @hints;
318 $html .= qq!\n<TR><TD><A href="javascript:insertHtml('{$key}')">$key</A></TD>!;
319 $html .= "\n<TD>".shift(@hints).'</TD></TR>';
321 $html .= "\n</TABLE>";
327 <SCRIPT TYPE="text/javascript">
328 function insertHtml(what) {
329 var oEditor = FCKeditorAPI.GetInstance("body");
330 oEditor.InsertHtml(what);
333 <TD valign="top"><FORM name="dummy">
336 '<BR>Click links to insert.
337 <BR>Enclose substitutions and other Perl expressions in braces:
338 <BR>{ $name } = ExampleCo (Smith, John)
339 <BR>{ time2str("%D", time) } = '.time2str("%D", time).'