<?php
/**
* Input new purification method
* <br/><br/>
* Access to all user except of guests
* @author Gabriele Droege, DNA Bank Network <contact@dnabank-network.org>
* @version 2.0
* @package Input
* @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
* @filesource
* @license http://www.mozilla.org/MPL/ MPL
*/

    /**
    * calling connection to database
    */
    include ("../config/head.php");

    /**
    * calling authorisation script
    */
    include ("../auth.php");
?>
<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>DNA Module - Add New Purification Method</title>
<link rel="stylesheet" type="text/css" href="../format.css">
<SCRIPT LANGUAGE="JavaScript1.1" src="../Functions.js"></SCRIPT>
<NOSCRIPT>Please enable Javascript!</NOSCRIPT>

</head>
<body>
<div align="center">
<?php 
  /**
  * including navigation menu
  */
include("../tablenavi.php"); ?>
<form name="formular" method="POST" action="new_purification.php"> 
<table id="tablemain" class="main">
<tr>
  <td id="tdLogo"><a href="<?php echo $Path_Wiki."/Input_DNA_Data"; ?>" target="_blank"><img border="0" src="../images/Logo-Wiki.png" height="78"></a></td>
		<td id="tdtitle">
		<h1>Add New Purification Method</h1></td>
    <td id="tdLogo2"><?php echo $Path_Logo; ?></td>
	</tr>
  <tr>
  <td><?php
    echo "Logged in as: ";
    $log = $_SESSION["log"];
    echo $log;

    ?></td>
  </tr>
<tr>
<td valign="top" align="center" valign="middle" colspan="3">
<table id="table" width="70%" border="0" style="margin:30 0 0 0">
<tr>
<td align="center" colspan="2">
<?php
if (isset($_SESSION['guest']) || $_SESSION['guest']) {
    /********************************************************************************************
    * Guests don't have permission for entering new DNA data                                    *
    *********************************************************************************************/
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>"; }

else {

if($formSubmitSave)
{  

  if(empty($formNewMethod) and empty($formNewCompany))
    { unset($formNewMethod);
      unset($formNewCompany); }

      
  if($formNewCompany=="" and $formNewMethod!="")
    { echo "Please complete 'Company'"; }
  
  if($formNewCompany!="" and $formNewMethod=="")
    { echo "Please complete 'Method'"; }
    
  if($formNewCompany!="" and $formNewMethod!="") 
  {
     $result= mysql_query ("SELECT ID_Purification_Method, Method FROM purification " .
                            "WHERE Method = '$formNewMethod'");
  
     if(mysql_num_rows($result))
       {  
       echo "<span class='error'>Purification Method already exists!</span>";
       }

     else    
       {
        $result = "INSERT INTO purification (Method, Company, Created_Who)" .
                          "VALUES ('$formNewMethod','$formNewCompany','$log')";   
        $sql = mysql_query($result);

#######################################Error 1###############################################################

if(!$sql)
{ $msg = $result."\n";
  $msg .= "####Error 1####";
  if($debug == '1') echo $msg;
  trigger_error($msg, E_USER_ERROR);
  /**
  * calling Error message
  */
  include ("Errorreport.php");   }
  
#############################################################################################################

        else {
        include("../config/DataSaved.php"); }                            
       }
   }
}//if ($formSubmitSave)
?>

<?php
$result= mysql_query ("SELECT * FROM purification " .
                      "ORDER BY Method");
      
$num_rows = mysql_num_rows($result);
echo "<table>";
if($num_rows > 0) {

    echo "<tr><td colspan='2'>The list shows all entries of table:purification. It is not possible to change or delete entries here. To do so please ask your administrator for assistance.<br/><br/></td></tr>";
    echo "<th width='400px'>Method (Company)</th><th width='300px'>Created</th>";

while ($row = mysql_fetch_object($result))
{
    echo "<tr><td align='center'>".$row->Method." (".$row->Company.")</td><td align='center'>".$row->Created_Who." (".$row->Created_When.")</td></tr>";
}}

else { echo "<tr><td><span class='fine'>No purification entries found.</span></td></tr>"; }

mysql_free_result($result);
?>
</table>
</td></tr>
<tr>
<td id="Change">Add new Method: </td><td><input type="text" name="formNewMethod"></tr>
<tr><td id="Change">and company: </td><td><input type="text" name="formNewCompany"></td></tr>
<tr><td></td><td>
<input type="submit" id="button" name="formSubmitSave" value="Save New Method" style="float:left" onClick="return CheckNewMethod();"></td></tr>

<tr><td colspan="2"><input type="submit" id="button" name="formSubmitClose" value="Close Form" style="float:right" onclick="window.close();"></td></tr>
<tr><td colspan="2">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>

<?php } ?>
</table>
</td>
</tr>
</table>
<?php
    /**
    * including footer
    */
    include("../footer.php"); ?> 

</form>
</div>
</body>
</html>