From 93e3f68e97990f4f9571f0087d17d66c2e31d159 Mon Sep 17 00:00:00 2001 From: root Date: Thu, 28 Jan 2021 17:38:08 +0100 Subject: [PATCH] Drush_Update_2021-01-28_17_38 --- install.php | 573 +++++++++++++++++++++++++++ install.php.org | 3 + update.php | 1003 +++++++++++++++++++++++++++++++++++++++++++++++ update.php.org | 4 + 4 files changed, 1583 insertions(+) create mode 100644 install.php create mode 100644 update.php diff --git a/install.php b/install.php new file mode 100644 index 0000000..bc64c17 --- /dev/null +++ b/install.php @@ -0,0 +1,573 @@ + + // Copyright: Matthias Steffens and the file's + // original author(s). + // + // This code is distributed in the hope that it will be useful, + // but WITHOUT ANY WARRANTY. Please see the GNU General Public + // License for more details. + // + // File: ./install.php + // Repository: $HeadURL: file:///svn/p/refbase/code/branches/bleeding-edge/install.php $ + // Author(s): Matthias Steffens + // + // Created: 07-Jan-04, 22:00 + // Modified: $Date: 2015-02-16 20:53:19 +0000 (Mon, 16 Feb 2015) $ + // $Author: karnesky $ + // $Revision: 1405 $ + + // This file will install the literature database for you. Note that you must have + // an existing PHP and MySQL installation. Please see the readme for further information. + // CAUTION: YOU MUST REMOVE THIS SCRIPT FROM YOUR WEB DIRECTORY AFTER INSTALLATION!! + + + // Incorporate some include files: + include 'initialize/db.inc.php'; // 'db.inc.php' is included to hide username and password + include 'includes/header.inc.php'; // include header + include 'includes/footer.inc.php'; // include footer + include 'includes/include.inc.php'; // include common functions + include 'includes/install.inc.php'; // include install/update functions + include 'initialize/ini.inc.php'; // include common variables + + // -------------------------------------------------------------------- + + // START A SESSION: + // call the 'start_session()' function (from 'include.inc.php') which will also read out available session variables: + start_session(false); + + // -------------------------------------------------------------------- + + // Initialize preferred display language: + // (note that 'locales.inc.php' has to be included *after* the call to the 'start_session()' function) + include 'includes/locales.inc.php'; // include the locales + + // -------------------------------------------------------------------- + + // This specifies the name of the database that handles the MySQL user access privileges. + // Unless you've fiddled with it, you shouldn't change the default value ('mysql'): + $adminDatabaseName = 'mysql'; + + // Extract any parameters passed to the script: + if (isset($_POST['adminUserName'])) + $adminUserName = $_POST['adminUserName']; + else + $adminUserName = ""; + + if (isset($_POST['adminPassword'])) + $adminPassword = $_POST['adminPassword']; + else + $adminPassword = ""; + + if (isset($_POST['pathToMYSQL'])) + $pathToMYSQL = $_POST['pathToMYSQL']; + else + $pathToMYSQL = ""; + + if (isset($_POST['databaseStructureFile'])) + $databaseStructureFile = $_POST['databaseStructureFile']; + else + $databaseStructureFile = ""; + + if (isset($_POST['pathToBibutils'])) + $pathToBibutils = $_POST['pathToBibutils']; + else + $pathToBibutils = ""; + + if (isset($_POST['defaultCharacterSet'])) + $defaultCharacterSet = $_POST['defaultCharacterSet']; + else + $defaultCharacterSet = ""; + + // -------------------------------------------------------------------- + + // Check the correct parameters have been passed: + if (empty($adminUserName) AND empty($adminPassword) AND empty($pathToMYSQL) AND empty($databaseStructureFile)) + { + // if 'install.php' was called without any valid parameters: + //Display an installation form: + + if (isset($_SESSION['errors'])) + { + $errors = $_SESSION['errors']; + + // Note: though we clear the session variable, the current error message is still available to this script via '$errors': + deleteSessionVariable("errors"); // function 'deleteSessionVariable()' is defined in 'include.inc.php' + } + else + $errors = array(); // initialize the '$errors' variable in order to prevent 'Undefined variable...' messages + + if (isset($_SESSION['formVars'])) + { + $formVars = $_SESSION['formVars']; + + // Note: though we clear the session variable, the current form variables are still available to this script via '$formVars': + deleteSessionVariable("formVars"); // function 'deleteSessionVariable()' is defined in 'include.inc.php' + } + else + { + // Reset the '$formVars' variable (since we're providing the default values): + $formVars = array(); + $pathSeparator = PATH_SEPARATOR; + $pathItems = explode($pathSeparator, getenv("PATH")); + + // Provide default values for the form fields: + $formVars["adminUserName"] = "root"; + $formVars["adminPassword"] = ""; + $formVars["databaseStructureFile"] = "./install.sql"; + + // Try to find the 'mysql' command line interpreter: + $mysqlLocations = array_unique(array_merge($pathItems, array("/Program Files/MySQL/bin", "/wamp/mysql/bin", "/Program Files/xampp/mysql/bin", "/www/xampp/mysql/bin", "/xampp/mysql/bin", "/apachefriends/xampp/mysql/bin", "/usr/local/mysql/bin", "/usr/local/bin/mysql/bin", "/usr/bin/mysql/bin", "/usr/mysql/bin", "/opt/local/bin/", "/opt/local/lib/mysql4/bin/", "/opt/local/lib/mysql5/bin/"))); + $mysqlNames = array("mysql", "mysql.exe"); + $formVars["pathToMYSQL"] = locateFile($mysqlLocations, $mysqlNames, false); // function 'locateFile()' is defined in 'install.inc.php' + + // Try to find the Bibutils programs: + $bibutilsLocations = array_unique(array_merge($pathItems, array("/usr/bin", "/usr/local/bin", "/opt/local/bin/", ".", "./refbase", "./bibutils"))); + // We'll only check for one program to save time (and because, we currently don't allow the script to have a subset of the functionality provided by Bibutils) + $bibutilsNames = array("xml2bib", "xml2bib.exe"); + $formVars["pathToBibutils"] = locateFile($bibutilsLocations, $bibutilsNames, true); + + $formVars["defaultCharacterSet"] = "latin1"; + } + + // If there's no stored message available: + if (!isset($_SESSION['HeaderString'])) + { + if (empty($errors)) // provide the default message: + $HeaderString = "To install the refbase package please fill out the form below and click the Install button:"; + else // -> there were errors when validating the fields + $HeaderString = "There were validation errors regarding the details you entered. Please check the comments above the respective fields:"; + } + else + { + $HeaderString = $_SESSION['HeaderString']; // extract 'HeaderString' session variable (only necessary if register globals is OFF!) + + // Note: though we clear the session variable, the current message is still available to this script via '$HeaderString': + deleteSessionVariable("HeaderString"); // function 'deleteSessionVariable()' is defined in 'include.inc.php' + } + + // Extract the view type requested by the user (either 'Mobile', 'Print', 'Web' or ''): + // ('' will produce the default 'Web' output style) + if (isset($_REQUEST['viewType'])) + $viewType = $_REQUEST['viewType']; + else + $viewType = ""; + + // For the default character set, make sure that the correct popup menu entry is selected upon reload: + if ($formVars["defaultCharacterSet"] == "utf8") + { + $latin1CharacterSetSelected = ""; + $unicodeCharacterSetSelected = " selected"; + } + else // $formVars["defaultCharacterSet"] is 'latin1' or '' + { + $latin1CharacterSetSelected = " selected"; + $unicodeCharacterSetSelected = ""; + } + + // Show the login status: + showLogin(); // (function 'showLogin()' is defined in 'include.inc.php') + + // DISPLAY header: + // call the 'displayHTMLhead()' and 'showPageHeader()' functions (which are defined in 'header.inc.php'): + displayHTMLhead(encodeHTML($officialDatabaseName) . " -- Installation", "index,follow", "Installation form for the " . encodeHTML($officialDatabaseName), "", false, "", $viewType, array()); + showPageHeader($HeaderString); + + // Start
and holding the form elements: +?> + + + + within a form field (instead of clicking the "Install" button) ?> + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

refbase Installation

Important note: + Before executing this script, it is highly recommended to open the include file initialize/db.inc.php in a text editor and edit the values of the variables $databaseName, $username and $password to suit your setup! Then, proceed with this form: +
MySQL admin user: + + " size="30"> + Give the name of an administrative user that has full access to the MySQL admin database. Often, this is the root user.
MySQL admin password:Please type your password again:\n\t\t\t
"; + else + echo fieldError("adminPassword", $errors); +?> + + +
Please enter the password for the administrative user you've specified above.
Path to the MySQL application: + + " size="30"> + Specify the full path to the mysql command line interpreter. The install script attempts to locate the mysql program for you. If the field is empty, please enter the full path manually.
Path to the database structure file: + + " size="30"> + Enter the full path to the SQL dump file containing the database structure & data. Keep the default value, if you're installing refbase for the first time.
Path to the Bibutils directory [optional]: + + " size="30"> + Bibutils provides additional import and export funtionality to refbase (e.g. support for Endnote & BibTeX). It is optional, but highly recommended. The install script attempts to locate Bibutils for you. If you can't access Bibutils from your path, please fill this value in manually (and, if you think other people might have Bibutils installed to the same path, report it to the refbase developers). The path must end with a slash!
Default character set: + + + Specify the default character set for the MySQL database used by refbase. Note that utf8 (Unicode) requires MySQL 4.1.x or greater, otherwise latin1 (i.e., ISO-8859-1 West European) will be used by default.
  + + CAUTION: Note that, if there's already an existing refbase database with the name specified in $databaseName, clicking the Install button will overwrite ALL data in that database! If you'd like to install the refbase tables into another existing database, you must ensure that there are no table name conflicts (more info).
