8 use HTML::Template::Pro;
16 $debug = $ENV{DEBUG} || 0;
19 my $dbh = C4::Context->dbh;
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
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'};
56 # $batch_id = get_highest_batch();
60 my ($itemnumber) = @itemnumber if (scalar(@itemnumber) == 1);
62 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
64 template_name => "labels/label-manager.tmpl",
68 flagsrequired => { catalogue => 1 },
73 if ( $op eq 'save_conf' ) { # this early sub is depreciated, use save_layout()
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");
83 elsif ( $op eq 'save_layout' ) {
85 $barcodetype, $title, $subtitle, $isbn,
86 $issn, $itemtype, $bcn, $dcn,
87 $classif, $subclass, $itemcallnumber, $author,
88 $tmpl_id, $printingtype, $guidebox, $startlabel, $layoutname,
92 print $query->redirect("label-home.pl");
95 elsif ( $op eq 'add_layout' ) {
97 $barcodetype, $title, $subtitle, $isbn,
98 $issn, $itemtype, $bcn, $dcn,
99 $classif, $subclass, $itemcallnumber, $author,
100 $tmpl_id, $printingtype, $guidebox, $startlabel, $layoutname,
104 print $query->redirect("label-home.pl");
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);
115 elsif ( $op eq 'deleteall' ) {
116 my $query2 = "DELETE FROM labels";
117 my $sth2 = $dbh->prepare($query2);
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);
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);
132 elsif ( $op eq 'delete_batch' ) {
133 delete_batch($batch_id);
134 print $query->redirect("label-manager.pl?batch_id=");
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");
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);
168 foreach (@messages) {
169 my %hash = (message_text => $_);
170 push @complex, \%hash;
172 $template->param(message_loop => \@complex);
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;