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