Adding Authorities list
[koha.git] / authorities / authorities-list.pl
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";
25   }
26 }