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