message templates, RT#8896
authorivan <ivan>
Mon, 12 Jul 2010 13:18:06 +0000 (13:18 +0000)
committerivan <ivan>
Mon, 12 Jul 2010 13:18:06 +0000 (13:18 +0000)
FS/FS.pm
FS/FS/AccessRight.pm
FS/FS/Schema.pm
FS/FS/msg_template.pm [new file with mode: 0644]
FS/MANIFEST
FS/t/msg_template.t [new file with mode: 0644]
httemplate/browse/msg_template.html [new file with mode: 0644]
httemplate/edit/msg_template.html [new file with mode: 0644]
httemplate/edit/process/msg_template.html [new file with mode: 0644]
httemplate/elements/menu.html
httemplate/elements/tr-htmlarea.html [new file with mode: 0644]

index 3a51230..51d63ba 100644 (file)
--- a/FS/FS.pm
+++ b/FS/FS.pm
@@ -326,7 +326,9 @@ L<FS::queue_arg> - Job arguments
 
 L<FS::queue_depend> - Job dependencies
 
-L<FS::msgcat> - Message catalogs
+L<FS::msg_template> - Message templates (customer notices)
+
+L<FS::msgcat> - Message catalogs (error messages)
 
 L<FS::clientapi_session>
 
index fbe5496..322fa3d 100644 (file)
@@ -268,7 +268,10 @@ tie my %rights, 'Tie::IxHash',
   
     'Edit billing events',
     { rightname=>'Edit global billing events', global=>1 },
-  
+
+    'Edit templates',
+    { rightname=>'Edit global templates', global=>1 },
+
     { rightname=>'Dialup configuration' },
     { rightname=>'Dialup global configuration', global=>1 },
 
index 84ca0a7..531a3ca 100644 (file)
@@ -2677,6 +2677,20 @@ sub tables_hashref {
       'index'       => [['listnum'],['svcnum'],['email']],
     },
 
+    'msg_template' => {
+      'columns' => [
+        'msgnum',     'serial',     '',      '', '', '',
+        'msgname',   'varchar',     '', $char_d, '', '',
+        'agentnum',      'int', 'NULL',      '', '', '',
+        'mime_type', 'varchar',     '', $char_d, '', '',
+        'body',         'blob', 'NULL',      '', '', '',
+        'disabled',     'char', 'NULL',       1, '', '', 
+      ],
+      'primary_key' => 'msgnum',
+      'unique'      => [ ['msgname', 'mime_type'] ],
+      'index'       => [ ['agentnum'], ]
+    },
+
 
     # name type nullability length default local
 
diff --git a/FS/FS/msg_template.pm b/FS/FS/msg_template.pm
new file mode 100644 (file)
index 0000000..7bf0504
--- /dev/null
@@ -0,0 +1,144 @@
+package FS::msg_template;
+
+use strict;
+use base qw( FS::Record );
+use FS::Record qw( qsearch qsearchs );
+
+=head1 NAME
+
+FS::msg_template - Object methods for msg_template records
+
+=head1 SYNOPSIS
+
+  use FS::msg_template;
+
+  $record = new FS::msg_template \%hash;
+  $record = new FS::msg_template { 'column' => 'value' };
+
+  $error = $record->insert;
+
+  $error = $new_record->replace($old_record);
+
+  $error = $record->delete;
+
+  $error = $record->check;
+
+=head1 DESCRIPTION
+
+An FS::msg_template object represents a customer message template.
+FS::msg_template inherits from FS::Record.  The following fields are currently
+supported:
+
+=over 4
+
+=item msgnum
+
+primary key
+
+=item msgname
+
+msgname
+
+=item agentnum
+
+agentnum
+
+=item mime_type
+
+mime_type
+
+=item body
+
+body
+
+=item disabled
+
+disabled
+
+
+=back
+
+=head1 METHODS
+
+=over 4
+
+=item new HASHREF
+
+Creates a new template.  To add the template to the database, see L<"insert">.
+
+Note that this stores the hash reference, not a distinct copy of the hash it
+points to.  You can ask the object for a copy with the I<hash> method.
+
+=cut
+
+# the new method can be inherited from FS::Record, if a table method is defined
+
+sub table { 'msg_template'; }
+
+=item insert
+
+Adds this record to the database.  If there is an error, returns the error,
+otherwise returns false.
+
+=cut
+
+# the insert method can be inherited from FS::Record
+
+=item delete
+
+Delete this record from the database.
+
+=cut
+
+# the delete method can be inherited from FS::Record
+
+=item replace OLD_RECORD
+
+Replaces the OLD_RECORD with this one in the database.  If there is an error,
+returns the error, otherwise returns false.
+
+=cut
+
+# the replace method can be inherited from FS::Record
+
+=item check
+
+Checks all fields to make sure this is a valid template.  If there is
+an error, returns the error, otherwise returns false.  Called by the insert
+and replace methods.
+
+=cut
+
+# the check method should currently be supplied - FS::Record contains some
+# data checking routines
+
+sub check {
+  my $self = shift;
+
+  my $error = 
+    $self->ut_numbern('msgnum')
+    || $self->ut_text('msgname')
+    || $self->ut_foreign_keyn('agentnum', 'agent', 'agentnum')
+    || $self->ut_textn('mime_type')
+    || $self->ut_anything('body')
+    || $self->ut_enum('disabled', [ '', 'Y' ] )
+  ;
+  return $error if $error;
+
+  $self->mime_type('text/html') unless $self->mime_type;
+
+  $self->SUPER::check;
+}
+
+=back
+
+=head1 BUGS
+
+=head1 SEE ALSO
+
+L<FS::Record>, schema.html from the base documentation.
+
+=cut
+
+1;
+
index f491b6c..f21105d 100644 (file)
@@ -494,3 +494,5 @@ FS/cgp_rule_condition.pm
 t/cgp_rule_condition.t
 FS/cgp_rule_action.pm
 t/cgp_rule_action.t
