From e431b4b07702fc110a65b8e7d1c93cfdb6f51d27 Mon Sep 17 00:00:00 2001 From: Henri-Damien LAURENT Date: Wed, 16 Sep 2009 21:31:30 +0200 Subject: [PATCH] MT 1587 : CSV export for cart and shelves, with the ability to define different export profiles Signed-off-by: Henri-Damien LAURENT --- C4/Csv.pm | 80 ++ C4/Record.pm | 98 ++ installer/data/mysql/updatedatabase.pl | 997 ++++++++++++++++++ .../prog/en/modules/tools/csv-profiles.tmpl | 98 ++ .../prog/en/modules/tools/tools-home.tmpl | 6 + .../prog/en/modules/opac-downloadcart.tmpl | 28 + .../prog/en/modules/opac-downloadshelf.tmpl | 28 + opac/opac-downloadcart.pl | 90 ++ opac/opac-downloadshelf.pl | 90 ++ tools/csv-profiles.pl | 121 +++ 10 files changed, 1636 insertions(+) create mode 100644 C4/Csv.pm create mode 100644 koha-tmpl/intranet-tmpl/prog/en/modules/tools/csv-profiles.tmpl create mode 100644 koha-tmpl/opac-tmpl/prog/en/modules/opac-downloadcart.tmpl create mode 100644 koha-tmpl/opac-tmpl/prog/en/modules/opac-downloadshelf.tmpl create mode 100755 opac/opac-downloadcart.pl create mode 100755 opac/opac-downloadshelf.pl create mode 100755 tools/csv-profiles.pl diff --git a/C4/Csv.pm b/C4/Csv.pm new file mode 100644 index 0000000000..3c1c56d535 --- /dev/null +++ b/C4/Csv.pm @@ -0,0 +1,80 @@ +package C4::Csv; + +# Copyright 2008 BibLibre +# +# 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 vars qw($VERSION @ISA @EXPORT); + +# set the version for version checking +$VERSION = 3.00; + +@ISA = qw(Exporter); + +# only export API methods + +@EXPORT = qw( + &GetCsvProfiles + &GetCsvProfilesLoop + &GetMarcFieldsForCsv +); + +my $dbh = C4::Context->dbh; + +# Returns all informations about csv profiles +sub GetCsvProfiles { + + my $query = "SELECT * FROM export_format"; + + $sth = $dbh->prepare($query); + $sth->execute; + + $sth->fetchall_arrayref({}); + +} + +# Returns fields to extract for the given csv profile +sub GetMarcFieldsForCsv { + + my ($id) = @_; + + my $query = "SELECT marcfields FROM export_format WHERE export_format_id=?"; + + $sth = $dbh->prepare($query); + $sth->execute($id); + + return ($sth->fetchrow_hashref)->{marcfields}; + + +} + +# Returns informations aboout csv profiles suitable for html templates +sub GetCsvProfilesLoop { + # List of existing profiles + my $sth; + my $query = "SELECT export_format_id, profile FROM export_format"; + $sth = $dbh->prepare($query); + $sth->execute(); + return $sth->fetchall_arrayref({}); + +} + + + +1; diff --git a/C4/Record.pm b/C4/Record.pm index 2be47519e0..1574af1ba9 100644 --- a/C4/Record.pm +++ b/C4/Record.pm @@ -29,6 +29,9 @@ use Biblio::EndnoteStyle; use Unicode::Normalize; # _entity_encode use XML::LibXSLT; use XML::LibXML; +use C4::Biblio; #marc2bibtex +use C4::Csv; #marc2csv +use Text::CSV; #marc2csv use vars qw($VERSION @ISA @EXPORT); @@ -46,6 +49,8 @@ $VERSION = 3.00; &marcxml2marc &marc2dcxml &marc2modsxml + &marc2bibtex + &marc2csv &html2marcxml &html2marc @@ -322,6 +327,99 @@ sub marc2endnote { } +=head2 marc2csv - Convert from UNIMARC to CSV + +=over 4 + +my ($csv) = marc2csv($record, $csvprofileid); + +Returns a CSV scalar + +=over 2 + +C<$record> - a MARC::Record object + +C<$csvprofileid> - the id of the CSV profile to use for the export (see export_format.export_format_id and the GetCsvProfiles function in C4::Csv) + +=back + +=back + +=cut + + +sub marc2csv { + my ($record, $id, $header) = @_; + my $output; + my $csv = Text::CSV->new(); + + # Get the information about the csv profile + my $marcfieldslist = GetMarcFieldsForCsv($id); + + # Getting the marcfields as an array + my @marcfields = split('\|', $marcfieldslist); + + # If we have to insert the headers + if ($header) { + my @marcfieldsheaders; + + my $dbh = C4::Context->dbh; + + # For each field or subfield + foreach (@marcfields) { + # We get the matching tag name + if (index($_, '$') > 0) { + my ($fieldtag, $subfieldtag) = split('\$', $_); + my $query = "SELECT liblibrarian FROM marc_subfield_structure WHERE tagfield=? AND tagsubfield=?"; + my $sth = $dbh->prepare($query); + $sth->execute($fieldtag, $subfieldtag); + my @results = $sth->fetchrow_array(); + push @marcfieldsheaders, @results[0]; + } else { + my $query = "SELECT liblibrarian FROM marc_tag_structure WHERE tagfield=?"; + my $sth = $dbh->prepare($query); + $sth->execute($_); + my @results = $sth->fetchrow_array(); + push @marcfieldsheaders, @results[0]; + } + } + $csv->combine(@marcfieldsheaders); + $output = $csv->string() . "\n"; + } + + # For each marcfield to export + my @fieldstab; + foreach my $marcfield (@marcfields) { + # If it is a subfield + if (index($marcfield, '$') > 0) { + my ($fieldtag, $subfieldtag) = split('\$', $marcfield); + my @fields = $record->field($fieldtag); + my @tmpfields; + + # For each field + foreach my $field (@fields) { + + # We take every matching subfield + my @subfields = $field->subfield($subfieldtag); + foreach my $subfield (@subfields) { + push @tmpfields, $subfield; + } + } + push (@fieldstab, join(',', @tmpfields)); + # Or a field + } else { + my @fields = ($record->field($marcfield)); + push (@fieldstab, join(',', map($_->as_string(), @fields))); + } + }; + + $csv->combine(@fieldstab); + $output .= $csv->string() . "\n"; + + return $output; + +} + =head2 html2marcxml diff --git a/installer/data/mysql/updatedatabase.pl b/installer/data/mysql/updatedatabase.pl index 1183375b48..0e4a96b02c 100755 --- a/installer/data/mysql/updatedatabase.pl +++ b/installer/data/mysql/updatedatabase.pl @@ -1965,10 +1965,1007 @@ if (C4::Context->preference("Version") =~/3\.00/) { unless ($return){ print STDERR "cannot read file $perllibdir/installer/data/mysql/updatedatabase30.pl : $! \n" if ($!); print STDERR "cannot read file $ENV{'PERL5LIB'}/installer/data/mysql/updatedatabase30.pl : $@ \n" if ($@); + +$DBversion = '3.01.00.000'; +if (C4::Context->preference("Version") < TransformToNum($DBversion)) { + print "Upgrade to $DBversion done (start of 3.1)\n"; + SetVersion ($DBversion); +} + +$DBversion = '3.01.00.001'; +if ( C4::Context->preference('Version') < TransformToNum($DBversion) ) { + $dbh->do(" + CREATE TABLE hold_fill_targets ( + `borrowernumber` int(11) NOT NULL, + `biblionumber` int(11) NOT NULL, + `itemnumber` int(11) NOT NULL, + `source_branchcode` varchar(10) default NULL, + `item_level_request` tinyint(4) NOT NULL default 0, + PRIMARY KEY `itemnumber` (`itemnumber`), + KEY `bib_branch` (`biblionumber`, `source_branchcode`), + CONSTRAINT `hold_fill_targets_ibfk_1` FOREIGN KEY (`borrowernumber`) + REFERENCES `borrowers` (`borrowernumber`) ON DELETE CASCADE ON UPDATE CASCADE, + CONSTRAINT `hold_fill_targets_ibfk_2` FOREIGN KEY (`biblionumber`) + REFERENCES `biblio` (`biblionumber`) ON DELETE CASCADE ON UPDATE CASCADE, + CONSTRAINT `hold_fill_targets_ibfk_3` FOREIGN KEY (`itemnumber`) + REFERENCES `items` (`itemnumber`) ON DELETE CASCADE ON UPDATE CASCADE, + CONSTRAINT `hold_fill_targets_ibfk_4` FOREIGN KEY (`source_branchcode`) + REFERENCES `branches` (`branchcode`) ON DELETE CASCADE ON UPDATE CASCADE + ) ENGINE=InnoDB DEFAULT CHARSET=utf8 + "); + $dbh->do(" + ALTER TABLE tmp_holdsqueue + ADD item_level_request tinyint(4) NOT NULL default 0 + "); + + print "Upgrade to $DBversion done (add hold_fill_targets table and a column to tmp_holdsqueue)\n"; + SetVersion($DBversion); +} + +$DBversion = '3.01.00.002'; +if ( C4::Context->preference('Version') < TransformToNum($DBversion) ) { + # use statistics where available + $dbh->do(" + ALTER TABLE statistics ADD KEY tmp_stats (type, itemnumber, borrowernumber) + "); + $dbh->do(" + UPDATE issues iss + SET issuedate = ( + SELECT max(datetime) + FROM statistics + WHERE type = 'issue' + AND itemnumber = iss.itemnumber + AND borrowernumber = iss.borrowernumber + ) + WHERE issuedate IS NULL; + "); + $dbh->do("ALTER TABLE statistics DROP KEY tmp_stats"); + + # default to last renewal date + $dbh->do(" + UPDATE issues + SET issuedate = lastreneweddate + WHERE issuedate IS NULL + and lastreneweddate IS NOT NULL + "); + + my $num_bad_issuedates = $dbh->selectrow_array("SELECT COUNT(*) FROM issues WHERE issuedate IS NULL"); + if ($num_bad_issuedates > 0) { + print STDERR "After the upgrade to $DBversion, there are still $num_bad_issuedates loan(s) with a NULL (blank) loan date. ", + "Please check the issues table in your database."; + } + print "Upgrade to $DBversion done (bug 2582: set null issues.issuedate to lastreneweddate)\n"; + SetVersion($DBversion); +} + +$DBversion = "3.01.00.003"; +if (C4::Context->preference("Version") < TransformToNum($DBversion)) { + $dbh->do("INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES('AllowRenewalLimitOverride', '0', 'if ON, allows renewal limits to be overridden on the circulation screen',NULL,'YesNo')"); + print "Upgrade to $DBversion done (add new syspref)\n"; + SetVersion ($DBversion); +} + +$DBversion = '3.01.00.004'; +if (C4::Context->preference("Version") < TransformToNum($DBversion)) { + $dbh->do("INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES ('OPACDisplayRequestPriority','0','Show patrons the priority level on holds in the OPAC','','YesNo')"); + print "Upgrade to $DBversion done (added OPACDisplayRequestPriority system preference)\n"; + SetVersion ($DBversion); +} + +$DBversion = '3.01.00.005'; +if (C4::Context->preference("Version") < TransformToNum($DBversion)) { + $dbh->do(" + INSERT INTO `letter` (module, code, name, title, content) + VALUES('reserves', 'HOLD', 'Hold Available for Pickup', 'Hold Available for Pickup at <>', 'Dear <> <>,\r\n\r\nYou have a hold available for pickup as of <>:\r\n\r\nTitle: <>\r\nAuthor: <>\r\nCopy: <>\r\nLocation: <>\r\n<>\r\n<>\r\n<>') + "); + $dbh->do("INSERT INTO `message_attributes` (message_attribute_id, message_name, takes_days) values(4, 'Hold Filled', 0)"); + $dbh->do("INSERT INTO `message_transports` (message_attribute_id, message_transport_type, is_digest, letter_module, letter_code) values(4, 'sms', 0, 'reserves', 'HOLD')"); + $dbh->do("INSERT INTO `message_transports` (message_attribute_id, message_transport_type, is_digest, letter_module, letter_code) values(4, 'email', 0, 'reserves', 'HOLD')"); + print "Upgrade to $DBversion done (Add letter for holds notifications)\n"; + SetVersion ($DBversion); +} + +$DBversion = '3.01.00.006'; +if (C4::Context->preference("Version") < TransformToNum($DBversion)) { + $dbh->do("ALTER TABLE `biblioitems` ADD KEY issn (issn)"); + print "Upgrade to $DBversion done (add index on biblioitems.issn)\n"; + SetVersion ($DBversion); +} + +$DBversion = "3.01.00.007"; +if (C4::Context->preference("Version") < TransformToNum($DBversion)) { + $dbh->do("UPDATE `systempreferences` SET options='70|10' WHERE variable='intranetmainUserblock'"); + $dbh->do("UPDATE `systempreferences` SET options='70|10' WHERE variable='intranetuserjs'"); + $dbh->do("UPDATE `systempreferences` SET options='70|10' WHERE variable='opacheader'"); + $dbh->do("UPDATE `systempreferences` SET options='70|10' WHERE variable='OpacMainUserBlock'"); + $dbh->do("UPDATE `systempreferences` SET options='70|10' WHERE variable='OpacNav'"); + $dbh->do("UPDATE `systempreferences` SET options='70|10' WHERE variable='opacuserjs'"); + $dbh->do("UPDATE `systempreferences` SET options='30|10', type='Textarea' WHERE variable='OAI-PMH:Set'"); + $dbh->do("UPDATE `systempreferences` SET options='50' WHERE variable='intranetstylesheet'"); + $dbh->do("UPDATE `systempreferences` SET options='50' WHERE variable='intranetcolorstylesheet'"); + $dbh->do("UPDATE `systempreferences` SET options='10' WHERE variable='globalDueDate'"); + $dbh->do("UPDATE `systempreferences` SET type='Integer' WHERE variable='numSearchResults'"); + $dbh->do("UPDATE `systempreferences` SET type='Integer' WHERE variable='OPACnumSearchResults'"); + $dbh->do("UPDATE `systempreferences` SET type='Integer' WHERE variable='ReservesMaxPickupDelay'"); + $dbh->do("UPDATE `systempreferences` SET type='Integer' WHERE variable='TransfersMaxDaysWarning'"); + $dbh->do("UPDATE `systempreferences` SET type='Integer' WHERE variable='StaticHoldsQueueWeight'"); + $dbh->do("UPDATE `systempreferences` SET type='Integer' WHERE variable='holdCancelLength'"); + $dbh->do("UPDATE `systempreferences` SET type='Integer' WHERE variable='XISBNDailyLimit'"); + $dbh->do("UPDATE `systempreferences` SET type='Float' WHERE variable='gist'"); + $dbh->do("UPDATE `systempreferences` SET type='Free' WHERE variable='BakerTaylorUsername'"); + $dbh->do("UPDATE `systempreferences` SET type='Free' WHERE variable='BakerTaylorPassword'"); + $dbh->do("UPDATE `systempreferences` SET type='Textarea', options='70|10' WHERE variable='ISBD'"); + $dbh->do("UPDATE `systempreferences` SET type='Textarea', options='70|10', explanation='Enter a specific hash for NoZebra indexes. Enter : \\\'indexname\\\' => \\\'100a,245a,500*\\\',\\\'index2\\\' => \\\'...\\\'' WHERE variable='NoZebraIndexes'"); + print "Upgrade to $DBversion done (fix display of many sysprefs)\n"; + SetVersion ($DBversion); +} + +$DBversion = '3.01.00.008'; +if (C4::Context->preference("Version") < TransformToNum($DBversion)) { + + $dbh->do("CREATE TABLE branch_transfer_limits ( + limitId int(8) NOT NULL auto_increment, + toBranch varchar(4) NOT NULL, + fromBranch varchar(4) NOT NULL, + itemtype varchar(4) NOT NULL, + PRIMARY KEY (limitId) + ) ENGINE=InnoDB DEFAULT CHARSET=utf8" + ); + + $dbh->do("INSERT INTO `systempreferences` ( `variable` , `value` , `options` , `explanation` , `type` ) VALUES ( 'UseBranchTransferLimits', '0', '', 'If ON, Koha will will use the rules defined in branch_transfer_limits to decide if an item transfer should be allowed.', 'YesNo')"); + + print "Upgrade to $DBversion done (added branch_transfer_limits table and UseBranchTransferLimits system preference)\n"; + SetVersion ($DBversion); +} + +$DBversion = "3.01.00.009"; +if (C4::Context->preference("Version") < TransformToNum($DBversion)) { + $dbh->do("ALTER TABLE permissions MODIFY `code` varchar(64) DEFAULT NULL"); + $dbh->do("ALTER TABLE user_permissions MODIFY `code` varchar(64) DEFAULT NULL"); + $dbh->do("INSERT INTO permissions (module_bit, code, description) VALUES ( 1, 'circulate_remaining_permissions', 'Remaining circulation permissions')"); + $dbh->do("INSERT INTO permissions (module_bit, code, description) VALUES ( 1, 'override_renewals', 'Override blocked renewals')"); + print "Upgrade to $DBversion done (added subpermissions for circulate permission)\n"; +} + +$DBversion = '3.01.00.010'; +if ( C4::Context->preference('Version') < TransformToNum($DBversion) ) { + $dbh->do("ALTER TABLE `borrower_attributes` MODIFY COLUMN `attribute` VARCHAR(64) DEFAULT NULL"); + $dbh->do("ALTER TABLE `borrower_attributes` MODIFY COLUMN `password` VARCHAR(64) DEFAULT NULL"); + print "Upgrade to $DBversion done (bug 2687: increase length of borrower attribute fields)\n"; + SetVersion ($DBversion); +} + +$DBversion = '3.01.00.011'; +if ( C4::Context->preference('Version') < TransformToNum($DBversion) ) { + + # Yes, the old value was ^M terminated. + my $bad_value = "function prepareEmailPopup(){\r\n if (!document.getElementById) return false;\r\n if (!document.getElementById('reserveemail')) return false;\r\n rsvlink = document.getElementById('reserveemail');\r\n rsvlink.onclick = function() {\r\n doReservePopup();\r\n return false;\r\n }\r\n}\r\n\r\nfunction doReservePopup(){\r\n}\r\n\r\nfunction prepareReserveList(){\r\n}\r\n\r\naddLoadEvent(prepareEmailPopup);\r\naddLoadEvent(prepareReserveList);"; + + my $intranetuserjs = C4::Context->preference('intranetuserjs'); + if ($intranetuserjs and $intranetuserjs eq $bad_value) { + my $sql = <<'END_SQL'; +UPDATE systempreferences +SET value = '' +WHERE variable = 'intranetuserjs' +END_SQL + $dbh->do($sql); + } + print "Upgrade to $DBversion done (removed bogus intranetuserjs syspref)\n"; + SetVersion($DBversion); +} + +$DBversion = "3.01.00.012"; +if (C4::Context->preference("Version") < TransformToNum($DBversion)) { + $dbh->do("INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES('AllowHoldPolicyOverride', '0', 'Allow staff to override hold policies when placing holds',NULL,'YesNo')"); + $dbh->do(" + CREATE TABLE `branch_item_rules` ( + `branchcode` varchar(10) NOT NULL, + `itemtype` varchar(10) NOT NULL, + `holdallowed` tinyint(1) default NULL, + PRIMARY KEY (`itemtype`,`branchcode`), + KEY `branch_item_rules_ibfk_2` (`branchcode`), + CONSTRAINT `branch_item_rules_ibfk_1` FOREIGN KEY (`itemtype`) REFERENCES `itemtypes` (`itemtype`) ON DELETE CASCADE ON UPDATE CASCADE, + CONSTRAINT `branch_item_rules_ibfk_2` FOREIGN KEY (`branchcode`) REFERENCES `branches` (`branchcode`) ON DELETE CASCADE ON UPDATE CASCADE + ) ENGINE=InnoDB DEFAULT CHARSET=utf8 + "); + $dbh->do(" + CREATE TABLE `default_branch_item_rules` ( + `itemtype` varchar(10) NOT NULL, + `holdallowed` tinyint(1) default NULL, + PRIMARY KEY (`itemtype`), + CONSTRAINT `default_branch_item_rules_ibfk_1` FOREIGN KEY (`itemtype`) REFERENCES `itemtypes` (`itemtype`) ON DELETE CASCADE ON UPDATE CASCADE + ) ENGINE=InnoDB DEFAULT CHARSET=utf8 + "); + $dbh->do(" + ALTER TABLE default_branch_circ_rules + ADD COLUMN holdallowed tinyint(1) NULL + "); + $dbh->do(" + ALTER TABLE default_circ_rules + ADD COLUMN holdallowed tinyint(1) NULL + "); + print "Upgrade to $DBversion done (Add tables and system preferences for holds policies)\n"; + SetVersion ($DBversion); +} + +$DBversion = '3.01.00.013'; +if (C4::Context->preference("Version") < TransformToNum($DBversion)) { + $dbh->do(" + CREATE TABLE item_circulation_alert_preferences ( + id int(11) AUTO_INCREMENT, + branchcode varchar(10) NOT NULL, + categorycode varchar(10) NOT NULL, + item_type varchar(10) NOT NULL, + notification varchar(16) NOT NULL, + PRIMARY KEY (id), + KEY (branchcode, categorycode, item_type, notification) + ) ENGINE=InnoDB DEFAULT CHARSET=utf8; + "); + + $dbh->do(q{ ALTER TABLE `message_queue` ADD metadata text DEFAULT NULL AFTER content; }); + $dbh->do(q{ ALTER TABLE `message_queue` ADD letter_code varchar(64) DEFAULT NULL AFTER metadata; }); + + $dbh->do(q{ + INSERT INTO `letter` (`module`, `code`, `name`, `title`, `content`) VALUES + ('circulation','CHECKIN','Item Check-in','Check-ins','The following items have been checked in:\r\n----\r\n<>\r\n----\r\nThank you.'); + }); + $dbh->do(q{ + INSERT INTO `letter` (`module`, `code`, `name`, `title`, `content`) VALUES + ('circulation','CHECKOUT','Item Checkout','Checkouts','The following items have been checked out:\r\n----\r\n<>\r\n----\r\nThank you for visiting <>.'); + }); + + $dbh->do(q{INSERT INTO message_attributes (message_attribute_id, message_name, takes_days) VALUES (5, 'Item Check-in', 0);}); + $dbh->do(q{INSERT INTO message_attributes (message_attribute_id, message_name, takes_days) VALUES (6, 'Item Checkout', 0);}); + + $dbh->do(q{INSERT INTO message_transports (message_attribute_id, message_transport_type, is_digest, letter_module, letter_code) VALUES (5, 'email', 0, 'circulation', 'CHECKIN');}); + $dbh->do(q{INSERT INTO message_transports (message_attribute_id, message_transport_type, is_digest, letter_module, letter_code) VALUES (5, 'sms', 0, 'circulation', 'CHECKIN');}); + $dbh->do(q{INSERT INTO message_transports (message_attribute_id, message_transport_type, is_digest, letter_module, letter_code) VALUES (6, 'email', 0, 'circulation', 'CHECKOUT');}); + $dbh->do(q{INSERT INTO message_transports (message_attribute_id, message_transport_type, is_digest, letter_module, letter_code) VALUES (6, 'sms', 0, 'circulation', 'CHECKOUT');}); + + print "Upgrade to $DBversion done (data for Email Checkout Slips project)\n"; + SetVersion ($DBversion); +} + +$DBversion = "3.01.00.014"; +if (C4::Context->preference("Version") < TransformToNum($DBversion)) { + $dbh->do("ALTER TABLE `branch_transfer_limits` CHANGE `itemtype` `itemtype` VARCHAR( 4 ) CHARACTER SET utf8 COLLATE utf8_general_ci NULL"); + $dbh->do("ALTER TABLE `branch_transfer_limits` ADD `ccode` VARCHAR( 10 ) NULL ;"); + $dbh->do("INSERT INTO `systempreferences` ( `variable` , `value` , `options` , `explanation` , `type` ) + VALUES ( + 'BranchTransferLimitsType', 'ccode', 'itemtype|ccode', 'When using branch transfer limits, choose whether to limit by itemtype or collection code.', 'Choice' + );"); + + print "Upgrade to $DBversion done ( Updated table for Branch Transfer Limits)\n"; + SetVersion ($DBversion); +} + +$DBversion = '3.01.00.015'; +if (C4::Context->preference("Version") < TransformToNum($DBversion)) { + $dbh->do("INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES ('SyndeticsClientCode', '0', 'Client Code for using Syndetics Solutions content','','free')"); + + $dbh->do("INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES ('SyndeticsEnabled', '0', 'Turn on Syndetics Enhanced Content','','YesNo')"); + + $dbh->do("INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES ('SyndeticsCoverImages', '0', 'Display Cover Images from Syndetics','','YesNo')"); + + $dbh->do("INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES ('SyndeticsTOC', '0', 'Display Table of Content information from Syndetics','','YesNo')"); + + $dbh->do("INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES ('SyndeticsSummary', '0', 'Display Summary Information from Syndetics','','YesNo')"); + + $dbh->do("INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES ('SyndeticsEditions', '0', 'Display Editions from Syndetics','','YesNo')"); + + $dbh->do("INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES ('SyndeticsExcerpt', '0', 'Display Excerpts and first chapters on OPAC from Syndetics','','YesNo')"); + + $dbh->do("INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES ('SyndeticsReviews', '0', 'Display Reviews on OPAC from Syndetics','','YesNo')"); + + $dbh->do("INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES ('SyndeticsAuthorNotes', '0', 'Display Notes about the Author on OPAC from Syndetics','','YesNo')"); + + $dbh->do("INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES ('SyndeticsAwards', '0', 'Display Awards on OPAC from Syndetics','','YesNo')"); + + $dbh->do("INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES ('SyndeticsSeries', '0', 'Display Series information on OPAC from Syndetics','','YesNo')"); + + $dbh->do("INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES ('SyndeticsCoverImageSize', 'MC', 'Choose the size of the Syndetics Cover Image to display on the OPAC detail page, MC is Medium, LC is Large','MC|LC','Choice')"); + + $dbh->do("INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES ('OPACAmazonCoverImages', '0', 'Display cover images on OPAC from Amazon Web Services','','YesNo')"); + + $dbh->do("INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES ('AmazonCoverImages', '0', 'Display Cover Images in Staff Client from Amazon Web Services','','YesNo')"); + + $dbh->do("UPDATE systempreferences SET variable='AmazonEnabled' WHERE variable = 'AmazonContent'"); + + $dbh->do("UPDATE systempreferences SET variable='OPACAmazonEnabled' WHERE variable = 'OPACAmazonContent'"); + + print "Upgrade to $DBversion done (added Syndetics Enhanced Content system preferences)\n"; + SetVersion ($DBversion); +} + +$DBversion = "3.01.00.016"; +if (C4::Context->preference("Version") < TransformToNum($DBversion)) { + $dbh->do("INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('Babeltheque',0,'Turn ON Babeltheque content - See babeltheque.com to subscribe to this service','','YesNo')"); + print "Upgrade to $DBversion done (Added Babeltheque syspref)\n"; + SetVersion ($DBversion); +} + +$DBversion = "3.01.00.017"; +if (C4::Context->preference("Version") < TransformToNum($DBversion)) { + $dbh->do("ALTER TABLE `subscription` ADD `staffdisplaycount` VARCHAR(10) NULL;"); + $dbh->do("ALTER TABLE `subscription` ADD `opacdisplaycount` VARCHAR(10) NULL;"); + $dbh->do("INSERT INTO `systempreferences` ( `variable` , `value` , `options` , `explanation` , `type` ) + VALUES ( + 'StaffSerialIssueDisplayCount', '3', '', 'Number of serial issues to display per subscription in the Staff client', 'Integer' + );"); + $dbh->do("INSERT INTO `systempreferences` ( `variable` , `value` , `options` , `explanation` , `type` ) + VALUES ( + 'OPACSerialIssueDisplayCount', '3', '', 'Number of serial issues to display per subscription in the OPAC', 'Integer' + );"); + + print "Upgrade to $DBversion done ( Updated table for Serials Display)\n"; + SetVersion ($DBversion); +} + +$DBversion = "3.01.00.018"; +if (C4::Context->preference("Version") < TransformToNum($DBversion)) { + $dbh->do("ALTER TABLE deletedborrowers ADD `smsalertnumber` varchar(50) default NULL"); + print "Upgrade to $DBversion done (added deletedborrowers.smsalertnumber, missed in 3.00.00.091)\n"; + SetVersion ($DBversion); +} + +$DBversion = "3.01.00.019"; +if (C4::Context->preference("Version") < TransformToNum($DBversion)) { + $dbh->do("INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('OPACShowCheckoutName','0','Displays in the OPAC the name of patron who has checked out the material. WARNING: Most sites should leave this off. It is intended for corporate or special sites which need to track who has the item.','','YesNo')"); + print "Upgrade to $DBversion done (adding OPACShowCheckoutName systempref)\n"; + SetVersion ($DBversion); +} + +$DBversion = "3.01.00.020"; +if (C4::Context->preference("Version") < TransformToNum($DBversion)) { + $dbh->do("INSERT INTO systempreferences (variable,value,explanation,options,type)VALUES('LibraryThingForLibrariesID','','See:http://librarything.com/forlibraries/','','free')"); + $dbh->do("INSERT INTO systempreferences (variable,value,explanation,options,type)VALUES('LibraryThingForLibrariesEnabled','0','Enable or Disable Library Thing for Libraries Features','','YesNo')"); + $dbh->do("INSERT INTO systempreferences (variable,value,explanation,options,type)VALUES('LibraryThingForLibrariesTabbedView','0','Put LibraryThingForLibraries Content in Tabs.','','YesNo')"); + print "Upgrade to $DBversion done (adding LibraryThing for Libraries sysprefs)\n"; + SetVersion ($DBversion); +} + +$DBversion = "3.01.00.021"; +if (C4::Context->preference("Version") < TransformToNum($DBversion)) { + my $enable_reviews = C4::Context->preference('OPACAmazonEnabled') ? '1' : '0'; + $dbh->do("INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES ('OPACAmazonReviews', '$enable_reviews', 'Display Amazon readers reviews on OPAC','','YesNo')"); + print "Upgrade to $DBversion done (adding OPACAmazonReviews syspref)\n"; + SetVersion ($DBversion); +} + +$DBversion = '3.01.00.022'; +if ( C4::Context->preference('Version') < TransformToNum($DBversion) ) { + $dbh->do("ALTER TABLE `labels_conf` MODIFY COLUMN `formatstring` mediumtext DEFAULT NULL"); + print "Upgrade to $DBversion done (bug 2945: increase size of labels_conf.formatstring)\n"; + SetVersion ($DBversion); +} + +$DBversion = '3.01.00.023'; +if ( C4::Context->preference('Version') < TransformToNum($DBversion) ) { + $dbh->do("ALTER TABLE biblioitems MODIFY COLUMN isbn VARCHAR(30) DEFAULT NULL"); + $dbh->do("ALTER TABLE deletedbiblioitems MODIFY COLUMN isbn VARCHAR(30) DEFAULT NULL"); + $dbh->do("ALTER TABLE import_biblios MODIFY COLUMN isbn VARCHAR(30) DEFAULT NULL"); + $dbh->do("ALTER TABLE suggestions MODIFY COLUMN isbn VARCHAR(30) DEFAULT NULL"); + print "Upgrade to $DBversion done (bug 2765: increase width of isbn column in several tables)\n"; + SetVersion ($DBversion); +} + +$DBversion = "3.01.00.024"; +if (C4::Context->preference("Version") < TransformToNum($DBversion)) { + $dbh->do("ALTER TABLE labels MODIFY COLUMN batch_id int(10) NOT NULL default 1;"); + print "Upgrade to $DBversion done (change labels.batch_id from varchar to int)\n"; + SetVersion ($DBversion); +} + +$DBversion = '3.01.00.025'; +if (C4::Context->preference("Version") < TransformToNum($DBversion)) { + $dbh->do("INSERT INTO `systempreferences` ( `variable` , `value` , `options` , `explanation` , `type` ) VALUES ( 'ceilingDueDate', '', '', 'If set, date due will not be past this date. Enter date according to the dateformat System Preference', 'free')"); + + print "Upgrade to $DBversion done (added ceilingDueDate system preference)\n"; + SetVersion ($DBversion); +} + +$DBversion = '3.01.00.026'; +if (C4::Context->preference("Version") < TransformToNum($DBversion)) { + $dbh->do("INSERT INTO `systempreferences` ( `variable` , `value` , `options` , `explanation` , `type` ) VALUES ( 'numReturnedItemsToShow', '20', '', 'Number of returned items to show on the check-in page', 'Integer')"); + + print "Upgrade to $DBversion done (added numReturnedItemsToShow system preference)\n"; + SetVersion ($DBversion); +} + +$DBversion = '3.01.00.027'; +if (C4::Context->preference("Version") < TransformToNum($DBversion)) { + $dbh->do("ALTER TABLE zebraqueue CHANGE `biblio_auth_number` `biblio_auth_number` bigint(20) unsigned NOT NULL default 0"); + print "Upgrade to $DBversion done (Increased size of zebraqueue biblio_auth_number to address bug 3148.)\n"; + SetVersion ($DBversion); +} + +$DBversion = '3.01.00.028'; +if (C4::Context->preference("Version") < TransformToNum($DBversion)) { + my $enable_reviews = C4::Context->preference('AmazonEnabled') ? '1' : '0'; + $dbh->do("INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES ('AmazonReviews', '$enable_reviews', 'Display Amazon reviews on staff interface','','YesNo')"); + print "Upgrade to $DBversion done (added AmazonReviews)\n"; + SetVersion ($DBversion); +} + +$DBversion = '3.01.00.029'; +if (C4::Context->preference("Version") < TransformToNum($DBversion)) { + $dbh->do(q( UPDATE language_rfc4646_to_iso639 + SET iso639_2_code = 'spa' + WHERE rfc4646_subtag = 'es' + AND iso639_2_code = 'rus' ) + ); + print "Upgrade to $DBversion done (fixed bug 2599: using Spanish search limit retrieves Russian results)\n"; + SetVersion ($DBversion); +} + +$DBversion = "3.01.00.030"; +if (C4::Context->preference("Version") < TransformToNum($DBversion)) { + $dbh->do("INSERT INTO `systempreferences` ( `variable` , `value` , `options` , `explanation` , `type` ) VALUES ( 'AllowNotForLoanOverride', '0', '', 'If ON, Koha will allow the librarian to loan a not for loan item.', 'YesNo')"); + print "Upgrade to $DBversion done (added AllowNotForLoanOverride system preference)\n"; + SetVersion ($DBversion); +} + +$DBversion = "3.01.00.031"; +if (C4::Context->preference("Version") < TransformToNum($DBversion)) { + $dbh->do("ALTER TABLE branch_transfer_limits + MODIFY toBranch varchar(10) NOT NULL, + MODIFY fromBranch varchar(10) NOT NULL, + MODIFY itemtype varchar(10) NULL"); + print "Upgrade to $DBversion done (fix column widths in branch_transfer_limits)\n"; + SetVersion ($DBversion); +} + +$DBversion = "3.01.00.032"; +if (C4::Context->preference("Version") < TransformToNum($DBversion)) { + $dbh->do(<preference("Version") < TransformToNum($DBversion)) { + $dbh->do(q/ + ALTER TABLE borrower_message_preferences + MODIFY borrowernumber int(11) default NULL, + ADD categorycode varchar(10) default NULL AFTER borrowernumber, + ADD KEY `categorycode` (`categorycode`), + ADD CONSTRAINT `borrower_message_preferences_ibfk_3` + FOREIGN KEY (`categorycode`) REFERENCES `categories` (`categorycode`) + ON DELETE CASCADE ON UPDATE CASCADE + /); + print "Upgrade to $DBversion done (DB changes to allow patron category defaults for messaging preferences)\n"; + SetVersion ($DBversion); +} + +$DBversion = "3.01.00.034"; +if (C4::Context->preference("Version") < TransformToNum($DBversion)) { + $dbh->do("ALTER TABLE `subscription` ADD COLUMN `graceperiod` INT(11) NOT NULL default '0';"); + print "Upgrade to $DBversion done (Adding graceperiod column to subscription table)\n"; + SetVersion ($DBversion); +} + +$DBversion = '3.01.00.035'; +if (C4::Context->preference("Version") < TransformToNum($DBversion)) { + $dbh->do(q{ ALTER TABLE `subscription` ADD location varchar(80) NULL DEFAULT '' AFTER callnumber; }); + print "Upgrade to $DBversion done (Adding location to subscription table)\n"; + SetVersion ($DBversion); +} + +$DBversion = '3.01.00.036'; +if (C4::Context->preference("Version") < TransformToNum($DBversion)) { + $dbh->do("UPDATE systempreferences SET explanation = 'Choose the default detail view in the staff interface; choose between normal, labeled_marc, marc or isbd' + WHERE variable = 'IntranetBiblioDefaultView' + AND explanation = 'IntranetBiblioDefaultView'"); + $dbh->do("UPDATE systempreferences SET type = 'Choice', options = 'normal|marc|isbd|labeled_marc' + WHERE variable = 'IntranetBiblioDefaultView'"); + $dbh->do("INSERT INTO systempreferences (variable,value,explanation,options,type)VALUES('viewISBD','1','Allow display of ISBD view of bibiographic records','','YesNo')"); + $dbh->do("INSERT INTO systempreferences (variable,value,explanation,options,type)VALUES('viewLabeledMARC','0','Allow display of labeled MARC view of bibiographic records','','YesNo')"); + $dbh->do("INSERT INTO systempreferences (variable,value,explanation,options,type)VALUES('viewMARC','1','Allow display of MARC view of bibiographic records','','YesNo')"); + print "Upgrade to $DBversion done (new viewISBD, viewLabeledMARC, viewMARC sysprefs and tweak IntranetBiblioDefaultView)\n"; + SetVersion ($DBversion); +} + +$DBversion = '3.01.00.037'; +if (C4::Context->preference("Version") < TransformToNum($DBversion)) { + $dbh->do('ALTER TABLE authorised_values ADD KEY `lib` (`lib`)'); + $dbh->do("INSERT INTO systempreferences (variable,value,explanation,options,type)VALUES('FilterBeforeOverdueReport','0','Do not run overdue report until filter selected','','YesNo')"); + SetVersion ($DBversion); + print "Upgrade to $DBversion done (added FilterBeforeOverdueReport syspref and new index on authorised_values)\n"; +} + +$DBversion = '3.01.00.038'; +if (C4::Context->preference("Version") < TransformToNum($DBversion)) { + $dbh->do('ALTER TABLE issuingrules DROP FOREIGN KEY issuingrules_ibfk_1'); + $dbh->do('ALTER TABLE issuingrules DROP FOREIGN KEY issuingrules_ibfk_2'); + SetVersion ($DBversion); + print "Upgrade to $DBversion done (deleting contraints in issuingrules)\n"; +} + +$DBversion = '3.01.00.039'; +if (C4::Context->preference("Version") < TransformToNum($DBversion)) { + $dbh->do('ALTER TABLE issuingrules ADD COLUMN `renewalsallowed` smallint(6) NOT NULL default "0" AFTER `issuelength`;'); + $sth = $dbh->prepare("SELECT itemtype, renewalsallowed FROM itemtypes"); + $sth->execute(); + + my $sthupd = $dbh->prepare("UPDATE issuingrules SET renewalsallowed = ? WHERE itemtype = ?"); + + while(my $row = $sth->fetchrow_hashref){ + $sthupd->execute($row->{renewalsallowed}, $row->{itemtype}); + } + + $dbh->do('ALTER TABLE itemtypes DROP COLUMN `renewalsallowed`;'); + + SetVersion ($DBversion); + print "Upgrade to $DBversion done (Moving allowed renewals from itemtypes to issuingrule)\n"; +} + +$DBversion = '3.01.00.040'; +if (C4::Context->preference("Version") < TransformToNum($DBversion)) { + $dbh->do('ALTER TABLE issuingrules ADD COLUMN `reservesallowed` smallint(6) NOT NULL default "0" AFTER `renewalsallowed`;'); + + my $maxreserves = C4::Context->preference('maxreserves'); + $sth = $dbh->prepare('UPDATE issuingrules SET reservesallowed = ?;'); + $sth->execute($maxreserves); + + $dbh->do('DELETE FROM systempreferences WHERE variable = "maxreserves";'); + + $dbh->do("INSERT INTO systempreferences (variable,value, options, explanation, type) VALUES('ReservesControlBranch','PatronLibrary','ItemHomeLibrary|PatronLibrary','Branch checked for members reservations rights','Choice')"); + + SetVersion ($DBversion); + print "Upgrade to $DBversion done (Moving max allowed reserves from system preference to issuingrule)\n"; +} + +$DBversion = "3.01.00.041"; +if (C4::Context->preference("Version") < TransformToNum($DBversion)) { + $dbh->do("INSERT INTO permissions (module_bit, code, description) VALUES ( 13, 'batchmod', 'Perform batch modification of items')"); + $dbh->do("INSERT INTO permissions (module_bit, code, description) VALUES ( 13, 'batchdel', 'Perform batch deletion of items')"); + print "Upgrade to $DBversion done (added permissions for batch modification and deletion)\n"; +} + + +$DBversion = '3.01.00.042'; +if (C4::Context->preference("Version") < TransformToNum($DBversion)) { + $dbh->do("INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('OPACFineNoRenewals','99999','Fine Limit above which user canmot renew books via OPAC','','Integer')"); + SetVersion ($DBversion); + print "Upgrade to $DBversion done (added OPACFineNoRenewals syspref)\n"; +} + +$DBversion = '3.01.00.043'; +if (C4::Context->preference("Version") < TransformToNum($DBversion)) { + $dbh->do('ALTER TABLE items ADD COLUMN permanent_location VARCHAR(80) DEFAULT NULL AFTER location'); + $dbh->do('UPDATE items SET permanent_location = location'); + $dbh->do("INSERT INTO `systempreferences` ( `variable` , `value` , `options` , `explanation` , `type` ) VALUES ( 'NewItemsDefaultLocation', '', '', 'If set, all new items will have a location of the given Location Code ( Authorized Value type LOC )', '')"); + $dbh->do("INSERT INTO `systempreferences` ( `variable` , `value` , `options` , `explanation` , `type` ) VALUES ( 'InProcessingToShelvingCart', '0', '', 'If set, when any item with a location code of PROC is ''checked in'', it''s location code will be changed to CART.', 'YesNo')"); + $dbh->do("INSERT INTO `systempreferences` ( `variable` , `value` , `options` , `explanation` , `type` ) VALUES ( 'ReturnToShelvingCart', '0', '', 'If set, when any item is ''checked in'', it''s location code will be changed to CART.', 'YesNo')"); + SetVersion ($DBversion); + print "Upgrade to $DBversion done (amended Item added NewItemsDefaultLocation, InProcessingToShelvingCart, ReturnToShelvingCart sysprefs)\n"; +} + +$DBversion = '3.01.00.044'; +if (C4::Context->preference("Version") < TransformToNum($DBversion)) { + $dbh->do("INSERT INTO systempreferences (variable,value,explanation,options,type)VALUES( 'DisplayClearScreenButton', '0', 'If set to yes, a clear screen button will appear on the circulation page.', 'If set to yes, a clear screen button will appear on the circulation page.', 'YesNo')"); + SetVersion ($DBversion); + print "Upgrade to $DBversion done (added DisplayClearScreenButton system preference)\n"; +} + +$DBversion = '3.01.00.045'; +if (C4::Context->preference("Version") < TransformToNum($DBversion)) { + $dbh->do("INSERT INTO systempreferences (variable,value,options,explanation,type)VALUES('HidePatronName', '0', '', 'If this is switched on, patron''s cardnumber will be shown instead of their name on the holds and catalog screens', 'YesNo')"); + SetVersion ($DBversion); + print "Upgrade to $DBversion done (added a preference to hide the patrons name in the staff catalog)"; +} + +$DBversion = "3.01.00.046"; +if (C4::Context->preference("Version") < TransformToNum($DBversion)) { + # update borrowers table + # + $dbh->do("ALTER TABLE borrowers ADD `country` text AFTER zipcode"); + $dbh->do("ALTER TABLE borrowers ADD `B_country` text AFTER B_zipcode"); + $dbh->do("ALTER TABLE deletedborrowers ADD `country` text AFTER zipcode"); + $dbh->do("ALTER TABLE deletedborrowers ADD `B_country` text AFTER B_zipcode"); + print "Upgrade to $DBversion done (add country and B_country to borrowers)\n"; + SetVersion ($DBversion); +} + +$DBversion = '3.01.00.047'; +if (C4::Context->preference("Version") < TransformToNum($DBversion)) { + $dbh->do("ALTER TABLE items MODIFY itemcallnumber varchar(255);"); + $dbh->do("ALTER TABLE deleteditems MODIFY itemcallnumber varchar(255);"); + $dbh->do("ALTER TABLE tmp_holdsqueue MODIFY itemcallnumber varchar(255);"); + SetVersion ($DBversion); + print " Upgrade to $DBversion done (bug 2761: change max length of itemcallnumber to 255 from 30)\n"; +} + +$DBversion = '3.01.00.048'; +if (C4::Context->preference("Version") < TransformToNum($DBversion)) { + $dbh->do("UPDATE userflags SET flagdesc='View Catalog (Librarian Interface)' WHERE bit=2;"); + $dbh->do("UPDATE userflags SET flagdesc='Edit Catalog (Modify bibliographic/holdings data)' WHERE bit=9;"); + $dbh->do("UPDATE userflags SET flagdesc='Allow to edit authorities' WHERE bit=14;"); + $dbh->do("UPDATE userflags SET flagdesc='Allow to access to the reports module' WHERE bit=16;"); + $dbh->do("UPDATE userflags SET flagdesc='Allow to manage serials subscriptions' WHERE bit=15;"); + SetVersion ($DBversion); + print " Upgrade to $DBversion done (bug 2611: fix spelling/capitalization in permission flag descriptions)\n"; +} + +$DBversion = '3.01.00.049'; +if (C4::Context->preference("Version") < TransformToNum($DBversion)) { + $dbh->do("UPDATE permissions SET description = 'Perform inventory (stocktaking) of your catalog' WHERE code = 'inventory';"); + SetVersion ($DBversion); + print "Upgrade to $DBversion done (bug 2611: changed catalogue to catalog per the standard)\n"; +} + +$DBversion = '3.01.00.050'; +if (C4::Context->preference("Version") < TransformToNum($DBversion)) { + $dbh->do("INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES ('OPACSearchForTitleIn','
  • \nOther Libraries (WorldCat)
  • \n
  • \nOther Databases (Google Scholar)
  • \n
  • \nOnline Stores (Bookfinder.com)
  • ','Enter the HTML that will appear in the ''Search for this title in'' box on the detail page in the OPAC. Enter TITLE, AUTHOR, or ISBN in place of their respective variables in the URL. Leave blank to disable ''More Searches'' menu.','70|10','Textarea');"); + SetVersion ($DBversion); + print "Upgrade to $DBversion done (bug 1934: Add OPACSearchForTitleIn syspref)\n"; +} + +$DBversion = '3.01.00.051'; +if (C4::Context->preference("Version") < TransformToNum($DBversion)) { + $dbh->do("UPDATE systempreferences SET explanation='Fine limit above which user cannot renew books via OPAC' WHERE variable='OPACFineNoRenewals';"); + $dbh->do("UPDATE systempreferences SET explanation='If set to ON, a clear screen button will appear on the circulation page.' WHERE variable='DisplayClearScreenButton';"); + SetVersion ($DBversion); + print "Upgrade to $DBversion done (fixed typos in new sysprefs)\n"; +} + +$DBversion = '3.01.00.052'; +if (C4::Context->preference("Version") < TransformToNum($DBversion)) { + $dbh->do('ALTER TABLE deleteditems ADD COLUMN permanent_location VARCHAR(80) DEFAULT NULL AFTER location'); + SetVersion ($DBversion); + print "Upgrade to $DBversion done (bug 3481: add permanent_location column to deleteditems)\n"; +} + +$DBversion = '3.01.00.053'; +if (C4::Context->preference("Version") < TransformToNum($DBversion)) { + my $upgrade_script = C4::Context->config("intranetdir") . "/installer/data/mysql/labels_upgrade.pl"; + system("perl $upgrade_script"); + print "Upgrade to $DBversion done (Migrated labels tables and data to new schema.) NOTE: All existing label batches have been assigned to the first branch in the list of branches. This is ONLY true of migrated label batches.\n"; + SetVersion ($DBversion); +} + +$DBversion = '3.01.00.054'; +if (C4::Context->preference("Version") < TransformToNum($DBversion)) { + $dbh->do("ALTER TABLE borrowers ADD `B_address2` text AFTER B_address"); + $dbh->do("ALTER TABLE borrowers ADD `altcontactcountry` text AFTER altcontactzipcode"); + $dbh->do("ALTER TABLE deletedborrowers ADD `B_address2` text AFTER B_address"); + $dbh->do("ALTER TABLE deletedborrowers ADD `altcontactcountry` text AFTER altcontactzipcode"); + SetVersion ($DBversion); + print "Upgrade to $DBversion done (bug 1600, bug 3454: add altcontactcountry and B_address2 to borrowers and deletedborrowers)\n"; +} + +$DBversion = '3.01.00.055'; +if (C4::Context->preference("Version") < TransformToNum($DBversion)) { + $dbh->do(qq|UPDATE systempreferences set explanation='Enter the HTML that will appear in the ''Search for this title in'' box on the detail page in the OPAC. Enter {TITLE}, {AUTHOR}, or {ISBN} in place of their respective variables in the URL. Leave blank to disable ''More Searches'' menu.', value='
  • Other Libraries (WorldCat)
  • \n
  • Other Databases (Google Scholar)
  • \n
  • Online Stores (Bookfinder.com)
  • ' WHERE variable='OPACSearchForTitleIn'|); + SetVersion ($DBversion); + print "Upgrade to $DBversion done (changed OPACSearchForTitleIn per requests in bug 1934)\n"; +} + +$DBversion = '3.01.00.056'; +if (C4::Context->preference("Version") < TransformToNum($DBversion)) { + $dbh->do("INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES ('OPACPatronDetails','1','If OFF the patron details tab in the OPAC is disabled.','','YesNo');"); + SetVersion ($DBversion); + print "Upgrade to $DBversion done (Bug 1172 : Add OPACPatronDetails syspref)\n"; +} + +$DBversion = '3.01.00.057'; +if (C4::Context->preference("Version") < TransformToNum($DBversion)) { + $dbh->do("INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES ('OPACFinesTab','1','If OFF the patron fines tab in the OPAC is disabled.','','YesNo');"); + SetVersion ($DBversion); + print "Upgrade to $DBversion done (Bug 2576 : Add OPACFinesTab syspref)\n"; +} + +$DBversion = '3.01.00.058'; +if (C4::Context->preference("Version") < TransformToNum($DBversion)) { + $dbh->do("ALTER TABLE `language_subtag_registry` ADD `id` INT( 11 ) NOT NULL AUTO_INCREMENT PRIMARY KEY;"); + $dbh->do("ALTER TABLE `language_rfc4646_to_iso639` ADD `id` INT( 11 ) NOT NULL AUTO_INCREMENT PRIMARY KEY;"); + $dbh->do("ALTER TABLE `language_descriptions` ADD `id` INT( 11 ) NOT NULL AUTO_INCREMENT PRIMARY KEY;"); + SetVersion ($DBversion); + print "Upgrade to $DBversion done (Added primary keys to language tables)\n"; +} + +$DBversion = '3.01.00.059'; +if (C4::Context->preference("Version") < TransformToNum($DBversion)) { + $dbh->do("INSERT INTO systempreferences (variable,value,options,explanation,type)VALUES('DisplayOPACiconsXSLT', '1', '', 'If ON, displays the format, audience, type icons in XSLT MARC21 results and display pages.', 'YesNo')"); + SetVersion ($DBversion); + print "Upgrade to $DBversion done (added DisplayOPACiconsXSLT sysprefs)\n"; +} + +$DBversion = '3.01.00.060'; +if (C4::Context->preference("Version") < TransformToNum($DBversion)) { + $dbh->do("INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES('AllowAllMessageDeletion','0','Allow any Library to delete any message','','YesNo');"); + $dbh->do('DROP TABLE IF EXISTS messages'); + $dbh->do("CREATE TABLE messages ( `message_id` int(11) NOT NULL auto_increment, + `borrowernumber` int(11) NOT NULL, + `branchcode` varchar(4) default NULL, + `message_type` varchar(1) NOT NULL, + `message` text NOT NULL, + `message_date` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, + PRIMARY KEY (`message_id`) + ) ENGINE=InnoDB DEFAULT CHARSET=utf8"); + + print "Upgrade to $DBversion done ( Added AllowAllMessageDeletion syspref and messages table )\n"; + SetVersion ($DBversion); +} + +$DBversion = '3.01.00.061'; +if (C4::Context->preference("Version") < TransformToNum($DBversion)) { + $dbh->do("INSERT INTO systempreferences (variable,value,explanation,options,type)VALUES('ShowPatronImageInWebBasedSelfCheck', '0', 'If ON, displays patron image when a patron uses web-based self-checkout', '', 'YesNo')"); + print "Upgrade to $DBversion done ( Added ShowPatronImageInWebBasedSelfCheck system preference )\n"; + SetVersion ($DBversion); +} + +$DBversion = "3.01.00.062"; +if (C4::Context->preference("Version") < TransformToNum($DBversion)) { + $dbh->do("INSERT INTO permissions (module_bit, code, description) VALUES ( 13, 'manage_csv_profiles', 'Manage CSV export profiles')"); + print "Upgrade to $DBversion done (added permissions for csv export profiles)\n"; +} + +=item + +Acquisitions update + +=cut + +$DBversion = "3.01.00.100"; +if (C4::Context->preference("Version") < TransformToNum($DBversion)) { + $dbh->do("INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES('OpacPrivacy', '0', 'if ON, allows patrons to define their privacy rules (reading history)',NULL,'YesNo')"); + # create a new syspref for the 'Mr anonymous' patron + $dbh->do("INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES('AnonymousPatron', '0', \"Set the identifier (borrowernumber) of the 'Mister anonymous' patron. Used for Suggestion and reading history privacy\",NULL,'')"); + # fill AnonymousPatron with AnonymousSuggestion value (copy) + my $sth=$dbh->prepare("SELECT value FROM systempreferences WHERE variable='AnonSuggestions'"); + $sth->execute; + my ($value) = $sth->fetchrow(); + $dbh->do("UPDATE systempreferences SET value='$value' WHERE variable='AnonymousPatron'"); + # set AnonymousSuggestion do YesNo + # 1st, set the value (1/True if it had a borrowernumber) + $dbh->do("UPDATE systempreferences SET value=1 WHERE variable='AnonSuggestions' AND value>0"); + # 2nd, change the type to Choice + $dbh->do("UPDATE systempreferences SET type='YesNo' WHERE variable='AnonSuggestions'"); + # borrower reading record privacy : 0 : forever, 1 : laws, 2 : don't keep at all + $dbh->do("ALTER TABLE `borrowers` ADD `privacy` INTEGER NOT NULL DEFAULT 1;"); + print "Upgrade to $DBversion done (add new syspref and column in borrowers)\n"; + SetVersion ($DBversion); +} + +$DBversion = '3.01.00.101'; +if (C4::Context->preference("Version") < TransformToNum($DBversion)) { + $dbh->do(<<'END_SQL'); +CREATE TABLE IF NOT EXISTS `aqcontract` ( + `contractnumber` int(11) NOT NULL auto_increment, + `contractstartdate` date default NULL, + `contractenddate` date default NULL, + `contractname` varchar(50) default NULL, + `contractdescription` mediumtext, + `booksellerid` int(11) not NULL, + PRIMARY KEY (`contractnumber`), + CONSTRAINT `booksellerid_fk1` FOREIGN KEY (`booksellerid`) + REFERENCES `aqbooksellers` (`id`) ON DELETE CASCADE ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ; +END_SQL + print "Upgrade to $DBversion done (adding aqcontract table)\n"; + SetVersion ($DBversion); +} + +$DBversion = '3.01.00.102'; +if (C4::Context->preference("Version") < TransformToNum($DBversion)) { + $dbh->do("ALTER TABLE `aqbasket` ADD COLUMN `basketname` varchar(50) default NULL AFTER `basketno`"); + $dbh->do("ALTER TABLE `aqbasket` ADD COLUMN `note` mediumtext AFTER `basketname`"); + $dbh->do("ALTER TABLE `aqbasket` ADD COLUMN `booksellernote` mediumtext AFTER `note`"); + $dbh->do("ALTER TABLE `aqbasket` ADD COLUMN `contractnumber` int(11) AFTER `booksellernote`"); + $dbh->do("ALTER TABLE `aqbasket` ADD FOREIGN KEY (`contractnumber`) REFERENCES `aqcontract` (`contractnumber`)"); + print "Upgrade to $DBversion done (edit aqbasket table done)\n"; + SetVersion ($DBversion); +} + +$DBversion = '3.01.00.103'; +if (C4::Context->preference("Version") < TransformToNum($DBversion)) { + $dbh->do("ALTER TABLE `aqorders` ADD COLUMN `uncertainprice` tinyint(1)"); + + print "Upgrade to $DBversion done (adding uncertainprices)\n"; + SetVersion ($DBversion); +} + +$DBversion = '3.01.00.104'; +if (C4::Context->preference("Version") < TransformToNum($DBversion)) { + $dbh->do("CREATE TABLE IF NOT EXISTS `aqbasketgroups` ( + `id` int(11) NOT NULL auto_increment, + `name` varchar(50) default NULL, + `closed` tinyint(1) default NULL, + `booksellerid` int(11) NOT NULL, + PRIMARY KEY (`id`), + KEY `booksellerid` (`booksellerid`), + CONSTRAINT `aqbasketgroups_ibfk_1` FOREIGN KEY (`booksellerid`) REFERENCES `aqbooksellers` (`id`) ON UPDATE CASCADE ON DELETE CASCADE + ) ENGINE=InnoDB DEFAULT CHARSET=utf8;"); + $dbh->do("ALTER TABLE aqbasket ADD COLUMN `basketgroupid` int(11)"); + $dbh->do("ALTER TABLE aqbasket ADD FOREIGN KEY (`basketgroupid`) REFERENCES `aqbasketgroups` (`id`) ON UPDATE CASCADE"); + $dbh->do("INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES ('pdfformat','pdfformat/example.pl','Controls what script is used for printing (basketgroups)','','free')"); + print "Upgrade to $DBversion done (adding basketgroups)\n"; + SetVersion ($DBversion); +} + +$DBversion = '3.01.00.105'; +if (C4::Context->preference("Version") < TransformToNum($DBversion)) { + $dbh->do("DROP TABLE IF EXISTS `aqbudgetperiods` "); + $dbh->do(qq| + CREATE TABLE `aqbudgetperiods` ( + `budget_period_id` int(11) NOT NULL auto_increment, + `budget_period_startdate` date NOT NULL, + `budget_period_enddate` date NOT NULL, + `budget_period_active` tinyint(1) default '0', + `budget_period_description` mediumtext, + `budget_period_locked` tinyint(1) default NULL, + `sort1_authcat` varchar(10) default NULL, + `sort2_authcat` varchar(10) default NULL, + PRIMARY KEY (`budget_period_id`) + ) ENGINE=InnoDB DEFAULT CHARSET=utf8 |); + + $dbh->do(< AQBUDGETS IMPORT JUST YET, +# BUT A NEW CLEAN AQBUDGETS TABLE CREATE FOR NOW.. +# DROP TABLE IF EXISTS `aqbudget`; +#CREATE TABLE `aqbudget` ( +# `bookfundid` varchar(10) NOT NULL default ', +# `startdate` date NOT NULL default 0, +# `enddate` date default NULL, +# `budgetamount` decimal(13,2) default NULL, +# `aqbudgetid` tinyint(4) NOT NULL auto_increment, +# `branchcode` varchar(10) default NULL, + DropAllForeignKeys('aqbudget'); + #$dbh->do("drop table aqbudget;"); + + + $dbh->do(<selectcol_arrayref(<do(<do(<do(<do(<do(<prepare(qq|SELECT budget_period_id from aqbudgetperiods where budget_period_startdate=? and budget_period_enddate=?|); + my $query_bookfund= $dbh->prepare(qq|SELECT * from aqbookfund where bookfundid=?|); + my $selectbudgets=$dbh->prepare(qq|SELECT * from aqbudgets|); + my $updatebudgets=$dbh->prepare(qq|UPDATE aqbudgets SET budget_period_id= ? , budget_name=?, budget_branchcode=? where budget_id=?|); + $selectbudgets->execute; + while (my $databudget=$selectbudgets->fetchrow_hashref){ + $query_period->execute ($$databudget{startdate},$$databudget{enddate}); + my ($budgetperiodid)=$query_period->fetchrow; + $query_bookfund->execute ($$databudget{budget_code}); + my $databf=$query_bookfund->fetchrow_hashref; + my $branchcode=$$databudget{budget_branchcode}||$$databf{branchcode}; + $updatebudgets->execute($budgetperiodid,$$databf{bookfundname},$branchcode,$$databudget{budget_id}); } + $dbh->do(<do("DROP TABLE aqbookfund "); + + $dbh->do("DROP TABLE IF EXISTS `aqbudgets_planning` "); + $dbh->do("CREATE TABLE `aqbudgets_planning` ( + `plan_id` int(11) NOT NULL auto_increment, + `budget_id` int(11) NOT NULL, + `budget_period_id` int(11) NOT NULL, + `estimated_amount` decimal(28,6) default NULL, + `authcat` varchar(30) NOT NULL, + `authvalue` varchar(30) NOT NULL, + `display` tinyint(1) DEFAULT 1, + PRIMARY KEY (`plan_id`), + CONSTRAINT `aqbudgets_planning_ifbk_1` FOREIGN KEY (`budget_id`) REFERENCES `aqbudgets` (`budget_id`) ON DELETE CASCADE ON UPDATE CASCADE + ) ENGINE=InnoDB DEFAULT CHARSET=utf8;"); + + $dbh->do("ALTER TABLE `aqorders` + ADD COLUMN `budget_id` tinyint(4) NOT NULL, + ADD COLUMN `budgetgroup_id` int(11) NOT NULL, + ADD COLUMN `sort1_authcat` varchar(10) default NULL, + ADD COLUMN `sort2_authcat` varchar(10) default NULL" ); + + + + +# $dbh->do("ALTER TABLE aqorders ADD FOREIGN KEY (`budget_id`) REFERENCES `aqbudgets` (`budget_id`) ON UPDATE CASCADE " ); ???? + + print "Upgrade to $DBversion done (Adding new aqbudgetperiods, aqbudgets and aqbudget_planning tables )\n"; + SetVersion ($DBversion); } + +$DBversion = '3.01.00.106'; +if ( C4::Context->preference("Version") < TransformToNum($DBversion) ) { + $dbh->do("ALTER TABLE aqbudgetperiods ADD COLUMN budget_period_total decimal(28,6)"); + print "Upgrade to $DBversion done (adds 'budget_period_total' column to aqbudgetperiods table)\n"; + SetVersion($DBversion); +} + + +$DBversion = '3.01.00.107'; +if ( C4::Context->preference("Version") < TransformToNum($DBversion) ) { + $dbh->do("ALTER TABLE currency ADD COLUMN active tinyint(1)"); + + print "Upgrade to $DBversion done (adds 'active' column to currencies table)\n"; + SetVersion($DBversion); +} + +$DBversion = '3.01.00.108'; +if ( C4::Context->preference("Version") < TransformToNum($DBversion) ) { + $dbh->do(<preference("Version") < TransformToNum($DBversion) ) { + $dbh->do("ALTER TABLE aqbooksellers ADD COLUMN `gstrate` decimal(6,4) default NULL"); + if (my $gist=C4::Context->preference("gist")){ + my $sql=$dbh->prepare("UPDATE aqbooksellers set `gstrate`=? "); + $sql->execute($gist) ; + } +} + + + =item DropAllForeignKeys($table) Drop all foreign keys of the table $table diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/csv-profiles.tmpl b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/csv-profiles.tmpl new file mode 100644 index 0000000000..f0a072ee7b --- /dev/null +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/csv-profiles.tmpl @@ -0,0 +1,98 @@ + + + Koha › Catalog › Profile for CSV export + + + + + + + + + + + + + +
    +
    +
    +
    + + +

    The new CSV profile "" has been successfully created.

    +

    The CSV profile has been successfully modified.

    +

    The CSV profile has been successfully deleted.

    + +

    The new CSV profile "" has not been created.

    +

    The CSV profile has not been modified.

    +

    The CSV profile has not been deleted.

    + + + +

    New profile for CSV export

    + +
    +
    + +

    + + +

    + + + +
    + + +
    + + + +

    +

    Modify or delete an existing profile

    + +
    +
    + +

    + + +

    + + +

    + + + + +
    + + " /> + + +
    + + +
    +
    +
    + + +
    +
    + diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/tools-home.tmpl b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/tools-home.tmpl index 75d810400b..08e206e4a0 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/tools-home.tmpl +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/tools-home.tmpl @@ -38,6 +38,12 @@
    Tags
    Moderate patron tags
    + + +
    CSV Profiles
    +
    Manage CSV export profiles
    + +
    diff --git a/koha-tmpl/opac-tmpl/prog/en/modules/opac-downloadcart.tmpl b/koha-tmpl/opac-tmpl/prog/en/modules/opac-downloadcart.tmpl new file mode 100644 index 0000000000..85a01368f2 --- /dev/null +++ b/koha-tmpl/opac-tmpl/prog/en/modules/opac-downloadcart.tmpl @@ -0,0 +1,28 @@ +Download shelf + + + + Your Download should automatically start + +
    + + + " /> + +
    + +

    Close this window

    +
    + + + + diff --git a/koha-tmpl/opac-tmpl/prog/en/modules/opac-downloadshelf.tmpl b/koha-tmpl/opac-tmpl/prog/en/modules/opac-downloadshelf.tmpl new file mode 100644 index 0000000000..52203f5037 --- /dev/null +++ b/koha-tmpl/opac-tmpl/prog/en/modules/opac-downloadshelf.tmpl @@ -0,0 +1,28 @@ +Download shelf + + + + Your Download should automatically start + +
    + + + " /> + +
    + +

    Close this window

    +
    + + + + diff --git a/opac/opac-downloadcart.pl b/opac/opac-downloadcart.pl new file mode 100755 index 0000000000..fe80f3008c --- /dev/null +++ b/opac/opac-downloadcart.pl @@ -0,0 +1,90 @@ +#!/usr/bin/perl + +# Copyright 2009 BibLibre +# +# 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 warnings; + +use CGI; +use Encode qw(encode); +use Switch; + +use C4::Auth; +use C4::Biblio; +use C4::Items; +use C4::Output; +use C4::VirtualShelves; +use C4::Record; +use C4::Ris; +use C4::Csv; +use utf8; +use open qw( :std :utf8); +my $query = new CGI; + +my ( $template, $borrowernumber, $cookie ) = get_template_and_user ( + { + template_name => "opac-downloadcart.tmpl", + query => $query, + type => "opac", + authnotrequired => 1, + flagsrequired => { borrow => 1 }, + } +); + +my $bib_list = $query->param('bib_list'); +my $format = $query->param('format'); +my $dbh = C4::Context->dbh; + +if ($bib_list && $format) { + + my @bibs = split( /\//, $bib_list ); + + my $marcflavour = C4::Context->preference('marcflavour'); + my $output; + + # retrieve biblios from shelf + my $firstpass = 1; + foreach my $biblio (@bibs) { + + my $record = GetMarcBiblio($biblio); + + switch ($format) { + case "iso2709" { $output .= $record->as_usmarc(); } + case "ris" { $output .= marc2ris($record); } + case "bibtex" { $output .= marc2bibtex($record, $biblio); } + # We're in the case of a csv profile (firstpass is used for headers printing) : + case /^\d+$/ { $output .= marc2csv($record, $format, $firstpass); } + } + $firstpass = 0; + + } + + # If it was a CSV export we change the format after the export so the file extension is fine + $format = "csv" if ($format =~ m/^\d+$/); + + print $query->header( + -type => 'application/octet-stream', + -'Content-Transfer-Encoding' => 'binary', + -attachment=>"cart.$format"); + print $output; + +} else { + $template->param(csv_profiles => GetCsvProfilesLoop()); + $template->param(bib_list => $bib_list); + output_html_with_http_headers $query, $cookie, $template->output; +} diff --git a/opac/opac-downloadshelf.pl b/opac/opac-downloadshelf.pl new file mode 100755 index 0000000000..976412b1de --- /dev/null +++ b/opac/opac-downloadshelf.pl @@ -0,0 +1,90 @@ +#!/usr/bin/perl + +# Copyright 2009 BibLibre +# +# 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 warnings; + +use CGI; +use Encode qw(encode); +use Switch; + +use C4::Auth; +use C4::Biblio; +use C4::Items; +use C4::Output; +use C4::VirtualShelves; +use C4::Record; +use C4::Ris; +use C4::Csv; +use utf8; +use open qw( :std :utf8); +my $query = new CGI; + +my ( $template, $borrowernumber, $cookie ) = get_template_and_user ( + { + template_name => "opac-downloadshelf.tmpl", + query => $query, + type => "opac", + authnotrequired => 1, + flagsrequired => { borrow => 1 }, + } +); + +my $shelfid = $query->param('shelfid'); +my $format = $query->param('format'); +my $dbh = C4::Context->dbh; + +if ($shelfid && $format) { + + my @shelf = GetShelf($shelfid); + my ($items, $totitems) = GetShelfContents($shelfid); + my $marcflavour = C4::Context->preference('marcflavour'); + my $output; + + # retrieve biblios from shelf + my $firstpass = 1; + foreach my $biblio (@$items) { + my $biblionumber = $biblio->{biblionumber}; + + my $record = GetMarcBiblio($biblionumber); + + switch ($format) { + case "iso2709" { $output .= $record->as_usmarc(); } + case "ris" { $output .= marc2ris($record); } + case "bibtex" { $output .= marc2bibtex($record, $biblionumber); } + # We're in the case of a csv profile (firstpass is used for headers printing) : + case /^\d+$/ { $output .= marc2csv($record, $format, $firstpass); } + } + $firstpass = 0; + } + + # If it was a CSV export we change the format after the export so the file extension is fine + $format = "csv" if ($format =~ m/^\d+$/); + + print $query->header( + -type => 'application/octet-stream', + -'Content-Transfer-Encoding' => 'binary', + -attachment=>"shelf.$format"); + print $output; + +} else { + $template->param(csv_profiles => GetCsvProfilesLoop()); + $template->param(shelfid => $shelfid); + output_html_with_http_headers $query, $cookie, $template->output; +} diff --git a/tools/csv-profiles.pl b/tools/csv-profiles.pl new file mode 100755 index 0000000000..1e037f3aab --- /dev/null +++ b/tools/csv-profiles.pl @@ -0,0 +1,121 @@ +#!/usr/bin/perl + +# Copyright 2009 BibLibre +# +# 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 + +=head1 NAME + +csv-profile.pl : Defines a CSV export profile + +=head1 SYNOPSIS + + +=head1 DESCRIPTION + +This script allow the user to define a new profile for CSV export + +=head1 FUNCTIONS + +=over 2 + +=cut + +use strict; +use Data::Dumper; + +use C4::Auth; +use C4::Context; +use C4::Output; +use CGI; +use C4::Koha; +use C4::Csv; + +my $input = new CGI; +my $dbh = C4::Context->dbh; + +# open template +my ( $template, $loggedinuser, $cookie ) = get_template_and_user( + { + template_name => "tools/csv-profiles.tmpl", + query => $input, + type => "intranet", + authnotrequired => 0, + flagsrequired => { tools => 'manage_csv_profiles' }, + debug => 1, + } +); + + +my $profile_name = $input->param("profile_name"); +my $profile_description = $input->param("profile_description"); +my $profile_content = $input->param("profile_content"); +my $action = $input->param("action"); +my $delete = $input->param("delete"); +my $id = $input->param("id"); +if ($delete) { $action = "delete"; } + +if ($profile_name && $profile_content && $profile_description && $action) { + my $rows; + + if ($action eq "create") { + my $query = "INSERT INTO export_format(export_format_id, profile, description, marcfields) VALUES (NULL, ?, ?, ?)"; + my $sth = $dbh->prepare($query); + $rows = $sth->execute($profile_name, $profile_description, $profile_content); + + } + + if ($action eq "edit") { + my $query = "UPDATE export_format SET description=?, marcfields=? WHERE export_format_id=? LIMIT 1"; + my $sth = $dbh->prepare($query); + $rows = $sth->execute($profile_description, $profile_content, $profile_name); + + } + + if ($action eq "delete") { + my $query = "DELETE FROM export_format WHERE export_format_id=? LIMIT 1"; + my $sth = $dbh->prepare($query); + $rows = $sth->execute($profile_name); + + } + + $rows ? $template->param(success => 1) : $template->param(error => 1); + $template->param(profile_name => $profile_name); + $template->param(action => $action); + +} + + # If a profile has been selected for modification + if ($id) { + my $query = "SELECT export_format_id, profile, description, marcfields FROM export_format WHERE export_format_id = ?"; + my $sth; + $sth = $dbh->prepare($query); + + $sth->execute($id); + my $selected_profile = $sth->fetchrow_arrayref(); + $template->param( + selected_profile_id => $selected_profile->[0], + selected_profile_name => $selected_profile->[1], + selected_profile_description => $selected_profile->[2], + selected_profile_marcfields => $selected_profile->[3] + ); + + } + + # List of existing profiles + $template->param(existing_profiles => GetCsvProfilesLoop()); + +output_html_with_http_headers $input, $cookie, $template->output; -- 2.39.5