templates!!!
[freeside.git] / httemplate / edit / part_svc.cgi
1 <!-- $Id: part_svc.cgi,v 1.1 2001-07-30 07:36:04 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+)$/;
11      $part_svc=qsearchs('part_svc',{'svcpart'=>$1});
12    } else { #adding
13      $part_svc = new FS::part_svc {};
14    }
15    my $action = $part_svc->svcpart ? 'Edit' : 'Add';
16    my $hashref = $part_svc->hashref;
17    my $p_svcdb = $part_svc->svcdb || 'svc_acct';
18
19 %>
20
21 <SCRIPT>
22 function visualize(what) {
23   if (document.getElementById) {
24     document.getElementById('d<%= $p_svcdb %>').style.visibility = "visible";
25   } else {
26     document.l<%= $p_svcdb %>.visibility = "visible";
27   }
28 }
29 </SCRIPT>
30
31 <%= header("$action Service Definition",
32            menubar( 'Main Menu'         => $p,
33                     'View all services' => "${p}browse/part_svc.cgi"
34                   ),
35            " onLoad=\"visualize()\""
36            )
37 %>
38
39 <% if ( $cgi->param('error') ) { %>
40 <FONT SIZE="+1" COLOR="#ff0000">Error: <%= $cgi->param('error') %></FONT>
41 <% } %>
42
43 <FORM NAME="dummy">
44
45       Service Part #<%= $part_svc->svcpart ? $part_svc->svcpart : "(NEW)" %>
46
47 <PRE>
48 Service  <INPUT TYPE="text" NAME="svc" VALUE="<%= $hashref->{svc} %>">
49 </PRE>
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 - Virtual domains
53     <LI>svc_acct_sm - Virtual domain mail aliasing
54     <LI>svc_www - Virtual domain website
55 <!--   <LI>svc_charge - One-time charges (Partially unimplemented)
56        <LI>svc_wo - Work orders (Partially unimplemented)
57 -->
58 </UL>
59 For the selected table, you can give fields default or fixed (unchangable)
60 values.  For example, a SLIP/PPP account may have a default (or perhaps fixed)
61 <B>slipip</B> of <B>0.0.0.0</B>, while a POP mailbox will probably have a fixed
62 blank <B>slipip</B> as well as a fixed shell something like <B>/bin/true</B> or
63 <B>/usr/bin/passwd</B>.
64 <BR><BR>
65 <SCRIPT>
66 var svcdb = null;
67 var something = null;
68 function changed(what) {
69   svcdb = what.options[what.selectedIndex].value;
70 <% foreach my $svcdb ( qw( svc_acct svc_domain svc_acct_sm svc_www ) ) { %>
71   if (svcdb == "<%= $svcdb %>" ) {
72     <% foreach my $not ( grep { $_ ne $svcdb } (
73                            qw(svc_acct svc_domain svc_acct_sm svc_www) ) ) { %>
74       if (document.getElementById) {
75         document.getElementById('d<%= $not %>').style.visibility = "hidden";
76       } else {
77         document.l<%= $not %>.visibility = "hidden";
78       }
79     <% } %>
80     if (document.getElementById) {
81       document.getElementById('d<%= $svcdb %>').style.visibility = "visible";
82     } else {
83       document.l<%= $svcdb %>.visibility = "visible";
84     }
85   }
86 <% } %>
87 }
88 </SCRIPT>
89 Table<SELECT NAME="svcdb" SIZE=1 onChange="changed(this)">
90 <% foreach my $svcdb (qw( svc_acct svc_domain svc_acct_sm svc_www )) { %>
91 <OPTION VALUE="<%= $svcdb %>" <%= ' SELECTED'x($svcdb eq $hashref->{svcdb}) %>><%= $svcdb %>
92 <% } %>
93 </SELECT>
94
95 <%
96 #these might belong somewhere else for other user interfaces 
97 #pry need to eventually create stuff that's shared amount UIs
98 my %defs = (
99   'svc_acct' => {
100     'dir'       => 'Home directory',
101     'uid'       => 'UID (set to fixed and blank for dial-only)',
102     'slipip'    => 'IP address (set to fixed and blank to disable dialin)',
103     'popnum'    => qq!<A HREF="$p/browse/svc_acct_pop.cgi/">POP number</A>!,
104     'username'  => 'Username',
105     'quota'     => '(unimplemented)',
106     '_password' => 'Password',
107     'gid'       => 'GID (when blank, defaults to UID)',
108     'shell'     => 'Shell (all service definitions should have a default or fixed shell that is present in the <b>shells</b> configuration file)',
109     'finger'    => 'GECOS',
110   },
111   'svc_domain' => {
112     'domain'    => 'Domain',
113   },
114   'svc_acct_sm' => {
115     'domuser'   => 'domuser@virtualdomain.com',
116     'domuid'    => 'UID where domuser@virtualdomain.com mail is forwarded',
117     'domsvc'    => 'svcnum from svc_domain for virtualdomain.com',
118   },
119   'svc_charge' => {
120     'amount'    => 'amount',
121   },
122   'svc_wo' => {
123     'worker'    => 'Worker',
124     '_date'      => 'Date',
125   },
126   'svc_www' => {
127     #'recnum' => '',
128     #'usersvc' => '',
129   },
130 );
131
132 #  svc_acct svc_domain svc_acct_sm svc_charge svc_wo
133 foreach my $svcdb ( qw(
134   konq_kludge svc_acct svc_domain svc_acct_sm svc_www
135 ) ) {
136
137   my(@rows)=map { /^${svcdb}__(.*)$/; $1 }
138     grep ! /_flag$/,
139       grep /^${svcdb}__/,
140         fields('part_svc');
141   #my($rowspan)=scalar(@rows);
142
143   #my($ptmp)="<TD ROWSPAN=$rowspan>$svcdb</TD>";
144 #  $visibility = $svcdb eq $part_svc->svcdb ? "SHOW" : "HIDDEN";
145 #  $visibility = $svcdb eq $p_svcdb ? "visible" : "hidden";
146   my $visibility = "hidden";
147 %>
148 <SCRIPT>
149 if (document.getElementById) {
150     document.write("<DIV ID=\"d<%= $svcdb %>\" STYLE=\"visibility: <%= $visibility %>; position: absolute\">");
151 } else {
152 <% $visibility="show" if $visibility eq "visible"; %>
153     document.write("<LAYER ID=\"l<%= $svcdb %>\" VISIBILITY=\"<%= $visibility %>\">");
154 }
155
156 function fixup(what) {
157   what.svc.value = document.dummy.svc.value;
158   what.svcdb.value = document.dummy.svcdb.options[document.dummy.svcdb.selectedIndex].value
159 }
160 </SCRIPT>
161 <FORM NAME="<%= $svcdb %>" ACTION="process/part_svc.cgi" METHOD=POST onSubmit="fixup(this)">
162 <INPUT TYPE="hidden" NAME="svcpart" VALUE="<%= $hashref->{svcpart} %>">
163 <INPUT TYPE="hidden" NAME="svc" VALUE="<%= $hashref->{svc} %>">
164 <INPUT TYPE="hidden" NAME="svcdb" VALUE="<%= $svcdb %>">
165 <%
166   print "$svcdb" unless $svcdb eq 'konq_kludge';
167   print "<BR><TABLE BORDER=1><TH>Field</TH><TH COLSPAN=2>Modifier</TH>" unless $svcdb eq 'konq_kludge';
168
169   my($row);
170   foreach $row (@rows) {
171     my $value = $part_svc->getfield($svcdb. '__'. $row);
172     my $flag = $part_svc->getfield($svcdb. '__'. $row. '_flag');
173     #print "<TR>$ptmp<TD>$row";
174     print "<TR><TD>$row";
175     print "- <FONT SIZE=-1>$defs{$svcdb}{$row}</FONT>"
176       if defined $defs{$svcdb}{$row};
177     print "</TD>";
178     print qq!<TD><INPUT TYPE="radio" NAME="${svcdb}__${row}_flag" VALUE=""!.
179       ' CHECKED'x($flag eq ''). ">Off</TD>";
180     print qq!<TD><INPUT TYPE="radio" NAME="${svcdb}__${row}_flag" VALUE="D"!.
181       ' CHECKED'x($flag eq 'D'). ">Default ";
182     print qq!<INPUT TYPE="radio" NAME="${svcdb}__${row}_flag" VALUE="F"!.
183       ' CHECKED'x($flag eq 'F'). ">Fixed ";
184     print qq!<INPUT TYPE="text" NAME="${svcdb}__${row}" VALUE="$value">!,
185       "</TD></TR>\n";
186     #$ptmp='';
187   }
188   print "</TABLE>" unless $svcdb eq 'konq_kludge';
189
190 print qq!\n<BR><INPUT TYPE="submit" VALUE="!,
191       $hashref->{svcpart} ? "Apply changes" : "Add service",
192       qq!">! unless $svcdb eq 'konq_kludge';
193
194   print "</FORM>";
195   print <<END;
196     <SCRIPT>
197     if (document.getElementById) {
198       document.write("</DIV>");
199     } else {
200       document.write("</LAYER>");
201     }
202     </SCRIPT>
203 END
204 }
205 #print "</TABLE>";
206 %>
207
208 <TAG onLoad="
209     if (document.getElementById) {
210       document.getElementById('d<%= $p_svcdb %>').style.visibility = 'visible';
211     } else {
212       document.l<%= $p_svcdb %>.visibility = 'visible';
213     }
214 ">
215
216   </BODY>
217 </HTML>
218