WebPAC cgi will now set it's own locale (using configuration directive in
authorDobrica Pavlinusic <dpavlin@rot13.org>
Sun, 13 Mar 2005 02:00:35 +0000 (02:00 +0000)
committerDobrica Pavlinusic <dpavlin@rot13.org>
Sun, 13 Mar 2005 02:00:35 +0000 (02:00 +0000)
global.conf)

git-svn-id: file:///home/dpavlin/private/svn/webpac/trunk@696 13eb9ef6-21d5-0310-b721-a9d68796d827

WebPac.pm
global.conf
index_DBI_filter.pm

index 0fe8791..680cc5b 100644 (file)
--- a/WebPac.pm
+++ b/WebPac.pm
@@ -10,6 +10,7 @@ use DBI;
 use Config::IniFiles;
 use Text::Unaccent;
 use Data::Pageset;
+use POSIX qw(locale_h);
 
 use lib '..';
 use index_DBI_filter;
@@ -32,11 +33,15 @@ my $UNAC_FILTER =$cfg_global->val('global', 'my_unac_filter');
 my $BASE_PATH =$cfg_global->val('webpac', 'base_path');
 # for pager
 my $pages_per_set = $cfg_global->val('webpac', 'pages_per_set') || 10;
+my $locale = $cfg_global->val('locale') || 'hr_HR';
 
 Text::Iconv->raise_error(0);     # Conversion errors raise exceptions
 
 my $from_utf8 = Text::Iconv->new('UTF8', $CHARSET);
 
+setlocale(LC_CTYPE, $locale);
+setlocale(LC_COLLATE, $locale);
+
 if ($UNAC_FILTER) {
        require $UNAC_FILTER;
 } else {
index 619400e..485fee7 100644 (file)
@@ -26,6 +26,8 @@
        template_html = /data/webpac/template_html
        # charset encoding for template file *and* users (default iso-8859-1)
        charset = ISO-8859-2
+       # locale to use (for sorting, uc/lc) (default hr_HR)
+       locale = hr_HR
        # path to swish binary (default /usr/bin/swish-e)
        swish = /usr/bin/swish-e
        # path to index file
index 566ec76..98ce339 100644 (file)
@@ -11,10 +11,9 @@ use strict qw(vars);
 use vars qw($Count);
 use HTML::Entities;
 use URI::Escape;
-use locale;
 use Carp;
-
 use DBI;
+use locale;
 
 # bench time
 my $bench_time = time();
@@ -103,7 +102,7 @@ sub insert {
 
        if (! $self->{c}->{$uc}->{$field}) {
 #print stderr "in index: $index_data\n";
-               $self->{c}->{$uc}->{$field}->{item} = $index_data;
+               $self->{c}->{$uc}->{$field}->{item} = lc($index_data);
                $self->{c}->{$uc}->{$field}->{display} = $display;
        }
 
@@ -121,7 +120,7 @@ sub count {
 
        my $tables_sql = 'data';
        my $where_sql = '';
-       my @sql_args = ( $field, $where );
+       my @sql_args = ( $field, lc($where) );
 
        if ($filter) {
                $tables_sql .= ",filters";
@@ -135,7 +134,7 @@ sub count {
        my $sql = qq{
                select count(*)
                from $tables_sql
-               where name = ? and upper(item) like upper(?)||'%'
+               where name = ? and item like ?||'%'
                $where_sql
        };
 
@@ -181,7 +180,7 @@ sub fetch {
        my $tables_sql = 'data';
        my $where_sql = '';
 
-       my @sql_args = ( $field, $where );
+       my @sql_args = ( $field, lc($where) );
 
        if ($filter) {
                $tables_sql .= ",filters";
@@ -196,29 +195,31 @@ sub fetch {
                my $sql2 = qq{
                        select data.ord as ord
                        from $tables_sql
-                       where name = ? and upper(item) like upper(?)||'%'
+                       where name = ? and item like ?||'%'
                        $where_sql
+                       order by data.ord
                };
                my $sth = $self->{dbh}->prepare($sql2) || confess "sql2: $sql2; ".$self->{dbh}->errstr();
 
                $sth->execute(@sql_args) || confess "sql2: $sql2; ".$self->{dbh}->errstr();
                if (my $row = $sth->fetchrow_hashref) {
-                       $from_ord += $row->{ord} - 1;
+                       $from_ord = $row->{ord} - 1;
                } else {
                        # if no match is found when searching from beginning
                        # of word in index, try substring match anywhere
                        $sql2 = qq{
                                select data.ord as ord
                                from $tables_sql
-                               where name = ? and upper(item) like '% '||upper(?)||'%'
+                               where name = ? and item like '%'||?||'%'
                                $where_sql
+                               order by data.ord
                        };
        
                        $sth = $self->{dbh}->prepare($sql2) || confess "sql2: $sql2; ".$self->{dbh}->errstr();
                        $sth->execute(@sql_args) || confess "sql2: $sql2; ".$self->{dbh}->errstr();
 
                        if (my $row = $sth->fetchrow_hashref) {
-                               $from_ord += $row->{ord} - 1;
+                               $from_ord = $row->{ord} - 1;
                        }
                }
        }