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