+FS/msg_template.pm
+t/msg_template.t
diff --git a/FS/t/msg_template.t b/FS/t/msg_template.t
new file mode 100644 (file)
index 0000000..cec1d41
--- /dev/null
@@ -0,0 +1,5 @@
+BEGIN { $| = 1; print "1..1\n" }
+END {print "not ok 1\n" unless $loaded;}
+use FS::msg_template;
+$loaded=1;
+print "ok 1\n";
diff --git a/httemplate/browse/msg_template.html b/httemplate/browse/msg_template.html
new file mode 100644 (file)
index 0000000..331906c
--- /dev/null
@@ -0,0 +1,27 @@
+<% include( 'elements/browse.html',
+              'title'         => 'Message templates',
+              'name_singular' => 'template',
+              'menubar'     => [ 'Add a new template' =>
+                                   $p.'edit/msg_template.html',
+                               ],
+              'query'       => { 'table' => 'msg_template', },
+              'count_query' => 'SELECT COUNT(*) FROM msg_template',
+              'disableable' => 1,
+              'disabled_statuspos' => 2,
+              'agent_virt'         => 1,
+              'agent_null_right'   => 'Edit global templates',
+              'agent_pos'          => 3,
+              'header' => [ 'Name' ],
+              'fields' => [ 'msgname' ],
+              'links'  => [ $link ],
+          )
+%>
+<%init>
+
+die "access denied"
+  unless $FS::CurrentUser::CurrentUser->access_right('Edit templates')
+  ||     $FS::CurrentUser::CurrentUser->access_right('Edit global templates');
+
+my $link = [ "${p}edit/msg_template.html?", 'msgnum' ];
+
+</%init>
diff --git a/httemplate/edit/msg_template.html b/httemplate/edit/msg_template.html
new file mode 100644 (file)
index 0000000..6632d02
--- /dev/null
@@ -0,0 +1,16 @@
+<% include( 'elements/edit.html',  
+              'name_singular' => 'template',
+              'table'         => 'msg_template',
+              'viewall_dir'   => 'browse',
+              'fields' => [ 'msgname',
+                            { field=>'body', type=>'htmlarea' },
+                          ],
+          )
+%>
+<%init>
+
+die "access denied"
+  unless $FS::CurrentUser::CurrentUser->access_right('Edit templates')
+  ||     $FS::CurrentUser::CurrentUser->access_right('Edit global templates');
+
+</%init>
diff --git a/httemplate/edit/process/msg_template.html b/httemplate/edit/process/msg_template.html
new file mode 100644 (file)
index 0000000..5cf88bf
--- /dev/null
@@ -0,0 +1,12 @@
+<% include( 'elements/process.html',  
+              'table'       => 'msg_template',
+              'viewall_dir' => 'browse',
+          )
+%>
+<%init>
+
+die "access denied"
+  unless $FS::CurrentUser::CurrentUser->access_right('Edit templates')
+  ||     $FS::CurrentUser::CurrentUser->access_right('Edit global templates');
+
+</%init>
index a68a575..427caca 100644 (file)
@@ -416,6 +416,9 @@ tie my %config_phone, 'Tie::IxHash',
 ;
 
 tie my %config_misc, 'Tie::IxHash';
+$config_misc{'Message templates'} = [ $fsurl.'browse/msg_template.html', 'Templates for customer notices' ]
+  if $curuser->access_right('Edit templates')
+  || $curuser->access_right('Edit global templates');
 $config_misc{'Advertising sources'} = [ $fsurl.'browse/part_referral.html', 'Where a customer heard about your service.  Tracked for informational purposes' ]
   if $curuser->access_right('Edit advertising sources')
   || $curuser->access_right('Edit global advertising sources');
diff --git a/httemplate/elements/tr-htmlarea.html b/httemplate/elements/tr-htmlarea.html
new file mode 100644 (file)
index 0000000..1a4e250
--- /dev/null
@@ -0,0 +1,25 @@
+<% include('tr-td-label.html', @_ ) %>
+
+  <TD <% $cell_style %>>
+
+    <% include('htmlarea.html', @_ ) %>
+
+  </TD>
+
+</TR>
+
+<%init>
+
+my %opt = @_;
+
+my $onchange = $opt{'onchange'}
+                 ? 'onChange="'. $opt{'onchange'}. '(this)"'
+                 : '';
+
+#my $rows = $opt{'rows'} ? 'ROWS="'.$opt{'rows'}.'"' : '';
+#my $cols = $opt{'cols'} ? 'COLS="'.$opt{'cols'}.'"' : '';
+
+my $cell_style = $opt{'cell_style'} ? 'STYLE="'. $opt{'cell_style'}. '"' : '';
+#my $curr_value = $opt{'curr_value'};
+
+</%init>