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.

347 lines
16 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_csa.php
  11. // Repository: $HeadURL: file:///svn/p/refbase/code/branches/bleeding-edge/import_csa.php $
  12. // Author(s): Matthias Steffens <mailto:refbase@extracts.de>
  13. //
  14. // Created: 21-Nov-03, 22:05
  15. // Modified: $Date: 2012-02-27 20:25:30 +0000 (Mon, 27 Feb 2012) $
  16. // $Author: msteffens $
  17. // $Revision: 1337 $
  18. // Import form that offers to import records from the "Cambridge Scientific Abstracts" (CSA)
  19. // Internet Database Service (<http://www.csa1.co.uk/csa/index.html>). This import form requires
  20. // the "full record" format offered by the CSA Internet Database Service.
  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. // Extract session variables:
  31. if (isset($_SESSION['errors']))
  32. {
  33. $errors = $_SESSION['errors']; // read session variable (only necessary if register globals is OFF!)
  34. // Note: though we clear the session variable, the current error message is still available to this script via '$errors':
  35. deleteSessionVariable("errors"); // function 'deleteSessionVariable()' is defined in 'include.inc.php'
  36. }
  37. else
  38. $errors = array(); // initialize the '$errors' variable in order to prevent 'Undefined variable...' messages
  39. if (isset($_SESSION['formVars']))
  40. {
  41. $formVars = $_SESSION['formVars']; // read session variable (only necessary if register globals is OFF!)
  42. // Remove slashes from parameter values if 'magic_quotes_gpc = On':
  43. foreach($formVars as $varname => $value)
  44. $formVars[$varname] = stripSlashesIfMagicQuotes($value); // function 'stripSlashesIfMagicQuotes()' is defined in 'include.inc.php'
  45. // Note: though we clear the session variable, the current form variables are still available to this script via '$formVars':
  46. deleteSessionVariable("formVars"); // function 'deleteSessionVariable()' is defined in 'include.inc.php'
  47. }
  48. else
  49. $formVars = array();
  50. // --------------------------------------------------------------------
  51. // Initialize preferred display language:
  52. // (note that 'locales.inc.php' has to be included *after* the call to the 'start_session()' function)
  53. include 'includes/locales.inc.php'; // include the locales
  54. // --------------------------------------------------------------------
  55. // If there's no stored message available:
  56. if (!isset($_SESSION['HeaderString']))
  57. {
  58. if (empty($errors)) // provide one of the default messages:
  59. {
  60. 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'...
  61. $HeaderString = "Import records from Cambridge Scientific Abstracts:"; // Provide the default message
  62. else
  63. $HeaderString = "Import a record from Cambridge Scientific Abstracts:"; // Provide the default message
  64. }
  65. else // -> there were errors validating the user's data input
  66. $HeaderString = "<b><span class=\"warning\">There were validation errors regarding the data you entered:</span></b>";
  67. }
  68. else // there is already a stored message available
  69. {
  70. $HeaderString = $_SESSION['HeaderString']; // extract 'HeaderString' session variable (only necessary if register globals is OFF!)
  71. // Note: though we clear the session variable, the current message is still available to this script via '$HeaderString':
  72. deleteSessionVariable("HeaderString"); // function 'deleteSessionVariable()' is defined in 'include.inc.php'
  73. }
  74. // Adopt the page title & some labels according to the user's permissions:
  75. 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'...
  76. {
  77. $pageTitle = " -- Import CSA Record"; // adopt page title
  78. $textEntryFormLabel = "Import CSA Full Record"; // adopt the label for the text entry form
  79. $rowSpan = ""; // adopt table row span parameter
  80. }
  81. else
  82. {
  83. $pageTitle = " -- Import CSA Records";
  84. $textEntryFormLabel = "Import CSA Full Records";
  85. $rowSpan = " rowspan=\"2\"";
  86. }
  87. // Extract the view type requested by the user (either 'Mobile', 'Print', 'Web' or ''):
  88. // ('' will produce the default 'Web' output style)
  89. if (isset($_REQUEST['viewType']))
  90. $viewType = $_REQUEST['viewType'];
  91. else
  92. $viewType = "";
  93. // If there were some errors on submit -> Re-load the data that were submitted by the user:
  94. if (!empty($errors))
  95. {
  96. if (isset($formVars['sourceText'])) // '$formVars['sourceText']' may be non-existent in the (unlikely but possible) event that a user calls 'import_csa_modify.php' directly
  97. $sourceText = $formVars['sourceText'];
  98. else
  99. $sourceText = "";
  100. // check if we need to set the checkbox in front of "Display original source data":
  101. if (isset($formVars['showSource'])) // the user did mark the 'showSource' checkbox
  102. $showSource = $formVars['showSource'];
  103. else
  104. $showSource = "";
  105. if (isset($formVars['importRecordsRadio'])) // 'importRecordsRadio' is only set if user has 'batch_import' permission
  106. $importRecordsRadio = $formVars['importRecordsRadio'];
  107. else
  108. $importRecordsRadio = "";
  109. if (isset($formVars['importRecords'])) // 'importRecords' is only set if user has 'batch_import' permission
  110. $importRecords = $formVars['importRecords'];
  111. else
  112. $importRecords = "";
  113. // check whether the user marked the checkbox to skip records with unrecognized data format:
  114. if (isset($formVars['skipBadRecords']))
  115. $skipBadRecords = $formVars['skipBadRecords'];
  116. else
  117. $skipBadRecords = "";
  118. }
  119. else // display an empty form (i.e., set all variables to an empty string [""] or their default values, respectively):
  120. {
  121. $sourceText = "";
  122. $showSource = "1";
  123. $importRecordsRadio = "only";
  124. $importRecords = "1";
  125. $skipBadRecords = "";
  126. }
  127. // Show the login status:
  128. showLogin(); // (function 'showLogin()' is defined in 'include.inc.php')
  129. // (2a) Display header:
  130. // call the 'displayHTMLhead()' and 'showPageHeader()' functions (which are defined in 'header.inc.php'):
  131. displayHTMLhead(encodeHTML($officialDatabaseName) . $pageTitle, "index,follow", "Search the " . encodeHTML($officialDatabaseName), "", false, "", $viewType, array());
  132. showPageHeader($HeaderString);
  133. // (2b) Start <form> and <table> holding the form elements:
  134. echo "\n<form action=\"import_csa_modify.php\" method=\"POST\">";
  135. echo "\n<input type=\"hidden\" name=\"formType\" value=\"importCSA\">"
  136. . "\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)
  137. . "\n<input type=\"hidden\" name=\"showLinks\" value=\"1\">"; // embed '$showLinks=1' so that links get displayed on any 'display details' page
  138. if (isset($errors['badRecords']))
  139. {
  140. if ($errors['badRecords'] == "all") // none of the given records had a recognized format
  141. {
  142. if (!empty($errors['skipBadRecords']))
  143. $skipBadRecordsInput = "<br>" . fieldError("skipBadRecords", $errors);
  144. else
  145. $skipBadRecordsInput = "";
  146. }
  147. elseif ($errors['badRecords'] == "some") // there were at least some records with recognized format but other records could NOT be recognized
  148. {
  149. if (!empty($skipBadRecords))
  150. $skipBadRecordsCheckBoxIsChecked = " checked"; // mark the 'Skip records with unrecognized data format' checkbox
  151. else
  152. $skipBadRecordsCheckBoxIsChecked = "";
  153. // display the 'Skip records with unrecognized data format' checkbox:
  154. $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);
  155. }
  156. }
  157. else // all records did have a valid data format -> supress the 'Skip records with unrecognized data format' checkbox
  158. {
  159. $skipBadRecordsInput = "";
  160. }
  161. echo "\n<table align=\"center\" border=\"0\" cellpadding=\"0\" cellspacing=\"10\" width=\"95%\" summary=\"This table holds the CSA import form\">"
  162. . "\n<tr>\n\t<td width=\"58\" valign=\"top\"><b>" . $textEntryFormLabel . ":</b></td>\n\t<td width=\"10\">&nbsp;</td>"
  163. . "\n\t<td colspan=\"3\">" . fieldError("sourceText", $errors) . $skipBadRecordsInput . "<textarea name=\"sourceText\" rows=\"6\" cols=\"60\" title=\"paste your CSA records here (requires 'full record' format!)\">$sourceText</textarea></td>"
  164. . "\n</tr>";
  165. if (!empty($showSource))
  166. $showSourceCheckBoxIsChecked = " checked"; // mark the 'Display original source data' checkbox
  167. else
  168. $showSourceCheckBoxIsChecked = "";
  169. echo "\n<tr>\n\t<td valign=\"top\"" . $rowSpan . "><b>Options:</b></td>\n\t<td" . $rowSpan . ">&nbsp;</td>"
  170. . "\n\t<td width=\"215\" valign=\"top\"" . $rowSpan . "><input type=\"checkbox\" name=\"showSource\" value=\"1\"$showSourceCheckBoxIsChecked title=\"mark this checkbox if original source data shall be displayed alongside the parsed data for easy comparison\">&nbsp;&nbsp;Display original source data</td>";
  171. 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'...
  172. {
  173. if ($importRecordsRadio == "all")
  174. {
  175. $importRecordsRadioAllChecked = " checked"; // select the 'All' radio button
  176. $importRecordsRadioOnlyChecked = "";
  177. }
  178. else // $importRecordsRadio == "only"
  179. {
  180. $importRecordsRadioAllChecked = "";
  181. $importRecordsRadioOnlyChecked = " checked"; // select the 'Only' radio button
  182. }
  183. echo "\n\t<td width=\"98\" valign=\"top\"" . $rowSpan . ">Import records:</td>"
  184. . "\n\t<td valign=\"top\"><input type=\"radio\" name=\"importRecordsRadio\" value=\"all\"$importRecordsRadioAllChecked title=\"choose 'All' if you want to import all pasted records at once\">&nbsp;All</td>"
  185. . "\n</tr>"
  186. . "\n<tr>"
  187. . "\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 from the pasted source data\">&nbsp;Only:&nbsp;&nbsp;<input type=\"text\" name=\"importRecords\" value=\"$importRecords\" size=\"5\" title=\"enter the record number(s) here: e.g. enter '1-5' to import the first five records; or enter '1 3-5 7' to import records 1, 3, 4, 5 and 7\"></td>";
  188. }
  189. else
  190. {
  191. echo "\n\t<td colspan=\"2\">&nbsp;</td>";
  192. }
  193. echo "\n</tr>";
  194. echo "\n<tr>\n\t<td>&nbsp;</td>\n\t<td>&nbsp;</td>";
  195. 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'...
  196. // adjust the title string for the import button
  197. {
  198. $importButtonLock = "";
  199. $importTitle = "press this button to import the given source data";
  200. }
  201. 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!
  202. {
  203. $importButtonLock = " disabled";
  204. $importTitle = "not available since you have no permission to import any records";
  205. }
  206. echo "\n\t<td colspan=\"3\">\n\t\t<input type=\"submit\" name=\"submit\" value=\"Import\"$importButtonLock title=\"$importTitle\">\n\t</td>"
  207. . "\n</tr>"
  208. . "\n<tr>\n\t<td align=\"center\" colspan=\"5\">&nbsp;</td>"
  209. . "\n</tr>"
  210. . "\n<tr>\n\t<td valign=\"top\"><b>Help:</b></td>\n\t<td>&nbsp;</td>"
  211. . "\n\t<td valign=\"top\" colspan=\"3\">This form enables you to import records from the <a href=\"" . $importCSArecordsURL . "\" target=\"top\">" // '$importCSArecordsURL' is defined in 'ini.inc.php'
  212. . "Cambridge Scientific Abstracts</a> (CSA) Internet Database Service. The form requires the 'full record' format offered by the CSA Internet Database Service. An example of a valid CSA 'full record' format is given below:</td>"
  213. . "\n</tr>"
  214. . "\n<tr>\n\t<td valign=\"top\"><b>Example:</b></td>\n\t<td>&nbsp;</td>"
  215. . "\n\t<td valign=\"top\" colspan=\"3\"><pre>Record 1 of 52
  216. DN: Database Name
  217. ASFA: Aquatic Sciences and Fisheries Abstracts
  218. TI: Title
  219. Diet composition influences the growth of the pelagic mysid
  220. shrimp, Mysis mixta (Mysidacea)
  221. AU: Author
  222. Lehtiniemi, M; Vitasalo, M; Kuosa, H
  223. AF: Affiliation
  224. Finnish Institute of Marine Research, P.O. Box 33, FIN-00931
  225. Helsinki, Finland
  226. SO: Source
  227. Boreal Environment Research [Boreal Environ. Res.]. Vol. 7, no. 2,
  228. pp. 121-128. 2002.
  229. IS: ISSN
  230. 1239-6095
  231. AB: Abstract
  232. We studied the growth, feeding, and elemental composition of Mysis
  233. mixta from June to September 1997 in the northern Baltic Sea. In
  234. June the juvenile population had a unimodal size distribution
  235. (mean length similar to 6 mm), but in July-August, the population
  236. was divided into two cohorts. A stomach content analysis showed
  237. that the mysids in the larger and faster growing cohort fed
  238. significantly more on crustacean zooplankton and pelagic material
  239. than the smaller one: the mean ratios of zooplankton:phytoplankton
  240. and pelagic:benthic particles in July-August were respectively
  241. 0.27 and 0.11 for the small cohort, and 0.54 and 0.36 for the
  242. large cohort. This suggests that food quality and its energy
  243. content are important in influencing the growth of pelagic mysids
  244. in the northern Baltic. The C:N ratio of the two cohorts did not
  245. vary much, which shows that ingestion of food items with varying
  246. elemental content is not necessarily reflected in the elemental
  247. composition of consumers.
  248. LA: Language
  249. English
  250. SL: Summary Language
  251. English
  252. PY: Publication Year
  253. 2002
  254. PD: Publication Date
  255. 20020000
  256. PT: Publication Type
  257. Journal Article
  258. DE: Descriptors
  259. Growth; Feeding; Diets; Chemical composition; Seasonal variations;
  260. Mysis mixta; ANE, Baltic Sea
  261. TR: ASFA Input Center Number
  262. CS0309883
  263. CL: Classification
  264. Q1 01424 Age and growth; O 1070 Ecology/Community Studies
  265. UD: Update
  266. 200305
  267. SF: Subfile
  268. ASFA 1: Biological Sciences &amp; Living Resources; Oceanic Abstracts
  269. AN: Accession Number
  270. 5449614
  271. F1: Fulltext Info
  272. 1239-6095,7,2,121-128,2002
  273. A1: Alert Info
  274. 20030606
  275. JN: Journal Name
  276. Boreal Environment Research
  277. JP: Journal Pages
  278. 121-128
  279. JV: Journal Volume
  280. 7
  281. JI: Journal Issue
  282. 2
  283. DT: Document Type
  284. J
  285. BL: Bibliographic Level
  286. AS
  287. </pre></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. ?>