MT 2050, Follow-up, Fast Cataloging
[koha.git] / installer / data / mysql / updatedatabase.pl
index 053cecf..ea7f84a 100755 (executable)
@@ -2438,7 +2438,381 @@ if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
     SetVersion ($DBversion);
 }
 
-$DBversion = "3.01.00.035";
+$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)) {
+    # update branches table
+    # 
+    $dbh->do("ALTER TABLE branches ADD `branchzip` varchar(25) default NULL AFTER `branchaddress3`");
+    $dbh->do("ALTER TABLE branches ADD `branchcity` mediumtext AFTER `branchzip`");
+    $dbh->do("ALTER TABLE branches ADD `branchcountry` text AFTER `branchcity`");
+    $dbh->do("ALTER TABLE branches ADD `branchurl` mediumtext AFTER `branchemail`");
+    $dbh->do("ALTER TABLE branches ADD `branchnotes` mediumtext AFTER `branchprinter`");
+    print "Upgrade to $DBversion done (add ZIP, city, country, URL, and notes column to branches)\n";
+    SetVersion ($DBversion);
+}
+
+$DBversion = '3.01.00.039';
+if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
+    $dbh->do("INSERT INTO systempreferences (variable,value,options,explanation,type)VALUES('SpineLabelFormat', '<itemcallnumber><copynumber>', '30|10', 'This preference defines the format for the quick spine label printer. Just list the fields you would like to see in the order you would like to see them, surrounded by <>, for example <itemcallnumber>.', 'Textarea')");
+    $dbh->do("INSERT INTO systempreferences (variable,value,options,explanation,type)VALUES('SpineLabelAutoPrint', '0', '', 'If this setting is turned on, a print dialog will automatically pop up for the quick spine label printer.', 'YesNo')");
+    SetVersion ($DBversion);
+    print "Upgrade to $DBversion done (added SpineLabelFormat and SpineLabelAutoPrint sysprefs)\n";
+}
+
+$DBversion = '3.01.00.040';
+if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
+    $dbh->do("INSERT INTO systempreferences (variable,value,explanation,options,type)VALUES('AllowHoldDateInFuture','0','If set a date field is displayed on the Hold screen of the Staff Interface, allowing the hold date to be set in the future.','','YesNo')");
+    $dbh->do("INSERT INTO systempreferences (variable,value,explanation,options,type)VALUES('OPACAllowHoldDateInFuture','0','If set, along with the AllowHoldDateInFuture system preference, OPAC users can set the date of a hold to be in the future.','','YesNo')");
+    SetVersion ($DBversion);
+    print "Upgrade to $DBversion done (AllowHoldDateInFuture and OPACAllowHoldDateInFuture sysprefs)\n";
+}
+
+$DBversion = '3.01.00.041';
+if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
+    $dbh->do("INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('AWSPrivateKey','','See:  http://aws.amazon.com.  Note that this is required after 2009/08/15 in order to retrieve any enhanced content other than book covers from Amazon.','','free')");
+    SetVersion ($DBversion);
+    print "Upgrade to $DBversion done (added AWSPrivateKey syspref - note that if you use enhanced content from Amazon, this should be set right away.)\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','<li class=\"yuimenuitem\">\n<a target=\"_blank\" class=\"yuimenuitemlabel\" href=\"http://worldcat.org/search?q=TITLE\">Other Libraries (WorldCat)</a></li>\n<li class=\"yuimenuitem\">\n<a class=\"yuimenuitemlabel\" href=\"http://www.scholar.google.com/scholar?q=TITLE\" target=\"_blank\">Other Databases (Google Scholar)</a></li>\n<li class=\"yuimenuitem\">\n<a class=\"yuimenuitemlabel\" href=\"http://www.bookfinder.com/search/?author=AUTHOR&amp;title=TITLE&amp;st=xl&amp;ac=qr\" target=\"_blank\">Online Stores (Bookfinder.com)</a></li>','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='<li><a  href="http://worldcat.org/search?q={TITLE}" target="_blank">Other Libraries (WorldCat)</a></li>\n<li><a href="http://www.scholar.google.com/scholar?q={TITLE}" target="_blank">Other Databases (Google Scholar)</a></li>\n<li><a href="http://www.bookfinder.com/search/?author={AUTHOR}&amp;title={TITLE}&amp;st=xl&amp;ac=qr" target="_blank">Online Stores (Bookfinder.com)</a></li>' 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')");
+    $dbh->do(q/
+       CREATE TABLE `export_format` (
+         `export_format_id` int(11) NOT NULL auto_increment,
+         `profile` varchar(255) NOT NULL,
+         `description` mediumtext NOT NULL,
+         `marcfields` mediumtext NOT NULL,
+         PRIMARY KEY  (`export_format_id`)
+       ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='Used for CSV export';
+    /);
+    print "Upgrade to $DBversion done (added csv export profiles)\n";
+}
+
+$DBversion = "3.01.00.063";
+if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
+    $dbh->do("
+        CREATE TABLE `fieldmapping` (
+          `id` int(11) NOT NULL auto_increment,
+          `field` varchar(255) NOT NULL,
+          `frameworkcode` char(4) NOT NULL default '',
+          `fieldcode` char(3) NOT NULL,
+          `subfieldcode` char(1) NOT NULL,
+          PRIMARY KEY  (`id`)
+        ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
+             ");
+    SetVersion ($DBversion);
+}
+
+$DBversion = '3.01.00.064';
+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.065';
+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.066';
+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.067";
+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.068";
+if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
+       $dbh->do("ALTER TABLE issuingrules ADD 
+                       COLUMN `finedays` int(11) default NULL AFTER `fine`,
+                       COLUMN `renewalsallowed` smallint(6) default NULL, 
+                       COLUMN `reservesallowed` smallint(6) default NULL,
+                       ");
+       my $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`;');
+       print "Upgrade done (Adding finedays renewalsallowed, and reservesallowed fields in issuingrules table)\n";
+}
+
+
+$DBversion = "3.01.00.069";
+if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
+       $dbh->do("INSERT INTO `systempreferences` (`variable`, `value`, `options`, `explanation`, `type`) VALUES ('EnableOpacSearchHistory', '1', '', 'Enable or disable opac search history', 'YesNo')");
+
+       my $create = <<SEARCHHIST;
+CREATE TABLE IF NOT EXISTS `search_history` (
+  `userid` int(11) NOT NULL,
+  `sessionid` varchar(32) NOT NULL,
+  `query_desc` varchar(255) NOT NULL,
+  `query_cgi` varchar(255) NOT NULL,
+  `total` int(11) NOT NULL,
+  `time` timestamp NOT NULL default CURRENT_TIMESTAMP,
+  KEY `userid` (`userid`),
+  KEY `sessionid` (`sessionid`)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='Opac search history results';
+SEARCHHIST
+       $dbh->do($create);
+
+       print "Upgrade done (added OPAC search history preference and table)\n";
+}
+
+$DBversion = "3.01.00.071";
+if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
+       $dbh->do("ALTER TABLE authorised_values ADD COLUMN `lib_opac` VARCHAR(80) default NULL AFTER `lib`");
+       print "Upgrade done (Added a lib_opac field in authorised_values table)\n";
+}
+
+$DBversion = "3.01.00.071";
+if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
+       $dbh->do("ALTER TABLE `subscription` ADD `enddate` date default NULL");
+       $dbh->do("ALTER TABLE subscriptionhistory CHANGE enddate histenddate DATE default NULL");
+       print "Upgrade to $DBversion done ( Adding enddate to subscription)\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
@@ -2446,8 +2820,8 @@ if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
     # 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'");
+    my ($value) = $sth->fetchrow() || 0;
+    $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");
@@ -2459,7 +2833,7 @@ if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
     SetVersion ($DBversion);
 }
 
-$DBversion = '3.01.00.036';
+$DBversion = '3.01.00.101';
 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
     $dbh->do(<<'END_SQL');
 CREATE TABLE IF NOT EXISTS `aqcontract` (
@@ -2478,7 +2852,7 @@ END_SQL
     SetVersion ($DBversion);
 }
 
-$DBversion = '3.01.00.037';
+$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`");
@@ -2489,7 +2863,7 @@ if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
     SetVersion ($DBversion);
 }
 
-$DBversion = '3.01.00.038';
+$DBversion = '3.01.00.103';
 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
     $dbh->do("ALTER TABLE `aqorders` ADD COLUMN `uncertainprice` tinyint(1)");
 
@@ -2497,7 +2871,7 @@ if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
     SetVersion ($DBversion);
 }
 
