[Koha] Instaling Koha -modifications upstream

colmcd at optusnet.com.au colmcd at optusnet.com.au
Sun Oct 1 19:54:47 NZDT 2006


Dear Koha Team

I sent am email a little while ago to a koha member I hope it go through. 

Either way it dosen't matter. I was installing koha on Debian Sarge in Papua New Guinea without an internet connection. After Downloading Marc::record I was having problems with Barcode Generation (labels) and barcode Autogeneration on a non marc database. I have written the code so that Barcodes will be autogenerated for NON marc users (actually it was really simple I guess that there are not many non marc users.). I have also written (actually still rewriting barcodesGenerator.pl to work with libpdf::report). Here is what I have written. Do not ask me to use Subversion or any other program I cannot I only get 1 hr of Dial up access per fourtnight if lucky. I cannot use any coding program. Also load modules goes straight to add biblio in Non Marc while In marc it goes to a search. I have redone this so that on both it goes to a search (why is it changed for non marc? We want to see if the book is on the records too). 

All in all now that Koha is running it is a nice program but the install is redicous. If barcodesGenerator will only work with API2:PDF> 0.377 you must either package the library with the program or make this explicit. I could only find this out by looking at user bug logs. Either way I have rewritten the module for libpdf:report. If you add a system preference to choose between libpdf :report or the old API2 then both should function together nicely.

Once my Library is compleated I will look at getting checkboxes for the Marc items when you want to use them. I think that this should help the marc configuration allot. If you have emailed me ill address those emails on a fourtnight after I have read them. Please provide feedback on if this code is useful or if I am wasting my time. 

Cheers\

Colin




-------------- next part --------------
#!/usr/bin/perl

# script to generate items barcodes
# written 07/04
# by Veleda Matias - matias_veleda at hotmail.com - Physics Library UNLP Argentina and
#    Castañeda Sebastian - seba3c at yahoo.com.ar - Physics Library UNLP Argentina and
#	Colin McDermott colmcd at optusnet.com.au - head teacher mercy Secondary High School Yarapos Papua New Guinea and

# This file might be part of Koha soon, and is under it's license.
#
# Koha is free software; you can redistribute it and/or modify it under the
# terms of the GNU General Public License as published by the Free Software
# Foundation; either version 2 of the License, or (at your option) any later
# version.
#
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along with
# Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
# Suite 330, Boston, MA  02111-1307 USA

require Exporter;

use strict;

use CGI;
use C4::Context;
use C4::Output;
use HTML::Template;
use PDF::API2;
use PDF::API2::Page;
use PDF::API2::PDF::Utils;
use C4::Barcodes::PrinterConfig;
use Time::localtime; 
use PDF::Report;


# This function returns the path to deal with the correct files, considering
# templates set and language.
sub getPath {
	my $type = shift @_;
	my $templatesSet = C4::Context->preference('template');
	my $lang = C4::Context->preference('opaclanguages');
	if ($type eq "intranet") {
		return "$ENV{'DOCUMENT_ROOT'}/intranet-tmpl/$templatesSet/$lang";
	} else {
		return "$ENV{'DOCUMENT_ROOT'}/opac-tmpl/$templatesSet/$lang";
	}
}

# Load a configuration file. Before use this function, check if that file exists.
sub loadConfFromFile {
  my $fileName = shift @_;
	my %keyValues;
	open FILE, "<$fileName";
	while (<FILE>) {
		chomp;
		if (/\s*([\w_]*)\s*=\s*([\[\]\<\>\w_\s:@,\.-]*)\s*/) {
			$keyValues{$1} = $2;
		}
	}
	close FILE;
	return %keyValues;
}

# Save settings to a configuration file. It delete previous configuration settings.
sub saveConfToFile {
	my $fileName = shift @_;
	my %keyValues = %{shift @_};
	my $i;
	open FILE, ">$fileName";			
	my $i;
	foreach $i (keys(%keyValues)) {
    print FILE $i." = ".$keyValues{$i}."\n";
	}
	close FILE;
}

# Load the config file.
my $filenameConf = &getPath("intranet")."/includes/labelConfig/itemsLabelConfig.conf";
my %labelConfig = &loadConfFromFile($filenameConf);

# Creates a CGI object and take its parameters
my $cgi = new CGI;
my $from = $cgi->param('from');
my $to = $cgi->param('to');
my $individualCodes = $cgi->param('individualCodes');
my $rangeType = $cgi->param('rangeType');
my $pageType = $cgi->param('pages');
my $label = $cgi->param('label');
my $numbersystem = $cgi->param('numbersystem');
my $text_under_label = $cgi->param('text_under_label');

