default to a session cookie instead of setting an explicit timeout, weird timezone...
[freeside.git] / httemplate / edit / process / msg_template.html
1 <% include( 'elements/process.html',  
2               'table'       => 'msg_template',
3               'fields'      => $fields,
4               'viewall_url' => "browse/msg_template/$msgclass.html",
5               'debug'       => 0,
6               'precheck_callback' => \&precheck_callback,
7               'args_callback' => \&args_callback,
8           )
9 %>
10 <%init>
11 die "access denied"
12   unless $FS::CurrentUser::CurrentUser->access_right(['Edit templates','Edit global templates']);
13
14 my $msgclass = 'email';
15 if ( $cgi->param('msgclass') =~ /^(\w+)$/ ) {
16   $msgclass = $1;
17 }
18
19 my $fields = [ fields('msg_template') ];
20 my $class = "FS::msg_template::$msgclass";
21 eval "use $class;";
22 if ( $class->extension_table ) {
23   push @$fields, fields($class->extension_table);
24 }
25
26 sub precheck_callback {
27   my $cgi = shift;
28   # validate locale field (for email-type records)
29   $cgi->param('locale') =~ /^(\w*)$/;
30   my $locale = $1;
31   return mt('Language required') if $locale eq 'new'; # the user didn't choose
32   die "unknown locale $locale" if ( $locale and 
33                                     !FS::Locales->locale_info($locale) );
34 }
35
36 sub args_callback {
37   my ($cgi, $object) = @_;
38   my %content;
39   $cgi->param('locale') =~ /^(\w*)$/;
40   $content{'locale'} = $1;
41   # no validation of these; they can contain just about anything
42   $content{'subject'} = $cgi->param('subject') || '';
43   $content{'body'} = $cgi->param('body') || '';
44   $object->subject('');
45   $object->body('');
46   return %content;
47 }
48
49 </%init>