adding a warn to log why we're redirecting to installer
[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
24 use POSIX;
25
26 my $dbh            = C4::Context->dbh;
27 my $query          = new CGI;
28 my $op             = $query->param('op');
29 my $barcodetype    = $query->param('barcodetype');
30 my $title          = $query->param('title');
31 my $isbn           = $query->param('isbn');
32 my $itemtype       = $query->param('itemtype');
33 my $bcn            = $query->param('bcn');
34 my $dcn            = $query->param('dcn');
35 my $classif        = $query->param('classif');
36 my $itemcallnumber = $query->param('itemcallnumber');
37 my $subclass       = $query->param('subclass');
38 my $author         = $query->param('author');
39 my $tmpl_id        = $query->param('tmpl_id');
40 my $itemnumber     = $query->param('itemnumber');
41 my $summary        = $query->param('summary');
42 my $startlabel     = $query->param('startlabel');
43 my $printingtype   = $query->param('printingtype');
44 my $guidebox       = $query->param('guidebox');
45 my $fontsize       = $query->param('fontsize');
46
47 #warn "ID =$tmpl_id";
48
49 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
50     {
51         template_name   => "barcodes/label-manager.tmpl",
52         query           => $query,
53         type            => "intranet",
54         authnotrequired => 1,
55         flagsrequired   => { tools => 1 },
56         debug           => 1,
57     }
58 );
59
60 if ( $op eq 'save_conf' ) {
61     SaveConf(
62         $barcodetype,    $title,  $isbn,    $itemtype,
63         $bcn,            $dcn,    $classif, $subclass,
64         $itemcallnumber, $author, $tmpl_id, $printingtype,
65         $guidebox,       $startlabel
66     );
67
68 }
69 elsif ( $op eq 'add' ) {
70     my $query2 = "INSERT INTO labels ( itemnumber ) values ( ? )";
71     my $sth2   = $dbh->prepare($query2);
72     $sth2->execute($itemnumber);
73     $sth2->finish;
74 }
75 elsif ( $op eq 'deleteall' ) {
76     my $query2 = "DELETE FROM labels";
77     my $sth2   = $dbh->prepare($query2);
78     $sth2->execute();
79     $sth2->finish;
80 }
81 elsif ( $op eq 'delete' ) {
82     warn "MASON, deleting label..";
83     my $query2 = "DELETE FROM labels where itemnumber = ?";
84     my $sth2   = $dbh->prepare($query2);
85     $sth2->execute($itemnumber);
86     $sth2->finish;
87 }
88
89 #  first lets do a read of the labels table , to get the a list of the
90 # currently entered items to be prinited
91
92 my @resultsloop = ();
93 my $count;
94 my @data;
95 my $query3 = "Select * from labels";
96 my $sth    = $dbh->prepare($query3);
97 $sth->execute();
98
99 my $cnt = $sth->rows;
100 my $i1  = 1;
101 while ( my $data = $sth->fetchrow_hashref ) {
102
103     # lets get some summary info from each item
104     my $query1 = "
105                         select * from biblio,biblioitems,items where itemnumber=? and 
106                                 items.biblioitemnumber=biblioitems.biblioitemnumber and 
107                                 biblioitems.biblionumber=biblio.biblionumber";
108
109     my $sth1 = $dbh->prepare($query1);
110     $sth1->execute( $data->{'itemnumber'} );
111     my $data1 = $sth1->fetchrow_hashref();
112
113     $data1->{'labelno'} = $i1;
114     $data1->{'summary'} =
115       "$data1->{'barcode'}, $data1->{'title'}, $data1->{'isbn'}";
116
117     push( @resultsloop, $data1 );
118     $sth1->finish;
119
120     $i1++;
121 }
122 $sth->finish;
123
124 # this script can be run from the side nav, and is not passed a value for $startrow
125 # so lets get it from the DB
126
127 my $dbh    = C4::Context->dbh;
128 my $query2 = "SELECT * FROM labels_conf LIMIT 1";
129 my $sth    = $dbh->prepare($query2);
130 $sth->execute();
131
132 my $data = $sth->fetchrow_hashref;
133 $sth->finish;
134
135 #calc-ing number of sheets
136
137 #$sheets_needed = ceil($sheets_needed);    # rounding up int's
138
139 #my $tot_labels       = ( $sheets_needed * 8 );
140 #my $start_results    = ( $number_of_results + $startrow );
141 #my $labels_remaining = ( $tot_labels - $start_results );
142
143 $template->param(
144     resultsloop => \@resultsloop,
145
146     #  startrow         => $startrow,
147     #  sheets           => $sheets_needed,
148     #  labels_remaining => $labels_remaining,
149     intranetcolorstylesheet =>
150       C4::Context->preference("intranetcolorstylesheet"),
151     intranetstylesheet => C4::Context->preference("intranetstylesheet"),
152     IntranetNav        => C4::Context->preference("IntranetNav"),
153 );
154 output_html_with_http_headers $query, $cookie, $template->output;