# Generate the checksum from an inventary code
sub checksum {

  sub calculateDigit {
    my $code = shift @_;
    my $sum = 0;
	  my $odd_parity = 1;
    my $i;
    for ($i = length($code) - 1; $i >= 0; $i--){
	   if ( $odd_parity ) {
		  $sum = $sum + ( 3 * substr($code, $i, 1) );
     } else {
			$sum = $sum + substr($code, $i, 1); }
		  $odd_parity = !$odd_parity;
	   }
    my $check_digit = 10 - ($sum%10);
	if ($check_digit==10) {
		$check_digit=0;
	}
	  return $code.$check_digit;
  }

  my $currentCode = shift @_;
  $currentCode = &calculateDigit($currentCode);
  return $currentCode;
}

# Assigns a temporary name to the PDF file
sub assingFilename {
	my ($from, $to) = @_;
	my $ip = $cgi->remote_addr();
	my $random = int(rand(1000000));
    my $timeObj = localtime();
	my ($day, $month, $year, $hour, $min, $sec) = ($timeObj->mday,
												   $timeObj->mon + 1,
												   $timeObj->year + 1900,
  												   $timeObj->hour,
												   $timeObj->min,
												   $timeObj->sec);
	my $tmpFileName = $random.'-'.$ip.'-(From '.$from.' to '.$to.')-['.$day.'.'.$month.'.'.$year.']-['.$hour.':'.$min.':'.$sec.'].pdf';
	return $tmpFileName;
}