+
$value) + $formVars[$varname] = $value; + + + // Validate the 'adminUserName' field: + if (empty($formVars["adminUserName"])) + // The 'adminUserName' field cannot be a null string + $errors["adminUserName"] = "This field cannot be blank:"; + + + // Validate the 'adminPassword' field: + if (empty($formVars["adminPassword"])) + // The 'adminPassword' field cannot be a null string + $errors["adminPassword"] = "This field cannot be blank:"; + + + // Validate the 'pathToMYSQL' field: + if (empty($formVars["pathToMYSQL"])) + // The 'pathToMYSQL' field cannot be a null string + $errors["pathToMYSQL"] = "This field cannot be blank:"; + + elseif (preg_match("/[;|]/", $formVars["pathToMYSQL"])) + // For security reasons, the 'pathToMYSQL' field cannot contain the characters ';' or '|' (which would tie multiple shell commands together) + $errors["pathToMYSQL"] = "Due to security reasons this field cannot contain the characters ';' or '|':"; + + elseif (is_dir($formVars["pathToMYSQL"])) + // Check if the specified path resolves to a directory + $errors["pathToMYSQL"] = "You cannot specify a directory! Please give the path to the mysql command:"; + + elseif (!is_readable($formVars["pathToMYSQL"])) + // Check if the specified path resolves to the mysql application + $errors["pathToMYSQL"] = "Your path specification is invalid (command not found):"; + +// Note: Currently, the checks for whether the function is executable or whether it is mysql have been commented out, +// since they don't seem to work on windows! (see ) + +// elseif (!is_executable($formVars["pathToMYSQL"])) +// // Check if the given file is executable +// $errors["pathToMYSQL"] = "This file does not appear to be an executable command:"; + +// elseif (!preg_match("#(^|.*/)mysql$#", $formVars["pathToMYSQL"])) +// // Make sure that the given file is 'mysql' +// $errors["pathToMYSQL"] = "This does not appear to be the 'mysql' command line interpreter:"; + + + // Validate the 'databaseStructureFile' field: + if (empty($formVars["databaseStructureFile"])) + // The 'databaseStructureFile' field cannot be a null string + $errors["databaseStructureFile"] = "This field cannot be blank:"; + + elseif (preg_match("/[;|]/", $formVars["databaseStructureFile"])) + // For security reasons, the 'databaseStructureFile' field cannot contain the characters ';' or '|' (which would tie multiple shell commands together) + $errors["databaseStructureFile"] = "Due to security reasons this field cannot contain the characters ';' or '|':"; + + elseif (is_dir($formVars["databaseStructureFile"])) + // Check if the specified path resolves to a directory + $errors["databaseStructureFile"] = "You cannot specify a directory! Please give the path to the database structure file:"; + + elseif (!is_readable($formVars["databaseStructureFile"])) + // Check if the specified path resolves to the database structure file + $errors["databaseStructureFile"] = "Your path specification is invalid (file not found):"; + + + // Validate the 'pathToBibutils' field: + if (!empty($formVars["pathToBibutils"])) // we'll only validate the 'pathToBibutils' field if it isn't empty (installation of Bibutils is optional) + { + if (preg_match("/[;|]/", $formVars["pathToBibutils"])) + // For security reasons, the 'pathToBibutils' field cannot contain the characters ';' or '|' (which would tie multiple shell commands together) + $errors["pathToBibutils"] = "Due to security reasons this field cannot contain the characters ';' or '|':"; + + elseif (!is_readable($formVars["pathToBibutils"])) + // Check if the specified path resolves to an existing directory + $errors["pathToBibutils"] = "Your path specification is invalid (directory not found):"; + + elseif (!is_dir($formVars["pathToBibutils"])) + // Check if the specified path resolves to a directory (and not a file) + $errors["pathToBibutils"] = "You must specify a directory! Please give the path to the directory containing the Bibutils utilities:"; + } + + + // Validate the 'defaultCharacterSet' field: + // Note: Currently we're not generating an error & rooting back to the install form, if the user did choose 'utf8' but has some MySQL version < 4.1 installed. + // In this case, we'll simply ignore the setting and 'latin1' will be used by default. + + // -------------------------------------------------------------------- + + // Now the script has finished the validation, check if there were any errors: + if (count($errors) > 0) + { + // Write back session variables: + saveSessionVariable("errors", $errors); // function 'saveSessionVariable()' is defined in 'include.inc.php' + saveSessionVariable("formVars", $formVars); + + // There are errors. Relocate back to the installation form: + header("Location: install.php"); + + exit; // >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> !EXIT! <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< + } + + // -------------------------------------------------------------------- + + // If we made it here, then the data is considered valid! + + // (1) Open the database connection and use the mysql database: + if (!($connection = @ mysql_connect($hostName,$adminUserName,$adminPassword))) + if (mysql_errno() != 0) // this works around a stupid(?) behaviour of the Roxen webserver that returns 'errno: 0' on success! ?:-( + showErrorMsg("The following error occurred while trying to connect to the host:", ""); + + if (!(mysql_select_db($adminDatabaseName, $connection))) + if (mysql_errno() != 0) // this works around a stupid(?) behaviour of the Roxen webserver that returns 'errno: 0' on success! ?:-( + showErrorMsg("The following error occurred while trying to connect to the database:", ""); + + + // First, check if we're a dealing with MySQL version 4.1.x or greater: + // (MySQL 4.1.x is required if the refbase MySQL database/tables shall be installed using Unicode/UTF-8 as default character set) + $mysqlVersion = getMySQLversion(); // function 'getMySQLversion()' is defined in 'include.inc.php' + + // -------------------------------------------------------------------- + + // Prepare the install queries and proceed with the actual installation procedure: + + // Build the database queries required for installation: + $queryGrantStatement = "GRANT SELECT,INSERT,UPDATE,DELETE ON " . $databaseName . ".* TO " . quote_smart($username) . "@" . quote_smart($hostName) . " IDENTIFIED BY " . quote_smart($password); + + $queryCreateDB = "CREATE DATABASE IF NOT EXISTS " . $databaseName; // by default, 'latin1' will be used as default character set + + if ($mysqlVersion >= 4.1) // if MySQL 4.1.x (or greater) is installed... + { + $queryCreateDB = $queryCreateDB . " DEFAULT CHARACTER SET " . $defaultCharacterSet; // ...add the default character set chosen by the user + + if ($defaultCharacterSet == "utf8") // ...in case of UTF-8, adjust the path to the default database structure file if necessary + if ($databaseStructureFile == "./install.sql") + $databaseStructureFile = "./install_utf8.sql"; + } + + if (!empty($pathToBibutils)) // we'll only update the Bibutils path if '$pathToBibutils' isn't empty (installation of Bibutils is optional) + $queryUpdateDependsTable = "UPDATE " . $databaseName . "." . $tableDepends . " SET depends_path = " . quote_smart($pathToBibutils) . " WHERE depends_external = \"bibutils\""; // update the Bibutils path spec + else // we set the 'depends_enabled' field in table 'depends' to 'false' to indicate that Bibutils isn't installed + $queryUpdateDependsTable = "UPDATE " . $databaseName . "." . $tableDepends . " SET depends_enabled = \"false\" WHERE depends_external = \"bibutils\""; // disable Bibutils functionality + + // (2) Run the INSTALL queries on the mysql database through the connection: + if (!($result = @ mysql_query ($queryGrantStatement, $connection))) + if (mysql_errno() != 0) // this works around a stupid(?) behaviour of the Roxen webserver that returns 'errno: 0' on success! ?:-( + showErrorMsg("The following error occurred while trying to query the database:", ""); + + if (!($result = @ mysql_query ($queryCreateDB, $connection))) + if (mysql_errno() != 0) // this works around a stupid(?) behaviour of the Roxen webserver that returns 'errno: 0' on success! ?:-( + showErrorMsg("The following error occurred while trying to query the database:", ""); + + // IMPORT the literature database structure from file: + exec($pathToMYSQL . " -h " . $hostName . " -u " . $adminUserName . " -p" . $adminPassword . " --database=" . $databaseName . " < " . $databaseStructureFile . " 2>&1", $resultArray); + + // User note from regarding the use of PHP's 'exec()' command: + // From 'eremy at ntb dot co dot nz' (28-Sep-2003 03:18): + // If an error occurs in the code you're trying to exec(), it can be challenging to figure out what's going + // wrong, since php echoes back the stdout stream rather than the stderr stream where all the useful error + // reporting's done. The solution is to add the code "2>&1" to the end of your shell command, which redirects + // stderr to stdout, which you can then easily print using something like print `shellcommand 2>&1`. + + // run the UPDATE query on the depends table of the (just imported) literature database: + if (!($result = @ mysql_query ($queryUpdateDependsTable, $connection))) + if (mysql_errno() != 0) // this works around a stupid(?) behaviour of the Roxen webserver that returns 'errno: 0' on success! ?:-( + showErrorMsg("The following error occurred while trying to query the database:", ""); + + // (5) Close the database connection: + if (!(mysql_close($connection))) + if (mysql_errno() != 0) // this works around a stupid(?) behaviour of the Roxen webserver that returns 'errno: 0' on success! ?:-( + showErrorMsg("The following error occurred while trying to disconnect from the database:", ""); + + $resultLines = ""; // initialize variable + + // Read out the execution result array: + if (!empty($resultArray)) // if there were any execution errors + { + reset($resultArray); // reset the internal array pointer to the first element + while (list ($key, $val) = each ($resultArray)) + $resultLines .= "\n" . trim($val); // append each of the array elements to a string + } + + // -------------------------------------------------------------------- + + // Provide a feedback page: + + // If there's no stored message available: + if (!isset($_SESSION['HeaderString'])) // provide one of the default messages: + { + if (!empty($resultArray)) // if there were any execution errors + $HeaderString = "The following error occurred while trying to import the SQL data into the database:"; + else // assume that the installation was successful + $HeaderString = "Installation of the Web Reference Database was successful!"; + } + else + { + $HeaderString = $_SESSION['HeaderString']; // extract 'HeaderString' session variable (only necessary if register globals is OFF!) + + // Note: though we clear the session variable, the current message is still available to this script via '$HeaderString': + deleteSessionVariable("HeaderString"); // function 'deleteSessionVariable()' is defined in 'include.inc.php' + } + + // Extract the view type requested by the user (either 'Mobile', 'Print', 'Web' or ''): + // ('' will produce the default 'Web' output style) + if (isset($_REQUEST['viewType'])) + $viewType = $_REQUEST['viewType']; + else + $viewType = ""; + + // Show the login status: + showLogin(); // (function 'showLogin()' is defined in 'include.inc.php') + + // DISPLAY header: + // call the 'displayHTMLhead()' and 'showPageHeader()' functions (which are defined in 'header.inc.php'): + displayHTMLhead(encodeHTML($officialDatabaseName) . " -- Installation Feedback", "index,follow", "Installation feedback for the " . encodeHTML($officialDatabaseName), "", false, "", $viewType, array()); + showPageHeader($HeaderString); + + // Start a : +?> + +
+ + + + + + + + + + + + + inform the user about successful database installation: + { +?> + + + + + + + + + + + + + + + + + +
Error:
  + Please make sure that you've specified the correct path to the MySQL database structure file! +
  + Go Back +

Welcome to refbase!

Important Note: + The install.php script is only provided for installation purposes and is not needed anymore. Due to security considerations you should remove this script from your web directory NOW!! +
Setup users: + Here's how to setup the admin user account for your newly created literature database: +
    +
  • Goto
  • +
  • Login with email address = user@refbase.net & password = start
  • +
  • Click on Add User and enter the name, institutional abbreviation, email address and password of the admin user
  • +
  • Open the file ini.inc.php in a text editor and change the value of the $adminLoginEmail variable to the email address you've specified for the admin user
  • +
  • Log out, then login again using the email address and password of your newly created admin account
  • +
+ If you want to add additional users use the Add User link and enter the user's name, institutional abbreviation, email address and password. +
Configure refbase: + In order to customize your literature database, please open again ini.inc.php in a text editor. This include file contains variables that are common to all scripts and whose values can/must be adopted to your needs. Please see the comments within the file for further information. +
diff --git a/install.php.org b/install.php.org index 64f2c41..bc64c17 100644 --- a/install.php.org +++ b/install.php.org @@ -1,4 +1,7 @@ // Copyright: Matthias Steffens and the file's // original author(s). diff --git a/update.php b/update.php new file mode 100644 index 0000000..1b6db04 --- /dev/null +++ b/update.php @@ -0,0 +1,1003 @@ + + // Copyright: Matthias Steffens and the file's + // original author(s). + // + // This code is distributed in the hope that it will be useful, + // but WITHOUT ANY WARRANTY. Please see the GNU General Public + // License for more details. + // + // File: ./update.php + // Repository: $HeadURL: file:///svn/p/refbase/code/branches/bleeding-edge/update.php $ + // Author(s): Matthias Steffens + // + // Created: 01-Mar-05, 20:47 + // Modified: $Date: 2015-02-16 20:53:19 +0000 (Mon, 16 Feb 2015) $ + // $Author: karnesky $ + // $Revision: 1405 $ + + // This file will update any refbase MySQL database installation from v0.8.0 or greater to v0.9.6. + // (Note that this script currently doesn't offer any conversion from 'latin1' to 'utf8') + // CAUTION: YOU MUST REMOVE THIS SCRIPT FROM YOUR WEB DIRECTORY AFTER THE UPDATE!! + + + // Incorporate some include files: + include 'initialize/db.inc.php'; // 'db.inc.php' is included to hide username and password + include 'includes/header.inc.php'; // include header + include 'includes/footer.inc.php'; // include footer + include 'includes/include.inc.php'; // include common functions + include 'includes/install.inc.php'; // include install/update functions + include 'initialize/ini.inc.php'; // include common variables + + // -------------------------------------------------------------------- + + // START A SESSION: + // call the 'start_session()' function (from 'include.inc.php') which will also read out available session variables: + start_session(false); + + // -------------------------------------------------------------------- + + // Initialize preferred display language: + // (note that 'locales.inc.php' has to be included *after* the call to the 'start_session()' function) + include 'includes/locales.inc.php'; // include the locales + + // -------------------------------------------------------------------- + + // This specifies the name of the database that handles the MySQL user access privileges. + // Unless you've fiddled with it, you shouldn't change the default value ('mysql'): + $adminDatabaseName = 'mysql'; + + // Extract any parameters passed to the script: + if (isset($_REQUEST['adminUserName'])) + $adminUserName = $_REQUEST['adminUserName']; + else + $adminUserName = ""; + + if (isset($_REQUEST['adminPassword'])) + $adminPassword = $_REQUEST['adminPassword']; + else + $adminPassword = ""; + + // -------------------------------------------------------------------- + + // Check the correct parameters have been passed: + if (empty($adminUserName) AND empty($adminPassword)) + { + // if 'update.php' was called without any valid parameters: + // Display an update form: + + if (isset($_SESSION['errors'])) + { + $errors = $_SESSION['errors']; + + // Note: though we clear the session variable, the current error message is still available to this script via '$errors': + deleteSessionVariable("errors"); // function 'deleteSessionVariable()' is defined in 'include.inc.php' + } + else + $errors = array(); // initialize the '$errors' variable in order to prevent 'Undefined variable...' messages + + if (isset($_SESSION['formVars'])) + { + $formVars = $_SESSION['formVars']; + + // Note: though we clear the session variable, the current form variables are still available to this script via '$formVars': + deleteSessionVariable("formVars"); + } + else + { + // Reset the '$formVars' variable (since we're providing the default values): + $formVars = array(); + + // provide the default values: + $formVars["adminUserName"] = "root"; + $formVars["adminPassword"] = ""; + } + + // If there's no stored message available: + if (!isset($_SESSION['HeaderString'])) + { + if (empty($errors)) // provide the default message: + $HeaderString = "To update refbase v0.8.0 or greater please fill out the form below and click the Update button:"; + else // -> there were errors when validating the fields + $HeaderString = "There were validation errors regarding the details you entered. Please check the comments above the respective fields:"; + } + else + { + $HeaderString = $_SESSION['HeaderString']; // extract 'HeaderString' session variable (only necessary if register globals is OFF!) + + // Note: though we clear the session variable, the current message is still available to this script via '$HeaderString': + deleteSessionVariable("HeaderString"); + } + + // Extract the view type requested by the user (either 'Mobile', 'Print', 'Web' or ''): + // ('' will produce the default 'Web' output style) + if (isset($_REQUEST['viewType'])) + $viewType = $_REQUEST['viewType']; + else + $viewType = ""; + + // Show the login status: + showLogin(); // (function 'showLogin()' is defined in 'include.inc.php') + + // DISPLAY header: + // call the 'displayHTMLhead()' and 'showPageHeader()' functions (which are defined in 'header.inc.php'): + displayHTMLhead(encodeHTML($officialDatabaseName) . " -- Update", "index,follow", "Update form for the " . encodeHTML($officialDatabaseName), "", false, "", $viewType, array()); + showPageHeader($HeaderString); + + // Start
and holding the form elements: +?> + + + + within a form field (instead of clicking the "Update" button) ?> + +
+ + + + + + + + + + + + + + + + + + + + + + +

refbase Update

Important Notes: + It's important that you make a backup copy of your original files db.inc.php and ini.inc.php (which are located within the initialize subdirectory of your refbase base directory). We also strongly recommend to backup your existing refbase MySQL database before proceeding. +
+
+ Before executing this script, you must edit the updated include file initialize/db.inc.php in a text editor and re-enter the values from your old db.inc.php file for the variables $databaseName, $username and $password. Then, proceed with this form: +
MySQL Admin User: + + " size="30"> + Give the name of an administrative user that has full access to your MySQL database. Often, this is the root user.
MySQL Admin Password:Please type your password again:\n\t\t\t
"; + else + echo fieldError("adminPassword", $errors); +?> + + +
Please enter the password for the administrative user you've specified above.
  + +  
+
$value) + $formVars[$varname] = $value; + + + // Validate the 'adminUserName' field: + if (empty($formVars["adminUserName"])) + // The 'adminUserName' field cannot be a null string + $errors["adminUserName"] = "This field cannot be blank:"; + + + // Validate the 'adminPassword' field: + if (empty($formVars["adminPassword"])) + // The 'adminPassword' field cannot be a null string + $errors["adminPassword"] = "This field cannot be blank:"; + + // -------------------------------------------------------------------- + + // Now the script has finished the validation, check if there were any errors: + if (count($errors) > 0) + { + // Write back session variables: + saveSessionVariable("errors", $errors); // function 'saveSessionVariable()' is defined in 'include.inc.php' + saveSessionVariable("formVars", $formVars); + + // There are errors. Relocate back to the update form: + header("Location: update.php"); + + exit; // >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> !EXIT! <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< + } + + // -------------------------------------------------------------------- + + // If we made it here, then the data is considered valid! + + // (0) CLOSE EXISTING CONNECTION + // we have to close the existing connection since we need to establish a new connection with admin permissions + disconnectFromMySQLDatabase(); // function 'disconnectFromMySQLDatabase()' is defined in 'include.inc.php' + + // (1) OPEN ADMIN CONNECTION, (2) SELECT DATABASE + connectToMySQLDatabaseAsAdmin($adminUserName, $adminPassword); // function 'connectToMySQLDatabaseAsAdmin()' is defined in 'install.inc.php' + + // -------------------------------------------------------------------- + + // (2) RUN the SQL queries on the database through the admin connection: + + // NOTE: many simple, brain-dead UPDATE queries follow below + // (we should probably have a SQL function and/or make this an array and process that) + + $resultArray = array(); + + // Alter table specification for table 'deleted' + // TODO: create a new function 'changeColumn()' that only modifies the column spec if the new column spec is different from the old one + $query = "ALTER table " . $tableDeleted . " MODIFY edition varchar(50) default NULL"; + $result = queryMySQLDatabase($query); + $resultArray["Table 'deleted': altered table specification. Affected rows"] = ($result ? mysql_affected_rows($connection) : 0); // get the number of rows that were modified (or return 0 if an error occurred) + + $query = "ALTER table " . $tableDeleted . " MODIFY thesis enum('Bachelor''s thesis','Honours thesis','Master''s thesis','Ph.D. thesis','Diploma thesis','Doctoral thesis','Habilitation thesis') default NULL"; + $result = queryMySQLDatabase($query); + $resultArray["Table 'deleted': altered table specification. Affected rows"] = ($result ? mysql_affected_rows($connection) : 0); + + // Alter table specification for table 'refs' + $query = "ALTER table " . $tableRefs . " MODIFY edition varchar(50) default NULL"; + $result = queryMySQLDatabase($query); + $resultArray["Table 'refs': altered table specification. Affected rows"] = ($result ? mysql_affected_rows($connection) : 0); + + $query = "ALTER table " . $tableRefs . " MODIFY thesis enum('Bachelor''s thesis','Honours thesis','Master''s thesis','Ph.D. thesis','Diploma thesis','Doctoral thesis','Habilitation thesis') default NULL"; + $result = queryMySQLDatabase($query); + $resultArray["Table 'refs': altered table specification. Affected rows"] = ($result ? mysql_affected_rows($connection) : 0); + + // Add field 'version' to table 'deleted' + $properties = "MEDIUMINT(8) UNSIGNED DEFAULT 1 AFTER modified_by"; + $resultArray["Table 'deleted': added field 'version'"] = addColumnIfNotExists("version", $tableDeleted, $properties); // function 'addColumnIfNotExists()' is defined in 'install.inc.php' + + // Add field 'version' to table 'refs' + $properties = "MEDIUMINT(8) UNSIGNED DEFAULT 1 AFTER modified_by"; + $resultArray["Table 'refs': added field 'version'"] = addColumnIfNotExists("version", $tableRefs, $properties); + + // Update table 'refs' + $query = "UPDATE " . $tableRefs . " SET thesis = NULL WHERE thesis = ''"; // this fix is required to ensure correct sorting when outputting citations with '$citeOrder="type"' or '$citeOrder="type-year"' + $result = queryMySQLDatabase($query); + $resultArray["Table 'refs': updated 'thesis' field (replaced empty string with NULL). Affected rows"] = ($result ? mysql_affected_rows($connection) : 0); + + $query = "UPDATE " . $tableRefs . " SET type = 'Conference Article' WHERE type RLIKE '^(Unsupported: )?Conference Proceeding$'"; // this may not be perfect since some items of type "Conference Proceeding" may be actually a "Conference Volume" + $result = queryMySQLDatabase($query); + $resultArray["Table 'refs': updated 'type' field ('Conference Proceeding' => 'Conference Article'). Affected rows"] = ($result ? mysql_affected_rows($connection) : 0); + + $query = "UPDATE " . $tableRefs . " SET type = 'Miscellaneous' WHERE type RLIKE '^(Unsupported: )?Generic$'"; + $result = queryMySQLDatabase($query); + $resultArray["Table 'refs': updated 'type' field ('Generic' => 'Miscellaneous'). Affected rows"] = ($result ? mysql_affected_rows($connection) : 0); + + $query = "UPDATE " . $tableRefs . " SET type = 'Newspaper Article' WHERE type RLIKE '^(Unsupported: )?Newspaper$'"; // this may not be perfect since some items of type "Newspaper" may be actually a "Newspaper Volume" + $result = queryMySQLDatabase($query); + $resultArray["Table 'refs': updated 'type' field ('Newspaper' => 'Newspaper Article'). Affected rows"] = ($result ? mysql_affected_rows($connection) : 0); + + $query = "UPDATE " . $tableRefs . " SET type = 'Software' WHERE type RLIKE '^(Unsupported: )?Computer Program$'"; + $result = queryMySQLDatabase($query); + $resultArray["Table 'refs': updated 'type' field ('Computer Program' => 'Software'). Affected rows"] = ($result ? mysql_affected_rows($connection) : 0); + + $query = "UPDATE " . $tableRefs . " SET type = REPLACE(type,'Unsupported: ','') WHERE type RLIKE '^Unsupported: (Abstract|Conference (Article|Volume)|Magazine Article|Manual|Miscellaneous|Newspaper Article|Patent|Report|Software)$'"; + $result = queryMySQLDatabase($query); + $resultArray["Table 'refs': updated 'type' field (removed 'Unsupported' label for all newly supported types). Affected rows"] = ($result ? mysql_affected_rows($connection) : 0); + + // Add new utilities to table 'depends' + $values = "(NULL, 'pdftotext', 'true', NULL)"; + $resultArray["Table 'depends': inserted entry for 'pdftotext' utility"] = insertIfNotExists(array("depends_external" => "pdftotext"), $tableDepends, $values); + + // Create new MySQL table 'user_options' + $properties = "(option_id MEDIUMINT(8) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, " + . "user_id MEDIUMINT(8) UNSIGNED NOT NULL DEFAULT '0', " + . "export_cite_keys ENUM('yes','no') NOT NULL DEFAULT 'yes', " + . "autogenerate_cite_keys ENUM('yes','no') NOT NULL DEFAULT 'yes', " + . "prefer_autogenerated_cite_keys ENUM('no','yes') NOT NULL DEFAULT 'no', " + . "use_custom_cite_key_format ENUM('no','yes') NOT NULL DEFAULT 'no', " + . "cite_key_format VARCHAR(255) DEFAULT NULL, " + . "uniquify_duplicate_cite_keys ENUM('yes','no') NOT NULL DEFAULT 'yes', " + . "nonascii_chars_in_cite_keys ENUM('transliterate','strip','keep') DEFAULT NULL, " + . "use_custom_text_citation_format ENUM('no','yes') NOT NULL DEFAULT 'no', " + . "text_citation_format VARCHAR(255) DEFAULT NULL, " + . "records_per_page SMALLINT(5) UNSIGNED DEFAULT NULL, " + . "show_auto_completions ENUM('yes','no') NOT NULL DEFAULT 'yes', " + . "main_fields TEXT, " + . "INDEX (user_id))"; + + $resultArray["Created table 'user_options'"] = addTableIfNotExists($tableUserOptions, $properties); // function 'addTableIfNotExists()' is defined in 'install.inc.php' + + // Insert default user options for anyone who's not logged in + $values = "(NULL, 0, 'yes', 'yes', 'no', 'no', '<:authors:><:year:>', 'yes', NULL, 'no', '<:authors[2| & | et al.]:>< :year:>< {:recordIdentifier:}>', NULL, 'author, title, publication, keywords, abstract')"; + $resultArray["Table 'user_options': inserted default options for anyone who's not logged in"] = insertIfNotExists(array("user_id" => 0), $tableUserOptions, $values); // function 'insertIfNotExists()' is defined in 'install.inc.php' + + // Insert default user options for all users + // First, check how many users are contained in table 'users': + $query = "SELECT user_id, first_name, last_name FROM " . $tableUsers; + $result = queryMySQLDatabase($query); // function 'queryMySQLDatabase()' is defined in 'include.inc.php' + $rowsFound = @ mysql_num_rows($result); + if ($rowsFound > 0) // If there were rows (= user IDs) found ... + { + while ($row = @ mysql_fetch_array($result)) + { + $values = "(NULL, " . $row['user_id'] . ", 'yes', 'yes', 'no', 'yes', '<:authors[2|+|++]:><:year:>', 'yes', 'transliterate', 'no', '<:authors[2| & | et al.]:>< :year:>< {:recordIdentifier:}>', NULL, 'author, title, publication, keywords, abstract')"; + $resultArray["Table 'user_options': inserted default options for user " . $row['user_id'] . " (" . $row['first_name'] . " " . $row['last_name'] . ")"] = insertIfNotExists(array("user_id" => $row['user_id']), $tableUserOptions, $values); + } + } + + // Add field 'records_per_page' to table 'user_options' + $properties = "SMALLINT(5) UNSIGNED DEFAULT NULL AFTER text_citation_format"; + $resultArray["Table 'user_options': added field 'records_per_page'"] = addColumnIfNotExists("records_per_page", $tableUserOptions, $properties); + + // Add field 'show_auto_completions' to table 'user_options' + $properties = "ENUM('yes','no') NOT NULL DEFAULT 'yes' AFTER records_per_page"; + $resultArray["Table 'user_options': added field 'show_auto_completions'"] = addColumnIfNotExists("show_auto_completions", $tableUserOptions, $properties); + + // Add field 'main_fields' to table 'user_options' + $properties = "TEXT AFTER show_auto_completions"; + $resultArray["Table 'user_options': added field 'main_fields'"] = addColumnIfNotExists("main_fields", $tableUserOptions, $properties); + + // Add field 'allow_browse_view' to table 'user_permissions' + $properties = "ENUM('yes','no') NOT NULL DEFAULT 'yes' AFTER allow_print_view"; + $resultArray["Table 'user_permissions': added field 'allow_browse_view'"] = addColumnIfNotExists("allow_browse_view", $tableUserPermissions, $properties); + + // Add field 'allow_list_view' to table 'user_permissions' + $properties = "ENUM('yes','no') NOT NULL DEFAULT 'yes' AFTER allow_upload"; + $resultArray["Table 'user_permissions': added field 'allow_list_view'"] = addColumnIfNotExists("allow_list_view", $tableUserPermissions, $properties); + + // Disable the Browse view feature (which isn't done yet) for all users + $query= "UPDATE " . $tableUserPermissions . " SET allow_browse_view = 'no'"; + $result = queryMySQLDatabase($query); + $resultArray["Table 'user_permissions': disabled the Browse view feature (which isn't done yet). Affected rows"] = ($result ? mysql_affected_rows($connection) : 0); + + // Enable the Export feature for anyone who's not logged in ('$userID = 0'): + $query= "UPDATE " . $tableUserPermissions . " SET allow_export = 'yes', allow_batch_export = 'yes' WHERE user_id = 0"; + $result = queryMySQLDatabase($query); + $resultArray["Table 'user_permissions': enabled the export feature for anyone who's not logged in. Affected rows"] = ($result ? mysql_affected_rows($connection) : 0); + + // Update table 'styles' + $query = "UPDATE " . $tableStyles . " SET style_spec = REPLACE(style_spec,'cite_','styles/cite_') WHERE style_spec RLIKE '^cite_'"; + $result = queryMySQLDatabase($query); + $resultArray["Table 'styles': updated 'style_spec' field. Affected rows"] = ($result ? mysql_affected_rows($connection) : 0); + + $values = "(NULL, 'Ann Glaciol', 'true', 'styles/cite_AnnGlaciol_JGlaciol.php', 'B010', '1')"; + $resultArray["Table 'styles': inserted style 'Ann Glaciol'"] = insertIfNotExists(array("style_name" => "Ann Glaciol"), $tableStyles, $values); + + $values = "(NULL, 'J Glaciol', 'true', 'styles/cite_AnnGlaciol_JGlaciol.php', 'B030', '1')"; + $resultArray["Table 'styles': inserted style 'J Glaciol'"] = insertIfNotExists(array("style_name" => "J Glaciol"), $tableStyles, $values); + + $values = "(NULL, 'APA', 'true', 'styles/cite_APA.php', 'A010', '1')"; + $resultArray["Table 'styles': inserted style 'APA'"] = insertIfNotExists(array("style_name" => "APA"), $tableStyles, $values); + + $values = "(NULL, 'AMA', 'true', 'styles/cite_AMA.php', 'A020', '1')"; + $resultArray["Table 'styles': inserted style 'AMA'"] = insertIfNotExists(array("style_name" => "AMA"), $tableStyles, $values); + + $values = "(NULL, 'MLA', 'true', 'styles/cite_MLA.php', 'A030', '1')"; + $resultArray["Table 'styles': inserted style 'MLA'"] = insertIfNotExists(array("style_name" => "MLA"), $tableStyles, $values); + + $values = "(NULL, 'Chicago', 'true', 'styles/cite_Chicago.php', 'A070', '1')"; + $resultArray["Table 'styles': inserted style 'Chicago'"] = insertIfNotExists(array("style_name" => "Chicago"), $tableStyles, $values); + + $values = "(NULL, 'Harvard 1', 'true', 'styles/cite_Harvard_1.php', 'A090', '1')"; + $resultArray["Table 'styles': inserted style 'Harvard 1'"] = insertIfNotExists(array("style_name" => "Harvard 1"), $tableStyles, $values); + + $values = "(NULL, 'Harvard 2', 'true', 'styles/cite_Harvard_2.php', 'A093', '1')"; + $resultArray["Table 'styles': inserted style 'Harvard 2'"] = insertIfNotExists(array("style_name" => "Harvard 2"), $tableStyles, $values); + + $values = "(NULL, 'Harvard 3', 'true', 'styles/cite_Harvard_3.php', 'A096', '1')"; + $resultArray["Table 'styles': inserted style 'Harvard 3'"] = insertIfNotExists(array("style_name" => "Harvard 3"), $tableStyles, $values); + + $values = "(NULL, 'Vancouver', 'true', 'styles/cite_Vancouver.php', 'A110', '1')"; + $resultArray["Table 'styles': inserted style 'Vancouver'"] = insertIfNotExists(array("style_name" => "Vancouver"), $tableStyles, $values); + + $query = "UPDATE " . $tableStyles . " SET order_by = 'B010' WHERE style_name = 'Ann Glaciol'"; + $result = queryMySQLDatabase($query); + $resultArray["Table 'styles': updated 'Ann Glaciol' style. Affected rows"] = ($result ? mysql_affected_rows($connection) : 0); + + $query = "UPDATE " . $tableStyles . " SET order_by = 'B020' WHERE style_name = 'Deep Sea Res'"; + $result = queryMySQLDatabase($query); + $resultArray["Table 'styles': updated 'Deep Sea Res' style. Affected rows"] = ($result ? mysql_affected_rows($connection) : 0); + + $query = "UPDATE " . $tableStyles . " SET order_by = 'B030' WHERE style_name = 'J Glaciol'"; + $result = queryMySQLDatabase($query); + $resultArray["Table 'styles': updated 'J Glaciol' style. Affected rows"] = ($result ? mysql_affected_rows($connection) : 0); + + $query = "UPDATE " . $tableStyles . " SET order_by = 'B040' WHERE style_name = 'Mar Biol'"; + $result = queryMySQLDatabase($query); + $resultArray["Table 'styles': updated 'Mar Biol' style. Affected rows"] = ($result ? mysql_affected_rows($connection) : 0); + + $query = "UPDATE " . $tableStyles . " SET order_by = 'B050' WHERE style_name = 'MEPS'"; + $result = queryMySQLDatabase($query); + $resultArray["Table 'styles': updated 'MEPS' style. Affected rows"] = ($result ? mysql_affected_rows($connection) : 0); + + $query = "UPDATE " . $tableStyles . " SET order_by = 'B060' WHERE style_name = 'Polar Biol'"; + $result = queryMySQLDatabase($query); + $resultArray["Table 'styles': updated 'Polar Biol' style. Affected rows"] = ($result ? mysql_affected_rows($connection) : 0); + + $query = "UPDATE " . $tableStyles . " SET order_by = 'C010' WHERE style_name = 'Text Citation'"; + $result = queryMySQLDatabase($query); + $resultArray["Table 'styles': updated 'Text Citation' style. Affected rows"] = ($result ? mysql_affected_rows($connection) : 0); + + // Update table 'types' + $query = "UPDATE " . $tableTypes . " SET order_by = '01' WHERE type_name = 'Journal Article'"; + $result = queryMySQLDatabase($query); + $resultArray["Table 'types': updated 'Journal Article' type. Affected rows"] = ($result ? mysql_affected_rows($connection) : 0); + + $query = "UPDATE " . $tableTypes . " SET order_by = '02' WHERE type_name = 'Abstract'"; + $result = queryMySQLDatabase($query); + $resultArray["Table 'types': updated 'Abstract' type. Affected rows"] = ($result ? mysql_affected_rows($connection) : 0); + + $query = "UPDATE " . $tableTypes . " SET order_by = '03' WHERE type_name = 'Book Chapter'"; + $result = queryMySQLDatabase($query); + $resultArray["Table 'types': updated 'Book Chapter' type. Affected rows"] = ($result ? mysql_affected_rows($connection) : 0); + + $query = "UPDATE " . $tableTypes . " SET order_by = '04' WHERE type_name = 'Book Whole'"; + $result = queryMySQLDatabase($query); + $resultArray["Table 'types': updated 'Book Whole' type. Affected rows"] = ($result ? mysql_affected_rows($connection) : 0); + + $query = "UPDATE " . $tableTypes . " SET order_by = '05' WHERE type_name = 'Conference Article'"; + $result = queryMySQLDatabase($query); + $resultArray["Table 'types': updated 'Conference Article' type. Affected rows"] = ($result ? mysql_affected_rows($connection) : 0); + + $query = "UPDATE " . $tableTypes . " SET order_by = '06' WHERE type_name = 'Conference Volume'"; + $result = queryMySQLDatabase($query); + $resultArray["Table 'types': updated 'Conference Volume' type. Affected rows"] = ($result ? mysql_affected_rows($connection) : 0); + + $query = "UPDATE " . $tableTypes . " SET order_by = '07' WHERE type_name = 'Journal'"; + $result = queryMySQLDatabase($query); + $resultArray["Table 'types': updated 'Journal' type. Affected rows"] = ($result ? mysql_affected_rows($connection) : 0); + + $query = "UPDATE " . $tableTypes . " SET order_by = '08' WHERE type_name = 'Magazine Article'"; + $result = queryMySQLDatabase($query); + $resultArray["Table 'types': updated 'Magazine Article' type. Affected rows"] = ($result ? mysql_affected_rows($connection) : 0); + + $query = "UPDATE " . $tableTypes . " SET order_by = '09' WHERE type_name = 'Manual'"; + $result = queryMySQLDatabase($query); + $resultArray["Table 'types': updated 'Manual' type. Affected rows"] = ($result ? mysql_affected_rows($connection) : 0); + + $query = "UPDATE " . $tableTypes . " SET order_by = '10' WHERE type_name = 'Manuscript'"; + $result = queryMySQLDatabase($query); + $resultArray["Table 'types': updated 'Manuscript' type. Affected rows"] = ($result ? mysql_affected_rows($connection) : 0); + + $query = "UPDATE " . $tableTypes . " SET order_by = '11' WHERE type_name = 'Map'"; + $result = queryMySQLDatabase($query); + $resultArray["Table 'types': updated 'Map' type. Affected rows"] = ($result ? mysql_affected_rows($connection) : 0); + + $query = "UPDATE " . $tableTypes . " SET order_by = '12' WHERE type_name = 'Miscellaneous'"; + $result = queryMySQLDatabase($query); + $resultArray["Table 'types': updated 'Miscellaneous' type. Affected rows"] = ($result ? mysql_affected_rows($connection) : 0); + + $query = "UPDATE " . $tableTypes . " SET order_by = '13' WHERE type_name = 'Newspaper Article'"; + $result = queryMySQLDatabase($query); + $resultArray["Table 'types': updated 'Newspaper Article' type. Affected rows"] = ($result ? mysql_affected_rows($connection) : 0); + + $query = "UPDATE " . $tableTypes . " SET order_by = '14' WHERE type_name = 'Patent'"; + $result = queryMySQLDatabase($query); + $resultArray["Table 'types': updated 'Patent' type. Affected rows"] = ($result ? mysql_affected_rows($connection) : 0); + + $query = "UPDATE " . $tableTypes . " SET order_by = '15' WHERE type_name = 'Report'"; + $result = queryMySQLDatabase($query); + $resultArray["Table 'types': updated 'Report' type. Affected rows"] = ($result ? mysql_affected_rows($connection) : 0); + + $query = "UPDATE " . $tableTypes . " SET order_by = '16' WHERE type_name = 'Software'"; + $result = queryMySQLDatabase($query); + $resultArray["Table 'types': updated 'Software' type. Affected rows"] = ($result ? mysql_affected_rows($connection) : 0); + + $values = "(NULL, 'Abstract', 'true', 2, '02')"; + $resultArray["Table 'types': inserted type 'Abstract'"] = insertIfNotExists(array("type_name" => "Abstract"), $tableTypes, $values); + + $values = "(NULL, 'Conference Article', 'true', 2, '05')"; + $resultArray["Table 'types': inserted type 'Conference Article'"] = insertIfNotExists(array("type_name" => "Conference Article"), $tableTypes, $values); + + $values = "(NULL, 'Conference Volume', 'true', 3, '06')"; + $resultArray["Table 'types': inserted type 'Conference Volume'"] = insertIfNotExists(array("type_name" => "Conference Volume"), $tableTypes, $values); + + $values = "(NULL, 'Magazine Article', 'true', 1, '08')"; + $resultArray["Table 'types': inserted type 'Magazine Article'"] = insertIfNotExists(array("type_name" => "Magazine Article"), $tableTypes, $values); + + $values = "(NULL, 'Manual', 'true', 3, '09')"; + $resultArray["Table 'types': inserted type 'Manual'"] = insertIfNotExists(array("type_name" => "Manual"), $tableTypes, $values); + + $values = "(NULL, 'Miscellaneous', 'true', 3, '12')"; + $resultArray["Table 'types': inserted type 'Miscellaneous'"] = insertIfNotExists(array("type_name" => "Miscellaneous"), $tableTypes, $values); + + $values = "(NULL, 'Newspaper Article', 'true', 1, '13')"; + $resultArray["Table 'types': inserted type 'Newspaper Article'"] = insertIfNotExists(array("type_name" => "Newspaper Article"), $tableTypes, $values); + + $values = "(NULL, 'Patent', 'true', 3, '14')"; + $resultArray["Table 'types': inserted type 'Patent'"] = insertIfNotExists(array("type_name" => "Patent"), $tableTypes, $values); + + $values = "(NULL, 'Report', 'true', 3, '15')"; + $resultArray["Table 'types': inserted type 'Report'"] = insertIfNotExists(array("type_name" => "Report"), $tableTypes, $values); + + $values = "(NULL, 'Software', 'true', 3, '16')"; + $resultArray["Table 'types': inserted type 'Software'"] = insertIfNotExists(array("type_name" => "Software"), $tableTypes, $values); + + // Add new language options to table 'languages' + $values = "(NULL, 'fr', 'true', '3')"; + $resultArray["Table 'languages': inserted French language option"] = insertIfNotExists(array("language_name" => "fr"), $tableLanguages, $values); + + $values = "(NULL, 'es', 'false', '4')"; + $resultArray["Table 'languages': inserted Spanish language option"] = insertIfNotExists(array("language_name" => "es"), $tableLanguages, $values); + + $values = "(NULL, 'cn', 'true', '5')"; + $resultArray["Table 'languages': inserted Chinese language option"] = insertIfNotExists(array("language_name" => "cn"), $tableLanguages, $values); + + $values = "(NULL, 'ru', 'true', '6')"; + $resultArray["Table 'languages': inserted Russian language option"] = insertIfNotExists(array("language_name" => "ru"), $tableLanguages, $values); + + $values = "(NULL, 'ja', 'true', '7')"; + $resultArray["Table 'languages': inserted Japanese language option"] = insertIfNotExists(array("language_name" => "ja"), $tableLanguages, $values); + + // Enable disabled localizations + $query = "UPDATE " . $tableLanguages . " SET language_enabled = 'true' WHERE language_name = 'de'"; + $result = queryMySQLDatabase($query); + $resultArray["Table 'languages': enabled German language option. Affected rows"] = ($result ? mysql_affected_rows($connection) : 0); + + // Alter table specification for table 'formats' + $query = "ALTER table " . $tableFormats . " MODIFY format_type enum('export','import','cite') NOT NULL default 'export'"; + $result = queryMySQLDatabase($query); + $resultArray["Table 'formats': altered table specification. Affected rows"] = ($result ? mysql_affected_rows($connection) : 0); + + // Update existing formats in table 'formats' + $query = "UPDATE " . $tableFormats . " SET format_name = 'BibTeX' WHERE format_name = 'Bibtex'"; + $result = queryMySQLDatabase($query); + $resultArray["Table 'formats': renamed format name 'Bibtex' to 'BibTeX'. Affected rows"] = ($result ? mysql_affected_rows($connection) : 0); + + // Update existing import formats in table 'formats' + $query = "UPDATE " . $tableFormats . " SET format_spec = 'bibutils/import_bib2refbase.php', order_by = 'A010' WHERE format_name = 'BibTeX' AND format_type = 'import'"; + $result = queryMySQLDatabase($query); + $resultArray["Table 'formats': updated 'BibTeX' import format. Affected rows"] = ($result ? mysql_affected_rows($connection) : 0); + + $query = "UPDATE " . $tableFormats . " SET order_by = 'A020' WHERE format_name = 'Copac' AND format_type = 'import'"; + $result = queryMySQLDatabase($query); + $resultArray["Table 'formats': updated 'Copac' import format. Affected rows"] = ($result ? mysql_affected_rows($connection) : 0); + + $query = "UPDATE " . $tableFormats . " SET order_by = 'A030' WHERE format_name = 'CSA' AND format_type = 'import'"; + $result = queryMySQLDatabase($query); + $resultArray["Table 'formats': updated 'CSA' import format. Affected rows"] = ($result ? mysql_affected_rows($connection) : 0); + + $query = "UPDATE " . $tableFormats . " SET format_spec = 'bibutils/import_end2refbase.php', order_by = 'A040' WHERE format_name = 'Endnote' AND format_type = 'import'"; + $result = queryMySQLDatabase($query); + $resultArray["Table 'formats': updated 'Endnote' import format. Affected rows"] = ($result ? mysql_affected_rows($connection) : 0); + + $query = "UPDATE " . $tableFormats . " SET order_by = 'A045' WHERE format_name = 'Endnote XML' AND format_type = 'import'"; + $result = queryMySQLDatabase($query); + $resultArray["Table 'formats': updated 'Endnote XML' import format. Affected rows"] = ($result ? mysql_affected_rows($connection) : 0); + + $query = "UPDATE " . $tableFormats . " SET format_name = 'ISI', format_spec = 'import_isi2refbase.php', order_by = 'A050', depends_id = 1 WHERE (format_name = 'RIS (ISI)' OR format_name = 'ISI') AND format_type = 'import'"; + $result = queryMySQLDatabase($query); + $resultArray["Table 'formats': updated 'ISI' import format. Affected rows"] = ($result ? mysql_affected_rows($connection) : 0); + + $query = "UPDATE " . $tableFormats . " SET order_by = 'A060' WHERE format_name = 'Pubmed Medline' AND format_type = 'import'"; + $result = queryMySQLDatabase($query); + $resultArray["Table 'formats': updated 'Pubmed Medline' import format. Affected rows"] = ($result ? mysql_affected_rows($connection) : 0); + + $query = "UPDATE " . $tableFormats . " SET format_spec = 'bibutils/import_med2refbase.php', order_by = 'A065' WHERE format_name = 'Pubmed XML' AND format_type = 'import'"; + $result = queryMySQLDatabase($query); + $resultArray["Table 'formats': updated 'Pubmed XML' import format. Affected rows"] = ($result ? mysql_affected_rows($connection) : 0); + + $query = "UPDATE " . $tableFormats . " SET order_by = 'A070' WHERE format_name = 'RefWorks' AND format_type = 'import'"; + $result = queryMySQLDatabase($query); + $resultArray["Table 'formats': updated 'RefWorks' import format. Affected rows"] = ($result ? mysql_affected_rows($connection) : 0); + + $query = "UPDATE " . $tableFormats . " SET format_spec = 'import_ris2refbase.php', order_by = 'A080', depends_id = 1 WHERE format_name = 'RIS' AND format_type = 'import'"; + $result = queryMySQLDatabase($query); + $resultArray["Table 'formats': updated 'RIS' import format. Affected rows"] = ($result ? mysql_affected_rows($connection) : 0); + + $query = "UPDATE " . $tableFormats . " SET order_by = 'A090' WHERE format_name = 'SciFinder' AND format_type = 'import'"; + $result = queryMySQLDatabase($query); + $resultArray["Table 'formats': updated 'SciFinder' import format. Affected rows"] = ($result ? mysql_affected_rows($connection) : 0); + + $query = "UPDATE " . $tableFormats . " SET order_by = 'A100' WHERE format_name = 'Text (Tab-Delimited)' AND format_type = 'import'"; + $result = queryMySQLDatabase($query); + $resultArray["Table 'formats': updated 'Text (Tab-Delimited)' import format. Affected rows"] = ($result ? mysql_affected_rows($connection) : 0); + + $query = "UPDATE " . $tableFormats . " SET order_by = 'A150' WHERE format_name = 'CrossRef XML' AND format_type = 'import'"; + $result = queryMySQLDatabase($query); + $resultArray["Table 'formats': updated 'CrossRef XML' import format. Affected rows"] = ($result ? mysql_affected_rows($connection) : 0); + + $query = "UPDATE " . $tableFormats . " SET format_spec = 'bibutils/import_modsxml2refbase.php', order_by = 'A160', depends_id = 2 WHERE format_name = 'MODS XML' AND format_type = 'import'"; + $result = queryMySQLDatabase($query); + $resultArray["Table 'formats': updated 'MODS XML' import format. Affected rows"] = ($result ? mysql_affected_rows($connection) : 0); + + $query = "UPDATE " . $tableFormats . " SET order_by = 'A170' WHERE format_name = 'OAI_DC XML' AND format_type = 'import'"; + $result = queryMySQLDatabase($query); + $resultArray["Table 'formats': updated 'OAI_DC XML' import format. Affected rows"] = ($result ? mysql_affected_rows($connection) : 0); + + // Add new import formats in table 'formats' + $values = "(NULL, 'Copac', 'import', 'true', 'bibutils/import_copac2refbase.php', 'A020', 2)"; + $resultArray["Table 'formats': inserted 'Copac' import format"] = insertIfNotExists(array("format_name" => "Copac", "format_type" => "import"), $tableFormats, $values); + + $values = "(NULL, 'CSA', 'import', 'true', 'import_csa2refbase.php', 'A030', 1)"; + $resultArray["Table 'formats': inserted 'CSA' import format"] = insertIfNotExists(array("format_name" => "CSA", "format_type" => "import"), $tableFormats, $values); + + $values = "(NULL, 'Endnote XML', 'import', 'true', 'bibutils/import_endx2refbase.php', 'A045', 2)"; + $resultArray["Table 'formats': inserted 'Endnote XML' import format"] = insertIfNotExists(array("format_name" => "Endnote XML", "format_type" => "import"), $tableFormats, $values); + + $values = "(NULL, 'Pubmed Medline', 'import', 'true', 'import_medline2refbase.php', 'A060', 1)"; + $resultArray["Table 'formats': inserted 'Pubmed Medline' import format"] = insertIfNotExists(array("format_name" => "Pubmed Medline", "format_type" => "import"), $tableFormats, $values); + + $values = "(NULL, 'RefWorks', 'import', 'true', 'import_refworks2refbase.php', 'A070', 1)"; + $resultArray["Table 'formats': inserted 'RefWorks' import format"] = insertIfNotExists(array("format_name" => "RefWorks", "format_type" => "import"), $tableFormats, $values); + + $values = "(NULL, 'SciFinder', 'import', 'true', 'import_scifinder2refbase.php', 'A090', 1)"; + $resultArray["Table 'formats': inserted 'SciFinder' import format"] = insertIfNotExists(array("format_name" => "SciFinder", "format_type" => "import"), $tableFormats, $values); + + $values = "(NULL, 'Text (Tab-Delimited)', 'import', 'true', 'import_tabdelim2refbase.php', 'A100', 1)"; + $resultArray["Table 'formats': inserted 'Text (Tab-Delimited)' import format"] = insertIfNotExists(array("format_name" => "Text (Tab-Delimited)", "format_type" => "import"), $tableFormats, $values); + + $values = "(NULL, 'arXiv XML', 'import', 'true', 'import_arxiv2refbase.php', 'A130', 1)"; + $resultArray["Table 'formats': inserted 'arXiv XML' import format"] = insertIfNotExists(array("format_name" => "arXiv XML", "format_type" => "import"), $tableFormats, $values); + + $values = "(NULL, 'CrossRef XML', 'import', 'true', 'import_crossref2refbase.php', 'A150', 1)"; + $resultArray["Table 'formats': inserted 'CrossRef XML' import format"] = insertIfNotExists(array("format_name" => "CrossRef XML", "format_type" => "import"), $tableFormats, $values); + + // Update existing export formats in table 'formats' + $query = "UPDATE " . $tableFormats . " SET order_by = 'B010' WHERE format_name = 'BibTeX' AND format_type = 'export'"; + $result = queryMySQLDatabase($query); + $resultArray["Table 'formats': updated 'BibTeX' export format. Affected rows"] = ($result ? mysql_affected_rows($connection) : 0); + + $query = "UPDATE " . $tableFormats . " SET order_by = 'B040' WHERE format_name = 'Endnote' AND format_type = 'export'"; + $result = queryMySQLDatabase($query); + $resultArray["Table 'formats': updated 'Endnote' export format. Affected rows"] = ($result ? mysql_affected_rows($connection) : 0); + + $query = "UPDATE " . $tableFormats . " SET order_by = 'B050' WHERE format_name = 'ISI' AND format_type = 'export'"; + $result = queryMySQLDatabase($query); + $resultArray["Table 'formats': updated 'ISI' export format. Affected rows"] = ($result ? mysql_affected_rows($connection) : 0); + + $query = "UPDATE " . $tableFormats . " SET order_by = 'B080' WHERE format_name = 'RIS' AND format_type = 'export'"; + $result = queryMySQLDatabase($query); + $resultArray["Table 'formats': updated 'RIS' export format. Affected rows"] = ($result ? mysql_affected_rows($connection) : 0); + + $query = "UPDATE " . $tableFormats . " SET order_by = 'B105' WHERE format_name = 'Text (CSV)' AND format_type = 'export'"; + $result = queryMySQLDatabase($query); + $resultArray["Table 'formats': updated 'Text (CSV)' export format. Affected rows"] = ($result ? mysql_affected_rows($connection) : 0); + + $query = "UPDATE " . $tableFormats . " SET format_name = 'Atom XML', format_enabled = 'true', format_spec ='export_atomxml.php', order_by = 'B140' WHERE format_name = 'OpenSearch RSS' AND format_type = 'export'"; + $result = queryMySQLDatabase($query); + $resultArray["Table 'formats': updated 'OpenSearch RSS' export format, and renamed it to 'Atom XML'. Affected rows"] = ($result ? mysql_affected_rows($connection) : 0); + + $query = "UPDATE " . $tableFormats . " SET order_by = 'B160' WHERE format_name = 'MODS XML' AND format_type = 'export'"; + $result = queryMySQLDatabase($query); + $resultArray["Table 'formats': updated 'MODS XML' export format. Affected rows"] = ($result ? mysql_affected_rows($connection) : 0); + + $query = "UPDATE " . $tableFormats . " SET order_by = 'B170' WHERE format_name = 'OAI_DC XML' AND format_type = 'export'"; + $result = queryMySQLDatabase($query); + $resultArray["Table 'formats': updated 'OAI_DC XML' export format. Affected rows"] = ($result ? mysql_affected_rows($connection) : 0); + + $query = "UPDATE " . $tableFormats . " SET order_by = 'B180' WHERE format_name = 'ODF XML' AND format_type = 'export'"; + $result = queryMySQLDatabase($query); + $resultArray["Table 'formats': updated 'ODF XML' export format. Affected rows"] = ($result ? mysql_affected_rows($connection) : 0); + + $query = "UPDATE " . $tableFormats . " SET format_name = 'SRW_MODS XML', order_by = 'B195' WHERE format_name = 'SRW XML' AND format_type = 'export'"; + $result = queryMySQLDatabase($query); + $resultArray["Table 'formats': updated 'SRW XML' export format, and renamed it to 'SRW_MODS XML'. Affected rows"] = ($result ? mysql_affected_rows($connection) : 0); + + $query = "UPDATE " . $tableFormats . " SET order_by = 'B200' WHERE format_name = 'Word XML' AND format_type = 'export'"; + $result = queryMySQLDatabase($query); + $resultArray["Table 'formats': updated 'Word XML' export format. Affected rows"] = ($result ? mysql_affected_rows($connection) : 0); + + // Add new export formats in table 'formats' + $values = "(NULL, 'ADS', 'export', 'true', 'bibutils/export_xml2ads.php', 'B005', 2)"; + $resultArray["Table 'formats': inserted 'ADS' export format"] = insertIfNotExists(array("format_name" => "ADS", "format_type" => "export"), $tableFormats, $values); + + $values = "(NULL, 'ISI', 'export', 'true', 'bibutils/export_xml2isi.php', 'B050', 2)"; + $resultArray["Table 'formats': inserted 'ISI' export format"] = insertIfNotExists(array("format_name" => "ISI", "format_type" => "export"), $tableFormats, $values); + + $values = "(NULL, 'Atom XML', 'export', 'true', 'export_atomxml.php', 'B140', 1)"; + $resultArray["Table 'formats': inserted 'Atom XML' export format"] = insertIfNotExists(array("format_name" => "Atom XML", "format_type" => "export"), $tableFormats, $values); + + $values = "(NULL, 'OAI_DC XML', 'export', 'true', 'export_oaidcxml.php', 'B170', 1)"; + $resultArray["Table 'formats': inserted 'OAI_DC XML' export format"] = insertIfNotExists(array("format_name" => "OAI_DC XML", "format_type" => "export"), $tableFormats, $values); + + $values = "(NULL, 'ODF XML', 'export', 'true', 'export_odfxml.php', 'B180', 1)"; + $resultArray["Table 'formats': inserted 'ODF XML' export format"] = insertIfNotExists(array("format_name" => "ODF XML", "format_type" => "export"), $tableFormats, $values); + + $values = "(NULL, 'SRW_DC XML', 'export', 'true', 'export_srwxml.php', 'B190', 1)"; + $resultArray["Table 'formats': inserted 'SRW_DC XML' export format"] = insertIfNotExists(array("format_name" => "SRW_DC XML", "format_type" => "export"), $tableFormats, $values); + + $values = "(NULL, 'SRW_MODS XML', 'export', 'true', 'export_srwxml.php', 'B195', 1)"; + $resultArray["Table 'formats': inserted 'SRW_MODS XML' export format"] = insertIfNotExists(array("format_name" => "SRW_MODS XML", "format_type" => "export"), $tableFormats, $values); + + $values = "(NULL, 'Word XML', 'export', 'true', 'bibutils/export_xml2word.php', 'B200', 2)"; + $resultArray["Table 'formats': inserted 'Word XML' export format"] = insertIfNotExists(array("format_name" => "Word XML", "format_type" => "export"), $tableFormats, $values); + + // Update existing citation formats in table 'formats' + $query = "UPDATE " . $tableFormats . " SET order_by = 'C010' WHERE format_name = 'html' AND format_type = 'cite'"; + $result = queryMySQLDatabase($query); + $resultArray["Table 'formats': updated 'html' citation format. Affected rows"] = ($result ? mysql_affected_rows($connection) : 0); + + $query = "UPDATE " . $tableFormats . " SET order_by = 'C020' WHERE format_name = 'RTF' AND format_type = 'cite'"; + $result = queryMySQLDatabase($query); + $resultArray["Table 'formats': updated 'RTF' citation format. Affected rows"] = ($result ? mysql_affected_rows($connection) : 0); + + $query = "UPDATE " . $tableFormats . " SET order_by = 'C030' WHERE format_name = 'PDF' AND format_type = 'cite'"; + $result = queryMySQLDatabase($query); + $resultArray["Table 'formats': updated 'PDF' citation format. Affected rows"] = ($result ? mysql_affected_rows($connection) : 0); + + $query = "UPDATE " . $tableFormats . " SET order_by = 'C040' WHERE format_name = 'LaTeX' AND format_type = 'cite'"; + $result = queryMySQLDatabase($query); + $resultArray["Table 'formats': updated 'LaTeX' citation format. Affected rows"] = ($result ? mysql_affected_rows($connection) : 0); + + $query = "UPDATE " . $tableFormats . " SET order_by = 'C045' WHERE format_name = 'LaTeX .bbl' AND format_type = 'cite'"; + $result = queryMySQLDatabase($query); + $resultArray["Table 'formats': updated 'LaTeX .bbl' citation format. Affected rows"] = ($result ? mysql_affected_rows($connection) : 0); + + $query = "UPDATE " . $tableFormats . " SET order_by = 'C050' WHERE format_name = 'Markdown' AND format_type = 'cite'"; + $result = queryMySQLDatabase($query); + $resultArray["Table 'formats': updated 'Markdown' citation format. Affected rows"] = ($result ? mysql_affected_rows($connection) : 0); + + $query = "UPDATE " . $tableFormats . " SET order_by = 'C060' WHERE format_name = 'ASCII' AND format_type = 'cite'"; + $result = queryMySQLDatabase($query); + $resultArray["Table 'formats': updated 'ASCII' citation format. Affected rows"] = ($result ? mysql_affected_rows($connection) : 0); + + // Add new citation formats in table 'formats' + $values = "(NULL, 'html', 'cite', 'true', 'formats/cite_html.php', 'C010', 1)"; + $resultArray["Table 'formats': inserted 'html' citation format"] = insertIfNotExists(array("format_name" => "html", "format_type" => "cite"), $tableFormats, $values); + + $values = "(NULL, 'RTF', 'cite', 'true', 'formats/cite_rtf.php', 'C020', 1)"; + $resultArray["Table 'formats': inserted 'RTF' citation format"] = insertIfNotExists(array("format_name" => "RTF", "format_type" => "cite"), $tableFormats, $values); + + $values = "(NULL, 'PDF', 'cite', 'true', 'formats/cite_pdf.php', 'C030', 1)"; + $resultArray["Table 'formats': inserted 'PDF' citation format"] = insertIfNotExists(array("format_name" => "PDF", "format_type" => "cite"), $tableFormats, $values); + + $values = "(NULL, 'LaTeX', 'cite', 'true', 'formats/cite_latex.php', 'C040', 1)"; + $resultArray["Table 'formats': inserted 'LaTeX' citation format"] = insertIfNotExists(array("format_name" => "LaTeX", "format_type" => "cite"), $tableFormats, $values); + + $values = "(NULL, 'LaTeX .bbl', 'cite', 'true', 'formats/cite_latex_bbl.php', 'C045', 1)"; + $resultArray["Table 'formats': inserted 'LaTeX .bbl' citation format"] = insertIfNotExists(array("format_name" => "LaTeX .bbl", "format_type" => "cite"), $tableFormats, $values); + + $values = "(NULL, 'Markdown', 'cite', 'true', 'formats/cite_markdown.php', 'C050', 1)"; + $resultArray["Table 'formats': inserted 'Markdown' citation format"] = insertIfNotExists(array("format_name" => "Markdown", "format_type" => "cite"), $tableFormats, $values); + + $values = "(NULL, 'ASCII', 'cite', 'true', 'formats/cite_ascii.php', 'C060', 1)"; + $resultArray["Table 'formats': inserted 'ASCII' citation format"] = insertIfNotExists(array("format_name" => "ASCII", "format_type" => "cite"), $tableFormats, $values); + + // Enable some of the existing export formats (which were previously disabled by default) for anyone who's not logged in ('$userID = 0'): + // Fetch IDs for all formats that shall be enabled: + $formatIDArray = array(); + $query = "SELECT format_id, format_name FROM " . $tableFormats . " WHERE (format_name RLIKE '^(BibTeX|Endnote|RIS)$' AND format_type = 'export')"; + $result = queryMySQLDatabase($query); + $rowsFound = @ mysql_num_rows($result); + if ($rowsFound > 0) + { + while ($row = @ mysql_fetch_array($result)) + $formatIDArray[$row['format_id']] = $row['format_name']; + } + + foreach ($formatIDArray as $formatID => $formatName) + { + $values = "(NULL, " . $formatID . ", 0, 'true')"; + $resultArray["Table 'user_formats': enabled format '" . $formatName . "' for anyone who's not logged in"] = insertIfNotExists(array("format_id" => $formatID), $tableUserFormats, $values, "0"); + } + + // Enable some of the newly created export/citation formats, citation styles & resource types for all users: + // Fetch IDs for all formats that shall be enabled: + $formatIDArray = array(); + $query = "SELECT format_id, format_name FROM " . $tableFormats . " WHERE (format_name RLIKE '^(ISI|ODF XML|Word XML)$' AND format_type = 'export') OR (format_name RLIKE '^(html|RTF|PDF|LaTeX)$' AND format_type = 'cite')"; + $result = queryMySQLDatabase($query); + $rowsFound = @ mysql_num_rows($result); + if ($rowsFound > 0) + { + while ($row = @ mysql_fetch_array($result)) + $formatIDArray[$row['format_id']] = $row['format_name']; + } + + // Fetch IDs for all styles that shall be enabled: + $styleIDArray = array(); + $query = "SELECT style_id, style_name FROM " . $tableStyles . " WHERE style_name RLIKE '^(AMA|APA|Chicago|Harvard( [0-9]+)?|J Glaciol|MLA|Vancouver)$'"; + $result = queryMySQLDatabase($query); + $rowsFound = @ mysql_num_rows($result); + if ($rowsFound > 0) + { + while ($row = @ mysql_fetch_array($result)) + $styleIDArray[$row['style_id']] = $row['style_name']; + } + + // Fetch IDs for all types that shall be enabled: + $typeIDArray = array(); + $query = "SELECT type_id, type_name FROM " . $tableTypes . " WHERE type_name RLIKE '^(Abstract|Conference Article|Conference Volume|Magazine Article|Manual|Miscellaneous|Newspaper Article|Patent|Report|Software)$'"; + $result = queryMySQLDatabase($query); + $rowsFound = @ mysql_num_rows($result); + if ($rowsFound > 0) + { + while ($row = @ mysql_fetch_array($result)) + $typeIDArray[$row['type_id']] = $row['type_name']; + } + + // Enable formats, styles & types for anyone who's not logged in ('$userID = 0'): + foreach ($formatIDArray as $formatID => $formatName) + { + $values = "(NULL, " . $formatID . ", 0, 'true')"; + $resultArray["Table 'user_formats': enabled format '" . $formatName . "' for anyone who's not logged in"] = insertIfNotExists(array("format_id" => $formatID), $tableUserFormats, $values, "0"); + } + + foreach ($styleIDArray as $styleID => $styleName) + { + $values = "(NULL, " . $styleID . ", 0, 'true')"; + $resultArray["Table 'user_styles': enabled style '" . $styleName . "' for anyone who's not logged in"] = insertIfNotExists(array("style_id" => $styleID), $tableUserStyles, $values, "0"); + } + + foreach ($typeIDArray as $typeID => $typeName) + { + $values = "(NULL, " . $typeID . ", 0, 'true')"; + $resultArray["Table 'user_types': enabled type '" . $typeName . "' for anyone who's not logged in"] = insertIfNotExists(array("type_id" => $typeID), $tableUserTypes, $values, "0"); + } + + // Enable formats, styles & types for all users: + // First, check how many users are contained in table 'users': + $query = "SELECT user_id, first_name, last_name FROM " . $tableUsers; + $result = queryMySQLDatabase($query); + $rowsFound = @ mysql_num_rows($result); + if ($rowsFound > 0) // If there were rows (= user IDs) found ... + { + while ($row = @ mysql_fetch_array($result)) + { + foreach ($formatIDArray as $formatID => $formatName) + { + $values = "(NULL, " . $formatID . ", " . $row['user_id'] . ", 'true')"; + $resultArray["Table 'user_formats': enabled format '" . $formatName . "' for user " . $row['user_id'] . " (" . $row['first_name'] . " " . $row['last_name'] . ")"] = insertIfNotExists(array("format_id" => $formatID), $tableUserFormats, $values, $row['user_id']); + } + + foreach ($styleIDArray as $styleID => $styleName) + { + $values = "(NULL, " . $styleID . ", " . $row['user_id'] . ", 'true')"; + $resultArray["Table 'user_styles': enabled style '" . $styleName . "' for user " . $row['user_id'] . " (" . $row['first_name'] . " " . $row['last_name'] . ")"] = insertIfNotExists(array("style_id" => $styleID), $tableUserStyles, $values, $row['user_id']); + } + + foreach ($typeIDArray as $typeID => $typeName) + { + $values = "(NULL, " . $typeID . ", " . $row['user_id'] . ", 'true')"; + $resultArray["Table 'user_types': enabled type '" . $typeName . "' for user " . $row['user_id'] . " (" . $row['first_name'] . " " . $row['last_name'] . ")"] = insertIfNotExists(array("type_id" => $typeID), $tableUserTypes, $values, $row['user_id']); + } + } + } + + // (3) ERRORS + + // Check whether any tables/rows were affected by the performed SQL queries: + unset($resultArray["Table 'deleted': altered table specification. Affected rows"]); // currently, we simply remove again the results of the 'ALTER TABLE' queries since they will always affect every row in that table + unset($resultArray["Table 'refs': altered table specification. Affected rows"]); + unset($resultArray["Table 'formats': altered table specification. Affected rows"]); + + foreach($resultArray as $varname => $value) + if (($value == "0") OR ($value == "false")) + unset($resultArray[$varname]); // remove any action that didn't affect any table or rows + + if (empty($resultArray)) + { + $HeaderString = "Nothing was changed! Your refbase installation is up-to-date."; + + // Write back session variables: + saveSessionVariable("HeaderString", $HeaderString); + } + + // (4) CLOSE ADMIN CONNECTION + disconnectFromMySQLDatabase(); + + // -------------------------------------------------------------------- + + // Provide a feedback page: + + // If there's no stored message available: + if (!isset($_SESSION['HeaderString'])) // provide a default message: + { + $HeaderString = "Update of the Web Reference Database was successful!"; + } + else + { + $HeaderString = $_SESSION['HeaderString']; // extract 'HeaderString' session variable (only necessary if register globals is OFF!) + + // Note: though we clear the session variable, the current message is still available to this script via '$HeaderString': + deleteSessionVariable("HeaderString"); + } + + // Extract the view type requested by the user (either 'Mobile', 'Print', 'Web' or ''): + // ('' will produce the default 'Web' output style) + if (isset($_REQUEST['viewType'])) + $viewType = $_REQUEST['viewType']; + else + $viewType = ""; + + // Show the login status: + showLogin(); // (function 'showLogin()' is defined in 'include.inc.php') + + // DISPLAY header: + // call the 'displayHTMLhead()' and 'showPageHeader()' functions (which are defined in 'header.inc.php'): + displayHTMLhead(encodeHTML($officialDatabaseName) . " -- Update Feedback", "index,follow", "Update feedback for the " . encodeHTML($officialDatabaseName), "", false, "", $viewType, array()); + showPageHeader($HeaderString); + + // Start a : +?> + +
+ + + + + + + + + + + + + + + + + + + + + + + +

Welcome to refbase v0.9.6!

Important Note: + The files update.php and update.sql (as well as install.php and install.sql) are only provided for update/installation purposes and are not needed anymore. Due to security considerations you should remove these files from your web directory NOW!! +
Configure refbase: + In order to re-establish your existing settings, please open file initialize/ini.inc.php in a text editor and restore all values from your old ini.inc.php file. The new include file contains new settings which you should check out and adopt to your needs if needed. Please see the comments within the file for further information. +
Log: + Following update actions were performed successfully: +
  +
 $value)
+			{
+				if ($value == "true")
+					echo $varname . ".\n";
+				else
+					echo $varname . ": " . $value . "\n";
+			}
+?>
+			
+
diff --git a/update.php.org b/update.php.org index a706318..1b6db04 100644 --- a/update.php.org +++ b/update.php.org @@ -1,4 +1,8 @@ // Copyright: Matthias Steffens and the file's // original author(s).