svc_dsl, ikano, on-going implementation, initial commit of freeside-pull-dsl, RT7111
[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     return "
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') {
45             @fields = ( 'password', 'monitored', );
46
47             foreach my $hf ( keys %$ti_fields ) {
48                 push @fields, {
49                     field => $hf,
50                     type => 'hidden',
51                     value => $svc_x->$hf,
52                 } unless ( $hf eq 'password' || $hf eq 'monitored' );
53             }
54         }
55         # else add any other export-specific stuff here
56     }
57     else {
58         # XXX allow editing everything
59     }
60 };
61
62 my $new_cb = sub {
63     my( $cgi,$svc_x, $part_svc,$cust_pkg, $fields1,$opt) = @_;
64     my @exports = $part_svc->part_export_dsl_pull;
65     die "more than one DSL-pulling export attached to svcpart ".$part_svc->svcpart
66         if ( scalar(@exports) > 1 );
67
68     if ( scalar(@exports) == 1 ) {
69         my $cust_main = $cust_pkg->cust_main;
70         my $defsvctn = $cust_main->ship_daytime ? $cust_main->ship_daytime
71                                                 : $cust_main->daytime;
72         $defsvctn =~ s/[^0-9]//g;
73
74         @fields = (
75             { field => 'first',
76               value => $cust_main->ship_first ? $cust_main->ship_first
77                                               : $cust_main->first,
78             },
79             { field => 'last',
80               value => $cust_main->ship_last ? $cust_main->ship_last
81                                              : $cust_main->last,
82             },
83             { field => 'company',
84               value => $cust_pkg->cust_main->ship_company,
85               value => $cust_main->ship_company ? $cust_main->ship_company
86                                                 : $cust_main->company,
87             },
88             { field => 'phonenum',
89               value => $defsvctn,
90             },
91         );
92
93         my $export = @exports[0];               
94         if($export->exporttype eq 'ikano') {
95             $cgi->param('vendor_qual_id') =~ /^(\d+)$/ 
96                 or die 'unparsable vendor_qual_id';
97             my $vendor_qual_id = $1;
98
99             die "no start date set on customer package" if !$cust_pkg->start_date;
100
101             my @addl_fields = ( 
102                 { field => 'loop_type',
103                   type => 'select',
104                   options => [ '', '0' ],
105                   labels => { '' => 'Line-share', '0', => 'Standalone' },
106                   onchange => 'ikano_loop_type_changed',
107                 },
108                 'password', 
109                 { field => 'isp_chg', type => 'checkbox', },
110                 'isp_prev',
111                 { field => 'vendor_qual_id', 
112                   type => 'fixed', 
113                   value => $vendor_qual_id,  },
114                 { field => 'vendor_order_type', 
115                   type => 'hidden', 
116                   value => 'NEW' },
117                 { field => 'desired_due_date',
118                   type => 'fixed',
119                   formatted_value => 
120                     time2str($date_format,$cust_pkg->start_date),
121                   value => $cust_pkg->start_date, 
122                 },
123             );
124             push @fields, @addl_fields;
125         }
126         # else add any other export-specific stuff here
127     }
128     else {
129         # XXX display everything when no exports attached
130     }
131 };
132 </%init>