Fix bug 3330 - Report notes modification
[koha-equinox.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, $total, $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
407     my ($useroffset, $userlimit);
408
409     # Grab offset/limit from user supplied LIMIT and drop the LIMIT so we can control pagination
410     ($sql, $useroffset, $userlimit) = strip_limit($sql);
411     $debug and warn sprintf "User has supplied (OFFSET,) LIMIT = %s, %s",
412         $useroffset,
413         (defined($userlimit ) ? $userlimit  : 'UNDEF');
414     $offset += $useroffset;
415     my $total;
416     if (defined($userlimit)) {
417         if ($offset + $limit > $userlimit ) {
418             $limit = $userlimit - $offset;
419         }
420         $total = $userlimit if $userlimit < $total;     # we will never exceed a user defined LIMIT and...
421         $userlimit = $total if $userlimit > $total;     # we will never exceed the total number of records available to satisfy the query
422     }
423     $sql .= " LIMIT ?, ?";
424
425     my $sth = C4::Context->dbh->prepare($sql);
426     $sth->execute($offset, $limit);
427     return ( $sth );
428     # my @xmlarray = ... ;
429     # my $url = "/cgi-bin/koha/reports/guided_reports.pl?phase=retrieve%20results&id=$id";
430     # my $xml = XML::Dumper->new()->pl2xml( \@xmlarray );
431     # store_results($id,$xml);
432 }
433
434 =item save_report($sql,$name,$type,$notes)
435
436 Given some sql and a name this will saved it so that it can resued
437
438 =cut
439
440 sub save_report {
441     my ( $borrowernumber, $sql, $name, $type, $notes ) = @_;
442     my $dbh = C4::Context->dbh();
443     $sql =~ s/(\s*\;\s*)$//; # removes trailing whitespace and /;/
444     my $query =
445 "INSERT INTO saved_sql (borrowernumber,date_created,last_modified,savedsql,report_name,type,notes)  VALUES (?,now(),now(),?,?,?,?)";
446     my $sth = $dbh->prepare($query);
447     $sth->execute( $borrowernumber, $sql, $name, $type, $notes );
448 }
449
450 sub update_sql {
451     my $id = shift || croak "No Id given";
452     my $sql = shift;
453     my $reportname = shift;
454     my $notes = shift;
455     my $dbh = C4::Context->dbh();
456     $sql =~ s/(\s*\;\s*)$//; # removes trailing whitespace and /;/
457     my $query = "UPDATE saved_sql SET savedsql = ?, last_modified = now(), report_name = ?, notes = ? WHERE id = ? ";
458     my $sth = $dbh->prepare($query);
459     $sth->execute( $sql, $reportname, $notes, $id );
460     $sth->finish();
461 }
462
463 sub store_results {
464         my ($id,$xml)=@_;
465         my $dbh = C4::Context->dbh();
466         my $query = "SELECT * FROM saved_reports WHERE report_id=?";
467         my $sth = $dbh->prepare($query);
468         $sth->execute($id);
469         if (my $data=$sth->fetchrow_hashref()){
470                 my $query2 = "UPDATE saved_reports SET report=?,date_run=now() WHERE report_id=?";
471                 my $sth2 = $dbh->prepare($query2);
472             $sth2->execute($xml,$id);
473         }
474         else {
475                 my $query2 = "INSERT INTO saved_reports (report_id,report,date_run) VALUES (?,?,now())";
476                 my $sth2 = $dbh->prepare($query2);
477                 $sth2->execute($id,$xml);
478         }
479 }
480
481 sub format_results {
482         my ($id) = @_;
483         my $dbh = C4::Context->dbh();
484         my $query = "SELECT * FROM saved_reports WHERE report_id = ?";
485         my $sth = $dbh->prepare($query);
486         $sth->execute($id);
487         my $data = $sth->fetchrow_hashref();
488         my $dump = new XML::Dumper;
489         my $perl = $dump->xml2pl( $data->{'report'} );
490         foreach my $row (@$perl) {
491                 my $htmlrow="<tr>";
492                 foreach my $key (keys %$row){
493                         $htmlrow .= "<td>$row->{$key}</td>";
494                 }
495                 $htmlrow .= "</tr>";
496                 $row->{'row'} = $htmlrow;
497         }
498         $sth->finish;
499         $query = "SELECT * FROM saved_sql WHERE id = ?";
500         $sth = $dbh->prepare($query);
501         $sth->execute($id);
502         $data = $sth->fetchrow_hashref();
503         return ($perl,$data->{'report_name'},$data->{'notes'}); 
504 }       
505
506 sub delete_report {
507         my ( $id ) = @_;
508         my $dbh = C4::Context->dbh();
509         my $query = "DELETE FROM saved_sql WHERE id = ?";
510         my $sth = $dbh->prepare($query);
511         $sth->execute($id);
512 }       
513
514 sub get_saved_reports {
515     my $dbh   = C4::Context->dbh();
516     my $query = "SELECT *,saved_sql.id AS id FROM saved_sql 
517     LEFT JOIN saved_reports ON saved_reports.report_id = saved_sql.id
518     ORDER by date_created";
519     my $sth   = $dbh->prepare($query);
520     $sth->execute();
521     
522     my $result = $sth->fetchall_arrayref({});
523     foreach (@$result){
524         $_->{date_created} = format_date($_->{date_created}); 
525         
526         my $member = C4::Members::GetMember($_->{borrowernumber});
527         $_->{borrowerfirstname} = $member->{firstname};
528         $_->{borrowersurname}   = $member->{surname};
529     }
530     return $result;
531 }
532
533 sub get_saved_report {
534     my ($id)  = @_;
535     my $dbh   = C4::Context->dbh();
536     my $query = " SELECT * FROM saved_sql WHERE id = ?";
537     my $sth   = $dbh->prepare($query);
538     $sth->execute($id);
539     my $data = $sth->fetchrow_hashref();
540     return ( $data->{'savedsql'}, $data->{'type'}, $data->{'report_name'}, $data->{'notes'} );
541 }
542
543 =item create_compound($masterID,$subreportID)
544
545 This will take 2 reports and create a compound report using both of them
546
547 =cut
548
549 sub create_compound {
550         my ($masterID,$subreportID) = @_;
551         my $dbh = C4::Context->dbh();
552         # get the reports
553         my ($mastersql,$mastertype) = get_saved_report($masterID);
554         my ($subsql,$subtype) = get_saved_report($subreportID);
555         
556         # now we have to do some checking to see how these two will fit together
557         # or if they will
558         my ($mastertables,$subtables);
559         if ($mastersql =~ / from (.*) where /i){ 
560                 $mastertables = $1;
561         }
562         if ($subsql =~ / from (.*) where /i){
563                 $subtables = $1;
564         }
565         return ($mastertables,$subtables);
566 }
567
568 =item get_column_type($column)
569
570 This takes a column name of the format table.column and will return what type it is
571 (free text, set values, date)
572
573 =cut
574
575 sub get_column_type {
576         my ($tablecolumn) = @_;
577         my ($table,$column) = split(/\./,$tablecolumn);
578         my $dbh = C4::Context->dbh();
579         my $catalog;
580         my $schema;
581
582         # mysql doesnt support a column selection, set column to %
583         my $tempcolumn='%';
584         my $sth = $dbh->column_info( $catalog, $schema, $table, $tempcolumn ) || die $dbh->errstr;
585         while (my $info = $sth->fetchrow_hashref()){
586                 if ($info->{'COLUMN_NAME'} eq $column){
587                         #column we want
588                         if ($info->{'TYPE_NAME'} eq 'CHAR' || $info->{'TYPE_NAME'} eq 'VARCHAR'){
589                                 $info->{'TYPE_NAME'} = 'distinct';
590                         }
591                         return $info->{'TYPE_NAME'};            
592                 }
593         }
594 }
595
596 =item get_distinct_values($column)
597
598 Given a column name, return an arrary ref of hashrefs suitable for use as a tmpl_loop 
599 with the distinct values of the column
600
601 =cut
602
603 sub get_distinct_values {
604         my ($tablecolumn) = @_;
605         my ($table,$column) = split(/\./,$tablecolumn);
606         my $dbh = C4::Context->dbh();
607         my $query =
608           "SELECT distinct($column) as availablevalues FROM $table";
609         my $sth = $dbh->prepare($query);
610         $sth->execute();
611     return $sth->fetchall_arrayref({});
612 }       
613
614 sub save_dictionary {
615         my ($name,$description,$sql,$area) = @_;
616         my $dbh = C4::Context->dbh();
617         my $query = "INSERT INTO reports_dictionary (name,description,saved_sql,area,date_created,date_modified)
618   VALUES (?,?,?,?,now(),now())";
619     my $sth = $dbh->prepare($query);
620     $sth->execute($name,$description,$sql,$area) || return 0;
621     return 1;
622 }
623
624 sub get_from_dictionary {
625         my ($area,$id) = @_;
626         my $dbh = C4::Context->dbh();
627         my $query = "SELECT * FROM reports_dictionary";
628         if ($area){
629                 $query.= " WHERE area = ?";
630         }
631         elsif ($id){
632                 $query.= " WHERE id = ?"
633         }
634         my $sth = $dbh->prepare($query);
635         if ($id){
636                 $sth->execute($id);
637         }
638         elsif ($area) {
639                 $sth->execute($area);
640         }
641         else {
642                 $sth->execute();
643         }
644         my @loop;
645         my @reports = ( 'Circulation', 'Catalog', 'Patrons', 'Acquisitions', 'Accounts');
646         while (my $data = $sth->fetchrow_hashref()){
647                 $data->{'areaname'}=$reports[$data->{'area'}-1];
648                 push @loop,$data;
649                 
650         }
651         return (\@loop);
652 }
653
654 sub delete_definition {
655         my ($id) = @_ or return;
656         my $dbh = C4::Context->dbh();
657         my $query = "DELETE FROM reports_dictionary WHERE id = ?";
658         my $sth = $dbh->prepare($query);
659         $sth->execute($id);
660 }
661
662 sub get_sql {
663         my ($id) = @_ or return;
664         my $dbh = C4::Context->dbh();
665         my $query = "SELECT * FROM saved_sql WHERE id = ?";
666         my $sth = $dbh->prepare($query);
667         $sth->execute($id);
668         my $data=$sth->fetchrow_hashref();
669         return $data->{'savedsql'};
670 }
671
672 sub _get_column_defs {
673         my ($cgi) = @_;
674         my %columns;
675         my $columns_def_file = "columns.def";
676         my $htdocs = C4::Context->config('intrahtdocs');                       
677         my $section='intranet';
678         my ($theme, $lang) = themelanguage($htdocs, $columns_def_file, $section,$cgi);
679
680         my $full_path_to_columns_def_file="$htdocs/$theme/$lang/$columns_def_file";    
681         open (COLUMNS,$full_path_to_columns_def_file);
682         while (my $input = <COLUMNS>){
683                 my @row =split(/\t/,$input);
684                 $columns{$row[0]}=$row[1];
685         }
686
687         close COLUMNS;
688         return \%columns;
689 }
690 1;
691 __END__
692
693 =back
694
695 =head1 AUTHOR
696
697 Chris Cormack <crc@liblime.com>
698
699 =cut