# Takes inventary codes from database and if they are between
# the interval specify by parameters, it generates the correspond barcodes
sub barcodesGenerator {
	my ($from, $to, $rangeType, $individualCodes,$text_under_label) = @_;
	# Returns a database handler
	my $dbh = C4::Context->dbh;
	# Create the query to database
	# Assigns a temporary filename for the pdf file
	my $tmpFileName = &assingFilename($from, $to);
	if ($rangeType eq 'continuous2') {
		# Set the temp directory for pdf´s files
		if (!defined($ENV{'TEMP'})) {
			$ENV{'TEMP'} = '/tmp/';
		}	
		$tmpFileName = $ENV{'TEMP'}.$tmpFileName;
		# Creates a PDF object
		my $pdf = PDF::API2->new(-file => $tmpFileName);
		# Set the positions where barcodes are going to be placed
		C4::Barcodes::PrinterConfig::setPositionsForX($labelConfig{'marginLeft'}, $labelConfig{'labelWidth'}, $labelConfig{'columns'}, $labelConfig{'pageType'});
		C4::Barcodes::PrinterConfig::setPositionsForY($labelConfig{'marginBottom'}, $labelConfig{'labelHeigth'}, $labelConfig{'rows'}, $labelConfig{'pageType'});
		# Creates a font object
		my $tr = $pdf->corefont('Helvetica-Bold');
		# Barcode position
		my ($page, $gfx, $text);
		for (my $code=$from; $code<=$to; $code++) {
			# Generetase checksum
			my $codeC = &checksum($code);
			# Generate the corresponde barcode to $code
			my $barcode = $pdf->barcode(-font => $tr,	# The font object to use
										-type => 'ean128',	# Standard of codification
										-code => $codeC, # Text to codify
										-extn	=> '012345',	# Barcode extension (if it is aplicable)
										-umzn => 10,		# Top limit of the finished bar
										-lmzn => 10,		# Bottom limit of the finished bar
										-zone => 15,		# Bars size
										-quzn => 0,		# Space destinated for legend
										-ofwt => 0.01,	# Bars width
										-fnsz => 8,		# Font size
										-text => ''
										);
			
			(my $x, my $y, $pdf, $page, $gfx, $text, $tr, $label) = C4::Barcodes::PrinterConfig::getLabelPosition(
																						$label, 
																						$pdf, 
																						$page,
																						$gfx,
																						$text,
																						$tr,
																						$pageType);	
			# Assigns a barcodes to $gfx
			$gfx->barcode($barcode, $x, $y , (72/$labelConfig{'systemDpi'}));
			# Assigns the additional information to the barcode (Legend)
			$text->translate($x - 48, $y - 22);
			if ($text_under_label) {
				$text->text($text_under_label);
			}
		}
		# Writes the objects added in $gfx to $page
		$pdf->finishobjects($page,$gfx, $text);
		# Save changes to the PDF
		$pdf->saveas;
		# Close the conection with the PDF file
		$pdf->end;
		# Show the PDF file
		print $cgi->redirect("/cgi-bin/koha/barcodes/pdfViewer.pl?tmpFileName=$tmpFileName");
	} else {
		my $rangeCondition;
		if ($individualCodes ne "") {
			$rangeCondition = "AND (I.barcode IN " . $individualCodes . ")";
		} else {
			$rangeCondition =  "AND (I.barcode >= " . $from . " AND I.barcode <="  . $to . " )";
		}
			
		my $query = "SELECT CONCAT('$numbersystem',REPEAT('0',((12 - LENGTH('$numbersystem')) - LENGTH(I.barcode))), I.barcode) AS Codigo, B.title, B.author FROM biblio B, items I WHERE (I.biblionumber = B.biblioNumber ) " .$rangeCondition. " AND (I.barcode <> 'FALTA') ORDER BY Codigo";
		
		# Prepare the query
		my $sth = $dbh->prepare($query);
		# Executes the query
		$sth->execute;
		if ($sth->rows) { # There are inventary codes
			# Set the temp directory for pdf´s files
			if (!defined($ENV{'TEMP'})) {
				$ENV{'TEMP'} = '/tmp/';
			}	
			# Assigns a temporary filename for the pdf file
			my $tmpFileName = &assingFilename($from, $to);
			$tmpFileName = $ENV{'TEMP'}.$tmpFileName;
			# Creates a PDF object
			my $pdf = PDF::API2->new(-file => $tmpFileName);
			# Set the positions where barcodes are going to be placed
			C4::Barcodes::PrinterConfig::setPositionsForX($labelConfig{'marginLeft'}, $labelConfig{'labelWidth'}, $labelConfig{'columns'}, $labelConfig{'pageType'});
			C4::Barcodes::PrinterConfig::setPositionsForY($labelConfig{'marginBottom'}, $labelConfig{'labelHeigth'}, $labelConfig{'rows'}, $labelConfig{'pageType'});
			# Creates a font object
			my $tr = $pdf->corefont('Helvetica-Bold');
			# Barcode position
			my ($page, $gfx, $text);
			while (my ($code,$title,$author) = $sth->fetchrow_array) {
				# Generetase checksum
				$code = &checksum($code);
				# Generate the corresponde barcode to $code
				my $barcode = $pdf->barcode(-font => $tr,	# The font object to use
											-type => 'ean13',	# Standard of codification
											-code => $code, # Text to codify
											-extn	=> '012345',	# Barcode extension (if it is aplicable)
											-umzn => 10,		# Top limit of the finished bar
											-lmzn => 10,		# Bottom limit of the finished bar
											-zone => 15,		# Bars size
											-quzn => 0,		# Space destinated for legend
											-ofwt => 0.01,	# Bars width
											-fnsz => 8,		# Font size
											-text => ''
											);
				
				(my $x, my $y, $pdf, $page, $gfx, $text, $tr, $label) = C4::Barcodes::PrinterConfig::getLabelPosition(
																							$label, 
																							$pdf, 
																							$page,
																							$gfx,
																							$text,
																							$tr,
																							$pageType);	
				# Assigns a barcodes to $gfx
				$gfx->barcode($barcode, $x, $y , (72/$labelConfig{'systemDpi'}));
				# Assigns the additional information to the barcode (Legend)
				$text->translate($x - 48, $y - 22);
				if ($text_under_label) {
					$text->text($text_under_label);
				} else {
					$text->text(substr $title, 0, 30);
					$text->translate($x - 48, $y - 29);
					$text->text(substr $author, 0, 30);
				}
			}
			# Writes the objects added in $gfx to $page
			$pdf->finishobjects($page,$gfx, $text);
			# Save changes to the PDF
			$pdf->saveas;
			# Close the conection with the PDF file
			$pdf->end;
			# Show the PDF file
			print $cgi->redirect("/cgi-bin/koha/barcodes/pdfViewer.pl?tmpFileName=$tmpFileName");
		} else {
			# Rollback and shows the error legend
			print $cgi->redirect("/cgi-bin/koha/barcodes/barcodes.pl?error=1");
		}
	$sth->finish;
	}
}

