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