svc_broadband merge
[freeside.git] / httemplate / edit / part_svc.cgi
1 <!-- mason kludge -->
2 <% 
3    my $part_svc;
4    my $clone = '';
5    if ( $cgi->param('error') ) { #error
6      $part_svc = new FS::part_svc ( {
7        map { $_, scalar($cgi->param($_)) } fields('part_svc')
8      } );
9    } elsif ( $cgi->param('clone') && $cgi->param('clone') =~ /^(\d+)$/ ) {#clone
10      #$cgi->param('clone') =~ /^(\d+)$/ or die "malformed query: $query";
11      $part_svc = qsearchs('part_svc', { 'svcpart'=>$1 } )
12        or die "unknown svcpart: $1";
13      $clone = $part_svc->svcpart;
14      $part_svc->svcpart('');
15    } elsif ( $cgi->keywords ) { #edit
16      my($query) = $cgi->keywords;
17      $query =~ /^(\d+)$/ or die "malformed query: $query";
18      $part_svc=qsearchs('part_svc', { 'svcpart'=>$1 } )
19        or die "unknown svcpart: $1";
20    } else { #adding
21      $part_svc = new FS::part_svc {};
22    }
23    my $action = $part_svc->svcpart ? 'Edit' : 'Add';
24    my $hashref = $part_svc->hashref;
25 #   my $p_svcdb = $part_svc->svcdb || 'svc_acct';
26
27
28            #" onLoad=\"visualize()\""
29 %>
30
31 <%= header("$action Service Definition",
32            menubar( 'Main Menu'         => $p,
33                     'View all service definitions' => "${p}browse/part_svc.cgi"
34                   ),
35            )
36 %>
37
38 <% if ( $cgi->param('error') ) { %>
39 <FONT SIZE="+1" COLOR="#ff0000">Error: <%= $cgi->param('error') %></FONT>
40 <% } %>
41
42 <FORM NAME="dummy">
43
44       Service Part #<%= $part_svc->svcpart ? $part_svc->svcpart : "(NEW)" %>
45 <BR><BR>
46 Service  <INPUT TYPE="text" NAME="svc" VALUE="<%= $hashref->{svc} %>"><BR>
47 Disable new orders <INPUT TYPE="checkbox" NAME="disabled" VALUE="Y"<%= $hashref->{disabled} eq 'Y' ? ' CHECKED' : '' %>><BR>
48 <INPUT TYPE="hidden" NAME="svcpart" VALUE="<%= $hashref->{svcpart} %>">
49 <BR>
50 Services are items you offer to your customers.
51 <UL><LI>svc_acct - Shell accounts, POP mailboxes, SLIP/PPP and ISDN accounts
52     <LI>svc_domain - Domains
53     <LI>svc_acct_sm - <B>deprecated</B> (use svc_forward for new installations) Virtual domain mail aliasing.
54     <LI>svc_forward - mail forwarding
55     <LI>svc_www - Virtual domain website
56     <LI>svc_broadband - Broadband/High-speed Internet service
57 <!--   <LI>svc_charge - One-time charges (Partially unimplemented)
58        <LI>svc_wo - Work orders (Partially unimplemented)
59 -->
60 </UL>
61 For the selected table, you can give fields default or fixed (unchangable)
62 values.  For example, a SLIP/PPP account may have a default (or perhaps fixed)
63 <B>slipip</B> of <B>0.0.0.0</B>, while a POP mailbox will probably have a fixed
64 blank <B>slipip</B> as well as a fixed shell something like <B>/bin/true</B> or
65 <B>/usr/bin/passwd</B>.
66 <BR><BR>
67
68 <%
69 #these might belong somewhere else for other user interfaces 
70 #pry need to eventually create stuff that's shared amount UIs
71 my %defs = (
72   'svc_acct' => {
73     'dir'       => 'Home directory',
74     'uid'       => 'UID (set to fixed and blank for dial-only)',
75     'slipip'    => 'IP address (Set to fixed and blank to disable dialin, or, set a value to be exported to RADIUS Framed-IP-Address.  Use the special value <code>0e0</code> [zero e zero] to enable export to RADIUS without a Framed-IP-Address.)',
76 #    'popnum'    => qq!<A HREF="$p/browse/svc_acct_pop.cgi/">POP number</A>!,
77     'popnum'    => {
78                      desc => 'Access number',
79                      type => 'select',
80                      select_table => 'svc_acct_pop',
81                      select_key   => 'popnum',
82                      select_label => 'city',
83                    },
84     'username'  => 'Username',
85     'quota'     => '',
86     '_password' => 'Password',
87     'gid'       => 'GID (when blank, defaults to UID)',
88     'shell'     => 'Shell (all service definitions should have a default or fixed shell that is present in the <b>shells</b> configuration file)',
89     'finger'    => 'GECOS',
90     'domsvc'    => {
91                      desc =>'svcnum from svc_domain',
92                      type =>'select',
93                      select_table => 'svc_domain',
94                      select_key   => 'svcnum',
95                      select_label => 'domain',
96                    },
97     'usergroup' => {
98                      desc =>'ICRADIUS/FreeRADIUS groups',
99                      type =>'radius_usergroup_selector',
100                    },
101   },
102   'svc_domain' => {
103     'domain'    => 'Domain',
104   },
105   'svc_acct_sm' => {
106     'domuser'   => 'domuser@virtualdomain.com',
107     'domuid'    => 'UID where domuser@virtualdomain.com mail is forwarded',
108     'domsvc'    => 'svcnum from svc_domain for virtualdomain.com',
109   },
110   'svc_forward' => {
111     'srcsvc'    => 'service from which mail is to be forwarded',
112     'dstsvc'    => 'service to which mail is to be forwarded',
113     'dst'       => 'someone@another.domain.com to use when dstsvc is 0',
114   },
115   'svc_charge' => {
116     'amount'    => 'amount',
117   },
118   'svc_wo' => {
119     'worker'    => 'Worker',
120     '_date'      => 'Date',
121   },
122   'svc_www' => {
123     #'recnum' => '',
124     #'usersvc' => '',
125   },
126   'svc_broadband' => {
127     'actypenum' => 'This is the actypenum that refers to the type of AC that can be provisioned for this service.  This field must be set fixed.',
128     'speed_down' => 'Maximum download speed for this service in Kbps.  0 denotes unlimited.',
129     'speed_up' => 'Maximum upload speed for this service in Kbps.  0 denotes unlimited.',
130     'acnum' => 'acnum of a specific AC that this service is restricted to.  Not required',
131     'ip_addr' => 'IP address.  Leave blank for automatic assignment.',
132     'ip_netmask' => 'Mask length, aka. netmask bits.  (Eg. 255.255.255.0 == 24)',
133     'mac_addr' => 'MAC address which is used by some ACs for access control.  Specified by 6 colon seperated hex octets. (Eg. 00:00:0a:bc:1a:2b)',
134     'location' => 'Defines the physically location at which this service was installed.  This is not necessarily the billing address',
135   },
136 );
137
138   my @dbs = $hashref->{svcdb}
139              ? ( $hashref->{svcdb} )
140              : qw( svc_acct svc_domain svc_acct_sm svc_forward svc_www svc_broadband );
141
142   tie my %svcdb, 'Tie::IxHash', map { $_=>$_ } @dbs;
143   my $widget = new HTML::Widgets::SelectLayers(
144     #'selected_layer' => $p_svcdb,
145     'selected_layer' => $hashref->{svcdb} || 'svc_acct',
146     'options'        => \%svcdb,
147     'form_name'      => 'dummy',
148     'form_action'    => 'process/part_svc.cgi',
149     'form_text'      => [ qw( svc svcpart ) ],
150     'form_checkbox'  => [ 'disabled' ],
151     'layer_callback' => sub {
152       my $layer = shift;
153       my $html = qq!<INPUT TYPE="hidden" NAME="svcdb" VALUE="$layer">!;
154
155       my $columns = 3;
156       my $count = 0;
157       my @part_export =
158         map { qsearch( 'part_export', {exporttype => $_ } ) }
159           keys %{FS::part_export::export_info($layer)};
160      $html .= '<BR><BR>'. table().
161                table(). "<TR><TH COLSPAN=$columns>Exports</TH></TR><TR>";
162       foreach my $part_export ( @part_export ) {
163         $html .= '<TD><INPUT TYPE="checkbox"'.
164                  ' NAME="exportnum'. $part_export->exportnum. '"  VALUE="1" ';
165         $html .= 'CHECKED'
166           if qsearchs( 'export_svc', {
167                                    exportnum => $part_export->exportnum,
168                                    svcpart   => $clone || $part_svc->svcpart });
169         $html .= '> '. $part_export->exporttype. ' to '. $part_export->machine.
170                  '</TD>';
171         $count++;
172         $html .= '</TR><TR>' unless $count % $columns;
173       }
174       $html .= '</TR></TABLE><BR><BR>';
175
176       $html .=  table(). "<TH>Field</TH><TH COLSPAN=2>Modifier</TH>";
177       #yucky kludge
178       my @fields = defined( $FS::Record::dbdef->table($layer) )
179                       ? grep { $_ ne 'svcnum' } fields($layer)
180                       : ();
181       push @fields, 'usergroup' if $layer eq 'svc_acct'; #kludge
182       $part_svc->svcpart($clone) if $clone; #haha, undone below
183       foreach my $field (@fields) {
184         my $part_svc_column = $part_svc->part_svc_column($field);
185         my $value = $cgi->param('error')
186                       ? $cgi->param("${layer}__${field}")
187                       : $part_svc_column->columnvalue;
188         my $flag = $cgi->param('error')
189                      ? $cgi->param("${layer}__${field}_flag")
190                      : $part_svc_column->columnflag;
191         my $def = $defs{$layer}{$field};
192         my $desc = ref($def) ? $def->{desc} : $def;
193         
194         $html .= "<TR><TD>$field";
195         $html .= "- <FONT SIZE=-1>$desc</FONT>" if $desc;
196         $html .=  "</TD>";
197         $html .=
198           qq!<TD><INPUT TYPE="radio" NAME="${layer}__${field}_flag" VALUE=""!.
199           ' CHECKED'x($flag eq ''). ">Off</TD>".
200           qq!<TD><INPUT TYPE="radio" NAME="${layer}__${field}_flag" VALUE="D"!.
201           ' CHECKED'x($flag eq 'D'). ">Default ".
202           qq!<INPUT TYPE="radio" NAME="${layer}__${field}_flag" VALUE="F"!.
203           ' CHECKED'x($flag eq 'F'). ">Fixed ".
204           '<BR>';
205         if ( ref($def) ) {
206           if ( $def->{type} eq 'select' ) {
207             $html .= qq!<SELECT NAME="${layer}__${field}">!;
208             $html .= '<OPTION> </OPTION>' unless $value;
209             foreach my $record ( qsearch( $def->{select_table}, {} ) ) {
210               my $rvalue = $record->getfield($def->{select_key});
211               $html .= qq!<OPTION VALUE="$rvalue"!.
212                        ( $rvalue==$value ? ' SELECTED>' : '>' ).
213                        $record->getfield($def->{select_label}). '</OPTION>';
214             }
215             $html .= '</SELECT>';
216           } elsif ( $def->{type} eq 'radius_usergroup_selector' ) {
217             $html .= FS::svc_acct::radius_usergroup_selector(
218               [ split(',', $value) ], "${layer}__${field}" );
219           } else {
220             $html .= '<font color="#ff0000">unknown type'. $def->{type};
221           }
222         } else {
223           $html .=
224             qq!<INPUT TYPE="text" NAME="${layer}__${field}" VALUE="$value">!;
225         }
226         $html .= "</TD></TR>\n";
227       }
228       $part_svc->svcpart('') if $clone; #undone
229       $html .= "</TABLE>";
230
231       $html .= '<BR><INPUT TYPE="submit" VALUE="'.
232                ($hashref->{svcpart} ? 'Apply changes' : 'Add service'). '">';
233
234       $html;
235
236     },
237   );
238
239 %>
240 Table <%= $widget->html %>
241   </BODY>
242 </HTML>
243