sub barcodeReport {
my ($from, $to, $rangeType, $individualCodes,$text_under_label) = @_;
	# Returns a database handler
	my $dbh = C4::Context->dbh;
	# Create the query to database
my $page = $labelConfig{'pageType'};
my $orientation = 'portrait';
my $pdf = new PDF::Report(
                          PageSize => $page,
                          PageOrientation => $orientation,
                          undef => undef
                         );

$pdf->newpage(1);
$pdf->setFont('Helvetica-bold');
$pdf->setSize(16);
my ($width, $height) = $pdf->getPageDimensions();

$pdf->centerString(0, $width, $height-40, "Barcodes");
my $tmpFileName = &assingFilename($from, $to);
my $x = $width/3;
my $y = $height-150; 
my $z=0;
my $w;

# types and codes need to be here

$pdf->setFont('Helvetica');
$pdf->setSize(10);

my $next_line = 120;
my $p=0;
my @codes;
my @titles;
my $ext = " ";
my $types = 'ean13';
if ($rangeType eq 'continuous'){
for (my $code=$from; $code<=$to; $code++) {
	# Generetase checksum
	my $codeC = &checksum($code);
	$codes[$p] = $codeC;
	$p++;
}
$w=$labelConfig{'marginLeft'};
#print the first barcode
$pdf->centerString(0, ($w+$labelConfig{'labelWidth'}), $y+85, $rangeType);#4th is message above bcode $width now $w
$pdf->drawBarcode($w,$y, 1, 1, $types, $codes[0], $ext, 10, 10, 50, 10, ' ', undef, 8, undef); #' '(4th last)
$ext = " ";
foreach my $nbr (1 .. $#codes) {
	
	if ($z<$labelConfig{'columns'}){
		$w+= $width/$labelConfig{'columns'}; #positions labels.
		$z++;
		}
		else{
		$y-=$next_line;
		$w=$labelConfig{'marginLeft'};
		$z=0;
		}
	if ($y < 50) {
	$pdf->newpage(1);
	$y = $height - 150;
	} # makes a new page
	$pdf->centerString(0, ($w+$labelConfig{'labelWidth'}), $y+85, $codes[$nbr]);#4th is message above bcode $width now $w
	$pdf->drawBarcode($w,$y, 1, 1, $types, $codes[$nbr], $ext, 10, 10, 50, 10, ' ', undef, 8, undef); #' '(4th last)
	$ext = " ";
}
	
#my @types = qw(3of9 code128 ean13 codabar 2of5int);

#my @codes = qw(010203045678909 ABCDEFabcdef012345 010203045678909 
#               384318530034967067 384318530034967067);
} # end if continious
else {
	my $rangeCondition;
	if ($individualCodes ne "") {
		$rangeCondition = "AND (I.barcode IN " . $individualCodes . ")";
	} else {
		$rangeCondition =  "AND (I.barcode >= " . $from . " AND I.barcode <="  . $to . " )";
	}
	my $query = "SELECT I.barcode AS Codigo, B.title, B.author FROM biblio B, items I WHERE (I.biblionumber = B.biblioNumber ) " .$rangeCondition. " AND (I.barcode <> 'FALTA') ORDER BY Codigo";		
# original query which returned country code. 
#	my $query = "SELECT CONCAT('$numbersystem',REPEAT('0',((12 - LENGTH('$numbersystem')) - LENGTH(I.barcode))), I.barcode) AS Codigo, B.title, B.author FROM biblio B, items I WHERE (I.biblionumber = B.biblioNumber ) " .$rangeCondition. " AND (I.barcode <> 'FALTA') ORDER BY Codigo";
# Prepare the query
	my $sth = $dbh->prepare($query);
	# Executes the query
	$sth->execute;
	if ($sth->rows) { # There are inventary codes
	# Set the temp directory for pdf´s files
	if (!defined($ENV{'TEMP'})) {
		$ENV{'TEMP'} = '/tmp/';
	}	
	# Assigns a temporary filename for the pdf file
	my $tmpFileName = &assingFilename($from, $to);
	$tmpFileName = $ENV{'TEMP'}.$tmpFileName;
	while (my ($code,$title,$author) = $sth->fetchrow_array) {
	my $codeC = &checksum($code);
	$codes[$p] = $codeC;
	$titles[$p] = $title;
	$p++;
	} #while
$w=$labelConfig{'marginLeft'};
#print the first barcode
$pdf->centerString(0, ($w+$labelConfig{'labelWidth'}), $y+85, $rangeType);#4th is message above bcode $width now $w
$pdf->drawBarcode($w,$y, 1, 1, $types, $codes[0], $ext, 10, 10, 50, 10, ' ', undef, 8, undef); #' '(4th last)
$ext = " ";
foreach my $nbr (1 .. $#codes) {
	
	if ($z<$labelConfig{'columns'}){
		$w+= $width/$labelConfig{'columns'}; #positions labels.
		$z++;
		}
		else{
		$y-=$next_line;
		$w=$labelConfig{'marginLeft'};
		$z=0;
		}
	if ($y < 50) {
	$pdf->newpage(1);
	$y = $height - 150;
	} # makes a new page
	$pdf->centerString(0, ($w*$labelConfig{'marginLeft'}+$labelConfig{'labelWidth'}), $y+85, $titles[$nbr]);#4th is message above bcode $width now $w
	$pdf->drawBarcode($w,$y, 1, 1, $types, $codes[$nbr], $ext, 10, 10, 50, 10, ' ', undef, 8, undef); #' '(4th last)
	$ext = " ";
	} #foreach
	} #if rows
	else {
			# Rollback and shows the error legend
			print $cgi->redirect("/cgi-bin/koha/barcodes/barcodes.pl?error=1");
		}
	$sth->finish;
} #else if continious

open(PDF, "> $tmpFileName") or die "Error opening $0.pdf: $!\n";
print PDF $pdf->Finish();
close(PDF);
print $cgi->redirect("/cgi-bin/koha/barcodes/pdfViewer.pl?tmpFileName=$tmpFileName");

}


