summaryrefslogtreecommitdiff
path: root/httemplate/edit
diff options
context:
space:
mode:
Diffstat (limited to 'httemplate/edit')
-rw-r--r--httemplate/edit/cgp_rule-redirect_all.html52
-rw-r--r--httemplate/edit/cgp_rule-vacation.html45
-rw-r--r--httemplate/edit/process/cgp_rule-redirect_all.html24
-rw-r--r--httemplate/edit/process/cgp_rule-simplified.html53
-rw-r--r--httemplate/edit/process/cgp_rule-vacation.html29
5 files changed, 179 insertions, 24 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',
+ },
+ ],
+ )
+%>