default to a session cookie instead of setting an explicit timeout, weird timezone...
[freeside.git] / httemplate / edit / process / cgp_rule-simplified.html
1 % if ( $error ) { #redirect back to edit...
2 %   $cgi->param('error', $error);
3 <% $cgi->redirect(popurl(3).'edit/'.$opt{'redirect'}.'?'. $cgi->query_string) %>
4 % } else { #success XXX better msg talking about vacation vs. redirect all
5   <% include('/elements/header-popup.html', 'Rule updated') %>
6   <SCRIPT TYPE="text/javascript">
7     topreload();
8   </SCRIPT>
9
10   </BODY>
11   </HTML>
12 % }
13 <%init>
14
15 my %opt = @_;
16
17 my %hash = (
18   'svcnum' => scalar($cgi->param('svcnum')),
19   'name'   => $opt{'name'},
20 );
21
22 my $cgp_rule = qsearchs('cgp_rule', \%hash);
23
24 my $error = '';
25 if ( $cgp_rule ) { #updating
26   $error = $cgp_rule->delete;
27 }
28
29 $cgp_rule = new FS::cgp_rule { %hash, 'priority' => $opt{'priority'} };
30 $error ||= $cgp_rule->insert;
31
32 foreach my $condition ( @{ $opt{'conditions'} } ) {
33   my $cgp_rule_condition = new FS::cgp_rule_condition {
34     %$condition,
35     'rulenum' => $cgp_rule->rulenum,
36   };
37   $error ||= $cgp_rule_condition->insert;
38 }
39
40 foreach my $action ( @{ $opt{'actions'} } ) {
41   my $cgp_rule_action = new FS::cgp_rule_action {
42     %$action,
43     'rulenum' => $cgp_rule->rulenum,
44   };
45   $error ||= $cgp_rule_action->insert;
46 }
47
48 unless ( $error ) {
49   my $export_error = $cgp_rule->svc_export;
50   die $export_error if $export_error; #error handling sucks wrt this... shouldn't happen though
51 }
52
53 </%init>