working on the road:
authorivan <ivan>
Fri, 4 Oct 2002 12:57:06 +0000 (12:57 +0000)
committerivan <ivan>
Fri, 4 Oct 2002 12:57:06 +0000 (12:57 +0000)
  - easier "change package" link for changing one package to another
  - sqlradius export now compatible with Pg
  - indices on phone numbers
  - install instructions specify Pg 7.1 (at least until ILIKE thing is changed)
  - searching on phone number fragments

FS/FS/part_export/sqlradius.pm
FS/FS/type_pkgs.pm
FS/bin/freeside-setup
httemplate/docs/install.html
httemplate/edit/process/cust_pkg.cgi
httemplate/misc/change_pkg.cgi [new file with mode: 0755]
httemplate/search/cust_main.cgi
httemplate/view/cust_main.cgi

index 3c781c0..0f93703 100644 (file)
@@ -187,10 +187,10 @@ sub sqlradius_insert { #subroutine, not method
     } else {
 
       my $i_sth = $dbh->prepare(
     } else {
 
       my $i_sth = $dbh->prepare(
-        "INSERT INTO rad$table ( id, UserName, Attribute, Value ) ".
-          "VALUES ( ?, ?, ?, ? )"
+        "INSERT INTO rad$table ( UserName, Attribute, Value ) ".
+          "VALUES ( ?, ?, ? )"
       ) or die $dbh->errstr;
       ) or die $dbh->errstr;
-      $i_sth->execute( '', $username, $attribute, $attributes{$attribute} )
+      $i_sth->execute( $username, $attribute, $attributes{$attribute} )
         or die $i_sth->errstr;
 
     }
         or die $i_sth->errstr;
 
     }
