[freeside-commits] freeside/httemplate/misc/process batch-cust_pay.cgi, 1.2, 1.3 catchall.cgi, 1.4, 1.5 cdr-import.html, 1.2, 1.3 cust_main-import.cgi, 1.4, 1.5 cust_main-import_charges.cgi, 1.3, 1.4 delete-customer.cgi, 1.4, 1.5 expire_pkg.cgi, 1.1, 1.2 inventory_item-import.html, 1.2, 1.3 link.cgi, 1.14, 1.15 meta-import.cgi, 1.6, 1.7 payment.cgi, 1.2, 1.3

Ivan,,, ivan at wavetail.420.am
Wed Aug 23 15:25:40 PDT 2006


Update of /home/cvs/cvsroot/freeside/httemplate/misc/process
In directory wavetail:/tmp/cvs-serv18630/httemplate/misc/process

Modified Files:
	batch-cust_pay.cgi catchall.cgi cdr-import.html 
	cust_main-import.cgi cust_main-import_charges.cgi 
	delete-customer.cgi expire_pkg.cgi inventory_item-import.html 
	link.cgi meta-import.cgi payment.cgi 
Log Message:
Will things ever be the same again?
It's the final masonize


Index: catchall.cgi
===================================================================
RCS file: /home/cvs/cvsroot/freeside/httemplate/misc/process/catchall.cgi,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- catchall.cgi	10 Feb 2002 13:21:31 -0000	1.4
+++ catchall.cgi	23 Aug 2006 22:25:38 -0000	1.5
@@ -1,33 +1,34 @@
-<%
-
-$FS::svc_domain::whois_hack=1;
-
-$cgi->param('svcnum') =~ /^(\d*)$/ or die "Illegal svcnum!";
-my $svcnum =$1;
-
-my $old = qsearchs('svc_domain',{'svcnum'=>$svcnum}) if $svcnum;
-
-my $new = new FS::svc_domain ( {
-  map {
-    ($_, scalar($cgi->param($_)));
-  } ( fields('svc_domain'), qw( pkgnum svcpart ) )
-} );
-
-$new->setfield('action' => 'M');
-
-my $error;
-if ( $svcnum ) {
-  $error = $new->replace($old);
-} else {
-  $error = $new->insert;
-  $svcnum = $new->getfield('svcnum');
-} 
-
-if ($error) {
-  $cgi->param('error', $error);
-  print $cgi->redirect(popurl(2). "catchall.cgi?". $cgi->query_string );
-} else {
-  print $cgi->redirect(popurl(3). "view/svc_domain.cgi?$svcnum");
-}
+%
+%
+%$FS::svc_domain::whois_hack=1;
+%
+%$cgi->param('svcnum') =~ /^(\d*)$/ or die "Illegal svcnum!";
+%my $svcnum =$1;
+%
+%my $old = qsearchs('svc_domain',{'svcnum'=>$svcnum}) if $svcnum;
+%
+%my $new = new FS::svc_domain ( {
+%  map {
+%    ($_, scalar($cgi->param($_)));
+%  } ( fields('svc_domain'), qw( pkgnum svcpart ) )
+%} );
+%
+%$new->setfield('action' => 'M');
+%
+%my $error;
+%if ( $svcnum ) {
+%  $error = $new->replace($old);
+%} else {
+%  $error = $new->insert;
+%  $svcnum = $new->getfield('svcnum');
+%} 
+%
+%if ($error) {
+%  $cgi->param('error', $error);
+%  print $cgi->redirect(popurl(2). "catchall.cgi?". $cgi->query_string );
+%} else {
+%  print $cgi->redirect(popurl(3). "view/svc_domain.cgi?$svcnum");
+%}
+%
+%
 
-%>

Index: cust_main-import_charges.cgi
===================================================================
RCS file: /home/cvs/cvsroot/freeside/httemplate/misc/process/cust_main-import_charges.cgi,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- cust_main-import_charges.cgi	25 Mar 2006 02:23:26 -0000	1.3
+++ cust_main-import_charges.cgi	23 Aug 2006 22:25:38 -0000	1.4
@@ -1,26 +1,30 @@
-<%
-
-  my $fh = $cgi->upload('csvfile');
-  #warn $cgi;
-  #warn $fh;
-
-  my $error = defined($fh)
-    ? FS::cust_main::batch_charge( {
-        filehandle => $fh,
-        'fields'    => [qw( custnum amount pkg )],
-      } )
-    : 'No file';
+%
+%
+%  my $fh = $cgi->upload('csvfile');
+%  #warn $cgi;
+%  #warn $fh;
+%
+%  my $error = defined($fh)
+%    ? FS::cust_main::batch_charge( {
+%        filehandle => $fh,
+%        'fields'    => [qw( custnum amount pkg )],
+%      } )
+%    : 'No file';
+%
+%  if ( $error ) {
+%    
 
-  if ( $error ) {
-    %>
     <!-- mason kludge -->
-    <%
-    eidiot($error);
-#    $cgi->param('error', $error);
-#    print $cgi->redirect( "${p}cust_main-import_charges.cgi
-  } else {
-    %>
+%
+%    eidiot($error);
+%#    $cgi->param('error', $error);
+%#    print $cgi->redirect( "${p}cust_main-import_charges.cgi
+%  } else {
+%    
+
     <!-- mason kludge -->
-    <%= include("/elements/header.html",'Import successful') %> <%
-  }
-%>
+    <% include("/elements/header.html",'Import successful') %> 
+%
+%  }
+%
+

Index: meta-import.cgi
===================================================================
RCS file: /home/cvs/cvsroot/freeside/httemplate/misc/process/meta-import.cgi,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -d -r1.6 -r1.7
--- meta-import.cgi	31 Jan 2006 04:26:54 -0000	1.6
+++ meta-import.cgi	23 Aug 2006 22:25:38 -0000	1.7
@@ -1,5 +1,5 @@
 <!-- mason kludge -->
-<%= include("/elements/header.html",'Map tables') %>
+<% include("/elements/header.html",'Map tables') %>
 
 <SCRIPT>
 var gSafeOnload = new Array();
@@ -22,157 +22,164 @@
 </SCRIPT>
 
 <FORM NAME="OneTrueForm" METHOD="POST" ACTION="meta-import.cgi">
