Source for file new_dataset.php

Documentation is available at new_dataset.php

  1. <?php
  2. /**
  3. * Input new Specimen Data Provider
  4. * <br/><br/>
  5. * Access to all user except of guests
  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.  
  14.     /**
  15.     * calling connection to database
  16.     */
  17.     include ("../config/head.php");
  18.  
  19.     /**
  20.     * calling authorisation script
  21.     */
  22.     include ("../auth.php");
  23. ?>
  24. <html>
  25.  
  26. <head>
  27. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  28. <title>DNA Module - Add new Specimen Data Provider</title>
  29. <link rel="stylesheet" type="text/css" href="../format.css">
  30. <link rel="stylesheet" type="text/css" href="XSLT/Styles.css">
  31. <SCRIPT LANGUAGE="JavaScript1.1" src="../Functions.js"></SCRIPT>
  32. <NOSCRIPT>Please enable Javascript!</NOSCRIPT>
  33.  
  34. </head>
  35. <body>
  36. <div align="center">
  37. <?php 
  38.   /**
  39.   * including navigation menu
  40.   */include("../tablenavi.php"); ?>
  41. <form name="formular" method="POST" action="new_dataset.php"> 
  42. <table id="tablemain" class="main">
  43.     <tr>
  44.   <td id="tdLogo"><a href="<?php echo $Path_Wiki."/Input_DNA_Data#Add_new_specimen_provider"; ?>" target="_blank"><img border="0" src="../images/Logo-Wiki.png" height="78"></a></td>
  45.         <td id="tdtitle">
  46.         <h1>Add new Specimen Data Provider</h1></td>
  47.     <td id="tdLogo2"><?php echo $Path_Logo; ?></td>
  48.     </tr>
  49.   <tr>
  50.   <td colspan="3"><?php
  51.  
  52.     echo "Logged in as: ";
  53.     $log = $_SESSION["log"];
  54.     echo $log;
  55.     ?></td></tr>
  56. <tr>
  57. <td valign="top" colspan="4">
  58. <table id="table2">
  59. <tr><td align="center">
  60. <?php 
  61. if (isset($_SESSION['guest']) || $_SESSION['guest']) {
  62.     /********************************************************************************************
  63.     * Guests don't have permission for entering new DNA data                                    *
  64.     *********************************************************************************************/
  65. echo "<tr><td colspan='3'><span class='error'>Sorry, as a guest you don't have permission for entering new data! If you want to search for existing DNA data please use the Search function!</span></td></tr>"; }
  66.  
  67. else {
  68.  
  69.  
  70.  
  71. if ($formVerifyProvider or $formCheckurl or $formSubmitSave or $formSubmitEditView or $formSubmitEditDataset or $formSubmitSaveNewDataset)
  72. {}
  73. else {echo "<a class='fine'>Please enter the new wrapper url.</a>"; } ?>
  74. </td></tr>
  75. <tr><td align="center">Wrapper Url <input type="text" name="formNewProvider" id="InputLong2" value="<?php if($formVerifyProvider)
  76. { echo $formNewProvider; } if ($formCheckurl) { echo $formNewProviderUrl; }?>"></td></tr>
  77. <tr><td align="center"><input type="submit" name="formVerifyProvider" id="button" value="Verify" onclick="return CheckProvider();"></td></tr>
  78. <tr><td align="left">
  79. <?php
  80. if($formVerifyProvider or $formCheckurl)
  81. {
  82.     /********************************************************************************************
  83.     * check if Wrapper url already exists in database                                           *
  84.     *********************************************************************************************/
  85. $result = mysql_query
  86. ("SELECT dataset.ID_Dataset, " .
  87.  "       dataset.Display, " .
  88.  "       dataset.Internal_External, " .
  89.  "       provider.Provider, " .
  90.  "       provider.ID_Schema " .
  91.  "  FROM dataset " .
  92.  "  LEFT JOIN provider ON dataset.ID_Provider = provider.ID_Provider " .
  93.  "  LEFT JOIN schemata ON provider.ID_Schema = schemata.ID_Schema " .
  94.  "  WHERE provider.Provider = '$formNewProvider'");
  95.  
  96.  
  97. $count = mysql_num_rows($result);
  98. if ($count == 0) 
  99. {
  100. if ($formCheckurl) {
  101.     /********************************************************************************************
  102.     * check Provider availability                                                               *
  103.     *********************************************************************************************/
  104. $inf = parse_url($formNewProviderUrl);
  105. $host = $inf['host'];
  106. $path = $inf['path'];
  107.  if (isset($inf['query'])) $path .= '?'.$inf['query'];
  108.  if (isset($inf['port'])) $port = $inf['port'];
  109.  else $port = 80;
  110.  
  111. if($formNewProviderUrl)
  112. {
  113. error_reporting(E_ALL ^ E_WARNING ^ E_NOTICE);
  114. $fp = fsockopen($host, $port, $errno, $error, 5);
  115. if(!$fp or !$host) { echo "<span class='error'>Connection to provider failed! Please check your entry or try again later.</span>";  }
  116. if($fp and $host) {
  117. if(!fopen($formNewProviderUrl,"r")) { echo "<span class='error'>Provider url incorrect. Please check your entry.</span>"; }
  118. if(fopen($formNewProviderUrl,"r")) {
  119.  
  120.   echo "<span class='fine'>Connection to provider successful!</span>"; } }
  121.  }
  122. }
  123. else {echo "<span class='fine'>Provider has not been found in the DNA Module! Please enter following parameters to add a new dataset. Please read the manual for further instructions!</span>"; }
  124.  
  125. echo "<table width='100%'>";
  126. echo "<tr><td id='change'>Provider url:</td><td><input type='text' name='formNewProviderUrl' id='InputLong' value='";
  127. if($formCheckurl)
  128. {echo $formNewProviderUrl; }
  129. else { echo $formNewProvider; }
  130. echo "'></td><td><input type='submit' name='formCheckurl' value='Check provider availability'></td></tr>";
  131. echo "<tr><td id='change'>Schema:</td><td colspan='2'>";
  132. build_select_list("formSchema",
  133.                       "SELECT ID_Schema, Schemata FROM schemata " .
  134.                       "ORDER BY Schemata", "");
  135. echo "</td></tr>";
  136. echo "<tr><td id='change'>Digir Resource:</td><td colspan='2'><input type='text' name='formDigirResource' id='InputLong'>Required for DiGIR providers!</td></tr>";
  137. echo "<tr><td id='change'>Digir Source:</td><td colspan='2'><input type='text' name='formDigirSource' id='InputLong'>Required for DiGIR providers!</td></tr>";
  138. echo "<tr><td id='change'>Display:</td><td colspan='2'><input type='text' name='formNewView' id='InputLong'></td></tr>";
  139. echo "<tr><td id='change'>Internal/External:</td><td colspan='2'><select id='SelectLong' name='formStatus'><option value = ''>Please select</option><option value = '1'>Internal</option><option value = '2'>External</option></select></td></tr>";
  140. echo "<tr><td colspan='3'><input type='submit' name='formSubmitSave' value='Save new dataset' id='button' ";
  141. if($formVerifyProvider or $formCheckurl) { echo "onclick='return CheckNewDataset();'"; } else {}
  142. echo "></td></tr>";
  143. echo "</table>";
  144. }
  145.  
  146.                  
  147. else {     
  148.  
  149. echo "<span class='error'>Provider Url exists already! ".$count." records have been found: </span>";
  150.  
  151. echo "<table width='100%'><th align='left'>Dataset</th><th align='left'>Internal/External</th>";
  152. $gesamt = mysql_num_rows($result); 
  153. for ($i=1; $i<=$gesamt; $i++) {
  154. $row=mysql_fetch_array($result);
  155. if($row['Internal_External'] == '1')
  156. { $Status = "Internal"; }
  157. if($row['Internal_External'] == '2')
  158. { $Status = "External"; } 
  159. $Schema = $row['ID_Schema'];
  160. $Provider = $row['Provider'];
  161.  
  162. if($Schema == '3')
  163. { echo "<tr><td>".$row['Display']."</td><td>".$Status."</td></tr>"; }
  164. else
  165. {
  166. echo "<tr><td><input type='checkbox' name='x[".$i."]' value='".$i."'><input type='hidden' name='formView[".$i."]' value='".$row['ID_Dataset']."'>".$row['Display']."</td><td>".$Status."</td></tr>"; }
  167. } 
  168.  
  169.  
  170. echo "</table>"; 
  171. if($Schema == '3')
  172. {
  173. echo "<table width='100%'><tr><td colspan='4'><hr /></td></tr>";
  174. echo "<tr><td colspan='4'><span class='error'>Provider is using DarwinCore/DiGIR. Please check if source already exists in database. If not fill out the following parameters. Please read the manual for further instructions!</span></td></tr>"; 
  175. echo "<tr><td colspan='4'><hr /></td></tr>";
  176. echo "<tr><td id='Change' colspan='4'>Add new Dataset for this Provider: <a class='red'> ".$Provider."</a></td></tr>";
  177. echo "<tr><th align='left'>Name (e.g. BGBM, Lichens)</th><th align='left'>Internal/External</th><th align='left'>Resource</th><th align='left'>Source</th></tr>"; 
  178. echo "<tr><td><input type='text' name='formNewView' id='InputLong2'></td><td><select id='InputLong2' name='formStatus'><option value = ''>Please select</option><option value = '1'>Internal</option><option value = '2'>External</option></select></td><td><input type='text' name='formDigirResource'></td><td><input type='text' name='formDigirSource'></td></tr>";
  179. echo "<tr><td colspan='4'><input type='submit' id='button' name='formSubmitSaveNewDataset' value='Save New Dataset' onClick='return CheckNewDataset3();'></td></tr>";
  180. echo "</table>"; }
  181.  
  182. else {
  183. echo "<table width='100%'><tr><td colspan='2'><hr /></td></tr>";
  184. echo "<tr><td colspan='2'><input type='submit' name='formSubmitEditView' value ='Edit selected datasets'></td></tr>";
  185. echo "<tr><td colspan='2'><span class='error'>Please check if an existing dataset should be renamed or if it is required to add a new one. For renaming please select the dataset and hit 'Edit'. Please read the manual for further instructions!</span></td></tr>";
  186. echo "<tr><td colspan='2'><hr /></td></tr>";
  187. echo "<tr><td id='Change' colspan='2'>Add new Dataset for this Provider: <a class='red'> ".$Provider."</a></td></tr>";
  188. echo "<tr><th align='left'>Name (e.g.BGBM, Lichens)</th><th align='left'>Internal/External</th></tr>"; 
  189. echo "<tr><td><input type='text' name='formNewView' id='InputLong2'></td><td><select id='InputLong2' name='formStatus'><option value = ''>Please select</option><option value = '1'>Internal</option><option value = '2'>External</option></select></td></tr>";
  190. echo "<tr><td colspan='2'><input type='submit' name='formSubmitSaveNewDataset' value='Save new dataset' id='button' onclick='return CheckNewDataset2();'></td></tr>";
  191. echo "</table>"; }
  192. }
  193.  
  194. }
  195.  
  196. if ($formSubmitSave)
  197. {
  198.  
  199. $result = "INSERT INTO provider (Provider, ID_Schema, Created_Who)" .
  200.                           "VALUES ('$formNewProviderUrl','$formSchema','$log')";
  201. $sql1 = mysql_query($result);
  202.  
  203. $IDProvider=mysql_insert_id();
  204.  
  205. $result2 = "INSERT INTO dataset (ID_Provider, Digir_Resource, Digir_Source, Display, Internal_External, Created_Who)" .
  206.                           "VALUES ('$IDProvider','$formDigirResource','$formDigirSource','$formNewView','$formStatus','$log')";        
  207. $sql2 = mysql_query($result2);        
  208.  
  209.  
  210. #######################################Error 1/2###############################################################
  211.  
  212. if(!$sql1 or !$sql2)
  213. { $msg = $result1."\n";
  214.   $msg .= $result2."\n";
  215.   $msg .= "####Error 1/2####";
  216.   trigger_error($msg, E_USER_ERROR);
  217.   include ("../config/Errorreport.php");   }
  218.   
  219. #############################################################################################################
  220. else {echo "<span class='fine'>New provider/dataset has been saved!</span>"; }
  221. }
  222.  
  223. if($formSubmitEditView)
  224. {
  225.  
  226.  if($_POST['x']=="")
  227.   { unset($x); }
  228.   
  229.   else 
  230.     {
  231.        echo "<table width='100%'><th align='left'>Dataset</th><th align='left'>Internal/External</th>";      
  232.     foreach ($_POST['x'] as $index)
  233.       {
  234.       $View = $_POST['formView'][$index];
  235.       
  236.       $result = mysql_query("SELECT dataset.ID_Dataset, " .
  237.                             "dataset.Display, " . 
  238.                             "provider.ID_Schema " .
  239.                             "FROM dataset " .
  240.                             "LEFT JOIN provider ON dataset.ID_Provider = provider.ID_Provider " .
  241.                             "WHERE dataset.ID_Dataset = '$View'");
  242.  
  243.  
  244.       while($row = mysql_fetch_object($result))
  245.         {
  246.         echo "<tr><td><input type='text' name='formView[".$index."]' value='".$row->Display."' id='InputLong2'><input type='hidden' name='formViewhidden[".$index."]' value='".$View."' id='InputLong2'>"."</td><td><select id='InputLong2' name='formStatus[".$index."]'><option value = ''>Please select</option><option value = '1'";
  247.       if ($row->ID_Schema == 1) { echo "selected"; } else {} 
  248.       echo ">Internal</option><option value = '2'";
  249.       if ($row->ID_Schema == 2) { echo "selected"; } else {} 
  250.       echo ">Extern</option></select></td></tr>";
  251.  
  252.        } // while
  253.     
  254.       } //foreach ['x']
  255.  
  256.     echo "<tr><td colspan='2'><input type='submit' name ='formSubmitEditDataset' value='Save Edits' id='button'></td></tr></table>";
  257.     } //else
  258.     } //if ($formSubmitEditView)
  259.  
  260.  
  261. if ($formSubmitEditDataset)
  262. {
  263. foreach ($_POST['formView'] as $index => $value)
  264. {
  265.     $UpdateView = $formViewhidden[$index];
  266.     $UpdateStatus = $formStatus[$index];
  267.     
  268.     $result = "UPDATE dataset SET Display = '$value', Internal_External = '$UpdateStatus' WHERE ID_Dataset = '$UpdateView'";
  269.     $sql = mysql_query($result); 
  270. }
  271.  
  272. #######################################Error 3###############################################################
  273.  
  274. if(!$sql)
  275. { $msg = $result."\n";
  276.   $msg .= "####Error 3####";
  277.   trigger_error($msg, E_USER_ERROR);
  278.   /**
  279.   * calling Error message
  280.   */
  281.   include ("Errorreport.php");   }
  282.   
  283. #############################################################################################################
  284.  
  285. else {echo "<span class='fine'>Changes accepted!</span>";}
  286. }    
  287.  
  288. if ($formSubmitSaveNewDataset)
  289. {
  290.   $result = mysql_query("SELECT ID_Provider FROM provider WHERE Provider = '$formNewProvider'");
  291.   
  292.   while ($row = mysql_fetch_object($result))
  293.   {$IDProvider = $row->ID_Provider; }
  294.  
  295.  $result = "INSERT INTO dataset (ID_Provider, Digir_Resource, Digir_Source, Display, Internal_External, Created_Who)" .
  296.                           "VALUES ('$IDProvider','$formDigirResource','$formDigirSource','$formNewView','$formStatus','$log')";
  297.  $sql = mysql_query($result);  
  298.  
  299. #######################################Error 4###############################################################
  300.  
  301. if(!$sql)
  302. { $msg = $result."\n";
  303.   $msg .= "####Error 4####";
  304.   trigger_error($msg, E_USER_ERROR);
  305.   /**
  306.   * calling Error message
  307.   */  
  308.   include ("Errorreport.php");   }
  309.   
  310. #############################################################################################################
  311.  
  312. else { echo "<span class='fine'>New provider/Dataset has been saved!</span>";  }
  313. }
  314.  
  315.  
  316. ?>
  317.  
  318. </td></tr>
  319. <tr><td><input type="submit" id="button" name="formSubmitClose" value="Close Form" style="float:right" onclick="window.close();"></td></tr>
  320. <tr><td>After finishing your entries please close this window and reload (F5) the input or search mask to get the updated list from database.</td></tr>
  321. <?php } ?>
  322. </table>
  323. </td>
  324. </tr>
  325. </table>
  326. <?php
  327.     /**
  328.     * including footer
  329.     */
  330.     include("../footer.php"); ?> 
  331. </form>
  332. </div>
  333. </body>
  334. </html>

Documentation generated on Tue, 29 Nov 2011 10:44:55 +0100 by phpDocumentor 1.4.3