bad warning, causing errors with strict
[freeside.git] / httemplate / edit / part_svc.cgi
1 <!-- mason kludge -->
2 <% 
3    my $part_svc;
4    if ( $cgi->param('error') ) { #error
5      $part_svc = new FS::part_svc ( {
6        map { $_, scalar($cgi->param($_)) } fields('part_svc')
7      } );
8    } elsif ( $cgi->keywords ) { #edit
9      my($query) = $cgi->keywords;
10      $query =~ /^(\d+)$/ or die "malformed query: $query";
11      $part_svc=qsearchs('part_svc', { 'svcpart'=>$1 } )
12        or die "unknown svcpart: $1";
13    } else { #adding
14      $part_svc = new FS::part_svc {};
15    }
16    my $action = $part_svc->svcpart ? 'Edit' : 'Add';
17    my $hashref = $part_svc->hashref;
18    my $p_svcdb = $part_svc->svcdb || 'svc_acct';
19
20 %>
21
22 <SCRIPT>
23 function visualize(what) {
24   if (document.getElementById) {
25     document.getElementById('d<%= $p_svcdb %>').style.visibility = "visible";
26   } else {
27     document.l<%= $p_svcdb %>.visibility = "visible";
28   }
29 }
30 </SCRIPT>
31
32 <%= header("$action Service Definition",
33            menubar( 'Main Menu'         => $p,
34                     'View all service definitions' => "${p}browse/part_svc.cgi"
35                   ),
36            " onLoad=\"visualize()\""
37            )
38 %>
39
40 <% if ( $cgi->param('error') ) { %>
41 <FONT SIZE="+1" COLOR="#ff0000">Error: <%= $cgi->param('error') %></FONT>
42 <% } %>
43
44 <FORM NAME="dummy">
45
46       Service Part #<%= $part_svc->svcpart ? $part_svc->svcpart : "(NEW)" %>
47 <BR><BR>
48 Service  <INPUT TYPE="text" NAME="svc" VALUE="<%= $hashref->{svc} %>"><BR>
49 Disable new orders <INPUT TYPE="checkbox" NAME="disabled" VALUE="Y"<%= $hashref->{disabled} eq 'Y' ? ' CHECKED' : '' %>><BR>
50 <BR>
51 Services are items you offer to your customers.
52 <UL><LI>svc_acct - Shell accounts, POP mailboxes, SLIP/PPP and ISDN accounts
53     <LI>svc_domain - Domains
54     <LI>svc_acct_sm - <B>deprecated</B> (use svc_forward for new installations) Virtual domain mail aliasing.
55     <LI>svc_forward - mail forwarding
56     <LI>svc_www - Virtual domain website
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 <SCRIPT>
68 var svcdb = null;
69 function changed(what) {
70   svcdb = what.options[what.selectedIndex].value;
71 <% foreach my $svcdb ( qw( svc_acct svc_domain svc_acct_sm svc_forward svc_www ) ) { %>
72   if (svcdb == "<%= $svcdb %>" ) {
73     <% foreach my $not ( grep { $_ ne $svcdb } (
74                            qw(svc_acct svc_domain svc_acct_sm svc_forward svc_www) ) ) { %>
75       if (document.getElementById) {
76         document.getElementById('d<%= $not %>').style.visibility = "hidden";
77       } else {
78         document.l<%= $not %>.visibility = "hidden";
79       }
80     <% } %>
81     if (document.getElementById) {
82       document.getElementById('d<%= $svcdb %>').style.visibility = "visible";
83     } else {
84       document.l<%= $svcdb %>.visibility = "visible";
85     }
86   }
87 <% } %>
88 }
89 </SCRIPT>
90 <% my @dbs = $hashref->{svcdb}
91              ? ( $hashref->{svcdb} )
92              : qw( svc_acct svc_domain svc_acct_sm svc_forward svc_www ); %>
93 Table<SELECT NAME="svcdb" SIZE=1 onChange="changed(this)">
94 <% foreach my $svcdb (@dbs) { %>
95 <OPTION VALUE="<%= $svcdb %>" <%= ' SELECTED'x($svcdb eq $hashref->{svcdb}) %>><%= $svcdb %>
96 <% } %>
97 </SELECT></FORM>
98
99 <%
100 #these might belong somewhere else for other user interfaces 
101 #pry need to eventually create stuff that's shared amount UIs
102 my %defs = (
103   'svc_acct' => {
104     'dir'       => 'Home directory',
105     'uid'       => 'UID (set to fixed and blank for dial-only)',
106     '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.)',
107 #    'popnum'    => qq!<A HREF="$p/browse/svc_acct_pop.cgi/">POP number</A>!,
108     'popnum'    => {
109                      desc => 'Access number',
110                      type => 'select',
111                      select_table => 'svc_acct_pop',
112                      select_key   => 'popnum',
113                      select_label => 'city',
114                    },
115     'username'  => 'Username',
116     'quota'     => '',
117     '_password' => 'Password',
118     'gid'       => 'GID (when blank, defaults to UID)',
119     'shell'     => 'Shell (all service definitions should have a default or fixed shell that is present in the <b>shells</b> configuration file)',
120     'finger'    => 'GECOS',
121     'domsvc'    => {
122                      desc =>'svcnum from svc_domain',
123                      type =>'select',
124                      select_table => 'svc_domain',
125                      select_key   => 'svcnum',
126                      select_label => 'domain',
127                    },
128   },
129   'svc_domain' => {
130     'domain'    => 'Domain',
131   },
132   'svc_acct_sm' => {
133     'domuser'   => 'domuser@virtualdomain.com',
134     'domuid'    => 'UID where domuser@virtualdomain.com mail is forwarded',
135     'domsvc'    => 'svcnum from svc_domain for virtualdomain.com',
136   },
137   'svc_forward' => {
138     'srcsvc'    => 'service from which mail is to be forwarded',
139     'dstsvc'    => 'service to which mail is to be forwarded',
140     'dst'       => 'someone@another.domain.com to use when dstsvc is 0',
141   },
142   'svc_charge' => {
143     'amount'    => 'amount',
144   },
145   'svc_wo' => {
146     'worker'    => 'Worker',
147     '_date'      => 'Date',
148   },
149   'svc_www' => {
150     #'recnum' => '',
151     #'usersvc' => '',
152   },
153 );
154
155 #  svc_acct svc_domain svc_acct_sm svc_charge svc_wo
156 foreach my $svcdb ( qw(
157   konq_kludge svc_acct svc_domain svc_acct_sm svc_forward svc_www
158 ) ) {
159
160 #  my(@fields) = $svcdb eq 'konq_kludge'
161 #                  ? ()
162 #                  : grep { $_ ne 'svcnum' } fields($svcdb);
163   #yucky kludge
164   my(@fields) = defined( $FS::Record::dbdef->table($svcdb) )
165                   ? grep { $_ ne 'svcnum' } fields($svcdb)
166                   : ();
167   #my($rowspan)=scalar(@rows);
168
169   #my($ptmp)="<TD ROWSPAN=$rowspan>$svcdb</TD>";
170 #  $visibility = $svcdb eq $part_svc->svcdb ? "SHOW" : "HIDDEN";
171 #  $visibility = $svcdb eq $p_svcdb ? "visible" : "hidden";
172   my $visibility = "hidden";
173 %>
174 <SCRIPT>
175 if (document.getElementById) {
176     document.write("<DIV ID=\"d<%= $svcdb %>\" STYLE=\"visibility: <%= $visibility %>; position: absolute\">");
177 } else {
178 <% $visibility="show" if $visibility eq "visible"; %>
179     document.write("<LAYER ID=\"l<%= $svcdb %>\" VISIBILITY=\"<%= $visibility %>\">");
180 }
181
182 function fixup(what) {
183   what.svc.value = document.dummy.svc.value;
184   what.svcdb.value = document.dummy.svcdb.options[document.dummy.svcdb.selectedIndex].value;
185   if (document.dummy.disabled.checked)
186     what.disabled.value = 'Y';
187   else
188     what.disabled.value = '';
189 }
190 </SCRIPT>
191 <FORM NAME="<%= $svcdb %>" ACTION="process/part_svc.cgi" METHOD=POST onSubmit="fixup(this)">
192 <INPUT TYPE="hidden" NAME="svcpart" VALUE="<%= $hashref->{svcpart} %>">
193 <INPUT TYPE="hidden" NAME="svc" VALUE="<%= $hashref->{svc} %>">
194 <INPUT TYPE="hidden" NAME="disabled" VALUE="<%= $hashref->{disabled} %>">
195 <INPUT TYPE="hidden" NAME="svcdb" VALUE="<%= $svcdb %>">
196 <%
197   #print "$svcdb<BR>" unless $svcdb eq 'konq_kludge';
198   print table(). "<TH>Field</TH><TH COLSPAN=2>Modifier</TH>" unless $svcdb eq 'konq_kludge';
199
200   foreach my $field (@fields) {
201     my $part_svc_column = $part_svc->part_svc_column($field);
202     my $value = $cgi->param('error')
203                   ? $cgi->param("${svcdb}__${field}")
204                   : $part_svc_column->columnvalue;
205     my $flag = $cgi->param('error')
206                  ? $cgi->param("${svcdb}__${field}_flag")
207                  : $part_svc_column->columnflag;
208     #print "<TR>$ptmp<TD>$field";
209     print "<TR><TD>$field";
210     my $def = $defs{$svcdb}{$field};
211     my $desc = ref($def) ? $def->{desc} : $def;
212     
213     print "- <FONT SIZE=-1>$desc</FONT>" if $desc;
214     print "</TD>";
215     print qq!<TD><INPUT TYPE="radio" NAME="${svcdb}__${field}_flag" VALUE=""!.
216       ' CHECKED'x($flag eq ''). ">Off</TD>";
217     print qq!<TD><INPUT TYPE="radio" NAME="${svcdb}__${field}_flag" VALUE="D"!.
218       ' CHECKED'x($flag eq 'D'). ">Default ";
219     print qq!<INPUT TYPE="radio" NAME="${svcdb}__${field}_flag" VALUE="F"!.
220       ' CHECKED'x($flag eq 'F'). ">Fixed ";
221     print '<BR>';
222     if ( ref($def) ) {
223       if ( $def->{type} eq 'select' ) {
224         print qq!<SELECT NAME="${svcdb}__${field}">!;
225         print '<OPTION> </OPTION>' unless $value;
226         foreach my $record ( qsearch( $def->{select_table}, {} ) ) {
227           my $rvalue = $record->getfield($def->{select_key});
228           print qq!<OPTION VALUE="$rvalue"!.
229                 ( $rvalue==$value ? ' SELECTED>' : '>' ).
230                 $record->getfield($def->{select_label}). '</OPTION>';
231         }
232         print '</SELECT>';
233       } else {
234         print '<font color="#ff0000">unknown type'. $def->{type};
235       }
236     } else {
237       print qq!<INPUT TYPE="text" NAME="${svcdb}__${field}" VALUE="$value">!;
238     }
239     print "</TD></TR>\n";
240     #$ptmp='';
241   }
242   print "</TABLE>" unless $svcdb eq 'konq_kludge';
243
244 print qq!\n<BR><INPUT TYPE="submit" VALUE="!,
245       $hashref->{svcpart} ? "Apply changes" : "Add service",
246       qq!">! unless $svcdb eq 'konq_kludge';
247
248   print "</FORM>";
249   print <<END;
250     <SCRIPT>
251     if (document.getElementById) {
252       document.write("</DIV>");
253     } else {
254       document.write("</LAYER>");
255     }
256     </SCRIPT>
257 END
258 }
259 #print "</TABLE>";
260 %>
261
262 <TAG onLoad="
263     if (document.getElementById) {
264       document.getElementById('d<%= $p_svcdb %>').style.visibility = 'visible';
265     } else {
266       document.l<%= $p_svcdb %>.visibility = 'visible';
267     }
268 ">
269
270   </BODY>
271 </HTML>
272