+%
+%  #use DBIx::DBSchema;
+%  my $schema = new_native DBIx::DBSchema
+%                 map { $cgi->param($_) } qw( data_source username password );
+%  foreach my $field (qw( data_source username password )) { 
 
-<%
-  #use DBIx::DBSchema;
-  my $schema = new_native DBIx::DBSchema
-                 map { $cgi->param($_) } qw( data_source username password );
-  foreach my $field (qw( data_source username password )) { %>
-    <INPUT TYPE="hidden" NAME=<%= $field %> VALUE="<%= $cgi->param($field) %>">
-  <% }
-
-  my %schema;
-  use Tie::DxHash;
-  tie %schema, 'Tie::DxHash';
-  if ( $cgi->param('schema') ) {
-    my $schema_string = $cgi->param('schema');
-    %> <INPUT TYPE="hidden" NAME="schema" VALUE="<%=$schema_string%>"> <%
-    %schema = map { /^\s*(\w+)\s*=>\s*(\w+)\s*$/
-                      or die "guru meditation #420: $_";
-                    ( $1 => $2 );
-                  }
-              split( /\n/, $schema_string );
-  }
+    <INPUT TYPE="hidden" NAME=<% $field %> VALUE="<% $cgi->param($field) %>">
+% }
+%
+%  my %schema;
+%  use Tie::DxHash;
+%  tie %schema, 'Tie::DxHash';
+%  if ( $cgi->param('schema') ) {
+%    my $schema_string = $cgi->param('schema');
+%    
+ <INPUT TYPE="hidden" NAME="schema" VALUE="<%$schema_string%>"> 
+%
+%    %schema = map { /^\s*(\w+)\s*=>\s*(\w+)\s*$/
+%                      or die "guru meditation #420: $_";
+%                    ( $1 => $2 );
+%                  }
+%              split( /\n/, $schema_string );
+%  }
+%
+%  #first page
+%  unless ( $cgi->param('magic') ) { 
 
-  #first page
-  unless ( $cgi->param('magic') ) { %>
 
     <INPUT TYPE="hidden" NAME="magic" VALUE="process">
-    <%= hashmaker('schema', [ $schema->tables ],
+    <% hashmaker('schema', [ $schema->tables ],
                             [ grep !/^h_/, dbdef->tables ],  ) %>
     <br><INPUT TYPE="submit" VALUE="done">
-    <%
+%
+%
+%  #second page
+%  } elsif ( $cgi->param('magic') eq 'process' ) { 
 
-  #second page
-  } elsif ( $cgi->param('magic') eq 'process' ) { %>
 
     <INPUT TYPE="hidden" NAME="magic" VALUE="process2">
-    <%
-
-    my %unique;
-    foreach my $table ( keys %schema ) {
-
-      my @from_columns = $schema->table($table)->columns;
-      my @fs_columns = dbdef->table($schema{$table})->columns;
+%
+%
+%    my %unique;
+%    foreach my $table ( keys %schema ) {
+%
+%      my @from_columns = $schema->table($table)->columns;
+%      my @fs_columns = dbdef->table($schema{$table})->columns;
+%
+%      
 
-      %>
-      <%= hashmaker( $table.'__'.$unique{$table}++,
+      <% hashmaker( $table.'__'.$unique{$table}++,
                      \@from_columns => \@fs_columns,
                      $table         =>  $schema{$table}, ) %>
       <br><hr><br>
-      <%
-
-    }
+%
+%
+%    }
+%
+%    
 
-    %>
     <br><INPUT TYPE="submit" VALUE="done">
-    <%
-
-  #third (results)
-  } elsif ( $cgi->param('magic') eq 'process2' ) {
-
-    print "<pre>\n";
-
-    my %unique;
-    foreach my $table ( keys %schema ) {
-      ( my $spaces = $table ) =~ s/./ /g;
-      print "'$table' => { 'table' => '$schema{$table}',\n".
-            #(length($table) x ' '). "         'map'   => {\n";
-            "$spaces        'map'   => {\n";
-      my %map = map { /^\s*(\w+)\s*=>\s*(\w+)\s*$/
-                         or die "guru meditation #420: $_";
-                       ( $1 => $2 );
-                     }
-                 split( /\n/, $cgi->param($table.'__'.$unique{$table}++) );
-      foreach ( keys %map ) {
-        print "$spaces                     '$_' => '$map{$_}',\n";
-      }
-      print "$spaces                   },\n";
-      print "$spaces      },\n";
-
-    }
-    print "\n</pre>";
-
-  } else {
-    warn "unrecognized magic: ". $cgi->param('magic');
-  }
+%
+%
+%  #third (results)
+%  } elsif ( $cgi->param('magic') eq 'process2' ) {
+%
+%    print "<pre>\n";
+%
+%    my %unique;
+%    foreach my $table ( keys %schema ) {
+%      ( my $spaces = $table ) =~ s/./ /g;
+%      print "'$table' => { 'table' => '$schema{$table}',\n".
+%            #(length($table) x ' '). "         'map'   => {\n";
+%            "$spaces        'map'   => {\n";
+%      my %map = map { /^\s*(\w+)\s*=>\s*(\w+)\s*$/
+%                         or die "guru meditation #420: $_";
+%                       ( $1 => $2 );
+%                     }
+%                 split( /\n/, $cgi->param($table.'__'.$unique{$table}++) );
+%      foreach ( keys %map ) {
+%        print "$spaces                     '$_' => '$map{$_}',\n";
+%      }
+%      print "$spaces                   },\n";
+%      print "$spaces      },\n";
+%
+%    }
+%    print "\n</pre>";
+%
+%  } else {
+%    warn "unrecognized magic: ". $cgi->param('magic');
+%  }
+%
+%  
 
-  %>
 </FORM>
 </BODY>
 </HTML>
+%
+%  #hashmaker widget
+%  sub hashmaker {
+%    my($name, $from, $to, $labelfrom, $labelto) = @_;
+%    my $fromsize = scalar(@$from);
+%    my $tosize = scalar(@$to);
+%    "<TABLE><TR><TH>$labelfrom</TH><TH>$labelto</TH></TR><TR><TD>".
+%        qq!<SELECT NAME="${name}_from" SIZE=$fromsize>\n!.
+%        join("\n", map { qq!<OPTION VALUE="$_">$_</OPTION>! } sort { $a cmp $b } @$from ).
+%        "</SELECT>\n<BR>".
+%      qq!<INPUT TYPE="button" VALUE="refill" onClick="repack_${name}_from()">!.
+%      '</TD><TD>'.
+%        qq!<SELECT NAME="${name}_to" SIZE=$tosize>\n!.
+%        join("\n", map { qq!<OPTION VALUE="$_">$_</OPTION>! } sort { $a cmp $b } @$to ).
+%        "</SELECT>\n<BR>".
+%      qq!<INPUT TYPE="button" VALUE="refill" onClick="repack_${name}_to()">!.
+%      '</TD></TR>'.
+%      '<TR><TD COLSPAN=2>'.
+%        qq!<INPUT TYPE="button" VALUE="map" onClick="toke_$name(this.form)">!.
+%      '</TD></TR><TR><TD COLSPAN=2>'.
+%      qq!<TEXTAREA NAME="$name" COLS=80 ROWS=8></TEXTAREA>!.
+%      '</TD></TR></TABLE>'.
+%      "<script>
+%            function toke_$name() {
+%              fromObject = document.OneTrueForm.${name}_from;
+%              for (var i=fromObject.options.length-1;i>-1;i--) {
+%                if (fromObject.options[i].selected)
+%                  fromname = deleteOption_$name(fromObject,i);
+%              }
+%              toObject = document.OneTrueForm.${name}_to;
+%              for (var i=toObject.options.length-1;i>-1;i--) {
+%                if (toObject.options[i].selected)
+%                  toname = deleteOption_$name(toObject,i);
+%              }
+%              document.OneTrueForm.$name.value = document.OneTrueForm.$name.value + fromname + ' => ' + toname + '\\n';
+%            }
+%            function deleteOption_$name(object,index) {
+%              value = object.options[index].value;
+%              object.options[index] = null;
+%              return value;
+%            }
+%            function repack_${name}_from() {
+%              var object = document.OneTrueForm.${name}_from;
+%              object.options.length = 0;
+%              ". join("\n", 
+%                   map { "addOption_$name(object, '$_');\n" }
+%                       ( sort { $a cmp $b } @$from )           ). "
+%            }
+%            function repack_${name}_to() {
+%              var object = document.OneTrueForm.${name}_to;
+%              object.options.length = 0;
+%              ". join("\n", 
+%                   map { "addOption_$name(object, '$_');\n" }
+%                       ( sort { $a cmp $b } @$to )           ). "
+%            }
+%            function addOption_$name(object,value) {
+%              var length = object.length;
+%              object.options[length] = new Option(value, value, false, false);
+%            }
+%      </script>".
+%      '';
+%  }
+%
+%
 
