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