invoice_sections_with_taxes per-agent, RT#79636
[freeside.git] / httemplate / edit / svc_acct.cgi
index 2eb4a8b..27ea3c5 100755 (executable)
@@ -1,54 +1,61 @@
-<% include('/elements/header.html', "$action $svc account") %>
+<& /elements/header.html, mt("$action [_1] account",$svc) &>
 
-<% include('/elements/error.html') %>
+<& /elements/error.html &>
 
 % if ( $cust_main ) { 
 
-  <% include( '/elements/small_custview.html', $cust_main, '', 1,
-              popurl(2) . "view/cust_main.cgi") %>
+  <& /elements/small_custview.html, $cust_main, '', 1,
+              popurl(2) . "view/cust_main.cgi" &>
   <BR>
 % } 
 
-<SCRIPT TYPE="text/javascript">
-function randomPass() {
-  var i=0;
-  var pw_set='<% join('', 'a'..'z', 'A'..'Z', '0'..'9' ) %>';
-  var pass='';
-  while(i < 8) {
-    i++;
-    pass += pw_set.charAt(Math.floor(Math.random() * pw_set.length));
-  }
-  document.OneTrueForm.clear_password.value = pass;
-}
-</SCRIPT>
-
 <FORM NAME="OneTrueForm" ACTION="<% $p1 %>process/svc_acct.cgi" METHOD=POST>
 <INPUT TYPE="hidden" NAME="svcnum" VALUE="<% $svcnum %>">
 <INPUT TYPE="hidden" NAME="pkgnum" VALUE="<% $pkgnum %>">
 <INPUT TYPE="hidden" NAME="svcpart" VALUE="<% $svcpart %>">
 
-Service # <% $svcnum ? "<B>$svcnum</B>" : " (NEW)" %><BR>
+% if ( $svcnum ) {
+% my $svclabel = emt("Service #[_1]",$svcnum);
+% $svclabel =~ s/$svcnum/<B>$svcnum<\/B>/;
+<% $svclabel %>
+% } else {
+<% mt("Service # (NEW)") |h %>
+% }
+<BR>
 
 <% ntable("#cccccc",2) %>
 
 <TR>
-  <TD ALIGN="right">Service</TD>
+  <TD ALIGN="right"><% mt('Service') |h %></TD>
   <TD BGCOLOR="#eeeeee"><% $part_svc->svc %></TD>
 </TR>
 
