<?php

include 'include/headscript.php';

include('languages/' . $_SESSION['langselect'] . '/tdgen.php');

if (isset($_GET['idtd'])) {

    $idtd = $_GET['idtd'];

}

?>

<!DOCTYPE html>

<html lang="en">



<head>

    <meta charset="UTF-8">

    <meta name="viewport" content="width=device-width, initial-scale=1.0">

    <title>Aggiungi Production Place</title>

    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">

    <style>

        .container {

            max-width: 960px;

        }



        /* Modifica le dimensioni del testo */

        body,

        input,

        label {

            font-size: 14px;

            /* Imposta la dimensione del testo desiderata */

        }



        /* Modifica le dimensioni degli input */

        input[type="text"],

        input[type="tel"],

        input[type="email"] {

            font-size: 14px;

            /* Imposta la dimensione del testo negli input desiderata */

            height: calc(1.5em + .75rem + 2px);

            /* Imposta l'altezza degli input */

            padding: .375rem .75rem;

            /* Imposta il padding negli input */

        }



        .search-result {

            cursor: pointer;

            padding: 10px;

            margin-bottom: 5px;

            border: 1px solid #ccc;

            border-radius: 5px;

            background-color: #f9f9f9;

        }



        .search-result:hover {

            background-color: #e9e9e9;

        }

    </style>

</head>



<body>

    <div class="container mt-3">

        <h3>Aggiungi Production Place</h3>

        <form id="productionPlaceForm" method="post" action="save_datalocplace.php">

            <div class="form-group row">

                <label for="companyname" class="col-sm-2 col-form-label">Company Name</label>

                <div class="col-sm-10">

                    <input type="text" class="form-control" id="companyname" name="companyname" required>

                </div>

            </div>

            <div class="form-group row">

                <label for="address" class="col-sm-2 col-form-label">Address</label>

                <div class="col-sm-6">

                    <input type="text" class="form-control" id="address" name="address" required>

                </div>

                <label for="cap" class="col-sm-1 col-form-label">CAP</label>

                <div class="col-sm-3">

                    <input type="text" class="form-control" id="cap" name="cap">

                </div>

            </div>

            <div class="form-group row">

                <label for="city" class="col-sm-2 col-form-label">City</label>

                <div class="col-sm-4">

                    <input type="text" class="form-control" id="city" name="city" required>

                </div>

                <label for="country" class="col-sm-1 col-form-label">Country</label>

                <div class="col-sm-5">

                    <input type="text" class="form-control" id="country" name="country" required>

                </div>

            </div>



            <div class="form-group row">

                <label for="telephone" class="col-sm-2 col-form-label">Telephone</label>

                <div class="col-sm-3">

                    <input type="tel" class="form-control" id="telephone" name="telephone">

                </div>

                <label for="email" class="col-sm-1 col-form-label">Email</label>

                <div class="col-sm-3">

                    <input type="email" class="form-control" id="email" name="email">

                </div>

                <label for="telephone" class="col-sm-1 col-form-label">Fax</label>

                <div class="col-sm-2">

                    <input type="tel" class="form-control" id="fax" name="fax">

                </div>

            </div>









            <div class="form-group row">

                <label for="contactname" class="col-sm-2 col-form-label">Contact Name</label>

                <div class="col-sm-4">

                    <input type="text" class="form-control" id="contactname" name="contactname" required>

                </div>



            </div>

            <input type="hidden" class="form-control" id="idtd" name="idtd" value="<?php echo $idtd; ?>">





            <div class="row">

                <div class="col-sm-9 offset-sm-3">

                    <button type="submit" class="btn btn-primary">Salva</button>

                </div>

            </div>

            <br>



        </form>

        <hr> <!-- Riga orizzontale -->

        <form name="search">

            <div class="form-group row">

                <label for="companysearch" class="col-sm-2 col-form-label">Ricerca azienda</label>

                <div class="col-sm-7">

                    <input type="text" class="form-control" id="companysearch" name="companysearch" required>

                    <small class="form-text text-muted" style="font-size: 12px;">Inserisci almeno 3 caratteri del nome della compagnia per iniziare la ricerca.</small>

                </div>

            </div>



        </form>

        <div id="searchResults" class="mt-3"></div><!-- Risultati della ricerca -->





    </div>

    <script src="https://code.jquery.com/jquery-3.5.1.min.js"></script>

    <form id="productionPlaceForm" method="post" action="">

        <!-- Il tuo codice HTML del form -->



        <div class="row">

            <div class="col-sm-9 offset-sm-3">

                <!-- Il tipo del pulsante rimane "submit", ma non è necessario specificare l'attributo "form" -->



            </div>

        </div>



    </form>

    <script>

        var idcompany = <?php echo json_encode($_SESSION["compid"]); ?>;

    </script>



    <script>

        $(document).ready(function() {

            $('#companysearch').on('input', function() {

                var searchQuery = $(this).val();

                if (searchQuery.length >= 3) {

                    $.ajax({

                        url: 'searchcompany.php', // Percorso dello script lato server

                        method: 'POST',

                        data: {

                            searchQuery: searchQuery,

                            idcompany: idcompany // Sostituisci con l'id della company se necessario

                        },

                        success: function(response) {

                            // Manipola il DOM per visualizzare i risultati della ricerca

                            $('#searchResults').html(response);

                        },

                        error: function(xhr, status, error) {

                            console.error(xhr.responseText);

                        }

                    });

                }

            });



            $(document).on('click', '.search-result', function() {

                $('#companyname').val($(this).data('companyname'));

                $('#address').val($(this).data('address'));

                $('#city').val($(this).data('city'));

                $('#cap').val($(this).data('cap'));

                $('#country').val($(this).data('country'));

                $('#telephone').val($(this).data('telephone'));

                $('#email').val($(this).data('email'));

                $('#fax').val($(this).data('fax'));

                $('#contactname').val($(this).data('contactname')); // Aggiunto il popolamento per il campo contactname

            });



            // Intercetta l'evento keypress sul campo di ricerca

            $('#companysearch').on('keypress', function(event) {

                if (event.which === 13) { // 13 è il codice ASCII per il tasto Invio

                    event.preventDefault(); // Previene l'invio del form

                }

            });

        });

    </script>







    <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>

</body>



</html>