working message catalogs (not used for enough yet)
authorivan <ivan>
Sun, 7 Apr 2002 05:56:09 +0000 (05:56 +0000)
committerivan <ivan>
Sun, 7 Apr 2002 05:56:09 +0000 (05:56 +0000)
- almost (but not quite) closes Bug#385 - still have to catalog the
  backend things triggered by signup server.

FS/FS/Conf.pm
FS/FS/msgcat.pm
bin/populate-msgcat
conf/show-msgcat-codes [new file with mode: 0644]
fs_signup/FS-SignupClient/cgi/signup.cgi
fs_signup/fs_signup_server
httemplate/browse/msgcat.cgi
httemplate/docs/install.html
httemplate/edit/msgcat.cgi [new file with mode: 0755]
httemplate/edit/process/msgcat.cgi [new file with mode: 0644]

index b39c821..6e58820 100644 (file)
@@ -873,6 +873,12 @@ httemplate/docs/config.html
     'select_enum' => [ qw(CARD PREPAY BILL COMP) ],
   },
 
+  {
+    'key'         => 'show-msgcat-codes',
+    'section'     => 'UI',
+    'description' => 'Show msgcat codes in error messages.  Turn this option on before reporting errors to the mailing list.',
+    'type'        => 'checkbox',
+  },
 
 );
 
index 53a7aee..3eca14b 100644 (file)
@@ -1,7 +1,7 @@
 package FS::msgcat;
 
 use strict;
-use vars qw( @ISA @EXPORT_OK $conf $locale );
+use vars qw( @ISA @EXPORT_OK $conf $locale $debug );
 use Exporter;
 use FS::UID;
 use FS::Record qw( qsearchs );
@@ -13,6 +13,7 @@ use FS::Conf;
 $FS::UID::callback{'msgcat'} = sub {
   $conf = new FS::Conf;
   $locale = $conf->config('locale') || 'en_US';
+  $debug = $conf->exists('show-msgcat-codes')
 };
 
 =head1 NAME