-$DBversion = '3.01.00.039';
+$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,
@@ -2509,13 +2883,13 @@ if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
                          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')");
+    $dbh->do("ALTER TABLE aqbasket ADD FOREIGN KEY (`basketgroupid`) REFERENCES `aqbasketgroups` (`id`) ON UPDATE CASCADE ON DELETE SET NULL");
+    $dbh->do("INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES ('pdfformat','pdfformat::example','Controls what script is used for printing (basketgroups)','','free')");
     print "Upgrade to $DBversion done (adding basketgroups)\n";
     SetVersion ($DBversion);
 }
 
-$DBversion = '3.01.00.040';
+$DBversion = '3.01.00.105';
 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
     $dbh->do("DROP TABLE IF EXISTS `aqbudgetperiods` ");
     $dbh->do(qq|
@@ -2531,33 +2905,91 @@ if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
                     PRIMARY KEY  (`budget_period_id`)
                     ) ENGINE=InnoDB  DEFAULT CHARSET=utf8 |);
 
+   $dbh->do(<<ADDPERIODS);
+INSERT INTO aqbudgetperiods (budget_period_startdate,budget_period_enddate,budget_period_active,budget_period_description,budget_period_locked)
+SELECT DISTINCT startdate, enddate, 1, concat(startdate," ",enddate),1 from aqbudget
+ADDPERIODS
 # SORRY , NO AQBUDGET/AQBOOKFUND -> 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("CREATE TABLE `aqbudgets` (
