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') if ($query->param('type') eq 'labels');
44 my @itemnumber = $query->param('borrowernumber') if ($query->param('type') eq 'patroncards');
45 my $batch_type = $query->param('type');
47 # little block for displaying active layout/template/batch in templates
49 my $batch_id = $query->param('batch_id');
50 my $active_layout = get_active_layout();
51 my $active_template = GetActiveLabelTemplate();
52 my $active_layout_name = $active_layout->{'layoutname'};
53 my $active_template_name = $active_template->{'tmpl_code'};
57 # $batch_id = get_highest_batch();
60 #my $batch_type = "labels"; #FIXME: Hardcoded for testing/development...
62 my ($itemnumber) = @itemnumber if (scalar(@itemnumber) == 1);
64 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
66 template_name => "labels/label-manager.tmpl",
70 flagsrequired => { catalogue => 1 },
75 if ( $op eq 'save_conf' ) { # this early sub is depreciated, use save_layout()
77 $barcodetype, $title, $isbn,
78 $issn, $itemtype, $bcn, $dcn,
79 $classif, $subclass, $itemcallnumber, $author,
80 $tmpl_id, $printingtype, $guidebox, $startlabel, $layoutname
82 print $query->redirect("label-home.pl");
85 elsif ( $op eq 'save_layout' ) {
87 $barcodetype, $title, $subtitle, $isbn,
88 $issn, $itemtype, $bcn, $dcn,
89 $classif, $subclass, $itemcallnumber, $author,
90 $tmpl_id, $printingtype, $guidebox, $startlabel, $layoutname,
94 print $query->redirect("label-home.pl");
97 elsif ( $op eq 'add_layout' ) {
99 $barcodetype, $title, $subtitle, $isbn,
100 $issn, $itemtype, $bcn, $dcn,
101 $classif, $subclass, $itemcallnumber, $author,
102 $tmpl_id, $printingtype, $guidebox, $startlabel, $layoutname,
106 print $query->redirect("label-home.pl");
110 # FIXME: The trinary conditionals here really need to be replaced with a more robust form of db abstraction -fbcit
112 elsif ( $op eq 'add' ) { # add item
113 my $query2 = "INSERT INTO $batch_type ( " . (($batch_type eq 'labels') ? 'itemnumber' : 'borrowernumber') . ", batch_id ) values ( ?,? )";
114 my $sth2 = $dbh->prepare($query2);
115 for my $inum (@itemnumber) {
116 warn "INSERTing " . (($batch_type eq 'labels') ? 'itemnumber' : 'borrowernumber') . ":$inum for batch $batch_id";
117 $sth2->execute($inum, $batch_id);
121 elsif ( $op eq 'deleteall' ) {
122 my $query2 = "DELETE FROM $batch_type";
123 my $sth2 = $dbh->prepare($query2);
127 elsif ( $op eq 'delete' ) {
128 my @labelids = $query->param((($batch_type eq 'labels') ? 'labelid' : 'cardid'));
129 scalar @labelids or push @messages, (($batch_type eq 'labels') ? "ERROR: No labelid(s) supplied for deletion." : "ERROR: No cardid(s) supplied for deletion.");
130 my $ins = "?," x (scalar @labelids);
132 my $query2 = "DELETE FROM $batch_type WHERE " . (($batch_type eq 'labels') ? 'labelid' : 'cardid') ." IN ($ins) ";
133 $debug and push @messages, "query2: $query2 -- (@labelids)";
134 my $sth2 = $dbh->prepare($query2);
135 $sth2->execute(@labelids);
138 elsif ( $op eq 'delete_batch' ) {
139 delete_batch($batch_id, $batch_type);
140 print $query->redirect("label-manager.pl");
143 elsif ( $op eq 'add_batch' ) {
144 $batch_id= add_batch($batch_type);
146 elsif ( $op eq 'set_active_layout' ) {
147 set_active_layout($layout_id);
148 print $query->redirect("label-home.pl");
151 elsif ( $op eq 'deduplicate' ) {
152 my $return = deduplicate_batch($batch_id);
153 my $msg = (($return) ? "Removed $return" : "Error revoving") . " duplicate items from Batch $batch_id";
154 push @messages, $msg;
157 # first lets do a read of the labels table , to get the a list of the
158 # currently entered items to be prinited
159 my @batches = get_batches($batch_type);
160 my @resultsloop = ($batch_type eq 'labels') ? GetLabelItems($batch_id) : GetPatronCardItems($batch_id);
161 #warn "$batches[0] (id $batch_id)";
162 #warn Dumper(@resultsloop);
164 #calc-ing number of sheets
165 #my $number_of_results = scalar @resultsloop;
166 #my $sheets_needed = ceil( ( --$number_of_results + $startrow ) / 8 ); # rounding up
167 #my $tot_labels = ( $sheets_needed * 8 );
168 #my $start_results = ( $number_of_results + $startrow );
169 #my $labels_remaining = ( $tot_labels - $start_results );
171 if (scalar @messages) {
172 $template->param(message => 1);
174 foreach (@messages) {
175 my %hash = (message_text => $_);
176 push @complex, \%hash;
178 $template->param(message_loop => \@complex);
182 batch_id => $batch_id,
183 batch_count => scalar @resultsloop,
184 active_layout_name => $active_layout_name,
185 active_template_name => $active_template_name,
187 resultsloop => \@resultsloop,
188 batches => \@batches,
189 tmpl_desc => $active_template->{'tmpl_desc'},
191 # startrow => $startrow,
192 # sheets => $sheets_needed,
193 # labels_remaining => $labels_remaining,
195 output_html_with_http_headers $query, $cookie, $template->output;