From: ivan Date: Fri, 6 Aug 2010 00:45:29 +0000 (+0000) Subject: communigate account rules: vacation & redirect all, RT#7514 X-Git-Tag: TORRUS_1_0_9~429 X-Git-Url: http://git.freeside.biz/gitweb/?p=freeside.git;a=commitdiff_plain;h=0715eb639658bfde2c21c39cd5ccaf4bf22b18d4 communigate account rules: vacation & redirect all, RT#7514 --- diff --git a/httemplate/edit/cgp_rule-redirect_all.html b/httemplate/edit/cgp_rule-redirect_all.html index 898eef8fc..c8c9e010c 100644 --- a/httemplate/edit/cgp_rule-redirect_all.html +++ b/httemplate/edit/cgp_rule-redirect_all.html @@ -1,37 +1,49 @@ <% include('/elements/header-popup.html', 'Redirect all mail') %> +<% include('/elements/error.html') %> +
-%# XXX upstream Redirect 1 + <% ntable("#cccccc", 2) %> Redirect all mail to - + <% include('/elements/tr-checkbox.html', - 'name' => 'RedirKeep', + 'field' => 'RedirKeep', 'label' => 'Keep a copy', 'value' => 1, - 'curr_value' => '', #XXX + 'curr_value' => ( $cgi->param('error') + ? scalar($cgi->param('RedirKeep')) + : ( ($redir_keep || !$cgp_rule) ? '' : 1 ) + ), ) %> <% include('/elements/tr-checkbox.html', - 'name' => 'RedirHuman', + 'field' => 'RedirHuman', 'label' => 'Do not redirect automatic messages', 'value' => 1, - 'curr_value' => '', #XXX + 'curr_value' => ( $cgi->param('error') + ? scalar($cgi->param('RedirHuman')) + : ( $redir_human ? 1 : '' ) + ), ) %> <% include('/elements/tr-checkbox.html', - 'name' => 'KeepToAndCc', + 'field' => 'KeepToAndCc', 'label' => 'Preserve To/Cc fields', 'value' => 1, - 'curr_value' => '', #XXX + 'curr_value' => ( $cgi->param('error') + ? scalar($cgi->param('KeepToAndCc')) + : ( $mirror_or_redir && + $mirror_or_redir->action eq 'Mirror To' ) + ), ) %> @@ -39,7 +51,6 @@
-%#XXX Add/Edit
@@ -52,6 +63,27 @@ my %opt = @_; my $svc_acct = qsearchs('svc_acct', { 'svcnum' => $opt{'svcnum'} } ) or die "unknown svcnum"; -#XXX look for existing redirect all rule +#look for existing rule +my $cgp_rule = qsearchs('cgp_rule', { 'svcnum' => $svc_acct->svcnum, + 'name' => '#Redirect' + } + ); + +my( $redir_human, $mirror_or_redir, $redir_keep ) = ( '', '', '' ); +if ( $cgp_rule ) { + $redir_human = qsearchs('cgp_rule_condition', { + 'rulenum' => $cgp_rule->rulenum, + 'conditionname' => 'Human Generated', + }); + $mirror_or_redir = qsearchs({ + 'table' => 'cgp_rule_action', + 'hashref' => { 'rulenum' => $cgp_rule->rulenum, }, + 'extra_sql' => " AND action IN ('Mirror To', 'Redirect To') ", + }); + $redir_keep = qsearchs('cgp_rule_action', { + 'rulenum' => $cgp_rule->rulenum, + 'action' => 'Discard', + }); +} diff --git a/httemplate/edit/cgp_rule-vacation.html b/httemplate/edit/cgp_rule-vacation.html index efdc5417e..8c288852b 100644 --- a/httemplate/edit/cgp_rule-vacation.html +++ b/httemplate/edit/cgp_rule-vacation.html @@ -1,35 +1,35 @@ <% include('/elements/header-popup.html', 'Vacation rule') %> +<% include('/elements/error.html') %> +
-%# XXX upstream Vacation 1 + <% ntable("#cccccc", 2) %> Vacation message - + <% include('/elements/tr-input-date-field.html', { - 'label' => 'Ends', - 'name' => 'vacationTill', - 'value' => '', #XXX + 'label' => 'Ends', + 'name' => 'vacationTill', + 'format' => '%d %b %Y', + 'value' => ( $cgi->param('error') + ? scalar($cgi->param('vacationTill')) + : ( $curr_date ? $curr_date->params : '' ) + ), }) %> -%# XXX upstream: -%# VacationTill 1 -%# vacationDay -%# vacationMonth -%# vacationYear -%#XXX Clear 'Replied Addresses' List +%#Clear 'Replied Addresses' List ?
- -%#XXX Add/Edit +
@@ -42,6 +42,23 @@ my %opt = @_; my $svc_acct = qsearchs('svc_acct', { 'svcnum' => $opt{'svcnum'} } ) or die "unknown svcnum"; -#XXX look for existing vacation rule +#look for existing rule +my $cgp_rule = qsearchs('cgp_rule', { 'svcnum' => $svc_acct->svcnum, + 'name' => '#Vacation' + } + ); + +my( $curr_date, $reply_with ) = ( '', '' ); +if ( $cgp_rule ) { + $curr_date = qsearchs('cgp_rule_condition', { + 'rulenum' => $cgp_rule->rulenum, + 'conditionname' => 'Current Date', + 'op' => 'less than', + }); + $reply_with = qsearchs('cgp_rule_action', { + 'rulenum' => $cgp_rule->rulenum, + 'action' => 'Reply with', + }); +} diff --git a/httemplate/edit/process/cgp_rule-redirect_all.html b/httemplate/edit/process/cgp_rule-redirect_all.html new file mode 100644 index 000000000..162d857c2 --- /dev/null +++ b/httemplate/edit/process/cgp_rule-redirect_all.html @@ -0,0 +1,24 @@ +<% include('cgp_rule-simplified.html', + 'name' => '#Redirect', + 'priority' => 1, + 'redirect' => 'cgp_rule-redirect_all.html', + 'conditions' => [ + ( $cgi->param('RedirHuman') + ? { conditionname => 'Human Generated', } + : () + ), + ], + 'actions' => [ + { action => ( $cgi->param('KeepToAndCc') + ? 'Mirror To' + : 'Redirect To' + ), + params => scalar($cgi->param('RedirectText')), + }, + ( $cgi->param('RedirKeep') + ? () + : ( { 'action' => 'Discard' } ) + ), + ], + ) +%> diff --git a/httemplate/edit/process/cgp_rule-simplified.html b/httemplate/edit/process/cgp_rule-simplified.html new file mode 100644 index 000000000..60769d4e6 --- /dev/null +++ b/httemplate/edit/process/cgp_rule-simplified.html @@ -0,0 +1,53 @@ +% if ( $error ) { #redirect back to edit... +% $cgi->param('error', $error); +<% $cgi->redirect(popurl(3).'edit/'.$opt{'redirect'}.'?'. $cgi->query_string) %> +% } else { #success XXX better msg talking about vacation vs. redirect all + <% include('/elements/header-popup.html', 'Rule updated') %> + + + + +% } +<%init> + +my %opt = @_; + +my %hash = ( + 'svcnum' => scalar($cgi->param('svcnum')), + 'name' => $opt{'name'}, +); + +my $cgp_rule = qsearchs('cgp_rule', \%hash); + +my $error = ''; +if ( $cgp_rule ) { #updating + $error = $cgp_rule->delete; +} + +$cgp_rule = new FS::cgp_rule { %hash, 'priority' => $opt{'priority'} }; +$error ||= $cgp_rule->insert; + +foreach my $condition ( @{ $opt{'conditions'} } ) { + my $cgp_rule_condition = new FS::cgp_rule_condition { + %$condition, + 'rulenum' => $cgp_rule->rulenum, + }; + $error ||= $cgp_rule_condition->insert; +} + +foreach my $action ( @{ $opt{'actions'} } ) { + my $cgp_rule_action = new FS::cgp_rule_action { + %$action, + 'rulenum' => $cgp_rule->rulenum, + }; + $error ||= $cgp_rule_action->insert; +} + +unless ( $error ) { + my $export_error = $cgp_rule->svc_export; + die $export_error if $export_error; #error handling sucks wrt this... shouldn't happen though +} + + diff --git a/httemplate/edit/process/cgp_rule-vacation.html b/httemplate/edit/process/cgp_rule-vacation.html new file mode 100644 index 000000000..f10d72b73 --- /dev/null +++ b/httemplate/edit/process/cgp_rule-vacation.html @@ -0,0 +1,29 @@ +<% include('cgp_rule-simplified.html', + 'name' => '#Vacation', + 'priority' => 2, + 'redirect' => 'cgp_rule-vacation.html', + 'conditions' => [ + { conditionname => 'Human Generated', }, + { conditionname => 'From', + op => 'not in', + params => '#RepliedAddresses', + }, + ( $cgi->param('VacationTill') + ? ( { conditionname => 'Current Date', + op => 'less than', #is less? + params => scalar($cgi->param('VacationTill')), + } + ) + : () + ), + ], + 'actions' => [ + { action => 'Reply with', + params => scalar($cgi->param('VacationText')), + }, + { action => "Remember 'From' in", + params => 'RepliedAddresses', + }, + ], + ) +%> diff --git a/httemplate/view/svc_acct/communigate.html b/httemplate/view/svc_acct/communigate.html index 0f090fdb9..870744a87 100644 --- a/httemplate/view/svc_acct/communigate.html +++ b/httemplate/view/svc_acct/communigate.html @@ -54,17 +54,16 @@ value=>$svc_acct->cgp_sendmdnmode ) %> %# vacation message -%#XXX finish me... do we need to search for specific rules -%# (and hide them?) need to see what CGP gives back after we've added a rule <% include('/elements/init_overlib.html') %> Vacation message + <% $vacation_rule ? 'Active' : '' %> <% include('/elements/popup_link.html', 'action' => $p.'edit/cgp_rule-vacation.html?'. 'svcnum='. $svc_acct->svcnum, - 'label' => '(add)', #XXX (edit) + 'label' => $vacation_rule ? '(edit)' : '(add)', 'actionlabel' => 'Vacation message', 'width' => 600, 'height' => 300, @@ -75,15 +74,15 @@ %# redirect all mail -%#XXX finish me... Redirect all mail + <% $redirect_rule ? 'Active' : '' %> <% include('/elements/popup_link.html', 'action' => $p.'edit/cgp_rule-redirect_all.html?'. 'svcnum='. $svc_acct->svcnum, - 'label' => '(add)', #XXX (edit) + 'label' => $redirect_rule ? '(edit)' : '(add)', 'actionlabel' => 'Redirect all mail', 'width' => 763, #'height' @@ -110,6 +109,16 @@ my $svc_acct = $opt{'svc_acct'}; #my $part_svc = $opt{'part_svc'}; my $rule_link = qq(View/edit mail rules'; + $svc_acct->svcnum. '">View/edit mail rules'; #'dum vim + +my $vacation_rule = qsearchs('cgp_rule', { 'svcnum' => $svc_acct->svcnum, + 'name' => '#Vacation' + } + ); + +my $redirect_rule = qsearchs('cgp_rule', { 'svcnum' => $svc_acct->svcnum, + 'name' => '#Redirect' + } + );