MT1109 , follow-up to 888cde546e5c62d71f312755f4a1dbc8631626eb
[koha.git] / authorities / authorities-list.pl
blob435948921d2a91526b4b02af624db6a897e9bb24
1 #!/usr/bin/perl
2 use strict;
3 use warnings;
4 use C4::Context;
5 use C4::AuthoritiesMarc;
6 use utf8;
7 my $dbh=C4::Context->dbh;
8 my $datatypes_query = $dbh->prepare(<<ENDSQL);
9 SELECT authtypecode,authtypetext,auth_tag_to_report from auth_types;
10 ENDSQL
11 $datatypes_query->execute;
12 my $datatypes=$datatypes_query->fetchall_arrayref({});
13 my %authtypes;
14 map { $authtypes{$_->{'authtypecode'}}={"tag"=> $_->{'auth_tag_to_report'}, "lib"=> $_->{'authtypetext'}};} @$datatypes;
15 my $data_query = $dbh->prepare(<<ENDSQL);
16 SELECT authid, authtypecode from auth_header
17 ENDSQL
18 $data_query->execute;
19 my $dataauthorities=$data_query->fetchall_arrayref({});
20 print "id;authtype;heading;count usage\n";
21 foreach my $authority (@$dataauthorities){
22 my $marcauthority=GetAuthority($authority->{'authid'});
23 if ($marcauthority && $marcauthority->field($authtypes{$authority->{'authtypecode'}}->{'tag'})){
24 print qq($authority->{'authid'};"),$authtypes{$authority->{'authtypecode'}}->{'lib'},qq(";"),$marcauthority->field($authtypes{$authority->{'authtypecode'}}->{"tag"})->as_string(),qq(";), CountUsage($authority->{authid}),"\n";