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