01d866dfbbce5106b7fbb399ae1aa865feff53eb
[freeside.git] / httemplate / edit / msg_template.html
1 <% include( 'elements/edit.html',  
2               'html_init'     => '<TABLE id="outerTable"><TR><TD>',
3               'name_singular' => 'template',
4               'table'         => 'msg_template',
5               'viewall_dir'   => 'browse',
6               'agent_virt'    => 1,
7               'agent_null'    => 1,
8               'agent_null_right' => 'Edit global templates',
9
10               'fields' => [ 'msgname',
11                             'subject',
12                             'from_addr',
13                             { field=>'body', type=>'htmlarea', width=>763 },
14                           ],
15               'labels' => { 'msgnum'    => 'Template',
16                             'msgname'   => 'Template name',
17                             'from_addr' => 'Return address',
18                             'subject'   => 'Message subject',
19                             'body'      => 'Message template',
20                           },
21               'html_foot' => "</TD>$sidebar</TR></TABLE>",
22           )
23 %>
24 <%init>
25
26 die "access denied"
27   unless $FS::CurrentUser::CurrentUser->access_right('Edit templates')
28   ||     $FS::CurrentUser::CurrentUser->access_right('Edit global templates')
29   ||     $FS::CurrentUser::CurrentUser->access_right('Configuration');
30
31 # Create hints pane
32
33 my %substitutions = (
34   'cust_main' => [
35     '$display_custnum'=> 'Customer#',
36     '$agentnum'       => 'Agent#',
37     '$agent_name'     => 'Agent name',
38     '$payby'          => 'Payment method',
39     '$paymask'        => 'Card/account# (masked)',
40     '$payname'        => 'Name on card/bank name',
41     '$paytype'        => 'Account type',
42     '$payip'          => 'IP address used to submit payment info',
43     '$num_ncancelled_pkgs'  => '# of active packages',
44     '$num_cancelled_pkgs'   => '# of cancelled packages',
45     '$num_pkgs'       => '# of packages',
46     '$classname'      => 'Customer class',
47     '$categoryname'   => 'Customer category',
48     '$balance'        => 'Current balance',
49     '$invoicing_list_emailonly' => 'Billing email address',
50     '$cust_status'    => 'Status',
51     '$ucfirst_cust_status'  => 'Status, capitalized',
52     '$cust_statuscolor'     => 'Status color code',
53   ],
54   'contact' => [ # duplicate this for shipping
55     '$name'           => 'Company and contact name',
56     '$name_short'     => 'Company or contact name',
57     '$company'        => 'Company name',
58     '$contact'        => 'Contact name (last, first)',
59     '$contact_firstlast'=> 'Contact name (first last)',
60     '$first'          => 'First name',
61     '$last'           => 'Last name',
62     '$address1'       => 'Address line 1',
63     '$address2'       => 'Address line 2',
64     '$city'           => 'City',
65     '$county'         => 'County',
66     '$state'          => 'State',
67     '$zip'            => 'Zip',
68     '$country'        => 'Country',
69     '$daytime'        => 'Day phone',
70     '$night'          => 'Night phone',
71     '$fax'            => 'Fax',
72   ],
73   'cust_bill' => [
74     '$invnum'         => 'Invoice#',
75   ],
76   'cust_pkg' => [
77     '$pkgnum'         => 'Package#',
78     '$pkg_label'      => 'Package label (short)',
79     '$pkg_label_long' => 'Package label (long)',
80     '$status'         => 'Status',
81     '$statuscolor'    => 'Status color code',
82     '$start_ymd'      => 'Start date',
83     '$setup_ymd'      => 'Setup date',
84     '$last_bill_ymd'  => 'Last bill date',
85     '$next_bill_ymd'  => 'Next bill date',
86     '$susp_ymd'       => 'Suspended on date',
87     '$cancel_ymd'     => 'Canceled on date',
88     '$adjourn_ymd'    => 'Adjournment date',
89     '$expire_ymd'     => 'Expiration date',
90     '$labels_short'   => 'Service labels',
91     '$location_label' => 'Service location',
92   ],
93   'svc_acct'  => [
94     '$username'       => 'Login name',
95     '$password'      => 'Password',
96   ],
97 );
98 my @c = @{ $substitutions{'contact'} };
99 for (my $i=0; $i<scalar(@c); $i += 2) {
100   $c[$i] =~ s/\$(.*)/\$ship_$1/;
101 }
102 $substitutions{'shipping'} = \@c;
103
104 tie my %sections, 'Tie::IxHash', (
105 'contact'   => 'Name and contact info (billing)',
106 'shipping'  => 'Name and contact info (shipping)',
107 'cust_main' => 'Customer status and payment info',
108 'cust_pkg'  => 'Package fields',
109 'cust_bill' => 'Invoice fields',
110 'svc_acct'  => 'Login service fields',
111 );
112
113 my $widget = new HTML::Widgets::SelectLayers(
114   'options'   => \%sections,
115   'form_name' => 'dummy',
116   'html_between'=>'</FORM><FONT SIZE=-1>',
117   'selected_layer'=>(keys(%sections))[0],
118   'layer_callback' => sub {
119     my $section = shift;
120     my $html = include('/elements/table-grid.html');
121     my @hints = @{ $substitutions{$section} };
122     while(@hints) {
123       my $key = shift @hints;
124       $html .= qq!\n<TR><TD><A href="javascript:insertHtml('{$key}')">$key</A></TD>!;
125       $html .= "\n<TD>".shift(@hints).'</TD></TR>';
126     }
127     $html .= "\n</TABLE>";
128     return $html;
129   },
130 );
131
132 my $sidebar = '
133 <SCRIPT TYPE="text/javascript">
134 function insertHtml(what) {
135   var oEditor = FCKeditorAPI.GetInstance("body");
136   oEditor.InsertHtml(what);
137 };
138 </SCRIPT>
139 <TD valign="top"><FORM name="dummy">
140 Substitutions: '
141 . $widget->html .
142 '<BR>Click links to insert.
143 <BR>Enclose substitutions and other Perl expressions in braces:
144 <BR>{ $name } = ExampleCo (Smith, John)
145 <BR>{ time2str("%D", time) } = '.time2str("%D", time).'
146 </FONT></TD>
147 ';
148
149 </%init>