From 833e6bf5b68e8751f6692a93413b2a34763cf6ef Mon Sep 17 00:00:00 2001 From: hdl Date: Fri, 24 Feb 2006 11:52:38 +0000 Subject: [PATCH] Adding tools directory template and scripts Changing barcodes, export and import and letters directory. Changing export script name (marc.pl) to export.pl Changing import script name (breeding.pl) to import.pl --- .../intranet-tmpl/prog/en/tools/barcodes.tmpl | 80 ++++ .../intranet-tmpl/prog/en/tools/export.tmpl | 14 + .../intranet-tmpl/prog/en/tools/import.tmpl | 53 +++ .../intranet-tmpl/prog/en/tools/letter.tmpl | 287 ++++++++++++ .../prog/en/tools/printerConfig.tmpl | 83 ++++ tools/barcodes.pl | 143 ++++++ tools/barcodesGenerator.pl | 302 ++++++++++++ tools/export.pl | 109 +++++ tools/import.pl | 430 ++++++++++++++++++ tools/letter.pl | 229 ++++++++++ tools/pdfViewer.pl | 40 ++ tools/printerConfig.pl | 116 +++++ 12 files changed, 1886 insertions(+) create mode 100644 koha-tmpl/intranet-tmpl/prog/en/tools/barcodes.tmpl create mode 100644 koha-tmpl/intranet-tmpl/prog/en/tools/export.tmpl create mode 100644 koha-tmpl/intranet-tmpl/prog/en/tools/import.tmpl create mode 100644 koha-tmpl/intranet-tmpl/prog/en/tools/letter.tmpl create mode 100644 koha-tmpl/intranet-tmpl/prog/en/tools/printerConfig.tmpl create mode 100755 tools/barcodes.pl create mode 100755 tools/barcodesGenerator.pl create mode 100755 tools/export.pl create mode 100755 tools/import.pl create mode 100755 tools/letter.pl create mode 100755 tools/pdfViewer.pl create mode 100755 tools/printerConfig.pl diff --git a/koha-tmpl/intranet-tmpl/prog/en/tools/barcodes.tmpl b/koha-tmpl/intranet-tmpl/prog/en/tools/barcodes.tmpl new file mode 100644 index 0000000000..97efe01438 --- /dev/null +++ b/koha-tmpl/intranet-tmpl/prog/en/tools/barcodes.tmpl @@ -0,0 +1,80 @@ + + + +
+
+ +

Add a new Country Code

+
    +
  • +
  • +
+ + +
+
+ + + +

Barcodes Generator

+

Generate barcodes from inventory codes

+ + +Can't find inventory codes in that range. Please try again. + +
" name="form1" onsubmit="return checkFields(this);" target="_blank"> + + +
+
    +
  • +
  • +
+
+ + + + +

+[+]

+ +

" size="10" />[Go to Printer Configuration]

+ + +

+ " /> If this field is empty, author and title will be used instead

+ + + + + + + + + + + + +
">Label number to start printing
+ " name="label" > Label
+ + + +
+ + + diff --git a/koha-tmpl/intranet-tmpl/prog/en/tools/export.tmpl b/koha-tmpl/intranet-tmpl/prog/en/tools/export.tmpl new file mode 100644 index 0000000000..d150f32559 --- /dev/null +++ b/koha-tmpl/intranet-tmpl/prog/en/tools/export.tmpl @@ -0,0 +1,14 @@ +Koha -- Cataloging: MARC Export + +

MARC Export

+

Export in MARC format the following biblios:

+
+

From biblio number: +to biblio number:

+

(leave blank to export every biblio)

+ + +
+

Note : the items are NOT exported by this tool

+ + diff --git a/koha-tmpl/intranet-tmpl/prog/en/tools/import.tmpl b/koha-tmpl/intranet-tmpl/prog/en/tools/import.tmpl new file mode 100644 index 0000000000..30ce8f9053 --- /dev/null +++ b/koha-tmpl/intranet-tmpl/prog/en/tools/import.tmpl @@ -0,0 +1,53 @@ +Koha -- Cataloging: MARC Import + +

MARC acquisition system

+

Import into the reservoir

+ + +

Import results :

+ + + +
" enctype="multipart/form-data"> + + + + + + + + + + + + + + + + + + +
+
+
+ +
+ +
If ISBN is already in the reservoir: Ignore this one, keep the existing one
+ Overwrite the existing one with this
+
+ + + diff --git a/koha-tmpl/intranet-tmpl/prog/en/tools/letter.tmpl b/koha-tmpl/intranet-tmpl/prog/en/tools/letter.tmpl new file mode 100644 index 0000000000..498fadb8b1 --- /dev/null +++ b/koha-tmpl/intranet-tmpl/prog/en/tools/letter.tmpl @@ -0,0 +1,287 @@ + +
+

Letters admin

+ +
+ +
+ +
You Searched for


+ + + + + + + + + + + > + + + + + + + +
ModuleCodeName  
+ &code="> + //images/fileopen.png" width="32" hspace="0" vspace="0" border="0"> + + + &code="> + //images/edittrash.png" width="32" hspace="0" vspace="0" border="0"> + +
+

+ +
+ +
+
+
+ + + + +
+ +

Modify letter

+ +

Add letter

+ +
+ + + +

+ + +

+

+ "> +

+ + + +

+ + +

+

+ +

+ + +

+ "> +

+

+ "> +

+

+ +

+

+ + +

+