-<TR>
-  <TD ALIGN="right">Username</TD>
-  <TD>
-    <INPUT TYPE="text" NAME="username" VALUE="<% $username %>" SIZE=<% $ulen2 %> MAXLENGTH=<% $ulen %>>
-  </TD>
+<% include('/elements/tr-td-label.html',
+     'label'    => $part_svc->part_svc_column('username')->columnlabel || mt('Username'),
+     'required' => $part_svc->part_svc_column('username')->required ) %>
+% if ( $svcnum && $conf->exists('svc_acct-no_edit_username') ) {
+    <TD BGCOLOR="#eeeeee"><% $svc_acct->username() %></TD>
+    <INPUT TYPE="hidden" NAME="username" VALUE="<% $username %>">
+% } else {
+    <TD>
+      <INPUT TYPE="text" NAME="username" VALUE="<% $username %>" SIZE=<% $ulen2 %> MAXLENGTH=<% $ulen %>>
+    </TD>
+% }
 </TR>
 
 %if ( $part_svc->part_svc_column('_password')->columnflag ne 'F' ) {
-<TR>
-  <TD ALIGN="right">Password</TD>
+% #XXX eventually should require "Edit Password" ACL
+<% include('/elements/tr-td-label.html',
+     'label'    => $part_svc->part_svc_column('_password')->columnlabel || mt('Password'),
+     'required' => $part_svc->part_svc_column('_password')->required ) %>
   <TD>
-    <INPUT TYPE="text" NAME="clear_password" VALUE="<% $password %>" SIZE=<% $pmax2 %> MAXLENGTH=<% $pmax %>>
-    <INPUT TYPE="button" VALUE="Generate" onclick="randomPass();">
+    <INPUT TYPE="text" ID="clear_password" NAME="clear_password" VALUE="<% $password %>" SIZE=<% $pmax2 %> MAXLENGTH=<% $pmax %>>
+    <& /elements/random_pass.html, 'clear_password' &><BR>
+    <DIV ID="clear_password_result" STYLE="font-size: smaller"></DIV>
+    <& '/elements/validate_password.html', 
+         'fieldid' => 'clear_password',
+         'svcnum' => $svcnum 
+    &>
   </TD>
 </TR>
 %}else{
@@ -59,19 +66,17 @@ Service # <% $svcnum ? "<B>$svcnum</B>" : " (NEW)" %><BR>
 %my $sec_phrase = $svc_acct->sec_phrase;
 %if ( $conf->exists('security_phrase') 
 %  && $part_svc->part_svc_column('sec_phrase')->columnflag ne 'F' ) {
-%
-
 
-  <TR>
-    <TD ALIGN="right">Security phrase</TD>
+<% include('/elements/tr-td-label.html',
+     'label'    => $part_svc->part_svc_column('sec_phrase')->columnlabel || mt('Security phrase'),
+     'required' => $part_svc->part_svc_column('sec_phrase')->required ) %>
     <TD>
       <INPUT TYPE="text" NAME="sec_phrase" VALUE="<% $sec_phrase %>" SIZE=32>
-      (for forgotten passwords)
+      (<% mt('for forgotten passwords') |h %>)
     </TD>
   </TD>
 % } else { 
 
-
   <INPUT TYPE="hidden" NAME="sec_phrase" VALUE="<% $sec_phrase %>">
 % } 
 %
@@ -80,7 +85,6 @@ Service # <% $svcnum ? "<B>$svcnum</B>" : " (NEW)" %><BR>
 %if ( $part_svc->part_svc_column('domsvc')->columnflag eq 'F' ) {
 %
 
-
   <INPUT TYPE="hidden" NAME="domsvc" VALUE="<% $domsvc %>">
 % } else { 
 %
@@ -89,7 +93,7 @@ Service # <% $svcnum ? "<B>$svcnum</B>" : " (NEW)" %><BR>
 %  if ( $domsvc ) {
 %    my $svc_domain = qsearchs('svc_domain', { 'svcnum' => $domsvc, } );
 %    if ( $svc_domain ) {
-%      $svc_domain{$svc_domain->svcnum} = $svc_domain;
+%      $svc_domain{$svc_domain->svcnum} = $svc_domain->domain;
 %    } else {
 %      warn "unknown svc_domain.svcnum for svc_acct.domsvc: $domsvc";
 %    }
@@ -100,11 +104,10 @@ Service # <% $svcnum ? "<B>$svcnum</B>" : " (NEW)" %><BR>
 %                                                 'pkgnum'  => $pkgnum,
 %                                                )
 %                );
-%
-
 
-  <TR>
-    <TD ALIGN="right">Domain</TD>
+<% include('/elements/tr-td-label.html',
+     'label'    => $part_svc->part_svc_column('domsvc')->columnlabel || mt('Domain'),
+     'required' => $part_svc->part_svc_column('domsvc')->required ) %>
     <TD>
       <SELECT NAME="domsvc" SIZE=1>
 % foreach my $svcnum (
@@ -114,7 +117,6 @@ Service # <% $svcnum ? "<B>$svcnum</B>" : " (NEW)" %><BR>
 %             my $svc_domain = $svc_domain{$svcnum};
 %        
 
-
              <OPTION VALUE="<% $svcnum %>" <% $svcnum == $domsvc ? ' SELECTED' : '' %>><% $svc_domain{$svcnum} %>
 % } 
 
@@ -127,7 +129,7 @@ Service # <% $svcnum ? "<B>$svcnum</B>" : " (NEW)" %><BR>
 % if ( $communigate ) {
 
     <TR>
-      <TD ALIGN="right">Aliases</TD>
+      <TD ALIGN="right"><% mt('Aliases') |h %></TD>
       <TD><INPUT TYPE="text" NAME="cgp_aliases" VALUE="<% $svc_acct->cgp_aliases %>"></TD>
     </TR>
 
@@ -136,28 +138,48 @@ Service # <% $svcnum ? "<B>$svcnum</B>" : " (NEW)" %><BR>
 % }
 
 
-<% include('/elements/tr-select-svc_pbx.html',
+<& /elements/tr-select-svc_pbx.html,
              'curr_value' => $svc_acct->pbxsvc,
              'part_svc'   => $part_svc,
              'cust_pkg'   => $cust_pkg,
-          )
-%>
+             'label'      => $part_svc->part_svc_column('pbxsvc')->columnlabel || 'PBX',
+&>
 
 %#pop
 %my $popnum = $svc_acct->popnum || 0;
 %if ( $part_svc->part_svc_column('popnum')->columnflag eq 'F' ) {
 %
 
-
   <INPUT TYPE="hidden" NAME="popnum" VALUE="<% $popnum %>">
 % } else { 
 
-
-  <TR>
-    <TD ALIGN="right">Access number</TD>
+<% include('/elements/tr-td-label.html',
+     'label'    => $part_svc->part_svc_column('popnum')->columnlabel || mt('Access number'),
+     'required' => $part_svc->part_svc_column('popnum')->required ) %>
     <TD><% FS::svc_acct_pop::popselector($popnum) %></TD>
   </TR>
 % } 
+
+%#tower (huh)
+%if ( $conf->exists('svc_acct-tower_sector')
+%     && $part_svc->part_svc_column('sectornum')->columnflag ne 'F' ) {
+    <& /elements/tr-select-tower_sector.html,
+         'curr_value' => $svc_acct->sectornum,
+         #'part_svc'   => $part_svc,
+         #'cust_pkg'   => $cust_pkg,
+         'required'   => $part_svc->part_svc_column('sectornum')->required,
+         'label'       => $part_svc->part_svc_column('sectornum')->columnlabel || mt('Tower sector'),
+    &>
+%} else {
+    <INPUT TYPE="hidden" NAME="sectornum" VALUE="<% $svc_acct->sectornum %>">
+%}
+
+<& /elements/tr-svc_export_machine.html,
+     'svc'      => $svc_acct,
+     'part_svc' => $part_svc,
+     'cgi'      => $cgi,
+&>
+
 % #uid/gid 
 % foreach my $xid (qw( uid gid )) { 
 %
@@ -167,22 +189,23 @@ Service # <% $svcnum ? "<B>$svcnum</B>" : " (NEW)" %><BR>
 %  
 % if ( length($svc_acct->$xid()) ) { 
 
-  
-      <TR>
-        <TD ALIGN="right"><% uc($xid) %></TD>
+<% include('/elements/tr-td-label.html',
+     'label'    => $part_svc->part_svc_column($xid)->columnlabel || uc($xid),
+     'required' => $part_svc->part_svc_column($xid)->required ) %>
+%#      <TR>
+%#        <TD ALIGN="right"><% uc($xid) %></TD>
           <TD BGCOLOR="#eeeeee"><% $svc_acct->$xid() %></TD>
         <TD>
         </TD>
       </TR>
 % } 
-
   
     <INPUT TYPE="hidden" NAME="<% $xid %>" VALUE="<% $svc_acct->$xid() %>">
 % } else { 
-
   
-    <TR>
-      <TD ALIGN="right"><% uc($xid) %></TD>
+<% include('/elements/tr-td-label.html',
+     'label'    => $part_svc->part_svc_column($xid)->columnlabel || uc($xid),
+     'required' => $part_svc->part_svc_column($xid)->required ) %>
       <TD>
         <INPUT TYPE="text" NAME="<% $xid %>" SIZE=8 MAXLENGTH=6 VALUE="<% $svc_acct->$xid() %>">
       </TD>
@@ -195,13 +218,13 @@ Service # <% $svcnum ? "<B>$svcnum</B>" : " (NEW)" %><BR>
 %     && ! $svc_acct->finger ) { 
 %
 
-
   <INPUT TYPE="hidden" NAME="finger" VALUE="">
 % } else { 
 
 
-  <TR>
-    <TD ALIGN="right">Real Name</TD>
+<% include('/elements/tr-td-label.html',
+     'label'    => $part_svc->part_svc_column('finger')->columnlabel || mt('Real Name'),
+     'required' => $part_svc->part_svc_column('finger')->required ) %>
     <TD>
       <INPUT TYPE="text" NAME="finger" VALUE="<% $svc_acct->finger %>">
     </TD>
@@ -218,8 +241,9 @@ Service # <% $svcnum ? "<B>$svcnum</B>" : " (NEW)" %><BR>
 % } else {
 
 
-  <TR>
-    <TD ALIGN="right">Home directory</TD>
+<% include('/elements/tr-td-label.html',
+     'label'    => $part_svc->part_svc_column('dir')->columnlabel || mt('Home directory'),
+     'required' => $part_svc->part_svc_column('dir')->required ) %>
     <TD><INPUT TYPE="text" NAME="dir" VALUE="<% $svc_acct->dir %>"></TD>
   </TR>
 % } 
@@ -231,13 +255,13 @@ Service # <% $svcnum ? "<B>$svcnum</B>" : " (NEW)" %><BR>
 %   ) {
 %
 
-
   <INPUT TYPE="hidden" NAME="shell" VALUE="<% $shell %>">
 % } else { 
 
 
-  <TR>
-    <TD ALIGN="right">Shell</TD>
+<% include('/elements/tr-td-label.html',
+     'label'    => $part_svc->part_svc_column('shell')->columnlabel || mt('Shell'),
+     'required' => $part_svc->part_svc_column('shell')->required ) %>
     <TD>
       <SELECT NAME="shell" SIZE=1>
 %
@@ -245,7 +269,6 @@ Service # <% $svcnum ? "<B>$svcnum</B>" : " (NEW)" %><BR>
 %           foreach $etc_shell (@shells) {
 %        
 
-
           <OPTION<% $etc_shell eq $shell ? ' SELECTED' : '' %>><% $etc_shell %>
 % } 
 
@@ -255,37 +278,53 @@ Service # <% $svcnum ? "<B>$svcnum</B>" : " (NEW)" %><BR>
   </TR>
 % } 
 