barcodeReport($from, $to, $rangeType, $individualCodes, $text_under_label);
#barcodesGenerator($from, $to, $rangeType, $individualCodes,$text_under_label);

#C4::Barcodes::PrinterConfig::setPositionsForX($labelConfig{'marginLeft'}, $labelConfig{'labelWidth'}, $labelConfig{'columns'}, $labelConfig{'pageType'});
#			C4::Barcodes::PrinterConfig::setPositionsForY($labelConfig{'marginBottom'}, $labelConfig{'labelHeigth'}, $labelConfig{'rows'}, $labelConfig{'pageType'});
#labelConfig{'pageType'} returns the page type a4 letter, etc. 
#labelConfig{'marginLeft'} No it returns 2
#labelConfig{'culumns'}
#labelConfig{'labelWidth'}

#=item $pdf->drawBarcode($x, $y, $scale, $frame, $type, $code, $extn, $umzn, 
#                        $lmzn, $zone, $quzn, $spcr, $ofwt, $fnsz, $text);

#This is really not that complicated, trust me! ;) I am pretty unfamiliar with 
#barcode lingo and types so if I get any of this wrong, lemme know! 
#This is a very flexible way to draw a barcode on your PDF document.  
#$x and $y represent the center of the barcode's position on the document.  
#$scale is the size of the entire barcode 1 being 1:1, which is all you'll 
#need most likely.  $type is the type of barcode which can be codabar, 2of5int, 
#3of9, code128, or ean13.  $code is the alpha-numeric code which the barcode 
#will represent.  $extn is the 
#extension to the $code, where applicable.  $umzn is the upper mending zone and 
#$lmzn is the lower mending zone. $zone is the the zone or height of the bars. 
#$quzn is the quiet zone or the space between the frame and the barcode.  $spcr
#is what to put between each number/character in the text.  $ofwt is the 
#overflow width.  $fnsz is the fontsize used for the text.  $text is optional 
#text beneathe the barcode. 

#=cut

-------------- next part --------------
problem autogenerating barcodes in nomarc settings -> fixed additem-nomarc.pl additem-nomarc.tmpl
problem going straight to add item screen instead of going to addbooks.pl
Problem not printing Barcodes Need PDF::ACIP version w
<quote>what verdion of PDF::API2 are you using?  Version 0.3r77 is required
(later versions will not work).</quote>
Why isn't this in the Debian install Guide? This is near impossible to find! I guess this begs a future compatibility question, but I think the thing that bothers me most is this. With so many perl libraries used by koha and with so many different people
working on those library's how is Koha going to be stable and easy to install in the future? If i download the latest Perl modules and they won't work. I also use the last debian modules and they don't work? then how am I going to know which modules to download! Even more then that if someone here in the future tries to upgrade Koha which modules will they need. The old perl modules the perl modules in Debian (which surprisingly are not the old modules) or the New perl Modules from the perl repository? If someone has no linux knowledge then the above becomes a very complicated if not impossible task. 

