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