usability for msgcat editing: redirect back to the message catalog you are working...
[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         var gateway_access_number = document.getElementById('gateway_access_number');
28         if(loop_type == '0') {
29             phonenum.value = '';
30             phonenum.disabled = true;        
31             gateway_access_number.value = '';
32             gateway_access_number.disabled = true;
33         } else {
34             phonenum.disabled = false;
35             gateway_access_number.disabled = false;
36         }
37   }
38 </SCRIPT>
39 "; };
40
41 my $edit_cb = sub {
42     my( $cgi,$svc_x, $part_svc,$cust_pkg, $fields1,$opt) = @_;
43     my @exports = $part_svc->part_export_dsl_pull;
44     die "more than one DSL-pulling export attached to svcpart ".$part_svc->svcpart
45         if ( scalar(@exports) > 1 );
46
47     if ( scalar(@exports) == 1 ) {
48         my $export = @exports[0];                
49         if($export->exporttype eq 'ikano' && $export->import_mode) {
50             @fields = ();
51         }
52         elsif($export->exporttype eq 'ikano') {
53             @fields = ( 'password', 'monitored', );
54
55             foreach my $hf ( keys %$ti_fields ) {
56                 push @fields, {
57                     field => $hf,
58                     type => 'hidden',
59                     value => $svc_x->$hf,
60                 } unless ( $hf eq 'password' || $hf eq 'monitored' );
61             }
62         }
63         # else add any other export-specific stuff here
64     }
65     else {
66         push @fields, qw( first last company phonenum gateway_access_number circuitnum rate_band vpi vci );
67     }
68 };
69
70 my $new_cb = sub {
71     my( $cgi,$svc_x, $part_svc,$cust_pkg, $fields1,$opt) = @_;
72     my @exports = $part_svc->part_export_dsl_pull;
73     die "more than one DSL-pulling export for svcpart ".$part_svc->svcpart
74       if ( scalar(@exports) > 1 );
75     
76     if ( scalar(@exports) == 1 ) {
77         my $export = @exports[0];                
78         if($export->exporttype eq 'ikano' && $export->import_mode) {
79             @fields = ( 'vendor_order_id' );
80             return;
81         }
82     }
83
84     my $cust_main = $cust_pkg->cust_main;
85
86     @fields = (
87         { field => 'first',
88           value => $cust_main->ship_first ? $cust_main->ship_first
89                                           : $cust_main->first,
90         },
91         { field => 'last',
92           value => $cust_main->ship_last ? $cust_main->ship_last
93                                          : $cust_main->last,
94         },
95         { field => 'company',
96           value => $cust_pkg->cust_main->ship_company,
97           value => $cust_main->ship_company ? $cust_main->ship_company
98                                             : $cust_main->company,
99         },
100     );
101
102     my $vendor_qual_id = '';
103     my $qual = '';
104     if ( $cgi->param('qualnum') ) {
105
106       $qual =
107         qsearchs('qual', { 'qualnum' => scalar($cgi->param('qualnum')) } )
108           or die 'unknown qualnum';
109
110       $vendor_qual_id = $qual->vendor_qual_id;
111
112       push @fields, { 'field' => 'qualnum',
113                       'type'  => 'hidden',
114                       'value' => $qual->qualnum,
115                     },
116                     { 'field' => 'phonenum',
117                       'type'  => 'fixed',
118                       'value' => $qual->phonenum,
119                     };
120     
121     } else {
122
123       my $phonenum = $cust_main->ship_daytime ? $cust_main->ship_daytime
124                                            : $cust_main->daytime;
125       $phonenum =~ s/[^0-9]//g;
126
127       push @fields,
128         { field => 'phonenum',
129           value => $phonenum,
130         };
131         { field => 'gateway_access_number',
132           value => '',
133         };
134
135
136     }
137
138     if ( scalar(@exports) == 1 ) {
139         my $export = @exports[0];                
140         if($export->exporttype eq 'ikano') {
141             my $ddd = $cust_pkg->start_date;
142             $ddd = time unless $ddd;
143
144             my @quals = $export->quals_by_cust_and_pkg($cust_pkg->cust_main->custnum,$cust_pkg->pkgpart);
145             my @prequalids;
146             my %prequal_labels;
147             foreach my $qual ( @quals ) {
148                 my $prequalid = $qual->vendor_qual_id;
149                 push @prequalids, $prequalid;
150                 $prequal_labels{$prequalid} = "$prequalid - qualification #"
151                                                             .$qual->qualnum;
152             }
153
154             if ( $vendor_qual_id ) {
155               splice @fields, -1, 0,
156                   { field    => 'loop_type',
157                     type     => 'fixed',
158                     value    => ( $qual->phonenum ? '' : '0' ),
159                     formatted_value => ( $qual->phonenum ? 'Line-share'
160                                                          : 'Standalone' ),
161                   };
162             } else {
163               splice @fields, -1, 0,
164                   { field    => 'loop_type',
165                     type     => 'select',
166                     options  => [ '', '0' ],
167                     labels   => { '' => 'Line-share', '0', => 'Standalone' },
168                     onchange => 'ikano_loop_type_changed',
169                   };
170             }
171
172             push @fields,
173                 'password', 
174                 { field => 'isp_chg', type => 'checkbox', value=>'Y', },
175                 'isp_prev',
176             ;
177
178             if ( $vendor_qual_id ) {
179               push @fields,
180                 { field => 'vendor_qual_id',
181                   type  => 'fixed',
182                   value => $vendor_qual_id,
183                 };
184             } else {
185               push @fields,
186                 { field    => 'vendor_qual_id', 
187                   type     => 'select',
188                   options  => \@prequalids,
189                   labels   => \%prequal_labels,
190                   onchange => 'ikano_vendor_qual_id_changed',
191                 };
192             }
193
194             push @fields,
195                 { field => 'vendor_order_type', 
196                   type  => 'hidden', 
197                   value => 'NEW' },
198                 { field => 'desired_due_date',
199                   type  => 'fixed',
200                   formatted_value => 
201                     time2str($date_format,$ddd),
202                   value => $ddd, 
203                 },
204             ;
205         }
206         # else add any other export-specific stuff here
207
208     } else { # display non-export and non-Ikano fields
209         push @fields, qw( rate_band circuitnum vpi vci );
210     }
211 };
212
213 my $error_cb = sub {
214     my( $cgi ) = @_;
215     #my( $cgi,$svc_x, $part_svc,$cust_pkg, $fields,$opt) = @_;
216     if ( $cgi->param('svcnum') ) {
217       &{ $edit_cb }( @_ );
218     } else {
219       &{ $new_cb }( @_ );
220     }
221 };
222
223 </%init>