Added issue date column to issues list
[koha.git] / labels / label-manager.pl
blobad3ae816f0c5b43ae6396a4e9323fd40c15da0c7
1 #!/usr/bin/perl
3 use strict;
4 use CGI;
5 use C4::Auth;
6 use C4::Labels;
7 use C4::Output;
8 use HTML::Template::Pro;
9 #use POSIX qw(ceil);
10 #use Data::Dumper;
11 #use Smart::Comments;
13 use vars qw($debug);
15 BEGIN {
16 $debug = $ENV{DEBUG} || 0;
19 my $dbh = C4::Context->dbh;
20 my $query = new CGI;
21 $query->param('debug') and $debug = $query->param('debug');
22 my $op = $query->param('op');
23 my $layout_id = $query->param('layout_id');
24 my $layoutname = $query->param('layoutname');
25 my $barcodetype = $query->param('barcodetype');
26 my $bcn = $query->param('tx_barcode');
27 my $title = $query->param('tx_title');
28 my $subtitle = $query->param('tx_subtitle');
29 my $isbn = $query->param('tx_isbn');
30 my $issn = $query->param('tx_issn');
31 my $itemtype = $query->param('tx_itemtype');
32 my $dcn = $query->param('tx_dewey');
33 my $classif = $query->param('tx_classif');
34 my $itemcallnumber = $query->param('tx_itemcallnumber');
35 my $subclass = $query->param('tx_subclass');
36 my $author = $query->param('tx_author');
37 my $tmpl_id = $query->param('tmpl_id');
38 my $summary = $query->param('summary');
39 my $startlabel = $query->param('startlabel');
40 my $printingtype = $query->param('printingtype');
41 my $guidebox = $query->param('guidebox');
42 my $fontsize = $query->param('fontsize');
43 my @itemnumber = $query->param('itemnumber');
46 # little block for displaying active layout/template/batch in templates
47 # ----------
48 my $batch_id = $query->param('batch_id');
49 my $active_layout = get_active_layout();
50 my $active_template = GetActiveLabelTemplate();
51 my $active_layout_name = $active_layout->{'layoutname'};
52 my $active_template_name = $active_template->{'tmpl_code'};
53 # ----------
55 #if (!$batch_id ) {
56 # $batch_id = get_highest_batch();
59 my @messages;
60 my ($itemnumber) = @itemnumber if (scalar(@itemnumber) == 1);
62 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
64 template_name => "labels/label-manager.tmpl",
65 query => $query,
66 type => "intranet",
67 authnotrequired => 1,
68 flagsrequired => { catalogue => 1 },
69 debug => 1,
73 if ( $op eq 'save_conf' ) { # this early sub is depreciated, use save_layout()
74 SaveConf(
75 $barcodetype, $title, $isbn,
76 $issn, $itemtype, $bcn, $dcn,
77 $classif, $subclass, $itemcallnumber, $author,
78 $tmpl_id, $printingtype, $guidebox, $startlabel, $layoutname
80 print $query->redirect("label-home.pl");
81 exit;
83 elsif ( $op eq 'save_layout' ) {
84 save_layout(
85 $barcodetype, $title, $subtitle, $isbn,
86 $issn, $itemtype, $bcn, $dcn,
87 $classif, $subclass, $itemcallnumber, $author,
88 $tmpl_id, $printingtype, $guidebox, $startlabel, $layoutname,
89 $layout_id
91 ### $layoutname
92 print $query->redirect("label-home.pl");
93 exit;
95 elsif ( $op eq 'add_layout' ) {
96 add_layout(
97 $barcodetype, $title, $subtitle, $isbn,
98 $issn, $itemtype, $bcn, $dcn,
99 $classif, $subclass, $itemcallnumber, $author,
100 $tmpl_id, $printingtype, $guidebox, $startlabel, $layoutname,
101 $layout_id
103 ### $layoutname
104 print $query->redirect("label-home.pl");
105 exit;
107 elsif ( $op eq 'add' ) { # add item
108 my $query2 = "INSERT INTO labels ( itemnumber, batch_id ) values ( ?,? )";
109 my $sth2 = $dbh->prepare($query2);
110 for my $inum (@itemnumber) {
111 $sth2->execute($inum, $batch_id);
113 $sth2->finish;
115 elsif ( $op eq 'deleteall' ) {
116 my $query2 = "DELETE FROM labels";
117 my $sth2 = $dbh->prepare($query2);
118 $sth2->execute();
119 $sth2->finish;
121 elsif ( $op eq 'delete' ) {
122 my @labelids = $query->param('labelid');
123 scalar @labelids or push @messages, "ERROR: No labelid(s) supplied for deletion.";
124 my $ins = "?," x (scalar @labelids);
125 $ins =~ s/\,$//;
126 my $query2 = "DELETE FROM labels WHERE labelid IN ($ins) ";
127 $debug and push @messages, "query2: $query2 -- (@labelids)";
128 my $sth2 = $dbh->prepare($query2);
129 $sth2->execute(@labelids);
130 $sth2->finish;
132 elsif ( $op eq 'delete_batch' ) {
133 delete_batch($batch_id);
134 print $query->redirect("label-manager.pl?batch_id=");
135 exit;
137 elsif ( $op eq 'add_batch' ) {
138 $batch_id= add_batch();
140 elsif ( $op eq 'set_active_layout' ) {
141 set_active_layout($layout_id);
142 print $query->redirect("label-home.pl");
143 exit;
145 elsif ( $op eq 'deduplicate' ) {
146 my $return = deduplicate_batch($batch_id);
147 my $msg = (($return) ? "Removed $return" : "Error revoving") . " duplicate items from Batch $batch_id";
148 push @messages, $msg;
151 # first lets do a read of the labels table , to get the a list of the
152 # currently entered items to be prinited
153 my @batches = get_batches();
154 my @resultsloop = get_label_items($batch_id);
155 #warn "$batches[0] (id $batch_id)";
156 #warn Dumper(@resultsloop);
158 #calc-ing number of sheets
159 #my $number_of_results = scalar @resultsloop;
160 #my $sheets_needed = ceil( ( --$number_of_results + $startrow ) / 8 ); # rounding up
161 #my $tot_labels = ( $sheets_needed * 8 );
162 #my $start_results = ( $number_of_results + $startrow );
163 #my $labels_remaining = ( $tot_labels - $start_results );
165 if (scalar @messages) {
166 $template->param(message => 1);
167 my @complex = ();
168 foreach (@messages) {
169 my %hash = (message_text => $_);
170 push @complex, \%hash;
172 $template->param(message_loop => \@complex);
174 $template->param(
175 batch_id => $batch_id,
176 batch_count => scalar @resultsloop,
177 active_layout_name => $active_layout_name,
178 active_template_name => $active_template_name,
180 resultsloop => \@resultsloop,
181 batches => \@batches,
182 tmpl_desc => $active_template->{'tmpl_desc'},
184 # startrow => $startrow,
185 # sheets => $sheets_needed,
186 # labels_remaining => $labels_remaining,
188 output_html_with_http_headers $query, $cookie, $template->output;