diff options
Diffstat (limited to 'httemplate/browse/cgp_rule.html')
-rw-r--r-- | httemplate/browse/cgp_rule.html | 113 |
1 files changed, 113 insertions, 0 deletions
diff --git a/httemplate/browse/cgp_rule.html b/httemplate/browse/cgp_rule.html new file mode 100644 index 0000000..8a427b8 --- /dev/null +++ b/httemplate/browse/cgp_rule.html @@ -0,0 +1,113 @@ +<% 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', 'Conditions', 'Actions', '' ], + 'fields' => [ sub { shift->priority || 'Inactive'; }, + 'name', + $condition_sub, + $action_sub, + 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 $part_svc = $cust_svc->part_svc; + +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' => $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>!; + +if ( $part_svc->svcdb eq 'svc_domain' ) { + + #areyousure for adding these? + + foreach my $line ( FS::Conf->new->config('cgp_rule-domain_templates') ) { + $line =~ /^\s*(\d+)\s+(.+)\s*$/ or next; + my($t_svcnum, $t_name) = ( $1, $2 ); + $html_init .= + qq!<A HREF="${p}misc/clone-cgp_rule.html?clone=$t_svcnum;svcnum=$svcnum">! + ."Add $t_name rule</A><BR>"; + } + +} + +$html_init .= + '<BR>'. + qq! + <SCRIPT> + function areyousure_delete(href) { + areyousure(href,"Are you sure you want to delete this rule?"); + } + function areyousure(href,message) { + if (confirm(message) == true) + window.location.href = href; + } + </SCRIPT> +!; + +my $condition_sub = sub { + my $cgp_rule = shift; + + [ map { + [ + { data => $_->conditionname, + #align => + }, + { data => $_->op, + align => 'center', + }, + { data => $_->params, + #align => + }, + ]; + } + $cgp_rule->cgp_rule_condition + ]; +}; + +my $action_sub = sub { + my $cgp_rule = shift; + + [ map { + [ + { data => $_->action }, + #{ data => '<pre>'.$_->params.'</pre>' }, #gets very big.. limit to + { data => $_->params }, # some actions? + ]; + } + $cgp_rule->cgp_rule_action + ]; +}; + +my $edit_sub = [ $p.'edit/cgp_rule.html?', 'rulenum' ]; +my $del_sub = sub { + my $rulenum = shift->rulenum; + [ "javascript:areyousure_delete('${p}misc/delete-cgp_rule.html?$rulenum')", '' ]; +}; + +</%init> |