first part of ACL and re-skinning work and some other small stuff
[freeside.git] / httemplate / edit / cust_main.cgi
index 2911fc1..bb2a861 100755 (executable)
@@ -35,6 +35,7 @@ if ( $cgi->param('error') ) {
   $popnum = $cgi->param('popnum');
   @invoicing_list = split( /\s*,\s*/, $cgi->param('invoicing_list') );
   $same = $cgi->param('same');
+  $cust_main->setfield('paid' => $cgi->param('paid')) if $cgi->param('paid');
 } elsif ( $cgi->keywords ) { #editing
   my( $query ) = $cgi->keywords;
   $query =~ /^(\d+)$/;
@@ -69,7 +70,11 @@ my $action = $custnum ? 'Edit' : 'Add';
 
 <!-- top -->
 
-<%= header("Customer $action", '', ' onUnload="myclose()"') %>
+<%= include('/elements/header.html',
+      "Customer $action",
+      '',
+      ' onUnload="myclose()"'
+) %>
 
 <% if ( $error ) { %>
 <FONT SIZE="+1" COLOR="#ff0000">Error: <%= $error %></FONT>
@@ -104,59 +109,65 @@ my $agentnum = $cust_main->agentnum || $agents[0]->agentnum; #default to first
   </SELECT>
 <% } %>
 
+<!-- referral (advertising source) -->
+
 <%
+my $refnum = $cust_main->refnum || $conf->config('referraldefault') || 0;
+if ( $custnum && ! $conf->exists('editreferrals') ) {
+%>
 
-# (referral and referring customer still need to be "template"ized)
+  <INPUT TYPE="hidden" NAME="refnum" VALUE="<%= $refnum %>">
 
-#referral
+<%
+ } else {
 
-my $refnum = $cust_main->refnum || $conf->config('referraldefault') || 0;
-if ( $custnum && ! $conf->exists('editreferrals') ) {
-  print qq!<INPUT TYPE="hidden" NAME="refnum" VALUE="$refnum">!;
-} else {
-  my(@referrals) = qsearch('part_referral',{});
-  if ( scalar(@referrals) == 0 ) {
-    eidiot "You have not created any advertising sources.  You must create at least one advertising source before adding a customer.  Go to ". popurl(2). "browse/part_referral.cgi and create one or more advertising sources.";
-  } elsif ( scalar(@referrals) == 1 ) {
-    $refnum ||= $referrals[0]->refnum;
-    print qq!<INPUT TYPE="hidden" NAME="refnum" VALUE="$refnum">!;
-  } else {
-    print qq!<BR><BR>${r}Advertising source <SELECT NAME="refnum" SIZE="1">!;
-    print "<OPTION> " unless $refnum;
-    my($referral);
-    foreach $referral (sort {
-      $a->refnum <=> $b->refnum;
-    } @referrals) {
-      print "<OPTION" . " SELECTED"x($referral->refnum==$refnum),
-      ">", $referral->refnum, ": ", $referral->referral;
-    }
-    print "</SELECT>";
-  }
-}
+   my(@referrals) = qsearch('part_referral',{});
+   if ( scalar(@referrals) == 0 ) {
+     eidiot "You have not created any advertising sources.  You must create at least one advertising source before adding a customer.  Go to ". popurl(2). "browse/part_referral.cgi and create one or more advertising sources.";
+   } elsif ( scalar(@referrals) == 1 ) {
+     $refnum ||= $referrals[0]->refnum;
+%>
+
+     <INPUT TYPE="hidden" NAME="refnum" VALUE="<%= $refnum %>">
+
+<% } else { %>
 
-#referring customer
+     <BR><BR><%=$r%>Advertising source 
+     <SELECT NAME="refnum" SIZE="1">
+       <%= $refnum ? '' : '<OPTION VALUE="">' %>
+       <% foreach my $referral (sort { $a->refnum <=> $b->refnum } @referrals) { %>
+         <OPTION VALUE="<%= $referral->refnum %>" <%= $referral->refnum == $refnum ? 'SELECTED' : '' %>><%= $referral->refnum %>: <%= $referral->referral %>
+       <% } %>
+     </SELECT>
+<% } %>
 
-#print qq!<BR><BR>Referring Customer: !;
+<% } %>
+
+<!-- referring customer -->
+
+<%
 my $referring_cust_main = '';
 if ( $cust_main->referral_custnum
      and $referring_cust_main =
            qsearchs('cust_main', { custnum => $cust_main->referral_custnum } )
 ) {
-  print '<BR><BR>Referring Customer: <A HREF="'. popurl(1). '/cust_main.cgi?'.
-        $cust_main->referral_custnum. '">'.
-        $cust_main->referral_custnum. ': '.
-        ( $referring_cust_main->company
-          || $referring_cust_main->last. ', '. $referring_cust_main->first ).
-        '</A><INPUT TYPE="hidden" NAME="referral_custnum" VALUE="'.
-        $cust_main->referral_custnum. '">';
-} elsif ( ! $conf->exists('disable_customer_referrals') ) {
-  print '<BR><BR>Referring customer number: <INPUT TYPE="text" NAME="referral_custnum" VALUE="">';
-} else {
-  print '<INPUT TYPE="hidden" NAME="referral_custnum" VALUE="">';
-}
-
 %>
 
+  <BR><BR>Referring Customer: 
+  <A HREF="<%= popurl(1) %>/cust_main.cgi?<%= $cust_main->referral_custnum %>"><%= $cust_main->referral_custnum %>: <%= $referring_cust_main->name %></A>
+  <INPUT TYPE="hidden" NAME="referral_custnum" VALUE="<%= $cust_main->referral_custnum %>">
+
+<% } elsif ( ! $conf->exists('disable_customer_referrals') ) { %>
+
+  <BR><BR>Referring customer number: 
+  <INPUT TYPE="text" NAME="referral_custnum" VALUE="">
+
+<% } else { %>
+
+  <INPUT TYPE="hidden" NAME="referral_custnum" VALUE="">
+
+<% } %>
+
 <!-- contact info -->
 
 <BR><BR>
