Added the facility to restrict a keyword search by dewey number
[koha.git] / C4 / Search.pm
1 package C4::Search; #asummes C4/Search
2
3 #requires DBI.pm to be installed
4 #uses DBD:Pg
5
6 use strict;
7 require Exporter;
8 use DBI;
9 use C4::Database;
10 use C4::Reserves2;
11
12 use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
13   
14 # set the version for version checking
15 $VERSION = 0.01;
16     
17 @ISA = qw(Exporter);
18 @EXPORT = qw(&CatSearch &BornameSearch &ItemInfo &KeywordSearch &subsearch
19 &itemdata &bibdata &GetItems &borrdata &getacctlist &itemnodata &itemcount
20 &OpacSearch &borrdata2 &NewBorrowerNumber &bibitemdata &borrissues
21 &getboracctrecord &ItemType &itemissues &FrontSearch &subject &subtitle
22 &addauthor &bibitems &barcodes &findguarantees &allissues &systemprefs
23 &findguarantor); 
24 %EXPORT_TAGS = ( );     # eg: TAG => [ qw!name1 name2! ],
25                   
26 # your exported package globals go here,
27 # as well as any optionally exported functions
28
29 @EXPORT_OK   = qw($Var1 %Hashit);
30
31
32 # non-exported package globals go here
33 use vars qw(@more $stuff);
34         
35 # initalize package globals, first exported ones
36
37 my $Var1   = '';
38 my %Hashit = ();
39                     
40 # then the others (which are still accessible as $Some::Module::stuff)
41 my $stuff  = '';
42 my @more   = ();
43         
44 # all file-scoped lexicals must be created before
45 # the functions below that use them.
46                 
47 # file-private lexicals go here
48 my $priv_var    = '';
49 my %secret_hash = ();
50                             
51 # here's a file-private function as a closure,
52 # callable as &$priv_func;  it cannot be prototyped.
53 my $priv_func = sub {
54   # stuff goes here.
55 };
56                                                     
57 # make all your functions, whether exported or not;
58 sub findguarantees{         
59   my ($bornum)=@_;         
60   my $dbh=C4Connect;           
61   my $query="select cardnumber,borrowernumber from borrowers where    
62   guarantor='$bornum'";               
63   my $sth=$dbh->prepare($query);                 
64   $sth->execute;                   
65   my @dat;                     
66   my $i=0;                       
67   while (my $data=$sth->fetchrow_hashref){    
68     $dat[$i]=$data;                           
69     $i++;                               
70   }                                   
71   $sth->finish; 
72   $dbh->disconnect;         
73   return($i,\@dat);             
74 }
75 sub findguarantor{  
76   my ($bornum)=@_;  
77   my $dbh=C4Connect;    
78   my $query="select guarantor from borrowers where      
79   borrowernumber='$bornum'";        
80   my $sth=$dbh->prepare($query);          
81   $sth->execute;            
82   my $data=$sth->fetchrow_hashref;              
83   $sth->finish;                
84   $query="Select * from borrowers where
85   borrowernumber='$data->{'guarantor'}'";  
86   $sth=$dbh->prepare($query);  
87   $sth->execute;    
88   $data=$sth->fetchrow_hashref;      
89   $sth->finish;        
90   $dbh->disconnect;          
91   return($data);            
92 }
93
94 sub systemprefs {
95     my %systemprefs;
96     my $dbh=C4Connect;
97     my $sth=$dbh->prepare("select variable,value from systempreferences");
98     $sth->execute;
99     while (my ($variable,$value)=$sth->fetchrow) {
100         $systemprefs{$variable}=$value;
101     }
102     $sth->finish;
103     $dbh->disconnect;
104     return(%systemprefs);
105 }
106
107 sub NewBorrowerNumber {           
108   my $dbh=C4Connect;        
109   my $sth=$dbh->prepare("Select max(borrowernumber) from borrowers");     
110   $sth->execute;            
111   my $data=$sth->fetchrow_hashref;                                  
112   $sth->finish;                   
113   $data->{'max(borrowernumber)'}++;         
114   $dbh->disconnect;
115   return($data->{'max(borrowernumber)'}); 
116 }    
117
118 sub OpacSearch {
119   my ($env,$type,$search,$num,$offset)=@_;
120   my $dbh = &C4Connect;
121   $search->{'keyword'}=~ s/'/\\'/g;
122   my @key=split(' ',$search->{'keyword'});
123   my $count=@key;
124   my $i=1;
125   my @results;
126   my $query ="Select count(*) from biblio where 
127   ((title like '$key[0]%' or title like '% $key[0]%')";
128   while ($i < $count){
129     $query=$query." and (title like '$key[$i]%' or title like '% $key[$i]%')";
130     $i++;
131   }
132   $query=$query.") or ((author like '$key[0]%' or author like '% $key[0]%')";
133   $i=1;
134   while ($i < $count){
135     $query=$query." and (author like '$key[$i]%' or author like '% $key[$i]%')";
136     $i++;
137   }
138   $query.=") or ((seriestitle like '$key[0]%' or seriestitle like '% $key[0]%')";
139   for ($i=1;$i<$count;$i++){
140     $query.=" and (seriestitle like '$key[$i]%' or seriestitle like '% $key[$i]%')";
141   }
142   $query.= ") or ((notes like '$key[0]%' or notes like '% $key[0]%')";
143   for ($i=1;$i<$count;$i++){
144     $query.=" and (notes like '$key[$i]%' or notes like '% $key[$i]%')";
145   }
146   $query=$query.") order by title";
147   my $sth=$dbh->prepare($query);
148   $sth->execute;
149   my $data=$sth->fetchrow_hashref;
150   my $count=$data->{'count(*)'};
151   $sth->finish;
152   $query=~ s/count\(\*\)/\*/;
153   $query= $query." limit $offset,$num";
154   $sth=$dbh->prepare($query);
155 #  print $query;
156   $sth->execute;
157   $i=0;
158   while (my $data=$sth->fetchrow_hashref){
159       my $sti=$dbh->prepare("select dewey,subclass from biblioitems where biblionumber=$data->{'biblionumber'}");
160       $sti->execute;
161       my ($dewey, $subclass) = $sti->fetchrow;
162       $dewey=~s/0*$//;
163       ($dewey == 0) && ($dewey='');
164       ($dewey) && ($dewey.=" $subclass");
165       $sti->finish;
166     $results[$i]="$data->{'author'}\t$data->{'title'}\t$data->{'biblionumber'}\t$dewey";
167     $i++;
168   }
169   $sth->finish;
170   $dbh->disconnect;
171   return($count,@results);
172 }
173
174
175   
176 sub FrontSearch {
177   my ($env,$type,$search,$num,$offset)=@_;
178   my $dbh = &C4Connect;
179   $search->{'front'}=~ s/ +$//;
180   $search->{'front'}=~ s/'/\\'/;
181   my @key=split(' ',$search->{'front'});
182   my $count=@key;
183   my $i=1;
184   my @results;
185   my $query ="Select * from biblio,bibliosubtitle where
186   biblio.biblionumber=bibliosubtitle.biblionumber and
187   ((title like '$key[0]%' or title like '% $key[0]%'
188   or subtitle like '$key[0]%' or subtitle like '% $key[0]%'
189   or author like '$key[0]%' or author like '% $key[0]%')";
190   while ($i < $count){
191     $query=$query." and (title like '%$key[$i]%' or subtitle like '%$key[$i]%')";
192     $i++;
193   }
194   $query=$query.") group by biblio.biblionumber order by author,title";
195   print $query;
196   my $sth=$dbh->prepare($query);
197   $sth->execute;
198   $i=0;
199   while (my $data=$sth->fetchrow_hashref){
200     my $sti=$dbh->prepare("select dewey,subclass from biblioitems where biblionumber=$data->{'biblionumber'}");
201     $sti->execute;
202     my ($dewey, $subclass) = $sti->fetchrow;
203     $dewey=~s/\.*0*$//;
204     ($dewey == 0) && ($dewey='');
205     ($dewey) && ($dewey.=" $subclass");
206     $sti->finish;
207     $results[$i]="$data->{'author'}\t$data->{'title'}\t$data->{'biblionumber'}\t$data->{'copyrightdate'}\t$dewey";
208 #      print $results[$i];
209     $i++;
210   }
211   $sth->finish;
212   $sth=$dbh->prepare("Select biblionumber from bibliosubject where subject
213   like '%$search->{'keyword'}%'");
214   $sth->execute;
215   while (my $data=$sth->fetchrow_hashref){
216     my $sth2=$dbh->prepare("Select * from biblio where
217     biblionumber=$data->{'biblionumber'}");
218     $sth2->execute;
219     while (my $data2=$sth2->fetchrow_hashref){
220
221 $results[$i]="$data2->{'author'}\t$data2->{'title'}\t$data2->{'biblionumber'}\t$data->{'copyrightdate'}";
222 #      print $results[$i];
223       $i++;   
224     }
225     $sth2->finish;
226   }    
227   my $i2=1;
228   @results=sort @results;
229   my @res;
230   my $count=@results;
231   $i=1;
232   $res[0]=$results[0];
233   while ($i2 < $count){
234     if ($results[$i2] ne $res[$i-1]){
235       $res[$i]=$results[$i2];
236       $i++;
237     }
238     $i2++;
239   }
240   $i2=0;
241   my @res2;
242   $count=@res;
243   while ($i2 < $num && $i2 < $count){
244     $res2[$i2]=$res[$i2+$offset];
245 #    print $res2[$i2];
246     $i2++;
247   }
248   $sth->finish;
249   $dbh->disconnect;
250   return($i,@res2);
251 }
252
253   
254 sub KeywordSearch {
255   my ($env,$type,$search,$num,$offset)=@_;
256   my $dbh = &C4Connect;
257   $search->{'keyword'}=~ s/ +$//;
258   $search->{'keyword'}=~ s/'/\\'/;
259   my @key=split(' ',$search->{'keyword'});
260   my $count=@key;
261   my $i=1;
262   my @results;
263   my $query ="Select * from biblio,bibliosubtitle,biblioitems where
264   biblio.biblionumber=biblioitems.biblionumber and
265   biblio.biblionumber=bibliosubtitle.biblionumber and
266   (((title like '$key[0]%' or title like '% $key[0]%')";
267
268   while ($i < $count){
269     $query=$query." and (title like '$key[$i]%' or title like '% $key[$i]%')";
270     $i++;
271   }
272   $query.= ") or ((subtitle like '$key[0]%' or subtitle like '% $key[0]%')";
273   for ($i=1;$i<$count;$i++){
274     $query.= " and (subtitle like '$key[$i]%' or subtitle like '% $key[$i]%')";
275   }
276   $query.= ") or ((seriestitle like '$key[0]%' or seriestitle like '% $key[0]%')";
277   for ($i=1;$i<$count;$i++){
278     $query.=" and (seriestitle like '$key[$i]%' or seriestitle like '% $key[$i]%')";
279   }
280   $query.= ") or ((biblio.notes like '$key[0]%' or biblio.notes like '% $key[0]%')";
281   for ($i=1;$i<$count;$i++){
282     $query.=" and (biblio.notes like '$key[$i]%' or biblio.notes like '% $key[$i]%')";
283   }
284   $query.= ") or ((biblioitems.notes like '$key[0]%' or biblioitems.notes like '% $key[0]%')";
285   for ($i=1;$i<$count;$i++){
286     $query.=" and (biblioitems.notes like '$key[$i]%' or biblioitems.notes like '% $key[$i]%')";
287   }
288   if ($search->{'keyword'} =~ /new zealand/i){
289     $query.= "or (title like 'nz%' or title like '% nz %' or title like '% nz' or subtitle like 'nz%'
290     or subtitle like '% nz %' or subtitle like '% nz' or author like 'nz %' 
291     or author like '% nz %' or author like '% nz')"
292   }
293   if ($search->{'keyword'} eq  'nz' || $search->{'keyword'} eq 'NZ' ||
294   $search->{'keyword'} =~ /nz /i || $search->{'keyword'} =~ / nz /i ||
295   $search->{'keyword'} =~ / nz/i){
296     $query.= "or (title like 'new zealand%' or title like '% new zealand %'
297     or title like '% new zealand' or subtitle like 'new zealand%' or
298     subtitle like '% new zealand %'
299     or subtitle like '% new zealand' or author like 'new zealand%' 
300     or author like '% new zealand %' or author like '% new zealand' or 
301     seriestitle like 'new zealand%' or seriestitle like '% new zealand %'
302     or seriestitle like '% new zealand')"
303   }
304   $query=$query."))";
305   if ($search->{'class'} ne ''){
306     my @temp=split(/\|/,$search->{'class'});
307     my $count=@temp;
308     $query.= "and ( itemtype='$temp[0]'";
309     for (my $i=1;$i<$count;$i++){
310       $query.=" or itemtype='$temp[$i]'";
311      }
312   $query.=")"; 
313   }
314   if ($search->{'dewey'} ne ''){
315     $query.= "and (dewey like '$search->{'dewey'}%') ";
316   }
317    $query.="group by biblio.biblionumber";
318    #$query.=" order by author,title";
319 #  print $query;
320   my $sth=$dbh->prepare($query);
321   $sth->execute;
322   $i=0;
323   while (my $data=$sth->fetchrow_hashref){
324 #    my $sti=$dbh->prepare("select dewey,subclass from biblioitems where biblionumber=$data->{'biblionumber'}
325 #    ");
326 #    $sti->execute;
327 #    my ($dewey, $subclass) = $sti->fetchrow;
328     my $dewey=$data->{'dewey'};
329     my $subclass=$data->{'subclass'};
330     $dewey=~s/\.*0*$//;
331     ($dewey == 0) && ($dewey='');
332     ($dewey) && ($dewey.=" $subclass");
333 #    $sti->finish;
334     $results[$i]="$data->{'author'}\t$data->{'title'}\t$data->{'biblionumber'}\t$data->{'copyrightdate'}\t$dewey";
335 #      print $results[$i];
336     $i++;
337   }
338   $sth->finish;
339   $sth=$dbh->prepare("Select biblionumber from bibliosubject where subject
340   like '%$search->{'keyword'}%' group by biblionumber");
341   $sth->execute;
342   while (my $data=$sth->fetchrow_hashref){
343     $query="Select * from biblio,biblioitems where
344     biblio.biblionumber=$data->{'biblionumber'} and
345     biblio.biblionumber=biblioitems.biblionumber ";
346     if ($search->{'class'} ne ''){
347       my @temp=split(/\|/,$search->{'class'});
348       my $count=@temp;
349       $query.= " and ( itemtype='$temp[0]'";
350       for (my $i=1;$i<$count;$i++){
351         $query.=" or itemtype='$temp[$i]'";
352       }
353       $query.=")"; 
354       
355     }
356     if ($search->{'dewey'} ne ''){
357       $query.= "and (dewey like '$search->{'dewey'}%') ";
358     }
359     my $sth2=$dbh->prepare($query);
360     $sth2->execute;
361 #    print $query;
362     while (my $data2=$sth2->fetchrow_hashref){
363       my $dewey= $data2->{'dewey'};
364       my $subclass=$data2->{'subclass'};
365       $dewey=~s/\.*0*$//;          
366       ($dewey == 0) && ($dewey='');              
367       ($dewey) && ($dewey.=" $subclass") ;                  
368 #      $sti->finish;              
369        $results[$i]="$data2->{'author'}\t$data2->{'title'}\t$data2->{'biblionumber'}\t$data2->{'copyrightdate'}\t$dewey";
370 #      print $results[$i];
371       $i++;   
372     }
373     $sth2->finish;
374   }    
375   my $i2=1;
376   @results=sort @results;
377   my @res;
378   my $count=@results;
379   $i=0;
380   if ($count > 0){
381     $res[0]=$results[0];
382   }
383   while ($i2 < $count){
384     if ($results[$i2] ne $res[$i-1]){
385       $res[$i]=$results[$i2];
386       $i++;
387     }
388     $i2++;
389   }
390   $i2=0;
391   my @res2;
392   $count=@res;
393   while ($i2 < $num && $i2 < $count){
394     $res2[$i2]=$res[$i2+$offset];
395 #    print $res2[$i2];
396     $i2++;
397   }
398   $sth->finish;
399   $dbh->disconnect;
400 #  $i--;
401   return($i,@res2);
402 }
403
404 sub CatSearch  {
405   my ($env,$type,$search,$num,$offset)=@_;
406   my $dbh = &C4Connect;
407   my $query = '';
408     my @results;
409   $search->{'title'}=~ s/'/\\'/g;
410   $search->{'author'}=~ s/'/\\'/g;
411   $search->{'illustrator'}=~ s/'/\\'/g;
412   my $title = lc($search->{'title'}); 
413   
414   if ($type eq 'loose') {
415       if ($search->{'author'} ne ''){
416         my @key=split(' ',$search->{'author'});
417         my $count=@key;
418         my $i=1;
419         $query="select *,biblio.author,biblio.biblionumber from
420          biblioitems,biblio
421          left join additionalauthors
422          on additionalauthors.biblionumber =biblio.biblionumber
423          where biblioitems.biblionumber=biblio.biblionumber 
424          and
425          ((biblio.author like '$key[0]%' or biblio.author like '% $key[0]%' or
426          additionalauthors.author like '$key[0]%' or additionalauthors.author 
427          like '% $key[0]%'
428                  )";    
429          while ($i < $count){ 
430            $query=$query." and (
431            biblio.author like '$key[$i]%' or biblio.author like '% $key[$i]%' or
432            additionalauthors.author like '$key[$i]%' or additionalauthors.author like '% $key[$i]%'
433            )";
434            $i++;       
435          }   
436          $query=$query.")";
437          if ($search->{'title'} ne ''){ 
438            $query=$query. " and (title like '%$search->{'title'}%' 
439            or seriestitle like '%$search->{'title'}%')";
440          }
441          if ($search->{'class'} ne ''){
442            my @temp=split(/\|/,$search->{'class'});
443            my $count=@temp;
444            $query.= "and ( itemtype='$temp[0]'";
445            for (my $i=1;$i<$count;$i++){
446              $query.=" or itemtype='$temp[$i]'";
447            }
448            $query.=") ";
449          }
450          if ($search->{'dewey'} ne ''){
451               $query.=" and dewey='$search->{'dewey'}' ";
452          }           
453           if ($search->{'illustrator'} ne ''){
454             $query.=" and illus like '%".$search->{'illustrator'}."%' ";
455           }
456          
457          $query.=" group by biblio.biblionumber";
458       } else {
459           if ($search->{'title'} ne '') {
460            if ($search->{'ttype'} eq 'exact'){
461              $query="select * from biblio
462              where                            
463              (biblio.title='$search->{'title'}' or (biblio.unititle = '$search->{'title'}'
464              or biblio.unititle like '$search->{'title'} |%' or 
465              biblio.unititle like '%| $search->{'title'} |%' or
466              biblio.unititle like '%| $search->{'title'}') or
467              (biblio.seriestitle = '$search->{'title'}' or
468              biblio.seriestitle like '$search->{'title'} |%' or
469              biblio.seriestitle like '%| $search->{'title'} |%' or
470              biblio.seriestitle like '%| $search->{'title'}')
471              )";
472            } else {
473             my @key=split(' ',$search->{'title'});
474             my $count=@key;
475             my $i=1;
476             $query="select * from biblio,bibliosubtitle,biblioitems
477             where
478             (biblio.biblionumber=bibliosubtitle.biblionumber and
479             biblioitems.biblionumber=biblio.biblionumber) and
480             (((title like '$key[0]%' or title like '% $key[0]%' or title like '% $key[0]')";
481             while ($i<$count){
482               $query=$query." and (title like '$key[$i]%' or title like '% $key[$i]%' or title like '% $key[$i]')";
483               $i++;
484             }
485             $query.=") or ((subtitle like '$key[0]%' or subtitle like '% $key[0] %' or subtitle like '% $key[0]')";
486             for ($i=1;$i<$count;$i++){
487               $query.=" and (subtitle like '$key[$i]%' or subtitle like '% $key[$i] %' or subtitle like '% $key[$i]')";
488             }
489             $query.=") or ((seriestitle like '$key[0]%' or seriestitle like '% $key[0] %' or seriestitle like '% $key[0]')";
490             for ($i=1;$i<$count;$i++){
491               $query.=" and (seriestitle like '$key[$i]%' or seriestitle like '% $key[$i] %')";
492             }
493             $query.=") or ((unititle like '$key[0]%' or unititle like '% $key[0] %' or unititle like '% $key[0]')";
494             for ($i=1;$i<$count;$i++){
495               $query.=" and (unititle like '$key[$i]%' or unititle like '% $key[$i] %')";
496             }
497             $query=$query."))";
498             if ($search->{'class'} ne ''){
499               my @temp=split(/\|/,$search->{'class'});
500               my $count=@temp;
501               $query.= " and ( itemtype='$temp[0]'";
502               for (my $i=1;$i<$count;$i++){
503                $query.=" or itemtype='$temp[$i]'";
504               }
505               $query.=")";
506             }
507             if ($search->{'dewey'} ne ''){
508               $query.=" and dewey='$search->{'dewey'}' ";
509             }
510             if ($search->{'illustrator'} ne ''){
511               $query.=" and illus like '%".$search->{'illustrator'}."%' ";
512             }
513            }
514           } elsif ($search->{'class'} ne ''){
515              $query="select * from biblioitems,biblio where biblio.biblionumber=biblioitems.biblionumber";
516              my @temp=split(/\|/,$search->{'class'});
517               my $count=@temp;
518               $query.= " and ( itemtype='$temp[0]'";
519               for (my $i=1;$i<$count;$i++){
520                $query.=" or itemtype='$temp[$i]'";
521               }
522               $query.=")";
523               if ($search->{'illustrator'} ne ''){
524                 $query.=" and illus like '%".$search->{'illustrator'}."%' ";
525               }
526               if ($search->{'dewey'} ne ''){
527                 $query.=" and biblioitems.dewey like '$search->{'dewey'}%'";
528               }
529           } elsif ($search->{'dewey'} ne ''){
530              $query="select * from biblioitems,biblio 
531              where biblio.biblionumber=biblioitems.biblionumber
532              and biblioitems.dewey like '$search->{'dewey'}%'";
533           } elsif ($search->{'illustrator'} ne '') {
534           if ($search->{'illustrator'} ne ''){
535              $query="select * from biblioitems,biblio 
536              where biblio.biblionumber=biblioitems.biblionumber
537              and biblioitems.illus like '%".$search->{'illustrator'}."%'";
538           }
539           }
540           $query .=" group by biblio.biblionumber";      
541       }
542   } 
543   if ($type eq 'subject'){
544     my @key=split(' ',$search->{'subject'});
545     my $count=@key;
546     my $i=1;
547     $query="select distinct(subject) from bibliosubject where( subject like
548     '$key[0]%' or subject like '% $key[0]%' or subject like '% $key[0]' or subject like '%($key[0])%')";
549     while ($i<$count){
550       $query.=" and (subject like '$key[$i]%' or subject like '% $key[$i]%'
551       or subject like '% $key[$i]'
552       or subject like '%($key[$i])%')";
553       $i++;
554     }
555     if ($search->{'subject'} eq 'NZ' || $search->{'subject'} eq 'nz'){ 
556       $query.= " or (subject like 'NEW ZEALAND %' or subject like '% NEW ZEALAND %'
557       or subject like '% NEW ZEALAND' or subject like '%(NEW ZEALAND)%' ) ";
558     } elsif ( $search->{'subject'} =~ /^nz /i || $search->{'subject'} =~ / nz /i || $search->{'subject'} =~ / nz$/i){
559       $query=~ s/ nz/ NEW ZEALAND/ig;
560       $query=~ s/nz /NEW ZEALAND /ig;
561       $query=~ s/\(nz\)/\(NEW ZEALAND\)/gi;
562     }  
563   }
564   if ($type eq 'precise'){
565       $query="select * from items,biblio ";
566       if ($search->{'item'} ne ''){
567         my $search2=uc $search->{'item'};
568         $query=$query." where 
569         items.biblionumber=biblio.biblionumber 
570         and barcode='$search2'";
571       }
572       if ($search->{'isbn'} ne ''){
573         my $search2=uc $search->{'isbn'};
574         my $query1 = "select * from biblioitems where isbn='$search2'";
575         my $sth1=$dbh->prepare($query1);
576 #       print $query1;
577         $sth1->execute;
578         my $i2=0;
579         while (my $data=$sth1->fetchrow_hashref) {
580            $query="select * from biblioitems,biblio where
581            biblio.biblionumber = $data->{'biblionumber'}
582            and biblioitems.biblionumber = biblio.biblionumber";
583            my $sth=$dbh->prepare($query);
584            $sth->execute;
585            my $data=$sth->fetchrow_hashref;
586            my ($dewey, $subclass) = ($data->{'dewey'}, $data->{'subclass'});
587            $dewey=~s/\.*0*$//;
588            ($dewey == 0) && ($dewey='');
589            ($dewey) && ($dewey.=" $subclass");
590            $results[$i2]="$data->{'author'}\t$data->{'title'}\t$data->{'biblionumber'}\t$data->{'copyrightdate'}\t$dewey\t$data->{'isbn'}\t$data->{'itemtype'}";
591            $i2++; 
592            $sth->finish;
593         }
594         $sth1->finish;
595       }
596   }
597 #print $query;
598 if ($type ne 'precise' && $type ne 'subject'){
599   if ($search->{'author'} ne ''){   
600       $query=$query." order by biblio.author,title";
601   } else {
602       $query=$query." order by title";
603   }
604 } else {
605   if ($type eq 'subject'){
606       $query=$query." order by subject";
607   }
608 }
609 my $sth=$dbh->prepare($query);
610 $sth->execute;
611 my $count=1;
612 my $i=0;
613 my $limit= $num+$offset;
614 while (my $data=$sth->fetchrow_hashref){
615   my $sti=$dbh->prepare("select dewey,subclass from biblioitems where biblionumber=$data->{'biblionumber'}");
616   $sti->execute;
617   my ($dewey, $subclass) = $sti->fetchrow;
618   $dewey=~s/\.*0*$//;
619   ($dewey == 0) && ($dewey='');
620   ($dewey) && ($dewey.=" $subclass");
621   $sti->finish;
622   if ($count > $offset && $count <= $limit){
623     if ($type ne 'subject' && $type ne 'precise'){
624        $results[$i]="$data->{'author'}\t$data->{'title'}\t$data->{'biblionumber'}\t$data->{'copyrightdate'}\t$dewey\t$data->{'illus'}";
625     } elsif ($search->{'isbn'} ne '' || $search->{'item'} ne ''){
626        $results[$i]="$data->{'author'}\t$data->{'title'}\t$data->{'biblionumber'}\t$data->{'copyrightdate'}\t$dewey\t$data->{'illus'}";
627     } else {  
628      $results[$i]="$data->{'author'}\t$data->{'subject'}\t$data->{'biblionumber'}\t$data->{'copyrightdate'}\t$dewey\t$data->{'illus'}";
629     }
630     $i++;
631   }
632   $count++;
633 }
634 $sth->finish;
635 #if ($type ne 'precise'){
636   $count--;
637 #}
638 #$count--;
639 return($count,@results);
640 }
641
642 sub updatesearchstats{
643   my ($dbh,$query)=@_;
644   
645 }
646
647 sub subsearch {
648   my ($env,$subject)=@_;
649   my $dbh=C4Connect();
650   my $query="Select * from biblio,bibliosubject where
651   biblio.biblionumber=bibliosubject.biblionumber and
652   bibliosubject.subject='$subject' group by biblio.biblionumber
653   order by biblio.title";
654   my $sth=$dbh->prepare($query);
655   $sth->execute;
656   my $i=0;
657 #  print $query;
658   my @results;
659   while (my $data=$sth->fetchrow_hashref){
660     $results[$i]="$data->{'title'}\t$data->{'author'}\t$data->{'biblionumber'}";
661     $i++;
662   }
663   $sth->finish;
664   $dbh->disconnect;
665   return(@results);
666 }
667
668
669 sub ItemInfo {
670   my ($env,$biblionumber,$type)=@_;
671   my $dbh = &C4Connect;
672   my $query="Select * from items,biblio,biblioitems,branches 
673   where (items.biblioitemnumber = biblioitems.biblioitemnumber)
674   and biblioitems.biblionumber=biblio.biblionumber
675   and biblio.biblionumber='$biblionumber' and branches.branchcode=
676   items.holdingbranch ";
677 #  print $type;
678   if ($type ne 'intra'){
679     $query.=" and (items.itemlost<>1 or items.itemlost is NULL)
680     and (wthdrawn <> 1 or wthdrawn is NULL)";
681   }
682   $query=$query."order by items.dateaccessioned desc";
683   my $sth=$dbh->prepare($query);
684   $sth->execute;
685   my $i=0;
686   my @results;
687 #  print $query;
688   while (my $data=$sth->fetchrow_hashref){
689     my $iquery = "Select * from issues
690     where itemnumber = '$data->{'itemnumber'}'
691     and returndate is null";
692     my $datedue = '';
693     my $isth=$dbh->prepare($iquery);
694     $isth->execute;
695     if (my $idata=$isth->fetchrow_hashref){
696       my @temp=split('-',$idata->{'date_due'});
697       $datedue = "$temp[2]/$temp[1]/$temp[0]";
698     }
699     if ($data->{'itemlost'} eq '1'){
700         $datedue='Itemlost';
701     }
702     if ($data->{'wthdrawn'} eq '1'){
703       $datedue="Cancelled";
704     }
705     if ($datedue eq ''){
706        my ($rescount,$reserves)=FindReserves($biblionumber,'');   
707        if ($rescount >0){                                
708           $datedue='Request';
709        }
710     }
711     $isth->finish;
712     my $class = $data->{'classification'};
713     my $dewey = $data->{'dewey'};
714     $dewey =~ s/0+$//;
715     if ($dewey eq "000.") { $dewey = "";};    
716     if ($dewey < 10){$dewey='00'.$dewey;}
717     if ($dewey < 100 && $dewey > 10){$dewey='0'.$dewey;}
718     if ($dewey <= 0){
719       $dewey='';
720     }
721     $dewey=~ s/\.$//;
722     $class = $class.$dewey;
723     $class = $class.$data->{'subclass'};
724  #   $results[$i]="$data->{'title'}\t$data->{'barcode'}\t$datedue\t$data->{'branchname'}\t$data->{'dewey'}";
725     my @temp=split('-',$data->{'datelastseen'});
726     my $date="$temp[2]/$temp[1]/$temp[0]";
727     $results[$i]="$data->{'title'}\t$data->{'barcode'}\t$datedue\t$data->{'branchname'}\t$class\t$data->{'itemnumber'}\t$data->{'itemtype'}\t$date\t$data->{'biblioitemnumber'}\t$data->{'volumeddesc'}";
728 #    print "$results[$i] <br>";
729     $i++;
730   }
731   $sth->finish;
732   $dbh->disconnect;
733   return(@results);
734 }
735
736 sub GetItems {
737    my ($env,$biblionumber)=@_;
738    #debug_msg($env,"GetItems");
739    my $dbh = &C4Connect;
740    my $query = "Select * from biblioitems where (biblionumber = $biblionumber)";
741    #debug_msg($env,$query);
742    my $sth=$dbh->prepare($query);
743    $sth->execute;
744    #debug_msg($env,"executed query");      
745    my $i=0;
746    my @results;
747    while (my $data=$sth->fetchrow_hashref) {
748       #debug_msg($env,$data->{'biblioitemnumber'});
749       my $dewey = $data->{'dewey'};
750       $dewey =~ s/0+$//; 
751       my $line = $data->{'biblioitemnumber'}."\t".$data->{'itemtype'};
752       $line = $line."\t$data->{'classification'}\t$dewey";
753       $line = $line."\t$data->{'subclass'}\t$data->{isbn}";
754       $line = $line."\t$data->{'volume'}\t$data->{number}";
755       my $isth= $dbh->prepare("select * from items where biblioitemnumber = $data->{'biblioitemnumber'}");
756       $isth->execute;
757       while (my $idata = $isth->fetchrow_hashref) {
758         my $iline = $idata->{'barcode'}."[".$idata->{'holdingbranch'}."[";
759         if ($idata->{'notforloan'} == 1) {
760           $iline = $iline."NFL ";
761         }
762         if ($idata->{'itemlost'} == 1) {
763           $iline = $iline."LOST ";
764         }        
765         $line = $line."\t$iline"; 
766       }
767       $isth->finish;
768       $results[$i] = $line;
769       $i++;      
770    }
771    $sth->finish;
772    $dbh->disconnect;
773    return(@results);
774 }            
775   
776 sub itemdata {
777   my ($barcode)=@_;
778   my $dbh=C4Connect;
779   my $query="Select * from items,biblioitems where barcode='$barcode'
780   and items.biblioitemnumber=biblioitems.biblioitemnumber";
781 #  print $query;
782   my $sth=$dbh->prepare($query);
783   $sth->execute;
784   my $data=$sth->fetchrow_hashref;
785   $sth->finish;
786   $dbh->disconnect;
787   return($data);
788 }
789
790 sub bibdata {
791   my ($bibnum,$type)=@_;
792   my $dbh=C4Connect;
793   my $query="Select *,biblio.notes from biblio,biblioitems,bibliosubtitle where biblio.biblionumber=$bibnum
794   and biblioitems.biblionumber=$bibnum and 
795 (bibliosubtitle.biblionumber=$bibnum)"; 
796 #  print $query;
797   my $sth=$dbh->prepare($query);
798   $sth->execute;
799   my $data=$sth->fetchrow_hashref;
800   $sth->finish;
801   $query="Select * from bibliosubject where biblionumber='$bibnum'";
802   $sth=$dbh->prepare($query);
803   $sth->execute;
804   while (my $dat=$sth->fetchrow_hashref){
805     $data->{'subject'}.=" | $dat->{'subject'}";
806
807   }
808   #print $query;
809   $sth->finish;
810   $dbh->disconnect;
811   return($data);
812 }
813
814 sub bibitemdata {
815   my ($bibitem)=@_;
816   my $dbh=C4Connect;
817   my $query="Select * from biblio,biblioitems,itemtypes where biblio.biblionumber=
818   biblioitems.biblionumber and biblioitemnumber=$bibitem and
819   biblioitems.itemtype=itemtypes.itemtype";
820 #  print $query;
821   my $sth=$dbh->prepare($query);
822   $sth->execute;
823   my $data=$sth->fetchrow_hashref;
824   $sth->finish;
825   $dbh->disconnect;
826   return($data);
827 }
828
829 sub subject {
830   my ($bibnum)=@_;
831   my $dbh=C4Connect;
832   my $query="Select * from bibliosubject where biblionumber=$bibnum";
833   my $sth=$dbh->prepare($query);
834   $sth->execute;
835   my @results;
836   my $i=0;
837   while (my $data=$sth->fetchrow_hashref){
838     $results[$i]=$data;
839     $i++;
840   }
841   $sth->finish;
842   $dbh->disconnect;
843   return($i,\@results);
844 }
845
846 sub addauthor {
847   my ($bibnum)=@_;
848   my $dbh=C4Connect;
849   my $query="Select * from additionalauthors where biblionumber=$bibnum";
850   my $sth=$dbh->prepare($query);
851   $sth->execute;
852   my @results;
853   my $i=0;
854   while (my $data=$sth->fetchrow_hashref){
855     $results[$i]=$data;
856     $i++;
857   }
858   $sth->finish;
859   $dbh->disconnect;
860   return($i,\@results);
861 }
862
863 sub subtitle {
864   my ($bibnum)=@_;
865   my $dbh=C4Connect;
866   my $query="Select * from bibliosubtitle where biblionumber=$bibnum";
867   my $sth=$dbh->prepare($query);
868   $sth->execute;
869   my @results;
870   my $i=0;
871   while (my $data=$sth->fetchrow_hashref){
872     $results[$i]=$data;
873     $i++;
874   }
875   $sth->finish;
876   $dbh->disconnect;
877   return($i,\@results);
878 }
879
880
881
882 sub itemissues {
883   my ($bibitem,$biblio)=@_;
884   my $dbh=C4Connect;
885   my $query="Select * from items where 
886   items.biblioitemnumber='$bibitem'";
887   my $sth=$dbh->prepare($query) || die $dbh->errstr;
888   $sth->execute || die $sth->errstr;
889   my $i=0;
890   my @results;
891   while (my $data=$sth->fetchrow_hashref) {
892     my $query2="select * from issues,borrowers where itemnumber=$data->{'itemnumber'}
893     and returndate is NULL and issues.borrowernumber=borrowers.borrowernumber";
894     my $sth2=$dbh->prepare($query2);
895     $sth2->execute;
896     if (my $data2=$sth2->fetchrow_hashref) {
897       $data->{'date_due'}=$data2->{'date_due'};
898       $data->{'card'}=$data2->{'cardnumber'};
899     } else {
900       if ($data->{'wthdrawn'} eq '1') {
901         $data->{'date_due'}='Cancelled';
902       } else {
903           $data->{'date_due'}='Available';
904       }
905     }
906     $sth2->finish;
907     $query2="select * from issues,borrowers where itemnumber='$data->{'itemnumber'}'
908     and issues.borrowernumber=borrowers.borrowernumber 
909     order by date_due desc";
910     my $sth2=$dbh->prepare($query2) || die $dbh->errstr;
911     $sth2->execute || die $sth2->errstr;
912     for (my $i2=0;$i2<2;$i2++){
913       if (my $data2=$sth2->fetchrow_hashref){
914         $data->{"timestamp$i2"}=$data2->{'timestamp'};
915         $data->{"card$i2"}=$data2->{'cardnumber'};
916         $data->{"borrower$i2"}=$data2->{'borrowernumber'};
917       }
918     }
919     $sth2->finish;
920     $results[$i]=$data;
921     $i++;
922   }
923   $sth->finish;
924   $dbh->disconnect;
925   return(@results);
926 }
927
928 sub itemnodata {
929   my ($env,$dbh,$itemnumber) = @_;
930   $dbh=C4Connect;
931   my $query="Select * from biblio,items,biblioitems
932     where items.itemnumber = '$itemnumber'
933     and biblio.biblionumber = items.biblionumber
934     and biblioitems.biblioitemnumber = items.biblioitemnumber";
935   my $sth=$dbh->prepare($query);
936 #  print $query;
937   $sth->execute;
938   my $data=$sth->fetchrow_hashref;
939   $sth->finish;  
940   $dbh->disconnect;
941   return($data);               
942 }
943
944 #used by member enquiries from the intranet
945 #called by member.pl
946 sub BornameSearch  {
947   my ($env,$searchstring,$type)=@_;
948   my $dbh = &C4Connect;
949   $searchstring=~ s/\'/\\\'/g;
950   my @data=split(' ',$searchstring);
951   my $count=@data;
952   my $query="Select * from borrowers 
953   where ((surname like \"$data[0]%\" or surname like \"% $data[0]%\" 
954   or firstname  like \"$data[0]%\" or firstname like \"% $data[0]%\" 
955   or othernames like \"$data[0]%\" or othernames like \"% $data[0]%\")
956   ";
957   for (my $i=1;$i<$count;$i++){
958     $query=$query." and (surname like \"$data[$i]%\" or surname like \"% $data[$i]%\"                  
959     or firstname  like \"$data[$i]%\" or firstname like \"% $data[$i]%\"                    
960     or othernames like \"$data[$i]%\" or othernames like \"% $data[$i]%\")";
961   }
962   $query=$query.") or cardnumber = \"$searchstring\"
963   order by surname,firstname";
964 #  print $query,"\n";
965   my $sth=$dbh->prepare($query);
966   $sth->execute;
967   my @results;
968   my $cnt=0;
969   while (my $data=$sth->fetchrow_hashref){
970     push(@results,$data);
971     $cnt ++;
972   }
973 #  $sth->execute;
974   $sth->finish;
975   $dbh->disconnect;
976   return ($cnt,\@results);
977 }
978
979 sub borrdata {
980   my ($cardnumber,$bornum)=@_;
981   $cardnumber = uc $cardnumber;
982   my $dbh=C4Connect;
983   my $query;
984   if ($bornum eq ''){
985     $query="Select * from borrowers where cardnumber='$cardnumber'";
986   } else {
987       $query="Select * from borrowers where borrowernumber='$bornum'";
988   }
989   #print $query;
990   my $sth=$dbh->prepare($query);
991   $sth->execute;
992   my $data=$sth->fetchrow_hashref;
993   $sth->finish;
994   $dbh->disconnect;
995   return($data);
996 }
997
998 sub borrissues {
999   my ($bornum)=@_;
1000   my $dbh=C4Connect;
1001   my $query;
1002   $query="Select * from issues,biblio,items where borrowernumber='$bornum' and
1003 items.itemnumber=issues.itemnumber and
1004 items.biblionumber=biblio.biblionumber and issues.returndate is NULL order
1005 by date_due";
1006   #print $query;
1007   my $sth=$dbh->prepare($query);
1008     $sth->execute;
1009   my @result;
1010   my $i=0;
1011   while (my $data=$sth->fetchrow_hashref){
1012     $result[$i]=$data;;
1013     $i++;
1014   }
1015   $sth->finish;
1016   $dbh->disconnect;
1017   return($i,\@result);
1018 }
1019
1020 sub allissues {
1021   my ($bornum)=@_;
1022   my $dbh=C4Connect;
1023   my $query;
1024   $query="Select * from issues,biblio,items where borrowernumber='$bornum' and
1025 items.itemnumber=issues.itemnumber and
1026 items.biblionumber=biblio.biblionumber order
1027 by date_due";
1028   #print $query;
1029   my $sth=$dbh->prepare($query);
1030     $sth->execute;
1031   my @result;
1032   my $i=0;
1033   while (my $data=$sth->fetchrow_hashref){
1034     $result[$i]=$data;;
1035     $i++;
1036   }
1037   $sth->finish;
1038   $dbh->disconnect;
1039   return($i,\@result);
1040 }
1041
1042
1043
1044 sub borrdata2 {
1045   my ($env,$bornum)=@_;
1046   my $dbh=C4Connect;
1047   my $query="Select count(*) from issues where borrowernumber='$bornum' and
1048     returndate is NULL";
1049     # print $query;
1050   my $sth=$dbh->prepare($query);
1051   $sth->execute;
1052   my $data=$sth->fetchrow_hashref;
1053   $sth->finish;
1054   $sth=$dbh->prepare("Select count(*) from issues where
1055     borrowernumber='$bornum' and date_due < now() and returndate is NULL");
1056   $sth->execute;
1057   my $data2=$sth->fetchrow_hashref;
1058   $sth->finish;
1059   $sth=$dbh->prepare("Select sum(amountoutstanding) from accountlines where
1060     borrowernumber='$bornum'");
1061   $sth->execute;
1062   my $data3=$sth->fetchrow_hashref;
1063   $sth->finish;
1064   $dbh->disconnect;
1065
1066 return($data2->{'count(*)'},$data->{'count(*)'},$data3->{'sum(amountoutstanding)'});
1067 }
1068                   
1069 sub getacctlist {
1070    my ($env,$params) = @_;
1071    my $dbh=C4Connect;
1072    my @acctlines;
1073    my $numlines;
1074    my $query = "Select borrowernumber, accountno, date, amount, description,
1075       dispute, accounttype, amountoutstanding, barcode, title
1076       from accountlines,items,biblio   
1077       where borrowernumber = $params->{'borrowernumber'} ";
1078    if ($params->{'acctno'} ne "") {
1079       my $query = $query." and accountlines.accountno = $params->{'acctno'} ";
1080       }
1081    my $query = $query." and accountlines.itemnumber = items.itemnumber
1082       and items.biblionumber = biblio.biblionumber
1083       and accountlines.amountoutstanding<>0 order by date";
1084    my $sth=$dbh->prepare($query);
1085 #   print $query;
1086    $sth->execute;
1087    my $total=0;
1088    while (my $data=$sth->fetchrow_hashref){
1089       $acctlines[$numlines] = $data;
1090       $numlines++;
1091       $total = $total+ $data->{'amountoutstanding'};
1092    }
1093    return ($numlines,\@acctlines,$total);
1094    $sth->finish;
1095    $dbh->disconnect;
1096 }
1097
1098 sub getboracctrecord {
1099    my ($env,$params) = @_;
1100    my $dbh=C4Connect;
1101    my @acctlines;
1102    my $numlines=0;
1103    my $query= "Select * from accountlines where
1104 borrowernumber=$params->{'borrowernumber'} order by date desc,timestamp desc";
1105    my $sth=$dbh->prepare($query);
1106 #   print $query;
1107    $sth->execute;
1108    my $total=0;
1109    while (my $data=$sth->fetchrow_hashref){
1110 #      if ($data->{'itemnumber'} ne ''){
1111 #        $query="Select * from items,biblio where items.itemnumber=
1112 #       '$data->{'itemnumber'}' and biblio.biblionumber=items.biblionumber";
1113 #       my $sth2=$dbh->prepare($query);
1114 #       $sth2->execute;
1115 #       my $data2=$sth2->fetchrow_hashref;
1116 #       $sth2->finish;
1117 #       $data=$data2;
1118  #     }
1119       $acctlines[$numlines] = $data;
1120       $numlines++;
1121       $total = $total+ $data->{'amountoutstanding'};
1122    }
1123    $sth->finish;
1124    $dbh->disconnect;
1125    return ($numlines,\@acctlines,$total);
1126 }
1127
1128 sub itemcount { 
1129   my ($env,$bibnum,$type)=@_; 
1130   my $dbh=C4Connect;   
1131   my $query="Select * from items where     
1132   biblionumber=$bibnum ";
1133   if ($type ne 'intra'){
1134     $query.=" and (itemlost <>1 or itemlost is NULL) and
1135     (wthdrawn <> 1 or wthdrawn is NULL)";      
1136   }
1137   my $sth=$dbh->prepare($query);         
1138   #  print $query;           
1139   $sth->execute;           
1140   my $count=0;             
1141   my $lcount=0;               
1142   my $nacount=0;                 
1143   my $fcount=0;
1144   my $scount=0;
1145   my $lostcount=0;
1146   my $mending=0;
1147   my $transit=0;
1148   my $ocount=0;
1149   while (my $data=$sth->fetchrow_hashref){
1150     $count++;                     
1151     my $query2="select * from issues,items where issues.itemnumber=                          
1152     '$data->{'itemnumber'}' and returndate is NULL
1153     and items.itemnumber=issues.itemnumber and (items.itemlost <>1 or
1154     items.itemlost is NULL)"; 
1155     my $sth2=$dbh->prepare($query2);     
1156     $sth2->execute;         
1157     if (my $data2=$sth2->fetchrow_hashref){         
1158        $nacount++;         
1159     } else {         
1160       if ($data->{'holdingbranch'} eq 'C'){         
1161         $lcount++;               
1162       }                       
1163       if ($data->{'holdingbranch'} eq 'F' || $data->{'holdingbranch'} eq 'FP'){         
1164         $fcount++;               
1165       }                       
1166       if ($data->{'holdingbranch'} eq 'S' || $data->{'holdingbranch'} eq 'SP'){         
1167         $scount++;               
1168       }                       
1169       if ($data->{'itemlost'} eq '1'){
1170         $lostcount++;
1171       }
1172       if ($data->{'holdingbranch'} eq 'FM'){
1173         $mending++;
1174       }
1175       if ($data->{'holdingbranch'} eq 'TR'){
1176         $transit++;
1177       }
1178     }                             
1179     $sth2->finish;     
1180   } 
1181 #  if ($count == 0){
1182     my $query2="Select * from aqorders where biblionumber=$bibnum";
1183     my $sth2=$dbh->prepare($query2);
1184     $sth2->execute;
1185     if (my $data=$sth2->fetchrow_hashref){
1186       $ocount=$data->{'quantity'} - $data->{'quantityreceived'};
1187     }
1188 #    $count+=$ocount;
1189     $sth2->finish;
1190   $sth->finish; 
1191   $dbh->disconnect;                   
1192   return ($count,$lcount,$nacount,$fcount,$scount,$lostcount,$mending,$transit,$ocount); 
1193 }
1194
1195 sub ItemType {
1196   my ($type)=@_;
1197   my $dbh=C4Connect;
1198   my $query="select description from itemtypes where itemtype='$type'";
1199   my $sth=$dbh->prepare($query);
1200   $sth->execute;
1201   my $dat=$sth->fetchrow_hashref;
1202   $sth->finish;
1203   $dbh->disconnect;
1204   return ($dat->{'description'});
1205 }
1206
1207 sub bibitems {
1208   my ($bibnum)=@_;
1209   my $dbh=C4Connect;
1210   my $query="Select * from biblioitems,itemtypes,items where
1211   biblioitems.biblionumber='$bibnum' and biblioitems.itemtype=itemtypes.itemtype and
1212   biblioitems.biblioitemnumber=items.biblioitemnumber group by
1213   items.biblioitemnumber";
1214   my $sth=$dbh->prepare($query);
1215   $sth->execute;
1216   my $i=0;
1217   my @results;
1218   while (my $data=$sth->fetchrow_hashref){
1219     $results[$i]=$data;
1220     $i++;
1221   }
1222   $sth->finish;
1223   $dbh->disconnect;
1224   return($i,@results);
1225 }
1226
1227 sub barcodes{
1228   my ($biblioitemnumber)=@_;
1229   my $dbh=C4Connect;
1230   my $query="Select barcode from items where
1231    biblioitemnumber='$biblioitemnumber'";
1232   my $sth=$dbh->prepare($query);
1233   $sth->execute;
1234   my @barcodes;
1235   my $i=0;
1236   while (my $data=$sth->fetchrow_hashref){
1237     $barcodes[$i]=$data->{'barcode'};
1238     $i++;
1239   }
1240   $sth->finish;
1241   $dbh->disconnect;
1242   return(@barcodes);
1243   
1244 }
1245 END { }       # module clean-up code here (global destructor)
1246
1247
1248
1249
1250
1251