summaryrefslogtreecommitdiff
path: root/httemplate/browse/part_pkg-fcc.html
blob: 69e7d8f31678315b13b52d7b189295e583e22c96 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
<& elements/browse.html,
  'title'                 => 'Package Definitions - FCC Options',
  'menubar'               => \@menubar,
  'html_init'             => $html_init,
  'html_form'             => $html_form,
  'name'                  => 'package definitions',
  'disableable'           => 1,
  'disabled_statuspos'    => 4,
  'agent_virt'            => 1,
  'agent_null_right'      => $edit_global,
  'agent_pos'             => 3,
  'query'                 =>
                            { 'select'    => $select,
                              'table'     => 'part_pkg',
                              'addl_from' => $addl_from,
                              'hashref'   => \%hash,
                              'extra_sql' => $extra_sql,
                              'order_by'  => "ORDER BY $orderby"
                            },
  'count_query'           => $count_query,
  'header'                => \@header,
  'fields'                => \@fields,
  'links'                 => \@links,
  'align'                 => $align,
  'link_field'            => 'pkgpart',
  'html_foot'             => $html_foot,
&>
<%init>

my $curuser = $FS::CurrentUser::CurrentUser;

my $edit        = 'Edit FCC report configuration';
my $edit_global = 'Edit FCC report configuration for all agents';
my $acl_edit        = $curuser->access_right($edit);
my $acl_edit_global = $curuser->access_right($edit_global);

die "access denied"
  unless $acl_edit || $acl_edit_global;

if ( $cgi->param('redirect') ) {
  my $session = $cgi->param('redirect');
  my $pref = $curuser->option("redirect$session");
  die "unknown redirect session $session\n" unless length($pref);
  $cgi = new CGI($pref);
  $cgi->param('redirect', $session);
}

my $conf = new FS::Conf;

my $orderby = 'pkgpart';
my %hash = ();
my $extra_count = '';

my @where = ();

# only ever show recurring packages here
$hash{'freq'} = { op=>'!=', value=>'0' };
$extra_count = " freq != '0' ";

# filter by classnum
my $classnum = '';
if ( $cgi->param('classnum') =~ /^(\d+)$/ ) {
  $classnum = $1;
  push @where, $classnum ? "classnum =  $classnum"
                         : "classnum IS NULL";
}
$cgi->delete('classnum');

# filter by agent permissions
push @where, FS::part_pkg->curuser_pkgs_sql
  unless $acl_edit_global;

my $extra_sql = scalar(@where)
                ? ( scalar(keys %hash) ? ' AND ' : ' WHERE ' ).
                  join( 'AND ', @where)
                : '';

# pull option values into the select
my @optionnames = ( qw(
  media
  is_consumer
  is_broadband technology broadband_upstream broadband_downstream
  is_phone phone_wholesale phone_vges phone_circuits 
  phone_lines phone_longdistance phone_localloop
  is_voip voip_lastmile voip_sessions
) );

my $select = join(',',
  'part_pkg.*',
  '(SELECT classname FROM pkg_class WHERE pkg_class.classnum = part_pkg.classnum) AS classname', # grr, disableable...
  @optionnames
);

my $addl_from = 
  FS::Report::FCC_477::join_optionnames(@optionnames);

my $link = [ $p.'edit/part_pkg.cgi?', 'pkgpart' ];

my @header = ( '#', 'Package', 'Comment' );
my @fields = ( 'pkgpart', 'pkg', 'comment' ,);
my $align = 'rll';
my @links = ( $link, $link, '', );

unless ( length($classnum) ) {
  push @header, 'Class';
  push @fields, 'classname';
  $align .= 'l';
}

# still include the report_option classes, to help with migration
# but not other plan options

my %report_optionname_name = map { 'report_option_'.$_->num, $_->name }
  qsearch('part_pkg_report_option', { disabled => '' });

push @header, 'Report classes';