@@ -173,11 +184,17 @@ function bill_changed(what) {
 <% for (qw( last first company address1 address2 city zip daytime night fax )) { %>
     what.form.ship_<%=$_%>.value = what.form.<%=$_%>.value;
 <% } %>
+
     what.form.ship_country.selectedIndex = what.form.country.selectedIndex;
-    ship_country_changed(what.form.ship_country);
-    what.form.ship_state.selectedIndex = what.form.state.selectedIndex;
-    ship_state_changed(what.form.ship_state);
-    what.form.ship_county.selectedIndex = what.form.county.selectedIndex;
+    function fix_ship_state() {
+      what.form.ship_state.selectedIndex = what.form.state.selectedIndex;
+    }
+    ship_country_changed(what.form.ship_country, fix_ship_state );
+
+    function fix_ship_county() {
+      what.form.ship_county.selectedIndex = what.form.county.selectedIndex;
+    }
+    ship_state_changed(what.form.ship_state, fix_ship_county );
   }
 }
 function samechanged(what) {
@@ -221,7 +238,10 @@ Service address
 
 <!-- billing info -->
 
-<%= include('cust_main/billing.html', $cust_main ) %>
+<%= include( 'cust_main/billing.html', $cust_main,
+               'invoicing_list' => \@invoicing_list,
+           )
+%>
 
 <SCRIPT>
 function bottomfixup(what) {
@@ -247,14 +267,16 @@ function bottomfixup(what) {
   var layervars = new Array(
     'payauto',
     'payinfo', 'payinfo1', 'payinfo2',
-    'exp_month', 'exp_year', 'paycvv',
+    'payname', 'exp_month', 'exp_year', 'paycvv',
     'paystart_month', 'paystart_year', 'payissue',
-    'payip'
+    'payip',
+    'paid'
   );
 
   var billing_bottomvars = new Array(
     'tax',
-    'invoicing_list', 'invoicing_list_POST', 'invoicing_list_FAX'
+    'invoicing_list', 'invoicing_list_POST', 'invoicing_list_FAX',
+    'spool_cdr'
   );
 
   for ( f=0; f < topvars.length; f++ ) {
@@ -300,7 +322,7 @@ function copyelement(from, to) {
       to.value = from.value;
     }
   }
-  //alert(from + ": " + to.name + " => " + to.value);
+  //alert(from + " (" + from.type + "): " + to.name + " => " + to.value);
 }
 
 </SCRIPT>
@@ -325,12 +347,14 @@ function copyelement(from, to) {
 
      'payauto',
      'payinfo', 'payinfo1', 'payinfo2',
-     'exp_month', 'exp_year', 'paycvv',
+     'payname', 'exp_month', 'exp_year', 'paycvv',
      'paystart_month', 'paystart_year', 'payissue',
      'payip',
+     'paid',
      
      'tax',
-     'invoicing_list', 'invoicing_list_POST', 'invoicing_list_FAX'
+     'invoicing_list', 'invoicing_list_POST', 'invoicing_list_FAX',
+     'spool_cdr'
    ) {
 %>
   <INPUT TYPE="hidden" NAME="<%= $hidden %>" VALUE="">
@@ -373,49 +397,66 @@ unless ( $custnum ) {
 
   if ( @part_pkg ) {
 
-#    print "<BR><BR>First package", &itable("#cccccc", "0 ALIGN=LEFT"),
-#apiabuse & undesirable wrapping
-    print "<BR>First package", &ntable("#cccccc"),
-          qq!<TR><TD COLSPAN=2><SELECT NAME="pkgpart_svcpart">!;
+    #    print "<BR><BR>First package", &itable("#cccccc", "0 ALIGN=LEFT"),
+    #apiabuse & undesirable wrapping
+
+    %>
+    <BR>First package
+    <%= ntable("#cccccc") %>
+    
+      <TR>
+        <TD COLSPAN=2>
+          <SELECT NAME="pkgpart_svcpart">
+            <OPTION VALUE="">(none)
+    
+            <% foreach my $part_pkg ( @part_pkg ) { %>
+    
+              <OPTION VALUE="<%= $part_pkg->pkgpart. "_". $part_pkg->svcpart('svc_acct') %>"<%= ( $saved_pkgpart && $part_pkg->pkgpart == $saved_pkgpart ) ? ' SELECTED' : '' %>><%= $part_pkg->pkg. " - ". $part_pkg->comment %>
+    
+            <% } %>
+          </SELECT>
+        </TD>
+      </TR>
+    
+      <% 
+        #false laziness: (mostly) copied from edit/svc_acct.cgi
+        #$ulen = $svc_acct->dbdef_table->column('username')->length;
+        my $ulen = dbdef->table('svc_acct')->column('username')->length;
+        my $ulen2 = $ulen+2;
+        my $passwordmax = $conf->config('passwordmax') || 8;
+        my $pmax2 = $passwordmax + 2;
+      %>
+    
+      <TR>
+        <TD ALIGN="right">Username</TD>
+        <TD>
+          <INPUT TYPE="text" NAME="username" VALUE="<%= $username %>" SIZE=<%= $ulen2 %> MAXLENGTH=<%= $ulen %>>
+        </TD>
+      </TR>
+    
+      <TR>
+        <TD ALIGN="right">Password</TD>
+        <TD>
+          <INPUT TYPE="text" NAME="_password" VALUE="<%= $password %>" SIZE=<%= $pmax2 %> MAXLENGTH=<%= $passwordmax %>>
+          (blank to generate)
+        </TD>
+      </TR>
+    
+      <TR>
+        <TD ALIGN="right">Access number</TD>
+        <TD><%= FS::svc_acct_pop::popselector($popnum) %></TD>
+      </TR>
+    </TABLE>
+    
+  <% } %>
 
-    print qq!<OPTION VALUE="">(none)!;
+<% } %>
 
-    foreach my $part_pkg ( @part_pkg ) {
-      print qq!<OPTION VALUE="!,
-#              $part_pkg->pkgpart. "_". $pkgpart{ $part_pkg->pkgpart }, '"';
-              $part_pkg->pkgpart. "_". $part_pkg->svcpart('svc_acct'), '"';
-      print " SELECTED" if $saved_pkgpart && ( $part_pkg->pkgpart == $saved_pkgpart );
-      print ">", $part_pkg->pkg, " - ", $part_pkg->comment;
-    }
-    print "</SELECT></TD></TR>";
-
-    #false laziness: (mostly) copied from edit/svc_acct.cgi
-    #$ulen = $svc_acct->dbdef_table->column('username')->length;
-    my $ulen = dbdef->table('svc_acct')->column('username')->length;
-    my $ulen2 = $ulen+2;
-    my $passwordmax = $conf->config('passwordmax') || 8;
-    my $pmax2 = $passwordmax + 2;
-    print <<END;
-<TR><TD ALIGN="right">Username</TD>
-<TD><INPUT TYPE="text" NAME="username" VALUE="$username" SIZE=$ulen2 MAXLENGTH=$ulen></TD></TR>
-<TR><TD ALIGN="right">Password</TD>
-<TD><INPUT TYPE="text" NAME="_password" VALUE="$password" SIZE=$pmax2 MAXLENGTH=$passwordmax>
-(blank to generate)</TD></TR>
-END
-
-    print '<TR><TD ALIGN="right">Access number</TD><TD>'
-          .
-          &FS::svc_acct_pop::popselector($popnum).
-          '</TD></TR></TABLE>'
-          ;
-  }
-}
+<INPUT TYPE="hidden" NAME="otaker" VALUE="<%= $cust_main->otaker %>">
+<BR>
+<INPUT TYPE="submit" NAME="submit" VALUE="<%= $custnum ?  "Apply Changes" : "Add Customer" %>">
+<BR>
+</FORM>
 
-my $otaker = $cust_main->otaker;
-print qq!<INPUT TYPE="hidden" NAME="otaker" VALUE="$otaker">!,
-      qq!<BR><INPUT TYPE="submit" NAME="submit" VALUE="!,
-      $custnum ?  "Apply Changes" : "Add Customer", qq!"><BR>!,
-      "</FORM></DIV></BODY></HTML>",
-;
+<%= include('/elements/footer.html') %>
 
-%>