Moved C4/Charset.pm to C4/Interface/CGI/Output.pm
authoracli <acli>
Sun, 2 Feb 2003 07:18:37 +0000 (07:18 +0000)
committeracli <acli>
Sun, 2 Feb 2003 07:18:37 +0000 (07:18 +0000)
Create output_html_with_http_headers function to contain the "print $query
->header(-type => guesstype...),..." call. This is in preparation for
non-HTML output (e.g., text/xml) and charset conversion before output in
the future.

Created C4/Interface/CGI/Template.pm to hold convenience functions specific
to the CGI interface using HTML::Template

Modified moremembers.pl to make the "sex" field localizable for languages
where M and F doesn't make sense

54 files changed:
C4/Interface/CGI/Output.pm [new file with mode: 0644]
C4/Interface/CGI/Template.pm [new file with mode: 0644]
MARCdetail.pl
acqui.simple/addbiblio.pl
acqui.simple/addbooks.pl
acqui.simple/additem.pl
acqui.simple/isbnsearch.pl
acqui.simple/marcimport.pl
acqui/newbasket2.pl
admin-home.pl
admin/aqbookfund.pl
admin/aqbudget.pl
admin/authorised_values.pl
admin/branches.pl
admin/checkmarc.pl
admin/koha2marclinks.pl
admin/marc_subfields_structure.pl
admin/marctagstructure.pl
admin/systempreferences.pl
admin/thesaurus.pl
boraccount.pl
catalogue-home.pl
circ/branchtransfers.pl
detail.pl
jmemberentry.pl
koha-tmpl/intranet-tmpl/default/zh-TW/members/moremember.tmpl
mainpage.pl
mancredit.pl
maninvoice.pl
member.pl
memberentry.pl
members-home.pl
moremember.pl
newmember.pl
opac/opac-account.pl
opac/opac-detail.pl
opac/opac-main.pl
opac/opac-membership.pl
opac/opac-readingrecord.pl
opac/opac-reserve.pl
opac/opac-search.pl
opac/opac-searchresults.pl
opac/opac-sidebar.pl
opac/opac-user.pl
opac/opac-userdetails.pl
opac/opac-userupdate.pl
readingrec.pl
reports-home.pl
search.marc/search.pl
search.pl
shelves.pl
t/Charset.t
thesaurus_popup.pl
userpage.pl