+
+
+ + + + Data recorded +
" method="post"> + +
+ + + + + + + + + + " method="post"> + "> + "> + + + + + + + + + + + +
/images/background-mem.gif"> + module / Code + /images/background-mem.gif"> + / +
Name
CONFIRM DELETION
+ + + +
" method="post"> + +
+
+ + + + Data deleted +
" method="post"> + +
+ +
+ diff --git a/koha-tmpl/intranet-tmpl/prog/en/tools/printerConfig.tmpl b/koha-tmpl/intranet-tmpl/prog/en/tools/printerConfig.tmpl new file mode 100644 index 0000000000..5c33f998ac --- /dev/null +++ b/koha-tmpl/intranet-tmpl/prog/en/tools/printerConfig.tmpl @@ -0,0 +1,83 @@ + + +

Printer Configuration

+

Set printer configuration corresponding to your environment

+ +
+
" name="form1"> + + + + + + + + + + + +
+ Label width (Expressed in mm) + + "> +
+ Label heigth (Expressed in mm) + + "> +
+ System dpi + + "> +
+ Page Type + + +
+ Columns + + "> +
+ Rows + + "> +
+ Margin Bottom (Expressed in mm) + + "> +
+ Margin Left (Expressed in mm) + + "> +
+
+ + diff --git a/tools/barcodes.pl b/tools/barcodes.pl new file mode 100755 index 0000000000..a568b753f0 --- /dev/null +++ b/tools/barcodes.pl @@ -0,0 +1,143 @@ +#!/usr/bin/perl + +# script to generate items barcodes +# written 07/04 +# by Veleda Matias - matias_veleda@hotmail.com - Physics Library UNLP Argentina and +# Castañeda Sebastian - seba3c@yahoo.com.ar - Physics Library UNLP Argentina and + +# 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 strict; +use CGI; +use C4::Auth; +use C4::Output; +use C4::Interface::CGI::Output; +use C4::Database; +use HTML::Template; +use C4::Context; +use C4::Barcodes::PrinterConfig; + + + +# 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 () { + 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); + +my $input = new CGI; +# Defines type of page to use in the printer process +my @labelTable = C4::Barcodes::PrinterConfig::labelsPage($labelConfig{'rows'}, $labelConfig{'columns'}); + +# It creates a list of posible intervals to choose codes to generate +my %list = ('continuous' => 'Continuous Range of items', 'individuals' => 'Individual Codes'); +my @listValues = keys(%list); +my $rangeType = CGI::scrolling_list(-name => 'rangeType', + -values => \@listValues, + -labels => \%list, + -size => 1, + -default => ['continuous'], + -multiple => 0, + -id => "rangeType", + -onChange => "changeRange(this)"); +# It creates a list of posible standard codifications. First checks if the user has just added a new code. +if ($input->param('addCode')) { + my $newCountryName = $input->param('countryName'); + my $newCountryCode = $input->param('countryCode'); + + my $countryCodesFilename = &getPath("intranet")."/includes/countryCodes/countryCodes.dat"; + open COUNTRY_CODES, ">>$countryCodesFilename"; + print COUNTRY_CODES $newCountryCode." = ".$newCountryName."\n"; + close COUNTRY_CODES; +} + +# Takes the country codes from a file and use them to set the country list. +my $countryCodes = &getPath("intranet")."/includes/countryCodes/countryCodes.dat"; +my %list = &loadConfFromFile($countryCodes); +@listValues = keys(%list); +my $number_system = CGI::scrolling_list(-name => 'numbersystem', + -values => \@listValues, + -labels => \%list, + -size => 1, + -multiple => 0); + +# Set the script name +my $script_name = "/cgi-bin/koha/tools/barcodesGenerator.pl"; + + +# Get the template to use +my ($template, $loggedinuser, $cookie) + = get_template_and_user({template_name => "barcodes/barcodes.tmpl", + type => "intranet", + query => $input, + authnotrequired => 0, + flagsrequired => {parameters => 1}, + debug => 1, + }); + +# Replace the template values with the real ones +$template->param(SCRIPT_NAME => $script_name); +$template->param(NUMBER_SYSTEM => $number_system); +$template->param(PAGES => $labelConfig{'pageType'}); +$template->param(RANGE_TYPE => $rangeType); +$template->param(LABEL_TABLE => \@labelTable); +$template->param(COL_SPAN => $labelConfig{'columns'}); +if ($input->param('error')) { + $template->param(ERROR => 1); +} else { + $template->param(ERROR => 0); +} +# Shows the template with the real values replaced +output_html_with_http_headers $input, $cookie, $template->output; \ No newline at end of file diff --git a/tools/barcodesGenerator.pl b/tools/barcodesGenerator.pl new file mode 100755 index 0000000000..7426602b37 --- /dev/null +++ b/tools/barcodesGenerator.pl @@ -0,0 +1,302 @@ +#!/usr/bin/perl + +# script to generate items barcodes +# written 07/04 +# by Veleda Matias - matias_veleda@hotmail.com - Physics Library UNLP Argentina and +# Castañeda Sebastian - seba3c@yahoo.com.ar - Physics Library UNLP Argentina and + +# 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 + +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; + + +# 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 () { + 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; +} +sub getCallnum { +#grabs a callnumber for the specified barcode +my ($barcode) = @_; +my $query = "select dewey from items,biblioitems where items.biblionumber=biblioitems.biblionumber and items.barcode=?"; +my $dbh = C4::Context->dbh; +my $sth = $dbh->prepare($query); +$sth->execute($barcode); +my ($callnum) = $sth->fetchrow_array(); +warn "Call number is:".$barcode; +return $callnum; +} +# 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); + # warn "range type: ".$rangeType; + if ($rangeType eq 'continuous') { + # 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 + # warn "Code is :-->".$codeC."<--"; + 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); + warn "code is ".$codeC; + if ($text_under_label) { + $text->text($text_under_label); + } else { + $text->text(getCallnum($code)); + } + } + # 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 . " )"; + } + warn "above the query"; + my $query = "SELECT CONCAT('$numbersystem',REPEAT('0',((12 - LENGTH('$numbersystem')) - LENGTH(I.barcode))), I.barcode) AS Codigo, I.dewey as dewey 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,$dewey,$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 { + warn "here a dewey:".$dewey; + $text->text(substr $dewey, 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/tools/pdfViewer.pl?tmpFileName=$tmpFileName"); + } else { + # Rollback and shows the error legend + print $cgi->redirect("/cgi-bin/koha/tools/barcodes.pl?error=1"); + } + $sth->finish; + } +} + +barcodesGenerator($from, $to, $rangeType, $individualCodes,$text_under_label); diff --git a/tools/export.pl b/tools/export.pl new file mode 100755 index 0000000000..e4cf7cd1b7 --- /dev/null +++ b/tools/export.pl @@ -0,0 +1,109 @@ +#!/usr/bin/perl +use HTML::Template; +use strict; +require Exporter; +use C4::Database; +use C4::Auth; +use C4::Interface::CGI::Output; +use C4::Output; # contains gettemplate +use C4::Biblio; +use CGI; +use C4::Koha; + +my $query = new CGI; +my $op=$query->param("op"); +my $dbh=C4::Context->dbh; + +if ($op eq "export") { + print $query->header('Content-Type: text/marc'); + my $start_bib = $query->param("start_bib"); + my $end_bib = $query->param("end_bib"); + my $format = $query->param("format"); + my $branch = $query->param("branch"); + my $start_callnumber = $query->param("start_callnumber"); + my $end_callnumber = $query->param("end_callnumber"); + my $limit = $query->param("limit"); + my $strsth; + $strsth="select bibid from marc_biblio "; + if ($start_bib && $end_bib) { + $strsth.=" where biblionumber>=$start_bib and biblionumber<=$end_bib "; + }elsif ($format) { + if ($strsth=~/ where/){ + $strsth=~s/ where (.*)/,biblioitems where biblioitems.biblionumber=marc_biblio.biblionumber and biblioitems.itemtype=\'$format\' and $1/; + }else { + $strsth.=",biblioitems where biblioitems.biblionumber=marc_biblio.biblionumber and biblioitems.itemtype=\'$format\'"; + } + } elsif ($branch) { + if ($strsth=~/ where/){ + $strsth=~s/ where (.*)/,items where items.biblionumber=marc_biblio.biblionumber and items.homebranch=\'$branch\' and $1/; + }else { + $strsth.=",items where items.biblionumber=marc_biblio.biblionumber and items.homebranch=\'$branch\'"; + } + } elsif ($start_callnumber && $end_callnumber) { + $start_callnumber=~s/\*/\%/g; + $start_callnumber=~s/\?/\_/g; + $end_callnumber=~s/\*/\%/g; + $end_callnumber=~s/\?/\_/g; + if ($strsth=~/,items/){ + $strsth.=" and items.itemcallnumber between \'$start_callnumber\' and \'$end_callnumber\'"; + } else { + if ($strsth=~/ where/){ + $strsth=~s/ where (.*)/,items where items.biblionumber=marc_biblio.biblionumber and items.itemcallnumber between \'$start_callnumber\' and \'$end_callnumber\' and $1/; + }else { + $strsth=~",items where items.biblionumber=marc_biblio.biblionumber and items.itemcallnumber between \'$start_callnumber\' and \'$end_callnumber\' "; + } + } + } + $strsth.=" order by marc_biblio.biblionumber "; + $strsth.= "LIMIT 0,$limit " if ($limit); + warn "requête marc.pl : ".$strsth; + my $req=$dbh->prepare($strsth); + $req->execute; + while (my ($bibid) = $req->fetchrow) { + my $record = MARCgetbiblio($dbh,$bibid); + + print $record->as_usmarc(); + } +} else { + my $sth=$dbh->prepare("Select itemtype,description from itemtypes order by description"); + $sth->execute; + my @itemtype; + my %itemtypes; + push @itemtype, ""; + $itemtypes{''} = ""; + while (my ($value,$lib) = $sth->fetchrow_array) { + push @itemtype, $value; + $itemtypes{$value}=$lib; + } + + my $CGIitemtype=CGI::scrolling_list( -name => 'format', + -values => \@itemtype, + -default => '', + -labels => \%itemtypes, + -size => 1, + -multiple => 0 ); + $sth->finish; + + my $branches = getallbranches; + my @branchloop; + foreach my $thisbranch (keys %$branches) { +# my $selected = 1 if $thisbranch eq $branch; + my %row =(value => $thisbranch, +# selected => $selected, + branchname => $branches->{$thisbranch}->{'branchname'}, + ); + push @branchloop, \%row; + } + + my ($template, $loggedinuser, $cookie) + = get_template_and_user({template_name => "tools/export.tmpl", + query => $query, + type => "intranet", + authnotrequired => 0, + flagsrequired => {parameters => 1, management => 1, tools => 1}, + debug => 1, + }); + $template->param(branchloop=>\@branchloop,CGIitemtype=>$CGIitemtype); + output_html_with_http_headers $query, $cookie, $template->output; +} + diff --git a/tools/import.pl b/tools/import.pl new file mode 100755 index 0000000000..2a19412af2 --- /dev/null +++ b/tools/import.pl @@ -0,0 +1,430 @@ +#!/usr/bin/perl + +# $Id$ + +# Script for handling import of MARC data into Koha db +# and Z39.50 lookups + +# Koha library project www.koha.org + +# Licensed under the GPL + + +# 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 strict; + +# standard or CPAN modules used +use CGI; +use DBI; + +# Koha modules used +use C4::Context; +use C4::Output; +use C4::Interface::CGI::Output; +use C4::Input; +use C4::Biblio; +use MARC::File::USMARC; +use HTML::Template; +use C4::Output; +use C4::Auth; +use C4::Breeding; + +#------------------ +# Constants + +my $includes = C4::Context->config('includes') || + "/usr/local/www/hdl/htdocs/includes"; + +# HTML colors for alternating lines +my $lc1='#dddddd'; +my $lc2='#ddaaaa'; + +#------------- +#------------- +# Initialize + +my $userid=$ENV{'REMOTE_USER'}; + +my $input = new CGI; +my $dbh = C4::Context->dbh; + +my $uploadmarc=$input->param('uploadmarc'); +my $overwrite_biblio = $input->param('overwrite_biblio'); +my $filename = $input->param('filename'); +my $syntax = $input->param('syntax'); +my ($template, $loggedinuser, $cookie) + = get_template_and_user({template_name => "tools/import.tmpl", + query => $input, + type => "intranet", + authnotrequired => 0, + flagsrequired => {parameters => 1, management => 1, tools => 1}, + debug => 1, + }); + +$template->param(SCRIPT_NAME => $ENV{'SCRIPT_NAME'}, + uploadmarc => $uploadmarc); +if ($uploadmarc && length($uploadmarc)>0) { + my $marcrecord=''; + while (<$uploadmarc>) { + $marcrecord.=$_; + } + my ($notmarcrecord,$alreadyindb,$alreadyinfarm,$imported) = ImportBreeding($marcrecord,$overwrite_biblio,$filename,$syntax,int(rand(99999))); + + $template->param(imported => $imported, + alreadyindb => $alreadyindb, + alreadyinfarm => $alreadyinfarm, + notmarcrecord => $notmarcrecord, + total => $imported+$alreadyindb+$alreadyinfarm+$notmarcrecord, + ); + +} + +output_html_with_http_headers $input, $cookie, $template->output; +my $menu; +my $file; + + +#--------------- +# log cleared, as marcimport is (almost) rewritten from scratch. +# $Log$ +# Revision 1.1 2006/02/24 11:52:38 hdl +# Adding tools directory template and scripts +# Changing barcodes, export and import and letters directory. +# Changing export script name (marc.pl) to export.pl +# Changing import script name (breeding.pl) to import.pl +# +# Revision 1.4 2005/05/04 08:52:13 tipaul +# synch'ing 2.2 and head +# +# Revision 1.3 2005/03/23 09:57:47 doxulting +# Adding a parameter to allow acces to people with management/tools flags +# +# Revision 1.2 2003/10/06 09:10:38 slef +# Removing config info from z3950*sh and using C4::Context in processz3950queue (Fixed bug 39) +# +# Revision 1.1 2003/06/04 13:46:25 tipaul +# moving breeding farm import to parameters page (GUI) and to new import/ directory (code structure) +# +# Revision 1.33 2003/04/29 16:48:36 tipaul +# really proud of this commit :-) +# z3950 search and import seems to works fine. +# Let me explain how : +# * a "search z3950" button is added in the addbiblio template. +# * when clicked, a popup appears and z3950/search.pl is called +# * z3950/search.pl calls addz3950search in the DB +# * the z3950 daemon retrieve the records and stores them in z3950results AND in marc_breeding table. +# * as long as there as searches pending, the popup auto refresh every 2 seconds, and says how many searches are pending. +# * when the user clicks on a z3950 result => the parent popup is called with the requested biblio, and auto-filled +# +# Note : +# * character encoding support : (It's a nightmare...) In the z3950servers table, a "encoding" column has been added. You can put "UNIMARC" or "USMARC" in this column. Depending on this, the char_decode in C4::Biblio.pm replaces marc-char-encode by an iso 8859-1 encoding. Note that in the breeding import this value has been added too, for a better support. +# * the marc_breeding and z3950* tables have been modified : they have an encoding column and the random z3950 number is stored too for convenience => it's the key I use to list only requested biblios in the popup. +# +# Revision 1.32 2003/04/22 12:22:54 tipaul +# 1st draft for z3950 client import. +# moving Breeding farm script to a perl package C4/Breeding.pm +# +# Revision 1.31 2003/02/19 01:01:07 wolfpac444 +# Removed the unecessary $dbh argument from being passed. +# Resolved a few minor FIXMEs. +# +# Revision 1.30 2003/02/02 07:18:38 acli +# Moved C4/Charset.pm to C4/Interface/CGI/Output.pm +# +# Create output_html_with_http_headers function to contain the "print $query +# ->header(-type => guesstype...),..." call. This is in preparation for +# non-HTML output (e.g., text/xml) and charset conversion before output in +# the future. +# +# Created C4/Interface/CGI/Template.pm to hold convenience functions specific +# to the CGI interface using HTML::Template +# +# Modified moremembers.pl to make the "sex" field localizable for languages +# where M and F doesn't make sense +# +# Revision 1.29 2003/01/28 15:28:31 tipaul +# removing use MARC::Charset +# Was a buggy test +# +# Revision 1.28 2003/01/28 15:00:31 tipaul +# user can now search in breeding farm with isbn/issn or title. Title/name are stored in breeding farm and showed when a search is done +# +# Revision 1.27 2003/01/26 23:21:49 acli +# Handle non-latin1 charsets +# +# Revision 1.26 2003/01/23 12:26:41 tipaul +# upgrading import in breeding farm (you can now search on ISBN or on title) AND character encoding. +# +# Revision 1.25 2003/01/21 08:13:50 tipaul +# character encoding ISO646 => 8859-1, first draft +# +# Revision 1.24 2003/01/14 16:41:17 tipaul +# bugfix : use gettemplate_and_user instead of gettemplate. +# fix a blank screen in 1.3.3 in "import in breeding farm" +# +# Revision 1.23 2003/01/06 13:06:28 tipaul +# removing trailing # +# +# Revision 1.22 2002/11/12 15:58:43 tipaul +# road to 1.3.2 : +# * many bugfixes +# * adding value_builder : you can map a subfield in the marc_subfield_structure to a sub stored in "value_builder" directory. In this directory you can create screen used to build values with any method. In this commit is a 1st draft of the builder for 100$a unimarc french subfield, which is composed of 35 digits, with 12 differents values (only the 4th first are provided for instance) +# +# Revision 1.21 2002/10/22 15:50:23 tipaul +# road to 1.3.2 : adding a biblio in MARC format. +# seems to work a few. +# still to do : +# * manage html checks (mandatory subfields...) +# * add list of acceptable values (authorities) +# * manage ## in MARC format +# * manage correctly repeatable fields +# and probably a LOT of bugfixes +# +# Revision 1.20 2002/10/16 12:46:19 arensb +# Added a FIXME comment. +# +# Revision 1.19 2002/10/15 10:14:44 tipaul +# road to 1.3.2. Full rewrite of marcimport.pl. +# The acquisition system in MARC version will work like this : +# * marcimport will put marc records into a "breeding farm" table. +# * when the user want to add a biblio, he enters first the ISBN/ISSN of the biblio. koha searches into breeding farm and if the record exists, it is shown to the user to help him adding the biblio. When the biblio is added, it's deleted from the breeding farm. +# +# This commit : +# * modify acqui.simple home page (addbooks.pl) +# * adds import into breeding farm +# +# Please note that : +# * z3950 functionnality is dropped from "marcimport" will be added somewhere else. +# * templates are in a new acqui.simple sub directory, and the marcimport template directory will become obsolete soon.I think this is more logic +# +#!/usr/bin/perl + +# $Id$ + +# Script for handling import of MARC data into Koha db +# and Z39.50 lookups + +# Koha library project www.koha.org + +# Licensed under the GPL + + +# 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 strict; + +# standard or CPAN modules used +use CGI; +use DBI; + +# Koha modules used +use C4::Context; +use C4::Output; +use C4::Interface::CGI::Output; +use C4::Input; +use C4::Biblio; +use MARC::File::USMARC; +use HTML::Template; +use C4::Output; +use C4::Auth; +use C4::Breeding; + +#------------------ +# Constants + +my $includes = C4::Context->config('includes') || + "/usr/local/www/hdl/htdocs/includes"; + +# HTML colors for alternating lines +my $lc1='#dddddd'; +my $lc2='#ddaaaa'; + +#------------- +#------------- +# Initialize + +my $userid=$ENV{'REMOTE_USER'}; + +my $input = new CGI; +my $dbh = C4::Context->dbh; + +my $uploadmarc=$input->param('uploadmarc'); +my $overwrite_biblio = $input->param('overwrite_biblio'); +my $filename = $input->param('filename'); +my $syntax = $input->param('syntax'); +my ($template, $loggedinuser, $cookie) + = get_template_and_user({template_name => "import/breeding.tmpl", + query => $input, + type => "intranet", + authnotrequired => 0, + flagsrequired => {parameters => 1, management => 1, tools => 1}, + debug => 1, + }); + +$template->param(SCRIPT_NAME => $ENV{'SCRIPT_NAME'}, + uploadmarc => $uploadmarc); +if ($uploadmarc && length($uploadmarc)>0) { + my $marcrecord=''; + while (<$uploadmarc>) { + $marcrecord.=$_; + } + my ($notmarcrecord,$alreadyindb,$alreadyinfarm,$imported) = ImportBreeding($marcrecord,$overwrite_biblio,$filename,$syntax,int(rand(99999))); + + $template->param(imported => $imported, + alreadyindb => $alreadyindb, + alreadyinfarm => $alreadyinfarm, + notmarcrecord => $notmarcrecord, + total => $imported+$alreadyindb+$alreadyinfarm+$notmarcrecord, + ); + +} + +output_html_with_http_headers $input, $cookie, $template->output; +my $menu; +my $file; + + +#--------------- +# log cleared, as marcimport is (almost) rewritten from scratch. +# $Log$ +# Revision 1.1 2006/02/24 11:52:38 hdl +# Adding tools directory template and scripts +# Changing barcodes, export and import and letters directory. +# Changing export script name (marc.pl) to export.pl +# Changing import script name (breeding.pl) to import.pl +# +# Revision 1.4 2005/05/04 08:52:13 tipaul +# synch'ing 2.2 and head +# +# Revision 1.2.4.1 2005/04/07 10:10:52 tipaul +# copying processz3950queue from 2.0 branch. The 2.2 version misses an important fix +# +# Revision 1.2 2003/10/06 09:10:38 slef +# Removing config info from z3950*sh and using C4::Context in processz3950queue (Fixed bug 39) +# +# Revision 1.1 2003/06/04 13:46:25 tipaul +# moving breeding farm import to parameters page (GUI) and to new import/ directory (code structure) +# +# Revision 1.33 2003/04/29 16:48:36 tipaul +# really proud of this commit :-) +# z3950 search and import seems to works fine. +# Let me explain how : +# * a "search z3950" button is added in the addbiblio template. +# * when clicked, a popup appears and z3950/search.pl is called +# * z3950/search.pl calls addz3950search in the DB +# * the z3950 daemon retrieve the records and stores them in z3950results AND in marc_breeding table. +# * as long as there as searches pending, the popup auto refresh every 2 seconds, and says how many searches are pending. +# * when the user clicks on a z3950 result => the parent popup is called with the requested biblio, and auto-filled +# +# Note : +# * character encoding support : (It's a nightmare...) In the z3950servers table, a "encoding" column has been added. You can put "UNIMARC" or "USMARC" in this column. Depending on this, the char_decode in C4::Biblio.pm replaces marc-char-encode by an iso 8859-1 encoding. Note that in the breeding import this value has been added too, for a better support. +# * the marc_breeding and z3950* tables have been modified : they have an encoding column and the random z3950 number is stored too for convenience => it's the key I use to list only requested biblios in the popup. +# +# Revision 1.32 2003/04/22 12:22:54 tipaul +# 1st draft for z3950 client import. +# moving Breeding farm script to a perl package C4/Breeding.pm +# +# Revision 1.31 2003/02/19 01:01:07 wolfpac444 +# Removed the unecessary $dbh argument from being passed. +# Resolved a few minor FIXMEs. +# +# Revision 1.30 2003/02/02 07:18:38 acli +# Moved C4/Charset.pm to C4/Interface/CGI/Output.pm +# +# Create output_html_with_http_headers function to contain the "print $query +# ->header(-type => guesstype...),..." call. This is in preparation for +# non-HTML output (e.g., text/xml) and charset conversion before output in +# the future. +# +# Created C4/Interface/CGI/Template.pm to hold convenience functions specific +# to the CGI interface using HTML::Template +# +# Modified moremembers.pl to make the "sex" field localizable for languages +# where M and F doesn't make sense +# +# Revision 1.29 2003/01/28 15:28:31 tipaul +# removing use MARC::Charset +# Was a buggy test +# +# Revision 1.28 2003/01/28 15:00:31 tipaul +# user can now search in breeding farm with isbn/issn or title. Title/name are stored in breeding farm and showed when a search is done +# +# Revision 1.27 2003/01/26 23:21:49 acli +# Handle non-latin1 charsets +# +# Revision 1.26 2003/01/23 12:26:41 tipaul +# upgrading import in breeding farm (you can now search on ISBN or on title) AND character encoding. +# +# Revision 1.25 2003/01/21 08:13:50 tipaul +# character encoding ISO646 => 8859-1, first draft +# +# Revision 1.24 2003/01/14 16:41:17 tipaul +# bugfix : use gettemplate_and_user instead of gettemplate. +# fix a blank screen in 1.3.3 in "import in breeding farm" +# +# Revision 1.23 2003/01/06 13:06:28 tipaul +# removing trailing # +# +# Revision 1.22 2002/11/12 15:58:43 tipaul +# road to 1.3.2 : +# * many bugfixes +# * adding value_builder : you can map a subfield in the marc_subfield_structure to a sub stored in "value_builder" directory. In this directory you can create screen used to build values with any method. In this commit is a 1st draft of the builder for 100$a unimarc french subfield, which is composed of 35 digits, with 12 differents values (only the 4th first are provided for instance) +# +# Revision 1.21 2002/10/22 15:50:23 tipaul +# road to 1.3.2 : adding a biblio in MARC format. +# seems to work a few. +# still to do : +# * manage html checks (mandatory subfields...) +# * add list of acceptable values (authorities) +# * manage ## in MARC format +# * manage correctly repeatable fields +# and probably a LOT of bugfixes +# +# Revision 1.20 2002/10/16 12:46:19 arensb +# Added a FIXME comment. +# +# Revision 1.19 2002/10/15 10:14:44 tipaul +# road to 1.3.2. Full rewrite of marcimport.pl. +# The acquisition system in MARC version will work like this : +# * marcimport will put marc records into a "breeding farm" table. +# * when the user want to add a biblio, he enters first the ISBN/ISSN of the biblio. koha searches into breeding farm and if the record exists, it is shown to the user to help him adding the biblio. When the biblio is added, it's deleted from the breeding farm. +# +# This commit : +# * modify acqui.simple home page (addbooks.pl) +# * adds import into breeding farm +# +# Please note that : +# * z3950 functionnality is dropped from "marcimport" will be added somewhere else. +# * templates are in a new acqui.simple sub directory, and the marcimport template directory will become obsolete soon.I think this is more logic +# diff --git a/tools/letter.pl b/tools/letter.pl new file mode 100755 index 0000000000..0ea6aba18d --- /dev/null +++ b/tools/letter.pl @@ -0,0 +1,229 @@ +#!/usr/bin/perl + +#script to administer the aqbudget table +#written 20/02/2002 by paul.poulain@free.fr +# This software is placed under the gnu General Public License, v2 (http://www.gnu.org/licenses/gpl.html) + +# ALGO : +# this script use an $op to know what to do. +# if $op is empty or none of the above values, +# - the default screen is build (with all records, or filtered datas). +# - the user can clic on add, modify or delete record. +# if $op=add_form +# - if primkey exists, this is a modification,so we read the $primkey record +# - builds the add/modify form +# if $op=add_validate +# - the user has just send datas, so we create/modify the record +# if $op=delete_form +# - we show the record having primkey=$primkey and ask for deletion validation form +# if $op=delete_confirm +# - we delete the record having primkey=$primkey + + +# 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 strict; +use CGI; +use C4::Date; +use C4::Auth; +use C4::Context; +use C4::Output; +use C4::Interface::CGI::Output; +use C4::Search; +use HTML::Template; + +sub StringSearch { + my ($env,$searchstring,$type)=@_; + my $dbh = C4::Context->dbh; + $searchstring=~ s/\'/\\\'/g; + my @data=split(' ',$searchstring); + my $count=@data; + my $sth=$dbh->prepare("Select * from letter where (code like ?) order by module,code"); + $sth->execute("$data[0]%"); + my @results; + my $cnt=0; + while (my $data=$sth->fetchrow_hashref){ + push(@results,$data); + $cnt ++; + } + # $sth->execute; + $sth->finish; + return ($cnt,\@results); +} + +my $input = new CGI; +my $searchfield=$input->param('searchfield'); +my $offset=$input->param('offset'); +my $script_name="/cgi-bin/koha/tools/letter.pl"; +my $code=$input->param('code'); +my $module = $input->param('module'); +my $pagesize=20; +my $op = $input->param('op'); +$searchfield=~ s/\,//g; +my $dbh = C4::Context->dbh; + +my ($template, $borrowernumber, $cookie) + = get_template_and_user({template_name => "tools/letter.tmpl", + query => $input, + type => "intranet", + authnotrequired => 0, + flagsrequired => {tools => 1}, + debug => 1, + }); + +if ($op) { +$template->param(script_name => $script_name, + $op => 1); # we show only the TMPL_VAR names $op +} else { +$template->param(script_name => $script_name, + else => 1); # we show only the TMPL_VAR names $op +} + +$template->param(action => $script_name); +################## ADD_FORM ################################## +# called by default. Used to create form to add or modify a record +if ($op eq 'add_form') { + #---- if primkey exists, it's a modify action, so read values to modify... + my $letter; + if ($code) { + my $sth=$dbh->prepare("select * from letter where module=? and code=?"); + $sth->execute($module,$code); + $letter=$sth->fetchrow_hashref; + $sth->finish; + } + # build field list + my @SQLfieldname; + my %line = ('value' => "LibrarianFirstname", 'text' => 'LibrarianFirstname'); + push @SQLfieldname, \%line; + my %line = ('value' => "LibrarianSurname", 'text' => 'LibrarianSurname'); + push @SQLfieldname, \%line; + my %line = ('value' => "LibrarianEmailaddress", 'text' => 'LibrarianEmailaddress'); + push @SQLfieldname, \%line; + my $sth2=$dbh->prepare("SHOW COLUMNS from branches"); + $sth2->execute; + my %line = ('value' => "", 'text' => '---BRANCHES---'); + push @SQLfieldname, \%line; + while ((my $field) = $sth2->fetchrow_array) { + my %line = ('value' => "branches.".$field, 'text' => "branches.".$field); + push @SQLfieldname, \%line; + } + my $sth2=$dbh->prepare("SHOW COLUMNS from biblio"); + $sth2->execute; + my %line = ('value' => "", 'text' => '---BIBLIO---'); + + push @SQLfieldname, \%line; + while ((my $field) = $sth2->fetchrow_array) { + # note : %line is redefined, otherwise \%line contains the same value for every entry of the list + my %line = ('value' => "biblio.".$field, 'text' => "biblio.".$field); + push @SQLfieldname, \%line; + } + my $sth2=$dbh->prepare("SHOW COLUMNS from biblioitems"); + $sth2->execute; + my %line = ('value' => "", 'text' => '---BIBLIOITEMS---'); + push @SQLfieldname, \%line; + while ((my $field) = $sth2->fetchrow_array) { + my %line = ('value' => "biblioitems.".$field, 'text' => "biblioitems.".$field); + push @SQLfieldname, \%line; + } + my %line = ('value' => "", 'text' => '---ITEMS---'); + push @SQLfieldname, \%line; + my %line = ('value' => "items.content", 'text' => 'items.content'); + push @SQLfieldname, \%line; + + my $sth2=$dbh->prepare("SHOW COLUMNS from borrowers"); + $sth2->execute; + my %line = ('value' => "", 'text' => '---BORROWERS---'); + push @SQLfieldname, \%line; + while ((my $field) = $sth2->fetchrow_array) { + my %line = ('value' => "borrowers.".$field, 'text' => "borrowers.".$field); + push @SQLfieldname, \%line; + } + if ($code) { + $template->param(modify => 1); + $template->param(code => $letter->{code}); + } else { + $template->param(adding => 1); + } + $template->param(name => $letter->{name},title => $letter->{title}, + content => $letter->{content}, + $letter->{module} => 1, + SQLfieldname => \@SQLfieldname,); + # END $OP eq ADD_FORM +################## ADD_VALIDATE ################################## +# called by add_form, used to insert/modify data in DB +} elsif ($op eq 'add_validate') { + my $dbh = C4::Context->dbh; + my $sth=$dbh->prepare("replace letter (module,code,name,title,content) values (?,?,?,?,?)"); + $sth->execute($input->param('module'),$input->param('code'),$input->param('name'),$input->param('title'),$input->param('content')); + $sth->finish; + print $input->redirect("letter.pl"); + exit; +# END $OP eq ADD_VALIDATE +################## DELETE_CONFIRM ################################## +# called by default form, used to confirm deletion of data in DB +} elsif ($op eq 'delete_confirm') { + my $dbh = C4::Context->dbh; + my $sth=$dbh->prepare("select * from letter where code=?"); + $sth->execute($code); + my $data=$sth->fetchrow_hashref; + $sth->finish; + $template->param(module => $data->{module}); + $template->param(code => $code); + $template->param(name => $data->{'name'}); + $template->param(content => $data->{'content'}); + # END $OP eq DELETE_CONFIRM +################## DELETE_CONFIRMED ################################## +# called by delete_confirm, used to effectively confirm deletion of data in DB +} elsif ($op eq 'delete_confirmed') { + my $dbh = C4::Context->dbh; + my $code=uc($input->param('code')); + my $module=$input->param('module'); + my $sth=$dbh->prepare("delete from letter where module=? and code=?"); + $sth->execute($module,$code); + $sth->finish; + print $input->redirect("letter.pl"); + return; + # END $OP eq DELETE_CONFIRMED +################## DEFAULT ################################## +} else { # DEFAULT + if ($searchfield ne '') { + $template->param(search => 1); + $template->param(searchfield => $searchfield); + } + my $env; + my ($count,$results)=StringSearch($env,$searchfield,'web'); + my $toggle="white"; + my @loop_data =(); + for (my $i=$offset; $i < ($offset+$pagesize<$count?$offset+$pagesize:$count); $i++){ + if ($toggle eq 'white'){ + $toggle="#ffffcc"; + } else { + $toggle="white"; + } + my %row_data; + $row_data{toggle} = $toggle; + $row_data{module} = $results->[$i]{'module'}; + $row_data{code} = $results->[$i]{'code'}; + $row_data{name} = $results->[$i]{'name'}; + push(@loop_data, \%row_data); + } + $template->param(letter => \@loop_data); +} #---- END $OP eq DEFAULT + +output_html_with_http_headers $input, $cookie, $template->output; + diff --git a/tools/pdfViewer.pl b/tools/pdfViewer.pl new file mode 100755 index 0000000000..d6ec298a5b --- /dev/null +++ b/tools/pdfViewer.pl @@ -0,0 +1,40 @@ +#!/usr/bin/perl + +# script to show a PDF file. +# written 07/04 +# by Veleda Matias - matias_veleda@hotmail.com - Physics Library UNLP Argentina and +# Castañeda Sebastian - seba3c@yahoo.com.ar - Physics Library UNLP Argentina and + +# 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 + +require Exporter; + +use strict; +use C4::Context; +use CGI; + +# This script take a pdf filename as a parameter and output it to the browser. +my $cgi = new CGI; +my $filename = "barcodes.pdf"; +my $tmpFileName = $cgi->param('tmpFileName'); +print "Content-Disposition: attachment; filename = $filename\n\n"; +print $cgi->header(-type => 'application/pdf'), + $cgi->start_html(-title=>"Codify to PDF"); +open fh, "<$tmpFileName"; +while () { + print; +} +print $cgi->end_html(); diff --git a/tools/printerConfig.pl b/tools/printerConfig.pl new file mode 100755 index 0000000000..e36ab5c4cf --- /dev/null +++ b/tools/printerConfig.pl @@ -0,0 +1,116 @@ +#!/usr/bin/perl + +# script to set the labels configuration for the printer process. +# written 07/04 +# by Veleda Matias - matias_veleda@hotmail.com - Physics Library UNLP Argentina and + +# 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 + +require Exporter; + +use strict; + +use CGI; +use C4::Context; +use C4::Output; +use C4::Auth; +use HTML::Template; +use PDF::API2; +use PDF::API2::Page; +use PDF::API2::PDF::Utils; +use C4::Interface::CGI::Output; + +# 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. +sub loadConfFromFile { + my $fileName = shift @_; + my %keyValues; + open FILE, "<$fileName"; + while () { + chomp; + if (/\s*([\w_]*)\s*=\s*([\[\]\<\>\w_\s:@,\.-]*)\s*/) { + $keyValues{$1} = $2; + } + } + close FILE; + return %keyValues; +} + +# Save settings to a configuration file. +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; +} + +# Creates a CGI object and take his parameters +my $input = new CGI; + +if ($input->param('saveSettings')) { + my $labelConf = &getPath("intranet")."/includes/labelConfig/itemsLabelConfig.conf"; + my %newConfiguration = (pageType => $input->param('pageType'), + columns => $input->param('columns'), + rows => $input->param('rows'), + systemDpi => $input->param('systemDpi'), + labelWidth => $input->param('labelWidth'), + labelHeigth => $input->param('labelHeigth'), + marginBottom => $input->param('marginBottom'), + marginLeft => $input->param('marginLeft')); + saveConfToFile($labelConf, \%newConfiguration); + print $input->redirect('/cgi-bin/koha/barcodes/barcodes.pl') +} + +# Get the template to use +my ($template, $loggedinuser, $cookie) + = get_template_and_user({template_name => "tools/printerConfig.tmpl", + type => "intranet", + query => $input, + authnotrequired => 0, + flagsrequired => {parameters => 1}, + debug => 1, + }); + +my $filenameConf = &getPath("intranet")."/includes/labelConfig/itemsLabelConfig.conf"; +my %labelConfig = &loadConfFromFile($filenameConf); + +$template->param(COLUMNS => $labelConfig{'columns'}); +$template->param(ROWS => $labelConfig{'rows'}); +$template->param(SYSTEM_DPI => $labelConfig{'systemDpi'}); +$template->param(LABEL_WIDTH => $labelConfig{'labelWidth'}); +$template->param(LABEL_HEIGTH => $labelConfig{'labelHeigth'}); +$template->param(MARGIN_TOP => $labelConfig{'marginBottom'}); +$template->param(MARGIN_LEFT => $labelConfig{'marginLeft'}); +$template->param(SCRIPT_NAME => '/cgi-bin/koha/tools/printerConfig.pl'); +$template->param("$labelConfig{'pageType'}" => 1); +output_html_with_http_headers $input, $cookie, $template->output; \ No newline at end of file -- 2.39.5