Source for file Save_Specimen.php

Documentation is available at Save_Specimen.php

  1. <?php
  2. /**
  3. * saving specimen data from original specimen data provider
  4. * <br/><br/>
  5. * final script, all subfiles ("Save_xy.php") provide final content in standardised way
  6. * @author Gabriele Droege, DNA Bank Network <contact@dnabank-network.org>
  7. * @version 2.0
  8. * @package Input
  9. * @copyright Copyright © 2011 DNA Bank Network http://www.dnabank-network.org<br>The contents of this file are subject to the Mozilla Public License Version 1.1
  10. * @filesource
  11. * @license http://www.mozilla.org/MPL/ MPL
  12. */
  13. if (isset($_SESSION['guest']) || $_SESSION['guest']) {
  14.  
  15. echo "<tr><td colspan='3'><span class='error'>Sorry, as a guest you don't have permission for entering new DNA data! If you want to search for existing DNA data please use the Search function!</span></td></tr>"; }
  16.  
  17. else {
  18.  
  19.  
  20. if($formProviderIntern) { $IDDataset = $formProviderIntern; }
  21. if($formProviderExtern) { $IDDataset = $formProviderExtern; }
  22.  
  23.     /********************************************************************************************
  24.     * at first, check if specimen data are already in cache tables                              *
  25.     * if so, count jhow many DNA samples are yet connected to this record                       *
  26.     ********************************************************************************************/
  27.  
  28. $test = mysql_query("SELECT ID_Cache FROM cachecollection " .
  29.                     "WHERE UnitID_Specimen = '$sqlUnitID' " .
  30.                     "  AND CollectionCode_Specimen = '$sqlSourceName' " .
  31.                     "  AND InstitutionCode_Specimen = '$sqlSourceInstitutionCode' " .
  32.                     "  AND ID_Dataset_Specimen = '$IDDataset'");
  33.                     
  34. while ($row = mysql_fetch_object($test))
  35. { $ID_Cache = $row->ID_Cache; }
  36.  
  37. $test2 = mysql_query("SELECT ID_TaxonIdentified, NameAuthorYear FROM cachetaxonidentified WHERE ID_Cache = '$ID_Cache'");
  38.  
  39. while ($row = mysql_fetch_object($test2))
  40. { $View = $row->NameAuthorYear; }
  41.  
  42.  
  43. if(mysql_num_rows($test))
  44. {$IDTableCache = $ID_Cache; 
  45.     
  46.  
  47. $Exist = mysql_query("SELECT ID_DNA, DNA_Bank_Number FROM dnabanknumbers " .
  48.                      "WHERE ID_Cache = '$IDTableCache'");
  49.                      
  50. $count = mysql_num_rows($Exist);
  51.  
  52. echo "<span class='fine'>Data have been saved: <br />Specimen Number: </span><span class='error'>".$sqlUnitID."</span><span class='fine'> Institution Code: </span><span class='error'>".$sqlSourceInstitutionCode."</span><span class='fine'> Collection Code: </span><span class='error'>".$sqlSourceName."</span><span class='fine'> Taxon Name: </span><span class='error'>".$View."</span><br />";
  53. if ($count == '1')
  54. { echo "<span class='fine'>".$count." DNA Sample already exist for the selected specimen!</span><br />"; }
  55. if($count > 1)
  56. { echo "<span class='fine'>".$count." DNA Samples already exist for the selected specimen!</span><br />"; }
  57.  
  58.  
  59. }
  60.  
  61. if(!mysql_num_rows($test))
  62. {
  63. if(isset($Identifications))
  64. {
  65.   
  66.     /********************************************************************************************
  67.     * first table to fill is cachecollection                                                    *
  68.     ********************************************************************************************/
  69.  
  70.   $sql4 = "INSERT INTO cachecollection (UnitID_Specimen, CollectionCode_Specimen, InstitutionCode_Specimen, ContinentOrOcean, CountryName, CountryISO2, Collectors, CollectionDate, CollectionDateMin, CollectionDateMax, CollectorsNo, Locality, Longitude, Latitude, Altitude, CollectionInfo_Other, ID_Dataset_Specimen, Created_Who) VALUES ('$sqlUnitID','$sqlSourceName','$sqlSourceInstitutionCode','$sqlContinentOrOcean','$sqlCountryName','$sqlISO2','$sqlPersonName','$sqlCollectionDate','$sqlCollectionDateMin','$sqlCollectionDateMax','$sqlCollectorsNo','$sqlLocality','$sqlLongitude','$sqlLatitude','$sqlAltitude','$sqlGatheringOther','$IDDataset','$log')";
  71.  
  72.  $result4 = mysql_query($sql4);
  73. $IDTableCache=mysql_insert_id();
  74.  
  75. ###############################################Error 4####################################################
  76.  
  77.  
  78. if(!$result4)
  79.      { 
  80.   $msg = $sql4."\n";
  81.   $msg .= "####Error 4####";
  82.   trigger_error($msg, E_USER_ERROR);
  83.   include ("../config/Errorreport.php"); 
  84.   $error = "true"; } 
  85.          
  86. #########################################################################################################    
  87.  
  88.   foreach ($Identifications as $IndexIdentification => $Identification) {
  89.   
  90.     /********************************************************************************************
  91.     * for each identification tag entering one row in cachetaxonidentified                      *
  92.     ********************************************************************************************/
  93.  
  94.  
  95.   $Genus = $sqlGenus[$IndexIdentification];
  96.   $Subgenus = $sqlSubgenus[$IndexIdentification];
  97.   $FirstEpithet = $sqlFirstEpithet[$IndexIdentification];
  98.   $SecondEpithet = $sqlSecondEpithet[$IndexIdentification];
  99.   $Rank = $sqlRank[$IndexIdentification];
  100.   $HybridFlag = $sqlHybridFlag[$IndexIdentification];
  101.   $NameAuthorYear = $sqlNameAuthorYearString[$IndexIdentification];
  102.   $Name_All = $sqlName_All[$IndexIdentification];
  103.   $PreferredFlag = $sqlPreferredIdentificationFlag[$IndexIdentification];
  104.   
  105.   $sql5 = "INSERT INTO cachetaxonidentified (ID_Cache, Genus, Subgenus, FirstEpithet, SecondEpithet, Rank, HybridFlag, NameAuthorYear, Other, PreferredFlag, Created_Who) VALUES ('$IDTableCache','$Genus','$Subgenus','$FirstEpithet','$SecondEpithet','$Rank','$HybridFlag','$NameAuthorYear','$Name_All','$PreferredFlag','$log')";
  106.   $result5 = mysql_query($sql5);
  107.  
  108.   $IDTableCacheTaxonIdentified=mysql_insert_id();
  109.   
  110. #################################################Error 5################################################  
  111.   if(!$result5)
  112.          { $msg = $sql5."\n";
  113.            $msg .= "####Error 5####";
  114.            trigger_error($msg, E_USER_ERROR);
  115.            include ("../config/Errorreport.php"); 
  116.            $error = "true"; } 
  117.          
  118. ########################################################################################################         
  119.  
  120.       foreach ($HigherTaxa as $index => $HigherTaxon) { // more than one HigherTaxon per Identification possible
  121.       
  122.     /********************************************************************************************
  123.     * for each identification tag and higher taxon tag entering one row in cachehighertaxa      *
  124.     ********************************************************************************************/      
  125.        
  126.          $TaxonHigher = $sqlHigherTaxon[$index];
  127.          $RankHigher = $sqlHigherTaxonRank[$index];
  128.  
  129.       $sql6 = "INSERT INTO cachehighertaxa (ID_CacheTaxonIdentified, HigherTaxon, TaxonRank, Created_Who) VALUES ('$IDTableCacheTaxonIdentified','$TaxonHigher','$RankHigher','$log')";
  130.       $result6 = mysql_query($sql6);
  131.  
  132. #################################################Error 6################################################
  133. if(!$result6)
  134.          { $msg = $sql6."\n";
  135.            $msg .= "####Error 6####";
  136.            trigger_error($msg, E_USER_ERROR);
  137.            include ("../config/Errorreport.php"); 
  138.            $error = "true"; } 
  139.          
  140. ########################################################################################################         
  141.   }
  142.  }
  143.  
  144. if(isset($sqlFileURI))
  145. { 
  146. foreach ($sqlFileURI as $MultiMediaObject)
  147.   {
  148.     /*********************************************************************************************
  149.     * for each multimedia tag entering one row in cacheimages                                    *
  150.     *********************************************************************************************/ 
  151.   $sql7 = "INSERT INTO cacheimages (ID_Cache, Images, Created_Who) VALUES ('$IDTableCache','$MultiMediaObject','$log')";
  152.   $result7 = mysql_query($sql7);
  153.   
  154. #######################################Error 7###############################################################
  155.  
  156. if(!$result7)
  157. { $msg = $sql7."\n";
  158.   $msg .= "####Error 7####";
  159.   trigger_error($msg, E_USER_ERROR);
  160.   include ("../config/Errorreport.php");   
  161.   $error = "true"; }
  162.   
  163. #############################################################################################################    
  164. } 
  165. if(empty($sqlFileURI)) {
  166. foreach ($sqlProductURI as $MultiMediaObject)
  167.   {
  168.    
  169.   $sql8= "INSERT INTO cacheimages (ID_Cache, Images, Created_Who) VALUES ('$IDTableCache','$MultiMediaObject','$log')";
  170.   $result8 = mysql_query($sql8);
  171.   
  172. #######################################Error 8###############################################################
  173.  
  174. if(!$result8)
  175. { $msg = $sql8."\n";
  176.   $msg .= "####Error 8####";
  177.   trigger_error($msg, E_USER_ERROR);
  178.   include ("../config/Errorreport.php");   
  179.   $error = "true"; }
  180.   
  181. #############################################################################################################    
  182. } } }
  183.  
  184.  
  185. if($result4)
  186. { 
  187.  
  188. echo "<span class='fine'>Data have been saved: <br />Specimen Number: </span><span class='error'>".$sqlUnitID."</span><span class='fine'> Institution Code: </span><span class='error'>".$sqlSourceInstitutionCode."</span><span class='fine'> Collection Code: </span><span class='error'>".$sqlSourceName."</span><span class='fine'> Taxon Name: </span><span class='error'>".$NameAuthorYear."</span><br />"; }   
  189.   }
  190.   
  191.   else {
  192.  
  193.  $sql7 = "INSERT INTO cachecollection (UnitID_Specimen, CollectionCode_Specimen, InstitutionCode_Specimen, ContinentOrOcean, CountryName, Collectors, CollectionDate, CollectionDateMin, CollectionDateMax, CollectorsNo, Locality, Longitude, Latitude, Altitude, ID_Dataset_Specimen, Created_Who) VALUES ('$sqlUnitID','$sqlSourceName','$sqlSourceInstitutionCode','$sqlContinentOrOcean','$sqlCountryName','$sqlPersonName','$sqlCollectionDate','$sqlCollectionDateMin','$sqlCollectionDateMax','$sqlCollectorsNo','$sqlLocality','$sqlLongitude','$sqlLatitude','$sqlAltitude','$IDDataset','$log')";
  194.  
  195.  $result7 = mysql_query($sql7);
  196. $IDTableCache=mysql_insert_id();
  197.  
  198. #######################################Error 7###############################################################
  199.  
  200. if(!$result7)
  201. { $msg = $sql7."\n";
  202.   $msg .= "####Error 7####";
  203.   trigger_error($msg, E_USER_ERROR);
  204.   include ("../config/Errorreport.php");   
  205.   $error = "true"; }
  206.   
  207. ############################################################################################################# 
  208.  
  209. if($result7)
  210. { 
  211.  
  212. echo "<span class='fine'>Data have been saved: <br />Specimen Number: </span><span class='error'>".$sqlUnitID."</span><span class='fine'> Institution Code: </span><span class='error'>".$sqlSourceInstitutionCode."</span><span class='fine'> Collection Code: </span><span class='error'>".$sqlSourceName."</span><span class='fine'> Taxon Name: </span><span class='error'>".$sqlNameAuthorYearString."</span><br />";  }
  213.  
  214.  $sql8 = "INSERT INTO cachetaxonidentified (ID_Cache, Genus, Subgenus, FirstEpithet, SecondEpithet, Rank, NameAuthorYear, Created_Who) VALUES ('$IDTableCache','$sqlGenus','$sqlSubgenus','$sqlFirstEpithet','$sqlSecondEpithet','$sqlRank','$sqlNameAuthorYearString','$log')";
  215.  $result8 = mysql_query($sql8);
  216.  
  217. ######################################################Error 8###########################################
  218. if(!$result8)
  219.          { $msg = $sql8."\n";
  220.            $msg .= "####Error 8####";
  221.            trigger_error($msg, E_USER_ERROR);
  222.            include ("../config/Errorreport.php"); 
  223.            $error = "true"; } 
  224.          
  225. ########################################################################################################         
  226.  
  227.   $IDTableCacheTaxonIdentified=mysql_insert_id();
  228.  
  229.  
  230.  foreach ($sqlHigherTaxon as $index => $HigherTaxa) { // more than one HigherTaxon per Identification possible 
  231.  
  232.  if(!empty($sqlHigherTaxon[$index])) {
  233.          $TaxonHigher = $sqlHigherTaxon[$index];
  234.          $RankHigher = $sqlHigherTaxonRank[$index];
  235.  
  236.     $sql9 = "INSERT INTO cachehighertaxa (ID_CacheTaxonIdentified, HigherTaxon, TaxonRank, Created_Who) VALUES ('$IDTableCacheTaxonIdentified','$TaxonHigher','$RankHigher','$log')";
  237.     $result9 = mysql_query($sql9);
  238.  
  239. ########################################################Error 9###########################################
  240. if(!$result9)
  241.          { $msg = $sql9."\n";
  242.            $msg .= "####Error 9####";
  243.            trigger_error($msg, E_USER_ERROR);
  244.            include ("../config/Errorreport.php"); 
  245.            $error = "true"; } 
  246. ##########################################################################################################           
  247.   } }
  248. if(isset($sqlFileURI))
  249. {
  250. foreach ($sqlFileURI as $MultiMediaObject)
  251.   {
  252.    
  253.   $sql10 = "INSERT INTO cacheimages (ID_Cache, Images, Created_Who) VALUES ('$IDTableCache','$MultiMediaObject','$log')";
  254.   $result10 = mysql_query($sql10);
  255.   
  256. #######################################Error 10###############################################################
  257.  
  258. if(!$result10)
  259. { $msg = $sql10."\n";
  260.   $msg .= "####Error 10####";
  261.   trigger_error($msg, E_USER_ERROR);
  262.   include ("../config/Errorreport.php");   
  263.   $error = "true"; }
  264.   
  265. #############################################################################################################    
  266. } 
  267. if(empty($sqlFileURI))
  268. {
  269. foreach ($sqlProductURI as $MultiMediaObject)
  270.   {
  271.    
  272.   $sql11= "INSERT INTO cacheimages (ID_Cache, Images, Created_Who) VALUES ('$IDTableCache','$MultiMediaObject','$log')";
  273.   $result11 = mysql_query($sql11);
  274.   
  275. #######################################Error 11###############################################################
  276.  
  277. if(!$result11)
  278. { $msg = $sql11."\n";
  279.   $msg .= "####Error 11####";
  280.   trigger_error($msg, E_USER_ERROR);
  281.   include ("../config/Errorreport.php");   
  282.   $error = "true"; }
  283.   
  284. #############################################################################################################    
  285. }   } }
  286. }
  287. }
  288. }
  289.  
  290. ?>

Documentation generated on Tue, 29 Nov 2011 10:45:11 +0100 by phpDocumentor 1.4.3