Initial revision
[koha.git] / C4 / Maintainance.pm
1 package C4::Maintainance; #asummes C4/Maintainance
2
3 #package to deal with marking up output
4
5 use strict;
6 use C4::Database;
7
8 require Exporter;
9
10 use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
11
12 # set the version for version checking
13 $VERSION = 0.01;
14
15 @ISA = qw(Exporter);
16 @EXPORT = qw(&listsubjects &updatesub);
17 %EXPORT_TAGS = ( );     # eg: TAG => [ qw!name1 name2! ],
18
19 # your exported package globals go here,
20 # as well as any optionally exported functions
21
22 @EXPORT_OK   = qw($Var1 %Hashit);
23
24
25 # non-exported package globals go here
26 use vars qw(@more $stuff);
27
28 # initalize package globals, first exported ones
29
30 my $Var1   = '';
31 my %Hashit = ();
32
33
34 # then the others (which are still accessible as $Some::Module::stuff)
35 my $stuff  = '';
36 my @more   = ();
37
38 # all file-scoped lexicals must be created before
39 # the functions below that use them.
40
41 # file-private lexicals go here
42 my $priv_var    = '';
43 my %secret_hash = ();
44
45 # here's a file-private function as a closure,
46 # callable as &$priv_func;  it cannot be prototyped.
47 my $priv_func = sub {
48 # stuff goes here.
49   };
50    
51 # make all your functions, whether exported or not;
52  
53 sub listsubjects {
54   my ($sub,$num,$offset)=@_;
55   my $dbh=C4Connect;
56   my $query="Select * from bibliosubject where subject like '$sub%' group by subject";
57   if ($num != 0){
58     $query.=" limit $offset,$num";
59   }
60   my $sth=$dbh->prepare($query);
61 #  print $query;
62   $sth->execute;
63   my @results;
64   my $i=0;
65   while (my $data=$sth->fetchrow_hashref){
66     $results[$i]=$data;
67     $i++;
68   }
69   $sth->finish;
70   $dbh->disconnect;
71   return($i,\@results);
72 }
73
74 sub updatesub{
75   my ($sub,$oldsub)=@_;
76   my $dbh=C4Connect;
77   my $query="update bibliosubject set subject='$sub' where subject='$oldsub'";
78   my $sth=$dbh->prepare($query);
79   $sth->execute;
80   $sth->finish;
81   $dbh->disconnect;
82 }
83 END { }       # module clean-up code here (global destructor)
84