-<% include('svc_acct/communigate.html',
+<& svc_acct/communigate.html,
              'svc_acct'    => $svc_acct,
              'part_svc'    => $part_svc,
              'communigate' => $communigate,
-          )
-%>
-
-% if ( $part_svc->part_svc_column('slipip')->columnflag =~ /^[FA]$/ ) { 
-  <INPUT TYPE="hidden" NAME="slipip" VALUE="<% $svc_acct->slipip %>">
-% } else { 
-  <TR>
-    <TD ALIGN="right">IP</TD>
-    <TD><INPUT TYPE="text" NAME="slipip" VALUE="<% $svc_acct->slipip %>"></TD>
-  </TR>
-% } 
+&>
+
+% if ( $conf->exists('svc_acct-ip_addr') ) {
+%   # router/block selection UI
+%   # (should we show this if slipip is fixed?)
+<& /elements/tr-select-router_block_ip.html, 
+  'object' => $svc_acct,
+  'ip_field' => 'slipip',
+  'required' => $part_svc->part_svc_column('routernum')->required,
+  'label'    => $part_svc->part_svc_column('routernum')->columnlabel,
+  'ip_addr_required' => $part_svc->part_svc_column('slipip')->required,
+  'ip_addr_label' => $part_svc->part_svc_column('slipip')->columnlabel,
+&>
+% } else {
+%   # don't expose these to the user--they're only useful in the other case
+  <INPUT TYPE="hidden" NAME="routernum" VALUE="<% $svc_acct->routernum %>">
+  <INPUT TYPE="hidden" NAME="blocknum"  VALUE="<% $svc_acct->blocknum  %>">
+%   if ( $part_svc->part_svc_column('slipip')->columnflag =~ /^[FA]$/ ) { 
+    <INPUT TYPE="hidden" NAME="slipip" VALUE="<% $svc_acct->slipip %>">
+%   } else { 
+<% include('/elements/tr-td-label.html',
+     'label'    => $part_svc->part_svc_column('slipip')->columnlabel || mt('IP'),
+     'required' => $part_svc->part_svc_column('slipip')->required ) %>
+      <TD><INPUT TYPE="text" NAME="slipip" VALUE="<% $svc_acct->slipip %>"></TD>
+    </TR>
+%   }
+% }
 
