diff options
author | ivan <ivan> | 2010-08-06 00:45:29 +0000 |
---|---|---|
committer | ivan <ivan> | 2010-08-06 00:45:29 +0000 |
commit | 0715eb639658bfde2c21c39cd5ccaf4bf22b18d4 (patch) | |
tree | a4abf0d4d046b65151d8e7d13657467b8f2322de | |
parent | b93983d6758cd67b7bcb6c4118344981d8bb6e8d (diff) |
communigate account rules: vacation & redirect all, RT#7514
-rw-r--r-- | httemplate/edit/cgp_rule-redirect_all.html | 52 | ||||
-rw-r--r-- | httemplate/edit/cgp_rule-vacation.html | 45 | ||||
-rw-r--r-- | httemplate/edit/process/cgp_rule-redirect_all.html | 24 | ||||
-rw-r--r-- | httemplate/edit/process/cgp_rule-simplified.html | 53 | ||||
-rw-r--r-- | httemplate/edit/process/cgp_rule-vacation.html | 29 | ||||
-rw-r--r-- | httemplate/view/svc_acct/communigate.html | 21 |
6 files changed, 194 insertions, 30 deletions
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') %> + <FORM NAME="RedirectAllForm" ACTION="process/cgp_rule-redirect_all.html" METHOD=POST> -%# XXX upstream Redirect 1 +<INPUT TYPE="hidden" NAME="svcnum" VALUE="<% $opt{'svcnum'} %>"> <% ntable("#cccccc", 2) %> <TR> <TD ALIGN="right">Redirect all mail to</TD> - <TD><textarea name="RedirectText" rows="5" cols="50"></textarea></TD> + <TD><textarea name="RedirectText" rows="5" cols="50"><% $mirror_or_redir ? $mirror_or_redir->params : '' %></textarea></TD> </TR> <% 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 @@ <BR> <INPUT TYPE="submit" VALUE="Redirect all mail"> -%#XXX Add/Edit </FORM> @@ -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', + }); +} </%init> 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') %> + <FORM NAME="VacationForm" ACTION="process/cgp_rule-vacation.html" METHOD=POST> -%# XXX upstream Vacation 1 +<INPUT TYPE="hidden" NAME="svcnum" VALUE="<% $opt{'svcnum'} %>"> <% ntable("#cccccc", 2) %> <TR> <TD ALIGN="right">Vacation message</TD> - <TD><textarea name="VacationText" rows="5" cols="50"></textarea></TD> + <TD><textarea name="VacationText" rows="5" cols="50"><% $reply_with ? $reply_with->params : '' %></textarea></TD> </TR> <% 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 ? </TABLE> <BR> -<INPUT TYPE="submit" VALUE="Add vacation message"> -%#XXX Add/Edit +<INPUT TYPE="submit" VALUE="<% $cgp_rule ? 'Edit' : 'Add' %> vacation message"> </FORM> @@ -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', + }); +} </%init> 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') %> + <SCRIPT TYPE="text/javascript"> + window.top.location.reload(); + </SCRIPT> + + </BODY> + </HTML> +% } +<%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 +} + +</%init> 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') %> <TR> <TD ALIGN="right">Vacation message</TD> <TD BGCOLOR="#FFFFFF"> + <% $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 @@ </TR> %# redirect all mail -%#XXX finish me... <TR> <TD ALIGN="right">Redirect all mail</TD> <TD BGCOLOR="#FFFFFF"> + <% $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(<A HREF="${p}browse/cgp_rule.html?svcnum=). - $svc_acct->svcnum. '">View/edit mail rules</A>'; + $svc_acct->svcnum. '">View/edit mail rules</A>'; #'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' + } + ); </%init> |