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 $formatstring = $query->param('formatstring');
44 my $batch_type = $query->param('type');
45 ($batch_type and $batch_type eq 'patroncards') or $batch_type = 'labels';
47 ($batch_type eq 'labels') ? (@itemnumber = $query->param('itemnumber')) : (@itemnumber = $query->param('borrowernumber'));
49 # little block for displaying active layout/template/batch in templates
51 my $batch_id = $query->param('batch_id');
52 my $active_layout = get_active_layout();
53 my $active_template = GetActiveLabelTemplate();
54 my $active_layout_name = $active_layout->{'layoutname'};
55 my $active_template_name = $active_template->{'tmpl_code'};
59 # $batch_id = get_highest_batch();
62 #my $batch_type = "labels"; #FIXME: Hardcoded for testing/development...
64 my ($itemnumber) = @itemnumber if (scalar(@itemnumber) == 1);
66 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
68 template_name => "labels/label-manager.tmpl",
72 flagsrequired => { catalogue => 1 },
77 #if ( $op eq 'save_conf' ) { # this early sub is depreciated, use save_layout()
79 # $barcodetype, $title, $isbn,
80 # $issn, $itemtype, $bcn, $dcn,
81 # $classif, $subclass, $itemcallnumber, $author,
82 # $tmpl_id, $printingtype, $guidebox, $startlabel, $layoutname
84 # print $query->redirect("label-home.pl");
87 #elsif ( $op eq 'save_layout' ) {
88 if ( $op eq 'save_layout' ) {
90 $barcodetype, $title, $subtitle, $isbn,
91 $issn, $itemtype, $bcn, $dcn,
92 $classif, $subclass, $itemcallnumber, $author,
93 $tmpl_id, $printingtype, $guidebox, $startlabel, $layoutname,
94 , $formatstring , $layout_id
97 print $query->redirect("label-home.pl");
100 elsif ( $op eq 'add_layout' ) {
102 $barcodetype, $title, $subtitle, $isbn,
103 $issn, $itemtype, $bcn, $dcn,
104 $classif, $subclass, $itemcallnumber, $author,
105 $tmpl_id, $printingtype, $guidebox, $startlabel, $layoutname,
106 $formatstring , $layout_id
109 print $query->redirect("label-home.pl");
113 # FIXME: The trinary conditionals here really need to be replaced with a more robust form of db abstraction -fbcit
115 elsif ( $op eq 'add' ) { # add item
116 my $query2 = ($batch_type eq 'patroncards') ?
117 "INSERT INTO patroncards (borrowernumber, batch_id) values (?,?)" :
118 "INSERT INTO labels (itemnumber, batch_id) values (?,?)" ;
119 my $sth2 = $dbh->prepare($query2);
120 for my $inum (@itemnumber) {
121 # warn "INSERTing " . (($batch_type eq 'labels') ? 'itemnumber' : 'borrowernumber') . ":$inum for batch $batch_id";
122 $sth2->execute($inum, $batch_id);
125 elsif ( $op eq 'deleteall' ) {
126 my $query2 = "DELETE FROM $batch_type";
127 my $sth2 = $dbh->prepare($query2);
130 elsif ( $op eq 'delete' ) {
131 my @labelids = $query->param((($batch_type eq 'labels') ? 'labelid' : 'cardid'));
132 scalar @labelids or push @messages, (($batch_type eq 'labels') ? "ERROR: No labelid(s) supplied for deletion." : "ERROR: No cardid(s) supplied for deletion.");
133 my $ins = "?," x (scalar @labelids);
135 my $query2 = "DELETE FROM $batch_type WHERE " . (($batch_type eq 'labels') ? 'labelid' : 'cardid') ." IN ($ins) ";
136 $debug and push @messages, "query2: $query2 -- (@labelids)";
137 my $sth2 = $dbh->prepare($query2);
138 $sth2->execute(@labelids);
140 elsif ( $op eq 'delete_batch' ) {
141 delete_batch($batch_id, $batch_type);
142 print $query->redirect("label-manager.pl?type=$batch_type");
145 elsif ( $op eq 'add_batch' ) {
146 $batch_id= add_batch($batch_type);
148 elsif ( $op eq 'set_active_layout' ) {
149 set_active_layout($layout_id);
150 print $query->redirect("label-home.pl");
153 elsif ( $op eq 'deduplicate' ) {
154 warn "\$batch_id=$batch_id and \$batch_type=$batch_type";
155 my ($return, $dberror) = deduplicate_batch($batch_id, $batch_type);
156 my $msg = (($return) ? "Removed $return" : "Error removing") . " duplicate items from Batch $batch_id." . (($dberror) ? " Database returned: $dberror" : "");
157 push @messages, $msg;
160 # first lets do a read of the labels table , to get the a list of the
161 # currently entered items to be prinited
162 my @batches = get_batches($batch_type);
163 my @resultsloop = ($batch_type eq 'labels') ? GetLabelItems($batch_id) : GetPatronCardItems($batch_id);
164 #warn "$batches[0] (id $batch_id)";
165 #warn Dumper(@resultsloop);
167 #calc-ing number of sheets
168 #my $number_of_results = scalar @resultsloop;
169 #my $sheets_needed = ceil( ( --$number_of_results + $startrow ) / 8 ); # rounding up
170 #my $tot_labels = ( $sheets_needed * 8 );
171 #my $start_results = ( $number_of_results + $startrow );
172 #my $labels_remaining = ( $tot_labels - $start_results );
174 if (scalar @messages) {
175 $template->param(message => 1);
177 foreach (@messages) {
178 my %hash = (message_text => $_);
179 push @complex, \%hash;
181 $template->param(message_loop => \@complex);
183 if ($batch_type eq 'labels' or $batch_type eq 'patroncards') {
184 $template->param("batch_is_$batch_type" => 1);
187 batch_type => $batch_type,
188 batch_id => $batch_id,
189 batch_count => scalar @resultsloop,
190 active_layout_name => $active_layout_name,
191 active_template_name => $active_template_name,
192 outputformat => ( $active_layout->{'printingtype'} eq 'CSV' ) ? 'csv' : 'pdf' ,
193 layout_tx => ( $active_layout->{'formatstring'}) ? 0 : 1 ,
194 layout_string => ( $active_layout->{'formatstring'}) ? 1 : 0 ,
196 resultsloop => \@resultsloop,
197 batches => \@batches,
198 tmpl_desc => $active_template->{'tmpl_desc'},
200 # startrow => $startrow,
201 # sheets => $sheets_needed,
202 # labels_remaining => $labels_remaining,
204 output_html_with_http_headers $query, $cookie, $template->output;