use FS::cust_pkg_discount;
use FS::cust_bill_pkg_discount;
use FS::svc_mailinglist;
+ use FS::cgp_rule;
# Sammath Naur
if ( $FS::Mason::addl_handler_use ) {
'cgp_rule' => {
'columns' => [
- 'rulenum', 'serial', '', '', '', '',
- 'name', 'varchar', '', $char_d, '', '',
- 'comment', 'varchar', '', $char_d, '', '',
- 'svcnum', 'int', '', '', '', '',
- 'priority', 'int', '', '', '', '',
+ 'rulenum', 'serial', '', '', '', '',
+ 'name', 'varchar', '', $char_d, '', '',
+ 'comment', 'varchar', 'NULL', $char_d, '', '',
+ 'svcnum', 'int', '', '', '', '',
+ 'priority', 'int', '', '', '', '',
],
'primary_key' => 'rulenum',
'unique' => [],
- 'index ' => [ [ 'svcnum' ] ],
+ 'index' => [ [ 'svcnum' ] ],
},
'cgp_rule_condition' => {
],
'primary_key' => 'ruleconditionnum',
'unique' => [],
- 'index ' => [ [ 'rulenum' ] ],
+ 'index' => [ [ 'rulenum' ] ],
},
'cgp_rule_action' => {
],
'primary_key' => 'ruleactionnum',
'unique' => [],
- 'index ' => [ [ 'rulenum' ] ],
+ 'index' => [ [ 'rulenum' ] ],
},
'svc_forward' => {
use strict;
use base qw( FS::Record );
-use FS::Record qw( qsearch qsearchs );
+use FS::Record qw( qsearch qsearchs dbh );
+use FS::cust_svc;
+use FS::cgp_rule_condition;
+use FS::cgp_rule_action;
=head1 NAME
=head1 DESCRIPTION
-An FS::cgp_rule object represents an example. FS::cgp_rule inherits from
-FS::Record. The following fields are currently supported:
+An FS::cgp_rule object represents a mail filtering rule. FS::cgp_rule
+inherits from FS::Record. The following fields are currently supported:
=over 4
=item new HASHREF
-Creates a new example. To add the example to the database, see L<"insert">.
+Creates a new rule. To add the rule 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 delete method can be inherited from FS::Record
+sub delete {
+ my $self = shift;
+
+ local $SIG{HUP} = 'IGNORE';
+ local $SIG{INT} = 'IGNORE';
+ local $SIG{QUIT} = 'IGNORE';
+ local $SIG{TERM} = 'IGNORE';
+ local $SIG{TSTP} = 'IGNORE';
+ local $SIG{PIPE} = 'IGNORE';
+
+ my $oldAutoCommit = $FS::UID::AutoCommit;
+ local $FS::UID::AutoCommit = 0;
+ my $dbh = dbh;
+
+ my @del = $self->cgp_rule_condition;
+ push @del, $self->cgp_rule_action;
+
+ foreach my $del (@del) {
+ my $error = $del->delete;
+ if ( $error ) {
+ $dbh->rollback if $oldAutoCommit;
+ return $error;
+ }
+ }
+
+ my $error = $self->SUPER::delete(@_);
+ if ( $error ) {
+ $dbh->rollback if $oldAutoCommit;
+ return $error;
+ }
+
+ $dbh->commit or die $dbh->errstr if $oldAutoCommit;
+
+}
=item replace OLD_RECORD
=item check
-Checks all fields to make sure this is a valid example. If there is
+Checks all fields to make sure this is a valid rule. If there is
an error, returns the error, otherwise returns false. Called by the insert
and replace methods.
my $error =
$self->ut_numbern('rulenum')
|| $self->ut_text('name')
- || $self->ut_text('comment')
- || $self->ut_number('svcnum')
+ || $self->ut_textn('comment')
+ || $self->ut_foreign_key('svcnum', 'cust_svc', 'svcnum')
|| $self->ut_number('priority')
;
return $error if $error;
$self->SUPER::check;
}
+=item cust_svc
+
+=cut
+
+sub cust_svc {
+ my $self = shift;
+ qsearchs('cust_svc', { 'svcnum' => $self->svcnum } );
+}
+
+=item cgp_rule_condition
+
+Returns the conditions associated with this rule, as FS::cgp_rule_condition
+objects.
+
+=cut
+
+sub cgp_rule_condition {
+ my $self = shift;
+ qsearch('cgp_rule_condition', { 'rulenum' => $self->rulenum } );
+}
+
+=item cgp_rule_action
+
+Returns the actions associated with this rule, as FS::cgp_rule_action
+objects.
+
+=cut
+
+sub cgp_rule_action {
+ my $self = shift;
+ qsearch('cgp_rule_action', { 'rulenum' => $self->rulenum } );
+}
+
=back
=head1 BUGS
-The author forgot to customize this manpage.
-
=head1 SEE ALSO
L<FS::Record>, schema.html from the base documentation.
use strict;
use base qw( FS::Record );
use FS::Record qw( qsearch qsearchs );
+use FS::cgp_rule;
=head1 NAME
=head1 DESCRIPTION
-An FS::cgp_rule_action object represents an example. FS::cgp_rule_action inherits from
-FS::Record. The following fields are currently supported:
+An FS::cgp_rule_action object represents a mail filtering action.
+FS::cgp_rule_action inherits from FS::Record. The following fields are
+currently supported:
=over 4
=item new HASHREF
-Creates a new example. To add the example to the database, see L<"insert">.
+Creates a new action. To add the action 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.
=item check
-Checks all fields to make sure this is a valid example. If there is
+Checks all fields to make sure this is a valid action. If there is
an error, returns the error, otherwise returns false. Called by the insert
and replace methods.
$self->ut_numbern('ruleactionnum')
|| $self->ut_text('action')
|| $self->ut_text('params')
- || $self->ut_number('rulenum')
+ || $self->ut_foreign_key('rulenum', 'cgp_rule', 'rulenum')
;
return $error if $error;
=head1 BUGS
-The author forgot to customize this manpage.
-
=head1 SEE ALSO
L<FS::Record>, schema.html from the base documentation.
use strict;
use base qw( FS::Record );
use FS::Record qw( qsearch qsearchs );
+use FS::cgp_rule;
=head1 NAME
=head1 DESCRIPTION
-An FS::cgp_rule_condition object represents an example. FS::cgp_rule_condition inherits from
-FS::Record. The following fields are currently supported:
+An FS::cgp_rule_condition object represents a mail filtering condition.
+FS::cgp_rule_condition inherits from FS::Record. The following fields are
+currently supported:
=over 4
=item new HASHREF
-Creates a new example. To add the example to the database, see L<"insert">.
+Creates a new condition. To add the condition 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.
=item check
-Checks all fields to make sure this is a valid example. If there is
+Checks all fields to make sure this is a valid condition. If there is
an error, returns the error, otherwise returns false. Called by the insert
and replace methods.
|| $self->ut_text('condition')
|| $self->ut_text('op')
|| $self->ut_text('params')
- || $self->ut_number('rulenum')
+ || $self->ut_foreign_key('rulenum', 'cgp_rule', 'rulenum')
;
return $error if $error;
=head1 BUGS
-The author forgot to customize this manpage.
-
=head1 SEE ALSO
L<FS::Record>, schema.html from the base documentation.
--- /dev/null
+<% include('elements/browse.html',
+ 'title' => "Rules for $svc_label: $svc_value",
+ 'name_singular' => 'rule',
+ 'html_init' => $html_init,
+ 'query' => { 'table' => 'cgp_rule',
+ 'hashref' => { 'svcnum' => $svcnum },
+ 'order_by' => 'ORDER BY priority DESC',
+ },
+ 'count_query' => $count_query,
+ 'header' => [ 'Priority', 'Name', '' ],
+ 'fields' => [ sub { shift->priority || 'Inactive'; },
+ 'name',
+ sub { 'Delete'; },
+ ],
+ #'align'
+ 'links' => [ $edit_sub, $edit_sub, $del_sub ],
+ )
+%>
+<%init>
+
+$cgi->param('svcnum') =~ /^(\d+)$/ or die 'no svcnum';
+my $svcnum = $1;
+
+#agent virt so you can't do cross-agent communigate rules
+my $cust_svc = qsearchs('cust_svc', { 'svcnum' => $svcnum })
+ or die 'unknown svcnum';
+
+my $count_query = "SELECT COUNT(*) FROM cgp_rule WHERE svcnum = $svcnum";
+
+my($svc_label, $svc_value, $svcdb) = $cust_svc->label;
+
+
+my $view = FS::UI::Web::svc_url( 'm' => $m,
+ 'action' => 'view',
+ 'part_svc' => $cust_svc->part_svc,
+ 'svc' => $cust_svc,
+ );
+
+my $html_init =
+ qq(<A HREF="$view">View this $svc_label</A><BR><BR>).
+ qq!<A HREF="${p}edit/cgp_rule.html?svcnum=$svcnum">Add new rule</A><BR><BR>!;
+
+my $edit_sub = [ $p.'edit/cgp_rule.html?', 'rulenum' ];
+my $del_sub = [ $p.'misc/delete-cgp_rule.html?', 'rulenum' ]; #XXX javascript areyousure or something
+
+</%init>
--- /dev/null
+<% include('elements/edit.html',
+ 'name_singular' => 'rule',
+ 'table' => 'cgp_rule',
+ 'labels' => { 'rulenum' => 'Rule',
+ 'name' => 'Name',
+ 'comment' => 'Comment',
+ 'priority' => 'Priority',
+ },
+ 'fields' => [ 'name',
+ 'comment',
+ { 'field' => 'priority',
+ 'type' => 'select',
+ 'options' => [ 0 .. 10 ],
+ 'labels' => { 0 => 'Inactive' },
+ },
+ { 'field' => 'svcnum', 'type' => 'hidden', },
+ ],
+ 'new_callback' => sub { my( $cgi, $cgp_rule ) = @_;
+ $cgp_rule->svcnum( $cgi->param('svcnum') );
+ },
+ #'viewall_url' => $viewall_url,
+ 'menubar' => [],
+ )
+%>
+<%init>
+
+#my $svcnum #huh
+#my $viewall_url = $p. "browse/$table.html?svcnum=$svcnum";
+
+</%init>
--- /dev/null
+<% include( 'elements/process.html',
+ 'table' => 'cgp_rule',
+ 'redirect' => $redirect,
+ )
+%>
+<%init>
+
+my $redirect = sub {
+ my($cgi, $new) = @_;
+ my $svcnum = $new->svcnum;
+ popurl(3)."browse/cgp_rule.html?svcnum=$svcnum;rulenum=";
+};
+
+</%init>
--- /dev/null
+% if ( $error ) {
+% errorpage($error);
+% } else {
+<% $cgi->redirect($p. "browse/cgp_rule.html?svcnum=". $svcnum) %>
+% }
+<%init>
+
+# :/ needs agent-virt so you can't futz with arbitrary rules
+
+#die "access denied"
+# unless $FS::CurrentUser::CurrentUser->access_right('Provision customer service');
+
+#untaint devicenum
+my($query) = $cgi->keywords;
+$query =~ /^(\d+)$/ || die "Illegal rulenum";
+my $rulenum = $1;
+
+my $cgp_rule = qsearchs('cgp_rule', { 'rulenum' => $rulenum } );
+my $svcnum = $cgp_rule->svcnum;
+
+my $error = $cgp_rule->delete;
+
+</%init>
% } elsif ( $opt{'communigate'} ) {
-%# settings
-
- <% include('/view/elements/tr.html', label=>'Mailbox type', value=>$svc_acct->cgp_type) %>
-
- <% include('/view/elements/tr.html', label=>'Enabled services',
- value=>$svc_acct->cgp_accessmodes ) %>
-
- <% include('/view/elements/tr.html', label=>'Mail storage limit',
- value=>$svc_acct->quota ) %>
-
- <% include('/view/elements/tr.html', label=>'File storage limit',
- value=>$svc_acct->file_quota ) %>
-
- <% include('/view/elements/tr.html', label=>'Number of files limit',
- value=>$svc_acct->file_maxnum ) %>
-
- <% include('/view/elements/tr.html', label=>'File size limit',
- value=>$svc_acct->file_maxsize ) %>
-
- <% include('/view/elements/tr.html', label=>'Password recovery',
- value=>$svc_acct->password_recover ? 'YES' : 'NO' ) %>
-
- <% include('/view/elements/tr.html', label=>'Allowed mail rules',
- value=>$svc_acct->cgp_rulesallowed || 'default (No)') %>
-
- <% include('/view/elements/tr.html', label=>'RPOP modifications',
- value=>$svc_acct->cgp_rpopallowed ? 'YES' : 'NO' ) %>
-
- <% include('/view/elements/tr.html', label=>'Accepts mail to "all"',
- value=>$svc_acct->cgp_mailtoall ? 'YES' : 'NO' ) %>
-
- <% include('/view/elements/tr.html', label=>'Add trailer to sent mail',
- value=>$svc_acct->cgp_addmailtrailer ? 'YES' : 'NO' ) %>
-
-%# preferences
-
- <% include('/view/elements/tr.html', label=>'Message delete method',
- value=>$svc_acct->cgp_deletemode ) %>
-
- <% include('/view/elements/tr.html', label=>'On logout remove trash',
- value=>$svc_acct->cgp_emptytrash ) %>
-
- <% include('/view/elements/tr.html', label=>'Language',
- value=>$svc_acct->cgp_language || 'default (English)' ) %>
- <% include('/view/elements/tr.html', label=>'Time zone',
- value=>$svc_acct->cgp_timezone || 'default (HostOS)' ) %>
- <% include('/view/elements/tr.html', label=>'Layout',
- value=>$svc_acct->cgp_skinname || 'default (***)' ) %>
-
- <% include('/view/elements/tr.html', label=>'Pronto style',
- value=>$svc_acct->cgp_prontoskinname ) %>
-
- <% include('/view/elements/tr.html', label=>'Send read receipts',
- value=>$svc_acct->cgp_sendmdnmode ) %>
-
-%#XXX vacation message, redirect all mail, mail rules
+ <% include( 'communigate.html', %opt ) %>
% }
--- /dev/null
+%# settings
+
+ <% include('/view/elements/tr.html', label=>'Mailbox type', value=>$svc_acct->cgp_type) %>
+
+ <% include('/view/elements/tr.html', label=>'Enabled services',
+ value=>$svc_acct->cgp_accessmodes ) %>
+
+ <% include('/view/elements/tr.html', label=>'Mail storage limit',
+ value=>$svc_acct->quota ) %>
+
+ <% include('/view/elements/tr.html', label=>'File storage limit',
+ value=>$svc_acct->file_quota ) %>
+
+ <% include('/view/elements/tr.html', label=>'Number of files limit',
+ value=>$svc_acct->file_maxnum ) %>
+
+ <% include('/view/elements/tr.html', label=>'File size limit',
+ value=>$svc_acct->file_maxsize ) %>
+
+ <% include('/view/elements/tr.html', label=>'Password recovery',
+ value=>$svc_acct->password_recover ? 'YES' : 'NO' ) %>
+
+ <% include('/view/elements/tr.html', label=>'Allowed mail rules',
+ value=>$svc_acct->cgp_rulesallowed || 'default (No)') %>
+
+ <% include('/view/elements/tr.html', label=>'RPOP modifications',
+ value=>$svc_acct->cgp_rpopallowed ? 'YES' : 'NO' ) %>
+
+ <% include('/view/elements/tr.html', label=>'Accepts mail to "all"',
+ value=>$svc_acct->cgp_mailtoall ? 'YES' : 'NO' ) %>
+
+ <% include('/view/elements/tr.html', label=>'Add trailer to sent mail',
+ value=>$svc_acct->cgp_addmailtrailer ? 'YES' : 'NO' ) %>
+
+%# preferences
+
+ <% include('/view/elements/tr.html', label=>'Message delete method',
+ value=>$svc_acct->cgp_deletemode ) %>
+
+ <% include('/view/elements/tr.html', label=>'On logout remove trash',
+ value=>$svc_acct->cgp_emptytrash ) %>
+
+ <% include('/view/elements/tr.html', label=>'Language',
+ value=>$svc_acct->cgp_language || 'default (English)' ) %>
+ <% include('/view/elements/tr.html', label=>'Time zone',
+ value=>$svc_acct->cgp_timezone || 'default (HostOS)' ) %>
+ <% include('/view/elements/tr.html', label=>'Layout',
+ value=>$svc_acct->cgp_skinname || 'default (***)' ) %>
+
+ <% include('/view/elements/tr.html', label=>'Pronto style',
+ value=>$svc_acct->cgp_prontoskinname ) %>
+
+ <% include('/view/elements/tr.html', label=>'Send read receipts',
+ value=>$svc_acct->cgp_sendmdnmode ) %>
+
+%#XXX vacation message, redirect all mail
+
+%# mail rules
+
+ <% include('/view/elements/tr.html', label=>'Mail rules',
+ value=>$rule_link,
+ )
+ %>
+
+<%init>
+
+my %opt = @_;
+
+#my $conf = new FS::Conf;
+
+my $svc_acct = $opt{'svc_acct'};
+#my $part_svc = $opt{'part_svc'};
+
+my $rule_link = qq(<A HREF="${p}browse/cgp_rule.html?svcnum=).
+ $svc_acct->svcnum. '">View/edit mail rules</A>';
+
+</%init>
</TD>
</TR>
-<TR>
- <TD ALIGN="right">Enabled services</TD>
- <TD BGCOLOR="#ffffff"><% $svc_domain->cgp_accessmodes %></TD>
-</TR>
+% if ( $svc_domain->cgp_accessmodes ) {
+ <TR>
+ <TD ALIGN="right">Enabled services</TD>
+ <TD BGCOLOR="#ffffff"><% $svc_domain->cgp_accessmodes %></TD>
+ </TR>
+% }
% if ( $svc_domain->trailer ) {
<TR>
</TR>
% }
+% if ( $communigate ) {
+% my $rule_url = $p. 'browse/cgp_rule.html?svcnum='. $svc_domain->svcnum;
+ <TR>
+ <TD ALIGN="right">Doimain mail rules</TD>
+ <TD BGCOLOR="#ffffff"><A HREF="<% $rule_url %>">View/Edit domain mail rules</A></TD>
+ </TR>
+% }
+
</TABLE></TD></TR></TABLE>
<%init>