Revert "Updatedatabase UPDATE For more_subfields_xml to be added to deleteditems...
[koha.git] / installer / data / mysql / updatedatabase.pl
index da1c23a..6ab5eb9 100755 (executable)
@@ -88,7 +88,7 @@ if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
 
 $DBversion = "3.00.00.003";
 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
-    if (C4::Context->preference("opaclanguage") eq "fr") {
+    if (C4::Context->preference("opaclanguages") eq "fr") {
         $dbh->do("INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('ReservesNeedReturns','0','Si ce paramètre est mis à 1, une réservation posée sur un exemplaire présent sur le site devra être passée en retour pour être disponible. Sinon, elle sera automatiquement disponible, Koha considère que le bibliothécaire place la réservation en ayant le document en mains','','YesNo')");
     } else {
         $dbh->do("INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('ReservesNeedReturns','0','If set, a reserve done on an item available in this branch need a check-in, otherwise, a reserve on a specific item, that is on the branch & available is considered as available','','YesNo')");
@@ -100,14 +100,14 @@ if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
 
 $DBversion = "3.00.00.004";
 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
-       $dbh->do("INSERT INTO `systempreferences` VALUES ('DebugLevel','2','set the level of error info sent to the browser. 0=none, 1=some, 2=most','0|1|2','Choice')");    
+    $dbh->do("INSERT INTO `systempreferences` VALUES ('DebugLevel','2','set the level of error info sent to the browser. 0=none, 1=some, 2=most','0|1|2','Choice')");    
     print "Upgrade to $DBversion done (adding DebugLevel systempref, in 'Admin' tab)\n";
     SetVersion ($DBversion);
 }
 
 $DBversion = "3.00.00.005";
 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
-       $dbh->do("CREATE TABLE `tags` (
+    $dbh->do("CREATE TABLE `tags` (
                     `entry` varchar(255) NOT NULL default '',
                     `weight` bigint(20) NOT NULL default 0,
                     PRIMARY KEY  (`entry`)
@@ -128,22 +128,22 @@ if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
 
 $DBversion = "3.00.00.006";
 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
-       $dbh->do("UPDATE issues SET issuedate=timestamp WHERE issuedate='0000-00-00'");
+    $dbh->do("UPDATE issues SET issuedate=timestamp WHERE issuedate='0000-00-00'");
     print "Upgrade to $DBversion done (filled issues.issuedate with timestamp)\n";
     SetVersion ($DBversion);
 }
 
 $DBversion = "3.00.00.007";
 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
-       $dbh->do("INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES ('SessionStorage','mysql','Use mysql or a temporary file for storing session data','mysql|tmp','Choice')");
+    $dbh->do("INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES ('SessionStorage','mysql','Use mysql or a temporary file for storing session data','mysql|tmp','Choice')");
     print "Upgrade to $DBversion done (set SessionStorage variable)\n";
     SetVersion ($DBversion);
 }
 
 $DBversion = "3.00.00.008";
 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
-       $dbh->do("ALTER TABLE `biblio` ADD `datecreated` DATE NOT NULL AFTER `timestamp` ;");
-       $dbh->do("UPDATE biblio SET datecreated=timestamp");
+    $dbh->do("ALTER TABLE `biblio` ADD `datecreated` DATE NOT NULL AFTER `timestamp` ;");
+    $dbh->do("UPDATE biblio SET datecreated=timestamp");
     print "Upgrade to $DBversion done (biblio creation date)\n";
     SetVersion ($DBversion);
 }
@@ -296,18 +296,18 @@ if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
 
 $DBversion = "3.00.00.010";
 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
-       $dbh->do("CREATE INDEX `userid` ON borrowers (`userid`) ");
+    $dbh->do("CREATE INDEX `userid` ON borrowers (`userid`) ");
     print "Upgrade to $DBversion done (userid index added)\n";
     SetVersion ($DBversion);
 }
 
 $DBversion = "3.00.00.011";
 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
-       $dbh->do("ALTER TABLE `branchcategories` CHANGE `categorycode` `categorycode` char(10) ");
-       $dbh->do("ALTER TABLE `branchcategories` CHANGE `categoryname` `categoryname` varchar(32) ");
-       $dbh->do("ALTER TABLE `branchcategories` ADD COLUMN `categorytype` varchar(16) ");
-       $dbh->do("UPDATE `branchcategories` SET `categorytype` = 'properties'");
-       $dbh->do("ALTER TABLE `branchrelations` CHANGE `categorycode` `categorycode` char(10) ");
+    $dbh->do("ALTER TABLE `branchcategories` CHANGE `categorycode` `categorycode` char(10) ");
+    $dbh->do("ALTER TABLE `branchcategories` CHANGE `categoryname` `categoryname` varchar(32) ");
+    $dbh->do("ALTER TABLE `branchcategories` ADD COLUMN `categorytype` varchar(16) ");
+    $dbh->do("UPDATE `branchcategories` SET `categorytype` = 'properties'");
+    $dbh->do("ALTER TABLE `branchrelations` CHANGE `categorycode` `categorycode` char(10) ");
     print "Upgrade to $DBversion done (added branchcategory type)\n";
     SetVersion ($DBversion);
 }
@@ -460,73 +460,73 @@ if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
 
 $DBversion = "3.00.00.014";
 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
