better error checking, fix scalar context to $cgi->keywords
[freeside.git] / httemplate / edit / part_svc.cgi
1 <!-- $Id: part_svc.cgi,v 1.3 2001-08-11 23:19:09 ivan Exp $ -->
2 <% 
3    my $part_svc;
4    if ( $cgi->param('error') ) { #error
5      $part_svc = new FS::part_svc ( {
6        map { $_, scalar($cgi->param($_)) } fields('part_svc')
7      } );
8    } elsif ( $cgi->keywords ) { #edit
9      my($query) = $cgi->keywords;
10      $query =~ /^(\d+)$/ or die "malformed query: $query";
11      $part_svc=qsearchs('part_svc', { 'svcpart'=>$1 } )
12        or die "unknown svcpart: $1";
13    } else { #adding
14      $part_svc = new FS::part_svc {};
15    }
16    my $action = $part_svc->svcpart ? 'Edit' : 'Add';
17    my $hashref = $part_svc->hashref;
18    my $p_svcdb = $part_svc->svcdb || 'svc_acct';
19
20 %>
21
22 <SCRIPT>
23 function visualize(what) {
24   if (document.getElementById) {
25     document.getElementById('d<%= $p_svcdb %>').style.visibility = "visible";
26   } else {
27     document.l<%= $p_svcdb %>.visibility = "visible";
28   }
29 }
30 </SCRIPT>
31
32 <%= header("$action Service Definition",
33            menubar( 'Main Menu'         => $p,
34                     'View all services' => "${p}browse/part_svc.cgi"
35                   ),
36            " onLoad=\"visualize()\""
37            )
38 %>
39
40 <% if ( $cgi->param('error') ) { %>
41 <FONT SIZE="+1" COLOR="#ff0000">Error: <%= $cgi->param('error') %></FONT>
42 <% } %>
43
44 <FORM NAME="dummy">
45
46       Service Part #<%= $part_svc->svcpart ? $part_svc->svcpart : "(NEW)" %>
47
48 <PRE>
49 Service  <INPUT TYPE="text" NAME="svc" VALUE="<%= $hashref->{svc} %>">
50 </PRE>
51 Services are items you offer to your customers.
52 <UL><LI>svc_acct - Shell accounts, POP mailboxes, SLIP/PPP and ISDN accounts
53     <LI>svc_domain - Virtual domains
54     <LI>svc_acct_sm - Virtual domain mail aliasing
55     <LI>svc_www - Virtual domain website
56 <!--   <LI>svc_charge - One-time charges (Partially unimplemented)
57        <LI>svc_wo - Work orders (Partially unimplemented)
58 -->
59 </UL>
60 For the selected table, you can give fields default or fixed (unchangable)
61 values.  For example, a SLIP/PPP account may have a default (or perhaps fixed)
62 <B>slipip</B> of <B>0.0.0.0</B>, while a POP mailbox will probably have a fixed
63 blank <B>slipip</B> as well as a fixed shell something like <B>/bin/true</B> or
64 <B>/usr/bin/passwd</B>.
65 <BR><BR>
66 <SCRIPT>
67 var svcdb = null;
68 var something = null;
69 function changed(what) {
70   svcdb = what.options[what.selectedIndex].value;
71 <% foreach my $svcdb ( qw( svc_acct svc_domain svc_acct_sm svc_www ) ) { %>
72   if (svcdb == "<%= $svcdb %>" ) {
73     <% foreach my $not ( grep { $_ ne $svcdb } (
74                            qw(svc_acct svc_domain svc_acct_sm svc_www) ) ) { %>
75       if (document.getElementById) {
76         document.getElementById('d<%= $not %>').style.visibility = "hidden";
77       } else {
78         document.l<%= $not %>.visibility = "hidden";
79       }
80     <% } %>
81     if (document.getElementById) {
82       document.getElementById('d<%= $svcdb %>').style.visibility = "visible";
83     } else {
84       document.l<%= $svcdb %>.visibility = "visible";
85     }
86   }
87 <% } %>
88 }
89 </SCRIPT>
90 <% my @dbs = $hashref->{svcdb}
91              ? ( $hashref->{svcdb} )
92              : qw( svc_acct svc_domain svc_acct_sm svc_www ); %>
93 Table<SELECT NAME="svcdb" SIZE=1 onChange="changed(this)">
94 <% foreach my $svcdb (@dbs) { %>
95 <OPTION VALUE="<%= $svcdb %>" <%= ' SELECTED'x($svcdb eq $hashref->{svcdb}) %>><%= $svcdb %>
96 <% } %>
97 </SELECT>
98
99 <%
100 #these might belong somewhere else for other user interfaces 
101 #pry need to eventually create stuff that's shared amount UIs
102 my %defs = (
103   'svc_acct' => {
104     'dir'       => 'Home directory',
105     'uid'       => 'UID (set to fixed and blank for dial-only)',
106     'slipip'    => 'IP address (set to fixed and blank to disable dialin)',
107     'popnum'    => qq!<A HREF="$p/browse/svc_acct_pop.cgi/">POP number</A>!,
108     'username'  => 'Username',
109     'quota'     => '(unimplemented)',
110     '_password' => 'Password',
111     'gid'       => 'GID (when blank, defaults to UID)',
112     'shell'     => 'Shell (all service definitions should have a default or fixed shell that is present in the <b>shells</b> configuration file)',
113     'finger'    => 'GECOS',
114   },
115   'svc_domain' => {
116     'domain'    => 'Domain',
117   },
118   'svc_acct_sm' => {
119     'domuser'   => 'domuser@virtualdomain.com',
120     'domuid'    => 'UID where domuser@virtualdomain.com mail is forwarded',
121     'domsvc'    => 'svcnum from svc_domain for virtualdomain.com',
122   },
123   'svc_charge' => {
124     'amount'    => 'amount',
125   },
126   'svc_wo' => {
127     'worker'    => 'Worker',
128     '_date'      => 'Date',
129   },
130   'svc_www' => {
131     #'recnum' => '',
132     #'usersvc' => '',
133   },
134 );
135
136 #  svc_acct svc_domain svc_acct_sm svc_charge svc_wo
137 foreach my $svcdb ( qw(
138   konq_kludge svc_acct svc_domain svc_acct_sm svc_www
139 ) ) {
140
141   my(@rows)=map { /^${svcdb}__(.*)$/; $1 }
142     grep ! /_flag$/,
143       grep /^${svcdb}__/,
144         fields('part_svc');
145   #my($rowspan)=scalar(@rows);
146
147   #my($ptmp)="<TD ROWSPAN=$rowspan>$svcdb</TD>";
148 #  $visibility = $svcdb eq $part_svc->svcdb ? "SHOW" : "HIDDEN";
149 #  $visibility = $svcdb eq $p_svcdb ? "visible" : "hidden";
150   my $visibility = "hidden";
151 %>
152 <SCRIPT>
153 if (document.getElementById) {
154     document.write("<DIV ID=\"d<%= $svcdb %>\" STYLE=\"visibility: <%= $visibility %>; position: absolute\">");
155 } else {
156 <% $visibility="show" if $visibility eq "visible"; %>
157     document.write("<LAYER ID=\"l<%= $svcdb %>\" VISIBILITY=\"<%= $visibility %>\">");
158 }
159
160 function fixup(what) {
161   what.svc.value = document.dummy.svc.value;
162   what.svcdb.value = document.dummy.svcdb.options[document.dummy.svcdb.selectedIndex].value
163 }
164 </SCRIPT>
165 <FORM NAME="<%= $svcdb %>" ACTION="process/part_svc.cgi" METHOD=POST onSubmit="fixup(this)">
166 <INPUT TYPE="hidden" NAME="svcpart" VALUE="<%= $hashref->{svcpart} %>">
167 <INPUT TYPE="hidden" NAME="svc" VALUE="<%= $hashref->{svc} %>">
168 <INPUT TYPE="hidden" NAME="svcdb" VALUE="<%= $svcdb %>">
169 <%
170   print "$svcdb" unless $svcdb eq 'konq_kludge';
171   print "<BR><TABLE BORDER=1><TH>Field</TH><TH COLSPAN=2>Modifier</TH>" unless $svcdb eq 'konq_kludge';
172
173   my($row);
174   foreach $row (@rows) {
175     my $value = $part_svc->getfield($svcdb. '__'. $row);
176     my $flag = $part_svc->getfield($svcdb. '__'. $row. '_flag');
177     #print "<TR>$ptmp<TD>$row";
178     print "<TR><TD>$row";
179     print "- <FONT SIZE=-1>$defs{$svcdb}{$row}</FONT>"
180       if defined $defs{$svcdb}{$row};
181     print "</TD>";
182     print qq!<TD><INPUT TYPE="radio" NAME="${svcdb}__${row}_flag" VALUE=""!.
183       ' CHECKED'x($flag eq ''). ">Off</TD>";
184     print qq!<TD><INPUT TYPE="radio" NAME="${svcdb}__${row}_flag" VALUE="D"!.
185       ' CHECKED'x($flag eq 'D'). ">Default ";
186     print qq!<INPUT TYPE="radio" NAME="${svcdb}__${row}_flag" VALUE="F"!.
187       ' CHECKED'x($flag eq 'F'). ">Fixed ";
188     print qq!<INPUT TYPE="text" NAME="${svcdb}__${row}" VALUE="$value">!,
189       "</TD></TR>\n";
190     #$ptmp='';
191   }
192   print "</TABLE>" unless $svcdb eq 'konq_kludge';
193
194 print qq!\n<BR><INPUT TYPE="submit" VALUE="!,
195       $hashref->{svcpart} ? "Apply changes" : "Add service",
196       qq!">! unless $svcdb eq 'konq_kludge';
197
198   print "</FORM>";
199   print <<END;
200     <SCRIPT>
201     if (document.getElementById) {
202       document.write("</DIV>");
203     } else {
204       document.write("</LAYER>");
205     }
206     </SCRIPT>
207 END
208 }
209 #print "</TABLE>";
210 %>
211
212 <TAG onLoad="
213     if (document.getElementById) {
214       document.getElementById('d<%= $p_svcdb %>').style.visibility = 'visible';
215     } else {
216       document.l<%= $p_svcdb %>.visibility = 'visible';
217     }
218 ">
219
220   </BODY>
221 </HTML>
222