Mostly templated.
[koha_fer] / acqui.simple / additem-nomarc.pl
index 9bffa2d..5b8a0ab 100755 (executable)
 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
 # Suite 330, Boston, MA  02111-1307 USA
 
+# $Log$
+# Revision 1.2  2003/05/11 06:59:11  rangi
+# Mostly templated.
+# Still needs some work
+#
+
 use CGI;
 use strict;
 use C4::Catalogue;
 use C4::Biblio;
 use C4::Output;
+use HTML::Template;
+use C4::Auth;
+use C4::Interface::CGI::Output;
 
-my $input = new CGI;
+my $input        = new CGI;
 my $biblionumber = $input->param('biblionumber');
 my $error        = $input->param('error');
 my $maxbarcode;
@@ -43,271 +52,82 @@ my $itemtypecount;
 my @itemtypes;
 my %itemtypedescriptions;
 
-if (! $biblionumber) {
+if ( !$biblionumber ) {
     print $input->redirect('addbooks.pl');
-} else {
-
-    ($bibliocount, @biblios)  = &getbiblio($biblionumber);
-
-    if (! $bibliocount) {
-       print $input->redirect('addbooks.pl');
-    } else {
-
-       ($biblioitemcount, @biblioitems) = &getbiblioitembybiblionumber($biblionumber);
-        ($branchcount, @branches)        = &branches;
-       ($itemtypecount, @itemtypes)     = &getitemtypes;
-
-       for (my $i = 0; $i < $itemtypecount; $i++) {
-           $itemtypedescriptions{$itemtypes[$i]->{'itemtype'}} = $itemtypes[$i]->{'description'};
-       } # for
-
-       for (my $i = 0; $i < $branchcount; $i++) {
-           $branchnames{$branches[$i]->{'branchcode'}} = $branches[$i]->{'branchname'};
-       } # for
-
-       print $input->header;
-       print startpage();
-       print startmenu('acquisitions');
-
-       print << "EOF";
-<font size="6"><em>$biblios[0]->{'title'}</em></font>
-<p>
-EOF
-
-       if ($error eq "nobarcode") {
-           print << "EOF";
-<font size="5" color="red">You must give the item a barcode</font>
-<p>
-EOF
-       } elsif ($error eq "nobiblioitem") {
-           print << "EOF";
-<font size="5" color="red">You must create a new group for your item to be added to</font>
-<p>
-EOF
-       } elsif ($error eq "barcodeinuse") {
-           print << "EOF";
-<font size="5" color="red">Sorry, that barcode is already in use</font>
-<p>
-EOF
-       } # elsif
-       print << "EOF";
-<table align="left" cellpadding="5" cellspacing="0" border="1" width="220">
-<tr valign="top" bgcolor="#CCCC99">
-<td background="/images/background-mem.gif"><b>BIBLIO RECORD $biblionumber</b></td>
-</tr>
-<tr valign="top">
-<td><b>Author:</b> $biblios[0]->{'author'}<br>
-<b>Copyright:</b> $biblios[0]->{'copyrightdate'}<br>
-<b>Series Title:</b> $biblios[0]->{'seriestitle'}<br>
-<b>Notes:</b> $biblios[0]->{'notes'}</td>
-</tr>
-EOF
-
-       for (my $i = 0; $i < $biblioitemcount; $i++) {
-           if ($biblioitems[$i]->{'itemtype'} eq "WEB") {
-
-               print << "EOF";
-<tr valign="top" bgcolor="#CCCC99">
-<td background="/images/background-mem.gif"><b>$biblioitems[$i]->{'biblioitemnumber'} GROUP - $itemtypedescriptions{$biblioitems[$i]->{'itemtype'}}</b></td>
-</tr>
-<tr valign="top">
-<td><b>URL:</b> $biblioitems[$i]->{'url'}<br>
-<b>Date:</b> $biblioitems[$i]->{'publicationyear'}<br>
-<b>Notes:</b> $biblioitems[$i]->{'notes'}</td>
-</tr>
-EOF
-
-           } else {
-               $biblioitems[$i]->{'dewey'} =~ /(\d*\.\d\d)/;
-               $biblioitems[$i]->{'dewey'} = $1;
-
-               print << "EOF";
-<tr valign="top" bgcolor="#CCCC99">
-<td background="/images/background-mem.gif"><b>$biblioitems[$i]->{'biblioitemnumber'} GROUP - $itemtypedescriptions{$biblioitems[$i]->{'itemtype'}}</b></td>
-</tr>
-<tr valign="top">
-<td><b>ISBN:</b> $biblioitems[$i]->{'isbn'}<br>
-<b>Dewey:</b> $biblioitems[$i]->{'dewey'}<br>
-<b>Publisher:</b> $biblioitems[$i]->{'publishercode'}<br>
-<b>Place:</b> $biblioitems[$i]->{'place'}<br>
-<b>Date:</b> $biblioitems[$i]->{'publicationyear'}</td>
-</tr>
-EOF
-
-               ($itemcount, @items) = &getitemsbybiblioitem($biblioitems[$i]->{'biblioitemnumber'});
-
-               for (my $j = 0; $j < $itemcount; $j++) {
-                   print << "EOF";
-<tr valign="top" bgcolor="#FFFFCC">
-<td><b>Item:</b> $items[$j]->{'barcode'}<br>
-<b>Home Branch:</b> $branchnames{$items[$j]->{'homebranch'}}<br>
-<b>Notes:</b> $items[$j]->{'itemnotes'}</td>
-</tr>
-EOF
-               } # for
-           } # else
-       } # for
-
-       print << "EOF";
-</table>
-<img src="/images/holder.gif" width="16" height="650" align="left">
-
-<center>
-
-<form action="saveitem.pl" method="post">
-<input type="hidden" name="biblionumber" value="$biblionumber">
-<table border="1" cellspacing="0" cellpadding="5">
-<tr valign="top" bgcolor="#CCCC99">
-<td background="/images/background-mem.gif" colspan="2"><b>ADD NEW ITEM:</b><br>
-<small><i>For a website add the group only</i></small></td>
-</tr>
-<tr valign="top">
-<td>Item Barcode:</td>
-<td><input type="text" name="barcode" size="40"></td>
-</tr>
-<tr valign="top">
-<td>Branch:</td>
-<td><select name="homebranch">
-EOF
-
-       for (my $i = 0; $i < $branchcount; $i++) {
-           print << "EOF";
-<option value="$branches[$i]->{'branchcode'}">$branches[$i]->{'branchname'}</option>
-EOF
-       } # for
-
-       print << "EOF";
-</select></td>
-</tr>
-<tr valign="top">
-<td>Replacement Price:</td>
-<td><input type="text" name="replacementprice" size="40"></td>
-</tr>
-<tr valign="top">
-<td>Notes:</td>
-<td><textarea name="itemnotes" cols="30" rows="6"></textarea></td>
-</tr>
-<tr valign="top" bgcolor="#CCCC99">
-<td colspan="2" background="/images/background-mem.gif"><b>Add to existing group:</b></td>
-</tr>
-<tr valign="top">
-<td>Group:</td>
-<td><select name="biblioitemnumber">
-EOF
-
-       for (my $i = 0; $i < $biblioitemcount; $i++) {
-           if ($biblioitems[$i]->{'itemtype'} ne "WEB") {
-               print << "EOF";
-<option value="$biblioitems[$i]->{'biblioitemnumber'}">$itemtypedescriptions{$biblioitems[$i]->{'itemtype'}}</option>
-EOF
-           } # if
-       } # for
-
-       print << "EOF";
-</select></td>
-</tr>
-<tr valign="top">
-<td colspan="2" align="center"><input type="submit" name="existinggroup" value="Add New Item to Existing Group"></td>
-</tr>
-<tr valign="top" bgcolor="#CCCC99">
-<td colspan="2" background="/images/background-mem.gif"><b>OR Add to a new Group:</b></td>
-</tr>
-<tr valign="top">
-<td>Format:</td>
-<td><select name="itemtype">
-EOF
-
-       for (my $i = 0; $i < $itemtypecount; $i++) {
-           print << "EOF";
-<option value="$itemtypes[$i]->{'itemtype'}">$itemtypes[$i]->{'description'}</option>
-EOF
-       } # for
-
-       print << "EOF";
-</select></td>
-</tr>
-<tr valign="top">
-<td>ISBN:</td>
-<td><input name="isbn" size="40"></td>
-</tr>
-<tr valign="top">
-<td>Publisher:</td>
-<td><input name="publishercode" size="40"></td>
-</tr>
-<tr valign="top">
-<td>Publication Year:</td>
-<td><input name="publicationyear" size="40"></td>
-</tr>
-<tr valign="top">
-<td>Place of Publication:</td>
-<td><input name="place" size="40"></td>
-</tr>
-<tr valign="top">
-<td>Illustrator:</td>
-<td><INPUT name="illus" size="40"></td>
-</tr>
-<tr valign="top">
-<td>Additional Authors:<br><i>One Author per line</i></td>
-<td><textarea name="additionalauthors" cols="30" rows="6"></textarea></td>
-</tr>
-<tr valign="top">
-<td>Subject Headings:<br><i>One Subject per line</i></td>
-<td><textarea name="subjectheadings" cols="30" rows="6"></textarea></td>
-</tr>
-<tr valign="top">
-<td>Website URL:</td>
-<td><INPUT name="url" size="40"></td>
-</tr>
-<tr valign="top">
-<td>Dewey:</td>
-<td><INPUT name="dewey" size="40"></td>
-</tr>
-<tr valign="top">
-<td>Dewey Subclass:</td>
-<td><input name="subclass" size="40"></td>
-</tr>
-<tr valign="top">
-<td>ISSN:</td>
-<td><input name="issn" size="40"></td>
-</tr>
-<tr valign="top">
-<td>LCCN:</td>
-<td><input name="lccn" size="40"</td>
-</tr>
-<tr valign="top">
-<td>Volume:</td>
-<td><input name="volume" size="40"></td>
-</tr>
-<tr valign="top">
-<td>Number:</td>
-<td><input name="number" size="40"></td>
-</tr>
-<tr valign="top">
-<td>Volume Description:</td>
-<td><input name="volumeddesc" size="40"></td>
-</tr>
-<tr valign="top">
-<td>Pages:</td>
-<td><input name="pages" size="40"></td>
-</tr>
-<tr valign="top">
-<td>Size:</td>
-<td><input name="size" size="40"></td>
-</tr>
-<tr valign="top">
-<td>Notes:</td>
-<td><textarea name="notes" cols="30" rows="6"></textarea></td>
-</tr>
-<tr valign="top">
-<td colspan="2" align="center"><input type="submit" name="newgroup" value="Add New Item to New Group"></td>
-</tr>
-</table>
-
-</form>
-</center>
-EOF
-
-       print endmenu('acquisitions');
-       print endpage();
-    } # if
-} # if
+}
+else {
+
+    ( $bibliocount, @biblios ) = &getbiblio($biblionumber);
+
+    if ( !$bibliocount ) {
+        print $input->redirect('addbooks.pl');
+    }
+    else {
+
+        ( $biblioitemcount, @biblioitems ) =
+          &getbiblioitembybiblionumber($biblionumber);
+        ( $branchcount,   @branches )  = &branches;
+        ( $itemtypecount, @itemtypes ) = &getitemtypes;
+
+        for ( my $i = 0 ; $i < $itemtypecount ; $i++ ) {
+            $itemtypedescriptions{ $itemtypes[$i]->{'itemtype'} } =
+              $itemtypes[$i]->{'description'};
+        }    # for
+
+        for ( my $i = 0 ; $i < $branchcount ; $i++ ) {
+            $branchnames{ $branches[$i]->{'branchcode'} } =
+              $branches[$i]->{'branchname'};
+        }    # for
+
+        #      print $input->header;
+        #      print startpage();
+        #      print startmenu('acquisitions');
+        my $input = new CGI;
+        my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
+            {
+                template_name   => "acqui.simple/additem-nomarc.tmpl",
+                query           => $input,
+                type            => "intranet",
+                authnotrequired => 0,
+                flagsrequired   => { catalogue => 1 },
+                debug           => 1,
+            }
+        );
+
+        if ( $error eq "nobarcode" ) {
+            $template->param( NOBARCODE => 1 );
+        }
+        elsif ( $error eq "nobiblioitem" ) {
+            $template->param( NOBIBLIOITEM => 1 );
+        }
+        elsif ( $error eq "barcodeinuse" ) {
+            $template->param( BARCODEINUSE => 1 );
+        }    # elsif
+
+        for ( my $i = 0 ; $i < $biblioitemcount ; $i++ ) {
+            if ( $biblioitems[$i]->{'itemtype'} eq "WEB" ) {
+                $biblioitems[$i]->{'WEB'} = 1;
+
+            }
+            $biblioitems[$i]->{'dewey'} =~ /(\d*\.\d\d)/;
+            $biblioitems[$i]->{'dewey'} = $1;
+            ( $itemcount, @items ) =
+              &getitemsbybiblioitem( $biblioitems[$i]->{'biblioitemnumber'} );
+            $biblioitems[$i]->{'items'} = \@items;
+        }    # for
+        $template->param(
+            BIBNUM    => $biblionumber,
+            AUTHOR    => $biblios[0]->{'author'},
+            TITLE     => $biblios[0]->{'title'},
+            COPYRIGHT => $biblios[0]->{'copyrightdate'},
+            SERIES    => $biblios[0]->{'seriestitle'},
+            NOTES     => $biblios[0]->{'notes'},
+            BIBITEMS  => \@biblioitems,
+            BRANCHES  => \@branches,
+            ITEMTYPES => \@itemtypes,
+
+        );
+
+        output_html_with_http_headers $input, $cookie, $template->output;
+    }    # if
+}    # if