new admin documentation, quick one-pkg order
[freeside.git] / httemplate / edit / part_svc.cgi
1 <!-- $Id: part_svc.cgi,v 1.6 2001-09-04 14:44:06 ivan Exp $ -->
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
48 <PRE>
49 Service  <INPUT TYPE="text" NAME="svc" VALUE="<%= $hashref->{svc} %>">
50 </PRE>
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>depreciated</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 var something = null;
70 function changed(what) {
71   svcdb = what.options[what.selectedIndex].value;
72 <% foreach my $svcdb ( qw( svc_acct svc_domain svc_acct_sm svc_forward svc_www ) ) { %>
73   if (svcdb == "<%= $svcdb %>" ) {
74     <% foreach my $not ( grep { $_ ne $svcdb } (
75                            qw(svc_acct svc_domain svc_acct_sm svc_forward svc_www) ) ) { %>
76       if (document.getElementById) {
77         document.getElementById('d<%= $not %>').style.visibility = "hidden";
78       } else {
79         document.l<%= $not %>.visibility = "hidden";
80       }
81     <% } %>
82     if (document.getElementById) {
83       document.getElementById('d<%= $svcdb %>').style.visibility = "visible";
84     } else {
85       document.l<%= $svcdb %>.visibility = "visible";
86     }
87   }
88 <% } %>
89 }
90 </SCRIPT>
91 <% my @dbs = $hashref->{svcdb}
92              ? ( $hashref->{svcdb} )
93              : qw( svc_acct svc_domain svc_acct_sm svc_forward svc_www ); %>
94 Table<SELECT NAME="svcdb" SIZE=1 onChange="changed(this)">
95 <% foreach my $svcdb (@dbs) { %>
96 <OPTION VALUE="<%= $svcdb %>" <%= ' SELECTED'x($svcdb eq $hashref->{svcdb}) %>><%= $svcdb %>
97 <% } %>
98 </SELECT>
99
100 <%
101 #these might belong somewhere else for other user interfaces 
102 #pry need to eventually create stuff that's shared amount UIs
103 my %defs = (
104   'svc_acct' => {
105     'dir'       => 'Home directory',
106     'uid'       => 'UID (set to fixed and blank for dial-only)',
107     '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.)',
108     'popnum'    => qq!<A HREF="$p/browse/svc_acct_pop.cgi/">POP number</A>!,
109     'username'  => 'Username',
110     'quota'     => '(unimplemented)',
111     '_password' => 'Password',
112     'gid'       => 'GID (when blank, defaults to UID)',
113     'shell'     => 'Shell (all service definitions should have a default or fixed shell that is present in the <b>shells</b> configuration file)',
114     'finger'    => 'GECOS',
115     'domsvc'    => 'svcnum from svc_domain',
116   },
117   'svc_domain' => {
118     'domain'    => 'Domain',
119   },
120   'svc_acct_sm' => {
121     'domuser'   => 'domuser@virtualdomain.com',
122     'domuid'    => 'UID where domuser@virtualdomain.com mail is forwarded',
123     'domsvc'    => 'svcnum from svc_domain for virtualdomain.com',
124   },
125   'svc_forward' => {
126     'srcsvc'    => 'service from which mail is to be forwarded',
127     'dstsvc'    => 'service to which mail is to be forwarded',
128     'dst'       => 'someone@another.domain.com to use when dstsvc is 0',
129   },
130   'svc_charge' => {
131     'amount'    => 'amount',
132   },
133   'svc_wo' => {
134     'worker'    => 'Worker',
135     '_date'      => 'Date',
136   },
137   'svc_www' => {
138     #'recnum' => '',
139     #'usersvc' => '',
140   },
141 );
142
143 #  svc_acct svc_domain svc_acct_sm svc_charge svc_wo
144 foreach my $svcdb ( qw(
145   konq_kludge svc_acct svc_domain svc_acct_sm svc_forward svc_www
146 ) ) {
147
148   my(@rows)=map { /^${svcdb}__(.*)$/; $1 }
149     grep ! /_flag$/,
150       grep /^${svcdb}__/,
151         fields('part_svc');
152   #my($rowspan)=scalar(@rows);
153
154   #my($ptmp)="<TD ROWSPAN=$rowspan>$svcdb</TD>";
155 #  $visibility = $svcdb eq $part_svc->svcdb ? "SHOW" : "HIDDEN";
156 #  $visibility = $svcdb eq $p_svcdb ? "visible" : "hidden";
157   my $visibility = "hidden";
158 %>
159 <SCRIPT>
160 if (document.getElementById) {
161     document.write("<DIV ID=\"d<%= $svcdb %>\" STYLE=\"visibility: <%= $visibility %>; position: absolute\">");
162 } else {
163 <% $visibility="show" if $visibility eq "visible"; %>
164     document.write("<LAYER ID=\"l<%= $svcdb %>\" VISIBILITY=\"<%= $visibility %>\">");
165 }
166
167 function fixup(what) {
168   what.svc.value = document.dummy.svc.value;
169   what.svcdb.value = document.dummy.svcdb.options[document.dummy.svcdb.selectedIndex].value
170 }
171 </SCRIPT>
172 <FORM NAME="<%= $svcdb %>" ACTION="process/part_svc.cgi" METHOD=POST onSubmit="fixup(this)">
173 <INPUT TYPE="hidden" NAME="svcpart" VALUE="<%= $hashref->{svcpart} %>">
174 <INPUT TYPE="hidden" NAME="svc" VALUE="<%= $hashref->{svc} %>">
175 <INPUT TYPE="hidden" NAME="svcdb" VALUE="<%= $svcdb %>">
176 <%
177   print "$svcdb" unless $svcdb eq 'konq_kludge';
178   print "<BR><TABLE BORDER=1><TH>Field</TH><TH COLSPAN=2>Modifier</TH>" unless $svcdb eq 'konq_kludge';
179
180   my($row);
181   foreach $row (@rows) {
182     my $value = $part_svc->getfield($svcdb. '__'. $row);
183     my $flag = $part_svc->getfield($svcdb. '__'. $row. '_flag');
184     #print "<TR>$ptmp<TD>$row";
185     print "<TR><TD>$row";
186     print "- <FONT SIZE=-1>$defs{$svcdb}{$row}</FONT>"
187       if defined $defs{$svcdb}{$row};
188     print "</TD>";
189     print qq!<TD><INPUT TYPE="radio" NAME="${svcdb}__${row}_flag" VALUE=""!.
190       ' CHECKED'x($flag eq ''). ">Off</TD>";
191     print qq!<TD><INPUT TYPE="radio" NAME="${svcdb}__${row}_flag" VALUE="D"!.
192       ' CHECKED'x($flag eq 'D'). ">Default ";
193     print qq!<INPUT TYPE="radio" NAME="${svcdb}__${row}_flag" VALUE="F"!.
194       ' CHECKED'x($flag eq 'F'). ">Fixed ";
195     print qq!<INPUT TYPE="text" NAME="${svcdb}__${row}" VALUE="$value">!,
196       "</TD></TR>\n";
197     #$ptmp='';
198   }
199   print "</TABLE>" unless $svcdb eq 'konq_kludge';
200
201 print qq!\n<BR><INPUT TYPE="submit" VALUE="!,
202       $hashref->{svcpart} ? "Apply changes" : "Add service",
203       qq!">! unless $svcdb eq 'konq_kludge';
204
205   print "</FORM>";
206   print <<END;
207     <SCRIPT>
208     if (document.getElementById) {
209       document.write("</DIV>");
210     } else {
211       document.write("</LAYER>");
212     }
213     </SCRIPT>
214 END
215 }
216 #print "</TABLE>";
217 %>
218
219 <TAG onLoad="
220     if (document.getElementById) {
221       document.getElementById('d<%= $p_svcdb %>').style.visibility = 'visible';
222     } else {
223       document.l<%= $p_svcdb %>.visibility = 'visible';
224     }
225 ">
226
227   </BODY>
228 </HTML>
229