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();
59 my $batch_type = "labels"; #FIXME: Hardcoded for testing...
61 my ($itemnumber) = @itemnumber if (scalar(@itemnumber) == 1);
63 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
65 template_name => "labels/label-manager.tmpl",
69 flagsrequired => { catalogue => 1 },
74 if ( $op eq 'save_conf' ) { # this early sub is depreciated, use save_layout()
76 $barcodetype, $title, $isbn,
77 $issn, $itemtype, $bcn, $dcn,
78 $classif, $subclass, $itemcallnumber, $author,
79 $tmpl_id, $printingtype, $guidebox, $startlabel, $layoutname
81 print $query->redirect("label-home.pl");
84 elsif ( $op eq 'save_layout' ) {
86 $barcodetype, $title, $subtitle, $isbn,
87 $issn, $itemtype, $bcn, $dcn,
88 $classif, $subclass, $itemcallnumber, $author,
89 $tmpl_id, $printingtype, $guidebox, $startlabel, $layoutname,
93 print $query->redirect("label-home.pl");
96 elsif ( $op eq 'add_layout' ) {
98 $barcodetype, $title, $subtitle, $isbn,
99 $issn, $itemtype, $bcn, $dcn,
100 $classif, $subclass, $itemcallnumber, $author,
101 $tmpl_id, $printingtype, $guidebox, $startlabel, $layoutname,
105 print $query->redirect("label-home.pl");
109 # FIXME: The trinary conditionals here really need to be replaced with a more robust form of db abstraction -fbcit
111 elsif ( $op eq 'add' ) { # add item
112 my $query2 = "INSERT INTO $batch_type ( " . (($batch_type eq 'labels') ? 'itemnumber' : 'borrowernumber') . ", batch_id ) values ( ?,? )";
113 my $sth2 = $dbh->prepare($query2);
114 for my $inum (@itemnumber) {
115 $sth2->execute($inum, $batch_id);
119 elsif ( $op eq 'deleteall' ) {
120 my $query2 = "DELETE FROM $batch_type";
121 my $sth2 = $dbh->prepare($query2);
125 elsif ( $op eq 'delete' ) {
126 my @labelids = $query->param((($batch_type eq 'labels') ? 'labelid' : 'cardid'));
127 scalar @labelids or push @messages, (($batch_type eq 'labels') ? "ERROR: No labelid(s) supplied for deletion." : "ERROR: No cardid(s) supplied for deletion.");
128 my $ins = "?," x (scalar @labelids);
130 my $query2 = "DELETE FROM $batch_type WHERE " . (($batch_type eq 'labels') ? 'labelid' : 'cardid') ." IN ($ins) ";
131 $debug and push @messages, "query2: $query2 -- (@labelids)";
132 my $sth2 = $dbh->prepare($query2);
133 $sth2->execute(@labelids);
136 elsif ( $op eq 'delete_batch' ) {
137 delete_batch($batch_id, $batch_type);
138 print $query->redirect("label-manager.pl?batch_id=");
141 elsif ( $op eq 'add_batch' ) {
142 $batch_id= add_batch($batch_type);
144 elsif ( $op eq 'set_active_layout' ) {
145 set_active_layout($layout_id);
146 print $query->redirect("label-home.pl");
149 elsif ( $op eq 'deduplicate' ) {
150 my $return = deduplicate_batch($batch_id);
151 my $msg = (($return) ? "Removed $return" : "Error revoving") . " duplicate items from Batch $batch_id";
152 push @messages, $msg;
155 # first lets do a read of the labels table , to get the a list of the
156 # currently entered items to be prinited
157 my @batches = get_batches();
158 my @resultsloop = get_label_items($batch_id);
159 #warn "$batches[0] (id $batch_id)";
160 #warn Dumper(@resultsloop);
162 #calc-ing number of sheets
163 #my $number_of_results = scalar @resultsloop;
164 #my $sheets_needed = ceil( ( --$number_of_results + $startrow ) / 8 ); # rounding up
165 #my $tot_labels = ( $sheets_needed * 8 );
166 #my $start_results = ( $number_of_results + $startrow );
167 #my $labels_remaining = ( $tot_labels - $start_results );
169 if (scalar @messages) {
170 $template->param(message => 1);
172 foreach (@messages) {
173 my %hash = (message_text => $_);
174 push @complex, \%hash;
176 $template->param(message_loop => \@complex);
179 batch_id => $batch_id,
180 batch_count => scalar @resultsloop,
181 active_layout_name => $active_layout_name,
182 active_template_name => $active_template_name,
184 resultsloop => \@resultsloop,
185 batches => \@batches,
186 tmpl_desc => $active_template->{'tmpl_desc'},
188 # startrow => $startrow,
189 # sheets => $sheets_needed,
190 # labels_remaining => $labels_remaining,
192 output_html_with_http_headers $query, $cookie, $template->output;