-  <%
-  #hashmaker widget
-  sub hashmaker {
-    my($name, $from, $to, $labelfrom, $labelto) = @_;
-    my $fromsize = scalar(@$from);
-    my $tosize = scalar(@$to);
-    "<TABLE><TR><TH>$labelfrom</TH><TH>$labelto</TH></TR><TR><TD>".
-        qq!<SELECT NAME="${name}_from" SIZE=$fromsize>\n!.
-        join("\n", map { qq!<OPTION VALUE="$_">$_</OPTION>! } sort { $a cmp $b } @$from ).
-        "</SELECT>\n<BR>".
-      qq!<INPUT TYPE="button" VALUE="refill" onClick="repack_${name}_from()">!.
-      '</TD><TD>'.
-        qq!<SELECT NAME="${name}_to" SIZE=$tosize>\n!.
-        join("\n", map { qq!<OPTION VALUE="$_">$_</OPTION>! } sort { $a cmp $b } @$to ).
-        "</SELECT>\n<BR>".
-      qq!<INPUT TYPE="button" VALUE="refill" onClick="repack_${name}_to()">!.
-      '</TD></TR>'.
-      '<TR><TD COLSPAN=2>'.
-        qq!<INPUT TYPE="button" VALUE="map" onClick="toke_$name(this.form)">!.
-      '</TD></TR><TR><TD COLSPAN=2>'.
-      qq!<TEXTAREA NAME="$name" COLS=80 ROWS=8></TEXTAREA>!.
-      '</TD></TR></TABLE>'.
-      "<script>
-            function toke_$name() {
-              fromObject = document.OneTrueForm.${name}_from;
-              for (var i=fromObject.options.length-1;i>-1;i--) {
-                if (fromObject.options[i].selected)
-                  fromname = deleteOption_$name(fromObject,i);
-              }
-              toObject = document.OneTrueForm.${name}_to;
-              for (var i=toObject.options.length-1;i>-1;i--) {
-                if (toObject.options[i].selected)
-                  toname = deleteOption_$name(toObject,i);
-              }
-              document.OneTrueForm.$name.value = document.OneTrueForm.$name.value + fromname + ' => ' + toname + '\\n';
-            }
-            function deleteOption_$name(object,index) {
-              value = object.options[index].value;
-              object.options[index] = null;
-              return value;
-            }
-            function repack_${name}_from() {
-              var object = document.OneTrueForm.${name}_from;
-              object.options.length = 0;
-              ". join("\n", 
-                   map { "addOption_$name(object, '$_');\n" }
-                       ( sort { $a cmp $b } @$from )           ). "
-            }
-            function repack_${name}_to() {
-              var object = document.OneTrueForm.${name}_to;
-              object.options.length = 0;
-              ". join("\n", 
-                   map { "addOption_$name(object, '$_');\n" }
-                       ( sort { $a cmp $b } @$to )           ). "
-            }
-            function addOption_$name(object,value) {
-              var length = object.length;
-              object.options[length] = new Option(value, value, false, false);
-            }
-      </script>".
-      '';
-  }
-
-%>

