rel_3_0 moved to HEAD
[koha.git] / barcodes / label-manager.pl
1 #!/usr/bin/perl
2
3 # This file is part of Koha.
4 #
5 # Koha is free software; you can redistribute it and/or modify it under the
6 # terms of the GNU General Public License as published by the Free Software
7 # Foundation; either version 2 of the License, or (at your option) any later
8 # version.
9 #
10 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
11 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
12 # A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License along with
15 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
16 # Suite 330, Boston, MA  02111-1307 USA
17
18 use strict;
19 use CGI;
20 use C4::Auth;
21 use C4::Labels;
22 use C4::Output;
23 use C4::Interface::CGI::Output;
24
25 use POSIX;
26
27 my $dbh            = C4::Context->dbh;
28 my $query          = new CGI;
29 my $op             = $query->param('op');
30 my $barcodetype    = $query->param('barcodetype');
31 my $title          = $query->param('title');
32 my $isbn           = $query->param('isbn');
33 my $itemtype       = $query->param('itemtype');
34 my $bcn            = $query->param('bcn');
35 my $dcn            = $query->param('dcn');
36 my $classif        = $query->param('classif');
37 my $itemcallnumber = $query->param('itemcallnumber');
38 my $subclass       = $query->param('subclass');
39 my $author         = $query->param('author');
40 my $tmpl_id        = $query->param('tmpl_id');
41 my $itemnumber     = $query->param('itemnumber');
42 my $summary        = $query->param('summary');
43 my $startlabel     = $query->param('startlabel');
44 my $printingtype   = $query->param('printingtype');
45 my $guidebox       = $query->param('guidebox');
46 my $fontsize       = $query->param('fontsize');
47
48 #warn "ID =$tmpl_id";
49
50 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
51     {
52         template_name   => "barcodes/label-manager.tmpl",
53         query           => $query,
54         type            => "intranet",
55         authnotrequired => 1,
56         flagsrequired   => { tools => 1 },
57         debug           => 1,
58     }
59 );
60
61 if ( $op eq 'save_conf' ) {
62     SaveConf(
63         $barcodetype,    $title,  $isbn,    $itemtype,
64         $bcn,            $dcn,    $classif, $subclass,
65         $itemcallnumber, $author, $tmpl_id, $printingtype,
66         $guidebox,       $startlabel
67     );
68
69 }
70 elsif ( $op eq 'add' ) {
71     my $query2 = "INSERT INTO labels ( itemnumber ) values ( ? )";
72     my $sth2   = $dbh->prepare($query2);
73     $sth2->execute($itemnumber);
74     $sth2->finish;
75 }
76 elsif ( $op eq 'deleteall' ) {
77     my $query2 = "DELETE FROM labels";
78     my $sth2   = $dbh->prepare($query2);
79     $sth2->execute();
80     $sth2->finish;
81 }
82 elsif ( $op eq 'delete' ) {
83     warn "MASON, deleting label..";
84     my $query2 = "DELETE FROM labels where itemnumber = ?";
85     my $sth2   = $dbh->prepare($query2);
86     $sth2->execute($itemnumber);
87     $sth2->finish;
88 }
89
90 #  first lets do a read of the labels table , to get the a list of the
91 # currently entered items to be prinited
92
93 my @resultsloop = ();
94 my $count;
95 my @data;
96 my $query3 = "Select * from labels";
97 my $sth    = $dbh->prepare($query3);
98 $sth->execute();
99
100 my $cnt = $sth->rows;
101 my $i1  = 1;
102 while ( my $data = $sth->fetchrow_hashref ) {
103
104     # lets get some summary info from each item
105     my $query1 = "
106                         select * from biblio,biblioitems,items where itemnumber=? and 
107                                 items.biblioitemnumber=biblioitems.biblioitemnumber and 
108                                 biblioitems.biblionumber=biblio.biblionumber";
109
110     my $sth1 = $dbh->prepare($query1);
111     $sth1->execute( $data->{'itemnumber'} );
112     my $data1 = $sth1->fetchrow_hashref();
113
114     $data1->{'labelno'} = $i1;
115     $data1->{'summary'} =
116       "$data1->{'barcode'}, $data1->{'title'}, $data1->{'isbn'}";
117
118     push( @resultsloop, $data1 );
119     $sth1->finish;
120
121     $i1++;
122 }
123 $sth->finish;
124
125 # this script can be run from the side nav, and is not passed a value for $startrow
126 # so lets get it from the DB
127
128 my $dbh    = C4::Context->dbh;
129 my $query2 = "SELECT * FROM labels_conf LIMIT 1";
130 my $sth    = $dbh->prepare($query2);
131 $sth->execute();
132
133 my $data = $sth->fetchrow_hashref;
134 $sth->finish;
135
136 #calc-ing number of sheets
137
138 #$sheets_needed = ceil($sheets_needed);    # rounding up int's
139
140 #my $tot_labels       = ( $sheets_needed * 8 );
141 #my $start_results    = ( $number_of_results + $startrow );
142 #my $labels_remaining = ( $tot_labels - $start_results );
143
144 $template->param(
145     resultsloop => \@resultsloop,
146
147     #  startrow         => $startrow,
148     #  sheets           => $sheets_needed,
149     #  labels_remaining => $labels_remaining,
150     intranetcolorstylesheet =>
151       C4::Context->preference("intranetcolorstylesheet"),
152     intranetstylesheet => C4::Context->preference("intranetstylesheet"),
153     IntranetNav        => C4::Context->preference("IntranetNav"),
154 );
155 output_html_with_http_headers $query, $cookie, $template->output;