@@ -204,7 +204,7 @@ sub sqlradius_usergroup_insert { #subroutine, not method
   my( $username, @groups ) = @_;
 
   my $sth = $dbh->prepare( 
   my( $username, @groups ) = @_;
 
   my $sth = $dbh->prepare( 
-    "INSERT INTO usergroup ( id, UserName, GroupName ) VALUES ( ?, ?, ? )"
+    "INSERT INTO usergroup ( UserName, GroupName ) VALUES ( ?, ? )"
   ) or die $dbh->errstr;
   foreach my $group ( @groups ) {
     $sth->execute( '', $username, $group )
   ) or die $dbh->errstr;
   foreach my $group ( @groups ) {
     $sth->execute( '', $username, $group )
index 8e0d4ef..efba60d 100644 (file)
@@ -94,11 +94,24 @@ sub check {
   ''; #no error
 }
 
   ''; #no error
 }
 
+=item part_pkg
+
+Returns the FS::part_pkg object associated with this record.
+
+=cut
+
+sub part_pkg {
+  my $self = shift;
+  qsearchs( 'part_pkg', { 'pkgpart' => $self->pkgpart } );
+}
+
+=cut
+
 =back
 
 =head1 VERSION
 
 =back
 
 =head1 VERSION
 
-$Id: type_pkgs.pm,v 1.1 1999-08-04 09:03:53 ivan Exp $
+$Id: type_pkgs.pm,v 1.2 2002-10-04 12:57:06 ivan Exp $
 
 =head1 BUGS
 
 
 =head1 BUGS
 
index f6a543f..d61e8b0 100755 (executable)
@@ -111,8 +111,9 @@ my($dbdef) = new DBIx::DBSchema ( map {
 my $cust_main = $dbdef->table('cust_main');
 unless ($ship) { #remove ship_ from cust_main
   $cust_main->delcolumn($_) foreach ( grep /^ship_/, $cust_main->columns );
 my $cust_main = $dbdef->table('cust_main');
 unless ($ship) { #remove ship_ from cust_main
   $cust_main->delcolumn($_) foreach ( grep /^ship_/, $cust_main->columns );
-} else { #add indices on ship_last and ship_company
-  push @{$cust_main->index->lol_ref}, ( ['ship_last'], ['ship_company'] ) 
+} else { #add indices
+  push @{$cust_main->index->lol_ref},
+    map { [ "ship_$_" ] } qw( last company daytime night fax );
 }
 
 #add radius attributes to svc_acct
 }
 
 #add radius attributes to svc_acct
@@ -496,7 +497,9 @@ sub tables_hash_hack {
       'primary_key' => 'custnum',
       'unique' => [],
       #'index' => [ ['last'], ['company'] ],
       'primary_key' => 'custnum',
       'unique' => [],
       #'index' => [ ['last'], ['company'] ],
-      'index' => [ ['last'], [ 'company' ], [ 'referral_custnum' ] ],
+      'index' => [ ['last'], [ 'company' ], [ 'referral_custnum' ],
+                   [ 'daytime' ], [ 'night' ], [ 'fax' ],
+                 ],
     },
 
     'cust_main_invoice' => {
     },
 
     'cust_main_invoice' => {
index 3d19e4d..3c48a74 100644 (file)
@@ -12,7 +12,7 @@ Before installing, you need:
   <li><a href="http://rsync.samba.org/">rsync</a>
   <li>A <b>transactional</b> database engine <a href="http://search.cpan.org/search?mode=module&query=DBD%3A%3A">supported</a> by Perl's <a href="http://dbi.perl.org">DBI</a>.
     <ul>
   <li><a href="http://rsync.samba.org/">rsync</a>
   <li>A <b>transactional</b> database engine <a href="http://search.cpan.org/search?mode=module&query=DBD%3A%3A">supported</a> by Perl's <a href="http://dbi.perl.org">DBI</a>.
     <ul>
-      <li><a href="http://www.postgresql.org/">PostgreSQL</a> (v7 or higher) is recommended.
+      <li><a href="http://www.postgresql.org/">PostgreSQL</a> is recommended (v7.1.x or later, not 7.0.x).
       <li>MySQL versions before 4.1 do not support standard SQL subqueries and are <b>NOT SUPPORTED</b>.  If you are a developer who wishes to contribute MySQL 3.x/4.0 support, see <a href="http://pouncequick.420.am/rt/Ticket/Display.html?id=438">ticket #438</a> in the bug-tracking system and ask on the -devel mailing list.
 <!--       <li>MySQL has been reported to work.
          <b>MySQL's default <a href="http://www.mysql.com/doc/M/y/MyISAM.html">MyISAM</a> and <a href="http://www.mysql.com/doc/I/S/ISAM.html">ISAM</a> table types are not supported</b>.  If you want to use MySQL, you <b>must</b> use one of the new <a href="http://www.mysql.com/doc/T/a/Table_types.html">transaction-safe table types</a> such as <a href="http://www.mysql.com/doc/B/D/BDB.html">BDB</a> or <a href="http://www.mysql.com/doc/I/n/InnoDB.html">InnoDB</a>, and set it as the default table type using the <code>--default-table-type=BDB</code> or <code>--default-table-type=InnoDB</code> <a href="http://www.mysql.com/documentation/mysql/bychapter/manual_MySQL_Database_Administration.html#Command-line_options">mysqld command-line option</a> or by setting <code>default-table-type=BDB</code> or <code>default-table-type=InnoDB</code> in the <a href="http://www.mysql.com/documentation/mysql/bychapter/manual_MySQL_Database_Administration.html#Option_files">my.cnf option file</a>. -->
       <li>MySQL versions before 4.1 do not support standard SQL subqueries and are <b>NOT SUPPORTED</b>.  If you are a developer who wishes to contribute MySQL 3.x/4.0 support, see <a href="http://pouncequick.420.am/rt/Ticket/Display.html?id=438">ticket #438</a> in the bug-tracking system and ask on the -devel mailing list.
 <!--       <li>MySQL has been reported to work.
          <b>MySQL's default <a href="http://www.mysql.com/doc/M/y/MyISAM.html">MyISAM</a> and <a href="http://www.mysql.com/doc/I/S/ISAM.html">ISAM</a> table types are not supported</b>.  If you want to use MySQL, you <b>must</b> use one of the new <a href="http://www.mysql.com/doc/T/a/Table_types.html">transaction-safe table types</a> such as <a href="http://www.mysql.com/doc/B/D/BDB.html">BDB</a> or <a href="http://www.mysql.com/doc/I/n/InnoDB.html">InnoDB</a>, and set it as the default table type using the <code>--default-table-type=BDB</code> or <code>--default-table-type=InnoDB</code> <a href="http://www.mysql.com/documentation/mysql/bychapter/manual_MySQL_Database_Administration.html#Command-line_options">mysqld command-line option</a> or by setting <code>default-table-type=BDB</code> or <code>default-table-type=InnoDB</code> in the <a href="http://www.mysql.com/documentation/mysql/bychapter/manual_MySQL_Database_Administration.html#Option_files">my.cnf option file</a>. -->
index f8c9f51..df8471c 100755 (executable)
@@ -11,16 +11,23 @@ my @remove_pkgnums = map {
   $1;
 } $cgi->param('remove_pkg');
 
   $1;
 } $cgi->param('remove_pkg');
 
+my $error_redirect;
 my @pkgparts;
 my @pkgparts;
-foreach my $pkgpart ( map /^pkg(\d+)$/ ? $1 : (), $cgi->param ) {
-  if ( $cgi->param("pkg$pkgpart") =~ /^(\d+)$/ ) {
-    my $num_pkgs = $1;
-    while ( $num_pkgs-- ) {
-      push @pkgparts,$pkgpart;
+if ( $cgi->param('new_pkgpart') =~ /^(\d+)$/ ) { #came from misc/change_pkg.cgi
+  $error_redirect = "misc/change_pkg.cgi";
+  @pkgparts = ($1);
+} else { #came from edit/cust_pkg.cgi
+  $error_redirect = "edit/cust_pkg.cgi";
+  foreach my $pkgpart ( map /^pkg(\d+)$/ ? $1 : (), $cgi->param ) {
+    if ( $cgi->param("pkg$pkgpart") =~ /^(\d+)$/ ) {
+      my $num_pkgs = $1;
+      while ( $num_pkgs-- ) {
+        push @pkgparts,$pkgpart;
+      }
+    } else {
+      $error = "Illegal quantity";
+      last;
     }
     }
-  } else {
-    $error = "Illegal quantity";
-    last;
   }
 }
 
   }
 }
 
@@ -28,7 +35,7 @@ $error ||= FS::cust_pkg::order($custnum,\@pkgparts,\@remove_pkgnums);
 
 if ($error) {
   $cgi->param('error', $error);
 
 if ($error) {
   $cgi->param('error', $error);
-  print $cgi->redirect(popurl(2). "cust_pkg.cgi?". $cgi->query_string );
+  print $cgi->redirect(popurl(3). $error_redirect. '?'. $cgi->query_string );
 } else {
   print $cgi->redirect(popurl(3). "view/cust_main.cgi?$custnum");
 }
 } else {
   print $cgi->redirect(popurl(3). "view/cust_main.cgi?$custnum");
 }
diff --git a/httemplate/misc/change_pkg.cgi b/httemplate/misc/change_pkg.cgi
new file mode 100755 (executable)
index 0000000..5346fd9
--- /dev/null
@@ -0,0 +1,66 @@
+<!-- mason kludge -->
+<%
+
+my $pkgnum;
+if ( $cgi->param('error') ) {
+  #$custnum = $cgi->param('custnum');
+  #%remove_pkg = map { $_ => 1 } $cgi->param('remove_pkg');
+  $pkgnum = ($cgi->param('remove_pkg'))[0];
+} else {
+  my($query) = $cgi->keywords;
+  $query =~ /^(\d+)$/;
+  #$custnum = $1;
+  $pkgnum = $1;
+  #%remove_pkg = ();
+}
+
+my $cust_pkg = qsearchs( 'cust_pkg', { 'pkgnum' => $pkgnum } )
+  or die "unknown pkgnum $pkgnum";
+my $custnum = $cust_pkg->custnum;
+
+my $conf = new FS::Conf;
+
+my $p1 = popurl(1);
+
+my $cust_main = $cust_pkg->cust_main
+  or die "can't get cust_main record for custnum ". $cust_pkg->custnum.
+         " ( pkgnum ". cust_pkg->pkgnum. ")";
+my $agent = $cust_main->agent;
+
+print header("Change Package",  menubar(
+  "View this customer (#$custnum)" => "${p}view/cust_main.cgi?$custnum",
+  'Main Menu' => $p,
+));
+
+print qq!<FONT SIZE="+1" COLOR="#ff0000">Error: !, $cgi->param('error'),
+      "</FONT><BR><BR>"
+  if $cgi->param('error');
+
+my $part_pkg = $cust_pkg->part_pkg;
+
+print small_custview( $cust_main, $conf->config('countrydefault') ).
+      qq!<FORM ACTION="${p}edit/process/cust_pkg.cgi" METHOD=POST>!.
+      qq!<INPUT TYPE="hidden" NAME="custnum" VALUE="$custnum">!.
+      qq!<INPUT TYPE="hidden" NAME="remove_pkg" VALUE="$pkgnum">!.
+      '<BR>Current package: '. $part_pkg->pkg. ' - '. $part_pkg->comment.
+      qq!<BR>New package: <SELECT NAME="new_pkgpart"><OPTION VALUE=0></OPTION>!;
+
+foreach my $part_pkg (
+  grep { ! $_->disabled && $_->pkgpart != $cust_pkg->pkgpart }
+    map { $_->part_pkg } $agent->agent_type->type_pkgs
+) {
+  my $pkgpart = $part_pkg->pkgpart;
+  print qq!<OPTION VALUE="$pkgpart"!;
+  print ' SELECTED' if $cgi->param('error')
+                       && $cgi->param('new_pkgpart') == $pkgpart;
+  print qq!>$pkgpart: !. $part_pkg->pkg. ' - '. $part_pkg->comment. '</OPTION>';
+}
+
+print <<END;
+</SELECT>
+<BR><BR><INPUT TYPE="submit" VALUE="Change package">
+    </FORM>
+  </BODY>
+</HTML>
+END
+%>
index 0a98b18..ac238b6 100755 (executable)
@@ -636,12 +636,19 @@ sub phonesearch {
 
   my $phone = $cgi->param('phone_text');
 
 
   my $phone = $cgi->param('phone_text');
 
-  #false laziness with Record::ut_phonen, only works with US/CA numbers...
+  #(no longer really) false laziness with Record::ut_phonen
+  #only works with US/CA numbers...
   $phone =~ s/\D//g;
   $phone =~ s/\D//g;
-  $phone =~ /^(\d{3})(\d{3})(\d{4})(\d*)$/
-    or eidiot gettext('illegal_phone'). ": $phone";
-  $phone = "$1-$2-$3";
-  $phone .= " x$4" if $4;
+  if ( $phone =~ /^(\d{3})(\d{3})(\d{4})(\d*)$/ ) {
+    $phone = "$1-$2-$3";
+    $phone .= " x$4" if $4;
+  } elsif ( $phone =~ /^(\d{3})(\d{4})$/ ) {
+    $phone = "$1-$2";
+  } elsif ( $phone =~ /^(\d{3,4})$/ ) {
+    $phone = $1;
+  } else {
+    eidiot gettext('illegal_phone'). ": $phone";
+  }
 
   my @fields = qw(daytime night fax);
   push @fields, qw(ship_daytime ship_night ship_fax)
 
   my @fields = qw(daytime night fax);
   push @fields, qw(ship_daytime ship_night ship_fax)
@@ -650,7 +657,7 @@ sub phonesearch {
   for my $field ( @fields ) {
     push @cust_main, qsearch ( 'cust_main', 
                                { $field => { 'op'    => 'LIKE',
   for my $field ( @fields ) {
     push @cust_main, qsearch ( 'cust_main', 
                                { $field => { 'op'    => 'LIKE',
-                                             'value' => "$phone%" } } );
+                                             'value' => "%$phone%" } } );
   }
 
   \@cust_main;
   }
 
   \@cust_main;
index 0610bc3..707de8d 100755 (executable)
@@ -370,6 +370,9 @@ foreach my $package (@packages) {
         qq!$pkg - $comment (&nbsp;<a href="$pkgview">Details</a>&nbsp;)!;
        # | !;
 
         qq!$pkg - $comment (&nbsp;<a href="$pkgview">Details</a>&nbsp;)!;
        # | !;
 
+  print qq! (&nbsp;<A HREF="${p}misc/change_pkg.cgi?$pkgnum">!.
+        'Change&nbsp;package</A>&nbsp;)';
+
   #false laziness with view/cust_pkg.cgi, but i'm trying to make that go away so
   unless ( $package->getfield('cancel') ) {
     print ' (&nbsp;';
   #false laziness with view/cust_pkg.cgi, but i'm trying to make that go away so
   unless ( $package->getfield('cancel') ) {
     print ' (&nbsp;';