Index: payment.cgi
===================================================================
RCS file: /home/cvs/cvsroot/freeside/httemplate/misc/process/payment.cgi,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- payment.cgi	24 Mar 2006 19:49:53 -0000	1.2
+++ payment.cgi	23 Aug 2006 22:25:38 -0000	1.3
@@ -1,140 +1,141 @@
-<%
-
-#some false laziness w/MyAccount::process_payment
-
-$cgi->param('custnum') =~ /^(\d+)$/
-  or die "illegal custnum ". $cgi->param('custnum');
-my $custnum = $1;
-
-my $cust_main = qsearchs('cust_main', { 'custnum' => $custnum } );
-die "unknown custnum $custnum" unless $cust_main;
-
-$cgi->param('amount') =~ /^\s*(\d*(\.\d\d)?)\s*$/
-  or eidiot "illegal amount ". $cgi->param('amount');
-my $amount = $1;
-eidiot "amount <= 0" unless $amount > 0;
-
-$cgi->param('year') =~ /^(\d+)$/
-  or die "illegal year ". $cgi->param('year');
-my $year = $1;
-
-$cgi->param('month') =~ /^(\d+)$/
-  or die "illegal month ". $cgi->param('month');
-my $month = $1;
-
-$cgi->param('payby') =~ /^(CARD|CHEK)$/
-  or die "illegal payby ". $cgi->param('payby');
-my $payby = $1;
-my %payby2bop = (
-  'CARD' => 'CC',
-  'CHEK' => 'ECHECK',
-);
-my %payby2fields = (
-  'CARD' => [ qw( address1 address2 city state zip ) ],
-  'CHEK' => [ qw( ss ) ],
-);
-my %type = ( 'CARD' => 'credit card',
-             'CHEK' => 'electronic check (ACH)',
-           );
-
-$cgi->param('payname') =~ /^([\w \,\.\-\']+)$/
-  or eidiot gettext('illegal_name'). " payname: ". $cgi->param('payname');
-my $payname = $1;
-
-$cgi->param('paybatch') =~ /^([\w \!\@\#\$\%\&\(\)\-\+\;\:\'\"\,\.\?\/\=]*)$/
-  or eidiot gettext('illegal_text'). " paybatch: ". $cgi->param('paybatch');
-my $paybatch = $1;
-
-my $payinfo;
-my $paycvv = '';
-if ( $payby eq 'CHEK' ) {
-
-  $cgi->param('payinfo1') =~ /^(\d+)$/
-    or eidiot "illegal account number ". $cgi->param('payinfo1');
-  my $payinfo1 = $1;
-   $cgi->param('payinfo2') =~ /^(\d+)$/
-    or eidiot "illegal ABA/routing number ". $cgi->param('payinfo2');
-  my $payinfo2 = $1;
-  $payinfo = $payinfo1. '@'. $payinfo2;
-
-} elsif ( $payby eq 'CARD' ) {
-
-  $payinfo = $cgi->param('payinfo');
-  $payinfo =~ s/\D//g;
-  $payinfo =~ /^(\d{13,16})$/
-    or eidiot gettext('invalid_card'); # . ": ". $self->payinfo;
-  $payinfo = $1;
-  validate($payinfo)
-    or eidiot gettext('invalid_card'); # . ": ". $self->payinfo;
-  eidiot gettext('unknown_card_type')
-    if cardtype($payinfo) eq "Unknown";
-
-  if ( defined $cust_main->dbdef_table->column('paycvv') ) {
-    if ( length($cgi->param('paycvv') ) ) {
-      if ( cardtype($payinfo) eq 'American Express card' ) {
-        $cgi->param('paycvv') =~ /^(\d{4})$/
-          or eidiot "CVV2 (CID) for American Express cards is four digits.";
-        $paycvv = $1;
-      } else {
-        $cgi->param('paycvv') =~ /^(\d{3})$/
-          or eidiot "CVV2 (CVC2/CID) is three digits.";
-        $paycvv = $1;
-      }
-    }
-  }
-
-} else {
-  die "unknown payby $payby";
-}
-
-my $error = $cust_main->realtime_bop( $payby2bop{$payby}, $amount,
-  'quiet'    => 1,
-  'payinfo'  => $payinfo,
-  'paydate'  => "$year-$month-01",
-  'payname'  => $payname,
-  'paybatch' => $paybatch,
-  'paycvv'   => $paycvv,
-  map { $_ => $cgi->param($_) } @{$payby2fields{$payby}}
-);
-eidiot($error) if $error;
-
-$cust_main->apply_payments;
-
-if ( $cgi->param('save') ) {
-  my $new = new FS::cust_main { $cust_main->hash };
-  if ( $payby eq 'CARD' ) { 
-    $new->set( 'payby' => ( $cgi->param('auto') ? 'CARD' : 'DCRD' ) );
-  } elsif ( $payby eq 'CHEK' ) {
-    $new->set( 'payby' => ( $cgi->param('auto') ? 'CHEK' : 'DCHK' ) );
-  } else {
-    die "unknown payby $payby";
-  }
-  $new->set( 'payinfo' => $payinfo );
-  $new->set( 'paydate' => "$year-$month-01" );
-  $new->set( 'payname' => $payname );
-
-  #false laziness w/FS:;cust_main::realtime_bop - check both to make sure
-  # working correctly
-  my $conf = new FS::Conf;
-  if ( $payby eq 'CARD' &&
-       grep { $_ eq cardtype($payinfo) } $conf->config('cvv-save') ) {
-    $new->set( 'paycvv' => $paycvv );
-  } else {
-    $new->set( 'paycvv' => '');
-  }
-
-  $new->set( $_ => $cgi->param($_) ) foreach @{$payby2fields{$payby}};
-
-  my $error = $new->replace($cust_main);
-  eidiot "payment processed successfully, but error saving info: $error"
-    if $error;
-  $cust_main = $new;
-}
-
-#success!
+%
+%
+%#some false laziness w/MyAccount::process_payment
+%
+%$cgi->param('custnum') =~ /^(\d+)$/
+%  or die "illegal custnum ". $cgi->param('custnum');
+%my $custnum = $1;
+%
+%my $cust_main = qsearchs('cust_main', { 'custnum' => $custnum } );
+%die "unknown custnum $custnum" unless $cust_main;
+%
+%$cgi->param('amount') =~ /^\s*(\d*(\.\d\d)?)\s*$/
+%  or eidiot "illegal amount ". $cgi->param('amount');
+%my $amount = $1;
+%eidiot "amount <= 0" unless $amount > 0;
+%
+%$cgi->param('year') =~ /^(\d+)$/
+%  or die "illegal year ". $cgi->param('year');
+%my $year = $1;
+%
+%$cgi->param('month') =~ /^(\d+)$/
+%  or die "illegal month ". $cgi->param('month');
+%my $month = $1;
+%
+%$cgi->param('payby') =~ /^(CARD|CHEK)$/
+%  or die "illegal payby ". $cgi->param('payby');
+%my $payby = $1;
+%my %payby2bop = (
+%  'CARD' => 'CC',
+%  'CHEK' => 'ECHECK',
+%);
+%my %payby2fields = (
+%  'CARD' => [ qw( address1 address2 city state zip ) ],
+%  'CHEK' => [ qw( ss ) ],
+%);
+%my %type = ( 'CARD' => 'credit card',
+%             'CHEK' => 'electronic check (ACH)',
+%           );
+%
+%$cgi->param('payname') =~ /^([\w \,\.\-\']+)$/
+%  or eidiot gettext('illegal_name'). " payname: ". $cgi->param('payname');
+%my $payname = $1;
+%
+%$cgi->param('paybatch') =~ /^([\w \!\@\#\$\%\&\(\)\-\+\;\:\'\"\,\.\?\/\=]*)$/
+%  or eidiot gettext('illegal_text'). " paybatch: ". $cgi->param('paybatch');
+%my $paybatch = $1;
+%
+%my $payinfo;
+%my $paycvv = '';
+%if ( $payby eq 'CHEK' ) {
+%
+%  $cgi->param('payinfo1') =~ /^(\d+)$/
+%    or eidiot "illegal account number ". $cgi->param('payinfo1');
+%  my $payinfo1 = $1;
+%   $cgi->param('payinfo2') =~ /^(\d+)$/
+%    or eidiot "illegal ABA/routing number ". $cgi->param('payinfo2');
+%  my $payinfo2 = $1;
+%  $payinfo = $payinfo1. '@'. $payinfo2;
+%
+%} elsif ( $payby eq 'CARD' ) {
+%
+%  $payinfo = $cgi->param('payinfo');
+%  $payinfo =~ s/\D//g;
+%  $payinfo =~ /^(\d{13,16})$/
+%    or eidiot gettext('invalid_card'); # . ": ". $self->payinfo;
+%  $payinfo = $1;
+%  validate($payinfo)
+%    or eidiot gettext('invalid_card'); # . ": ". $self->payinfo;
+%  eidiot gettext('unknown_card_type')
+%    if cardtype($payinfo) eq "Unknown";
+%
+%  if ( defined $cust_main->dbdef_table->column('paycvv') ) {
+%    if ( length($cgi->param('paycvv') ) ) {
+%      if ( cardtype($payinfo) eq 'American Express card' ) {
+%        $cgi->param('paycvv') =~ /^(\d{4})$/
+%          or eidiot "CVV2 (CID) for American Express cards is four digits.";
+%        $paycvv = $1;
+%      } else {
+%        $cgi->param('paycvv') =~ /^(\d{3})$/
+%          or eidiot "CVV2 (CVC2/CID) is three digits.";
+%        $paycvv = $1;
+%      }
+%    }
+%  }
+%
+%} else {
+%  die "unknown payby $payby";
+%}
+%
+%my $error = $cust_main->realtime_bop( $payby2bop{$payby}, $amount,
+%  'quiet'    => 1,
+%  'payinfo'  => $payinfo,
+%  'paydate'  => "$year-$month-01",
+%  'payname'  => $payname,
+%  'paybatch' => $paybatch,
+%  'paycvv'   => $paycvv,
+%  map { $_ => $cgi->param($_) } @{$payby2fields{$payby}}
+%);
+%eidiot($error) if $error;
+%
+%$cust_main->apply_payments;
+%
+%if ( $cgi->param('save') ) {
+%  my $new = new FS::cust_main { $cust_main->hash };
+%  if ( $payby eq 'CARD' ) { 
+%    $new->set( 'payby' => ( $cgi->param('auto') ? 'CARD' : 'DCRD' ) );
+%  } elsif ( $payby eq 'CHEK' ) {
+%    $new->set( 'payby' => ( $cgi->param('auto') ? 'CHEK' : 'DCHK' ) );
+%  } else {
+%    die "unknown payby $payby";
+%  }
+%  $new->set( 'payinfo' => $payinfo );
+%  $new->set( 'paydate' => "$year-$month-01" );
+%  $new->set( 'payname' => $payname );
+%
+%  #false laziness w/FS:;cust_main::realtime_bop - check both to make sure
+%  # working correctly
+%  my $conf = new FS::Conf;
+%  if ( $payby eq 'CARD' &&
+%       grep { $_ eq cardtype($payinfo) } $conf->config('cvv-save') ) {
+%    $new->set( 'paycvv' => $paycvv );
+%  } else {
+%    $new->set( 'paycvv' => '');
+%  }
+%
+%  $new->set( $_ => $cgi->param($_) ) foreach @{$payby2fields{$payby}};
+%
+%  my $error = $new->replace($cust_main);
+%  eidiot "payment processed successfully, but error saving info: $error"
+%    if $error;
+%  $cust_main = $new;
+%}
+%
+%#success!
+%
+%
 
-%>
-<%= include( '/elements/header.html', ucfirst($type{$payby}). ' processing successful',
+<% include( '/elements/header.html', ucfirst($type{$payby}). ' processing successful',
              include('/elements/menubar.html',
                        'Main menu' => popurl(3),
                        "View this customer (#$custnum)" =>
@@ -143,6 +144,6 @@
 
     )
 %>
-<%= include( '/elements/small_custview.html', $cust_main ) %>
+<% include( '/elements/small_custview.html', $cust_main ) %>
 </BODY>
 </HTML>

Index: expire_pkg.cgi
===================================================================
RCS file: /home/cvs/cvsroot/freeside/httemplate/misc/process/expire_pkg.cgi,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- expire_pkg.cgi	22 Mar 2004 10:16:43 -0000	1.1
+++ expire_pkg.cgi	23 Aug 2006 22:25:38 -0000	1.2
@@ -1,25 +1,26 @@
-<%
-
-#untaint date & pkgnum
-
-my $date;
-if ( $cgi->param('date') ) {
-  str2time($cgi->param('date')) =~ /^(\d+)$/ or die "Illegal date";
-  $date=$1;
-} else {
-  $date='';
-}
-
-$cgi->param('pkgnum') =~ /^(\d+)$/ or die "Illegal pkgnum";
-my $pkgnum = $1;
-
-my $cust_pkg = qsearchs('cust_pkg',{'pkgnum'=>$pkgnum});
-my %hash = $cust_pkg->hash;
-$hash{expire}=$date;
-my $new = new FS::cust_pkg ( \%hash );
-my $error = $new->replace($cust_pkg);
-&eidiot($error) if $error;
-
-print $cgi->redirect(popurl(3). "view/cust_main.cgi?".$cust_pkg->getfield('custnum'));
+%
+%
+%#untaint date & pkgnum
+%
+%my $date;
+%if ( $cgi->param('date') ) {
+%  str2time($cgi->param('date')) =~ /^(\d+)$/ or die "Illegal date";
+%  $date=$1;
+%} else {
+%  $date='';
+%}
+%
+%$cgi->param('pkgnum') =~ /^(\d+)$/ or die "Illegal pkgnum";
+%my $pkgnum = $1;
+%
+%my $cust_pkg = qsearchs('cust_pkg',{'pkgnum'=>$pkgnum});
+%my %hash = $cust_pkg->hash;
+%$hash{expire}=$date;
+%my $new = new FS::cust_pkg ( \%hash );
+%my $error = $new->replace($cust_pkg);
+%&eidiot($error) if $error;
+%
+%print $cgi->redirect(popurl(3). "view/cust_main.cgi?".$cust_pkg->getfield('custnum'));
+%
+%
 
-%>

Index: cust_main-import.cgi
===================================================================
RCS file: /home/cvs/cvsroot/freeside/httemplate/misc/process/cust_main-import.cgi,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- cust_main-import.cgi	15 Aug 2006 14:20:51 -0000	1.4
+++ cust_main-import.cgi	23 Aug 2006 22:25:38 -0000	1.5
@@ -1,31 +1,35 @@
-<%
-
-  my $fh = $cgi->upload('csvfile');
-  #warn $cgi;
-  #warn $fh;
-
-  my $error = defined($fh)
-    ? FS::cust_main::batch_import( {
-        filehandle => $fh,
-        agentnum   => scalar($cgi->param('agentnum')),
-        refnum     => scalar($cgi->param('refnum')),
-        pkgpart    => scalar($cgi->param('pkgpart')),
-        #'fields'    => [qw( cust_pkg.setup dayphone first last address1 address2
-        #                   city state zip comments                          )],
-        'format'   => scalar($cgi->param('format')),
-      } )
-    : 'No file';
+%
+%
+%  my $fh = $cgi->upload('csvfile');
+%  #warn $cgi;
+%  #warn $fh;
+%
+%  my $error = defined($fh)
+%    ? FS::cust_main::batch_import( {
+%        filehandle => $fh,
+%        agentnum   => scalar($cgi->param('agentnum')),
+%        refnum     => scalar($cgi->param('refnum')),
+%        pkgpart    => scalar($cgi->param('pkgpart')),
+%        #'fields'    => [qw( cust_pkg.setup dayphone first last address1 address2
+%        #                   city state zip comments                          )],
+%        'format'   => scalar($cgi->param('format')),
+%      } )
+%    : 'No file';
+%
+%  if ( $error ) {
+%    
 
-  if ( $error ) {
-    %>
     <!-- mason kludge -->
-    <%
-    eidiot($error);
-#    $cgi->param('error', $error);
-#    print $cgi->redirect( "${p}cust_main-import.cgi
-  } else {
-    %>
+%
+%    eidiot($error);
+%#    $cgi->param('error', $error);
+%#    print $cgi->redirect( "${p}cust_main-import.cgi
+%  } else {
+%    
+
     <!-- mason kludge -->
-    <%= include("/elements/header.html",'Import successful') %> <%
-  }
-%>
+    <% include("/elements/header.html",'Import successful') %> 
+%
+%  }
+%
+

Index: batch-cust_pay.cgi
===================================================================
RCS file: /home/cvs/cvsroot/freeside/httemplate/misc/process/batch-cust_pay.cgi,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- batch-cust_pay.cgi	12 Oct 2005 12:02:26 -0000	1.2
+++ batch-cust_pay.cgi	23 Aug 2006 22:25:38 -0000	1.3
@@ -1,42 +1,45 @@
-<%
-  my $param = $cgi->Vars;
-
-  #my $paybatch = $param->{'paybatch'};
-  my $paybatch = time2str('webbatch-%Y/%m/%d-%T'. "-$$-". rand() * 2**32, time);
-
-  my @cust_pay = ();
-  #my $row = 0;
-  #while ( exists($param->{"custnum$row"}) ) {
-  for ( my $row = 0; exists($param->{"custnum$row"}); $row++ ) {
-    push @cust_pay, new FS::cust_pay {
-                                       'custnum'  => $param->{"custnum$row"},
-                                       'paid'     => $param->{"paid$row"},
-                                       'payby'    => 'BILL',
-                                       'payinfo'  => $param->{"payinfo$row"},
-                                       'paybatch' => $paybatch,
-                                     }
-      if    $param->{"custnum$row"}
-         || $param->{"paid$row"}
-         || $param->{"payinfo$row"};
-    #$row++;
-  }
-
-  my @errors = FS::cust_pay->batch_insert(@cust_pay);
-  my $num_errors = scalar(grep $_, @errors);
-
-  if ( $num_errors ) {
-
-    $cgi->param('error', "$num_errors error". ($num_errors>1 ? 's' : '').
-                         ' - Batch not processed, correct and resubmit'
-               );
-
-    my $erow=0;
-    $cgi->param('error'. $erow++, shift @errors) while @errors;
-
-    %><%= $cgi->redirect($p.'batch-cust_pay.html?'. $cgi->query_string)
-
-  %><% } else {
+%
+%  my $param = $cgi->Vars;
+%
+%  #my $paybatch = $param->{'paybatch'};
+%  my $paybatch = time2str('webbatch-%Y/%m/%d-%T'. "-$$-". rand() * 2**32, time);
+%
+%  my @cust_pay = ();
+%  #my $row = 0;
+%  #while ( exists($param->{"custnum$row"}) ) {
+%  for ( my $row = 0; exists($param->{"custnum$row"}); $row++ ) {
+%    push @cust_pay, new FS::cust_pay {
+%                                       'custnum'  => $param->{"custnum$row"},
+%                                       'paid'     => $param->{"paid$row"},
+%                                       'payby'    => 'BILL',
+%                                       'payinfo'  => $param->{"payinfo$row"},
+%                                       'paybatch' => $paybatch,
+%                                     }
+%      if    $param->{"custnum$row"}
+%         || $param->{"paid$row"}
+%         || $param->{"payinfo$row"};
+%    #$row++;
+%  }
+%
+%  my @errors = FS::cust_pay->batch_insert(@cust_pay);
+%  my $num_errors = scalar(grep $_, @errors);
+%
+%  if ( $num_errors ) {
+%
+%    $cgi->param('error', "$num_errors error". ($num_errors>1 ? 's' : '').
+%                         ' - Batch not processed, correct and resubmit'
+%               );
+%
+%    my $erow=0;
+%    $cgi->param('error'. $erow++, shift @errors) while @errors;
+%
+%    
+<% $cgi->redirect($p.'batch-cust_pay.html?'. $cgi->query_string)
 
-    %><%= $cgi->redirect(popurl(3). "search/cust_pay.cgi?magic=paybatch;paybatch=$paybatch") %>
+  %>
+% } else {
+%
+%    
+<% $cgi->redirect(popurl(3). "search/cust_pay.cgi?magic=paybatch;paybatch=$paybatch") %>
+% } 
 
-  <% } %>

Index: cdr-import.html
===================================================================
RCS file: /home/cvs/cvsroot/freeside/httemplate/misc/process/cdr-import.html,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- cdr-import.html	25 Mar 2006 02:23:26 -0000	1.2
+++ cdr-import.html	23 Aug 2006 22:25:38 -0000	1.3
@@ -1,26 +1,30 @@
-<%
-
-  my $fh = $cgi->upload('csvfile');
-
-  my $error = defined($fh)
-    ? FS::cdr::batch_import( {
-        'filehandle' => $fh,
-        'format'     => $cgi->param('format'),
-      } )
-    : 'No file';
+%
+%
+%  my $fh = $cgi->upload('csvfile');
+%
+%  my $error = defined($fh)
+%    ? FS::cdr::batch_import( {
+%        'filehandle' => $fh,
+%        'format'     => $cgi->param('format'),
+%      } )
+%    : 'No file';
+%
+%  if ( $error ) {
+%    
 
-  if ( $error ) {
-    %>
     <!-- mason kludge -->
-    <%
-    eidiot($error);
-#    $cgi->param('error', $error);
-#    print $cgi->redirect( "${p}cust_main-import.cgi
-  } else {
-    %>
+%
+%    eidiot($error);
+%#    $cgi->param('error', $error);
+%#    print $cgi->redirect( "${p}cust_main-import.cgi
+%  } else {
+%    
+
     <!-- mason kludge -->
-    <%= include("/elements/header.html",'Import successful') %>
+    <% include("/elements/header.html",'Import successful') %>
     <!-- XXX redirect to batch search like the payment entry... -->
-    <%= include("/elements/footer.html",'Import successful') %> <%
-  }
-%>
+    <% include("/elements/footer.html",'Import successful') %> 
+%
+%  }
+%
+

Index: inventory_item-import.html
===================================================================
RCS file: /home/cvs/cvsroot/freeside/httemplate/misc/process/inventory_item-import.html,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- inventory_item-import.html	25 Mar 2006 02:23:26 -0000	1.2
+++ inventory_item-import.html	23 Aug 2006 22:25:38 -0000	1.3
@@ -1,27 +1,31 @@
-<%
-
-  my $fh = $cgi->upload('filename');
-
-  my $error = defined($fh)
-    ? FS::inventory_item::batch_import( {
-        'filehandle' => $fh,
-        'classnum'   => $cgi->param('classnum'),
-      } )
-    : 'No file';
+%
+%
+%  my $fh = $cgi->upload('filename');
+%
+%  my $error = defined($fh)
+%    ? FS::inventory_item::batch_import( {
+%        'filehandle' => $fh,
+%        'classnum'   => $cgi->param('classnum'),
+%      } )
+%    : 'No file';
+%
+%  if ( $error ) {
+%    
 
-  if ( $error ) {
-    %>
     <!-- mason kludge -->
-    <%
-    eidiot($error);
-#    $cgi->param('error', $error);
-#    print $cgi->redirect( "${p}cust_main-import.cgi
-  } else {
-    %>
+%
+%    eidiot($error);
+%#    $cgi->param('error', $error);
+%#    print $cgi->redirect( "${p}cust_main-import.cgi
+%  } else {
+%    
+
     <!-- mason kludge -->
-    <%= include("/elements/header.html",'Import successful') %>
+    <% include("/elements/header.html",'Import successful') %>
     <!-- XXX redirect to batch search like the payment entry... -->
-    <%= include("/elements/footer.html",'Import successful') %> <%
-  }
-%>
+    <% include("/elements/footer.html",'Import successful') %> 
+%
+%  }
+%
+
 

Index: delete-customer.cgi
===================================================================
RCS file: /home/cvs/cvsroot/freeside/httemplate/misc/process/delete-customer.cgi,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- delete-customer.cgi	10 Feb 2002 13:21:31 -0000	1.4
+++ delete-customer.cgi	23 Aug 2006 22:25:38 -0000	1.5
@@ -1,29 +1,30 @@
-<%
-
-my $conf = new FS::Conf;
-die "Customer deletions not enabled" unless $conf->exists('deletecustomers');
-
-$cgi->param('custnum') =~ /^(\d+)$/;
-my $custnum = $1;
-my $new_custnum;
-if ( $cgi->param('new_custnum') ) {
-  $cgi->param('new_custnum') =~ /^(\d+)$/
-    or die "Illegal new customer number: ". $cgi->param('new_custnum');
-  $new_custnum = $1;
-} else {
-  $new_custnum = '';
-}
-my $cust_main = qsearchs( 'cust_main', { 'custnum' => $custnum } )
-  or die "Customer not found: $custnum";
-
-my $error = $cust_main->delete($new_custnum);
+%
+%
+%my $conf = new FS::Conf;
+%die "Customer deletions not enabled" unless $conf->exists('deletecustomers');
+%
+%$cgi->param('custnum') =~ /^(\d+)$/;
+%my $custnum = $1;
+%my $new_custnum;
+%if ( $cgi->param('new_custnum') ) {
+%  $cgi->param('new_custnum') =~ /^(\d+)$/
+%    or die "Illegal new customer number: ". $cgi->param('new_custnum');
+%  $new_custnum = $1;
+%} else {
+%  $new_custnum = '';
+%}
+%my $cust_main = qsearchs( 'cust_main', { 'custnum' => $custnum } )
+%  or die "Customer not found: $custnum";
+%
+%my $error = $cust_main->delete($new_custnum);
+%
+%if ( $error ) {
+%  $cgi->param('error', $error);
+%  print $cgi->redirect(popurl(2). "delete-customer.cgi?". $cgi->query_string );
+%} elsif ( $new_custnum ) {
+%  print $cgi->redirect(popurl(3). "view/cust_main.cgi?$new_custnum");
+%} else {
+%  print $cgi->redirect(popurl(3));
+%}
+%
 
-if ( $error ) {
-  $cgi->param('error', $error);
-  print $cgi->redirect(popurl(2). "delete-customer.cgi?". $cgi->query_string );
-} elsif ( $new_custnum ) {
-  print $cgi->redirect(popurl(3). "view/cust_main.cgi?$new_custnum");
-} else {
-  print $cgi->redirect(popurl(3));
-}
-%>

Index: link.cgi
===================================================================
RCS file: /home/cvs/cvsroot/freeside/httemplate/misc/process/link.cgi,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -d -r1.14 -r1.15
--- link.cgi	17 Jun 2005 05:31:50 -0000	1.14
+++ link.cgi	23 Aug 2006 22:25:38 -0000	1.15
@@ -1,76 +1,78 @@
-<%
-
-my $DEBUG = 0;
-
-$cgi->param('pkgnum') =~ /^(\d+)$/;
-my $pkgnum = $1;
-$cgi->param('svcpart') =~ /^(\d+)$/;
-my $svcpart = $1;
-$cgi->param('svcnum') =~ /^(\d*)$/;
-my $svcnum = $1;
-
-unless ( $svcnum ) {
-  my $part_svc = qsearchs('part_svc',{'svcpart'=>$svcpart});
-  my $svcdb = $part_svc->getfield('svcdb');
-  $cgi->param('link_field') =~ /^(\w+)$/;
-  my $link_field = $1;
-  my %search = ( $link_field => $cgi->param('link_value') );
-  if ( $cgi->param('link_field2') =~ /^(\w+)$/ ) {
-    $search{$1} = $cgi->param('link_value2');
-  }
-
-  my @svc_x = ( sort { ($a->cust_svc->pkgnum > 0) <=> ($b->cust_svc->pkgnum > 0)
-                       or ($b->cust_svc->svcpart == $svcpart)
-                            <=> ($a->cust_svc->svcpart == $svcpart)
-                     }
-                     qsearch( $svcdb, \%search )
-              );
-
-  if ( $DEBUG ) {
-    warn scalar(@svc_x). " candidate accounts found for linking ".
-         "(svcpart $svcpart):\n";
-    foreach my $svc_x ( @svc_x ) {
-      warn "  ". $svc_x->email.
-           " (svcnum ". $svc_x->svcnum. ",".
-           " pkgnum ".  $svc_x->cust_svc->pkgnum. ",".
-           " svcpart ". $svc_x->cust_svc->svcpart. ")\n";
-    }
-  }
-
-  my $svc_x = $svc_x[0];
-
-  eidiot("$link_field not found!") unless $svc_x;
-
-  $svcnum = $svc_x->svcnum;
-
-}
-
-my $old = qsearchs('cust_svc',{'svcnum'=>$svcnum});
-die "svcnum not found!" unless $old;
-my $conf = new FS::Conf;
-my($error, $new);
-if ( $old->pkgnum && ! $conf->exists('legacy_link-steal') ) {
-  $error = "svcnum $svcnum already linked to package ". $old->pkgnum;
-} else {
-  $new = new FS::cust_svc ({
-    'svcnum' => $svcnum,
-    'pkgnum' => $pkgnum,
-    'svcpart' => $svcpart,
-  });
-
-  $error = $new->replace($old);
-}
+%
+%
+%my $DEBUG = 0;
+%
+%$cgi->param('pkgnum') =~ /^(\d+)$/;
+%my $pkgnum = $1;
+%$cgi->param('svcpart') =~ /^(\d+)$/;
+%my $svcpart = $1;
+%$cgi->param('svcnum') =~ /^(\d*)$/;
+%my $svcnum = $1;
+%
+%unless ( $svcnum ) {
+%  my $part_svc = qsearchs('part_svc',{'svcpart'=>$svcpart});
+%  my $svcdb = $part_svc->getfield('svcdb');
+%  $cgi->param('link_field') =~ /^(\w+)$/;
+%  my $link_field = $1;
+%  my %search = ( $link_field => $cgi->param('link_value') );
+%  if ( $cgi->param('link_field2') =~ /^(\w+)$/ ) {
+%    $search{$1} = $cgi->param('link_value2');
+%  }
+%
+%  my @svc_x = ( sort { ($a->cust_svc->pkgnum > 0) <=> ($b->cust_svc->pkgnum > 0)
+%                       or ($b->cust_svc->svcpart == $svcpart)
+%                            <=> ($a->cust_svc->svcpart == $svcpart)
+%                     }
+%                     qsearch( $svcdb, \%search )
+%              );
+%
+%  if ( $DEBUG ) {
+%    warn scalar(@svc_x). " candidate accounts found for linking ".
+%         "(svcpart $svcpart):\n";
+%    foreach my $svc_x ( @svc_x ) {
+%      warn "  ". $svc_x->email.
+%           " (svcnum ". $svc_x->svcnum. ",".
+%           " pkgnum ".  $svc_x->cust_svc->pkgnum. ",".
+%           " svcpart ". $svc_x->cust_svc->svcpart. ")\n";
+%    }
+%  }
+%
+%  my $svc_x = $svc_x[0];
+%
+%  eidiot("$link_field not found!") unless $svc_x;
+%
+%  $svcnum = $svc_x->svcnum;
+%
+%}
+%
+%my $old = qsearchs('cust_svc',{'svcnum'=>$svcnum});
+%die "svcnum not found!" unless $old;
+%my $conf = new FS::Conf;
+%my($error, $new);
+%if ( $old->pkgnum && ! $conf->exists('legacy_link-steal') ) {
+%  $error = "svcnum $svcnum already linked to package ". $old->pkgnum;
+%} else {
+%  $new = new FS::cust_svc ({
+%    'svcnum' => $svcnum,
+%    'pkgnum' => $pkgnum,
+%    'svcpart' => $svcpart,
+%  });
+%
+%  $error = $new->replace($old);
+%}
+%
+%unless ($error) {
+%  #no errors, so let's view this customer.
+%  my $custnum = $new->cust_pkg->custnum;
+%  print $cgi->redirect(popurl(3). "view/cust_main.cgi?$custnum".
+%                       "#cust_pkg$pkgnum" );
+%} else {
+%
 
-unless ($error) {
-  #no errors, so let's view this customer.
-  my $custnum = $new->cust_pkg->custnum;
-  print $cgi->redirect(popurl(3). "view/cust_main.cgi?$custnum".
-                       "#cust_pkg$pkgnum" );
-} else {
-%>
 <!-- mason kludge -->
-<%
-  idiot($error);
-}
+%
+%  idiot($error);
+%}
+%
+%
 
-%>



More information about the freeside-commits mailing list