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.

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