-       $dbh->do("ALTER TABLE subscription ADD lastbranch VARCHAR(4)");
+    $dbh->do("ALTER TABLE subscription ADD lastbranch VARCHAR(4)");
     print "Upgrade to $DBversion done (userid index added)\n";
-       SetVersion ($DBversion);
-}
-
-$DBversion = "3.00.00.015";    
-if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
-       $dbh->do("CREATE TABLE `saved_sql` (
-                  `id` int(11) NOT NULL auto_increment,
-                  `borrowernumber` int(11) default NULL,
-                  `date_created` datetime default NULL,
-                  `last_modified` datetime default NULL,
-                  `savedsql` text,
-                  `last_run` datetime default NULL,
-                  `report_name` varchar(255) default NULL,
-                  `type` varchar(255) default NULL,
-                  `notes` text,
-                  PRIMARY KEY  (`id`),
-                  KEY boridx (`borrowernumber`)
-               ) ENGINE=InnoDB DEFAULT CHARSET=utf8;");
+    SetVersion ($DBversion);
+}
+
+$DBversion = "3.00.00.015"; 
+if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
+    $dbh->do("CREATE TABLE `saved_sql` (
+           `id` int(11) NOT NULL auto_increment,
+           `borrowernumber` int(11) default NULL,
+           `date_created` datetime default NULL,
+           `last_modified` datetime default NULL,
+           `savedsql` text,
+           `last_run` datetime default NULL,
+           `report_name` varchar(255) default NULL,
+           `type` varchar(255) default NULL,
+           `notes` text,
+           PRIMARY KEY  (`id`),
+           KEY boridx (`borrowernumber`)
+        ) ENGINE=InnoDB DEFAULT CHARSET=utf8;");
     $dbh->do("CREATE TABLE `saved_reports` (
-                  `id` int(11) NOT NULL auto_increment,
-                  `report_id` int(11) default NULL,
-                  `report` longtext,
-                  `date_run` datetime default NULL,
-                  PRIMARY KEY  (`id`)
-               ) ENGINE=InnoDB DEFAULT CHARSET=utf8;");
+           `id` int(11) NOT NULL auto_increment,
+           `report_id` int(11) default NULL,
+           `report` longtext,
+           `date_run` datetime default NULL,
+           PRIMARY KEY  (`id`)
+        ) ENGINE=InnoDB DEFAULT CHARSET=utf8;");
     print "Upgrade to $DBversion done (saved_sql and saved_reports added)\n";
     SetVersion ($DBversion);
 }
 
-$DBversion = "3.00.00.016";    
+$DBversion = "3.00.00.016"; 
 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
-       $dbh->do(" CREATE TABLE reports_dictionary (
-                 id int(11) NOT NULL auto_increment,
-                 name varchar(255) default NULL,
-                 description text,
-                 date_created datetime default NULL,
-                 date_modified datetime default NULL,
-                 saved_sql text,
-                 area int(11) default NULL,
-                 PRIMARY KEY  (id)
-               ) ENGINE=InnoDB DEFAULT CHARSET=utf8 ");
+    $dbh->do(" CREATE TABLE reports_dictionary (
+          id int(11) NOT NULL auto_increment,
+          name varchar(255) default NULL,
+          description text,
+          date_created datetime default NULL,
+          date_modified datetime default NULL,
+          saved_sql text,
+          area int(11) default NULL,
+          PRIMARY KEY  (id)
+        ) ENGINE=InnoDB DEFAULT CHARSET=utf8 ");
     print "Upgrade to $DBversion done (reports_dictionary) added)\n";
     SetVersion ($DBversion);
-}      
+}   
 
 $DBversion = "3.00.00.017";
 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
     $dbh->do("ALTER TABLE action_logs DROP PRIMARY KEY");
-       $dbh->do("ALTER TABLE action_logs ADD KEY  timestamp (timestamp,user)");
-       $dbh->do("ALTER TABLE action_logs ADD action_id INT(11) NOT NULL FIRST");
-       $dbh->do("UPDATE action_logs SET action_id = if (\@a, \@a:=\@a+1, \@a:=1)");
+    $dbh->do("ALTER TABLE action_logs ADD KEY  timestamp (timestamp,user)");
+    $dbh->do("ALTER TABLE action_logs ADD action_id INT(11) NOT NULL FIRST");
+    $dbh->do("UPDATE action_logs SET action_id = if (\@a, \@a:=\@a+1, \@a:=1)");
     $dbh->do("ALTER TABLE action_logs MODIFY action_id INT(11) NOT NULL AUTO_INCREMENT PRIMARY KEY");
-       print "Upgrade to $DBversion done (added column to action_logs)\n";
-       SetVersion ($DBversion);
+    print "Upgrade to $DBversion done (added column to action_logs)\n";
+    SetVersion ($DBversion);
 }
 
 $DBversion = "3.00.00.018";
 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
-       $dbh->do("ALTER TABLE `zebraqueue` 
+    $dbh->do("ALTER TABLE `zebraqueue` 
                     ADD `done` INT NOT NULL DEFAULT '0',
                     ADD `time` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ; 
             ");
     print "Upgrade to $DBversion done (adding timestamp and done columns to zebraque table to improve problem tracking) added)\n";
     SetVersion ($DBversion);
-}      
+}   
 
 $DBversion = "3.00.00.019";
 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
