683bf9ec554415d4d3619b09bd364a8969411951
[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_charge - One-time charges (Partially unimplemented)
57        <LI>svc_wo - Work orders (Partially unimplemented)
58 -->
59 </UL>
60 For the selected table, you can give fields default or fixed (unchangable)
61 values.  For example, a SLIP/PPP account may have a default (or perhaps fixed)
62 <B>slipip</B> of <B>0.0.0.0</B>, while a POP mailbox will probably have a fixed
63 blank <B>slipip</B> as well as a fixed shell something like <B>/bin/true</B> or
64 <B>/usr/bin/passwd</B>.
65 <BR><BR>
66
67 <%
68 #these might belong somewhere else for other user interfaces 
69 #pry need to eventually create stuff that's shared amount UIs
70 my %defs = (
71   'svc_acct' => {
72     'dir'       => 'Home directory',
73     'uid'       => 'UID (set to fixed and blank for dial-only)',
74     '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.)',
75 #    'popnum'    => qq!<A HREF="$p/browse/svc_acct_pop.cgi/">POP number</A>!,
76     'popnum'    => {
77                      desc => 'Access number',
78                      type => 'select',
79                      select_table => 'svc_acct_pop',
80                      select_key   => 'popnum',
81                      select_label => 'city',
82                    },
83     'username'  => {
84                       desc => 'Username',
85                       type => 'disabled',
86                    },
87     'quota'     => '',
88     '_password' => 'Password',
89     'gid'       => 'GID (when blank, defaults to UID)',
90     'shell'     => 'Shell (all service definitions should have a default or fixed shell that is present in the <b>shells</b> configuration file)',
91     'finger'    => 'GECOS',
92     'domsvc'    => {
93                      desc =>'svcnum from svc_domain',
94                      type =>'select',
95                      select_table => 'svc_domain',
96                      select_key   => 'svcnum',
97                      select_label => 'domain',
98                    },
99     'usergroup' => {
100                      desc =>'ICRADIUS/FreeRADIUS groups',
101                      type =>'radius_usergroup_selector',
102                    },
103   },
104   'svc_domain' => {
105     'domain'    => 'Domain',
106   },
107   'svc_acct_sm' => {
108     'domuser'   => 'domuser@virtualdomain.com',
109     'domuid'    => 'UID where domuser@virtualdomain.com mail is forwarded',
110     'domsvc'    => 'svcnum from svc_domain for virtualdomain.com',
111   },
112   'svc_forward' => {
113     'srcsvc'    => 'service from which mail is to be forwarded',
114     'dstsvc'    => 'service to which mail is to be forwarded',
115     'dst'       => 'someone@another.domain.com to use when dstsvc is 0',
116   },
117   'svc_charge' => {
118     'amount'    => 'amount',
119   },
120   'svc_wo' => {
121     'worker'    => 'Worker',
122     '_date'      => 'Date',
123   },
124   'svc_www' => {
125     #'recnum' => '',
126     #'usersvc' => '',
127   },
128 );
129
130   my @dbs = $hashref->{svcdb}
131              ? ( $hashref->{svcdb} )
132              : qw( svc_acct svc_domain svc_acct_sm svc_forward svc_www );
133
134   tie my %svcdb, 'Tie::IxHash', map { $_=>$_ } @dbs;
135   my $widget = new HTML::Widgets::SelectLayers(
136     #'selected_layer' => $p_svcdb,
137     'selected_layer' => $hashref->{svcdb} || 'svc_acct',
138     'options'        => \%svcdb,
139     'form_name'      => 'dummy',
140     'form_action'    => 'process/part_svc.cgi',
141     'form_text'      => [ qw( svc svcpart ) ],
142     'form_checkbox'  => [ 'disabled' ],
143     'layer_callback' => sub {
144       my $layer = shift;
145       my $html = qq!<INPUT TYPE="hidden" NAME="svcdb" VALUE="$layer">!;
146
147       my $columns = 3;
148       my $count = 0;
149       my @part_export =
150         map { qsearch( 'part_export', {exporttype => $_ } ) }
151           keys %{FS::part_export::export_info($layer)};
152       $html .= '<BR><BR>'. table().
153                table(). "<TR><TH COLSPAN=$columns>Exports</TH></TR><TR>";
154       foreach my $part_export ( @part_export ) {
155         $html .= '<TD><INPUT TYPE="checkbox"'.
156                  ' NAME="exportnum'. $part_export->exportnum. '"  VALUE="1" ';
157         $html .= 'CHECKED'
158           if ( $clone || $part_svc->svcpart ) #null svcpart search causing error
159               && qsearchs( 'export_svc', {
160                                    exportnum => $part_export->exportnum,
161                                    svcpart   => $clone || $part_svc->svcpart });
162         $html .= '>'. $part_export->exportnum. ': '. $part_export->exporttype.
163                  ' to '. $part_export->machine. '</TD>';
164         $count++;
165         $html .= '</TR><TR>' unless $count % $columns;
166       }
167       $html .= '</TR></TABLE><BR><BR>';
168
169       $html .=  table(). "<TH>Field</TH><TH COLSPAN=2>Modifier</TH>";
170       #yucky kludge
171       my @fields = defined( $FS::Record::dbdef->table($layer) )
172                       ? grep { $_ ne 'svcnum' } fields($layer)
173                       : ();
174       push @fields, 'usergroup' if $layer eq 'svc_acct'; #kludge
175       $part_svc->svcpart($clone) if $clone; #haha, undone below
176       foreach my $field (@fields) {
177         my $part_svc_column = $part_svc->part_svc_column($field);
178         my $value = $cgi->param('error')
179                       ? $cgi->param("${layer}__${field}")
180                       : $part_svc_column->columnvalue;
181         my $flag = $cgi->param('error')
182                      ? $cgi->param("${layer}__${field}_flag")
183                      : $part_svc_column->columnflag;
184         my $def = $defs{$layer}{$field};
185         my $desc = ref($def) ? $def->{desc} : $def;
186         
187         $html .= "<TR><TD>$field";
188         $html .= "- <FONT SIZE=-1>$desc</FONT>" if $desc;
189         $html .=  "</TD>";
190         $flag = '' if ref($def) && $def->{type} eq 'disabled';
191         $html .=
192           qq!<TD><INPUT TYPE="radio" NAME="${layer}__${field}_flag" VALUE=""!.
193           ' CHECKED'x($flag eq ''). ">Off</TD>".
194           '<TD>';
195         unless ( ref($def) && $def->{type} eq 'disabled' ) {
196           $html .= 
197             qq!<INPUT TYPE="radio" NAME="${layer}__${field}_flag" VALUE="D"!.
198             ' CHECKED'x($flag eq 'D'). ">Default ".
199             qq!<INPUT TYPE="radio" NAME="${layer}__${field}_flag" VALUE="F"!.
200             ' CHECKED'x($flag eq 'F'). ">Fixed ".
201             '<BR>';
202         }
203         if ( ref($def) ) {
204           if ( $def->{type} eq 'select' ) {
205             $html .= qq!<SELECT NAME="${layer}__${field}">!;
206             $html .= '<OPTION> </OPTION>' unless $value;
207             foreach my $record ( qsearch( $def->{select_table}, {} ) ) {
208               my $rvalue = $record->getfield($def->{select_key});
209               $html .= qq!<OPTION VALUE="$rvalue"!.
210                        ( $rvalue==$value ? ' SELECTED>' : '>' ).
211                        $record->getfield($def->{select_label}). '</OPTION>';
212             }
213             $html .= '</SELECT>';
214           } elsif ( $def->{type} eq 'radius_usergroup_selector' ) {
215             $html .= FS::svc_acct::radius_usergroup_selector(
216               [ split(',', $value) ], "${layer}__${field}" );
217           } elsif ( $def->{type} eq 'disabled' ) {
218             $html .=
219               qq!<INPUT TYPE="hidden" NAME="${layer}__${field}" VALUE="">!;
220           } else {
221             $html .= '<font color="#ff0000">unknown type'. $def->{type};
222           }
223         } else {
224           $html .=
225             qq!<INPUT TYPE="text" NAME="${layer}__${field}" VALUE="$value">!;
226         }
227         $html .= "</TD></TR>\n";
228       }
229       $part_svc->svcpart('') if $clone; #undone
230       $html .= "</TABLE>";
231
232       $html .= '<BR><INPUT TYPE="submit" VALUE="'.
233                ($hashref->{svcpart} ? 'Apply changes' : 'Add service'). '">';
234
235       $html;
236
237     },
238   );
239
240 %>
241 Table <%= $widget->html %>
242   </BODY>
243 </HTML>
244