4.x+ self-service API: list and remove cards on file, RT#38919
[freeside.git] / httemplate / browse / reason_type.html
1 <& elements/browse.html,
2   'title'       => ucwords($classname) . " Reasons",
3   'html_init'   => $html_init,
4   'name'        => $classname . " reason types",
5   'query'       => { 'table'     => 'reason_type',
6                     'hashref'   => {},
7                     'extra_sql' => $where_clause .
8                                    'ORDER BY typenum',
9                   },
10   'count_query' => $count_query,
11   'header'      => [ '#',
12                     ucwords($classname) . ' Reason Type',
13                     ucwords($classname) . ' Reasons',
14                   ],
15   'fields'      => [ 'typenum',
16                     'type',
17                     $reasons_sub,
18                   ],
19   'links'       => [ $link,
20                     $link,
21                     '',
22                   ],
23   'disable_total' => 1,
24 &>
25 <%init>
26
27 sub ucwords {
28   join(' ', map ucfirst($_), split(/ /, shift));
29 }
30
31 die "access denied"
32   unless $FS::CurrentUser::CurrentUser->access_right('Configuration');
33
34 $cgi->param('class') =~ /^(\w)$/ or die "illegal class";
35 my $class=$1;
36
37 my $classname = ucfirst($FS::reason_type::class_name{$class});
38
39 my $html_init = 'Reasons: ' .
40   include('/elements/menubar.html',
41     map {
42       ucfirst($FS::reason_type::class_name{$_}),
43       $p.'browse/reason_type.html?class=' .  $_
44     } keys (%FS::reason_type::class_name)
45   );
46
47 $html_init .= '<BR><P>' .
48   $classname . ' reasons ' .
49   $FS::reason_type::class_purpose{$class} .
50   '. Reason types allow reasons to be grouped for reporting purposes.' .
51   qq!<BR><BR><A HREF="${p}edit/reason_type.html?class=$class"><I>! .
52   ($classname =~ /^[aeiou]/i ? 'Add an ' : 'Add a ') .
53   lc($classname) . ' reason type</I></A>'.
54   '</P>';
55
56 my $reasons_sub = sub {
57   my $reason_type = shift;
58
59   [ ( map {
60           [
61             {
62               'data'  => $_->reason,
63               'align' => 'left',
64               'link'  => $p. "edit/reason.html?class=$class&reasonnum=".
65                              $_->reasonnum,
66             },
67           ];
68         }
69     $reason_type->enabled_reasons ),
70     [
71       {
72         'data'  => '(add)',
73         'align' => 'left',
74         'link'  => $p. "edit/reason.html?class=$class",
75         'data_style' => 'i',
76       }
77     ]
78
79   ];
80   
81 };
82
83 my $where_clause = "WHERE class='$class'";
84 my $count_query = 'SELECT COUNT(*) FROM reason_type ';
85 $count_query .= $where_clause;
86
87 my $link = [ $p.'edit/reason_type.html?class='.$class.'&typenum=', 'typenum' ];
88
89 </%init>