Look koha looks great and seems to be able to do all I want (except print barcodes though I am downloading 0.3r77 atm). But it's installation process has to get allot easier then this! I should be able to follow instructions on the prompt and have koha up and working near bug free. Instead I get something that is rather buggy and looking almost like alpha ware. It should not be like this. I honestly think that what you need to do is package all the necessary perl modules and their versions into a big tar file and have that as an optional extra download. Include with it an extraction script. That way we have the Koha and the perl mods we need. Either way we need a better solution for installation. It is a nightmare. 

-------------- next part --------------
#!/usr/bin/perl
use lib "/usr/local/koha/intranet/modules";

#script to show list of budgets and bookfunds
#written 4/2/00 by chris at katipo.co.nz
#called as an include by the acquisitions index page


# Copyright 2000-2002 Katipo Communications
#
# This file is part of Koha.
#
# Koha is free software; you can redistribute it and/or modify it under the
# terms of the GNU General Public License as published by the Free Software
# Foundation; either version 2 of the License, or (at your option) any later
# version.
#
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along with
# Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
# Suite 330, Boston, MA  02111-1307 USA

use C4::Context;
use CGI;
my $input=new CGI;

my $module=$input->param('module');

SWITCH: {
	if ($module eq 'acquisitions') { acquisitions(); last SWITCH; }
	if ($module eq 'search') { catalogue_search(); last SWITCH; }
	if ($module eq 'addbiblio') {addbiblio(); last SWITCH;}
	if ($module eq 'somethingelse') { somethingelse(); last SWITCH; }
}

sub acquisitions {
	my $aq_type = $input->param('acquisitions');
	$aq_type = C4::Context->preference("acquisitions") || "normal" unless $aq_type;
	my $marc_bool =$input->param('MARC');
	$marc_bool = C4::Context->boolean_preference('marc') || 0 unless $marc_bool;
	# Get the acquisition preference. This should be:
	#       "simple" - minimal information required
	#       "normal" - full information required
	#       other - Same as "normal"

	if ($aq_type eq 'simple') {
			print $input->redirect("/cgi-bin/koha/acqui.simple/addbooks.pl");
	} else {
		print $input ->redirect("/cgi-bin/koha/acqui/acqui-home.pl");
	}
}

sub addbiblio {
	my $marc_bool = C4::Context->boolean_preference("MARC") || 0;
		if ($marc_bool eq "1") {
			print $input->redirect("/cgi-bin/koha/acqui.simple/addbooks.pl");
		} else {
			#i am changing this
			#print $input->redirect("/cgi-bin/koha/acqui.simple/addbiblio-nomarc.pl");
			#to this
			 print $input->redirect("/cgi-bin/koha/acqui.simple/addbooks.pl");
		}
}

sub catalogue_search {
	my $marc_p = $input->param('marc');
	$marc_p = C4::Context->boolean_preference('marc') unless defined $marc_p;
	$marc_p = 'ON' unless defined $marc_p;
	my $keyword=$input->param('keyword');
	my $query = new CGI;
	my $type = $query->param('type');
# 	if ($keyword) {
# 		if ($marc_p) {
# 			print $input->redirect("/cgi-bin/koha/search.marc/search.pl?type=$type");
# 		} else {
# 			print $input ->redirect("/cgi-bin/koha/search.pl?keyword=$keyword");
# 		}
# 	} else {
# 		if ($marc_p) {
			print $input->redirect("/cgi-bin/koha/search.marc/search.pl?type=$type");
# 		} else {
# 			print $input ->redirect("/cgi-bin/koha/catalogue-home.pl");
# 		}
# 	}
}

sub somethingelse {
# just an example subroutine
}
-------------- next part --------------
#!/usr/bin/perl
use lib "/usr/local/koha/intranet/modules";

# $Id: additem-nomarc.pl,v 1.4.2.1 2005/03/25 12:52:44 tipaul Exp $

# Copyright 2000-2002 Katipo Communications
#
# This file is part of Koha.
#
# Koha is free software; you can redistribute it and/or modify it under the
# terms of the GNU General Public License as published by the Free Software
# Foundation; either version 2 of the License, or (at your option) any later
# version.
#
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along with
# Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
# Suite 330, Boston, MA  02111-1307 USA

