signups with snarf info!
authorivan <ivan>
Sat, 25 Oct 2003 02:05:44 +0000 (02:05 +0000)
committerivan <ivan>
Sat, 25 Oct 2003 02:05:44 +0000 (02:05 +0000)
FS/FS/ClientAPI/Signup.pm
FS/FS/acct_snarf.pm
FS/FS/svc_Common.pm
FS/FS/svc_acct.pm
fs_signup/FS-SignupClient/cgi/signup.cgi

index 92fc636..60639b1 100644 (file)
@@ -10,6 +10,8 @@ use FS::part_pkg;
 use FS::svc_acct_pop;
 use FS::cust_main;
 use FS::cust_pkg;
+use FS::svc_acct;
+use FS::acct_snarf;
 use FS::Msgcat qw(gettext);
 
 use FS::ClientAPI; #hmm
@@ -155,6 +157,20 @@ sub new_customer {
       qw( username _password sec_phrase popnum ),
   } );
 
+  my @acct_snarf;
+  my $snarfnum = 1;
+  while ( length($packet->{"snarf_machine$snarfnum"}) ) {
+    my $acct_snarf = new FS::acct_snarf ( {
+      'machine'   => $packet->{"snarf_machine$snarfnum"},
+      'protocol'  => $packet->{"snarf_protocol$snarfnum"},
+      'username'  => $packet->{"snarf_username$snarfnum"},
+      '_password' => $packet->{"snarf_password$snarfnum"},
+    } );
+    $snarfnum++;
+    push @acct_snarf, $acct_snarf;
+  }
+  $svc_acct->child_objects( \@acct_snarf );
+
   my $y = $svc_acct->setdefault; # arguably should be in new method
   return { 'error' => $y } if $y && !ref($y);
 
index 7c51d69..b4e88bf 100644 (file)
@@ -90,9 +90,9 @@ returns the error, otherwise returns false.
 
 =item check
 
-Checks all fields to make sure this is a valid example.  If there is
-an error, returns the error, otherwise returns false.  Called by the insert
-and replace methods.
+Checks all fields to make sure this is a valid external mail account.  If
+there is an error, returns the error, otherwise returns false.  Called by the
+insert and replace methods.
 
 =cut
 
@@ -103,7 +103,7 @@ sub check {
     || $self->ut_number('svcnum')
     || $self->ut_foreign_key('svcnum', 'svc_acct', 'svcnum')
     || $self->ut_domain('machine')
-    || $self->alphan('protocol')
+    || $self->ut_alphan('protocol')
     || $self->ut_textn('username')
   ;
   return $error if $error;
index 524e550..2fed5dd 100644 (file)
@@ -80,7 +80,7 @@ sub check {
   $self->SUPER::check;
 }
 
-=item insert [ JOBNUM_ARRAYREF ]
+=item insert [ JOBNUM_ARRAYREF [ OBJECTS_ARRAYREF ] ]
 
 Adds this record to the database.  If there is an error, returns the error,
 otherwise returns false.
@@ -91,11 +91,16 @@ defined.  An FS::cust_svc record will be created and inserted.
 If an arrayref is passed as parameter, the B<jobnum>s of any export jobs will
 be added to the array.
 
+If an arrayref of FS::tablename objects (for example, FS::acct_snarf objects)
+is passed as the optional second parameter, they will have their svcnum fields
+set and will be inserted after this record, but before any exports are run.
+
 =cut
 
 sub insert {
   my $self = shift;
   local $FS::queue::jobnums = shift if @_;
+  my $objects = scalar(@_) ? shift : [];
   my $error;
 
   local $SIG{HUP} = 'IGNORE';
@@ -142,6 +147,15 @@ sub insert {
     return $error;
   }
 
+  foreach my $object ( @$objects ) {
+    $object->svcnum($self->svcnum);
+    $error = $object->insert;
+    if ( $error ) {
+      $dbh->rollback if $oldAutoCommit;
+      return $error;
+    }
+  }
+
   #new-style exports!
   unless ( $noexport_hack ) {
     foreach my $part_export ( $self->cust_svc->part_svc->part_export ) {
@@ -416,7 +430,7 @@ sub cancel { ''; }
 
 =head1 VERSION
 
-$Id: svc_Common.pm,v 1.13 2003-08-05 00:20:47 khoff Exp $
+$Id: svc_Common.pm,v 1.14 2003-10-25 02:05:44 ivan Exp $
 
 =head1 BUGS
 
index 3fb28c0..4ea7734 100644 (file)
@@ -188,10 +188,16 @@ The additional field I<usergroup> can optionally be defined; if so it should
 contain an arrayref of group names.  See L<FS::radius_usergroup>.  (used in
 sqlradius export only)
 
+The additional field I<child_objects> can optionally be defined; if so it
+should contain an arrayref of FS::tablename objects.  They will have their
+svcnum fields set and will be inserted after this record, but before any
+exports are run.
+
 (TODOC: L<FS::queue> and L<freeside-queued>)
 
 (TODOC: new exports!)
 
+
 =cut
 
 sub insert {
@@ -319,7 +325,7 @@ sub insert {
   #see?  i told you it was more complicated
 
   my @jobnums;
-  $error = $self->SUPER::insert(\@jobnums);
+  $error = $self->SUPER::insert(\@jobnums, $self->child_objects || [] );
   if ( $error ) {
     $dbh->rollback if $oldAutoCommit;
     return $error;
index 70facb5..5ca93d2 100755 (executable)
@@ -1,6 +1,6 @@
 #!/usr/bin/perl -Tw
 #
-# $Id: signup.cgi,v 1.47 2003-10-24 19:28:49 ivan Exp $
+# $Id: signup.cgi,v 1.48 2003-10-25 02:05:44 ivan Exp $
 
 use strict;
 use vars qw( @payby $cgi $locales $packages
@@ -266,6 +266,7 @@ if ( defined $cgi->param('magic') ) {
         '_password'        => $password,
         'popnum'           => $popnum,
         'agentnum'         => $agentnum,
+        map { $_ => $cgi->param($_) } grep { /^snarf_/ } $cgi->param
       } );
 
     }
@@ -273,6 +274,9 @@ if ( defined $cgi->param('magic') ) {
     if ( $error eq '_decline' ) {
       print_decline();
     } elsif ( $error ) {
+      #fudge the snarf info
+      no strict 'refs';
+      ${$_} = $cgi->param($_) foreach grep { /^snarf_/ } $cgi->param;
       print_form();
     } else {
       print_okay();