RADIUS counter/limit accounting with realms stored as @realm in UserName column inste...
[freeside.git] / httemplate / elements / tr-select-cust-part_pkg.html
1 %if ( scalar(@pkg_class) > 1 && ! $conf->exists('disable-cust-pkg_class') ) {
2
3   <& /elements/xmlhttp.html,
4                 'url'  => $p.'misc/cust-part_pkg.cgi',
5                 'subs' => [ 'get_part_pkg' ],
6   &>
7
8   <SCRIPT TYPE="text/javascript">
9
10     function part_pkg_opt(what, value, text, can_discount, can_start_date, start_date) {
11       var optionName = new Option(text, value, false, false);
12       optionName.setAttribute('data-can_discount',   can_discount);
13       optionName.setAttribute('data-can_start_date', can_start_date);
14       optionName.setAttribute('data-start_date',     start_date || '');
15       var length = what.length;
16       what.options[length] = optionName;
17     }
18
19     function classnum_changed(what) {
20
21       what.form.pkgpart.disabled = 'disabled'; //disable part_pkg dropdown
22       var submitButton = what.form.submitButton; // || what.form.submit;
23       if ( submitButton ) {
24         submitButton.disabled = true; //disable the submit button
25       }
26       var discountnum = what.form.discountnum;
27       if ( discountnum ) {
28         discountnum.disabled = true; //disable discount dropdown
29       }
30
31       classnum = what.options[what.selectedIndex].value;
32
33       function update_part_pkg(part_pkg) {
34
35         // blank the current packages
36         for ( var i = what.form.pkgpart.length; i>= 0; i-- )
37           what.form.pkgpart.options[i] = null;
38
39         // add the new packages
40         opt(what.form.pkgpart, '', 'Select package');
41         var packagesArray = eval('(' + part_pkg + ')' );
42         for ( var s = 0; s < packagesArray.length; s=s+5 ) {
43           //surely this should be some kind of JSON structure
44           var packagesLabel  = packagesArray[s+1];
45           var can_discount   = packagesArray[s+2];
46           var can_start_date = packagesArray[s+3];
47           var start_date     = packagesArray[s+4];
48           part_pkg_opt(
49             what.form.pkgpart, packagesArray[s], packagesLabel, can_discount, can_start_date, start_date
50           );
51         }
52
53         what.form.pkgpart.disabled = ''; //re-enable part_pkg dropdown
54
55       }
56
57       get_part_pkg( <% $cust_main->custnum %>, classnum, update_part_pkg );
58     
59     }
60
61     window.onload = function() {
62       classnum_changed(document.getElementById('classnum'));
63     }
64
65   </SCRIPT>
66
67   <TR>
68     <TH ALIGN="right"><% mt('Package Class') |h %></TH>
69     <TD COLSPAN=7>
70       <& /elements/select-cust-pkg_class.html,
71                    'curr_value' => $opt{'classnum'},
72                    'pkg_class'  => \@pkg_class,
73                    'onchange'   => 'classnum_changed',
74       &>
75     </TD>
76   </TR>
77
78 %}
79
80 <TR>
81   <TH ALIGN="right"><% mt('Package') |h %></TH>
82   <TD COLSPAN=7>
83     <& /elements/select-cust-part_pkg.html,
84                  'curr_value' => $opt{'curr_value'}, #$pkgpart
85                  'classnum'   => $opt{'classnum'},
86                  'cust_main'  => $opt{'cust_main'},  #$cust_main
87                  'onchange'   => 'pkg_changed',
88     &>
89   </TD>
90 </TR>
91
92 <%init>
93
94 my $conf = new FS::Conf;
95
96 my %opt = @_;
97
98 my $pre_label = $opt{'pre_label'} || '';
99 $pre_label .= ' ' if length($pre_label) && $pre_label =~ /\S$/;
100
101 my $cust_main = $opt{'cust_main'}
102   or die "cust_main not specified";
103
104 #"normal" part_pkg agent virtualization (agentnum or type)
105 my @part_pkg = qsearch({
106   'select'    => 'DISTINCT classnum',
107   'table'     => 'part_pkg',
108   'hashref'   => { 'disabled' => '' },
109   'extra_sql' =>
110     ' AND '. $FS::CurrentUser::CurrentUser->agentnums_sql( 'null'=>1 ).
111     ' AND '. FS::part_pkg->agent_pkgs_sql( $opt{'cust_main'}->agent ),
112 });
113
114 my @pkg_class =
115   sort { $a->classname cmp $b->classname } #should get a sort order in config
116   map  { $_->pkg_class || new FS::pkg_class { 'classnum'  => '',
117                                               'classname' => '(none)' }
118        }
119   @part_pkg;
120
121 </%init>