// 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: ./import.php // Repository: $HeadURL: file:///svn/p/refbase/code/branches/bleeding-edge/import.php $ // Author(s): Matthias Steffens // // Created: 17-Feb-06, 20:57 // Modified: $Date: 2015-02-16 20:53:19 +0000 (Mon, 16 Feb 2015) $ // $Author: karnesky $ // $Revision: 1405 $ // Import form that offers to import records from Reference Manager (RIS), CSA Illumina, // RefWorks Tagged Format, SciFinder Tagged Format, ISI Web of Science, PubMed MEDLINE, PubMed XML, MODS XML, // Endnote Tagged Text, BibTeX or COPAC. Import of the latter five formats is provided via use of bibutils. // Incorporate some include files: include 'includes/header.inc.php'; // include header include 'includes/footer.inc.php'; // include footer include 'includes/include.inc.php'; // include common 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(true); // -------------------------------------------------------------------- // 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 // -------------------------------------------------------------------- // Extract session variables: if (isset($_SESSION['errors'])) { $errors = $_SESSION['errors']; // read session variable (only necessary if register globals is OFF!) // 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']; // read session variable (only necessary if register globals is OFF!) // Remove slashes from parameter values if 'magic_quotes_gpc = On': foreach($formVars as $varname => $value) $formVars[$varname] = stripSlashesIfMagicQuotes($value); // function 'stripSlashesIfMagicQuotes()' is defined in 'include.inc.php' // 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 $formVars = array(); // -------------------------------------------------------------------- // 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 // -------------------------------------------------------------------- // If there's no stored message available: if (!isset($_SESSION['HeaderString'])) { if (empty($errors)) // provide one of the default messages: { if (isset($_SESSION['user_permissions']) AND preg_match("/allow_batch_import/", $_SESSION['user_permissions'])) // if the 'user_permissions' session variable does contain 'allow_batch_import'... $HeaderString = "Import records:"; // Provide the default message else $HeaderString = "Import a record:"; // Provide the default message } else // -> there were errors validating the user's data input $HeaderString = "There were validation errors regarding the data you entered:"; } else // there is already a stored message available { $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' } // Adopt the page title & some labels according to the user's permissions: if (isset($_SESSION['user_permissions']) AND !preg_match("/allow_batch_import/", $_SESSION['user_permissions'])) // if the 'user_permissions' session variable does NOT contain 'allow_batch_import'... { $pageTitle = " -- Import Record"; // adopt page title $textEntryFormLabel = "Record"; // adopt the label for the text entry form $rowSpan = ""; // adopt table row span parameter } else { $pageTitle = " -- Import Records"; $textEntryFormLabel = "Records"; $rowSpan = " rowspan=\"2\""; } // 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 = ""; // If there were some errors on submit -> Re-load the data that were submitted by the user: if (!empty($errors)) { if (isset($formVars['formType'])) $formType = $formVars['formType']; // get the form type that was submitted by the user (and which subsequently caused an error) else $formType = ""; // (A) main import form: if (isset($formVars['sourceText'])) // '$formVars['sourceText']' may be non-existent in the (unlikely but possible) event that a user calls 'import_modify.php' directly $sourceText = $formVars['sourceText']; else $sourceText = ""; if (isset($formVars['importRecordsRadio'])) // 'importRecordsRadio' is only set if user has 'batch_import' permission $importRecordsRadio = $formVars['importRecordsRadio']; else $importRecordsRadio = ""; if (isset($formVars['importRecords'])) // 'importRecords' is only set if user has 'batch_import' permission $importRecords = $formVars['importRecords']; else $importRecords = "1"; // check whether the user marked the checkbox to skip records with unrecognized data format: if (isset($formVars['skipBadRecords'])) $skipBadRecords = $formVars['skipBadRecords']; else $skipBadRecords = ""; // (B) "Import IDs" form (imports records from PubMed ID, arXiv ID, DOI or OpenURL): if (isset($formVars['sourceIDs'])) $sourceIDs = $formVars['sourceIDs']; else $sourceIDs = ""; } else // display an empty form (i.e., set all variables to an empty string [""] or their default values, respectively): { $formType = ""; // (A) main import form: $sourceText = ""; $importRecordsRadio = "all"; $importRecords = "1"; $skipBadRecords = ""; // (B) "Import IDs" form: $sourceIDs = ""; } // Show the login status: showLogin(); // (function 'showLogin()' is defined in 'include.inc.php') // (2a) Display header: // call the 'displayHTMLhead()' and 'showPageHeader()' functions (which are defined in 'header.inc.php'): displayHTMLhead(encodeHTML($officialDatabaseName) . $pageTitle, "index,follow", "Import records into the " . encodeHTML($officialDatabaseName), "", false, "", $viewType, array()); showPageHeader($HeaderString); // (2b) Start
and holding the form elements of the main import form: echo "\n" . "\n" . "\n" // provide a default value for the 'submit' form tag. Otherwise, some browsers may not recognize the correct output format when a user hits within a form field (instead of clicking the "Import" button) . "\n" // embed '$showLinks=1' so that links get displayed on any 'display details' page . "\n"; // for particular formats (e.g., CSA or MEDLINE) original source data will be displayed alongside the parsed data for easier comparison if (isset($errors['badRecords'])) { if ($errors['badRecords'] == "all") // none of the given records had a recognized format { if (!empty($errors['skipBadRecords'])) $skipBadRecordsInput = "
" . fieldError("skipBadRecords", $errors); else $skipBadRecordsInput = ""; } elseif ($errors['badRecords'] == "some") // there were at least some records with recognized format but other records could NOT be recognized { if (!empty($skipBadRecords)) $skipBadRecordsCheckBoxIsChecked = " checked"; // mark the 'Skip records with unrecognized data format' checkbox else $skipBadRecordsCheckBoxIsChecked = ""; // display the 'Skip records with unrecognized data format' checkbox: $skipBadRecordsInput = "
  " . fieldError("skipBadRecords", $errors); } } else // all records did have a valid data format -> supress the 'Skip records with unrecognized data format' checkbox { $skipBadRecordsInput = ""; } if (!empty($skipBadRecordsInput)) { if ($formType == "importID") { $skipBadRecordsInputMain = ""; $skipBadRecordsInputID = $skipBadRecordsInput; } else // $formType == "import" { $skipBadRecordsInputMain = $skipBadRecordsInput; $skipBadRecordsInputID = ""; } } else { $skipBadRecordsInputMain = ""; $skipBadRecordsInputID = ""; } echo "\n
