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