From e491946343abd5b7dddfd19f20a44ceb767bd37b Mon Sep 17 00:00:00 2001 From: ivan Date: Mon, 12 Jul 2010 13:18:06 +0000 Subject: [PATCH] message templates, RT#8896 --- FS/FS.pm | 4 +- FS/FS/AccessRight.pm | 5 +- FS/FS/Schema.pm | 14 +++ FS/FS/msg_template.pm | 144 ++++++++++++++++++++++++++++++ FS/MANIFEST | 2 + FS/t/msg_template.t | 5 ++ httemplate/browse/msg_template.html | 27 ++++++ httemplate/edit/msg_template.html | 16 ++++ httemplate/edit/process/msg_template.html | 12 +++ httemplate/elements/menu.html | 3 + httemplate/elements/tr-htmlarea.html | 25 ++++++ 11 files changed, 255 insertions(+), 2 deletions(-) create mode 100644 FS/FS/msg_template.pm create mode 100644 FS/t/msg_template.t create mode 100644 httemplate/browse/msg_template.html create mode 100644 httemplate/edit/msg_template.html create mode 100644 httemplate/edit/process/msg_template.html create mode 100644 httemplate/elements/tr-htmlarea.html diff --git a/FS/FS.pm b/FS/FS.pm index 3a512305d..51d63bafc 100644 --- a/FS/FS.pm +++ b/FS/FS.pm @@ -326,7 +326,9 @@ L - Job arguments L - Job dependencies -L - Message catalogs +L - Message templates (customer notices) + +L - Message catalogs (error messages) L diff --git a/FS/FS/AccessRight.pm b/FS/FS/AccessRight.pm index fbe549693..322fa3d12 100644 --- a/FS/FS/AccessRight.pm +++ b/FS/FS/AccessRight.pm @@ -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 }, diff --git a/FS/FS/Schema.pm b/FS/FS/Schema.pm index 84ca0a744..531a3ca0b 100644 --- a/FS/FS/Schema.pm +++ b/FS/FS/Schema.pm @@ -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 index 000000000..7bf050441 --- /dev/null +++ b/FS/FS/msg_template.pm @@ -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 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, schema.html from the base documentation. + +=cut + +1; + diff --git a/FS/MANIFEST b/FS/MANIFEST index f491b6cd7..f21105d2e 100644 --- a/FS/MANIFEST +++ b/FS/MANIFEST @@ -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 index 000000000..cec1d41af --- /dev/null +++ b/FS/t/msg_template.t @@ -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 index 000000000..331906ccf --- /dev/null +++ b/httemplate/browse/msg_template.html @@ -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' ]; + + diff --git a/httemplate/edit/msg_template.html b/httemplate/edit/msg_template.html new file mode 100644 index 000000000..6632d027a --- /dev/null +++ b/httemplate/edit/msg_template.html @@ -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'); + + diff --git a/httemplate/edit/process/msg_template.html b/httemplate/edit/process/msg_template.html new file mode 100644 index 000000000..5cf88bfad --- /dev/null +++ b/httemplate/edit/process/msg_template.html @@ -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'); + + diff --git a/httemplate/elements/menu.html b/httemplate/elements/menu.html index a68a5754d..427caca20 100644 --- a/httemplate/elements/menu.html +++ b/httemplate/elements/menu.html @@ -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 index 000000000..1a4e25080 --- /dev/null +++ b/httemplate/elements/tr-htmlarea.html @@ -0,0 +1,25 @@ +<% include('tr-td-label.html', @_ ) %> + + > + + <% include('htmlarea.html', @_ ) %> + + + + + +<%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'}; + + -- 2.11.0