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