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.

357 lines
18 KiB

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