" . "\n\n\t\n\t" . "\n\t" . "\n"; // the code for the next table row is kept a bit more modular than necessary to allow for easy changes in the future if (isset($_SESSION['user_permissions']) AND preg_match("/allow_batch_import/", $_SESSION['user_permissions'])) // if the 'user_permissions' session variable does contain 'allow_batch_import'... echo "\n\n\t \n\t "; if (isset($_SESSION['user_permissions']) AND preg_match("/allow_batch_import/", $_SESSION['user_permissions'])) // if the 'user_permissions' session variable does contain 'allow_batch_import'... { // display a file upload button: $uploadButtonLock = ""; $uploadTitle = $loc["DescriptionFileImport"]; echo "\n\t"; } // else // { // // note that we currently simply hide the upload button if the user doesn't have the 'allow_batch_import' permission (i.e., the two lines below are currently without effect): // $uploadButtonLock = " disabled"; // disabling of the upload button doesn't seem to work in all browsers (e.g., it doesn't work in Safari on MacOSX Panther, but does work with Mozilla & Camino) ?:-/ // $uploadTitle = $loc["NoPermission"] . $loc["NoPermission_ForFileImport"]; // similarily, not all browsers will show title strings for disabled buttons (Safari does, Mozilla & Camino do not) // // echo "\n\t"; // } if (isset($_SESSION['user_permissions']) AND preg_match("/allow_batch_import/", $_SESSION['user_permissions'])) // if the 'user_permissions' session variable does contain 'allow_batch_import'... { if ($importRecordsRadio == "all") { $importRecordsRadioAllChecked = " checked"; // select the 'All' radio button $importRecordsRadioOnlyChecked = ""; } else // $importRecordsRadio == "only" { $importRecordsRadioAllChecked = ""; $importRecordsRadioOnlyChecked = " checked"; // select the 'Only' radio button } echo "\n\t" . "\n\t" . "\n" . "\n" . "\n\t"; } // else // { // echo "\n\t"; // } if (isset($_SESSION['user_permissions']) AND preg_match("/allow_batch_import/", $_SESSION['user_permissions'])) // if the 'user_permissions' session variable does contain 'allow_batch_import'... echo "\n"; echo "\n\n\t\n\t"; if (isset($_SESSION['user_permissions']) AND preg_match("/allow_import|allow_batch_import/", $_SESSION['user_permissions'])) // if the 'user_permissions' session variable contains either 'allow_import' or 'allow_batch_import'... // adjust the title string for the import button { $importButtonLock = ""; $importTitleMain = "press this button to import the given source data"; $importTitleID = "press this button to fetch & import source data for the given IDs"; } else // Note, that disabling the submit button is just a cosmetic thing -- the user can still submit the form by pressing enter or by building the correct URL from scratch! { $importButtonLock = " disabled"; $importTitleMain = "not available since you have no permission to import any records"; $importTitleID = "not available since you have no permission to import any records"; } echo "\n\t" . "\n" . "\n
" . $textEntryFormLabel . ": " . fieldError("sourceText", $errors) . $skipBadRecordsInputMain . "
" . fieldError("uploadFile", $errors) . " Import records: All
" . fieldError("importRecords", $errors) . " Only:   
  \n\t\t\n\t