-                    `budget_id` int(11) NOT NULL auto_increment,
-                    `budget_parent_id` int(11) default NULL,
-                    `budget_code` varchar(30) default NULL,
-                    `budget_name` varchar(80) default NULL,
-                    `budget_branchcode` varchar(10) default NULL,
-                    `budget_amount` decimal(13,2) NOT NULL default '0.00',
-                    `budget_encumb` tinyint(3) default NULL,
-                    `budget_expend` tinyint(3) default NULL,
-                    `budget_notes` mediumtext,
-                    `budget_desciption` mediumtext,
-                    `timestamp` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
-                    `budget_period_id` int(11) default NULL,
-                    `sort1_authcat` varchar(80) default NULL,
-                    `sort2_authcat` varchar(80) default NULL,
-                    `owner` tinyint(11) default NULL,
-                    `budget_owner_id` tinyint(11) default NULL,
-                    `budget_permission` int(1) default '0',
-                            PRIMARY KEY  (`budget_id`),
-                            CONSTRAINT `aqbudgets_ifbk_1` FOREIGN KEY (`budget_period_id`) REFERENCES `aqbudgetperiods` (`budget_period_id`) ON DELETE CASCADE ON UPDATE CASCADE
-                    ) ENGINE=InnoDB DEFAULT CHARSET=utf8;");
+  #$dbh->do("drop table aqbudget;");  
+
+
+    $dbh->do(<<BUDGETNAME);
+ALTER TABLE aqbudget RENAME`aqbudgets` 
+BUDGETNAME
+    my $maxbudgetid=$dbh->selectcol_arrayref(<<IDsBUDGET);
+SELECT MAX(aqbudgetid) from aqbudgets 
+IDsBUDGET
+
+    $dbh->do(<<BUDGETAUTOINCREMENT);
+ALTER TABLE `aqbudgets` AUTO_INCREMENT=$$maxbudgetid[0]
+BUDGETAUTOINCREMENT
+
+    $dbh->do(<<BUDGETS);
+ALTER TABLE `aqbudgets` 
+   CHANGE  COLUMN aqbudgetid `budget_id` int(11) NOT NULL AUTO_INCREMENT,
+   CHANGE  COLUMN branchcode `budget_branchcode` varchar(10) default NULL,
+   CHANGE  COLUMN budgetamount `budget_amount` decimal(28,6) NOT NULL default '0.00',
+   CHANGE  COLUMN bookfundid   `budget_code` varchar(30) default NULL,
+   ADD     COLUMN `budget_parent_id` int(11) default NULL,
+   ADD     COLUMN `budget_name` varchar(80) default NULL,
+   ADD     COLUMN `budget_encumb` decimal(28,6) default '0.00',
+   ADD     COLUMN `budget_expend` decimal(28,6) default '0.00',
+   ADD     COLUMN `budget_notes` mediumtext,
+   ADD     COLUMN `budget_description` mediumtext,
+   ADD     COLUMN `timestamp` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
+   ADD     COLUMN `budget_amount_sublevel`  decimal(28,6) AFTER `budget_amount`,
+   ADD     COLUMN `budget_period_id` int(11) default NULL,
+   ADD     COLUMN `sort1_authcat` varchar(80) default NULL,
+   ADD     COLUMN `sort2_authcat` varchar(80) default NULL,
+   ADD     COLUMN `budget_owner_id` int(11) default NULL,
+   ADD     COLUMN `budget_permission` int(1) default '0';
+BUDGETS
+
+    $dbh->do(<<BUDGETCONSTRAINTS);
+ALTER TABLE `aqbudgets` 
+   ADD CONSTRAINT `aqbudgets_ifbk_1` FOREIGN KEY (`budget_period_id`) REFERENCES `aqbudgetperiods` (`budget_period_id`) ON DELETE CASCADE ON UPDATE CASCADE
+BUDGETCONSTRAINTS
+#    $dbh->do(<<BUDGETPKDROP);
+#ALTER TABLE `aqbudgets` 
+#   DROP PRIMARY KEY
+#BUDGETPKDROP
+#    $dbh->do(<<BUDGETPKADD);
+#ALTER TABLE `aqbudgets` 
+#   ADD PRIMARY KEY budget_id
+#BUDGETPKADD
+
+
+       my $query_period= $dbh->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(<<BUDGETDROPDATES);
+ALTER TABLE `aqbudgets` 
+   DROP startdate,
+   DROP enddate,
+   DROP bookfundid
+BUDGETDROPDATES
+
+    $dbh->do("DROP TABLE aqbookfund ");
 
     $dbh->do("DROP TABLE IF EXISTS `aqbudgets_planning` ");
     $dbh->do("CREATE TABLE  `aqbudgets_planning` (
@@ -2567,6 +2999,7 @@ if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
                     `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;");
@@ -2578,8 +3011,6 @@ if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
                     ADD COLUMN  `sort2_authcat` varchar(10) default NULL" );
 
 
-    $dbh->do("ALTER TABLE `aqorderbreakdown` 
-  ADD COLUMN `budget_id` int(11) NOT NULL" );
 
 
 #    $dbh->do("ALTER TABLE aqorders  ADD FOREIGN KEY (`budget_id`) REFERENCES `aqbudgets` (`budget_id`) ON UPDATE CASCADE  " ); ????
@@ -2588,47 +3019,9 @@ if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
     SetVersion ($DBversion);
 }
 
-$DBversion = '3.01.00.041';
-if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
-
-# removes 'aqbudgets' NOT NULL
-    $dbh->do("ALTER table `aqbudgets` MODIFY COLUMN `budget_amount`  decimal(28,6)  ");
-    $dbh->do("ALTER table `aqbudgets` ADD  COLUMN `budget_amount_sublevel`  decimal(28,6) AFTER `budget_amount` ");
-    $dbh->do("ALTER table `aqbudgets` DROP  COLUMN `owner` ");
-    $dbh->do("ALTER table `aqbudgets` DROP  COLUMN `budget_desciption` ");
- #   $dbh->do("ALTER table `aqbudgets` DROP  COLUMN `budgetgroup_id` ");
-    $dbh->do("ALTER table `aqbudgets` MODIFY  COLUMN `budget_encumb`  decimal(28,6) default '0.00'   ");
-    $dbh->do("ALTER table `aqbudgets` MODIFY  COLUMN `budget_expend`  decimal(28,6) default '0.00'   ");
-
-    print "Upgrade to $DBversion done (adding `budget_amount_sublevel` colmn, and removing temp columns )\n";
-    SetVersion ($DBversion);
-}
-
-$DBversion = '3.01.00.042';
-if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
-
-# removes 'aqbudgets' NOT NULL
-    $dbh->do("ALTER TABLE aqorderbreakdown DROP FOREIGN KEY aqorderbreakdown_ibfk_2 ");
-    $dbh->do("ALTER TABLE aqorderbreakdown DROP COLUMN bookfundid ");
-    $dbh->do("ALTER TABLE aqorderbreakdown ADD KEY budget_id (budget_id)" );
-
-    print "Upgrade to $DBversion done (aqorderbreakdown table tidy)\n";
-    SetVersion ($DBversion);
-}
-
-
-$DBversion = '3.01.00.043';
-if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
-
-# removes 'aqbudgets' NOT NULL
-#    $dbh->do("ALTER TABLE aqorderbreakdown ADD COLUMN  budget_id int(11) " );
-#    $dbh->do("ALTER TABLE aqorderbreakdown ADD KEY budget_id (budget_id)" );
 
-    print "Upgrade to $DBversion done (aqorderbreakdown table tidy2)\n";
-    SetVersion ($DBversion);
-}
 
-$DBversion = '3.01.00.044';
+$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";
@@ -2636,7 +3029,7 @@ if ( C4::Context->preference("Version") < TransformToNum($DBversion) ) {
 }
 
 
-$DBversion = '3.01.00.045';
+$DBversion = '3.01.00.107';
 if ( C4::Context->preference("Version") < TransformToNum($DBversion) ) {
     $dbh->do("ALTER TABLE currency ADD COLUMN active  tinyint(1)");
 
@@ -2644,53 +3037,42 @@ if ( C4::Context->preference("Version") < TransformToNum($DBversion) ) {
     SetVersion($DBversion);
 }
 
-$DBversion = '3.01.00.046';
+$DBversion = '3.01.00.108';
 if ( C4::Context->preference("Version") < TransformToNum($DBversion) ) {
-    $dbh->do("INSERT INTO permissions (module_bit, code, description) VALUES
+    $dbh->do(<<BUDG_PERM );
+INSERT INTO permissions (module_bit, code, description) VALUES
             (11, 'vendors_manage', 'Manage vendors'),
             (11, 'contracts_manage', 'Manage contracts'),
             (11, 'period_manage', 'Manage periods'),
             (11, 'budget_manage', 'Manage budgets'),
-            (11, 'budget_modify', 'Modify budget (can''t create lines, but can modify existing ones)'),
+            (11, 'budget_modify', "Modify budget (can't create lines but can modify existing ones)"),
             (11, 'planning_manage', 'Manage budget plannings'),
             (11, 'order_manage', 'Manage orders & basket'),
             (11, 'group_manage', 'Manage orders & basketgroups'),
-            (11, 'order_receive', 'Manage orders & basket')
-    ");
+            (11, 'order_receive', 'Manage orders & basket'),
+            (11, 'budget_add_del', "Add and delete budgets (but can't modify budgets)");
+BUDG_PERM
 
     print "Upgrade to $DBversion done (adds permissions for the acquisitions module)\n";
     SetVersion($DBversion);
 }
 
-$DBversion = '3.01.00.047';
-if ( C4::Context->preference("Version") < TransformToNum($DBversion) ) {
-    $dbh->do("ALTER TABLE aqbudgets CHANGE COLUMN budget_owner_id budget_owner_id int(11)");
-
-    print "Upgrade to $DBversion done (changes 'budget_owner_id' col to int(11)\n";
-    SetVersion($DBversion);
-}
-
-
-$DBversion = '3.01.00.048';
-if ( C4::Context->preference("Version") < TransformToNum($DBversion) ) {
-    $dbh->do(qq|  INSERT INTO permissions (module_bit, code, description) VALUES
-            (11, 'budget_add_del', "Add and delete budgets (but can't modify budgets) )") |);
-
-    print "Upgrade to $DBversion done (small budget perm change)\n";
-    SetVersion($DBversion);
-}
 
-$DBversion = '3.01.00.049';
+$DBversion = '3.01.00.109';
 if ( C4::Context->preference("Version") < TransformToNum($DBversion) ) {
-    $dbh->do("ALTER TABLE aqbooksellers ADD COLUMN `gstrate` decimal(5,2) default NULL");
+    $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) ;
+       }
     print "Upgrade to $DBversion done (added per-supplier gstrate setting)\n";
     SetVersion($DBversion);
 }
 
-$DBversion = "3.01.00.050";
+$DBversion = "3.01.00.110";
 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
     if (C4::Context->preference("opaclanguages") eq "fr") {
-        $dbh->do("INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('AcqCreateItem','ordering','Définit quand l'exemplaire est créé : à la commande, à la livraison, au catalogage','ordering|receiving|cataloguing','Choice')");
+        $dbh->do(qq#INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('AcqCreateItem','ordering',"Définit quand l'exemplaire est créé : à la commande, à la livraison, au catalogage",'ordering|receiving|cataloguing','Choice')#);
     } else {
         $dbh->do("INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('AcqCreateItem','ordering','Define when the item is created : when ordering, when receiving, or in cataloguing module','ordering|receiving|cataloguing','Choice')");
     }
@@ -2698,7 +3080,7 @@ if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
     SetVersion ($DBversion);
 }
 
-$DBversion = "3.01.00.051";
+$DBversion = "3.01.00.111";
 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
     $dbh->do(qq| 
  CREATE TABLE `aqorders_items` (
@@ -2715,25 +3097,7 @@ if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
     SetVersion ($DBversion);
 }
 
-$DBversion = "3.01.00.052";
-if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
-    my $query = "SELECT * FROM `aqbooksellers`";
-    my $sth = $dbh->prepare($query);
-    $sth->execute;
-    my $booksellers=$sth->fetchall_arrayref({});
-    $sth->finish;
-    $dbh->do("ALTER TABLE `aqbooksellers` DROP COLUMN `gstrate`");
-    $dbh->do("ALTER TABLE `aqbooksellers` ADD COLUMN `gstrate` decimal(6,4) default NULL");
-    for my $bookseller (@$booksellers) {
-        my $sth = $dbh->prepare("UPDATE aqbooksellers SET gstrate=? WHERE id=?");
-        $sth->execute($bookseller->{gstrate}?$bookseller->{gstrate}:0 / 100, $bookseller->{id});
-        $sth->finish;
-    }
-    print "Upgrade to $DBversion done (modify gstrate to be consistent with syspref)\n";
-    SetVersion ($DBversion);
-}
-
-$DBversion = "3.01.00.053";
+$DBversion = "3.01.00.112";
 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
     $dbh->do(  qq# INSERT INTO `systempreferences` VALUES ('CurrencyFormat','US','US|FR','Determines the display format of currencies. eg: ''36000'' is displayed as ''360 000,00''  in ''FR'' or 360,000.00''  in ''US''.','Choice')  #);
 
@@ -2741,255 +3105,201 @@ if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
     SetVersion ($DBversion);
 }
 
-$DBversion = "3.01.00.054";
+$DBversion = "3.01.00.113";
 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
     $dbh->do("ALTER table aqorders drop column title");
-
-    print "Upgrade to $DBversion done (dropped the title column from the aqorders table)\n";
-    SetVersion ($DBversion);
-}
-
-$DBversion = "3.01.00.055";
-if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
     $dbh->do("ALTER TABLE `aqorders` CHANGE `budget_id` `budget_id` INT( 11 ) NOT NULL");
     print "Upgrade to $DBversion done update budget_id size that should not be a tinyint\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)) {
-    # update branches table
-    # 
-    $dbh->do("ALTER TABLE branches ADD `branchzip` varchar(25) default NULL AFTER `branchaddress3`");
-    $dbh->do("ALTER TABLE branches ADD `branchcity` mediumtext AFTER `branchzip`");
-    $dbh->do("ALTER TABLE branches ADD `branchcountry` text AFTER `branchcity`");
-    $dbh->do("ALTER TABLE branches ADD `branchurl` mediumtext AFTER `branchemail`");
-    $dbh->do("ALTER TABLE branches ADD `branchnotes` mediumtext AFTER `branchprinter`");
-    print "Upgrade to $DBversion done (add ZIP, city, country, URL, and notes column to branches)\n";
-    SetVersion ($DBversion);
-}
-
-$DBversion = '3.01.00.039';
+$DBversion = "3.01.00.114";
 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
-    $dbh->do("INSERT INTO systempreferences (variable,value,options,explanation,type)VALUES('SpineLabelFormat', '<itemcallnumber><copynumber>', '30|10', 'This preference defines the format for the quick spine label printer. Just list the fields you would like to see in the order you would like to see them, surrounded by <>, for example <itemcallnumber>.', 'Textarea')");
-    $dbh->do("INSERT INTO systempreferences (variable,value,options,explanation,type)VALUES('SpineLabelAutoPrint', '0', '', 'If this setting is turned on, a print dialog will automatically pop up for the quick spine label printer.', 'YesNo')");
+    $dbh->do(<<SUGGESTIONS);
+ALTER table suggestions 
+    ADD budgetid INT(11),
+    ADD branchcode VARCHAR(10) default NULL,
+    ADD acceptedby INT(11) default NULL,
+    ADD accepteddate date default NULL,
+    ADD suggesteddate date default NULL,
+    ADD manageddate date default NULL,
+    ADD rejectedby INT(11) default NULL,
+    ADD rejecteddate date default NULL,
+    ADD collectiontitle text default NULL,
+    ADD itemtype VARCHAR(30) default NULL,
+    ;
+SUGGESTIONS
+    print "Upgrade to $DBversion done Suggestions";
     SetVersion ($DBversion);
-    print "Upgrade to $DBversion done (added SpineLabelFormat and SpineLabelAutoPrint sysprefs)\n";
 }
 
-$DBversion = '3.01.00.040';
+$DBversion = "3.01.00.115";
 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
-    $dbh->do("INSERT INTO systempreferences (variable,value,explanation,options,type)VALUES('AllowHoldDateInFuture','0','If set a date field is displayed on the Hold screen of the Staff Interface, allowing the hold date to be set in the future.','','YesNo')");
-    $dbh->do("INSERT INTO systempreferences (variable,value,explanation,options,type)VALUES('OPACAllowHoldDateInFuture','0','If set, along with the AllowHoldDateInFuture system preference, OPAC users can set the date of a hold to be in the future.','','YesNo')");
+    $dbh->do("ALTER table aqbudgets drop column budget_amount_sublevel;");
+    print "Upgrade to $DBversion done drop column budget_amount_sublevel from aqbudgets\n";
     SetVersion ($DBversion);
-    print "Upgrade to $DBversion done (AllowHoldDateInFuture and OPACAllowHoldDateInFuture sysprefs)\n";
 }
 
-$DBversion = '3.01.00.041';
+$DBversion = "3.01.00.116";
 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
-    $dbh->do("INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('AWSPrivateKey','','See:  http://aws.amazon.com.  Note that this is required after 2009/08/15 in order to retrieve any enhanced content other than book covers from Amazon.','','free')");
-    SetVersion ($DBversion);
-    print "Upgrade to $DBversion done (added AWSPrivateKey syspref - note that if you use enhanced content from Amazon, this should be set right away.)\n";
-}
+    $dbh->do(  qq# INSERT INTO `systempreferences` VALUES ('intranetbookbag','1','','If ON, enables display of Cart feature in the intranet','YesNo')  #);
 
-$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')");
+    print "Upgrade to $DBversion done (intranetbookbag syspref added)\n";
     SetVersion ($DBversion);
-    print "Upgrade to $DBversion done (added OPACFineNoRenewals syspref)\n";
 }
 
-$DBversion = '3.01.00.043';
+$DBversion = "3.01.00.117";
 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";
-}
+    $dbh->do(  qq# ALTER TABLE authorised_values ADD COLUMN `lib_opac` VARCHAR(80) default NULL AFTER `lib` #);
 
-$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')");
+    print "Upgrade to $DBversion done (opac authorised values added)\n";
     SetVersion ($DBversion);
-    print "Upgrade to $DBversion done (added DisplayClearScreenButton system preference)\n";
 }
 
-$DBversion = '3.01.00.045';
+$DBversion = "3.01.00.118";
 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)";
-}
+$dbh->do("
+       INSERT INTO `permissions` (`module_bit`, `code`, `description`) VALUES
+               (16, 'execute_reports', 'Execute SQL reports'),
+               (16, 'create_reports', 'Create SQL Reports')
+       ");
 
-$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";
+    print "Upgrade to $DBversion done (granular permissions for guided reports added)\n";
     SetVersion ($DBversion);
 }
 
-$DBversion = '3.01.00.047';
+$DBversion = "3.01.00.119";
 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";
-}
+$dbh->do("
+       UPDATE `systempreferences` SET `options` = 'holdings|serialcollection|subscriptions'
+       WHERE `systempreferences`.`variable` = 'opacSerialDefaultTab' LIMIT 1 
+       ");
 
-$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;");
+    print "Upgrade to $DBversion done (opac-detail default tag updated)\n";
     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';
+$DBversion = "3.01.00.120";
 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
-    $dbh->do("INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES ('OPACSearchForTitleIn','<li class=\"yuimenuitem\">\n<a target=\"_blank\" class=\"yuimenuitemlabel\" href=\"http://worldcat.org/search?q=TITLE\">Other Libraries (WorldCat)</a></li>\n<li class=\"yuimenuitem\">\n<a class=\"yuimenuitemlabel\" href=\"http://www.scholar.google.com/scholar?q=TITLE\" target=\"_blank\">Other Databases (Google Scholar)</a></li>\n<li class=\"yuimenuitem\">\n<a class=\"yuimenuitemlabel\" href=\"http://www.bookfinder.com/search/?author=AUTHOR&amp;title=TITLE&amp;st=xl&amp;ac=qr\" target=\"_blank\">Online Stores (Bookfinder.com)</a></li>','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');");
+    if (C4::Context->preference("opaclanguages") =~ /fr/) {
+       $dbh->do(qq{
+INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES ('RoutingListAddReserves','1','Si activé, des reservations sont automatiquement créées pour chaque lecteur de la liste de circulation d''un numéro de périodique','','YesNo');
+       });
+       }else{
+       $dbh->do(qq{
+INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES ('RoutingListAddReserves','1','If ON the patrons on routing lists are automatically added to holds on the issue.','','YesNo');
+       });
+       }
+    print "Upgrade to $DBversion done (Added RoutingListAddReserves syspref)\n";
     SetVersion ($DBversion);
-    print "Upgrade to $DBversion done (bug 1934: Add OPACSearchForTitleIn syspref)\n";
 }
 
-$DBversion = '3.01.00.051';
+$DBversion = "3.01.00.121";
 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';");
+       $dbh->do(qq{
+       ALTER TABLE biblioitems ADD INDEX issn_idx (issn);
+       });
+    print "Upgrade to $DBversion done (added index to ISSN)\n";
     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";
-}
+=item
 
-$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);
-}
+    Deal with branches
 
-$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";
-}
+=cut
 
-$DBversion = '3.01.00.055';
+my $DBversion = "3.01.00.0122";
 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='<li><a  href="http://worldcat.org/search?q={TITLE}" target="_blank">Other Libraries (WorldCat)</a></li>\n<li><a href="http://www.scholar.google.com/scholar?q={TITLE}" target="_blank">Other Databases (Google Scholar)</a></li>\n<li><a href="http://www.bookfinder.com/search/?author={AUTHOR}&amp;title={TITLE}&amp;st=xl&amp;ac=qr" target="_blank">Online Stores (Bookfinder.com)</a></li>' WHERE variable='OPACSearchForTitleIn'|);
+    # update branches table
+    # 
+    $dbh->do("ALTER TABLE branches ADD `branchzip` varchar(25) default NULL AFTER `branchaddress3`");
+    $dbh->do("ALTER TABLE branches ADD `branchcity` mediumtext AFTER `branchzip`");
+    $dbh->do("ALTER TABLE branches ADD `branchcountry` text AFTER `branchcity`");
+    $dbh->do("ALTER TABLE branches ADD `branchurl` mediumtext AFTER `branchemail`");
+    $dbh->do("ALTER TABLE branches ADD `branchnotes` mediumtext AFTER `branchprinter`");
+    print "Upgrade to $DBversion done (branches)\n";
     SetVersion ($DBversion);
-    print "Upgrade to $DBversion done (changed OPACSearchForTitleIn per requests in bug 1934)\n";
 }
 
-$DBversion = '3.01.00.056';
+$DBversion = "3.01.00.123";
 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');");
+       $dbh->do(qq{
+       ALTER TABLE aqbasketgroups ADD deliveryplace VARCHAR(10) default NULL, ADD deliverycomment VARCHAR(255) default NULL;
+       });
+       
+    print "Upgrade to $DBversion done (adding deliveryplace deliverycomment to basketgroups)\n";
     SetVersion ($DBversion);
-    print "Upgrade to $DBversion done (Bug 1172 : Add OPACPatronDetails syspref)\n";
 }
 
-$DBversion = '3.01.00.057';
+$DBversion = "3.01.00.124";
 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');");
+       $dbh->do(qq{
+       ALTER TABLE items ADD stocknumber VARCHAR(32) DEFAULT NULL COMMENT "stores the inventory number";
+       });
+       $dbh->do(qq{
+       ALTER TABLE items ADD UNIQUE INDEX itemsstocknumberidx (stocknumber);
+       });
+       $dbh->do(qq{
+       ALTER TABLE deleteditems ADD stocknumber VARCHAR(32) DEFAULT NULL COMMENT "stores the inventory number of deleted items";
+       });
+       $dbh->do(qq{
+       ALTER TABLE deleteditems ADD UNIQUE INDEX deleteditemsstocknumberidx (stocknumber);
+       });
+       if (C4::Context->preference('marcflavour') eq 'UNIMARC'){
+               $dbh->do(qq{
+       INSERT IGNORE INTO marc_subfield_structure (frameworkcode,tagfield, tagsubfield, tab, repeatable, mandatory,kohafield) 
+       SELECT DISTINCT (frameworkcode),995,"j",10,0,0,"items.stocknumber" from biblio_framework ;
+               });
+               #Previously, copynumber was used as stocknumber
+               $dbh->do(qq{
+       UPDATE items set stocknumber=copynumber;
+               });
+               $dbh->do(qq{
+       UPDATE items set copynumber=NULL;
+               });
+       }       
+    print "Upgrade to $DBversion done (stocknumber field added)\n";
     SetVersion ($DBversion);
-    print "Upgrade to $DBversion done (Bug 2576 : Add OPACFinesTab syspref)\n";
 }
 
-$DBversion = '3.01.00.058';
+$DBversion = "3.01.00.125";
 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;");
+    $dbh->do("INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES ('OrderPdfTemplate','','Uploads a PDF template to use for printing baskets','NULL','Upload')");
+    $dbh->do("UPDATE systempreferences SET variable='OrderPdfFormat' WHERE variable='pdfformat'");
+    print "Upgrade to $DBversion done (PDF orders system preferences added and updated)\n";
     SetVersion ($DBversion);
-    print "Upgrade to $DBversion done (Added primary keys to language tables)\n";
 }
 
-$DBversion = '3.01.00.059';
+$DBversion = "3.01.00.127";
 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')");
+       $dbh->do(qq{
+       ALTER TABLE aqbasketgroups ADD billingplace VARCHAR(10) NOT NULL AFTER deliverycomment;
+       });
+       
+    print "Upgrade to $DBversion done (Adding billingplace to aqbasketgroups)\n";
     SetVersion ($DBversion);
-    print "Upgrade to $DBversion done (added DisplayOPACiconsXSLT sysprefs)\n";
 }
 
-$DBversion = '3.01.00.060';
+$DBversion = "3.01.00.128";
 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";
+       $dbh->do(qq{
+       ALTER TABLE auth_subfield_structure MODIFY frameworkcode VARCHAR(10) NULL;
+       });
+       
+    print "Upgrade to $DBversion done (changing frameworkcode length in auth_subfield_structure)\n";
     SetVersion ($DBversion);
 }
 
-$DBversion = '3.01.00.061';
+$DBversion = "3.01.00.128";
 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";
+       $dbh->do(qq{
+               INSERT INTO `permissions` (`module_bit`, `code`, `description`) VALUES
+                (9, 'edit_catalogue', 'Edit catalogue'),
+               (9, 'fast_cataloging', 'Fast cataloging')
+       });
+       
+    print "Upgrade to $DBversion done (granular permissions for cataloging added)\n";
     SetVersion ($DBversion);
 }
 
@@ -2999,6 +3309,7 @@ if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
 
 =cut
 
+
 sub DropAllForeignKeys {
     my ($table) = @_;
     # get the table description