Now, the acqui.simple system...
[koha.git] / acqui.simple / additem.pl
1 #!/usr/bin/perl
2
3 use CGI;
4 use strict;
5 use C4::Catalogue;
6 use C4::Biblio;
7 use C4::Output;
8
9 my $input = new CGI;
10 my $biblionumber = $input->param('biblionumber');
11 my $error        = $input->param('error');
12 my $maxbarcode;
13 my $isbn;
14 my $bibliocount;
15 my @biblios;
16 my $biblioitemcount;
17 my @biblioitems;
18 my $branchcount;
19 my @branches;
20 my %branchnames;
21 my $itemcount;
22 my @items;
23 my $itemtypecount;
24 my @itemtypes;
25 my %itemtypedescriptions;
26
27 if (! $biblionumber) {
28     print $input->redirect('addbooks.pl');
29 } else {
30
31     ($bibliocount, @biblios)  = &getbiblio($biblionumber);
32
33     if (! $bibliocount) {
34         print $input->redirect('addbooks.pl');
35     } else {
36
37         ($biblioitemcount, @biblioitems) = &getbiblioitembybiblionumber($biblionumber);
38         ($branchcount, @branches)        = &branches;
39         ($itemtypecount, @itemtypes)     = &getitemtypes;
40         
41         for (my $i = 0; $i < $itemtypecount; $i++) {
42             $itemtypedescriptions{$itemtypes[$i]->{'itemtype'}} = $itemtypes[$i]->{'description'};
43         } # for
44         
45         for (my $i = 0; $i < $branchcount; $i++) {
46             $branchnames{$branches[$i]->{'branchcode'}} = $branches[$i]->{'branchname'};
47         } # for
48
49         print $input->header;
50         print startpage();
51         print startmenu('acquisitions');
52
53         print << "EOF";
54 <font size="6"><em>$biblios[0]->{'title'}</em></font>
55 <p>
56 EOF
57
58         if ($error eq "nobarcode") {
59             print << "EOF";
60 <font size="5" color="red">You must give the item a barcode</font>
61 <p>
62 EOF
63         } elsif ($error eq "nobiblioitem") {
64             print << "EOF";
65 <font size="5" color="red">You must create a new group for your item to be added to</font>
66 <p>
67 EOF
68         } elsif ($error eq "barcodeinuse") {
69             print << "EOF";
70 <font size="5" color="red">Sorry, that barcode is already in use</font>
71 <p>
72 EOF
73         } # elsif
74         print << "EOF";
75 <table align="left" cellpadding="5" cellspacing="0" border="1" width="220">
76 <tr valign="top" bgcolor="#CCCC99">
77 <td background="/images/background-mem.gif"><b>BIBLIO RECORD $biblionumber</b></td>
78 </tr>
79 <tr valign="top">
80 <td><b>Author:</b> $biblios[0]->{'author'}<br>
81 <b>Copyright:</b> $biblios[0]->{'copyrightdate'}<br>
82 <b>Series Title:</b> $biblios[0]->{'seriestitle'}<br>
83 <b>Notes:</b> $biblios[0]->{'notes'}</td>
84 </tr>
85 EOF
86
87         for (my $i = 0; $i < $biblioitemcount; $i++) {
88             if ($biblioitems[$i]->{'itemtype'} eq "WEB") {
89                 
90                 print << "EOF";
91 <tr valign="top" bgcolor="#CCCC99">
92 <td background="/images/background-mem.gif"><b>$biblioitems[$i]->{'biblioitemnumber'} GROUP - $itemtypedescriptions{$biblioitems[$i]->{'itemtype'}}</b></td>
93 </tr>
94 <tr valign="top">
95 <td><b>URL:</b> $biblioitems[$i]->{'url'}<br>
96 <b>Date:</b> $biblioitems[$i]->{'publicationyear'}<br>
97 <b>Notes:</b> $biblioitems[$i]->{'notes'}</td>
98 </tr>
99 EOF
100
101             } else {
102                 $biblioitems[$i]->{'dewey'} =~ /(\d*\.\d\d)/;
103                 $biblioitems[$i]->{'dewey'} = $1;
104
105                 print << "EOF";
106 <tr valign="top" bgcolor="#CCCC99">
107 <td background="/images/background-mem.gif"><b>$biblioitems[$i]->{'biblioitemnumber'} GROUP - $itemtypedescriptions{$biblioitems[$i]->{'itemtype'}}</b></td>
108 </tr>
109 <tr valign="top">
110 <td><b>ISBN:</b> $biblioitems[$i]->{'isbn'}<br>
111 <b>Dewey:</b> $biblioitems[$i]->{'dewey'}<br>
112 <b>Publisher:</b> $biblioitems[$i]->{'publishercode'}<br>
113 <b>Place:</b> $biblioitems[$i]->{'place'}<br>
114 <b>Date:</b> $biblioitems[$i]->{'publicationyear'}</td>
115 </tr>
116 EOF
117
118                 ($itemcount, @items) = &getitemsbybiblioitem($biblioitems[$i]->{'biblioitemnumber'});
119
120                 for (my $j = 0; $j < $itemcount; $j++) {
121                     print << "EOF";
122 <tr valign="top" bgcolor="#FFFFCC">
123 <td><b>Item:</b> $items[$j]->{'barcode'}<br>
124 <b>Home Branch:</b> $branchnames{$items[$j]->{'homebranch'}}<br>
125 <b>Notes:</b> $items[$j]->{'itemnotes'}</td>
126 </tr>
127 EOF
128                 } # for
129             } # else
130         } # for
131
132         print << "EOF";
133 </table>
134 <img src="/images/holder.gif" width="16" height="650" align="left">
135
136 <center>
137
138 <form action="saveitem.pl" method="post">
139 <input type="hidden" name="biblionumber" value="$biblionumber">
140 <table border="1" cellspacing="0" cellpadding="5">
141 <tr valign="top" bgcolor="#CCCC99">
142 <td background="/images/background-mem.gif" colspan="2"><b>ADD NEW ITEM:</b><br>
143 <small><i>For a website add the group only</i></small></td>
144 </tr>
145 <tr valign="top">
146 <td>Item Barcode:</td>
147 <td><input type="text" name="barcode" size="40"></td>
148 </tr>
149 <tr valign="top">
150 <td>Branch:</td>
151 <td><select name="homebranch">
152 EOF
153
154         for (my $i = 0; $i < $branchcount; $i++) {
155             print << "EOF";
156 <option value="$branches[$i]->{'branchcode'}">$branches[$i]->{'branchname'}</option>
157 EOF
158         } # for
159
160         print << "EOF";
161 </select></td>
162 </tr>
163 <tr valign="top">
164 <td>Replacement Price:</td>
165 <td><input type="text" name="replacementprice" size="40"></td>
166 </tr>
167 <tr valign="top">
168 <td>Notes:</td>
169 <td><textarea name="itemnotes" cols="30" rows="6"></textarea></td>
170 </tr>
171 <tr valign="top" bgcolor="#CCCC99">
172 <td colspan="2" background="/images/background-mem.gif"><b>Add to existing group:</b></td>
173 </tr>
174 <tr valign="top">
175 <td>Group:</td>
176 <td><select name="biblioitemnumber">
177 EOF
178
179         for (my $i = 0; $i < $biblioitemcount; $i++) {
180             if ($biblioitems[$i]->{'itemtype'} ne "WEB") {
181                 print << "EOF";
182 <option value="$biblioitems[$i]->{'biblioitemnumber'}">$itemtypedescriptions{$biblioitems[$i]->{'itemtype'}}</option>
183 EOF
184             } # if
185         } # for
186
187         print << "EOF";
188 </select></td>
189 </tr>
190 <tr valign="top">
191 <td colspan="2" align="center"><input type="submit" name="existinggroup" value="Add New Item to Existing Group"></td>
192 </tr>
193 <tr valign="top" bgcolor="#CCCC99">
194 <td colspan="2" background="/images/background-mem.gif"><b>OR Add to a new Group:</b></td>
195 </tr>
196 <tr valign="top">
197 <td>Format:</td>
198 <td><select name="itemtype">
199 EOF
200
201         for (my $i = 0; $i < $itemtypecount; $i++) {
202             print << "EOF";
203 <option value="$itemtypes[$i]->{'itemtype'}">$itemtypes[$i]->{'description'}</option>
204 EOF
205         } # for
206
207         print << "EOF";
208 </select></td>
209 </tr>
210 <tr valign="top">
211 <td>ISBN:</td>
212 <td><input name="isbn" size="40"></td>
213 </tr>
214 <tr valign="top">
215 <td>Publisher:</td>
216 <td><input name="publishercode" size="40"></td>
217 </tr>
218 <tr valign="top">
219 <td>Publication Year:</td>
220 <td><input name="publicationyear" size="40"></td>
221 </tr>
222 <tr valign="top">
223 <td>Place of Publication:</td>
224 <td><input name="place" size="40"></td>
225 </tr>
226 <tr valign="top">
227 <td>Illustrator:</td>
228 <td><INPUT name="illus" size="40"></td>
229 </tr>
230 <tr valign="top">
231 <td>Additional Authors:<br><i>One Author per line</i></td>
232 <td><textarea name="additionalauthors" cols="30" rows="6"></textarea></td>
233 </tr>
234 <tr valign="top">
235 <td>Subject Headings:<br><i>One Subject per line</i></td>
236 <td><textarea name="subjectheadings" cols="30" rows="6"></textarea></td>
237 </tr>
238 <tr valign="top">
239 <td>Website URL:</td>
240 <td><INPUT name="url" size="40"></td>
241 </tr>
242 <tr valign="top">
243 <td>Dewey:</td>
244 <td><INPUT name="dewey" size="40"></td>
245 </tr>
246 <tr valign="top">
247 <td>Dewey Subclass:</td>
248 <td><input name="subclass" size="40"></td>
249 </tr>
250 <tr valign="top">
251 <td>ISSN:</td>
252 <td><input name="issn" size="40"></td>
253 </tr>
254 <tr valign="top">
255 <td>LCCN:</td>
256 <td><input name="lccn" size="40"</td>
257 </tr>
258 <tr valign="top">
259 <td>Volume:</td>
260 <td><input name="volume" size="40"></td>
261 </tr>
262 <tr valign="top">
263 <td>Number:</td>
264 <td><input name="number" size="40"></td>
265 </tr>
266 <tr valign="top">
267 <td>Volume Description:</td>
268 <td><input name="volumeddesc" size="40"></td>
269 </tr>
270 <tr valign="top">
271 <td>Pages:</td>
272 <td><input name="pages" size="40"></td>
273 </tr>
274 <tr valign="top">
275 <td>Size:</td>
276 <td><input name="size" size="40"></td>
277 </tr>
278 <tr valign="top">
279 <td>Notes:</td>
280 <td><textarea name="notes" cols="30" rows="6"></textarea></td>
281 </tr>
282 <tr valign="top">
283 <td colspan="2" align="center"><input type="submit" name="newgroup" value="Add New Item to New Group"></td>
284 </tr>
285 </table>
286
287 </form>
288 </center>
289 EOF
290
291         print endmenu('acquisitions');
292         print endpage();
293     } # if
294 } # if