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($env);
490 @queues = keys %$printers;
492 Returns information about existing printer queues.
496 C<$printers> is a reference-to-hash whose keys are the print queues
497 defined in the printers table of the Koha database. The values are
498 references-to-hash, whose keys are the fields in the printers table.
505 my $dbh = C4::Context->dbh;
506 my $sth = $dbh->prepare("select * from printers");
508 while ( my $printer = $sth->fetchrow_hashref ) {
509 $printers{ $printer->{'printqueue'} } = $printer;
511 return ( \%printers );
516 $printer = GetPrinter( $query, $printers );
520 sub GetPrinter ($$) {
521 my ( $query, $printers ) = @_; # get printer for this query from printers
522 my $printer = $query->param('printer');
523 my %cookie = $query->cookie('userenv');
524 ($printer) || ( $printer = $cookie{'printer'} ) || ( $printer = '' );
525 ( $printers->{$printer} ) || ( $printer = ( keys %$printers )[0] );
531 Returns the number of pages to display in a pagination bar, given the number
532 of items and the number of items per page.
537 my ( $nb_items, $nb_items_per_page ) = @_;
539 return int( ( $nb_items - 1 ) / $nb_items_per_page ) + 1;
544 (@themes) = &getallthemes('opac');
545 (@themes) = &getallthemes('intranet');
547 Returns an array of all available themes.
555 if ( $type eq 'intranet' ) {
556 $htdocs = C4::Context->config('intrahtdocs');
559 $htdocs = C4::Context->config('opachtdocs');
561 opendir D, "$htdocs";
562 my @dirlist = readdir D;
563 foreach my $directory (@dirlist) {
564 -d "$htdocs/$directory/en" and push @themes, $directory;
571 if ( C4::Context->preference("marcflavour") eq "UNIMARC" ) {
574 link_value => 'su-to',
575 label_value => 'Topics',
577 [ '600', '601', '602', '603', '604', '605', '606', '610' ],
581 link_value => 'su-geo',
582 label_value => 'Places',
587 link_value => 'su-ut',
588 label_value => 'Titles',
589 tags => [ '500', '501', '502', '503', '504', ],
594 label_value => 'Authors',
595 tags => [ '700', '701', '702', ],
600 label_value => 'Series',
605 link_value => 'branch',
606 label_value => 'Branches',
616 link_value => 'su-to',
617 label_value => 'Topics',
623 # link_value => 'su-na',
624 # label_value => 'People and Organizations',
625 # tags => ['600', '610', '611'],
629 link_value => 'su-geo',
630 label_value => 'Places',
635 link_value => 'su-ut',
636 label_value => 'Titles',
642 label_value => 'Authors',
643 tags => [ '100', '110', '700', ],
648 label_value => 'Series',
649 tags => [ '440', '490', ],
653 link_value => 'branch',
654 label_value => 'Branches',
666 Return a href where a key is associated to a href. You give a query, the
667 name of the key among the fields returned by the query. If you also give as
668 third argument the name of the value, the function returns a href of scalar.
677 # generic href of any information on the item, href of href.
678 my $iteminfos_of = get_infos_of($query, 'itemnumber');
679 print $iteminfos_of->{$itemnumber}{barcode};
681 # specific information, href of scalar
682 my $barcode_of_item = get_infos_of($query, 'itemnumber', 'barcode');
683 print $barcode_of_item->{$itemnumber};
688 my ( $query, $key_name, $value_name ) = @_;
690 my $dbh = C4::Context->dbh;
692 my $sth = $dbh->prepare($query);
696 while ( my $row = $sth->fetchrow_hashref ) {
697 if ( defined $value_name ) {
698 $infos_of{ $row->{$key_name} } = $row->{$value_name};
701 $infos_of{ $row->{$key_name} } = $row;
709 =head2 get_notforloan_label_of
711 my $notforloan_label_of = get_notforloan_label_of();
713 Each authorised value of notforloan (information available in items and
714 itemtypes) is link to a single label.
716 Returns a href where keys are authorised values and values are corresponding
719 foreach my $authorised_value (keys %{$notforloan_label_of}) {
721 "authorised_value: %s => %s\n",
723 $notforloan_label_of->{$authorised_value}
729 sub get_notforloan_label_of {
730 my $dbh = C4::Context->dbh;
733 SELECT authorised_value
734 FROM marc_subfield_structure
735 WHERE kohafield = \'items.notforloan\'
738 my $sth = $dbh->prepare($query);
740 my ($statuscode) = $sth->fetchrow_array();
745 FROM authorised_values
748 $sth = $dbh->prepare($query);
749 $sth->execute($statuscode);
750 my %notforloan_label_of;
751 while ( my $row = $sth->fetchrow_hashref ) {
752 $notforloan_label_of{ $row->{authorised_value} } = $row->{lib};
756 return \%notforloan_label_of;
761 $sort_by =~ s/</\</;
762 $sort_by =~ s/>/\>/;
764 { value => "1=9523 >i", label => "Popularity (Most to Least)" },
765 { value => "1=9523 <i", label => "Popularity (Least to Most)" },
766 { value => "1=1003 <i", label => "Author (A-Z)" },
767 { value => "1=1003 >i", label => "Author (Z-A)" },
769 value => "1=20 <i",
770 label => "Call Number (Non-fiction 0-9 to Fiction A-Z)"
773 value => "1=20 >i",
774 label => "Call Number (Fiction Z-A to Non-fiction 9-0)"
776 { value => "1=31 >i", label => "Dates" },
778 value => "1=31 >i",
780 " Publication/Copyright Date: Newest to Oldest"
783 value => "1=31 <i",
785 " Publication/Copyright Date: Oldest to Newest"
788 value => "1=32 >i",
789 label => " Acquisition Date: Newest to Oldest"
792 value => "1=32 <i",
793 label => " Acquisition Date: Oldest to Newest"
795 { value => "1=36 <i", label => "Title (A-Z)" },
796 { value => "1=36 >i", label => "Title (Z-A)" },
798 for my $hash (@$sort_by_loop) {
800 #warn "sort by: $sort_by ... hash:".$hash->{value};
801 if ($sort_by && $hash->{value} eq $sort_by ) {
802 $hash->{selected} = "selected";
805 return $sort_by_loop;
811 { value => '', label => 'Keyword' },
812 { value => 'au', label => 'Author' },
815 label => ' Author Phrase'
817 { value => 'cpn', label => ' Corporate Name' },
818 { value => 'cfn', label => ' Conference Name' },
821 label => ' Corporate Name Phrase'
825 label => ' Conference Name Phrase'
827 { value => 'pn', label => ' Personal Name' },
830 label => ' Personal Name Phrase'
832 { value => 'ln', label => 'Language' },
834 # { value => 'mt', label => 'Material Type' },
835 # { value => 'mt,phr', label => 'Material Type Phrase' },
836 # { value => 'mc', label => 'Musical Composition' },
837 # { value => 'mc,phr', label => 'Musical Composition Phrase' },
839 { value => 'nt', label => 'Notes/Comments' },
840 { value => 'pb', label => 'Publisher' },
841 { value => 'pl', label => 'Publisher Location' },
842 { value => 'sn', label => 'Standard Number' },
843 { value => 'nb', label => ' ISBN' },
844 { value => 'ns', label => ' ISSN' },
845 { value => 'lcn', label => ' Call Number' },
846 { value => 'su', label => 'Subject' },
849 label => ' Subject Phrase'
852 # { value => 'de', label => ' Descriptor' },
853 # { value => 'ge', label => ' Genre/Form' },
854 # { value => 'gc', label => ' Geographic Coverage' },
856 # { value => 'nc', label => ' Named Corporation and Conference' },
857 # { value => 'na', label => ' Named Person' },
859 { value => 'ti', label => 'Title' },
860 { value => 'ti,phr', label => ' Title Phrase' },
861 { value => 'se', label => ' Series Title' },
866 sub displaySubtypesLimit {
867 my $outer_subtype_limits_loop = [
869 { # in MARC21, aud codes are stored in 008/22 (Target audience)
871 inner_subtype_limits_loop => [
874 label => 'Any Audience',
875 selected => "selected"
877 { value => 'aud:a', label => 'Easy', },
878 { value => 'aud:c', label => 'Juvenile', },
879 { value => 'aud:d', label => 'Young Adult', },
880 { value => 'aud:e', label => 'Adult', },
884 { # in MARC21, fic is in 008/33, bio in 008/34, mus in LDR/06
886 inner_subtype_limits_loop => [
887 { value => '', label => 'Any Content', selected => "selected" },
888 { value => 'fic:1', label => 'Fiction', },
889 { value => 'fic:0', label => 'Non Fiction', },
890 { value => 'bio:b', label => 'Biography', },
891 { value => 'mus:j', label => 'Musical recording', },
892 { value => 'mus:i', label => 'Non-musical recording', },
896 { # MARC21, these are codes stored in 007/00-01
898 inner_subtype_limits_loop => [
899 { value => '', label => 'Any Format', selected => "selected" },
900 { value => 'l-format:ta', label => 'Regular print', },
901 { value => 'l-format:tb', label => 'Large print', },
902 { value => 'l-format:fk', label => 'Braille', },
903 { value => '', label => '-----------', },
904 { value => 'l-format:sd', label => 'CD audio', },
905 { value => 'l-format:ss', label => 'Cassette recording', },
907 value => 'l-format:vf',
908 label => 'VHS tape / Videocassette',
910 { value => 'l-format:vd', label => 'DVD video / Videodisc', },
911 { value => 'l-format:co', label => 'CD Software', },
912 { value => 'l-format:cr', label => 'Website', },
916 { # in MARC21, these are codes in 008/24-28
918 inner_subtype_limits_loop => [
919 { value => '', label => 'Additional Content Types', },
920 { value => 'ctype:a', label => 'Abstracts/summaries', },
921 { value => 'ctype:b', label => 'Bibliographies', },
922 { value => 'ctype:c', label => 'Catalogs', },
923 { value => 'ctype:d', label => 'Dictionaries', },
924 { value => 'ctype:e', label => 'Encyclopedias ', },
925 { value => 'ctype:f', label => 'Handbooks', },
926 { value => 'ctype:g', label => 'Legal articles', },
927 { value => 'ctype:i', label => 'Indexes', },
928 { value => 'ctype:j', label => 'Patent document', },
929 { value => 'ctype:k', label => 'Discographies', },
930 { value => 'ctype:l', label => 'Legislation', },
931 { value => 'ctype:m', label => 'Theses', },
932 { value => 'ctype:n', label => 'Surveys', },
933 { value => 'ctype:o', label => 'Reviews', },
934 { value => 'ctype:p', label => 'Programmed texts', },
935 { value => 'ctype:q', label => 'Filmographies', },
936 { value => 'ctype:r', label => 'Directories', },
937 { value => 'ctype:s', label => 'Statistics', },
938 { value => 'ctype:t', label => 'Technical reports', },
939 { value => 'ctype:v', label => 'Legal cases and case notes', },
940 { value => 'ctype:w', label => 'Law reports and digests', },
941 { value => 'ctype:z', label => 'Treaties ', },
945 return $outer_subtype_limits_loop;
948 sub displayLimitTypes {
949 my $outer_limit_types_loop = [
952 inner_limit_types_loop => [
957 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)",
958 icon => "search-books.gif",
960 "Books, Pamphlets, Technical reports, Manuscripts, Legal papers, Theses and dissertations",
967 value => "(mc-collection:DVD or mc-collection:AV or mc-collection:AVJ or mc-collection:AVJN or mc-collection:AVJNF or mc-collection:AVNF)",
968 icon => "search-movies.gif",
970 "Motion pictures, Videorecordings, Filmstrips, Slides, Transparencies, Photos, Cards, Charts, Drawings",
977 value => "(mc-collection:CDM)",
978 icon => "search-music.gif",
979 title => "Spoken, Books on CD and Cassette",
984 inner_limit_types_loop => [
986 label => "Audio Books",
987 id => "mc-audio-books",
989 value => "(mc-collection:AB or mc-collection:AC or mc-collection:JAC or mc-collection:YAC)",
990 icon => "search-audio-books.gif",
991 title => "Spoken, Books on CD and Cassette",
995 label => "Local History Materials",
996 id => "mc-local-history",
998 value => "mc-collection:LH",
999 icon => "Local history.gif",
1000 title => "Local History Materials",
1003 {label => "Large Print",
1004 id => "mc-large-print",
1006 value => "(mc-collection:LP or mc-collection:LPNF)",
1007 icon => "search-large-print.gif ",
1008 title => "Large Print",},
1011 { inner_limit_types_loop => [
1015 value => "(mc-collection:EASY or mc-collection:JNF or mc-collection:JF or mc-collection:JREF or mc-collection:JB)",
1016 icon => "search-kids.gif",
1019 {label => "Software/Internet",
1020 id => "mc-sofware-web",
1022 value => "(mc-collection:CDR)",
1023 icon => "search-software-web.gif",
1026 {label => "Reference",
1027 id => "mc-reference",
1029 value => "mc-collection:REF",
1030 icon => "search-reference.gif",
1031 title => "Reference",},
1037 return $outer_limit_types_loop;
1040 sub displayServers {
1041 my ( $position, $type ) = @_;
1042 my $dbh = C4::Context->dbh;
1043 my $strsth = "SELECT * FROM z3950servers where 1";
1044 $strsth .= " AND position=\"$position\"" if ($position);
1045 $strsth .= " AND type=\"$type\"" if ($type);
1046 my $rq = $dbh->prepare($strsth);
1048 my @primaryserverloop;
1050 while ( my $data = $rq->fetchrow_hashref ) {
1052 $cell{label} = $data->{'description'};
1053 $cell{id} = $data->{'name'};
1056 . ( $data->{port} ? ":" . $data->{port} : "" ) . "/"
1058 if ( $data->{host} );
1059 $cell{checked} = $data->{checked};
1060 push @primaryserverloop,
1062 label => $data->{description},
1063 id => $data->{name},
1065 value => $data->{host} . ":"
1066 . $data->{port} . "/"
1067 . $data->{database},
1068 checked => "checked",
1069 icon => $data->{icon},
1070 zed => $data->{type} eq 'zed',
1071 opensearch => $data->{type} eq 'opensearch'
1074 return \@primaryserverloop;
1077 sub displaySecondaryServers {
1079 # my $secondary_servers_loop = [
1080 # { inner_sup_servers_loop => [
1081 # {label => "Google", id=>"GOOG", value=>"google",icon => "google.ico",opensearch => "1"},
1082 # {label => "Yahoo", id=>"YAH", value=>"yahoo", icon =>"yahoo.ico", zed => "1"},
1083 # {label => "Worldcat", id=>"WCT", value=>"worldcat", icon => "worldcat.gif", zed => "1"},
1084 # {label => "Library of Congress", id=>"LOC", name=> "server", value=>"z3950.loc.gov:7090/Voyager", icon =>"loc.ico", zed => "1"},
1088 return; #$secondary_servers_loop;
1091 =head2 GetAuthorisedValues
1093 $authvalues = GetAuthorisedValues($category);
1095 this function get all authorised values from 'authosied_value' table into a reference to array which
1096 each value containt an hashref.
1098 Set C<$category> on input args if you want to limits your query to this one. This params is not mandatory.
1102 sub GetAuthorisedValues {
1103 my $category = shift;
1104 my $dbh = C4::Context->dbh;
1105 my $query = "SELECT * FROM authorised_values";
1106 $query .= " WHERE category = '" . $category . "'" if $category;
1108 my $sth = $dbh->prepare($query);
1110 my $data = $sth->fetchall_arrayref({});
1116 $marcrecord = &fixEncoding($marcblob);
1118 Returns a well encoded marcrecord.
1123 my $record = MARC::Record->new_from_usmarc($marc);
1124 if (C4::Context->preference("MARCFLAVOUR") eq "UNIMARC"){
1126 my $targetcharset="utf8" if (C4::Context->preference("TemplateEncoding") eq "utf-8");
1127 $targetcharset="latin1" if (C4::Context->preference("TemplateEncoding") eq "iso-8859-1");
1128 my $decoder = guess_encoding($marc, qw/utf8 latin1/);
1129 # die $decoder unless ref($decoder);
1130 if (ref($decoder)) {
1131 my $newRecord=MARC::Record->new();
1132 foreach my $field ($record->fields()){
1133 if ($field->tag()<'010'){
1134 $newRecord->insert_grouped_field($field);
1138 foreach my $subfield ($field->subfields()){
1140 if (($newField->tag eq '100')) {
1141 substr($subfield->[1],26,2,"0103") if ($targetcharset eq "latin1");
1142 substr($subfield->[1],26,4,"5050") if ($targetcharset eq "utf8");
1144 map {C4::Biblio::char_decode($_,"UNIMARC")} @$subfield;
1145 $newField->add_subfields($subfield->[0]=>$subfield->[1]);
1147 map {C4::Biblio::char_decode($_,"UNIMARC")} @$subfield;
1148 $newField=MARC::Field->new($field->tag(),$field->indicator(1),$field->indicator(2),$subfield->[0]=>$subfield->[1]);
1152 $newRecord->insert_grouped_field($newField);
1155 # warn $newRecord->as_formatted();
1165 =head2 GetKohaAuthorisedValues
1167 Takes $dbh , $kohafield as parameters.
1168 returns hashref of authvalCode => liblibrarian
1169 or undef if no authvals defined for kohafield.
1173 sub GetKohaAuthorisedValues {
1174 my ($kohafield) = @_;
1176 my $dbh = C4::Context->dbh;
1177 my $sthnflstatus = $dbh->prepare('select authorised_value from marc_subfield_structure where kohafield=?');
1178 $sthnflstatus->execute($kohafield);
1179 my $authorised_valuecode = $sthnflstatus->fetchrow;
1180 if ($authorised_valuecode) {
1181 $sthnflstatus = $dbh->prepare("select authorised_value, lib from authorised_values where category=? ");
1182 $sthnflstatus->execute($authorised_valuecode);
1183 while ( my ($val, $lib) = $sthnflstatus->fetchrow_array ) {
1184 $values{$val}= $lib;