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
79 &GetKohaAuthorisedValues
87 $slash_date = &slashifyDate($dash_date);
89 Takes a string of the form "DD-MM-YYYY" (or anything separated by
90 dashes), converts it to the form "YYYY/MM/DD", and returns the result.
96 # accepts a date of the form xx-xx-xx[xx] and returns it in the
98 my @dateOut = split( '-', shift );
99 return ("$dateOut[2]/$dateOut[1]/$dateOut[0]");
105 my $string = DisplayISBN( $isbn );
112 if ( substr( $isbn, 0, 1 ) <= 7 ) {
113 $seg1 = substr( $isbn, 0, 1 );
115 elsif ( substr( $isbn, 0, 2 ) <= 94 ) {
116 $seg1 = substr( $isbn, 0, 2 );
118 elsif ( substr( $isbn, 0, 3 ) <= 995 ) {
119 $seg1 = substr( $isbn, 0, 3 );
121 elsif ( substr( $isbn, 0, 4 ) <= 9989 ) {
122 $seg1 = substr( $isbn, 0, 4 );
125 $seg1 = substr( $isbn, 0, 5 );
127 my $x = substr( $isbn, length($seg1) );
129 if ( substr( $x, 0, 2 ) <= 19 ) {
131 # if(sTmp2 < 10) sTmp2 = "0" sTmp2;
132 $seg2 = substr( $x, 0, 2 );
134 elsif ( substr( $x, 0, 3 ) <= 699 ) {
135 $seg2 = substr( $x, 0, 3 );
137 elsif ( substr( $x, 0, 4 ) <= 8399 ) {
138 $seg2 = substr( $x, 0, 4 );
140 elsif ( substr( $x, 0, 5 ) <= 89999 ) {
141 $seg2 = substr( $x, 0, 5 );
143 elsif ( substr( $x, 0, 6 ) <= 9499999 ) {
144 $seg2 = substr( $x, 0, 6 );
147 $seg2 = substr( $x, 0, 7 );
149 my $seg3 = substr( $x, length($seg2) );
150 $seg3 = substr( $seg3, 0, length($seg3) - 1 );
151 my $seg4 = substr( $x, -1, 1 );
152 return "$seg1-$seg2-$seg3-$seg4";
155 # FIXME.. this should be moved to a MARC-specific module
156 sub subfield_is_koha_internal_p ($) {
159 # We could match on 'lib' and 'tab' (and 'mandatory', & more to come!)
160 # But real MARC subfields are always single-character
161 # so it really is safer just to check the length
163 return length $subfield != 1;
168 $itemtypes = &GetItemTypes();
170 Returns information about existing itemtypes.
172 build a HTML select with the following code :
174 =head3 in PERL SCRIPT
176 my $itemtypes = GetItemTypes;
178 foreach my $thisitemtype (sort keys %$itemtypes) {
179 my $selected = 1 if $thisitemtype eq $itemtype;
180 my %row =(value => $thisitemtype,
181 selected => $selected,
182 description => $itemtypes->{$thisitemtype}->{'description'},
184 push @itemtypesloop, \%row;
186 $template->param(itemtypeloop => \@itemtypesloop);
190 <form action='<!-- TMPL_VAR name="script_name" -->' method=post>
191 <select name="itemtype">
192 <option value="">Default</option>
193 <!-- TMPL_LOOP name="itemtypeloop" -->
194 <option value="<!-- TMPL_VAR name="value" -->" <!-- TMPL_IF name="selected" -->selected<!-- /TMPL_IF -->><!-- TMPL_VAR name="description" --></option>
197 <input type=text name=searchfield value="<!-- TMPL_VAR name="searchfield" -->">
198 <input type="submit" value="OK" class="button">
206 # returns a reference to a hash of references to branches...
208 my $dbh = C4::Context->dbh;
213 my $sth = $dbh->prepare($query);
215 while ( my $IT = $sth->fetchrow_hashref ) {
216 $itemtypes{ $IT->{'itemtype'} } = $IT;
218 return ( \%itemtypes );
221 sub get_itemtypeinfos_of {
229 WHERE itemtype IN (' . join( ',', map( { "'" . $_ . "'" } @itemtypes ) ) . ')
232 return get_infos_of( $query, 'itemtype' );
235 # this is temporary until we separate collection codes and item types
239 my $dbh = C4::Context->dbh;
242 "SELECT * FROM authorised_values ORDER BY authorised_value");
244 while ( my $data = $sth->fetchrow_hashref ) {
245 if ( $data->{category} eq "CCODE" ) {
247 $results[$count] = $data;
253 return ( $count, @results );
258 grab itemlost authorized values
262 sub GetAuthItemlost {
263 my $itemlost = shift;
266 my $dbh = C4::Context->dbh;
269 "SELECT * FROM authorised_values ORDER BY authorised_value");
271 while ( my $data = $sth->fetchrow_hashref ) {
272 if ( $data->{category} eq "ITEMLOST" ) {
274 if ( $itemlost eq $data->{'authorised_value'} ) {
275 $data->{'selected'} = 1;
277 $results[$count] = $data;
283 return ( $count, @results );
286 =head2 GetAuthItembinding
288 grab itemlost authorized values
292 sub GetAuthItembinding {
293 my $itembinding = shift;
296 my $dbh = C4::Context->dbh;
299 "SELECT * FROM authorised_values ORDER BY authorised_value");
301 while ( my $data = $sth->fetchrow_hashref ) {
302 if ( $data->{category} eq "BINDING" ) {
304 if ( $itembinding eq $data->{'authorised_value'} ) {
305 $data->{'selected'} = 1;
307 $results[$count] = $data;
313 return ( $count, @results );
318 $authtypes = &getauthtypes();
320 Returns information about existing authtypes.
322 build a HTML select with the following code :
324 =head3 in PERL SCRIPT
326 my $authtypes = getauthtypes;
328 foreach my $thisauthtype (keys %$authtypes) {
329 my $selected = 1 if $thisauthtype eq $authtype;
330 my %row =(value => $thisauthtype,
331 selected => $selected,
332 authtypetext => $authtypes->{$thisauthtype}->{'authtypetext'},
334 push @authtypesloop, \%row;
336 $template->param(itemtypeloop => \@itemtypesloop);
340 <form action='<!-- TMPL_VAR name="script_name" -->' method=post>
341 <select name="authtype">
342 <!-- TMPL_LOOP name="authtypeloop" -->
343 <option value="<!-- TMPL_VAR name="value" -->" <!-- TMPL_IF name="selected" -->selected<!-- /TMPL_IF -->><!-- TMPL_VAR name="authtypetext" --></option>
346 <input type=text name=searchfield value="<!-- TMPL_VAR name="searchfield" -->">
347 <input type="submit" value="OK" class="button">
355 # returns a reference to a hash of references to authtypes...
357 my $dbh = C4::Context->dbh;
358 my $sth = $dbh->prepare("select * from auth_types order by authtypetext");
360 while ( my $IT = $sth->fetchrow_hashref ) {
361 $authtypes{ $IT->{'authtypecode'} } = $IT;
363 return ( \%authtypes );
367 my ($authtypecode) = @_;
369 # returns a reference to a hash of references to authtypes...
371 my $dbh = C4::Context->dbh;
372 my $sth = $dbh->prepare("select * from auth_types where authtypecode=?");
373 $sth->execute($authtypecode);
374 my $res = $sth->fetchrow_hashref;
380 $frameworks = &getframework();
382 Returns information about existing frameworks
384 build a HTML select with the following code :
386 =head3 in PERL SCRIPT
388 my $frameworks = frameworks();
390 foreach my $thisframework (keys %$frameworks) {
391 my $selected = 1 if $thisframework eq $frameworkcode;
392 my %row =(value => $thisframework,
393 selected => $selected,
394 description => $frameworks->{$thisframework}->{'frameworktext'},
396 push @frameworksloop, \%row;
398 $template->param(frameworkloop => \@frameworksloop);
402 <form action='<!-- TMPL_VAR name="script_name" -->' method=post>
403 <select name="frameworkcode">
404 <option value="">Default</option>
405 <!-- TMPL_LOOP name="frameworkloop" -->
406 <option value="<!-- TMPL_VAR name="value" -->" <!-- TMPL_IF name="selected" -->selected<!-- /TMPL_IF -->><!-- TMPL_VAR name="frameworktext" --></option>
409 <input type=text name=searchfield value="<!-- TMPL_VAR name="searchfield" -->">
410 <input type="submit" value="OK" class="button">
418 # returns a reference to a hash of references to branches...
420 my $dbh = C4::Context->dbh;
421 my $sth = $dbh->prepare("select * from biblio_framework");
423 while ( my $IT = $sth->fetchrow_hashref ) {
424 $itemtypes{ $IT->{'frameworkcode'} } = $IT;
426 return ( \%itemtypes );
429 =head2 getframeworkinfo
431 $frameworkinfo = &getframeworkinfo($frameworkcode);
433 Returns information about an frameworkcode.
437 sub getframeworkinfo {
438 my ($frameworkcode) = @_;
439 my $dbh = C4::Context->dbh;
441 $dbh->prepare("select * from biblio_framework where frameworkcode=?");
442 $sth->execute($frameworkcode);
443 my $res = $sth->fetchrow_hashref;
447 =head2 getitemtypeinfo
449 $itemtype = &getitemtype($itemtype);
451 Returns information about an itemtype.
455 sub getitemtypeinfo {
457 my $dbh = C4::Context->dbh;
458 my $sth = $dbh->prepare("select * from itemtypes where itemtype=?");
459 $sth->execute($itemtype);
460 my $res = $sth->fetchrow_hashref;
462 $res->{imageurl} = getitemtypeimagesrcfromurl( $res->{imageurl} );
467 sub getitemtypeimagesrcfromurl {
470 if ( defined $imageurl and $imageurl !~ m/^http/ ) {
471 $imageurl = getitemtypeimagesrc() . '/' . $imageurl;
477 sub getitemtypeimagedir {
478 return C4::Context->opachtdocs . '/'
479 . C4::Context->preference('template')
483 sub getitemtypeimagesrc {
484 return '/opac-tmpl' . '/'
485 . C4::Context->preference('template')
491 $printers = &GetPrinters($env);
492 @queues = keys %$printers;
494 Returns information about existing printer queues.
498 C<$printers> is a reference-to-hash whose keys are the print queues
499 defined in the printers table of the Koha database. The values are
500 references-to-hash, whose keys are the fields in the printers table.
507 my $dbh = C4::Context->dbh;
508 my $sth = $dbh->prepare("select * from printers");
510 while ( my $printer = $sth->fetchrow_hashref ) {
511 $printers{ $printer->{'printqueue'} } = $printer;
513 return ( \%printers );
518 $printer = GetPrinter( $query, $printers );
522 sub GetPrinter ($$) {
523 my ( $query, $printers ) = @_; # get printer for this query from printers
524 my $printer = $query->param('printer');
525 my %cookie = $query->cookie('userenv');
526 ($printer) || ( $printer = $cookie{'printer'} ) || ( $printer = '' );
527 ( $printers->{$printer} ) || ( $printer = ( keys %$printers )[0] );
533 Returns the number of pages to display in a pagination bar, given the number
534 of items and the number of items per page.
539 my ( $nb_items, $nb_items_per_page ) = @_;
541 return int( ( $nb_items - 1 ) / $nb_items_per_page ) + 1;
546 (@themes) = &getallthemes('opac');
547 (@themes) = &getallthemes('intranet');
549 Returns an array of all available themes.
557 if ( $type eq 'intranet' ) {
558 $htdocs = C4::Context->config('intrahtdocs');
561 $htdocs = C4::Context->config('opachtdocs');
563 opendir D, "$htdocs";
564 my @dirlist = readdir D;
565 foreach my $directory (@dirlist) {
566 -d "$htdocs/$directory/en" and push @themes, $directory;
573 if ( C4::Context->preference("marcflavour") eq "UNIMARC" ) {
576 link_value => 'su-to',
577 label_value => 'Topics',
579 [ '600', '601', '602', '603', '604', '605', '606', '610' ],
583 link_value => 'su-geo',
584 label_value => 'Places',
589 link_value => 'su-ut',
590 label_value => 'Titles',
591 tags => [ '500', '501', '502', '503', '504', ],
596 label_value => 'Authors',
597 tags => [ '700', '701', '702', ],
602 label_value => 'Series',
607 link_value => 'branch',
608 label_value => 'Branches',
618 link_value => 'su-to',
619 label_value => 'Topics',
625 # link_value => 'su-na',
626 # label_value => 'People and Organizations',
627 # tags => ['600', '610', '611'],
631 link_value => 'su-geo',
632 label_value => 'Places',
637 link_value => 'su-ut',
638 label_value => 'Titles',
644 label_value => 'Authors',
645 tags => [ '100', '110', '700', ],
650 label_value => 'Series',
651 tags => [ '440', '490', ],
655 link_value => 'branch',
656 label_value => 'Branches',
668 Return a href where a key is associated to a href. You give a query, the
669 name of the key among the fields returned by the query. If you also give as
670 third argument the name of the value, the function returns a href of scalar.
679 # generic href of any information on the item, href of href.
680 my $iteminfos_of = get_infos_of($query, 'itemnumber');
681 print $iteminfos_of->{$itemnumber}{barcode};
683 # specific information, href of scalar
684 my $barcode_of_item = get_infos_of($query, 'itemnumber', 'barcode');
685 print $barcode_of_item->{$itemnumber};
690 my ( $query, $key_name, $value_name ) = @_;
692 my $dbh = C4::Context->dbh;
694 my $sth = $dbh->prepare($query);
698 while ( my $row = $sth->fetchrow_hashref ) {
699 if ( defined $value_name ) {
700 $infos_of{ $row->{$key_name} } = $row->{$value_name};
703 $infos_of{ $row->{$key_name} } = $row;
711 =head2 get_notforloan_label_of
713 my $notforloan_label_of = get_notforloan_label_of();
715 Each authorised value of notforloan (information available in items and
716 itemtypes) is link to a single label.
718 Returns a href where keys are authorised values and values are corresponding
721 foreach my $authorised_value (keys %{$notforloan_label_of}) {
723 "authorised_value: %s => %s\n",
725 $notforloan_label_of->{$authorised_value}
731 sub get_notforloan_label_of {
732 my $dbh = C4::Context->dbh;
735 SELECT authorised_value
736 FROM marc_subfield_structure
737 WHERE kohafield = \'items.notforloan\'
740 my $sth = $dbh->prepare($query);
742 my ($statuscode) = $sth->fetchrow_array();
747 FROM authorised_values
750 $sth = $dbh->prepare($query);
751 $sth->execute($statuscode);
752 my %notforloan_label_of;
753 while ( my $row = $sth->fetchrow_hashref ) {
754 $notforloan_label_of{ $row->{authorised_value} } = $row->{lib};
758 return \%notforloan_label_of;
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 sub GetDepartments {
1092 my $dbh = C4::Context->dbh;
1093 my $sth = $dbh->prepare(
1094 "SELECT authorised_value,lib FROM authorised_values WHERE category='DPT'
1100 while ( my $data = $sth->fetchrow_hashref ) {
1101 $getdepartments[$i] = $data;
1105 return (@getdepartments);
1108 sub GetDepartmentLib {
1109 my ($authorisedvalue) = @_;
1110 my $dbh = C4::Context->dbh;
1111 my $sth = $dbh->prepare(
1112 "SELECT lib,authorised_value FROM authorised_values WHERE category='DPT' AND authorised_value=?
1115 $sth->execute($authorisedvalue);
1116 my (@lib) = $sth->fetchrow_array;
1121 =head2 GetAuthorisedValues
1123 $authvalues = GetAuthorisedValues($category);
1125 this function get all authorised values from 'authosied_value' table into a reference to array which
1126 each value containt an hashref.
1128 Set C<$category> on input args if you want to limits your query to this one. This params is not mandatory.
1132 sub GetAuthorisedValues {
1133 my $category = shift;
1134 my $dbh = C4::Context->dbh;
1135 my $query = "SELECT * FROM authorised_values";
1136 $query .= " WHERE category = '" . $category . "'" if $category;
1138 my $sth = $dbh->prepare($query);
1140 my $data = $sth->fetchall_arrayref({});
1146 $marcrecord = &fixEncoding($marcblob);
1148 Returns a well encoded marcrecord.
1153 my $record = MARC::Record->new_from_usmarc($marc);
1154 if (C4::Context->preference("MARCFLAVOUR") eq "UNIMARC"){
1156 my $targetcharset="utf8" if (C4::Context->preference("TemplateEncoding") eq "utf-8");
1157 $targetcharset="latin1" if (C4::Context->preference("TemplateEncoding") eq "iso-8859-1");
1158 my $decoder = guess_encoding($marc, qw/utf8 latin1/);
1159 # die $decoder unless ref($decoder);
1160 if (ref($decoder)) {
1161 my $newRecord=MARC::Record->new();
1162 foreach my $field ($record->fields()){
1163 if ($field->tag()<'010'){
1164 $newRecord->insert_grouped_field($field);
1168 foreach my $subfield ($field->subfields()){
1170 if (($newField->tag eq '100')) {
1171 substr($subfield->[1],26,2,"0103") if ($targetcharset eq "latin1");
1172 substr($subfield->[1],26,4,"5050") if ($targetcharset eq "utf8");
1174 map {C4::Biblio::char_decode($_,"UNIMARC")} @$subfield;
1175 $newField->add_subfields($subfield->[0]=>$subfield->[1]);
1177 map {C4::Biblio::char_decode($_,"UNIMARC")} @$subfield;
1178 $newField=MARC::Field->new($field->tag(),$field->indicator(1),$field->indicator(2),$subfield->[0]=>$subfield->[1]);
1182 $newRecord->insert_grouped_field($newField);
1185 # warn $newRecord->as_formatted();
1195 =head2 GetKohaAuthorisedValues
1197 Takes $dbh , $kohafield as parameters.
1198 returns hashref of authvalCode => liblibrarian
1199 or undef if no authvals defined for kohafield.
1203 sub GetKohaAuthorisedValues {
1204 my ($kohafield) = @_;
1206 my $dbh = C4::Context->dbh;
1207 my $sthnflstatus = $dbh->prepare('select authorised_value from marc_subfield_structure where kohafield=?');
1208 $sthnflstatus->execute($kohafield);
1209 my $authorised_valuecode = $sthnflstatus->fetchrow;
1210 if ($authorised_valuecode) {
1211 $sthnflstatus = $dbh->prepare("select authorised_value, lib from authorised_values where category=? ");
1212 $sthnflstatus->execute($authorised_valuecode);
1213 while ( my ($val, $lib) = $sthnflstatus->fetchrow_array ) {
1214 $values{$val}= $lib;