ikano.pm initial commit, svc_dsl UI initial commit, and svc_dsl on-going work, 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           )
7 %>
8 <%init>
9
10 die "access denied"
11   unless $FS::CurrentUser::CurrentUser->access_right('Provision customer service'); #something else more specific?
12
13 my $conf = new FS::Conf;
14 my $date_format = $conf->config('date_format') || '%m/%d/%Y';
15
16 my $ti_fields = FS::svc_dsl->table_info->{'fields'};
17
18 my @fields = ();
19 my @uneditable = qw( pushed vendor_qual_id isp_chg isp_prev staticips last_pull notes );
20
21 my $edit_cb = sub {
22     my( $cgi,$svc_x, $part_svc,$cust_pkg, $fields1,$opt) = @_;
23     my @exports = $part_svc->part_export_dsl_pull;
24     die "more than one DSL-pulling export attached to svcpart ".$part_svc->svcpart
25         if ( scalar(@exports) > 1 );
26
27     if ( scalar(@exports) == 1 ) {
28         my $export = @exports[0];               
29         if($export->exporttype eq 'ikano') {
30             @fields = ( 'password', 'monitored', );
31
32             foreach my $hf ( keys %$ti_fields ) {
33                 push @fields, {
34                     field => $hf,
35                     type => 'hidden',
36                     value => $svc_x->$hf,
37                 } unless ( $hf eq 'password' || $hf eq 'monitored' );
38             }
39         }
40         else {
41             # XXX
42         }
43     }
44     else {
45         # XXX
46     }
47 };
48
49 my $new_cb = sub {
50     my( $cgi,$svc_x, $part_svc,$cust_pkg, $fields1,$opt) = @_;
51     my @exports = $part_svc->part_export_dsl_pull;
52     die "more than one DSL-pulling export attached to svcpart ".$part_svc->svcpart
53         if ( scalar(@exports) > 1 );
54
55     if ( scalar(@exports) == 1 ) {
56         my $cust_main = $cust_pkg->cust_main;
57         my $defsvctn = $cust_main->ship_daytime ? $cust_main->ship_daytime
58                                                 : $cust_main->daytime;
59         $defsvctn =~ s/[^0-9]//g;
60
61         @fields = (
62             { field => 'first',
63               value => $cust_main->ship_first ? $cust_main->ship_first
64                                               : $cust_main->first,
65             },
66             { field => 'last',
67               value => $cust_main->ship_last ? $cust_main->ship_last
68                                              : $cust_main->last,
69             },
70             { field => 'company',
71               value => $cust_pkg->cust_main->ship_company,
72               value => $cust_main->ship_company ? $cust_main->ship_company
73                                                 : $cust_main->company,
74             },
75             { field => 'svctn',
76               value => $defsvctn,
77             },
78         );
79
80         my $loop_type = { field => 'loop_type' };
81
82         my $export = @exports[0];               
83         if($export->exporttype eq 'ikano') {
84             $cgi->param('vendor_qual_id') =~ /^(\d+)$/ 
85                 or die 'unparsable vendor_qual_id';
86             my $vendor_qual_id = $1;
87
88             die "no start date set on customer package" if !$cust_pkg->start_date;
89
90             $loop_type = { field => 'loop_type',
91                     type => 'select',
92                     options => [ '', '0' ],
93                     labels => { '' => 'Line-share', '0', => 'Standalone' },
94                    # onchange => "document.getElementById('svctn').value = ''",
95                 };
96             push @fields, { field => 'isp_chg', type => 'checkbox', };
97             push @fields, 'isp_prev';
98             push @fields, { field => 'vendor_qual_id',
99                             type => 'fixed',
100                             value => $vendor_qual_id, 
101                           };
102         }
103         else {
104             push @fields, 'username';
105         }
106         
107         push @fields, 'password';
108
109         push @fields, $loop_type;
110             
111         push @fields, { field => 'vendor_order_type',
112                         type => 'hidden',
113                         value => 'N' };
114         push @fields, { field => 'desired_dd',
115                         type => 'fixed',
116                         formatted_value => 
117                             time2str($date_format,$cust_pkg->start_date),
118                         value => $cust_pkg->start_date, 
119                       };
120     }
121     else {
122         # XXX
123     }
124 };
125 </%init>