RADIUS group enhancements, overlimit_groups changes, etc. RT13432
[freeside.git] / httemplate / edit / svc_dsl.cgi
1 <% include( 'elements/svc_Common.html',
2               'table'              => 'svc_dsl',
3               'fields'             => \@fields,
4               'svc_new_callback'   => $new_cb,
5               'svc_edit_callback'  => $edit_cb,
6               'svc_error_callback' => $error_cb,
7               'html_foot'          => $html_foot,
8           )
9 %>
10 <%init>
11
12 die "access denied"
13   unless $FS::CurrentUser::CurrentUser->access_right('Provision customer service'); #something else more specific?
14
15 my $conf = new FS::Conf;
16 my $date_format = $conf->config('date_format') || '%m/%d/%Y';
17
18 my $ti_fields = FS::svc_dsl->table_info->{'fields'};
19
20 my @fields = ();
21
22 my $html_foot = sub { "
23 <SCRIPT TYPE=\"text/javascript\">
24   function ikano_loop_type_changed() {
25         var loop_type = document.getElementById('loop_type').value;
26         var phonenum = document.getElementById('phonenum');
27         if(loop_type == '0') {
28             phonenum.value = '';
29             phonenum.disabled = true;        
30         }
31         else phonenum.disabled = false;
32   }
33 </SCRIPT>
34 "; };
35
36 my $edit_cb = sub {
37     my( $cgi,$svc_x, $part_svc,$cust_pkg, $fields1,$opt) = @_;
38     my @exports = $part_svc->part_export_dsl_pull;
39     die "more than one DSL-pulling export attached to svcpart ".$part_svc->svcpart
40         if ( scalar(@exports) > 1 );
41
42     if ( scalar(@exports) == 1 ) {
43         my $export = @exports[0];                
44         if($export->exporttype eq 'ikano' && $export->import_mode) {
45             @fields = ();
46         }
47         elsif($export->exporttype eq 'ikano') {
48             @fields = ( 'password', 'monitored', );
49
50             foreach my $hf ( keys %$ti_fields ) {
51                 push @fields, {
52                     field => $hf,
53                     type => 'hidden',
54                     value => $svc_x->$hf,
55                 } unless ( $hf eq 'password' || $hf eq 'monitored' );
56             }
57         }
58         # else add any other export-specific stuff here
59     }
60     else {
61         push @fields, qw( first last company phonenum circuitnum rate_band vpi vci );
62     }
63 };
64
65 my $new_cb = sub {
66     my( $cgi,$svc_x, $part_svc,$cust_pkg, $fields1,$opt) = @_;
67     my @exports = $part_svc->part_export_dsl_pull;
68     die "more than one DSL-pulling export for svcpart ".$part_svc->svcpart
69       if ( scalar(@exports) > 1 );
70     
71     if ( scalar(@exports) == 1 ) {
72         my $export = @exports[0];                
73         if($export->exporttype eq 'ikano' && $export->import_mode) {
74             @fields = ( 'vendor_order_id' );
75             return;
76         }
77     }
78
79     my $cust_main = $cust_pkg->cust_main;
80
81     @fields = (
82         { field => 'first',
83           value => $cust_main->ship_first ? $cust_main->ship_first
84                                           : $cust_main->first,
85         },
86         { field => 'last',
87           value => $cust_main->ship_last ? $cust_main->ship_last
88                                          : $cust_main->last,
89         },
90         { field => 'company',
91           value => $cust_pkg->cust_main->ship_company,
92           value => $cust_main->ship_company ? $cust_main->ship_company
93                                             : $cust_main->company,
94         },
95     );
96
97     my $vendor_qual_id = '';
98     my $qual = '';
99     if ( $cgi->param('qualnum') ) {
100
101       $qual =
102         qsearchs('qual', { 'qualnum' => scalar($cgi->param('qualnum')) } )
103           or die 'unknown qualnum';
104
105       $vendor_qual_id = $qual->vendor_qual_id;
106
107       push @fields, { 'field' => 'qualnum',
108                       'type'  => 'hidden',
109                       'value' => $qual->qualnum,
110                     },
111                     { 'field' => 'phonenum',
112                       'type'  => 'fixed',
113                       'value' => $qual->phonenum,
114                     };
115     
116     } else {
117
118       my $phonenum = $cust_main->ship_daytime ? $cust_main->ship_daytime
119                                            : $cust_main->daytime;
120       $phonenum =~ s/[^0-9]//g;
121
122       push @fields,
123         { field => 'phonenum',
124           value => $phonenum,
125         };
126
127     }
128
129     if ( scalar(@exports) == 1 ) {
130         my $export = @exports[0];                
131         if($export->exporttype eq 'ikano') {
132             my $ddd = $cust_pkg->start_date;
133             $ddd = time unless $ddd;
134
135             my @quals = $export->quals_by_cust_and_pkg($cust_pkg->cust_main->custnum,$cust_pkg->pkgpart);
136             my @prequalids;
137             my %prequal_labels;
138             foreach my $qual ( @quals ) {
139                 my $prequalid = $qual->vendor_qual_id;
140                 push @prequalids, $prequalid;
141                 $prequal_labels{$prequalid} = "$prequalid - qualification #"
142                                                             .$qual->qualnum;
143             }
144
145             if ( $vendor_qual_id ) {
146               splice @fields, -1, 0,
147                   { field    => 'loop_type',
148                     type     => 'fixed',
149                     value    => ( $qual->phonenum ? '' : '0' ),
150                     formatted_value => ( $qual->phonenum ? 'Line-share'
151                                                          : 'Standalone' ),
152                   };
153             } else {
154               splice @fields, -1, 0,
155                   { field    => 'loop_type',
156                     type     => 'select',
157                     options  => [ '', '0' ],
158                     labels   => { '' => 'Line-share', '0', => 'Standalone' },
159                     onchange => 'ikano_loop_type_changed',
160                   };
161             }
162
163             push @fields,
164                 'password', 
165                 { field => 'isp_chg', type => 'checkbox', value=>'Y', },
166                 'isp_prev',
167             ;
168
169             if ( $vendor_qual_id ) {
170               push @fields,
171                 { field => 'vendor_qual_id',
172                   type  => 'fixed',
173                   value => $vendor_qual_id,
174                 };
175             } else {
176               push @fields,
177                 { field    => 'vendor_qual_id', 
178                   type     => 'select',
179                   options  => \@prequalids,
180                   labels   => \%prequal_labels,
181                   onchange => 'ikano_vendor_qual_id_changed',
182                 };
183             }
184
185             push @fields,
186                 { field => 'vendor_order_type', 
187                   type  => 'hidden', 
188                   value => 'NEW' },
189                 { field => 'desired_due_date',
190                   type  => 'fixed',
191                   formatted_value => 
192                     time2str($date_format,$ddd),
193                   value => $ddd, 
194                 },
195             ;
196         }
197         # else add any other export-specific stuff here
198
199     } else { # display non-export and non-Ikano fields
200         push @fields, qw( rate_band circuitnum vpi vci );
201     }
202 };
203
204 my $error_cb = sub {
205     my( $cgi ) = @_;
206     #my( $cgi,$svc_x, $part_svc,$cust_pkg, $fields,$opt) = @_;
207     if ( $cgi->param('svcnum') ) {
208       &{ $edit_cb }( @_ );
209     } else {
210       &{ $new_cb }( @_ );
211     }
212 };
213
214 </%init>