7ecf906f033cc4acaa8e8b6566e43679f129b4eb
[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               'html_foot'          => $html_foot,
7           )
8 %>
9 <%init>
10
11 die "access denied"
12   unless $FS::CurrentUser::CurrentUser->access_right('Provision customer service'); #something else more specific?
13
14 my $conf = new FS::Conf;
15 my $date_format = $conf->config('date_format') || '%m/%d/%Y';
16
17 my $ti_fields = FS::svc_dsl->table_info->{'fields'};
18
19 my @fields = ();
20
21 my $html_foot = sub { "
22 <SCRIPT TYPE=\"text/javascript\">
23   function ikano_loop_type_changed() {
24         var loop_type = document.getElementById('loop_type').value;
25         var phonenum = document.getElementById('phonenum');
26         if(loop_type == '0') {
27             phonenum.value = '';
28             phonenum.disabled = true;        
29         }
30         else phonenum.disabled = false;
31   }
32 </SCRIPT>
33 "; };
34
35 my $edit_cb = sub {
36     my( $cgi,$svc_x, $part_svc,$cust_pkg, $fields1,$opt) = @_;
37     my @exports = $part_svc->part_export_dsl_pull;
38     die "more than one DSL-pulling export attached to svcpart ".$part_svc->svcpart
39         if ( scalar(@exports) > 1 );
40
41     if ( scalar(@exports) == 1 ) {
42         my $export = @exports[0];                
43         if($export->exporttype eq 'ikano') {
44             @fields = ( 'password', 'monitored', );
45
46             foreach my $hf ( keys %$ti_fields ) {
47                 push @fields, {
48                     field => $hf,
49                     type => 'hidden',
50                     value => $svc_x->$hf,
51                 } unless ( $hf eq 'password' || $hf eq 'monitored' );
52             }
53         }
54         # else add any other export-specific stuff here
55     }
56     else {
57         push @fields, qw( first last company phonenum circuitnum rate_band vpi vci );
58     }
59 };
60
61 my $new_cb = sub {
62     my( $cgi,$svc_x, $part_svc,$cust_pkg, $fields1,$opt) = @_;
63     my @exports = $part_svc->part_export_dsl_pull;
64     die "more than one DSL-pulling export attached to svcpart ".$part_svc->svcpart
65         if ( scalar(@exports) > 1 );
66
67         my $cust_main = $cust_pkg->cust_main;
68         my $defsvctn = $cust_main->ship_daytime ? $cust_main->ship_daytime
69                                                 : $cust_main->daytime;
70         $defsvctn =~ s/[^0-9]//g;
71
72         @fields = (
73             { field => 'first',
74               value => $cust_main->ship_first ? $cust_main->ship_first
75                                               : $cust_main->first,
76             },
77             { field => 'last',
78               value => $cust_main->ship_last ? $cust_main->ship_last
79                                              : $cust_main->last,
80             },
81             { field => 'company',
82               value => $cust_pkg->cust_main->ship_company,
83               value => $cust_main->ship_company ? $cust_main->ship_company
84                                                 : $cust_main->company,
85             },
86             { field => 'phonenum',
87               value => $defsvctn,
88             },
89         );
90
91     if ( scalar(@exports) == 1 ) {
92         my $export = @exports[0];                
93         if($export->exporttype eq 'ikano') {
94             my $ddd = $cust_pkg->start_date;
95             $ddd = time unless $ddd;
96
97             my @quals = $export->quals_by_cust_and_pkg($cust_pkg->cust_main->custnum,$cust_pkg->pkgpart);
98             my @prequalids;
99             my %prequal_labels;
100             foreach my $qual ( @quals ) {
101                 my $prequalid = $qual->vendor_qual_id;
102                 push @prequalids, $prequalid;
103                 $prequal_labels{$prequalid} = "$prequalid - qualification #"
104                                                             .$qual->qualnum;
105             }
106
107             splice @fields, -1, 0,
108                 { field => 'loop_type',
109                   type => 'select',
110                   options => [ '', '0' ],
111                   labels => { '' => 'Line-share', '0', => 'Standalone' },
112                   onchange => 'ikano_loop_type_changed',
113                 },
114             ;
115
116             push @fields,
117                 'password', 
118                 { field => 'isp_chg', type => 'checkbox', value=>'Y', },
119                 'isp_prev',
120                 { field => 'vendor_qual_id', 
121                   type => 'select',
122                   options => \@prequalids,
123                   labels => \%prequal_labels,
124                   onchange => 'ikano_vendor_qual_id_changed',
125                 },
126                 { field => 'vendor_order_type', 
127                   type => 'hidden', 
128                   value => 'NEW' },
129                 { field => 'desired_due_date',
130                   type => 'fixed',
131                   formatted_value => 
132                     time2str($date_format,$ddd),
133                   value => $ddd, 
134                 },
135             ;
136         }
137         # else add any other export-specific stuff here
138
139     } else { # display non-export and non-Ikano fields
140         push @fields, qw( rate_band circuitnum vpi vci );
141     }
142 };
143 </%init>