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