You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

359 lines
19 KiB

  1. <?php
  2. // turn on warnings and notice during developement
  3. include('initialize/PhpErrorSettings.inc.php');
  4. // Project: Web Reference Database (refbase) <http://www.refbase.net>
  5. // Copyright: Matthias Steffens <mailto:refbase@extracts.de> and the file's
  6. // original author(s).
  7. //
  8. // This code is distributed in the hope that it will be useful,
  9. // but WITHOUT ANY WARRANTY. Please see the GNU General Public
  10. // License for more details.
  11. //
  12. // File: ./import.php
  13. // Repository: $HeadURL: file:///svn/p/refbase/code/branches/bleeding-edge/import.php $
  14. // Author(s): Matthias Steffens <mailto:refbase@extracts.de>
  15. //
  16. // Created: 17-Feb-06, 20:57
  17. // Modified: $Date: 2015-02-16 20:53:19 +0000 (Mon, 16 Feb 2015) $
  18. // $Author: karnesky $
  19. // $Revision: 1405 $
  20. // Import form that offers to import records from Reference Manager (RIS), CSA Illumina,
  21. // RefWorks Tagged Format, SciFinder Tagged Format, ISI Web of Science, PubMed MEDLINE, PubMed XML, MODS XML,
  22. // Endnote Tagged Text, BibTeX or COPAC. Import of the latter five formats is provided via use of bibutils.
  23. // Incorporate some include files:
  24. include 'includes/header.inc.php'; // include header
  25. include 'includes/footer.inc.php'; // include footer
  26. include 'includes/include.inc.php'; // include common functions
  27. include 'initialize/ini.inc.php'; // include common variables
  28. // --------------------------------------------------------------------
  29. // START A SESSION:
  30. // call the 'start_session()' function (from 'include.inc.php') which will also read out available session variables:
  31. start_session(true);
  32. // --------------------------------------------------------------------
  33. // Initialize preferred display language:
  34. // (note that 'locales.inc.php' has to be included *after* the call to the 'start_session()' function)
  35. include 'includes/locales.inc.php'; // include the locales
  36. // --------------------------------------------------------------------
  37. // Extract session variables:
  38. if (isset($_SESSION['errors']))
  39. {
  40. $errors = $_SESSION['errors']; // read session variable (only necessary if register globals is OFF!)
  41. // Note: though we clear the session variable, the current error message is still available to this script via '$errors':
  42. deleteSessionVariable("errors"); // function 'deleteSessionVariable()' is defined in 'include.inc.php'
  43. }
  44. else
  45. $errors = array(); // initialize the '$errors' variable in order to prevent 'Undefined variable...' messages
  46. if (isset($_SESSION['formVars']))
  47. {
  48. $formVars = $_SESSION['formVars']; // read session variable (only necessary if register globals is OFF!)
  49. // Remove slashes from parameter values if 'magic_quotes_gpc = On':
  50. foreach($formVars as $varname => $value)
  51. $formVars[$varname] = stripSlashesIfMagicQuotes($value); // function 'stripSlashesIfMagicQuotes()' is defined in 'include.inc.php'
  52. // Note: though we clear the session variable, the current form variables are still available to this script via '$formVars':
  53. deleteSessionVariable("formVars"); // function 'deleteSessionVariable()' is defined in 'include.inc.php'
  54. }
  55. else
  56. $formVars = array();
  57. // --------------------------------------------------------------------
  58. // Initialize preferred display language:
  59. // (note that 'locales.inc.php' has to be included *after* the call to the 'start_session()' function)
  60. include 'includes/locales.inc.php'; // include the locales
  61. // --------------------------------------------------------------------
  62. // If there's no stored message available:
  63. if (!isset($_SESSION['HeaderString']))
  64. {
  65. if (empty($errors)) // provide one of the default messages:
  66. {
  67. 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'...
  68. $HeaderString = "Import records:"; // Provide the default message
  69. else
  70. $HeaderString = "Import a record:"; // Provide the default message
  71. }
  72. else // -> there were errors validating the user's data input
  73. $HeaderString = "There were validation errors regarding the data you entered:";
  74. }
  75. else // there is already a stored message available
  76. {
  77. $HeaderString = $_SESSION['HeaderString']; // extract 'HeaderString' session variable (only necessary if register globals is OFF!)
  78. // Note: though we clear the session variable, the current message is still available to this script via '$HeaderString':
  79. deleteSessionVariable("HeaderString"); // function 'deleteSessionVariable()' is defined in 'include.inc.php'
  80. }
  81. // Adopt the page title & some labels according to the user's permissions:
  82. 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'...
  83. {
  84. $pageTitle = " -- Import Record"; // adopt page title
  85. $textEntryFormLabel = "Record"; // adopt the label for the text entry form
  86. $rowSpan = ""; // adopt table row span parameter
  87. }
  88. else
  89. {
  90. $pageTitle = " -- Import Records";
  91. $textEntryFormLabel = "Records";
  92. $rowSpan = " rowspan=\"2\"";
  93. }
  94. // Extract the view type requested by the user (either 'Mobile', 'Print', 'Web' or ''):
  95. // ('' will produce the default 'Web' output style)
  96. if (isset($_REQUEST['viewType']))
  97. $viewType = $_REQUEST['viewType'];
  98. else
  99. $viewType = "";
  100. // If there were some errors on submit -> Re-load the data that were submitted by the user:
  101. if (!empty($errors))
  102. {
  103. if (isset($formVars['formType']))
  104. $formType = $formVars['formType']; // get the form type that was submitted by the user (and which subsequently caused an error)
  105. else
  106. $formType = "";
  107. // (A) main import form:
  108. if (isset($formVars['sourceText'])) // '$formVars['sourceText']' may be non-existent in the (unlikely but possible) event that a user calls 'import_modify.php' directly
  109. $sourceText = $formVars['sourceText'];
  110. else
  111. $sourceText = "";
  112. if (isset($formVars['importRecordsRadio'])) // 'importRecordsRadio' is only set if user has 'batch_import' permission
  113. $importRecordsRadio = $formVars['importRecordsRadio'];
  114. else
  115. $importRecordsRadio = "";
  116. if (isset($formVars['importRecords'])) // 'importRecords' is only set if user has 'batch_import' permission
  117. $importRecords = $formVars['importRecords'];
  118. else
  119. $importRecords = "1";
  120. // check whether the user marked the checkbox to skip records with unrecognized data format:
  121. if (isset($formVars['skipBadRecords']))
  122. $skipBadRecords = $formVars['skipBadRecords'];
  123. else
  124. $skipBadRecords = "";
  125. // (B) "Import IDs" form (imports records from PubMed ID, arXiv ID, DOI or OpenURL):
  126. if (isset($formVars['sourceIDs']))
  127. $sourceIDs = $formVars['sourceIDs'];
  128. else
  129. $sourceIDs = "";
  130. }
  131. else // display an empty form (i.e., set all variables to an empty string [""] or their default values, respectively):
  132. {
  133. $formType = "";
  134. // (A) main import form:
  135. $sourceText = "";
  136. $importRecordsRadio = "all";
  137. $importRecords = "1";
  138. $skipBadRecords = "";
  139. // (B) "Import IDs" form:
  140. $sourceIDs = "";
  141. }
  142. // Show the login status:
  143. showLogin(); // (function 'showLogin()' is defined in 'include.inc.php')
  144. // (2a) Display header:
  145. // call the 'displayHTMLhead()' and 'showPageHeader()' functions (which are defined in 'header.inc.php'):
  146. displayHTMLhead(encodeHTML($officialDatabaseName) . $pageTitle, "index,follow", "Import records into the " . encodeHTML($officialDatabaseName), "", false, "", $viewType, array());
  147. showPageHeader($HeaderString);
  148. // (2b) Start <form> and <table> holding the form elements of the main import form:
  149. echo "\n<form enctype=\"multipart/form-data\" action=\"import_modify.php\" method=\"POST\">"
  150. . "\n<input type=\"hidden\" name=\"formType\" value=\"import\">"
  151. . "\n<input type=\"hidden\" name=\"submit\" value=\"Import\">" // provide a default value for the 'submit' form tag. Otherwise, some browsers may not recognize the correct output format when a user hits <enter> within a form field (instead of clicking the "Import" button)
  152. . "\n<input type=\"hidden\" name=\"showLinks\" value=\"1\">" // embed '$showLinks=1' so that links get displayed on any 'display details' page
  153. . "\n<input type=\"hidden\" name=\"showSource\" value=\"1\">"; // for particular formats (e.g., CSA or MEDLINE) original source data will be displayed alongside the parsed data for easier comparison
  154. if (isset($errors['badRecords']))
  155. {
  156. if ($errors['badRecords'] == "all") // none of the given records had a recognized format
  157. {
  158. if (!empty($errors['skipBadRecords']))
  159. $skipBadRecordsInput = "<br>" . fieldError("skipBadRecords", $errors);
  160. else
  161. $skipBadRecordsInput = "";
  162. }
  163. elseif ($errors['badRecords'] == "some") // there were at least some records with recognized format but other records could NOT be recognized
  164. {
  165. if (!empty($skipBadRecords))
  166. $skipBadRecordsCheckBoxIsChecked = " checked"; // mark the 'Skip records with unrecognized data format' checkbox
  167. else
  168. $skipBadRecordsCheckBoxIsChecked = "";
  169. // display the 'Skip records with unrecognized data format' checkbox:
  170. $skipBadRecordsInput = "<br><input type=\"checkbox\" name=\"skipBadRecords\" value=\"1\"$skipBadRecordsCheckBoxIsChecked title=\"mark this checkbox to omit records with unrecognized data format during import\">&nbsp;&nbsp;" . fieldError("skipBadRecords", $errors);
  171. }
  172. }
  173. else // all records did have a valid data format -> supress the 'Skip records with unrecognized data format' checkbox
  174. {
  175. $skipBadRecordsInput = "";
  176. }
  177. if (!empty($skipBadRecordsInput))
  178. {
  179. if ($formType == "importID")
  180. {
  181. $skipBadRecordsInputMain = "";
  182. $skipBadRecordsInputID = $skipBadRecordsInput;
  183. }
  184. else // $formType == "import"
  185. {
  186. $skipBadRecordsInputMain = $skipBadRecordsInput;
  187. $skipBadRecordsInputID = "";
  188. }
  189. }
  190. else
  191. {
  192. $skipBadRecordsInputMain = "";
  193. $skipBadRecordsInputID = "";
  194. }
  195. echo "\n<table align=\"center\" border=\"0\" cellpadding=\"0\" cellspacing=\"10\" width=\"95%\" summary=\"This table holds the main import form\">"
  196. . "\n<tr>\n\t<td width=\"94\" valign=\"top\"><b>" . $textEntryFormLabel . ":</b></td>\n\t<td width=\"10\">&nbsp;</td>"
  197. . "\n\t<td colspan=\"3\">" . fieldError("sourceText", $errors) . $skipBadRecordsInputMain . "<textarea name=\"sourceText\" rows=\"6\" cols=\"63\" title=\"paste your records here\">$sourceText</textarea></td>"
  198. . "\n</tr>";
  199. // the code for the next table row is kept a bit more modular than necessary to allow for easy changes in the future
  200. 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'...
  201. echo "\n<tr>\n\t<td" . $rowSpan . ">&nbsp;</td>\n\t<td" . $rowSpan . ">&nbsp;</td>";
  202. 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'...
  203. {
  204. // display a file upload button:
  205. $uploadButtonLock = "";
  206. $uploadTitle = $loc["DescriptionFileImport"];
  207. echo "\n\t<td width=\"215\" valign=\"top\"" . $rowSpan . ">" . fieldError("uploadFile", $errors) . "<input type=\"file\" name=\"uploadFile\" size=\"17\"$uploadButtonLock title=\"$uploadTitle\"></td>";
  208. }
  209. // else
  210. // {
  211. // // 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):
  212. // $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) ?:-/
  213. // $uploadTitle = $loc["NoPermission"] . $loc["NoPermission_ForFileImport"]; // similarily, not all browsers will show title strings for disabled buttons (Safari does, Mozilla & Camino do not)
  214. //
  215. // echo "\n\t<td width=\"215\"" . $rowSpan . ">&nbsp;</td>";
  216. // }
  217. 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'...
  218. {
  219. if ($importRecordsRadio == "all")
  220. {
  221. $importRecordsRadioAllChecked = " checked"; // select the 'All' radio button
  222. $importRecordsRadioOnlyChecked = "";
  223. }
  224. else // $importRecordsRadio == "only"
  225. {
  226. $importRecordsRadioAllChecked = "";
  227. $importRecordsRadioOnlyChecked = " checked"; // select the 'Only' radio button
  228. }
  229. echo "\n\t<td width=\"98\" valign=\"top\"" . $rowSpan . ">Import records:</td>"
  230. . "\n\t<td valign=\"top\"><input type=\"radio\" name=\"importRecordsRadio\" value=\"all\"$importRecordsRadioAllChecked title=\"choose 'All' if you want to import all records at once\">&nbsp;All</td>"
  231. . "\n</tr>"
  232. . "\n<tr>"
  233. . "\n\t<td valign=\"top\">" . fieldError("importRecords", $errors) . "<input type=\"radio\" name=\"importRecordsRadio\" value=\"only\"$importRecordsRadioOnlyChecked title=\"choose 'Only' if you just want to import particular records\">&nbsp;Only:&nbsp;&nbsp;<input type=\"text\" name=\"importRecords\" value=\"$importRecords\" size=\"5\" title=\"enter record number(s): e.g. '1-5 7' imports the first five and the seventh\"></td>";
  234. }
  235. // else
  236. // {
  237. // echo "\n\t<td colspan=\"2\">&nbsp;</td>";
  238. // }
  239. 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'...
  240. echo "\n</tr>";
  241. echo "\n<tr>\n\t<td>&nbsp;</td>\n\t<td>&nbsp;</td>";
  242. 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'...
  243. // adjust the title string for the import button
  244. {
  245. $importButtonLock = "";
  246. $importTitleMain = "press this button to import the given source data";
  247. $importTitleID = "press this button to fetch &amp; import source data for the given IDs";
  248. }
  249. 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!
  250. {
  251. $importButtonLock = " disabled";
  252. $importTitleMain = "not available since you have no permission to import any records";
  253. $importTitleID = "not available since you have no permission to import any records";
  254. }
  255. echo "\n\t<td colspan=\"3\">\n\t\t<input type=\"submit\" name=\"submit\" value=\"Import\"$importButtonLock title=\"$importTitleMain\">\n\t</td>"
  256. . "\n</tr>"
  257. . "\n</table>"
  258. . "\n</form>";
  259. // (2c) Start <form> and <table> holding the form elements of the "Import IDs" form:
  260. echo "\n<form action=\"import_modify.php\" method=\"POST\">"
  261. . "\n<input type=\"hidden\" name=\"formType\" value=\"importID\">"
  262. . "\n<input type=\"hidden\" name=\"submit\" value=\"Import\">" // provide a default value for the 'submit' form tag. Otherwise, some browsers may not recognize the correct output format when a user hits <enter> within a form field (instead of clicking the "Import" button)
  263. . "\n<input type=\"hidden\" name=\"showSource\" value=\"1\">"; // in case of the MEDLINE format, original source data will be displayed alongside the parsed data for easier comparison
  264. echo "\n<table align=\"center\" border=\"0\" cellpadding=\"0\" cellspacing=\"10\" width=\"95%\" summary=\"This table holds a form to import records via their ID\">"
  265. . "\n<tr>\n\t<td width=\"94\" valign=\"top\"><b>Import IDs:</b></td>\n\t<td width=\"10\">&nbsp;</td>"
  266. . "\n\t<td colspan=\"3\">" . fieldError("sourceIDs", $errors) . $skipBadRecordsInputID . "<input type=\"text\" name=\"sourceIDs\" value=\"$sourceIDs\" size=\"66\" title=\"enter PubMed IDs, arXiv IDs, DOIs or OpenURLs, multiple IDs must be delimited by whitespace\"></td>"
  267. . "\n</tr>"
  268. . "\n<tr>\n\t<td>&nbsp;</td>\n\t<td>&nbsp;</td>"
  269. . "\n\t<td colspan=\"3\">\n\t\t<input type=\"submit\" name=\"submit\" value=\"Import\"$importButtonLock title=\"$importTitleID\">\n\t</td>"
  270. . "\n</tr>"
  271. . "\n<tr>\n\t<td align=\"center\" colspan=\"5\">&nbsp;</td>"
  272. . "\n</tr>";
  273. // (2d) Display a table row with some help text:
  274. echo "\n<tr>\n\t<td valign=\"top\"><b>Help:</b></td>\n\t<td>&nbsp;</td>"
  275. . "\n\t<td valign=\"top\" colspan=\"3\">The upper form enables you to import records from "
  276. . "<a href=\"http://www.endnote.com/\" target=\"top\">Endnote</a> (tagged text or XML), "
  277. . "<a href=\"http://www.refman.com/\" target=\"top\">Reference Manager</a> (RIS), "
  278. . "<a href=\"http://www.refworks.com/\" target=\"top\">RefWorks</a>, "
  279. . "<a href=\"http://en.wikipedia.org/wiki/Bibtex\" target=\"top\">BibTeX</a>, "
  280. . "<a href=\"http://www.loc.gov/standards/mods/\" target=\"top\">MODS XML</a>, "
  281. . "<a href=\"http://isiknowledge.com/wos/\" target=\"top\">ISI Web of Science</a>, "
  282. . "<a href=\"http://www.pubmed.gov/\" target=\"top\">PubMed</a> (MEDLINE or XML), "
  283. . "<a href=\"" . $importCSArecordsURL . "\" target=\"top\">CSA Illumina</a>, " // '$importCSArecordsURL' is defined in 'ini.inc.php'
  284. . "<a href=\"http://www.cas.org/SCIFINDER/\" target=\"top\">SciFinder</a> "
  285. . "and <a href=\"http://www.copac.ac.uk/\" target=\"top\">COPAC</a>."
  286. . " Please see the <a href=\"http://import.refbase.net/\" target=\"top\">refbase online documentation</a> for more information about the supported formats and any requirements in format structure.</td>"
  287. . "\n</tr>"
  288. . "\n<tr>\n\t<td>&nbsp;</td>\n\t<td>&nbsp;</td>"
  289. . "\n\t<td colspan=\"3\">The lower form allows you to import records via their ID; supported IDs: <a href=\"http://www.pubmed.gov/\" target=\"top\">PubMed</a> <a href=\"http://en.wikipedia.org/wiki/PMID\" target=\"top\">ID (PMID)</a>, <a href=\"http://arxiv.org/\" target=\"top\">arXiv</a> <a href=\"http://arxiv.org/help/arxiv_identifier\" target=\"top\">ID</a>, <a href=\"http://www.doi.org/\" target=\"top\">DOI</a> and <a href=\"http://en.wikipedia.org/wiki/OpenURL\" target=\"top\">OpenURL</a>. Just enter one or more IDs (delimited by whitespace) and press the <em>Import</em> button. Please note that currently you cannot mix different IDs within the same import action, i.e. specify either PubMed IDs or DOIs, etc.</td>"
  290. . "\n</tr>"
  291. . "\n</table>"
  292. . "\n</form>";
  293. // --------------------------------------------------------------------
  294. // SHOW ERROR IN RED:
  295. function fieldError($fieldName, $errors)
  296. {
  297. if (isset($errors[$fieldName]))
  298. return "<b><span class=\"warning2\">" . $errors[$fieldName] . "</span></b><br>";
  299. }
  300. // --------------------------------------------------------------------
  301. // DISPLAY THE HTML FOOTER:
  302. // call the 'showPageFooter()' and 'displayHTMLfoot()' functions (which are defined in 'footer.inc.php')
  303. showPageFooter($HeaderString);
  304. displayHTMLfoot();
  305. // --------------------------------------------------------------------
  306. ?>