push @fields, 
              sub {
                    my $part_pkg = shift;
                    my %options = $part_pkg->options;
                    # gather any options that are really report options,
                    # convert them to their user-friendly names,
                    # and sort them (I think?)
                    my @report_options =
                      sort { $a cmp $b }
                      map { $report_optionname_name{$_} }
                      grep { $options{$_}
                             and exists($report_optionname_name{$_}) }
                      keys %options;

                    my @rows;
                    foreach (@report_options) {
                      push @rows, [
                        { 'data'  => $_,
                          'align' => 'center',
                          'colspan' => 2
                        }
                      ];
                    } # foreach @report_options
                    \@rows;
                  };

$align .= 'cr';

# --------
# now the FCC option part
# --------

my @pkgparts;
push @header, 'FCC report parameters';
push @fields, sub {
  my $part_pkg = shift;
  my %hash = $part_pkg->fcc_options;
  include('/elements/input-fcc_options.html',
            id          => 'pkgpart'.$part_pkg->pkgpart,
            curr_value  => encode_json(\%hash),
            html_only   => 1
  );
};
$align .= 'l';

my $count_extra_sql = $extra_sql;
$count_extra_sql =~ s/^\s*AND /WHERE /i;
$extra_count = ( $count_extra_sql ? ' AND ' : ' WHERE ' ). $extra_count
  if $extra_count;
my $count_query = "SELECT COUNT(*) FROM part_pkg $count_extra_sql $extra_count";

# in case of error redirect
if ( $cgi->param('redirect') ) {
  push @header, '';
  push @fields, sub {
    my $part_pkg = shift;
    my $pkgpart = $part_pkg->pkgpart;
    '<B><FONT COLOR="#ffffff">' . $cgi->param("error$pkgpart") || '' . '</FONT></B>'
  };
  $align .= 'l';
}

my $html_init = 
  include('/elements/init_overlib.html') .
  include('/elements/input-fcc_options.html', js_only => 1) .
  include('.style') .
  include('.script');

my $html_form = qq!<FORM ACTION="${p}edit/process/bulk-part_pkg-fcc.html" METHOD="POST" NAME="bulk-part_pkg-fcc">
  <INPUT TYPE="hidden" NAME="jump">
  ( show class: !.
  include('/elements/select-pkg_class.html',
            #'curr_value'    => $classnum,
            'value'         => $classnum, #insist on 0 :/
            'onchange'      => 'filter_change()',
            'pre_options'   => [ '-1' => 'all',
                                 '0'  => '(none)', ],
            'disable_empty' => 1,
         ).
  ' )
  <BR><BR>';

# pass the page selection through so we can jump back to the current spot
if ( $cgi->param('maxrecords') =~ /^(\d+)$/ ) {
  $html_form .= qq!<INPUT TYPE="hidden" NAME="maxrecords" VALUE="$1">!;
}
if ( $cgi->param('offset') =~ /^(\d+)$/ ) {
  $html_form .= qq!<INPUT TYPE="hidden" NAME="offset" VALUE="$1">!;
}

# restore this only after creating $html_form
$cgi->param('classnum', $classnum) if length($classnum);

my $html_foot = '</FORM>';

my @menubar =
  ( 'Package definitions' => $p.'browse/part_pkg.cgi' );

</%init>
<%def .style>
<style>
  ul.fcc_options {
    text-align: left;
  }
  ul.fcc_options li {
  }
  button.edit_fcc_options {
    float: right;
  }
</style>
</%def>
<%def .script>
<script type="text/javascript">
  function finish_edit_fcc(id) {
    cClick();
    document.forms['bulk-part_pkg-fcc']['jump'].value = id;
    document.forms['bulk-part_pkg-fcc'].submit(); //immediately save/refresh
  }

  function filter_change() {
    window.location = '<% $cgi->self_url %>?classnum='
      + document.getElementById('classnum').value;
  }
</script>
</%def>