@@ -548,13 +548,13 @@ if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
 
 $DBversion = "3.00.00.021";
 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
-       $dbh->do("ALTER TABLE items CHANGE homebranch homebranch VARCHAR(10)");
-       $dbh->do("ALTER TABLE deleteditems CHANGE homebranch homebranch VARCHAR(10)");
-       $dbh->do("ALTER TABLE statistics CHANGE branch branch VARCHAR(10)");
-       $dbh->do("ALTER TABLE subscription CHANGE lastbranch lastbranch VARCHAR(10)");
+    $dbh->do("ALTER TABLE items CHANGE homebranch homebranch VARCHAR(10)");
+    $dbh->do("ALTER TABLE deleteditems CHANGE homebranch homebranch VARCHAR(10)");
+    $dbh->do("ALTER TABLE statistics CHANGE branch branch VARCHAR(10)");
+    $dbh->do("ALTER TABLE subscription CHANGE lastbranch lastbranch VARCHAR(10)");
     print "Upgrade to $DBversion done (extended missed branchcode columns to 10 chars)\n";
-       SetVersion ($DBversion);
-}      
+    SetVersion ($DBversion);
+}   
 
 $DBversion = "3.00.00.022";
 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
@@ -566,8 +566,8 @@ if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
 
 $DBversion = "3.00.00.023";
 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
-        $dbh->do("INSERT INTO `systempreferences` (variable,value,options,explanation,type)
-                VALUES ('yuipath','http://yui.yahooapis.com/2.3.1/build','Insert the path to YUI libraries','','free')");
+     $dbh->do("INSERT INTO `systempreferences` (variable,value,options,explanation,type)
+         VALUES ('yuipath','http://yui.yahooapis.com/2.3.1/build','Insert the path to YUI libraries','','free')");
     print "Upgrade to $DBversion done (adding new system preference for controlling YUI path)\n";
     SetVersion ($DBversion);
 }
@@ -583,8 +583,8 @@ $DBversion = "3.00.00.025";
 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
     $dbh->do("ALTER TABLE items ADD COLUMN itype VARCHAR(10)");
     if(C4::Context->preference('item-level_itypes')){
-       $dbh->do('update items,biblioitems set items.itype=biblioitems.itemtype where items.biblionumber=biblioitems.biblionumber and itype is null');
-       }
+        $dbh->do('update items,biblioitems set items.itype=biblioitems.itemtype where items.biblionumber=biblioitems.biblionumber and itype is null');
+    }
     print "Upgrade to $DBversion done (reintroduce items.itype - fill from itemtype)\n ";
     SetVersion ($DBversion);
 }
@@ -675,7 +675,7 @@ if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
 
 $DBversion = "3.00.00.029";
 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
-       $dbh->do("ALTER TABLE `import_batches` ADD `matcher_id` int(11) NULL AFTER `import_batch_id`");
+    $dbh->do("ALTER TABLE `import_batches` ADD `matcher_id` int(11) NULL AFTER `import_batch_id`");
     print "Upgrade to $DBversion done (adding matcher_id to import_batches)\n";
     SetVersion ($DBversion);
 }
@@ -784,24 +784,445 @@ if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
 $DBversion = "3.00.00.037";
 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
     $dbh->do("ALTER TABLE `borrowers` ADD COLUMN `altcontactfirstname` varchar(255)");
-       $dbh->do("ALTER TABLE `borrowers` ADD COLUMN `altcontactsurname` varchar(255)");
-       $dbh->do("ALTER TABLE `borrowers` ADD COLUMN `altcontactaddress1` varchar(255)");
-       $dbh->do("ALTER TABLE `borrowers` ADD COLUMN `altcontactaddress2` varchar(255)");
-       $dbh->do("ALTER TABLE `borrowers` ADD COLUMN `altcontactaddress3` varchar(255)");
-       $dbh->do("ALTER TABLE `borrowers` ADD COLUMN `altcontactzipcode` varchar(50)");
-       $dbh->do("ALTER TABLE `borrowers` ADD COLUMN `altcontactphone` varchar(50)");
+    $dbh->do("ALTER TABLE `borrowers` ADD COLUMN `altcontactsurname` varchar(255)");
+    $dbh->do("ALTER TABLE `borrowers` ADD COLUMN `altcontactaddress1` varchar(255)");
+    $dbh->do("ALTER TABLE `borrowers` ADD COLUMN `altcontactaddress2` varchar(255)");
+    $dbh->do("ALTER TABLE `borrowers` ADD COLUMN `altcontactaddress3` varchar(255)");
+    $dbh->do("ALTER TABLE `borrowers` ADD COLUMN `altcontactzipcode` varchar(50)");
+    $dbh->do("ALTER TABLE `borrowers` ADD COLUMN `altcontactphone` varchar(50)");
     print "Upgrade to $DBversion done (Adding Alternative Contact Person information to borrowers table)\n";
     SetVersion ($DBversion);
 }
 
 $DBversion = "3.00.00.038";
 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