" . "\n
"; // (2c) Start
and holding the form elements of the "Import IDs" form: echo "\n" . "\n" . "\n" // provide a default value for the 'submit' form tag. Otherwise, some browsers may not recognize the correct output format when a user hits within a form field (instead of clicking the "Import" button) . "\n"; // in case of the MEDLINE format, original source data will be displayed alongside the parsed data for easier comparison echo "\n
" . "\n\n\t\n\t" . "\n\t" . "\n" . "\n\n\t\n\t" . "\n\t" . "\n" . "\n\n\t" . "\n"; // (2d) Display a table row with some help text: echo "\n\n\t\n\t" . "\n\t" . "\n" . "\n\n\t\n\t" . "\n\t" . "\n" . "\n
Import IDs: " . fieldError("sourceIDs", $errors) . $skipBadRecordsInputID . "
  \n\t\t\n\t
 
Help: The upper form enables you to import records from " . "Endnote (tagged text or XML), " . "Reference Manager (RIS), " . "RefWorks, " . "BibTeX, " . "MODS XML, " . "ISI Web of Science, " . "PubMed (MEDLINE or XML), " . "CSA Illumina, " // '$importCSArecordsURL' is defined in 'ini.inc.php' . "SciFinder " . "and COPAC." . " Please see the refbase online documentation for more information about the supported formats and any requirements in format structure.
  The lower form allows you to import records via their ID; supported IDs: PubMed ID (PMID), arXiv ID, DOI and OpenURL. Just enter one or more IDs (delimited by whitespace) and press the Import button. Please note that currently you cannot mix different IDs within the same import action, i.e. specify either PubMed IDs or DOIs, etc.
" . "\n
"; // -------------------------------------------------------------------- // SHOW ERROR IN RED: function fieldError($fieldName, $errors) { if (isset($errors[$fieldName])) return "" . $errors[$fieldName] . "
"; } // -------------------------------------------------------------------- // DISPLAY THE HTML FOOTER: // call the 'showPageFooter()' and 'displayHTMLfoot()' functions (which are defined in 'footer.inc.php') showPageFooter($HeaderString); displayHTMLfoot(); // -------------------------------------------------------------------- ?>