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