diff --git a/C4/Interface/CGI/Output.pm b/C4/Interface/CGI/Output.pm
new file mode 100644 (file)
index 0000000..379f3d9
--- /dev/null
@@ -0,0 +1,128 @@
+package C4::Interface::CGI::Output;
+
+# $Id$
+
+#package to work around problems in HTTP headers
+# Note: This is just a utility module; it should not be instantiated.
+
+
+# Copyright 2003 Katipo Communications
+#
+# This file is part of Koha.
+#
+# Koha is free software; you can redistribute it and/or modify it under the
+# terms of the GNU General Public License as published by the Free Software
+# Foundation; either version 2 of the License, or (at your option) any later
+# version.
+#
+# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along with
+# Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
+# Suite 330, Boston, MA  02111-1307 USA
+
+use strict;
+require Exporter;
+
+use vars qw($VERSION @ISA @EXPORT);
+
+# set the version for version checking
+$VERSION = 0.01;
+
+=head1 NAME
+
+C4::CGI::Output - Convenience functions for handling outputting HTML pages
+
+=head1 SYNOPSIS
+
+  use C4::CGI::Output;
+
+  print $query->header(-type => C4::CGI::Output::gettype($output)), $output;
+
+=head1 DESCRIPTION
+
+The functions in this module peek into a piece of HTML and return strings
+related to the (guessed) charset.
+
+=head1 FUNCTIONS
+
+=over 2
+
+=cut
+
+@ISA = qw(Exporter);
+@EXPORT = qw(
+               &guesscharset
+               &guesstype
+               &output_html_with_http_headers
+            );
+
+=item guesscharset
+
+   &guesscharset($output)
+
+"Guesses" the charset from the some HTML that would be output.
+
+C<$output> is the HTML page to be output. If it contains a META tag
+with a Content-Type, the tag will be scanned for a language code.
+This code is returned if it is found; undef is returned otherwise.
+
+This function only does sloppy guessing; it will be confused by
+unexpected things like SGML comments. What it basically does is to
+grab something that looks like a META tag and scan it.
+
+=cut
+
+sub guesscharset ($) {
+    my($html) = @_;
+    my $charset = undef;
+    local($`, $&, $', $1, $2, $3);
+    # FIXME... These regular expressions will miss a lot of valid tags!
+    if ($html =~ /<meta\s+http-equiv=(["']?)Content-Type\1\s+content=(["'])text\/html\s*;\s*charset=([^\2\s\r\n]+)\2\s*(?:\/?)>/is) {
+        $charset = $3;
+    } elsif ($html =~ /<meta\s+content=(["'])text\/html\s*;\s*charset=([^\1\s\r\n]+)\1\s+http-equiv=(["']?)Content-Type\3\s*(?:\/?)>/is) {
+        $charset = $2;
+    }
+    return $charset;
+} # guess
+
+sub guesstype ($) {
+    my($html) = @_;
+    my $charset = guesscharset($html);
+    return defined $charset? "text/html; charset=$charset": "text/html";
+}
+
+=item output_html_with_http_headers
+
+   &output_html_with_http_headers($query, $cookie, $html)
+
+Outputs the HTML page $html with the appropriate HTTP headers,
+with the authentication cookie $cookie and a Content-Type that
+corresponds to the HTML page $html.
+
+=cut
+
+sub output_html_with_http_headers ($$$) {
+    my($query, $cookie, $html) = @_;
+    print $query->header(
+       -type   => guesstype($html),
+       -cookie => $cookie,
+    ), $html;
+}
+
+#---------------------------------
+
+END { }       # module clean-up code here (global destructor)
+
+1;
+__END__
+
+=back
+
+=head1 AUTHOR
+
+Koha Developement team <info@koha.org>
+
+=cut
diff --git a/C4/Interface/CGI/Template.pm b/C4/Interface/CGI/Template.pm
new file mode 100644 (file)
index 0000000..74bea2f
--- /dev/null
@@ -0,0 +1,90 @@
+package C4::Interface::CGI::Template;
+
+# $Id$
+
+# convenience package for HTML templating
+# Note: This is just a utility module; it should not be instantiated.
+
+
+# Copyright 2003 Katipo Communications
+#
+# This file is part of Koha.
+#
+# Koha is free software; you can redistribute it and/or modify it under the
+# terms of the GNU General Public License as published by the Free Software
+# Foundation; either version 2 of the License, or (at your option) any later
+# version.
+#
+# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along with
+# Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
+# Suite 330, Boston, MA  02111-1307 USA
+
+use strict;
+require Exporter;
+
+use vars qw($VERSION @ISA @EXPORT);
+
+# set the version for version checking
+$VERSION = 0.01;
+
+=head1 NAME
+
+C4::Members - Convenience functions for using HTML::Template
+
+=head1 SYNOPSIS
+
+  use C4::Interface::HTML::Template;
+
+=head1 DESCRIPTION
+
+The functions in this module peek into a piece of HTML and return strings
+related to the (guessed) charset.
+
+=head1 FUNCTIONS
+
+=over 2
+
+=cut
+
+@ISA = qw(Exporter);
+@EXPORT = qw(
+               &expand_sex_into_predicate
+            );
+
+=item expand_sex_into_predicate
+
+  $data{&expand_sex_into_predicate($data{sex})} = 1;
+
+Converts a single 'M' or 'F' into 'sex_M_p' or 'sex_F_p'
+respectively.
+
+In some languages, 'M' and 'F' are not appropriate. However,
+with HTML::Template, there is no way to localize 'M' or 'F'
+unless these are converted into variables that TMPL_IF can
+understand. This function provides this conversion.
+
+=cut
+
+sub expand_sex_into_predicate ($) {
+   my($sex) = @_;
+   return "sex_${sex}_p";
+} # expand_sex_into_predicate
+
+#---------------------------------
+
+END { }       # module clean-up code here (global destructor)
+
+1;
+__END__
+
+=back
+
+=head1 AUTHOR
+
+Koha Developement team <info@koha.org>
+
+=cut
index a1573b2..eac610c 100755 (executable)
@@ -50,6 +50,7 @@ require Exporter;
 use C4::Auth;
 use C4::Context;
 use C4::Output;
+use C4::Interface::CGI::Output;
 use CGI;
 use C4::Search;
 use MARC::Record;
@@ -160,8 +161,5 @@ $template->param(item_loop => \@item_value_loop,
                                                item_header_loop => \@header_value_loop,
                                                biblionumber => $biblionumber,
                                                bibid => $bibid);
-print $query->header(
-    -type => guesstype($template->output),
-    -cookie => $cookie
-),$template->output;
+output_html_with_http_headers $query, $cookie, $template->output;
 
index ee52c4f..200198f 100755 (executable)
@@ -23,7 +23,7 @@ use strict;
 use CGI;
 use C4::Auth;
 use C4::Output;
-use C4::Charset;
+use C4::Interface::CGI::Output;
 use C4::Biblio;
 use C4::Context;
 use HTML::Template;
@@ -306,7 +306,4 @@ if ($op eq "addbiblio") {
                                                        oldbiblioitemnumtagsubfield => $oldbiblioitemnumtagsubfield,
                                                        oldbiblioitemnumber => $oldbiblioitemnumber);
 }
-print $input->header(
-    -type => guesstype($template->output),
-    -cookie => $cookie
-),$template->output;
+output_html_with_http_headers $input, $cookie, $template->output;
index e566cdd..5b76d39 100755 (executable)
@@ -39,7 +39,7 @@ use C4::Auth;
 use C4::Catalogue;
 use C4::Biblio;
 use C4::Output;
-use C4::Charset;
+use C4::Interface::CGI::Output;
 use HTML::Template;
 
 my $query = new CGI;
@@ -54,7 +54,4 @@ my ($template, $loggedinuser, $cookie)
                             flagsrequired => {catalogue => 1},
                             debug => 1,
                             });
-print $query->header(
-    -type => guesstype($template->output),
-    -cookie => $cookie
-),$template->output;
+output_html_with_http_headers $query, $cookie, $template->output;
index 86dd779..1ed08bd 100755 (executable)
@@ -23,7 +23,7 @@ use CGI;
 use strict;
 use C4::Auth;
 use C4::Output;
-use C4::Charset;
+use C4::Interface::CGI::Output;
 use C4::Biblio;
 use C4::Context;
 use HTML::Template;
@@ -251,7 +251,4 @@ $template->param(item_loop => \@item_value_loop,
                                                itemtagsubfield =>$itemtagsubfield,
                                                op => $nextop,
                                                opisadd => ($nextop eq "saveitem")?0:1);
-print $input->header(
-    -type => guesstype($template->output),
-    -cookie => $cookie
-),$template->output;
+output_html_with_http_headers $input, $cookie, $template->output;
index 1ef6ed8..2846799 100755 (executable)
@@ -25,7 +25,7 @@ use C4::Catalogue;
 use C4::Biblio;
 use C4::Search;
 use C4::Output;
-use C4::Charset;
+use C4::Interface::CGI::Output;
 use HTML::Template;
 
 my $input      = new CGI;
index b8bae89..34930ef 100755 (executable)
@@ -36,7 +36,7 @@ use DBI;
 # Koha modules used
 use C4::Context;
 use C4::Output;
-use C4::Charset;
+use C4::Interface::CGI::Output;
 use C4::Input;
 use C4::Biblio;
 use MARC::File::USMARC;
@@ -150,10 +150,7 @@ if ($uploadmarc && length($uploadmarc)>0) {
 
 }
 
-print $input->header(
-    -type => guesstype($template->output),
-    -cookie => $cookie
-),$template->output;
+output_html_with_http_headers $input, $cookie, $template->output;
 my $menu;
 my $file;
 
@@ -809,6 +806,20 @@ sub FormatMarcText {
 #---------------
 # log cleared, as marcimport is (almost) rewritten from scratch.
 # $Log$
+# Revision 1.30  2003/02/02 07:18:38  acli
+# Moved C4/Charset.pm to C4/Interface/CGI/Output.pm
+#
+# Create output_html_with_http_headers function to contain the "print $query
+# ->header(-type => guesstype...),..." call. This is in preparation for
+# non-HTML output (e.g., text/xml) and charset conversion before output in
+# the future.
+#
+# Created C4/Interface/CGI/Template.pm to hold convenience functions specific
+# to the CGI interface using HTML::Template
+#
+# Modified moremembers.pl to make the "sex" field localizable for languages
+# where M and F doesn't make sense
+#
 # Revision 1.29  2003/01/28 15:28:31  tipaul
 # removing use MARC::Charset
 # Was a buggy test
index 104e96a..741b5f4 100755 (executable)
@@ -28,7 +28,7 @@ use C4::Catalogue;
 use C4::Biblio;
 use HTML::Template;
 use C4::Auth;
-use C4::Charset;
+use C4::Interface::CGI::Output;
 
 my $env;
 my $input = new CGI;
@@ -246,7 +246,4 @@ $template->param(   bookselname => $booksellers[0]->{'name'},
                                                                loopsearch =>\@loopsearch,
                                                                loopresult =>\@loopresult);
 
-print $input->header(
--type => guesstype($template->output),
--cookie => $cookie
-),$template->output;
+output_html_with_http_headers $input, $cookie, $template->output;
index 779883a..a71467c 100755 (executable)
@@ -4,7 +4,7 @@ use strict;
 use CGI;
 use C4::Auth;
 use C4::Output;
-use C4::Charset;
+use C4::Interface::CGI::Output;
 use C4::Database;
 use HTML::Template;
 
@@ -19,7 +19,4 @@ my ($template, $loggedinuser, $cookie)
                             });
 $template->param(loggeninuser => $loggedinuser);
 
-print $query->header(
-    -type => guesstype($template->output),
-    -cookie => $cookie
-),$template->output;
+output_html_with_http_headers $query, $cookie, $template->output;
index ed16af7..63335ab 100755 (executable)
@@ -42,7 +42,7 @@ use CGI;
 use C4::Auth;
 use C4::Context;
 use C4::Output;
-use C4::Charset;
+use C4::Interface::CGI::Output;
 use C4::Search;
 use HTML::Template;
 
@@ -206,7 +206,4 @@ if ($op eq 'add_form') {
        $template->param(bookfund => \@loop_data);
 } #---- END $OP eq DEFAULT
 
-print $input->header(
-    -type => guesstype($template->output),
-    -cookie => $cookie
-), $template->output;
+output_html_with_http_headers $input, $cookie, $template->output;
index 2989314..29b98b9 100755 (executable)
@@ -42,7 +42,7 @@ use CGI;
 use C4::Auth;
 use C4::Context;
 use C4::Output;
-use C4::Charset;
+use C4::Interface::CGI::Output;
 use C4::Search;
 use HTML::Template;
 
@@ -227,8 +227,5 @@ if ($op eq 'add_form') {
        $template->param(budget => \@loop_data);
 } #---- END $OP eq DEFAULT
 
-print $input->header(
-    -type => guesstype($template->output),
-    -cookie => $cookie
-), $template->output;
+output_html_with_http_headers $input, $cookie, $template->output;
 
index b36c3f0..24fbc96 100755 (executable)
@@ -22,7 +22,7 @@ use CGI;
 use C4::Auth;
 use C4::Context;
 use C4::Output;
-use C4::Charset;
+use C4::Interface::CGI::Output;
 use C4::Search;
 use HTML::Template;
 use C4::Context;
@@ -189,7 +189,4 @@ if ($op eq 'add_form') {
        }
 } #---- END $OP eq DEFAULT
 
-print $input->header(
-    -type => guesstype($template->output),
-    -cookie => $cookie
-), $template->output;
+output_html_with_http_headers $input, $cookie, $template->output;
index 7094bf7..c6d0ea0 100755 (executable)
@@ -26,7 +26,7 @@ use CGI;
 use C4::Auth;
 use C4::Context;
 use C4::Output;
-use C4::Charset;
+use C4::Interface::CGI::Output;
 use HTML::Template;
 
 # Fixed variables
@@ -377,7 +377,4 @@ sub checkdatabasefor {
     return $message;
 }
 
-print $input->header(
-    -type => guesstype($template->output),
-    -cookie => $cookie
-), $template->output;
+output_html_with_http_headers $input, $cookie, $template->output;
index b6cc8dc..359fc35 100755 (executable)
@@ -20,7 +20,7 @@
 
 use strict;
 use C4::Output;
-use C4::Charset;
+use C4::Interface::CGI::Output;
 use C4::Auth;
 use CGI;
 use C4::Search;
@@ -121,7 +121,4 @@ if ($res && $res2 eq 10 && $field eq "branches") {
 }
 
 $template->param(total => $total);
-print $input->header(
-    -type => guesstype($template->output),
-    -cookie => $cookie
-), $template->output;
+output_html_with_http_headers $input, $cookie, $template->output;
index 070e44b..72d153a 100755 (executable)
@@ -20,7 +20,7 @@
 
 use strict;
 use C4::Output;
-use C4::Charset;
+use C4::Interface::CGI::Output;
 use C4::Auth;
 use CGI;
 use C4::Search;
@@ -135,7 +135,4 @@ if ($op eq 'add_form') {
                                                        );
 } #---- END $OP eq DEFAULT
 
-print $input->header(
-    -type => guesstype($template->output),
-    -cookie => $cookie
-), $template->output;
+output_html_with_http_headers $input, $cookie, $template->output;
index 67facc2..c0284af 100755 (executable)
@@ -20,7 +20,7 @@
 
 use strict;
 use C4::Output;
-use C4::Charset;
+use C4::Interface::CGI::Output;
 use C4::Auth;
 use CGI;
 use C4::Search;
@@ -347,7 +347,4 @@ if ($op eq 'add_form') {
        }
 } #---- END $OP eq DEFAULT
 
-print $input->header(
-    -type => guesstype($template->output),
-    -cookie => $cookie
-), $template->output;
+output_html_with_http_headers $input, $cookie, $template->output;
index 52caa5f..2bd72d4 100755 (executable)
@@ -23,7 +23,7 @@ use CGI;
 use C4::Auth;
 use C4::Context;
 use C4::Output;
-use C4::Charset;
+use C4::Interface::CGI::Output;
 use C4::Search;
 use C4::Context;
 use HTML::Template;
@@ -197,7 +197,4 @@ if ($op eq 'add_form') {
 } #---- END $OP eq DEFAULT
 
 $template->param(loggeninuser => $loggedinuser);
-print $input->header(
-    -type => guesstype($template->output),
-    -cookie => $cookie
-), $template->output;
+output_html_with_http_headers $input, $cookie, $template->output;
index 332657c..6a2ce37 100755 (executable)
@@ -42,7 +42,7 @@ use CGI;
 use C4::Auth;
 use C4::Context;
 use C4::Output;
-use C4::Charset;
+use C4::Interface::CGI::Output;
 use C4::Search;
 use HTML::Template;
 use C4::Context;
@@ -185,7 +185,4 @@ if ($op eq 'add_form') {
        }
 } #---- END $OP eq DEFAULT
 
-print $input->header(
-    -type => guesstype($template->output),
-    -cookie => $cookie
-), $template->output;
+output_html_with_http_headers $input, $cookie, $template->output;
index 4ceb41f..d838c48 100755 (executable)
@@ -20,7 +20,7 @@
 use strict;
 use CGI;
 use C4::Auth;
-use C4::Charset;
+use C4::Interface::CGI::Output;
 use C4::Context;
 use C4::Output;
 use C4::Search;
@@ -256,7 +256,4 @@ if ($op eq 'add_form') {
        }
 } #---- END $OP eq DEFAULT
 
-print $input->header(
-    -type => guesstype($template->output),
-    -cookie => $cookie
-), $template->output;
+output_html_with_http_headers $input, $cookie, $template->output;
index 024e0f7..b30ef5d 100755 (executable)
@@ -26,7 +26,7 @@
 use strict;
 use C4::Auth;
 use C4::Output;
-use C4::Charset;
+use C4::Interface::CGI::Output;
 use CGI;
 use C4::Search;
 use HTML::Template;
@@ -79,7 +79,4 @@ $template->param(
                        total           => $total,
                        accounts        => \@accountrows );
 
-print $input->header(
-   -type => guesstype($template->output),
-   -cookie => $cookie
-),$template->output;
+output_html_with_http_headers $input, $cookie, $template->output;
index 95ae211..39e95d4 100755 (executable)
@@ -4,7 +4,7 @@ use strict;
 use CGI;
 use C4::Auth;
 use C4::Output;
-use C4::Charset;
+use C4::Interface::CGI::Output;
 use C4::Database;
 use HTML::Template;
 
@@ -27,7 +27,4 @@ $template->param(loggedinuser => $loggedinuser,
                                                classlist => $classlist,
                                                type => 'intranet',);
 
-print $query->header(
-    -type => guesstype($template->output),
-    -cookie => $cookie
-), $template->output;
+output_html_with_http_headers $query, $cookie, $template->output;
index c895a94..9c87e5a 100755 (executable)
@@ -282,7 +282,7 @@ $template->param(   genbrname => $genbrname,
                                                                branchoptionloop => \@branchoptionloop,
                                                                errmsgloop => \@errmsgloop
                                                        );
-print $query->header(-cookie=>$sessioncookie), $template->output;
+output_html_with_http_headers $query, $sessioncookie, $template->output;
 
 
 sub name {
index d39c182..5c8a7bc 100755 (executable)
--- a/detail.pl
+++ b/detail.pl
@@ -93,5 +93,5 @@ $template->param(ITEM_RESULTS => $itemsarray);
 $template->param(WEB_RESULTS => $webarray);
 $template->param(SITE_RESULTS => $sitearray);
 $template->param(loggedinuser => $loggedinuser);
-print $query->header(-cookie => $cookie), $template->output;
+output_html_with_http_headers $query, $cookie, $template->output;
 
index 2592574..a16f73f 100755 (executable)
@@ -94,4 +94,4 @@ $template->param( startmenumember => join('', startmenu('member')),
                        titleloop       => \@titledata,
                        cmemloop        => \@cmemdata );
 
-print $input->header(-cookie => $cookie),$template->output;
+output_html_with_http_headers $input, $cookie, $template->output;
index d5dd6fe..4051628 100644 (file)
@@ -39,7 +39,8 @@
         ±Ú¸Ç¡G<TMPL_VAR NAME="ethnicity">, <TMPL_VAR NAME="ethnotes"><br>
       </TMPL_IF>
       ¥X¥Í¤é´Á¡G<TMPL_VAR NAME="dateofbirth"><BR>
-      ©m§O¡G<TMPL_VAR NAME="sex"><P>
+      ©m§O¡G<TMPL_IF NAME="sex_M_p">¨k<TMPL_ELSE><TMPL_IF NAME="sex_F_p">¤k<TMPL_ELSE><TMPL_VAR NAME="sex"></TMPL_IF></TMPL_IF>
+      <P>
       Alternative Contact: <TMPL_VAR NAME="contactname"><BR>
       Phone: <TMPL_VAR NAME="altphone"><BR>
       Relationship: <TMPL_VAR NAME="altrelationship"><BR>
index 5ca4a0f..cf3b486 100755 (executable)
@@ -4,7 +4,7 @@ use strict;
 require Exporter;
 use C4::Database;
 use C4::Output;  # contains gettemplate
-use C4::Charset;
+use C4::Interface::CGI::Output;
 use CGI;
 use C4::Auth;
 
@@ -18,7 +18,4 @@ my ($template, $loggedinuser, $cookie)
                             debug => 1,
                             });
 
-print  $query->header(
-   -type => guesstype($template->output),
-   -cookie => $cookie
-), $template->output;
+output_html_with_http_headers $query, $cookie, $template->output;
index 90b5356..449bfb1 100755 (executable)
@@ -24,7 +24,7 @@
 use strict;
 use C4::Auth;
 use C4::Output;
-use C4::Charset;
+use C4::Interface::CGI::Output;
 use CGI;
 use HTML::Template;
 use C4::Search;
index 5719c4d..de1385e 100755 (executable)
@@ -24,7 +24,7 @@
 use strict;
 use C4::Auth;
 use C4::Output;
-use C4::Charset;
+use C4::Interface::CGI::Output;
 use CGI;
 use C4::Search;
 use C4::Accounts2;
index 8d09516..6baa3a3 100755 (executable)
--- a/member.pl
+++ b/member.pl
@@ -26,7 +26,7 @@
 use strict;
 use C4::Auth;
 use C4::Output;
-use C4::Charset;
+use C4::Interface::CGI::Output;
 use CGI;
 use C4::Search;
 use HTML::Template;
@@ -78,7 +78,4 @@ $template->param(
                        member          => $member,
                        resultsloop     => \@resultsdata );
 
-print $input->header(
-    -type => guesstype($template->output),
-    -cookie => $cookie
-),$template->output;
+output_html_with_http_headers $input, $cookie, $template->output;
index 98660f0..3e532ae 100755 (executable)
@@ -27,7 +27,7 @@ use strict;
 use C4::Auth;
 use C4::Context;
 use C4::Output;
-use C4::Charset;
+use C4::Interface::CGI::Output;
 use CGI;
 use C4::Search;
 use C4::Koha;
@@ -242,10 +242,7 @@ if ($delete){
                        cardnumber      => $cardnumber,
                        dateofbirth     => $data->{'dateofbirth'});
 
-print $input->header(
-    -type => guesstype($template->output),
-    -cookie => $cookie
-),$template->output;
+output_html_with_http_headers $input, $cookie, $template->output;
 
 
 }
index e910c30..b2730e0 100755 (executable)
@@ -4,7 +4,7 @@ use strict;
 use CGI;
 use C4::Auth;
 use C4::Output;
-use C4::Charset;
+use C4::Interface::CGI::Output;
 use C4::Context;
 use HTML::Template;
 
@@ -18,7 +18,4 @@ my ($template, $loggedinuser, $cookie)
                             debug => 1,
                             });
 
-print $query->header(
-    -type => guesstype($template->output),
-    -cookie => $cookie
-),$template->output;
+output_html_with_http_headers $query, $cookie, $template->output;
index a9c7b29..4fbd333 100755 (executable)
@@ -34,7 +34,8 @@ use strict;
 use C4::Auth;
 use C4::Context;
 use C4::Output;
-use C4::Charset;
+use C4::Interface::CGI::Output;
+use C4::Interface::CGI::Template;
 use CGI;
 use C4::Search;
 use Date::Manip;
@@ -69,6 +70,8 @@ $data->{'dateofbirth'} = slashifyDate($data->{'dateofbirth'});
 
 $data->{'ethnicity'} = fixEthnicity($data->{'ethnicity'});
 
+$data->{&expand_sex_into_predicate($data->{'sex'})} = 1;
+
 if ($data->{'categorycode'} eq 'C'){
     my $data2=borrdata('',$data->{'guarantor'});
     $data->{'streetaddress'}=$data2->{'streetaddress'};
@@ -203,7 +206,4 @@ $template->param(
                 issueloop       => \@issuedata,
                 reserveloop     => \@reservedata);
 
-print $input->header(
-    -type => guesstype($template->output),
-    -cookie => $cookie
-),$template->output;
+output_html_with_http_headers $input, $cookie, $template->output;
index b83a590..070293c 100755 (executable)
@@ -38,7 +38,7 @@
 use strict;
 use C4::Auth;
 use C4::Input;
-use C4::Charset;
+use C4::Interface::CGI::Output;
 use CGI;
 use Date::Manip;
 use HTML::Template;
@@ -180,9 +180,6 @@ if ($ok == 0) {
     ;
 }
 
-print $input->header(
-    -type => guesstype($template->output),
-    -cookie => $cookie
-), $template->output;
+output_html_with_http_headers $input, $cookie, $template->output;
 
 
index 4d0e27c..68f2324 100755 (executable)
@@ -55,5 +55,5 @@ $template->param( ACCOUNT_LINES => $accts );
 $template->param( total => $total );
 
 #$template->param(loggeninuser => $loggedinuser);
-print $query->header(-cookie => $cookie), $template->output;
+output_html_with_http_headers $query, $cookie, $template->output;
 
index 3a01739..dbdfff4 100755 (executable)
@@ -4,7 +4,7 @@ require Exporter;
 use CGI;
 use C4::Search;
 use C4::Auth;
-use C4::Charset;
+use C4::Interface::CGI::Output;
 use HTML::Template;
 
 my $query=new CGI;
@@ -54,8 +54,5 @@ $template->param(ITEM_RESULTS => $itemsarray);
 $template->param(WEB_RESULTS => $webarray);
 $template->param(SITE_RESULTS => $sitearray);
 
-print $query->header(
-    -type => guesstype($template->output),
-    -cookie => $cookie
-), $template->output;
+output_html_with_http_headers $query, $cookie, $template->output;
 
index b3a9854..9e25305 100755 (executable)
@@ -5,7 +5,7 @@ use CGI;
 use HTML::Template;
 
 use C4::Auth;       # get_template_and_user
-use C4::Charset;
+use C4::Interface::CGI::Output;
 
 my $query = new CGI;
 
@@ -17,7 +17,4 @@ my ($template, $borrowernumber, $cookie)
                             flagsrequired => {borrow => 1},
                         });
 
-print $query->header(
-    -type => guesstype($template->output),
-    -cookie => $cookie
-), $template->output;
+output_html_with_http_headers $query, $cookie, $template->output;
index 7096e65..20f0406 100644 (file)
@@ -15,4 +15,4 @@ my ($template, $borrowernumber, $cookie)
                             flagsrequired => {borrow => 1},
                         });
 
-print $query->header(-cookie => $cookie), $template->output;
+output_html_with_http_headers $query, $cookie, $template->output;
index 1db4663..b0eb178 100755 (executable)
@@ -51,5 +51,5 @@ $template->param(count => $count);
 $template->param(READING_RECORD => $issues);
 
 
-print $query->header(-cookie => $cookie), $template->output;
+output_html_with_http_headers $query, $cookie, $template->output;
 
index 3e490c7..5233e9b 100755 (executable)
@@ -225,4 +225,4 @@ if ($query->param('item_types_selected')) {
 $template->param(BIBLIOITEMS => \@data);
 
 
-print $query->header(-cookie => $cookie), $template->output;
+output_html_with_http_headers $query, $cookie, $template->output;
index b03de61..93bfa39 100755 (executable)
@@ -3,7 +3,7 @@ use strict;
 require Exporter;
 
 use C4::Auth;
-use C4::Charset;
+use C4::Interface::CGI::Output;
 use C4::Context;
 use CGI;
 use C4::Database;
@@ -32,7 +32,4 @@ my ($template, $borrowernumber, $cookie)
 
 $template->param(classlist => $classlist);
 
-print $query->header(
-    -type => guesstype($template->output),
-    -cookie => $cookie
-), $template->output;
+output_html_with_http_headers $query, $cookie, $template->output;
index dafdcb0..9e9ef48 100755 (executable)
@@ -4,7 +4,7 @@ require Exporter;
 use CGI;
 use C4::Search;
 use C4::Auth;
-use C4::Charset;
+use C4::Interface::CGI::Output;
 use HTML::Template;
 
 my $query=new CGI;
@@ -127,8 +127,5 @@ if ($count>10) {
 
 $template->param(numbers => $numbers);
 
-print $query->header(
-    -type => guesstype($template->output),
-    -cookie => $cookie
-), $template->output;
+output_html_with_http_headers $query, $cookie, $template->output;
 
index 059896d..0c37f68 100755 (executable)
@@ -28,4 +28,4 @@ $template->param(INPUTS => \@inputs);
 my $self_url = $query->url(-absolute => 1);
 $template->param(url => $self_url);
 
-print $query->header(-cookie => $cookie), $template->output;
+output_html_with_http_headers $query, $cookie, $template->output;
index cdcdde8..5aac6c1 100755 (executable)
@@ -131,5 +131,5 @@ foreach my $res (@$reserves) {
 # $template->param(WAITING => \@waiting);
 $template->param(waiting_count => $wcount);
 
-print $query->header(-cookie => $cookie), $template->output;
+output_html_with_http_headers $query, $cookie, $template->output;
 
index d914528..a476bf0 100755 (executable)
@@ -30,5 +30,5 @@ $borr->{'ethnicity'}    = fixEthnicity($borr->{'ethnicity'});
 
 $template->param($borr);
 
-print $query->header(-cookie => $cookie), $template->output;
+output_html_with_http_headers $query, $cookie, $template->output;
 
index c609da1..a85e312 100755 (executable)
@@ -68,4 +68,4 @@ $bordat[0] = $borr;
 
 $template->param(BORROWER_INFO => \@bordat);
 
-print $query->header(-cookie => $cookie), $template->output;
+output_html_with_http_headers $query, $cookie, $template->output;
index c4d258c..120cfd5 100755 (executable)
@@ -25,7 +25,7 @@
 use strict;
 use C4::Auth;
 use C4::Output;
-use C4::Charset;
+use C4::Interface::CGI::Output;
 use CGI;
 use C4::Search;
 use HTML::Template;
@@ -73,10 +73,7 @@ $template->param(title => $data->{'title'},
                                                bornum => $bornum,
                                                limit => $limit,
                                                loop_reading => \@loop_reading);
-print $input->header(
-    -type => guesstype($template->output),
-    -cookie => $cookie
-),$template->output;
+output_html_with_http_headers $input, $cookie, $template->output;
 
 
 
index 4a86630..488b7c4 100755 (executable)
@@ -4,7 +4,7 @@ use strict;
 use CGI;
 use C4::Auth;
 use C4::Output;
-use C4::Charset;
+use C4::Interface::CGI::Output;
 use C4::Context;
 use HTML::Template;
 
@@ -17,7 +17,4 @@ my ($template, $loggedinuser, $cookie)
                                flagsrequired => {permissions => 1},
                                debug => 1,
                                });
-print $query->header(
-    -type => guesstype($template->output),
-    -cookie => $cookie
-),$template->output;
+output_html_with_http_headers $query, $cookie, $template->output;
index 7bc0ced..d77502a 100755 (executable)
@@ -26,7 +26,7 @@ use C4::Context;
 use C4::Search;
 use C4::Auth;
 use C4::Output;
-use C4::Charset;
+use C4::Interface::CGI::Output;
 use C4::Biblio;
 use C4::SearchMarc;
 
@@ -108,7 +108,4 @@ if ($op eq "do_search") {
        $template->param("marclist" => $marclist);
 }
 # Print the page
-print $query->header(
-    -type => guesstype($template->output),
-    -cookie => $cookie
-), $template->output;
+output_html_with_http_headers $query, $cookie, $template->output;
index 04a5b18..b24e958 100755 (executable)
--- a/search.pl
+++ b/search.pl
@@ -26,7 +26,7 @@ use C4::Context;
 use C4::Search;
 use C4::Auth;
 use C4::Output;
-use C4::Charset;
+use C4::Interface::CGI::Output;
 
 my $query=new CGI;
 my $type=$query->param('type');
@@ -200,8 +200,5 @@ if (C4::Context->preference('acquisitions') eq 'simple') {
 }
 
 # Print the page
-print $query->header(
-    -type => guesstype($template->output),
-    -cookie => $cookie
-), $template->output;
+output_html_with_http_headers $query, $cookie, $template->output;
 
index 4dc6e71..713da9a 100755 (executable)
@@ -83,7 +83,7 @@ SWITCH: {
        $template->param(shelvesloop => \@shelvesloop);
 }
 
-print $query->header(-cookie => $cookie), $template->output;
+output_html_with_http_headers $query, $cookie, $template->output;
 
 
 sub shelves {
@@ -151,6 +151,20 @@ sub viewshelf {
 
 #
 # $Log$
+# Revision 1.10  2003/02/02 07:18:37  acli
+# Moved C4/Charset.pm to C4/Interface/CGI/Output.pm
+#
+# Create output_html_with_http_headers function to contain the "print $query
+# ->header(-type => guesstype...),..." call. This is in preparation for
+# non-HTML output (e.g., text/xml) and charset conversion before output in
+# the future.
+#
+# Created C4/Interface/CGI/Template.pm to hold convenience functions specific
+# to the CGI interface using HTML::Template
+#
+# Modified moremembers.pl to make the "sex" field localizable for languages
+# where M and F doesn't make sense
+#
 # Revision 1.9  2002/12/19 18:55:40  hdl
 # Templating reservereport et shelves.
 #
index 167235a..d4105e5 100644 (file)
@@ -1,5 +1,5 @@
 use strict;
-use C4::Charset;
+use C4::Interface::CGI::Output;
 
 use vars qw( @tests );
 use vars qw( $loaded );
@@ -8,84 +8,84 @@ BEGIN {
    @tests = (
    [
       'Normal HTML without meta tag',
-      sub { C4::Charset::guesscharset($_[0]) },
+      sub { guesscharset($_[0]) },
       undef,
       <<EOF
 <title>control case</title>
 EOF
    ], [
       'Result of guesscharset with normal HTML with irrelevant meta tag',
-      sub { C4::Charset::guesscharset($_[0]) },
+      sub { guesscharset($_[0]) },
       undef,
       <<EOF
 <meta http-equiv="Content-Language" content="zh-TW">
 EOF
    ], [
-      'Result of guesscharset with normal HTML with irrelevant meta tag',
-      sub { C4::Charset::guesstype($_[0]) },
-      undef,
+      'Result of guesstype with normal HTML with irrelevant meta tag',
+      sub { guesstype($_[0]) },
+      'text/html',
       <<EOF
 <meta http-equiv="Content-Language" content="zh-TW">
 EOF
    ], [
       'Result of guesscharset with normal HTML with relevant meta tag',
-      sub { C4::Charset::guesscharset($_[0]) },
+      sub { guesscharset($_[0]) },
       'big5',
       <<EOF
 <meta http-equiv="Content-Type" content="text/html; charset=big5">
 EOF
    ], [
       'Result of guesstype with normal HTML with relevant meta tag',
-      sub { C4::Charset::guesstype($_[0]) },
+      sub { guesstype($_[0]) },
       'text/html; charset=big5',
       <<EOF
 <meta http-equiv="Content-Type" content="text/html; charset=big5">
 EOF
    ], [
       'Variant 1 using single quotes',
-      sub { C4::Charset::guesstype($_[0]) },
+      sub { guesstype($_[0]) },
       'text/html; charset=iso-2022-jp',
       <<EOF
 <meta http-equiv="Content-Type" content='text/html; charset=iso-2022-jp'>
 EOF
    ], [
       'Variant 2 using single quotes',
-      sub { C4::Charset::guesstype($_[0]) },
+      sub { guesstype($_[0]) },
       'text/html; charset=utf-8',
       <<EOF
 <meta http-equiv='Content-Type' content="text/html; charset=utf-8">
 EOF
    ], [
       'Unquoted Content-Type',
-      sub { C4::Charset::guesstype($_[0]) },
+      sub { guesstype($_[0]) },
       'text/html; charset=big5',
       <<EOF
 <meta http-equiv=Content-Type content="text/html; charset=big5">
 EOF
    ], [
       'XML syntax',
-      sub { C4::Charset::guesstype($_[0]) },
+      sub { guesstype($_[0]) },
       'text/html; charset=iso-8859-2',
       <<EOF
 <meta http-equiv=Content-Type content="text/html; charset=iso-8859-2" />
 EOF
    ], [
       'Expected attributes in reverse order',
-      sub { C4::Charset::guesstype($_[0]) },
+      sub { guesstype($_[0]) },
       'text/html; charset=big5',
       <<EOF
 <meta content="text/html; charset=big5" http-equiv="Content-Type">
 EOF
    ], [
       'Extra whitespace at end',
-      sub { C4::Charset::guesstype($_[0]) },
+      sub { guesstype($_[0]) },
       'text/html; charset=big5',
       <<EOF
 <meta http-equiv="Content-Type" content="text/html; charset=big5"   >
 EOF
    ], [
       'Multiple lines',
-      sub { C4::Charset::guesstype($_[0]) },
+      sub { guesstype($_[0]) },
       'text/html; charset=big5',
       <<EOF
 <meta
@@ -94,8 +94,9 @@ content="text/html; charset=big5"
 >
 EOF
    ], [
+      # FIXME - THIS IS NOT A WELL-WRITTEN TEST CASE!!!
       'With surrounding HTML',
-      sub { C4::Charset::guesstype($_[0]) },
+      sub { guesstype($_[0]) },
       'text/html; charset=us-ascii',
       <<EOF
 <html>
@@ -131,13 +132,13 @@ for (my $i = 1; $i <= scalar @tests; $i += 1) {
         (!defined $output && !defined $expected)
       || (defined $output && defined $expected && $output eq $expected)
    ) {
-      print "ok $i ($title)\n";
+      print "ok $i - $title\n";
    } else {
-      print "not ok $i ($title: got ",
+      print "not ok $i - $title: got ",
            (defined $output? "\"$output\"": 'undef'),
            ', expected ',
            (defined $expected? "\"$expected\"": 'undef'),
-           ")\n";
+           "\n";
    }
 }
 
index ba56402..2873570 100755 (executable)
@@ -93,6 +93,6 @@ $template->param(select_list => $select_list,
                                                category => $category,
                                                index => $index
                                                );
-print $input->header(-cookie => $cookie),$template->output;
+output_html_with_http_headers $input, $cookie, $template->output;
 
 
index 044d0f2..181be9c 100755 (executable)
@@ -38,4 +38,4 @@ my ($template, $loggedinuser, $cookie)
 
 warn "userloggedin : $loggedinuser (".$query->param('userid')." et ".$query->param('password');
 
-print $query->header(-cookie => $cookie), $template->output;
+output_html_with_http_headers $query, $cookie, $template->output;