<?php
/**
* User settings
* <br/><br/>
* Script for defining settings for individual users
* <br/><br/>
* Access for all users
* @author Gabriele Droege, DNA Bank Network <contact@dnabank-network.org>
* @version 2.0
* @package Configuration
* @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 - Settings</title>
<link rel="stylesheet" type="text/css" href="../format.css">
<link rel="stylesheet" type="text/css" href="../input/XSLT/Styles.css">
<SCRIPT LANGUAGE="JavaScript1.1" src="../Functions.js"></SCRIPT>
<NOSCRIPT>Please enable Javascript!</NOSCRIPT>

</head>

<body>
<form name="formular" method="POST" action="settings.php">
<div align="center">

<?php 
     /**
    * including navigation menu
    */
    include("../tablenavi.php"); ?>
    
<table id="tablemain" class="main">
<tr>
<td id="tdLogo"><a href="<?php echo $Path_Wiki."/Installation#First_steps"; ?>" target="_blank"><img border="0" src="../images/Logo-Wiki.png" width="123"></a></td>
		<td id="tdtitle">
		<h1>User defined Settings</h1></td>
    <td id="tdLogo2"><?php echo $Path_Logo; ?></td>
    </tr>
  <tr>
    <td colspan="4"><?php
    echo "Logged in as: ";
    $log = $_SESSION["log"];
    $ID = $_SESSION["log2"];
    echo $log;
    ?></td>
  </tr>    
	<tr>
		<td colspan="3" valign="top">
		<table border="0 id="table2">
    <?php
    
    /********************************************************************************************
    * updating table usersettings with new parameters                                           *
    * START                                                                                     *
    *********************************************************************************************/
    if($_POST['formSubmitSave']) {

    $sql = "SELECT ID_Setting FROM usersettings WHERE FK_User = '$ID'";
    $result = mysql_query($sql);
    
    $count = mysql_num_rows($result);
    if($count == '0')
    {    $sqlnew = "INSERT INTO usersettings (Sorting, RecordsPerPage, SortingSP, RecordsPerPageSP, FK_User) VALUES ('$sorting','$recordspage','$sortingsp','$recordspagesp','$ID')";
         $resultnew = mysql_query($sqlnew); }
    else {
         $sqlchange = "UPDATE usersettings SET Sorting = '$sorting', RecordsPerPage = '$recordspage', 
         SortingSP = '$sortingsp', RecordsPerPageSP = '$recordspagesp' WHERE FK_User = '$ID'";
         $resultchange = mysql_query($sqlchange);
         
         if ($resultchange) { include("ChangesAccepted.php");   } 
         }


    }
    
    /********************************************************************************************
    * updating table usersettings with new parameters                                           *
    * END                                                                                       *
    *********************************************************************************************/
    
    /********************************************************************************************
    * start page                                                                                *
    * START                                                                                     *
    *********************************************************************************************/
    
    $sql = "SELECT * FROM usersettings WHERE FK_User = '$ID'";
    $result = mysql_query($sql);

    while($row = mysql_fetch_object($result))
    { $RecordsPerPage = $row->RecordsPerPage;
      $Sorting = $row->Sorting;
      $RecordsPerPageSP = $row->RecordsPerPageSP;
      $SortingSP = $row->SortingSP; }
           
    ?>
    <tr><td colspan="3"><h3>Search for DNA samples:</h3></td></tr>
 		<tr>
				<td id="DescriptionBlack">
				Records per page (hitlist):</td>
				<td colspan="2">
        <input name="recordspage" id="SelectLong" type="text" value="<?php echo $RecordsPerPage; ?>"/></td>
    </tr>
    <tr>
				<td id="DescriptionBlack">
				Sorting:</td>
				<td colspan="2">
        <select name="sorting" id="SelectLong">
          <option <?php if($Sorting == "") echo "selected "; ?>value="">----------</option>
          <option <?php if($Sorting == "DNANo") echo "selected "; ?>value="DNANo">DNA Number</option>
          <option <?php if($Sorting == "UnitIDS") echo "selected "; ?>value="UnitIDS">UnitID Specimen</option>
          <option <?php if($Sorting == "CollCodeS") echo "selected "; ?>value="CollCodeS">Collection Code Specimen</option>          
          <option <?php if($Sorting == "InstCodeS") echo "selected "; ?>value="InstCodeS">Institution Code Specimen</option>          
          <option <?php if($Sorting == "Taxon") echo "selected "; ?>value="Taxon">Taxon Name</option>          
        </select></td>
    </tr>
    <tr><td colspan="3"><h3>Search in Specimen Tool:</h3></td></tr>
 		<tr>
				<td id="DescriptionBlack">
				Records per page (hitlist):</td>
				<td colspan="2">
        <input name="recordspagesp" id="SelectLong" type="text" value="<?php echo $RecordsPerPageSP; ?>"/></td>
    </tr>
    <tr>
				<td id="DescriptionBlack">
				Sorting:</td>
				<td colspan="2">
        <select name="sortingsp" id="SelectLong">
          <option <?php if($SortingSP == "") echo "selected "; ?>value="">----------</option>
          <option <?php if($SortingSP == "SU") echo "selected "; ?>value="SU">UnitID Specimen</option>
          <option <?php if($SortingSP == "CU") echo "selected "; ?>value="CU">Collection Code Specimen</option>          
          <option <?php if($SortingSP == "IU") echo "selected "; ?>value="IU">Institution Code Specimen</option>          
          <option <?php if($SortingSP == "TU") echo "selected "; ?>value="TU">Taxon Name</option>          
        </select></td>
    </tr>    
	  <tr>
	    <td id="DescriptionBlack"></td>
	    <td>
          <input type="submit" value="Save" name="formSubmitSave" id="SelectLong"></td>
    </tr>    
			</table>
      
      <?php 
    /********************************************************************************************
    * start page                                                                                *
    * END                                                                                     *
    *********************************************************************************************/
      ?>
		</td>
	</tr>
  <tr>
      <td id="DescriptionBlack" colspan="2"></td>
      <td align="right"><input type="button" value="Return to Configuration Tool" name="formSubmitMenu" id="SelectLong" onClick="self.location.href = 'configuration.php';"></td>
    </tr>
</table>
 <?php
    /**
    * including footer
    */
    include ("../footer.php"); ?>

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

</html>