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