-    $dbh->do("UPDATE `systempreferences` set explanation='Choose the fines mode, \'off\', \'test\' (emails admin report) or \'production\' (accrue overdue fines).  Requires fines cron script' , options='off|test|production' where variable='finesMode'");
-       $dbh->do('DELETE FROM `systempreferences` WHERE variable='hideBiblioNumber'");
+    $dbh->do("UPDATE `systempreferences` set explanation='Choose the fines mode, off, test (emails admin report) or production (accrue overdue fines).  Requires fines cron script' , options='off|test|production' where variable='finesMode'");
+    $dbh->do("DELETE FROM `systempreferences` WHERE variable='hideBiblioNumber'");
     print "Upgrade to $DBversion done ('alter finesMode systempreference, remove superfluous syspref.')\n";
     SetVersion ($DBversion);
 }
 
+$DBversion = "3.00.00.039";
+if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
+    $dbh->do("INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('uppercasesurnames',0,'If ON, surnames are converted to upper case in patron entry form',NULL,'YesNo')");
+    $dbh->do("INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('CircControl','ItemHomeLibrary','Specify the agency that controls the circulation and fines policy','PickupLibrary|PatronLibrary|ItemHomeLibrary','Choice')");
+    $dbh->do("INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('finesCalendar','noFinesWhenClosed','Specify whether to use the Calendar in calculating duedates and fines','ignoreCalendar|noFinesWhenClosed','Choice')");
+    $dbh->do("DELETE FROM `systempreferences` WHERE variable='HomeOrHoldingBranch'");
+    print "Upgrade to $DBversion done ('add circ sysprefs CircControl, finesCalendar, and uppercasesurnames, and delete HomeOrHoldingBranch.')\n";
+    SetVersion ($DBversion);
+}
+
+$DBversion = "3.00.00.040";
+if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
+       $dbh->do("INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('previousIssuesDefaultSortOrder','asc','Specify the sort order of Previous Issues on the circulation page','asc|desc','Choice')");
+       $dbh->do("INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES('todaysIssuesDefaultSortOrder','desc','Specify the sort order of Todays Issues on the circulation page','asc|desc','Choice')");
+       print "Upgrade to $DBversion done ('add circ sysprefs todaysIssuesDefaultSortOrder and previousIssuesDefaultSortOrder.')\n";
+    SetVersion ($DBversion);
+}
+
+
+$DBversion = "3.00.00.041";
+if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
+    # Strictly speaking it is not necessary to explicitly change
+    # NULL values to 0, because the ALTER TABLE statement will do that.
+    # However, setting them first avoids a warning.
+    $dbh->do("UPDATE items SET notforloan = 0 WHERE notforloan IS NULL");
+    $dbh->do("UPDATE items SET damaged = 0 WHERE damaged IS NULL");
+    $dbh->do("UPDATE items SET itemlost = 0 WHERE itemlost IS NULL");
+    $dbh->do("UPDATE items SET wthdrawn = 0 WHERE wthdrawn IS NULL");
+    $dbh->do("ALTER TABLE items
+                MODIFY notforloan tinyint(1) NOT NULL default 0,
+                MODIFY damaged    tinyint(1) NOT NULL default 0,
+                MODIFY itemlost   tinyint(1) NOT NULL default 0,
+                MODIFY wthdrawn   tinyint(1) NOT NULL default 0");
+       print "Upgrade to $DBversion done (disallow NULL in several item status columns)\n";
+    SetVersion ($DBversion);
+}
+
+$DBversion = "3.00.00.042";
+if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
+    $dbh->do("ALTER TABLE aqbooksellers CHANGE name name mediumtext NOT NULL");
+       print "Upgrade to $DBversion done (disallow NULL in aqbooksellers.name; part of fix for bug 1251)\n";
+    SetVersion ($DBversion);
+}
+
+$DBversion = "3.00.00.043";
+if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
+    $dbh->do("ALTER TABLE `currency` ADD `symbol` varchar(5) default NULL, ADD `timestamp` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP");
+       print "Upgrade to $DBversion done (currency table: add symbol and timestamp columns)\n";
+    SetVersion ($DBversion);
+}
+
+$DBversion = "3.00.00.044";
+if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
+    $dbh->do("ALTER TABLE deletedborrowers
+  ADD `altcontactfirstname` varchar(255) default NULL,
+  ADD `altcontactsurname` varchar(255) default NULL,
+  ADD `altcontactaddress1` varchar(255) default NULL,
+  ADD `altcontactaddress2` varchar(255) default NULL,
+  ADD `altcontactaddress3` varchar(255) default NULL,
+  ADD `altcontactzipcode` varchar(50) default NULL,
+  ADD `altcontactphone` varchar(50) default NULL
+  ");
+  $dbh->do("INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES
+('OPACBaseURL',NULL,'Specify the Base URL of the OPAC, e.g., opac.mylibrary.com, the http:// will be added automatically by Koha.',NULL,'Free'),
+('language','en','Set the default language in the staff client.',NULL,'Languages'),
+('QueryAutoTruncate',1,'If ON, query truncation is enabled by default',NULL,'YesNo'),
+('QueryRemoveStopwords',0,'If ON, stopwords listed in the Administration area will be removed from queries',NULL,'YesNo')
+  ");
+        print "Upgrade to $DBversion done (syncing deletedborrowers table with borrowers table)\n";
+    SetVersion ($DBversion);
+}
+
+#-- http://www.w3.org/International/articles/language-tags/
+
+#-- RFC4646
+$DBversion = "3.00.00.045";
+if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
+    $dbh->do("
+CREATE TABLE language_subtag_registry (
+        subtag varchar(25),
+        type varchar(25), -- language-script-region-variant-extension-privateuse
+        description varchar(25), -- only one of the possible descriptions for ease of reference, see language_descriptions for the complete list
+        added date,
+        KEY `subtag` (`subtag`)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8");
+
+#-- TODO: add suppress_scripts
+#-- this maps three letter codes defined in iso639.2 back to their
+#-- two letter equivilents in rfc4646 (LOC maintains iso639+)
+ $dbh->do("CREATE TABLE language_rfc4646_to_iso639 (
+        rfc4646_subtag varchar(25),
+        iso639_2_code varchar(25),
+        KEY `rfc4646_subtag` (`rfc4646_subtag`)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8");
+
+ $dbh->do("CREATE TABLE language_descriptions (
+        subtag varchar(25),
+        type varchar(25),
+        lang varchar(25),
+        description varchar(255),
+        KEY `lang` (`lang`)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8");
+
+#-- bi-directional support, keyed by script subcode
+ $dbh->do("CREATE TABLE language_script_bidi (
+        rfc4646_subtag varchar(25), -- script subtag, Arab, Hebr, etc.
+        bidi varchar(3), -- rtl ltr
+        KEY `rfc4646_subtag` (`rfc4646_subtag`)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8");
+
+#-- BIDI Stuff, Arabic and Hebrew
+ $dbh->do("INSERT INTO language_script_bidi(rfc4646_subtag,bidi)
+VALUES( 'Arab', 'rtl')");
+ $dbh->do("INSERT INTO language_script_bidi(rfc4646_subtag,bidi)
+VALUES( 'Hebr', 'rtl')");
+
+#-- TODO: need to map language subtags to script subtags for detection
+#-- of bidi when script is not specified (like ar, he)
+ $dbh->do("CREATE TABLE language_script_mapping (
+        language_subtag varchar(25),
+        script_subtag varchar(25),
+        KEY `language_subtag` (`language_subtag`)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8");
+
+#-- Default mappings between script and language subcodes
+ $dbh->do("INSERT INTO language_script_mapping(language_subtag,script_subtag)
+VALUES( 'ar', 'Arab')");
+ $dbh->do("INSERT INTO language_script_mapping(language_subtag,script_subtag)
+VALUES( 'he', 'Hebr')");
+
+        print "Upgrade to $DBversion done (adding language subtag registry and basic BiDi support NOTE: You should import the subtag registry SQL)\n";
+    SetVersion ($DBversion);
+}
+
+$DBversion = "3.00.00.046";
+if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
+    $dbh->do("ALTER TABLE `subscription` CHANGE `numberlength` `numberlength` int(11) default NULL , 
+                CHANGE `weeklength` `weeklength` int(11) default NULL");
+    $dbh->do("CREATE TABLE `serialitems` (`serialid` int(11) NOT NULL, `itemnumber` int(11) NOT NULL, UNIQUE KEY (`serialid`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8");
+    $dbh->do("INSERT INTO `serialitems` SELECT `serialid`,`itemnumber` from serial where NOT ISNULL(itemnumber) && itemnumber <> '' && itemnumber NOT LIKE '%,%'");
+       print "Upgrade to $DBversion done (Add serialitems table to link serial issues to items. )\n";
+    SetVersion ($DBversion);
+}
+
+$DBversion = "3.00.00.047";
+if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
+    $dbh->do("INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('OpacRenewalAllowed',0,'If ON, users can renew their issues directly from their OPAC account',NULL,'YesNo');");
+       print "Upgrade to $DBversion done ( Added OpacRenewalAllowed syspref )\n";
+    SetVersion ($DBversion);
+}
+
+$DBversion = "3.00.00.048";
+if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
+    $dbh->do("ALTER TABLE `items` ADD `more_subfields_xml` longtext default NULL");
+       print "Upgrade to $DBversion done (added items.more_subfields_xml)\n";
+    SetVersion ($DBversion);
+}
+
+$DBversion = "3.00.00.049";
+if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
+       $dbh->do("ALTER TABLE `z3950servers` ADD `encoding` text default NULL ");
+       print "Upgrade to $DBversion done ( Added encoding field to z3950servers table )\n";
+    SetVersion ($DBversion);
+}
+
+$DBversion = "3.00.00.050";
+if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
+    $dbh->do("INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('OpacHighlightedWords','0','If Set, query matched terms are highlighted in OPAC',NULL,'YesNo');");
+       print "Upgrade to $DBversion done ( Added OpacHighlightedWords syspref )\n";
+    SetVersion ($DBversion);
+}
+
+$DBversion = "3.00.00.051";
+if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
+    $dbh->do("UPDATE systempreferences SET explanation = 'Define the current theme for the OPAC interface.' WHERE variable = 'opacthemes';");
+       print "Upgrade to $DBversion done ( Corrected opacthemes explanation. )\n";
+    SetVersion ($DBversion);
+}
+
+$DBversion = "3.00.00.052";
+if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
+    $dbh->do("ALTER TABLE `deleteditems` ADD `more_subfields_xml` LONGTEXT DEFAULT NULL;");
+       print "Upgrade to $DBversion done ( Adding missing column to deleteditems table. )\n";
+    SetVersion ($DBversion);
+}
+
+$DBversion = "3.00.00.053"; 
+if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
+    $dbh->do("CREATE TABLE `printers_profile` (
+            `prof_id` int(4) NOT NULL auto_increment,
+            `printername` varchar(40) NOT NULL,
+            `tmpl_id` int(4) NOT NULL,
+            `paper_bin` varchar(20) NOT NULL,
+            `offset_horz` float default NULL,
+            `offset_vert` float default NULL,
+            `creep_horz` float default NULL,
+            `creep_vert` float default NULL,
+            `unit` char(20) NOT NULL default 'POINT',
+            PRIMARY KEY  (`prof_id`),
+            UNIQUE KEY `printername` (`printername`,`tmpl_id`,`paper_bin`),
+            CONSTRAINT `printers_profile_pnfk_1` FOREIGN KEY (`tmpl_id`) REFERENCES `labels_templates` (`tmpl_id`) ON DELETE CASCADE ON UPDATE CASCADE
+            ) ENGINE=InnoDB DEFAULT CHARSET=utf8 ");
+    $dbh->do("CREATE TABLE `labels_profile` (
+            `tmpl_id` int(4) NOT NULL,
+            `prof_id` int(4) NOT NULL,
+            UNIQUE KEY `tmpl_id` (`tmpl_id`),
+            UNIQUE KEY `prof_id` (`prof_id`)
+            ) ENGINE=InnoDB DEFAULT CHARSET=utf8 ");
+    print "Upgrade to $DBversion done ( Printer Profile tables added )\n";
+    SetVersion ($DBversion);
+}   
+
+$DBversion = "3.00.00.054";
+if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
+    $dbh->do("UPDATE systempreferences SET options = 'incremental|annual|hbyymmincr|OFF', explanation = 'Used to autogenerate a barcode: incremental will be of the form 1, 2, 3; annual of the form 2007-0001, 2007-0002; hbyymmincr of the form HB08010001 where HB = Home Branch' WHERE variable = 'autoBarcode';");
+       print "Upgrade to $DBversion done ( Added another barcode autogeneration sequence to barcode.pl. )\n";
+    SetVersion ($DBversion);
+}
+
+$DBversion = "3.00.00.055";
+if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
+    $dbh->do("ALTER TABLE `zebraqueue` ADD KEY `zebraqueue_lookup` (`server`, `biblio_auth_number`, `operation`, `done`)");
+       print "Upgrade to $DBversion done ( Added index on zebraqueue. )\n";
+    SetVersion ($DBversion);
+}
+$DBversion = "3.00.00.056";
+if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
+    $dbh->do("INSERT INTO `marc_subfield_structure` (`tagfield`, `tagsubfield`, `liblibrarian`, `libopac`, `repeatable`, `mandatory`, `kohafield`, `tab`, `authorised_value` , `authtypecode`, `value_builder`, `isurl`, `hidden`, `frameworkcode`, `seealso`, `link`, `defaultvalue`) VALUES ('952', 'h', 'Serial Enumeration / chronology','Serial Enumeration / chronology', 0, 0, 'items.enumchron', 10, '', '', '', 0, 0, '', '', '', NULL) ");
+    $dbh->do("ALTER TABLE `items` ADD `enumchron` VARCHAR(80) DEFAULT NULL;");
+    print "Upgrade to $DBversion done ( Added item.enumchron column, and framework map to 952h )\n";
+    SetVersion ($DBversion);
+}
+    
+$DBversion = "3.00.00.057";
+if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
+    $dbh->do("INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('OAI-PMH','0','if ON, OAI-PMH server is enabled',NULL,'YesNo');");
+    $dbh->do("INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('OAI-PMH:archiveID','KOHA-OAI-TEST','OAI-PMH archive identification',NULL,'Free');");
+    $dbh->do("INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('OAI-PMH:MaxCount','50','OAI-PMH maximum number of records by answer to ListRecords and ListIdentifiers queries',NULL,'Integer');");
+    $dbh->do("INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('OAI-PMH:Set','SET,Experimental set\r\nSET:SUBSET,Experimental subset','OAI-PMH exported set, the set name is followed by a comma and a short description, one set by line',NULL,'Free');");
+    $dbh->do("INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('OAI-PMH:Subset',\"itemtype='BOOK'\",'Restrict answer to matching raws of the biblioitems table (experimental)',NULL,'Free');");
+    SetVersion ($DBversion);
+}
+
+$DBversion = "3.00.00.058";
+if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
+    $dbh->do("ALTER TABLE `opac_news` 
+                CHANGE `lang` `lang` VARCHAR( 25 ) 
+                CHARACTER SET utf8 
+                COLLATE utf8_general_ci 
+                NOT NULL ");
+       print "Upgrade to $DBversion done ( lang field in opac_news made longer )\n";
+    SetVersion ($DBversion);
+}
+
+$DBversion = "3.00.00.059";
+if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
+
+    $dbh->do("CREATE TABLE IF NOT EXISTS `labels_templates` (
+            `tmpl_id` int(4) NOT NULL auto_increment,
+            `tmpl_code` char(100)  default '',
+            `tmpl_desc` char(100) default '',
+            `page_width` float default '0',
+            `page_height` float default '0',
+            `label_width` float default '0',
+            `label_height` float default '0',
+            `topmargin` float default '0',
+            `leftmargin` float default '0',
+            `cols` int(2) default '0',
+            `rows` int(2) default '0',
+            `colgap` float default '0',
+            `rowgap` float default '0',
+            `active` int(1) default NULL,
+            `units` char(20)  default 'PX',
+            `fontsize` int(4) NOT NULL default '3',
+            PRIMARY KEY  (`tmpl_id`)
+            ) ENGINE=InnoDB DEFAULT CHARSET=utf8;");
+    $dbh->do("CREATE TABLE  IF NOT EXISTS `printers_profile` (
+            `prof_id` int(4) NOT NULL auto_increment,
+            `printername` varchar(40) NOT NULL,
+            `tmpl_id` int(4) NOT NULL,
+            `paper_bin` varchar(20) NOT NULL,
+            `offset_horz` float default NULL,
+            `offset_vert` float default NULL,
+            `creep_horz` float default NULL,
+            `creep_vert` float default NULL,
+            `unit` char(20) NOT NULL default 'POINT',
+            PRIMARY KEY  (`prof_id`),
+            UNIQUE KEY `printername` (`printername`,`tmpl_id`,`paper_bin`),
+            CONSTRAINT `printers_profile_pnfk_1` FOREIGN KEY (`tmpl_id`) REFERENCES `labels_templates` (`tmpl_id`) ON DELETE CASCADE ON UPDATE CASCADE
+            ) ENGINE=InnoDB DEFAULT CHARSET=utf8 ");
+    print "Upgrade to $DBversion done ( Added labels_templates table if it did not exist. )\n";
+    SetVersion ($DBversion);
+}
+
+$DBversion = "3.00.00.060";
+if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
+    $dbh->do("CREATE TABLE IF NOT EXISTS `patronimage` (
+            `cardnumber` varchar(16) NOT NULL,
+            `mimetype` varchar(15) NOT NULL,
+            `imagefile` mediumblob NOT NULL,
+            PRIMARY KEY  (`cardnumber`),
+            CONSTRAINT `patronimage_fk1` FOREIGN KEY (`cardnumber`) REFERENCES `borrowers` (`cardnumber`) ON DELETE CASCADE ON UPDATE CASCADE
+            ) ENGINE=InnoDB DEFAULT CHARSET=utf8;");
+       print "Upgrade to $DBversion done ( Added patronimage table. )\n";
+    SetVersion ($DBversion);
+}
+
+$DBversion = "3.00.00.061";
+if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
+    $dbh->do("ALTER TABLE labels_templates ADD COLUMN font char(10) NOT NULL DEFAULT 'TR';");
+       print "Upgrade to $DBversion done ( Added font column to labels_templates )\n";
+    SetVersion ($DBversion);
+}
+
+$DBversion = "3.00.00.062";
+if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
+    $dbh->do("CREATE TABLE `old_issues` (
+                `borrowernumber` int(11) default NULL,
+                `itemnumber` int(11) default NULL,
+                `date_due` date default NULL,
+                `branchcode` varchar(10) default NULL,
+                `issuingbranch` varchar(18) default NULL,
+                `returndate` date default NULL,
+                `lastreneweddate` date default NULL,
+                `return` varchar(4) default NULL,
+                `renewals` tinyint(4) default NULL,
+                `timestamp` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
+                `issuedate` date default NULL,
+                KEY `old_issuesborridx` (`borrowernumber`),
+                KEY `old_issuesitemidx` (`itemnumber`),
+                KEY `old_bordate` (`borrowernumber`,`timestamp`),
+                CONSTRAINT `old_issues_ibfk_1` FOREIGN KEY (`borrowernumber`) REFERENCES `borrowers` (`borrowernumber`) 
+                    ON DELETE SET NULL ON UPDATE SET NULL,
+                CONSTRAINT `old_issues_ibfk_2` FOREIGN KEY (`itemnumber`) REFERENCES `items` (`itemnumber`) 
+                    ON DELETE SET NULL ON UPDATE SET NULL
+                ) ENGINE=InnoDB DEFAULT CHARSET=utf8");
+    $dbh->do("CREATE TABLE `old_reserves` (
+                `borrowernumber` int(11) default NULL,
+                `reservedate` date default NULL,
+                `biblionumber` int(11) default NULL,
+                `constrainttype` varchar(1) default NULL,
+                `branchcode` varchar(10) default NULL,
+                `notificationdate` date default NULL,
+                `reminderdate` date default NULL,
+                `cancellationdate` date default NULL,
+                `reservenotes` mediumtext,
+                `priority` smallint(6) default NULL,
+                `found` varchar(1) default NULL,
+                `timestamp` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
+                `itemnumber` int(11) default NULL,
+                `waitingdate` date default NULL,
+                KEY `old_reserves_borrowernumber` (`borrowernumber`),
+                KEY `old_reserves_biblionumber` (`biblionumber`),
+                KEY `old_reserves_itemnumber` (`itemnumber`),
+                KEY `old_reserves_branchcode` (`branchcode`),
+                CONSTRAINT `old_reserves_ibfk_1` FOREIGN KEY (`borrowernumber`) REFERENCES `borrowers` (`borrowernumber`) 
+                    ON DELETE SET NULL ON UPDATE SET NULL,
+                CONSTRAINT `old_reserves_ibfk_2` FOREIGN KEY (`biblionumber`) REFERENCES `biblio` (`biblionumber`) 
+                    ON DELETE SET NULL ON UPDATE SET NULL,
+                CONSTRAINT `old_reserves_ibfk_3` FOREIGN KEY (`itemnumber`) REFERENCES `items` (`itemnumber`) 
+                    ON DELETE SET NULL ON UPDATE SET NULL
+                ) ENGINE=InnoDB DEFAULT CHARSET=utf8");
+
+    # move closed transactions to old_* tables
+    $dbh->do("INSERT INTO old_issues SELECT * FROM issues WHERE returndate IS NOT NULL");
+    $dbh->do("DELETE FROM issues WHERE returndate IS NOT NULL");
+    $dbh->do("INSERT INTO old_reserves SELECT * FROM reserves WHERE cancellationdate IS NOT NULL OR found = 'F'");
+    $dbh->do("DELETE FROM reserves WHERE cancellationdate IS NOT NULL OR found = 'F'");
+
+       print "Upgrade to $DBversion done ( Added old_issues and old_reserves tables )\n";
+    SetVersion ($DBversion);
+}
+
+$DBversion = "3.00.00.063";
+if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
+    $dbh->do("ALTER TABLE deleteditems
+                CHANGE COLUMN booksellerid booksellerid MEDIUMTEXT DEFAULT NULL,
+                ADD COLUMN enumchron VARCHAR(80) DEFAULT NULL AFTER more_subfields_xml,
+                ADD COLUMN copynumber SMALLINT(6) DEFAULT NULL AFTER enumchron;");
+    $dbh->do("ALTER TABLE items
+                CHANGE COLUMN booksellerid booksellerid MEDIUMTEXT,
+                ADD COLUMN copynumber SMALLINT(6) DEFAULT NULL AFTER enumchron;");
+       print "Upgrade to $DBversion done ( Changed items.booksellerid and deleteditems.booksellerid to MEDIUMTEXT and added missing items.copynumber and deleteditems.copynumber to fix Bug 1927)\n";
+    SetVersion ($DBversion);
+}
+
+$DBversion = "3.00.00.064";
+if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
+    $dbh->do("INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('AmazonLocale','US','Use to set the Locale of your Amazon.com Web Services','US|CA|DE|FR|JP|UK','Choice');");
+    $dbh->do("INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('AWSAccessKeyID','','See:  http://aws.amazon.com','','free');");
+    $dbh->do("DELETE FROM `systempreferences` WHERE variable='AmazonDevKey';");
+    $dbh->do("DELETE FROM `systempreferences` WHERE variable='XISBNAmazonSimilarItems';");
+    $dbh->do("DELETE FROM `systempreferences` WHERE variable='OPACXISBNAmazonSimilarItems';");
+    print "Upgrade to $DBversion done (IMPORTANT: Upgrading to Amazon.com Associates Web Service 4.0 ) ";
+    SetVersion ($DBversion);
+}
+
+$DBversion = "3.00.00.065";
+if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
+    $dbh->do("CREATE TABLE `patroncards` (
+                `cardid` int(11) NOT NULL auto_increment,
+                `batch_id` varchar(10) NOT NULL default '1',
+                `borrowernumber` int(11) NOT NULL,
+                `timestamp` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
+                PRIMARY KEY  (`cardid`),
+                KEY `patroncards_ibfk_1` (`borrowernumber`),
+                CONSTRAINT `patroncards_ibfk_1` FOREIGN KEY (`borrowernumber`) REFERENCES `borrowers` (`borrowernumber`) ON DELETE CASCADE ON UPDATE CASCADE
+                ) ENGINE=InnoDB DEFAULT CHARSET=utf8;");
+    print "Upgrade to $DBversion done (Adding patroncards table for patroncards generation feature. ) ";
+    SetVersion ($DBversion);
+}
+
+$DBversion = "3.00.00.066";
+if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
+    $dbh->do("ALTER TABLE `virtualshelfcontents` MODIFY `dateadded` timestamp NOT NULL
+DEFAULT CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP;
+");
+    print "Upgrade to $DBversion done (fix for bug 1873: virtualshelfcontents dateadded column empty. ) ";
+    SetVersion ($DBversion);
+}
+
 =item DropAllForeignKeys($table)
 
   Drop all foreign keys of the table $table
@@ -859,10 +1280,9 @@ sub SetVersion {
       my $finish=$dbh->prepare("UPDATE systempreferences SET value=? WHERE variable='Version'");
       $finish->execute($kohaversion);
     } else {
-      my $finish=$dbh->prepare("INSERT into systempreferences (variable,value,explanation) values ('Version',?,'The Koha database version. Don t change this value manually, it s holded by the webinstaller')");
+      my $finish=$dbh->prepare("INSERT into systempreferences (variable,value,explanation) values ('Version',?,'The Koha database version. WARNING: Do not change this value manually, it is maintained by the webinstaller')");
       $finish->execute($kohaversion);
     }
 }
 exit;
 
-# Revision 1.172  2007/07/19 10:21:22  hdl