# $Log: additem-nomarc.pl,v $
# Revision 1.4.2.1  2005/03/25 12:52:44  tipaul
# needs "editcatalogue" flag, not "catalogue"
#
# Revision 1.4  2004/11/19 16:41:49  tipaul
# improving behaviour when MARC=OFF
#
# Revision 1.3  2004/08/13 16:37:25  tipaul
# adding frameworkcode to API in some subs
#
# Revision 1.2  2003/05/11 06:59:11  rangi
# Mostly templated.
# Still needs some work
#

use CGI;
use strict;
use C4::Acquisition;
use C4::Biblio;
use C4::Output;
use HTML::Template;
use C4::Auth;
use C4::Interface::CGI::Output;
use C4::Context; #addition



my $input        = new CGI;
my $biblionumber = $input->param('biblionumber');
my $error        = $input->param('error');
my $maxbarcode;
my $isbn;
my $bibliocount;
my @biblios;
my $biblioitemcount;
my @biblioitems;
my $branchcount;
my @branches;
my %branchnames;
my $itemcount;
my @items;
my $itemtypecount;
my @itemtypes;
my %itemtypedescriptions;
my $dbh = C4::Context->dbh;
my $newcode;


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');
        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   => { editcatalogue => 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
	#lets see if Autobarcode is on
	        if (C4::Context->preference('autoBarcode')) {
		#add a barcode
		my $sth_barcode = $dbh->prepare("select max(abs(barcode)) from items");
		$sth_barcode->execute;
		my ($newbarcode) = $sth_barcode->fetchrow;
		$newbarcode++;
		$newcode=$newbarcode;
											  
		}
	
        $template->param(
            BIBNUM    => $biblionumber,
            AUTHOR    => $biblios[0]->{'author'},
            TITLE     => $biblios[0]->{'title'},
            COPYRIGHT => $biblios[0]->{'copyrightdate'},
            SERIES    => $biblios[0]->{'seriestitle'},
            NOTES     => $biblios[0]->{'notes'},
	    BIBABAR => $newcode,
            BIBITEMS  => \@biblioitems,
            BRANCHES  => \@branches,
            ITEMTYPES => \@itemtypes,

        );

        output_html_with_http_headers $input, $cookie, $template->output;
    }    # if
}    # if
-------------- next part --------------
<!-- TMPL_INCLUDE NAME="cat-top.inc" -->
<div id="mainbloc">
		<h1 class="catalogue"><!-- TMPL_VAR NAME="TITLE" --></h1>
	<div id="bloc25">
		<p>
		<!-- TMPL_IF NAME="NOBARCODE" -->
			<p class="problem">You must give the item a barcode</p>
		<!-- /TMPL_IF -->
		<!-- TMPL_IF NAME="NOBIBLIOITEM" -->
			<p class="problem">You must create a new group for your item to be added to</p>
		<!-- /TMPL_IF -->
		<!-- TMPL_IF NAME="BARCODEINUSE" -->
			<p class="problem">Sorry, that barcode is already in use</p>
		<!-- /TMPL_IF -->
		<h2 class="catalogue">BIBLIO RECORD <!-- TMPL_VAR NAME="BIBNUM" --></h2>
		<p><label class="label100">Author:</label> <!-- TMPL_VAR NAME="AUTHOR" --></p>
		<p><label class="label100">Copyright:</label> <!-- TMPL_VAR NAME="COPYRIGHT" --></p>
		<p><label class="label100">Series Title:</label> <!-- TMPL_VAR NAME="SERIES" --></p>
		<p><label class="label100">Notes:</label> <!-- TMPL_VAR NAME="NOTES" --></p>
		<!-- TMPL_LOOP NAME="BIBITEMS" -->
			<!-- TMPL_IF NAME="WEB" -->
				<h2 class="catalogue"><!-- TMPL_VAR NAME="biblioitemnumber" --> GROUP - <!-- TMPL_VAR NAME="itemtype" --></h2>
				<p><label>URL:</label><!-- TMPL_VAR NAME="url" --></p>
				<p><label>Date:</label> <!-- TMPL_VAR NAME="publicationyear" --></p>
				<p><label>Notes:</label> <!-- TMPL_VAR NAME="notes" --></p>
			<!-- TMPL_ELSE -->
				<h2 class="catalogue"><!-- TMPL_VAR NAME="biblioitemnumber" --> GROUP - <!-- TMPL_VAR NAME="itemtype" --></h2>
				<p><label>ISBN:</label> <!-- TMPL_VAR NAME="isbn" --></p>
				<p><label>Dewey:</label> <!-- TMPL_VAR NAME="dewey" --></p>
				<p><label>Publisher:</label> <!-- TMPL_VAR NAME="publishercode" --></p>
				<p><label>Place:</label> <!-- TMPL_VAR NAME="place" --></p>
				<p><label>Date:</label> <!-- TMPL_VAR NAME="publicationyear" --></p>
				<!-- TMPL_LOOP NAME="ITEMS -->
					<p><label class="label100">Item:</label> <!-- TMPL_VAR NAME="barcode" --></p>
					<p><label class="label100">Home Branch:</label> <!-- TMPL_VAR NAME="homebranch" --></p>
					<p><label class="label100">Notes:</label> <!-- TMPL_VAR NAME="itemnotes" --></p>
				<!-- /TMPL_LOOP -->
			<!-- /TMPL_IF -->
		<!-- /TMPL_LOOP -->
	</div>
	<div id="bloc25">
		<form action="saveitem.pl" method="post">
		<input type="hidden" name="biblionumber" value="<!-- TMPL_VAR NAME="BIBNUM" -->">
		<h2 class="catalogue">ADD NEW ITEM:</h2>
		<p><i>For a website add the group only</i></p>
		<p><label>Item Barcode:</label><input type="text" name="barcode" value="<!-- TMPL_VAR NAME="BIBABAR" -->" size="40"></p>
		<p>
			<label>Branch:</label>
			<select name="homebranch">
			<!-- TMPL_LOOP NAME="BRANCHES" -->
				<option value="<!-- TMPL_VAR NAME="branchcode" -->"><!-- TMPL_VAR NAME="branchname" --></option>
			<!-- /TMPL_LOOP -->
			</select>
		</p>
		<p><label>Replacement Price:</label><input type="text" name="replacementprice" size="40"></p>
		<p><label>Notes:</label><textarea name="itemnotes" cols="30" rows="6"></textarea></p>
	</div>
	<div id="bloc25">
		<h2 class="catalogue">Add to existing group:</h2>
		<p>
			<label>Group:</label><select name="biblioitemnumber">
			<!-- TMPL_LOOP NAME="BIBITEMS" -->
				<!-- TMPL_IF NAME="WEB" -->
				<!-- TMPL_ELSE -->
					<option value="<!-- TMPL_VAR NAME="biblioitemnumber" -->"><!-- TMPL_VAR NAME="itemtype" --></option>
				<!-- /TMPL_IF -->
			<!-- /TMPL_LOOP -->
			</select>
		</p>
		<p><input type="submit" name="existinggroup" value="Add New Item to Existing Group"></p>
	</div>
	<div id="bloc25">
		<h2 class="catalogue">OR Add to a new Group:</h2>
		<p>
			<label>Format:</label>
			<select name="itemtype">
				<!-- TMPL_LOOP NAME="ITEMTYPES" -->
					<option value="<!-- TMPL_VAR NAME="itemtype" -->"><!-- TMPL_VAR NAME="description" --></option>
				<!-- /TMPL_LOOP -->
			</select>
		</p>
		<p><label>ISBN:</label><input name="isbn" size="40"></p>
		<p><label>Publisher:</label><input name="publishercode" size="40"></p>
		<p><label>Publication Year:</label><input name="publicationyear" size="40"></p>
		<p><label>Place of Publication:</label><input name="place" size="40"></p>
		<p><label>Illustrator:</label><input name="illus" size="40"></p>
		<p><label>Website URL:</label><input name="url" size="40"></p>
		<p><label>Dewey:</label><input name="dewey" size="40"></p>
		<p><label>Dewey Subclass:</label><input name="subclass" size="40"></p>
		<p><label>ISSN:</label><input name="issn" size="40"></p>
		<p><label>LCCN:</label><input name="lccn" size="40"></p>
		<p><label>Volume:</label><input name="volume" size="40"></p>
		<p><label>Number:</label><input name="number" size="40"></p>
		<p><label>Volume Description:</label><input name="volumeddesc" size="40"></p>
		<p><label>Pages:</label><input name="pages" size="40"></p>
		<p><label>Size:</label><input name="size" size="40"></p>
		<p><label>Notes:</label><textarea name="notes" cols="30" rows="6"></textarea></p>
		<p><input type="submit" name="newgroup" value="Add New Item to New Group" class="button catalogue"></p>
		</form>
	</div>
</div>
<!-- TMPL_INCLUDE NAME="acquisitions-bottom.inc" -->


More information about the Koha mailing list