@@ -140,6 +141,10 @@ Returns the full message for the supplied message code.
 =cut
 
 sub gettext {
+  $debug ? geterror(@_) : _gettext(@_);
+}
+
+sub _gettext {
   my $msgcode = shift;
   my $msgcat = qsearchs('msgcat', {
     'msgcode' => $msgcode,
@@ -163,7 +168,7 @@ code.
 
 sub geterror {
   my $msgcode = shift;
-  my $msg = gettext($msgcode);
+  my $msg = _gettext($msgcode);
   if ( $msg eq $msgcode ) {
     "Error code $msgcode (message for locale $locale not found)";
   } else {
@@ -175,7 +180,7 @@ sub geterror {
 
 =head1 BUGS
 
-i18n/l10n is a mess.
+i18n/l10n, eek
 
 =head1 SEE ALSO
 
index fa88732..51f04c1 100755 (executable)
@@ -1,23 +1,26 @@
-#!/usr/bin/perl
+#!/usr/bin/perl -Tw
 
+use strict;
 use FS::UID qw(adminsuidsetup);
+use FS::Record qw(qsearch);
 use FS::msgcat;
 
 my $user = shift or die &usage;
 adminsuidsetup $user;
 
-foreach my $del_msgcat ( qsearchs('msgcat', {}) ) {
+foreach my $del_msgcat ( qsearch('msgcat', {}) ) {
   my $error = $del_msgcat->delete;
   die $error if $error;
 }
 
 my %messages = messages();
 
-foreach $msgcode ( keys %messages ) {
+foreach my $msgcode ( keys %messages ) {
   foreach my $locale ( keys %{$messages{$msgcode}} ) {
     my $msgcat = new FS::msgcat( {
       'msgcode' => $msgcode,
       'locale'  => $locale,
+      'msg'     => $messages{$msgcode}{$locale},
     });
     my $error = $msgcat->insert;
     die $error if $error;
@@ -32,8 +35,20 @@ sub messages {
 
   (
 
-    'msgcode' => {
-      'en_US' => 'Message',
+    'passwords_dont_match' => {
+      'en_US' => "Passwords don't match",
+    },
+
+    'invalid_card' => {
+      'en_US' => 'Invalid credit card number',
+    },
+
+    'unknown_card_type' => {
+      'en_US' => 'Unknown card type',
+    },
+
+    'not_a' => {
+      'en_US' => 'Not a ',
     },
 
   );
diff --git a/conf/show-msgcat-codes b/conf/show-msgcat-codes
new file mode 100644 (file)
index 0000000..e69de29
index 7cf4230..46621d1 100755 (executable)
@@ -1,6 +1,6 @@
 #!/usr/bin/perl -Tw
 #
-# $Id: signup.cgi,v 1.18 2002-04-07 00:00:40 ivan Exp $
+# $Id: signup.cgi,v 1.19 2002-04-07 05:56:08 ivan Exp $
 
 use strict;
 use vars qw( @payby $cgi $locales $packages $pops $init_data $error
@@ -120,15 +120,22 @@ if ( defined $cgi->param('magic') ) {
     $error = '';
 
     if ( $cgi->param('_password') ne $cgi->param('_password2') ) {
-      $error = "Passwords don't match"; #msgcat
+      $error = $init_data->{msgcat}{passwords_dont_match}; #msgcat
       $password  = '';
       $password2 = '';
     } else {
       $password2 = $cgi->param('_password2');
 
-      if ( $payby eq 'CARD' && $cgi->param('CARD_type')
-           && cardtype($payinfo) ne $cgi->param('CARD_type') ) {
-        $error = 'Not an '. $cgi->param('CARD_type'). '| - is: |'. cardtype($payinfo). '|'; #msgcat
+      if ( $payby eq 'CARD' && $cgi->param('CARD_type') ) {
+        $payinfo =~ s/\D//g;
+
+        $payinfo =~ /^(\d{13,16})$/
+          or $error ||= $init_data->{msgcat}{invalid_card}; #. $self->payinfo;
+        $payinfo = $1;
+        validate($payinfo)
+          or $error ||= $init_data->{msgcat}{invalid_card}; #. $self->payinfo;
+        cardtype($payinfo) eq $cgi->param('CARD_type')
+          or $error ||= $init_data->{msgcat}{not_a}. $cgi->param('CARD_type');
       }
 
       $error ||= new_customer ( {
index b902d9f..f3030e9 100755 (executable)
@@ -13,6 +13,7 @@ use FS::Conf;
 use FS::Record qw( qsearch qsearchs );
 use FS::cust_main_county;
 use FS::cust_main;
+use FS::msgcat qw(gettext);
 
 use vars qw( $opt $Debug );
 
@@ -67,6 +68,10 @@ while (1) {
 
     'payby' => [ $conf->config('signup_server-payby') ],
 
+    'msgcat' => { map { $_=>gettext($_) } qw(
+      passwords_dont_match invalid_card unknown_card_type not_a
+    ) }
+
   };
 
   warn "[fs_signup_server] Sending init data...\n" if $Debug;
index 5dab5cf..774473b 100755 (executable)
@@ -18,8 +18,8 @@ my $widget = new HTML::Widgets::SelectLayers(
     $html .= '</TR>';
 
     #foreach my $msgcat ( sort { $a->msgcode cmp $b->msgcode }
-    #                       qsearchs('msgcat', { 'locale' => $layer } ) ) {
-    foreach my $msgcat ( qsearchs('msgcat', { 'locale' => $layer } ) ) {
+    #                       qsearch('msgcat', { 'locale' => $layer } ) ) {
+    foreach my $msgcat ( qsearch('msgcat', { 'locale' => $layer } ) ) {
       $html .= '<TR><TD>'. $msgcat->msgnum. '</TD>'.
                '<TD>'. $msgcat->msgcode. '</TD>'.
                '<TD>'. $msgcat->msg. '</TD>';
index 2ad75b1..4870c7d 100644 (file)
@@ -181,6 +181,11 @@ $ <a href="man/bin/freeside-adduser.html">freeside-adduser</a> -h /usr/local/etc
 $ su freeside
 $ bin/fs-setup <b>username</b>
 </pre>
+  <li>As the freeside UNIX user, run <tt>bin/populate-msgcat <b>username</b></tt> to populate the message catalog, passing the username of a Freeside user you created above:
+<pre>
+$ su freeside
+$ bin/populate-msgcat <b>username</b>
+</pre>
   <li><tt>freeside-queued</tt> was installed with the Perl modules.  Start it now and ensure that is run upon system startup.
   <li>Now proceed to the initial <a href="admin.html">administration</a> of your installation.
 </ul>
diff --git a/httemplate/edit/msgcat.cgi b/httemplate/edit/msgcat.cgi
new file mode 100755 (executable)
index 0000000..5d256c0
--- /dev/null
@@ -0,0 +1,57 @@
+<!-- mason kludge -->
+<%
+
+print header("Message catalog", menubar(
+#  'Main Menu' => $p,
+)), '<BR>';
+
+print qq!<FONT SIZE="+1" COLOR="#ff0000">Error: !. $cgi->param('error')
+  if $cgi->param('error');
+
+my $widget = new HTML::Widgets::SelectLayers(
+  'selected_layer' => 'en_US',
+  'options'        => { 'en_US'=>'en_US' },
+  'form_action'    => 'process/msgcat.cgi',
+  'layer_callback' => sub {
+    my $layer = shift;
+    my $html = qq!<INPUT TYPE="hidden" NAME="locale" VALUE="$layer">!.
+               "<BR>Messages for locale $layer<BR>". table().
+               "<TR><TH COLSPAN=2>Code</TH>".
+               "<TH>Message</TH>";
+    $html .= "<TH>en_US Message</TH>" unless $layer eq 'en_US';
+    $html .= '</TR>';
+
+    #foreach my $msgcat ( sort { $a->msgcode cmp $b->msgcode }
+    #                       qsearch('msgcat', { 'locale' => $layer } ) ) {
+    foreach my $msgcat ( qsearch('msgcat', { 'locale' => $layer } ) ) {
+      $html .=
+        '<TR><TD>'. $msgcat->msgnum. '</TD><TD>'. $msgcat->msgcode. '</TD>'.
+        '<TD><INPUT TYPE="text" SIZE=32 '.
+        qq! NAME="!. $msgcat->msgnum. '" '.
+        qq!VALUE="!. $msgcat->msg. qq!"></TD>!;
+      unless ( $layer eq 'en_US' ) {
+        my $en_msgcat = qsearchs('msgcat', {
+          'locale'  => 'en_US',
+          'msgcode' => $msgcat->msgcode,
+        } );
+        $html .= '<TD>'. $en_msgcat->msg. '</TD>';
+      }
+      $html .= '</TR>';
+    }
+
+    $html .= '</TABLE><BR><INPUT TYPE="submit" VALUE="Apply changes">';
+
+    $html;
+  },
+
+);
+
+print $widget->html;
+
+print <<END;
+    </TABLE>
+  </BODY>
+</HTML>
+END
+
+%>
diff --git a/httemplate/edit/process/msgcat.cgi b/httemplate/edit/process/msgcat.cgi
new file mode 100644 (file)
index 0000000..ab30f06
--- /dev/null
@@ -0,0 +1,19 @@
+<%
+
+my $error;
+foreach my $param ( grep { /^\d+$/ } $cgi->param ) {
+  my $old = qsearchs('msgcat', { msgnum=>$param } );
+  my $new = new FS::msgcat { $old->hash };
+  $new->msg($cgi->param($param));
+  $error = $new->replace($old);
+  last if $error;
+}
+
+if ( $error ) {
+  $cgi->param('error',$error);
+  print $cgi->redirect($p. "msgcat.cgi?". $cgi->query_string );
+} else {
+  print $cgi->redirect(popurl(3). "browse/msgcat.cgi");
+}
+
+%>