explicit & for table/itable/ntable
[freeside.git] / htdocs / edit / part_svc.cgi
1 #!/usr/bin/perl -Tw
2 #
3 # $Id: part_svc.cgi,v 1.11 1999-04-09 03:52:55 ivan Exp $
4 #
5 # ivan@sisd.com 97-nov-14
6 #
7 # Changes to allow page to work at a relative position in server
8 #       bmccane@maxbaud.net     98-apr-3
9 #
10 # use FS::CGI, added inline documentation ivan@sisd.com 98-jul-12
11 #
12 # $Log: part_svc.cgi,v $
13 # Revision 1.11  1999-04-09 03:52:55  ivan
14 # explicit & for table/itable/ntable
15 #
16 # Revision 1.10  1999/04/08 13:01:50  ivan
17 #  [ AND DOCUMENT! ] all svc_acct services should have a default
18 #  or fixed shell
19 #
20 # Revision 1.9  1999/02/23 08:09:21  ivan
21 # beginnings of one-screen new customer entry and some other miscellania
22 #
23 # Revision 1.8  1999/02/07 09:59:21  ivan
24 # more mod_perl fixes, and bugfixes Peter Wemm sent via email
25 #
26 # Revision 1.7  1999/01/19 05:13:42  ivan
27 # for mod_perl: no more top-level my() variables; use vars instead
28 # also the last s/create/new/;
29 #
30 # Revision 1.6  1999/01/18 09:41:31  ivan
31 # all $cgi->header calls now include ( '-expires' => 'now' ) for mod_perl
32 # (good idea anyway)
33 #
34 # Revision 1.5  1998/12/30 23:03:21  ivan
35 # bugfixes; fields isn't exported by derived classes
36 #
37 # Revision 1.4  1998/12/17 06:17:07  ivan
38 # fix double // in relative URLs, s/CGI::Base/CGI/;
39 #
40 # Revision 1.3  1998/11/21 06:43:26  ivan
41 # visual
42 #
43
44 use strict;
45 use vars qw( $cgi $part_svc $action $query $hashref $p %defs $svcdb );
46 use CGI;
47 use CGI::Carp qw(fatalsToBrowser);
48 use FS::UID qw(cgisuidsetup);
49 use FS::Record qw(qsearchs fields);
50 use FS::part_svc;
51 use FS::CGI qw(header menubar popurl table);
52
53 $cgi = new CGI;
54
55 &cgisuidsetup($cgi);
56
57 if ( $cgi->param('error') ) {
58   $part_svc = new FS::part_svc ( {
59     map { $_, scalar($cgi->param($_)) } fields('part_svc')
60   } );
61 } elsif ( $cgi->keywords ) {
62   my ($query) = $cgi->keywords;
63   $query =~ /^(\d+)$/;
64   $part_svc=qsearchs('part_svc',{'svcpart'=>$1});
65 } else { #adding
66   $part_svc = new  FS::part_svc {};
67 }
68 $action = $part_svc->svcpart ? 'Edit' : 'Add';
69 $hashref = $part_svc->hashref;
70
71 $p = popurl(2);
72 print $cgi->header( '-expires' => 'now' ), header("$action Service Definition", menubar(
73   'Main Menu' => $p,
74   'View all services' => "${p}browse/part_svc.cgi",
75 ));
76
77 print qq!<FONT SIZE="+1" COLOR="#ff0000">Error: !, $cgi->param('error'),
78       "</FONT>"
79   if $cgi->param('error');
80
81 print '<FORM ACTION="', popurl(1), 'process/part_svc.cgi" METHOD=POST>';
82
83 print qq!<INPUT TYPE="hidden" NAME="svcpart" VALUE="$hashref->{svcpart}">!,
84       "Service Part #", $hashref->{svcpart} ? $hashref->{svcpart} : "(NEW)";
85
86 print <<END;
87 <PRE>
88 Service  <INPUT TYPE="text" NAME="svc" VALUE="$hashref->{svc}">
89 </PRE>
90 Services are items you offer to your customers.
91 <UL><LI>svc_acct - Shell accounts, POP mailboxes, SLIP/PPP and ISDN accounts
92     <LI>svc_domain - Virtual domains
93     <LI>svc_acct_sm - Virtual domain mail aliasing
94 END
95 #    <LI>svc_charge - One-time charges (Partially unimplemented)
96 #    <LI>svc_wo - Work orders (Partially unimplemented)
97 print <<END;
98 </UL>
99 For the selected table, you can give fields default or fixed (unchangable)
100 values.  For example, a SLIP/PPP account may have a default (or perhaps fixed)
101 <B>slipip</B> of <B>0.0.0.0</B>, while a POP mailbox will probably have a fixed
102 blank <B>slipip</B> as well as a fixed shell something like <B>/bin/true</B> or
103 <B>/usr/bin/passwd</B>.
104 <BR><BR>
105 END
106 print &table, '<TR><TH>Table<SELECT NAME="svcdb" SIZE=1>',
107       map '<OPTION'. ' SELECTED'x($_ eq $hashref->{svcdb}). ">$_\n", qw(
108         svc_acct svc_domain svc_acct_sm
109       );
110       print "</SELECT>";
111 #  svc_acct svc_domain svc_acct_sm svc_charge svc_wo
112
113 print <<END;
114 </TH><TH>Field</TH>
115 <TH COLSPAN=2>Modifier</TH></TR>
116 END
117
118 #these might belong somewhere else for other user interfaces 
119 #pry need to eventually create stuff that's shared amount UIs
120 %defs = (
121   'svc_acct' => {
122     'dir'       => 'Home directory',
123     'uid'       => 'UID (set to fixed and blank for dial-only)',
124     'slipip'    => 'IP address',
125     'popnum'    => qq!<A HREF="$p/browse/svc_acct_pop.cgi/">POP number</A>!,
126     'username'  => 'Username',
127     'quota'     => '(unimplemented)',
128     '_password' => 'Password',
129     'gid'       => 'GID (when blank, defaults to UID)',
130     'shell'     => 'Shell (all service definitions should have a default or fixed shell that is present in the <b>shells</b> configuration file)',
131     'finger'    => 'GECOS',
132   },
133   'svc_domain' => {
134     'domain'    => 'Domain',
135   },
136   'svc_acct_sm' => {
137     'domuser'   => 'domuser@virtualdomain.com',
138     'domuid'    => 'UID where domuser@virtualdomain.com mail is forwarded',
139     'domsvc'    => 'svcnum from svc_domain for virtualdomain.com',
140   },
141   'svc_charge' => {
142     'amount'    => 'amount',
143   },
144   'svc_wo' => {
145     'worker'    => 'Worker',
146     '_date'      => 'Date',
147   },
148 );
149
150 #  svc_acct svc_domain svc_acct_sm svc_charge svc_wo
151 foreach $svcdb ( qw(
152   svc_acct svc_domain svc_acct_sm
153 ) ) {
154
155   my(@rows)=map { /^${svcdb}__(.*)$/; $1 }
156     grep ! /_flag$/,
157       grep /^${svcdb}__/,
158         fields('part_svc');
159   my($rowspan)=scalar(@rows);
160
161   my($ptmp)="<TD ROWSPAN=$rowspan>$svcdb</TD>";
162   my($row);
163   foreach $row (@rows) {
164     my $value = $part_svc->getfield($svcdb. '__'. $row);
165     my $flag = $part_svc->getfield($svcdb. '__'. $row. '_flag');
166     print "<TR>$ptmp<TD>$row";
167     print "- <FONT SIZE=-1>$defs{$svcdb}{$row}</FONT>"
168       if defined $defs{$svcdb}{$row};
169     print "</TD>";
170     print qq!<TD><INPUT TYPE="radio" NAME="${svcdb}__${row}_flag" VALUE=""!.
171       ' CHECKED'x($flag eq ''). ">Off</TD>";
172     print qq!<TD><INPUT TYPE="radio" NAME="${svcdb}__${row}_flag" VALUE="D"!.
173       ' CHECKED'x($flag eq 'D'). ">Default ";
174     print qq!<INPUT TYPE="radio" NAME="${svcdb}__${row}_flag" VALUE="F"!.
175       ' CHECKED'x($flag eq 'F'). ">Fixed ";
176     print qq!<INPUT TYPE="text" NAME="${svcdb}__${row}" VALUE="$value">!,
177       "</TD></TR>\n";
178     $ptmp='';
179   }
180 }
181 print "</TABLE>";
182
183 print qq!\n<BR><INPUT TYPE="submit" VALUE="!,
184       $hashref->{svcpart} ? "Apply changes" : "Add service",
185       qq!">!;
186
187 print <<END;
188
189     </FORM>
190   </BODY>
191 </HTML>
192 END
193