1 <% include( 'elements/edit.html',
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' => ['Edit global templates', 'Configuration'],
12 { field => 'agentnum',
13 type => 'select-agent',
15 { field => 'msgname', size=>60, },
16 { field => 'from_addr', size=>60, },
17 { field => 'bcc_addr', size=>60, },
18 { type => 'tablebreak-tabs',
19 include_opt_callback => \&menubar_opt_callback,
21 # template_content fields
22 { field => 'locale', type => 'hidden' },
23 { field => 'subject', size=>60, },
30 'msgnum' => 'Template',
31 'agentnum' => 'Agent',
32 'msgname' => 'Template name',
33 'from_addr' => 'From: ',
34 'bcc_addr' => 'Bcc: ',
35 'locale' => 'Language',
36 'subject' => 'Subject: ',
37 'body' => 'Message body',
39 'edit_callback' => \&edit_callback,
40 'error_callback' => \&edit_callback,
41 'html_bottom' => '</DIV>',
42 'html_foot' => "</TD>$sidebar</TR></TABLE>",
48 unless $FS::CurrentUser::CurrentUser->access_right('Edit templates')
49 || $FS::CurrentUser::CurrentUser->access_right('Edit global templates')
50 || $FS::CurrentUser::CurrentUser->access_right('Configuration');
53 $body_etc = q!onload="document.getElementById('locale').onchange()"!
54 if $cgi->param('locale') eq 'new';
57 my ($cgi, $object, $fields_listref, $opt_hashref) = @_;
58 my $template_content = new FS::template_content { 'locale' => '' };
59 $object->{'Hash'} = { $object->hash, $template_content->hash };
63 my ($cgi, $object, $fields_listref, $opt_hashref) = @_;
64 $cgi->param('locale') =~ /^(\w*)$/ or die 'bad locale '.$cgi->param('locale');
67 # fetch the content object and merge its fields
69 'msgnum' => $object->msgnum,
72 my $template_content = qsearchs('template_content', \%args)
73 || new FS::template_content( { %args });
74 $object->{'Hash'} = { $object->hash, $template_content->hash };
76 # set up the locale selector if this is a new content
77 if ( $locale eq 'new' ) {
79 # make a list of available locales
80 my $content_locales = $object->content_locales;
81 my @locales = grep { !exists($content_locales->{$_}) } FS::Locales->locales;
84 my %info = FS::Locales->locale_info($_);
85 $labels{$_} = $info{'name'}; # ignoring country for now
87 unshift @locales, 'new';
88 $labels{'new'} = 'Select language';
92 $i++ until ( $fields_listref->[$i]->{'field'} eq 'locale' );
93 my $locale_field = $fields_listref->[$i];
95 my $onchange_locale = "document.getElementById('submit').disabled =
96 (this.options[this.selectedIndex].value == 'new');";
101 options => \@locales,
104 onchange => $onchange_locale,
106 } # else it's already set up correctly
109 sub menubar_opt_callback {
111 # generate no tabs for new msg_templates.
112 my $msgnum = $object->msgnum or return;
113 my (@tabs, @options, %labels);
114 push @tabs, mt('Default'), '';
117 foreach my $l (FS::Locales->locales) {
118 if ( exists $object->content_locales->{$l} ) {
119 my %info = FS::Locales->locale_info($l);
123 $selected = $info{'name'} if $object->locale eq $l;
126 $display_new = 1; # there is at least one unused locale left
129 push @tabs, mt('New'), ';locale=new' if $display_new;
130 $selected = mt('New') if $object->locale eq 'new';
131 $selected ||= mt('Default');
133 'url_base' => $p.'edit/msg_template.html?msgnum='.$msgnum,
134 'selected' => $selected,
139 my $onchange_locale = '';
143 my %substitutions = (
145 '$display_custnum'=> 'Customer#',
146 '$agentnum' => 'Agent#',
147 '$agent_name' => 'Agent name',
148 '$payby' => 'Payment method',
149 '$paymask' => 'Card/account# (masked)',
150 '$payname' => 'Name on card/bank name',
151 '$paytype' => 'Account type',
152 '$payip' => 'IP address used to submit payment info',
153 '$num_ncancelled_pkgs' => '# of active packages',
154 '$num_cancelled_pkgs' => '# of cancelled packages',
155 '$num_pkgs' => '# of packages',
156 '$classname' => 'Customer class',
157 '$categoryname' => 'Customer category',
158 '$balance' => 'Current balance',
159 '$credit_limit' => 'Credit limit',
160 '$invoicing_list_emailonly' => 'Billing email address',
161 '$cust_status' => 'Status',
162 '$ucfirst_cust_status' => 'Status, capitalized',
163 '$cust_statuscolor' => 'Status color code',
164 '$company_name' => 'Our company name',
165 '$company_address'=> 'Our company address',
166 '$company_phonenum' => 'Our phone number',
168 'contact' => [ # duplicate this for shipping
169 '$name' => 'Company and contact name',
170 '$name_short' => 'Company or contact name',
171 '$company' => 'Company name',
172 '$contact' => 'Contact name (last, first)',
173 '$contact_firstlast'=> 'Contact name (first last)',
174 '$first' => 'First name',
175 '$last' => 'Last name',
176 '$address1' => 'Address line 1',
177 '$address2' => 'Address line 2',
179 '$county' => 'County',
182 '$country' => 'Country',
183 '$daytime' => 'Day phone',
184 '$night' => 'Night phone',
188 '$invnum' => 'Invoice#',
191 '$pkgnum' => 'Package#',
192 '$pkg' => 'Package description',
193 '$pkg_label' => 'Description + comment',
194 '$status' => 'Status',
195 '$statuscolor' => 'Status color code',
196 '$start_ymd' => 'Start date',
197 '$setup_ymd' => 'Setup date',
198 '$last_bill_ymd' => 'Last bill date',
199 '$next_bill_ymd' => 'Next bill date',
200 '$susp_ymd' => 'Suspended on date',
201 '$cancel_ymd' => 'Canceled on date',
202 '$adjourn_ymd' => 'Adjournment date',
203 '$expire_ymd' => 'Expiration date',
204 '$labels_short' => 'Service labels',
205 '$location_label' => 'Service location',
208 '$svcnum' => 'Service#',
209 '$username' => 'Login name',
210 '$password' => 'Password',
211 '$domain' => 'Domain name',
214 '$svcnum' => 'Service#',
215 '$domain' => 'Domain name',
216 '$registrar' => 'Registrar name',
217 '$catchall' => 'Catchall email',
220 '$svcnum' => 'Service#',
221 '$phonenum' => 'Phone number',
222 '$countrycode' => 'Country code',
223 '$domain' => 'Domain name'
226 '$svcnum' => 'Service#',
227 '$ip_addr' => 'IP address',
228 '$mac_addr' => 'MAC address',
229 '$speed_up' => 'Upstream speed',
230 '$speed_down' => 'Downstream speed',
233 '$paynum' => 'Payment#',
235 '$payby' => 'Payment method',
236 '$date' => 'Payment date',
237 '$payinfo' => 'Card/account# (masked)',
238 '$error' => 'Decline reason',
241 my @c = @{ $substitutions{'contact'} };
242 for (my $i=0; $i<scalar(@c); $i += 2) {
243 $c[$i] =~ s/\$(.*)/\$ship_$1/;
245 $substitutions{'shipping'} = \@c;
247 tie my %sections, 'Tie::IxHash', (
248 'contact' => 'Name and contact info (billing)',
249 'shipping' => 'Name and contact info (shipping)',
250 'cust_main' => 'Customer status and payment info',
251 'cust_pkg' => 'Package fields',
252 'cust_bill' => 'Invoice fields',
253 'cust_pay' => 'Payment fields',
254 'svc_acct' => 'Login service fields',
255 'svc_domain'=> 'Domain service fields',
256 'svc_phone' => 'Phone service fields',
257 'svc_broadband' => 'Broadband service fields',
260 my $widget = new HTML::Widgets::SelectLayers(
261 'options' => \%sections,
262 'form_name' => 'dummy',
263 'html_between'=>'</FORM><FONT SIZE=-1>',
264 'selected_layer'=>(keys(%sections))[0],
265 'layer_callback' => sub {
267 my $html = include('/elements/table-grid.html');
268 my @hints = @{ $substitutions{$section} };
270 my $key = shift @hints;
271 $html .= qq!\n<TR><TD><A href="javascript:insertHtml('{$key}')">$key</A></TD>!;
272 $html .= "\n<TD>".shift(@hints).'</TD></TR>';
274 $html .= "\n</TABLE>";
280 <SCRIPT TYPE="text/javascript">
281 function insertHtml(what) {
282 var oEditor = FCKeditorAPI.GetInstance("body");
283 oEditor.InsertHtml(what);
286 <TD valign="top"><FORM name="dummy">
289 '<BR>Click links to insert.
290 <BR>Enclose substitutions and other Perl expressions in braces:
291 <BR>{ $name } = ExampleCo (Smith, John)
292 <BR>{ time2str("%D", time) } = '.time2str("%D", time).'