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.

776 lines
46 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_modify.php
  13. // Repository: $HeadURL: file:///svn/p/refbase/code/branches/bleeding-edge/import_csa_modify.php $
  14. // Author(s): Matthias Steffens <mailto:refbase@extracts.de>
  15. //
  16. // Created: 21-Nov-03, 22:46
  17. // Modified: $Date: 2012-02-27 20:25:30 +0000 (Mon, 27 Feb 2012) $
  18. // $Author: msteffens $
  19. // $Revision: 1337 $
  20. // This php script accepts input from 'import_csa.php' and will process any CSA full record data. In case of a single
  21. // record, the script will call 'record.php' with all provided fields pre-filled. The user can then verify the data,
  22. // add or modify any details as necessary and add the record to the database. Multiple records will be imported directly.
  23. // TODO: I18n
  24. // Incorporate some include files:
  25. include 'initialize/db.inc.php'; // 'db.inc.php' is included to hide username and password
  26. include 'includes/include.inc.php'; // include common functions
  27. include 'includes/import.inc.php'; // include common import functions
  28. include 'initialize/ini.inc.php'; // include common variables
  29. // --------------------------------------------------------------------
  30. // START A SESSION:
  31. // call the 'start_session()' function (from 'include.inc.php') which will also read out available session variables:
  32. start_session(true);
  33. // --------------------------------------------------------------------
  34. // Initialize preferred display language:
  35. // (note that 'locales.inc.php' has to be included *after* the call to the 'start_session()' function)
  36. include 'includes/locales.inc.php'; // include the locales
  37. // --------------------------------------------------------------------
  38. // Clear any errors that might have been found previously:
  39. $errors = array();
  40. // Write the (POST or GET) form variables into an array:
  41. foreach($_REQUEST as $varname => $value)
  42. $formVars[$varname] = $value;
  43. // --------------------------------------------------------------------
  44. // Get the referring page (or set a default one if no referrer is available):
  45. if (!empty($_SERVER['HTTP_REFERER'])) // if the referrer variable isn't empty
  46. $referer = $_SERVER['HTTP_REFERER']; // on error, redirect to calling page
  47. else
  48. $referer = "import_csa.php"; // on error, redirect to CSA import form
  49. // First of all, check if the user is logged in:
  50. if (!isset($_SESSION['loginEmail'])) // -> if the user isn't logged in
  51. {
  52. header("Location: user_login.php?referer=" . rawurlencode($referer)); // ask the user to login first, then he'll get directed back to the calling page (normally, 'import_csa.php')
  53. exit; // >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> !EXIT! <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
  54. }
  55. // now, check if the (logged in) user is allowed to import any record into the database:
  56. if (isset($_SESSION['user_permissions']) AND !preg_match("/allow_import|allow_batch_import/", $_SESSION['user_permissions'])) // if the 'user_permissions' session variable does NOT contain either 'allow_import' or 'allow_batch_import'...
  57. {
  58. // return an appropriate error message:
  59. $HeaderString = returnMsg($loc["NoPermission"] . $loc["NoPermission_ForImport"] . "!", "warning", "strong", "HeaderString"); // function 'returnMsg()' is defined in 'include.inc.php'
  60. if (!preg_match("/^cli/i", $client))
  61. header("Location: index.php"); // redirect back to main page ('index.php')
  62. exit; // >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> !EXIT! <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
  63. }
  64. // Extract form variables sent through POST:
  65. // Note: Although we could use the '$formVars' array directly below (e.g.: $formVars['sourceText'] etc., like in 'user_validation.php'), we'll read out
  66. // all variables individually again. This is done to enhance readability. (A smarter way of doing so seems to be the use of the 'extract()' function, but that
  67. // may expose yet another security hole...)
  68. // Get the form used by the user:
  69. $formType = $formVars['formType'];
  70. // Get the source text containing the CSA record(s):
  71. $sourceText = $formVars['sourceText'];
  72. // Check if source text originated from a PubMed import form (instead of 'import_csa.php')
  73. if ($formType == "importPUBMED")
  74. {
  75. $sourceText = trim($sourceText); // trim whitespace from poorly copied id's
  76. // Fetch PubMed XML data (by PubMed ID given in '$sourceText') and convert to CSA format:
  77. // (this allows for import of PubMed records via the import form provided by 'import_pubmed.php')
  78. $sourceText = PubmedToCsa($sourceText); // function 'PubmedToCsa()' is defined in 'import.inc.php'
  79. }
  80. // Check if the format of the pasted source data is in "ISI Web of Science" format (instead of "CSA" format):
  81. if ((!preg_match("/\s*Record \d+ of \d+\s*/", $sourceText)) and (preg_match("/\s*FN ISI Export Format\s*/", $sourceText)))
  82. {
  83. // Convert ISI WoS format to CSA format:
  84. // (this allows for import of ISI WoS records via the import form provided by 'import_csa.php')
  85. $sourceText = IsiToCsa($sourceText); // function 'IsiToCsa()' is defined in 'import.inc.php'
  86. }
  87. // Check whether we're supposed to display the original source data:
  88. if (isset($formVars['showSource']))
  89. $showSource = $formVars['showSource'];
  90. else
  91. $showSource = "";
  92. 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'...
  93. {
  94. // Check whether we're supposed to import all records ('all') or just particular ones ('only'):
  95. $importRecordsRadio = $formVars['importRecordsRadio'];
  96. // Get the record numbers of those records that shall be imported:
  97. // examples of recognized formats: '1-5' imports the first five records; '1 3 7' will import records 1, 3 and 7; '1-3 5-7 9' will import records 1, 2, 3, 5, 6, 7 and 9
  98. // (note that the first three records could be labelled e.g. as 'Record 12 of 52', 'Record 30 of 112' and 'Record 202 of 533' but they must be referred to as records '1-3'
  99. // in the 'importRecords' form)
  100. $importRecords = $formVars['importRecords'];
  101. }
  102. else // if the user is only allowed to import one record at a time, we'll always import the very first record
  103. {
  104. $importRecordsRadio = "only";
  105. $importRecords = "1";
  106. }
  107. // Check whether we're supposed to skip records with unrecognized data format:
  108. if (isset($formVars['skipBadRecords']))
  109. $skipBadRecords = $formVars['skipBadRecords'];
  110. else
  111. $skipBadRecords = "";
  112. // --------------------------------------------------------------------
  113. // Do some pre-processing of the data input:
  114. // Process record number input:
  115. $importRecordNumbersArray = array(); // initialize array variable which will hold all the record numbers that shall be imported
  116. if (!empty($importRecords))
  117. {
  118. // split input string on all but digits or the hyphen ("-") character:
  119. // (the 'PREG_SPLIT_NO_EMPTY' flag causes only non-empty pieces to be returned)
  120. $importRecordsArray = preg_split("/[^0-9-]+/", $importRecords, -1, PREG_SPLIT_NO_EMPTY); // this keeps only elements such as '1', '3-5', '3-5-9' or '3-' (we'll deal with the last two cases below)
  121. foreach ($importRecordsArray as $importRecordsElement)
  122. {
  123. if (preg_match("/\d+-\d+/", $importRecordsElement)) // if we're dealing with a range of record numbers (such as '1-5')
  124. {
  125. $importRecordsElementArray = preg_split("/-/", $importRecordsElement); // split input string on hyphen ("-") character
  126. // generate an array that includes all numbers from start number to end number:
  127. // (in case of incorrect input (such as '3-5-9') we'll only take the first two numbers and ignore anything else)
  128. $importRecordRangeArray = range($importRecordsElementArray[0], $importRecordsElementArray[1]);
  129. foreach ($importRecordRangeArray as $importRecordNumber) // append all record numbers within range to array
  130. $importRecordNumbersArray[] = $importRecordNumber;
  131. }
  132. else // this element contains just a single record number
  133. {
  134. // append this record number to array:
  135. $importRecordNumbersArray[] = preg_replace("/(\d+).*/", "\\1", $importRecordsElement); // we account for the case that '$importRecordsElement' contains something like '3-'
  136. }
  137. }
  138. }
  139. // validation will throw up an error if we're supposed to import only particular records but no record numbers were specified
  140. // Remove any duplicate record number(s) from the list of extracted record numbers:
  141. $importRecordNumbersArray = array_unique($importRecordNumbersArray);
  142. // Extract the first record identifier of the input data (e.g. "\nRecord 1 of ...\n"):
  143. // this will also allow to paste record data that don't start with "\nRecord 1 of ...\n" but with e.g. "\nRecord 3 of ...\n"
  144. // (note that I couldn't figure out a non-greedy regex pattern to reliably extract the *very first* record identifier
  145. // which is why I'm using this 'preg_split()' workaround here)
  146. // - split on record identifiers ("\nRecord ... of ...\n") and include the found identifiers (i.e. the delimiters) as additional array elements ('PREG_SPLIT_DELIM_CAPTURE' flag):
  147. $recordsAndRecordNumbersArray = preg_split("/\s*(Record \d+ of \d+)\s*/", $sourceText, -1, PREG_SPLIT_DELIM_CAPTURE);
  148. $firstRecordIdentifier = "Record 1 of \d+"; // establish a default search pattern for the regex replace action below (otherwise, if '$firstRecordIdentifier' would be empty, all of the '$sourceText' would be deleted!)
  149. for ($i=0; $i<(count($recordsAndRecordNumbersArray)); $i++)
  150. {
  151. if (preg_match("/^Record \d+ of \d+$/", $recordsAndRecordNumbersArray[$i]))
  152. {
  153. // - extract the first record identifier
  154. $firstRecordIdentifier = $recordsAndRecordNumbersArray[$i];
  155. break;
  156. }
  157. }
  158. // Remove any text preceeding the actual record data as well as the first record identifier ("\nRecord ... of ...\n"):
  159. // CAUTION: Note that record identifiers must be unique among the pasted records! If e.g. the record identifier in '$firstRecordIdentifier'
  160. // occurs twice, the line below will remove all records up to the *second* occurrence of this identifier!
  161. $trimmedSourceText = preg_replace("/.*\s*" . $firstRecordIdentifier . "(?=\D)\s*/s", "", $sourceText);
  162. // Split input text on the header text preceeding each CSA record (e.g. "\nRecord 4 of 52\n"):
  163. $recordArray = preg_split("/\s*Record \d+ of \d+\s*/", $trimmedSourceText);
  164. $recordsCount = count($recordArray); // count how many records are available
  165. // --------------------------------------------------------------------
  166. // VALIDATE data fields:
  167. // Verify that some source text was given:
  168. if (empty($sourceText)) // no source data given
  169. {
  170. $errors["sourceText"] = "Source data missing!";
  171. }
  172. // Validate the 'importRecords' text entry field...
  173. if ($importRecordsRadio == "only") // ...if we're supposed to import only particular records
  174. {
  175. // ...make sure that some records were specified and that they are actually available in the input data:
  176. if (empty($importRecords) OR !preg_match("/[0-9]/", $importRecords)) // partial import requested but no record numbers given
  177. {
  178. $errors["importRecords"] = "Record number(s) missing!";
  179. }
  180. else // if some record numbers were given, check that these numbers are actually available in the input data:
  181. {
  182. $availableRecordNumbersArray = range(1, $recordsCount); // construct an array of available record numbers
  183. // get all record numbers to import which are NOT available in the source data:
  184. $importRecordNumbersNotAvailableArray = array_diff($importRecordNumbersArray, $availableRecordNumbersArray); // get all unique array elements from '$importRecordNumbersArray' that are not present in '$availableRecordNumbersArray'
  185. // just FYI, the line below would get all record numbers to import which ARE actually available in the source data:
  186. // $importRecordNumbersAvailableArray = array_diff($importRecordNumbersArray, $importRecordNumbersNotAvailableArray); // get all unique array elements from '$importRecordNumbersArray' that are not present in '$importRecordNumbersNotAvailableArray'
  187. if (!empty($importRecordNumbersNotAvailableArray)) // the user did request to import some record(s) that don't exist in the pasted source data
  188. {
  189. if ($recordsCount == 1) // one record available
  190. $errors["importRecords"] = "Only one record available! You can only use record number '1'.";
  191. else // several records available
  192. $errors["importRecords"] = "Only " . $recordsCount . " records available! You can only use record numbers '1-" . $recordsCount . "'.";
  193. }
  194. }
  195. }
  196. // the user did enter some source text and did input some recognized record numbers
  197. if (!empty($sourceText))
  198. {
  199. $importRecordNumbersRecognizedFormatArray = array(); // initialize array variable which will hold all record numbers of those records that shall be imported AND which were of a recognized format
  200. $importRecordNumbersNotRecognizedFormatArray = array(); // same for all records that shall be imported BUT which had an UNrecognized format
  201. // Verify the record format:
  202. for ($i=0; $i<$recordsCount; $i++) // for each record...
  203. {
  204. $singleRecord = $recordArray[$i];
  205. if (($importRecordsRadio == "only") AND (!in_array(($i+1), $importRecordNumbersArray))) // if we're NOT supposed to import this record... ('$i' starts with 0 so we have to add 1 to point to the correct record number)
  206. {
  207. continue; // process next record (if any)
  208. }
  209. else // ...validate the format of the current record:
  210. {
  211. // We assume a single record as valid if the '$singleRecord' variable is not empty and if it does contain
  212. // at least the following three field identifiers: "TI: Title", "SO: Source", "AU: Author" (only exception: for book monographs we accept "ED: Editor" instead of "AU: Author")
  213. // In addition, each of these field identifiers must be followed by a return and/or newline and four spaces!
  214. if (!empty($singleRecord) AND preg_match("/^TI: Title *[\r\n]+ {4,4}/m", $singleRecord) AND preg_match("/^SO: Source *[\r\n]+ {4,4}/m", $singleRecord) AND (preg_match("/^AU: Author *[\r\n]+ {4,4}/m", $singleRecord) OR (preg_match("/^ED: Editor *[\r\n]+ {4,4}/m", $singleRecord) AND preg_match("/^(PT: Publication Type\s+Book Monograph|DT: Document Type\s+B)/m", $singleRecord))))
  215. {
  216. $importRecordNumbersRecognizedFormatArray[] = $i + 1; // append this record number to the list of numbers whose record format IS recognized ('$i' starts with 0 so we have to add 1 to point to the correct record number)
  217. }
  218. else // unrecognized record format
  219. {
  220. $importRecordNumbersNotRecognizedFormatArray[] = $i + 1; // append this record number to the list of numbers whose record format is NOT recognized
  221. // prepare an appropriate error message:
  222. $errorMessage = "Record " . ($i + 1) . ": Unrecognized data format!";
  223. $emptyFieldsArray = array();
  224. // check for required fields:
  225. if (!preg_match("/^TI: Title *[\r\n]+ {4,4}/m", $singleRecord)) // required field empty: 'title'
  226. $emptyFieldsArray[] = "title";
  227. if (!preg_match("/^AU: Author *[\r\n]+ {4,4}/m", $singleRecord) AND !preg_match("/^(PT: Publication Type\s+Book Monograph|DT: Document Type\s+B)/m", $singleRecord)) // non-books: required field empty: 'author'
  228. $emptyFieldsArray[] = "author";
  229. elseif (!preg_match("/^AU: Author *[\r\n]+ {4,4}/m", $singleRecord) AND !preg_match("/^ED: Editor *[\r\n]+ {4,4}/m", $singleRecord) AND preg_match("/^(PT: Publication Type\s+Book Monograph|DT: Document Type\s+B)/m", $singleRecord)) // books: required fields empty: 'author' AND 'editor' (for books, either 'author' or 'editor' must be given)
  230. $emptyFieldsArray[] = "author (or editor)";
  231. if (!preg_match("/^SO: Source *[\r\n]+ {4,4}/m", $singleRecord)) // required field empty: 'source'
  232. $emptyFieldsArray[] = "source";
  233. if (!empty($emptyFieldsArray)) // some required fields were missing
  234. {
  235. if (count($emptyFieldsArray) == 1) // one field missing
  236. $errorMessage .= " Required field missing: " . $emptyFieldsArray[0];
  237. else // several fields missing
  238. $errorMessage .= " Required fields missing: " . implode(', ', $emptyFieldsArray);
  239. }
  240. if (!isset($errors["sourceText"]))
  241. $errors["sourceText"] = $errorMessage;
  242. else
  243. $errors["sourceText"] = $errors["sourceText"] . "<br>" . $errorMessage;
  244. }
  245. }
  246. }
  247. if (empty($importRecordNumbersRecognizedFormatArray)) // if none of the records to import had a recognized format
  248. {
  249. // we'll file an additional error element here, which will indicate whether the 'Skip records with unrecognized data format' checkbox shall be displayed or not
  250. $errors["badRecords"] = "all";
  251. if (count($importRecordNumbersNotRecognizedFormatArray) > 1) // if the user attempted to import more than one record
  252. $errors["skipBadRecords"] = "Sorry, but all of the specified records were of unrecognized data format!";
  253. else // user tried to import one single record (will be also triggered if '$importRecords' is empty)
  254. $errors["skipBadRecords"] = ""; // we insert an empty 'skipBadRecords' element so that 'import_csa.php' does the right thing
  255. }
  256. elseif (!empty($importRecordNumbersNotRecognizedFormatArray)) // some records had a recognized format but some were NOT recognized
  257. {
  258. $errors["badRecords"] = "some"; // see note above
  259. $errors["skipBadRecords"] = "Skip records with unrecognized data format";
  260. }
  261. }
  262. // --------------------------------------------------------------------
  263. // Check if there were any validation errors:
  264. if (count($errors) > 0)
  265. {
  266. // we ignore errors regarding records with unrecognized format if:
  267. // - at least some of the specified records had a valid data format and
  268. // - the user did mark the 'Skip records with unrecognized data format' checkbox
  269. if (!(($errors["badRecords"] == "some") AND ($skipBadRecords == "1")))
  270. {
  271. // ...otherwise we'll redirect back to the CSA import form and present the error message(s):
  272. // Write back session variables:
  273. saveSessionVariable("errors", $errors); // function 'saveSessionVariable()' is defined in 'include.inc.php'
  274. saveSessionVariable("formVars", $formVars);
  275. // Redirect the browser back to the CSA import form:
  276. header("Location: " . $referer);
  277. exit; // >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> !EXIT! <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
  278. }
  279. }
  280. // --------------------------------------------------------------------
  281. // If we made it here, then the data is considered valid!
  282. // (3) PROCESS SOURCE DATA:
  283. $parsedRecordsArray = array(); // initialize array variable which will hold parsed data of all records that shall be imported
  284. // LOOP OVER EACH RECORD:
  285. for ($i=0; $i<$recordsCount; $i++) // for each record...
  286. {
  287. // if we're NOT supposed to import this record (because it was either not selected by the user -OR- because it did contain an unrecognized data format)
  288. if (!in_array(($i+1), $importRecordNumbersRecognizedFormatArray)) // '$i' starts with 0 so we have to add 1 to point to the correct record number
  289. {
  290. continue; // process next record (if any)
  291. }
  292. else // ...import the current record:
  293. {
  294. $singleRecord = $recordArray[$i];
  295. // if the "AU: Author" field is missing BUT the "ED: Editor" is present (which is allowed for book monographs, see above):
  296. // we replace the "ED: Editor" field identifier with "AU: Author" (this will keep any " (ed)" and " (eds)" tags in place which, in turn, will cause the "is Editor" checkbox in 'record.php' to get marked)
  297. if (!preg_match("/^AU: Author *[\r\n]+ {4,4}/m", $singleRecord) AND preg_match("/^ED: Editor *[\r\n]+ {4,4}/m", $singleRecord) AND preg_match("/^(PT: Publication Type\s+Book Monograph|DT: Document Type\s+B)/m", $singleRecord))
  298. $singleRecord = preg_replace("/^ED: Editor(?= *[\r\n]+ {4,4})/m", "AU: Author", $singleRecord);
  299. $fieldArray = preg_split("/[\r\n]+(?=\w\w: )/", $singleRecord); // split each record into its fields
  300. // initialize some variables:
  301. $fieldParametersArray = array(); // setup an empty array (it will hold the parameters that get passed to 'record.php')
  302. $additionalDocumentTypeInfo = ""; // will be used with the "PT: Publication Type" field
  303. $environmentalRegime = ""; // will be used with the "ER: Environmental Regime" field
  304. // GENERATE EXTRA FIELDS:
  305. // check if the fields "MT: Monograph Title", "JN: Journal Name", "JV: Journal Volume", "JI: Journal Issue" and "JP: Journal Pages" are present,
  306. // if not, we attempt to generate them from the "SO: Source" field:
  307. $sourceField = preg_replace("/.*SO: Source *[\r\n]+ {4,4}(.+?)(?=([\r\n]+\w\w: |\s*\z)).*/ms", "\\1", $singleRecord); // first, we need to extract the "SO: Source" field data from the record text
  308. $sourceField = preg_replace("/\s{2,}/", " ", $sourceField); // remove any hard returns and extra spaces within the source field data string
  309. // if the current record is of type "Book Monograph" but the field "MT: Monograph Title" is missing:
  310. if (preg_match("/^(PT: Publication Type\s+Book Monograph|DT: Document Type\s+B)/m", $singleRecord) AND !preg_match("/^MT: Monograph Title *[\r\n]+ {4,4}/m", $singleRecord))
  311. {
  312. $extractedSourceFieldData = preg_replace("/^([^.[]+).*/", "\\1", $sourceField); // attempt to extract the full monograph title from the source field
  313. if (preg_match("/^[[:upper:]\W\d]+$/", $extractedSourceFieldData)) // if all of the words within the monograph title are uppercase, we attempt to convert the string to something more readable:
  314. $extractedSourceFieldData = ucwords(strtolower($extractedSourceFieldData)); // perform case transformation (e.g. convert "BIOLOGY AND ECOLOGY OF GLACIAL RELICT CRUSTACEA" into "Biology And Ecology Of Glacial Relict Crustacea")
  315. $fieldArray[] = "MT: Monograph Title\r\n " . $extractedSourceFieldData; // add field "MT: Monograph Title" to the array of fields
  316. }
  317. // else if the current record is of type "Journal Article", "Report", etc (or wasn't specified) but the field "JN: Journal Name" is missing:
  318. elseif (!preg_match("/^JN: Journal Name *[\r\n]+ {4,4}/m", $singleRecord)) // preg_match("/^(PT: Publication Type\s+(Journal Article|Report)|DT: Document Type\s+(J|R))/m", $singleRecord)
  319. {
  320. if (preg_match("/\[/", $sourceField)) // if the source field data contain a square bracket we assume a format like: "Journal of Phycology [J. Phycol.]. Vol. 37, no. s3, pp. 18-18. Jun 2001."
  321. $extractedSourceFieldData = preg_replace("/^([^.[]+).*/", "\\1", $sourceField); // attempt to extract the full journal name from the source field
  322. else // source field format might be something like: "Phycologia, vol. 34, no. 2, pp. 135-144, 1995"
  323. $extractedSourceFieldData = preg_replace("/^([^.,]+).*/", "\\1", $sourceField); // attempt to extract the full journal name from the source field
  324. if (preg_match("/^[[:upper:]\W\d]+$/", $extractedSourceFieldData)) // if all of the words within the journal name are uppercase, we attempt to convert the string to something more readable:
  325. $extractedSourceFieldData = ucwords(strtolower($extractedSourceFieldData)); // perform case transformation (e.g. convert "POLAR BIOLOGY" into "Polar Biology")
  326. $fieldArray[] = "JN: Journal Name\r\n " . $extractedSourceFieldData; // add field "JN: Journal Name" to the array of fields
  327. }
  328. // if the "JV: Journal Volume" is missing BUT the "SO: Source" field contains a volume specification:
  329. if (!preg_match("/^JV: Journal Volume *[\r\n]+ {4,4}/m", $singleRecord) AND preg_match("/(?<=\W)vol[. ]+[\w\/-]+/i", $sourceField))
  330. {
  331. $extractedSourceFieldData = preg_replace("/.*(?<=\W)vol[. ]+([\w\/-]+).*/i", "\\1", $sourceField); // attempt to extract the journal volume from the source field
  332. $fieldArray[] = "JV: Journal Volume\r\n " . $extractedSourceFieldData; // add field "JV: Journal Volume" to the array of fields
  333. }
  334. // if the "JI: Journal Issue" is missing BUT the "SO: Source" field contains an issue specification:
  335. if (!preg_match("/^JI: Journal Issue *[\r\n]+ {4,4}/m", $singleRecord) AND preg_match("/(?<=\W)no[. ]+[\w\/-]+/i", $sourceField))
  336. {
  337. $extractedSourceFieldData = preg_replace("/.*(?<=\W)no[. ]+([\w\/-]+).*/i", "\\1", $sourceField); // attempt to extract the journal issue from the source field
  338. $fieldArray[] = "JI: Journal Issue\r\n " . $extractedSourceFieldData; // add field "JI: Journal Issue" to the array of fields
  339. }
  340. // if the "JP: Journal Pages" is missing BUT the "SO: Source" field contains a pages specification:
  341. if (!preg_match("/^JP: Journal Pages *[\r\n]+ {4,4}/m", $singleRecord) AND preg_match("/((?<=\W)pp?[. ]+[\w\/,-]+|[\d,]+ *pp\b)/i", $sourceField))
  342. {
  343. if (preg_match("/(?<=\W)pp?[. ]+[\w\/,-]+/i", $sourceField)) // e.g. "pp. 212-217" or "p. 216" etc
  344. $extractedSourceFieldData = preg_replace("/.*(?<=\W)pp?[. ]+([\w\/,-]+).*/i", "\\1", $sourceField); // attempt to extract the journal pages from the source field
  345. elseif (preg_match("/[\d,]+ *pp\b/", $sourceField)) // e.g. "452 pp"
  346. $extractedSourceFieldData = preg_replace("/.*?([\d,]+ *pp)\b.*/i", "\\1", $sourceField); // attempt to extract the journal pages from the source field
  347. $extractedSourceFieldData = preg_replace("/,/", "", $extractedSourceFieldData); // remove any thousands separators from journal pages
  348. $fieldArray[] = "JP: Journal Pages\r\n " . $extractedSourceFieldData; // add field "JP: Journal Pages" to the array of fields
  349. }
  350. // Additionally, we extract the abbreviated journal name from the "SO: Source" field (if available):
  351. if (preg_match("/\[/", $sourceField)) // if the source field data contain a square bracket we assume a format like: "Journal of Phycology [J. Phycol.]. Vol. 37, no. s3, pp. 18-18. Jun 2001."
  352. {
  353. $extractedSourceFieldData = preg_replace("/.*\[(.+?)\].*/", "\\1", $sourceField); // attempt to extract the abbreviated journal name from the source field
  354. $extractedSourceFieldData = preg_replace("/\./", "", $extractedSourceFieldData); // remove any dots from the abbreviated journal name
  355. if (preg_match("/^[[:upper:]\W\d]+$/", $extractedSourceFieldData)) // if all of the words within the abbreviated journal name are uppercase, we attempt to convert the string to something more readable:
  356. $extractedSourceFieldData = ucwords(strtolower($extractedSourceFieldData)); // perform case transformation (e.g. convert "BALT SEA ENVIRON PROC" into "Balt Sea Environ Proc")
  357. $fieldArray[] = "JA: Abbrev Journal Name\r\n " . $extractedSourceFieldData; // add field "JA: Abbrev Journal Name" to the array of fields (note that this field normally does NOT occur within the CSA full record format!)
  358. }
  359. // (END GENERATE EXTRA FIELDS)
  360. // LOOP OVER EACH FIELD:
  361. foreach ($fieldArray as $singleField) // for each field within the current record...
  362. {
  363. $singleField = preg_replace("/^(\w\w: [^\r\n]+)[\r\n]+ {4,4}/", "\\1___LabelDataSplitter___", $singleField); // insert a unique text string between the field identifier and the field data
  364. $fieldLabelPlusDataArray = preg_split("/___LabelDataSplitter___/", $singleField); // split each field into a 2-element array containing [0] the field identifier and [1] the field data
  365. $fieldLabelPlusDataArray[1] = preg_replace("/\s{2,}/", " ", $fieldLabelPlusDataArray[1]); // remove any hard returns and extra spaces within the data string
  366. $fieldLabelPlusDataArray[1] = trim($fieldLabelPlusDataArray[1]); // remove any preceeding and trailing whitespace from the field data
  367. if (preg_match("/AU: Author/", $fieldLabelPlusDataArray[0]))
  368. $fieldLabelPlusDataArray[1] = preg_replace("/\*/", "", $fieldLabelPlusDataArray[1]); // remove any asterisk ("*")
  369. elseif (preg_match("/ED: Editor/", $fieldLabelPlusDataArray[0]))
  370. $fieldLabelPlusDataArray[1] = preg_replace("/ \(eds?\)(?= *$| *;)/", "", $fieldLabelPlusDataArray[1]); // remove " (ed)" and/or " (eds)"
  371. elseif (preg_match("/TI: Title|AB: Abstract/", $fieldLabelPlusDataArray[0]))
  372. {
  373. if (preg_match("/TI: Title/", $fieldLabelPlusDataArray[0]))
  374. {
  375. $fieldLabelPlusDataArray[1] = preg_replace("/--/", "-", $fieldLabelPlusDataArray[1]); // remove en-dash markup
  376. $fieldLabelPlusDataArray[1] = preg_replace("/ *\. *$/", "", $fieldLabelPlusDataArray[1]); // remove any dot from end of title
  377. }
  378. if (preg_match("/ su(b|per)\(.+?\)/", $fieldLabelPlusDataArray[1]))
  379. $fieldLabelPlusDataArray[1] = preg_replace("/ (su(?:b|per))\((.+?)\)/", "[\\1:\\2]", $fieldLabelPlusDataArray[1]); // transform " sub(...)" & " super(...)" markup into "[sub:...]" & "[super:...]" markup
  380. if (preg_match("/(?<= )mu /", $fieldLabelPlusDataArray[1]))
  381. $fieldLabelPlusDataArray[1] = preg_replace("/(?<= )mu /", "", $fieldLabelPlusDataArray[1]); // transform "mu " markup into "�" markup
  382. }
  383. // BUILD FIELD PARAMETERS:
  384. // build an array of key/value pairs:
  385. // "AU: Author":
  386. if (preg_match("/AU: Author/", $fieldLabelPlusDataArray[0]))
  387. $fieldParametersArray['author'] = $fieldLabelPlusDataArray[1];
  388. // "TI: Title":
  389. elseif (preg_match("/TI: Title/", $fieldLabelPlusDataArray[0]))
  390. $fieldParametersArray['title'] = $fieldLabelPlusDataArray[1];
  391. // "PT: Publication Type":
  392. elseif (preg_match("/PT: Publication Type/", $fieldLabelPlusDataArray[0])) // could also check for "DT: Document Type" (but DT was added only recently)
  393. {
  394. if (preg_match("/[;:,.]/", $fieldLabelPlusDataArray[1])) // if the "PT: Publication Type" field contains a delimiter (e.g. like: "Journal Article; Conference")
  395. {
  396. $correctDocumentType = preg_replace("/(.+?)\s*[;:,.]\s*.*/", "\\1", $fieldLabelPlusDataArray[1]); // extract everything before this delimiter
  397. $additionalDocumentTypeInfo = preg_replace("/.*?\s*[;:,.]\s*(.+)/", "\\1", $fieldLabelPlusDataArray[1]); // extract everything after this delimiter
  398. $additionalDocumentTypeInfo = $additionalDocumentTypeInfo; // this info will be appended to any notes field data (see below)
  399. }
  400. else // we take the "PT: Publication Type" field contents as they are
  401. $correctDocumentType = $fieldLabelPlusDataArray[1];
  402. // Note that for books the "PT: Publication Type" field will always start with "Book Monograph", no matter whether the referenced
  403. // publication is a whole book or just a book chapter within that book! This is a design flaw within the CSA full record format.
  404. // So we can only apply some "good guessing" whether the current record actually references a complete book or just a book chapter:
  405. if (preg_match("/^(PT: Publication Type\s+Book Monograph|DT: Document Type\s+B)/m", $singleRecord)) // if the current record is of type "Book Monograph"
  406. {
  407. // and if the source field contains some page specification like "213 pp." (AND NOT something like "pp. 76-82" or "p. 216")...
  408. if (preg_match("/[\d,]+ *pp\b/i", $sourceField) AND !preg_match("/(?<=\W)pp?[. ]+[\w\/,-]+/i", $sourceField))
  409. $correctDocumentType = "Book Whole"; // ...we assume its a whole book
  410. else
  411. $correctDocumentType = "Book Chapter"; // ...otherwise we assume its a book chapter (which may NOT always be correct!)
  412. }
  413. $fieldParametersArray['type'] = $correctDocumentType;
  414. }
  415. // "PY: Publication Year":
  416. elseif (preg_match("/PY: Publication Year/", $fieldLabelPlusDataArray[0]))
  417. $fieldParametersArray['year'] = $fieldLabelPlusDataArray[1];
  418. // "JN: Journal Name":
  419. elseif (preg_match("/JN: Journal Name/", $fieldLabelPlusDataArray[0]))
  420. {
  421. // if the current record is of type "Book Monograph" AND the field "JN: Journal Name" was given within the *original* record data (i.e., before adding stuff to it):
  422. if (preg_match("/^(PT: Publication Type\s+Book Monograph|DT: Document Type\s+B)/m", $singleRecord) AND preg_match("/^JN: Journal Name *[\r\n]+ {4,4}/m", $singleRecord))
  423. // for book monographs the publication title is given in "MT: Monograph Title"; if a "JN: Journal Name" was originally provided as well, we assume, it's the series title:
  424. $fieldParametersArray['series_title'] = $fieldLabelPlusDataArray[1];
  425. else
  426. $fieldParametersArray['publication'] = $fieldLabelPlusDataArray[1];
  427. }
  428. // "JA: Abbrev Journal Name":
  429. elseif (preg_match("/JA: Abbrev Journal Name/", $fieldLabelPlusDataArray[0]))
  430. {
  431. if (preg_match("/^(PT: Publication Type\s+Book Monograph|DT: Document Type\s+B)/m", $singleRecord)) // if the current record is of type "Book Monograph"
  432. // for book monographs the publication title is given in "MT: Monograph Title"; if a "JA: Abbrev Journal Name" is provided as well, we assume, it's the abbreviated series title:
  433. $fieldParametersArray['abbrev_series_title'] = $fieldLabelPlusDataArray[1];
  434. else
  435. $fieldParametersArray['abbrev_journal'] = $fieldLabelPlusDataArray[1];
  436. }
  437. // "MT: Monograph Title":
  438. elseif (preg_match("/MT: Monograph Title/", $fieldLabelPlusDataArray[0]))
  439. {
  440. // if the source field contains some page specification like "213 pp." (AND NOT something like "pp. 76-82" or "p. 216")...
  441. if (preg_match("/[\d,]+ *pp\b/i", $sourceField) AND !preg_match("/(?<=\W)pp?[. ]+[\w\/,-]+/i", $sourceField))
  442. // ...we assume its a whole book (see above comment), in which case we assign the monograph title to the series title field:
  443. $fieldParametersArray['series_title'] = $fieldLabelPlusDataArray[1];
  444. else
  445. $fieldParametersArray['publication'] = $fieldLabelPlusDataArray[1];
  446. }
  447. // "JV: Journal Volume":
  448. elseif (preg_match("/JV: Journal Volume/", $fieldLabelPlusDataArray[0]))
  449. {
  450. if (preg_match("/^(PT: Publication Type\s+Book Monograph|DT: Document Type\s+B)/m", $singleRecord)) // if the current record is of type "Book Monograph"
  451. // for book monographs, if there's a volume given, we assume, it's the series volume:
  452. $fieldParametersArray['series_volume'] = $fieldLabelPlusDataArray[1];
  453. else
  454. $fieldParametersArray['volume'] = $fieldLabelPlusDataArray[1];
  455. }
  456. // "JI: Journal Issue":
  457. elseif (preg_match("/JI: Journal Issue/", $fieldLabelPlusDataArray[0]))
  458. {
  459. if (preg_match("/^(PT: Publication Type\s+Book Monograph|DT: Document Type\s+B)/m", $singleRecord)) // if the current record is of type "Book Monograph"
  460. // for book monographs, if there's an issue given, we assume, it's the series issue:
  461. $fieldParametersArray['series_issue'] = $fieldLabelPlusDataArray[1];
  462. else
  463. $fieldParametersArray['issue'] = $fieldLabelPlusDataArray[1];
  464. }
  465. // "JP: Journal Pages":
  466. elseif (preg_match("/JP: Journal Pages/", $fieldLabelPlusDataArray[0]))
  467. $fieldParametersArray['pages'] = $fieldLabelPlusDataArray[1];
  468. // "AF: Affiliation" & "AF: Author Affilition":
  469. elseif (preg_match("/AF: (Author )?Affilia?tion/", $fieldLabelPlusDataArray[0]))
  470. $fieldParametersArray['address'] = $fieldLabelPlusDataArray[1];
  471. // "CA: Corporate Author":
  472. elseif (preg_match("/CA: Corporate Author/", $fieldLabelPlusDataArray[0]))
  473. $fieldParametersArray['corporate_author'] = $fieldLabelPlusDataArray[1];
  474. // "DE: Descriptors":
  475. elseif (preg_match("/DE: Descriptors/", $fieldLabelPlusDataArray[0])) // currently, the fields "KW: Keywords" and "ID: Identifiers" are ignored!
  476. $fieldParametersArray['keywords'] = $fieldLabelPlusDataArray[1];
  477. // "AB: Abstract":
  478. elseif (preg_match("/AB: Abstract/", $fieldLabelPlusDataArray[0]))
  479. $fieldParametersArray['abstract'] = $fieldLabelPlusDataArray[1];
  480. // "PB: Publisher":
  481. elseif (preg_match("/PB: Publisher/", $fieldLabelPlusDataArray[0]))
  482. $fieldParametersArray['publisher'] = $fieldLabelPlusDataArray[1];
  483. // "ED: Editor":
  484. elseif (preg_match("/ED: Editor/", $fieldLabelPlusDataArray[0]))
  485. $fieldParametersArray['editor'] = $fieldLabelPlusDataArray[1];
  486. // "LA: Language":
  487. elseif (preg_match("/LA: Language/", $fieldLabelPlusDataArray[0]))
  488. $fieldParametersArray['language'] = $fieldLabelPlusDataArray[1];
  489. // "SL: Summary Language":
  490. elseif (preg_match("/SL: Summary Language/", $fieldLabelPlusDataArray[0]))
  491. $fieldParametersArray['summary_language'] = $fieldLabelPlusDataArray[1];
  492. // "OT: Original Title":
  493. elseif (preg_match("/OT: Original Title/", $fieldLabelPlusDataArray[0]))
  494. $fieldParametersArray['orig_title'] = $fieldLabelPlusDataArray[1];
  495. // "IS: ISSN":
  496. elseif (preg_match("/IS: ISSN/", $fieldLabelPlusDataArray[0]))
  497. $fieldParametersArray['issn'] = $fieldLabelPlusDataArray[1];
  498. // "IB: ISBN":
  499. elseif (preg_match("/IB: ISBN/", $fieldLabelPlusDataArray[0]))
  500. $fieldParametersArray['isbn'] = $fieldLabelPlusDataArray[1];
  501. // "ER: Environmental Regime":
  502. elseif (preg_match("/ER: Environmental Regime/", $fieldLabelPlusDataArray[0]))
  503. $environmentalRegime = $fieldLabelPlusDataArray[1]; // this info will be appended to any notes field data (see below)
  504. // "CF: Conference":
  505. elseif (preg_match("/CF: Conference/", $fieldLabelPlusDataArray[0]))
  506. $fieldParametersArray['conference'] = $fieldLabelPlusDataArray[1];
  507. // "NT: Notes":
  508. elseif (preg_match("/NT: Notes/", $fieldLabelPlusDataArray[0]))
  509. $fieldParametersArray['notes'] = $fieldLabelPlusDataArray[1];
  510. // "DO: DOI":
  511. elseif (preg_match("/DO: DOI/", $fieldLabelPlusDataArray[0]))
  512. $fieldParametersArray['doi'] = $fieldLabelPlusDataArray[1];
  513. }
  514. // (END LOOP OVER EACH FIELD)
  515. if (!empty($showSource)) // if we're supposed to display the original source data
  516. // append original source field data (they will be presented within the header message of 'record.php' for easy comparison with the extracted data):
  517. $fieldParametersArray['source'] = $sourceField;
  518. // we'll hack the "notes" element in order to append additional info:
  519. // (this cannot be done earlier above since we don't know about the presence & order of fields within the source text!)
  520. if (!empty($additionalDocumentTypeInfo)) // if the "PT: Publication Type" field contains some additional info
  521. {
  522. if (isset($fieldParametersArray['notes'])) // and if the notes element is present
  523. $fieldParametersArray['notes'] = $fieldParametersArray['notes'] . "; " . $additionalDocumentTypeInfo; // append additional info from "PT: Publication Type" field
  524. else // the notes parameter wasn't specified yet
  525. $fieldParametersArray['notes'] = $additionalDocumentTypeInfo; // add notes element with additional info from "PT: Publication Type" field
  526. }
  527. if (!empty($environmentalRegime)) // if the "ER: Environmental Regime" field contains some data
  528. {
  529. if (isset($fieldParametersArray['notes'])) // and if the notes element is present
  530. $fieldParametersArray['notes'] = $fieldParametersArray['notes'] . "; " . $environmentalRegime; // append "ER: Environmental Regime" field data
  531. else // the notes parameter wasn't specified yet
  532. $fieldParametersArray['notes'] = $environmentalRegime; // add notes element with "ER: Environmental Regime" field data
  533. }
  534. // Append the array of extracted field data to the main data array which holds all records to import:
  535. $parsedRecordsArray[] = $fieldParametersArray;
  536. }
  537. }
  538. // (END LOOP OVER EACH RECORD)
  539. // --------------------------------------------------------------------
  540. // IMPORT RECORDS:
  541. if (count($importRecordNumbersRecognizedFormatArray) == 1) // if this is the only record we'll need to import:
  542. {
  543. // we can use '$fieldParametersArray' directly here, since it still holds the data of the *one* record that we're supposed to import
  544. foreach ($fieldParametersArray as $fieldParameterKey => $fieldParameterValue)
  545. $fieldParametersArray[$fieldParameterKey] = $fieldParameterKey . "=" . rawurlencode($fieldParameterValue); // copy parameter name and equals sign in front of parameter value
  546. $fieldParameters = implode("&", $fieldParametersArray); // merge list of parameters
  547. // RELOCATE TO IMPORT PAGE:
  548. // call 'record.php' and load the form fields with the data of the current record
  549. header("Location: record.php?recordAction=add&mode=import&importSource=csa&" . $fieldParameters);
  550. exit; // >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> !EXIT! <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
  551. }
  552. else // import record(s) directly:
  553. {
  554. // Build an array structure suitable for passing to the 'addRecords()' function:
  555. $importDataArray = array(); // for an explanation of the structure of '$importDataArray', see the comments above the 'addRecords()' function (in 'include.inc.php')
  556. $importDataArray['type'] = "refbase"; // we use the "refbase" array format
  557. $importDataArray['version'] = "1.0"; // we use version "1.0" of the array structure
  558. $importDataArray['creator'] = "http://refbase.net"; // calling script/importer is "refbase"
  559. $importDataArray['author'] = "Matthias Steffens"; // author/contact name of the person who's responsible for this script/importer
  560. $importDataArray['contact'] = "refbase@extracts.de"; // author's email/contact address
  561. $importDataArray['options'] = array('prefix_call_number' => "true"); // if "true", any 'call_number' string will be prefixed with the correct call number prefix of the currently logged-in user (e.g. 'IP� @ msteffens @ ')
  562. $importDataArray['records'] = $parsedRecordsArray; // this array will hold the record(s) (with each record being a sub-array of fields)
  563. // NOTES: - due to the nature of the CSA format, this importer doesn't provide input for the following fields:
  564. // 'place', 'series_editor', 'edition', 'medium', 'area', 'expedition', 'call_number', 'approved', 'file', 'thesis', 'url', 'contribution_id', 'online_publication', 'online_citation', 'orig_record'
  565. // - the 'addRecords()' function will take care of the calculation fields ('first_author', 'author_count', 'first_page', 'volume_numeric' and 'series_volume_numeric')
  566. // - similarly, the *date/*time/*by fields ('created_date', 'created_time', 'created_by', 'modified_date', 'modified_time', 'modified_by') will be filled automatically
  567. // if no custom values (in correct date ['YYYY-MM-DD'] and time ['HH:MM:SS'] format) are given in the '$importDataArray'
  568. // - we could pass any custom info for the 'location' field with the '$importDataArray', omitting it here
  569. // causes the 'addRecords()' function to insert name & email address of the currently logged-in user (e.g. 'Matthias Steffens (refbase@extracts.de)')
  570. // - the serial number(s) will be assigned automatically (and returned by the 'addRecords()' function in form of an array)
  571. // - we don't add anything to the 'user_data' table since the import data don't contain any user-specific data
  572. // Add all records to the database (i.e., for each record, add a row entry to MySQL table 'refs'):
  573. // ('$importedRecordsArray' will hold the serial numbers of all newly imported records)
  574. $importedRecordsArray = addRecords($importDataArray); // function 'addRecords()' is defined in 'include.inc.php'
  575. }
  576. // --------------------------------------------------------------------
  577. // (4) DISPLAY RESULTS
  578. if (!empty($importedRecordsArray)) // if some records were successfully imported
  579. {
  580. $recordSerialsQueryString = implode(",", $importedRecordsArray);
  581. $importedRecordsCount = count($importedRecordsArray);
  582. // Send EMAIL announcement:
  583. if ($sendEmailAnnouncements == "yes")
  584. {
  585. // variables '$sendEmailAnnouncements', '$mailingListEmail', '$officialDatabaseName' and '$databaseBaseURL' are specified in 'ini.inc.php';
  586. // '$loginFirstName' and '$loginLastName' are provided as session variables by the 'start_session()' function in 'include.inc.php'
  587. // send a notification email to the mailing list email address given in '$mailingListEmail':
  588. $emailRecipient = "Literature Database Announcement List <" . $mailingListEmail . ">";
  589. if ($importedRecordsCount == 1)
  590. {
  591. $emailSubject = "New record added to the " . $officialDatabaseName;
  592. $emailBodyIntro = "One record has been added to the " . $officialDatabaseName . ":";
  593. $detailsURL = $databaseBaseURL . "show.php?record=" . $importedRecordsArray[0];
  594. }
  595. else // $importedRecordsCount > 1
  596. {
  597. $emailSubject = "New records added to the " . $officialDatabaseName;
  598. $emailBodyIntro = $importedRecordsCount . " records have been added to the " . $officialDatabaseName . ":";
  599. $detailsURL = $databaseBaseURL . "show.php?records=" . $recordSerialsQueryString;
  600. }
  601. $emailBody = $emailBodyIntro
  602. . "\n\n added by: " . $loginFirstName . " " . $loginLastName
  603. . "\n details: " . $detailsURL
  604. . "\n";
  605. sendEmail($emailRecipient, $emailSubject, $emailBody); // function 'sendEmail()' is defined in 'include.inc.php'
  606. }
  607. if ($importedRecordsCount == 1)
  608. $headerMessage = $importedRecordsCount . " " . $loc["RecordSuccessfullyImported"] . ":";
  609. else // $importedRecordsCount > 1
  610. $headerMessage = $importedRecordsCount . " " . $loc["RecordsSuccessfullyImported"] . ":";
  611. // DISPLAY all newly added records:
  612. header("Location: show.php?records=" . $recordSerialsQueryString . "&headerMsg=" . rawurlencode($headerMessage));
  613. }
  614. else // nothing imported
  615. {
  616. // we'll file again this additional error element here so that the 'errors' session variable isn't empty causing 'import_csa.php' to re-load the form data that were submitted by the user
  617. $errors["badRecords"] = "all";
  618. // return an appropriate error message:
  619. $HeaderString = returnMsg($loc["NoRecordsImported"] . "!", "warning", "strong", "HeaderString"); // function 'returnMsg()' is defined in 'include.inc.php'
  620. // Write back session variables:
  621. saveSessionVariable("errors", $errors); // function 'saveSessionVariable()' is defined in 'include.inc.php'
  622. saveSessionVariable("formVars", $formVars);
  623. header("Location: " . $referer); // redirect to the calling page (normally, 'import_csa.php')
  624. }
  625. // --------------------------------------------------------------------
  626. ?>