(bug #3174) fill borrower number, and show author and creation date in saved reports
[koha.git] / C4 / Reports / Guided.pm
1 package C4::Reports::Guided;
2
3 # Copyright 2007 Liblime Ltd
4 #
5 # This file is part of Koha.
6 #
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
10 # version.
11 #
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.
15 #
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
19
20 use strict;
21 # use warnings;  # FIXME: this module needs a lot of repair to run clean under warnings
22 use CGI;
23 use Carp;
24
25 use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
26 use C4::Context;
27 use C4::Dates qw/format_date/;
28 use C4::Output;
29 use C4::Dates;
30 use XML::Simple;
31 use XML::Dumper;
32 use C4::Debug;
33 # use Smart::Comments;
34 # use Data::Dumper;
35
36 BEGIN {
37         # set the version for version checking
38         $VERSION = 0.12;
39         require Exporter;
40         @ISA = qw(Exporter);
41         @EXPORT = qw(
42                 get_report_types get_report_areas get_columns build_query get_criteria
43             save_report get_saved_reports execute_query get_saved_report create_compound run_compound
44                 get_column_type get_distinct_values save_dictionary get_from_dictionary
45                 delete_definition delete_report format_results get_sql
46         select_2_select_count_value update_sql
47         );
48 }
49
50 our %table_areas;
51 $table_areas{'1'} =
52   [ 'borrowers', 'statistics','items', 'biblioitems' ];    # circulation
53 $table_areas{'2'} = [ 'items', 'biblioitems', 'biblio' ];   # catalogue
54 $table_areas{'3'} = [ 'borrowers' ];        # patrons
55 $table_areas{'4'} = ['aqorders', 'biblio', 'items'];        # acquisitions
56 $table_areas{'5'} = [ 'borrowers', 'accountlines' ];        # accounts
57 our %keys;
58 $keys{'1'} = [
59     'statistics.borrowernumber=borrowers.borrowernumber',
60     'items.itemnumber = statistics.itemnumber',
61     'biblioitems.biblioitemnumber = items.biblioitemnumber'
62 ];
63 $keys{'2'} = [
64     'items.biblioitemnumber=biblioitems.biblioitemnumber',
65     'biblioitems.biblionumber=biblio.biblionumber'
66 ];
67 $keys{'3'} = [ ];
68 $keys{'4'} = [
69         'aqorders.biblionumber=biblio.biblionumber',
70         'biblio.biblionumber=items.biblionumber'
71 ];
72 $keys{'5'} = ['borrowers.borrowernumber=accountlines.borrowernumber'];
73
74 # have to do someting here to know if its dropdown, free text, date etc
75
76 our %criteria;
77 $criteria{'1'} = [
78     'statistics.type',   'borrowers.categorycode',
79     'statistics.branch',
80     'biblioitems.publicationyear|date',
81     'items.dateaccessioned|date'
82 ];
83 $criteria{'2'} =
84   [ 'items.holdingbranch', 'items.homebranch' ,'items.itemlost', 'items.location', 'items.ccode'];
85 $criteria{'3'} = ['borrowers.branchcode'];
86 $criteria{'4'} = ['aqorders.datereceived|date'];
87 $criteria{'5'} = ['borrowers.branchcode'];
88
89 if (C4::Context->preference('item-level_itypes')) {
90     unshift @{ $criteria{'1'} }, 'items.itype';
91     unshift @{ $criteria{'2'} }, 'items.itype';
92 } else {
93     unshift @{ $criteria{'1'} }, 'biblioitems.itemtype';
94     unshift @{ $criteria{'2'} }, 'biblioitems.itemtype';
95 }
96
97 =head1 NAME
98    
99 C4::Reports::Guided - Module for generating guided reports 
100
101 =head1 SYNOPSIS
102
103   use C4::Reports::Guided;
104
105 =head1 DESCRIPTION
106
107
108 =head1 METHODS
109
110 =over 2
111
112 =cut
113
114 =item get_report_types()
115
116 This will return a list of all the available report types
117
118 =cut
119
120 sub get_report_types {
121     my $dbh = C4::Context->dbh();
122
123     # FIXME these should be in the database perhaps
124     my @reports = ( 'Tabular', 'Summary', 'Matrix' );
125     my @reports2;
126     for ( my $i = 0 ; $i < 3 ; $i++ ) {
127         my %hashrep;
128         $hashrep{id}   = $i + 1;
129         $hashrep{name} = $reports[$i];
130         push @reports2, \%hashrep;
131     }
132     return ( \@reports2 );
133
134 }
135
136 =item get_report_areas()
137
138 This will return a list of all the available report areas
139
140 =cut
141
142 sub get_report_areas {
143     my $dbh = C4::Context->dbh();
144
145     # FIXME these should be in the database
146     my @reports = ( 'Circulation', 'Catalog', 'Patrons', 'Acquisitions', 'Accounts');
147     my @reports2;
148     for ( my $i = 0 ; $i < 5 ; $i++ ) {
149         my %hashrep;
150         $hashrep{id}   = $i + 1;
151         $hashrep{name} = $reports[$i];
152         push @reports2, \%hashrep;
153     }
154     return ( \@reports2 );
155
156 }
157
158 =item get_all_tables()
159
160 This will return a list of all tables in the database 
161
162 =cut
163
164 sub get_all_tables {
165     my $dbh   = C4::Context->dbh();
166     my $query = "SHOW TABLES";
167     my $sth   = $dbh->prepare($query);
168     $sth->execute();
169     my @tables;
170     while ( my $data = $sth->fetchrow_arrayref() ) {
171         push @tables, $data->[0];
172     }
173     $sth->finish();
174     return ( \@tables );
175
176 }
177
178 =item get_columns($area)
179
180 This will return a list of all columns for a report area
181
182 =cut
183
184 sub get_columns {
185
186     # this calls the internal fucntion _get_columns
187     my ($area,$cgi) = @_;
188     my $tables = $table_areas{$area};
189     my @allcolumns;
190     my $first = 1;
191     foreach my $table (@$tables) {
192         my @columns = _get_columns($table,$cgi, $first);
193         $first = 0;
194         push @allcolumns, @columns;
195     }
196     return ( \@allcolumns );
197 }
198
199 sub _get_columns {
200     my ($tablename,$cgi, $first) = @_;
201     my $dbh         = C4::Context->dbh();
202     my $sth         = $dbh->prepare("show columns from $tablename");
203     $sth->execute();
204     my @columns;
205         my $column_defs = _get_column_defs($cgi);
206         my %tablehash;
207         $tablehash{'table'}=$tablename;
208     $tablehash{'__first__'} = $first;
209         push @columns, \%tablehash;
210     while ( my $data = $sth->fetchrow_arrayref() ) {
211         my %temphash;
212         $temphash{'name'}        = "$tablename.$data->[0]";
213         $temphash{'description'} = $column_defs->{"$tablename.$data->[0]"};
214         push @columns, \%temphash;
215     }
216     $sth->finish();
217     return (@columns);
218 }
219
220 =item build_query($columns,$criteria,$orderby,$area)
221
222 This will build the sql needed to return the results asked for, 
223 $columns is expected to be of the format tablename.columnname.
224 This is what get_columns returns.
225
226 =cut
227
228 sub build_query {
229     my ( $columns, $criteria, $orderby, $area, $totals, $definition ) = @_;
230 ### $orderby
231     my $keys   = $keys{$area};
232     my $tables = $table_areas{$area};
233
234     my $sql =
235       _build_query( $tables, $columns, $criteria, $keys, $orderby, $totals, $definition );
236     return ($sql);
237 }
238
239 sub _build_query {
240     my ( $tables, $columns, $criteria, $keys, $orderby, $totals, $definition) = @_;
241 ### $orderby
242     # $keys is an array of joining constraints
243     my $dbh           = C4::Context->dbh();
244     my $joinedtables  = join( ',', @$tables );
245     my $joinedcolumns = join( ',', @$columns );
246     my $joinedkeys    = join( ' AND ', @$keys );
247     my $query =
248       "SELECT $totals $joinedcolumns FROM $tables->[0] ";
249         for (my $i=1;$i<@$tables;$i++){
250                 $query .= "LEFT JOIN $tables->[$i] on ($keys->[$i-1]) ";
251         }
252
253     if ($criteria) {
254                 $criteria =~ s/AND/WHERE/;
255         $query .= " $criteria";
256     }
257         if ($definition){
258                 my @definitions = split(',',$definition);
259                 my $deftext;
260                 foreach my $def (@definitions){
261                         my $defin=get_from_dictionary('',$def);
262                         $deftext .=" ".$defin->[0]->{'saved_sql'};
263                 }
264                 if ($query =~ /WHERE/i){
265                         $query .= $deftext;
266                 }
267                 else {
268                         $deftext  =~ s/AND/WHERE/;
269                         $query .= $deftext;                     
270                 }
271         }
272     if ($totals) {
273         my $groupby;
274         my @totcolumns = split( ',', $totals );
275         foreach my $total (@totcolumns) {
276             if ( $total =~ /\((.*)\)/ ) {
277                 if ( $groupby eq '' ) {
278                     $groupby = " GROUP BY $1";
279                 }
280                 else {
281                     $groupby .= ",$1";
282                 }
283             }
284         }
285         $query .= $groupby;
286     }
287     if ($orderby) {
288         $query .= $orderby;
289     }
290     return ($query);
291 }
292
293 =item get_criteria($area,$cgi);
294
295 Returns an arraref to hashrefs suitable for using in a tmpl_loop. With the criteria and available values.
296
297 =cut
298
299 sub get_criteria {
300     my ($area,$cgi) = @_;
301     my $dbh    = C4::Context->dbh();
302     my $crit   = $criteria{$area};
303         my $column_defs = _get_column_defs($cgi);
304     my @criteria_array;
305     foreach my $localcrit (@$crit) {
306         my ( $value, $type )   = split( /\|/, $localcrit );
307         my ( $table, $column ) = split( /\./, $value );
308         if ( $type eq 'date' ) {
309                         my %temp;
310             $temp{'name'}   = $value;
311             $temp{'date'}   = 1;
312                         $temp{'description'} = $column_defs->{$value};
313             push @criteria_array, \%temp;
314         }
315         else {
316
317             my $query =
318               "SELECT distinct($column) as availablevalues FROM $table";
319             my $sth = $dbh->prepare($query);
320             $sth->execute();
321             my @values;
322             while ( my $row = $sth->fetchrow_hashref() ) {
323                 push @values, $row;
324                 ### $row;
325             }
326             $sth->finish();
327             my %temp;
328             $temp{'name'}   = $value;
329                         $temp{'description'} = $column_defs->{$value};
330             $temp{'values'} = \@values;
331             push @criteria_array, \%temp;
332         }
333     }
334     return ( \@criteria_array );
335 }
336
337 =item execute_query
338
339 =over
340
341 ($results, $error) = execute_query($sql, $offset, $limit)
342
343 =back
344
345     When passed C<$sql>, this function returns an array ref containing a result set
346     suitably formatted for display in html or for output as a flat file when passed in
347     C<$format> and C<$id>. It also returns the C<$total> records available for the
348     supplied query. If passed any query other than a SELECT, or if there is a db error,
349     C<$errors> an array ref is returned containing the error after this manner:
350
351     C<$error->{'sqlerr'}> contains the offending SQL keyword.
352     C<$error->{'queryerr'}> contains the native db engine error returned for the query.
353     
354     Valid values for C<$format> are 'text,' 'tab,' 'csv,' or 'url. C<$sql>, C<$type>,
355     C<$offset>, and C<$limit> are required parameters. If a valid C<$format> is passed
356     in, C<$offset> and C<$limit> are ignored for obvious reasons. A LIMIT specified by
357     the user in a user-supplied SQL query WILL apply in any case.
358
359 =cut
360
361 # returns $sql, $offset, $limit
362 # $sql returned will be transformed to:
363 #  ~ remove any LIMIT clause
364 #  ~ repace SELECT clause w/ SELECT count(*)
365
366 sub select_2_select_count_value ($) {
367     my $sql = shift or return;
368     my $countsql = select_2_select_count($sql);
369     $debug and warn "original query: $sql\ncount query: $countsql\n";
370     my $sth1 = C4::Context->dbh->prepare($countsql);
371     $sth1->execute();
372     my $total = $sth1->fetchrow();
373     $debug and warn "total records for this query: $total\n";
374     return $total;
375 }
376 sub select_2_select_count ($) {
377     # Modify the query passed in to create a count query... (I think this covers all cases -crn)
378     my ($sql) = strip_limit(shift) or return;
379     $sql =~ s/\bSELECT\W+(?:\w+\W+){1,}?FROM\b|\bSELECT\W\*\WFROM\b/SELECT count(*) FROM /ig;
380     return $sql;
381 }
382 sub strip_limit ($) {
383     my $sql = shift or return;
384     ($sql =~ /\bLIMIT\b/i) or return ($sql, 0, undef);
385     $sql =~ s/\bLIMIT\b\s*\d+(\,\s*\d+)?\s*/ /ig;
386     return ($sql, (defined $1 ? $1 : 0), $2);   # offset can default to 0, LIMIT cannot!
387 }
388
389 sub execute_query ($;$$$) {
390
391     my ( $sql, $offset, $limit, $no_count ) = @_;
392
393     # check parameters
394     unless ($sql) {
395         carp "execute_query() called without SQL argument";
396         return;
397     }
398     $offset = 0    unless $offset;
399     $limit  = 9999 unless $limit;
400     $debug and print STDERR "execute_query($sql, $offset, $limit)\n";
401     if ($sql =~ /;?\W?(UPDATE|DELETE|DROP|INSERT|SHOW|CREATE)\W/i) {
402         return (undef, {  sqlerr => $1} );
403     } elsif ($sql !~ /^\s*SELECT\b\s*/i) {
404         return (undef, { queryerr => 'Missing SELECT'} );
405     }
406     my ($useroffset, $userlimit);
407
408     # Grab offset/limit from user supplied LIMIT and drop the LIMIT so we can control pagination
409     ($sql, $useroffset, $userlimit) = strip_limit($sql);
410     $debug and warn sprintf "User has supplied (OFFSET,) LIMIT = %s, %s",
411         $useroffset,
412         (defined($userlimit ) ? $userlimit  : 'UNDEF');
413     $offset += $useroffset;
414     my $total;
415     if (defined($userlimit)) {
416         if ($offset + $limit > $userlimit ) {
417             $limit = $userlimit - $offset;
418         }
419         $total = $userlimit if $userlimit < $total;     # we will never exceed a user defined LIMIT and...
420         $userlimit = $total if $userlimit > $total;     # we will never exceed the total number of records available to satisfy the query
421     }
422     $sql .= " LIMIT ?, ?";
423
424     my $sth = C4::Context->dbh->prepare($sql);
425     $sth->execute($offset, $limit);
426     return ( $sth );
427     # my @xmlarray = ... ;
428     # my $url = "/cgi-bin/koha/reports/guided_reports.pl?phase=retrieve%20results&id=$id";
429     # my $xml = XML::Dumper->new()->pl2xml( \@xmlarray );
430     # store_results($id,$xml);
431 }
432
433 =item save_report($sql,$name,$type,$notes)
434
435 Given some sql and a name this will saved it so that it can resued
436
437 =cut
438
439 sub save_report {
440     my ( $borrowernumber, $sql, $name, $type, $notes ) = @_;
441     my $dbh = C4::Context->dbh();
442     $sql =~ s/(\s*\;\s*)$//; # removes trailing whitespace and /;/
443     my $query =
444 "INSERT INTO saved_sql (borrowernumber,date_created,last_modified,savedsql,report_name,type,notes)  VALUES (?,now(),now(),?,?,?,?)";
445     my $sth = $dbh->prepare($query);
446     $sth->execute( $borrowernumber, $sql, $name, $type, $notes );
447 }
448
449 sub update_sql {
450     my $id = shift || croak "No Id given";
451     my $sql = shift;
452     my $reportname = shift;
453     my $dbh = C4::Context->dbh();
454     $sql =~ s/(\s*\;\s*)$//; # removes trailing whitespace and /;/
455     my $query = "UPDATE saved_sql SET savedsql = ?, last_modified = now(), report_name = ? WHERE id = ? ";
456     my $sth = $dbh->prepare($query);
457     $sth->execute( $sql, $reportname, $id );
458     $sth->finish();
459 }
460
461 sub store_results {
462         my ($id,$xml)=@_;
463         my $dbh = C4::Context->dbh();
464         my $query = "SELECT * FROM saved_reports WHERE report_id=?";
465         my $sth = $dbh->prepare($query);
466         $sth->execute($id);
467         if (my $data=$sth->fetchrow_hashref()){
468                 my $query2 = "UPDATE saved_reports SET report=?,date_run=now() WHERE report_id=?";
469                 my $sth2 = $dbh->prepare($query2);
470             $sth2->execute($xml,$id);
471         }
472         else {
473                 my $query2 = "INSERT INTO saved_reports (report_id,report,date_run) VALUES (?,?,now())";
474                 my $sth2 = $dbh->prepare($query2);
475                 $sth2->execute($id,$xml);
476         }
477 }
478
479 sub format_results {
480         my ($id) = @_;
481         my $dbh = C4::Context->dbh();
482         my $query = "SELECT * FROM saved_reports WHERE report_id = ?";
483         my $sth = $dbh->prepare($query);
484         $sth->execute($id);
485         my $data = $sth->fetchrow_hashref();
486         my $dump = new XML::Dumper;
487         my $perl = $dump->xml2pl( $data->{'report'} );
488         foreach my $row (@$perl) {
489                 my $htmlrow="<tr>";
490                 foreach my $key (keys %$row){
491                         $htmlrow .= "<td>$row->{$key}</td>";
492                 }
493                 $htmlrow .= "</tr>";
494                 $row->{'row'} = $htmlrow;
495         }
496         $sth->finish;
497         $query = "SELECT * FROM saved_sql WHERE id = ?";
498         $sth = $dbh->prepare($query);
499         $sth->execute($id);
500         $data = $sth->fetchrow_hashref();
501         return ($perl,$data->{'report_name'},$data->{'notes'}); 
502 }       
503
504 sub delete_report {
505         my ( $id ) = @_;
506         my $dbh = C4::Context->dbh();
507         my $query = "DELETE FROM saved_sql WHERE id = ?";
508         my $sth = $dbh->prepare($query);
509         $sth->execute($id);
510 }       
511
512 sub get_saved_reports {
513     my $dbh   = C4::Context->dbh();
514     my $query = "SELECT *,saved_sql.id AS id FROM saved_sql 
515     LEFT JOIN saved_reports ON saved_reports.report_id = saved_sql.id
516     ORDER by date_created";
517     my $sth   = $dbh->prepare($query);
518     $sth->execute();
519     
520     my $result = $sth->fetchall_arrayref({});
521     foreach (@$result){
522         $_->{date_created} = format_date($_->{date_created}); 
523     }
524     return $result;
525 }
526
527 sub get_saved_report {
528     my ($id)  = @_;
529     my $dbh   = C4::Context->dbh();
530     my $query = " SELECT * FROM saved_sql WHERE id = ?";
531     my $sth   = $dbh->prepare($query);
532     $sth->execute($id);
533     my $data = $sth->fetchrow_hashref();
534     return ( $data->{'savedsql'}, $data->{'type'}, $data->{'report_name'}, $data->{'notes'} );
535 }
536
537 =item create_compound($masterID,$subreportID)
538
539 This will take 2 reports and create a compound report using both of them
540
541 =cut
542
543 sub create_compound {
544         my ($masterID,$subreportID) = @_;
545         my $dbh = C4::Context->dbh();
546         # get the reports
547         my ($mastersql,$mastertype) = get_saved_report($masterID);
548         my ($subsql,$subtype) = get_saved_report($subreportID);
549         
550         # now we have to do some checking to see how these two will fit together
551         # or if they will
552         my ($mastertables,$subtables);
553         if ($mastersql =~ / from (.*) where /i){ 
554                 $mastertables = $1;
555         }
556         if ($subsql =~ / from (.*) where /i){
557                 $subtables = $1;
558         }
559         return ($mastertables,$subtables);
560 }
561
562 =item get_column_type($column)
563
564 This takes a column name of the format table.column and will return what type it is
565 (free text, set values, date)
566
567 =cut
568
569 sub get_column_type {
570         my ($tablecolumn) = @_;
571         my ($table,$column) = split(/\./,$tablecolumn);
572         my $dbh = C4::Context->dbh();
573         my $catalog;
574         my $schema;
575
576         # mysql doesnt support a column selection, set column to %
577         my $tempcolumn='%';
578         my $sth = $dbh->column_info( $catalog, $schema, $table, $tempcolumn ) || die $dbh->errstr;
579         while (my $info = $sth->fetchrow_hashref()){
580                 if ($info->{'COLUMN_NAME'} eq $column){
581                         #column we want
582                         if ($info->{'TYPE_NAME'} eq 'CHAR' || $info->{'TYPE_NAME'} eq 'VARCHAR'){
583                                 $info->{'TYPE_NAME'} = 'distinct';
584                         }
585                         return $info->{'TYPE_NAME'};            
586                 }
587         }
588 }
589
590 =item get_distinct_values($column)
591
592 Given a column name, return an arrary ref of hashrefs suitable for use as a tmpl_loop 
593 with the distinct values of the column
594
595 =cut
596
597 sub get_distinct_values {
598         my ($tablecolumn) = @_;
599         my ($table,$column) = split(/\./,$tablecolumn);
600         my $dbh = C4::Context->dbh();
601         my $query =
602           "SELECT distinct($column) as availablevalues FROM $table";
603         my $sth = $dbh->prepare($query);
604         $sth->execute();
605     return $sth->fetchall_arrayref({});
606 }       
607
608 sub save_dictionary {
609         my ($name,$description,$sql,$area) = @_;
610         my $dbh = C4::Context->dbh();
611         my $query = "INSERT INTO reports_dictionary (name,description,saved_sql,area,date_created,date_modified)
612   VALUES (?,?,?,?,now(),now())";
613     my $sth = $dbh->prepare($query);
614     $sth->execute($name,$description,$sql,$area) || return 0;
615     return 1;
616 }
617
618 sub get_from_dictionary {
619         my ($area,$id) = @_;
620         my $dbh = C4::Context->dbh();
621         my $query = "SELECT * FROM reports_dictionary";
622         if ($area){
623                 $query.= " WHERE area = ?";
624         }
625         elsif ($id){
626                 $query.= " WHERE id = ?"
627         }
628         my $sth = $dbh->prepare($query);
629         if ($id){
630                 $sth->execute($id);
631         }
632         elsif ($area) {
633                 $sth->execute($area);
634         }
635         else {
636                 $sth->execute();
637         }
638         my @loop;
639         my @reports = ( 'Circulation', 'Catalog', 'Patrons', 'Acquisitions', 'Accounts');
640         while (my $data = $sth->fetchrow_hashref()){
641                 $data->{'areaname'}=$reports[$data->{'area'}-1];
642                 push @loop,$data;
643                 
644         }
645         return (\@loop);
646 }
647
648 sub delete_definition {
649         my ($id) = @_ or return;
650         my $dbh = C4::Context->dbh();
651         my $query = "DELETE FROM reports_dictionary WHERE id = ?";
652         my $sth = $dbh->prepare($query);
653         $sth->execute($id);
654 }
655
656 sub get_sql {
657         my ($id) = @_ or return;
658         my $dbh = C4::Context->dbh();
659         my $query = "SELECT * FROM saved_sql WHERE id = ?";
660         my $sth = $dbh->prepare($query);
661         $sth->execute($id);
662         my $data=$sth->fetchrow_hashref();
663         return $data->{'savedsql'};
664 }
665
666 sub _get_column_defs {
667         my ($cgi) = @_;
668         my %columns;
669         my $columns_def_file = "columns.def";
670         my $htdocs = C4::Context->config('intrahtdocs');                       
671         my $section='intranet';
672         my ($theme, $lang) = themelanguage($htdocs, $columns_def_file, $section,$cgi);
673
674         my $full_path_to_columns_def_file="$htdocs/$theme/$lang/$columns_def_file";    
675         open (COLUMNS,$full_path_to_columns_def_file);
676         while (my $input = <COLUMNS>){
677                 my @row =split(/\t/,$input);
678                 $columns{$row[0]}=$row[1];
679         }
680
681         close COLUMNS;
682         return \%columns;
683 }
684 1;
685 __END__
686
687 =back
688
689 =head1 AUTHOR
690
691 Chris Cormack <crc@liblime.com>
692
693 =cut