3 # Copyright 2000-2002 Katipo Communications
5 # This file is part of Koha.
7 # Koha is free software; you can redistribute it and/or modify it under the
8 # terms of the GNU General Public License as published by the Free Software
9 # Foundation; either version 2 of the License, or (at your option) any later
12 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License along with
17 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
18 # Suite 330, Boston, MA 02111-1307 USA
26 use vars qw($VERSION @ISA @EXPORT);
28 $VERSION = do { my @v = '$Revision$' =~ /\d+/g; shift(@v) . "." . join( "_", map { sprintf "%03d", $_ } @v ); };
32 C4::Koha - Perl Module containing convenience functions for Koha scripts
41 Koha.pm provides many functions for Koha scripts.
53 &subfield_is_koha_internal_p
54 &GetPrinters &GetPrinter
55 &GetItemTypes &getitemtypeinfo
60 &getframeworks &getframeworkinfo
61 &getauthtypes &getauthtype
70 &getitemtypeimagesrcfromurl
72 &get_notforloan_label_of
77 &GetKohaAuthorisedValues
85 $slash_date = &slashifyDate($dash_date);
87 Takes a string of the form "DD-MM-YYYY" (or anything separated by
88 dashes), converts it to the form "YYYY/MM/DD", and returns the result.
94 # accepts a date of the form xx-xx-xx[xx] and returns it in the
96 my @dateOut = split( '-', shift );
97 return ("$dateOut[2]/$dateOut[1]/$dateOut[0]");
103 my $string = DisplayISBN( $isbn );
110 if ( substr( $isbn, 0, 1 ) <= 7 ) {
111 $seg1 = substr( $isbn, 0, 1 );
113 elsif ( substr( $isbn, 0, 2 ) <= 94 ) {
114 $seg1 = substr( $isbn, 0, 2 );
116 elsif ( substr( $isbn, 0, 3 ) <= 995 ) {
117 $seg1 = substr( $isbn, 0, 3 );
119 elsif ( substr( $isbn, 0, 4 ) <= 9989 ) {
120 $seg1 = substr( $isbn, 0, 4 );
123 $seg1 = substr( $isbn, 0, 5 );
125 my $x = substr( $isbn, length($seg1) );
127 if ( substr( $x, 0, 2 ) <= 19 ) {
129 # if(sTmp2 < 10) sTmp2 = "0" sTmp2;
130 $seg2 = substr( $x, 0, 2 );
132 elsif ( substr( $x, 0, 3 ) <= 699 ) {
133 $seg2 = substr( $x, 0, 3 );
135 elsif ( substr( $x, 0, 4 ) <= 8399 ) {
136 $seg2 = substr( $x, 0, 4 );
138 elsif ( substr( $x, 0, 5 ) <= 89999 ) {
139 $seg2 = substr( $x, 0, 5 );
141 elsif ( substr( $x, 0, 6 ) <= 9499999 ) {
142 $seg2 = substr( $x, 0, 6 );
145 $seg2 = substr( $x, 0, 7 );
147 my $seg3 = substr( $x, length($seg2) );
148 $seg3 = substr( $seg3, 0, length($seg3) - 1 );
149 my $seg4 = substr( $x, -1, 1 );
150 return "$seg1-$seg2-$seg3-$seg4";
153 # FIXME.. this should be moved to a MARC-specific module
154 sub subfield_is_koha_internal_p ($) {
157 # We could match on 'lib' and 'tab' (and 'mandatory', & more to come!)
158 # But real MARC subfields are always single-character
159 # so it really is safer just to check the length
161 return length $subfield != 1;
166 $itemtypes = &GetItemTypes();
168 Returns information about existing itemtypes.
170 build a HTML select with the following code :
172 =head3 in PERL SCRIPT
174 my $itemtypes = GetItemTypes;
176 foreach my $thisitemtype (sort keys %$itemtypes) {
177 my $selected = 1 if $thisitemtype eq $itemtype;
178 my %row =(value => $thisitemtype,
179 selected => $selected,
180 description => $itemtypes->{$thisitemtype}->{'description'},
182 push @itemtypesloop, \%row;
184 $template->param(itemtypeloop => \@itemtypesloop);
188 <form action='<!-- TMPL_VAR name="script_name" -->' method=post>
189 <select name="itemtype">
190 <option value="">Default</option>
191 <!-- TMPL_LOOP name="itemtypeloop" -->
192 <option value="<!-- TMPL_VAR name="value" -->" <!-- TMPL_IF name="selected" -->selected<!-- /TMPL_IF -->><!-- TMPL_VAR name="description" --></option>
195 <input type=text name=searchfield value="<!-- TMPL_VAR name="searchfield" -->">
196 <input type="submit" value="OK" class="button">
204 # returns a reference to a hash of references to branches...
206 my $dbh = C4::Context->dbh;
211 my $sth = $dbh->prepare($query);
213 while ( my $IT = $sth->fetchrow_hashref ) {
214 $itemtypes{ $IT->{'itemtype'} } = $IT;
216 return ( \%itemtypes );
219 sub get_itemtypeinfos_of {
227 WHERE itemtype IN (' . join( ',', map( { "'" . $_ . "'" } @itemtypes ) ) . ')
230 return get_infos_of( $query, 'itemtype' );
233 # this is temporary until we separate collection codes and item types
237 my $dbh = C4::Context->dbh;
240 "SELECT * FROM authorised_values ORDER BY authorised_value");
242 while ( my $data = $sth->fetchrow_hashref ) {
243 if ( $data->{category} eq "CCODE" ) {
245 $results[$count] = $data;
251 return ( $count, @results );
256 grab itemlost authorized values
260 sub GetAuthItemlost {
261 my $itemlost = shift;
264 my $dbh = C4::Context->dbh;
267 "SELECT * FROM authorised_values ORDER BY authorised_value");
269 while ( my $data = $sth->fetchrow_hashref ) {
270 if ( $data->{category} eq "ITEMLOST" ) {
272 if ( $itemlost eq $data->{'authorised_value'} ) {
273 $data->{'selected'} = 1;
275 $results[$count] = $data;
281 return ( $count, @results );
284 =head2 GetAuthItembinding
286 grab itemlost authorized values
290 sub GetAuthItembinding {
291 my $itembinding = shift;
294 my $dbh = C4::Context->dbh;
297 "SELECT * FROM authorised_values ORDER BY authorised_value");
299 while ( my $data = $sth->fetchrow_hashref ) {
300 if ( $data->{category} eq "BINDING" ) {
302 if ( $itembinding eq $data->{'authorised_value'} ) {
303 $data->{'selected'} = 1;
305 $results[$count] = $data;
311 return ( $count, @results );
316 $authtypes = &getauthtypes();
318 Returns information about existing authtypes.
320 build a HTML select with the following code :
322 =head3 in PERL SCRIPT
324 my $authtypes = getauthtypes;
326 foreach my $thisauthtype (keys %$authtypes) {
327 my $selected = 1 if $thisauthtype eq $authtype;
328 my %row =(value => $thisauthtype,
329 selected => $selected,
330 authtypetext => $authtypes->{$thisauthtype}->{'authtypetext'},
332 push @authtypesloop, \%row;
334 $template->param(itemtypeloop => \@itemtypesloop);
338 <form action='<!-- TMPL_VAR name="script_name" -->' method=post>
339 <select name="authtype">
340 <!-- TMPL_LOOP name="authtypeloop" -->
341 <option value="<!-- TMPL_VAR name="value" -->" <!-- TMPL_IF name="selected" -->selected<!-- /TMPL_IF -->><!-- TMPL_VAR name="authtypetext" --></option>
344 <input type=text name=searchfield value="<!-- TMPL_VAR name="searchfield" -->">
345 <input type="submit" value="OK" class="button">
353 # returns a reference to a hash of references to authtypes...
355 my $dbh = C4::Context->dbh;
356 my $sth = $dbh->prepare("select * from auth_types order by authtypetext");
358 while ( my $IT = $sth->fetchrow_hashref ) {
359 $authtypes{ $IT->{'authtypecode'} } = $IT;
361 return ( \%authtypes );
365 my ($authtypecode) = @_;
367 # returns a reference to a hash of references to authtypes...
369 my $dbh = C4::Context->dbh;
370 my $sth = $dbh->prepare("select * from auth_types where authtypecode=?");
371 $sth->execute($authtypecode);
372 my $res = $sth->fetchrow_hashref;
378 $frameworks = &getframework();
380 Returns information about existing frameworks
382 build a HTML select with the following code :
384 =head3 in PERL SCRIPT
386 my $frameworks = frameworks();
388 foreach my $thisframework (keys %$frameworks) {
389 my $selected = 1 if $thisframework eq $frameworkcode;
390 my %row =(value => $thisframework,
391 selected => $selected,
392 description => $frameworks->{$thisframework}->{'frameworktext'},
394 push @frameworksloop, \%row;
396 $template->param(frameworkloop => \@frameworksloop);
400 <form action='<!-- TMPL_VAR name="script_name" -->' method=post>
401 <select name="frameworkcode">
402 <option value="">Default</option>
403 <!-- TMPL_LOOP name="frameworkloop" -->
404 <option value="<!-- TMPL_VAR name="value" -->" <!-- TMPL_IF name="selected" -->selected<!-- /TMPL_IF -->><!-- TMPL_VAR name="frameworktext" --></option>
407 <input type=text name=searchfield value="<!-- TMPL_VAR name="searchfield" -->">
408 <input type="submit" value="OK" class="button">
416 # returns a reference to a hash of references to branches...
418 my $dbh = C4::Context->dbh;
419 my $sth = $dbh->prepare("select * from biblio_framework");
421 while ( my $IT = $sth->fetchrow_hashref ) {
422 $itemtypes{ $IT->{'frameworkcode'} } = $IT;
424 return ( \%itemtypes );
427 =head2 getframeworkinfo
429 $frameworkinfo = &getframeworkinfo($frameworkcode);
431 Returns information about an frameworkcode.
435 sub getframeworkinfo {
436 my ($frameworkcode) = @_;
437 my $dbh = C4::Context->dbh;
439 $dbh->prepare("select * from biblio_framework where frameworkcode=?");
440 $sth->execute($frameworkcode);
441 my $res = $sth->fetchrow_hashref;
445 =head2 getitemtypeinfo
447 $itemtype = &getitemtype($itemtype);
449 Returns information about an itemtype.
453 sub getitemtypeinfo {
455 my $dbh = C4::Context->dbh;
456 my $sth = $dbh->prepare("select * from itemtypes where itemtype=?");
457 $sth->execute($itemtype);
458 my $res = $sth->fetchrow_hashref;
460 $res->{imageurl} = getitemtypeimagesrcfromurl( $res->{imageurl} );
465 sub getitemtypeimagesrcfromurl {
468 if ( defined $imageurl and $imageurl !~ m/^http/ ) {
469 $imageurl = getitemtypeimagesrc() . '/' . $imageurl;
475 sub getitemtypeimagedir {
476 return C4::Context->opachtdocs . '/'
477 . C4::Context->preference('template')
481 sub getitemtypeimagesrc {
482 return '/opac-tmpl' . '/'
483 . C4::Context->preference('template')
489 $printers = &GetPrinters();
490 @queues = keys %$printers;
492 Returns information about existing printer queues.
494 C<$printers> is a reference-to-hash whose keys are the print queues
495 defined in the printers table of the Koha database. The values are
496 references-to-hash, whose keys are the fields in the printers table.
502 my $dbh = C4::Context->dbh;
503 my $sth = $dbh->prepare("select * from printers");
505 while ( my $printer = $sth->fetchrow_hashref ) {
506 $printers{ $printer->{'printqueue'} } = $printer;
508 return ( \%printers );
513 $printer = GetPrinter( $query, $printers );
517 sub GetPrinter ($$) {
518 my ( $query, $printers ) = @_; # get printer for this query from printers
519 my $printer = $query->param('printer');
520 my %cookie = $query->cookie('userenv');
521 ($printer) || ( $printer = $cookie{'printer'} ) || ( $printer = '' );
522 ( $printers->{$printer} ) || ( $printer = ( keys %$printers )[0] );
528 Returns the number of pages to display in a pagination bar, given the number
529 of items and the number of items per page.
534 my ( $nb_items, $nb_items_per_page ) = @_;
536 return int( ( $nb_items - 1 ) / $nb_items_per_page ) + 1;
541 (@themes) = &getallthemes('opac');
542 (@themes) = &getallthemes('intranet');
544 Returns an array of all available themes.
552 if ( $type eq 'intranet' ) {
553 $htdocs = C4::Context->config('intrahtdocs');
556 $htdocs = C4::Context->config('opachtdocs');
558 opendir D, "$htdocs";
559 my @dirlist = readdir D;
560 foreach my $directory (@dirlist) {
561 -d "$htdocs/$directory/en" and push @themes, $directory;
568 if ( C4::Context->preference("marcflavour") eq "UNIMARC" ) {
571 link_value => 'su-to',
572 label_value => 'Topics',
574 [ '600', '601', '602', '603', '604', '605', '606', '610' ],
578 link_value => 'su-geo',
579 label_value => 'Places',
584 link_value => 'su-ut',
585 label_value => 'Titles',
586 tags => [ '500', '501', '502', '503', '504', ],
591 label_value => 'Authors',
592 tags => [ '700', '701', '702', ],
597 label_value => 'Series',
602 link_value => 'branch',
603 label_value => 'Branches',
613 link_value => 'su-to',
614 label_value => 'Topics',
620 # link_value => 'su-na',
621 # label_value => 'People and Organizations',
622 # tags => ['600', '610', '611'],
626 link_value => 'su-geo',
627 label_value => 'Places',
632 link_value => 'su-ut',
633 label_value => 'Titles',
639 label_value => 'Authors',
640 tags => [ '100', '110', '700', ],
645 label_value => 'Series',
646 tags => [ '440', '490', ],
650 link_value => 'branch',
651 label_value => 'Branches',
663 Return a href where a key is associated to a href. You give a query, the
664 name of the key among the fields returned by the query. If you also give as
665 third argument the name of the value, the function returns a href of scalar.
674 # generic href of any information on the item, href of href.
675 my $iteminfos_of = get_infos_of($query, 'itemnumber');
676 print $iteminfos_of->{$itemnumber}{barcode};
678 # specific information, href of scalar
679 my $barcode_of_item = get_infos_of($query, 'itemnumber', 'barcode');
680 print $barcode_of_item->{$itemnumber};
685 my ( $query, $key_name, $value_name ) = @_;
687 my $dbh = C4::Context->dbh;
689 my $sth = $dbh->prepare($query);
693 while ( my $row = $sth->fetchrow_hashref ) {
694 if ( defined $value_name ) {
695 $infos_of{ $row->{$key_name} } = $row->{$value_name};
698 $infos_of{ $row->{$key_name} } = $row;
706 =head2 get_notforloan_label_of
708 my $notforloan_label_of = get_notforloan_label_of();
710 Each authorised value of notforloan (information available in items and
711 itemtypes) is link to a single label.
713 Returns a href where keys are authorised values and values are corresponding
716 foreach my $authorised_value (keys %{$notforloan_label_of}) {
718 "authorised_value: %s => %s\n",
720 $notforloan_label_of->{$authorised_value}
726 sub get_notforloan_label_of {
727 my $dbh = C4::Context->dbh;
730 SELECT authorised_value
731 FROM marc_subfield_structure
732 WHERE kohafield = \'items.notforloan\'
735 my $sth = $dbh->prepare($query);
737 my ($statuscode) = $sth->fetchrow_array();
742 FROM authorised_values
745 $sth = $dbh->prepare($query);
746 $sth->execute($statuscode);
747 my %notforloan_label_of;
748 while ( my $row = $sth->fetchrow_hashref ) {
749 $notforloan_label_of{ $row->{authorised_value} } = $row->{lib};
753 return \%notforloan_label_of;
758 $sort_by =~ s/</\</;
759 $sort_by =~ s/>/\>/;
761 { value => "1=9523 >i", label => "Popularity (Most to Least)" },
762 { value => "1=9523 <i", label => "Popularity (Least to Most)" },
763 { value => "1=1003 <i", label => "Author (A-Z)" },
764 { value => "1=1003 >i", label => "Author (Z-A)" },
766 value => "1=20 <i",
767 label => "Call Number (Non-fiction 0-9 to Fiction A-Z)"
770 value => "1=20 >i",
771 label => "Call Number (Fiction Z-A to Non-fiction 9-0)"
773 { value => "1=31 >i", label => "Dates" },
775 value => "1=31 >i",
777 " Publication/Copyright Date: Newest to Oldest"
780 value => "1=31 <i",
782 " Publication/Copyright Date: Oldest to Newest"
785 value => "1=32 >i",
786 label => " Acquisition Date: Newest to Oldest"
789 value => "1=32 <i",
790 label => " Acquisition Date: Oldest to Newest"
792 { value => "1=36 <i", label => "Title (A-Z)" },
793 { value => "1=36 >i", label => "Title (Z-A)" },
795 for my $hash (@$sort_by_loop) {
797 #warn "sort by: $sort_by ... hash:".$hash->{value};
798 if ($sort_by && $hash->{value} eq $sort_by ) {
799 $hash->{selected} = "selected";
802 return $sort_by_loop;
808 { value => '', label => 'Keyword' },
809 { value => 'au', label => 'Author' },
812 label => ' Author Phrase'
814 { value => 'cpn', label => ' Corporate Name' },
815 { value => 'cfn', label => ' Conference Name' },
818 label => ' Corporate Name Phrase'
822 label => ' Conference Name Phrase'
824 { value => 'pn', label => ' Personal Name' },
827 label => ' Personal Name Phrase'
829 { value => 'ln', label => 'Language' },
831 # { value => 'mt', label => 'Material Type' },
832 # { value => 'mt,phr', label => 'Material Type Phrase' },
833 # { value => 'mc', label => 'Musical Composition' },
834 # { value => 'mc,phr', label => 'Musical Composition Phrase' },
836 { value => 'nt', label => 'Notes/Comments' },
837 { value => 'pb', label => 'Publisher' },
838 { value => 'pl', label => 'Publisher Location' },
839 { value => 'sn', label => 'Standard Number' },
840 { value => 'nb', label => ' ISBN' },
841 { value => 'ns', label => ' ISSN' },
842 { value => 'lcn', label => ' Call Number' },
843 { value => 'su', label => 'Subject' },
846 label => ' Subject Phrase'
849 # { value => 'de', label => ' Descriptor' },
850 # { value => 'ge', label => ' Genre/Form' },
851 # { value => 'gc', label => ' Geographic Coverage' },
853 # { value => 'nc', label => ' Named Corporation and Conference' },
854 # { value => 'na', label => ' Named Person' },
856 { value => 'ti', label => 'Title' },
857 { value => 'ti,phr', label => ' Title Phrase' },
858 { value => 'se', label => ' Series Title' },
863 sub displaySubtypesLimit {
864 my $outer_subtype_limits_loop = [
866 { # in MARC21, aud codes are stored in 008/22 (Target audience)
868 inner_subtype_limits_loop => [
871 label => 'Any Audience',
872 selected => "selected"
874 { value => 'aud:a', label => 'Easy', },
875 { value => 'aud:c', label => 'Juvenile', },
876 { value => 'aud:d', label => 'Young Adult', },
877 { value => 'aud:e', label => 'Adult', },
881 { # in MARC21, fic is in 008/33, bio in 008/34, mus in LDR/06
883 inner_subtype_limits_loop => [
884 { value => '', label => 'Any Content', selected => "selected" },
885 { value => 'fic:1', label => 'Fiction', },
886 { value => 'fic:0', label => 'Non Fiction', },
887 { value => 'bio:b', label => 'Biography', },
888 { value => 'mus:j', label => 'Musical recording', },
889 { value => 'mus:i', label => 'Non-musical recording', },
893 { # MARC21, these are codes stored in 007/00-01
895 inner_subtype_limits_loop => [
896 { value => '', label => 'Any Format', selected => "selected" },
897 { value => 'l-format:ta', label => 'Regular print', },
898 { value => 'l-format:tb', label => 'Large print', },
899 { value => 'l-format:fk', label => 'Braille', },
900 { value => '', label => '-----------', },
901 { value => 'l-format:sd', label => 'CD audio', },
902 { value => 'l-format:ss', label => 'Cassette recording', },
904 value => 'l-format:vf',
905 label => 'VHS tape / Videocassette',
907 { value => 'l-format:vd', label => 'DVD video / Videodisc', },
908 { value => 'l-format:co', label => 'CD Software', },
909 { value => 'l-format:cr', label => 'Website', },
913 { # in MARC21, these are codes in 008/24-28
915 inner_subtype_limits_loop => [
916 { value => '', label => 'Additional Content Types', },
917 { value => 'ctype:a', label => 'Abstracts/summaries', },
918 { value => 'ctype:b', label => 'Bibliographies', },
919 { value => 'ctype:c', label => 'Catalogs', },
920 { value => 'ctype:d', label => 'Dictionaries', },
921 { value => 'ctype:e', label => 'Encyclopedias ', },
922 { value => 'ctype:f', label => 'Handbooks', },
923 { value => 'ctype:g', label => 'Legal articles', },
924 { value => 'ctype:i', label => 'Indexes', },
925 { value => 'ctype:j', label => 'Patent document', },
926 { value => 'ctype:k', label => 'Discographies', },
927 { value => 'ctype:l', label => 'Legislation', },
928 { value => 'ctype:m', label => 'Theses', },
929 { value => 'ctype:n', label => 'Surveys', },
930 { value => 'ctype:o', label => 'Reviews', },
931 { value => 'ctype:p', label => 'Programmed texts', },
932 { value => 'ctype:q', label => 'Filmographies', },
933 { value => 'ctype:r', label => 'Directories', },
934 { value => 'ctype:s', label => 'Statistics', },
935 { value => 'ctype:t', label => 'Technical reports', },
936 { value => 'ctype:v', label => 'Legal cases and case notes', },
937 { value => 'ctype:w', label => 'Law reports and digests', },
938 { value => 'ctype:z', label => 'Treaties ', },
942 return $outer_subtype_limits_loop;
945 sub displayLimitTypes {
946 my $outer_limit_types_loop = [
949 inner_limit_types_loop => [
954 value => "(mc-collection:AF or mc-collection:MYS or mc-collection:SCI or mc-collection:NF or mc-collection:YA or mc-collection:BIO or mc-collection:LP or mc-collection:LPNF)",
955 icon => "search-books.gif",
957 "Books, Pamphlets, Technical reports, Manuscripts, Legal papers, Theses and dissertations",
964 value => "(mc-collection:DVD or mc-collection:AV or mc-collection:AVJ or mc-collection:AVJN or mc-collection:AVJNF or mc-collection:AVNF)",
965 icon => "search-movies.gif",
967 "Motion pictures, Videorecordings, Filmstrips, Slides, Transparencies, Photos, Cards, Charts, Drawings",
974 value => "(mc-collection:CDM)",
975 icon => "search-music.gif",
976 title => "Spoken, Books on CD and Cassette",
981 inner_limit_types_loop => [
983 label => "Audio Books",
984 id => "mc-audio-books",
986 value => "(mc-collection:AB or mc-collection:AC or mc-collection:JAC or mc-collection:YAC)",
987 icon => "search-audio-books.gif",
988 title => "Spoken, Books on CD and Cassette",
992 label => "Local History Materials",
993 id => "mc-local-history",
995 value => "mc-collection:LH",
996 icon => "Local history.gif",
997 title => "Local History Materials",
1000 {label => "Large Print",
1001 id => "mc-large-print",
1003 value => "(mc-collection:LP or mc-collection:LPNF)",
1004 icon => "search-large-print.gif ",
1005 title => "Large Print",},
1008 { inner_limit_types_loop => [
1012 value => "(mc-collection:EASY or mc-collection:JNF or mc-collection:JF or mc-collection:JREF or mc-collection:JB)",
1013 icon => "search-kids.gif",
1016 {label => "Software/Internet",
1017 id => "mc-sofware-web",
1019 value => "(mc-collection:CDR)",
1020 icon => "search-software-web.gif",
1023 {label => "Reference",
1024 id => "mc-reference",
1026 value => "mc-collection:REF",
1027 icon => "search-reference.gif",
1028 title => "Reference",},
1034 return $outer_limit_types_loop;
1037 sub displayServers {
1038 my ( $position, $type ) = @_;
1039 my $dbh = C4::Context->dbh;
1040 my $strsth = "SELECT * FROM z3950servers where 1";
1041 $strsth .= " AND position=\"$position\"" if ($position);
1042 $strsth .= " AND type=\"$type\"" if ($type);
1043 my $rq = $dbh->prepare($strsth);
1045 my @primaryserverloop;
1047 while ( my $data = $rq->fetchrow_hashref ) {
1049 $cell{label} = $data->{'description'};
1050 $cell{id} = $data->{'name'};
1053 . ( $data->{port} ? ":" . $data->{port} : "" ) . "/"
1055 if ( $data->{host} );
1056 $cell{checked} = $data->{checked};
1057 push @primaryserverloop,
1059 label => $data->{description},
1060 id => $data->{name},
1062 value => $data->{host} . ":"
1063 . $data->{port} . "/"
1064 . $data->{database},
1065 checked => "checked",
1066 icon => $data->{icon},
1067 zed => $data->{type} eq 'zed',
1068 opensearch => $data->{type} eq 'opensearch'
1071 return \@primaryserverloop;
1074 sub displaySecondaryServers {
1076 # my $secondary_servers_loop = [
1077 # { inner_sup_servers_loop => [
1078 # {label => "Google", id=>"GOOG", value=>"google",icon => "google.ico",opensearch => "1"},
1079 # {label => "Yahoo", id=>"YAH", value=>"yahoo", icon =>"yahoo.ico", zed => "1"},
1080 # {label => "Worldcat", id=>"WCT", value=>"worldcat", icon => "worldcat.gif", zed => "1"},
1081 # {label => "Library of Congress", id=>"LOC", name=> "server", value=>"z3950.loc.gov:7090/Voyager", icon =>"loc.ico", zed => "1"},
1085 return; #$secondary_servers_loop;
1088 =head2 GetAuthorisedValues
1090 $authvalues = GetAuthorisedValues($category);
1092 this function get all authorised values from 'authosied_value' table into a reference to array which
1093 each value containt an hashref.
1095 Set C<$category> on input args if you want to limits your query to this one. This params is not mandatory.
1099 sub GetAuthorisedValues {
1100 my $category = shift;
1101 my $dbh = C4::Context->dbh;
1102 my $query = "SELECT * FROM authorised_values";
1103 $query .= " WHERE category = '" . $category . "'" if $category;
1105 my $sth = $dbh->prepare($query);
1107 my $data = $sth->fetchall_arrayref({});
1113 $marcrecord = &fixEncoding($marcblob);
1115 Returns a well encoded marcrecord.
1120 my $record = MARC::Record->new_from_usmarc($marc);
1121 if (C4::Context->preference("MARCFLAVOUR") eq "UNIMARC"){
1123 my $targetcharset="utf8" if (C4::Context->preference("TemplateEncoding") eq "utf-8");
1124 $targetcharset="latin1" if (C4::Context->preference("TemplateEncoding") eq "iso-8859-1");
1125 my $decoder = guess_encoding($marc, qw/utf8 latin1/);
1126 # die $decoder unless ref($decoder);
1127 if (ref($decoder)) {
1128 my $newRecord=MARC::Record->new();
1129 foreach my $field ($record->fields()){
1130 if ($field->tag()<'010'){
1131 $newRecord->insert_grouped_field($field);
1135 foreach my $subfield ($field->subfields()){
1137 if (($newField->tag eq '100')) {
1138 substr($subfield->[1],26,2,"0103") if ($targetcharset eq "latin1");
1139 substr($subfield->[1],26,4,"5050") if ($targetcharset eq "utf8");
1141 map {C4::Biblio::char_decode($_,"UNIMARC")} @$subfield;
1142 $newField->add_subfields($subfield->[0]=>$subfield->[1]);
1144 map {C4::Biblio::char_decode($_,"UNIMARC")} @$subfield;
1145 $newField=MARC::Field->new($field->tag(),$field->indicator(1),$field->indicator(2),$subfield->[0]=>$subfield->[1]);
1149 $newRecord->insert_grouped_field($newField);
1152 # warn $newRecord->as_formatted();
1162 =head2 GetKohaAuthorisedValues
1164 Takes $dbh , $kohafield as parameters.
1165 returns hashref of authvalCode => liblibrarian
1166 or undef if no authvals defined for kohafield.
1170 sub GetKohaAuthorisedValues {
1171 my ($kohafield) = @_;
1173 my $dbh = C4::Context->dbh;
1174 my $sthnflstatus = $dbh->prepare('select authorised_value from marc_subfield_structure where kohafield=?');
1175 $sthnflstatus->execute($kohafield);
1176 my $authorised_valuecode = $sthnflstatus->fetchrow;
1177 if ($authorised_valuecode) {
1178 $sthnflstatus = $dbh->prepare("select authorised_value, lib from authorised_values where category=? ");
1179 $sthnflstatus->execute($authorised_valuecode);
1180 while ( my ($val, $lib) = $sthnflstatus->fetchrow_array ) {
1181 $values{$val}= $lib;