-% my %label = ( seconds => 'Time',
-%               upbytes => 'Upload bytes',
-%               downbytes => 'Download bytes',
-%               totalbytes => 'Total bytes',
-%             );
+% tie my %label, 'Tie::IxHash', seconds    => 'Time',
+%                               upbytes    => 'Upload bytes',
+%                               downbytes  => 'Download bytes',
+%                               totalbytes => 'Total bytes',
+% ;
 % foreach my $uf (keys %label) {
 %   my $tf = $uf . "_threshold";
 %   if ( $curuser->access_right('Edit usage') ) { 
   <TR>
-    <TD ALIGN="right"><% $label{$uf} %> remaining</TD>
-    <TD><INPUT TYPE="text" NAME="<% $uf %>" VALUE="<% $svc_acct->$uf %>">(blank disables)</TD>
+    <TD ALIGN="right"><% mt("[_1] remaining",$label{$uf}) |h %> </TD>
+    <TD><INPUT TYPE="text" NAME="<% $uf %>" VALUE="<% $svc_acct->$uf %>">(<% mt('blank disables') |h %>)</TD>
   </TR>
   <TR>
-    <TD ALIGN="right"><% $label{$uf} %> threshold</TD>
-    <TD><INPUT TYPE="text" NAME="<% $tf %>" VALUE="<% $svc_acct->$tf %>">(blank disables)</TD>
+    <TD ALIGN="right"><% mt("[_1] threshold",$label{$uf}) |h %> </TD>
+    <TD><INPUT TYPE="text" NAME="<% $tf %>" VALUE="<% $svc_acct->$tf %>">(<% mt('blank disables') |h %>)</TD>
   </TR>
 %   }else{
       <INPUT TYPE="hidden" NAME="<% $uf %>" VALUE="<% $svc_acct->$uf %>">
@@ -299,11 +338,9 @@ Service # <% $svcnum ? "<B>$svcnum</B>" : " (NEW)" %><BR>
 %
 % if ( $part_svc->part_svc_column($r)->columnflag =~ /^[FA]$/ ) { 
 
-
     <INPUT TYPE="hidden" NAME="<% $r %>" VALUE="<% $svc_acct->getfield($r) %>">
 % } else { 
 
-
     <TR>
       <TD ALIGN="right"><% $FS::raddb::attrib{$a} %></TD>
       <TD><INPUT TYPE="text" NAME="<% $r %>" VALUE="<% $svc_acct->getfield($r) %>"></TD>
@@ -312,37 +349,71 @@ Service # <% $svcnum ? "<B>$svcnum</B>" : " (NEW)" %><BR>
 % } 
 
 
-
-<TR>
-  <TD ALIGN="right">RADIUS groups</TD>
-% if ( $part_svc->part_svc_column('usergroup')->columnflag eq 'F' ) { 
-
-
-    <TD BGCOLOR="#eeeeee"><% join('<BR>', @groups) %></TD>
+<% include('/elements/tr-td-label.html',
+     'label'    => $part_svc->part_svc_column('usergroup')->columnlabel || mt('RADIUS groups'),
+     'required' => $part_svc->part_svc_column('usergroup')->required ) %>
+% if ( $part_svc_usergroup->columnflag eq 'F' ) { 
+    <TD BGCOLOR="#eeeeee"><% join('<BR>', @groupnames) %></TD>
 % } else { 
-
-
-    <TD><% FS::svc_acct::radius_usergroup_selector( \@groups ) %></TD>
+%   my $radius_group_selected = '';
+%   if ( $svc_acct->svcnum ) {
+%      $radius_group_selected = join(',',$svc_acct->radius_groups('groupnum'));
+%   }
+%   elsif ( !$svc_acct->svcnum && $part_svc_usergroup->columnflag eq 'D' ) {
+%       $radius_group_selected = $part_svc_usergroup->columnvalue;
+%   }
+    <TD><& /elements/select-radius_group.html, 
+                curr_value => $radius_group_selected,
+                element_name => 'radius_usergroup',
+                multiple => 1,
+        &>
+    </TD>
 % } 
 
-
 </TR>
+
+% if ( $part_svc->has_router ) {
+<& /elements/hidden.html,
+    field => 'router_routernum',
+    curr_value => $svc_acct->router_routernum
+&>
+<& /elements/tr-input-text.html,
+    label => 'Attached router name',
+    field => 'router_routername',
+    size  => 32,
+    curr_value => $svc_acct->router_routername
+&>
+<& /elements/tr-select-table.html,
+    label         => 'Attached address block',
+    field         => 'router_blocknum',
+    table         => 'addr_block',
+    hashref       => { 'routernum' => '0' },
+    extra_sql     => ($svc_acct->router_routernum ?
+                        ' OR routernum = '.$svc_acct->router_routernum : ''),
+    agent_virt    => 1,
+    agent_null    => 1,
+    name_col      => 'cidr',
+    order_by      => 'ORDER BY ip_gateway, ip_netmask',
+    empty_label   => '(none)',
+    disable_empty => 0,
+    curr_value    => $svc_acct->router_blocknum
+&>
+% }
+
 % foreach my $field ($svc_acct->virtual_fields) { 
 % # If the flag is X, it won't even show up in $svc_acct->virtual_fields. 
 % if ( $part_svc->part_svc_column($field)->columnflag ne 'F' ) { 
 
-
     <% $svc_acct->pvf($field)->widget('HTML', 'edit', $svc_acct->getfield($field)) %>
 % } 
 % } 
-
   
 </TABLE>
 <BR>
 
 % if ( $captcha_url ) {
 <IMG SRC="<% $captcha_url %>"><BR>
-Enter the word shown above: <INPUT TYPE="text" NAME="captcha_response"><BR>
+<% mt('Enter the word shown above:') |h %> <INPUT TYPE="text" NAME="captcha_response"><BR>
 <BR>
 % }
 
@@ -350,7 +421,7 @@ Enter the word shown above: <INPUT TYPE="text" NAME="captcha_response"><BR>
 
 </FORM>
 
-<% include('/elements/footer.html') %>
+<& /elements/footer.html &>
 
 <%init>
 
@@ -451,17 +522,21 @@ unless ( $svcnum || $cgi->param('error') ) { #adding
 
 }
 
+my $part_svc_usergroup = $part_svc->part_svc_column('usergroup');
 #fixed radius groups always override & display
-if ( $part_svc->part_svc_column('usergroup')->columnflag eq 'F' ) {
-  @groups = split(',', $part_svc->part_svc_column('usergroup')->columnvalue);
+my @groupnames; # only used for display of Fixed RADIUS groups
+if ( $part_svc_usergroup->columnflag eq 'F' ) {
+  @groups = split(',',$part_svc_usergroup->columnvalue);
+  @groupnames = map { $_->long_description } 
+                    qsearch({ 'table'         => 'radius_group',
+                           'extra_sql'     => "where groupnum in (".$part_svc_usergroup->columnvalue.")",
+                        }) if length($part_svc_usergroup->columnvalue);
 }
 
 my $action = $svcnum ? 'Edit' : 'Add';
 
 my $svc = $part_svc->getfield('svc');
 
-my $otaker = getotaker;
-
 my $username = $svc_acct->username;
 
 my $password = '';
@@ -482,7 +557,7 @@ my $ulen =
   : dbdef->table('svc_acct')->column('username')->length;
 my $ulen2 = $ulen+2;
 
-my $pmax = max($conf->config('passwordmax') || 13);
+my $pmax = max($conf->config('passwordmax') || 12);
 my $pmax2 = $pmax+2;
 
 my $p1 = popurl(1);
@@ -494,7 +569,32 @@ sub max {
 my $captcha_url;
 my ($export_google) = $part_svc->part_export('acct_google');
 if ( $export_google ) {
-  $captcha_url = $export_google->captcha_url || '';
+  my $error = $export_google->auth_error;
+  if ( $error ) {
+    if ( $error->{'captcha_url'} ) {
+      $captcha_url = $error->{'captcha_url'};
+    }
+    else {
+      $cgi->param('error', $error->{'message'});
+    }
+  } #if $error
+}
+
+if ( $part_svc->has_router ) { # duplicates the one in elements/svc_Common
+  if ( $svcnum ) {
+    my $router = qsearchs('router', {svcnum => $svc_acct->svcnum});
+    if ( $router ) {
+      $svc_acct->set("router_$_", $router->get($_))
+        foreach ('routername', 'routernum');
+      my ($block) = $router->addr_block;
+      $svc_acct->set('router_blocknum', $block->blocknum) if ( $block );
+    }
+  }
+  foreach (qw(router_routername router_routernum router_blocknum)) {
+    if ( $cgi->param($_) =~ /^(\w+)$/ ) {
+      $svc_acct->set($_, $1);
+    }
+  }
 }
 
 </%init>