Online Help on Scrolling_list building for sort1 and sort2.
[koha.git] / acqui / newbiblio.pl
1 #!/usr/bin/perl
2
3 #script to show display basket of orders
4 #written by chris@katipo.co.nz 24/2/2000
5
6
7 # Copyright 2000-2002 Katipo Communications
8 #
9 # This file is part of Koha.
10 #
11 # Koha is free software; you can redistribute it and/or modify it under the
12 # terms of the GNU General Public License as published by the Free Software
13 # Foundation; either version 2 of the License, or (at your option) any later
14 # version.
15 #
16 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
17 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
18 # A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
19 #
20 # You should have received a copy of the GNU General Public License along with
21 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
22 # Suite 330, Boston, MA  02111-1307 USA
23
24 use strict;
25 use CGI;
26 use C4::Context;
27 use C4::Input;
28 use C4::Database;
29 use C4::Auth;
30 use C4::Acquisition;
31 use C4::Suggestions;
32 use C4::Search;
33 use C4::Output;
34 use C4::Interface::CGI::Output;
35 use HTML::Template;
36
37 my $input=new CGI;
38 my $booksellerid=$input->param('booksellerid');
39 my $title=$input->param('title');
40 my $author=$input->param('author');
41 my $copyright=$input->param('copyright');
42 my ($count,@booksellers)=bookseller($booksellerid);
43 my $ordnum=$input->param('ordnum');
44 my $biblio=$input->param('biblio');
45 my $basketno=$input->param('basketno');
46 my $suggestionid = $input->param('suggestionid');
47 my $data;
48 my $new;
49 my $dbh = C4::Context->dbh;
50 if ($ordnum eq ''){ # create order
51         $new='yes';
52 #       $ordnum=newordernum;
53         if ($biblio && !$suggestionid) {
54                         $data=bibdata($biblio);
55         }
56         # get suggestion fields if applicable. If it's a subscription renewal, then the biblio already exists
57         # otherwise, retrieve suggestion information.
58         if ($suggestionid) {
59                 if ($biblio) {
60                         $data=bibdata($biblio);
61                 } else {
62                         $data = getsuggestion($suggestionid);
63                 }
64         }
65         if ($data->{'title'} eq ''){
66                 $data->{'title'}=$title;
67                 $data->{'author'}=$author;
68                 $data->{'copyrightdate'}=$copyright;
69         }
70 }else { #modify order
71         $data=getsingleorder($ordnum);
72         $biblio=$data->{'biblionumber'};
73 }
74 my ($template, $loggedinuser, $cookie)
75     = get_template_and_user({template_name => "acqui/newbiblio.tmpl",
76                              query => $input,
77                              type => "intranet",
78                              authnotrequired => 0,
79                              flagsrequired => {acquisition => 1},
80                              debug => 1,
81                              });
82
83
84 # get currencies (for change rates calcs if needed
85 my ($count,$rates)=getcurrencies();
86 my @loop_currency = ();
87 for (my $i=0;$i<$count;$i++){
88         my %line;
89         $line{currency} = $rates->[$i]->{'currency'};
90         $line{rate} = $rates->[$i]->{'rate'};
91         push @loop_currency, \%line;
92 }
93
94 # build itemtype list
95 my $sth=$dbh->prepare("Select itemtype,description from itemtypes order by description");
96 $sth->execute;
97 my  @itemtype;
98 my %itemtypes;
99 while (my ($value,$lib) = $sth->fetchrow_array) {
100         push @itemtype, $value;
101         $itemtypes{$value}=$lib;
102 }
103 my $CGIitemtype=CGI::scrolling_list( -name     => 'format',
104                         -values   => \@itemtype,
105                         -default  => $data->{'itemtype'},
106                         -labels   => \%itemtypes,
107                         -size     => 1,
108                         -multiple => 0 );
109 $sth->finish;
110
111 # build branches list
112 my @branches;
113 my @select_branch;
114 my %select_branches;
115 my ($count2,@branches)=branches();
116 for (my $i=0;$i<$count2;$i++){
117         push @select_branch, $branches[$i]->{'branchcode'};#
118         $select_branches{$branches[$i]->{'branchcode'}} = $branches[$i]->{'branchname'};
119 }
120 my $CGIbranch=CGI::scrolling_list( -name     => 'branch',
121                         -values   => \@select_branch,
122                         -default  => $data->{'branchcode'},
123                         -labels   => \%select_branches,
124                         -size     => 1,
125                         -multiple => 0 );
126
127 # build bookfund list
128 my @bookfund;
129 my @select_bookfund;
130 my %select_bookfunds;
131 ($count2,@bookfund)=bookfunds();
132 for (my $i=0;$i<$count2;$i++){
133         push @select_bookfund, $bookfund[$i]->{'bookfundid'};
134         $select_bookfunds{$bookfund[$i]->{'bookfundid'}} = $bookfund[$i]->{'bookfundname'}
135 }
136 my $CGIbookfund=CGI::scrolling_list( -name     => 'bookfund',
137                         -values   => \@select_bookfund,
138                         -default  => $data->{'bookfundid'},
139                         -labels   => \%select_bookfunds,
140                         -size     => 1,
141                         -multiple => 0 );
142
143 my $CGIsort1 = buildCGIsort("Asort1","sort1",$data->{'sort1'});
144 if ($CGIsort1) {
145         $template->param(CGIsort1 => $CGIsort1);
146 } else {
147         $template->param( sort1 => $data->{'sort1'});
148 }
149
150 my $CGIsort2 = buildCGIsort("Asort2","sort2",$data->{'sort2'});
151 if ($CGIsort2) {
152         $template->param(CGIsort2 =>$CGIsort2);
153 } else {
154         $template->param( sort2 => $data->{'sort2'});
155 }
156                         
157                         
158 # fill template
159 $template->param( existing => $biblio,
160                                                 title => $title,
161                                                 ordnum => $ordnum,
162                                                 basketno => $basketno,
163                                                 booksellerid => $booksellerid,
164                                                 suggestionid => $suggestionid,
165                                                 biblio => $biblio,
166                                                 biblioitemnumber => $data->{'biblioitemnumber'},
167                                                 itemtype => $data->{'itemtype'},
168                                                 discount => $booksellers[0]->{'discount'},
169                                                 listincgst => $booksellers[0]->{'listincgst'},
170                                                 listprice => $booksellers[0]->{'listprice'},
171                                                 gstreg => $booksellers[0]->{'gstreg'},
172                                                 name => $booksellers[0]->{'name'},
173                                                 currency => $booksellers[0]->{'listprice'},
174                                                 gstrate => C4::Context->preference("gist") ,
175                                                 loop_currencies => \@loop_currency,
176                                                 orderexists => ($new eq 'yes')?0:1,
177                                                 title => $data->{'title'},
178                                                 author => $data->{'author'},
179                                                 copyrightdate => $data->{'copyrightdate'},
180                                                 CGIitemtype => $CGIitemtype,
181                                                 CGIbranch => $CGIbranch,
182                                                 CGIbookfund => $CGIbookfund,
183                                                 isbn => $data->{'isbn'},
184                                                 seriestitle => $data->{'seriestitle'},
185                                                 quantity => $data->{'quantity'},
186                                                 listprice => $data->{'listprice'},
187                                                 rrp => $data->{'rrp'},
188                                                 invoice => $data->{'booksellerinvoicenumber'},
189                                                 ecost => $data->{'ecost'},
190                                                 notes => $data->{'notes'},
191                                                 publishercode => $data->{'publishercode'});
192
193 output_html_with_http_headers $input, $cookie, $template->output;